akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

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

ll n,m,a[200005];
map<ll,ll> mp;
int main()
{
    ll k;
    sfl(n);
    for(int i=1;i<=n;i++)
    {
        sfl(a[i]);
        mp[i-a[i]]++;
    }
    ll ans =0;
    for(int i=1;i<=n;i++)
    {
        mp[i-a[i]]--;
        ans += mp[i+a[i]];
    }
    pf("%lld\n",ans);
}


Measured memory_bytes: 27988
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N
    for i in range(N - 1, -1, -1):
        for j in range(i, N, i + 1):
            B[i] += B[j]
        if B[i] % 2 == 1:
            if A[i] == 1:
                B[i] = 0
            else:
                B[i] = 1
        else:
            if A[i] == 1:
                B[i] = 1
            else:
                B[i] = 0
    print(B.count(1))
    for i, c in enumerate(B):
        if c == 1:
            print(i + 1)


main()


Measured memory_bytes: 7100
N=int(input())
X=list(map(int,input().split()))

def get_dist(X,p):
    sum_=0
    for x in X:
        sum_+=(x-p)**(2)
        
    return sum_

dist_min=10**10
for p in range(0,101):
    dist=get_dist(X,p)
    if dist_min>dist:
        dist_min=dist
print(dist_min)
       

Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,k;
	cin>>a>>b>>k;
	if(a>=k){
		cout<<a-k<<" "<<b<<endl;
		return 0;
	}
	else if(a+b<=k){
		cout<<"0 0"<<endl;
		return 0;
	}
	else{
		cout<<"0 "<<b-k+a<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
@A=glob<>;@l=<>;printf sort{$a-$b}map{$x=@v=++$i;$v[$t=$i>>2*$_&3]+=$t&&$l[$x+=10,$_]for 0..@l;$x+=abs$A[$_]-($v[$_]||1e9)for 1..3;$x-31}1..1e5

Measured memory_bytes: 9856
#include <stdio.h>

int main(void) {
  int a,b,c,t;
  scanf("%d %d %d",&a,&b,&c);
  for(a;a<b+1;a++){
  if(c%a==0){
    t++;
  }
  }
  printf("%d\n",t);
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
vector<pair<int, int> > g[N];
string ans[N];

string getString(int n){
	string ret = "";
	for(int i = 0; i < 6; i++){
		ret += char(n%10 + '0');
		n /= 10;
	}
	reverse(ret.begin(), ret.end());
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		int p, y;
		cin>>p>>y;
		g[p].push_back({y, i});
	}
	for(int i = 1; i <= n; i++){
		sort(g[i].begin(), g[i].end());
		string s = getString(i);
		for(int j = 0; j < g[i].size(); j++){
			string t = getString(j + 1);
			ans[g[i][j].second] = s + t;
		}
	}
	for(int i = 0; i < m; i++){
		cout<<ans[i]<<'\n';
	}

	return 0;
}

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

 #define NMAX 2000000
 #define AMAX 10000

int main(){
    int n,a[NMAX+1],b[NMAX+1],c[AMAX+1];
    cin>>n;
    for(int i=0;i<=AMAX;i++) c[i]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        c[a[i]]++;
    }
    for(int i=1;i<=AMAX;i++) c[i]+=c[i-1];
    for(int i=n;i>0;i--){
        b[c[a[i]]]=a[i];
        c[a[i]]--;
    }    
    for(int i=1;i<=n;i++){
        cout<<b[i]<<((i==n)?'\n':' ');
    }
}


