akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

kz gcd(kz a,kz b) { if(b==0) return a; else gcd(b,a%b); }

bool sol(double xa,double ya,double xb,double yb,double xc,double yc,double xd,double yd) {
    if (abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1e-10) return true;
    return false;
}

int main(){
    int mod=1000000007;
    int n;
    double a,b,c,d,e,f,g,h;
    while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f,&g,&h)!=EOF) {
        if (sol(a,b,c,d,e,f,g,h)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  ll q;
  cin >> a >> b >> q;
  ll tmp;
  vector<ll> A,B,Q;
  REP(i,a){
      cin >> tmp;
      A.push_back(tmp);
  }
  A.push_back(-LLINF);A.push_back(LLINF);
  REP(i,b){
      cin >> tmp;
      B.push_back(tmp);
  }
  B.push_back(-LLINF);B.push_back(LLINF);
  REP(i,q){
      cin >> tmp;
      Q.push_back(tmp);
  }
  SORT(A);SORT(B);
  
  for(auto x: Q){
      ll ans = LLINF;
      auto it_s1 = lower_bound(ALL(A),x)-1;
      auto it_s2 = upper_bound(ALL(A),x);
      auto it_t1 = lower_bound(ALL(B),x)-1;
      auto it_t2 = upper_bound(ALL(B),x);
      //cout << *it_s1 << " " <<  *it_s2 << " " <<  *it_t1 << " " <<  *it_t2 << " " << endl;

      ans = min( ans, abs(x - *it_s1) + abs(*it_s1 - *it_t1));
      ans = min( ans, abs(x - *it_s1) + abs(*it_s1 - *it_t2));
      ans = min( ans, abs(x - *it_s2) + abs(*it_s2 - *it_t1));
      ans = min( ans, abs(x - *it_s2) + abs(*it_s2 - *it_t2));
      ans = min( ans, abs(x - *it_t1) + abs(*it_t1 - *it_s1));
      ans = min( ans, abs(x - *it_t1) + abs(*it_t1 - *it_s2));
      ans = min( ans, abs(x - *it_t2) + abs(*it_t2 - *it_s1));
      ans = min( ans, abs(x - *it_t2) + abs(*it_t2 - *it_s2));
      cout << ans << endl;
  }
}


Measured memory_bytes: 3828
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    inp = list(input().split())
    a = int(inp[0])
    bstr = ''
    for i in inp[1]:
        if i == '.':
            continue
        bstr+=i
    b = int(bstr)
    ans = a*b
    print(ans//100)


main()




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

int main(){
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  int64_t ans = 0, cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if (s.at(i) == 'B'){
      ans += i - cnt;
      cnt++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3780
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

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

    vector<int> a(n+1), b(n+2);

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

    ll result = 0;
    for (int i = 0; i < n + 1; i++) {
        if (a[i] <= b[i]) {
            result += (ll)a[i];
        }
        else {
            a[i] -= b[i];
            result += (ll)b[i];
            if (a[i] <= b[i + 1]) {
                b[i + 1] -= a[i];
                result += (ll)a[i];
            }
            else {
                result += (ll)b[i + 1];
                b[i + 1] = 0;
            }
        }
    }

    cout << result << endl;

    return 0;
}


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

int main() {
  int N, M, sum=0;
  
  cin >> N;
  M = N;
  for(int i = 0; M > 0; i++) {
    sum = sum + M % 10;
    M = M / 10;
  }
  if(N % sum) {
    cout << "No" << endl;
  }else {
    cout << "Yes" << endl;
  }
}



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

vector<vector<int>> d(202, vector<int>(202, 1001001001));
vector<int> r;

int dp[10][1010];

int dfs(int v, int bit) {
  int &res = dp[v][bit];

  if (~res) return res;
  res = 1001001001;

  for (int i = 0; i < r.size(); ++i) {
    if ((bit >> i) & 1) continue;
    res = min(res, dfs(i, bit + (1 << i)) + d[r[v]][r[i]]);
  }

  if (res == 1001001001) res = 0;
  return res;
}

int solve() {
  int ans = 1001001001;

  for (int i = 0; i < r.size(); ++i) {
    memset(dp, -1, sizeof(dp));
    ans = min(ans, dfs(i, (1 << i)));
  }

  return ans;
}

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

  for (int i = 0; i < e; ++i) {
    int a;
    cin >> a;
    r.push_back(a - 1);
  }

  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    u--; v--;
    d[u][v] = c;
    d[v][u] = c;
  }

  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  cout << solve() << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "a"||s == "i"||s == "u"||s == "e"||s == "o"){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

const int mod = 1e9+7;
const ll INF = 1e18;

void test(){

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    string ans = "";

    while(t > 0){
        --t;
        ll v = t % 26;
        ans += (char)('a' + v);
        t /= 26;
    }

    reverse(ans.begin(),ans.end());
    cout << ans;
}


Measured memory_bytes: 3632
from sys import stdin

class Node(object):
    def __init__(self, parent=None, children=None, name=None):
        self.parent = parent
        self.children = children
        self.name = name

def print_nodes(nodes, n):
    def get_depth(nodes, u):
        p = nodes[u].parent
        nonlocal d
        if p != None and p != -1:
            get_depth(nodes, p)
            d += 1
        return d

    for i in range(n):
        d = 0
        if nodes[i].parent == None:
            nodes[i].parent = -1
            nodes[i].name = "root"
        print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(
               i, nodes[i].parent, get_depth(nodes, i), nodes[i].name, nodes[i].children))

def read_rooted_tree(nodes, n):
    for _ in range(n):
        i = [int(i) for i in stdin.readline().strip().split()]
        c = i[2:len(i)]
        nodes[i[0]].children = c
        if c:
            nodes[i[0]].name = "internal node"
        else:
            nodes[i[0]].name = "leaf"
        for j in nodes[i[0]].children:
            nodes[j].parent = i[0]

n = int(input())
nodes = [Node() for _ in range(n)]
read_rooted_tree(nodes, n)
print_nodes(nodes, n)


Measured memory_bytes: 35712
#include<stdio.h>
#define MAX 100005
#define NIL -1
 
typedef struct{
  int parent, left, right;
}Node;
 
Node Tree[MAX];
int n, Depth[MAX];
 
int getDepth(int);
void print(int);
 
int child[MAX];
 
int main(void){
  int i, j;
  int degree, vertex;
 
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &vertex, &degree);
    for ( j = 0; j < degree; j++ ){
      scanf("%d", &child[j]);
 
      Tree[child[j]].parent = vertex;
       
      //rightを決める基準となる。
      if(j == 0)
    Tree[vertex].left = child[0];
       
      else
    Tree[child[j - 1]].right = child[j];
    }
  }
   
  for ( i = 0; i < n; i++ )
    Depth[i] = getDepth(i);
   
  for ( i = 0; i < n; i++ )
    print(i);
   
  return 0;
}
 
