akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <deque>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;

int N, M;

signed main()
{
	cin >> N >> M;

	int time = M * 1900 + (N - M) * 100;
	double base_ratio = 1.0 / pow(2, M);
	double rest_r = 1.0;
	double r = base_ratio;

	double ans = 0;
	for (int i = 1; i < 10000000; i++)
	{
		ans += (r * (time * i));
		rest_r -= r;
		r = base_ratio * rest_r;
	}
	cout << (int)(ans + 0.1) << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000009;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int N, M;
int L[100001], R[100001];

int A[100001];

int main() {
    cin >> N >> M;
    REP (i, N + 1) {
        A[i] = 0;
    }
    REP (i, M) {
        int L, R;
        cin >> L >> R;
            A[L]++;
            A[R + 1]--;
    }
    int ans = 0;
    REP (i, N + 1) {
        if (i > 0) {
            A[i] += A[i - 1];
        }
        if (A[i] == M) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<cstring>
#define N 810
using namespace std;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
int n,m,K,a[N][N],vis[N][N],sx,sy;
queue<int> x,y,k;
int main(){
	scanf("%d%d%d",&n,&m,&K);
	memset(a,0,sizeof(a));
	memset(vis,0,sizeof(vis));
	for (int i=1;i<=n;i++){
		string s;cin>>s;;
		for (int j=0;j<m;j++){
			if (s[j]=='S') sx=i,sy=j+1;
			a[i][j+1]=(s[j]=='.');
		}
	}
	vis[sx][sy]=1;
	if (sx==1||sx==n||sy==1||sy==m) {cout<<"0";return 0;};
	x.push(sx);y.push(sy);k.push(0);
	while (!x.empty()){
		int xx,yy,kk;
		xx=x.front();x.pop();
		yy=y.front();y.pop();
		kk=k.front();k.pop();
		if (kk==K) continue;
		if (xx==1||xx==n||yy==1||yy==m) {cout<<"1"; return 0;};
		for (int i=0;i<4;i++){
			int nx,ny;
			nx=xx+dx[i];ny=yy+dy[i];
			if (a[nx][ny]&&!vis[nx][ny]){
				vis[nx][ny]=1;
				x.push(nx);y.push(ny);k.push(kk+1);
			}
		}
	}
	int res=(int)1e9+7;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (vis[i][j]){
				int d=min(min(i-1,j-1),min(n-i,m-j));
				int cur=(d+K-1)/K;
				res=min(res,cur+1);
			}
	cout<<res;
	return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e18
#define EPS 1e-9
#define MAX 200009
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tt, T)
	{
		//cout << "Case #" << tp << ": ";
		int n; cin >> n;
		if(n % 1000 == 0) cout << 0;
		else cout << 1000-n%1000;
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3636
import numpy
n = int(input())
l = []
ans = n

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

if is_prime(n) :
    print(n-1)
if is_prime(n) == False:
    for i in range(2,int(numpy.sqrt(n))+1):
        if n%i == 0:
            a = i
            b = n//i
            ans = min(n,a+b-2)
    print(ans)

Measured memory_bytes: 27148
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
ll gcd(ll a,ll b){
    if(a < b) swap(a,b);
    if(a % b == 0) return b;
    return gcd(b, a % b);

}

class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N;
        cin >> N;

        vector<ll> A(N);
        for(int i = 0; i < N; ++i){
            cin >> A[i];
        }

        ll g = A[0];
        for(int i = 0; i < N; ++i){
            g = gcd(g, A[i]);
        }

        for(int i = 0; i < N; ++i){
            A[i] /= g;
        }

        sort(all(A));
        ll ans = A[1];
        for(int i = 1; i < N; ++i){
            ans = gcd(ans, A[i]);
        }
        ans *= g;

        ll h = A[0];
        for(int i = 1; i < N; ++i){
            h = gcd(h, A[i]);
            if(h == 1){
                ll x = A[0];
                for(int j = 0; j < N; ++j){
                    if(i != j){
                        x = gcd(x, A[j]);
                    }
                }
                if(ans < x * g){
                    ans = x * g;
                }
                break;
            }
        }
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int a,b;
    int x[]= {4,6,9,11};
    int y[]= {1,3,5,7,8,10,12};
    cin>>a>>b;
    if(a==2||b==2)
    {
        cout<<"No"<<endl;
        return 0;
    }
    int f=0;
    for(int i=0; i<4; i++)
    {
        if(a==x[i])
        {
            for(int i=0; i<4; i++)
            {
                if(b==x[i])
                {
                    cout<<"Yes"<<endl;
                    f=1;
                    return 0;
                }
            }
        }
    }
    if(f==0)
    {
        for(int i=0; i<7; i++)
        {
            if(a==y[i])
            {
                for(int i=0; i<7 ;i++)
                {
                    if(b==y[i])
                    {
                        cout<<"Yes"<<endl;
                        f=1;
                        return 0;
                    }
                }
            }
        }
    }
    if(f==0) cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
//JAI SAI RAM Trying to solve harder problems first
//atcoder seems better than codechef might or might not be...
// message me on codeforces if you want anything related to competitive coding my codeforces handle is @AM_I_Learning.
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{  
     ll i,j,k,l,m,n,o,p,q,r,s,t,a[100001],b[100001];
     string ss;
     cin>>n>>m>>k;
     r=10000000000000000;
     l=1000000000000000;
     for(i=0;i<n;i++)
     {
         cin>>a[i];
         r=min(r,a[i]);
     }
     for(i=0;i<m;i++)
     {
         cin>>b[i];
         l=min(l,b[i]);
     }
     s=1000000000000000;
     s=min(s,r+l);
     for(i=0;i<k;i++)
     {
          cin>>o>>p>>q;
          j=a[o-1]+b[p-1]-q;
          s=min(s,j);
     }
     cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public static class Program
{
    public static void Main(params string[] args)
    {
        var l = Console.ReadLine()
            .Split(' ')
            .Select(int.Parse)
            .ToArray();
        var x = l[0];
        var a = l[1];
        Console.WriteLine(x < a ? "0" : "10");
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<queue>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;

int main() {
  ll x;
  cin >> x;
  ll sum = 0;
  int cnt = 0;
  for(ll i=1;sum<x;i++) {
    sum += i;
    ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<int> x(N), y(N);
        for(int i=0;i<N;i++) cin >> x[i] >> y[i];
        map<pair<int,int>, int> S;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i == j) continue;
                auto key = make_pair(x[j]-x[i], y[j]-y[i]);
                if(!S.count(key)) S[key] = 0;
                ++S[key];
            }
        }
        int res = N;
        for(auto it : S){
            res = min(res, N-it.second);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int x=scan.nextInt();
        int element, outpint;
        int[] out=new int[x+1];
        
        for(int i=0; i<n; i++){
            outpint=0;
            for(int j=0; j<x; j++){
                out[j]+=element=scan.nextInt();
                System.out.print(element+" ");
                outpint+=element;
            }
            System.out.println(outpint);
        }
        for(int j=0; j<x; j++){
            System.out.print(out[j]+" ");
        }
        System.out.println(Arrays.stream(out).sum());
    }
}


Measured memory_bytes: 45792
import java.util.*;
import java.io.*;

public class Main {
	private static void solve() throws Exception {
		// final long MAX = 999999;

		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new FileReader("a.in"));
		PrintWriter pw = new PrintWriter(System.out, true);

		while(sc.hasNext()) {
			int i = 2;
			int n = sc.nextInt();
			boolean bool[] = new boolean[n+1];
			
			while(i<=n) {
				int k = 2;
				int c = i*k++;
				while(!bool[i] && c<=n) {
					bool[c] = true;
					c=i*k++;
				}
				i++;
			}

			long counter=0;
			for(int z=2; z<=n; z++) {
				if(!bool[z]) counter++;
			}

			System.out.println(counter);
		}
	}

	public static void main(String[] args) throws Exception {
		new Main().solve();
	}

	static void debug (Object...a) {
		System.out.println(Arrays.deepToString(a));
	}
}

Measured memory_bytes: 34976
#include <iostream>
#include <algorithm>

using namespace std;

class B {
	int a, b, k;
public:
	void solve()
	{
		int lower_bound{ max(a, b - k + 1) };
		int upper_bound{ min(b, a + k - 1) };

		if (upper_bound >= lower_bound)
		{
			for (int i{ a }; i <= b; i++)
				cout << i << endl;
		}
		else
		{
			for (int i{ a }; i <= upper_bound; i++)
				cout << i << endl;
			for (int i{ lower_bound }; i <= b; i++)
				cout << i << endl;
		}
	}

	B()
	{
		cin >> a >> b >> k;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		double[] p1 = {0, 0}, p2 = {100, 0};
		System.out.println(p1[0] + " " + p1[1]);
		koch(n, p1, p2);
		System.out.println(p2[0] + " " + p2[1]);
		
		scanner.close();
	}
	
	public static void koch(int d, double[] p1, double[] p2) {
		if(d == 0) return;
		
		double[] s = new double[2];
		double[] u = new double[2];
		double[] t = new double[2];
		
		s[0] = (p1[0] * 2 + p2[0] * 1) / 3;
		s[1] = (p1[1] * 2 + p2[1] * 1) / 3;
		t[0] = (p1[0] * 1 + p2[0] * 2) / 3;
		t[1] = (p1[1] * 1 + p2[1] * 2) / 3;
		
		u[0] = (t[0] - s[0]) * Math.cos(Math.PI / 3) - (t[1] - s[1]) * Math.sin(Math.PI / 3) + s[0];
		u[1] = (t[0] - s[0]) * Math.sin(Math.PI / 3) + (t[1] - s[1]) * Math.cos(Math.PI / 3) + s[1];
		
		koch(d - 1, p1, s);
		System.out.println(s[0] + " " + s[1]);
		koch(d -1, s, u);
		System.out.println(u[0] + " " + u[1]);
		koch(d -1, u, t);
		System.out.println(t[0] + " " + t[1]);
		koch(d - 1, t, p2);
	}
} 



Measured memory_bytes: 32388
import  itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

for i, aaa in enumerate(itertools.permutations(range(1,N+1),N)):
    if P == list(aaa):
        num_P = i + 1

    if Q == list(aaa):
        num_Q = i + 1

print(abs(num_P-num_Q))

Measured memory_bytes: 3064
program name
    implicit none
    integer(4):: n,i,ans
    character(200):: s


    read*, s(:)
    n = len_trim(s)
    ans = 0
    do i=1,n/2-1
        if (guu(i)) ans=max(ans,i)
    end do

    print*, ans*2

contains
function guu(num) result(ret)
    integer(4):: num
    logical:: ret

    ret = s(1:num) == s(num+1:2*num)
end function
end program name

Measured memory_bytes: 512
/*
 * main.c
 *
 *  Created on: 2020/02/22
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

char S[100] = {0};

int main()
{
	int i = 0, len = 0, ans = 0;
	scanf("%s", S);
	len = strlen(S);
	for (i = 0; i < (len/2); i++) {
		if (S[i] == S[(len - 1) - i]) {
			continue;
		} else {
			ans = 1;
			break;
		}
	}

	if (ans == 0) {
		len = len/2;
		for (i = 0; i < (len/2); i++) {
			if (S[i] == S[(len - 1) - i]) {
				continue;
			} else {
				ans = 1;
				break;
			}
		}
	}

	if (ans == 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
     int a,b,c;
             scanf("%d %d %d",&a,&b,&c);
     if (a<=b && b<=c){
             printf("%d %d %d\n",a,b,c);
     }
     else if (b<=a && a<=c){
             printf("%d %d %d\n",b,a,c);
     }
     else if (a<=c && c<=b){
             printf("%d %d %d\n",a,c,b);
     }
     else if (b<=c && c<=a){
             printf("%d %d %d\n",b,c,a);
     }
     else if (c<=a && a<=b){
             printf("%d %d %d\n",c,a,b);
     }
     else if (c<=b && b<=a){
             printf("%d %d %d\n",c,b,a);
     }
     return 0;
}

       

Measured memory_bytes: 596
#!/usr/bin/env python
# coding: utf-8

# In[24]:


import sys
#import numpy as np
input = sys.stdin.readline
N = int(input())
l = [input().split()+[i+1] for i in range(N)]


# In[25]:


sl = sorted(l, key=lambda x:int(x[1]), reverse=True)
sl = sorted(sl, key=lambda x:x[0])
#print(sl)
for i in range(N):
    print(sl[i][2])


# In[ ]:


"""
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
"""



Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int d;
int c[27];
int s[366][27];
int calc(vector<int> t){
    int last[26]={};
    vector<int> ret(d);
    int ans=0;
    for(int i=0; i<d; i++){
        ans+=s[i][t[i]];
        last[t[i]]=i+1;
        for(int j=0; j<26; j++){
            ans-=c[j]*(i+1-last[j]);
        }
        ret[i]=ans;
    }
    return ans;
}
int main()
{
    cin>>d;
    for(int i=0; i<26; i++) cin>>c[i];
    for(int i=0; i<d; i++) for(int j=0; j<26; j++) cin>>s[i][j];
    vector<int> t(d);
    for(int i=0; i<d; i++){
        cin>>t[i];
        t[i]--;
    }
    int ans=calc(t);
    int m; cin>>m;
    while(m--){
        int k, q; cin>>k>>q;
        k--; q--;
        if(t[k]==q){
            cout<<ans<<endl;
            continue;
        }
        int pr=t[k];
        ans-=s[k][pr];
        ans+=s[k][q];
        int last[2]={};
        for(int i=0; i<d; i++){
            if(t[i]==pr) last[0]=i+1;
            else if(t[i]==q) last[1]=i+1;
            ans+=c[pr]*(i+1-last[0]);
            ans+=c[q]*(i+1-last[1]);
        }
        t[k]=q, last[0]=last[1]=0;
        for(int i=0; i<d; i++){
            if(t[i]==pr) last[0]=i+1;
            else if(t[i]==q) last[1]=i+1;
            ans-=c[pr]*(i+1-last[0]);
            ans-=c[q]*(i+1-last[1]);
        }
        cout<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;

int main () {
    bool isStPal;
    string s, t, ss, st;
    cin >> s;
    t = s;
    reverse(begin(t), end(t));
    if (s != t) isStPal = false;
    else {
        ss = s.substr (0,(s.length() - 1) / 2);
        st = ss;
        reverse(begin(st), end(st));
        if (ss != st) isStPal = false;
        else {
            ss = s.substr ((s.length() + 1) / 2, (s.length() - 1) / 2);
            st = ss;
            reverse(begin(st), end(st));
            if (ss != st) isStPal = false;
            else isStPal = true;
        }
    }
    printf("%s\n", isStPal ? "Yes" : "No");
    //cout << t << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <functional>
#include <string>
#define SIZE 3005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll inv[SIZE],fac[SIZE],finv[SIZE];
int L[SIZE],R[SIZE];
char str[SIZE];
ll dp[SIZE];
ll nxt[SIZE];
int sz;

void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	scanf("%s",&str);
	for(int i=0;i<m;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);l--,r--;
		if(sz>0&&L[sz-1]==l) R[sz-1]=max(R[sz-1],r);
		else if(sz==0||R[sz-1]<r)
		{
			L[sz]=l;
			R[sz]=r;
			sz++;
		}
	}
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	int c=0;
	for(int i=0;i<sz;i++)
	{
		//printf("* %d %d\n",L[i],R[i]);
		int one=0;
		int f=L[i];
		if(i>0) f=max(f,R[i-1]+1);
		for(int j=f;j<=R[i];j++) if(str[j]=='1') one++;
		
		//printf("%d %d\n",one,c);
		if(one>0)
		{
			for(int j=c;j>=0;j--)
			{
				dp[j+one]=dp[j];
				dp[j]=0;
			}
		}
		//今 1 が何個あるかが分かった
		int wt=0;
		if(i+1<sz) wt=max(wt,R[i]-L[i+1]+1);
		//wt 個残したい
		int len=R[i]-L[i]+1;
		for(int j=0;j<len-wt;j++)
		{
			for(int k=0;k+1<SIZE;k++)
			{
				dp[k]+=dp[k+1];
				if(dp[k]>=MOD) dp[k]-=MOD;
			}
			dp[len-j]=0;
		}
		//for(int j=0;j<10;j++) printf("%d ",dp[j]);puts("");
		c=wt;
	}
	printf("%d\n",dp[0]);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

//a,b???GCD
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//?´???°??????
vector<ll> divisor(ll n){
    vector<ll> res;
    //res.push_back(1);res.push_back(n);
    ll tmp=n;
    for(int i=2;i*i<=n;i++){
        if(tmp%i!=0)continue;
        res.push_back(i);
        while(tmp%i==0){
            tmp/=i;
        } 
    }
    if(tmp!=n) res.push_back(tmp);
    sort(res.begin(),res.end());
    return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    ll p,q;cin>>p>>q;
    ll g=gcd(p,q);
    p/=g;q/=g;
    vector<ll> res=divisor(q);
    if(res.size()==0) cout<<q<<endl;
    else{
        ll ret=1;
        for(int i=0;i<(int)res.size();i++) ret*=res[i];
        cout<<ret<<endl;
    }
}

Measured memory_bytes: 3208
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll t,n;
    while (cin >> t>>n)
    {
        if(n>=t)cout<<"unsafe\n";
        else cout<<"safe\n";
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILL(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){

  int a,b,c;
  cin >> a >> b >> c;
  int rest = a-b;
  if(rest > 0 && rest <= c)cout << c - rest;
  else if(rest > 0 && rest > c) cout << 0;
  else if(rest <= 0)cout << c;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
int main() {
    long long n,k,i,ans,coall,cof,j;
    long long mod=1000000007;
    coall=0;
    cof=0;
    ans=0;
    cin>>n>>k;
    vector<int> vec(n);
    for(i=0;i<n;i++){
      cin>>vec[i];
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        if(vec[i]>vec[j]){
          coall++;
        }
      }
      ans+=coall*((k-1)%mod*k/2%mod)%mod;
      coall=0;
      for(j=i;j<n;j++){
        if(vec[i]>vec[j]){
          cof++;
        }
      }
      ans+=cof*k%mod;
      cof=0;
    }
  ans=ans%mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
from scipy.sparse.csgraph import johnson
h, w = map(int, input().split())
c = johnson([list(map(int, input().split())) for _ in range(10)])

ans = 0
for _ in range(h):
    for j in map(int, input().split()):
        ans += (j != -1) * int(c[j][1])
print(ans)

Measured memory_bytes: 25244
#include<stdio.h>

int exist[26];

int main(){
	char S[27];
	scanf("%s",S);
	for(int i=0;S[i]!='\0';i++){
		int c=S[i]-'a';
		if(exist[c]>0){
			printf("no\n");
			return 0;
		}
		exist[c]++;
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N,M;cin>>N>>M;
    int s=0,g=10;
    if(N==2){
        s=10,g=100;
    }
    if(N==3){
        s=100,g=1000;
    }
    vector<int> a(N,-1);
    REP(i,M){
        int s,c;
        cin>>s>>c;
        s--;
        if(a[s]==-1){
            a[s]=c;
        }
        else if(a[s]!=c){
            cout<<-1<<endl;
            return 0;
        }
    }
    rep(i,s,g){
        string n=to_string(i);
        bool ok=true;
        REP(j,N) if(a[j]>=0&&a[j]!=n[j]-'0'){
            ok=false;
        }
        if(ok){
            cout<<n<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iiii tuple<int, int, int, int>
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define vi vector<int>
#define vvi vector<vector<int>>
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int cal(vector<vi>& a, int x, int y) {
    for (auto& i : a)
        for (auto& j : i)
            if (j != -1) j = 0;

    queue<iii> q;
    q.push(iii{x, y, 1});

    int u, v, c, res = 0;
    while (!q.empty()) {
        tie(u, v, c) = q.front();
        q.pop();

        if (u < 0 || u == a.size() || v < 0 || v == a[0].size() || a[u][v]) continue;
        a[u][v] = c;
        res = max(res, c);

        for (int i = -1; i < 2; i += 2) {
            q.push(iii{u + i, v, c + 1});
            q.push(iii{u, v + i, c + 1});
        }
    }
    return res - 1;
}

void solve() {
    int h, w;
    cin >> h >> w;
    vector<vi> a(h, vi(w, 0));
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if (c == '#') a[i][j] = -1;
        }
    int res = 0;
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j) {
            if (a[i][j] == -1) continue;
            res = max(res, cal(a, i, j));
        }
    cout << res << '\n';
}

int main() {
    // ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

Measured memory_bytes: 256
program friction
  implicit none
  integer :: h, w, c(300,300) = 0, i, j, ans = 0
  character(300) :: s
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    do j = 1, w
      c(i,j) = ichar(s(j:j))-96
    end do
  end do
  do j = 1, w-1
    ans = ans+calc(h,c(1:h,j:j+1))
  end do
  write(*,'(i0)') ans
contains
  integer function calc(h,c)
    integer, intent(in) :: h, c(h,2)
    integer :: dp(0:h,0:h), cost(0:h,0:h), x, y
    dp = 0
    cost = 0
    do x = -h, h
      do y = max(1,1-x), min(h,h-x)
        cost(y,y+x) = cost(y-1,y+x-1)
        if (c(y,1) == c(y+x,2)) cost(y,y+x) = cost(y,y+x)+1
      end do
    end do
    do x = 1, h
      do y = 1, h
        dp(x,y) = min(dp(x-1,y),dp(x,y-1))+cost(x,y)
      end do
    end do
    calc = dp(h,h)
  end
end program friction

Measured memory_bytes: 1336
// Created by new_sm
//
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int a,b,c;
cin>>a>>b>>c;
if((a<c&&c<b)||(b<c&&c<a))
cout<<"Yes";
else
cout<<"No";
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}



Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	double a,b,c,cr,S,L,h;
	cin >> a >> b >> c;
	cr = c*3.1415926535/180;
	h = b*sin(cr);
	//S = a/2*h; //?????£?¢?
	S = a/2.0*b*sin(cr);
	//L = a+b+sqrt(pow(a-cos(cr)*b,2)+pow(h,2)); //?????£?¢?
	L = a+b+sqrt(a*a+b*b-2.0*a*b*cos(cr));

	printf("%f\n",S);
	printf("%f\n",L);
	printf("%f\n",h);
	//printf("%.16f\n",sin(cr));
	//printf("%.10f\n",cr);

	return 0; 
}

Measured memory_bytes: 3444
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int from, to;
    lint cost;
};

int n, m;
lint p;
vector<edge> edges;
vector<lint> cost;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

bool bellman_ford(int start, int goal){
    cost.resize(n);
    fill(cost.begin(), cost.end(), -LLINF);
    cost[start] = 0;
    for(int i = 0 ; i < n * 2 ; ++i){
        for(int j = 0 ; j < m ; ++j){
            edge now = edges[j];
            if(cost[now.from] != -LLINF && cost[now.to] < cost[now.from] + now.cost){
                cost[now.to] = cost[now.from] + now.cost;
                if(i >= n - 1 && now.to == goal){
                    return false;
                }
                if(i >= n - 1){
                    cost[now.to] = LLINF;
                }
            }
        }
    }
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> m >> p;

    rep(i, m){
        int a, b;
        lint c;
        cin >> a >> b >> c;
        edges.push_back({--a, --b, c - p});
    }

    if(bellman_ford(0, n - 1)){
        cout << max(cost[n - 1], 0LL) << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    sort(a.begin(), a.end());

    vector<P> seq;
    vector<bool> used(n, false);
    for(int i=n-2; i>0; i--){
        if(0 <= a[i] && !used[i]){
            used[i] = true;
            seq.emplace_back(a[0], a[i]);
            a[0] -= a[i];
        }
        else break;
    }

    for(int i=0; i<n-1; i++){
        if(a[i] <= 0 && !used[i]){
            used[i] = true;
            seq.emplace_back(a[n-1], a[i]);
            a[n-1] -= a[i];
        }
        else break;
    }

    cout << a[n-1] << endl;
    for(auto i:seq){
        cout << i.fs << " " << i.sc << endl;
    }
}

Measured memory_bytes: 3192
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main implements Runnable
{
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        P p[]=new P[n];
        for (int i = 0; i < p.length; i++) {
        	int x=sc.nextInt();
        	int l=sc.nextInt();
			p[i]=new P(x-l,x+l);
		}
        sort(p);
        int a=0,l=-(1<<28);
        for (int i = 0; i < p.length; i++) {
        	if(l<=p[i].x) {
        		a++;
        		l=p[i].y;
        	}
//			db(p[i].x,p[i].y);
		}
        out.print(a);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int x,y;
    P(int x,int y) {
    	this.x=x;
    	this.y=y;
    }

    public int compareTo(P p){
        return y-p.y;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 46696
'use strict'

function Main(input) {
  const N = Number(input.split("\n")[0])
  const W = input.split("\n")[1].split(" ").map(x => Number(x))
  const list = []

  const total = W.reduce((acc, x) => acc + x)

  for(let i=1; i<N; i++) {
      let before = 0
      for(let j=0; j<i; j++) {
          before += W[j]
      }
      let after = total - before
      list.push(Math.abs(before - after))
  }
  console.log(Math.min.apply(null, list))
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())


Measured memory_bytes: 21192
s = input()
k = int(input())

#5 sen tyou = 5 * (10 ** 15)

co = 0
for i in s:
    co += 1
    if i == "1":
        if k == co:
            print(1)
            break
        else:
            continue
    else:
        print(int(i))
        break


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    String str=reader.readLine();
	    String s[]=str.split(" ");
	    int a=Integer.parseInt(s[0]);
	    int b=Integer.parseInt(s[1]);
	    int c=Integer.parseInt(s[2]);

	    if(a>=c){
		System.out.println("0");
	    }else{
		int d=c-a;
		if(d<=b){
		    System.out.println(d);
		}else{
		    System.out.println("NA");
		}
	    }
	    
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int gcd (int a, int b){
	return b>0?gcd(b,a%b):a;
    }
    static int lcm (int a, int b) {
	return a*b/gcd(a,b);
    }
}



Measured memory_bytes: 24356
#include<bits/stdc++.h>
using namespace std;

int main(){
  double mine = 0, leader = 0;
  int t;
  cin >> t;
  for(int x=0;x<=t;x++){
    int n,m;
    cin >> n >> m;
    double v,r,exp = 0, sum=0;
    for(int i=0;i<m;i++){
      cin >> v >> r;
      exp += v*r;
      sum += r;
    }
    exp /= sum;

    if(x==t)leader = exp;
    else mine = max(mine, exp);
  }
  cout << (leader+1e-8<mine?"YES":"NO") << endl;
}

Measured memory_bytes: 1228
s = input()[::-1]
mod = 2019
cnt = [0] * mod
x = 1
cnt[0] = 1
total = 0
for s in s:
    total += int(s) * x
    total %= mod
    cnt[total] += 1
    x *= 10
    x %= mod


ans = sum(i*(i-1)//2 for i in cnt)
print(ans)


Measured memory_bytes: 9200
# import sys
# input = sys.stdin.readline

N,M,Q = map(int,input().split())

com = [[0] * 502 for i in range(502)]

for _ in range(M):
    L,R = map(int,input().split())
    com[L][R] += 1

for i in range(502):
    for j in range(1,502):
        com[i][j] += com[i][j-1]

for _ in range(Q):
    p,q = map(int,input().split())
    ans = 0
    for i in range(p,q+1):
        ans += com[i][q]
    print(ans)


Measured memory_bytes: 76688
/*
ID: jerrywcy
TASK: AtCoder ABC 105 Problem A
LINK: https://abc105.contest.atcoder.jp/tasks/abc105_a
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n,k;

int main()
{
	cin>>n>>k;
	if (n%k==0)cout<<0<<endl;
	else cout<<1<<endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
  
// A utility function that returns 
// maximum of two integers 

using namespace std;

int max(int a, int b) 
{ 
    return (a > b) ? a : b; 
} 
  
// Returns the maximum value that 
// can be put in a knapsack of capacity W 
long long int knapSack(int W, int wt[], int val[], int n) 
{ 
    int i, w; 
    long long int K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (i>=1 && wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    return K[n][W]; 
} 
  
int main() 
{
	int n,W;
	cin>>n>>W;
	
    int val[n];
    int wt[n]; 
    
    for(int i=0;i<n;i++)
    {
    	cin>>wt[i]>>val[i];
	}
    //int W = 50; 
    //int n = sizeof(val) / sizeof(val[0]); 
    cout<<knapSack(W, wt, val, n); 
    return 0; 
} 


Measured memory_bytes: 82384
#include <bits/stdc++.h>
using namespace std;

const int maxn = 100100;
int k, n;
int h[maxn];

signed main() {
  // freopen("in", "r", stdin);
  while(~scanf("%d%d",&n,&k)) {
    for(int i = 1; i <= n; i++) {
      scanf("%d", &h[i]);
    }
    sort(h+1, h+n+1);
    int ret = 0x7f7f7f7f;
    for(int i = 1; i <= n; i++) {
      if(i + k - 1 > n) break;
      ret = min(ret, h[i+k-1]-h[i]);
    }
    printf("%d\n", ret);
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <random>
#include <vector>

using namespace std;

struct Lamp {
  vector<int> sws;
  bool even;
};

bool check(vector<bool>& sw, vector<Lamp>& lamps) {
  for (const Lamp& lamp : lamps) {
    int cnt = 0;
    for (const int s : lamp.sws) {
      if (sw[s]) ++cnt;
    }
    if (lamp.even && cnt % 2 == 1) return false;
    else if (!lamp.even && cnt % 2 == 0) return false;
  }
  return true;
}

int bruteforce(vector<bool>& sws, size_t idx, vector<Lamp>& lamps) {
  int cnt = 0;
  if (idx == sws.size() - 1) {
    for (int i = 0; i < 2; ++i) {
      sws[idx] = i == 0;
//      Log(true, sws);
        if (check(sws, lamps)) {
        ++cnt;
//        cout << ": bingo" << endl;
          }// else { cout << ": fail" << endl;}
    }
    return cnt;
  }
  sws[idx] = true;
  cnt += bruteforce(sws, idx+1, lamps);
  sws[idx] = false;
  cnt += bruteforce(sws, idx+1, lamps);

  return cnt;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<Lamp> lamps;
//  vector<bool> fix(N, true);
  for (int m = 0; m < M; ++m) {
    int S;
    cin >> S;
    vector<int> sws;
    for (int s = 0; s < S; ++s) {
      int sw;
      cin >> sw;
      sws.push_back(sw-1);
//      fix[sw-1] = false;
    }
    lamps.push_back(Lamp{sws, true});
  }
  for (int m = 0; m < M; ++m) {
    int ev;
    cin >> ev;
    lamps[m].even = ev == 0;
  }
  vector<bool> init_sws(N, true);
  
  cout << bruteforce(init_sws, 0, lamps) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    vector<vector<double> > dp(31, vector<double>(100000,0));
    dp[0][0]=1;
    double win=0.0;
    for(int i=1; i<=N; i++){
        dp[1][i]+=(double) 1.0/N;
        if(i>=K)win+=dp[1][i];
    }
    for(int i=1; i<30; i++){
        for(int j=1; j<K; j++){
            if(2*j>=K){
                win+=0.5*dp[i][j];
                continue;
            }
            dp[i+1][2*j]+=0.5*dp[i][j];
        }
    }
    cout << setprecision(10) << win << endl;

}

Measured memory_bytes: 25344
#include<stdio.h>

int main(){
    int jp=1;
    float x1,y1,x2,y2,x3,y3,xp,yp;
    while(scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
    if(y3>(y1-y2)*(x3-x1)/(x1-x2)+y1){
        if(yp<=(y1-y2)*(xp-x1)/(x1-x2)+y1)jp*=0;
    }
    else  if(yp>=(y1-y2)*(xp-x1)/(x1-x2)+y1)jp*=0;
    
    if(y2>(y1-y3)*(x2-x1)/(x1-x3)+y1){
        if(yp<=(y1-y3)*(xp-x1)/(x1-x3)+y1)jp*=0;
    }
    else  if(yp>=(y1-y3)*(xp-x1)/(x1-x3)+y1)jp*=0;
    
    if(y1>(y3-y2)*(x1-x3)/(x3-x2)+y3){
        if(yp<=(y3-y2)*(xp-x3)/(x3-x2)+y3)jp*=0;
    }
    else  if(yp>=(y3-y2)*(xp-x3)/(x3-x2)+y3)jp*=0;
    
    if(jp==1)printf("YES\n");
    else printf("NO\n");
    jp=1;
    }
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main(){
	int n,k,m,l,sum=0,cot=0,x=1e7,y=-1;
	memset(a,0,sizeof(a));
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>m;
		a[m]++;
		x=min(x,m);
		y=max(y,m);
	}
	if((y-x+1)<=k){
		cout<<0;
		return 0;
	}
	sort(a+x,a+y+1);
	while((y-x+1)>k){
		sum+=a[x];
		x++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>

int isprime(int n){
  int i;
  for(i = 2; i * i <= n; i++){
    if(n % i == 0) return 0;
  }
  return 1;
 }

int	main(){
	int	n,	i,	a,	b,	max,	data[10000];
	while(1){
	  a	=	0;
	  b	=	0;
	  max	=	0;
	  scanf("%d",	&n);
	  if(n	==	0) break;
	  for(i	=	n;	i	>=	1;	i--){
		  if(isprime(i)	==	1){
			  a	=	b;
			  b	=	i;
		  }
		  if(a	-	b	==	2)break;
		}
		printf("%d %d\n",	b,	a);
	}
	return	0;
}

Measured memory_bytes: 1028
#169A https://atcoder.jp/contests/abc169/tasks/abc169_a

# 1．入力を受け取ること
# スペース区切りの入力を整数として受け取れる「2 5」　-> 「a=2, b=5」となる
a, b = map(int, input().split())

# print(a)
# print(b)

#2. 受け取った結果を使って目的の計算をすること
answer = a * b

#3. 出力すること
print(answer)


Measured memory_bytes: 9088
#include<cstdio>
#include<algorithm>
const int MaxN=1000010;
int N,a[3][MaxN],x[MaxN];
bool rev[MaxN],vis[MaxN];
bool solve(){
	int rs[2]={0};
	for(int i=0;i<N;i++){
		int v[4]={a[0][i],a[1][i],a[2][i]};
		std::sort(v,v+3);
		if(v[1]-v[0]==1&&v[2]-v[1]==1){
			x[i]=v[0]/3;
			if(a[0][i]==v[0]&&a[1][i]==v[1]&&a[2][i]==v[2])rev[i]=0;
			else if(a[0][i]==v[2]&&a[1][i]==v[1]&&a[2][i]==v[0])rev[i]=1;
			else return 0;
		}
		if((x[i]-i)%2)return 0;
		if((x[i]-i)/2%2)rev[i]=!rev[i];
		if(rev[i])rs[i%2]^=1;
	}
	for(int t=0;t<2;t++){
		int r=0;
		for(int i=t;i<N;i+=2)r^=1,vis[i]=0;
		for(int i=t;i<N;i+=2)if(!vis[i]){
			for(int j=i;!vis[j];j=x[j])vis[j]=1;
			r^=1;
		}
		if(r!=rs[!t])return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<3;i++)
		for(int j=0;j<N;j++)scanf("%d",a[i]+j);
	puts(solve()?"Yes":"No");
}

Measured memory_bytes: 10752