akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10, LOG = 28;
int n;
int a[N], b[N], A[N], B[N];

int find(int x, int y) {
  int l = 1, r = n, ans = 0;
  while(l <= r) {
    int mid = (l + r) >> 1;
    if(B[mid] + x <= y) ans = mid, l = mid + 1;
    else r = mid - 1;
  }
  return ans;  
}

int main() {
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  int ans = 0;
  for(int i = 0; i <= LOG; ++i) {
    int base = (1 << (i + 1)) - 1;
    for(int j = 1; j <= n; ++j) A[j] = a[j] & base;
    for(int j = 1; j <= n; ++j) B[j] = b[j] & base;
    sort(B + 1, B + 1 + n);
    ll pos = 1ll * n * n;
/*    for(int j = 1; j <= n; ++j) 
      printf("%d ", A[j]);
    puts("");
    for(int j = 1; j <= n; ++j)
      printf("%d ", B[j]);
    puts("");*/
    for(int j = 1; j <= n; ++j) {
      pos -= find(A[j], (1 << i) - 1);
      pos -= find(A[j], (1 << (i + 1)) + (1 << i) - 1) - find(A[j], (1 << (i + 1)) - 1);
    }
//    printf("%lld\n", pos);
    if(pos & 1) ans |= (1 << i);
  }
  printf("%d\n", ans);
  return 0;
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    string s;
    cin >> s;
    rep(l, 0, sz(s))
    {
        rep(c, 0, ABC)
        {
            bool ok = true;
            rep(i, 0, sz(s) - l)
            {
                bool ok1 = false;
                rep(j, 0, l + 1)
                    if (s[i + j] - 'a' == c)
                        ok1 = true;
                if (!ok1)
                {
                    ok = false;
                    break;
                }
            }
            if (ok)
            {
                cout << l << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

class Data{
public:
    LL a,b;
};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N;
    cin>>N;
    VL A(N), B(N);
    REP(i,N)cin>>A[i];
    REP(i,N)cin>>B[i];
    LL sum_a = accumulate(ALL(A), 0LL);
    LL sum_b = accumulate(ALL(B), 0LL);
    if(sum_a < sum_b){
        PUTS(-1);
        return 0;
    }

    vector<Data> x(N);
    REP(i,N){
        x[i].a = A[i];
        x[i].b = B[i];
    }
    sort(ALL(x), [](const Data &x1, const Data &x2){
            return (x1.a-x1.b) < (x2.a-x2.b);});

    LL ans = 0;
    LL husoku = 0;
    REP(i,N)if(x[i].a < x[i].b){
        ans++;
        husoku += x[i].b - x[i].a;
    }
    for(int i = N - 1; i >= 0; i--){
        if(husoku <= 0)break;
        ans++;
        LL yoyu = x[i].a - x[i].b;
        husoku -= yoyu;
    }
    PUTS(ans);
}

Measured memory_bytes: 3328
from fractions import gcd
from functools import reduce

mod = 10 ** 9 + 7

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

# print('input >>')
N = int(input())
A = list(map(int,(input().split())))

lcmn = lcm(A)

ans = 0
for i in range(len(A)):
    ans += lcmn // A[i]

# print('-----output-----')
print(int(ans%mod))

Measured memory_bytes: 6136
//
//  Simple_Calculator.c
//  AOJ
//
//  Created by admin on 2014/07/12.
//
//

#include <stdio.h>

main(){
    int a,b;
    char op;
    do{
        scanf("%d %c %d",&a,&op,&b);
        
        if(op == '?'){
            break;
        } else if(op == '+'){
            printf("%d\n",a+b);
        } else if(op == '-'){
            printf("%d\n",a-b);
        } else if(op == '*'){
            printf("%d\n",a*b);
        } else if(op == '/'){
            printf("%d\n",a/b);
        }
    }while(1);
    
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long int ll;
int main(void) {
	int a, b; cin >> a >> b;
	vector<int> v(3);
	v[0] = a + b;
	v[1] = a * b;
	v[2] = a - b;
	sort(v.begin(), v.end(),greater<>());
	cout << v[0] << endl;
	return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int k,s; cin>>k>>s;
	map<int,int> ct;
	for (int x=0; x<=k; x++)
		for (int y=0; y<=k; y++)
			ct[x+y]++;
	int ret=0;
	for (int z=0; z<=k; z++)
		ret+=ct[s-z];
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 640
from collections import deque
N = int(input())
A = deque()
for _ in range(N):
    a,b = list(map(int,input().split()))
    A.append([b,a])
A = list(A)
A.sort()
time = 0
for i in A:
    time += i[1]
    if time > i[0]:
        print('No')
        exit()
print('Yes')

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

int main(){
    int x_1,y_1,x_2,y_2;
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    int del_x = x_2 - x_1;
    int del_y = y_2 - y_1;
    
    int x_3 = x_2 - del_y;
    int y_3 = y_2 + del_x;
    int x_4 = x_3 - del_x;
    int y_4 = y_3 - del_y;
    
    cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;
}


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

int main() {
    string s,t;
    cin >> s>>t;
    bool ok = false;
    if (s==t){ cout << "Yes" << endl;
              return 0;}
    rep(i,s.size()){
    if(t==s.substr(i,s.size()-1)+s.substr(0,i)){
        ok = true;
    }
    }
    if(ok) cout << "Yes" <<endl;
    else cout << "No" <<endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

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

    string s; cin >> s;

    int cnt = 0;
    for(int i=0;i<3;i++) if(s[i]=='R') cnt++;

    if(cnt == 2){
        if(s[1] == 'S') cnt = 1;
    }

    cout << cnt << "\n";



}


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

using str = string;
using ss = stringstream;

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

    str s;

    cin>>s;

    str bs="";
    ss as;

    int ans=0;

    for(int i=0;i<s.size();i++)
    {
        as<<s[i];
        if(bs!=as.str())
        {
            ans++;
            bs=as.str();
            as.str(str());
        }
    }

    cout<<ans<<"\n";

    return 0;
}


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

typedef long long LL;
typedef pair <LL, LL> Pair;
typedef vector <Pair> vec;
const int N = 1.4e5 + 50;

int n, lc[N], rc[N], v[N];
vec dp[N], swp;
int sz[N];
LL lim;

template <typename T> inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline void Init(int x) {
  if (!lc[x]) {
    sz[x] = 1;
    dp[x].emplace_back(v[x], v[x]);
    return;
  }
  Init(lc[x]); Init(rc[x]);
  sz[x] = min(sz[lc[x]], sz[rc[x]]) << 1;
  dp[x].reserve(sz[x]);
}

inline void Double(vec &a, int val) {
  swp.clear();
  for (vec :: iterator i = a.begin(), j = a.end(); i != a.end() || j != a.begin(); ) {
    if (i == a.end()) j --, swp.emplace_back(j -> second, j -> first);
    else if (j == a.begin()) swp.emplace_back(*i), i ++;
    else {
      if ((j - 1) -> second < i -> first) j --, swp.emplace_back(j -> second, j -> first);
      else swp.emplace_back(*i), i ++;
    }
  }
  a.clear();
  for (auto i : swp) {
    i.first += val; i.second += val;
    if (!a.size()) a.emplace_back(i);
    else {
      if ((a.end() - 1) -> first == i.first)
        chkmin((a.end() - 1) -> second, i.second);
      else if (i.second < (a.end() - 1) -> second)
        a.emplace_back(i);
    }
  }
}

inline void Upd(vec &a, vec &b, vec &c) {
  c.clear();
  if (!a.size() || !b.size()) return;
  for (vec :: iterator ia = a.begin(), ib = b.begin(); ia != a.end(); ia ++) {
    while (ib + 1 != b.end() && ia -> second + (ib + 1) -> first <= lim) ib ++;
    if (ia -> second + ib -> first <= lim) c.emplace_back(ia -> first, ib -> second);
  }
}

inline void Dfs(int x) {
  if (!lc[x]) return;
  Dfs(lc[x]); Dfs(rc[x]);
  Upd(dp[lc[x]], dp[rc[x]], dp[x]);
  Double(dp[x], v[x]);
}

int main() {
  scanf("%d", &n);
  for (int i = 2, f; i <= n; i ++) {
    scanf("%d%d", &f, &v[i]);
    if (!lc[f]) lc[f] = i;
    else rc[f] = i;
  }
  Init(1);
  swp.reserve(n << 1);
  LL L = 0, R = 1LL << 34, ans = 0;
  while (L <= R) {
    lim = (L + R) >> 1;
    Dfs(1);
    if (dp[1].size()) R = lim - 1, ans = lim;
    else L = lim + 1;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 27520
// dile a la jardinera que traigo flores
// corner cases // int vs ll // cin vs scanf
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 100050
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n,m, dp[N];
vector<int> adj[N];

int go(int u){
	int &ans = dp[u];
	if(ans != -1) return ans;
	ans = 0;
	for(int v : adj[u]) ans = max(ans,go(v)+1);
	return ans;
}

int main(){

	fastio;
	int a,b;
	cin >> n >> m;
	FER(i,0,m){
		cin >> a >> b;
		adj[a].pb(b);
	}

	int ans = 0;
	fill(dp,-1);
	for(int i = 1; i <= n; ++i)
		ans = max(ans,go(i));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7552
import copy
import itertools

def funcF(p):
    return p

def funcG(p):
    return funcF(p) + p*p

N, M = (int(i) for i in input().split())
X = list(int(i) for i in input().split())
X.sort()

if N >= M:
    print ("0")
    exit()

# X[0] ... X[M-1] をN個のグループに分ける
# X[i]とX[i+1]の間でグループを分ける場合Cx=iとする（i = 0 .. M-2の個数(N-1)個のCombinationで求まる）

# minS=max(X) - min(X)
# for C in list(itertools.combinations(range(M-1), N-1)):
#     tmpS = 0
#     if C[0] > 0:
#         tmpS += X[C[0]] - X[0]
#     for i in range(N-2):
#         if C[i+1] > C[i]+1:
#             tmpS += X[C[i+1]] - X[C[i]+1]
#     tmpS += X[M-1] - X[C[N-2]+1]
#     if tmpS < minS:
#         minS = tmpS

L=[]
for i in range(M-1):
    L.append(X[i+1] - X[i])
L.sort(reverse=True)
tmpL=0
for i in L[:N-1]:
    tmpL += i

print("{}".format(X[M-1]-X[0]-tmpL))


Measured memory_bytes: 14080
n,m = map(int,input().split())
l = []
for i in range(1 << n):
    tmp = str(bin(i))[2:]
    l.append(tmp.zfill(n))
K = [list(map(int,input().split())) for _ in range(m)]
P = list(map(int,input().split()))
#print(P)
ans = 0
#print("----")
for i in range(len(l)):
    #スイッチの状態l[i]
    #付いている電球のリストO
    O = []
    for j in range(m):
        #電球のきになるすいっちの数K[j][0]
        ON = 0
        for ii in range(K[j][0]): #スイッチのリスト
            if l[i][K[j][ii+1] - 1] == "1":
                ON += 1
        if ON % 2 == P[j]:
            O.append(1)
        else:
            O.append(0)
    if sum(O) == m:
        #print(l[i])
        ans += 1
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <math.h>
using namespace std;

int main() {
    double n, d;
    cin >> n >> d;
    double x[20][20];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    long long cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            long double sum = 0;
            for (int k = 0; k < d; k++) {
                sum += (x[j][k] - x[i][k]) * (x[j][k] - x[i][k]);
            }
            if (sqrt(sum) == (int)sqrt(sum)) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

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

struct rmq{
    int n; //size
    vector<int> segtree; //完全二分木を格納した配列
    const int INF = 0;
    
    rmq(int sz){
    	n = 1;
        while(n<sz) n<<=1; //配列サイズをsz以上の2冪に。
        //セグ木のサイズは2*n-1, 取り敢えず全て単位元で初期化しておく。
        segtree.assign(2*n-1,INF);
    }
    
    int find(int l, int r){
    	return find(l,r,0,n,0);
    }
    int find(int l, int r, int a, int b, int k){
    	if(b<=l || r<=a) return INF;  //区間外
        else if(l<=a && b<=r) return segtree[k];  //区間内
        //それ以外なら、子を調べてその結果をminしたものを返す。
        else return find(l,r,a,(a+b)/2,2*k+1)+find(l,r,(a+b)/2,b,2*k+2);
    }
    void update(int i, int x){
        i += n-1;
        segtree[i] += x; //元の配列のindexは頂点数2*n-1より、n-1足したもの。
        while(i>0){
            i = (i-1)/2;  //親に移動
            //子同士を比較して小さい方を親の値として更新。
            segtree[i] = segtree[2*i+1]+segtree[2*i+2];
        }
    }
};

int main(){
	int n, q;
	cin >> n >> q;
    rmq tr(n);
    for(int i=0; i<q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com==0){
            tr.update(x-1,y);
        }else{
            cout << tr.find(x-1,y-1+1) << endl;
        }
    }
}


Measured memory_bytes: 3792
//### In The Name Of GOD ###

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const int MOD = 1000000007;
const int INF = 30 * 1000 + 20;
const int MAXN = 2 * 1000 * 1000 + 15;
const int MLOG = 18;
const int NMAX = 251;

#define int ll
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define ct(x) const_cast<const int&>(x)

bool Ains[MAXN];
int all[MAXN];

int32_t main(){
	int n;
	cin >> n;
	int a = 1, b = 1, l,r;
	for(int i = 0; i < n; i++){
		cin >> l >> r;
		int lll = (a/l) + ((a%l) && 1);
		int rr = (b/r) + ((b%r) && 1);
		a = max(lll,rr)*l;
		b = max(lll,rr)*r;
		//cout << lll <<' '<< rr << ' ' << a << ' ' << b << endl;
	}
	cout << a + b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<pii> graph[n];

    rep(i, 0, n-1)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].emplace_back(b, i);
        graph[b].emplace_back(a, i);
    }

    // bfs
    queue<pii> que;
    vector<int> colors(n-1, -1);
    vector<bool> visited(n, false);
    que.push(make_pair(0, -1));
    int k = 0;
    while (que.size() > 0)
    {
        int now, c;
        tie(now, c) = que.front();
        que.pop();
        visited[now] = true;
        
        int colo = 1;
        for (auto edge: graph[now])
        {
            if (colo == c) ++colo;

            int next, i;
            tie(next, i) = edge;
    
            if (visited[next]) continue;
            que.push(make_pair(next, colo));
            colors[i] = colo++;
        }
        k = max(k, colo-1);
    }

    cout << k << endl;
    rep(i, 0, n-1)
        cout << colors[i] << endl;

    return 0;
}

Measured memory_bytes: 7040
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
ostream &operator<<(ostream &os, const vector<int> &a) {
	os<<"[";
	rep(i,a.size()){
		os<<a[i];
		if(i<a.size()-1) os<<",";
	}
	os<<"]";
	return os; 
}
int a[200100];
int n,m,inf=1001001001;
vector<int> cal(int mi){
	int mn1=inf,mx1=0,mn2=inf,mx2=0;
	rep(i,mi){
		mn1=min(mn1,a[i]+a[2*mi-1-i]);
		mx1=max(mx1,a[i]+a[2*mi-1-i]);
	}
	rep(i,n-mi){
		mn2=min(mn2,a[mi*2+i]+a[2*n-1-i]);
		mx2=max(mx2,a[mi*2+i]+a[2*n-1-i]);
	}
	vector<int> ret;
	ret.pb(mn1);ret.pb(mx1);ret.pb(mn2);ret.pb(mx2);
	//cout<<mi<<ret<<endl;
	return ret;
}
int main()
{
	cin>>n>>m;
	rep(i,n*2) cin>>a[i];
	sort(a,a+n*2);
	int lo=0,hi=n,out=inf;
	//cout<<lo<<' '<<hi<<endl;
	while(hi>lo){
		int mi=(hi+lo)/2;
		vector<int> v=cal(mi);
		if(v[2]<m) lo=mi+1;
		else hi=mi;
		/*else if(v[1]>=v[3]-m) hi=mi;
		else lo=mi;*/
	}
	REP(i,lo,hi+1){
		vector<int> v=cal(i);
		if(v[1]>=m || v[2]<m) continue;
		out=min(out,max(v[1],v[3]-m));
	}
	cout<<out<<endl;
}


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

using namespace std;

int N, K;
bool graph[105][105];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> K;
    int cnt = 0;
    for(int i = 1; i<=N; i++){
        for(int j = i+1; j<=N; j++){
            graph[i][j] = 1;
            cnt++;
        }
    }
    int crnt = 0;
    for(int i = 1; i<N && crnt < K; i++){
        for(int j = i+1; j<N && crnt < K; j++){
            crnt++;
            graph[i][j] = 0;
            cnt--;
        }
    }
    if(crnt < K){
        cout << -1 << "\n";
        exit(0);
    }
    cout << cnt << "\n";
    for(int i =1 ; i<=N; i++){
        for(int j = i+1; j<=N; j++){
            if(graph[i][j]){
                cout << i << " " << j << "\n";
            }
        }
    }
}


Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [0] * M
X = [0] * M
for i in range(M):
    cnt = 0
    P, X = map(int, input().split())
    for j in range(N):
        if j == P-1:
            cnt += X
        else:
            cnt += T[j]
    print(cnt)

Measured memory_bytes: 3064
k = int(input())
s = input()
mod = 10 ** 9 + 7
n = k + len(s)

fact = [1] * (n + 1)
revfact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = ((i + 1) * fact[i]) % mod
revfact[n] = pow(fact[n], mod - 2, mod)
for i in reversed(range(n)):
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
def combination(n, k, p):
    return (fact[n] * revfact[k] * revfact[n - k]) % p

ans = 0
comb = []
tf = [1]
for i in range(n + 1):
    comb.append(combination(n, i, mod))
    tf.append(tf[-1] * 25 % mod)
del tf[-1]
tf.reverse()
for i in range(len(s), n + 1):
    ans += comb[i] * tf[i]
    ans %= mod
print(ans)

Measured memory_bytes: 380432
#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 200010

vector<pair<int,int>> G[SIZE];
int ans[SIZE];

int dfs(int now, int back = -1, int color = -1) {
  int res = 0;
  int c = 0;
  for (auto e : G[now]) {
    if (e.first == back) continue;
    if (c == color) c++;
    ans[e.second] = c;
    res = max(res, c);
    res = max(dfs(e.first, now, c), res);
    c++;
  }

  return res;
}

int main(){
  int N;

  cin >> N;

  for (int i=0; i<N-1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;

    G[a].push_back({b, i});
    G[b].push_back({a, i});
  }

  int K = dfs(0);

  cout << K + 1 << '\n';

  for (int i=0; i<N-1; i++) {
    cout << ans[i] + 1 << '\n';
  }

  return 0;
}


Measured memory_bytes: 11648
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const ll N=1e6+5;
ll n,c[N],f[N],s[N];
struct node{
	ll l,r,b,k;
}a[N];
ll read(){
	ll x=0,w=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*w;
}

bool cmp1(node a,node b){return a.k==b.k?a.b<b.b:a.k<b.k;}
bool cmp2(node a,node b){return a.l==b.l?a.r<b.r:a.l<b.l;}
int main(){
	n=read();
	for(ll i=1;i<=n;i++)
	a[i].b=read(),a[i].k=read();
	sort(a+1,a+n+1,cmp1);
	c[1]=a[1].b;for(ll i=2;i<=n;i++)c[i]=max(c[i-1],a[i].b);
	for(ll i=1;i<=n;i++){
		ll l=1,r=i-1,ans=i;
		while(r>=l){
			ll mid=(l+r+1)>>1;
			if(c[mid]>a[i].b)ans=mid,r=mid-1;
			else l=mid+1;
		}a[i].l=ans;
	}
	c[n]=a[n].b;for(ll i=n-1;i>=1;i--)c[i]=min(c[i+1],a[i].b);
///	for(ll i=1;i<=n;i++)cout <<c[i]<<endl;
	for(ll i=1;i<=n;i++){
		ll l=i+1,r=n,ans=i;
		while(r>=l){
			ll mid=(l+r+1)>>1;
			if(c[mid]<a[i].b)ans=mid,l=mid+1;
			else r=mid-1;
		}a[i].r=ans;
	}
//	for(ll i=1;i<=n;i++)cout<<a[i].b<<' '<<a[i].k<<' '<<a[i].l<<' '<<a[i].r<<endl;
	sort(a+1,a+n+1,cmp2);
	ll now=1,ans=0;
	for(ll i=1;i<=n;i++){
		while(a[now].r<a[i].l-1)now++;
		f[i]=(s[i-1]-s[now-1])%mod;
		if(a[i].l==1)f[i]=(f[i]+1)%mod;
		s[i]=s[i-1]+f[i];
		if(a[i].r==n)ans=(ans+f[i])%mod;
	}
//	for(ll i=1;i<=n;i++)cout<<i<<' '<<f[i]<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18688
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	int h, w;
	cin >> h >> w;
	vector<string>c(h);
	rep(i, 0, h)cin >> c[i];
	rep(i, 0, h)rep(j, 0, 2)cout << c[i]<<endl;
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int k;
  cin>>k;
  int N=50;
  cout<<N<<endl;
  int a[N];
  for(int i=0;i<N;i++) a[i]=N-1;
  int p=k/50;
  for(int i=0;i<N;i++) a[i]+=p;
  int q=k%50;
  for(int i=0;i<q;i++) a[i]+=N-(q-1);
  for(int i=q;i<N;i++) a[i]-=q;
  for(int i=0;i<N;i++){
    if(i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  return 0;
}


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

int main(){
  string S , T ;
  cin >> S >> T ; 
  
  int N = S.size() ; 
  int M = T.size() ; 
  
  sort(S.begin(),S.end()) ;
  sort(T.begin(),T.end()) ;
  reverse(T.begin(),T.end()) ; 
  
  for(int i = 0 ; i < N ; i++){
    
    if(S < T){
      cout << "Yes" << endl ;
      return 0 ; 
    }
    else{
      cout << "No" << endl ;
      return 0 ; 
    }
  }
  
}

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

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

    int res = 0;
    for(int i=0;i<n;i++){
        // 同じ値をスキップ
        while(i+1 < n && a[i] == a[i+1]){
            i++;
        }

        // up
        if (i+1 < n && a[i] < a[i+1]){
            while(i+1 < n && a[i] <= a[i+1]){
                i++;
            }
        }// down
        else if (i+1 < n && a[i] > a[i+1]){
            while(i+1 < n && a[i] >= a[i+1]){
                i++;
            }
        }
        res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
use proconio::{fastout, input};
// use proconio::marker::*;

#[fastout]
fn main() {
   input! {
      a: f64,
      b: f64,
      h: f64,
      m: f64,
   }
   let th = (h as f64 / 12.0 + m as f64 / 60.0 / 12.0) * 2.0 * std::f64::consts::PI;
   let tm = (m as f64 / 60.0) * 2.0 * std::f64::consts::PI;
   let rs = a * a + b * b - 2.0 * a * b * (th - tm).cos();
   println!("{0:.10}", rs.sqrt());
}


Measured memory_bytes: 2992
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

int N, K;
int[][] edge;
bool[] visited;

void dfs(int n, int prev, int d) {
    visited[n] = true;
    if (d == 0) return;

    foreach (m; edge[n]) {
        if (m == prev) continue;
        dfs(m, n, d-1);
    }
}


void main() {
    auto s = readln.split.map!(to!int).array;
    N = s[0];
    K = s[1];
    visited = new bool[](N);
    edge = new int[][](N);
    foreach (i; 0..N-1) {
        s = readln.split.map!(to!int).array;
        edge[s[0]-1] ~= s[1]-1;
        edge[s[1]-1] ~= s[0]-1;
    }

    int ans = 1 << 29;
    if (K % 2 == 0) {
        foreach (i; 0..N) { // 各頂点を木の中心と仮定
            fill(visited, false);
            dfs(i, -1, K/2);
            ans = min(ans, N-visited.sum);
        }
    }
    else {
        foreach (i; 0..N) {
            foreach (j; edge[i]) {
                if (j < i) continue;
                fill(visited, false);
                dfs(i, -1, K/2);
                dfs(j, -1, K/2);
                ans = min(ans, N-visited.sum);
            }
        }
    }

    writeln(K == 1 ? N-2 : ans);
}


Measured memory_bytes: 636
#include <iostream>
#include <cmath>
#include <climits>

#define KEYMAX 12
#define KEY_POW (int)std::pow(2,KEYMAX)
#define MAX (int)1e3

using namespace std;
typedef long long int ll;
#define INFIN (int)1e9;
int openNum[MAX+1]={};
int value[MAX+1];
ll dp[MAX+1][KEY_POW];
int main(void){
  int N,M;
  cin >> N >> M;
  int total = (int)pow(2,N);
  for(int i=0;i<=M;i++){
    openNum[i] = 0;
  }
  for(int i=1;i<=M;i++){
    int a,b;
    cin >> a >> b;
    value[i] = a;
    for(int j=0;j<b;j++){
      int c,tmp;
      cin >> c;
      tmp = pow(2,c-1);
      openNum[i] += tmp;
    }
  }
  // initialize
  for(int i=0;i<=MAX;i++){
    for(int j=0;j<KEY_POW;j++){
      if(j==0){
        dp[i][0] = 0;
      }else{
        dp[i][j] = INFIN;
      }
    }
  }
  dp[0][0] = 0;
  // dp caliculate
  for(int i=1;i<=M;i++){
    int key = openNum[i];
    int v = value[i];
    //cout << key << " " << v << endl;
    for(int j=0;j<total;j++){
      if(dp[i-1][j] < dp[i][j]){
        //cout << "up" << endl;
        dp[i][j] = dp[i-1][j];
      }
      //cout << "par:" << j << " " << total << endl;
      int opend = j|key;
      int ans = 0;
      int count = 1;
      while(opend > 0){
        if(opend%2 == 1){
          ans = ans + count;
          opend = opend - 1;
        }
        opend /= 2;
        count *= 2;
      }
      //cout << ans << endl;
      if(dp[i-1][j] + v < dp[i][ans]){
        dp[i][ans] = dp[i-1][j] + v;
        //cout << "hit:" << ans << endl;
      }
    }
  }
  ll answer = dp[M][total-1];
  if(answer == (ll)1e9){
    answer = -1;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 36124
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val m = sc.nextLong()
    println(problem065c(n, m))
}

fun problem065c(n: Long, m: Long): Long {
    if (Math.abs(n - m) >= 2) return 0
    val mod: Long = (Math.pow(10.0, 9.0) + 7).toLong()
    fun computeFactorial(n: Long): Long {
        return (1..n).toList().reduce { acc, l -> acc * l % mod }
    }

    return if (n != m) {
        computeFactorial(n) * computeFactorial(m) % mod
    } else {
        computeFactorial(n) * computeFactorial(m) * 2 % mod
    }
}


Measured memory_bytes: 40476
x = 1
y = 1
z = input()
x , y = [ int(a) for a in z.split() ]
while not(x == 0 and y == 0):
    if x < y:
        print (str(x) + " " + str(y))
    elif x > y:
        print (str(y) + " " + str(x))
    else:
        print (str(x) + " " + str(y))
    z = input()
    x , y = [ int(a) for a in z.split() ]


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

signed main() {
    int n, k;
    cin >> n >> k;

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

    sort(h.begin(), h.end(), greater<int>());
    
    int ans = 0;
    rep(i, k, n) ans += h[i];

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int a, b;
	cin >> a >> b;

	ll res = -1;
	for (ll i = 1; i <= 10000 ; i++)
	{
		if ((int)(i * 0.08) == a && (int)(i * 0.1) == b)
		{
			res = i;
			break;
		}
	}

	println(res);
}


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

const int MOD = 1000000007;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;



map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}



int main(){
    int N;
    vector<ll> A(10010);
    cin >> N;
    map<ll,ll> lcm;
    rep(i,N){
        cin >> A[i];
        auto mp = prime_factor(A[i]);
        for(auto it: mp){
            if(lcm[it.first] < it.second) lcm[it.first] = it.second;
        }
    }

    modint lcmod = 1;
    for(auto it : lcm){
        lcmod *= pow(it.first,it.second);
    }

    modint res = 0;
    rep(i,N){
        res += (lcmod / A[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 4292
#include <iostream>
#include <cmath>
#include <list>
#include <algorithm>

#define INF (1<<30)
using namespace std;

int main(void) {
    int n, k;
    cin >> n;
    int a[n][3];
    for (int i = 0; i < n; i++)cin >> a[i][0] >> a[i][1] >> a[i][2];
    int f[3];
    f[0] = a[0][0];
    f[1] = a[0][1];
    f[2] = a[0][2];
    for (int i = 1; i < n; i++) {
        int x = max(f[1] + a[i][0], f[2] + a[i][0]);
        int y = max(f[0] + a[i][1], f[2] + a[i][1]);
        int z = max(f[0] + a[i][2], f[1] + a[i][2]);
        f[0] = x, f[1] = y, f[2] = z;
    }
    cout << max(f[0], max(f[1], f[2])) << endl;
    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static string str1, str2;
    static int[,] _lcs;
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            str1 = Console.ReadLine();
            str2 = Console.ReadLine();
            _lcs = new int[str1.Length, str2.Length];
            Console.WriteLine(Lcs(str1.Length - 1, str2.Length - 1));
        }
    }

    static int Lcs(int i, int j)
    {
        if(i < 0 || j < 0 || i >= str1.Length || j >= str2.Length) return 0;
        else if(_lcs[i, j] != 0) return _lcs[i, j];
        else if(str1[i] == str2[j]) return _lcs[i, j] = Lcs(i - 1, j - 1) + 1;
        else return _lcs[i, j] = Math.Max(Lcs(i, j - 1), Lcs(i - 1, j));
    }
}

Measured memory_bytes: 18324
S = input()
if S[0] == 'A' and S[2:-1].count('C') == 1:
    index_c = S[2:-1].index('C')
    S = S[1:2 + index_c] + S[3 + index_c:]
    if S.islower():
        print('AC')
        exit()
print('WA')

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

int main(){
	int x;cin>>x;
    int b=sqrt(x),mx=1;
	while(b){
      int p=2,y=1;
      while(y<=x){
        mx=max(mx,y);
        if(b==1)break;
        y=pow(b,p);
        p++;
      }
    b--;
    }
   cout<<mx;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader =
				new BufferedReader(new InputStreamReader(System.in));
		Main byakko = new Main();
		
		int n = Integer.parseInt(reader.readLine()),x,y;
		String str;
		
		for(int i = 0; i < n; i++){
			str = reader.readLine();
			x = Integer.parseInt(str.split(" ",0)[0]);
			y = Integer.parseInt(str.split(" ",0)[1]);
			
			System.out.println(byakko.daoda(x, y));
		}
		reader.close();
	}
	
	public int daoda(int x, int y){
		if(x < y)return x;
		
		else
			if(x % y == 0)return y;
		
			else return x % y;
	}
	
}

Measured memory_bytes: 17248
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	map<vi, int> M;
	vector<vi> VV;
	REP(i, N) {
		string str;
		cin >> str;
		vi V(26);
		REP(j, SZ(str)) {
			V[str[j] - 'a']++;
		}
		M[V]++;
		VV.push_back(V);
	}
	ll ans = 0;
	REP(i, N) {
		ans += M[VV[i]] - 1;
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 32688
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

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

int H, W;
int sx, sy, gx, gy;
vector<string> S;
vector<vector<int>> dist(55, vector<int> (55, -1));


int main(){
  cin >> H >> W;
  S.resize(H);
  for(int i=0; i<H; i++){
    cin >> S[i];
  }
  sx=0, sy=0;
  gx=W-1, gy=H-1;
  queue<pair<int, int>> Q;
  pair<int, int> P;
  P = make_pair(sy, sx);
  dist[sy][sx] = 0;
  Q.push(P);
  while(!Q.empty()){
    P = Q.front();
    Q.pop();
    for(int i=0; i<4; i++){
      int ny = P.first + dy[i];
      int nx = P.second + dx[i];
      if(ny>=H || ny<0 || nx>=W || nx<0){
        continue;
      }
      if(S[ny][nx] == '#'){
        continue;
      }
      if(dist[ny][nx] != -1){
        continue;
      }
      dist[ny][nx] = dist[P.first][P.second] + 1;
      pair<int, int> p;
      p = make_pair(ny, nx);
      Q.push(p);
    }
  }
  int count=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '.'){
        count++;
      }
    }
  }
  if(dist[gy][gx] == -1){
    cout << -1 << endl;
  }else{
    cout << count-(dist[gy][gx]+1) << 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);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		System.out.print(a.charAt(0));
		System.out.print(b.charAt(0));
		System.out.print(c.charAt(0));
	}
}




Measured memory_bytes: 22996
#include<stdio.h>
#include<iostream>
using namespace std;
int main() {
/*
	int a, b;
	cin >> a;
	cin >> b;
	if (a <= 5) {
		cout << 0;
	}
	else if (a <= 12) {
		cout << b / 2;
	}else{
		cout << b;
	}

	return 0;
	*/
	//B
	/*long long int r, d, x;
	cin >> r;
	cin >> d;
	cin >> x;

	int i;
	for (i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x;
		cout <<'\n';
	}


	return 0;*/
	//C
	int n, m;
	int l, r;
	cin >> n;
	cin >> m;

	int lmax, rmin;
	lmax = 1;
	rmin = n;
	int i;
	for (i = 0; i < m; i++) {
		cin >> l;
		cin >> r;
		if (l > lmax) {
			lmax = l;
		}
		if (r < rmin) {
			rmin = r;
		}
	}
	if (lmax <= rmin) {
		cout << (rmin - lmax + 1);
	}
	else {
		cout << 0;
	}

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int a[10000001];

int main() {
  rep(i, 2, 10000001) {
    if(!a[i]) {
      for(int j = i * 2; j < 10000001; j += i) {
        a[j] = 1;
      }
    }
  }
  int sum;
  rep(i, 1, 9999993) {
    if(!a[i] && !a[i + 2] && !a[i + 6] && !a[i + 8]) sum = i + 8;
    a[i] = sum;
  }

  int b;
  while(cin >> b && b) {
    cout << a[b - 8] << endl;
  }
}

Measured memory_bytes: 42148
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  ll w[100],v[100];
  vll vec[5];
  cin >> n >> m;
  //入力
  rep(i,0,n){
    cin >> w[i] >> v[i];
    vec[w[i] - w[0]].pb(v[i]);
  }
  //1 ~ 3を整理
  rep(i,0,4){
    sort(all(vec[i]));
    vec[i].pb(0);
    reverse(all(vec[i]));
    rep(j,0,vec[i].sz - 1)vec[i][j + 1] += vec[i][j];
  }
  l = 0;
  //1 ~ 3について値を取り、そのあと4を選ぶ
  rep(i,0,vec[0].sz){
    rep(j,0,vec[1].sz){
      rep(k,0,vec[2].sz){
        ll p = w[0] * i + (w[0] + 1) * j + (w[0] + 2) * k;
        ll q = vec[0][i] + vec[1][j] + vec[2][k];
        if(p > m)continue;
        ll g = vec[3].sz;
        g = min(g,(m-p)/(w[0] + 3));
        q += vec[3][g];
        l = max(l,q);
      }
    }
  }
  print(l);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
     d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <vector>

int main() {
    int H, W;
    std::cin >> H >> W;

    std::vector<std::string> result;

    result.push_back(std::string(W + 2, '#'));

    for (int i = 0; i < H; ++i) {
        std::string line;
        std::cin >> line;
        result.push_back("#" + line + "#");
    }

    result.push_back(std::string(W + 2, '#'));

    for (int i = 0; i < result.size(); ++i) {
        std::cout << result[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 888
//JSD
#include<iostream>
#include<vector>
using namespace std;
int main(){
	string a;
	cin>>a;
	vector<string > v={"SUN", "MON", "TUE", "WED", "THU", "FRI",  "SAT"};
	int p1,p2;
	int q=0;
	for(int i=0;i<7;i++){
		if(v[i]==a){
			q=i;
			break;
		}
	}		
	int ans=0;
	for(int i=q;;i++,i%=7){				
		if(v[i]=="SUN"){
			if(ans==0) ans=7;
			cout<<ans<<"\n";
			
			break;
		}
		ans++;	
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long N, K, i, ans=0; cin >> N >> K; vector<long> H(N);
for(i=0; i<N; i++){ cin >> H[i]; }
sort(H.begin(), H.end());
for(i=0; i<N-K; i++){ ans+=H[i]; }
cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

ll n;
vec<std::string> ans;

void dfs(std::string s, ll k) {
    if (k == s.size()) {
        ans.push_back(std::move(s));
        return;
    }

    bool used[10] = { };
    ll maxv = -1;
    for (ll i = 0; i < k; i++) {
        ll idx = s[i] - 'a';
        if (used[idx]) continue;
        used[idx] = true;
        chmax(maxv, idx);
        s[k] = s[i];
        dfs(s, k + 1);
    }

    s[k] = 'a' + (maxv + 1);
    dfs(s, k + 1);
}

int main() {
    std::cin >> n;
    std::string init(n, '0');
    dfs(init, 0);
    std::sort(ALL(ans));
    for (auto &&s : ans) std::cout << s << '\n';
    return 0;
}


Measured memory_bytes: 7796
FIXMAX = 2**62 - 1
def gli
  gets.split.map(&:to_i)
end

n = gets.to_i
c = gli
mn =  FIXMAX
for i in (c.min..c.max)
  tmp = 0
  c.each { |cc|
    tmp += (cc - i) ** 2
  }
  mn = tmp if mn > tmp
end
puts mn


Measured memory_bytes: 1788