int getDepth(int u){
  int d = 0;
 
  while(Tree[u].parent >= 0){
    u = Tree[u].parent;
    d++;
  }
 
  return d;
}
 
void print(int u){
 
  int i, cnt = 0;
 
  printf("node %d: parent = %d, depth = %d, ",u,Tree[u].parent,Depth[u]);
 
  if(Tree[u].parent == NIL)
    printf("root, [");
 
  else if(Tree[u].left == NIL)
    printf("leaf, [");
 
  else
    printf("internal node, [");
 
  u = Tree[u].left;
  while(u != NIL){
    if(cnt == 0)
      printf("%d",u);
 
    else
      printf(", %d",u);
   
    u = Tree[u].right;
    cnt++;
 
     
  
 }
 
 
    printf("]\n");
 
}

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

int main(void){
    long long N;
    cin >> N;
    vector<long long> bucket(N,0);    //1->bucket[0]に数値の個数格納
    vector<long long> cube(N);        //玉の数値を順番に格納
    for(long long i=0;i<N;i++){
        cin >> cube[i];
        bucket[cube[i]-1]++;
    }

    vector<long long> parts(N);   //bucket[i]個の玉を二つ選ぶ総数
    long long sum = 0;
    for(int i=0;i<N;i++){
        parts[i] = bucket[i]*(bucket[i]-1)/2;
        sum += parts[i];
    }
    //cout << "sum: " << sum << endl;

    for(long long i=0;i<N;i++){
        long long ans = sum - parts[cube[i]-1];
        //cout << "ans0 = " << ans << endl;
        //cout << "bucket[cube[i]-1] == " << bucket[cube[i]-1] << endl;
        long long fix = (bucket[cube[i]-1]-1)*(bucket[cube[i]-1]-2)/2;
        if(fix>0) ans += fix;
        cout << ans << endl;
    }
}

