akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#define ll long long
#define ld long double
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin );
  ll a,b;
  cin>>a>>b;
  cout<<a*b;

  return 0;

}


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

using namespace std;
#define ll long long int

int f(int a, int b, int c){
    return __gcd(a,__gcd(b,c));
}
int main()
{
    int n;
    cin >> n;
    ll s = 0;
    for(int a = 1;a<=n; a++){
        for(int b= 1;b<=n;b++){
            for(int c=1;c<=n;c++){
                s+=f(a,b,c);
            }
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

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

#define pb push_back
#define fr first
#define sc second

const int p[21] = { 3,9,15,21,5,7,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32 };
//const int q[4] = { 13,14,15,16 };

int main(){
	int N;
	ll a[102] = {};
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; i ++){
		scanf("%lld",&a[i]);
	}
	for(int i = N/2+1 ; i <= N ; i ++){
		a[i] = max( a[i] , 0LL );
	}
	
	ll ret = 0;
	for(int s = 0 ; s < (1<<21) ; ++s){
		ll A[102];
		for(int i = 1 ; i <= N ; ++i){
			A[i] = a[i];
		}
		for(int i = 0 ; i < 21 ; ++i){
			if((s>>i)&1){
				for(int j = p[i] ; j <= N ; j += p[i]){
					A[j] = 0;
				}
			}
		}
		
		for(int i = N/2 ; i >= 1 ; --i){
			ll sum = 0;
			for(int j = i ; j <= N ; j += i){
				sum += A[j];
			}
			if(i == 1){
				ret = max( ret , sum );
				break;
			}
			if(sum < 0){
				for(int j = i ; j <= N ; j += i){
					A[j] = 0;
				}
			}
		}
	}
	for(int i = 2 ; i <= N ; i += 2){
		a[i] = 0;
	}
	for(int s = 0 ; s < (1<<6) ; ++s){
		ll A[102];
		for(int i = 1 ; i <= N ; ++i){
			A[i] = a[i];
		}
		for(int i = 0 ; i < 6 ; ++i){
			if((s>>i)&1){
				for(int j = p[i] ; j <= N ; j += p[i]){
					A[j] = 0;
				}
			}
		}
		
		for(int i = N/2 ; i >= 1 ; --i){
			ll sum = 0;
			for(int j = i ; j <= N ; j += i){
				sum += A[j];
			}
			if(i == 1){
				ret = max( ret , sum );
				break;
			}
			if(sum < 0){
				for(int j = i ; j <= N ; j += i){
					A[j] = 0;
				}
			}
		}
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
//☠️_Do_not_copy_from_me_☠️//
#include <bits/stdc++.h>
#define ll/*////////*/long long
#define gcd()/*////////*/___gcd()
#define pi/*////////*/3.1415926536
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//------Enter your code here.------
	int l,r,d,ans=0;cin>>l>>r>>d;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)ans++;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3608
#include <stdio.h>

int main() {
	int N, M, C, A[20][20], B[20], cnt = 0, sum;
	scanf("%d%d%d", &N, &M, &C);
	int i, j;
	for (i = 0; i < M; i++)scanf("%d", &B[i]);
	for (i = 0; i < N; i++) for (j = 0; j < M; j++) scanf("%d", &A[i][j]);
	for (i = 0; i < N; i++) {
		sum = C;
		for (j = 0; j < M; j++) {
			sum += A[i][j] * B[j];
		}
		if (sum > 0)cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, m;
vector<vector<int>> g(5010, vector<int>(5010, 0));

void imos3_add(int a, int b, int x, vector<vector<int>>& g) {
    g[a][b] += 1; g[a][b + 1] -= 1;
    g[a + x + 1][b] -= 1; g[a + x + 2][b + 1] += 1;
    g[a + x + 1][b + x + 2] += 1; g[a + x + 2][b + x + 2] -= 1;
    return ;
}

void imos3_update(vector<vector<int>>& g) {
    for (int i = 0; i < 5005; i++) for (int j = 0; j < 5005; j++) g[i][j + 1] += g[i][j];
    for (int i = 0; i < 5005; i++) for (int j = 0; j < 5005; j++) g[i + 1][j] += g[i][j];
    for (int i = 0; i < 5005; i++) for (int j = 0; j < 5005; j++) g[i + 1][j + 1] += g[i][j];
    return ;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> m;
    rep(i, m) {
        int a, b, x;
        cin >> a >> b >> x;
        imos3_add(a, b, x, g);
    }
    imos3_update(g);
    int ans = 0;
    rep(i, 5005)rep(j, 5005) {
        if (g[i][j] > 0) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

using int64 = long long;

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

  string s, t;
  cin >> s >> t;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) count++;
  }
  cout << count << endl;
}

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

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

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    cout << min(a, k) - max(k - a - b, 0);

    return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, waking = 0, arriving;
  bool flag = false;
  cin >> a >> b >> c;
  arriving = c;
  while (arriving < 3600+c) {
    while (waking < arriving) {
      if (waking <= arriving && arriving <= waking+a) {
        flag = true;
        break;
      }
      waking += a+b;
    }
    if (flag) break;
    arriving += 60;
  }
  if (flag) cout << arriving << el;
  else cout << "-1" << el;
}

Measured memory_bytes: 1164
# C問題

# 難しく考えず、入力された配列の先頭の要素から順に見に行く
# cur_maxという、①最大身長格納変数を用意、②①を更新して行く　この2ステップの考え方が大事
N = int(input())
cur_max = 0
ans = 0
# 配列を入力   
A = list(map(int, input().split()))

for i in A:
    if cur_max > i:
        ans += cur_max - i
# どんどん高いものに更新→max関数で処理
    cur_max = max(i, cur_max)
print(ans)

Measured memory_bytes: 32196
s = list(input())
x = 0
for i in range(len(s)):
  if i%2 == 0 and s[i] != '0':
    x += 1
  elif i%2 ==1 and s[i] != '1':
    x += 1
y = 0
for i in range(len(s)):
  if i%2 == 0 and s[i] != '1':
    y += 1
  elif i%2 ==1 and s[i] != '0':
    y += 1
print(min(x,y))

Measured memory_bytes: 49392
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    string S;
    cin >> S;
    S.erase(S.end() - 3, S.end() - 1);
    for (int i = 0; i < S.size(); i += 2)
    {
        bool flag = true;
        for (int j = 0; j < (S.size() - i) / 2; j++)
        {
            if (S[j] != S[j + (S.size() - i) / 2])
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            cout << S.size() - i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int sum;
vec G,v,seen;

void func(int x,int par){
    seen[x]=0;
    
    if(G[x]==par){
        v.push_back(x);
        v.push_back(par);
        sum++;
        return;
    }
    if(seen[G[x]]!=-1)return;
    func(G[x],x);
    
    return;
}

int main(){
    int n,ans=0;cin>>n;
    const int N=n;
    G.resize(N);
    seen.resize(N,-1);
    mat A(N,vector<int>(N-1));
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            int a;cin>>a;
            a--;
            A[i][j]=a;
        }
    }
    for(int i=0;i<N;i++){
        G[i]=A[i][0];
        A[i].erase(A[i].begin());
    }
    
    //ここから繰り返し
    sum=0;
    while(true){
        for(int i=0;i<N;i++){
            if(seen[i]==-1)
                func(i,-1);
        }

        if(v.empty()){
            cout<<"-1"<<endl;
            return 0;
        }
        
        ans++;
        if(sum==N*(N-1)/2){
            cout<<ans<<endl;
            return 0;
        }
      
        for(int i=0;i<v.size();i++){
            if(!A[v[i]].empty()){
                G[v[i]]=A[v[i]][0];
                A[v[i]].erase(A[v[i]].begin());
            }
            else seen[v[i]]=pow(10,9);
        }
        v.resize(0);
        for(int i=0;i<N;i++)
            seen[i]--;
    }
    return 0;
}

Measured memory_bytes: 4224
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = [[] for i in range(N + 1)]
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            testimonies[i].append((x, y))

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            honest_people = set(honest_people)
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt();
		if(a*b%2 == 1) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

using namespace std;

#define ll long long int
#define MOD 1000000007
#define mt make_tuple
#define eb emplace_back
#define error(args...){string _s = #args; replace(_s.begin(),_s.end(),',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args){cerr<<*it<<" = "<<a<<endl; err(++it,args...);}
ll modPow(ll x,ll n){
	ll r=1;
	while(n){
		if(n&1)r = (r*x)%MOD;
		x = (x*x)%MOD;
		n = (n>>1);
	}
	return r;
}


int main()
{
	ll t,i,j,k,l,n,m;
    cin>>n>>k;
    ll A[n];
    for(i=0;i<n;++i)cin>>A[i];
    ll ans=1e9;
    for(i=0;i<=n-k;++i){
        l=A[i];
        ll r = A[i+k-1];
        ll cost = min(abs(r)+abs(l-r),abs(l)+abs(l-r));
        ans = min(ans,cost);
    }
    cout<<ans;
	return 0;
}


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

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }

  int ans(){
      int tmp=0;
      rep(i,data.size()){
          if(data[i]<0)++tmp;
      }
      return tmp;
  }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        --x;--y;
        uf.unite(x,y);
    }
    cout<<uf.ans()<<endl;
}



