akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
using namespace std;
bool a[200001], b[200001];
int  c, m, x, y;
int  main() {
	cin >> c >> m;
	for(int i= 0; i < m; i++) {
		 cin >> x >> y;
		 if(x == 1) a[y]= 1;
		 if(y == c) b[x]= 1;
	}
	for(int i= 1; i <= c; i++) {
		 if(a[i] && b[i]) {
			 printf("POSSIBLE\n");
			 return 0;
		 }
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

//Unequal Dice
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		double e = 0;
		while(t--!=0){
			sc.next();
			int m = sc.nextInt();
			double[][] a = new double[m][2];
			double r = 0;
			for(int i=0;i<m;i++){
				a[i][0] = sc.nextDouble(); a[i][1] = sc.nextDouble();
				r+=a[i][1];
			}
			double p = 0;
			for(int i=0;i<m;i++)p+=a[i][0]*a[i][1]/r;
			e = Math.max(e, p);
		}
		sc.nextInt();
		int q = sc.nextInt();
		double x = 0, r = 0;
		double[][] a = new double[q][2];
		for(int i=0;i<q;i++){
			a[i][0] = sc.nextDouble(); a[i][1] = sc.nextDouble();
			r+=a[i][1];
		}
		for(int i=0;i<q;i++)x+=a[i][0]*a[i][1]/r;
		System.out.println(x+1e-7<e?"YES":"NO");
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;

#define pb emplace_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define in1(a,n) F(i,1,n)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<"\n";cout<<endl
#define ff first
#define ss second
#define F(i,a,b) for (ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,n) F(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

#define mod 1000000007

ll add(ll a, ll b){return (a%mod + b%mod)%mod;}
ll sub(ll a , ll b){return (a%mod - b%mod + mod)%mod;}
ll mul(ll a, ll b){return (a%mod * b%mod)%mod;}
ull poww(ull a,ull b){ull res=1;while(b){if(b&1){res*=a;}a=a*a;b>>=1;}return res;}
ll poww(ll a,ll b,ll MOD){ll res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define dbg(x) cout<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define dbg4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;

//end of template

const int N = 1e5 + 5;

ll a[N];

int main(int argc, char const *argv[])
{
	crap;
	ll n, m ;
	cin >> n >> m;
	in(a, n);
	priority_queue< pair<ll, ll > > pq;
	rep(i, n){
		pq.push(mp(a[i], 1));
	}
	rep(i, m){
		ll b, c;
		cin >> b >> c;
		pq.push(mp(c, b));
	}

	ll ans = 0 ;
	ll f = 0;
	while (!pq.empty()){
		pair<ll, ll> t = pq.top();
		pq.pop();
		ll v = t.ff, num = t.ss; 
		if ( f < n ){
			ll diff = n - f;
			diff = min(diff, num);
			ans += diff * v;
			f += diff;
		}
		if (f == n)
			break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7024
# include <bits/stdc++.h>
using namespace std;
long long n,k;
string s;
int main()
{
	cin>>n>>k;
	cin>>s;
	for (int i=0; i<s.size(); i++)
	{
		if (i+1==k) 
		{
			if (s[i]=='A') cout<<'a';
			if (s[i]=='B') cout<<'b';
			if (s[i]=='C') cout<<'c';
		}
		else
		cout<<s[i];
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  int mass[31],ans[31];
  for(i=0;i<31;i++){
    mass[i]=0;
    ans[i]=0;
  }
  int a[n+1],b;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b=a[i];
    for(j=0;j<31;j++){
      if(mass[j]+b%2==1)
        mass[j]=1;
      else
        mass[j]=0;
      b/=2;
    }
  }
  for(i=0;i<n;i++){
    int j=0,count=0,num=1;
    b=a[i];
    for(j=0;j<31;j++){
      if(mass[j]+b%2==1)
        count+=num;
      num*=2;
      b/=2;
    }
    printf("%d ",count);
  }
  return 0;
}


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

int a[30], s;
void solve(int x, int left) {
	if (!x)rep(i, s)cout << a[i] << (i == s - 1 ? '\n' : ' ');
	for (int i = min(x, left); i > 0; i--) {
		a[s++] = i; solve(x - i, i); s--;
	}
}
int main() {
	int n;
	while (cin >> n, n) { s = 0; solve(n, n); }
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
int run_test(){
	ll a, b;
	cin >> a >> b;
	ll g = __gcd(a, b);
	//now I have to find all the prime factors of g
	int count = 0;
	for(int i=2; i<=sqrt(g); i++){
		if(g % i == 0){
			count++;
			while(g % i == 0){
				g /= i;
			}
			if(g == 1) break;//this means all the prime numbers have been visited 
			//there is no need of looping over remaining elements
		}
	}//what if after looping, still g is not equal to 1
	//this means that g is a prime number which divides the gcd(a,b)
	//therefore add 1 to the count
	if(g != 1) count++;
	cout << count + 1;
	return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

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

int main(){
	int N;
	cin >> N;
	if(N == 1){
		cout << "Yes" << endl;
		return 0;
	}
	vector<int> H(N);
	for(int i = 0; i < N; i++)cin >> H.at(i);
	bool jdg = true;
	
	for(int i = N - 1; i > 1; i--){
		if(H.at(i) < H.at(i - 1)){
			H.at(i - 1)--;
		} else {
			continue;
		}
		if(H.at(i) < H.at(i - 1)){
			jdg = false;
			break;
		}
	}
	
	if(jdg) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>

#define pai 3.14159265358979323846264338327950288
using namespace std;


// Battle
//*
int main() {

	int a, b, c, d;
	cin >> a>> b>> c>> d;
	int cnt = 0;

	while (1) {		
		if (cnt % 2 == 0) {
			c -= b;
		}
		else {
			a -= d;
		}

		if (c<1) {
			cout << "Yes";
			break;
		}
		else if(a<1) {
			cout << "No";
			break;
		}
		cnt++;
	}
	

	return 0;
}
//*/


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

int main()
{


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

	if (a > b)
		cout << "a > b" << endl;
	if (a < b)
		cout << "a < b" << endl;
	if (a == b)
		cout << "a == b" << endl;



	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<int> a(n);
    for(int i=0;i<n;++i)
      cin>>a[i];
    int cnt=0;
    for(int i=0;i<n;++i)
      for(int j=0;j<n-1;++j)
        if(a[j]>a[j+1]){
          swap(a[j],a[j+1]);
          ++cnt;
        }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    int i;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int ans(0);
    int maxn(0);
    rep(i, n) maxn = max(a[i], maxn);
    vector<int> used(maxn+1, 0);
    xrep(i, 1, n) if (a[i] == a[i-1]) {
        int in = a[i];
        used[a[i]] = 1;
        while (in <= maxn) {
            used[in] = 1;
            in += a[i];
        }
    }
    rep(i, n) {
        int in = a[i];
        if (!used[in]) {
            ans++;
            while (in <= maxn) {
                used[in] = 1;
                in += a[i];
            }
        }
    }
    cout << ans << endl;
}


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

int main(){
    int a[3][3];
    int che[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
            che[i][j] = 0;
        }
    }

    int n;
    cin >> n;

    int b[n];
    for(int i = 0; i < n; i++){
        cin >> b[i];
        for(int k = 0; k < 3; k++){
            for(int j = 0; j < 3; j++){
                if(a[k][j] == b[i]){
                    che[k][j] = 1;
                }
            }
        }
    }

    int flag = 0;
    for(int i = 0; i < 3; i++){
        flag = 0;
        for(int j = 0; j < 3; j++){
            if(che[i][j] == 1){
                flag++;
            }
        }

        if(flag == 3){
            break;
        }
    }

    if(flag != 3){
        for(int i = 0; i < 3; i++){
            flag = 0;
            for(int j = 0; j < 3; j++){
                if(che[j][i] == 1){
                    flag++;
                }
            }

            if(flag == 3){
                break;
            }
        }
    }

    if(flag != 3){
        flag = 0;
        if(che[0][0] == 1){
            flag++;
        }
        if(che[1][1] == 1){
            flag++;
        }
        if(che[2][2] == 1){
            flag++;
        }
    }

    if(flag != 3){
        flag = 0;
        if(che[2][0] == 1){
            flag++;
        }
        if(che[1][1] == 1){
            flag++;
        }
        if(che[0][2] == 1){
            flag++;
        }
    }

    if(flag == 3){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
from itertools import product
import math
D,G = map(int,input().split())

pc = []
for i in range(D):
    pc.append(list(map(int, input().split())))

#pc.sort(key=lambda x:x[1])

ans = 1001
# 各セットをコンプするか否かでまずループ
for comp in product(range(2), repeat=D):
    
#    print(comp)

    #コンプしたものだけでOKな場合はその数を既存の回答数と比較して小さい方を保存
    num_ans = 0
    score = 0
    max_index = -1 #コンプしないセットで1問あたりの特典が最大のセット番号
    for i in range(D):
        if comp[i]:
            num_ans +=pc[i][0]
            score += 100*(i+1)*pc[i][0]+pc[i][1]
        else:
            max_index = i
            
    
    if score >= G:
        ans = min(ans, num_ans)
    else:
        #コンプしたものだけではNGな場合
        #コンプしていない各セットについて全探索して最小値を保存
        #このときコンプしていないセットのなかで個別の特典が一番高いものだけ見ればOK
        if score + 100*(max_index+1)*(pc[max_index][0]-1) >= G:
           num_ans += math.ceil((G-score)/(100*(max_index+1)))
           ans = min(ans, num_ans)
#    if ans == 60:
#        print(comp)

print(ans)

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		for (int i = 0; i < n; i++) {
		    String city = scan.next();
		    int point = scan.nextInt();
		    sp[i] = city + "," + (1100 - point) + "," + (i+1);
		}
		scan.close();
		Arrays.sort(sp);
		for (String s: sp) {
		    String ans = s.split(",")[2];
		    System.out.println(ans);
		}
	}
}

Measured memory_bytes: 22356
! https://beta.atcoder.jp/contests/abc097/submissions/3768076

module UnionFind
    implicit none
    public
        type :: Union_Find
            integer,allocatable,dimension(:) :: par
        end type Union_Find
    contains
        subroutine init(p,n)
            implicit none
            type(Union_Find)  p
            integer n,i
            allocate( p%par(n) )
            do i=1,n
                p%par(i) = i
            enddo
        end subroutine init
        recursive function root(p,n) result(ret)
            implicit none
            type(Union_Find) p
            integer ret,n
            if(p%par(n)==n)then
                ret = n
                return
            else
                p%par(n) = root(p,p%par(n))
                ret = p%par(n)
                return
            endif
        end
        subroutine unite(p,a,b)
            implicit none
            type(Union_Find) p
            integer a,b
            a = root(p,a)
            b = root(p,b)
            if(a/=b)then
                p%par(a) = b
            endif
        end
end module UnionFind

program atcoder_abc97d
    use UnionFind
    implicit none
    type(Union_Find) a
    integer n,m,i,x,y,ans
    integer,allocatable,dimension(:) :: p
    read*,n,m
    allocate( p(n) )
    call init(a,n)

    read(*,*)(p(i),i=1,n)
    do i = 1,m
        read*,x,y
        call unite(a,x,y)
    enddo

    ans = 0
    do i=1,n
        if(root(a,p(i))==root(a,i))then
            ans = ans+1
        endif
    enddo
    write(*,'(I0)')ans
!----------------------functions--------------------------
contains
end program atcoder_abc97d

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	int n = s1.length();
	int m = s2.length();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
			}
			else if(s1[i-1] == s2[j-1])
			{
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string res = "";
	int ind = dp[n][m];
	int i=n,j=m;
	while(i>0 && j>0)
	{
		if(s1[i-1] == s2[j-1])
		{
			res += s1[i-1];
			i--;
			j--;
			ind--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
	}
	reverse(res.begin(),res.end());
	if(res.size()==0)
	{
		cout<<" ";
		return 0;
	}
	cout<<res<<"\n";
	return 0;
}	
			
		


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


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	ll n = s.length();
	if (s[n - 1] == 's')
		cout << s << "es";
	else
		cout << s << "s";
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void)

{

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(H>=y+r&&W>=x+r&&x-r>=0&&y-r>=0)

{

printf("Yes\n");

}

else

{

printf("No\n");

}

return 0;

}

Measured memory_bytes: 584
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    rep(i,k){
        if(b<=a){
            b*=2;
        }else if(c<=b){
            c*=2;
        }else{
            c*=2;
        }
    }
    if(c>b&&b>a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    


    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 3;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;

 void solve () {
 	int n, k; cin >> n >> k;
 	int mk = k + 1;
 	vector<int> h(mk);
 	vector<int> dp(mk, 1e9 + 100);

 	dp[0] = 0;
 	cin >> h[0];

 	for (auto i = 1; i < n; ++i) {
 		auto cur = i % mk;
 		cin >> h[cur];
 		dp[cur] = 1e9 + 100;
 		for (int j = i - 1; j >= i - k and j >= 0; --j) {
 			auto prev = j % mk;
 			auto a = abs(h[cur] - h[prev]);
 			dp[cur] = min(dp[cur], a + dp[prev]);
 		}
 	}

 	cout << dp[(n - 1) % mk];
 }



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int> > x(N, vector<int>(D));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < D; j++) {
            cin >> x.at(i).at(j);
        }
    }

    int count = 0;

    for(int i = 0; i < N; i++) {
        for(int k = i+1; k < N; k++) {
            double len = 0.0;
            for(int j = 0; j < D; j++) {
                len += pow(x.at(i).at(j) - x.at(k).at(j), 2);
            }
            len = sqrt(len);
            int leng = (int)len;
            if(len - (double)leng == 0) {
                count++;
            }
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 256
N,M=map(int, input().split())
H=list(map(int, input().split()))
li = [[0] for i in range(N+1)]

for i in range(M):
    a,b=map(int, input().split())
    li[a].append(b)
    li[b].append(a)
sum = 0

for i in range(N):
    if len(li[i+1]) == 1:
        sum += 1
    else:
        n = False
        for j in range(len(li[i+1])-1):

            if H[i] <= H[li[i+1][j+1]-1]:
                n = True
                break
        if n == False:

            sum+=1

print(sum)

Measured memory_bytes: 95952
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
 int a,b,k;
  cin >> a >> b >> k;
  vector<int> vec(min(a,b)+2);
  for(int i=1;i<min(a,b)+1;i++){
    if(a%i==0&&b%i==0){
      vec.at(i)=i;
    }
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(min(a,b)+2-k) << endl;
}

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

int main()
{
	string s,t,t1;
	long long k;
	cin >> s;
	cin >> k;
	int l = s.length();
	t = s;
	t1 = s;
	long long ans1 = 0,ans2 = 0,ans3 = 0;
	for(int i = 1; i < l; i++){
		if(t[i] == t[i - 1]){
			ans1++;
			t[i] = '0';
		}
	}
	if(s[0] != s[l - 1])
		ans2 = ans1;
	else{
		if(s[0] == t[l - 1]){
			s[0] = '0';
			ans2++;
		}
		for(int i = 1; i < l; i++){
			if(s[i] == s[i - 1]){
				ans2++;
				s[i] = '0';
			}
		}
	}
	if(t1[0] == s[l - 1]){
		t1[0] = '0';
		ans3++;
	}
	for(int i = 1; i < l; i++){
		if(t1[i] == t1[i - 1]){
			ans3++;
			t1[i] = '0';
		}
	}
	long long sum = ans1 + (ans3 + ans2) * ((k - 1) / 2);
	if((k - 1) % 2 == 1)
		sum += ans2;
	cout << sum << endl;
	return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double ld;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
    #define debug true
    #define ln << endl
#else
    #define debug false
    #define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '



signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    long X;
    scanf("%lld", &X);

    int x = sqrt(abs(X) * 2);

    cout << (x * (x+1) / 2 >= X ? x : x+1) ln;

    return 0;
}


Measured memory_bytes: 256
using System;using System.Linq;
class A{static void Main(){
int n=int.Parse(Console.ReadLine());
int max=-1;
int oh=0;
for(int i=0;i<n;i++){string y=Console.ReadLine();
int []a=y.Split().Select(int.Parse).ToArray();
if(a[1]==max){oh=Math.Min(a[0],oh);}
else if(a[1]>max){max=a[1];oh=a[0];}

}
Console.WriteLine(oh+" "+max);

}}

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

int gcd(int x,int y){
    if(x%y==0){
        return y;
    }else{
        return(gcd(y,x%y));
    }
}

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

    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans=a[0];
    for(int i=1;i<n;i++){
        ans = gcd(ans,a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
X = int(input())
if X <= 599:
  print("8")
elif X <= 799:
  print("7")
elif X <= 999:
  print("6")
elif X <= 1199:
  print("5")
elif X <= 1399:
  print("4")
elif X <= 1599:
  print("3")
elif X <= 1799:
  print("2")
else:
  print("1")

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


int get_first_digit(int a) {
    // Input num is assumed to be below 1000.
    int ans = a;
    ans = ans % 100;
    ans = ans % 10;
    return ans;
}

int main() {
    vector<int> nums(5); for (int i = 0; i < 5; i++) cin >> nums[i];

    int ans = 0;
    int ones_place = 10;
    for (auto elem : nums) {
        int one_p = get_first_digit(elem);
        if (one_p == 0) {
            ans += elem;
        } else {
            ans += elem - one_p + 10;
            if (one_p < ones_place) {
                ans -= ones_place;
                ans += 10;
                ones_place = one_p;
                ans += ones_place;
                ans -= 10;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

char dealing(string str,int test)
{
	int len = str.length();
	stack<int> num;
	stack<char> yun;
	for(int i=len-1;i>=0;--i)
	{
		if(str[i]>='0'&&str[i]<='9')
		{
			int j = i;
			int sum = 0;
			int by = 1;
			while(j>=0)
			{
				if(str[j]>='0'&&str[j]<='9')
				{
					sum+=by*(str[j]-'0');
					by*=10;
					j--;
				}
				else{
					i =j+1;
					break;
				}
			}
			num.push(sum);
			if(j<0)
			break;
		}
		else
			yun.push(str[i]);
		
	}
	
	int result_left_to_right =0;
	int result_normal = 0;
	
		stack<int> num_copy(num);
	stack<char> yun_copy(yun);
	
	int num_len = num.size();
	result_left_to_right  = num.top();
	num.pop();
	

	
	
	for(int i=1;i<num_len;++i)
	{
		char cc = yun.top();
		yun.pop();
		int num1 = num.top();
		num.pop();
		if(cc=='+')
		result_left_to_right +=num1;
		else
		result_left_to_right *=num1;
	}
	
	//cout<<result_left_to_right <<endl;
	
	stack<int> result_nor;
	
	int q= num_copy.top();
	num_copy.pop();
	
	for(int i=1;i<num_len;++i)
	{
		char cc;
		cc = yun_copy.top();
		yun_copy.pop();
		
		int num1 = num_copy.top();
		num_copy.pop();
		
		
		if(cc=='*')
		q = q*num1;
		else
		{
			result_nor.push(q);
			q = num1;
		}
		
	}
	result_nor.push(q);
	int sizes = result_nor.size();
	for(int i=0;i<sizes;++i){
		result_normal+=result_nor.top();
		result_nor.pop();
	}
	
//cout<<"test"<<result_normal<<endl;
	
	
	if(test==result_left_to_right&&test!=result_normal)
		return 'L';
	if(test!=result_left_to_right&&test==result_normal)
	return 'M';
	if(test==result_left_to_right&&test==result_normal)
	return 'U';
	if(test!=result_left_to_right&&test!=result_normal)
	return 'I';
	return 'I';
}

int main()
{
	string str;
	int num;
	cin>>str;
	cin>>num;
	cout<<dealing(str,num)<<endl;
	
	return 0;
	
	
}

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

string S;
int dp[511][511];
int solve(int l,int r){
  if( dp[l][r] != -1 ) return dp[l][r];
  if( l > r ) return true;
  if( S[l] == 'm' && S[r] == 'w' )
    for(int i=l+1;i<r;i++)
      if( S[i] == 'e' )
	if( solve(l+1,i-1) && solve(i+1,r-1) ) return dp[l][r] = 1;	
  return dp[l][r] = 0;
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin >> S;
  if( solve(0,S.size()-1) )
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
  
}

Measured memory_bytes: 2220
// inputに入力データ全体が入る
function Main(input) {
	var a = parseInt(input, 10);
	var b=Math.floor(a/500);
  var c=Math.floor((a%500)/5);
  var ans=b*1000+c*5;
  console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<ll> vec;
    rep(i,n){
        int h;cin >> h;
        vec.push_back(h);
    }
    bool ok = true;
    for(int i=0;i<vec.size()-1;i++){
        if (vec[i]>vec[i+1]) ok = false;
        if (vec[i+1]==vec[i])continue;
        if (vec[i+1]>vec[i]) vec[i+1] -= 1;

    }
    if (ok) cout << "Yes" << endl;
    else cout  << "No" << endl;
    
}

Measured memory_bytes: 1400
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll dp[101][110][310];

int main() {
    int n, p;
    cin >> n >> p;
    VL w(n), v(n);
    REP(i,n) scanf("%lld %lld", &w[i], &v[i]);

    REP(i,n) REP(j,n) REP(k,300){
        int x = w[i] - w[0];
        dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
        // if (k + x >= 300) continue;
        dp[i+1][j+1][k+x] = max(dp[i+1][j+1][k+x], dp[i][j][k] + v[i]);
    }
    ll ans = 0;
    REP(j,n+1) REP(k,300){
        if (w[0] * j + k > p) continue;
        ans = max(ans, dp[n][j][k]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    int n,m;
    cin >> n >> m;  
    int cnt = 0;
    vector<vector<int>> d(m);
    vector<int> val(m);
    vector<int> digit(n,0);
    vector<int> hantei(n,1);
    REP(i,m){
        int cnt;
        cin >> cnt;
        d[i] = vector<int>(cnt);
        REP(j,cnt)
            cin >> d[i][j]; 
    } 
    REP(i,m)
        cin >> val[i];

    while(1){
        bool flag = true;
        REP(i,m){
            int num = 0;
            REP(j,d[i].size()){
                if(digit[d[i][j] - 1] == 1)
                    num++;
            }
            if(num % 2 != val[i])
                flag = false;
        }
        if(flag)
            cnt++;

        if(hantei == digit)
            break;
        digit[0] += 1;
        REP(i,n){
            if(digit[i] == 2){
                digit[i + 1] += 1;
                digit[i] = 0;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{
	ll a[5];
	fo(i,5)
	{
		ll x;cin>>x;
		if(x==0){
			cout<<i+1;
			return;
		}
	}

}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(100001);
	int x,ans=0;
	rep(i,n){
		cin >> x;
		if(x>100000) ans++;
		else a[x]++;
	}
	rep(i,100001){
		if(a[i]!=0){
			if(a[i]>i) ans+=a[i]-i;
			else if(a[i]<i) ans+=a[i];
		}
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    REP(i,0,W+2) {
        S[0] += ".";
        S[H+1] += ".";
    }
    REP(i,1,H+1) {
        cin >> S[i];
        S[i] = "." + S[i] + ".";
    }
    
    bool f = true;
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            if(S[i][j] == '#') {
                if(S[i-1][j] == '.' && S[i+1][j] == '.' && S[i][j-1] == '.' && S[i][j+1] == '.') {
                    f = false;
                    break;
                }
            }
        }
        if(!f) break;
    }
    if(f) PR("Yes");
    else PR("No");


    return 0;
}

/*



*/

Measured memory_bytes: 3584
N = int(input())
L = list(map(int,input().split()))
cnt = 0

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            #print(str(i+1)+" "+str(j+1)+" "+str(k+1)+" "+str(L[i])+" "+str(L[j])+" "+str(L[k])+" "+str(cnt))
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            elif L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
                cnt += 1
                
print(cnt)

Measured memory_bytes: 9152
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let a: u64 = itr.next().unwrap().parse().unwrap();
    let b: f64 = itr.next().unwrap().parse().unwrap();
    let c: u64 = (b * 100.0 + 0.5) as u64;
    println!("{}", a * c / 100);
}


Measured memory_bytes: 2176
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int h = stdIn.nextInt();
		int a = stdIn.nextInt();
		
		int ans = (h+a-1)/a;
		System.out.println(ans);
		



	}

}


Measured memory_bytes: 23124
#include <iostream>

using namespace std;

struct node {
    int id;
    int left;
    int right;
};

void print_node(const node& n){
    cout << " " << n.id;
}

void preorder(node* ns, int r){
    print_node(ns[r]);
    if(ns[r].left >= 0){
        preorder(ns, ns[r].left);
    }
    if(ns[r].right >= 0){
        preorder(ns, ns[r].right);
    }
}

void inorder(node* ns, int r){
    if(ns[r].left >= 0){
        inorder(ns, ns[r].left);
    }
    print_node(ns[r]);
    if(ns[r].right >= 0){
        inorder(ns, ns[r].right);
    }
}

void postorder(node* ns, int r){
    if(ns[r].left >= 0){
        postorder(ns, ns[r].left);
    }
    if(ns[r].right >= 0){
        postorder(ns, ns[r].right);
    }
    print_node(ns[r]);
}

int main(){
    int n;
    cin >> n;
    node ts[n];
    auto fs = new bool[n];
    for(int i = 0; i < n; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        node n = node {a, b, c};
        ts[a] = n;
        if(b >= 0){
            fs[b] = true;
        }
        if(c >= 0){
            fs[c] = true;
        }
    }
    int root = -1;
    for(int i = 0; i < n; ++i){
        if(!fs[i]){
            root = i;
            break;
        }
    }
    cout << "Preorder" << endl;
    preorder(ts, root);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(ts, root);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(ts, root);
    cout << endl;
}

Measured memory_bytes: 1192
//AtCoder ABC104 C - All Green
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll BinarySearch(ll low, ll high, std::function<bool(ll)> check){
    if(high-low<=1){
        return high;
    }
    ll mid = (high+low)/2; 
    //cout<<mid<<" ,"<<low<<","<<high<<endl;
    if(check(mid)){
        //return BinarySearch(mid, high, check);
        return BinarySearch(low, mid, check);
    }else{
        //return BinarySearch(low, mid, check);
        return BinarySearch(mid, high, check);
    }
}
struct Data{
    ll p; //問題数
    ll sc; //点数
    ll b; //ボーナス
    ll scb; //全部といた点数
    //bool flag=false;
    void use(){
        sc=0;
        scb=0;
        //flag=true;
    }
};
#if 1
ll search(ll num,ll score,const vector<Data>& pd,ll use_flag){
    if (num<=0) return score;
    ll ret_score=0;
    for(ll i=0;i<pd.size();++i){
        auto&& d=pd[i];
        ll uf=1<<i;
        if (use_flag&uf)continue;
        if(num>=d.p){
            ret_score=std::max(search(num-d.p,score+d.scb,pd,use_flag|uf),ret_score);
        } else {
            ret_score=std::max(search(0,score+d.sc*num,pd,use_flag|uf),ret_score);
        }
    }
    return ret_score;
}
#else
#endif
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
#if LOCAL&0
    std::ifstream in("input.txt");
    //std::ifstream in("./test/sample-2.in");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll D,G; cin>>D>>G;
    vector<Data> pd;
    pd.reserve(D+1);
    ll ttl_p_num=0;
    for(ll i=1;i<=D;++i){
        ll p,c; cin>>p>>c;
        Data dat;
        dat.p=p;
        dat.sc=100*i;
        dat.b=c;
        dat.scb=c+100*i*p;
        pd.push_back(dat);
        ttl_p_num+=p;
    }
    ll sc=0;
    ll num=0;
    // while(sc<G){
    //     //auto tmp=pd;//copy
    //     ++num;
    //     sc=search(num,0,pd,0);
    // }
	num = BinarySearch(0, ttl_p_num,
					   [&](ll mid) { return (search(mid, 0, pd, 0) >= G); });
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	ll n; cin >>n;
	ll sum=0;
	ll cnt=-1;
	for(int i=1;;i++){
		sum+=i;
		if(n<=sum){
			cnt=i;
			break;
		}
	}
	for(int i=1;i<=cnt;i++){
		if(sum-i!=n)cout << i <<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(void)
{
	int num;
	long int sec, push[200000], ans = 0, plus;
	scanf("%d %ld", &num, &sec);
	for (int i = 0; i < num; i++) {
		scanf("%ld", &push[i]);
	}
	ans += sec;
	plus = 0;
	for (int i = 1; i < num; i++) {
		if (push[i] - push[i - 1] < sec) {
			plus += push[i] - push[i - 1];
		}
		if (plus) {
			ans += plus;
			plus = 0;
		}
		else {
			ans += sec;
		}
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>
#include <stdint.h>

int main() {

  uint8_t str[101] = {};
  scanf("%s", str);
  uint32_t len = strlen((char *)str);

  uint32_t count[26] = {};
  for(uint32_t i=0;i<len;i++)
    count[str[i] - 'a']++;

  for(uint32_t i=0;i<26;i++) {
    if(count[i] % 2) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] num = new int[5];
		for(int i = 0;i < 5;i++){
			num[i] = scan.nextInt();
		}
		for(int i = 0;i < 4;i++){
			for(int j = i+1;j < 5;j++){
				if(num[i] < num[j]){
					int t = num[i];
					num[i] = num[j];
					num[j] = t;
				}
			}
		}
		for(int i = 0;i < 5;i++){
			if(i != 4){
				System.out.print(num[i] + " ");
			}else{
				System.out.println(num[i]);
			}
		}
	}
}

Measured memory_bytes: 12000
from collections import Counter, defaultdict


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

# Do one step to reduce the list to only 0, 1, or 2
# All subsequent steps will only contain 0, 1, or 2
A = [abs(x - y) for x, y in zip(A, A[1:])]
N -= 1


def solve(A):
    N = len(A)

    def fact(n):
        if n == 0:
            return 1
        return n * fact(n - 1)

    def nCr(n, r):
        return fact(n) // (fact(n - r) * fact(r))

    def nCrMod2(n, r):
        return 0 if (n ^ r) & r else 1
        # See https://brilliant.org/wiki/lucas-theorem/
        while r:
            if r % 2 and not n % 2:
                return 0
            n //= 2
            r //= 2
        return 1

    onlyZeroesAndTwos = Counter(A)[1] == 0

    ans = None
    if onlyZeroesAndTwos:
        ans = 2 * (sum(nCrMod2(N - 1, i) * (A[i] // 2) for i in range(N)) % 2)
    else:
        ans = sum(nCrMod2(N - 1, i) * A[i] for i in range(N)) % 2

    if False:
        import numpy as np

        # Absolute difference and mod 4 sum is almost the same:
        #         abs(x - y)   (x + y) % 4
        # 0, 0    0            0
        # 0, 2    2            2
        # 2, 2    0            0
        #
        # 0, 1    1            1
        # 1, 2    1            3
        #
        # 1, 1    0            2
        #
        # When the list only contains 0 and 2, can just use mod 4 sum exactly
        # When the mod 4 sum answer is odd, know the real answer is 1?

        # nextVec[i] = (vec[i] + vec[i + 1]) % 4
        mat = np.zeros((N, N), dtype=np.int64)
        for i in range(N - 1):
            mat[i][i] = 1
            mat[i][i + 1] = 1

        vec = np.array(A, dtype=np.int64)

        for t in range(N):
            M = np.linalg.matrix_power(mat, t)
            print("t", t)
            print("M^t", M)
            print("v_t", np.matmul(M, vec)[: N - t] % 4)
            print()
        # By inspection, it turns out the M^(N - 1) * v is just the corresponding row of the pascal triangle
        for i in range(N):
            assert np.linalg.matrix_power(mat, N - 1)[0][i] == nCr(N - 1, i)

        mod4 = sum(nCr(N - 1, i) * A[i] for i in range(N)) % 4

        # If there are no ones, mod4 is the exact answer (either 0 or 2)
        ans2 = mod4
        if not onlyZeroesAndTwos:
            # If there are ones, answer is either 0 or 1
            # The answer is 1 if mod4 is 1 or 3
            ans2 = mod4 % 2
        # Check fast and slow way
        assert ans == ans2
    return ans


print(solve(A))

if False:
    # Test
    from itertools import product

    for N in range(2, 7):
        print("N", N)

        groups = defaultdict(list)
        for A in product([0, 1, 2], repeat=N):
            temp = list(A)
            for i in range(N - 1):
                temp = [abs(x - y) for x, y in zip(temp, temp[1:])]
            assert len(temp) == 1
            groups[temp[0]].append(A)

        for k, v in groups.items():
            print("ans", k)
            for A in v:
                assert k == solve(A)
                print("\t", A)
        print()


Measured memory_bytes: 127924
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
constexpr ll MOD = 1e9 + 7;



int main(){
    int h, n;
    cin >> h >> n;
    ll sum = 0;
    rep(i, n){
        ll x;
        cin >> x;
        sum += x;
    }
    if(h <= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	int n,q;
	int m;
	
	while(cin>>n>>q,n!=0||q!=0){
		int p[120]={0};
		int e=10000;
		bool f=false;
		for(int i=0;i<n;i++){
			cin>>m;
			int a;
			for(int j=0;j<m;j++){
				cin>>a;
				p[a]++;
			}
		}
		int max=0;
		int d=0;
		for(int i=0;i<101;i++){
			if(p[i]>=q&&p[i]>max){
				max=p[i];
				d=i;
			}
		}
		cout<<d<<endl;
	
	}
	

}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int r = sc.nextInt();
		int D = sc.nextInt();
		int x = sc.nextInt();

		long ans = x;

		for(int i=0;i<10;i++){
			ans = ans*r-D;

			// 出力
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

const int MAX_N = 200'050;

vector<int> G[MAX_N];
long long dp[MAX_N]; //長さiの増加部分列の末尾として取りうる最小値をdp[i]として持つ
long long ans[MAX_N];

void dfs(int v, vector<long long>& a, int p = -1){
  int index = lower_bound(dp, dp + MAX_N, a[v]) - dp;
  long long old_val = dp[index];
  dp[index] = a[v];
  ans[v] = lower_bound(dp, dp + MAX_N, INF) - dp - 1;
  for(int nv: G[v]){
    if(nv == p) continue;
    dfs(nv, a, v);
  }
  dp[index] = old_val;
  return;
}

int main(){
  //using namespace std;
  int n;
  cin>>n;
  vector<long long> a(n);
  REP(i, n) cin>>a[i];
  int u[n - 1], v[n - 1];
  REP(i, n - 1){
    cin>>u[i]>>v[i];
    u[i]--; v[i]--;
  }
  
  REP(i, n - 1){
    G[u[i]].push_back(v[i]);
    G[v[i]].push_back(u[i]);
  }
  REP(i, MAX_N) dp[i] = INF;
  dp[0] = -INF;
  
  dfs(0, a);
  
  REP(i, n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 34808
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll x = n-1;
	ll h = 0;
	for(ll i = 0; i < n -1 ; i++){
		if(s[i]== 'W'){
			for(ll j = x; j >= 0; j --){
				
			if(s[j] == 'R' || j == 0){
				x = j;
				break;
			}
			
		}
		if(s[i] == 'W' && s[x] == 'R' & x > i){
			swap(s[x], s[i]);
			h ++;
			x --;
		}
		}
		
	}
	cout << h;
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  string S;
  cin >> S;
  vector<int> ans(2, 0);
  for(char c:S)
  {
    if(c-'0') ++ans[0];
    else ++ans[1];
  }
  cout << 2*min(ans[0],ans[1]) << endl;
  return 0;
}


Measured memory_bytes: 512
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
$b = explode(' ', trim(fgets(STDIN)));
$c = explode(' ', trim(fgets(STDIN)));

$satisfied = 0;

foreach ($a as $key => $value) {
  $i = $value - 1;

  if ( (isset($latest)) && ($value == ($latest + 1)) ) {
    $satisfied = $satisfied + $b[$i] + $c[$i - 1];
  } else {
    $satisfied = $satisfied + $b[$i];
  }
  $latest = $value;
}

echo $satisfied;


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

int main()
{
	string s, t;
  	cin >> s >> t;
  	int n = s.size();
  	for(int i = 0; i < n; i++)
    {
    	if(i != n - 1 && s.at(i) == t.at(i))
        {
        	continue;
        }
      	else if(i == n - 1 && s.at(i) == t.at(i))
        {
        	cout << "Yes" << endl;
        }
      	else
        {
        	cout << "No" << endl;
          	break;
        }
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  string s;cin>>s;
  string t=s.substr(0,s.size()/2);
  string u=t,v=s;;
  reverse(u.begin(),u.end());
  reverse(v.begin(),v.end());
  if(t==u&&v==s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <array>

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

using lli = long long int;

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

constexpr lli inf = 2e18;
constexpr int iinf = 1e9;
constexpr int N = 300;
std::array<std::array<lli, N>, N> Dist;
std::array<std::array<int, N>, N> Time;


int main(void){
    int n, m, L; scanf("%d%d%d", &n, &m, &L);
    REP(i, n) REP(j, n) {Dist[i][j] = inf; Time[i][j] = iinf;}
    REP(i, m){
        int a, b, c; scanf("%d%d%d", &a, &b, &c); a--; b--;
        Dist[a][b] = c;
        Dist[b][a] = c;
    }
    REP(k, n) REP(i, n) REP(j, n) chmin(Dist[i][j], Dist[i][k] + Dist[k][j]);
    REP(i, n) REP(j, n) if(Dist[i][j] <= L) Time[i][j] = 1;
    REP(k, n) REP(i, n) REP(j, n) chmin(Time[i][j], Time[i][k] + Time[k][j]);

    int Q; scanf("%d", &Q);
    while(Q--){
        int s, t; scanf("%d%d", &s, &t); s--; t--;
        if(Time[s][t] == iinf) puts("-1");
        else printf("%d\n", Time[s][t] - 1);
    }
    return 0;
}


Measured memory_bytes: 1536