Measured memory_bytes: 7296
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int H, N;
    cin >> H >> N;
    int sum = 0;
    rep(i, N) {
        int A;
        cin >> A;
        sum += A;
    }

    cout << (H <= sum ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
#print(l)
#start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        #print(l[i], l[j],ab , c_index, j+1, res)
        res += c_index - j - 1
print(res)

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


int main(){
  int N;
  vector<string> S(200010, "0");

  cin >> N;
  for(int i=0; i<N; i++) cin >> S[i];

  sort(S.begin(), S.begin()+N);

  int cnt = 1, max_cnt = 0;
  for(int i=0; i<N; i++){
    if(S[i] == S[i+1]){
      cnt++;
    } else {
      max_cnt = max(cnt, max_cnt);
      cnt = 1;
    }
  }

  cnt = 1; vector<string> ans;
  for(int i=0; i<N; i++){
    if(cnt == max_cnt) ans.push_back(S[i]);

    if(S[i] == S[i+1]){
      cnt++;
    } else {
      cnt = 1;
    }
  }

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

  for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;
  
  


}

Measured memory_bytes: 15988
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n, x[10000000], ba; char s;
int main() {
	while (true) {
		cin >> n;
		ba = 0;
		memset(x, 0, sizeof(x));
		if (!n) { break; }
		for (int i = 0; i < 100; i++) {
			cin >> s;
			x[i%n]++;
			if (s == 'S') { ba += x[i%n]; x[i%n] = 0; }
			if (s == 'L') { x[i%n] += ba; ba = 0; }
		}
		sort(x, x + n);
		for (int i = 0; i < n; i++) {
			cout << x[i];
			cout << ' ';
		}
		cout << ba << endl;
	}
}

Measured memory_bytes: 40244
n = int(input())
a,b = map(int,input().split())
x,y,z = 0,0,0
li = list(map(int,input().split()))
for i in range(n):
    if li[i] <= a:
        x += 1
    elif li[i] >= a + 1 and li[i] <= b:
        y += 1
    else:
        z += 1
print(min(x,y,z))

Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int N;
    cin>>N;
    vector<int> X(N),Y(N),h(N);
    rep(i,N) cin>>X[i]>>Y[i]>>h[i];

    rep(Cx,101){
        rep(Cy,101){
            vector<int> H;
            bool ok = true;
            int p;
            rep(i,N){
                if(h[i]){
                    H.pb(abs(X[i]-Cx) + abs(Y[i]-Cy) + h[i]);
                    p = H[i];
                }
                else H.pb(0);   
            }
            rep(i,N){
                if(H[i] == 0) abs(X[i]-Cx) + abs(Y[i]-Cy) < p ? ok = false:0;
                else if(H[i] != p) ok = false; 
            }
            if(ok){
                cout<<Cx<<" "<<Cy<<" "<<p<<endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const ll maxmaxIN = 1LL << 60;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<ll> A(n + 1), actI(n + 1), maxIN(n + 1);
  ll totl = 0;
  for (auto &x : A) {
    cin >> x;
    totl += x;
  }

  maxIN[0] = 1 - A[0];
  for (int i = 0; i < n; i++) {
    maxIN[i + 1] = min(maxIN[i] * 2 - A[i + 1], maxmaxIN);
  }

  bool poss = (*min_element(maxIN.begin(), maxIN.end())) >= 0;

  actI[n] = 0;
  ll toti = 0;
  for (int i = n - 1; i >= 0 && poss; i--) {
    actI[i] = min(actI[i + 1] + A[i + 1], maxIN[i]);
    toti += actI[i];
  }

  cout << (poss ? (toti + totl) : -1) << "\n";
}

Measured memory_bytes: 5568
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back
#define inf (1<<29)

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        ll a,b,c,d; cin >> a >> b >> c >> d;
        cout<<max((a*b),(c*d))<<endl;



return 0;
}







Measured memory_bytes: 384
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb push_back

const int N = 1010;
const int M = 12;
const int inf = -inf;

int dp[N][1<<M];

bool solve(int n,int *damage,int m,int *portion,int hpini,int hpmax){
  rep(i,n)rep(j,(1<<m))dp[i][j]=-inf;
  dp[0][0]=hpini;

  rep(i,n){
    rep(j,(1<<m)){
      if (i)dp[i][j]=max(dp[i-1][j]-damage[i],dp[i][j]);
      if (dp[i][j] <= 0)continue;
      //cout << i <<" " << j << " " << dp[i][j] << endl;
      rep(k,m){
	if ((1<<k)&j)continue;
	dp[i][j|(1<<k)]=min(hpmax,max(dp[i][j]+portion[k],dp[i][j|(1<<k)]));
      }
    }
  }
  rep(i,(1<<m))if (dp[n-1][i] > 0)return true;
  return false;
}


char m[100][100];//convert to damage
//DURL
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
void make(vector<int> path,int *damage){
  int x=0,y=0;
  rep(i,path.size()){
    y+=dy[path[i]];
    x+=dx[path[i]];
    damage[i+1]=m[y][x];
  }
}

main(){
  int hpini,hpmax;
  int damage[N];
  int portion[M];
  map<char,int> MAP;
  while(cin>>hpini >>hpmax && hpmax){
    int r,c;
    cin>>r>>c;
    rep(i,r)rep(j,c)cin>>m[i][j];
    
    int ns;
    cin>>ns;
    rep(i,ns){
      char tmp;int a;
      cin>>tmp>>a;
      MAP[tmp]=a;
    }
    rep(i,r)rep(j,c)m[i][j]=MAP[m[i][j]];

    vector<int> path;
    int pnum;
    cin>>pnum;
    rep(i,pnum){
      char tmp;int cnt;
      cin>>tmp>>cnt;
      int ins;
      if (tmp == 'D')ins=0;
      if (tmp == 'U')ins=1;
      if (tmp == 'R')ins=2;
      if (tmp == 'L')ins=3;
      rep(j,cnt)path.pb(ins);
    }

    int po;
    cin>>po;
    rep(i,po)cin>>portion[i];

    make(path,damage);

    //    rep(i,po)cout << portion[i] <<" " ;cout << endl;
    //    rep(i,path.size()+1)cout << damage[i]<<" " ;cout << endl;

    if (solve(path.size()+1,damage,po,portion,hpini,hpmax))cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return false;
}

Measured memory_bytes: 16000
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
typedef string::const_iterator State;
Def expr(State &i);
Def term(State &i);
Def factor(State &i);
Def number(State &i);
ll MOD=1000000007;
string s;
void consume(State &i,char expected){
	if(*i==expected)i++;
	else{
		exit(0);
	}
}
Def expr(State &i){
	Def out=term(i);
	while(*i=='>'&&*(i+1)=='>'&&(*(i+2)=='S'||isdigit(*(i+2)))){
		i+=2;
		Def out1=term(i);
		out>>=min(out1,33ll);
	}
	return out;
}
Def term(State &i){
	if(isdigit(*i))return number(i);
	i++;
	i++;
	Def out=expr(i);
	out=out*out%MOD;
	i++;
	return out;
}
Def number(State &i){
	Def out=0;
	while(isdigit(*i))out=out*10+*(i++)-'0';
	return out;
}
int main(){
	while(1){
		getline(cin,s);
		if(s=="#")break;
		s.erase(remove(s.begin(),s.end(),' '),s.end());
		State begin=s.begin();
		cout<<expr(begin)<<endl;
	}
}

Measured memory_bytes: 4908
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >>h >> w;
    string s;
    for(int i=0;i<h;i++){
    	cin >> s;
    	cout << s << "\n" << s << "\n"; 
    }
    return 0;
}


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

return 0;
}


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

#define ll long long
#define pb push_back

using namespace std;

ll n, m, v, p, res;
vector<ll> a, b;

bool f(ll tm){
    vector<ll> c = b;
    c[tm] += m;
    ll sc = c[tm], tc = m * v; 
    for(int i = 0; i < c.size(); ++i){
        if(i == tm) continue;
        if(c[i] > sc) continue;
        ll dec = min(sc - c[i], m);
        tc  -= dec;
        c[i] = sc;
    }
    auto it = max_element(c.begin(), c.end());
    return (*it == sc && tc <= 0);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> v >> p;
    a.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n - p + 1; ++i){
        b.pb(a[i]);
    }
    reverse(b.begin(), b.end());
    res = 0;
    v -= p;
    v = max(v, 0LL);
    ll l = 1, r = b.size() - 1;
    while(l <= r){
        ll tm = l + (r - l)/2;
        if(f(tm)){
            res = tm;
            l = tm + 1;
        }
        else{
            r = tm - 1;
        }
    }
    // cout << res << "\n";
    cout << res + p;
    return 0;
}