Measured memory_bytes: 640
#include<stdio.h>
int main(){
	
	int a,b;
	scanf("%d %d",&a,&b);
	if(-1000<=a && b<=1000){
		if(a<b){
			printf("a < b\n");
		}else if(a>b){
			printf("a > b\n");
		}else if(a==b){
			printf("a == b\n");
		}
	}
	return 0;
		
}

Measured memory_bytes: 1820
fiv = 0
seven = 0
a,b,c = gets.chomp.split(' ').map{|n| n.to_i}


if a == 5 then
  fiv+=1
end

if b == 5 then
  fiv+=1
end

if c == 5
  fiv+=1
end

if a == 7
  seven+=1
end

if b == 7
  seven+=1
end

if c == 7
  seven+=1
end

if seven == 1 && fiv == 2
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cfloat>
#include <cmath>
#include <random>
#include <algorithm>
#define norm(X) ((X) * (X))
using namespace std;
using ll = long long;
    
struct Point {
    ll x, y;
    ll z;
};

int main() {
    ll n;
    Point e[105];
    double ans = 0;
    ll sx[4] = {};
    ll sy[4] = {};

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> e[i].x >> e[i].y;

        e[i].z = 0;
        if (e[i].y > 0) {
            e[i].z |= 2;
        }
        if (e[i].x > 0) {
            e[i].z |= 1;
        }

        sx[e[i].z] += e[i].x;
        sy[e[i].z] += e[i].y;
    }

    mt19937 rnd(7882620);
    ll x, y;

    for (int z = 0; z < 4; z++) {
        
        for (int k = 0; k < 30000; k++) {
            x = sx[z];
            y = sy[z];

            for (int i = 0; i < n; i++) {
                ll zz = 0;
                if (e[i].y > 0) zz |= 2;
                if (e[i].x > 0) zz |= 1;
                e[i].z = (zz == z ? -1 : 1);
            }

            for (int j = 0; j < 300; j++) {
                ll indx = rnd() % n;

                if (e[indx].z != -1) {
                    if (norm(x) + norm(y) < norm(x + e[indx].x) + norm(y + e[indx].y)) {
                        x += e[indx].x;
                        y += e[indx].y;
                        e[indx].z = -1;
                    }
                }
                else {
                    if (norm(x) + norm(y) < norm(x - e[indx].x) + norm(y - e[indx].y)) {
                        x -= e[indx].x;
                        y -= e[indx].y;
                        e[indx].z = 1;
                    }
                }
            }

            ans = max(ans, hypot(x, y));
        }
    }
    
    printf("%.*lf\n", DBL_DIG, ans);

    return 0;
}