Measured memory_bytes: 18740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;
  if(S.size()==26){
    if(S=="zyxwvutsrqponmlkjihgfedcba"){
      cout<<-1<<endl;
    }
    else{
      int L=1;
      for(int X=24;X>=0;X--){
        if(S[X]>S[X+1]){
          L++;
        }
        else{
          break;
        }
      }
      for(int X=0;X<25-L;X++){
        cout<<S[X];
      }
      for(char X=S[25-L];X<='z';X++){
        bool H=true;
        for(int Y=0;Y<26-L;Y++){
          if(S[Y]==X){
            H=false;
          }
        }
        if(H){
          cout<<X<<endl;
          break;
        }
      }
    }
  }
  else{
    cout<<S;
    for(char X='a';X<='z';X++){
      bool H=true;
      for(int Y=0;Y<S.size();Y++){
        if(S[Y]==X){
          H=false;
        }
      }
      if(H){
        cout<<X<<endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3640
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(A,B);
    // 1 + (A-1)*k >= B
    cout << ceil((double)(B-1)/(A-1)) << nn;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		
		if (S.equals("A"))
			System.out.println("T");
				
		else if (S.equals("T"))
			System.out.println("A");
		
		else if (S.equals("G"))
			System.out.println("C");
		
		else
			System.out.println("G");
	}

}

Measured memory_bytes: 18900
char s[];main(){double*q=s+9,b;for(;~scanf("%s",s);getchar()<14&&printf("%f\n",*q)){!sscanf(s,"%lf",q+1)?b=*q--,*q=*s-47?*s-42?*s-45?*q+b:*q-b:*q*b:*q/b:*++q;}}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

int gcd(int a, int b, int c) {
    int min_abc = min(min(a, b), c);

    int ret = 1;
    for (int i = 2; i <= min_abc; ++i) {
        if (a % i == 0 && b % i == 0 && c % i == 0) {
            ret = i;
        }
    }
    return ret;
}

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

    int sum = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                sum += gcd(i, j, k);
            }
        }
    }

    cout << sum << endl;
    //cout << setprecision(15) << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
typedef long double ld;

//typedef acos(-1) PI;

#define PI acos(-1)

int main(){
	int n;
	cin>>n;
	ld ans=2*PI*n;
	//printf("%.9Lf\n",ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int map[21][21], w, h;

bool check(int j, int k) {
	return (j >= 0 && j < h && k >= 0 && k < w && map[j][k] >= 1);
}

int main() {
	while (1) {
		int sj, sk, j, k, diff[] = {-1, 0, 1, 0, -1}, ans;
		string input;
		queue<pair<int, int> > bfs;

		cin >> w >> h;
		if (w==0 && h==0) break;

		REP(j, h) { REP(k, w) map[j][k] = -1; }
		ans = 0;

		REP(j, h) {
			cin >> input;
			REP(k, w) {
				map[j][k] = (input[k] == '#') ? 0 : 1;
				if (input[k] == '@') {
					sj = j;
					sk = k;
				}
			}
		}

		bfs.push(make_pair(sj, sk));
		map[sj][sk] = -1;
		ans++;

		while (!bfs.empty()) {
			j = bfs.front().first;
			k = bfs.front().second;
			bfs.pop();
			REP(i, 4) {
				if (check(j + diff[i], k + diff[i + 1])) {
					/*debug(j);
					debug(k);
					debug(j+diff[i]);
					debug(k+diff[i+1]);*/
					bfs.push(make_pair(j + diff[i], k + diff[i + 1]));
					map[j + diff[i]][k + diff[i + 1]] = -1;
					ans++;
				}
			}
		}

		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%ld\n",a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007
#define w while
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)

///////////////////////////////////////////////////////////////
int main()
{
	int x;
	cin>>x;
	fr(i,1,360)
	{
		int y=x*i;
		if(y%360==0)
		{
			cout<<i;
			return 0;
		}
	}
    return 0;
}





Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<s.length();i++)
		{
			if(s[i]==t[i])
			{
				ans++;
			}
		}
		cout<<ans<<endl;
		return 0;
} 

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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; }

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

int dp[10001];

signed main(){
    int N, W; cin >> N >> W;
    vector<int> w( N ), v( N );
    REP( i, N ){
        cin >> v[i] >> w[i];
    }

    REP( i, N ){
        for( int j = W; j >= w[i]; j-- ){
            chmax( dp[j], dp[j - w[i]] + v[i] );
        }
    }

    cout << dp[W] << endl;

}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define l long long
int main()
{
	l a,b,c,k;
	cin>>a>>b>>c>>k;
	l x;
	if(k>a)
	{
		if(k-a-b>0)
			x=a-k+a+b;
		else
			x=a;
	}
	else
		x=k;
	cout<<x;
	return 0;
}

Measured memory_bytes: 3636
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define REPB(i,n) for(int i=(int)(n)-1;i>=0;i--)