Measured memory_bytes: 2804
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 51;
int n, t[maxn];
string s[maxn], x;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0;i < n;++i)cin >> s[i] >> t[i];
	cin >> x;
	int res = 0;
	bool ed = false;
	for(int i = 0;i < n;++i){
		if(ed)res += t[i];
		if(s[i] == x)ed = true;
	}
	cout << res << '\n';

}


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

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

    vector<vector<int>> graph(10, vector<int>(10, 0));
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        graph[x-1][y-1] = graph[y-1][x-1] = 1;
    }

    vector<int> s(n);
    rep(i,n){
        s[i] = i; 
    }

    int ans = 0;
    do {
        if(s[0]!=0) break;                    //スタートが1以外は無視
        rep(i, n-1) {                         //全ての辺（n-1）の繋がりがあるか
            if(graph[s[i]][s[i+1]]==0) break;
            if(i == n-2) ans++;
        }
    } while (next_permutation(s.begin(), s.end()));


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

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

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

    vector<int> f(n+1,0);

    rep1(x,100){
        rep1(y,100){
            rep1(z,100){
                int t=x*x+y*y+z*z+x*y+y*z+z*x;
                if(t<=n)f.at(t)++;
            }
        }
    }

    rep1(i,n){
        cout << f.at(i) << endl;
    }

    
    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

