akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define fir first
#define sec second
#define mod 998244353
#define INF 0x3fffffff
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
#define N 105
char s[N][N];
int f[N][N];
signed main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%s",s[i]+2);
	s[1][1]='.'; for(int i=2;i<=n;i++) s[i][1]='#';
	for(int i=1;i<n;i++) s[i][m+2]='#'; s[n][m+2]='.';
	m+=2;
	// for(int i=1;i<=n;i++) printf("%s\n",s[i]+1);
	for(int i =1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) f[i][j]=INF;
	}
	f[1][1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i+1][j]=='.')
			{
				f[i+1][j]=min(f[i+1][j],f[i][j]);
			}
			if(s[i][j+1]=='.')
			{
				f[i][j+1]=min(f[i][j+1],f[i][j]);
			}
			if(s[i+1][j]=='#'&&j!=1&&j!=1)
			{
				if(f[i+1][j]>f[i][j]+1)
				{
					f[i+1][j]=f[i][j]+1;
					queue<pii> q;
					q.push(mp(i+1,j));
					while(!q.empty())
					{
						pii u=q.front(); q.pop();
						pii v=u; v.fir++;
						if(s[v.fir][v.sec]=='#'&&v.sec!=m)
						{
							if(f[i][j]+1<f[v.fir][v.sec])
							{
								f[v.fir][v.sec]=f[i][j]+1;
								q.push(v);
							}
						}
						v=u; v.sec++;
						if(s[v.fir][v.sec]=='#'&&v.sec!=m)
						{
							if(f[i][j]+1<f[v.fir][v.sec])
							{
								f[v.fir][v.sec]=f[i][j]+1;
								q.push(v);
							}
						}
					}
				}
			}
			if(s[i][j+1]=='#')
			{
				if(f[i][j+1]>f[i][j]+1)
				{
					f[i][j+1]=f[i][j]+1;
					queue<pii> q;
					q.push(mp(i,j+1));
					while(!q.empty())
					{
						pii u=q.front(); q.pop();
						pii v=u; v.fir++;
						if(s[v.fir][v.sec]=='#'&&v.sec!=m)
						{
							if(f[i][j]+1<f[v.fir][v.sec])
							{
								f[v.fir][v.sec]=f[i][j]+1;
								q.push(v);
							}
						}
						v=u; v.sec++;
						if(s[v.fir][v.sec]=='#'&&v.sec!=m)
						{
							if(f[i][j]+1<f[v.fir][v.sec])
							{
								f[v.fir][v.sec]=f[i][j]+1;
								q.push(v);
							}
						}
					}
				}
			}
		}
	}
	cout<<f[n][m]<<endl;
	return 0;
}




Measured memory_bytes: 256
N,A,B = map(int,input().split())
S = input()

win = 0  
abr = 0 
for c in S:
    if c == "a":
        if win<A+B:
            print("Yes") 
            win += 1
        else:
            print("No")
    elif c == "b":
        if win < A+B and abr < B: 
            print("Yes")
            win += 1
            abr += 1
        else:
            print("No")
    else:   
        print("No")


Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  
  auto fin=[](){
    cout<<-1<<endl;
    exit(0);
  };
  
  reverse(a.begin(),a.end());
  if(a[0]!=2) fin();
  
  Int c=2,d=2;
  for(Int i=0;i<n-1;i++){
    if(c*2<=a[i+1]) fin();
    
    c=(c+a[i+1]-1)/a[i+1]*a[i+1];
    d=(d+a[i]-1)/a[i+1]*a[i+1];
    
    if(c>d) fin();
  }
  
  d+=a.back()-1;
  cout<<c<<" "<<d<<endl;
  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll a, b;
  cin >> a >> b;

  if(a <= 8 && b <= 8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;

  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0, c - (a - b)) << endl;
}


Measured memory_bytes: 256
s = input()
s_list = []
for i in s:
    s_list.append(i)
for j in range(len(s_list)):
    if s_list[j] == "A":
        A_first = j
        break
s_list = s_list[::-1]
for k in range(len(s_list)):
    if s_list[k] == "Z":
        Z_last = k
        break

print(len(s_list) - (A_first) - (Z_last))