int main() {
  int n; cin>>n;
  int exc = 1;
  REP(i,n) {
    int a; cin>>a;
    if (a%2==0) exc*=2;
  }
  cout << pow(3,n)-exc << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
using ll = long long;

int n,m,ans=1e9;
string s,t;
int x[105];

int main() {
  cin >> n;
  rep(i,n) cin >> x[i];
  rep(i,100){
    int sum=0;
    rep(j,n) sum+=(x[j]-i)*(x[j]-i);
    chmin(ans,sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int N;
  cin >> N;
  cout << 1110 - N << endl;
}

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


int main(){
  int num, yen;
  cin >> num >> yen;

  int gaku  = num * 500;
  if (gaku >= yen){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
        int ara[5][5];
        for(int i=1;i<=3;i++)
        {
            for(int j=1;j<=3;j++)sf("%d",&ara[i][j]);
        }

        int a[5],b[5];
        bool ff=true;
        for(int a1=0;a1<=100;a1++)
        {
            a[1]=1;
            b[1]=ara[1][1]-a1;
            b[2]=ara[1][2]-a1;
            b[3]=ara[1][3]-a1;

            a[2]=ara[2][1]-b[1];
            a[3]=ara[3][1]-b[1];

            bool f=true;
            for(int i=1;i<=3;i++)
            {
                for(int j=1;j<=3;j++)
                {
                    if(ara[i][j]!=a[i]+b[j])
                    {
                        f=false;
                        break;
                    }
                }
                if(!f)break;
            }
            if(f)
            {
                puts("Yes");
                ff=false;
                break;
            }
        }
        if(ff)puts("No");
    return 0;
}
 









 




























Measured memory_bytes: 256
def main():
    R,G,B,N = map(int,input().split())
    ans = 0
    for i in range(N//R+1):
        for j in range(N//G+1):
            now = N - R*i - G*j
            if now%B==0 and now>=0:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40684
# coding: utf-8
# Your code here!
N = int(input())
S = input()
MOD = 1000000007

ans = 1
for e in set(S):
    cnt = 0
    
    for i in range(N):
        if S[i] == e:
            cnt += 1
    ans *= cnt+1
    
print((ans-1) % MOD)

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 3005
#define INF 0x3f3f3f3f
#define p 1000000007
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, ans, f[MAXN][MAXN], pre[MAXN], suf[MAXN];
char s[MAXN];


int main()
{
	scanf("%d", &n);
	scanf("%s", s+1);
	f[1][1]=1;
	for(rint i=2; i<=n; ++i)
	{
		pre[0]=0; suf[i]=0;
		for(rint j=1; j<=i-1; ++j) pre[j]=(pre[j-1]+f[i-1][j])%p;
		for(rint j=i-1; j>=1; --j) suf[j]=(suf[j+1]+f[i-1][j])%p;
		if(s[i-1]=='<')
		{
			for(rint j=1; j<=i; ++j) f[i][j]=pre[j-1];
		}
		else
		{
			for(rint j=i; j>=1; j--) f[i][j]=suf[j];
		}
		//for(rint j=1; j<=i; ++j) printf("%d %d %d %d %d\n", i, j, f[i][j], pre[j-1], suf[j]);
	}
	for(rint i=1; i<=n; ++i) ans=(ans+f[n][i])%p;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 34176
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<int> can_survive[500];
int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> inputs;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		inputs.push_back(make_pair(a, b));
	}
	for (int i = 0; i < n; ++i) {
		set<int> hoge;
		hoge.insert(i);
		for (int q = m - 1; q >= 0; --q) {
			int ok = 0;
			if (hoge.find(inputs[q].first) != hoge.end()) {
				ok = 1;
			}
			if (hoge.find(inputs[q].second) != hoge.end()) {
				ok += 2;
			}
			if (ok == 3) {
				hoge.clear();
				break;
			}
			else if (ok == 2) {
				hoge.insert(inputs[q].first);
			}
			else if (ok == 1) {
				hoge.insert(inputs[q].second);
			}
		}
		if (hoge.empty() == true) continue;
		for (auto q = hoge.begin(); q != hoge.end(); ++q) {
			can_survive[i].push_back(*q);
		}
		sort(can_survive[i].begin(), can_survive[i].end());
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int q = i + 1; q < n; ++q) {
			if (can_survive[i].size() == 0 || can_survive[q].size() == 0) continue;
			int itr[2] = { 0,0 };
			int ok = 1;
			while (can_survive[i].size() != itr[0] && can_survive[q].size() != itr[1]) {
				if (can_survive[i][itr[0]] == can_survive[q][itr[1]]) {
					ok = 0;
					break;
				}
				if (can_survive[i][itr[0]] < can_survive[q][itr[1]]) {
					itr[0]++;
				}
				else {
					itr[1]++;
				}
			}
			ans += ok;
		}
	}
	cout << ans << endl;
}

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

int main() {

  int N,X,T;
  cin>> N >>X>>T;
  
  if (N%X==0){
    cout << T*(N/X) <<endl;
  }
  else{
    cout << T*((N/X) +1)<<endl;
  }
}



Measured memory_bytes: 3616
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Array.Sort(A);
        int sum = 0;
        for(int i = 1; i < A.Length; i++)
        {
            sum += A[i] - A[i - 1];
        }
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#include <iomanip>      
#define pb push_back
#define x first
#define y second
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
using namespace std;
  
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }

const string FILENAME = "input";
const int MAXN = 3e5 + 1;

int n, L, R;
int dp[2012][2012];
vector <int> a; 

int main() {
    ios::sync_with_stdio(0);
    //read(FILENAME);
    cin >> n >> L >> R;
    a.resize(n + 1);
    a[0] = R;
    for (int i = 1; i <= n; ++i) {
    	cin >> a[i];
    }
    for (int i = n; i >= 0; --i) {
    	int minv1 = 1e9, minv2 = 1e9;
    	int maxv1 = -1e9, maxv2 = -1e9;
    	for (int j = n; j > i; --j) {
    		chkmax(maxv1, dp[i][j]);
    		chkmax(maxv2, dp[j][i]);
    		chkmin(minv1, dp[i][j]);
    		chkmin(minv2, dp[j][i]);
    	}
    	//cout << minv1 << ' ' << maxv2 << endl;
    	for (int j = i - 1; j >= 0; --j) {
    		if (i == n || j == n) {
    			dp[i][j] = dp[j][i] = abs(a[i] - a[j]);
    		} else {
    			dp[i][j] = minv1;
    			dp[j][i] = maxv2;
    		}
    	}
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
    	chkmax(ans, dp[i][0]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> A(n), B(n), id(n);
  rep(i, n) {
    cin >> A[i] >> B[i];
    id[i] = i;
  }
  sort(all(id), [&](int i, int j) {
      return A[i] < A[j];
    });
  int cnt = m;
  ll ans = 0;
  int i = 0;
  while(cnt) {
    if(cnt < B[id[i]]) {
      ans += A[id[i]] * cnt;
      break;
    } else {
      ans += A[id[i]] * B[id[i]];
      cnt -= B[id[i]];
    }
    i++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 5572
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] D = new int[K];

    for (int i = 0; i < K; i++) {
      D[i] = sc.nextInt();
    }

    sc.close();

    for (int i = N; i < N * 10; i++) {
      boolean valid = true;
      for (int j = 0; j < K; j++) {
        String d = String.valueOf(i);
        String d_ = String.valueOf(D[j]);
        if ((d.indexOf(d_) != -1)){
          valid = false;
        }
      }
      if (valid) {
        System.out.println(i);
        break;
      }
    }

  }

}

Measured memory_bytes: 41044
s = input()
t = input()

lens= len(s)
lent= len(t)
#print(lens,lent)
#print(t[:(lent-1)])
ans = 'No'
if lens >= 1 and lens <= 10 and lent == lens + 1:
  if s == t[:(lent-1)] :
    ans = 'Yes'
print(ans)


Measured memory_bytes: 61628
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

class Node {
public:
  Node()
    : counter_(0), parent_(nullptr)
  {
  };

  void set_parent(Node* node) {
    this->parent_ = node;
  }

  void count_up(uint32_t x) {
    if (this->parent_) {
      this->counter_ = this->parent_->counter() + x;
    } else {
      this->counter_ = x;
    }
  }

  uint64_t counter() {
    return this->counter_;
  }

private:
  Node* parent_;
  uint64_t counter_;
};

int main()
{
  uint32_t N, Q;
  cin >> N >> Q;

  vector<Node*> nodes(N+1);
  for (Node*& n : nodes)
    n = new Node();
  
  for (int n=0; n<N-1; ++n) {
    int a, b;
    cin >> a >> b;
    nodes[b]->set_parent(nodes[a]);
  }

  multimap<uint32_t, uint16_t> values;

  for (int q=0; q<Q; ++q) {
    int p, qq;
    cin >> p >> qq;
    values.emplace(p,qq);
  }

  for (int n=1; n<=N; ++n) {
    auto value_n = values.equal_range(n);
    uint64_t sum = accumulate(value_n.first, value_n.second, 0, [](uint64_t a, pair<const uint32_t,uint16_t> b){return a+b.second;});
    nodes[n]->count_up(sum);
    cout << nodes[n]->counter() << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 19584
#include <iostream>
#include <map>
#include <utility>
#include <set>
#include <vector>

using namespace std;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

class UnionFind {
public:
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }

  void unite(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (px != py) {
      if (data[py] < data[px]) swap(px, py);
      data[px] += data[py]; data[py] = px;
    }
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> lp;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p; --p;
    lp.push_back(p);
  }
  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y; --x; --y;
    uf.unite(x, y);
  }
  map<int, vector<int>> from, to;
  for (int i = 0; i < n; ++i) {
    int p = uf.find(i);
    if (p < 0) p = i;
    from[p].push_back(i);
    to[p].push_back(lp[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (from.find(i) == from.end()) continue;
    set<int> s;
    for (int p: from[i]) { s.insert(p); }
    for (int p: to[i]) { s.insert(p); }
    ans += from[i].size()+to[i].size()-s.size();
  }
  cout << ans << endl;
}


Measured memory_bytes: 22904
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>


using namespace std;

int main() {
   

    int a,b,c;
    cin >> a >> b >> c;
    if (b > c){
        int t = b;
        b = c;
        c = t;
    }
    if (a > b){
        int t = a;
        a = b;
        b = t;
    }
    if (b > c){
        int t = b;
        b = c;
        c = t;
    }
    cout << a << " " << b << " " << c << endl;


}



Measured memory_bytes: 3080
n=int(input())
a=list(map(int,input().split()))
pl = [0]*100005

for i in range(n):
    num = a[i]
    pl[num-1 + 2] += 1
    pl[num+2 + 2] -= 1

for i in range(1,100004):
    pl[i] += pl[i-1]

print(max(pl))

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

int main()
{
  int n, m, i;
  cin  >> n >> m;
  int m1 = 0;
  int m2 = 1000000000;
  int l[100000];
  int r[100000];
  for (i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
    if (m1 < l[i])
      m1 = l[i];
    if (m2 > r[i])
      m2 = r[i];
  }
  cout << max(m2 - m1 + 1, 0) << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> H(N);
    vector<int> A(M), B(M);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
    }
    // cout << "OK" << endl;
    map<int, int> E;
    for (int i = 0; i < M; i++) {
        // cout << i << endl;
        if (H[A[i]-1] < H[B[i]-1]) {
            E[A[i]] = 1;
        } else if (H[A[i]-1] > H[B[i]-1]) {
            E[B[i]] = 1;
        } else {
            E[A[i]] = 1;
            E[B[i]] = 1;
        }
        
        
    }
    // cout << "OK" << endl;
    
    cout << H.size() - E.size() << endl;
    

}

Measured memory_bytes: 7484
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

l = iinput()
ans = (l/3)**3
print(ans)


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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int a,b;
string s;

signed main(){
    cin>>a>>s>>b;
    if(s=="+"){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  rep(i, N) {
    cin >> a[i];
  }
  rep(i, N) {
    cin >> b[i];
  }
  rep(i, N) {
    cin >> c[i];
  }

  std::sort(a.begin(), a.end());
  std::sort(b.begin(), b.end());
  std::sort(c.begin(), c.end());

  vector<int> combi(N);
  int pos = 0;
  rep(i, N) {
    while (b[i] > a[pos] && pos < N) {
      pos++;
    }
    combi[i] = pos;
  }

  long long sum = 0;
  long long combi_sum = 0;
  pos = 0;
  rep(i, N) {
    while (c[i] > b[pos] && pos < N) {
      combi_sum += combi[pos];
      pos++;
    }

    sum += combi_sum;
  }

  cout << sum << endl;

  return 0;
}


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

int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	vector<int> a = { A,B,C };
	sort(a.begin(), a.end());
	int ans = a[2] * 10 + a[1] + a[0];

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 1123456789012;
std::vector<std::vector<LL>>dist;
std::vector<std::vector<edge>>G;

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	dist[s][0] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL c = p.first, v = p.second;
		if (dist[v][c % 3] < c) continue;
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to][(c + 1) % 3] > dist[v][c % 3] + e.cost)
			{
				dist[e.to][(c + 1) % 3] = dist[v][c % 3] + e.cost;
				que.push(P(c + 1, e.to));
			}
		}
	}
}

int main()
{
	LL N, M, S, T;
	in >> N >> M;
	std::vector<LL>u(M), v(M);
	rep(i, M) in >> u[i] >> v[i];
	in >> S >> T;

	dist.resize(N + 1, std::vector<LL>(3, inf));
	G.resize(N + 1);
	rep(i, M) G[u[i]].push_back({ v[i],1 });
	dijkstra(S);

	out << (dist[T][0] != inf ? dist[T][0] / 3 : -1) << std::endl;
}


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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();

		int tx = sc.nextInt();
		int ty = sc.nextInt();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ty - sy; i++) {
			sb.append('U');
		}

		for (int i = 0; i < tx - sx; i++) {
			sb.append('R');
		}

		sb.append('U');
		for (int i = 0; i < tx - sx + 1; i++) {
			sb.append('L');
		}

		for (int i = 0; i < ty - sy + 1; i++) {
			sb.append('D');
		}
		sb.append('R');
		for (int i = 0; i < tx - sx; i++) {
			sb.append('R');
		}

		for (int i = 0; i < ty - sy; i++) {
			sb.append('U');
		}
		sb.append('R');
		for (int i = 0; i < ty - sy + 1; i++) {
			sb.append('D');
		}
		for (int i = 0; i < tx - sx + 1; i++) {
			sb.append('L');
		}
		sb.append('U');

		System.out.println(sb.toString());
	}
}


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

