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

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

  int a, b, c;
  cin >> a >> b >> c;
  if (a < b && b < c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n, k, m;
		cin >> n >> k >> m;
		if (!n)break;
		vi v(n);
		REP(i, n)v[i] = i;
		int p = m-1;
		REP(i, n - 1) {
			v.erase(v.begin() + p);
			p = (p - 1 + k) % v.size();
		}
		cout << v[0] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int count = 0;
		if(A == 5 || A == 7) {
			count++;
		}
		if(A == 7) {
			if(B == 5) {
				count++;
			}
		} else if(A == 5) {
			if(B == 5 || B == 7) {
				count++;
			}
		}
		if(A == 7 && B == 5) {
			if(C == 5) {
				count++;
			}
		} else if(A == 5 && B == 7) {
			if(C == 5) {
				count++;
			}
		} else if(A == 5 && B == 5) {
			if(C == 7) {
				count++;
			}
		}
		if(count == 3) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 35364
#include<bits/stdc++.h>
#define N 2000009
#define ll long long
#define ld long double
#define ff first
#define ss second
#define inf 1000000005
#define mod 1000000007
using namespace std;
int n;
double p[3009];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    vector<double> dp(n + 1, 0);
    dp[0] = 1;
    for(int i=1;i<=n;i++) {
        vector<double> newdp = dp;
        newdp[0] *= (1 - p[i]);
        for(int j=1;j<=i;j++) {
            newdp[j] = p[i] * dp[j - 1] + (1 - p[i]) * dp[j];
            //cout<<i<<" "<<j<<" "<<newdp[j]<<endl;
        }
        dp = newdp;
    }
    double ans;
    for(int i=n/2+1;i<=n;i++)
        ans += dp[i];
    cout.precision(15);
    cout<<fixed<<ans;
}


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

typedef vector<int> vi;
typedef vector<vi> vii;

const int INF = 1000000000;

int N, Ma, Mb;
vi A, B, C;
vector<vii> dp;

int main(void) {
	cin >> N >> Ma >> Mb;
	A.resize(N);
	B.resize(N);
	C.resize(N);
	int sum_a = 0;
	int sum_b = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
		sum_a += A[i];
		sum_b += B[i];
	}

	vi vb;
	vb.resize(sum_b + 1, INF);
	vii va;
	va.resize(sum_a + 1, vb);
	dp.resize(N + 1, va);

	dp[0][0][0] = 0;
	for (int i = 0; i < N; ++i) {
		for (int ca = 0; ca <= sum_a; ++ca) {
			for (int cb = 0; cb <= sum_b; ++cb) {
				if (dp[i][ca][cb] == INF)
					continue;
				dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
				dp[i + 1][ca + A[i]][cb + B[i]] = min(dp[i + 1][ca + A[i]][cb + B[i]], dp[i][ca][cb] + C[i]);
			}
		}
	}

	int ans = INF;
	for (int ca = 1; ca <= sum_a; ++ca) {
		for (int cb = 1; cb <= sum_b; ++cb) {
			if (ca * Mb == cb * Ma)
				ans = min(ans, dp[N][ca][cb]);
		}
	}

	if (ans == INF)
		ans = -1;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int x, y;
    while (cin >> x >> y) {
        if (x == 0 && y == 0)
            break;
        cout << min(x, y) << " " << max(x, y) << endl;
    }
}



Measured memory_bytes: 3040
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k%2==0)cout << a-b << endl;
    else cout << b-a << endl;

    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>
