akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,M;
  cin >> N >> M;
  vector<pair<int,P>> py(M);
  rep(i,M) {
    int p,y;
    cin >> p >> y;
    py[i] = pair<int,P>(y,P(p,i));
  }
  sort(rng(py));
  map<int,int> mp;
  v(string) ans(M);
  rep(i,M) {
    mp[py[i].second.first]++;
    string f = ("000000" + to_string(py[i].second.first));
    string b = ("000000" + to_string(mp[py[i].second.first]));
    ans[py[i].second.second] = f.substr(sz(f)-6,6) + b.substr(sz(b)-6,6);
  }
  rep(i,M) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(long long i = 0;i < n;i++)
int main()
{
  int A,B;
  cin>>A>>B;
  if(A+B==3)cout<<3;
  if(A+B==5)cout<<1;
  if(A+B==4)cout<<2;
  return 0;
}




Measured memory_bytes: 3632
m, d = map(int, input().split())
cnt = 0
for i in range(4, m + 1):
    for j in range(22, d + 1):
        if int(str(j)[0]) > 1 and int(
                str(j)[1]) > 1 and i == int(str(j)[0]) * int(str(j)[1]):
            cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int gcd(int a, int b){
	if(a < b) swap(a, b);
	if(b == 0) return a;
	return gcd(b, a % b);
}