ll dp[105][100005], dps[105][100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, k; read(n, k);
	vector<int> a(n + 1);
	rep(i, 1, n + 1) read(a[i]);

	dp[0][0] = 1;
	rep(i, 0, k + 1) dps[0][i] = 1;

	const ll mod = 1000000007;

	rep(i, 1, n + 1) {
		rep(j, 0, k + 1) {
			int lo = j - a[i], hi = j;
			dp[i][j] = (dps[i - 1][hi] - (lo > 0 ? dps[i - 1][lo - 1] : 0) + mod) % mod;
		}
		rep(j, 0, k + 1) dps[i][j] = (j ? dps[i][j - 1] : 0) + dp[i][j];
	}

	die(dp[n][k]);
}


Measured memory_bytes: 160000
#include<stdio.h>
#define N 500001
int n,count;
void merge(int a[],int left,int mid,int right){
    int n1,n2,i,j,k;
    n1=mid-left;
    n2=right-mid;
    int l[n1+1],r[n2+1];
    for(i=0;i<n1;++i) l[i]=a[left+i];
    for(i=0;i<n2;++i) r[i]=a[mid+i];
    l[n1]=r[n2]=2000000000;
    i=j=0;
    for(k=left;k<right;k++){
        count++;
        if(l[i]<=r[j])a[k]=l[i++];
        else a[k]=r[j++];
    }
}
void mergeSort(int a[],int left,int right){
    int mid;
    if(left+1<right){
        mid=(left+right)/2;
        mergeSort(a,left,mid);
        mergeSort(a,mid,right);
        merge(a,left,mid,right);
    }
}
int main()
{
  int i;
  int A[N];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
      if(i) printf(" ");
      printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}


Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
int a[200005];
long long s[200005],ss[200005],ans;
int main(){
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
	for (int i=1;i<=n;i++) ss[i]=ss[i-1]^a[i];
	int j=1;
	for (int i=1;i<=n;i++){
		while (s[i]-s[j-1]!=(ss[i]^ss[j-1]))
			j++;
		ans+=i-j+1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4096
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1)%MOD;
}
int main(){
  ll n,m;cin>>n>>m;
  if(n==m)cout<<factorial(n)*factorial(m)%MOD*2%MOD<<endl;
  else if(n==m+1 || n==m-1)cout<<factorial(n)*factorial(m)%MOD<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
using ll = long long int;

int main(void) {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k < a) cout << k << endl;
    else if (a <= k && k < a + b) cout << a << endl;
    else cout << a + (-1) * (k - a - b) << endl;
}

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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	string s; cin >> s;
	vector<char> v;
	for (char c : s) {
		if (c != 'B') v.push_back(c);
		else if (v.size()) v.pop_back();
	}
	for (char c : v) cout << c;
	cout << endl;
	system("pause");
}

