akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<P>>;

int main(){
    int N, Q, K;
    cin >> N;
    Graph G(N);
    rep(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(P(b, c));
        G[b].push_back(P(a, c));
    }
    cin >> Q >> K;
    K--;
    vector<ll> dist(N, -1);
    queue<int> q;
    dist[K] = 0;
    q.push(K);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (P nv: G[v]) {
            if (dist[nv.first] != -1) continue;
            dist[nv.first] = dist[v] + nv.second;
            q.push(nv.first);
        }
    }
    vector<int> x(Q), y(Q);
    rep(i, Q) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    rep(i, Q) {
        cout << dist[x[i]] + dist[y[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 9588
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
void sol(void)
{
ll d;
cin>>a>>b>>c>>d;
ll calc=-INF;
if(a<=0 && c<=0)
{
    calc=max(a*c,calc);
}
if(b>=0 && d>=0)
{
  calc=max(calc,b*d);  
}
if((a<=0 && b>=0 )|| (c<=0 && d>=0))
{
    calc=max(0,calc);
}
calc=max(b*c,max(a*d,calc));
cout<<calc;
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    int A,B,C,D,n;
    cin>>A>>B>>C>>D>>n;
    int s=min(A*8,min(B*4,min(C*2,D)));
    long long ans=1LL*n/2*s;
    if(n&1) ans+=min(A*4,min(B*2,C));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

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

LL a[100005];

int main()
{
	int n;
	LL k;
	LL g;
	scanf("%d %lld", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}

	g = a[1];
	for (int i = 1; i <= n; i++) {
		g = gcd(g, a[i]);
	}

	int flag = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] >= k && ((a[i] - k) % g == 0))
			flag = 1;
	}

	if (flag) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int X, Y;
  cin >> X >> Y;
  rep(turu, 200)
  {
    int restX = X - turu;
    int restY = Y - (2 * turu);
    if (restX < 0 || restY < 0)
      continue;
    if (restX * 4 == restY)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N=3030;
const ll mod =1e9+7;
ll dp[N],sum[N],n;
string s;

void add_self(ll &a, ll b){a+=b;if(a>=mod)a-=mod;}
void sub_self(ll &a, ll b){a-=b;if(a<0)a+=mod;}

int main()
{
    ios_base::sync_with_stdio(false);

    cin>>n>>s;
    dp[0]=sum[0]=1;

    for(int k=1;k<n;k++)
	{
		forn(i,k+1)
		{
			dp[i]=0;
			if(s[k-1]=='<'){if(i!=0)dp[i]=sum[i-1];}
			else {dp[i]=sum[k-1];if(i!=0)sub_self(dp[i],sum[i-1]);}
		}
		forn(i,n){sum[i]=dp[i];if(i!=0)add_self(sum[i],sum[i-1]);}
	}
    ll ans=0;
    forn(i,n)add_self(ans,dp[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int flag1=0,flag2=0;
    string s;
    cin>>s;
    if(s[0]=='A'||s[1]=='A'||s[2]=='A')
    {
        flag1 = 1;
    }
    if(s[0]=='B'||s[1]=='B'||s[2]=='B')
    {
        flag2 = 1;
    }
    if(flag1&&flag2)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll r=0,g=0,b=0;
    for(auto c:s){
        if(c=='R')r++;
        else if(c=='G')g++;
        else b++;
    }
    ll all=r*g*b;
    ll sub=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j])continue;
            int k=2*j-i;
            if(k>=n||s[k]==s[i]||s[k]==s[j])continue;
            sub++;
        }
    }
    cout<<all-sub<<endl;
    return 0;
    // int n;
    // cin>>n:
    // string s;
    // cin>>s;
    // char tmp;
    // int cnt=0;
    // int diff;
    // int now=0;
    // tmp=s[now];
    // for(int i=1;i<n-3;i++){
    //     if(tmp!=s[i]){
    //         diff=i-now;
    //         for(int j=i+1;j<n;j++){
    //             if(s[i]!=s[j]){
    //                 if(j-i==diff)continue;
    //                 else cnt++;
    //             }
    //         }
    //     }
    // }
    // return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  cout<<max(max(a+a-1,b+b-1),a+b)<<endl;

  return 0;
}


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


int main()
{
    // cout << "A.cpp" << endl;

    char S[4];
    char T[4];

    // 入力
    scanf("%s", S);
    // cout << "----S----" << endl;
    // cout << S << endl;
    scanf("%s", T);
    // cout << "----T----" << endl;
    // cout << T << endl;

    // 結果
    int sameCount = 0;

    // チェック
    for( int count=0; count < 3; count++ ) {
        if( S[count] == T[count] ) {
            sameCount++;
        }
    }
    // cout << "----Result----" << endl;
    cout << sameCount << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()

# (鍵の購入コスト, 開けられる宝箱)
keys = [None] * M
for i in range(M):
    c, _ = MAP()
    # どの宝箱を開けられるのかをbitで持っておく
    s = 0
    for a in [a-1 for a in LIST()]:
        s += 1 << a
    keys[i] = (c, s)

# dp[i][j] := i個目の鍵まで見て、集合jの宝箱を開けるための最小コスト
dp = list2d(M+1, 1<<N, INF)
dp[0][0] = 0
for i in range(M):
    # 今回の鍵で開けられる宝箱の集合s
    s = keys[i][1]
    c = keys[i][0]
    for j in range(1<<N):
        # 今回の鍵を買わない遷移
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if dp[i][j] != INF:
            m = j | s
            # 買う遷移：遷移元の開けられる宝箱の集合j | 今回の鍵で開けられる宝箱の集合s
            dp[i+1][m] = min(dp[i+1][m], dp[i][j]+c)
ans = dp[M][-1]

if ans != INF:
    print(ans)
else:
    print(-1)


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

// input
int N, K;

vector<int> w;


void input() {
    cin >> N >> K;
}


int main() {
    input();
    w = vector<int>(K, 0);
    rep(i, N) w[(i + 1) % K]++;
    ll ans = pow(w[0], 3);
    if (K % 2 == 0) {
        ans += pow(w[K / 2], 3);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
 
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

/*
	<<XORの性質>>
    n^n=0 ・・・自明
    n^(n+1)=1　・・・ビット差１なので
    F(A,B)=F(0,A-1)^F(0,B)より
    F(0,n)のみ求めれば良い
    
    F(0,6)=0^1^2^3^4^5^6
    =(0^1)^(2^3)^(4^5)^6
    =1^1^1^6
*/

ll f(ll n)
{
  ll ret;
  if (n%2==0) ret = n;
  else ret = 0;
  
  ll num = (n+1)/2;
  if (num%2==0) ret = ret^0;
  else ret = ret^1;
  return (ret);
}

int main()
{
  ll A,B;cin>>A>>B;
  ll a = f(A-1);
  ll b = f(B);
  ll ans = a^b;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
	int h1, h2, m1, m2, k;
	std::cin >> h1 >> m1 >> h2 >> m2 >> k;

	int term = (h2-h1)*60 + m2-m1;
	term -= k;
	std::cout << term << std::endl;
	return 0;
}

Measured memory_bytes: 3628
#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;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll powmod(ll n,ll k){
    n %= mod;
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

ll gcd(ll x,ll y){
    return y?gcd(y,x%y):x;
}
int main(){
    ll h,w,t;
    cin>>h>>w>>t;
    ll g = gcd(h,t);
    ll mul = g;
    h/=g;
    g = gcd(w,t);
    mul *= g;
    w/=g;
    ll ans = 1 + (powmod(2,h)-1) + (powmod(2,w)-1) + (powmod(2,gcd(h,w))-2);
    cout<<powmod(ans,mul)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.io.*;


public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        HashMap<Integer, Boolean> m = new HashMap<>();
        for(int i = 1; i < 10000; i++) {
            m.put(i * i, true);
        }
        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                int tmp = 0;
                for(int k = 0; k < d; k++) {
                    tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                if(m.containsKey(tmp)) ans++;
            }
        }
        System.out.println(ans);
    } 
}

Measured memory_bytes: 22868
from sys import stdin
import numpy as np


############################################

# read data for n sequences.
temp = stdin.readline().split()
N, K = np.asarray(temp).astype(int)

# K==1の場合
if K == 1:
    print(0)
    
elif N <= K:
    a = np.abs(N-K)
    if a < N:
        print(a)
    else:
        print(N)
else:
    rem = N%K
    print(np.abs(rem - K))


Measured memory_bytes: 13644
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
#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__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  int n,m; cin >> n >> m;
  UnionFind uf(n);
  rep(i,m) {
    int a,b; cin >> a >> b;
    --a,--b;
    uf.unite(a,b);
  }
  set<int> z;
  rep(i,n) {
    int r = uf.root(i);
    z.insert(r);
  }
  int s = z.size();
  cout << s-1 << endl;
}


Measured memory_bytes: 7516
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	s := readString()

	codeList := make(map[int]int, 0)
	for i := 0; i <= 999; i++ {
		num := fmt.Sprintf("%03d", i)
		k := 0
		for j := 0; j < n; j++ {
			if int(s[j]-'0') == int(num[k]-'0') {
				k++
				if k == 3 {
					codeList[i]++
					break
				}
			}
		}

	}
	fmt.Println(len(codeList))
}


