akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
using namespace std;

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

	int n;
	cin >> n;
	
	string s;
	cin >> s;

	vector<int> todo;
	int i = 0;
	while (i < n) {
		if (i < n - 1) {
			if (s[i] == s[i + 1]) {
				todo.push_back(2);
				i += 2;
			}
			else {
				todo.push_back(1);
				i++;
			}
		}
		else {
			todo.push_back(1);
			i++;
		}
	}

	long long ans = 1;
	if (todo[0] == 1) ans = 3;
	else ans = 6;

	for (i = 1; i < todo.size(); ++i) {
		if (todo[i] == 1) {
			if (todo[i - 1] == 1) ans *= 2;
		}
		else {
			if (todo[i - 1] == 1) ans *= 2;
			else ans *= 3;
		}
		ans %= MOD;
	}

	cout << ans;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int n;
signed main() {
  cin >> n;
  for(int i=111;i<1000;i+=111){
  	if(i>=n){cout<<i<<endl;return 0;}
  }
}


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

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t;
	while (scanf("%d", &t) != EOF)
	{
		int count = 0, i;
		char str[51];
		for (i=0; i<t; i++)
			cin>>str[i];
		for (i=0; i<t;)
		{
			if (str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C')
			{
				count++;
				i+=2;
			}
			else
				i++;
		}
		cout<<count<<endl;
	}	
	return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 3000 + 100;
const int MOD = 1000000000 + 7;

int n, m;
char s[MAXN];
int sum[MAXN];
int f[MAXN][MAXN], rig[MAXN];

void add(int &x, int y)
{
	x = (x + y) % MOD;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	cin >> (s + 1);
	for(int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + (s[i] == '1');
	for(int i = 1; i <= n; i++)
		rig[i] = i;
	for(int i = 1; i <= m; i++)
	{
		int l, r;
		cin >> l >> r;
		rig[l] = max(rig[l], r);
	}
	for(int i = 1; i <= n; i++)
		rig[i] = max(rig[i], rig[i - 1]);

	// for(int i = 1; i <= n; i++)
	// 	cerr << i << ' ' << rig[i] << endl;

	f[0][0] = 1;
	for(int i = 0; i <= n - 1; i++)
		for(int j = 0; j <= rig[i] - i + 1; j++)
			if(f[i][j])
			{
				int a = j + sum[rig[i + 1]] - sum[rig[i]];
				int b = rig[i + 1] - (i + 1) + 1 - a;
				if(a >= 1)
					add(f[i + 1][a - 1], f[i][j]);
				if(b >= 1)
					add(f[i + 1][a], f[i][j]);
			}
	int ans = f[n][0];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int countDigits(ll n) {
  int ans = 0;
  while (n > 0) {
    n /= 10;
    ++ans;
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  int ans = INF;
  for (ll a = 1; a * a <= n; ++a) {
    if (n % a != 0) continue;
    ll b = n / a;
    ans = min(ans, countDigits(max(a, b)));
    // cout << a << " " << b << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
	int n,k,q;
	cin >> n;
	cin >> k;
	cin >> q;
	vector<int> a(n);

	for(int i=0;i<n;i++){
		a[i]=k-q;
	}

	for(int i=0;i<q;i++){
		int a_i;
		cin>>a_i;
		//全探索を行い一々、減らしていたようでは
		//O(n^2)になってしまう。
		//なので、あらかじめ、減らしておいて
		//[a_i-1]部のみを増やす事によりO(n)に落とし込める。
		a[a_i-1]++;
	}

	// for(int i=0;i<q;i++){
	// 	int a_i;
	// 	cin >> a_i;
	// 	for(int j=0;j<n;j++){
	// 		if(a_i-1!=j){
	// 			a[j]= a[j]-1;
	// 		}
	// 	}
	// }

	for(int i=0;i<n;i++){
		if(a[i]>0){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}

}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int A[1000];
int dupA[1000];
int pos[10001];
int dupPos[10001];
bool checked[1000];

int main()
{
	int N;
	int mini = 100000;
	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		dupA[i] = A[i];
		pos[A[i]] = i;
		dupPos[A[i]] = pos[A[i]];
		mini = min(mini, A[i]);
	}

	sort(A, A + N);

	int cost = 0;
	for (int i = 0; i < N; i++)
	{
		if (checked[i])
		{
			continue;
		}
		int mini2 = 100000, counter = 0, now = i, sum = 0;
		
		while (true)
		{
			if (checked[now])
			{
				break;
			}
			checked[now] = true;
			mini2 = min(mini2, A[now]);
			sum += A[now];
			counter++;
			now = pos[A[now]];
		}
		cost += min(sum + mini2*(counter - 2), sum + mini + mini2 + mini*counter);
	}

	cout << cost << endl;

	return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    ll ans=0;
    if(A[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=1;i<N;i++){
        if(A[i]==0) continue;
        if(A[i]-A[i-1]>1){
            cout<<-1<<endl;
            return 0;
        }
        if(A[i]==A[i-1]){
            if(A[i]==1)ans++;
            else ans+=A[i];
            continue;
        }
        else if(A[i]-A[i-1]==1) ans++;
        else ans+=A[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
a = []
while True:
    try:
        a.append(int(input()))
    except EOFError:
        break
for i in a:
    frag = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a + b + c + d == i:
                        frag += 1
    print(frag)



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

int main(){
    string A,B;
    cin >> A >> B;
    if(A==B){
        cout << "EQUAL" << endl;
    }
    else{
        if(A.size()>B.size()){
            cout << "GREATER" << endl;
            return 0;
        }
        else if(B.size()>A.size()){
            cout << "LESS" << endl;
            return 0;
        }
        for(int i=0;i<A.size();i++){
            if(A[i]>B[i]){
            cout << "GREATER" << endl;
            return 0;
            }
            if(B[i]>A[i]){
            cout << "LESS" << endl;
            return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int N, ans =0, rep = 0;
    cin >> N;
    vector<int> v(0);
    while(N){
        int stair;
        cin >> stair;
        v.push_back(stair);
        --N;
    }
    REP(i, v.size()-1){
        if(v[i] >= v[i+1]) ++rep;
        else{
            if (rep > ans) ans = rep;
            rep = 0;
        }        
    }
    if (rep > ans) ans = rep;
    cout << ans;
 }




Measured memory_bytes: 892
from collections import defaultdict

H, W = map(int, input().split())
cnt = defaultdict(int)

for _ in range(H):
    a = list(input())
    
    for ai in a:
        cnt[ai] += 1

four = 0
odd = 0

for v in cnt.values():
    four += v//4
    odd += v%2
    
if four>=H//2*(W//2) and odd<=1:
    print('Yes')
else:
    print('No')

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

int main() {
  int A[3][3];
  bool M[3][3]{};
  for (int i{}; i < 3; ++i) {
    for (int j{}; j < 3; ++j) {
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  for (int n{}; n < N; ++n) {
    int b;
    cin >> b;
    for (int i{}; i < 3; ++i) {
      for (int j{}; j < 3; ++j) {
        if (A[i][j] == b) M[i][j] = true;
      }
    }
  }

  bool ans{};
  if (
        M[0][0] && M[0][1] && M[0][2] ||
        M[1][0] && M[1][1] && M[1][2] ||
        M[2][0] && M[2][1] && M[2][2] ||
          M[0][0] && M[1][0] && M[2][0] ||
          M[0][1] && M[1][1] && M[2][1] ||
          M[0][2] && M[1][2] && M[2][2] ||
            M[0][0] && M[1][1] && M[2][2] ||
            M[0][2] && M[1][1] && M[2][0]
      )
    ans = true;

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    if (N%2==0){
        cout << N/2 <<endl;
    }else{
        cout << (N+1)/2<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vl a(n+1,0);
    
    rep(i,n){cin>>a[i+1];};
    partial_sum(all(a),a.begin());
    rep(i,n+1){a[i]-=i;a[i]+=k*100001;a[i]%=k;}
    map<ll,ll> mp;
    ll ans=0;
    range(i,0,n+1){
        mp[a[i]]++;
        if(i>=k)mp[a[i-k]]--;
        ans+=mp[a[i]]-1;
    }
    puta(ans);

    return 0;
}

Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {

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

        int cnt = 0;
        for (int x = 0; x <= k; x++) {
            for (int y = 0; y <= k; y++) {
                int z = s - x - y;
                if (0 <= z && z <= k) {
                    cnt++;
                }
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 22868
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    int u[n];
    int s[n];
    rep(i,n)cin>>u[i];
    rep(i,n)cin>>s[i];
    ll mx=0;
    
    rep(i,n){
        ll ans=0;
        for(int j=0;j<=i;j++){
            ans+=u[j];
        }
        for(int j=i;j<n;j++){
            ans+=s[j];
        }
        mx=max(mx,ans);
    }
    cout<<mx<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N+1], b[N+1];
  for (int i = 1; i < N + 1; i++){
    cin >> a[i];
    b[i] = 1;
  }

  for (int i = N; i > 0; i--){
    int s=0;
    for (int j = i; j < N + 1; j+=i){
      s += b[j];
    }
    if (a[i] != s%2){
      b[i] = 0;
    }
  }

  int M = 0;
  for (int i = 1; i < N + 1; i++){
    M += b[i];
  }

  printf("%d\n", M);
  if (M > 0){
    for (int i = 0; i < N + 1; i++){
      if (b[i]==1) printf("%d ", i);
    }
    printf("\n");
  }
  
  
}


Measured memory_bytes: 5160
#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 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 all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int n;
    string s;
    cin>>n;
    cin>>s;

    string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    string ans = "";
    rep(i,0,s.length())
    {
        ans += str[((s[i]-'A') + n)%26];
    }

    cout<<ans<<endl;
}

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

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

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

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 256
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
ma=-10000000000000
for i in range(1,2**10):
    check=[0]*n
    for j in range(10):
        if (i>>j) & 1:
            for k in range(n):
                check[k]+=f[k][j]
    ma_sub=0
    for i in range(n):
        ma_sub+=p[i][check[i]]
    ma=max(ma,ma_sub)
print(ma)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    pair<int, int> pr[m];
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        pr[i] = make_pair(b, a);
    }
    sort(pr, pr + m);
    int ans = 0;
    int cut = 0;
    rep(i, 0, m) {
        if (pr[i].second > cut) {
            cut = pr[i].first - 1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int a[105][105];
int b[105][105];
bool del[105][105];
int n, m;
pii v[105];

int func(int x) {
	return ((x - 1) / m) + 1;
}


const int MAXN = 210; // the maximum value of N

int matched[MAXN + 10]; // matched[v] = -1 if v is not matched, else matched[v] == u, where u is the vertice it matched with
bool vis[MAXN + 10]; // vis[v] = have we visited v before?

// the graph. this code assumes that there are N vertices from 1 to N, and the graph is a bipartite graph

// User's duty: the following data's must be filled by you
int N; // the count of nodes
vector<int> G[MAXN + 10]; // the graph, in adjacency list form
// done

// this function tries to match u with another v
// it returns true if its successful, false if its unsuccessful
// Complexity: jani na :P
bool bpm(int u) {
   for(int v : G[u]) {
      // if we've tried v recently, don't try again
      if(vis[v]) continue;
      vis[v] = true;
      // if v is not used, or I can match matched[v] with another vertice
      // then we can match u with v :)
      if(matched[v] == -1 || bpm(matched[v])) {
         matched[v] = u;
         matched[u] = v;
         return true;
      }
   }
   return false;
}

// return the maximum bipartite matching of the graph
// Complexity: Wikipedia says its O(V * E), so...
int maxBPM() {
   // fill matched with -1, that is, every vertice is unmatched at the beginning
   memset(matched, -1, sizeof(matched));
   int rs = 0; // rs is the count of matches
   for(int u = 1; u <= N; u++) {
      memset(vis, 0, sizeof(vis));
      // try to match u with any vertice
      // if its possible, increase rs
      rs += bpm(u);
   }
   return rs;
}


int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	N = n;
	for(int itr = 1; itr <= m; itr++) {
		for(int i = 1; i <= n + m; i++) {
			G[i].clear();
		}
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				if(del[i][j]) continue;
				G[func(a[i][j])].push_back(i + n);
				G[i + n].push_back(func(a[i][j]));
				// cout << func(a[i][j]) << ' ' << i + n << endl;
			}
		}
		int mat = maxBPM();
		// cout << mat << endl;
		for(int i = 1; i <= n; i++) {
			int r = matched[i] - n;
			// cout << i << ' ' << r << endl;
			for(int j = 1; j <= m; j++) {
				if(del[r][j]) continue;
				if(func(a[r][j]) == i) {
					del[r][j] = true;
					b[r][itr] = a[r][j];
					break;
				}
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			printf("%d ", b[i][j]);
		}
		printf("\n");
	}
	for(int j = 1; j <= m; j++) {
		vector <int> v;
		for(int i = 1; i <= n; i++) {
			v.push_back(b[i][j]);
		}
		sort(v.begin(), v.end());
		for(int i = 1; i <= n; i++) {
			a[i][j] = v[i - 1];
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			printf("%d ", a[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    double ans = 0;
    rep(i,n){
        double d; string s;
        cin >> d >> s;
        if(s == "JPY") ans += d;
        else ans += d * 380000.0;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import log2

ROUND = 10 ** 100
LOG = 33#int(log2(ROUND))

def main():
    S = input()
    #S = "R" * (10 ** 5 - 1) + "L"
    N = len(S)
    to = []
    for _ in range(LOG):
        l = [0] * N
        to.append(l)
    
    for i in range(N):
        to[0][i] = i + 1 if S[i] == "R" else i - 1
    
    for i in range(1, LOG):
        for j in range(N):
            to[i][j] = to[i - 1][to[i - 1][j]]

    ans = [0] * N
    for j in range(N):
        ans[to[LOG - 1][j]] += 1

    L = [str(i) for i in ans]
    print(" ".join(L))
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 39932
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

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

int main(){
    long int w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = (double)(h * w);
    ans /= 2;
    printf("%.15lf ", ans);
    if (2 * x == w && 2 * y == h){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const string YES = "Yes";
const string NO = "No";

int main()
{
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  if (S == T.substr(0, S.size()))
    cout << YES << endl;
  else
    cout << NO << endl;

  return 0;
}


Measured memory_bytes: 3128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int sum = A + B;
        
        System.out.println(sum - C >= 0 ? "Yes" : "No");
    }
}
 

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
  int n,k;
  cin >> n >> k;
  int x[n];
  for(int i=0;i<n;i++) cin >> x[i];
  int ans[n+1];
  for(int i=0;i<n+1;i++) ans[i] = 0;
  for(int i=1;i<=n;i++){
    vector<int> y(k);
    fill(y.begin(),y.end(),0);
    for(int j=1;j<=k;j++){
    	y[j-1] = ans[max(i-j,0)] + abs(x[i-1]-x[max(i-1-j,0)]);
    }
    ans[i] = *min_element(y.begin(),y.end());
  }
  cout << ans[n] << endl;
  return 0;
}
      

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 2e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
 
template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll sum = 0;
    ll ret1 = 0;
    ll ret2 = 0;
    for(int i = 0;i < N;i++) {
        sum += vec.at(i);
        if(i % 2 == 0) {
            if(sum <= 0) {
                ret1 += 1 - sum;
                sum = 1;
            }
        }
        else {
            if(sum >= 0) {
                ret1 += sum + 1;
                sum = -1;
            }
        }
    }
    sum = 0;
    for(int i = 0;i < N;i++) {
        sum += vec.at(i);
        if(i % 2 == 0) {
            if(sum >= 0) {
                ret2 += sum + 1;
                sum = -1;
            }
        }
        else {
            if(sum <= 0) {
                ret2 += 1 - sum;
                sum = 1;
            }
        }
    }
    cout << min(ret1,ret2) << endl;
}

Measured memory_bytes: 640
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        N: usize,
        B: [usize; N-1],
    }
    let mut B = B;

    let mut v2 = vec![MOD];
    for &b in &B {
        v2.push(b);
    }
    B.push(MOD);
    let ans = (0..N).fold(0, |acc, i| acc + min(B[i], v2[i]));
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
  
    ll S;cin>>S;
    if(S<=1000000000){
        cout<<0<<" "<<0<<" "<<S<<" "<<0<<" "<<0<<" "<<1<<endl;
    }else{
        ll x=(S+999999999)/1000000000;
        cout<<0<<" "<<0<<" "<<1000000000<<" "<<1<<" "<<1000000000*x-S<<" "<<x<<endl;
    }
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

const int maxn = (int) 1e5 + 5;
int n, k;
int a[maxn];

int read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

void solve() {
  int g = 0;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    g = gcd(g, a[i]);
    mx = max(mx, a[i]);
  }
  if (k % g == 0 && k <= mx) {
    printf("POSSIBLE\n");
  } else {
    printf("IMPOSSIBLE\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
/*
 * @Autor: valk
 * @Date: 2020-07-17 16:50:40
 * @LastEditTime: 2020-09-19 20:17:25
 * @Description: 如果邪恶  是华丽残酷的乐章 它的终场 我会亲手写上 晨曦的光 风干最后一行忧伤 黑色的墨 染上安详
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int seed = 12289;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int main()
{
    int d, t, s;
    cin >> d >> t >> s;
    int T = d / s;
    if (d % s)
        T++;
    if (t >= T) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

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

int main(){
    int n; cin >> n;
    int e = 0, o = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a %2 == 0) e++;
        else o++;
    }
    if(o%2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
//      freopen("q.gir","r",stdin);
      int n,t;
      cin>>n>>t;
      vector<int> dp(100000,0);
      vector<vector<bool> >vis(t+1,vector<bool>(n,false));
      vector<ii>data;
      for(int i=0;i<n;i++){
            int x,y;
            cin>>x>>y;
            data.pb({x,y});
      }
      for(int i=0;i<t;i++){
            for(int j=0;j<n;j++){
                  if(vis[i][j])continue;
                  if(dp[i]+data[j].second>=dp[i+data[j].first]){
                        dp[i+data[j].first]=dp[i]+data[j].second;
                        int q=i+data[j].first;
                        if(q<vis.size()){
                              vis[q]=vis[i];
                              vis[q][j]=true;
                        }
                  }
            }
      }
      cout<<*max_element(all(dp));
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char[] array = str.toCharArray();
        if(array[2] == array[3] && array[4] == array[5]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
a,b,c,k = input().split()
a = int(a)
b= int(b)
c = int(c)
k = int(k)
sum = 0
if k>0:
	if k>a:
  		sum = sum + a
  		k = k - a
	else:
  		sum = sum + k
  		k = 0
if k>0:
	if k>b:
	  k = k - b
	else:
		k = 0
if k>0:
	sum = sum - k
	k = k - c
print(sum)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> score(n, k - q);
  rep(i, q) {
    int a;
    cin >> a;
    --a;
    score[a]++;
  }
  rep(i, n) {
    if(score[i] <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
       int n, result=0, food=0;
       cin >> n;
       
       vector<int> a(n);
       vector<int> b(n);
       vector<int> c(n-1);
       
       for(int i=0; i < n; i++) cin >> a[i];
       for(int i=0; i < n; i++) cin >> b[i];
       for(int i=0; i < n; i++) cin >> c[i];
       
       for(int i=0; i < n; i++) {
           food = a[i];
           result += b[i];
           if ( a[i]+1 == a[i+1]) {
               result += c[food-1];
           }
       }
       
       cout << result << endl;
       
}

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

int main() {
  int n,m,c,ans=0;
  cin >> n >> m >> c;
  vector<int> b(m);
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<m;i++) cin >> b[i];
  for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];

  for(int i=0;i<n;i++) {
    int x=c;
    for(int j=0;j<m;j++) x+=b[j]*a[i][j];
    if(x>0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

void printData(int data[], int dataNum ) {
    for( int i = 0; i < dataNum; i++ ){
        if( i != 0 ) {
            std::cout << " ";
        }
        std::cout << data[i];
    }
}

int main() {
    int lineCnt;
    std::cin >> lineCnt;

    int data[lineCnt];
    for( int i = 0; i < lineCnt; i++ ){
        std::cin >> data[i];
    }

    int exchangeCnt = 0;
    for( int i = 0; i < lineCnt - 1; i++ ) {
        int curMinIndex = i;
        for( int k = i + 1; k < lineCnt; k++ ) {
            if( data[k] < data[curMinIndex] ) {
                curMinIndex = k;
            }
        }
        if( curMinIndex != i ) {
            int buf = data[i];
            data[i] = data[curMinIndex];
            data[curMinIndex] = buf;
            exchangeCnt++;
        }
    }

    printData(data,lineCnt);
    std::cout << std::endl;
    std::cout << exchangeCnt;
    std::cout << std::endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

string S;
LL MOD=1e9+7;
LL large[100011];
LL small[100011];

int main(){
	cin>>S;
	large[0]=2;
	small[0]=1;
	REP(i,S.size()-1){
		if(S[i+1]=='1'){
			large[i+1]=2*large[i];
			large[i+1]%=MOD;
			small[i+1]=large[i]+small[i]*3;
			small[i+1]%=MOD;
		}else{
			large[i+1]=large[i];
			small[i+1]=small[i]*3;
			small[i+1]%=MOD;
		}
		//cout<<S[i+1]<<" "<<large[i+1]<<" "<<small[i+1]<<endl;
	}
	cout<<(large[S.size()-1]+small[S.size()-1])%MOD<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<string.h>
int main()
{
    int i,l,x=1;
    char a[10],b[20];
    scanf("%s",a);
    scanf("%s",b);
    l=strlen(a);
    for(i=0;i<l;i++)
    {
        if(a[i]!=b[l-i-1]) x=0;
    }
    if(x==1) printf("YES\n");
        else printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include<iostream>
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n; 
void Print(int *arr, int n)
{
    for(int i=0; i<n; i++){
        cout<<arr[i]<<" ";

    }
    cout<<endl;

}


int Merge(int *arr, int lft, int mid, int rht)
{
	
	int inv_cnt=0;
	int n1= mid-lft+1;
	int n2= rht-mid; ///rht-(mid+1)+1
	int L[n1], R[n2];
	for(int i=0; i<n1; i++){
		L[i]= arr[lft+i];
	}


	for(int i=0; i<n2; i++){

		R[i]= arr[mid+i+1];
	}


	int lidx= 0;
	int ridx= 0;
	int k= lft;
	///***Previous Bug: Ekta while use ; tahole lidx or ridx might cross n1 (or n2)
	///*vital : 3ta while hobe ;
	while(lidx<n1 && ridx<n2){
		if(L[lidx]<= R[ridx]){
			arr[k++]= L[lidx++];
			//cout<<"arr["<<k<<"]="<<arr[k]<<endl;

		}
		else{
			//cout<<"Else :arr["<<k<<"]="<<arr[k]<<endl;
			inv_cnt+= (n1-lidx);
			
			//cout<<"\n\n##############lft="<<lft<<" rht="<<rht<<"  mid-k+1="<<mid-k+1<<" inv_cnt="<<inv_cnt<<endl; 
			arr[k++]= R[ridx++];
			
			
			//ridx++;
		}
	}

    while(lidx<n1){
        arr[k++]= L[lidx++];

    }
    ///**ei 2tar modhdeh ekta while i kebol cholbe
    while(ridx<n2){
        arr[k++] = R[ridx++];
    }
    //cout<<"\nMerge:inv_cnt="<<inv_cnt<<endl; 
	return inv_cnt;



}
int mergeSort(int *arr, int lft, int rht)
{
	int inversion_cnt=0; 
	
	if(lft<rht){

		int mid= (lft+rht)/2;
		inversion_cnt+= mergeSort(arr, lft, mid);
		inversion_cnt+= mergeSort(arr, mid+1, rht);
		inversion_cnt+= Merge(arr, lft, mid, rht);
		
	}
	
	
	return inversion_cnt;
}



int32_t main()
{
	
    int choice;
    int *arr;
    bool flag= true;
            //printf("Number of elements: ");
            scanf("%d", &n);
            arr= new int[n];

            for(int i=0; i<n; i++){
                cin>>arr[i];
            }
    int inv= mergeSort(arr, 0, n-1); 
    //cout<<"Inversion Cnt="<<inv<<endl;
    //Print(arr, n);
	cout<<inv<<endl; 

    return 0;
}





Measured memory_bytes: 6260
N = int(input())
l = input()
k = [[0,0] for i in range(N)]
Rc = 0
Wc = 0
for i in range(N):
    if l[i]=='R':
        Rc += 1
    else:
        Wc += 1

for i in range(N-1):
    k[i+1][0]=k[i][0]
    if l[i]=='W':
        k[i+1][0]+=1
    k[i][1]=Rc+k[i+1][0]-(i+1)

ans = 3*10**5
for i in range(N):
    if ans >= max(k[i][0],k[i][1]):
        ans = max(k[i][0],k[i][1])


print(ans)

Measured memory_bytes: 38412
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define EPB emplace_back
#define MP make_pair
#define deb(x) cerr << #x << ":" << x << endl;
#define deba(x) cerr << #x << endl; for (auto a : x) cerr << a << " "; cerr << endl;
const int MOD = 1e9 + 7;
const double EPS = 0.01;

int main() {
	fastio();
	int n;
	cin >> n;
	ll a[n];
	ll suf[n];
	suf[n - 1] = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sum = 0;
	for (int i = n - 2; i >= 0; i--) {
		suf[i] = (suf[i + 1] % MOD + a[i + 1] % MOD) % MOD;
		sum = (sum % MOD + ((a[i] % MOD) * (suf[i] % MOD)) % MOD) % MOD;
	}
	cout << sum << '\n';




	return 0;
}


Measured memory_bytes: 6692
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
const int N=2e6+5;
typedef long long ll;
int n,m;
bool vis[N];
vector<int>edge[N];
queue<int>q;
map<int,int>f[N];
int dist[N];
int fa[N];
int find_father(int x){
    if(x==fa[x]) return x;
    return fa[x]=find_father(fa[x]);
}
void merge(int x,int y){
    int f1=find_father(x),f2=find_father(y);
    fa[f1]=f2;
}
void bfs(){
    memset(dist,-1,sizeof dist);
    q.push(1);
    vis[1]=1;
    dist[1]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=0,sz=edge[u].size();i<sz;i++){
            int v=edge[u][i];
            v=find_father(v);
            if(!vis[v]){
                dist[v]=dist[u]+1;
                q.push(v);
                vis[v]=1;
            }
        }
    }
}
void Read(int &x){
	char ch = getchar();x = 0;
	for (; ch < '0' || ch > '9'; ch = getchar());
	for (; ch >='0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int main()
{
    while(~scanf("%d%d",&n,&m)){
        int cnt=0;
        for(int i=1;i<=n;i++){
            f[i].clear();
            f[i][0]=++cnt;
        }
        for(int i=1;i<=n+2*m;i++)
            fa[i]=i;
        for(int i=1;i<=m;i++){
            int u,v,w;
            //scanf("%d%d%d",&u,&v,&w);
            Read(u),Read(v),Read(w);
            if(f[u][w]==0){
                f[u][w]=++cnt;
            }
            u=f[u][w];
            u=find_father(u);
            if(f[v][w]==0){
                f[v][w]=++cnt;
            }
            v=f[v][w];
            v=find_father(v);
            merge(u,v);
        }
        if(cnt>n+2*m)
            n/=0;
        for(int i=1;i<=cnt;i++)
            vis[i]=0,edge[i].clear();
        for(int i=1;i<=n;i++)
            for(map<int,int>::iterator it=f[i].begin();it!=f[i].end();it++){
                int j=it->second;
                j=find_father(j);
                edge[i].push_back(j);
                edge[j].push_back(i);
            }
        bfs();
        if(dist[n]==-1)
            puts("-1");
        else
            printf("%d\n",dist[n]/2);
    }
}


Measured memory_bytes: 188416
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <ctype.h>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
// #include <pair> 
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
// long long binpow(long long a,long long b)
// {
//     if (b == 1) return a;
//     long long res = binpow(a, b/2)%MOD;
//     if (b % 2) return (res*((res*a)%MOD))%MOD;
//     else return (res * res)%MOD;
// }
 
// long long int fact(long long int a)
// {
//     if(a==0||a==1)
//         return 1;
//     long long int ans = 1;
//     for(int i=a;i>=1;i--)
//         ans = (ans * i);
//     return ans;
// }
 
// long long int ivmod(long long int a)
// {
//     return binpow(a,MOD-2);
// }
 
// long long int ncr(long long int a,long long int b)
// {
//     long long int pans=1;
//     for(int i =a;i>max(b,a-b);i--)
//         pans=pans*i;
//     long long int div = fact(min(b,a-b));
//     // cout<<ans<<"            "<<div<<endl;
//     pans = pans/div;
//     return pans;
// }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif   
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
def solve():
  s = input()
  a = len(s)
  n = int(s)
  udge = '9'*a
  if a == 1:
    ans = n
  elif a > 1:
   if s == udge: ans = 9*a
   else:
     ans = 9*(a-1)+int(s[0])-1
     ans2 = 0
     for i in s:
      ans2 += int(i)
     ans = max(ans,ans2)
  return ans
  
  
if __name__ == '__main__':
  print(solve())

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;
int N;
int ud[100002];
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		a--;
		ud[a]++;
		ud[b]--;
	}
	int cnt=0;
	int res=0;
	for(int i=0;i<=N;i++){
		cnt+=ud[i];
		if(cnt>=i)res=i;
	}
	cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 1212
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]

    c = [int(i) for i in input().split()]

    print(((a[0]+b[0])*c[0])//2)


Measured memory_bytes: 3828
#include <iostream>

using namespace std;

int main() {
  int i,p,d[6][2]={{1,3},{0,2},{4,5},{1,0},{5,3},{3,1}};
  char c[102];
  while(cin >> c) {
	  if (c[0]=='#') break;
	  p=0;
	  for (i=0;c[i]!='\0';i++) { p=d[p][c[i]-'0']; if (p==0) break;}
	  if (p==5) cout << "Yes"; else cout << "No"; 
	  cout << endl;
  }	  
  return 0;
 } 

Measured memory_bytes: 1136
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{   
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}


Measured memory_bytes: 3640
A = []
for i in range(3):
    A.append(list(map(int,input().split())))
N=int(input())
num = [int(input())for i in range(N)]

bingo=[[0,0,0],[0,0,0],[0,0,0]]
for i in num:
    for j in range(3):
        for k in range(3):
            if i==A[j][k]:
                bingo[j][k]=1
#行がビンゴ
for i in range(3):
    if sum(bingo[i])==3:
        print("Yes")
        exit()
#列がビンゴ
if bingo[0][0]+bingo[1][0]+bingo[2][0]==3 or bingo[0][1]+bingo[1][1]+bingo[2][1]==3 or bingo[0][2]+bingo[1][2]+bingo[2][2]==3:
        print("Yes")
        exit()
#斜めがビンゴ
elif bingo[0][0]+bingo[1][1]+bingo[2][2]==3 or bingo[0][2]+bingo[1][1]+bingo[2][0]==3:
    print("Yes")
    exit()
    
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n;
	cin >> n;
	int ans = 0;
	if (n >= 9) {
		ans += 9;
		if (n >= 999) {
			ans += 900;
			if (n >= 99999) {
				ans += 90000;
			}
			else if (n >= 9999)
				ans += n - 9999;
		}
		else if(n >= 99)
			ans += n - 99;
	}
	else
		ans += n;
	cout << ans;
}

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

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

	vector<string> S;
	vector<int> T;
	for (int i = 0; i < N; i++) {
		string s;
		int t;
		cin >> s >> t;
		S.push_back(s);
		T.push_back(t);
	}

	string X;
	cin >> X;

	bool flag = false;
	int total = 0;
	for (int i = 0; i < N; i++) {
		if (flag) {
			total += T[i];
		}

		if (X == S[i]) {
			flag = true;
		}
	}

	cout << total << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#define N 1005
using namespace std;

int n, d, gc, cur, nm[N];
queue<int> a[N], qu[2];
int main() {
	int i, j, t, x, y;
	cin >> n;
	for(i=1; i<=n; i++) {
		for(j=1; j<n; j++) scanf("%d", &t), a[i].push(t);
		qu[0].push(i);
	}
	gc = n * (n-1) / 2;
	for(d=1; ; d++, cur = 1-cur) {
		while(!qu[cur].empty()) {
			x = qu[cur].front(); qu[cur].pop();
			y = a[x].front(); a[x].pop();
			if(nm[y] == x) {
				gc--;
				qu[1-cur].push(x);
				qu[1-cur].push(y);
				nm[y] = nm[x] = 0;
			} else {
				nm[x] = y;
			}
		}
		if(gc==0) {cout << d; return 0;}
		if(qu[0].empty() && qu[1].empty()) {cout << -1; return 0;}
	}
}

Measured memory_bytes: 4736