Measured memory_bytes: 504
N = int(input())
A = map(int, input().split())

B = [[i, a] for i, a in enumerate(A)]

C = sorted(B, key=lambda b: b[1], reverse=True)

dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]

dp[1][0] = (C[0][0] - 0) * C[0][1]
dp[0][1] = ((N - 1) - C[0][0]) * C[0][1]

ans = 0
for i in range(2, N + 1):
    for j in range(0, i + 1):
        t1, t2 = 0, 0

        if j - 1 >= 0:
            t1 = dp[j - 1][i - j] + abs((C[i - 1][0] - (j - 1))) * C[i - 1][1]

        if i - j - 1 >= 0:
            t2 = dp[j][i - j - 1] + abs((C[i - 1][0] - (N - (i - j)))) * C[i - 1][1]

        dp[j][i - j] = max(t1, t2)

        if i == N:
            ans = max(ans, dp[j][i - j])

print(ans)


Measured memory_bytes: 108212
import java.util.*

fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(' ').map { it.toInt() }

    var t = 0
    val queue = ArrayDeque<Pair<String, Int>>()

    repeat(n) {
        val (name, time) = readLine()!!.split(' ')
        queue.addLast(Pair(name, time.toInt()))
    }

    while (queue.isNotEmpty()) {
        val process = queue.removeFirst()

        if (process.second > q) {
            t += q
            queue.addLast(Pair(process.first, process.second - q))
            continue
        }

        t += process.second
        println("${process.first} $t")
    }

}


Measured memory_bytes: 77516
dp = Array.new(10){ Array.new(1001){0} }
dp[0][0] = 1

0.upto(100) do |i|
  1000.downto(0) do |j|
    9.downto(1) do |k|
      dp[k][j] += dp[k-1][j-i] if j-i >= 0
    end
  end
end

while gets do
  n, s = $_.split(' ').map(&:to_i)
  break if n == 0 && s == 0
  puts dp[n][s]
end

Measured memory_bytes: 6184
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    set<LL> tb;
    IOS;
    int n;
    LL x;
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> x;
        tb.insert(x);
    }
    if((int)tb.size() == n)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
}


Measured memory_bytes: 9600
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x-a)%b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s,t;
  cin>>s>>t;
  long long int ans=0;
  for(long long int i=0; i<s.size(); i++){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3852
import sys
input = sys.stdin.readline
import bisect
import itertools

n,m,k= map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))

a =[0]+ list(itertools.accumulate(a))
b =[0]+ list(itertools.accumulate(b))



ans=0
for i in range(n+1):
    x=k-a[i]
    if x<0:
        break
    else:
        v=bisect.bisect_right(b,x)-1
        ans=max(ans,i+v)
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int parent[100010];
int depth[100010];

int find_root(int x)
{
    if(parent[x] == x) return x;
    else return find_root(parent[x]);
}

void unite(int x, int y)
{
    int x_root = find_root(x);
    int y_root = find_root(y);
    if(depth[x_root] < depth[y_root]){
        parent[x_root] = y_root;
        depth[y_root] = max(depth[y_root], depth[x_root]+1);
    }else{
        parent[y_root] = x_root;
        depth[x_root] = max(depth[y_root]+1, depth[x_root]);
    }
    return;
}

int same(int x, int y)
{
    if(find_root(x) == find_root(y)) return 1;
    else return 0;
}

