akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


k = I()
dq = deque([i for i in range(1, 10)])
for i in range(k):
    x = dq.popleft()
    k = x % 10
    if k:
        dq += [x * 10 + k - 1]
    dq += [x * 10 + k]
    if k != 9:
        dq += [x * 10 + k + 1]


print(x)


Measured memory_bytes: 47708
#include<iostream>
#include<vector>
#include<string>

using ll = long long;
int n, m, q;
std::vector<int> a, b, c, d;
ll maxScore = 0;

void dfs(std::vector<ll> &A, int depth = 1){
    if(depth == n){
        ll score = 0;
        for(int i = 0; i < q; i++){
            if(A[b[i]] - A[a[i]] == c[i]){
                score += d[i];
            }
        }
        maxScore = std::max(score, maxScore);
        return;
    }

    for(int i = A[depth - 1]; i <= m; i++){
        A[depth] = i;
        dfs(A, depth + 1);
    }
}

int main(){
    std::cin >> n >> m >> q;
    a = std::vector<int>(q);
    b = std::vector<int>(q);
    c = std::vector<int>(q);
    d = std::vector<int>(q);
    for(int i = 0; i < q; i++){
        std::cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    std::vector<ll> A(n);
    for(int i = 1; i <= m; i++){
        A[0] = i;
        dfs(A);
    }

    std::cout << maxScore << std::endl;
    return 0;
}


Measured memory_bytes: 3632
use std::io::Read;

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let a = it.next().unwrap().parse::<i32>().unwrap();
    let b = it.next().unwrap().parse::<i32>().unwrap();
    let c = it.next().unwrap().parse::<i32>().unwrap();
    println!("{}", b + std::cmp::min(a+b+1, c));
}

Measured memory_bytes: 4352
import sys
L, R = map(int, input().split())
ans = []

def calc_mod(x, y):
    return x * y % 2019

left = L % 2019
right = R % 2019

if R-L > 2019:
    print(0)
    sys.exit(0)

elif left > right:
    print(0)
    sys.exit(0)

elif left==0 or right==0:
    print(0)
    sys.exit(0)

for i in range(left, right):
    for j in range(i+1, right+1):
        ans.append(calc_mod(i, j))

print(min(ans))

Measured memory_bytes: 75412
N,M = list(map(int, input().split()))

L = [0 for i in range(N)]

for i in range(M):
	a, b = list(map(int, input().split()))
	if a == 1:
		L[b - 1] += 1
	elif b == 1:
		L[a - 1] += 1
	elif a == N:
		L[b - 1] += 1
	elif b == N:
		L[a - 1] += 1
	else:
		pass