Measured memory_bytes: 384
import statistics

n = int(input())
a = input().split()
a = [int(m) for m in a]
x = []

for i in range(1, n + 1):
    x.append(a[i - 1] - i)

x.sort()

y1 = []
y2 = []
c = 0

if n % 2 == 0:
    #statistics.median()
    for i in range(n):
        if i <= int(n / 2) - 1:
            y1.append(x[i])
        else:
            y2.append(x[i])

    sumy1 = sum(y1)
    sumy2 = sum(y2)
    sumar = sumy2 - sumy1
    print(sumar)

w = []
z1 = []
z2 = []
d = 0

if n % 2 != 0:
    #med = x[int((n + 1) / 2)]
    #statistics.median()
    for h in range(1, n + 1):#中央値を排除
        if h != (n + 1) / 2:
            w.append(x[h - 1])
    for i in range(n - 1):#中央値の分をひく
        if i <= int((n - 1) / 2) - 1:#長さをリストのインデックス番号に変換するために１をひく
            z1.append(w[i])
        else:
            z2.append(w[i])
    sumz1 = sum(z1)
    sumz2 = sum(z2)
    sumar = sumz2 - sumz1
    print(sumar)

Measured memory_bytes: 27244
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c,d;
    int x,y;
    cin >> a >> b >> c >> d;
    x = (a+d-1)/d;
    y = (c+b-1)/b;
    if (x >= y)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
}




Measured memory_bytes: 3612
#include<stdio.h>
#define H 500000

int n,A[H+1];

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l,r,x,largest;
  l=left(i);
  r=right(i);
  if(l<=n && A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=n && A[r]>A[largest])
    largest=r;
  if(largest!=i){
    x=A[i];
    A[i]=A[largest];
    A[largest]=x;
    maxHeapify(largest);
  }
}
void buildMaxHeap(){
  int i;
  for(i=n/2;i>=1;i--)
    maxHeapify(i);
}  
int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap();
  for(i=1;i<=n;i++)
    printf(" %d",A[i]);
  printf("\n");    
  



  return 0;
}

