akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

int main()
{
	int A, B, C, X, Y;

	cin >> A >> B >> C >> X >> Y;

	int min_xy = min(X, Y);

	int sum = 0;

	if (2 * C < A + B) {
		sum = 2 * C * min_xy;
		sum += max(0, X - min_xy) * min(A, 2 * C);
		sum += max(0, Y - min_xy) * min(B, 2 * C);
	}
	else {
		sum += X * min(A, 2 * C);
		sum += Y * min(B, 2 * C);
	}


	int  ans = sum;
	//printf("%.9f", ans);
	std::cout << ans;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
#define MAX 505
 
typedef long long ll;

int main(int, char**)
{
    int n, m;
    cin >> n >> m;

    int ofs = 0;
    int fst, snd;
    rep(i,m) {
        fst = i + 1;
        snd = n - i;
        if (fst > n / 4 && n % 2 == 0) snd -= 1;
        cout << fst << " " << snd << endl;
    }

    return 0;
}

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

int		main(void)
{
	string	a;	cin >> a;
	int		j = 0;
	for (int i = a.size() - 1; i >= 0; i--)
	{
		if (a.at(i) != a.at(j))
		{
			cout << "No" << endl;
			goto OUT;
		}
		j++;
	}
	cout << "Yes" << endl;
	OUT:
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

ll f(ll x){
	if(x>=0) return x;
	return INF;
}

int x,y;

int main(){
	cin>>x>>y;
	ll a=y-x,b=y+x+1,c=-y-x+1,d=x-y+2;
	cout<<min(f(a),min(f(b),min(f(c),f(d))))<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<set>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;

signed main(){
    string s;cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3616
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 15;
const int M = 1e3+5;

int cost[M], mask[M];
long long dis[1<<N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int k;
		cin >> cost[i] >> k;
		for(int j=0;j<k;j++) {
			int x;
			cin >> x;
			mask[i] |= 1<<(x-1);
		}
	}
	for(int i=0;i<(1<<N);i++) {
		dis[i] = 1e10;
	}
	queue<int> q;
	q.push(0);
	dis[0] = 0;
	while(!q.empty()) {
		int now = q.front();
		q.pop();
		for(int i=0;i<m;i++) {
			int go = mask[i] | now;
			if(dis[go] > cost[i] + dis[now]) {
				dis[go] = cost[i] + dis[now];
				q.push(go);
			}
		}
	}
	if(dis[(1<<n)-1]==1e10) cout << -1;
	else cout << dis[(1<<n)-1];
	return 0;
}


Measured memory_bytes: 640
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]

count = 0

for i in range(n):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (x[i][k] - x[j][k])**2
        if int(int(math.sqrt(a))**2) == a:
            count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {

    string integer;
    char checkValue;
    
    
    cin >> integer;

    checkValue = integer[1];



    if((integer[0] == checkValue && integer[2] == checkValue) || (integer[2] == checkValue && integer[3] == checkValue)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;
ll const MAX_V = 10000;
ll const MAX_E = 10000;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N), b(N), c(M), d(M);

    rep(i, N) cin >> a[i] >> b[i];
    rep(i, M) cin >> c[i] >> d[i];

    rep(i, N) {
        ll dist_min = INF;
        ll idx = -1;
        rep(j, M) {
            ll dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dist < dist_min) {
                dist_min = dist;
                idx = j + 1;
            }
        }
        cout << idx << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e,f,g,h,tc,tl;

    while(cin>>a>>b>>c)
    {

        for(d=1;d<=10;d++)
        {
            e=(a*c)-b;
            cout<<e<<endl;
            c=e;
        }
    }



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;


istringstream input;
int k;


struct elem{
	int sum, rep;
	vector<elem> vec;
	char ch;

	elem( char c, int r )
		: ch(c), sum(1), rep(r) {}
	
	elem( const vector<elem> &v, int r )
		: rep(r), vec(v), ch(0) {
		int s = 0;
		for( int i = 0; i < vec.size(); ++i ){
			s += vec[i].len();
		}
		sum = s;


		rep = min( rep, k / sum + 1 );
	}

	int len(){
		return sum * rep;
	}

	char at( int x ){
		x %= sum;
		if( vec.empty() ){
			if( x == 0 ) return ch;
		}
		else{
			for( int i = 0; i < vec.size(); ++i ){
				if( x < vec[i].len() ){
					return vec[i].at(x);
				}
				x -= vec[i].len();
			}
		}
		
		return '0';
	}
};



elem parse(int rep){
	if( isalpha( input.peek() ) ){
		char c;
		input >> c;
		return elem( c, rep );
	}

	input.ignore();
	vector<elem> v;
	while( input.peek() != ')' ){
		if( isdigit( input.peek() ) ){
			int r;
			input >> r;
			v.push_back( parse( r ) );
		}
		else{
			char c;
			input >> c;
			v.push_back( elem( c, 1 ) );
		}
	}
	input.ignore();
	return elem( v, rep );
}


char solve(){
	while(true){
		input.peek();
		if( input.eof() ) break;

		if( isdigit( input.peek() ) ){
			int r;
			input >> r;
			elem e = parse(r);

			if( k < e.len() ){
				return e.at(k);
			}
			k -= e.len();
		}
		else{
			char c;
			input >> c;
			if( k == 0 ){
				return c;
			}
			--k;
		}
	}
	return '0';
}


int main(){
	string s;
	while(true){
		cin >> s >> k;
		if( s == "0" )
			return 0;

		input.clear();
		input.str(s);
		cout << solve() << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  /*int mi[n+1];
  mi[0]=810;
  rep(i,0,n) mi[i+1]=min(mi[i],a[i]);
  int ma[n+1];
  ma[0]=0;
  rep(i,0,n) ma[i+1]=max(ma[i],a[n-1-i]);
  int ans=1000;
  rep(i,1,n){
    if(mi[i]<ma[n-i]){
      ans=max(ans,1000+(ma[n-1]-mi[i])*(1000/mi[i]));
    }
  }
  cout<<ans<<endl;*/
  ll ans=1000;
  int mi=a[0];
  int ma=a[0];
  
  rep(i,0,n){
    if(ma<a[i]){
      ma=a[i];
    }
    else{
      ans=ans+(ma-mi)*(ans/mi);
      mi=a[i];
      ma=a[i];
    }
  }
  ans=ans+(ma-mi)*(ans/mi);
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n,d,x,p[10][10];
int dp[200001];

int main(){
  cin>>n>>d>>x;
  for(int i=0;i<d;i++)
    for(int j=0;j<n;j++)cin>>p[i][j];
  for(int i=1;i<d;i++){
    for(int j=0;j<=x;j++)dp[j]=j;
    for(int j=0;j<n;j++)
      for(int k=0;k<=x;k++)
	dp[k+p[i-1][j]]=max(dp[k+p[i-1][j]],dp[k]+p[i][j]);
     x=dp[x];
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;
const int maxk = 2000;

int n,k;
int ans=0;
int x[maxn],y[maxn];
char c[maxn+1];
int d[2*maxk][2*maxk]={0};

int main(){
    
    cin >> n>>k;
    rep(i,n){
        cin >> x[i]>>y[i]>>c[i];
        if(c[i]=='B'){
            x[i]+=k;
            c[i]='W';
        }
        x[i]=x[i]%(2*k);
        y[i]=y[i]%(2*k);
        d[y[i]][x[i]]++;
    }
    
    rep(i,2*k){
        rep(j,2*k){
            if(i==0&&j==0){
                continue;
            }else if(i==0){
                d[i][j]+=d[i][j-1];
            }else if(j==0){
                d[i][j]+=d[i-1][j];
            }else{
                d[i][j]+=d[i][j-1]+d[i-1][j]-d[i-1][j-1];
            }
        }
    }
    
    rep(y,k){
        rep(x,k){
            int can = 0;
            if(y==0&&x==0){
                can += d[y+k-1][x+k-1];
            }else if(y==0){
                can += d[y+k-1][x+k-1]-d[y+k-1][x-1];
            }else if(x==0){
                can += d[y+k-1][x+k-1]-d[y-1][x+k-1];
            }else{
                can += d[y+k-1][x+k-1]-d[y+k-1][x-1]-d[y-1][x+k-1]+d[y-1][x-1];
            }
            
            if(x!=0&&y!=0){
                can += d[y-1][x-1];
            }
            if(x!=0){
                can += d[2*k-1][x-1]-d[y+k-1][x-1];
            }
            if(y!=0){
                can += d[y-1][2*k-1]-d[y-1][x+k-1];
            }
            can += d[2*k-1][2*k-1]-d[2*k-1][x+k-1]-d[y+k-1][2*k-1]+d[y+k-1][x+k-1];
            ans = max(ans,max(can,n-can));
            
        }
    }
    
    
    cout << ans<<endl;
    
    return 0;
}



Measured memory_bytes: 33408
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin>>S;

    while(!S.empty()){
        int sz=S.length();
        int a1,a2,a3,a4;
        a1=S.rfind("eraser");
        a2=S.rfind("dreamer");
        a3=S.rfind("erase");
        a4=S.rfind("dream");
        if(sz<=5){
            if(S=="erase"||S=="dream") break;
        }
        if(sz==6) if(S=="eraser") break;
        if(sz==7&&S=="dreamer") break;
        if(a1==sz-6){ S=S.substr(0,a1);continue;}
        if(a2==sz-7){ S=S.substr(0,a2);continue;}
        if(a3==sz-5){ S=S.substr(0,a3);continue;}
        if(a4==sz-5){ S=S.substr(0,a4);continue;}
        
        cout<<"NO"<<endl;
        return 0;
        
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int s,i,j,v[110],n;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>v[i];
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
            s=s+v[i]*v[j];
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import functools

def calc_temp(t, x):
    return (t - x * 0.006)

N = int(input())
T, A = map(int, input().split())
H = list(map(int,input().split()))

T_H = []
for i in range(len(H)):
    T_H.append(calc_temp(T, H[i]))

list_A = [A] * N

#print(T_H)
#print(list_A)

diff_T_H = []
for i in range(len(H)):
    diff_T_H.append(abs(T_H[i] - list_A[i]))

#diff_T_H_array = np.array(T_H) - np.array(list_A)
#diff_T_H = diff_T_H_array.tolist()
#print(diff_T_H)
min_index = diff_T_H.index(min(diff_T_H)) + 1
print(min_index)


Measured memory_bytes: 12452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){   
  ll A,B,N;
  cin >> A >> B >> N;
  if(N < B - 1) cout << A*N/B - A*(N/B) << endl;
  else cout << A*(B-1)/B - A*((B-1)/B) << endl;
  
  
  
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}
int m, a, r, c, h;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;

	string s[n];
	zip(i, 0, n) cin >> s[i];
	map<char, int>mt;
	int x = 0;

	zip(i, 0, n)
	{
		char y = s[i][0];
		if (y == 'M')
			m++;
		else if (y == 'A')
			a++;
		else if (y ==  'R')
			r++;
		else if (y == 'C')
			c++;
		else if (y == 'H')
			h++;
	}
	cout << m*a*r + a*r*c + r*c*h + m*r*c + m*r*h + m*c*h + a*c*h + m*a*h + m*a*c + a*r*h << en;


	return 0;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int x;
    cin>>x;
    if ( 360 % x ){
        int cnt = 1;
        int i = -x;
        while( i % 360 != 0 ){
            i -= x;
            cnt++;
        }
        cout<<cnt<<endl;
    }
    else{
        cout<<360/x<<endl;
    }

}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

/*
正面衝突の場合 U-D, L-R
斜め衝突の場合 U-L, L-D, D-R, R-U





*/


int X[1<<18], Y[1<<18];
char D[1<<18];
vector<pair<int, char>> V1[1<<19];
vector<pair<int, char>> V2[1<<19];

int n;

int solve_UR(){
	for (int i = 0; i <= 500000; i++) V1[i].clear();
	for (int i = 1; i <= n; i++) {
		if (D[i] != 'R' && D[i] != 'U') continue;
		V1[X[i] + Y[i]].push_back(make_pair(X[i], D[i]));
	}
	int Answer = (1<<24);
	for (int i = 0; i <= 500000; i++) {
        sort(V1[i].begin(), V1[i].end());
		for (int j = 0; j < (int)V1[i].size() - 1; j++) {
			if (!(V1[i][j].second == 'R' && V1[i][j + 1].second == 'U')) continue;
			Answer = min(Answer, V1[i][j + 1].first - V1[i][j].first);
		}
	}
	return Answer * 10;
}



int solve_UD(){
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V2[i].clear();
	for (int i = 1; i <= n; i++) {
		if (!(D[i] == 'L' || D[i] == 'R')) continue;
		V2[Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V2[i].begin(), V2[i].end());
		for (int j = 0; j < (int)V2[i].size() - 1; j++) {
			if (!(V2[i][j].second == 'R' && V2[i][j + 1].second == 'L')) continue;
			Answer = min(Answer, V2[i][j + 1].first - V2[i][j].first);
		}
	}
	return Answer * 5;
}


void rotate(){
    int tmp;
    rep1(i, n){
        tmp = X[i];
        X[i] = 200000-Y[i];
        Y[i] = tmp;
        if (D[i] == 'U') D[i] = 'L';
        else if (D[i] == 'L') D[i] = 'D';
        else if (D[i] == 'D') D[i] = 'R';
        else D[i] = 'U';
    }
    
}


int main()
{
    cin >> n;
    rep1(i, n){
        cin >> X[i] >> Y[i] >> D[i];
    }

    int t_time = 2000001;    
    rep(t, 4){
        t_time = min(t_time, solve_UD());
        t_time = min(t_time, solve_UR());
        rotate();
    }

    if (t_time == 2000001) cout << "SAFE" << endl;
    else cout << t_time << endl;

}



Measured memory_bytes: 42732
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
    long long n, k;
    cin >> n >> k;

    vector<long long> a(n);
    for(long long i = 0; i < n; i++) cin >> a[i], a[i]--;

    long long now = 0;

    if(k <= n){
        for(long long i = 0; i < k; i++){
            now = a[now];
        }
        printf("%lld\n", now+1);
    }
    else{
        vector<bool> visit(n, false);
        visit[now] = true;
        long long start;
        long long dist;
        for(long long i = 1; i <= n; i++){
            now = a[now];
            if(visit[now] == true){
                dist = i;
                start = now;
                break;
            }
            visit[now] = true;
        }

        now = start;
        vector<long long> v;
        v.push_back(now);
        for(long long i = 1; i <= n; i++){
            now = a[now];
            if(now == start){
                break;
            }
            v.push_back(now);
        }

        long long ans = v[(k-dist)%v.size()];
        printf("%lld\n", ans+1);
    }
    return 0;
}

Measured memory_bytes: 5676
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> vp(m);
	rep(i, m){
		int s, c;
		cin >> s >> c;
		vp.at(i) = make_pair(s, c);
	}
	rep(i, 1000){
		string is = to_string(i);
		if(is.size() != n) continue;
		bool flag = true;
		rep(j, m){
			if(is[vp.at(j).first-1] - '0' != vp.at(j).second){
				flag = false;
				break;
			}
		}
		if(flag == true){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = reads()

S = [0] * (N+1)
for i in range(N):
  S[i+1] = S[i] + A[i]

d = defaultdict(int)
for s in S:
  d[s] += 1

ans = sum(v * (v - 1) // 2 for v in d.values())

print(ans)


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

#define dv(i) for (int c=0; c<(int)(i).size(); c++) cout<<(i)[c]<<(c==(int)(i).size()-1?"\n":" ")
#define dm(i) for (auto f: i) cout<<f.first<<" "<<f.second<<"\n"
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define alp(i) (i),(i)+sizeof((i))/sizeof((i)[0])

const int MOD = 1000000007;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N; cin>>N;
    ll ret=0;
    FOR(i,0,N) {
        ll cur; cin>>cur;
        while (cur%2==0) {
            cur/=2; ret++;
        }
    }
    cout<<ret<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL n,k;
LL a[105];
LL dp[105][100005] = {0};
LL pre[100005] = {0};

int main(){
	scanf("%lld %lld",&n,&k);
	for(LL i = 1;i <= n;i ++) scanf("%lld",&a[i]);
	for(LL i = 1;i <= n;i ++){
		pre[0] = 1; for(LL j = 1;j <= k;j ++) pre[j] = (pre[j - 1] + dp[i - 1][j]) % N;
		for(LL j = 0;j <= k;j ++){
			LL del = 0;
			if(j - a[i] > 0) del = pre[max(0LL,j - a[i] - 1)];
			dp[i][j] = pre[j] - del;
			dp[i][j] = (dp[i][j] + N) % N;
		}
	}
	printf("%lld\n",dp[n][k]);
	return 0;
}
//

Measured memory_bytes: 79360
import sys

# 全体
s = input()
s_len = len(s)

# 部分
t = input()
t_len = len(t)

results = []

for start in range(0, s_len - t_len + 1):
    cut = s[start:start + t_len]
    diff_count = 0
    for i in range(0, t_len):
        if cut[i] != t[i]:
            diff_count += 1
    results.append(diff_count)

print(min(results))


Measured memory_bytes: 9124
#pragma GCC optimize "-Ofast"
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 3e2 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

ld dp[maxN][maxN][maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, cnt[4];
	memset(cnt, 0, sizeof cnt);
	cin >> n;
	for (int i = 0; i < n; i++){
		int inp;
		cin >> inp;
		cnt[inp] += 1;
	}
	for (int k = 0; k < maxN; k++){
		for (int j = 0; k + j < maxN; j++){
			for (int i = 0; k + j + i < maxN; i++){
				if (i + j + k == 0) continue;
				if (i) dp[i][j][k] += 1.0 * i * dp[i - 1][j][k];
				if (j) dp[i][j][k] += 1.0 * j * dp[i + 1][j - 1][k];
				if (k) dp[i][j][k] += 1.0 * k * dp[i][j + 1][k - 1];
				dp[i][j][k] += 1.0 * n;
				dp[i][j][k] /= 1.0 * (i + j + k);
			}
		}
	}
	cout << fixed << setprecision(10);
	cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
	return 0;
}



Measured memory_bytes: 221440
#include<cstdio>
#include<cctype>
#define getc (l==r&&(r=(l=c)+fread(c,1,1<<21,stdin),l==r)?EOF:*l++)

char c[1<<21],*l=c,*r=c;
inline int read() {
	int x=0; char ch=getc;
	while (!isdigit(ch)) ch=getc;
	while (isdigit(ch)) { x=x*10+(ch^48); ch=getc; }
	return x;
}

const int N=200010;
int n,q,cnt,last[N],s[N];
struct Edge { int y,pre; }E[N<<1];
void dfs(int x,int fa,int sum) {
	s[x]+=sum;
	for (int j=last[x]; j; j=E[j].pre)
		if (E[j].y!=fa) dfs(E[j].y,x,s[x]);
}
int main() {
	n=read(); q=read();
	for (int i=1; i<n; ++i) {
		int x=read(),y=read();
		E[++cnt]=(Edge){y,last[x]}; last[x]=cnt;
		E[++cnt]=(Edge){x,last[y]}; last[y]=cnt;
	}
	while (q--) { int p=read(),x=read(); s[p]+=x; }
	dfs(1,-1,0);
	for (int i=1; i<=n; ++i) printf("%d ",s[i]);
	return 0;
}

Measured memory_bytes: 15360
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp
import itertools as it
import functools
import math

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

K = ri()

@functools.lru_cache()
def Sx(i):
  return i/sum(int(s) for s in str(i))

def gen():
  diff = 1
  n = 1
  while True:
    if Sx(n) <= Sx(n+diff):
      yield n
      n += diff
    else:
      n -= diff
      diff *= 10
      n += diff

for n in it.islice(gen(),K):
  print(n)

Measured memory_bytes: 3956
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-all-loops")
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long int LL;

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

int N;
LL L, R, k, p, Ans;

struct node
{
	LL l, r;
	void give(LL _l, LL _r)
	{
		l = _l, r = _r;
	}
};
int tot;
node v[3];

void dfs(int p, int cnt, LL l, LL r)
{
	if (p == tot)
	{
		if (cnt)
			if (cnt & 1)
			{
				if (l <= r)
					Ans += r - l + 1LL;
			}
			else
			{
				if (l <= r)
					Ans -= r - l + 1LL;
			}
		return ;
	}
	dfs(p + 1, cnt, l, r);
	dfs(p + 1, cnt + 1, max(l, v[p].l), min(r, v[p].r));
}

int main()
{
	gi(L), gi(R);
	if (N == 1 || L == R)
		Ans = R - L + 1LL;
	else
	{
		for (k = 59LL;k >= 0LL;--k)
			if ((L & (1LL << k)) ^ (R & (1LL << k)))
				break;
			else
			{
				if (L & (1LL << k))
					L -= (1LL << k);
				if (R & (1LL << k))
					R -= (1LL << k);
			}
		tot = 0;
		v[tot++].give(L, R);
		for (LL p = 59LL;p >= 0LL;--p)
			if ((1LL << k) + (1LL << p) <= R)
			{
				v[tot++].give(1LL << k, (1LL << k) + (1LL << (p + 1LL)) - 1LL);
				break;
			}
		v[tot++].give(L + (1LL << k), (1LL << (k + 1LL)) - 1LL);
		Ans = 0LL, dfs(0, 0, 0LL, 1LL << 60LL);
	}
	print(Ans), putc('\n');
	return 0;
}
/*
考虑把L和R的二进制位从高到低写下来，去掉最长公共前缀，特判掉L = R的情况，那么L的最高位 = 0、R的最高位 = 1，设最高位是k，有L < 2^k <= R
分如下几段考虑：
(1)[L, R]一定在答案中
(2)找到最大p使得2^k + 2^p <= R，容易发现对于所有0 <= i <= p都有L < 2^k + 2^i <= R，故[2^k, 2^k + 2^(p + 1))在答案中
(3)考虑[L, 2^k)中的数，显然让它们or上> 2^k的数是没有任何意义的。故[L + 2^k, 2^(k + 1))在答案中
把这三段求并即可 
*/

Measured memory_bytes: 2304
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
have_money = 1000
have_stock = 0
have_stock_valuation = 0
call_status = True

def buy_stock(have_money, have_stock, have_stock_valuation, stock_price):
    stock_num = have_money // stock_price
    have_money -= stock_num * stock_price
    have_stock += stock_num
    have_stock_valuation += stock_num * stock_price

    return have_money, have_stock, have_stock_valuation

def sell_stock(have_money, have_stock, have_stock_valuation, stock_price):
    have_money += have_stock * stock_price
    have_stock = 0
    have_stock_valuation = 0

    return have_money, have_stock, have_stock_valuation

for i in range(N):

        if call_status:
            if i == N - 1:
                continue
            if A[i] < A[i+1]:
                have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                call_status = False
            if not call_status:
                if have_stock_valuation / have_stock < A[i]:
                    have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                    call_status = True
        else:
            if have_stock_valuation / have_stock < A[i]:
                have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                call_status = True
            if call_status:
                if i == N - 1:
                    continue
                if A[i] < A[i+1] and call_status:
                    have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                    call_status = False
        
print(have_money)

Measured memory_bytes: 27088
from itertools import accumulate
N, M = map(int, input().split())

left = 1
right = N

for i in range(M):
    a,b = map(int, input().split())
    left = max(left,a)
    right = min(right, b)

print(max(0,right-left+1))

# imos = [0] * (N + 2)
# for i in range(M):
#     l, r = map(int, input().split())
#     imos[l] += 1
#     imos[r + 1] -= 1
#
# imos = list(accumulate(imos))
#
# ans = 0
# for im in imos:
#     ans += (im == M)
#
# print(ans)


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 300010, M = 1010;

int n, m;
int h[N], e[N], ne[N], idx;
int q[N], dist[N];
int s, t;

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

int bfs(int st, int ed)
{
	int hh = 0, tt = -1;
	dist[st] = 0;
	q[ ++ tt] = st;
	
	while (hh <= tt)
	{
		int t = q[hh ++ ];
		
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			if (dist[j]) continue;
			
			q[ ++ tt] = j;
			dist[j] = dist[t] + 1;
			
			if (j == ed) break;
		}
	}

	if (dist[ed]) return dist[ed] / 3;
	else return -1;
}

int main()
{
	memset(h, -1, sizeof h);
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i ++ )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		add(a * 3, b * 3 + 1);
		add(a * 3 + 1, b * 3 + 2);
		add(a * 3 + 2, b * 3);
	}
	
	scanf("%d%d", &s, &t);
	printf("%d\n", bfs(s * 3, t * 3));
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h;
    cin >> h;
    int k = 0;
    while (h != 0) {
        h /= 2LL;
        k++;
    }
    eprintf("%d\n", k);
    cout << (1LL << k) - 1LL << "\n";
    return 0;
}

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

namespace ABC157
{
    class B
    {
        static int[] grid;
        static void Main(string[] args)
        {
            grid = new int[9];
            int[][] a;
            a = new int[3][];
            for (int i = 0; i < 3; i++)
            {
                a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }
            int n = int.Parse(Console.ReadLine());
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                b[i] = int.Parse(Console.ReadLine());
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (a[j][k] == b[i]) { grid[3*j+k] = 1; }
                    }
                }
            }
            string ans = "No";
            if (grid[0] == 1)
            {
                if (grid[1] == 1){if (grid[2] == 1) { ans = "Yes"; }}
                if (grid[3] == 1) { if (grid[6] == 1){ ans = "Yes"; } }
                if (grid[4] == 1) { if (grid[8] == 1) { ans = "Yes"; } }
            }
            if (grid[1] == 1) { if (grid[4] == 1 && grid[7] == 1) { ans = "Yes"; } }
            if (grid[2] == 1) 
            { 
                if (grid[4] == 1 && grid[6] == 1) { ans = "Yes"; } 
                if (grid[5] == 1 && grid[8] == 1) { ans = "Yes"; } 
            }
            if (grid[3] == 1) { if (grid[4] == 1 && grid[5] == 1) { ans = "Yes"; } }
            if (grid[6] == 1) { if (grid[7] == 1 && grid[8] == 1) { ans = "Yes"; } }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, d;
  int ans = 0;
  cin >> a >> b >> c >> d;
  for(int i=0; i<=100; ++i){
    if(i >= a && i >= c && i <= b && i <= d) ++ans;
  }
  cout << (ans == 0 ? 0 : --ans) << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N)cin >> A[i];
  ll sum=0;
  rep(i,N) sum += A[i];
  ll sumnoa = 0;
  for(int i=1;i<=N-2;i+=2){
    sumnoa += 2*A[i];
  }
  vector<ll> ans(N);
  ans[0]=sum-sumnoa;
  for(int i=1;i<N;i++){
    ans[i] = 2*A[i-1]-ans[i-1];
  }
  rep(i,N){
    cout << ans[i];
    if(i==N-1)break;
    cout << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
import sys
line = sys.stdin.readline()
line = line.split(" ")
inp = []
for i in line:
    inp.append(int(i))

a,b,c=inp[0],inp[1],inp[2]

if (a==b+c):
    print ("Yes")
elif (b==a+c):
    print ("Yes")
elif (c==a+b):
    print ("Yes")
else:
    print ("No")


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

using namespace std;

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

	int n;
	cin >> n;

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (0 <= i && i < 10) {
			ans++;
		}
		if (100 <= i && i < 1000) {
			ans++;
		}
		if (10000 <= i && i < 100000) {
			ans++;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define all(v) v.begin(), v.end()


int main(){
  ll t1,t2,a1,a2,b1,b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if(t1*a1+t2*a2==t1*b1+t2*b2){
    cout << "infinity" << endl;
  }else if((a1>b1&&t1*a1+t2*a2>t1*b1+t2*b2)||(a1<b1&&t1*a1+t2*a2<t1*b1+t2*b2)){
    cout << 0 << endl;
  }else if(a1>b1){
    if(((a1-b1)*t1)%(t1*b1+t2*b2-t1*a1-t2*a2)==0){
      cout << (((a1-b1)*t1)/(t1*b1+t2*b2-t1*a1-t2*a2))*2 << endl;
    }else{
      cout << (((a1-b1)*t1)/(t1*b1+t2*b2-t1*a1-t2*a2))*2+1 << endl;
    }
  }else{
    if(((b1-a1)*t1)%(t1*a1+t2*a2-t1*b1-t2*b2)==0){
      cout << (((b1-a1)*t1)/(t1*a1+t2*a2-t1*b1-t2*b2))*2 << endl;
    }else{
      cout << (((b1-a1)*t1)/(t1*a1+t2*a2-t1*b1-t2*b2))*2+1 << endl;
    }
  }
    
}

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

long long pow(long long a,long long b,long long mod){
    if(b==0){
        return 1;
    }else{
        if(b%2==0){
            return pow(a*a%mod,b/2,mod);
        }else{
            return pow(a*a%mod,b/2,mod)*a%mod;
        }
    }

}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int K;
    cin>>K;
    string S;
    cin>>S;
    int n=S.size();
    long long mod=1000000007;

    long long ans=0;
    long long comb=1;
    long long pl;
    for(int i=0;i<=K;i++){
        pl=pow(25,i,mod);
        pl*=comb;
        pl%=mod;
        pl*=pow(26,K-i,mod);
        pl%=mod;
        ans+=pl;
        ans%=mod;
        comb*=(n+i);
        comb%=mod;
        comb*=modinv(i+1,mod);
        comb%=mod;
        //cout<<"comb:"<<comb<<endl;
    }
    if(ans<0){
        while(ans<0){
            ans+=mod;
            ans%=mod;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5280
#include<stdio.h>

int main() {
	char s1[7] = { 'S','u','n','n','y' };
	char s2[7] = { 'C','l','o','u','d','y' };
	char s3[7] = { 'R','a','i','n','y' };
	char n[7] = { 0 };
	
	scanf("%s", n);
	
	if(*n==*s1) puts(s2);
	else if (*n == *s2) puts(s3);
	else if (*n == *s3) puts(s1);
	else return 1;
	
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000007LL
using namespace std;

int main()
{
	long long int n, m, x,x1, y,y1, xsum=0, ysum=0;
	scanf("%lld %lld", &n, &m);
	for(long long int k=1; k<=n; k++){
		scanf("%lld", &x);
		if(k==1){
			x1=x;
		}else{
			xsum=(xsum+(x-x1)*(k-1)%INF*(n-k+1)%INF)%INF;
			x1=x;
		}
	}
	for(long long int k=1; k<=m; k++){
		scanf("%lld", &y);
		if(k==1){
			y1=y;
		}else{
			ysum=(ysum+(y-y1)*(k-1)%INF*(m-k+1)%INF)%INF;
			y1=y;
		}
	}
	printf("%lld\n", xsum*ysum%INF);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s, t;
  cin >> s >> t;
  int n = s.size();

  string ans = s;
  rep(i, 0, n) {
    if (ans == t) {
      cout << "Yes" << endl;
      return 0;
    }

    ans.erase(n - 1);
    ans = s[n - i - 1] + ans;
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
int main() {
	std::string abe;
	std::cin >> abe;
	int k = 0, u = 0, p = 0, c = 0;
	for (int i = 0; i < abe.size(); ++i) {
		if (abe[i] == 'K')++k;
		if (abe[i] == 'U')++u;
		if (abe[i] == 'P')++p;
		if (abe[i] == 'C')++c;
	}
	std::cout << std::min(std::min(k, u), std::min(p, c)) << std::endl;
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct st{
	long long  a,b;
}s[100005];
int cmp(st x,st y){
	return x.a<y.a;
}

long long sum=0,n,m;

int main()
{
	cin >> n >>m;
	for(long long  i=0;i<n;i++) {
		cin >> s[i].a>>s[i].b;
	}
	sort(s,s+n,cmp) ;
	for(long long i=0;i<n;i++){
		if(m>0){
			if(m>=s[i].b) {
			sum+=s[i].a*s[i].b;
			m-=s[i].b;
			}
			else {
				sum+=s[i].a*m;
				break;
			}
		}
	}
	cout<<sum; 
	return 0;
}

Measured memory_bytes: 1792
N=int(input())
A=[int(i) for i in input().split()]
X=[-1,-1,-1]
ans=1
mod=10**9+7
for i in range(N):
    tmp=0
    if A[i]>i:
        ans=0
    for j in range(3):
        if X[j]==A[i]-1:
            tmp+=1
    for j in range(3):
        if X[j]==A[i]-1 or tmp==0:
            ans=tmp*ans
            ans%=mod
            X[j]+=1
            break
print(ans)


Measured memory_bytes: 14396
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var Q = int.Parse(Console.ReadLine());
            var dict = new Dictionary<long, long>();
            var answer = 0L;
            for (var i = 0; i < A.Length; i++)
            {
                if (dict.ContainsKey(A[i])) dict[A[i]]++;
                else dict[A[i]] = 1L;
                answer += A[i];
            }

            for (var i = 0; i < Q; i++)
            {
                var BC = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
                var B = BC[0];
                var C = BC[1];
                if (!dict.ContainsKey(B)) dict[B] = 0L;
                if (!dict.ContainsKey(C)) dict[C] = 0L;
                dict[C] += dict[B];
                answer += (C - B) * dict[B];
                dict.Remove(B);
                Console.WriteLine(answer);
            }
        }
    }
}


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


int main() {

    long int n;
    cin>>n;
    long long sum=0;
    for(int i=1; i<=n; i++) {
        if(i%3==0)
            sum=sum;
        else if(i%5==0)
            sum=sum;
        else if(i%3==0&&i%5==0) {
            break;
        } else {
            sum=sum+i;
        }
    }

    cout<<sum<<endl;


    return 0;
}



Measured memory_bytes: 3632
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N, L = LI()

A = [x for x in range(L, L+N)]
A.sort(key=lambda x : abs(x))

print(sum(A[1:]))


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

int main(){
  vector<int> S = {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;
  cin >> K;
  cout << S.at(K-1) << endl;
}

Measured memory_bytes: 256
program ABC116B
    implicit none
    integer(8)::i=2
    integer(8)::j
    integer(8)::flg=0
    integer(8),dimension(1000000)::A

    read(5,*)A(1)

    do
        if(mod(A(i-1),2)==0)then
            A(i)=A(i-1)/2
        else
            A(i)=3*A(i-1)+1
        end if

        do j=1,i-1
            if(A(j)==A(i))then
                flg=1
                exit
            end if
        end do

        if(flg==1)then
            exit
        end if

        i=i+1
    end do
    
    print'(i0)',i

end program ABC116B

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  long long int n,k,a,b;
  scanf("%lld%lld",&n,&k);
  a=n%k;
  b=a-k;
  b=0-b;
  if(a<b){
    printf("%lld\n",a);
  }else{
    printf("%lld\n",b);
  }
  return 0;
}


Measured memory_bytes: 128
s=input()
a=0
for x in range(len(s)-1):
    if x%2==0: continue
    for y in range(0,int((x+1)/2)):
        if(s[y]!=s[int((x+1)/2)+y]): break
        if(y==(x-1)/2): a=2*(y+1)
print(a)

Measured memory_bytes: 2940
N,M,Q = map(int,input().split())
l = [[0 for i in range(N)] for j in range(N)]
 
for _ in range(M):
    L,R = map(int,input().split())
    l[L-1][R-1] += 1
 
csum = [[0 for i in range(N+1)] for j in range(N+1)]
 
for i in range(1,N+1):
    for j in range(1,N+1):
        csum[i][j] = csum[i][j-1] + csum[i-1][j] - csum[i-1][j-1] + l[i-1][j-1]
 
for _ in range(Q):
    p,q = map(int,input().split())
    print(csum[q][q]-csum[q][p-1]-csum[p-1][q]+csum[p-1][p-1])

Measured memory_bytes: 20732
# ?????§??¬?´???°?????????????????????????????????????????????
def gcd(x, y)
  r = x % y
  return y if r == 0
  gcd(y, r)
end

# ?????§??¬?????°
def lcm(x, y, gcd)
  return (x * y) / gcd
end

array = []
while line = gets do
  x, y = line.split.map(&:to_i)
  gcd = gcd(x, y)
  lcm = lcm(x, y, gcd)
  puts "#{gcd} #{lcm}"
end

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll N, M;
    cin >> N >> M;
    vll A(M), B(M);
    rep(i, M) cin >> A[i] >> B[i];

    vll p(N+1);
    rep(i, N+1) p[i] = i;
    
    function<ll(ll)> root = [&](ll x){
        if(p[x]==x) return x;
        return p[x] = root(p[x]);
    };

    rep(i, M){
        ll ra = root(A[i]);
        ll rb = root(B[i]);
        if(ra==rb) continue;
        p[ra] = rb;
    }

    vll cnts(N+1, 0);
    rep(i, N+1) ++cnts[root(i)];
    ll ans = *max_element(all(cnts));
    cout << ans << endl;
}


Measured memory_bytes: 18668
H, W = map(int, input().split())
field = []
mines = []
for ridx in range(H):
    row = list(input())
    field.append([])
    for cidx in range(W):
        is_mine = row[cidx] == '#'
        field[-1].append('#' if is_mine else 0)
        if is_mine:
            mines.append((ridx, cidx))

for m in mines:
    for i in range(-1, 2):
        for j in range(-1, 2):
            if m[0] + i >= 0 and m[0] + i < H and m[1] + j >= 0 and m[1] + j < W and isinstance(field[m[0] + i][m[1] + j], int):
                field[m[0] + i][m[1] + j] += 1

for r in field:
    print(''.join([str(e) for e in r]))


Measured memory_bytes: 3188
N, K = [int(i) for i in input().split()]
sunuke = [False] * N

for i in range(K):
    d = int(input())
    target_list = list(input().split())
    for k in target_list:
        sunuke[int(k)-1] = True
    
#print("**")
print(N-sum(sunuke))

Measured memory_bytes: 9180