if L.count(2) >= 1:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Measured memory_bytes: 4760
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repf(i,a,n) for(int i = (int)(a); i < (int)(n); i++)

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main(){
    int n,p,t;
    cin >>n;
    rep(i,n){
        if((i*i+i)/2 >=n){
            t = i;
            break;
        }
    }
    int m= (t* t +t)/2 - n;
    rep(i,t){
        if(m != i+1){
            cout << i+1<< endl;
        }

    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  string s,t; cin>>s>>t;
  vector<string> ans;
  for(int i=0;i+t.size()-1<s.size();i++){
    bool f=1;
    // cout<<"i "<<i<<endl;
    for(int j=i;j<i+t.size();j++){
      if(s[j]!='?'&&(s[j]!=t[j-i])){
        f=0;
        break;
      }
    }
    if(f){
      // cout<<"f ture"<<endl;
      string A;
      rep(k,s.size()){
        if(i<=k&&k<i+t.size()){
          A.pb(t[k-i]);
        }else if(s[k]=='?'){
          A.pb('a');
        }else{
          A.pb(s[k]);
        }
      }
      // cout<<"A "<<endl;
      ans.pb(A);
    }
  }
  if(ans.size()==0)
  cout<<"UNRESTORABLE"<<endl;
  else{
    sort(ALL(ans));
    cout<<ans[0]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,max;
    cin >> a >> b;
    
    max = a+b;
    
    if(a+b >= max){
        max = a+b;
    }
    if(a-b >= max){
        max = a-b;
    }
    if(a*b >= max){
        max = a*b;
    }
    cout << max;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    map<int, vector<pair<int,int>>> data;
    vector<int> ranking(M);
    rep(i, M)
    {
        cin >> P[i] >> Y[i];
        P[i]--;
        data[P[i]].pb(mp(Y[i],i));
    }
    rep(i, N)
    {
        if (data.count(i))
        {
            sort(data[i].begin(), data[i].end());
            rep(j,data[i].size()){
                ranking[data[i][j].second]=j;
            }
        }
    }
    
    rep(i, M)
    {
        cout << setfill('0') << std::right << std::setw(6) << P[i] + 1;
        cout << setfill('0') << std::right << std::setw(6) << ranking[i] + 1<< endl;
    }
   // system("pause");
    return 0;
}

Measured memory_bytes: 13568
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    s=input()
    print("ARC") if s=="ABC" else print("ABC")





if __name__ == "__main__":

    main()

Measured memory_bytes: 68172
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

class DAtCoderExpress2 {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, m, q; in >> n >> m >> q;
		vector<vector<int>> arr(n+1);
		f(i, m){
			int l,r ; in >> l >> r;
			arr[l].emplace_back(r);
		}
		rep(i, 1, n) sort(arr[i].begin(), arr[i].end());
		while(q--){
			int l, r; in >> l >> r;
			int res = 0;
			rep(i, l, r){
				res += (upper_bound(arr[i].begin(), arr[i].end(), r) - arr[i].begin());
			}
			out << res << '\n';
		}
	}
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	DAtCoderExpress2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 2e6+7;

ll fact[mxn];
int k, n;
string s;

inline ll f(ll x){ return fact[x]; }

ll pw(ll x, ll y){
	ll res = 1;
	while (y){
		if (y&1) res = (res*x)%INF;
		y >>= 1;
		x = (x*x)%INF;
	}
	return res;
}

inline ll C(ll N, ll R){
	return ((f(N) * pw(f(N-R),INF-2) % INF) * pw(f(R), INF-2)) % INF;
}

int main(){
	setIO();
	function<void()>generateFactorial = [](){
		fact[0] = 1;
		for (int i = 1; i < mxn; i++)
			fact[i] = (fact[i-1]*i)%INF;
	};
	generateFactorial();
	cin >> k >> s;
	n = (int)s.size()+k;
	ll t = pw(26, n);
	for (int i = 0; i < (int)s.size(); i++){
		t -= (C(n, i)*pw(25, n-i))%INF;
		t += INF;
		t %= INF;
	}
	cout << (t+INF)%INF << endl;
}

Measured memory_bytes: 19892
#include<iostream>
    #include<cstdio>
    const int N=1e5+5;
    int vis[N]={},n;
    char s[20];
    void dfs(int l,int r) {
        int mid=(l+r)>>1;
        printf("%d\n",mid);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V') return;
        else if(s[0]=='F') vis[mid]=1;
        else vis[mid]=0;
        int v=(mid-l)&1;
        if(vis[mid]!=vis[l]^v) dfs(l,mid);
        else dfs(mid,r);
    }
    int main() {
        scanf("%d",&n);
        printf("%d\n",0);fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V') return 0;
        else if(s[0]=='F') vis[0]=1;
        else vis[0]=0;
        printf("%d\n",n-1);fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V') return 0;
        else if(s[0]=='F') vis[n-1]=1;
        else vis[n-1]=0;
        dfs(0,n-1);
        return 0;
    }

Measured memory_bytes: 852
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
double n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	printf("%.6lf",(n/3.0)*(n/3.0)*(n/3.0));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n, k;
    while (cin >> n >> k, n) {
        vector<string> a(n);
        rep(i, n) cin >> a[i];

        set<string> st;
        rep(s, 1 << n) {
            if (__builtin_popcount(s) != k) continue;

            vector<int> b;
            rep(i, n) {
                if ((s >> i) & 1) {
                    b.emplace_back(i);
                }
            }

            do {
                string t = "";
                rep(i, b.size()) {
                    t += a[b[i]];
                }
                if (st.count(t) == 0) {
                    st.insert(t);
                }
            } while (next_permutation(all(b)));
        }

        cout << st.size() << endl;

    }
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	char march[] = {'M', 'A', 'R', 'C', 'H'};
	int n;
	cin >> n;
	vector<long long> v(5);
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for(int j = 0; j < 5; j++) {
			if(s[0] == march[j]) {
				v[j]++;
				break;
			}
		}
	}
	long long ans = 0;
	for(int i = 0; i < 5; i++) {
		for(int j = i + 1; j < 5; j++) {
			for(int k = j + 1; k < 5; k++) {
				ans += v[i] * v[j] * v[k];
			}
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using boost::multiprecision::cpp_dec_float_100;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    string S, T;
    cin >> S >> T;

    int N = S.size();

    rep(i, N) if (S[i] != T[i]) { cout << "No" << endl; goto xyz; }
    cout << "Yes" << endl;
xyz:;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include<vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

  long K,ans,sum;
  int N,i,s,t;
  int A[200000];
  bool can;
  can=true;

  cin>>K>>N;

  for(i=i;i<N;i++){
    cin>>A[i];
  }
  ans=A[N-1]-A[0];
  for(i=0;i<N-1;i++){
    sum=K-(A[i+1]-A[i]);
    //if(sum>(K/2)){
    //  sum=K-sum;
    //}
    if(ans>sum)ans=sum;
  }
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	char s[101], o;
	while (cin >> s >> o)
	{
		if (o == 'X') break;
		int k = 0, u = 0;
		char t[100][101] = {""};
		t[k][u] = ('A' <= s[0] && s[0] <= 'Z') ? s[0]-'A'+'a' : s[0];
		++u;
		for (int i = 1; i < strlen(s); ++i)
		{
			if ('A' <= s[i] && s[i] <= 'Z')
			{
				t[k][u] = '\0';
				++k, u = 0;
				t[k][u] = s[i]-'A'+'a';
				++u;
			}
			else if (s[i] == '_')
			{
				t[k][u] = '\0';
				++k, u = 0;
			}
			else if (s[i] == '\0')
			{
				t[k][u] = '\0';
				break;
			}
			else
			{
				t[k][u] = s[i];
				++u;
			}
		}
		int m = k;
		k = 0;

		char r[201] = "";
		if (o == 'U' || o == 'L')
		{
			for (int i = 0; i <= m; ++i)
			{
				for (int j = 0; j < strlen(t[i]); ++j)
				{
					if (i == 0 && j == 0) r[k] = (o == 'U') ? 'A'+t[i][j]-'a' : t[i][j];
					else if (j == 0) r[k] = 'A'+t[i][j]-'a';
					else r[k] = t[i][j];
					++k;
				}
			}
			r[k] = '\0';
		}
		else
		{
			for (int i = 0; i <= m; ++i)
			{
				for (int j = 0; j < strlen(t[i]); ++j)
				{
					r[k] = t[i][j];
					++k;
				}
				r[k] = '_';
				++k;
			}
			r[k-1] = '\0';
		}

		cout << r << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
int gcd(int a,int b){
 	if(b==0) 
  		return a;
  	return gcd(b,a%b);
} 
bool setwise_coprime(int a[],int n){
  	int res=a[0];
  	for(int i=1;i<n;i++)
      	res=gcd(a[i],res);
  	if(res==1)
      return true;
  	else
      return false;
}
bool pairwise_coprime(int a[],int n){
  	map<int,int>mp;
  	for(int i=0;i<n;i++){
      int x=a[i];
      for(int j=2;j*j<=x;j++){
          if(x%j==0){
              mp[j]++;
              while(x%j==0)
                  x/=j;
          }
      }
      if(x!=1)
        mp[x]++;
  	}
      for(auto i:mp)
      {
        if(i.second>=2)
            return false;
      }
      return true;
}
int32_t main(){
      FIO;
      int n;cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
        cin>>a[i];
      if(pairwise_coprime(a,n))
        cout<<"pairwise coprime"<<"\n";
      else if(setwise_coprime(a,n))
        cout<<"setwise coprime"<<"\n";
      else
        cout<<"not coprime"<<"\n";
      return 0;
}

Measured memory_bytes: 16216
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    vector<int> x(4), y(4);
    cin >> x[0] >> y[0] >> x[1] >> y[1];

    int dx = x[1] - x[0];
    int dy = y[1] - y[0];
    for(int i=2; i<4; ++i){
        swap(dx, dy);
        dx *= -1;
        x[i] = x[i-1] + dx;
        y[i] = y[i-1] + dy;
    }
    cout << x[2] << ' ' << y[2] << ' '
         << x[3] << ' ' << y[3] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
using namespace __gnu_pbds;

// replace ll  with pair if multiset needed
typedef tree<pair<ll,ll>, null_type, greater<pair<ll,ll> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;

// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)

//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	ll x,k,d; cin >> x >> k >> d;
	
	if(abs(x) / d > k){
		cout << abs(x) - k * d;
	} else {
		if((k - abs(x) / d) % 2 == 0) cout << abs(x) % d;
		else cout << d - abs(x) % d;
	}
	
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string ans;
    int d;cin >> d;
    if(d == 25)ans = "Christmas";
    if(d == 24)ans = "Christmas Eve";
    if(d == 23)ans = "Christmas Eve Eve";
    if(d == 22)ans = "Christmas Eve Eve Eve";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


struct edge
{
	int to, cost;
	edge(int to, int cost) : to(to), cost(cost){}
};

const int INF = 1 << 29;


int main()
{
    int n, m;
	
	cin >> n >> m;
	
	vector<vint> G(n, vint(n, INF));
	rep(i, m)
	{
		int a, b, c, d;
		char k;
		
		cin >> a >> k >> b >> k >> c >> k >> d;
		
		G[a-1][b-1] = c;
		G[b-1][a-1] = d;
	}
	
	
	rep(k, n) rep(i, n) rep(j, n)
		chmin(G[i][j], G[i][k] + G[k][j]);
	
	int s, t, ta, gi;
	char k;
	cin >> s >> k >> t >> k >> ta >> k >> gi;
	
	cout << ta - gi - G[s-1][t-1] - G[t-1][s-1] << endl;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main()
{
    int n,a,flag=0;
    cin>>n>>a;

    if (n%500==0) {
        flag=0;
    }
    else if (a==0 && n%500!=0) {
        flag=1;
    }

    else {
        int h;
        h=n%500;
        if (h<=a) {
            flag=0;
        }
        else {
            flag=1;
        }
    }
    
    if (flag==0) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
using namespace std;

int n, d, m, t, i;
map <int, int> cnt;

int main()
{
    scanf("%d", &n);
    while (n--)
    {
        scanf("%d", &d);
        ++cnt[d];
    }
    scanf("%d", &m);
    while (m--)
    {
        scanf("%d", &t);
        if (cnt.count(t) == 0 || cnt[t] == 0)
        {
            printf("NO");
            return 0;
        }
        else --cnt[t];
    }
    printf("YES");
}

Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<queue>
using namespace std;
#define rep(i, n) for (int i=0; i<(int) (n);i++)
using ll = long long;
using P = pair<int,int>;

void solve_8(){//7m
    string a, b;
    cin >> a >> b;
    string tmp =  a+b;
    int c = atoi(tmp.c_str());
    //cout << c << endl;
    int c_square = sqrt(c);
    cout << (c_square * c_square == c? "Yes": "No") << endl;
    
}

void solve_8re(){
    string a, b;
    cin >> a >> b;
    //stoi -> int
    //stol -> long
    //stof -> float
    int c = stoi(a+b);
    int c_square = sqrt(c);
    cout << (c_square * c_square == c? "Yes": "No")<< endl;
}

void solve_9(){//12m
    int n,k;
    cin >> n >> k;
    int sum_distance = 0;
    rep(i, n){
        int x;
        cin >> x;
        sum_distance += 2 * min(x, k-x);
    }
    cout << sum_distance;
}

void solve_10(){//7m
    int n;
    cin >> n;
    priority_queue<int> pq;
    int a;
    rep(i, n){
        cin >> a;
        pq.push(a);
    }
    int alice = 0, bob = 0;
    int turn = 0;
    while(!pq.empty()){
        a = pq.top();
        pq.pop();
        if (turn % 2 == 0){
            alice += a;
        }
        else{
            bob += a;
        }
        turn += 1;
    }
    cout << alice - bob;
    
}
#include<algorithm>
void solve_10re(){
    int n;
    cin >> n;
    vector<int> a;
    int a_;
    rep(i, n){
        cin >> a_;
        a.push_back(a_);
    }
    sort(a.begin(), a.end(), greater<int>());
    int total = 0;
    rep(i, n){
        total += (i%2==0?a[i]:-a[i]);
    }
    cout << total;
}

void solve_D(){
    
}

void solve_E(){
    
}

void solve_F(){
    
}

int main(){
    //solve_8re();
    //solve_9();
    solve_10re();
    //solve_D();
    //solve_E();
    //solve_F();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	while(1){
		string s1;	
		cin>>s1;

		if(s1==".")
			break;

		string s2;
  		cin>>s2;	
		
		if(s1==s2){
			cout<<"IDENTICAL"<<endl;
			continue;
		}
		
		string t1=s1;
		string t2=s2;

		while(1){
			size_t d1b=t1.find('\"');
			if(d1b==string::npos)
				break;
			t1.replace(d1b,1,"@");

			size_t d1e=t1.find('\"');
			t1.replace(d1e,1,"@");

			size_t d2b=t2.find('\"');
			if(d2b==string::npos)
				break;
			t2.replace(d2b,1,"@");

			size_t d2e=t2.find('\"');
			t2.replace(d2e,1,"@");

			string u1=s1;
			u1.replace(d1b+1,d1e-d1b-1,"");
			string u2=s2;
			u2.replace(d2b+1,d2e-d2b-1,"");

			if(u1==u2){
				t1=u1;
				t2=u2;
				break;
			}
		}

		if(t1==t2){
			cout<<"CLOSE"<<endl;
		}
		else{
			cout<<"DIFFERENT"<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;
const ll inf = 1LL<<60;

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

int main(){
  int n; cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(i % 2 == 1){
      if(cnt(i) == 8) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> v;
    ll A,B;
    for(ll i = 0; i < N; i++){
        cin >> A >> B;
        v.push_back(pair<ll,ll>(A,B));
    } 
    sort(v.begin(), v.end());
    ll ans = 0;
    for(ll i = 0;;i++){
        if(M < v[i].second){
            ans += M*v[i].first;
            break;
        }
        ans += v[i].second*v[i].first;
        M -= v[i].second;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


vector<int> G[105];
int cnt = 1;
int d[105];
int f[105];
int check[105];

void dfs(int now) {

	
	d[now] = cnt;
	check[now] = 1;
	cnt++;

	for (auto itr : G[now]) {

		if (check[itr] == 1)continue;
		dfs(itr);
	}
	f[now] = cnt;
	cnt++;
}



int main() {

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int v, k;
		cin >> v >> k;
		v--;
		for (int j = 0; j < k; j++)
		{
			int c;
			cin >> c;
			c--;
			G[v].push_back(c);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (check[i] == 1)continue;
		dfs(i);
	}

	

	for (int i = 0; i < n; i++)
	{
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}


	return 0;
}



Measured memory_bytes: 3172
#include<stdio.h>

static const int N = 100;

int main(){
  int M[N][N];
  int n, i, j, u, k, v;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      M[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(j){
	printf(" ");
      }
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int digit(int b){
	int i=0,x;
	if(b==0) return 1;
	while(b!=0){
		x=b%10;
		b/=10;
		i++;
	}
	return i;
}
int main(){
	int n,m,s[6]={0},f=0,flag=0,c[6]={0},i,j,b=0,x;
	cin>>n>>m;
	for(i=0;i<m;i++){ 
		cin>>s[i]>>c[i];
		if(s[i]==1 && c[i]==0 && n!=1){
			f=1;
			break;
		}
		if(s[i]>n){
			f=1;
			break;
		}
		for(j=0;j<i;j++){
			if(s[i]==s[j] && c[i]!=c[j]){
				f=1;
				break;
			}
			else if(s[i]==s[j]){
				flag=1;
				break;
			}
		}
	if(flag==0){
		x=1;
		for(int k=1;k<=n-s[i];k++)
			x*=10;
		b+=c[i]*x;
	}
	else if(f==1){
		break;
	}
	else{
		flag=0;
	}
	}
	if(f==1){
		cout<<-1;
		return 0;
	}
	if(digit(b)<n){
		cout<<1;
		for(i=2;i<=n-digit(b);i++)
			cout<<0;
		cout<<b<<endl;
	}
	else{
		cout<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		while (true) {
			int e = sc.nextInt();
			if (e == 0) break;
			int m = 1 << 30;
			for (int z = 0;; ++z) {
				int yx = e - z * z * z;
				if (yx < 0) break;
				for (int y = 0; y * y <= yx; ++y) {
					int x = yx - y * y;
					m = Math.min(m, x + y + z);
				}
			}
			System.out.println(m);
		}
	}

}

Measured memory_bytes: 26256
#include<bits/stdc++.h> // 这是一个经过推导后的做法 
using namespace std;
int main(){ 
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	cout<<a-b+1<<endl;
	/* 
	int s1,s2,s3;
    cin>>s1>>s2>>s3;
    if(s3>s1+s2)
		cout<<s1+s2+1<<endl;
    else if(s2>s1+s3)
		cout<<s1+s3+1<<endl;
    else if(s1>s3+s2)
		cout<<s3+s2+1<<endl;
    else 
		cout<<(s1+s2+s3+3)/2<<endl;
	*/
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#define N 1000
#define MOD 1000000007
using namespace std;
char s[2][N];
int n;
long long ans;
int main(){
	scanf("%d",&n);
	scanf(" %s",s[0]+1);
	scanf(" %s",s[1]+1);
	int l=1;
	ans=1;
	while (l<=n){
		if (l<n&&s[0][l]==s[0][l+1]){
			if (l==1)ans=6;
			else
				if (s[0][l-1]!=s[1][l-1])(ans*=3)%=MOD;
				else
					(ans*=2)%=MOD;
			l+=2;
		}else{
			if (l==1)ans=3;
			else
				if (s[0][l-1]==s[1][l-1])(ans*=2)%=MOD;
			l++;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#define fastio ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;

int main()
{
	#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin); 
	freopen("output.txt", "w", stdout); 
	#endif	
	
	fastio;

	string num;
	cin >> num;
	ll total = 0;

	for(int i = 0; i < num.size(); i++)
	{
		char c = num[i];
		total += int(c) - 48;
	}
	if(total % 9 == 0)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

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

int main(){
    int count;
    unsigned long int d, g;
    scanf("%lu%lu", &d, &g);
    g = g/100;
    unsigned long int p[d+1], c[d+1], a[d+1], f[d+1];
    for(int i=1; i<=d; i++){
        scanf("%lu%lu", &p[i], &c[i]);
        c[i] = c[i]/100;
        a[i] = i*p[i] + c[i];
        count += p[i];
    }
    int x = pow(2, d) - 1;
    while(x >= 0){
        int y = x;
        unsigned long int buf = 0, sum = 0;
        x--;
        for(int i=1; i<=d; i++){
            if(y%2 == 1){
                sum += a[i];
                buf += p[i];
            }
            f[i] = y%2;
            y = y/2;
        }
        if(count > buf && g <= sum){
            count = buf;
            continue;
        }
        int id;
        for(int i=d; i>=1; i--){
            if(f[i] == 0){
                buf += (g-sum+i-1)/i;
                sum += i*(p[i]-1);
                break;
            }
        }
        if(count > buf && g <= sum){
            count = buf;
        }
    }
    printf("%lu", count);

    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n; cin >> n;
  cout << 0 << endl;
  flush(cout);
  string s; cin >> s;
  char fst=s.front();
  if(fst == 'V'){
    cout << 0 << endl;  
    return 0;
  }
  int l = 0, r = n;
  for(;;){
    int mid = (l+r)/2;
    cout << mid << endl;
    flush(cout);
    cin >> s;
    char c = s.front();   
    if(c == 'V'){
      cout << mid << endl;
      return 0;
    }
    if(((c == fst)) ^ (mid%2))l = mid;
    else r = mid;
  }
}


Measured memory_bytes: 3872
#include <iostream>

using namespace std;

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

int main() {

    int N;
    scanf("%d", &N);

    if (N % 2 == 0) {
        printf("%d\n", N);
    } else {
        printf("%d\n", N * 2);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  cin>>n;
  n%=10;
  if(n==3){
    cout<<"bon"<<'\n';
  }
  else if(n==0 || n==1 || n==6 || n==8){
    cout<<"pon"<<'\n';
  }
  else{
    cout<<"hon"<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

std::int64_t run()
{
	int N;
	std::cin >> N;
	std::vector<std::int64_t> fitness(N);
	for (auto& v : fitness)
	{
		std::cin >> v;
	}
	boost::sort(fitness, std::greater<>());
	auto ret = fitness[0];
	for (auto i : boost::irange(1, N / 2))
	{
		ret += 2 * fitness[i];
	}
	if (N % 2 == 1)
	{
		ret += fitness[N / 2];
	}
	return ret;
}

void Main()
{
	std::cout << run() << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 4776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;


int main(void) {
  int r, D, x2000;
  cin >> r >> D >> x2000;
  int x = x2000;
  for (int i = 0; i < 10; i++) {
    cout << (r * x - D) << endl;
    x = r * x - D;
  }
}


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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

const ll MAX = 10000100;

int main() {
    ll i, j, k;
    ll N;
    cin >> N;
    vll d(N + 1, 0);
    for(i = 1; i < N + 1; i++) {
        ll m = 1;
        while(1) {
            if(i * m > N)
                break;
            d[i * m]++;
            m++;
        }
    }
    ll ans = 0;
    for(i = 1; i < N + 1; i++) {
        ans += i * d[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 81340
def gcd(x, y):
    # ユークリッドの互除法で最大公約数を見つける
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


n = int(input())
a = list(map(int, input().split()))

# 最大公約数の1番小さい値を取る
# a[0]との最大公約数を全パターン取って、小さい方をansに入れる
ans = min(gcd(a[0], x) for x in a)

print(ans)


Measured memory_bytes: 14224
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

const int INF = 1 << 30;

void m_min(int& a, int b)
{
    if (a > b) a = b;
}

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        m_min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if (i > 1)
            m_min(dp[i], dp[i-2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1] << endl;

    return 0;
}



Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i64 = int64_t;
constexpr char newl = '\n';

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= a; i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

// INSERT ABOVE HERE
#if 1
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  /*
  D: Multiple of 2019
  (4 月 27 日: 誤りを訂正しました。)
  S の長さを n、S の左から k 番目の数字を ak とします。
  左から k + 1 文字目以降の数字列を整数とみなした時の値 an + 10an−1 + ... + 10n−k−1ak+1 を
  Tk とします (Tn = 0)。 すると、(i, j) が条件をみたすのは Ti−1 == Tj (mod2019) のときです。
  各 Timod2019 を計算し、mod の値が同じごとに個数を計算して足したものが答えです。Ti =
  Ti+1 + 10n−i−1ai より、これは DP で計算でき、mod ごとに m(m − 1)/2 (m は Timod2019 があ
  る値になる 0 ≤ i ≤ n の個数) を足せば良いです。
  */

  string S;
  cin >> S;

  auto len = S.size();

  // mod2019それぞれのカウント
  vector<int> rcs(2019);
  rcs[0]++;

  int l = 1, r = 0;
  RF0(i, len) {
    int n = S[i] - '0';
    n = (r + n * l) % 2019;
    rcs[n]++;
    r = n;  // 前回のあまりを記憶
    l = (l * 10) % 2019;  // 10倍していく(mod2019)
    //cout << n << ' ';
  }

  i64 result = 0;
  for (auto n : rcs) {
    result += n * (n - 1) / 2;
  }
  cout << result;
}
#endif

Measured memory_bytes: 3708
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 1000000000000)

	n := nextInt()
	as := make([]int, n)

	mod := int(1e9 + 7)

	for i := 0; i < n; i++ {
		as[i] = nextInt() % mod
	}

	asum := make([]int, n)
	asum[n-1] = as[n-1]
	for i := 1; i < n; i++ {
		asum[n-1-i] = (asum[n-i] + as[n-1-i]) % mod
	}

	ans := 0
	for i := 0; i < n-1; i++ {
		ans += as[i] * (asum[i+1]) % mod
		ans = ans % mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7460
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b;
	cin>>a>>b;
	set<ll> st;
	st.insert(1);
	st.insert(2); 
	st.insert(3);
	st.erase(a);
	st.erase(b);
	for(auto it:st){
		cout<<it;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int A,B,C;
	cin>>A>>B>>C;
	if(C>=A && C<=B)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
def resolve():
    def Dijkstra(s, g):
        from collections import deque
        d = {s}
        queue = deque()
        for q in edge[s]:
            queue.append((1, q))
        while queue:
            dist, point = queue.popleft()
            if point in d:
                continue
            d.add(point)
            if point == g:
                return dist
            for nextp in edge[point]:
                if not nextp in d:
                    if not -1 in point or -1 in nextp:
                        queue.appendleft((dist, nextp))
                    else:
                        queue.append((dist + 1, nextp))
        return -1
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    n, m = map(int, input().split())
    edge = defaultdict(set)
    for _ in range(m):
        p, q, c = map(int, input().split())
        p, q = p - 1, q - 1
        edge[(p, c)].add((q, c))
        edge[(q, c)].add((p, c))
        edge[(p, c)].add((p, -1))
        edge[(q, c)].add((q, -1))
        edge[(p, -1)].add((p, c))
        edge[(q, -1)].add((q, c))
    print(Dijkstra((0, -1), (n - 1, -1)))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 239096
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int A,B,C;
    cin >> A >> B >> C;
    auto c = (A==B) && (B==C) && (A==C);
    cout << (c ? "Yes" : "No") << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        q.push(x);
    }
    for(int i = 0; i < m; ++i) {
        int x = q.top();
        q.pop();
        q.push(x / 2);
    }
    LL ans = 0;
    while(!q.empty()) {
        ans += q.top();
        q.pop();
    }
    cout << ans;
}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3868
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#define LLONG_MAX     9223372036854775807i64

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

ll Pow(ll a, ll b) {
	ll x = 1;
	while (b > 0) {
		if (b & 1) x = x * a;
		a = a * a;
		b = b >> 1;
	}
	return x;
}

/*<ここから>***********************************************************/




int main()
{
	int N;
	cin >> N;
	string ans;
	if (N < 1000) {
		ans = "ABC";
	}
	else {
		 ans = "ABD";

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define pb push_back
#define sx 200007
map<int,int> m1,m,m3;
map<pair<int,int>,int> ma;
int main()
{
    int n;
    cin>>n;
    int ans=n%1000;
    if(ans==0)
        cout<<ans<<endl;
    else
        cout<<1000-ans<<endl;
    return 0;
}


Measured memory_bytes: 3596