akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


int n, M[MAX][MAX];

void dijkstra() {
    int minv;
    int d[MAX], color[MAX];

    for (int i= 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;
    while(1) {
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n, k;
	cin>>n>>k;
	int a[n];
	for(int i = 0;i<n;i++){
		cin>>a[i];
	}    
	bool dp[k+2];
	memset(dp, 0, sizeof(dp));
	for(int i = 1;i<=k;i++){
		for(int j= 0;j<n;j++){
			if(i>=a[j] and !dp[i-a[j]] ){
				dp[i] = 1;
			}
		}

	}

	if(dp[k]){
		cout<<"First"<<endl;
	} else {
		cout<<"Second"<<endl;
	}
    return 0;
}





Measured memory_bytes: 3744
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
	vector<int> ifact;
vector<int> inv;
vi pow3;
vector<int> pow2;
const int MOD = (1e9 + 7);
ll add(ll a, ll b)
{
	a+=b;
	a%=MOD;
	return a;
}
ll ms(ll a, ll b)
{
	a-=b; a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	a%=MOD; b%=MOD;
	return (a*1LL*b)%MOD;
}
ll modpow(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear(); pow3.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow3.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	pow3[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		pow3[i]=add(pow3[i-1],add(pow3[i-1],pow3[i-1]));
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}

ll F[111];
ll G[111];
ll solve(int bit, ll curL, ll curR)
{
	if(curL<0||curR<0) return 0;
	if(bit<0) return 1;
	ll ans = 0;
	if(curR>=(1LL<<(bit+1))-1&&curL>=(1LL<<(bit+1))-1)
	{
		return pow3[bit+1];
	}
	if(curR>=(1LL<<(bit+1))-1)
	{
		ll coeff = 1;
		for(int i=bit;i>=0;i--)
		{
			if(curL<(1LL<<i))
			{
				coeff=add(coeff,coeff);
				continue;
			}	
			//pick 0
			ans=add(ans,mult(mult(coeff,2),F[i]));
			curL-=(1LL<<i);
		}
		ans=add(ans,coeff);
		return ans;
	}
	if(curL>=curR)
	{
		ll coeff = 1;
		for(int i=bit;i>=0;i--)
		{
			if(curR<(1LL<<i))
			{
				continue;
			}	
			//pick 0
			ans=add(ans,mult(coeff,G[i]));
			curR-=(1LL<<i); coeff=mult(coeff,2);
		}
		ans=add(ans,coeff);
		return ans;
	}
	ans=add(ans,solve(bit-1,curL,curR));
	//if y bit is 1, x bit is 0
	ans=add(ans,solve(bit-1,curL,curR-(1LL<<bit)));
	ans=add(ans,solve(bit-1,curL-(1LL<<bit),curR-(1LL<<bit)));	
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(101001);
	ll l,r; cin>>l>>r;
	F[0]=1;
	for(int i=1;i<=61;i++)
	{
		for(int j=0;j<=i;j++)
		{
			F[i]=add(F[i], mult(choose(i,j),pow2[j]));
		}
	}
	G[0]=1;
	for(int i=1;i<=61;i++)
	{
		for(int j=0;j<=i;j++)
		{
			G[i]=add(G[i], mult(choose(i,j),pow2[j]));
		}
	}
	ll ans = 0;
	for(int i=61;i>=0;i--)
	{
		if((1LL<<i)>r) continue;
		//start from y=(1LL<<i),x=(1LL<<i)
		ll curr = r-(1LL<<i);
		ll a = solve(i-1,curr,curr);
		ll b = solve(i-1,l-(1LL<<i)-1,curr);
		ans=add(ans,ms(a,b));
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 2176
#include <cstdio>
#include <algorithm>
int n,flag,p[100010],a[100010],b[100010],c[100010],d[100010];
char s[100010];
int main(){
     while(~scanf("%d",&n)){
         scanf("%s",s);flag=0;
         for(int i=0;i<n;i++){
             if(s[i]=='o')p[i]=0;
             else p[i]=1;
         }a[0]=a[1]=0;
         for(int i=1;i+1<n;i++){
             a[i+1]=a[i-1]^a[i]^p[i];
         }if(a[n-1]^a[0]^a[1]==p[0]&&a[n-1]^a[0]^a[n-2]==p[n-1])flag++;
         b[0]=0;b[1]=1;
         for(int i=1;i+1<n;i++){
             b[i+1]=b[i-1]^b[i]^p[i];
         }if(b[n-1]^b[0]^b[1]==p[0]&&b[n-1]^b[0]^b[n-2]==p[n-1])flag++;
         c[0]=1;c[1]=0;
         for(int i=1;i+1<n;i++){
             c[i+1]=c[i-1]^c[i]^p[i];
         }if(c[n-1]^c[0]^c[1]==p[0]&&c[n-1]^c[0]^c[n-2]==p[n-1])flag++;
         d[0]=d[1]=1;
         for(int i=1;i+1<n;i++){
             d[i+1]=d[i-1]^d[i]^p[i];
         }if(d[n-1]^d[0]^d[1]==p[0]&&d[n-1]^d[0]^d[n-2]==p[n-1])flag++;
         if(!flag)puts("-1");
         else{
             if(a[n-1]^a[0]^a[1]==p[0]&&a[n-1]^a[0]^a[n-2]==p[n-1]){
                 for(int i=0;i<n;i++){
                     if(a[i])printf("W");
                     else printf("S");
                 }puts("");continue;
             }
             if(b[n-1]^b[0]^b[1]==p[0]&&b[n-1]^b[0]^b[n-2]==p[n-1]){
                 for(int i=0;i<n;i++){
                     if(b[i])printf("W");
                     else printf("S");
                 }puts("");continue;
             }
             if(c[n-1]^c[0]^c[1]==p[0]&&c[n-1]^c[0]^c[n-2]==p[n-1]){
                 for(int i=0;i<n;i++){
                     if(c[i])printf("W");
                     else printf("S");
                 }puts("");continue;
             }
             if(d[n-1]^d[0]^d[1]==p[0]&&d[n-1]^d[0]^d[n-2]==p[n-1]){
                 for(int i=0;i<n;i++){
                     if(d[i])printf("W");
                     else printf("S");
                 }puts("");continue;
             }
         }
     }return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

int n, k;
vector<ll> dp;
vector<ll> h;

const ll INF = 1ll << 60;

void mindp(int p, int a, int b) {
  for (int i = a; i <= b; i++) {
    dp[p] = min(dp[p], dp[i] + abs(h[i] - h[p]));
  }
  return;
}

int main() {
  cin >> n >> k;
  h = vector<ll>(n);
  rep(i, n) cin >> h[i];
  dp = vector<ll>(n);
  rep(i, n) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    mindp(i, max(i - k, 0), i - 1);
  }
  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 4788
#include <stdio.h>
#include <math.h>

int isPrime(int);

int main(){

    int i,j,n,num;
    int count=0;
    int a;

scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&num);
    a=isPrime(num);
    if(a==1) count++;
}

printf("%d\n",count);

return 0;
}

int isPrime(int x){
    
    int i;

    if(x==2) return 1;

    if(x<2||x%2==0) return 0;

    for(i=2;i<=sqrt(x);i++){
        if(x%i==0) return 0;
    }

return 1;

}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

bool isPrime(int n) {
  if (n < 2) return false;
  else if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

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

  int n;
  cin >> n;

  int ans = 0;
  rep(i, n) {
    int a;
    cin >> a;
    if (isPrime(a)) ++ans;
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int max=0;
		for(int i=1; i<=N; i+=2) {
			max++;
		}
		if(max>=K) {
			pl("YES");
		}
		else {
			pl("NO");
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define int long long
#define inf (int)(3e18)
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[7],b[7];
signed main(){
	rep(i,7)cin>>a[i];
	rep(i,7)b[i]=a[i];
	int ans=a[1],ans2=a[1];
	if(a[0]&&a[3]&&a[4]){
		ans+=3;a[0]--;a[3]--;a[4]--;
		ans+=a[0]/2*2+a[3]/2*2+a[4]/2*2;
	}
	ans2+=b[0]/2*2+b[3]/2*2+b[4]/2*2;
	cout<<max(ans,ans2)<<endl;
}


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

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    ll res = 0;
    for(int i = 0; i < N; ++i) {
        if(i != N - 1) {
            if(A[i] & 1 && A[i + 1] > 0) {
                res++;
                A[i]--;
                A[i + 1]--;
            }
        }
        res += A[i] / 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  set<int> S;
  S.insert(s);
  int x=s,ans;
  for (int i=2;;i++){
    if (x%2==0){
      x/=2;
    }
    else {
      x=3*x+1;
    }
    if (S.count(x)){
      ans=i;
      break;
    }
    else {
      S.insert(x);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, x; cin >> n >> x;
	if (x == 1 || x == 2 * n - 1)cout << "No\n";
	else if (x == 2) {
		cout << "Yes\n";
		if (n == 2)cout << "1\n2\n3\n";
		else {
			for (int i = 0; i < n - 2; i++)
				cout << i + 5 << endl;
			cout << "4\n1\n2\n3\n";
			for (int i = n + 3; i < 2 * n; i++)
				cout << i << endl;
		}
	}
	else {
		cout << "Yes\n";
		int i = 1;
		for (int j = 0; j < n - 2; j++) {
			if (i == x - 2)i = x + 2;
			cout << i++ << endl;
		}
		printf("%d\n%d\n%d\n%d\n", x - 2, x + 1, x, x - 1);
		for (int j = n + 3; j < 2 * n; j++) {
			if (i == x - 2)i = x + 2;
			cout << i++ << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1536
n = int(input())
a = list(map(int,input().split()))

ans = {}
for i in range(n-1) :
  if a[i] in ans :
    ans[a[i]] += 1
  else :
    ans[a[i]] = 1
    
for i in range(1,n+1) :
  if i in ans :
    print(ans[i])
  else :
    print(0)

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

int bubbleSort(int A[], int N){
    int count = 0;
    int flag = true;
    while(flag){
        flag = 0;
        for(int j=N-1, tmp=0; j>=1; j--){
            if(A[j] < A[j - 1]){
                tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
                flag = true;
                count++;
            }
        }
    }
    for(int i=0; i<N; i++){
        cout << A[i];
        if(i < N-1) cout << " ";
    }
    cout << endl;
    return count;
}

int main(void)
{
    int length = 0;
    int num_array[101];
    
    cin >> length;
    
    // gets num
    for(int i=0; i<length; i++){
        cin >> num_array[i];
    }
    
    // Bubble Sort
    cout << bubbleSort(num_array, length) << endl;
    
    return 0;
}



Measured memory_bytes: 3096
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 ll n;
 cin>>n;
 ll ans=(n/500)*1000;
 n%=500;
 ans+=n/5*5;
 cout<<ans<<"\n";
}


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

long long N, M, X;
long long C[20];
long long A[20][20];

int main(){
	cin >> N >> M >> X;
	for(long long i = 0; i < N; i++) {
		cin >> C[i];
		for(long long j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}


	long long ans = LONG_MAX;
	for(long long pat = 0; pat < (1<<N); pat++) {
		vector<long long> rikai(20);
		long long cost = 0;
		for(long long idx = 0; idx < N; idx++) {
			//idx版目の教科書を読む
			if((pat>>idx)&1) {
				cost += C[idx];
				for(long long kamoku = 0; kamoku < M; kamoku++) {
					rikai[kamoku] += A[idx][kamoku];
				}
			}
		}

		bool ok = true;
		for(long long kamoku = 0; kamoku < M; kamoku++) {
			if(rikai[kamoku] < X) {
				ok = false;
			}
		}
		if(ok) {
			ans = min(ans, cost);
		}
	}
	if(ans == LONG_MAX) {
		cout << -1 << endl;
	}else{
	cout << ans << endl;
	}
}



Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAXN = 50;

int main()
{
    int n;
    lld a[MAXN+1] = {0};

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

    lld max = 0;
    int num = 0;
    for(int i = 1; i <= n; i++)
    {
        if (abs(a[i]) > max)
        {
            max = abs(a[i]);
            num = i;
        }
    }

    max = a[num];


    vector<pair<int,int> > change;

    for(int i = 1; i <= n; i++)
    {
        pair<int,int> p;
        p.first = num;
        p.second = i;
        //a[i] += max;

        change.push_back(p);
    }

    // for(int i = 0; i < n; i++)
    // {
    //     cout << a[i] << " ";
    // }
    // printf("\n");
    if (max == 0)
    {
        cout << 0 << endl;
        return 0;
    }else if (max > 0)
    {
        for(int i = 2; i <= n; i++)
        {
            pair<int,int> p;
            p.first = i-1;
            p.second = i;
            //a[i] += a[i-1];
            change.push_back(p);
        }
    }else
    {
        for(int i = n-1; i >= 1; i--)
        {
            pair<int,int> p;
            p.first = i+1;
            p.second = i;
            //a[i] += a[i+1];
            change.push_back(p);
        }
    }

    cout << change.size() << endl;
    for(int i = 0; i < change.size(); i++)
    {
        cout << change[i].first << " " << change[i].second << endl;
    }

    // for(int i = 0; i < n; i++)
    // {
    //     cout << a[i] << " ";
    // }
    // printf("\n");

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
using namespace std;
int main(){
  string s; cin >> s;
  set<char>a;
  for(int i = 0; i < 4; i++){
    a.insert(s.at(i));
  }
  if(a.size() == 2)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

 
int main(){
  int n, k;
  scanf("%d %d", &n, &k);
  printf("%d\n", n%k!=0);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for(int i = 1;i <= 20; ++i)
	{
		if(i * 111 >= n)
		{
			printf("%d\n",i * 111);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

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

	LL ans = 0;

	map<LL, LL> m;
	for (int i = 0; i < n; i++) {
		ans += m[a[i]]; m[a[i]]++;
	}

	for (int i = 0; i < n; i++) {
		cout << ans - (m[a[i]] - 1) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	int lena,b=0;
	cin>>a;
	lena=a.size();
	for(int i=0;i<lena;i++){
		if(a[i]=='C'&&b==0)
			b=1;
		if(a[i]=='F'&&b==1){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color, D; vll path;
//***********//
int main() {
	ll T;
	cin >> N >> T;
	for (i = 0; i < N; i++) {
		ll c, t;
		cin >> c >> t;
		if (t <= T) ans = min(ans, c);
	}
	if (ans == INF)cout << "TLE";
	else cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int prev = 0;
		long count = 0;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    count += (prev + x) / 2;
		    if (x == 0) {
		        prev = 0;
		    } else {
		        prev = (prev + x) % 2;
		    }
		}
		System.out.println(count);
   }
}




Measured memory_bytes: 49508
def solve():
    n, k = map(int, input().split())
    d = set(input().split())
    while True:
        s = str(n)
        for x in d:
            if x in s:
                break
        else:
            print(s)
            break
        n += 1


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int n,m;

const int Max = 5020;

int data[Max * Max * 5 / 3];

int* getdata(int x,int y){
	//return &data[y * Max + x];
	int a;
	y += 2;
	a = (y * (y + 1)) / 2;
	a += x;
	return &data[a];
}


void debug(){
#if 0
	//int n = 50;
	for(int j=1;j<=n + 1;j++){
		for(int i=1;i<=j + 2;i++){
			printf("%+d ",*(getdata(i,j)));
		}
		puts("");
	}
	puts("");
#endif	
}

int main(){
	scanf("%d %d",&n,&m);
	int a,b,x;
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&b,&a,&x);
		//printf("%d %d %d\n",a,b,x);
		*(getdata(a,b)) += 1;
		*(getdata(a+1,b)) -= 1;
		*(getdata(a,b + x + 1)) -= 1;
		*(getdata(a+1,b + x + 1 + 1)) += 1;
		*(getdata(a + x + 2,b + x + 1)) += 1;
		*(getdata(a + x + 2,b + x + 1 + 1)) -= 1;
	}
	debug();
	//ツ可。ツづ可づづゥ
	for(int i=0;i<Max;i++){
		int s = 0;
		for(int j=0;j<i + 2;j++){
			s += *(getdata(j,i));
			*(getdata(j,i)) = s;
		}
	}
	debug();
	//ツ縦ツづ可づづゥ
	for(int i=0;i<Max;i++){
		int s = 0;
		for(int j=i;j<Max;j++){
			s += *(getdata(i,j));
			*(getdata(i,j)) = s;
		}
	}
	debug();
	//ツ偲篠づ淞づ可偲ヲツづゥ
	for(int i=0;i<Max;i++){
		int s=0;
		for(int j=0;i+j<Max;j++){
			//printf("%d,%d:%d\n",i,j,i+j);
			if(j < 0 || j + i < 0){ continue; }
			if(j >= Max || j + i >= Max){ break; }
			s += *(getdata(j,i+j));
			*(getdata(j,i+j)) = s;
		}
	}
	debug();
	int ans = 0;
	for(int i=0;i<Max;i++){
		for(int j=0;j<=i;j++){
			if(*(getdata(j,i)) > 0){
				ans++;
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 48000
import java.util.LinkedList;
import java.util.Scanner;


public class Main {
	public static final int[][] move_dir = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	
	public static boolean is_ok(int x, int y, int w, int h){
		if(x < 0 || x >= w || y < 0 || y >= h){
			return false;
		}
		
		return true;
	}
	
	public static class Shot{
		int clash;
		int[][] clash_list;
		int x, y;
		
		public Shot(int clash, int[][] clash_list, int x, int y, int c_x, int c_y) {
			super();
			this.clash = clash;
			this.clash_list = new int[10][];
			for(int i = 0; i < clash - 1; i++){
				this.clash_list[i] = new int[]{clash_list[i][0], clash_list[i][1]};
			}
			this.clash_list[clash - 1] = new int[]{c_x, c_y};
			this.x = x;
			this.y = y;
		}
		
		public Shot(int clash, int x, int y){
			super();
			this.clash = clash;
			this.clash_list = new int[10][];
			this.x = x;
			this.y = y;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(w == 0 && h == 0){
				break;
			}
			
			boolean[][] is_wall = new boolean[h][w];
			int s_x = 0, s_y = 0, g_x = 0, g_y = 0;
			
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					final int t = sc.nextInt();
					
					if(t == 1){
						is_wall[i][j] = true;
					}else if(t == 2){
						s_x = j;
						s_y = i;
					}else if(t == 3){
						g_x = j;
						g_y = i;
					}
				}
			}
			
			//System.out.println(s_x + " " + s_y + " " + g_x + " " + g_y);
			
			LinkedList<Shot> queue = new LinkedList<Shot>();
			queue.add(new Shot(0, s_x, s_y));
			
			boolean found = false;
			while(!queue.isEmpty()){
				Shot shot = queue.poll();
				
				if(shot.clash >= 10){
					continue;
				}
				
				//System.out.println(shot.clash + " " + shot.x + " " + shot.y);
				
				for(int i = 0; i < shot.clash; i++){
					is_wall[shot.clash_list[i][1]][shot.clash_list[i][0]] = false;
				}
				
				for(int[] move : move_dir){
					int n_x = shot.x + move[0];
					int n_y = shot.y + move[1];
					
					if(!is_ok(n_x, n_y, w, h) || is_wall[n_y][n_x]){
						continue;
					}else if(n_x == g_x && n_y == g_y){
						System.out.println(shot.clash + 1);
						found = true;
						break;
					}
					
					while(true){
						n_x += move[0];
						n_y += move[1];
						
						if(!is_ok(n_x, n_y, w, h)){
							break;
						}else if(is_wall[n_y][n_x]){
							//System.out.println("> " + shot.clash + " " + n_x + " " + n_y);
							queue.add(new Shot(shot.clash + 1, shot.clash_list, n_x - move[0], n_y - move[1], n_x, n_y));
							break;
						}else if(n_x == g_x && n_y == g_y){
							System.out.println(shot.clash + 1);
							found = true;
							break;
						}
					}
					
					if(found){
						break;
					}
				}
				
				if(found){
					break;
				}
				
				for(int i = 0; i < shot.clash; i++){
					is_wall[shot.clash_list[i][1]][shot.clash_list[i][0]] = true;
				}
			}
			
			if(!found){
				System.out.println(-1);
			}
		}
		
	}

}

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

template<typename T, typename K> struct P{
    T a;
    K b;
};

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	string a, b;
	cin >> a >> b;
	int N, A, B, C;
	cin >> N >> A ;
	string c;
	cin >> c;
	if (c == a){
		N--;
	}
	else
		A--;
	cout << N << " " << A << endl;

}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 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;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

ll GCD(vl &v) {  // vの全要素のgcd
    ll res = v[0];
    rep(i, v.size()) {
        res = gcd(res, v[i]);
    }
    return res;
}

// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    if(GCD(a) > 1) {
        out("not coprime");
        re0;
    }

    vl v(1000010);
    rep(i, n) {
        map<ll, ll> mp = primefactor(a[i]);
        for(auto p : mp) {
            if(v[p.first]) {
                out("setwise coprime");
                re0;
            }
            v[p.first] = 1;
        }
    }

    out("pairwise coprime");
    re0;
}

Measured memory_bytes: 18728
#include<bits/stdc++.h>
using namespace std;
int main () 
{
    int n, m;
    cin>>n>>m;
    vector<bool>vis(n+1,false);
    bool ans=false;
    for(int i = 0; i < m; i++) 
    {
        int a, b ;
        cin>>a>>b ;
        assert(1<=a && a<b && b<=n);
        if(a == 1) 
        {
            if(vis[b])
                ans = true;
            vis[b] = true;
        } 
        else if(b == n) 
        {
            if(vis[a])
                ans = true;
            vis[a] = true;
        }
    }
    if(!ans) 
        cout<<"IM";
    cout<<"POSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x1 = 0
x2 = W
y3 = 0
y4 = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        if x1 < x[i]:
            x1 = x[i]
    elif a[i] == 2:
        if x2 > x[i]:
            x2 = x[i]
    elif a[i] == 3:
        if y3 < y[i]:
            y3 = y[i]
    elif a[i] == 4:
        if y4 > y[i]:
            y4 = y[i]

if x2-x1 <=0 or y4-y3 <= 0:
    print(0)
else:
    print((x2-x1)*(y4-y3))


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

int main() {
  int n;
  int count = 0;
  cin >> n;

  for (int i = 1; i < n; i++) {
    int d = n - i;
    int l = floor(sqrt(d));
    for (int j = 1; j <= l; j++) {
      
      if (d % j == 0) {
        if (d == j * j) {
          count += 1;
        } else {
          count += 2;
        }
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n,d;
    cin>>n>>d;
    int m=d*2+1;
    cout<<(n+m-1)/m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i<k;i++)
int w,h,xs,ys,xg,yg,n;
int m[102][102];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool DFS(int x,int y,int c){
  if(m[x][y]!=c)return false;
  if(x==xg && y == yg)return true;
  m[x][y]=-1;
  bool ans =false;
  rep(i,0,4){
    ans = max(ans,DFS(x+dx[i],y+dy[i],c));
  }
  return ans;
}
int main(){
  cin >>w>>h;
  while(w!=0){
    cin>>xs>>ys>>xg>>yg>>n;
    xs++;
    ys++;
    xg++;
    yg++;
    rep(i,0,102)rep(j,0,102)m[i][j]=-1;
    rep(i,0,n){
      int c,d,x,y;
      cin >>c>>d>>x>>y;
      x++;
      y++;
      if(d==0){
        rep(j,x,x+4)rep(k,y,y+2)m[j][k]=c;
      }else{
        rep(j,x,x+2)rep(k,y,y+4)m[j][k]=c;
      }
    }
    string ans[2]={"NG","OK"};
    if(m[xs][ys]==-1)cout <<"NG"<<endl;
    else cout << ans[DFS(xs,ys,m[xs][ys])]<<endl;
    cin >> w>>h;
  }
  return 0;
}



Measured memory_bytes: 3200
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int>b(n-1);
	rep(i,n-1)cin>>b[i];
	int sum=0;
	sum+=b[0];
	rep(i,n-2) sum+=(b[i]<b[i+1])?b[i]:b[i+1];
	sum+=b[n-2];
	cout<<sum<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

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

	int r;
	cin >> r;

	cout << setprecision(10) << 2 * r * 3.1415926535 << endl;

	return 0;
}

Measured memory_bytes: 3816
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
bool isPerfectSquare(long double x) 
{  
  long double sr = sqrt(x);  
  return ((sr - floor(sr)) == 0); 
}
int main()
{
  	fast();
    ll n,i,j,d,k,ans=0;
    cin>>n>>d;
    ll a[n][d];
    for(i=0;i<n;i++)
    {
        for(j=0;j<d;j++)
            cin>>a[i][j];
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            long double p=0;
            for(k=0;k<d;k++)
            {
                p+=((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
            }
            if(isPerfectSquare(p))
                ans++;
        }
    }
    cout<<ans;
    exit(0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000
int head,tail;
int Q[MAX];
char QN[MAX][11];
char retname[11];

void initialize(void){
	head=0;
	tail=0;
}

int isEmpty(){
	return head==tail;
}

int isFull(){
	return head==(tail+1)%MAX;
}

void enqueue(char *name, int x){
	if(isFull()){
		exit(1);
	}
	strcpy(QN[tail],name);
	Q[tail]=x;
	if(tail+1==MAX){
		tail=0;
	}else{
		tail++;
	}
}

int dequeue(){
	int x;
	if(isEmpty()){
		exit(1);
	}
	x=Q[head];
	strcpy(retname,QN[head]);
	if(head+1==MAX){
		head=0;
	}else{
		head++;
	}
	return x;
}

int main(void){
	int n,q;
	int alltime=0;
	int i;
	char inputN[11];
	int inputT;
	scanf("%d",&n);
	scanf("%d",&q);
	initialize();
	for(i=0;i<n;i++){
		scanf("%s",inputN);
		scanf("%d",&inputT);
		enqueue(inputN, inputT);
	}
	int useT;
	while(1){
		if(isEmpty()==1) break;
		useT=dequeue();
		if(useT<=q){
			alltime+=useT;
			printf("%s %d\n",retname,alltime);
		}else{
			alltime+=q;
			useT-=q;
			enqueue(retname,useT);
		}
	}
	
	return 0;
}

Measured memory_bytes: 3196
#include<stdio.h>
int main()
{
	int n,a[111]={},i,j,x=0,y=0;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(a[i]<a[j]){
				a[i]+=a[j];
				a[j]=a[i]-a[j];
				a[i]=a[i]-a[j];
			}
	for(i=0;i<n;i++){
		if(i%2==0)
			x+=a[i];
		else
			y+=a[i];
	}
	printf("%d",x-y);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,a1,b1;
    cin>>n>>a>>b;
    if(a>n)    a1=a-n;
    else a1=n-a;
    if(b>n)    b1=b-n;
    else b1=n-b;
    if(a1<b1) cout<<'A'<<endl;
    else cout<<'B'<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	ll sum=0;
	for(ll i=n-1;i>=0;i--)
	{
		sum+=a[i];
	}
	if(sum%10==0)
	{
		for(ll i=0;i<n;i++)
		{
			if((sum-a[i])%10!=0)
			{
				cout<<sum-a[i];return 0;
			}
		}
		cout<<0;return 0;
	}
	else cout<<sum;
}

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

using namespace std;

struct edge {
	int to, cost;
};
typedef pair<int, int> P;

int V;
vector<vector<edge>> G;
vector<int> d;
vector<int> g;

const int INF = 10e8;

void dijkstra(int s)
{
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	fill(g.begin(), g.end(), INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		if (d[v] < p.first)
			continue;

		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				g[e.to] = v;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	
}

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

	V = n;
	G.resize(n);
	d.resize(n);
	g.resize(n);
	for (int i = 0; i < m; i++) {
		G[a[i]-1].push_back(edge{b[i]-1, 1});
		G[b[i]-1].push_back(edge{a[i]-1, 1});
	}

	dijkstra(0);
	cout << "Yes" << endl;
	for (int i = 1; i < n; i++) {
		cout << g[i]+1 << endl;
	}
}

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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int ar[100000+5];
int dp[100000+5];

int main()
{
    IOS
    int n;
    cin >> n;
    REP(i,n)
    cin>>ar[i];

    dp[0]=0;
    dp[1]=abs(ar[1]-ar[0]);

    FOR(i,2,n,1)
    {
        dp[i] = min(dp[i-1]+abs(ar[i]-ar[i-1]), dp[i-2]+abs(ar[i]-ar[i-2]));
    }
    cout << dp[n-1];
    
}

Measured memory_bytes: 1024
#include <vector>



template<class E> struct AdjMat { //adjacency matrix
  using size_t = std::size_t;
  size_t n; E ei; std::vector<std::vector<E>> dat;
  AdjMat() {}
  AdjMat(size_t n, E ei) : n(n), ei(ei), dat(n, std::vector<E>(n, ei)) {}
  void init(size_t n) { this->n = n; dat.resize(n); for(size_t i=0;i<n;++i) dat[i].assign(n, ei); }
  auto& operator[](size_t i) { return dat[i]; }
  void wf() { // WarshallFloyd
    for(size_t k=0; k<n; ++k) for(size_t i=0; i<n; ++i) for(size_t j=0; j<n; ++j) {
      if(dat[i][k] == ei || dat[k][j] == ei) continue;
      E e = dat[i][k] + dat[k][j];
      if(dat[i][j] == ei || e < dat[i][j]) dat[i][j] = e;
    }
  }
  auto begin() { return dat.begin(); }
  auto end() { return dat.end(); }
};



#include <iostream>

void abc143_e() {
  using namespace std;
  int N, M;
  long long L;
  cin >> N >> M >> L;
  AdjMat<long long> g(N, -1);
  for(int i=0;i<M;++i) {
    int A, B, C;
    cin >> A >> B >> C;
    --A; --B;
    g[A][B] = C;
    g[B][A] = C;
  }

  g.wf();
  for(auto& v : g) for(auto& e : v) e = (e != g.ei && e <= L ? 1 : g.ei);
  g.wf();

  int Q; cin >> Q;
  for(int i=0;i<Q;++i) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    cout << (g[s][t] == g.ei ? -1 : g[s][t]-1) << '\n';
  }
}

signed main() {

  abc143_e();

  return 0;
}


Measured memory_bytes: 1280
sd = input()
t = input()
keylist = []
for i in range(len(sd) - len(t) + 1):
    a = sd[i:i+len(t)]
    flag = True
    for j in range(len(t)):
        if a[j] == t[j]:
            pass
        elif a[j] == '?':
            a = a[:j] + t[j] + a[j+1:]
            #print(sd)
        else:
            flag = False
            #print('False')
            break
    if(flag == True):
        keylist.append((sd[:i]+a+sd[i+len(t):]).replace('?','a'))
keylist.sort()
if keylist != []:
    print(keylist[0])
else:
    print('UNRESTORABLE')

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

//諸機能
#pragma region MACRO 
#define putans(x)  cerr << "answer: " ; cout << (x) << endl
#define dputans(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define input ifs >>
#else //いい感じにやる
#define input cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

int main() {
	int n; input n;
	vi a;
	vector<pii> b;

	rep(i, n) {
		int k; input k;
		a.push_back(k);
		b.push_back(mp(k,i+1));
	}
	if (n == 1) { 
		putans(0);
		return  0;
	}
	if (n == 2) {
		if (a[0] > a[1]) {
			putans(1);
		}
		else {
			putans(0);
		}
		return 0;
	}
	sort(all(b));
	int oezure = 0;
	rep(i, n) {
		if (b[i].second % 2 != ( i + 1 ) % 2) oezure++;
	}
	putans(oezure/2);
	return 0;
}


Measured memory_bytes: 1780
<?php
	$x=$y=0;
	fscanf(STDIN,"%d%d%d",$X,$Y,$n);
	for($i=0;$i<$n;$i++)
	{
		fscanf(STDIN,"%d%d%d",$a,$b,$c);
		if($c==1&&$x<$a)$x=$a;
		if($c==2&&$X>$a)$X=$a;
		if($c==3&&$y<$b)$y=$b;
		if($c==4&&$Y>$b)$Y=$b;
	}
	echo ($x<$X?$X-$x:0)*($y<$Y?$Y-$y:0);


Measured memory_bytes: 3828
x,y=map(int,input().split())
initx=x
inity=y
while True:
    if x<y:
        x,y=y,x#常にx>yにしたい
    pre_gcd=x%y
    if pre_gcd==0:
        print(y)
        break
    elif initx%pre_gcd==0 and inity%pre_gcd==0:
        print(pre_gcd)
        break
    x=pre_gcd
    


Measured memory_bytes: 5600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define fi first
#define se second
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define out(t, a) copy(all(a), ostream_iterator<t>(cout, " ")); cout << "\n";
// #define DEBUG
#define int long long

using namespace std;

void set_program() {
	#ifdef DEBUG
		freopen ("test.in", "r", stdin);
		freopen ("test.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pt;

const int INF = 1e9 + 1;
const int MAXN = 3000;
const int LOGN = 20;
const int MOD = 1e7;
const int ALF = 26;

void solve() {
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
}

main() {
	set_program();
	int t;
	#ifdef DEBUG
		// cin >> t;
		t = 1;
	#else
		// cin >> t;
		t = 1;
	#endif
	for (; t--; ) {
		solve();
		cout << "\n";
	}
 	return 0;
}

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

using namespace std;

void solve()
{
    int n;
    while (cin >> n && n)
    {
        vector<double> as(n), bs(n);
        for (int i = 0; i < n; i++)
        {
            cin >> as[i];
        }
        for (int i = 0; i < n; i++)
        {
            cin >> bs[i];
        }
        double ans[4] = {0};
        for (int i = 0; i < n; i++)
        {
            ans[0] += fabs(as[i] - bs[i]);
            ans[1] += pow(fabs(as[i] - bs[i]), 2);
            ans[2] += pow(fabs(as[i] - bs[i]), 3);
            ans[3] = max(ans[3], fabs(as[i] - bs[i]));
        }
        ans[1] = sqrt(ans[1]);
        ans[2] = cbrt(ans[2]);
        for (int i = 0; i < 4; i++)
        {
            cout << setprecision(9) << ans[i] << endl;
        }
    }
}

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



Measured memory_bytes: 3480