akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		char [] a = sc.next().toCharArray();
		char [] b = sc.next().toCharArray();
		char [] c = sc.next().toCharArray();
		char turn = 'a';
		int an = 0;
		int bn = 0;
		int cn = 0;
		
		
		roop : while(true){
		switch(turn){
		case 'a' : if(a.length == an){System.out.println("A"); break roop;} 
		           turn = a[an]; an += 1; break;
		case 'b' : if(b.length == bn){System.out.println("B"); break roop;} 
				   turn = b[bn]; bn += 1; break;
		case 'c' : if(c.length == cn){System.out.println("C"); break roop;} 
				   turn = c[cn]; cn += 1; break;
		default :}}
	}}

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

using namespace std;

int main()
{
    vector<int> A(9);
    for(int i=0;i<9;i++) cin >> A.at(i);

    vector<bool> Ab(9,false);
    
    int N;
    cin >> N;

    vector<int> B(N);
    for(int i=0;i<N;i++) cin >> B.at(i);

    for(int i=0;i<9;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(A.at(i) == B.at(j)) Ab.at(i) = true;
        }
    }

    if (Ab.at(0)==true && Ab.at(1)==true && Ab.at(2)==true ||
        Ab.at(3)==true && Ab.at(4)==true && Ab.at(5)==true ||
        Ab.at(6)==true && Ab.at(7)==true && Ab.at(8)==true ||
        Ab.at(0)==true && Ab.at(3)==true && Ab.at(6)==true ||
        Ab.at(1)==true && Ab.at(4)==true && Ab.at(7)==true ||
        Ab.at(2)==true && Ab.at(5)==true && Ab.at(8)==true ||
        Ab.at(0)==true && Ab.at(4)==true && Ab.at(8)==true ||
        Ab.at(2)==true && Ab.at(4)==true && Ab.at(6)==true )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    double r;cin>>r;
    cout<<2*r*3.141592<<endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n); rank.resize(n);
    fill(par.begin(), par.end(), 1); fill(rank.begin(), rank.end(), 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};
int main(void){
    ll N,M,K;
    cin>>N>>M>>K;
    UnionFind uf;
    uf.init(N);
    ll d[100001]={};
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        uf.merge(a,b);
        d[a]--,d[b]--;
    }
    for(int i=0;i<K;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(uf.isSame(a,b)){
            d[a]--,d[b]--;
        }
    }
    for(int i=0;i<N;i++){
        cout<<uf.getSize(i)+d[i]-1<<" ";
    }
}


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

typedef long long ll;

ll mod = 1e9 + 7;

ll mp(ll a, ll b) {
    if (b == 0) return 1LL;
    if (b == 1) return a;
    ll ret = mp(a, b/2);
    ret *= ret;
    ret %= mod;
    if (b&1) ret *= a;
    return ret % mod;
}

ll inv(ll k) {
    return mp(k, mod - 2);
}

ll kai[1<<18];

ll C(ll n, ll k) {
    if (k == 0) return 1LL;
    if (n == k) return 1LL;
    return kai[n] * inv(kai[k]) % mod * inv(kai[n-k]) % mod;
}

ll mul(ll a, ll b) {
    return (a * b) % mod;
}

ll add(ll a, ll b) {
    return (a + b) % mod;
}