Measured memory_bytes: 6632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ll x; cin >> x;

	ll a_ans;
	ll b_ans;
	for (ll a = -120; a <= 120; a++) {

		for (ll b = -120; b < 120; b++) {

			ll tmp = a * a * a * a * a - b * b * b * b * b;

			if (tmp == x) {
				a_ans = a;
				b_ans = b;
				break;
			}

		}

	}
	
	cout << a_ans <<  " " << b_ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    int sum_a=0,sum_b=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            sum_a+=a[i];
        }else{
            sum_b+=a[i];
        }
    }
    cout << abs(sum_a-sum_b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main() {
  int count=0,i=0,j=0;
  string S,A="keyence";
  cin >> S;
  if(S.find(A)!=string::npos){
    cout << "YES" << endl;
    return 0;
  }
  if(S[i]==A[j]){
    while(S[i]==A[j]){
      i+=1;
      j+=1;
    }
  }

  for(; i<S.size(); i++){
    if(S.substr(i,S.size()-j+1)==A.substr(j,S.size()-j+1)){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
struct Card{
  char suit,value;
};

void bubble(struct Card A[], int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i;j--){
      if(A[j].value<A[j-1].value){
        Card t = A[j];
        A[j] = A[j-1];
        A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[],int N){
  for(int i=0;i<N;i++){
    int minj = i;
    for(int j=i;j<N;j++){
      if(A[j].value < A[minj].value)minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[],int N){
  for(int i=0;i<N;i++){
    if(i > 0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
  for(int i = 0;i < N;i++){
    if(C1[i].suit != C2[i].suit)return false;
  }
  return true;
}

int main(){
  Card C1[100],C2[100];
  int N;

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0;i<N;i++)C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3096
import math
import itertools

N = int(input())
L = []
cnt = 0

for i in range(N):
    xy = list(map(int, input().split()))
    L.append(xy)

for i in itertools.permutations(L,N):
    for j in range(len(i)-1):
        cnt += math.sqrt((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)

print(cnt / math.factorial(N))

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1000000007;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s,t;
  cin>>s>>t;
  int ans=INT_MAX,ans1=0;
  for(int i=0; i<s.size()-t.size()+1; i++){
        ans1=0;
    for(int j=i; j<i+t.size(); j++){
        if(s[j]!=t[j-i]){ans1++;}
    }
    ans=min(ans,ans1);
  }
  cout<<ans;
    return 0;
}

Measured memory_bytes: 3640
import std.stdio;
import std.string;
import std.conv;

char[string] ch;
string[char] code;

void main(){
	string s;
	setData();
	while ((s = chomp(readln)), s) {
		s = textToCode(s);
		s = codeToText(s);
		writeln(s);
	}
}

void setData(){
	code[' '] = "11010";
	code['.'] = "11011";
	code[','] = "11100";
	code['-'] = "11101";
	code['\''] = "11110";
	code['?'] = "11111";
	ch["101"] = ' '; 
	ch["000000"] = '\''; 
	ch["000011"] = ','; 
	ch["10010001"] = '-'; 
	ch["010001"] = '.'; 
	ch["000001"] = '?'; 
	ch["100101"] = 'A'; 
	ch["10011010"] = 'B'; 
	ch["0101"] = 'C'; 
	ch["0001"] = 'D'; 
	ch["110"] = 'E'; 
	ch["01001"] = 'F'; 
	ch["10011011"] = 'G'; 
	ch["010000"] = 'H'; 
	ch["0111"] = 'I'; 
	ch["10011000"] = 'J'; 
	ch["0110"] = 'K'; 
	ch["00100"] = 'L'; 
	ch["10011001"] = 'M'; 
	ch["10011110"] = 'N'; 
	ch["00101"] = 'O'; 
	ch["111"] = 'P'; 
	ch["10011111"] = 'Q'; 
	ch["1000"] = 'R'; 
	ch["00110"] = 'S'; 
	ch["00111"] = 'T'; 
	ch["10011100"] = 'U'; 
	ch["10011101"] = 'V'; 
	ch["000010"] = 'W'; 
	ch["10010010"] = 'X'; 
	ch["10010011"] = 'Y'; 
	ch["10010000"] = 'Z'; 
}

string textToCode(string s){
	string result;
	for (int i = 0; i < s.length; i++) {
		if (s[i] >= 'A' && s[i] <= 'Z') {
			result ~= format("%05b", s[i] - 'A');
		}else {
			result ~= code[s[i]];
		}
	}
	return result;
}

string codeToText(string s){
	string result;
	for (int i = 0; i < s.length; i++) {
		if (s[0..i+1] in ch) {
			result ~= ch[s[0..i+1]];
			s = s[i+1..$];
			i = 0;
		}
	}
	return result;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr LL kInf = 1e18;
vector<vector<int>> d;

void warshal_floyd() {
  int V = d.size();
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
      for (int j = 0; j < V; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  int H, W; cin >> H >> W;
  d.resize(10, vector<int>(10));
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> d[i][j];
    }
  }

  map<int, int> m;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int a; cin >> a;
      if (a >= 0) m[a]++;
    }
  }

  warshal_floyd();

  int total = 0;
  for (auto p : m) {
    int key = p.first;
    int cnt = p.second;
    total += d[key][1] * cnt;
  }
  cout << total << endl;
}


Measured memory_bytes: 256
import sys

#最大公約数
def gcd(x, y):
    s = x / y
    r = x % y
    if r == 0:
        return y
    else:
        return gcd(y, r)

#最小公倍数
def lcm(x, y):
    return x*y/gcd(x, y)

def main():
    #print ("a")
    for line in iter(sys.stdin.readline, ""):
        #print (line)
        #tmp = sys.stdin.readline().split(" ")
        #print ("b")
        tmp = line.split(" ")
    
        a = int(tmp[0])
        b = int(tmp[1])
        #print ("a="+str(a))
        #print ("b="+str(b))
        #b = sys.stdin.readline()
        #print ("d")
        if a > b:
            c = a
            d = b
        else:
            c = b
            d = a

        print (str(gcd(c, d)) + " " + str(int(lcm(c,d))))

        #tmp = sys.stdin.readline()
        #if len(tmp) == 1:
        #    break
        #else:
        #    tmp = tmp.split(" ")

    #print ("exit")
     
if __name__ == "__main__":
    main()

Measured memory_bytes: 6732
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <stdio.h>
#define rep(i,n) for (int i=0;i<n;i++)
using namespace std;
typedef long long ll;


int main(){
  int H,A;
  cin >> H >> A;
  if(H%A == 0)cout << H/A << endl;
  else cout << H/A + 1 << endl;
  
  return 0;
}


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

int main(void)
{
    int n,m;
    cin >> n >> m;
    
    int A[101][101] = {0};
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cin >> A[i][j];
        }
    }
    
    int b[101] = {0};
    for(int i = 0 ; i < m ; i++)
    {
        cin >> b[i];
    }
    
    int c[101] = {0};
    for(int i = 0 ; i < n ; i++)
    {
        
        for(int j = 0 ; j < m ; j++)
        {
            c[i] += A[i][j] * b[j];
        }
        cout << c[i];
        cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define endl "\n"
#define BRISK ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

signed main()
{
    BRISK;
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];

    vi dp(n,MAX);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        for(int j=1;j<=min(k,i);j++){
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
    }
    cout<<dp[n-1];   
}

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

int gcd(int a, int b){
	if(b == 0){
		return a;
	}
	else{
		return gcd(b, a % b);
	}
}

int lcm(int a, int b){
	return (a / gcd(a, b)) * b;
}

signed main(){
	int N, M, i;
	scanf("%lld%lld", &N, &M);
	vector<int> a(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &a[i]);
		a[i] /= 2;
	}
	int L = 1;
	for(i = 0; i < N; i++){
		L = lcm(L, a[i]);
		if(L > M){
			printf("0\n");
			return 0;
		}
	}
	for(i = 0; i < N; i++){
		if((L / a[i]) % 2 == 0){
			printf("0\n");
			return 0;
		}
	}
	printf("%lld\n", (M + L) / (2 * L));
	return 0;
}

Measured memory_bytes: 1024
K = int(input())

first_mod = 7 % K
"""
cnt = 1
if first_mod == 0:
    print(1)
else:
    flg = True
    for i in range(2,K):
        seven = old * 10 + 7
        mod = seven % K
        cnt += 1
        old = seven
        if mod == 0:
            break
        if mod == first_mod:
            flg = False
            break
    if flg:
        print(cnt)
    else:
        print(-1)
"""
old_mod = now_mod = first_mod

cnt = 1
if first_mod == 0:
    print(1)
else:
    flg = False
    for i in range(2,K+1):
        now_mod = ((old_mod * 10) + 7) % K
        cnt += 1
        old_mod = now_mod
        if now_mod == 0:
            flg = True
            break
        if now_mod == first_mod:
            break
    if flg:
        print(cnt)
    else:
        print(-1)

Measured memory_bytes: 9132
#include <cstdio>

using namespace std;

int main(){

  while(1){

  int n;

  bool t[203],h[203];

  scanf("%d",&n);
  if(n == 0) break;

  for(int i = 0;i <= n*2;i++){
    t[i] = false;
    h[i] = false;
  }

  for(int i = 1;i <= n;i++){
    int tmp;
    scanf("%d",&tmp);
    t[tmp] = true;
  }
  for(int i = 1;i <= n*2;i++){
    if(t[i] == false){
      h[i] = true;
    }
  }
  int tc = 0,hc = 0,pre = 0;
  bool ban = true;
  while(1){
    if(tc == n || hc == n) break;
    if(ban){
      for(int i = pre+1;i <= n*2;i++){
	if(t[i] == true){
	  pre = i;
	  t[i] = false;
	  tc++;
	  goto out;
	}
      }
      pre = 0;
    out:
      ;
      ban = !ban;
    }else{
      for(int i = pre+1;i <= n*2;i++){
	if(h[i] == true){
	  pre = i;
	  h[i] = false;
	  hc++;
	  goto hev;
	}
      }
      pre = 0;
    hev:
      ;
      ban = !ban;
    }
  }
  int a=0,b=0;
  if(tc == n){
    a = n - hc;
  }else{
    b = n - tc;
  }

  printf("%d\n%d\n",a,b);

  }

  return 0;

}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> row(H);
  
  for(int i=0; i<H; i++){
    cin >> row.at(i);
  }
  
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  
  cout << endl;
  
  for(int i=0; i<H; i++){
    cout << '#';
    for(int j=0; j<W; j++){
      cout << row.at(i).at(j);
    }
    cout << '#' << endl;
  }
  
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  
  cout << endl;
  
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int n;
	cin >> n;

	vector<string> v;
	rep(i, n){
		string s;
		cin >> s;
		v.push_back(s);
	}

	sort(all(v));

	int ans = 1;
	string s = v[0];

	REP(i, 1, n){
		string x = v[i];
		if(x == s) continue;
		else{
			s = x;
			ans++;
		}
	}

	cout << ans;

	return 0;
}

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


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 1005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int dp[ARRAY_MAX][ARRAY_MAX];


int main() {

	string s, t;
	cin >> s >> t;

	int s_siz = s.size();
	int t_siz = t.size();

	memset(dp, INF, sizeof(dp));

	for (int i = 0; i < ARRAY_MAX; i++)
	{
		dp[i][0] = dp[0][i] = i;
	}

	for (int i = 1; i <= s_siz; i++)
	{
		for (int j = 1; j <= t_siz; j++)
		{
			dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
			dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
			dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (s[i - 1] != t[j - 1]));
		}
	}
	cout << dp[s_siz][t_siz] << endl;


	return 0;
}


Measured memory_bytes: 7156
#include<bits/stdc++.h>
#define pb push_back
#define N 1000003
#define SZ(a) (int)(a.size())
#define sorta(a) sort(a.begin(),a.end()) 
#define sortrev(a) sort(a.rbegin(),a.rend())
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define VI vector<int>
typedef long long LL;
using namespace std;
LL powmod(LL a, LL p, LL mod)
{
	LL ret = 1;while(p){if(p&1)ret = (ret*a)%mod;a=(a*a)%mod;p/=2;}return ret;
}
int pow(int a, int p)
{
	int ret = 1;while(p){if(p&1)ret = (ret*a);a=(a*a);p/=2;}return ret;
}
int n,x,t,y,a,b,i,j,k,p1[N],p2[N];
int main()
{
	cin.sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	set<int> s;
	while(t--)
	{
		cin>>a;
		if(s.find(a)==s.end())
			s.insert(a);
		else
			s.erase(a);
	}
	cout<<s.size()<<endl;
	 return 0;
}



Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int x[10000], y[10000][10000], a, b, cnt2;

void uruu(int s) {
	for (int i = 0; i < s; i++) {
		if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
			x[i] = 1;
		}
	}
}

void hantei(int start, int end) {
	int cnt = 0;
	for (int i = start; i <= end; i++) {
		if (x[i]) { cout << i << endl; cnt++; }
	}
	if (!cnt) { cout << "NA" << endl; }
}

int main() {
	uruu(10000);
	while (true) {
		cin >> a >> b; if (!a) { break; }
		if (cnt2) { cout << endl; }
		cnt2++;
		hantei(a, b);
	}
}

Measured memory_bytes: 1204
import sys 
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7    
N, K = map(int, readline().split())
d = [0] * (K+1)
for i in range(K,0,-1):
    t = K // i
    cnt = pow(t,N,MOD)
    for j in range(2,t+1):
        cnt -= d[i*j]
        cnt %= MOD
    d[i] = cnt
ans = 0
for num,cnt in enumerate(d):
    ans += num * cnt
    ans %= MOD
print(ans) 

Measured memory_bytes: 29048
#include<bits/stdc++.h>
using namespace std;
int n,a[200010],b[200010],cnt[200010],L,R,l,r;
inline int read()
{
	int x=0,w=0;char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return w?-x:x;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)cnt[a[i]=read()]++;
	for(int i=1;i<=n;i++)cnt[b[n-i+1]=read()]++;
	for(int i=1;i<=n;i++)
	if(cnt[i]>n){cout<<"No";return 0;}
	cout<<"Yes\n";
	L=n;R=1;l=1;r=n;
	for(int i=1;i<=n;i++)
	if(a[i]==b[i]){
		L=min(L,i);
		R=max(R,i);
	}
	for(int i=L;i<=R;i++){
		if(b[i]!=a[l]&&b[i]!=b[l]){
			swap(b[i],b[l]);
			l++;
		}else{
			swap(b[i],b[r]);
			r--;
		}
	}
	/*for(int i=L;i<=R;i++)
	if(l<L&&b[l]!=b[i])swap(b[i],b[l++]);
	else swap(b[i],b[r--]);*/
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]);
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[222] ;

