akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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 (b<a) { a=b; return 1; } return 0; }

int dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    p += 3*a;
    cout << (int)p/2 << endl;

}

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

constexpr ll MAX_V = 1000*100+10;
ll dp[110][MAX_V];

int main(int argc, char **argv)
{
	ll N, W; cin >> N >> W;
	vector<ll> weight(N), value(N);
	for (ll i = 0; i < N; ++i) cin >> weight[i] >> value[i];

	for (ll i = 0; i <= N; ++i) for (ll v = 0; v < MAX_V; ++v) dp[i][v] = 1ll << 60;

	dp[0][0] = 0;
	for (ll i = 0; i < N; ++i)
	{
		for (ll v = 0; v < MAX_V; ++v)
		{
			dp[i+1][v] = min(dp[i+1][v], dp[i][v]);
			if (v-value[i]>=0)dp[i+1][v] = min(dp[i+1][v], dp[i][v-value[i]]+weight[i]);
		}
	}
	ll res{0};
	for (ll v = 0; v < MAX_V; ++v)
	{
		if (dp[N][v] <= W) res = v;
	}
	std::cout << res << std::endl;
}


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

int main(){

    int a,b,k;
    cin >> a >> b >> k;

    vector<int> ans;
    if(b - a + 1 <= k*2){
        for(int i=a; i < b+1; i++){
           cout << i << endl;
        }
    }else{
       for(int i=a;i < a+k;i++){
           ans.push_back(i);
       }
        for(int i=b-k+1;i <= b;i++){
           ans.push_back(i);
        }
        for(int i=0; i < ans.size(); i++){
           cout << ans[i] << endl;
        }
    }


}

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