#include<limits.h>
int main(void)
{
	int n,m,a[50],b[50],c[50],d[50],min,x,i,j;
	scanf("%d %d", &n, &m);
	for(i=0; i<n; i++)
	scanf("%d %d", &a[i], &b[i]);
	for(i=0; i<m; i++)
	scanf("%d %d", &c[i], &d[i]);
	for(i=0; i<n; i++)
	{
		min=INT_MAX;
		for(j=0; j<m; j++)
		{
			if(min>(abs(a[i]-c[j]))+(abs(b[i]-d[j])))
			{
				min=(abs(a[i]-c[j]))+(abs(b[i]-d[j]));
				x=j;
			}
		}
		printf("%d\n", x+1);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll syuu[100002];
ll sc[100002];//集合の数カウント
ll find(ll x){
    if(syuu[x]==x){
        return x;
    }else{
        return syuu[x]=find(syuu[x]);
    }
}


int main(){
    
    
      ll n,m;
    cin>>n>>m;
    ll a[m],b[m];
    
    rep(i,m){
        cin>>a[i]>>b[i];
       
    }
    
    ll ans[m];
    rep(i,m){
        ans[i]=0;
    }
   
    for(ll i=m-1;i>=0;i--){
        
        //cout<<a[i]<<b[i]<<endl;
        
        if(syuu[a[i]]==0&&syuu[b[i]]==0){
            ans[i]=1;
            ll pp=max(a[i],b[i]);
            syuu[a[i]]=pp;
            syuu[b[i]]=pp;//その添字要素の親を保管
            
            sc[pp]+=2;//その集合の親pp その集合の数sc
            
            
        }else if(syuu[a[i]]==0||syuu[b[i]]==0){
            
            ll ss;
            if(syuu[a[i]]!=0){ss=find(a[i]);}else{ss=find(b[i]);}
            if(syuu[a[i]]==0){syuu[a[i]]=ss;}else{syuu[b[i]]=ss;}
            
            
            ans[i]=sc[ss];
            
            sc[ss]++;
            
        }else{
            ll u=find(syuu[a[i]]);
            ll k=find(syuu[b[i]]);
            if(u==k){
                ans[i]=0;
                
            }else{
                
                ans[i]=sc[u]*sc[k];
                sc[k]+=sc[u];
                syuu[u]=k;
            }
            
        }
        //cout<<ans[i]<<" "<<i<<endl;
    }
    ll h=0;
    for(int i=0;i<m;i++){
        h+=ans[i];
        cout<<h<<endl;
    }

return 0;
}


Measured memory_bytes: 5248
N=int(input())
S=input()
ANS=-1
def check(s,a,b,c):
    if s=="o":
        if b=="S" and a==c:
            return True
        elif b=="W" and a!=c:
            return True
    else:
        if b=="S" and a!=c:
            return True
        elif b=="W" and a==c:
            return True
    return False
for start in ["SS","SW","WS","WW"]:
    ans=start
    for i in range(2,N):
        if S[i-1]=="o":
            if ans[i-2]==ans[i-1]:
                ans+="S"
            else:
                ans+="W"
        else:
            if ans[i-2]==ans[i-1]:
                ans+="W"
            else:
                ans+="S"
    if check(S[0],ans[N-1],ans[0],ans[1]) and check(S[N-1],ans[N-2],ans[N-1],ans[0]):
        ANS=ans
        break
print(ANS)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111
 
#define TASK "1"
 
using namespace std;
 
int n;
string s[555];
 
int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];

	int em = 1;

	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (s[i][j] == '#') em = 0;
	if (em) {
		cout << -1 << endl;
		return 0;
	}
 
	int ans = 1e9 + 1;
 
	int nc = 0;
 
	for (int i = 0; i < n; i++) {
		int fu = 1;
		for (int j = 0; j < n; j++) if (s[j][i] == '.') fu = 0;
		if (!fu) nc++;
 
	}
 
	for (int i = 0; i < n; i++) {
		int have = 0;
		for (int j = 0; j < n; j++) if (s[j][i] == '#') have = 1;
 
		int need = 0;
		for (int j = 0; j < n; j++) if (s[i][j] == '.') need++;
 
		if (need > 0 && have == 0) need++;
 
		ans = min(ans, need + nc);
	}
	if (ans > 1e9) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

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

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

int main() {
	int n,m,w1,ma1=-1,ma2=-1,acnt=0,wcnt=0;
	string w2;
	cin>>n>>m;
	ma1=max(n,m);
	vector<pair<int,pair<bool,int>>>v(ma1+1);
	for(int i=0;i<m;i++){
		cin>>w1>>w2;
		ma2=max(w1,ma2);
		if(v.at(w1).second.first==false && w2=="AC"){
			v.at(w1).second.first=true;
			acnt++;
		}else if(v.at(w1).second.first==false && w2=="WA") {
				v.at(w1).second.second++;
		}
	}
	for(int i=1;i<ma2+1;i++){
		if(v.at(i).second.first==true){
			wcnt+=v.at(i).second.second;
		}
	}
	cout<<acnt<<" "<<wcnt<<endl;

	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int k;
    cin >> k;
    queue<ll> q;//キュー
    for(int i = 1;i < 10;i++){
        q.push(i);
    }
    int cnt = 0;
    while(1){
        cnt++;
        ll x = q.front();q.pop();
        //printf("cnt:%d x:%d\n",cnt,x);
        if(cnt == k){
            cout << x << endl;
            return 0;
        }
        ll one_keta = x % 10; //1桁目を出したいときは10で割った余り
        if(one_keta == 0){
            for(int i = 0;i <= 1;i++){
                q.push(x * 10 + i);
            }
        }else if(one_keta == 9){
            for(int i = 8;i <= 9;i++){
                q.push(x * 10 + i);
            }
        }else{
            for(int i = one_keta - 1;i <= one_keta + 1;i++){
                q.push(x * 10 + i);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long powing(long long a, long long b) {
	long long ans = 1;
	while (b != 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MAX_MOD;
		}
		a *= a;
		a %= MAX_MOD;
		b /= 2;
	}
	return ans;
}
long long cnt[300000] = {};
int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> inputs;
	for (long long i = 1; i <= sqrt(n); ++i) {
		if (n % i == 0) {
			inputs.push_back(i);
			if (i * i != n) {
				inputs.push_back(n / i);
			}
		}
	}
	sort(inputs.begin(), inputs.end());
	long long ans = 0;
	for (int i = 0; i < inputs.size(); ++i) {
		cnt[i] = powing(k, (inputs[i] + 1) / 2);
		for (int q = 0; q < i; ++q) {
			if (inputs[i] % inputs[q] != 0) continue;
			cnt[i] += MAX_MOD - cnt[q];
			cnt[i] %= MAX_MOD;
		}
		long long geko = inputs[i];
		if (geko % 2 == 0) geko /= 2;
		ans += geko * cnt[i];
		ans %= MAX_MOD;
	}
	cout << ans << endl;
}

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

const int INF = 1e9;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 1) continue;
        if (A[i] % 5 != 0 && A[i] % 3 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}





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

using namespace std;

int N, M, X, Y;
vector<int>x, y;

int main(void) {

	cin >> N >> M >> X >> Y;
	int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; x.push_back(tmp);
	}
	for (int j = 1; j <= M; j++) {
		cin >> tmp; y.push_back(tmp);
	}

	sort(x.begin(), x.end() );
	sort(y.begin(), y.end());

	if (x[N - 1] < y[0] && X<y[0] && x[N-1]<Y) { cout << "No War" << endl; }
	else { cout << "War" << endl; }

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;
const int maxn = 15 + 10;
int n,a[maxn][maxn],b[maxn][maxn],cnt[maxn],c[maxn],Ans;
inline void dfs(int now) {
	if (now == n+1) {
		bool flag = true;
		int ans = 0;
		for (int i = 1;i <= n;i++) {
			ans += c[i];
			for (int j = 1;j <= cnt[i];j++)
				if (c[i] == 1) if (b[i][j] != c[a[i][j]]) { flag = false; break; }
		}
		if (flag) Ans = max(Ans,ans);
		return;
	}
	c[now] = 1;
	dfs(now+1);
	c[now] = 0;
	dfs(now+1);
}
int main() {
	scanf("%d",&n);
	for (int i = 1;i <= n;i++) {
		scanf("%d",&cnt[i]);
		for (int j = 1;j <= cnt[i];j++)
			scanf("%d%d",&a[i][j],&b[i][j]);
	}
	dfs(1);
	printf("%d",Ans);
	return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,k,l; cin >> n >> k >> l;
  ll a[n]; REP(i,n) cin >> a[i];
  ll lb = 0, ub = n+1, x;
  while(ub-lb>1){
    x = (lb+ub)/2;
    //printf("x=%lld\n", x);
    ll b[n+1]; //x以下の個数の累積和
    REP(i,n+1){
      if(i==0) b[i] = 0;
      else b[i] = b[i-1] + ((a[i-1]<=x) ? 1 : 0);
    }
    ll right = k;
    ll cnt = 0;
    for(ll left = 1; left <= n-k+1; left++){
      while(b[right]-b[left-1]<k&&right<=n){
        right++;
      }
      cnt += n-right+1;
      if(left==right) right++;
    }
    //printf("cnt=%lld\n", cnt);
    if(cnt >= l){
      ub = x;
    }else{
      lb = x;
    }
  }
  cout << ub << endl;
  return 0;
}



Measured memory_bytes: 6232
while True:
    try:
        cha = input()
        cha = list(cha)
        ans = ""
        i = 0
        while i < len(cha):
            if cha[i] == "@":
                n = int(cha[i + 1])
                moji = cha[i + 2]
                for j in range(n):
                    ans += moji
                i += 3
            else:
                ans += cha[i]
                i += 1
        print(ans)
    except:
        break

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

using namespace std;

int main(){
	int k, n;
	vector<int> a;
	cin>>k>>n;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		a.push_back(tmp);
	}

	sort(a.begin(), a.end());

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

	int ans = sum-(a[0]+k-a[n-1]);
	//cout<<ans<<" ";
	for(int i=1;i<n-1;i++){
		ans = min(ans, min(sum-(a[i+1]-a[i]), sum-(a[i]-a[i-1])));
		//cout<<ans<<" ";
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
using namespace std;
int n, l, a[200000], flag = -1;
int main() {
	cin >> n >> l; for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n - 1; i++) { if (a[i] + a[i + 1] >= l)flag = i; }
	if (flag == -1)cout << "Impossible" << endl;
	else {
		cout << "Possible" << endl;
		for (int i = 1; i < flag; i++)cout << i << endl;
		for (int i = n - 1; i > flag; i--)cout << i << endl;
		cout << flag << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main(){
  int x;
  cin>>x;
  
  cout<<(x+1)%2<<endl;
  return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int main(){
  int a,b,m,n,l;

  scanf("%d%d",&a,&b);
  if(a>b){
    n = a;
    m = b;
  }
  else{
    m = a;
    n = b;
  }
  while(n%m!=0){
    l = n%m; 
    n = m;
    m = l;
  }

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

  return 0;
}



Measured memory_bytes: 2124
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 510

int h, w;
char s[SIZE][SIZE];

int dx[8] = {0,0,1,-1,1,1,-1,-1};
int dy[8] = {1,-1,0,0,1,-1,1,-1};
char dirchar[] = "DURL"; // "SNWE"

pair<int,int> memo[SIZE][SIZE] = {};
ll ans[SIZE][SIZE] = {};

int check(int Y, int X) {
  bool visited[SIZE][SIZE] = {};

  if (s[Y][X] != '#') return 0;

  queue<pair<int,int> > que;
  que.push({Y,X});

  int res = 0;

  while(que.size()){
    auto p = que.front();
    que.pop();

    int y = p.first;
    int x = p.second;

    if(visited[y][x]) continue;
    visited[y][x] = true;

    debug(memo[y][x]);
    if(memo[y][x].first != -1) {
      return ans[Y][X] = ans[memo[y][x].first][memo[y][x].second];
    }
    memo[y][x] = {Y, X};

    res += s[y][x] != '#';

    for(int i=0;i<4;i++){
      if(0 <= y+dy[i] && y+dy[i] < h && 0<= x+dx[i] && x+dx[i] < w &&
         s[y][x] != s[y+dy[i]][x+dx[i]]){
        que.push({y+dy[i], x+dx[i]});
      }
    }
  }

  ans[Y][X] = res;

  return res;
}

int main(){

  scanf("%d%d", &h, &w);

  for(int i=0;i<h;i++){
    scanf("%s", s[i]);
  }

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      memo[i][j] = {-1, -1};

  ll ans = 0;

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      ans += check(i, j);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int N, A[201010];
//---------------------------------------------------------------------------------------------------
ll solve() {
    ll ans = 0;
    
    if (0 < A[0]) return -1;

    rep(i, 0, N - 1) {
        if (A[i] + 1 < A[i + 1]) return -1;

        if (A[i] + 1 == A[i + 1]) ans++;
        else ans += A[i + 1];
    }
    return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  double height;

  while(cin >> height){
      double N,t;
    for(int i=1;;i++){
      N = 5*i - 5;
      t = sqrt(N/4.9);
      if(height <= 9.8*t){
	cout << i << endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int b1, b2, a;
int ans;
int last;

int calc(int from, int to){
    int now = ans;
    if(from > b1)now++;
    if(from > b2)now++;
    if(from < to)now++;
    if(last-from > a-to)now++;
    return now;
}

int solve(int x){
    int res = calc(last, x);
    res = min(res, calc(b1,x));
    res = min(res, calc(b2,x));
    return res;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++){
        if(i < n)cin >> a;
        else a= 0;
        int tmp = solve(0);
        int bottom = 0, top = a;
        while(top - bottom > 1){
            int mid = (top + bottom) / 2;
            if(solve(mid) <= tmp)bottom = mid;
            else top = mid;
        }
        int new_b1 = bottom;
        if(solve(a) <= tmp)new_b1 = a;

        bottom = 0, top = a;
        while(top - bottom > 1){
            int mid = (top + bottom) / 2;
            if(solve(mid) <= tmp + 1)bottom = mid;
            else top = mid;
        }
        int new_b2 = bottom;
        if(solve(a) <= tmp+1)new_b2 = a;
        ans = solve(0);
        b1 = new_b1;
        b2 = new_b2;
        last = a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

// long long lcm(long long a, long long b){
//     return a * b / gcd(a, b);
// }

int main(){
    char s[101];
    cin >> s;
    for(int i=0;i<=strlen(s);i+=2){
        if(s[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=1;i<=strlen(s);i+=2){
        if(s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
#include <numeric>
#include <utility>
#include<math.h>
#include<functional>
#include<queue>
#include<sstream>
#include<stack>
#include<algorithm>

int solve(std::string s){
    int ct=700;
    for(int i=0;i<s.length();i++)if(s[i]=='o')ct+=100;
    std::cout<<ct;
    return 0;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::string s;
    std::cin>>s;
    return solve(s);
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list( map(int, input().split()))
F = list( map(int, input().split())) 
A = sorted(A)
F = sorted(F, reverse = True)

def isok(ans):
    k_ = 0
    for a,f in zip(A,F):
        if a > ans//f:
            k_ += a - ans//f
            if k_ > k:
                return False
    return True

ok = max(A)*max(F)
ng = 0

while ok - ng >= 1:
    m = (ok+ng)//2
    if ok - ng == 1:
        if isok(ng):
            ok = ng
            break
        break
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)



Measured memory_bytes: 121804
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! {
    	a: usize,
        b: usize,
        c: usize
    }
    println!("{}", calc(a,b,c));
}

fn calc(a:usize, b:usize, d:usize) -> &'static str {
	let mut c = 0;
    if a==b { c+=1 }
    if b==d { c+=1 }
    if d==a { c+=1 }
    match c {
    0 => "No",
    1 => "Yes",
    2 => "No",
    3 => "No",
    _ => ""
    }
}

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

#define mod 1000000007

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

#define rep(i, n) for(ll i=0; i<n; ++i)
 
int main(void){
	
	ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N){
        cin >> A[i];
        A[i]--;
    }
    ll now = 0;
    vector<ll> tereport;
    tereport.push_back(now);
    vector<bool> seen;
    seen.assign(N, false);
    seen[0] = true;
    
    while(1){
        now = A[now];
        if(seen[now])
            break;
        seen[now] = true;
        tereport.push_back(now);
    }

    ll before, roop_end_i;
    rep(i, tereport.size()){
        if(tereport[i] == now){
            before = i;
            break;
        }
    }
    roop_end_i = tereport.size() - before;

    if(before > K)
        cout << tereport[K] + 1 << endl;
    else
        cout << tereport[((K - before) % roop_end_i) + before] + 1 << endl;
   
	return 0;
}

Measured memory_bytes: 6848
var n,i,j:integer;
s:array[1..100]of string;
begin 
	readln(n);
	readln(s[1]);
	for i:=2 to n do
	begin 
		readln(s[i]);
		if s[i][1]<>s[i-1][length(s[i-1])] then 
		begin 
			write('No');
			exit;
		end;
		for j:=1 to i-1 do if s[i]=s[j] then 
		begin 
			write('No');
			exit;
		end;
	end;
	write('Yes');
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
//  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  float dis, tim, spe;
 cin>>dis>>tim>>spe ;
// cin>>
  //float e=n/m;
  if((dis/spe)<=tim) cout<<" Yes ";
  else cout<<" No ";
} 
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A == B && B == C){
    cout << "No";
  }
  else if(A == B || B == C || A == C){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        boolean[] k = new boolean[4];
        for(int i = 0; i < 4; i++) {
            int n = sc.nextInt();
            if(n == 1) k[0] = true;
            if(n == 9) k[1] = true;
            if(n == 7) k[2] = true;
            if(n == 4) k[3] = true;            
        }
        boolean ans = true;
        for(int i = 0; i < 4; i++ ) {
            ans &= k[i];
        }
        System.out.println(ans?"YES":"NO");
    } 
}

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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int count = 1;
	for (int i = 1; i < N; ++i)
	{
		if (S[i] != S[i-1])
			count++;
	}
	cout << count;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int K = stdIn.nextInt();
        int[] heights = new int[N];

        for (int i = 0; i < N; i++) {
            int h = stdIn.nextInt();
            heights[i] = h;
        }

        System.out.println(solve(heights, K));
    }

    private static int solve(int[] h, int k) {
        int[] w = new int[h.length];

        w[0] = 0;

        for (int i = 1; i < h.length; i++) {
            int o = Math.min(k, i);
            int min = Integer.MAX_VALUE;
            for (int j = 1; j <= o; j++) {
                min = Math.min(min, w[i - j] + Math.abs(h[i - j] - h[i]));
            }

            w[i] = min;
        }

        return w[w.length - 1];
    }
}


Measured memory_bytes: 51000
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	string s;
	cin >> s;
	if (s.length() == 3) {
		reverse(s.begin(), s.end());
	}
	cout << s << endl;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    map<int, vector<int>> cityMap;
    REP(i, M)
    {
         cin >> P[i] >> Y[i];
         cityMap[P[i]].push_back(Y[i]);
    } 
    map<int, int> cityRank[N + 1];
    for (auto iter = cityMap.begin(); iter != cityMap.end(); ++iter)
    {
        int p = iter->first;
        vector<int> v = iter->second;
        sort(v.begin(), v.end());
        REP(i, v.size())
        {
            cityRank[p][v[i]] = i + 1;
        }
    }

    REP(i, M)
    {
        cout << setfill('0') << setw(6) << P[i];
        cout << setfill('0') << setw(6) << cityRank[P[i]][Y[i]] << endl;
    }
   
}

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

bool prime(int n){
	if(n <= 1) return false;
	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;
}

int main(){
	int x;
	cin >> x;
	
	for(int i = x; x <= 100000; i++){
		if(prime(i))
		{
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split(' '))
    An = list(map(int, input().split(' ')))
    thres = sum(An) / (4 * M)
    
    count = 0
    for a in An:
        if not thres > a:
            count += 1
            
    if count >= M:
        print('Yes')
    else:
        print('No')
    
    
    
    
main()

Measured memory_bytes: 3060
n, k = map(int, input().split())

ans = 0
if k == 0:
    ans = n ** 2
else:
    for b in range(k + 1, n + 1):
        ans += (b - k) * (n // b)
        last_count = n % b - k + 1
        ans += last_count if last_count > 0 else 0

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#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++)
int INF=1e9+7;

int main() {
  string S,T;
  cin >> S >> T;
  int Ssiz=S.size(),Tsiz=T.size();
  int ans=INF;
  rep(i,Ssiz-Tsiz+1) {
    int count=0;
    rep(j,Tsiz) {
      if(S[i+j]!=T[j]) count++;
    }
    ans=min(ans,count);
  }
  
  cout << ans << endl;
}

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

int mod = 1000000007;

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

int combination(int N, int M) {
  if (N / 2 < M) return combination(N, N - M);
  
  long long ans = 1;
  
  for (long long i = 0; i < M; ++i) {
    ans *= (N - i);
    ans %= mod;
  }
  for (long long i = 0; i < M; ++i) {
    ans *= exp(i + 1, mod - 2);
    ans %= mod;
  }
  return ans;
}

int main() {
  long long X, Y;
  cin >> X >> Y;
  
  if ((X + Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if (Y < X / 2 || Y > 2 * X) {
    cout << 0 << endl;
    return 0;
  }
  
  long long N = (X + Y) / 3;
  long long M = Y - N;
  cout << combination(N, M) << endl;
  return 0;
}

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

cash={}
cnt = 1
for i in a:
    cash[i] = cnt
    cnt += 1
st = sorted(cash.items(), key=lambda x:x[0])

res = []
for vl in st:
    res.append(str(vl[1]))
print(' '.join(res))

Measured memory_bytes: 31472
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

# --------------------------------------------

dp = None

def main():
    N = input()
    op = ["+", "-"]

    for op1 in op:
        for op2 in op:
            for op3 in op:
                if eval(N[0] + op1 + N[1] + op2 + N[2] + op3 + N[3]) == 7:
                    print(N[0] + op1 + N[1] + op2 + N[2] + op3 + N[3] + "=7")
                    return

main()


Measured memory_bytes: 4924
#include <iostream>
using namespace std;
int main () {
    string a;
    int check = 0;
    cin >> a;
    for (int i = 0; i < a.length(); i++) {
        if (a[i] == 'C') {
            check = 1;
        }
        if (a[i] == 'F' && check) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
int main(){
  int N; cin >> N;
  vector<ll> A(N);
  for(int i = 0;i < N;i++)cin >> A[i];

  for(int i = 1;i < N;i++){
    A[i] = __gcd(A[i],A[i-1]);
  }

  cout << A[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int X;
int sum;
int main()
{
	scanf("%d",&X);
	sum+=X;	
	scanf("%d",&X);
	sum+=X*5;	
	scanf("%d",&X);
	sum+=X*10;	
	scanf("%d",&X);
	sum+=X*50;	
	scanf("%d",&X);
	sum+=X*100;	
	scanf("%d",&X);
	sum+=X*500;
	if(sum>=1000)printf("1\n");
	else printf("0\n");	
	return 0;
}

Measured memory_bytes: 1168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#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,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  ll N;
  cin>>N;
  Graph G(N+1);
  REP(i,N-1){
    ll A,B,C;
    cin>>A>>B>>C;
    G[A].PB(Edge(B,C));
    G[B].PB(Edge(A,C));
  }
  
  ll Q,K;
  cin>>Q>>K;
  
  ll DIS[N+1];
  RREP(i,N) DIS[i]=INF;
  
  DIS[K]=0;
  queue<ll> QQ;
  QQ.push(K);
  while(!QQ.empty()){
    ll v=QQ.front();
    QQ.pop();
    FORE(nv,G[v]){
      if(DIS[nv.first]<INF) continue;
      DIS[nv.first]=DIS[v]+nv.second;
      QQ.push(nv.first);
    }
  }
  
  REP(i,Q){
    ll X,Y;
    cin>>X>>Y;
    cout<<DIS[X]+DIS[Y]<<endl;
  }
  return 0;
}

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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x;
    cin >> x;
    
    int a,b,c,d;
    
    d = x%10;
    x /= 10;
    c = x%10;
    x /= 10;
    b = x%10;
    x /= 10;
    a = x%10;
    
    int sum = a + b + c + d;
    
    if(sum == 7){
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    }else if(sum - 2*d == 7){
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
     } else if(sum - 2*c == 7){
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
     } else if(sum - 2*b == 7){
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
     } else if(sum - 2*d - 2*c == 7){
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
     } else if(sum - 2*d - 2*b == 7){
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
     } else if(sum - 2*c - 2*b == 7){
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
     } else if(sum - 2*d - 2*c - 2*b == 7){
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
     }
    
}


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

int const N = 18;
map<pair<int, int>, ll> dp[17][17];
int x[N];

ll go(int l, int r, int cl, int cr){
	if (l > r)return 0;
	if (l == r)return (cl + cr) * (ll)x[l];
	auto it = dp[l][r].find(make_pair(cl, cr));
	if (it != dp[l][r].end())return it->second;
	ll mn = 1e18;
	f(i, l, r + 1)mn = min(mn, go(l, i - 1, cl, cl + cr) + go(i + 1, r, cl + cr, cr) + (cl + cr) * (ll)x[i]);
	return dp[l][r][make_pair(cl, cr)] = mn;
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)scanf("%d", x + i);
	printf("%lld\n", go(1, n - 2, 1, 1) + x[0] + x[n - 1]);
}

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

int main(){
 string s, t;
 cin >> s >> t;
 int n = s.size();
 int m = t.size();
 int cnt = 0;
 int mx = 0;
 for(int i = 0; i < n - m + 1; i++){
   cnt = 0;
   for(int j = 0; j < m; j++){
     if(s[i+j]==t[j]) cnt++;
   }
   mx = max(mx, cnt);
 }
  int ans = m -mx;  
  cout << ans << endl;
  return 0;
}


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

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2,v=0; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder();
      for (int[] i : graph) {
        for (int v : i) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


Measured memory_bytes: 25620
/*
                    Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }      
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
} 
signed main()
{   jaldi
    int n,k,q;
    cin>>n>>k>>q;
    int a[n]={0},i,x;
    for(int i=0;i<q;i++)
    {   cin>>x;
        x--;
        a[x]++;
    }
    for(i=0;i<n;i++)
    {   a[i]=a[i]-q+k;
        if(a[i]>0)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1408
#include <stdio.h>

int main() 
{
	char s[4];
	int i;
	scanf("%s", s);

	for (i = 0; s[i] != '\0'; i++)
		;
	if (i == 2) {
		printf("%s", s);
	}
	else {
		for (i=i-1; i >= 0; i--) {
			printf("%c", s[i]);
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 128