signed main(){
	int a, b;
	cin >> a >> b;
	int ans = a / gcd(a, b) * b;
	cout << ans << endl;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

const int N_MAX = 10010;
vector<vector<int>> tree(N_MAX);
vector<int> res(N_MAX);
queue<int> q;
priority_queue<int> pq;

int main() {
    int n;
    cin >> n;
    rp(i, 0, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree.at(a).emplace_back(b);
        tree.at(b).emplace_back(a);
    }
    int ans = 0;
    rp(i, 0, n) {
        int c; cin >> c;
        pq.push(c);
        ans += c;
    }
    ans -= pq.top();

    q.push(0);
    while(!q.empty()) {
        int now = q.front(); q.pop();
        res.at(now) = pq.top(); pq.pop();
        for(auto x: tree.at(now)) {
            if(res.at(x) == 0) q.push(x);
        }
    }
    printf("%d\n", ans);
    rp(i, 0, n) {
        printf("%d ", res.at(i));
    }
    printf("\n");
    return 0;

}

Measured memory_bytes: 4200
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;

int main(){
    int x,y;
    cin>>x>>y;
    set<int>a={1,3,5,7,8,10,12};
    set<int>b={4,6,9,11};
    set<int>c={2};
    if((a.count(x)&&a.count(y))||(b.count(x)&&b.count(y))||(c.count(x)&&c.count(y))){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

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

    int x = n * (n - 1) / 2;
    int y = m * (m - 1) / 2;

    cout << x + y << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(ll i=0;i<n;i++)
#define repp(j, n) for(ll j=0;j<n;j++)
#define reppp(i, m, n) for(ll i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};


signed main(){
    ll n;
    cin >> n;
    bool flag = false;
    vector<ll> a(n);
    rep(n){
        cin >> a[i];
        if(a[i] >= n) flag = true;
    }
    if(!flag){
        cout << 0;
        return 0;
    }
    
    flag = true;
    ll ans = 0LL;
    vector<ll> b(n);
    while(flag){
        rep(n) b[i] = a[i] / n;
        ll tmp = accumulate(all(b), 0LL);
        ans += tmp;
        flag = false;
        rep(n){
            b[i] = tmp - b[i] + a[i] % n;
            if(b[i] >= n) flag = true;
        }
        swap(a, b);
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int sum = 0;
	while(1)
	{
		sum = 0;
		string s;
		cin >> s;
		if(s=="0")break;
		for(int i =0;i<s.size();i++)sum+=s[i]-'0';
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3180
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
int n,m,w[10001],cnt[10001],ans=19260817;
bool visit[10001];
inline void dfs(int pos,int v,int tot)
{
	if(v>=m)
	{
		ans=min(ans,tot);
		return ;
	}
	if(pos==n+1)
	{
		int ct=tot,s=m-v;
		for(int i=n;i>=1;i--)
		if(!visit[i])
		{
			if(s>(i*100*(cnt[i]-1)))
				return ;
			else
				ct+=(s/(i*100));
			if(s%(i*100))
				ct++;
			break;
		}
		ans=min(ans,ct);
		return ;
	}
	dfs(pos+1,v,tot);
	visit[pos]=1;
	dfs(pos+1,v+100*pos*cnt[pos]+w[pos],tot+cnt[pos]);
	visit[pos]=0;
	return ;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>cnt[i]>>w[i];
	dfs(1,0,0);
	cout<<ans;
	return 0;
	
}


Measured memory_bytes: 256
from collections import Counter

def topological_sort(E, D):
    D = D[:]
    n = len(E)
    Q = [i for i in range(n) if D[i] == 0]
    L = []
    while Q:
        p = Q.pop()
        L.append(p)
        for vf in E[p]:
            D[vf] -= 1
            if not D[vf]:
                Q.append(vf)
    
    if len(L) != n:
        return False
    return L

N = int(input())
wsv = [list(map(int, input().split())) for _ in range(N)]
W, S, V = map(list, zip(*wsv))
 
Edge = [[] for _ in range(N)]
Dim = [0]*N
for i in range(N):
    for j in range(N):
        m1 = min(S[j], S[i]-W[j])
        m2 = min(S[i], S[j]-W[i])
        if m1 == m2:
            continue
        if m1 < m2:
            Edge[i].append(j)
            Dim[j] += 1
        else:
            Edge[j].append(i)
            Dim[i] += 1

L = topological_sort(Edge, Dim)
dp = Counter()
dp[10**9+7] = 0

for l in L[::-1]:
    for k, v in dp.copy().items():
        if k >= W[l]:
            t = min(k - W[l], S[l])
            dp[t] = max(dp[t], v + V[l])

print(max(dp.values()))


Measured memory_bytes: 126600
n, a, b, c, d = map(int, input().split())
s = input()

def is_possible(start, goal):
    for i in range(start, goal - 1):
        if s[i] == "#" and s[i + 1] == "#":
            return False
    return True
  
def is_possible2(start, goal):
    for i in range(start, goal):
        if s[i - 1] == "." and s[i] == "." and s[i + 1] == ".":
            return True
    return False

if c < d:
    if is_possible(a - 1, c) and is_possible(b - 1, d):
        print("Yes")
    else:
        print("No")
else:
    if is_possible(a - 1, c) and is_possible(b - 1, d) and is_possible2(b - 1, d):
        print("Yes")
    else:
        print("No")
      

Measured memory_bytes: 40048
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if(a[0] == 5 && a[1] == 5 && a[2] == 7){
        print("YES");
    }else{
        print("NO");
    }

}


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

int main(){
    int N;
    cin >> N;
    vector<int> vect(N);
    for(int i = 0; i < N; i++){
        cin >> vect[i];
    }
    sort(vect.begin(),vect.end());
    int count = 0;
    for(int i = 0;i < N; i++){
        for(int j = i+1; j < N; j++){
            if(vect[i] < vect[j]) {
                for (int k = j+1; k < N;k++){
                    if(vect[j] < vect[k] && vect[i] + vect[j] > vect[k]){
                        count += 1;
                    }
                }
            }
        }
    }
    cout << count << endl;
}

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

int main(){
   int m,f,r;
   while(true){
       cin >> m >> f >> r;
       if(m== -1 && f== -1 && r== -1) break;
       if(m== -1 || f== -1){
           cout << "F" << endl;
       }
       else if(m + f >= 80){
           cout << "A" << endl;
       }
       else if(m + f >= 65){
           cout << "B" << endl;
       }
       else if(m + f >= 50){
           cout << "C" << endl;
       }
       else if(m + f >= 30){
           if(r >= 50){
               cout << "C" << endl;
           }
           else {
               cout << "D" << endl;
           }
       }
       else {
           cout << "F" << endl;
       }
   }
}



Measured memory_bytes: 3044
N, M, K = gets.split.map(&:to_i)
MOD = 1E9.to_i + 7

def mpow(x, n)
  ret = 1
  while n > 0
    if n.even?
      x = x * x % MOD
      n >>= 1
    else
      ret = ret * x % MOD
      n -= 1
    end
  end
  ret
end

def comb(n, k)
  k = [k, n - k].min
  (n - k + 1 .. n).inject(1){|p, q| p*q % MOD} * mpow((1 .. k).inject(1){|p, q| p*q % MOD}, MOD - 2)
end

def f(x, y)
  x*(x-1)*(x+1)*y*y / 6 * comb(x*y - 2, K - 2)
end

puts (f(N, M) + f(M, N)) % MOD

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = items[0];
            var K = items[1];
            var dic = new Dictionary<int, bool>();
            foreach (var i in Enumerable.Range(1, N))
            {
                dic[i] = false;
            }

            foreach (var i in Enumerable.Range(0, K))
            {
                var d = Console.ReadLine();
                foreach (var A in Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray())
                {
                    dic[A] = true;
                }
            }

            Console.WriteLine(dic.Count(elem => elem.Value == false));
        }
    }
}


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

int main(){
  int m,d;
  cin >> m >> d;
  int ans = 0;
  vector<int>vec1 ={2,3,4,5,6,7,8,9};
  vector<int>vec2 ={2,3,4,5,6,7,8,9};
  for(int i = 1; i<=m; i++){
    for(int j = 0; j<8; j++){
      for(int k = 0; k<8; k++){
        if(vec1.at(j)*vec2.at(k) == i){
          if(d >= vec1.at(j)*10 + vec2.at(k)){
            ans++;
          }
        }
      }
    }  
  }
  cout << ans << endl;
}

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

using namespace std;

static uint32_t index = 0;
void reconstruction(vector<int32_t> pre, vector<int32_t> in, uint32_t l, uint32_t r, void (*postorder)(int32_t))
{
  if (l >= r) return;

  int32_t root = pre[index];
  index++;

  uint32_t root_index = 0;
  for (uint32_t i = 0; i < in.size(); i++) {
    if (in[i] == root) {
      root_index = i;
      break;
    }
  }

  reconstruction(pre, in, l, root_index, postorder);
  reconstruction(pre, in, root_index + 1, r, postorder);

  if (postorder != nullptr) {
    postorder(root);
  }
}

#if !defined(TEST)

static vector<int32_t> pre, in, post;

static void postorder(int32_t index)
{
  post.push_back(index);
}

int32_t main()
{
  uint32_t len;
  cin >> len;

  for (uint32_t i = 0; i < len; i++) {
    int32_t index;
    cin >> index;
    pre.push_back(index);
  }

  for (uint32_t i = 0; i < len; i++) {
    int32_t index;
    cin >> index;
    in.push_back(index);
  }

  reconstruction(pre, in, 0, in.size(), postorder);

  for (uint32_t i = 0; i < post.size(); i++) {
    if (i != 0) {
      cout << " ";
    }

    cout << post[i];
  }
  cout << endl;

  return 0;
}
#endif

Measured memory_bytes: 3152
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int N, W;
long long int w[100];
long long int v[100];
map<long long int, long long int>M[100][101];
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> W;
	for (int i = 0; i < N; i++)cin >> w[i] >> v[i];
	long long int box = w[0];
	for (int i = 0; i < N; i++)w[i] -= box;
	if (w[0] + box <= W)M[0][1][w[0]] = v[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k <= j * 3; k++) {
				if (k + j*box > W)break;
				M[i][j][k] = max(M[i][j][k],M[i - 1][j][k]);
				ans = max(ans, M[i][j][k]);
			}
			for (int k = 0; k <= j * 3; k++) {
				if (k + w[i] + (j + 1)*box > W)break;
				M[i][j + 1][k + w[i]] = max(M[i][j + 1][k + w[i]], M[i - 1][j][k] + v[i]);
				ans = max(ans, M[i][j + 1][k + w[i]]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 92288
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
//	while(cin){
		int K;
		cin >> K;
		if ((K%2==0)||(K%5==0)) cout << -1 << endl;
		else {
			if (K%7==0) K /= 7;
			K *= 9;
			int res = 1;
			long long int i;
			for (i = 1; i < 1000000000; i++){
				res = (res*(10%K))%K;
				if (res==1) break;
			}
			cout << ((i==1000000000)?-1:i) << endl;
		}
//	}
	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<sstream>
#include<fstream>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
const int maxn=2e5; 
typedef long long ll;
typedef long double ld;
typedef pair<int,int>PII;
//priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
//priority_queue <int,vector<int>,less<int> >q2;  //从大到小 

//set multiset vector queue priority_queue map multimap pair string structure 

//枚举 思维 贪心 搜索 模拟 预处理 二分 排序 
int a[maxn];
int main(){
	//ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	double sum=0,maxsum=-1;
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	if(sum>maxsum) maxsum=sum;
	for(int i=k;i<n;i++){
		sum+=a[i];
		sum-=a[i-k];
		if(sum>maxsum){
			maxsum=sum;
	    }
	}
	printf("%.12lf",(maxsum+k)/2);
	
	return 0;
}



Measured memory_bytes: 1024
import math
while True:
    n=int(input())
    if n==0:
        break
    
    s=list(map(int,input().split()))
    m=sum(s)/n
    aa=0
    for i in range(n):
        aa+=(s[i]-m)**2
    
    print('{:.8f}'.format(math.sqrt(aa/n)))
        


Measured memory_bytes: 5708
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<int> sMass;
  vector<int> wMass;
  rep(i, f + 1){
    rep(j, f + 1){
      //if(!i && !j) continue;
      int s = c * i + d * j;
      if(s <= f){ // s <= f
        sMass.push_back(s);
      }
      if(!i && !j) continue;
      int w = 100 * a * i + 100 * b * j;
      if(w <= f){
        wMass.push_back(w);
      }
    }
  }
  int sans = 0;
  int wans = 0;
  bool first = true;
  rep(i, sMass.size()){
    rep(j, wMass.size()){
      if(sMass[i] + wMass[j] <= f){
        if(first){
          if(sMass[i] * (100 + e) > e * (sMass[i] + wMass[j])) continue; //反対の項に分母をかける
          sans = sMass[i];
          wans = wMass[j];
          first = false;
          continue;
        }
        if(sMass[i] * (100 + e) > e * (sMass[i] + wMass[j])) continue;
        if(sans * (sMass[i] + wMass[j]) < sMass[i] * (sans + wans)){
          sans = sMass[i];
          wans = wMass[j];
        }
      }
    }
  }
  cout << wans + sans << " " << sans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int prime[1000001],isnprime[1000001];
long long store[1000001],cnt[1000001];
int main()
{
	int top=0;
	for(int i=2;i<=1000000;i++)
	{
		if(!isnprime[i])
		{
			prime[top++]=i;
			for(long long j=(long long)i*i;j<=1000000;j=j+i)
			{
				isnprime[j]=1;
			}
		}
	}
	long long n,p;
	scanf("%lld%lld",&n,&p);
	int tot=0;
	for(int i=0;i<top&&(long long)prime[i]*prime[i]<=p;i++)
	{
		if(p%prime[i]==0)
		{
			store[tot]=prime[i];
			while(p%prime[i]==0)
			{
				cnt[tot]++;
				p=p/prime[i];
			}
			tot++;
		}
	}
	if(p!=1)
	{
		store[tot]=p;
		cnt[tot]=1;
		tot++;
	}
	long long ans=1;
	for(int i=0;i<tot;i++)
	{
		for(int j=1;j<=cnt[i]/n;j++)
		{
			ans=ans*store[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8448
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func WarshallFloyd(G *[][]int) {
  N := len((*G))
  for k := 0; k < N; k++ {
    for i := 0; i < N; i++ {
      for j := 0; j < N; j++ {
        if (*G)[i][k] + (*G)[k][j] < (*G)[i][j] {
          (*G)[i][j] = (*G)[i][k] + (*G)[k][j]
        }
      }
    }
  }
}
func Query(H *[][]int, s, t int) int {
  h := (*H)[s][t]
  if h == Inf { return -1 }
  return h - 1
}
const Inf = 1000000001
func main() {
  NML := NextIntVec()
  N, M, L := NML[0], NML[1], NML[2]
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, N)
    for j := range G[i] {
      G[i][j] = Inf
    }
    G[i][i] = 0
  }
  for i := 0; i < M; i++ {
    ABC := NextIntVec()
    A, B, C := ABC[0] - 1, ABC[1] - 1, ABC[2]
    G[A][B] = C
    G[B][A] = C
  }
  WarshallFloyd(&G)
  H := make([][]int, N)
  for i := range H {
    H[i] = make([]int, N)
    for j := range H[i] {
      H[i][j] = Inf
      if G[i][j] <= L { H[i][j] = 1 }
    }
  }
  WarshallFloyd(&H)
  Q := NextInt()
  ans := make([]string, Q)
  for i := 0; i < Q; i++ {
    ST := NextIntVec()
    s, t := ST[0] - 1, ST[1] - 1
    ans[i] = strconv.Itoa(Query(&H, s, t))
  }
  Write(strings.Join(ans, "\n"))
  Output()
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
    IOS;
    double d;
    cin >> d;
    d = d/3.0;
    cout << setprecision(9) << (d*d*d) << endl;
    return 0;
}

Measured memory_bytes: 256
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 t = sc.nextInt();
        sc.close();

        int time = a;
        int ans = 0;
        while (time <= t) {
            ans += b;
            time += a;
        }
        System.out.println(ans);
    }

}


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

int main() {
    int N;
    int zeroFlag = 0;
    cin >> N;

    vector<long long> A(N+1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) zeroFlag = 1;
    }

    if (zeroFlag) {
        cout << 0 << endl;
        return 0;
    }

    unsigned long long NUM = 1e18;
    unsigned long long ans = 1;
    for (int i = 0; i < N; i++) {
        if (NUM / ans < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 4028
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int k;
    int n;
    vector<int> a;
    int tmp_a;
    int ans;

    cin >> k >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        a.push_back(tmp_a);
    }

    ans=k;

    for(int i=0; i<n; i++){
        if(i==0){
            if(a[n-1]-a[0]<ans){
                ans = a[n-1]-a[0];
            }
            if(k-(a[1]-a[0])<ans){
                ans = k-(a[1]-a[0]);
            }
        }else if(i==n-1){
            if(a[n-1]-a[0]<ans){
                ans = a[n-1]-a[0];
            }
            if(k-(a[n-1]-a[n-2])<ans){
                ans = k-(a[n-1]-a[n-2]);
            }
        }else{
            if(k-(a[i+1]-a[i])<ans){
                ans = k-(a[i+1]-a[i]);
            }
            if(k-(a[i]-a[i-1])<ans){
                ans = k-(a[i]-a[i-1]);
            }            
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int X=in.nextInt();
    int A=in.nextInt();
    if(X<A){
     System.out.println(0);
    }
    else{
      System.out.println(10);
  	}
  }
}
    

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

int max(int a, int b) {
    if (a > b) return a;
    else return b;
}

int main() {
    int a, b, k;
    int i, m;

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

    m = max(a, b);
    for (i = m; i >= 1; i--) {
        if (a%i == 0 && b%i == 0) {k--;}
        if (k <= 0) {break;}
    }
    printf("%d", i);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main() {
	int t, i=0, j, k;
	LL a, b=1, c=0 ,d,n,F=0,M=0,m=1000;
	string A,D,E;
	char B,C;
	cin >> a;
	for (i = 1; i <= a; i++) {
		b *= i;
	b = b % (1000000000 + 7);
	}
	cout << b << endl;
	return 0;
}

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

int main(int argc, char const *argv[]) {

  int N;
  scanf("%d", &N);

  double X, A, B;
  X = (double)N / 108.0 * 100.0;
  // printf("%f\n", X);
  A = ceil(X);
  // printf("%f\n", A);
  B = floor(X);
  // printf("%f\n", B);
  int C = (int)((int)A * 1.08);
  int D = (int)((int)B * 1.08);
  // printf("%d\n", C);
  // printf("%d\n", D);

  if (A == B) {
    printf("%d\n", (int)X);
  }else if(C == N){
    printf("%d\n", (int)A);
  }else if(D == N){
    printf("%d\n", (int)B);
  }else{
    printf(":(\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#define maxn 200009
using namespace std;
long long a, b ,t;
int main(){
	cin >> a >> b >> t;
	long long x = floor((t + 0.5) / a);
	cout << b * x << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll ans = (1ll + n) * n / 2;
    for (int i = 2; i <= n; i++) {
        for (int k = i; k <= n; k += i) {
            ans += k;
        }
    }
    cout << ans << "\n";
}


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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
    static modint H(ll a,ll b){
        return C(a+b,a);
    }
};
vector<modint> modint::factorial;


int main(void){
    ll H,W,h,w;
    cin >> H >> W >> h >> w;
    modint res = modint::H(W-1,H-1);
    rep(x,w-1){
        res -= modint::H(H-h,x) * modint::H(h-2,W-x-1);
    }
    res -= modint::H(H-h,w-1) * modint::H(h-1,W-w);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    ll a, b, k; cin >> a >> b >> k;
    if(a >= k){
        cout << a - k << " " << b;
    }else if(k <= a+b){
        cout << 0 << " " << b - (k-a);
    }else{
        cout << 0 << " " << 0;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////


void solve() {
	vector<string> S(3);
	for (int i = 0; i < 3; ++i) {
		cin >> S[i];
	}
	vector<int> pos(3, 0);
	int now = 0;
	while (true) {
		if (S[now].size() == pos[now]) {
			char temp = 'A' + now;
			cout << temp << endl;
			return;
		}

		int ter = S[now][pos[now]]-'a';
		pos[now]++;
		
		now = ter;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<vector<char>> c(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>c[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
      int cnt=0;
      for(int s=0;s<h;s++){
        for(int t=0;t<w;t++){
          if(1&(i>>s))continue;
          if(1&(j>>t))continue;
          if(c[s][t]=='#')cnt++;
        }
      }
      if(cnt==k)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int isComb(int);

int main()
{
	int N;
	cin >> N;
	if (isComb(N) == 0)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
		int k = isComb(N);
		cout << k << endl;
		vector<vector<int>> S(k);
		int l = 1;
		for (int i = 0; i < k; i++)
		{
			for (int j = i + 1; j < k; j++)
			{
				S[i].push_back(l);
				S[j].push_back(l);
				l++;
			}
		}

		for (int i = 0; i < k; i++)
		{
			cout << S[i].size() << " ";
			for (int j = 0; j < S[i].size(); j++)
			{
				cout << S[i][j] << " ";
			}
			cout << endl;
		}
	}
	return 0;
}

int isComb(int N)
{
	int k = 1;
	int comb = k * (k - 1) / 2;
	while (comb <= N)
	{
		if (comb == N)
		{
			return k;
		}
		k++;
		comb = k * (k - 1) / 2;
	}
	return 0;
}


Measured memory_bytes: 2304
// c++include
#include <iostream>
#include <algorithm>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(ll i = 0; i < (n); i++)
typedef long long ll;

// main関数
int main(void) {
	ll n;
	cin >> n;
	vector<ll> a;
	a.reserve(n);
	rpt(i, n) {
		ll tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.begin(), a.end());
	ll count = 0, cnt = 1;
	ll box = a[0];
	for (ll i = 1; i < n; i++) {
		if (box == a[i]) {
			cnt++;
		}
		else {
			count += (cnt % 2);
			cnt = 1;
			box = a[i];
		}
	}
	count += (cnt % 2);
	cout << count;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N, K, sum;
  cin >> N >> K;
  sum = 0;
  
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    
    if(x >= K-x){
      sum += 2*(K-x);
    }
    else{
      sum += 2*x;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main { 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int[] S = new int[n];
        while (n != 0) {
            S[n - 1] = in.nextInt();
            n--;
        }
        
        int q = in.nextInt();
        int[] T = new int[q];
        while (q != 0) {
            T[q - 1] = in.nextInt();
            q--;
        }
        
        System.out.println(include(S, T));
    }
    
    static int include(int[] S, int[] T) {
        int count = 0;
        for (int i = 0; i < T.length; i++) {
            for (int j = 0; j < S.length; j++) {
                if (T[i] == S[j]) {
                    count++;
                    break;
                }
            }
        }
        return count;
    }
}

Measured memory_bytes: 31184
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;


const int VMAX = 10;

int dist[VMAX][VMAX];
signed main() {
  int n;
  cin >> n;
  n++;
  int d[n];
  d[n - 1] = 0;
  for (size_t i = 0; i < n - 1; i++) {
    cin >> d[i];
  }
  sort(d, d + n);
  for (size_t i = 0; i < n; i++) {
    if (i % 2 == 0) {
      d[i] = 24 - d[i];
    }
    // cout << d[i] << " ";
  }
  // cout << endl;

  int dmin = 10000000;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      int t = abs(d[i] - d[j]);
      dmin = min(dmin, min(t % 24, (24 - t) % 24));
    }
  }
  cout << dmin << endl;
}


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

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

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

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

int main()
{
    ll N, M;
    cin >> N >> M;
    set<ll> A, B;
    REP(i,0,M) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        if(a == 0) A.insert(b);
        if(b == N-1) B.insert(a);
    }

    bool f = false;
    FORR(a,A) {
        if(B.count(a) > 0) f = true;
    }
    if(f) PR("POSSIBLE");
    else PR("IMPOSSIBLE");

    



    return 0;
}

/*



*/

Measured memory_bytes: 12856
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    val n = scanner.nextInt
    val a = Array.fill(n)(scanner.nextInt)

    var flag = true
    var c = 0
    while(flag) {
      flag = false
      for(j <- n - 1 to 1 by -1) {
        if(a(j) < a(j - 1)) {
          val t = a(j)
          a(j) = a(j - 1)
          a(j - 1) = t
          flag = true
          c = c + 1
        }
      }
    }
    println(a.mkString(" "))
    println(c)
  }
}



Measured memory_bytes: 45244
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int calc(VI &l, VI &r, int p){
    vector<P> a;
    int n = l.size();
    REP(i,n){
        a.push_back(P(l[i], r[i]));
    }
    sort(ALL(a));
    reverse(ALL(a));
 
    int res = 1e9, pma = p;
    REP(i,n){
        res = min(res, 2*a[i].first + 2*pma - p);
        pma = max(pma, a[i].second);
        // cout << "res" << res << " pma" << pma << endl;
    }
    res = min(res, 2*pma - p);
    return res;
}
 
int main(){
    string a, b;
    cin >> a >> b;
    int n = a.length();
 
    if (a == b){
        cout << 0 << endl;
        return 0;
    }
 
    if (b.find('1') == string::npos){
        cout << -1 << endl;
        return 0;
    }
 
    VI l(n), r(n);
    REP(i,n){
        while (b[(i+l[i])%n] == '0') l[i]++;
        while (b[(i-r[i]+n)%n] == '0') r[i]++;
        swap(l[i], r[i]);
    }
 
    int ans = 1e9;
    REP(i,n){
        VI ll, rr;
        REP(j,n){
            if (a[j] != b[(j+i)%n]){
                ll.push_back(l[j]);
                rr.push_back(r[j]);
            }
        }
        int m = ll.size();
        ans = min(ans, calc(ll, rr, i) + m);
        ans = min(ans, calc(rr, ll, (n-i) % n) + m);
 
        // cout << i << endl;
        // REP(i,m) cout << ll[i] << " ";
        // cout << endl;
        // REP(i,m) cout << rr[i] << " ";
        // cout << endl;
        // cout << calc(ll, rr, i) << " " << calc(rr, ll, (n-i) % n) << endl << endl;
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 123;
#define int long long 
int n, m;
pair <int, int> a[maxn];
string s[60], t[60];
main () { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    for(int i = 0; i < n; i++)
    	cin >> s[i];
    for(int i = 0; i < m; i++)
    	cin >> t[i];

	for(int x = 0; x + m - 1 < n; x++)
	for(int y = 0; y + m - 1 < n; y++) {
		bool ok = 1;
		for(int i = 0; i < m; i++)
		for(int j = 0; j < m; j++)
			ok &= s[x + i][y + j] == t[i][j];
		if(ok) {
			cout << "Yes";
			exit(0);
		}
	}
	cout<<"No";
}




Measured memory_bytes: 3580
#include<bits/stdc++.h>
    using namespace std;
    int n, a, ans = 0, dp[1000000];
    int main()
    {
    	cin >> n;
    	for (int i = 1; i <= n; i++)
    	{
    		cin >> a;
    		dp[a]++;
    		dp[a+1]++;
    		dp[a+2]++;
    	}
    	for (int i = 0; i <= 100002; i++)
    		ans=max (ans,dp[i]);
    	cout << ans;
    }

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

int main() {
	int h,w;
	int ans;
	cin>>h>>w;
	int used[h][w];
	char s[h][w];
	int a[h][w];
	int whitenum=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>s[i][j];
			used[i][j]=0;
			if(s[i][j]=='.') whitenum++;
			a[i][j]=2500;
		}
	}

	int x,y;
	int count=1;
//	used[0][0]=1;
	a[0][0]=1;
	vector<pair<int,int>> r,nextr,nullr;
	vector<pair<int,int>>::iterator itr;
	r.push_back(pair<int,int>(0,0));
	int flag=1;
	while(count<2500){
		flag=1;
		for(itr=r.begin();itr!=r.end();itr++){
			x=(*itr).first+1;
			y=(*itr).second;
//			cout<<x-1<<' '<<y<<endl;
			if(x<h){
				if(s[x][y]=='.'){
					if(a[x][y]>a[(*itr).first][(*itr).second]+1){
						a[x][y]=a[(*itr).first][(*itr).second]+1;
						nextr.push_back(pair<int,int>(x,y));
						flag=0;
					}
				}
			}
			x=(*itr).first-1;
			if(x>=0){
				if(s[x][y]=='.'){
					if(a[x][y]>a[(*itr).first][(*itr).second]+1){
						a[x][y]=a[(*itr).first][(*itr).second]+1;
						nextr.push_back(pair<int,int>(x,y));
						flag=0;
					}
				}
			}
			x=(*itr).first;
			y=(*itr).second+1;
			if(y<w){
				if(s[x][y]=='.'){
//					cout<<'a'<<endl;
					if(a[x][y]>a[(*itr).first][(*itr).second]+1){
						a[x][y]=a[(*itr).first][(*itr).second]+1;
						nextr.push_back(pair<int,int>(x,y));
						flag=0;
					}
				}
			}
			y=(*itr).second-1;
			if(y>=0){
				if(s[x][y]=='.'){
					if(a[x][y]>a[(*itr).first][(*itr).second]+1){
						a[x][y]=a[(*itr).first][(*itr).second]+1;
						nextr.push_back(pair<int,int>(x,y));
						flag=0;
					}
				}
			}
		}
		if(flag)break;
		r=nextr;
		nextr=nullr;
		count++;
//		cout<<endl;
	}
	if(a[h-1][w-1]==2500){
		ans=-1;
	}else{
		ans=whitenum-a[h-1][w-1];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)

mv = K * D
if mv <= X:
    ans = X - mv
    print(ans)
    exit()

need = (X + D - 1) // D

X -= need * D
K -= need

if K % 2 == 0:
    ans = abs(X)
    print(ans)
else:
    X += D
    print(X)


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch;
    cin >> ch;
    if(ch=='A'){
        cout << "T" << endl;
    }
    else if(ch=='T'){
        cout << "A" << endl;
    }
    else if(ch=='G'){
        cout << "C" << endl;
    }
    else if(ch=='C'){
        cout << "G" << endl;
    }
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

ll minCostSort(int n, vector<int> as) {
    vector<int> bs(n);
    copy(as.begin(), as.end(), bs.begin());
    sort(bs.begin(), bs.end());
    vector<bool> visited(n);

    int gm = bs[0];
    ll cost = 0;
    rep(i, n) {
        if (visited[i]) continue;

        int cur = i;
        ll s = 0;
        int m = INT_MAX;
        int hop = 0;
        while (!visited[cur]) {
            if (as[cur] < m) m = as[cur];
            s += as[cur];
            visited[cur] = true;
            hop++;
            cur = distance(bs.begin(), lower_bound(bs.begin(), bs.end(), as[cur]));
        }
        cost += min(s + m * (hop - 2), s + m + gm * (hop + 1));
    }
    return cost;
}

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    ll ans = minCostSort(n, as);
    cout<<ans<<endl;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define v vector<ll>
#define st stack<ll>
#define pq  priority_queue <int>
#define q queue<ll>
#define mod 1000000005
using namespace std;
 char ch[1000000];
int main(){
     string s;
     cin>>s;
     s.erase(s.length()-8,s.length()-1);
     cout<<s<<endl;
    return 0;
   }

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

int main(){
  int l, a, b, c, d, e, f, m;

  cin >> l >> a >> b >> c >> d;

  e=a/c; m=a%c;
  if (m!=0) e++;

  f=b/d; m=b%d;
  if (m!=0) f++;

  if(e>f){
    cout << l-e << endl;
  } else {
    cout << l-f << endl;
  }

  return 0;
}

Measured memory_bytes: 3080
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

const int IMPOSSIBLE = 10e+5 * 12 + 1;

int dp(const vector<int> &price, const vector<vector<int>> &skill,
       vector<int> acquired, int X, int M, int N, int layer, int cprice) {
  if (all_of(acquired.begin(), acquired.end(), [X](int x) { return x >= X; })) {
    return cprice;
  }

  if (layer == N) return IMPOSSIBLE;

  int a, b;
  vector<int> nacquired(acquired);
  for (int i = 0; i < M; i++) {
    nacquired[i] += skill[layer][i];
  }
  a = dp(price, skill, nacquired, X, M, N, layer + 1, cprice + price[layer]);
  b = dp(price, skill, acquired, X, M, N, layer + 1, cprice);

  return min(a, b);
}

int main() {
  int N, M, X, m;
  cin >> N >> M >> X;
  vector<vector<int>> skill(N, vector<int>(M));
  vector<int> price(N), acquired(M, 0);
  for (int i = 0; i < N; i++) {
    cin >> price.at(i);
    for (int j = 0; j < M; j++) {
      cin >> skill[i][j];
    }
  }

  m = dp(price, skill, acquired, X, M, N, 0, 0);
  cout << (m == IMPOSSIBLE ? -1 : m) << endl;
}


Measured memory_bytes: 3196
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	ll ans = 0;  int cnt = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'A') cnt++;
		else if (i+1<s.size()&&s[i] == 'B' && s[i + 1] == 'C') {
			ans += cnt; i++;
		}
		else cnt = 0;
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 720
n = int(input())
lst = []
s = input().rstrip().split(' ')
for j in range(n):
  lst.append(int(s[j]))
lst.sort()
for i in range(n-2):
  temp = (lst[0] + lst[1]) /2
  del lst[1]
  del lst[0]
  lst.append(temp)
  lst.sort()
ans = (lst[0] + lst[1]) / 2
print(ans)

Measured memory_bytes: 3064
import scala.collection.mutable.ListBuffer

object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M, K = in.nextInt
  val uf = new UnionFind(N + 1)
  val friends = new Array[Int](N + 1)

  (1 to M).foreach {m =>
    val a, b = in.nextInt
    uf.union(a, b)
    friends(a) += 1
    friends(b) += 1
  }

  val blocks = Array.fill(N + 1)(new ListBuffer[Int])
  (1 to K).foreach {m =>
    val c, d = in.nextInt
    blocks(c) += d
    blocks(d) += c
  }

  val result = (1 to N).map {i =>
    uf.size(i) - friends(i) - blocks(i).filter(j => uf.find(i) == uf.find(j)).size - 1
  }

  println(result.mkString(" "))
}

class UnionFind(nodes: Int) {
  val parents = Array.tabulate(nodes)(identity)
  val sizes = Array.fill(nodes)(1)

  // @scala.annotation.tailrec
  /** @retrun (root, rank) */
  def findWithRank(x: Int, rank: Int = 0): (Int, Int) = {
    parents(x) match {
      case p if x == p => (p, rank)
      case p => {
        val (newRoot, newRank) = findWithRank(p, rank + 1)
        parents(x) = newRoot
        (newRoot, newRank)
      }
    }
  }

  def find(x: Int): Int = {
    parents(x) match {
      case p if x == p => p
      case p => {
        val newRoot = find(p)
        parents(x) = newRoot
        newRoot
      }
    }
  }

  def size(x: Int) = sizes(find(x))

  def union(x: Int, y: Int): Int = {
    val (xRoot, xRank) = findWithRank(x)
    val (yRoot, yRank) = findWithRank(y)
    val newRoot = if (xRank < yRank) yRoot else xRoot
    if (xRoot != yRoot) {
      parents(xRoot) = newRoot
      parents(yRoot) = newRoot
      sizes(newRoot) = sizes(xRoot) + sizes(yRoot)
    }
    parents(x) = newRoot
    parents(y) = newRoot
    newRoot
  }
}

Measured memory_bytes: 121788