Measured memory_bytes: 2552
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
struct S{
  char s[11];
};
int b[10],n,m;
vector<int> a[10],x,y,q,r;
char t[11],u[11];
vector<S> s;
int fi(int p){
  int i,j;
  if(p==n){
    for(i=0;i<m;++i){
      if(q[i]!=x[i]||r[i]!=y[i])
	break;
    }
    if(i==m){
      if(u[0]=='\0')
	copy(t,t+11,u);
      else
	return 1;
    }
  }else{
    for(i=0;i<10;++i){
      if(b[i]){
	for(j=0;j<m;++j){
	  if(0){
	  }else if(s[j].s[p]-'0'==i){
	    ++q[j];
	    if(q[j]>x[j])
	      break;
	  }else if(a[i][j]){
	    ++r[j];
	    if(r[j]>y[j])
	      break;
	  }
	}
	if(j==m){
	  b[i]=0;
	  t[p]='0'+i;
	  if(fi(p+1))
	    return 1;
	  b[i]=-1;
	  --j;
	}
	for(;j>=0;--j){
	  if(0){
	  }else if(s[j].s[p]-'0'==i){
	    --q[j];
	  }else if(a[i][j]){
	    --r[j];
	  }
	}
      }
    }
  }
  return 0;
}
int main(){
  int i,j;
  while(cin>>n>>m,n||m){
    S c;
    s.assign(m,c);
    x.assign(m,0);
    y.assign(m,0);
    for(i=0;i<10;++i)
      a[i].assign(m,0);
    for(i=0;i<m;++i){
      cin>>s[i].s>>x[i]>>y[i];
      for(j=0;j<n;++j)
	a[s[i].s[j]-'0'][i]=-1;
    }
    fill(b,b+10,-1);
    fill(t,t+11,0);
    fill(u,u+11,0);
    q.assign(m,0);
    r.assign(m,0);
    if(fi(0)||u[0]=='\0')
      cout<<"NO"<<endl;
    else
      cout<<u<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 1000020;
const int maxm = 1000020;
const int MOd = 998244353;

int a, q, ar[maxn];
int beg[maxn], en[maxn], cnt;
Lint T[maxn];
vector<int> w[maxn];

void dfs(int n, int back) {
	beg[n] = ++cnt;
	for(int i=0;i<w[n].size();i++)
		if( w[n][i] != back ) dfs( w[n][i], n );
	en[n] = cnt;
}

int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);

    string s;
    scanf("%d %d",&a,&q);
    for(int i=1,j,k;i<a;i++) {
    	scanf("%d %d",&j,&k);
    	w[j].pb( k );
    	w[k].pb( j );
    }
    dfs( 1, 0 );
    for(int i=1,x,y;i<=q;i++) {
    	scanf("%d %d",&x,&y);
    	T[ beg[x] ] += y;
    	T[ en[x]+1 ] -= y;
    }

    for(int i=2;i<=a;i++)
    	T[i] += T[i-1];

    for(int i=1;i<=a;i++)
    	printf("%lld ",T[ beg[i] ]);

    printf("\n");
	return 0;
}


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


int main()
{
	while (true) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y) {
			cout << y << " " << x << endl;
		}
		else {
			cout << x << " " << y << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int64_t i = 0; i < n; ++i)
using namespace std;