#define int long long
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = a ^ b ^ c;
  if(!(a == b && b == c) && (x == a || x == b || x == c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//
// Created on 2020/02/09.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    int ans;
    int A;
    int B;
    string s;
    string t;
    cin>>s>>t;
    cin>>A>>B;
    string u;
    cin>>u;
    if (u==s){
        A --;
    }else{
        B --;
    }

    cout<<A<<" "<<B<<endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        ArrayList<Integer> x = new ArrayList<>();
        ArrayList<String> st = new ArrayList<>();
        ArrayList<Integer> y = new ArrayList<>();
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        while (true) {
             
            String[] line = br.readLine().split(" ");
            if ("?".equals(line[1])) {
                break;
            }
            x.add(Integer.parseInt(line[0]));
            st.add(line[1]);
            y.add(Integer.parseInt(line[2]));
 
        }
 
        for (int i = 0; i < x.size(); i++) {
            if ("+".equals(st.get(i))) {
                System.out.println(x.get(i) + y.get(i));
            }
 
            if ("-".equals(st.get(i))) {
                System.out.println(x.get(i) - y.get(i));
            }
 
            if ("*".equals(st.get(i))) {
                System.out.println(x.get(i) * y.get(i));
            }
 
            if ("/".equals(st.get(i))) {
                System.out.println(x.get(i) / y.get(i));
            }
        }
 
    }
 
}