int main(void)
{
    int n, q;
    cin >> n >> q;
    int query, x, y;

    // init
    rep(i,n){
        parent[i] = i;
        depth[i] = 0;
    }

    // query
    rep(i,q) {
        cin >> query >> x >> y;
        if(query == 0) unite(x, y);
        else if(query == 1) cout << same(x, y) << endl;
    }
    return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(ll, N);
    CIN(ll, M);
    CINS(ll, A, N);
    vector<pair<ll,ll>> CB(M);

    for (int i = 0; i < M; i++) {
        ll b, c;
        cin >> b >> c;
        CB[i] = make_pair(-c, b);
    }
    sort(A.begin(), A.end());
    sort(CB.begin(), CB.end());

    ll indexA = 0;
    for (int i = 0; i < M; i++) {
        ll b, c;
        c = -1 * CB[i].first;
        b = CB[i].second;

        for (int j = 0; j < b; j++) {
            if ( A[indexA] >= c ) break;
            A[indexA] = c;
            indexA++;
        }
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += A[i];
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>

int isBase(char a);

int main() {
	int i, cnt, max;
	char s[11];
	scanf("%s", s);
	cnt = 0;
	max = 0;
	for (i = 0; i < strlen(s); i++) {
		if (isBase(s[i])) cnt++;
		else if (cnt) {
			if (max < cnt) max = cnt;
			cnt = 0;
		}
	}
	if (max < cnt) max = cnt;
	printf("%d", max);
	return 0;
}

int isBase(char a) {
	if (a == 'A' || a == 'G' || a == 'C' || a == 'T') return 1;
	else return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
		 break;}
		if(x<y){
			printf("%d %d\n",x,y);
		}
		else{
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}

Measured memory_bytes: 2576
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */
int main()
{
	int		ans = 0;
	int		N,K;

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

	if (K==1) {
		ans = 0;
	} else {
		ans = N-K ;
	}

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


	return 0;
}


Measured memory_bytes: 128
import sys
S = input()
T = input()

if not ( 1 <= len(S) <= 2*10**5 ): sys.exit()
if not ( len(S) == len(T) ): sys.exit()
if not ( S.islower() and T.islower() ): sys.exit()

count = 0
for I in range(len(S)):
    if S[I] != T[I]:
        count += 1 
print(count)

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

using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);


int main()
{
	IOS

	string e = "keyence";
	string st;
	cin >> st;

	int pref = 0;
	int suf = 0;
	while (st[pref] == e[pref])
	{
		++pref;
		if (pref > 6)
		{
			break;
		}
	}
	while (st[st.size() - 1 - suf] == e[6 - suf])
	{
		++suf;
		if (suf > 6)
		{
			break;
		}
	}
	if(pref + suf >= 7){
		cout << "YES";
	}
	else{
		cout << "NO";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,K;
ll p[1005];
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>K;
rep(i,N) cin>>p[i];
sort(p,p+N);
rep(i,K) ans+=p[i];
cout<<ans<<endl;

}
    


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
const int INF = 3e18;
typedef pair<int, int> PII;
typedef pair<int, PII> PIP;
int n, x[100010], y[100010];
int newx[100010], newy[100010], side[4];

priority_queue<PIP> pq;

struct uf
{
  int parent[200010];

  void reset()
  {
    for(int i = 0; i < n * 2; i++){
      parent[i] = i;
    }
  }

  int top(int x)
  {
    return parent[x] == x ? x : (parent[x] = top(parent[x]));
  }

  bool same(int x, int y)
  {
    return top(x) == top(y);
  }

  void bond(int x, int y)
  {
    if(!same(x, y)){
      parent[top(y)] = top(x);
    }
  }
} uf;

signed main()
{
  scanf("%lld", &n);
  for(int i = 0; i < n; i++){
    scanf("%lld%lld", &x[i], &y[i]);
  }

  for(int i = 0; i < n; i++){
    newx[i] = x[i] + y[i];
    newy[i] = x[i] - y[i];
  }
  
  for(int i = 1; i < n; i++){
    side[0] = newx[i] < newx[side[0]] ? i : side[0];
    side[1] = newx[i] > newx[side[1]] ? i : side[1];
    side[2] = newy[i] < newy[side[2]] ? i : side[2];
    side[3] = newy[i] > newy[side[3]] ? i : side[3];
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 4; j++){
      pq.push(MP(max(abs(newx[i] - newx[side[j]]), abs(newy[i] - newy[side[j]])), MP(side[j], i)));
    }
  }

  uf.reset();
  
  while(!pq.empty()){
    if(!uf.same(pq.top().S.F, pq.top().S.S) && !uf.same(pq.top().S.F + n, pq.top().S.S + n)){
      uf.bond(pq.top().S.F, pq.top().S.S + n);
      uf.bond(pq.top().S.F + n, pq.top().S.S);
      pq.pop();
    }
    else{
      printf("%lld\n", pq.top().F);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 18160
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] values = new int[3][3];

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                values[i][j] = sc.nextInt();
            }
        }

        boolean ok = false;
        for (int i = 0; i < 101; i++) { // a1
            for (int j = 0; j < 101; j++) { // a2
                for (int k = 0; k < 101; k++) { // a3
                    int b1 = values[0][0] - i;
                    int b2 = values[0][1] - i;
                    int b3 = values[0][2] - i;
                    if (b1 < 0 || b2 < 0 || b3 < 0) continue;
                    if ((values[1][0] == j + b1 && values[1][1] == j + b2 && values[1][2] == j + b3) &&
                            (values[2][0] == k + b1 && values[2][1] == k + b2 && values[2][2] == k + b3)) {
                        ok = true;
                    }
                }
            }
        }

        System.out.println(ok ? "Yes" : "No");
    }
}