Measured memory_bytes: 896
// G - Longest Path
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int in(){int x;cin>>x;return x;}

#define VMAX 100000
vvi V(VMAX);
vi D(VMAX,-1);

int dfs(int p){
	if(D[p]>-1 || V[p].size()<1) return D[p];
	int a=0; for(int c:V[p]) a = max(a, dfs(c)+1);
	return D[p] = a;
}

int main(){
	int N,M; cin>>N>>M;
	while(M--) V[in()-1].push_back(in()-1);
	int a = 0; while(N--) a = max(a, dfs(N)+1);
	cout<< a <<endl;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    int a,b;cin >> a >> b;
    for(int i=1;i<=1250;i++){
        if(int(i*0.08) == a && int(i*0.1) == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
s = (input())

l=0
r=0
g=0
for x in range(len(s)-1) :
        if(s[x] == '<') :
                l+=1
        else :
                r+=1
                if(s[x+1] == '<') :
                        if(l>r) :
                            for ll in range(1,l+1) :
                                    g += ll
                            for rr in range(1,r) :
                                    g += rr
                        else :
                            for ll in range(1,l) :
                                    g += ll
                            for rr in range(1,r+1) :
                                    g += rr
                        l=0
                        r=0

if(s[len(s)-1] == '<') :
        l+=1
else :
        r+=1

if(l>r) :
        for ll in range(1,l+1) :
                g += ll
        for rr in range(1,r) :
                g += rr
else :
        for ll in range(1,l) :
                g += ll
        for rr in range(1,r+1) :
                g += rr


print(g)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  cout<<n/3<<endl;
  return 0 ;
}


Measured memory_bytes: 256
n=int(input())
A=[]
for i in range(n):
  for _ in range(int(input())):
    x,y=map(int,input().split())
    A+=[(i,x-1,y)]
print(max(sum(map(int,bin(i)[2:]))*all(i>>j&1<1 or i>>x&1==y for j,x,y in A) for i in range(2**n)))

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

int main() {
    long h, w;
    cin >> h >> w;
    long ch, cw;
    cin >> ch >> cw;
    long dh, dw;
    cin >> dh >> dw;
    ch--; cw--; dh--; dw--;
    string s;
    vector<string> grid;
    for (long i=0; i<h; i++) {
        cin >> s;
        grid.push_back(s);
    }
    vector<long> drow(w,1000000);
    vector<vector<long>> dists(h,drow);
    priority_queue<pair<long,pair<long,long>>> moves;
    moves.push(make_pair(0,make_pair(ch,cw)));
    while (moves.size()>0) {
        pair<long,pair<long,long>> curr = moves.top();
        moves.pop();
        long x = curr.second.first;
        long y = curr.second.second;
        long c = curr.first;
        if (x<0 || x>=h || y<0 || y>=w) continue;
        if (-c>=dists[x][y]) continue;
        if (grid[x][y]=='#') continue;
        dists[x][y] = -c;
        if (x-1>=0 && -c<dists[x-1][y] && grid[x-1][y]!='#') moves.push(make_pair(c,make_pair(x-1,y)));
        if (y-1>=0 && -c<dists[x][y-1] && grid[x][y-1]!='#') moves.push(make_pair(c,make_pair(x,y-1)));
        if (x+1<h && -c<dists[x+1][y] && grid[x+1][y]!='#') moves.push(make_pair(c,make_pair(x+1,y)));
        if (y+1<w && -c<dists[x][y+1] && grid[x][y+1]!='#') moves.push(make_pair(c,make_pair(x,y+1)));
        for (long i=-2; i<=2; i++) for (long j=-2; j<=2; j++) {
            if (x+i>=0 && x+i<h && y+j>=0 && y+j<w && -c<dists[x+i][y+j] && grid[x+i][y+j]!='#') moves.push(make_pair(c-1,make_pair(x+i,y+j)));
        }
    }
    if (dists[dh][dw]==1000000) cout << -1;
    else cout << dists[dh][dw];
    return 0;
}


Measured memory_bytes: 15184
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	register int x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200];int tt;
inline void print(register int x,register char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
const int maxn=2e6+100;
const int inf=1234567890; 
int t[maxn<<2];
void pushup(int o){
	t[o]=min(t[o<<1],t[o<<1|1]);
	return;
}
void build(int o,int l,int r){
    if(l==r){
    	t[o]=inf;
    	return; 
	}
    int mid=l+r>>1;
    build(o<<1,l,mid);
    build(o<<1|1,mid+1,r);
    pushup(o);
    return;
}
void change(int o,int l,int r,int q,int v){
    if(l==r){
		t[o]=v;
		return;
	}
	int mid=l+r>>1;
    if(q<=mid) change(o<<1,l,mid,q,v);
    else change(o<<1|1,mid+1,r,q,v);
    pushup(o);
    return;
}
int query(int o,int l,int r,int ql,int qr){
    if(ql<=l&&r<=qr){
    	return t[o];
	}
	int mid=l+r>>1,res=inf;
    if(ql<=mid) res=min(res,query(o<<1,l,mid,ql,qr));
    if(qr>mid) res=min(res,query(o<<1|1,mid+1,r,ql,qr));
    return res;
}
struct edge{
	int to,nxt;
}e[maxn<<1];int h[maxn],cnt,n,in[maxn],k;
void add(int x,int y){
	e[++cnt].to=y;
	e[cnt].nxt=h[x];
	in[y]++;
	h[x]=cnt;
	return;
}
priority_queue<int>q;
int a[maxn],b[maxn],tot,p[maxn];
void topo(){
    for(int i=1;i<=n;i++)
		if(!in[i])q.push(-i);
    while(!q.empty()){
        int u=-q.top();q.pop();
		b[++tot]=u;
        for(int i=h[u];i;i=e[i].nxt){
        	int v=e[i].to;
			in[v]--;
        	if(!in[v])q.push(-v);
		}
    }
    return;
}
signed main(){
	n=read();k=read();
    for(int i=1;i<=n;i++){
		a[read()]=i;
	}
    build(1,1,n);
    for(int i=n;i>=1;i--){
        int x=query(1,1,n,max(1,a[i]-k+1),a[i]);
        if(x>=1&&x<=n)add(a[i],a[x]);
        x=query(1,1,n,a[i],min(n,a[i]+k-1));
        if(x>=1&&x<=n)add(a[i],a[x]);
        change(1,1,n,a[i],i);
    }
    topo();
    for(int i=1;i<=n;i++)
		p[b[i]]=i;
    for(int i=1;i<=n;i++)print(p[i]);
	return 0;
}


Measured memory_bytes: 36604
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;

    int cnt = 0, c = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if(S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') c++;
        else{
            if(cnt < c) cnt = c;
            c = 0;
        }
        if(i == S.size()-1){
            if(cnt < c) cnt = c;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 1000000007;
vel par;
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; ans %= p; }
	return ans;
}
int root1(int ser, vel &path) {
	if (par[ser] == -1) {
		for (int i = 0; i < path.size(); i++) {
			par[path[i]] = ser;
		}
		return ser;
	}
	path.push_back(ser);
	return root1(par[ser], path);
}
int root(int ser) {
	vel emp(0);
	return root1(ser, emp);
}
bool uni(pin a) {
	int x = root(a.first);
	int y = root(a.second);
	if (x != y) {
		par[y] = x;
	}
	return (x != y);
}
signed main() {
	int n, m; cin >> n >> m;
	int x; cin >> x;
	V<pair<int, pin>> way(m);
	rep(i, m) {
		int u, v; cin >> u >> v; u--; v--;
		int w1; cin >> w1;
		way[i] = mkp(w1, mkp(u, v));
	}
	V<V<pin>> n_way(n,V<pin>(0));
	sor(way);
	int sum = 0;
	par = vel(n, -1);
	rep(i, m) {
		pin pair1 = way[i].second;
		if (uni(pair1)) {
			int w1 = way[i].first;
			sum += w1;
			int st = pair1.first; int to = pair1.second;
			n_way[st].push_back(mkp(w1, to));
			n_way[to].push_back(mkp(w1, st));
		}
	}
	int is_same = 0;
	int must_dif = 0;
	int any = 0;
	rep(i, m) {
		pin wy = way[i].second;
		int st = wy.first;
		queue<int> q;
		q.push(st);
		V<bool> seen(n, false); seen[st] = true;
		vel ans(n, 0);
		bool fl = true;
		while (fl) {
			int st1 = q.front(); q.pop();
			rep(j, n_way[st1].size()) {
				int to = n_way[st1][j].second;
				if (!seen[to]) {
					seen[to] = true;
					q.push(to);
					ans[to] = max(ans[st1], n_way[st1][j].first);
					if (to == wy.second) { fl = false; break; }
				}
			}
		}
		int val = sum + way[i].first - ans[wy.second];
		if (val < x) { is_same++; }
		else  if (val == x) { must_dif++; }
		else { any++; }
	}
	if (must_dif == 0) { cout << 0 << endl; return 0; }
	if (is_same == 0) {
		int ans = ru(2, any)*(ru(2, must_dif) + p - 2); cout << ans % p << endl;
	}
	else {
		int ans = ru(2, any + 1)*(ru(2, must_dif) + p - 1); ans %= p;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import numpy as np
K, N = map(int, input().split())
A = np.array(list(map(int, input().split())))
diff = A[1:] - A[:-1]
diff = np.append(diff, K + A[0] - A[-1])
# print('diff', diff)
ans = diff.sum() - diff.max()
print(ans)


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

char n[2000005];
long long len,sum=0;

int main()
{
	scanf("%s",n);
	len=strlen(n);
	if(n[0]=='0')
	{
		printf("Yes");
		return 0;
	}
	for(long long i=0;i<len;i++)
	{
		sum+=n[i]-'0';
	}
	if(sum%9)
	{
		printf("No");
	}
	else
	{
		printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 3940
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int x = int.Parse(Console.ReadLine());
      int a = int.Parse(Console.ReadLine());
      int b = int.Parse(Console.ReadLine());
      Console.WriteLine(x-a-((x-a)/b)*b);
    }
}


Measured memory_bytes: 27284
#include <cstdio>
#include <string>
#include <stack>
#include <iostream>
using namespace std;

string S[3];

int main()
{
    for(int i = 0 ; i < 3 ; i++ )
        cin>>S[i];
    cout<<S[0][0]<<S[1][0]<<S[2][0]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<vector<int>> v(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        while (k--) {
            int t; cin >> t;
            v[u-1][t-1] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) cout << " ";
            cout << v[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod2;
        }
        now*=now;
        now%=mod2;
        k/=2;
    }
    return ret;
}

int main(){
    ll n;cin>>n;
    ll sum=0;
    ll a[n];
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll ans=beki(3,n);
    ll dp1[n+1][sum/2+1];
    memset(dp1,0,sizeof dp1);
    dp1[0][0]=1;
    rep(i,0,n){
        rep(j,0,sum/2+1){
            dp1[i+1][j]+=dp1[i][j];
            dp1[i+1][j]%=mod2;
            if(j+a[i]<=sum/2){
                dp1[i+1][j+a[i]]+=dp1[i][j]*2;
                dp1[i+1][j+a[i]]%=mod2;
            }
        }
    }
    ll ss=0;
    rep(i,0,sum/2+1){
        ss+=dp1[n][i];
        ss%=mod2;
    }
    ll ss2=0;
    if(sum%2==0){
        ll dp2[n+1][sum/2+1];
        memset(dp2,0,sizeof dp2);
        dp2[0][0]=1;
        rep(i,0,n){
            rep(j,0,sum/2+1){
                dp2[i+1][j]+=dp2[i][j];
                dp2[i+1][j]%=mod2;
                if(j+a[i]<=sum/2){
                    dp2[i+1][j+a[i]]+=dp2[i][j];
                    dp2[i+1][j+a[i]]%=mod2;
                }
            }
        }
        ss2=dp2[n][sum/2];
        ss+=-ss2+mod2;
        ss%=mod2;
    }
    ss*=3;
    ss%=mod2;
    ss2*=3;
    ss2%=mod2;
    ans-=ss;
    ans+=mod2+mod2;
    ans%=mod2;
    cout<<ans<<endl;
    //cout<<ss<<" "<<ss2<<endl;
}


Measured memory_bytes: 211200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll lcm(ll a, ll b) { return a / __gcd(a, b) * b;}

int main() {
  // X = Ak/2 * (2*p + 1)
  // それぞれのAkが2で割れる回数が同じでなければならない
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  int time = 0; // 2で割れる回数
  while (A[0] % 2 == 0) {
    time++;
    A[0] /= 2;
  }
  rep(j, time) {
    for (int i = 1; i < N; i++) {
      if (A[i] & 1) {
        cout << 0 << '\n';
        return 0;
      } else {
        A[i] /= 2;
      }
    }
  }
  rep(i, N) {
    if (A[i] % 2 == 0) {
      cout << 0 << '\n';
      return 0;
    }
  }
  ll l = 1;
  rep(i, N) {
    l = lcm(l, (ll)A[i]);
  }
  ll coef = 1;
  rep(i, time-1) coef *= 2;
  ll ans = M / l / coef - (M / 2 / l / coef);
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        VI A(n);
        FOR(i,0,n)
            cin >> A[i];
        double ans = 0;
        FOR(i,0,n) {
            ans += 1.0/A[i];
        }
        ans = 1.0/ans;
        printf("%.6f\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
        int H = sc.nextInt(), W = sc.nextInt();
        if(H == 0 && W == 0) break;
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 33072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    string S;
    cin>>S;
    int N=S.size();
    int n=0,e=0,w=0,s=0;
    rep(i,N) {
        if(S[i]=='N') n++;
        else if(S[i]=='E') e++;
        else if(S[i]=='W') w++;
        else if(S[i]=='S') s++;
    }
    bool ok=true;
    if(n>0&&s==0) ok=false;
    else if(n==0&&s>0) ok=false;
    else if(w==0&&e>0) ok=false;
    else if(w>0&&e==0) ok=false;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N){
    cout << (N % 1000 == 0 ? 0 : (1000 - N%1000)) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll a,b,c,k;
int main(){
	ios::sync_with_stdio(0);
	cin>>a>>b>>c>>k;
	if(k<a){
		cout<<k;
		re 0;
	}
	k-=a;
	k=max(0ll,k-b);
	cout<<a-k;
	re 0;
}

Measured memory_bytes: 3648
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for x in range(N)]
X.append(X[0])

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        a = 0
        for k in range(D):
            a += abs(X[i][k] - X[j][k]) ** 2
        if math.sqrt(a).is_integer():
            cnt += 1

print(cnt)

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

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int sum = 0;
    rep(i, n) sum += a[i];
    int ans = INF, l = 0;
    rep(i, n)
    {
        l += a[i];
        int r = sum - l;
        ans = min(ans, max(r - l, l - r));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      k: u64,
      abs: [((u64, u64)); n],
    }

    let mut xs = vec![];
    xs.push(k);
    let d = 64 - k.leading_zeros();
    for i in (0..d).rev() {
        if k & (1 << i) > 0 {
            let mask = (1 << i) - 1;
            let bit = (k - (1 << i)) | mask;
            xs.push(bit);
        }
    }

    let mut ans = 0;
    for x in xs {
        let mut sumb = 0;
        for &(a, b) in abs.iter() {
            if a|x == x {
                sumb += b;
            }
        }
        ans = max(ans, sumb);
    }
    puts!("{}\n", ans);
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

class Edge;
class Node {
 public:
  vector<Edge *> con_edges;
};

class Edge {
 public:
  Node *a;
  Node *b;
  int color;

  Node *GetOther(Node *n) {
    if (n != a) return a;
    return b;
  }
};

Edge *EDGE_NIL;

void Paint(Node *node, Edge *parent_edge = EDGE_NIL) {
  int color = 1;
  FOR(i, 0, node->con_edges.size()) {
    Edge *edge = node->con_edges[i];
    if (edge == parent_edge) {
      continue;
    }

    // color
    if (parent_edge != EDGE_NIL) {
      if (parent_edge->color == color) color += 1;
    }
    edge->color = color;
    color++;

    Node *child = edge->GetOther(node);
    Paint(child, edge);
  }
}

int main() {
  int n;
  cin >> n;
  vector<Node> nodes(n);
  vector<Edge> edges(n - 1);
  FOR(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i].a = &nodes[a - 1];
    edges[i].b = &nodes[b - 1];
    nodes[a - 1].con_edges.push_back(&edges[i]);
    nodes[b - 1].con_edges.push_back(&edges[i]);
  }
  int k = 0;
  FOR(i, 0, n) { k = max(k, (int)nodes[i].con_edges.size()); }

  Node *root = &nodes[0];
  Paint(root);
  cout << k << endl;
  FOR(i, 0, n - 1) { cout << edges[i].color << endl; }
  return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i, s, e) for(int i = s; i < e; i++)
#define rrep(i, s, e) for(int i = s; i > (s)-(e); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  string a, b, c;
  cin >> a >> b >> c;

  if (a.substr(a.length()-1,1) == b.substr(0,1) && b.substr(b.length()-1,1) == c.substr(0,1)) pr("YES");
  else pr("NO");


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N = 105;
const int MOD = 1000000007;

int n,m,h[N],w[N];
LL dp[N][N];

int pow_(int x,int y) {///快速幂求 x的y次方
    int ans = 1;
    if(y > 0) {
        while(y) {
            if(y % 2)ans = (LL)ans * x % MOD;
            x = (LL)x * x % MOD;
            y /= 2;
        }
    }
    return ans;
}

int main() {
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++) {
        scanf("%d",&h[i]);
        w[++ m] = h[i];
    }
    sort(w + 1,w + m + 1);///高度排序
    m = unique(w + 1,w + m + 1) - w - 1;///离散化 m是离散化后的长度
    for(int i = 1;i <= n;i ++) {
        h[i] = lower_bound(w + 1,w + m + 1,h[i]) - w;
    }
    dp[0][0]=1;
    for(int i = 1;i <= n;i ++) {
        for(int j = h[i] + 1;j <= h[i - 1];j ++)
            (dp[i][0] += dp[i - 1][j] * 2 % MOD) %= MOD;

        (dp[i][0] += dp[i - 1][0] * 2 % MOD) %= MOD;///交叉或者不交叉

        int d = pow_(2,w[h[i]] - w[h[i-1]]);
        for(int j = 1;j <= min(h[i - 1],h[i]);j ++) {
            dp[i][j] = dp[i - 1][j] * d % MOD;
        }

        for(int j = h[i - 1] + 1;j <= h[i];j ++) {///比前一列高出的部分
            if(j > 1)(dp[i][j] += dp[i - 1][0] * (pow_(2,w[j] - w[j - 1]) - 1) % MOD * 2 % MOD * pow_(2,w[h[i]] - w[j]) % MOD) %= MOD;
            else (dp[i][1] += dp[i - 1][0] * (pow_(2,w[1]) - 2) % MOD * pow_(2,w[h[i]] - w[1]) % MOD) %= MOD;///上一列中无重复的乘上化不超过上一列高度中有重复的
        }
    }
    LL ans = 0;
    for(int i = 0;i <= h[n];i++)
        (ans += dp[n][i]) %= MOD;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 384
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    l = {i:0 for i in range(1,100001)}
    for num in A:
        l[num] += 1

    s = sum(A)

    for _ in range(Q):
        B, C = map(int, input().split())
        num_of_before = l[B]
        l[C] += num_of_before
        s = s + num_of_before * (C-B)
        l[B] = 0
        print(s)


if __name__ == '__main__':
    main()



Measured memory_bytes: 89020
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	string ans = "CODEFESTIVAL2016";
	int tot = 0;
	string x;
	cin >> x;
	for (int i = 0; i < (int) ans.size(); i++)
		if (ans[i] != x[i])
			tot += 1;
	cout << tot << endl;
}

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

int main(){
	
	int a[3],cnt=100000;
	cin>>a[0]>>a[1]>>a[2];
	for(int i =0; i<3; i++){
		for(int j=i+1; j<3; j++)if(a[i]+a[j]<cnt)cnt=a[i]+a[j];
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

template<class T> T umax(T a,T b) {return (a>b?a:b);}
template<class T> T umin(T a,T b) {return (a<b?a:b);}
template<class T,class P> T umax(T a,P b) {return (a>b?a:b);}
template<class T,class P> T umin(T a,P b) {return (a<b?a:b);}

typedef long long int ll;
const int maxn = 1e5+7;
const ll mod = 1e9+7;

bool compare(const pair<ll,ll>& x, const pair<ll,ll>& y) {
    if(x.second == y.second) return x.first < y.first;
    return x.second < y.second;
}

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

double dp[305][305][305];
int n;

int main() {
    int x;
    cin >> n;
    int a,b,c;
    a = b = c = 0;
    for(int i=0;i<n;i++) {
        cin >> x;
        if(x == 1) a++;
        else if(x == 2) b++;
        else c++;
    }
    for(int k=0;k<=n;k++) {
        for(int j=0;j<=n;j++) {
            for(int i=0;i<=n;i++) {
                if(i==0 && j==0 && k==0) {
                    continue;
                }
                if(i+j+k > n) {
                    continue;
                }
                if(i > 0) {
                    dp[i][j][k] += 1.0*i/(i+j+k) * dp[i-1][j][k];
                }
                if(j > 0) {
                    dp[i][j][k] += 1.0*j/(i+j+k) * dp[i+1][j-1][k];
                }
                if(k > 0) {
                    dp[i][j][k] += 1.0*k/(i+j+k) * dp[i][j+1][k-1];
                }
                dp[i][j][k] += 1.0*n/(i+j+k);
            }
        }
    }
    printf("%.16lf\n",dp[a][b][c]);
    return 0;
}


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

int main(){
  int n,m;
  string s,p,g,a,b;

  while( cin>>n>>m && n && m ){
    cin >> s >> p >> g;
    int d[n][n];
    for( int i=0;i<n;i++ ){
      for( int j=0;j<n;j++ )
	d[i][j] = 10000000;
      d[i][i] = 0;
    }

    map<string,int> mp;
    int nn=0;
    for( int i=0;i<m;i++ ){
      int dd,t;
      cin >> a >> b >> dd >> t;
      if( mp.find(a) == mp.end() )
	mp[a] = nn++;
      if( mp.find(b) == mp.end() )
	mp[b] = nn++;
      int time = dd/40 + t;
      d[ mp[a] ][ mp[b] ] = d[ mp[b] ][ mp[a] ] = time;
    }

    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 << d[ mp[s] ][ mp[p] ] + d[ mp[p] ][ mp[g] ] << endl;
  }

  return 0;
}

Measured memory_bytes: 2248
#include<bits/stdc++.h>
using namespace std;
string s;
int end_w;
long long res;
int main(){
  cin>>s;
  for(int i=0;i<s.size();++i){
    if(s.c_str()[i]=='W'){
      res += i - end_w++;
    }
  }
  cout<<res;
}

Measured memory_bytes: 640