int main() {
  int n, sum = 0 ;
  scanf("%d", &n) ;

  for(int i = 0 ;i<n ; i++){
    scanf("%d", &a[i]);
    sum+=a[i] ;
  }

  if(sum % 10 != 0) {
    cout <<sum << endl ;
    return 0 ;
  }

  sort(a, a+n);
  for(int i = 0 ;i<n ; i++){
    if(a[i] % 10 != 0) {
      cout << sum - a[i] << endl ;
      return 0 ;
    }
  }
  cout << 0 << endl ;
  return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int m; cin >> m;
    loop (m, _m) {
        unordered_set<string> S;
        string s; cin >> s;
        int l = s.size();
        for (int i = 1; i < l; i++) {
            string a = s.substr(0, i), b = s.substr(i);
            string ra = a, rb = b;
            reverse(all(ra));
            reverse(all(rb));
            S.insert({
                    b + a,
                    ra + b,
                    b + ra,
                    a + rb,
                    rb + a,
                    ra + rb
                    });
        }
        cout << S.size() << endl;
    }
    return 0;
}

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

int main() {
    int h,w;
    cin >> h >> w;
    string board[h];
    for(int i=0;i<h;i++){
        cin >> board[i];
    }

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

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(board[i][j]=='#'){
                continue;
            }
            int num=0;
            for(int k=0;k<8;k++){
                const int ni=i+dy[k];
                const int nj=j+dx[k];
                if(ni<0||ni>=h) continue;
                if(nj<0||nj>=w) continue;
                if(board[ni][nj]=='#') num++;
            }
            board[i][j]=char(num+'0');
        }
    }
    for(int i=0;i<h;i++){
        cout << board[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N;
    cin >> N;
    if (N==1) {
        cout << "Hello World\n";
    } else {
        ll A, B;
        cin >> A >> B;
        cout << A+B << "\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
int n,m,ans=-1;
int a[2005][2005],a1[2005][2005],a2[2005][2005],a3[2005][2005],a4[2005][2005];
 
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			char temp;
			cin>>temp;
			
			if (temp=='#')  a[i][j]=0;
			else a[i][j]=1;
		}
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			if (!a[i][j])  a1[i][j]=0;
			else a1[i][j]=a1[i][j-1]+1;
		}
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=m;j>=1;j--)
		{
			if (!a[i][j])  a2[i][j]=0;
			else a2[i][j]=a2[i][j+1]+1;
		}
	}
	for (int j=1;j<=m;j++)
	{
		for (int i=1;i<=n;i++)
		{
			if (!a[i][j])  a3[i][j]=0;
			else a3[i][j]=a3[i-1][j]+1;
		}
	}
	for (int j=1;j<=m;j++)
	{
		for (int i=n;i>=1;i--)
		{
			if (!a[i][j])  a4[i][j]=0;
			else a4[i][j]=a4[i+1][j]+1;
		}
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)  ans=max(ans,a1[i][j]+a2[i][j]+a3[i][j]+a4[i][j]-3);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 157184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X1, X2;	// X:整数
  int fx, fx_num;	// fx:各桁の数字
  int n = 100000000;	// n:桁数
  
  fx_num = 0;
  cin >> X1;	// Xの入力
  X2 = X1;
  for(int i=0 ; i<9 ; i++)
  {
    fx = X1 / n;		// 桁数
    X1 -= n * fx;
 	fx_num += fx;	// 桁数の合計
    n /= 10;		// nの桁数を下げる
  }
  
  if(X2 % fx_num == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

ll beki(ll a, ll b){
    a %= MOD;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % MOD;
    if(b % 2 == 1){
        ans = ans * a % MOD;
    }
    return ans;
}

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  ll ans = (beki(10, n) - beki(9, n) - beki(9, n) + beki(8, n)) % MOD;
  cout << (ans + MOD) % MOD << endl;
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}