Measured memory_bytes: 24024
def solve():
    n = int(input())
    ST = []
    ans = 0
    for _ in range(n):
        s, t = input().split()
        t = int(t)
        ans += t
        ST.append([s, t])
    X = input()
    for s, t in ST:
        ans -= t
        if s == X:
            break
    print(ans)
solve()


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

int main(void){
	int n, q;
	cin >> n;
	int s[n];

	for(int i = 0; i < n; i++){
		cin >> s[i];
	}

	cin >> q;
	int t[q];

	for(int i = 0; i < q; i++){
		cin >> t[i];
	}
	int count = 0;
	for(int i = 0; i < q; i++){
		for(int j = 0; j < n; j++){
			if(t[i] == s[j]){
				count++;
				break;
			}
			else continue;
		
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define H_MAX 50
#define W_MAX 50

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

namespace patch {
  template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
}

int main() {
	string s;
	cin >> s;
	int count = 0;
	int max = 0;
	rep(i,s.size()) {
		rep(j, s.size()) {
			if(i > j)  
				continue;
			int t = i;
			while(t <= j) {
				if(s[t] == 'A' || s[t] == 'C' || s[t] == 'G' || s[t] == 'T') {
					count = count + 1;
					max = max > count ? max : count;
				}
				else {
					count = 0;
				}
				t++;
			}
			count = 0;
		}
	}
	cout << max << endl;
			

  return 0;
}
 


Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
import math
def inpl(): return list(map(int, input().split()))

#### START
# a_1, b_1 = map(int,input().split())

# if N-K>0:
#   print("YES")
# else:
#   print("NO")
N, K = map(int,input().split())

ans = math.ceil(N/2)
if ans>=K:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3444
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + ''.join(list(reversed(x))) + ''.join(list(reversed(a))))

Measured memory_bytes: 41596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String t = br.readLine();
		int q = Integer.parseInt(br.readLine());
		int[] a = new int[q];
		int[] b = new int[q];
		int[] c = new int[q];
		int[] d = new int[q];
		for (int i = 0; i < q; i++) {
			String[] sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]) - 1;
			b[i] = Integer.parseInt(sa[1]);
			c[i] = Integer.parseInt(sa[2]) - 1;
			d[i] = Integer.parseInt(sa[3]);
		}
		br.close();

		int[] ss = new int[s.length() + 1];
		for (int i = 0; i < s.length(); i++) {
			ss[i + 1] = ss[i] + toInt(s.charAt(i));
		}
		int[] tt = new int[t.length() + 1];
		for (int i = 0; i < t.length(); i++) {
			tt[i + 1] = tt[i] + toInt(t.charAt(i));
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int v1 = ss[b[i]] - ss[a[i]];
			int v2 = tt[d[i]] - tt[c[i]];
			if (v1 % 3 == v2 % 3) {
				pw.println("YES");
			} else {
				pw.println("NO");
			}
		}
		pw.flush();
	}

	static int toInt(char ch) {
		return ch == 'A' ? 1 : 2;
	}
}