int main() {
    kai[0] = 1LL;
    for (int i = 1; i < (1<<18); i++) {
        kai[i] = kai[i - 1] * i;
        kai[i] %= mod;
    }
    
    ll n,a,b,c;
    cin >> n >> a >> b >> c;
    ll ta = a * 100 * inv(100 - c) % mod;
    ll tb = b * 100 * inv(100 - c) % mod;
    a = ta;
    b = tb;
    ll ans = 0;
    for (int m = n; m <= n * 2 - 1; m++) {
        ll tmp = add(mul(mp(a,n),mp(b,m-n)), mul(mp(a,m-n),mp(b,n)));
        tmp = mul(tmp,m);
        tmp = mul(tmp,inv(mul(mp(100LL,m-1),100LL-c)));
        ans = add(ans, mul(tmp,C(m-1,n-1)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2304
n=int(input())
l=[int(i) for i in input().split()]
if len(set(l))==1:
    print(n//2)
    exit()
even=[l[i] for i in range(n) if i%2==0]
odd=[l[i] for i in range(n) if i&1]
from collections import Counter 
c1=Counter(even)
c2=Counter(odd)
a=[i for i in c1]
b=[i for i in c2]
maxi=max(c1.values())
maxi=max(maxi,max(c2.values()))
a.sort(key=lambda x:-c1[x])
b.sort(key=lambda x:-c2[x])
for a1 in a: 
    for b1 in b: 
        if a1==b1:
            continue 
        maxi=max(maxi,c1[a1]+c2[b1])
        break 
print(n-maxi)

Measured memory_bytes: 67688
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <ctime>
#include <set>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 3e5+5;
struct P { int x, y; } p[N];
int w, h, n, ans, t[N<<2], tag[N<<2];
void pusha(int x, int d) { tag[x] += d, t[x] += d; }
void pushdown(int x) { if(tag[x]) pusha(x<<1, tag[x]), pusha(x<<1|1, tag[x]), tag[x] = 0; }
void pushup(int x) { t[x] = max(t[x<<1], t[x<<1|1]); }
void add(int x, int l, int r, int ql, int qr, int d)
{
    if(ql <= l&&r <= qr) return pusha(x, d); int mid = (l+r)>>1; pushdown(x);
    if(ql <= mid) add(x<<1, l, mid, ql, qr, d); if(qr > mid) add(x<<1|1, mid+1, r, ql, qr, d); pushup(x);
}
void work()
{
    sort(p+1, p+1+n, [&](P a, P b) { return a.y<b.y; });
    static int s1[N], s2[N], u[N], v[N]; int t1 = 0, t2 = 0; memset(t, 0, sizeof(t)), memset(tag, 0, sizeof(tag));
    for(int l = 1, r, i = 1; l <= n; l = r+1, ++i)
    {
        for(r = l; r < n&&p[r+1].y == p[l].y; ++r);
        ans = max(ans, max(2*(p[l].y+t[1]), 2*(w+p[l].y-p[l-1].y))), add(1, 1, n, i, i, -p[l-1].y), u[i] = 0, v[i] = w;
        for(int k = l; k <= r; ++k) p[k].x*2<=w?u[i] = max(u[i], p[k].x):v[i]=min(v[i], p[k].x);
        while(t1&&u[s1[t1]] <= u[i]) add(1, 1, n, s1[t1-1]+1, s1[t1], u[s1[t1]]), --t1;
        add(1, 1, n, s1[t1]+1, i, -u[i]), s1[++t1] = i;
        while(t2&&v[s2[t2]] >= v[i]) add(1, 1, n, s2[t2-1]+1, s2[t2], -v[s2[t2]]), --t2;
        add(1, 1, n, s2[t2]+1, i, v[i]), s2[++t2] = i;
    }
    ans = max(ans, 2*(h+t[1])), ans = max(ans, 2*(h-p[n].y+w));
}
int main()
{
    w = read(), h = read(), n = read(), ans = 2*(max(w, h)+1); 
    for(int i = 1; i <= n; ++i) 
    {
        p[i].x = read(), p[i].y = read();
        if(!p[i].x||!p[i].y||p[i].x == w||p[i].y == h) --n, --i;
    }
    work(); for(int i = 1; i <= n; ++i) swap(p[i].x, p[i].y); swap(w, h); work();
    if(!n) ans = (w+h)*2; printf("%d\n", ans);
    return 0;
}

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

ll GCD(ll a,ll b){
  if(b==0) return a;
  else return GCD(b,a%b);}
ll LCM(ll a, ll b){ return a/GCD(a,b)*b;}
ll F(ll x, ll c, ll d){
    ll res = x;
    res -= x/c;
    res -= x/d;
    res += x/LCM(c,d);
    return res;
}

int main(){
     ll a, b;
     int c, d;
     cin >> a>>b >> c >>d;
     
     ll ans = F(b,c,d)-F(a-1,c,d);
     cout << ans << endl;
}  

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

int main() {
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int count=1e9;
    int com;
    for(int i=0;i<=2*(max(x,y));i+=2){
        com=c*i+a*(max(0,x-(i/2)))+b*(max(0,y-(i/2)));
        count=min(com,count);
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int A[n];

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

    int a,b,c;
    a = 0;
    b = 0;
    c = 0;

    for (int i = 0; i < n; i++){
        if (A[i] % 2 != 0){
            a += 1;
        }
        else if (A[i] % 4 != 0){
            b += 1;
        }
        else {
            c += 1;
        }
    }   
    if (b != 0){
        if (a > c){
            cout << "No";
            return 0;
        }
        else {
            cout << "Yes";
            return 0;
        }
    }
    else{
        if (a > c + 1){
            cout << "No";
            return 0;
        }
        else {
            cout << "Yes";
            return 0;
        }
    }


}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	string s;
	int x[2];
	cin >> s >> x[0] >> x[1];
	int p, dir, dist;
	p = 0;
	for(; p < s.size() && s[p] != 'T'; ++p) {
		x[0]--;
	}
	vector<int> dx[2];
	dist = dir = 0;
	for(; p < s.size(); ++p) {
		if (s[p] == 'T') {
			dx[dir].push_back(dist);
			dir = !dir;
			dist = 0;
		}
		else {
			dist++;
		}
	}
	if(dist) {
		dx[dir].push_back(dist);
	}

	set<int> dp[2][2];
	for(int k = 0; k < 2; ++k) {
		dp[k][0].insert(0);
		for(int i = 0; i < dx[k].size(); ++i) {
			dp[k][(i + 1) % 2].clear();
			EACH(j, dp[k][i % 2]) {
				dp[k][(i + 1) % 2].insert(*j + dx[k][i]);
				dp[k][(i + 1) % 2].insert(*j - dx[k][i]);
			}
		}
		/*
		EACH(i, dp[k][dx[k].size() % 2]){
			cout << *i << "," << endl;
		}
		cout << endl;
		*/
		if(dp[k][dx[k].size() % 2].find(x[k]) == dp[k][dx[k].size() % 2].end()) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int a = 0, b = 0;
    for (int i = 0; i < s.size(); ++i) {
    	if (s[i] == 'A') ++a;
    	else ++b;
    }
    if (a > 0 && b > 0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  priority_queue<ll> A;
  
  REP(i,N){
    ll a;
    cin>>a;
    A.push(a);
  }
  
  
  REP(i,M){
    int d=A.top()/2;
    A.pop();
    A.push(d);
  }
  
  ll ans=0;
  REP(i,N){
    ans+=A.top();
    A.pop();
  }
  
  cout<<ans<<endl;
}

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

int main (void) {
  int n, m, ans = 0; cin >> n >> m;
  vector<vector<int>> adj(n);
  for (int i = 0;i < m;i++) {
    int u, v; cin >> u >> v;
    u--; v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<bool> visited(n);
  queue<int> q;
  for (int i = 0;i < n;i++) {
    if (visited[i]) continue;
    int cnt = 1;
    q.push(i);
    visited[i] = true;
    while (!q.empty()) {
      int u = q.front(); q.pop();
      for (int v: adj[u]) {
        if (visited[v]) continue;
        visited[v] = true;
        cnt++;
        q.push(v);
      }
    }
    ans = max(ans, cnt);
  }

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

Measured memory_bytes: 14916
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

struct UnionFind{
  vector<int> par,w;

  UnionFind(int n) : par(n,-1), w(n, 0) { }
  void init(int n) {
    par.assign(n, -1);
    w.assign(n, 0);
  }
  int root(int x){
    if(par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  bool issame(int x, int y){
    return root(x) == root(y);
  }
  bool merge(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y){
      w[x]++;
      return false;
    }
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    w[x] += w[y];
    w[x]++;
    return true;
  }
  int size(int x){
    return -par[root(x)];
  }
  int wei(int x){
    return w[root(x)];
  }
};


int main(){
  int N;
  cin >> N;
  vector<P> x(N),y(N);
  for(int i=0; i<N; i++){
    cin >> x[i].first >> y[i].first;
    x[i].second = y[i].second = i;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<>> Q;
  for(int i=1; i<N; i++){
    Q.push(make_pair(x[i].first-x[i-1].first,make_pair(x[i].second,x[i-1].second)));
    Q.push(make_pair(y[i].first-y[i-1].first,make_pair(y[i].second,y[i-1].second)));
  }
  UnionFind uf(N);
  int cnt = N;
  ll ans = 0;
  while(cnt-1){
    auto v = Q.top();
    Q.pop();
    if(uf.issame(v.second.first,v.second.second)) continue;
    uf.merge(v.second.first,v.second.second);
    ans += v.first;
    cnt--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6516
N = int(input())
A = [0 for i in range(N + 1)]
B = list(map(int, input().split()))

for i in range(N - 1):
    if i == 0:
        A[i+1] = B[i]
    if B[i] < A[i+1]:
        A[i+1] = B[i]
    A[i + 2] = B[i]

print(sum(A))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+9, INF = 0x3f3f3f3f;
int dt[105], ans = 0;

void selectionSort( int n ) {
    for( int i = 0; i < n; ++i ) {
        int minj = i;
        for( int j = i; j < n; ++j ) {
            if( dt[j] < dt[minj] ) minj = j;
        }
        if( minj != i ) swap( dt[minj], dt[i] ), ++ans;
    }
}

int main( void ) {
    ios::sync_with_stdio( false );
    int n;
    cin >> n;
    for( int i = 0; i < n; ++i ) cin >> dt[i];
    selectionSort( n );
    for( int i = 0; i < n; ++i ) cout << dt[i] << ( i == n - 1 ? '\n' : ' '  );
    cout << ans << '\n';
    return 0;
}



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

using namespace std;

#define ll long long int

vector<string> v;

void generate(string s, int index = 0, string sub = "") {
	
	if(index == s.size())
		v.push_back(sub+"+");
	else {
		string tmp = s.substr(index,1);
		generate(s,index+1,sub+tmp);
		if(sub.size())generate(s,index+1,sub+"+" + tmp);
	}
}

ll value(string s) {
	
	ll sum = 0;

	for(int i = 0; i < s.size(); i++) {
		sum = sum*10 + (s[i]-'0');
	}

	return sum;
}

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

	string s; cin >> s;

	generate(s);

	ll ans = 0;
	
	for(int j = 0; j < v.size(); j++) {
		int pre = 0;
		for(int i = 0; i < v[j].size(); i++) {
			if(v[j][i] == '+'){
				string tmp = v[j].substr(pre,i-pre);
				ans += value(tmp);
				pre = i+1;
			}
		}
	}

	cout << ans << '\n';

	return 0;
}

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

int n , m ;

void input ( ) {
    scanf ( "%d%d" , &n , &m ) ;
}

void solve ( ) {
    int ans = 0 ;
    ans = 100 * ( n - m ) ;
    ans += 1900 * m ;
    ans *= (1<<m) ;
    printf ( "%d\n" , ans ) ;
}

int main ( ) {
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>


int main() {

	int N;
	unsigned long totalCount = 0;
	std::vector<int> A;

	std::map<int, int> B;
	std::map<int, std::pair<unsigned long, unsigned long>> C;

	std::cin >> N;

	for (int i = 0; i < N; i++) {
		int c;
		std::cin >> c;
		A.push_back(c);

		// [] Creates 0 if not exist
		B[c] += 1;
	}

	for (auto const& x: B) {
		unsigned long valueCount = (unsigned long) x.second;
		unsigned long firstValue = 0; 
		unsigned long secondValue = 0;

		if (valueCount >= 2) {
			unsigned long buffer = 1;
			for (unsigned long j = valueCount; j > valueCount - 2; j--) {
				buffer *= j;
			}

			firstValue = buffer / 2;
			secondValue = buffer * (valueCount - 2) / (valueCount * 2) ;
		}
		totalCount += firstValue;

		C.insert({x.first, {firstValue, secondValue}});
	}

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

		std::map<int, std::pair<unsigned long, unsigned long>>::iterator it;

		it = C.find(A[i]);

		std::cout << totalCount - it->second.first + it->second.second << "\n";
	}

	return 0;

}



Measured memory_bytes: 16244
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
	int n, m, i, a[103], s = 0;
	
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}

	sort(a, a + n, greater<int>());

	if (a[m - 1] * 4 * m < s) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
ll INF=1000000007;

int main(){
    ll dp[110][110];
    ll n;
    cin >> n;
    ll r[n],c[n];
    rep(i,n) cin >> r[i] >> c[i];
    rep(i,n) dp[i][i]=0;
    for(ll m=1;m<=n-1;m++){
        rep(i,n-m){
            dp[i][i+m]=INF;
            for(ll k=i;k<=i+m-1;k++){
                if(dp[i][i+m]>dp[i][k]+dp[k+1][i+m]+r[i]*c[k]*c[i+m]){
                    dp[i][i+m] = dp[i][k]+dp[k+1][i+m]+r[i]*c[k]*c[i+m];
                }
            }
        }
    }
    cout << dp[0][n-1] << endl;
}


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

int main() {
	int h,w;cin >> h >> w;
	auto haji = string(w + 2, '#');
	vector<string> v;
	v.push_back(haji);
	for (int i = 0; i < h; ++i) {
		string tmp, s;
		cin >> tmp;
		s += "#";s += tmp;s += "#";
		v.push_back(s);
	}
	v.push_back(haji);
	for (int j = 0; j < h + 2; ++j) {
		cout << v[j] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd

n=int(input())
a=list(map(int,input().split(' ')))
east=[0]*(n+1)
west=[0]*(n+1)
for i in range(1,n+1):
    east[i]=gcd(east[i-1],a[i-1])
    west[-i-1]=gcd(west[-i],a[-i])
ans=0
for k in range(1,n+1):
    tmp=gcd(east[k-1],west[k])
    if tmp>ans:
        ans=tmp
print(ans)

Measured memory_bytes: 16108
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    vector<string> V(n);
    for (int i = 0; i < n; ++i) {
        cin >> V[i];
    }
    sort(V.begin(), V.end());
    for (int i = 0; i < n; ++i) {
        cout << V[i];
    }
    cout << "\n";
    return 0;
}

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

int main(){
  vector<string> w={"a","SAT","FRI","THU","WED","TUE","MON","SUN"};
  string a;
  cin >> a;
  for(int i=1;; i++){
    if(a==w.at(i)){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h;
  int n;
 
  int count = 0;
  int c;
  
  
  scanf("%d%d",&h,&n);
  
  
  
 
  for(int i=0;i<n;i++){
    scanf("%d",&c);
    count+=c;
  }
  
  if(count<h){
      
    printf("No");
  }else{
    printf("Yes");
  }
  
  return 0;
}

Measured memory_bytes: 128
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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        ab : usize,
        bc : usize,
        cd : usize,
    }
    println!("{}", ab * bc / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int w[n+1];
    int sum = 0;
    for(int i = 0; i < n; ++i)
    {
        cin >> w[i];
        sum += w[i];
    }
    int sum2 = 0;
    int ans = sum;
    for(int i = 0; i < n; ++i)
    {
        sum2 += w[i];
        if(abs((sum - sum2) - sum2) < ans)
            ans = abs((sum - sum2) - sum2);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	ll x;
	cin >> x;
	ll val = 100;
	for (int i = 1; i <= 10000; ++i) {
		val *= 1.01;
		if(val >= x){
			cout << i << endl;
			return 0;
		}
	}
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  VVI X(10,VI(0));
  rep(i,N) X[S[i]-'0'].push_back(i);
  int ans=0;
  rep(i,1000){
    int A=i/100;
    int B=(i%100)/10;
    int C=i%10;
    if(X[A].size()&&X[B].size()&&X[C].size()){
      if(X[A][0]<X[C][X[C].size()-1]){
        if(upper_bound(all(X[B]),X[A][0])-X[B].begin()<X[B].size()){
          int Z=X[B][upper_bound(all(X[B]),X[A][0])-X[B].begin()];
          if(Z<X[C][X[C].size()-1]){
            ans++;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}





Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> fidx(26, vector<int>(s.size(), -1));
    for (char c = 'a'; c <= 'z'; ++c) {
        for (int i = s.size() - 1; i >= 0; --i) {
            if (s[i] == c) {
                fidx[c - 'a'][i] = i;
            } else if (i < s.size() - 1) {
                fidx[c - 'a'][i] = fidx[c - 'a'][i + 1];
            }
        }
    }
    int beg = 0;
    ll ans = 0;
    for (int i = 0; i < t.size(); ++i) {
        int idx = fidx[t[i] - 'a'][beg];
        if (idx != -1) {
            ans += idx - beg + 1;
            beg = (idx + 1) % s.size();
        } else {
            idx = fidx[t[i] - 'a'][0];
            if (idx == -1) {
                cout << -1 << endl;
                return 0;
            }
            ans += s.size() - beg;
            ans += idx + 1;
            beg = (idx + 1) % s.size();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

int cnt[N];

int main(){
fast;
int n;
cin>>n;
ll ans =0;
fill(cnt,0);
for(int i=0;i<n;i++) {
    int x;
    cin>>x;
    cnt[x]++;
    ans +=x;
}

int q;
cin>>q;
for(int i=0;i<q;i++) {
    int b,c;
    cin>>b>>c;
    ll val = cnt[b];
    cnt[b]=0;
    cnt[c]+=val;
    ans += val*(c-b);
    cout<<ans<<endl;
}

return 0;
}

Measured memory_bytes: 5596
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long num = 0;
        long numB = 0;
        long numA = 0;
        if (k % 2 == 1) {
            for (int i = 1; i <= n; i++)
                if (i % k == 0)
                    num++;
            System.out.println((long) Math.pow(num, 3));
        } else {
            for (int i = 1; i <= n; i++) {
                if (i % k == 0)
                    numA++;
                if (i % k == k / 2)
                    numB++;
            }
            System.out.println((long) Math.pow(numA, 3) + (long) Math.pow(numB, 3));
        }
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=999999;
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; }

int dist[100010][3];

int main(int argc, char const *argv[]) {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--,b--;
    to[a].pb(b);
  }
  int sv,tv;
  cin >> sv >> tv;
  sv--,tv--;

  rep(i,n)rep(j,3) dist[i][j]=INF;

  queue<pii> q;
  q.push(pii(sv,0));
  dist[sv][0]=0;

  while(!q.empty()){
    int v=q.front().fi;
    int l=q.front().se;
    q.pop();
    for(int u : to[v]){
      int nl=(l+1)%3;
      if(dist[u][nl]!=INF) continue;
      dist[u][nl]=dist[v][l]+1;
      q.push(pii(u,nl));
    }
  }

  int ans=dist[tv][0];
  if(ans==INF) ans=-1;
  else ans/=3;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 
const int MAXN = 1e9;

ll count(ll h) {
	if(h == 1) 
		return 1;
	return 2 * count(h/2)+1;
}

int main() {
	ll h;
	cin >> h;
	cout << count(h) << endl;	
	return 0;
}



Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
void solve(){
   string odd, even;
   cin >> odd >> even;
   int n1 = (int)odd.length();
   int n2 = (int)even.length();
   string ret = "";
   for(int i = 0; i < n1 + n2; i++){
	   if (i % 2 == 0){
		    cout << odd[i/2]; 
		  }
	   else{
		    cout << even[i/2]; 
		  }  
	 }
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << min({a+b, b+c, c+a}) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            int n = Integer.parseInt(inputReader.readLine());
            if (n == 0) {
                break;
            }
            int[] inputList = new int[n];
            for (int i = 0; i < n; i++) {
                inputList[i] = Integer.parseInt(inputReader.readLine());
            }
            int max = Integer.MIN_VALUE;
            for (int i = 0; i < inputList.length; i++) {
                int sum = 0;
                for (int j = i; j < inputList.length; j++) {
                    sum += inputList[j];
                    if (max < sum) {
                        max = sum;
                    }
                }
            }
            System.out.println(max);
        }
    }
}

Measured memory_bytes: 11000
#include <stdio.h>

int main()
{
	int a, b, c, i, ans;
	long sum;

	scanf("%d %d %d", &a, &b, &c);

	sum = a + c;
	ans = 0;
	for (i = 0; i < b; i++)
	{
		if (sum % b == 0)
		{
			ans = 1; break;
		}
		else sum += a;
	}

	if (ans == 1)
		printf("YES");
	else printf("NO");

	return 0;
}

Measured memory_bytes: 128
def era()
  a=Array.new(10001,false)
  ans=[]
  for i in 2..10000
    if !a[i]
      ans.push(i)
      j=i
      while j<=10000
        a[j]=true
        j+=i
      end
    end
  end
  return ans
end

def bin_search(a,n)
  l=0
  r=a.length
  while r-l>0
    t=(r+l)/2
    if a[t]==n
      return true
    elsif a[t]<n
      l=t+1
    else
      r=t
    end
  end
  return false
end

def prime(a,t)
  sum=Array.new(a.length+1,0)
  for i in 0..a.length-1
    sum[i+1]=sum[i]+a[i]
  end
  count=0
  for s in 0..a.length
    b=sum[s..-1]
    if(bin_search(b,t+sum[s]))
      count+=1
    end
  end
  return count
end

a=era()
while true
  t=gets.to_i
  if t==0
    break
  end
  puts prime(a,t)
end
    

Measured memory_bytes: 8748
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int A,B,C;
    cin >> A >> B >> C;
    if(A == B && B == C && A%2 == 0) {
        cout << -1 << endl;
        return 0;
    }
    if(A%2 == 1 || B%2 == 1 || C%2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    int i = 1;
    while(true) {
        int X = A,Y = B,Z = C;
        A = (Y+Z)/2;
        B = (X+Z)/2;
        C = (X+Y)/2;
        if(A%2 == 1 || B%2 == 1 || C%2 == 1) {
            cout << i << endl;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
//#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(void)
{
    lli A, B, C, K; cin >> A >> B >> C >> K;
    lli ans = (A <= K ? A : K); K -= A;
    if (K > 0) K -= B;
    if (K > 0)ans -= K;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    ll k;
    ll ans =0;
    cin >> n >> k;
    REP(i,n){
        ll tmp;
        ll b_dst=0;
        cin >> tmp;
        b_dst = abs(k-tmp);
        if(b_dst < tmp){
            ans+= b_dst *2;
        }else{
            ans+= tmp*2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3144
program main

  implicit none

  integer :: i, j, k, l, n
  integer, parameter :: limit = 1000000
  integer :: prime

  read(*,*) i
  n = 0
  do k = i, limit
    l = 0
    if ( mod( k, 2 ) == 0 .and. k /= 2 ) cycle

    do j = 2, int( sqrt( real( k ) ) )
      if( mod(k, j) == 0 ) then
        l = l + 1
      end  if
    end do

    if ( l == 0 ) then
      prime = k
      exit
    end  if

  end do

  print*, prime


end program main

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    string s; cin >> s;
    Ans(s[0] == s[2]);
    return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, m;
int a[100005];
ll b[100005];
std::vector<ll> ab[100005];
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        std::cin >> a[i] >> b[i];
        ab[a[i]].push_back(b[i]);
    }

    ll ans = 0;
    std::priority_queue<ll> que;
    for (int i = 1; i <= m; ++i) {
        for (auto& v : ab[i])
            que.push(v);
        if (que.empty())
            continue;
        auto p = que.top();
        que.pop();
        ans += p;
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main(){
int w,h,n;
cin >> w >> h >> n;

int xmax = 0;
int xmin = w;
int ymax = 0;
int ymin = h;
int x,y,a;

for (int i = 0; i < n; i++)
{
  cin >> x >> y >> a;

  if(a == 1){
    xmax = max(xmax,x);
  }
  if(a == 2){
    xmin = min(xmin,x);
  }
  if(a == 3){
    ymax = max(ymax,y);
  }
  if(a == 4){
    ymin = min(ymin,y);
  }

}

int s = max((ymin-ymax),0) * max((xmin-xmax),0);

cout << s << endl;


}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int ans = 0;
    if (N%1000 != 0) ans = 1000 - N%1000;
    else ans = 0;

    cout << ans << endl;

    return 0;
}

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

int main(){
    int s, i = 1;
    cin >> s;
    
    while (!(s == 1 || s == 2 || s == 4)){
        if (s % 2 == 0){
            s /= 2;
        }else {
            s = 3 * s + 1;
        }
        i++;
    }
    
    cout << i + 3 << endl;
}

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

vector<int> va[4];
int ki = 0;

int solve(int i, int j, int w){
  if(i == 4) return 0;
  if(j == va[i].size()) return solve(i+1, 0, w);
  int ans = 0;
  if(w >= ki+i) ans = solve(i, j+1, w-(ki+i)) + va[i][j];
  return max(ans, solve(i+1, 0, w));
}

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

  int we, v;
  for(int i = 0;i < n;i++){
    cin >> we >> v;
    if(i == 0) ki = we;
    va[we-ki].push_back(v);
  }

  for(int i = 0;i < 4;i++) sort(va[i].begin(), va[i].end(), greater<int>());

  cout << solve(0, 0, w) << endl;

  return 0;
}

Measured memory_bytes: 256
l=input()
s=[]
s[0:1]=l[0:1]
s[1:2]=l[1:2]
s[2:3]=l[2:3]
s[3:4]=l[3:4]
s.sort()
if(s[0:1]==s[1:2] and s[2:3]==s[3:4] and s[1:2]!=s[2:3]):
	print("Yes")
else:
	print("No")

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    bool canYYMM = (S[2] == '0' && S[3] > '0') || (S[2] == '1' && S[3] <= '2');
    bool canMMYY = (S[0] == '0' && S[1] > '0') || (S[0] == '1' && S[1] <= '2');

    cout << (
        canYYMM && canMMYY ? "AMBIGUOUS"
        : canYYMM ? "YYMM"
        : canMMYY ? "MMYY"
        : "NA"
    ) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define T int t = 0; cin >> t; while(t--)
#define pr(a) for(int i = 0; i < (int)a.size(); ++i)cout << a[i] << " ";cout << endl;
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 2;
const ll inf = 2e18;
const int sz = 256;
const int max_k = 20;
const int len = 3e5 + 2;
typedef long long ll;

struct segmentree{
    vector<int>tree;
    segmentree(){
        tree.resize(4 * len, 0);
    }
    void update(int si, int ss, int se, int i, int val){
        if(ss > i || se < i || ss > se)return;
        if(ss == se){
            tree[si] = val;
            return;
        }
        int mid = (ss + se) >> 1;
        update(2 * si + 1, ss, mid, i, val);
        update(2 * si + 2, mid + 1, se, i, val);
        tree[si] = max(tree[2 * si + 1], tree[2 * si + 2]);
    }
    void update(int i, int diff){
        update(0, 0, len - 1, i, diff);
    }
    int get_max(int si, int ss, int se, int qs, int qe){
        if(ss > qe || ss > se || se < qs)return 0;
        if(ss >= qs && se <= qe)return tree[si];
        int mid = (ss + se) >> 1;
        return max(get_max(2 * si + 1, ss, mid, qs, qe), get_max(2 * si + 2, mid + 1, se, qs, qe));
    }
    int get_max(int l, int r){
        return get_max(0, 0, len - 1, l, r);
    }
}st;
void input(){
    IOS;
    int  n, k;
    cin >> n >> k;
    vector<int>a(n);
    f(i, n)cin >> a[i];
    int ans = 0;
    f(i, n){
        int old = st.get_max(a[i], a[i]);
        int left = max(0, a[i] - k);
        int right = min(3000001, a[i] + k);
        int temp = st.get_max(left, right);
        ans = max(ans, temp + 1);
        st.update(a[i], max(old, temp + 1));
    }
    cout << ans << endl;
}

int main(){
    input();
    return 0;
} 
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 8956
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.StreamSupport;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();
    if (s * t >= d) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 32684
import java.util.*;
public class Main{
  public static void main(String args[]){
      Scanner s=new Scanner(System.in);
      String a=s.next();
      String b=s.next();
      if(a.equals(b.substring(0,a.length())))
        System.out.println("Yes");
    else
        System.out.println("No");
  }
}

Measured memory_bytes: 35448
use proconio::{input,fastout};
use std::collections::HashMap;

fn main() {
    input! {
        n: isize,
        hs: [isize; n],
    }

    let mut hash = HashMap::<isize, Vec<isize>>::new();
    let mut results = 0;

    for i in 0..n {
        let sum = i + 1 + hs[i as usize];

        if let Some(n) = hash.get_mut(&sum) {
            n.push(i);
        } else {
            hash.insert(sum, vec![i]);
        };
    }

    for i in 0..n {
        let diff = i + 1 - hs[i as usize];

        if let Some(n) = hash.get_mut(&diff) {
            results += n.len();
        };
    }

    println!("{}", results);
}


Measured memory_bytes: 21196
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, d; cin >> n >> d;
		if (n == 0) break;
		if (n == 1) {
			cout << "Yes" << endl;
			continue;
		}
		vector<int> m(n);
		vector< vector<int> > c(n);
		for (int i = 0; i < n; i++) {
			cin >> m[i];
			c[i] = vector<int>(m[i]);
			for (int j = 0; j < m[i]; j++)
				cin >> c[i][j];
		}
		vector<int> index(n), sum(n);
		for (;;) {
			i_i min1(INT_MAX, -1), min2(INT_MAX, -1);
			for (int i = 0; i < n; i++) {
				i_i p(sum[i], i);
				if (p < min1) {
					min2 = min1;
					min1 = p;
				}
				else if (p < min2)
					min2 = p;
			}
			bool flag = false;
			for (int i = 0; i < n; i++) {
				int& j = index[i];
				if (j == m[i]) continue;
				int mini = (i == min1.second ? min2.first : min1.first);
				if (sum[i] + c[i][j] - mini <= d) {
					sum[i] += c[i][j];
					j++;
					flag = true;
					break;
				}
			}
			if (!flag) break;
		}
		bool flag = true;
		for (int i = 0; i < n; i++)
			if (index[i] < m[i])
				flag = false;
		cout << (flag ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 1252