int main() {
  string s, t, r = "";
  cin >> s >> t;
  rep(i, s.size()){
    r += s[i];
    if(i < t.size()) r += t[i];
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, X, T = read_values()
    print(((N - 1) // X + 1) * T)


if __name__ == "__main__":
    main()



Measured memory_bytes: 67936
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char x){
    int y;
    if(x=='E'){
      y=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=y;
    }
    if(x=='W'){
      y=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=y;
    }
    if(x=='N'){
      y=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=y;
    }
    if(x=='S'){
      y=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=y;
    }
    if(x=='R'){
        y=s[1];
        s[1]=s[2];
        s[2]=s[4];
        s[4]=s[3];
        s[3]=y;
    }
  }
  int ue() {
    return s[0];
  }
  int migi(){
      return s[2];
  }
  int hidari(){
      return s[3];
  }
  int mae(){
      return s[1];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  int n;
  cin >>n;
  while(n--){
      int a,b;
      cin >> a >>b;
      if(d.migi()==a)d.roll('W');
      if(d.hidari()==a)d.roll('E');
      while(d.ue()!=a)d.roll('N');
      while(d.mae()!=b)d.roll('R');
      cout << d.migi() << endl;
  }
  return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h> 
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=4005;
int n,a[N],c[N],pos[2][N],f[N][N],w[N][N],b[N][N];
int main()
{
	scanf("%d",&n);
	char ch;
	for(int i=1;i<=2*n;i++){
		scanf("%s%d",&ch,&a[i]);
		c[i]= ch=='W' ? 0 : 1;
		pos[c[i]][a[i]]=i;
	}
	for(int i=1;i<=n*2;i++)
	{
		for(int j=0;j<=n;j++)
    	{
    		w[i][j]=w[i-1][j] + (c[i-1]==0&&a[i-1]>j);
    		b[i][j]=b[i-1][j] + (c[i-1]==1&&a[i-1]>j);
//    		cout<<i<<' '<<j<<" w: "<<w[i][j]<<" b: "<<b[i][j]<<endl;
    	}
	}
	  
	clr(f,7); f[0][0]=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			int pw=pos[0][i],pb=pos[1][j];
			if(i) f[i][j]=min(f[i][j],f[i-1][j]+w[pw][i]+b[pw][j]);
			if(j) f[i][j]=min(f[i][j],f[i][j-1]+w[pb][i]+b[pb][j]);
//			cout<<i<<' '<<j<<"  "<<f[i][j]<<endl;
		}
	}
	printf("%d\n",f[n][n]);
	return 0;
}



Measured memory_bytes: 187776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int A,B,C,X;

		try(Scanner sc = new Scanner(System.in)){
			A = sc.nextInt();
			B = sc.nextInt();
			C = sc.nextInt();
			X = sc.nextInt();
		}

		int ans = 0;

		for(int a = 0; a <= A; a++){
			for(int b = 0; b <= B; b++){
				for(int c = 0; c <= C; c++){
					if((500 * a + 100 * b + 50 * c) == X){
						ans++;
					}
				}
			}
		}

		System.out.println(ans);
	}

}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,colors[maxn];
vector<pair<int,int>> g[maxn];

void dfs(int at, int par, int c) {
  colors[at] = c;
  for (auto ed: g[at]) {
    int to = ed.first;
    int wei = ed.second;
    if (to==par) continue;
    dfs(to, at, (c+wei)%2);
  }
}

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

  cin>>n;
  for (int i=0; i<n-1; i++) {
    int u,v,w; cin>>u>>v>>w;
    g[u].push_back({v,w});
    g[v].push_back({u,w});
  }

  dfs(1,-1,0);

  for (int i=1; i<=n; i++) {
    cout<<colors[i]<<'\n';
  }

  return 0;
}


Measured memory_bytes: 30208
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    A = LI()
    counter = Counter(A)

    comsum = 0
    for v in counter.values():
        comsum += v * (v - 1) // 2

    for ai in A:
        tmp = counter[ai]
        now = tmp * (tmp - 1) // 2
        print(comsum - now + (tmp - 1) * (tmp - 2) // 2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 111848
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var two = nextIntArray();
  if(two[1] == 1){
    myout(1);
  }else{
    myout(0);
  }
}

Measured memory_bytes: 31216
h, w = map(int, input().split())
s = [input() for i in range(h)]
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
for i in range(h):
    for j in range(w):
        mine = 0
        for k in range(8):
            if 0 <= i+dy[k] < h and 0 <= j+dx[k] < w and s[i+dy[k]][j+dx[k]] == '#':
                mine += 1
        if s[i][j] == '.':
            s[i] = s[i].replace(".", str(mine), 1)
    print(s[i])

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