Measured memory_bytes: 48880
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn=200050;
unordered_map<int,int> mp;
ll sum[maxn];
ll n;
int x,mod;

void solve(){
	scanf("%lld %d %d",&n,&x,&mod);
	ll res=0;
	for(int i=1;i<=n;i++){
		if(mp.count(x)){
			res+=((n-i+1)/(i-mp[x]))*(sum[i-1]-((mp[x]-1>=0)?sum[mp[x]-1]:0));
			int now=mp[x];
			int ret=(n-i+1)%(i-mp[x]);
			for(int j=ret;j>0;j--){
				res+=sum[now]-(now-1>=0?sum[now-1]:0);
				now++;
			}
			break;
		}
		res+=x;
		sum[i]=sum[i-1]+x;mp[x]=i;
		x=(ll)x*x%mod;
	}
	printf("%lld\n",res);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 5664
import sys
S = input()
T = input()

S = S[::-1]
T = T[::-1]

for i in range(len(S)):
    match = True
    for j in range(len(T)):
        if i + j < len(S):
            if not (T[j] == S[i + j] or S[i + j] == '?'):
                match = False
        else:
            match = False
    if match:
        for j in range(len(T)):
            S = S[:i + j] + T[j] + S[i + j + 1:]
        break
else:
    print('UNRESTORABLE')
    sys.exit()

S = S.replace('?', 'a')
print(S[::-1])


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <string>
#include <limits.h>
#include <iomanip>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <set>
#include <bitset>
#include <unordered_map>
#include <string.h>
#define fastIo                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MOD 1000000007

using namespace std;
int main()
{
    fastIo; 

    ll x,k,d;
    cin>>x>>k>>d;

    ll ax = abs(x);
    
    ll y = ax/d;
    if(x==0){
        if(k%2==0)
            cout<<0<<endl;
        else
            cout<<x+d<<endl; 
        return 0;      
    }
    //else if(x>0){
        x = abs(x);
        if(x%d==0){
            if(k<=y){
                cout<<x-k*d;
            }
            else{
                ll extra = k-y;
                if(extra%2==0)
                    cout<<0<<endl;
                else{
                    cout<<d<<endl;
                }
                
            }
        }
        else{
            if(k<=y){
                cout<<x-k*d;
            }
            else{
                ll extra = k-y;
                if(extra%2==0){
                    cout<<x%d<<endl;
                }
                else{
                    cout<<abs(x%d-d);
                }
            }
        }
    //}
   // else{

    //}




    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),max=Integer.MIN_VALUE;
		int[] a=new int[100003];
		for(int i=0;i<n;i++) {
			int buff=sc.nextInt();
			if(buff!=0)a[buff-1]++;
			a[buff]++;
			a[buff+1]++;
		}
		for(int i=0;i<100003;i++) {
			max=Math.max(max, a[i]);
		}

		System.out.println(max);
	}
}