int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n),f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());
  ll l = -1, r = 1e12;
  while(l+1<r){
    ll c = (l+r)/2;
    bool ok = [&]{
      ll s = 0;
      rep(i,n){
        s+= max(0ll, a[i]-c/f[i]);
      }
      return s <= k;
    }();
    if (ok) r = c;
    else l = c;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 1792
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n, m;
    cin >> n >> m;

    int total = 0;
    rep(i, m){
        int a;
        cin >> a;
        total += a;
    }

    cout << max(-1, n - total) << endl;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
//#include <chrono>
//#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int a[N];

int main() {
	//mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
	int n = 3;
	for(int i=1;i<=n;i++){
        cin>>a[i];
	}
	sort(a + 1 , a + n + 1);
	if(a[1] == a[2] && a[2] == a[3]){
        cout<<"Yes"<<endl;
	}
	else{
        cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef pair<int, int> pii;

struct P {
    int cost;
    uint16_t bit;
};

char colorchar[] = {'R', 'G', 'B'};
char G[1<<16];

int main() {
    int N;
    cin >> N;
    vector<pii> stamp(N);
    REP(i, N) {
        cin >> stamp[i].second >> stamp[i].first;
    }
    vvc field(4, vc(4));
    REP(y, 4) REP(x, 4) {
        cin >> field[y][x];
    }

    fill_n((char *)G, 1<<16, -1);
    uint16_t goal = (1<<16)-1;

    queue<uint16_t> que;
    G[0] = 0;
    que.push(0);
    while (!que.empty()) {
        uint16_t p = que.front(); que.pop();
        if (p == goal) {
            printf("%d\n", G[p]);
            break;
        }
        REP(i, N) {
            FOR(ly, -stamp[i].second+1, 4) FOR(lx, -stamp[i].first+1, 4) {
                int rx = lx + stamp[i].first, ry = ly + stamp[i].second;
                uint16_t bit[3] = {p, p, p};
                FOR(sy, ly, ry) FOR(sx, lx, rx) {
                    if (0 <= sx && sx < 4 && 0 <= sy && sy < 4) {
                        REP(j, 3) {
                            int k = 4*sy+sx;
                            if (field[sy][sx] == colorchar[j]) {
                                bit[j] |= 1<<k;
                            } else {
                                bit[j] &= ~(1<<k);
                            }
                        }
                    }
                }
                REP(j, 3) {
                    if (G[bit[j]] == -1) {
                        G[bit[j]] = G[p]+1;
                        que.push(bit[j]);
                    }
                }
            }
        }
    }
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(48)

using namespace std;

typedef pair<int, int> P;

class FEngines {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<double> x(N), y(N);
        REP(i, N) cin >> x[i] >> y[i];

        vector<pair<double, int>> rad;
        REP(i, N) {
            rad.emplace_back(atan2(x[i], y[i]), i);
            rad.emplace_back(atan2(x[i], y[i]) + 2 * M_PI, i);
        }
        sort(rad.begin(), rad.end());

        double res = 0;
        REP(l, N) {
            FOR(r, l, 2 * N - 1) {
                if (r >= l + N) continue;
                double px = 0;
                double py = 0;
                FOR(i, l, r) {
                    auto kv = rad[i];
                    px += x[kv.second];
                    py += y[kv.second];
                }
                res = max(sqrt(px * px + py * py), res);
            }
        }
        fcout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    FEngines solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d1(n);
  vector<int> d2(n);
  for(int i=0; i<n; i++) {
    cin >> d1[i] >> d2[i];
  }
  for(int i=0; i<n-2; i++) {
    if(d1[i] == d2[i] && d1[i+1] == d2[i+1] && d1[i+2] == d2[i+2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3632
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint;
// }}}

void main() {
  int n = readln.chomp.to!int;
  writeln(24 + (24 - n));
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  int a, b;
  
  scanf("%d %d",&a,&b);
  
  if( a + b < 10 ){
    printf("%d\n",a + b);
  }
  else{
    printf("error\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, _) = get!(usize, usize);
    let mut fs = [false, false, false, false, false, false, false, false, false, false];
    for i in get!(String).split_whitespace() {
        fs[i.parse::<usize>().unwrap()] = true;
    }
    let check = |n: usize| {
        let mut x = n;
        while x != 0 {
            if fs[x%10] {
                return false;
            }
            x /= 10;
        }
        true
    };
    let mut x = n;
    while !check(x) {
        x += 1;
    }
    println!("{}", x);
}

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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int a;
        cin >> a;
        cout << a + a * a + a * a * a << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
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;}
/*
ll dp[2][2019];
int main(){
  string S; cin >> S;
  ll ans = 0;
  rep(i,sz(S)){
    rep(j,2019){
      dp[(i+1)%2][(j*10+(int)(S[i]-'0'))%2019] = dp[i%2][j];
    }
    dp[(i+1)%2][S[i]-'0']++;
    ans += dp[(i+1)%2][0];
  }
  cout << ans << endl;
  return 0;
}
*/

ll mpow(ll a, ll x){
  ll res = 1;
  while(x > 0){
    if(x & 1) res = (res * a) % 2019;
    a = (a * a) % 2019;
    x >>= 1;
  }
  return res;
}

int main(){
  string S; cin >> S;
  int N = sz(S);
  map<int,int> mods;
  reverse(all(S));
  int now = 0;
  mods[now]++;
  rep(i,N){
    now = now+ (int)(S[i]-'0')*mpow(10,i);
    now %= 2019;
    //cout << now << endl;
    mods[now]++;
  }
  ll ans = 0;
  for(auto m:mods){
    ll cnt = m.second;
    ans += cnt*(cnt-1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  std::string s;
  std::cin >> s;


  int a = 0, z = 0;
  bool flag = false;
  rep(i,s.size()) {
    if(s[i] == 'A' && flag == false) {
      a = i;
      flag = true;
    }
    if(s[i] == 'Z')
      z = i;
  }



  std::cout << (z - a + 1 > 0 ? z - a + 1 : 0) << '\n';
  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>



typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll W = 1000000007;


using namespace std;
void omajinai() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}


class Main{
public:
    long N;
    ll A,B,C,D;
    Main(){
        cin>>N>>A>>B>>C>>D;
    }
    
    void run(){
        for(int i = 0; i<N;i++){
                const ll lower = A + i * C - (N-i -1 )  * D;
                const ll upper = A + i * D - (N-i-1)  * C;
                if(lower<= B && B<=upper){
                    cout<<"YES"<<endl;
                    return;
                }
            
        }
        cout<<"NO"<<endl;
        return;
    }
};

int main(){
    omajinai();
    Main().run();
}

Measured memory_bytes: 256
K, N = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
b = list()
for i in range(N-1):
    x = a[i+1] - a[i]
    b.append(x)
b.append(K-a[-1]+a[0])
print(K-max(b))


Measured memory_bytes: 26436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int K,n;
string s;
ll mypow(int x,int t){
	ll ans=1,res=x;
	while(t){
		if(t&1)ans=ans*res%MOD;
		res=res*res%MOD,t>>=1;
	}
	return ans;
}
ll a[4000004],inv[4000004];
void init(){
	a[0]=1,inv[1]=1;
	for(int i=1;i<=4e6;i++)
		a[i]=a[i-1]*i%MOD;
	for(int i=2;i<=4e6;i++)
		inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
	inv[0]=1;
	for(int i=1;i<=4e6;i++)inv[i]=inv[i-1]*inv[i]%MOD;
}
ll C(int A,int B){
	return a[A+B]*inv[A]%MOD*inv[B]%MOD;
}
int main(){
	init();
	cin>>K>>s,n=s.size();
	ll ans=0;
	for(int i=0;i<=K;i++){
		ans+=C(n-1,i)*mypow(25,i)%MOD*mypow(26,K-i)%MOD;
		ans%=MOD;
	}
	cout<<ans;
}

Measured memory_bytes: 67776
def include3(n):
	cond = 0
	while True:
		if n%10==3:
			cond = 1
			return cond
		elif n>9:
			n //= 10
		else:
			return cond

n = int(input())
for i in range(1,n+1):
	if i%3==0 or include3(i)==1:
		print(' ',end='')
		print(i,end='')
print()


Measured memory_bytes: 6248
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int m;
	string s;

	cin >> m;
	rep(i, m) {
		cin >> s;
		set<string> all;
		all.insert(s);
		for (int j = 1; j < s.size(); j++) {
			string L;
			L = s.substr(0,j);
			string R;
			R = s.substr(j);
			string L2=L, R2=R;
			reverse(L2.begin(),L2.end());
			reverse(R2.begin(),R2.end());
			all.insert(R+L);
			all.insert(R2+L);
			all.insert(L+R2);
			all.insert(L2 + R);
			all.insert(R+L2);
			all.insert(R2+L2);
			all.insert(L2+R2);
		}
		cout << all.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3216
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    D, N = [int(_) for _ in input().split()]

    if D == 0:
        if N != 100:
            print(N)
        else:
            print(101)

    elif D == 1:
        if N != 100:
            print(100 * N)
        else:
            print(10100)

    else:
        if N != 100:
            print(10000 * N)
        else:
            print(1010000)

main()


Measured memory_bytes: 4668
N, K = [int(x) for x in input().split()]
ans = 0
for i in range(1, N+1):
    cnt = 1
    if (i >= K):
        ans += (1/N)
        continue
    tmp = i
    while(True):
        tmp *= 2
        if (tmp >= K):
            break
        cnt += 1
    ans += (1/N * (1/2 ** cnt))
print(ans)


Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c;
  in2(a, b);
  if(a <= 0 && b >= 0){
    out("Zero");
    memi;
    return 0;
  }
  if(a < 0 && b < 0){
    if((b - a) % 2 == 0){
      out("Negative");
      memi;
      return 0;
    }
  }
  out("Positive");
  memi;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;

int a[2005];
int d[2][2005];

int main() {

	int n,z,w;
	cin >> n>>z>>w;
	
	FORI(0,n){
		cin>>a[i];
	}
	int ans=0;
	if(n==1)
		ans=abs(a[0]-w);
	if(n>=2)
		ans = max(abs(a[n-1]-w),abs(a[n-2]-a[n-1]));
	cout << ans << endl;
	return 0;
}




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

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int maxn = 1000;
int N, F[maxn] = {}, P[maxn][21];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N;
	REP(i, N) {
		REP(j, 10) {
			int x;
			cin >> x;
			F[i] = 2 * F[i] + x;
		}
	}
	REP(i, N) REP(j, 11) cin >> P[i][j];

	int ret = 1 << 31;
	for (int i = 1; i < (1 << 10); i++) {
		int cur = 0;
		REP(j, N) {
			cur += P[j][__builtin_popcount(F[j] & i)];
		}
		ret = max(ret, cur);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256