int main() {
    int n;cin>>n;
    int a[n];
    ll ans = 0;
    rep(i,n)cin>>a[i];
    
    rep(i,n-1){
        if(a[i+1]<a[i]){
            ans+=(a[i]-a[i+1]);
            a[i+1]=a[i];
        }
    }
    cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> even;
    vector<int> odd;
    rep(i,a.size()){
        if(a[i]%2==0) {
            even.push_back(a[i]);
        }else{
            odd.push_back(a[i]);
        }
    }
    int evenSum=0, oddSum=0;
    rep(i,even.size()) evenSum += even[i];
    rep(i,odd.size()) oddSum += odd[i];
    if((evenSum%2==0 && oddSum%2==0) || (evenSum%2!=0 && oddSum%2!=0)){
        cout << "YES" << endl;
        return 0;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d;
  cin >> s;
  vector<int> dp(n, 0), x(n);
  for (int i = 0; i < n; i++){
    if(s[i] == '#'){
      x[i] = 0;
    }else{
      x[i] = 1;
    }
  }
  int flag = 1;

  if(c > d){
    flag = 0;
    for (int i = b - 2; i < d - 1; i++){
      if(x[i] == x[i+1] && x[i+1] == 1 && x[i+1] == x[i+2]){
        flag = 1;
        break;
      }
    }
    if(flag == 0){
      cout << "No\n";
      return 0;
    }
  }
  for (int i = a - 1; i < max(c, d) - 1; i++){
    if(x[i] == x[i+1] && x[i+1] == 0){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";

  return 0;
}

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

int main() {
  string S;
  cin >> S;
  long long sum=0;
  int s=S.size();
  for(int bit=0;bit<(1<<s-1);bit++){
    sum+=S[s-1]-'0';
    int cnt=0;
    for(int i=s-2;i>=0;i--){
      long long q=S[i]-'0';
      if(bit & (1<<i))cnt++;
      else{cnt=0;}
      for(int j=0;j<cnt;j++){q*=10;}
      sum+=q;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main(){
  double A, B, H, M, ANS;
  cin >> A >> B >> H >> M;
 
  double pi = 3.14159265358979323846264338327950L;
  double Hkaku, Mkaku, Skaku;  
  Hkaku = H * 30 + M * 0.5;
  Mkaku = M * 6;
  Skaku = abs(Hkaku - Mkaku);
 
  /*if (Skaku == 0){
    cout << B - A << endl;
    return 0 ;
  } else if (Skaku == 180){
    cout << B + A << endl;
    return 0 ;
  }*/
 
  //cout << A*A << " " << B*B << " " << 2 * A * B << endl;
  //cout << Hkaku << " " << Mkaku << " " << Skaku << " " << cos(Skaku / 180.0 * pi) << endl;
  
  ANS = (A * A) + (B * B) - 2 * A * B * cos(Skaku / 180.0 * pi);
  printf("%.20lf\n", sqrt(ANS));
  
}

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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };



//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

//================================================================//



//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=2e5+5;


int main(){
    #ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
    fast

    ll n; cin>>n;
    int a[n],dp[n];
    loop(i,n) cin>>a[i];
    dp[0]=0; dp[1]=abs(a[0]-a[1]);
    for(int i=2; i<n; i++){
    	dp[i] = min(abs(a[i]-a[i-1])+dp[i-1], abs(a[i]-a[i-2])+dp[i-2]);
    }
    pt(dp[n-1]);
}


/*


*/





Measured memory_bytes: 4388
#include<stdio.h>
int main()
{
    int A1, A2, A3;
    scanf("%d %d %d", &A1, &A2, &A3);

    if( A1+A2+A3 >= 22) {
        printf("bust\n");
    }

    else{
        printf("win\n");
    }


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    int N, A, B;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}


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

using namespace std;

#define sz(a) ((int)a.size())
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n;
string s;
vector<pair<int, int>> v;
int dp[200005][2];

int main() {
    cin >> n;

    cin >> s;

    int cnt = 0;
    for (int i = 0; i < sz(s); i++) {
        if (!i || s[i] != s[i - 1]) {
            if (i) {
                int cur = (s[i - 1] == '.' ? 1 : 0);
                v.pb(mp(cur, cnt));
            }
            cnt = 1;
        } else cnt++;
    }
    int cur = (s[n - 1] == '.' ? 1 : 0);
    v.pb(mp(cur, cnt));

    vector<pair<int, int> > g;
    for (int i = 1; i < sz(v); i++) {
        if (v[i].fi == 1 && v[i - 1].fi == 0) {
            g.pb(mp(v[i].se, v[i - 1].se));
        }
    }

    if (sz(g) == 0) {
        cout << 0;
        return 0;
    }

    dp[0][0] = g[0].se;
    dp[0][1] = g[0].fi;
    for (int i = 1; i < sz(g); i++) {
        dp[i][0] = dp[i - 1][0] + g[i].se;
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + g[i].fi;
    }

    cout << min(dp[sz(g) - 1][1], dp[sz(g) - 1][0]);

    return 0;
}


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  multimap<string,int> M;
  
  int q;
  cin>>q;

  while(q--){
    int cmd;
    cin>>cmd;
    
    if(cmd == 0){
      string key;
      int x;
      cin>>key>>x;
      M.insert(make_pair(key, x));
    }
    
    if(cmd == 1){
      string key;
      cin>>key;
      for(auto it = M.lower_bound(key); it != M.end() && it->first == key; it++){
	cout<<it->second<<endl;
      }
    }
    
    if(cmd == 2){
      string key;
      cin>>key;
      M.erase(key);
    }

    if(cmd == 3){
      string l,r;
      cin>>l>>r;
      auto start = M.lower_bound(l);
      auto last = M.upper_bound(r);
      assert(l <= r);
      for(auto it=start; it != last; it++) cout<<it->first<<" "<<it->second<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 24836
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		ArrayList<Integer> H = new ArrayList<Integer>();

		for(int i=0; i<N; i++){
			H.add(sc.nextInt());
		}
		H.sort(null);;
		int diff = H.size()-K;
		long sum = 0;

		if(diff>0){
			for(int i=0; i<diff; i++){
				sum += H.get(i);
			}
		}


		System.out.println(sum);
    }
}


Measured memory_bytes: 64868
#include <iostream>

using namespace std;

void gcd_lcm(int, int);

int main() {

	int a, b;

	while(cin >> a >> b) {
		gcd_lcm(a, b);
	}

}

void gcd_lcm(int a, int b) {
	int i=2, gcd=1;
	if(a<b) {
		int t=a;
		a=b;
		b=t;
	}

	while(i<=a) {
		if(a%i==0&&b%i==0) {
			gcd*=i;
			a/=i;
			b/=i;
			continue;
		}
		i++;
	}
	
	cout << gcd << " " << a*b*gcd << endl;
}

Measured memory_bytes: 1160
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    red = []
    for _ in range(n):
        red.append(nl())
    blue = []
    for _ in range(n):
        blue.append(nl())

    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort(key=lambda x:x[0], reverse=True)

    #print(red, blue)
    ans = 0
    for _ in range(n):
        mn = blue.pop()
        for i in range(len(red)):
            if mn[0] > red[i][0] and mn[1] > red[i][1]:
                #print(mn, red.pop(i), 'pair')
                red.pop(i)
                ans += 1
                break

    print(ans)
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 3696
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=2*305;
const int mod=1e9+7;
ll dp[maxn][maxn][maxn];//从后往前 这个之后弄到了多少个 一个确定了的多少个 一个都没确定多少个
int ty[maxn];
int a[maxn];
int main(){
    ios::sync_with_stdio(0);
    int n;cin>>n;int unknow=0;
    rep(i,1,n){
        int x,y;cin>>x>>y;if(x>y)swap(x,y);
        if(y==-1)unknow++;//都没定
        else if(x==-1)ty[y]=1;//缺一个
        else ty[x]=ty[y]=2;//定了
    }
    dp[2*n][0][0]=1;int ava=0;
    for(int i=2*n;i>=1;i--){
        for(int j=0;j<=ava;j++){
            for(int k=0;j+k<=ava;k++)if(dp[i][j][k]){
                if(ty[i]==2){
                    dp[i-1][j][k]+=dp[i][j][k];dp[i-1][j][k]%=mod;
                }
                else if(ty[i]==1){
                    dp[i-1][j+1][k]+=dp[i][j][k];dp[i-1][j+1][k]%=mod;
                    if(k){dp[i-1][j][k-1]+=dp[i][j][k];dp[i-1][j][k-1]%=mod;}
                }
                else{
                    dp[i-1][j][k+1]+=dp[i][j][k];dp[i-1][j][k+1]%=mod;
                    if(j){dp[i-1][j-1][k]+=1ll*j*dp[i][j][k]%mod;dp[i-1][j-1][k]%=mod;}
                    if(k){dp[i-1][j][k-1]+=dp[i][j][k];dp[i-1][j][k-1]%=mod;}
                }
            }
        }
        if(ty[i]!=2)ava++;//非2的有多少个
    }
    ll ans=dp[0][0][0];
    rep(i,1,unknow)ans=ans*i%mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 408572
#include <iostream>
#include <string.h>

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

	char money_type[4];
	double sum;
	double num;

	for (int i = 0; i < n; i++) {
		std::cin >> num >> money_type;
		if (strcmp(money_type, "JPY") == 0)
			sum = sum + num;
		else
			sum = sum + num * 380000;
	}

	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, dp[5007][5007], tmp[5007], g[5007], sz[5007];
vector<int>e[5007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c<'0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int dfs(int w, int f)
{
	dp[w][1] = sz[w] = 1;
	for (int i = 0, l = e[w].size(); i < l; i++)
		if (e[w][i] != f)
		{
			dfs(e[w][i], w);
			memset(tmp, 0, sizeof tmp);
			for (int j = 1; j <= sz[w]; j++)
				for (int k = 0; k <= sz[e[w][i]]; k++)
					tmp[j + k] = (tmp[j + k] + 1LL * dp[w][j] * dp[e[w][i]][k] % mod) % mod;
			memcpy(dp[w], tmp, sizeof dp[w]);
			sz[w] += sz[e[w][i]];
		}
	for (int i = 2; i <= sz[w]; i += 2)
		dp[w][0] = (dp[w][0] - 1LL * dp[w][i] * g[i] % mod + mod) % mod;
	return 0;
}
int main()
{
	n = read();
	for (int i = 2; i <= n; i++)
	{
		int a = read(), b = read();
		e[a].push_back(b);
		e[b].push_back(a);
	}
	g[0] = 1;
	for (int i = 2; i <= n; i += 2)
		g[i] = 1LL * g[i - 2] * (i - 1) % mod;
	dfs(1, 0);
	cout << (mod - dp[1][0]) % mod << endl;
	return 0;
}

Measured memory_bytes: 98816
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }
int main(){
  llong A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  if(2 * C >= A + B){
    cout << A * X + B * Y << endl;
    return 0;
  }else if(2 * C > A && 2 * C > B){
    if(X > Y){
      cout << 2 * C * Y + A * (X-Y) << endl;
      return 0;
    }else{
      cout << 2 * C * X + B * (Y-X) << endl;
      return 0;
    }
  }else if(2 * C < min(A,B)){
    cout << 2 * C * max(X,Y) << endl;
    return 0;
  }else{
    if(X>Y && A>B){
      cout << 2 * C * X << endl;
      return 0;
    }else if(X<=Y && A<=Y){
      cout << 2 * C * Y << endl;
      return 0;
    }else if(X > Y){
      cout << 2 * C * Y + A * (X-Y) << endl;
      return 0;
    }else{
      cout << 2 * C * X + B * (Y-X) << endl;
      return 0;
    }
  }
}

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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

using ll = long long;
const ll MOD = 1e9+7;

map<ll, ll> m;

ll solve(ll n)
{
	if(m[n]) return m[n];
	return m[n] = (solve(n/2) + solve((n-1)/2) + solve((n-2)/2)) % MOD;
}

int main()
{
	ll n;
	cin >> n;
	m[0] = 1;
	m[1] = 2;
	
	cout << solve(n);
}


Measured memory_bytes: 3596
import sys
input = sys.stdin.readline

n, m, x = [int(x) for x in input().split()]
c = []
a = []
for _ in range(n):
    c_, *a_ = [int(x) for x in input().split()]
    c.append(c_)
    a.append(a_)
ans = float("inf")
for i in range(2**n):
    i_bin = bin(i)[2:].zfill(n)
    ans_ = 0
    a_ = [0]*m
    for j in range(n):
        if i_bin[j] == "1":
            ans_ += c[j]
            for k in range(m):
                a_[k] += a[j][k]
    flag = 1
    for k in range(m):
        if a_[k] < x:
            flag = 0
            break
    if flag:
        ans = min(ans, ans_)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68832
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;
int store[100001];
int point[10001];
long long int ans[10001];
int abs(int x){
	if(x>0) return x;
	else return x*-1;
}

int main(){
	lli d;
	int n,m;
	while(cin >> d&&d){
		cin >> n >> m;
		store[0]=0;
		for(int i=1; i<n; ++i){
			cin >> store[i];
		}
		for(int i=0; i<m; ++i){
			cin >> point[i];
		}
		for(int i=0; i<m; ++i){
			ans[i]=INF;
		}
		sort(store,store+n);
		for(int i=0; i<m; ++i){
			int up=n,down=0;
			int count=0;
			/*for(int j=0; j<n; ++j){
				cout << store[j] << "\n";
			}*/
			//cout << "\n";
			while(1){
				int mid=(up+down)/2.0;
				if(ans[i]>abs(point[i]-store[mid])) ans[i]=abs(point[i]-store[mid]);
				if(count==5000) {
					break;
				}
				if(store[mid]>point[i]){
					up=mid;
				} else {
					down=mid;
				}
				++count;
			}
			if(d-point[i]<ans[i]) ans[i]=d-point[i];
			//cout << ans[i] << "\n";
		}
		long long int Ans=0;
		for(int i=0; i<m; ++i){
			Ans+=ans[i];
		}
		cout << Ans << "\n";
	}
}

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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define fst first
#define scd second

int main()
{
    int N; cin >> N;
    vector<int> L(2*N);
    rep(i, 2*N) cin>>L[i];
    sort(begin(L),end(L),greater<int>());

    int sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += L[i * 2 + 1];
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A >= 13) cout << B << endl;
	else if (A >= 6 && A <= 12) cout << B / 2 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 3556