Measured memory_bytes: 49568
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {



    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String S = in.readLine();
        String T = in.readLine();
        if(S.length() + 1 == T.length() && S.equals(T.substring(0, T.length() - 1))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 25328
let id a = a
let n = Scanf.scanf "%d\n" id
let repeat f =
  let rec loop acc = function
    | 0 -> List.rev acc
    | n -> loop (f () :: acc) (n-1) in
  loop []

let r = repeat (fun () -> Scanf.scanf "%c" id) n

let rec ans x list = function
  | [] -> list
  | a :: rest ->
     match a with
     | 'I' -> ans (x+1) ((x+1) :: list) rest
     | 'D' -> ans (x-1) ((x-1) :: list) rest
     | _   -> ans x (x :: list) rest

let anslist = ans 0 [] r 

let rec maxlist l x =
  match l with
  | [] -> x
  | a :: rest -> if a > x then maxlist rest a else maxlist rest x
 
let saidai = maxlist anslist 0
	
let () = Printf.printf "%d\n" saidai


Measured memory_bytes: 384
N = input()
a = list(map(int,input().split()))
ave = sum(a)/len(a)
ans = 10e12
tmp = 0
ans_num = 0
for i in range(len(a)):
  tmp = abs(a[i] - ave)
  if ans > tmp:
    ans = tmp
    ans_num = i
print(ans_num)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int bll, chg;
	int i;

	while (1) {
		scanf("%d", &bll);
		if (bll == 0)
			break;
		chg = 0;
		bll = 1000 - bll;
		if (bll >= 500) {
			chg += bll / 500;
			bll %= 500;
		}
		if (bll >= 100) {
			chg += bll / 100;
			bll %= 100;
		}
		if (bll >= 50) {
			chg += bll / 50;
			bll %= 50;
		}
		if (bll >= 10) {
			chg += bll / 10;
			bll %= 10;
		}
		if (bll >= 5) {
			chg += bll / 5;
			bll %= 5;
		}
		chg += bll;
		printf("%d\n", chg);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
inline int ri() {
	int r; cin >> r; return r;
}
const ll mod = 1e9 + 7;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	for(auto &i : s)i -= '0';
	vector<vector<ll>> dp(n + 1, vector<ll>(2)); //i桁目まで見てフラグがj
	dp[0][0] = 1;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 2; j++) {

			for(int d = 0; d <= (j ? 1 : s[i]); d++) {
				if(d == 0) {
					dp[i + 1][j || d < s[i]] += dp[i][j];
					dp[i + 1][j || d < s[i]] %= mod;
				}else {
					dp[i + 1][j || d < s[i]] += dp[i][j] * 2;
					dp[i + 1][j || d < s[i]] %= mod;
				}
			}
		}
	}
	//cout << dp[1][0] << " : " <<  dp[1][1] << endl;
	cout << (dp[n][0] + dp[n][1]) % mod  << endl;
}

Measured memory_bytes: 5760
import java.util.*;

public class Main {

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

    if(n == 1) {
      System.out.println("Hello World");
    } else if(n == 2) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      System.out.println(a+b);
    }
  }

}


Measured memory_bytes: 25044