int main(){
long double a,b,c;
cin>>a>>b>>c;
if(4*a*b<(c-b-a)*(c-b-a)&&c>a+b){
	cout<<"Yes";
}
else cout<<"No";
return 0;
}


Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def main():
    n,m = map(int,input().split())
    X = list(map(int,input().split()))

    X.sort()
    X_diff = []
    for i in range(m-1):
        X_diff.append(X[i+1]-X[i])
    X_diff.sort()
    if n ==1:
        print(sum(X_diff))
    else:
        print(sum(X_diff[0:-(n-1)]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 56744
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(void) {
	string s;
	cin >> s;
	int ans = 0;
	int n = s.length();
	for (int i = 0; i < n / 2; ++i) {
		if (s[i] != s[n -1- i]) {
			++ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] ST = Console.ReadLine().Split(" ");
            string S = ST[0];
            string T = ST[1];
            string ans = "";
            for(int i = 0; i < N; i++)
            {
                ans += S.Substring(i, 1) + T.Substring(i, 1);
            }
            Console.WriteLine(ans);
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 27024
import math

A,B,C,X,Y=map(int,input().split())
limit=max(2*X,2*Y)

ans=float('inf')
#L=[]
for i in range(limit+1):
    temp=C*i+A*math.ceil(max(0,X-i/2))+B*math.ceil(max(0,Y-i/2))
    #L.append(temp)
    ans=min(ans,temp)

print(ans)
#print(L)


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

#define pb            push_back
#define mp            make_pair
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<'\n'<<(#X)<<" = "<<(X)<<'\n'; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    string s;
    cin>>n>>s;
    if (n%2)
        cout<<"No";
    else
        cout<<(s.substr(0,n/2)==s.substr(n/2, n/2)?
                "Yes":"No")<<'\n';

}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a;
    char c[6];
    int i,tmp = 0;
    scanf("%s",c);
    
    
    for(i = 0;i<6;i++)
    {
if(c[i] == '1')
tmp++;
    }
    printf("%d",tmp);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
typedef vector<int> Vi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  int n;
  while( cin >> n, n ) {
    ll a, b, c;
    map<ll, ll> m;
    vector<ll> v;
    bool flag = false;
    Rep(i, n) {
      cin >> a >> b >> c;
      if( m.find( a ) == m.end() ) {
	v.pb( a );
	m[a] = 0;
      }
      m[a] += b * c;
    }
    
    Rep(i, v.size()) {
      if( m[v[i]] >= 1000000 ) {
	cout << v[i] << endl;
	flag = true;
      }
    }

    if( !flag ) cout << "NA" << endl;
  }
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  cout << (n%10 == 9 || n/10 == 9 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
    int a,b,c;
    do{
    scanf("%d",&a);
    }while(a<1 || a>9);
    do{
    scanf("%d",&b);
    }while(b<1 || b>9);
    do{
    scanf("%d",&c);
    }while(c<1 || c>9);
    if(a==b){
        if(b==c){
            printf("No");
        }
        else{
            printf("Yes");
        }
    }
    else{
        if(b==c){
            printf("Yes");
        }
        else{
          if(a==c)
            printf("Yes");
          else
            printf("No");
        }
    }
    return 0;
 
}

Measured memory_bytes: 128
N,A,B,C=map(int,input().split())
L=[int(input()) for i in range(N)]
INF=10**8
def dfs(n,a,b,c):
  #n:n番目の竹までをみる
  #a:Aに使う竹の合計
  #b:Bに使う竹の合計
  #c:Cに使う竹の合計
  if n==N:
    if a*b*c>0:
      ret=abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
      ret=INF
  else:
    ret=dfs(n+1,a,b,c)
    reta=dfs(n+1,a+L[n],b,c)+10
    retb=dfs(n+1,a,b+L[n],c)+10
    retc=dfs(n+1,a,b,c+L[n])+10
    ret = min(ret,reta,retb,retc)
  return ret
print(dfs(0,0,0,0))


Measured memory_bytes: 3064
using System;
using System.IO;

namespace AtCoder {
	class Program {
		public static void Main(string[] args) {
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

			int[] a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
			int k = int.Parse(Console.ReadLine());
			Console.WriteLine(a[k - 1]);

			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13140
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void){
    string S;
    cin>>S;
    string N;
    for(int i=0;i<6;i++){
        N+=S[i+4];

    }
    cout<<"2018"<<N<<endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h, m, s;
	scanf("%d", &s);

	h = s / 3600;
	m = s % 3600 / 60;
	s = s % 60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    vi cnt(8,0);
    int pro=0;
    REP(i,n) {
        if(1<=a[i] && a[i]<=399) cnt[0]++;
        else if(400<=a[i] && a[i]<=799) cnt[1]++;
        else if(800<=a[i] && a[i]<=1199) cnt[2]++;
        else if(1200<=a[i] && a[i]<=1599) cnt[3]++;
        else if(1600<=a[i] && a[i]<=1999) cnt[4]++;
        else if(2000<=a[i] && a[i]<=2399) cnt[5]++;
        else if(2400<=a[i] && a[i]<=2799) cnt[6]++;
        else if(2800<=a[i] && a[i]<=3199) cnt[7]++;
        else pro++;
    }
    dump(pro);
    int ans=0;
    REP(i,8) {
        if(cnt[i]!=0) ans++;
    }
    if(ans==0) {
        cout<<1<<" "<<pro<<endl;
    }
    else {
        cout<<ans<<" "<<ans+pro<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
	int n,s,l;
	scanf("%d",&n);
	for(register int i=1;i<=n+1;i++)
	    scanf("%d",&a[i]);
	sort(a+1,a+n+2);
	for(register int i=1;i<=n;i++)
		a[i]=a[i+1]-a[i];
	a[n+1]=0;
	sort(a+1,a+n+1);
	s=a[1];
	l=0;
	while(s>0)
	{
	    l=0;
    	for(register int i=1;i<=n;i++)
	    	if(a[i]%s!=0)
		    {
			    l=1;
			    s--;
	    		break;
	        }
	    if(l==0)
	    {
			printf("%d\n",s);
			exit(0);
		}
    }
    return 0;
}

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

int main(){
	string s;
	while(getline(cin,s)){
		if(s.length()==1)break;
		stack<char> st;
		st.push('#');
		bool flag = true;
		for(int i=0;i<s.length();i++){
			if(s[i]==')'){
				if(st.top()!='('){
					flag = false;
					break;
				}
				st.pop();
			}else if(s[i]==']'){
				if(st.top()!='['){
					flag = false;
					break;
				}
				st.pop();
			}else if(s[i]=='['||s[i]=='('){
				st.push(s[i]);
			}
		}
		if(st.top()!='#')flag=false;
		if(flag)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int H,W;
    while(true){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < W; i++) printf("#");
        printf("\n");
 
        for(int i = 1; i < H-1; i++){
            printf("#");
            for(int j = 1; j < W-1; j++) printf(".");
            printf("#\n");
        }
 
        if(H > 1){
            for(int i = 0; i < W; i++) printf("#");
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2692
#include <stdio.h>

int main(void){
    int coin[6]={1,5,10,50,100,500};
    int num,sum,i;

    sum=0;
    for(i=0;i<6;i++){
        scanf("%d",&num);
        sum+=num*coin[i];
    }
    if(sum>=1000){
        puts("1");
    }else{
        puts("0");
    }
    return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    llint ans = 0;

    for(int i = 1; i <= N; i ++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    ll mx=0,ans=0;
    for(int i=0;i<n;i++){
    if(arr[i]>=mx)
    mx=arr[i];
    else
    ans+=mx-arr[i];
    }
    cout<<ans<<endl;
   
    return 0;
}

Measured memory_bytes: 5152
A,B,C=[list(input()) for i in range(3)]
now="a"
while True:
    if now=="a":
        if len(A)==0:
            print("A")
            break
        now=A.pop(0)
    elif now=="b":
        if len(B)==0:
            print("B")
            break
        now=B.pop(0)
    else:
        if len(C)==0:
            print("C")
            break
        now=C.pop(0)

Measured memory_bytes: 3064
#!/usr/bin/env python2
#encoding: UTF-8

# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
import math
line=raw_input().rstrip().split(' ')
N=int(line[0])
L=int(line[1])
listo=[]
for i in range(N):
    listo.append(raw_input().rstrip())
listi=sorted(listo)
listni=''
for i in range(N):
    listni+=listi[i]
print listni    

Measured memory_bytes: 2692
#include <iostream>
#include <cstdio>
#define MAX_N 10
#define MAX_M 10
using namespace std;

int field[MAX_N][MAX_M] = {0};
int x, y, size, nx, ny;

void Big()
{
	int mx[13] = {-1, -1, -1, 0, 0, 0, 1, 1, 1, -2, 0, 0, 2}, my[13] = {-1, 0, 1, -1, 0, 1, -1, 0, 1, 0, -2, 2, 0};
	for (int i = 0; i < 13; i++) {
		nx = x + mx[i]; ny = y + my[i];
		if (0 <= nx && nx < MAX_N && 0 <= ny && ny < MAX_M) field[nx][ny]++; 
	}
}

void Midole()
{
	int mx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}, my[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
	for (int i = 0; i < 9; i++) {
		nx = x + mx[i]; ny = y + my[i];
		if (0 <= nx && nx < MAX_N && 0 <= ny && ny < MAX_M) field[nx][ny]++; 
	}
}

void Mini()
{
	int mx[5] = {-1, 0, 0, 0, 1}, my[5] = {0, -1, 0, 1, 0};
	for (int i = 0; i < 5; i++) {
		nx = x + mx[i]; ny = y + my[i];
		if (0 <= nx && nx < MAX_N && 0 <= ny && ny < MAX_M) field[nx][ny]++; 
	}
}

int main(void)
{
	int ans = 0, color = 0;
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF) {
		if (x == 0 && y == 0 && size == 0) break;
		switch (size) {
			case 1: Mini(); break;
			case 2: Midole(); break;
			case 3: Big(); break;
		}
	}
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (field[i][j] == 0) ans++;
			else if (color < field[i][j]) color = field[i][j];
		}
	}
	cout << ans << endl << color << endl;

	return 0;
}

Measured memory_bytes: 1208
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable MO = 10L^^9 + 7;

int H, W;
string[] A;

void main() {
  try {
    for (; ; ) {
      H = readInt();
      W = readInt();
      A = new string[H];
      foreach (x; 0 .. H) {
        A[x] = readToken();
      }
      auto dp = new long[][](H, W);
      dp[0][0] = 1;
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        if (A[x][y] == '.') {
          if (x + 1 < H && A[x + 1][y] == '.') {
            (dp[x + 1][y] += dp[x][y]) %= MO;
          }
          if (y + 1 < W && A[x][y + 1] == '.') {
            (dp[x][y + 1] += dp[x][y]) %= MO;
          }
        }
      }
      writeln(dp[H - 1][W - 1]);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 11004
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl
#define pv(v) for(auto a: v){ cout << a << endl; }

int main() {
  int n, m; cin >> n >> m; 
  vector<int> l(n);

  rep(i, m) {
    int a,b; 
    cin >> a >> b;
    l[a-1]++;
    l[b-1]++;
  }

  rep(i, n){
    cout << l[i] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    for(int a=0;a<100;a++){
        for(int b=0;b<100;b++){
            int sum = a*4+b*7;
            if(sum==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B, C, D = map(int, input().split())

# check
AB = B - (A - 1)

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // D

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

ans = AB - C_cnt - D_cnt + lcm_cnt

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, res = 0;
    string S;
    cin >> N >> S;
    for (int i=0;i+2<N;i++) {
        if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') res++;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
int w, h;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
bool inrange(int y, int x){
    return y >= 0 && x >= 0 && x < w && y < h;
}
int wall[31][31][31][31];
struct node{
    int y;
    int x;
    int cst;
    bool operator<(const node &o)const{
        return cst > o.cst;
    }
};
int main() {
    while(cin >> w >> h, w){
        int tmp;
        memset(wall, 0, sizeof(wall));
        rep(i, h){
            rep(j, w-1){
                cin >> tmp;
                wall[i][j][i][j+1] = tmp;
                wall[i][j+1][i][j] = tmp;
            }
            if(i != h-1) {
                rep(j, w){
                    cin >> tmp;
                    wall[i][j][i+1][j] = tmp;
                    wall[i+1][j][i][j] = tmp;
                }
            }
        }
        int ans = 0;
        int done[31][31] = {0};
        priority_queue<node> pq;
        pq.push((node){0,0,1});
        while(!pq.empty()){
            int y = pq.top().y;
            int x = pq.top().x;
            int cst = pq.top().cst;
            pq.pop();
//            cout << x << " " << y << "  "<< cst << endl;
            if(x == w-1 && y == h-1){
                ans = cst;
                break;
            }
            if(done[y][x]) continue;
            done[y][x] = 1;
            rep(i, 4){
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(inrange(ny, nx) && !wall[y][x][ny][nx]) pq.push((node){ny, nx, cst + 1});
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4840
#include <stdio.h>

int main()
{
    char str[1200];

    int ascii_a = 'a';
    int ascii_z = 'z';
    int ascii_A = 'A';
    int ascii_Z = 'Z';

    int ascii_diff = ascii_a - ascii_A;

    int i;
    int  ascii_str;
    for (i = 0; ; i++) {
        scanf("%c", &str[i]);
        ascii_str = str[i];
        if (str[i] == '\n') {
            break;
        } else if ((ascii_a <= ascii_str)&&(ascii_str <= ascii_z)) {
            printf("%c", ascii_str - ascii_diff);
        } else if ((ascii_A <= ascii_str)&&(ascii_str <= ascii_Z)) {
            printf("%c", ascii_str + ascii_diff);
        } else {
            printf("%c", str[i]);
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ret = 0;
    for (int i = 0; i < 29; ++i) {
        vl c = a, d = b;
        for (int j = 0; j < n; ++j) {
            c[j] %= 1 << (i + 1);
            d[j] %= 1 << (i + 1);
        }
        sort(c.begin(), c.end());
        sort(d.begin(), d.end());
        if (i == 0) {
            int oddc = 0, oddd = 0;
            for (int j = 0; j < n; ++j) {
                if (c[j] == 1)
                    oddc++;
                if (d[j] == 1)
                    oddd++;
            }
            ll t = oddc * (n - oddd) + (n - oddc) * oddd;
            ret += t % 2;
        } else {
            ll t = 0;
            for (int j = 0; j < n; ++j) {
                auto l1 = lower_bound(d.begin(), d.end(), (1 << i) - c[j]);
                auto u1 = lower_bound(d.begin(), d.end(), (1 << (i + 1)) - c[j]);
                auto l2 = lower_bound(d.begin(), d.end(), (1 << (i + 1)) + (1 << i) - c[j]);
                auto u2 = lower_bound(d.begin(), d.end(), (1 << (i + 2)) - c[j]);
                t += u1 - l1 + u2 - l2;
            }
            ret += t % 2 * (1 << i);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6548
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    string s = "";
    string acl = "ACL";
    for (int i = 0; i < n; i++) s += acl;
    cout << s << '\n';
}


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

#define int long long
int ans,n,k;

signed main(){
  cin>>n>>k;
  if(k==0)
    return cout<<n*n<<endl,0;
  for(int i=1;i<=n;++i){
    if(i>k){
      ans+=(i-k)*(n/i);
      ans+=max(0LL,((n%i)-k)+1LL);
    }
  }
  return cout<<ans<<endl,0;
}

Measured memory_bytes: 256
#include <iostream>

long long int strToInt4(std::string str)
{
	long long int sum = 0;
	for (int i=0; i<str.size(); i++) {
		sum <<= 2; // sum *= 4
		if (str[i] == 'A') sum+=3;
		else if (str[i] == 'C') sum+=2;
		else if (str[i] == 'G') sum++;
	}
	return sum;
}

int main()
{
	int n;
	std::cin >> n;
	
	bool** exists = new bool*[12];
	for (int i=0; i<12; i++) exists[i] = new bool[1<<(2*(i+1))];
	for (int i=0; i<12; i++) {
		for (int j=0; j<(1<<(2*(i+1))); j++) exists[i][j] = false;
	}
	
	//std::cout << "check" << std::endl;
	
	for(int i=0; i<n; i++) {
		std::string op, key;
		std::cin >> op >> key;
		long long int nKey = strToInt4(key);
		//std::cout << nKey << std::endl;
		if ( op == "insert" ) exists[key.size()-1][nKey] = true;
		else {
			if (exists[key.size()-1][nKey]) std::cout << "yes" << std::endl;
			else std::cout << "no" << std::endl;
		}
	}
	
	for (int i=0; i<12; i++) delete[] exists[i];
	delete[] exists;
	
	return 0;
}




Measured memory_bytes: 24720
s = gets.chomp
n = gets.to_i
(1..n).each do |_x|
  op, x, y, z = gets.split
  x = x.to_i
  y = y.to_i
  case op
  when 'replace'
    s0 = (x == 0) ? '' : s[0..x - 1]
    s1 = (y == s.length - 1) ? '' : s[y + 1..-1]
    s = s0 + z + s1
  when 'reverse'
    s0 = (x == 0) ? '' : s[0..x - 1]
    s1 = (y == s.length - 1) ? '' : s[y + 1..-1]
    m = s[x..y]
    s = s0 + m.reverse + s1
  when 'print'
    puts s[x..y]
  end
end

Measured memory_bytes: 8832
#include <string>
#include <utility>
#include <iostream>

#define MAX 1000

int DP[MAX][MAX];

int main(){
  int n;
  
  std::cin >> n;
  
  for(int t = 0; t < n; t++){
    std::string str1, str2;

    std::cin >> str1;
    std::cin >> str2;
    
    const int one_len = str1.length();
    const int two_len = str2.length();
    
    for(int i = 0; i < one_len; i++){
      for(int j = 0; j < two_len; j++){
	DP[i][j] = 0;
      }
    }

    for(int i = 0; i < one_len; i++){
      for(int j = 0; j < two_len; j++){
	if(i == 0 && j == 0){
	  DP[i][j] = str1[i] == str2[j] ? 1 : 0;
	}else if(i == 0){	
	  DP[i][j] = std::max(DP[i][j-1], str1[i] == str2[j] ? 1 : 0);
	}else if(j == 0){
	  DP[i][j] = std::max(DP[i-1][j], str1[i] == str2[j] ? 1 : 0);
	}else{
	  DP[i][j] = std::max(DP[i-1][j-1] + (str1[i] == str2[j] ? 1 : 0), std::max(DP[i-1][j], DP[i][j-1]));
	}
      }
    }
    
    std::cout << DP[one_len - 1][two_len - 1] << std::endl;
  }
}

Measured memory_bytes: 5112
#include <iostream>
#include <cstdio>

using namespace std;


int main() {
  int N,T;
  scanf("%d%d",&N,&T);
  int routes[N][2];
  for (int i=0;i<N;i++) 
    scanf("%d%d",&routes[i][0],&routes[i][1]);
  int min_cost=1001;

  for (int i=0;i<N;i++) {
    if (routes[i][1]<=T && min_cost>routes[i][0])
      min_cost=routes[i][0];
  }
  if (min_cost==1001) printf("TLE");
  else printf("%d",min_cost);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,c;
	int b = 0;
	scanf("%d",&a);fflush(stdin);
	while(a > 0){
		c = a%10;
		if(c == 9)
			b++;
		a = a/10;
	}
	if(b > 0)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

int main(void){
    string o,e;
    cin>>o>>e;
    for(int i=0;i<e.size();i++){
        cout<<o[i]<<e[i];
    }
    if(o.size()>e.size()) cout<<o[o.size()-1];
    cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long h  = sc.nextLong();
		sc.close();
		long num = 1;
		while(h > 1) {
			h = h/2;
			num+=1;
		}
		System.out.println((long)(Math.pow(2, num)-1));
		
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



int main(void) {
    
    int a=0,b=0;
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='o')a++;
        else b++;
    }
    if(b>=8)fin("NO");
    else fin("YES");
}


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


#define ll long long
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, a, b) for(int i = (a); i > (b); --i)

typedef pair <int,int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <ll> vl;

const int mod = 1e9+7;
const int inf = 2e18+5;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;cin>>n;
  vi a(n),b(n);
  
  loop(i,0,n) {cin>>a[i];b[i]=a[i];}
  sort(b.begin(),b.end());
  int c=0;
  loop(i,0,n)
    if(a[i]!=b[i])
      	c++;
  if(c>2)
    cout<<"NO";
  else
    cout<<"YES";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

typedef long long ll;
int r, c, k;
int m[3010][3010];
ll dp[3010][3010][4];

int main(){
    cin >> r >> c >> k;
    rep(i, k){
        int R, C, K;
        cin >> R >> C >> K;
        m[R][C] = K;
    }

    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= c; j++){
            ll lst = max(max(dp[i-1][j][0], dp[i-1][j][1]), max(dp[i-1][j][2], dp[i-1][j][3]));
            dp[i][j][0] = max(dp[i][j-1][0], lst);
            dp[i][j][1] = max(dp[i][j-1][1], dp[i][j][0] + m[i][j]);
            dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + m[i][j]);
            dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + m[i][j]);
        }
    }
    cout << max(max(dp[r][c][0], dp[r][c][1]), max(dp[r][c][2], dp[r][c][3])) << endl;
    
}

Measured memory_bytes: 321028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	map<char,int> mp;
	rep(i,0,4){
		char c; cin>>c;
		mp[c]++;
	}
	bool ok=true;
	if(mp.size()!=2)ok=0;
	for(auto c:mp){
		if(c.second!=2)ok=0;
	}
	cout<<(ok ? "Yes":"No");
	
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = unsigned long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

ll msb(ll v){
    v |= (v >> 1);
    v |= (v >> 2);
    v |= (v >> 4);
    v |= (v >> 8);
    v |= (v >> 16);
    v |= (v >> 32);
    return (v+1) >> 1;
}

int main(void){
    Cin(ll, a, b);

    if(a == b){
        Cout(1);
        return 0;
    }
    
    ll c = msb(a ^ b);
    ll d = b & ~(c-1);
    ll e = ((b ^ d) == 0) ? b : (b | msb(b ^ d)-1);
    Cout(d-a + min(e+1-a, c));
}




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

#define ll long long int
#define pii pair<int,int>

const ll sz=2019;
ll tot[sz+2];

int main()
{
    ll a,b,c,d,p,q;


    string str;
    cin>>str;
    ll ans=0;

    for(ll i=0;str[i];i++){
        ll temp[sz+2];
        memset(temp,0,sizeof temp);

        for(ll j=0;j<sz;j++){
            p=(j*10ll + (str[i] - '0'))%sz;
            temp[p]+=tot[j];
        }
        ++temp[str[i]-'0'];

        ans+=temp[0];

        for(ll j=0;j<sz;j++) tot[j]=temp[j];
    }

    cout<<ans<<'\n';
}


Measured memory_bytes: 3728
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll x;
    cin >> x;
    ll ng = 0;
    ll ok = 1000000000;
    while (ng + 1 != ok) {
        ll mid = (ng + ok) / 2;
        if (mid * (mid + 1) / 2 >= x)
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,k,ans;
int a[10][10];
char x;
int h[10],w[10];
void dfs(int u){
	if(u==n+m+1){
//		for(int i=1;i<=n;++i)cout<<h[i]<<" ";
//			for(int j=1;j<=m;++j)cout<<w[j]<<" ";cout<<endl;
		int s=0;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j){
				if(h[i]||w[j]) continue;
				if(a[i][j]) s++;
			}
//		cout<<s<<endl;
		if(s==k) ans++;
		return;
	}
	if(u<=n){
		dfs(u+1);
		h[u]=1;
		dfs(u+1);
		h[u]=0;
	}
	else{
		dfs(u+1);
		w[u-n]=1;
		dfs(u+1);
		w[u-n]=0;
	}
}
int main(){
//	freopen("x.txt","r",stdin);
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			cin>>x;
			if(x=='#') a[i][j]=1;//cout<<x<<" "<<a[i][j]<<endl;
		}
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 200000+5;
const int MAX = 10000+5;

int n;
int p;
char s[N];
int F[MAX];

int main(){
	ri2(n,p);
	scanf("%s",s);
	ll ans = 0LL;
	if(p == 2){
		for(int i=0; i<n; i++){
			if((s[i] - '0') & 1) continue;
			ans += i+1;
		}
	}
	else if(p == 5){
		for(int i=0; i<n; i++){
			if(s[i] != '0' and s[i] != '5') continue;
			ans += i+1;
		}
	}
	else{
		int invd = pow_mod(10,p-2,p);
		int pot = 1;
		F[0] = 1;
		int prefix = 0;
		for(int i=0; i<n; i++){
			prefix = add(prefix, mul(pot, s[i] - '0',p),p);
			ans += prefix ? F[prefix] : F[0];
			F[prefix] += 1;
			pot = mul(pot, invd, p);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
import sys
write = sys.stdout.write

N = int(input())
A = list(map(int,input().split()))
rain = []

x = 0
for i in range(N):
    if i % 2 == 0:
        x += A[i]
    else:
        x -= A[i]
rain.append(x // 2)
N -= 1
for i in range(N):
    rain.append(A[i]-rain[i])

for i in range(N):
    write(str(rain[i]*2) + " ")
write(str(rain[-1]*2) + "\n")

Measured memory_bytes: 65764
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 K, X;
  std::cin >> K >> X;
  std::string delimiter = "";
  for (i64 i = X - (K - 1); i <= X + (K - 1); ++i) {
    std::cout << delimiter << i;
    delimiter = " ";
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 256
<?php
// input
$input = STDIN;

$line = explode(" ", trim(fgets($input)));

$stack = array();

foreach ($line as $op) {
    switch ($op) {
        case "+":
            $b = array_pop($stack);
            $a = array_pop($stack);
            array_push($stack, $a + $b);
            break;
        case "-":
            $b = array_pop($stack);
            $a = array_pop($stack);
            array_push($stack, $a - $b);
            break;
        case "*":
            $b = array_pop($stack);
            $a = array_pop($stack);
            array_push($stack, $a * $b);
            break;
        default:
            array_push($stack, $op);
    }
}

print array_pop($stack) . "\n";


Measured memory_bytes: 9288
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

X = int(readline())

answer = 0

answer += int(X / 500) * 1000
X = X % 500

answer += int(X / 5) * 5

print(answer)

Measured memory_bytes: 3060
import numpy as np

s = input()
n = int(s)
k = int(input())

m = len(s)
dp = np.zeros((m+1, 2, k+2), dtype=np.int64)
dp[0][1][0] = 1
for cs in range(m):
    cn = int(s[cs])
    for ck in range(k+2):
        if ck == k+1:
            nk = ck
        else:
            nk = ck + 1
        dp[cs+1][0][nk] += 9 * dp[cs][0][ck]
        dp[cs+1][0][ck] += dp[cs][0][ck]

        if cn == 0:
            dp[cs+1][1][ck] += dp[cs][1][ck]
        else:
            dp[cs+1][1][nk] += dp[cs][1][ck]
            dp[cs+1][0][nk] += (cn - 1) * dp[cs][1][ck]
            dp[cs+1][0][ck] += dp[cs][1][ck]
print(dp[m][0][k] + dp[m][1][k] )

Measured memory_bytes: 27256
N, S = map(int, input().split())
a = list(map(int, input().split()))

ans = float('INF')
total = 0
l = r = 0

while r < N:
    total += a[r]
    r += 1

    if total >= S:
        while total >= S:
            total -= a[l]
            l += 1
        ans = min(ans, r-l+1)

if ans == float('INF'): ans = 0
print(ans)


Measured memory_bytes: 16380
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
int cmp(long long int a,long long int b){
    return a>b;
}
int main(){
    int N;
    int K;
    long long int h[200002];
    memset(h,0,sizeof(h));
    cin>>N>>K;
    long long int res=0;
    for(int i=0;i<N;i++){
        cin>>h[i];
        res=res+h[i];
    }
    if(K>=N){
        cout<<0<<endl;
        return 0;
    }
    sort(h,h+N,cmp);
    for(int i=0;i<K;i++){
        res-=h[i];
    }
    cout<<res<<endl;
    
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second
#define maxn 100005
#define mod 1000000007
int mark[10];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k;
	cin>>n>>k;
	set<int>s;
	for(int i=0;i<k;i++){
		int x;
		cin>>x;
		mark[x]=1;
	}
	for(int i=0;i<10;i++){
		if(i&&mark[i]==0)s.insert(i);
	}

	while(1){
		int x=*s.begin();
		s.erase(s.begin());
		if(x>=n){
			cout<<x;
			return 0;
		}
		for(int i=0;i<10;i++){
			if(mark[i]==0)s.insert(x*10+i);
		}
	}

	return 0;
}

Measured memory_bytes: 3072
x = int(input())
ans = []
for i in range(10000):
	b = i**5 - x
	if b <0:
		B = -b
		s = int(pow(B,0.2))
		if s**5 == B:
			ans = [i, -s]
			break
	else:
		s = int(pow(b,0.2))
		if s**5 == b:
			ans = [i, s]
			break
print(ans[0], ans[1])


Measured memory_bytes: 9448
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int a,b;
	cin>>a>>b;
	if(a==1 ||b==1)
		cout<<1;
		else
cout<<a*b/2+((a&1) && (b&1));
	
}	


Measured memory_bytes: 256
$drc = [[0, 1], [0, -1], [1, 0], [-1, 0]]
def dfs(y, x, d, n)
  return true if n == $max
  $fld[y][x] = false
  4.times do |i|
    next if i == 'UDLR'.index(d)
    ny, nx = y, x
    loop do
      nx += $drc[i][0]; ny += $drc[i][1]
      break if $fld[ny][nx].nil?
      if $fld[ny][nx]
        $ans[n] = 'DURL'[i]
        return true if dfs(ny, nx, 'DURL'[i], n + 1)
        break
      end
    end
  end
  $fld[y][x] = true
  false
end


sx = sy = 0; d = ''
r, c = gets.split.map(&:to_i)
$fld = []
r.times do |y|
  l = gets.chomp.split('')
  l.each do |a|
    if a != '.' && a != 'o'
      sx = l.index(a) + 1
      sy = y + 1
      d = a
    end
  end
  $fld << [nil, *l.map{ |a| a == '.' ? false : true }, nil]
end
$fld = [[nil] * (c + 2), *$fld, [nil] * (c + 2)]
$max = $fld.flatten.count(true) - 1
$ans = ['x'] * $max
dfs(sy, sx, d, 0)
puts $ans.join

Measured memory_bytes: 8972