Measured memory_bytes: 24020
from collections import deque

N,K=map(int,input().split())
mod = 10**9+7
G=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

def bfs(s):
    seen = [0]*N
    prev = [0]*N
    color = [0]*N
    todo = deque()
    seen[s]=1
    todo.append(s)
    color[s]=K
    while todo:
      a = todo.popleft()
      if a == start: count = K-1
      else: count = K-2
      for b in G[a]:
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          prev[b] = a
          color[b] = count %mod
          count -= 1
    return color
  
MAX,start = 0,-1
for i in range(N):
  if len(G[i])>MAX:
    MAX=len(G[i])
    start = i
    
color = bfs(start)
ans = 1
for i in range(N):
  ans *= color[i]
  ans %= mod
  
print(ans)

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

int main() {
    int N;
    cin >> N;
    int t[N],x[N],y[N];
    t[0] = x[0] = y[0] = 0; 
    for(int i = 1; i < N+1; i++) {
        cin >> t[i] >> x[i] >> y[i];
        if( (x[i] + y[i] - t[i]) % 2 != 0 || abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]) > t[i] - t[i-1] ) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
N, K = map(int, input().split())  # 1~Nが出るようなN面のサイコロ, そして得点がKより小さい限りコインを投げる

ans = 0
for i in range(1, N+1):
    cnt = 0

    while K > i:
        i *= 2
        cnt += 1

    if cnt == 0:
        ans += 1
    else:
        ans += 1/(2**cnt)

print(ans/N)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
int main(){
    
    int N,K;
    cin >> N >> K;
    vector<int> H(N);
    
    rep(i,N){
        cin >> H[i];
    }
    
    sort(H.begin(),H.end());
    
    K=min(N,K);
    
    ll ans = 0;
    rep(i,K){
        H.pop_back();
    }
    
        for(int i = 0;i<H.size();i++){
            ans += H[i];
        }
         cout << ans << endl;
    
}



Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
INF = 1<<48

def solve(N: int, S: str):
    b = [1 if S[i] == '#' else 0 for i in range(N)]
    w = [1 if S[i] == '.' else 0 for i in range(N)]

    rb = [0] * (N+1)
    for i in range(N):
        rb[i+1] = rb[i] + b[i]

    rw = [0] * (N+1)
    for i in range(N-1, -1, -1):
        rw[i] = rw[i+1] + w[i]

    ans = INF
    for i in range(N+1):
        ans = min(ans, rb[i]+rw[i])
    
    print(ans)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


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

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

    int n;
    string s;
    cin >> n;
    cin >> s;
    
    vector<int> b(n + 1, 0), w(n + 1, 0);
    
    rep(i, n){
        if(s[i] == '#'){
            b[i + 1] = b[i] + 1;
            w[i + 1] = w[i];
        }else{
            b[i + 1] = b[i];
            w[i + 1] = w[i] + 1;
        }
    }
    int ans = INF;
    
    rep(i, n + 1){
        int a = b[i] + (w[n] - w[i]);
        
        ans = min(ans, a);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2196
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 100000000
typedef pair<int, int> P;
typedef pair<int, P> PP;



//initialization here
//


//
//initialization finish


// your function is here
//


//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int a, b, c, x; cin >> a >> b >> c >> x;
	int cnt = 0;
	rep(i, a + 1)rep(j, b + 1)rep(k, c + 1)if (500 * i + 100 * j + 50 * k == x)cnt++;
	
	Print(cnt);
	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int INF=INT_MAX;
const ld PI=3.1415926535838797323;
const ld E=2.71828183;
const int MOD=1e9+7;
vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
int powMod(int base,int exp,int mod){
    //base^exp %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}

void solve();

int main() {
    //  int t;
    //cin >> t;
    //while(t--)
    solve();
}
void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " "<< b <<"\n";
    
}

Measured memory_bytes: 3556