akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

class Program{
    static void Main(){
        string s = Console.ReadLine();
        int b = 0;
        int e = b + 1;
        bool found = false;
        while(!found && b < s.Length){
            for(int i = 1; i <= 2; i++){
                e = b + i;  
                if(e < s.Length && Unbalance(s.Substring(b, i + 1))){
                    found = true;
                    b++;
                    e++;
                    break;
                }
            }
            if(found) break;
            else b++;
        }
        if(!found){
            b = -1;
            e = -1;
        }
        Console.WriteLine("{0} {1}", b, e);
    }

    static bool Unbalance(string str){
        int[] cnt = new int[30];
        for(int i = 0; i < str.Length; i++){
            cnt[str[i] - 'a']++;
        }
        if(cnt.Max() > str.Length / 2) return true;
        else return false;
    }
}

Measured memory_bytes: 7308
package main

import "fmt"

func main() {
	var (
		n     int = 3
		count int
	)
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}
	flag := true
	for flag {
		for i := 0; i < n; i++ {
			if nums[i]%2 == 0 {
				nums[i] /= 2
			} else {
				flag = false
			}
		}
		if flag {
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 2e9+7;

int main() {
    int h, w;
    cin >> h >> w;
    vi road;
    rep(y, h) {
        vi k(w);
        rep(x, w) cin >> k[x];
        if (y % 2 != 0) reverse(all(k));
        rep(x, w) road.pb(k[x]);
    }
    // for(auto r: road) cout << r << " "; cout << endl;

    vvi moves;
    rep(i, road.size()) {
        if (road[i] % 2 == 0 || i == road.size() - 1) continue;
        if (i == road.size() - 2 && road[i + 1] % 2 == 0) continue;
        road[i]--; road[i + 1]++;
        int from_y = (i / w) + 1;
        int to_y = ((i + 1) / w) + 1;

        int from_x = (i % w) + 1;
        if (from_y % 2 == 0) from_x = (w - from_x) + 1;
        int to_x = ((i + 1) % w) + 1;
        if (to_y % 2 == 0) to_x = (w - to_x) + 1;
        vi move{from_y, from_x, to_y, to_x};
        moves.pb(move);
    }
    cout << moves.size() << endl;
    for(auto move: moves) {
        cout << move[0] << " " << move[1] << " " << move[2] <<  " " << move[3] << endl;
    }
    return 0;
}

Measured memory_bytes: 9964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

const int INF = 2147480000;

int main(void){

    ll H, N;
    vector<ll> A, B;
    cin >> H >> N;
    for(ll i=0; i<N; i++){
        ll a, b; cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }

    ll max_A = 0;
    for(ll i=0; i<N; i++){
        max_A = max(max_A, A[i]);
    }

    ll dp[1005][20200];
    for(ll i=0; i<=N; i++){
        for(ll j=0; j<=H+max_A; j++){
            dp[i][j] = INF;
        }
    }

    for(int i=0; i<=N; i++) dp[i][0] = 0;
    for(ll i=0; i<N; i++){
        for(ll j=0; j<=H+max_A; j++){
            if(j - A[i] < 0){
                dp[i+1][j] = dp[i][j];
            }
            else{
                dp[i+1][j] = min(dp[i][j], dp[i+1][j - A[i]] + B[i]);
            }
        }
    }
    ll ans = INF;
    for(ll i=H; i<=H+max_A; i++){
        ans = min(ans, dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 158464
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int d;
  cin>>d;
  int c=0;
  long long int x,y;
  for(int i=0;i<n;i++)
  {
    cin>>x>>y;
    if(x*x+y*y<=d*d)
     c++;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
using std::priority_queue;
using std::vector;

priority_queue<int, vector<int> > q;
int n, m;
long long ans;

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1, a; i <= n; i++) {
		scanf("%d", &a);
		ans += a;
		q.push(a);
	}

	for (int i = 1; i <= m; i++) {
		int now = q.top();
		q.pop();
		ans -= now - (now >> 1);
		q.push(now >> 1);
	}

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

	return 0;
}


Measured memory_bytes: 892
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long L = long.Parse(str[0]);
		long A = long.Parse(str[1]);
		long B = long.Parse(str[2]);
		long M = long.Parse(str[3]);
		int A1 = str[1].Length;
		int B1 = ((A+B*(L-1)).ToString()).Length;
		long s = A;
		long X = 0;
		for(var i=A1;i<=B1;i++){
          	if((s.ToString()).Length > i){
              continue;
            }
			long Cd;
			if(i==B1){
				Cd = (long)((A+B*(L-1)-s)/B+1);
			} else {
				Cd = (long)(((long)Math.Pow(10,i)-1-s)/B+1);
			}
			long ns = (long)(s+B*Cd);
          	Console.Error.WriteLine(Cd+" "+i+" "+s+" "+ns);
          	if(Cd<=0){
              continue;
            }
			long[,]D = new long[3,3];
			long[,]D2 = new long[3,3];
 	        long[,]DX = new long[3,3];
			D[0,0] = 1;
			D[1,1] = 1;
			D[2,2] = 1;
          	DX[0,0] = (long)Math.Pow(10,i) % M;
          	DX[1,0] = 1;
          	DX[1,1] = 1;
          	DX[2,1] = B;
          	DX[2,2] = 1; 	
			while(Cd > 0){
				if(Cd%2==1){
                  	for(var h1=0;h1<=2;h1++){
						D2[h1,0] = (D[h1,0]*DX[0,0])%M+(D[h1,1]*DX[1,0])%M+D[h1,2]*DX[2,0];
						D2[h1,1] = (D[h1,0]*DX[0,1])%M+(D[h1,1]*DX[1,1])%M+D[h1,2]*DX[2,1];
						D2[h1,2] = (D[h1,0]*DX[0,2])%M+(D[h1,1]*DX[1,2])%M+D[h1,2]*DX[2,2];
					}
					for(var h1=0;h1<=2;h1++){
						for(var h2=0;h2<=2;h2++){
							D[h1,h2] = D2[h1,h2] % M;
						}
					}
					Cd--;
				}
				for(var h1=0;h1<=2;h1++){
					D2[h1,0] = (DX[h1,0]*DX[0,0])%M+(DX[h1,1]*DX[1,0])%M+DX[h1,2]*DX[2,0];
					D2[h1,1] = (DX[h1,0]*DX[0,1])%M+(DX[h1,1]*DX[1,1])%M+DX[h1,2]*DX[2,1];
					D2[h1,2] = (DX[h1,0]*DX[0,2])%M+(DX[h1,1]*DX[1,2])%M+DX[h1,2]*DX[2,2];
				}
				for(var h1=0;h1<=2;h1++){
					for(var h2=0;h2<=2;h2++){
						DX[h1,h2] = D2[h1,h2] % M;
					}
				}
				Cd /= 2;
			}
			Console.Error.WriteLine(X+" "+D[0,0]+" "+D[1,0]+" "+D[2,0]);
			X = ((X * D[0,0]) % M + (s % M * D[1,0]) % M + D[2,0]) % M;
			Console.Error.WriteLine(X+" "+D[0,0]+" "+D[1,0]+" "+D[2,0]);
			s = ns;
		}
		Console.WriteLine(X);
	}
  
  	public static long mm(long a,long b,long mod)
	{
		long a0 = 0;
		long a1 = a;
		while(a1 >= 1000000000){
			a0 = (a0 + b * 1000000000) % mod;
			a1 -= 1000000000;
		}
		a0 = (a0 + b * a1) % mod;
		return a0;
	}
}

Measured memory_bytes: 13396
x1, y1, x2, y2 = map(int, input().split())
x3 = x2 - y2 + y1
y3 = y2 + x2 - x1
x4 = x1 - y2 + y1
y4 = y1 + x2 - x1
print('{} {} {} {}'.format(x3, y3, x4, y4))

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }


ll x, d;
int n;
void solve() {
    cin >> n >> x >> d;

    if (d == 0) {
        if (x == 0) cout << 1 << endn;
        else cout << n + 1 << endn;
        return;
    }
    if (d < 0) { x *= -1; d *= -1; }

    map<ll, vector<pair<ll, ll>>> vec;
    rep(k, n + 1) {
        auto idx = ((ll)k * x % d + d) % d;
        auto l = (ll)k * x / d + (ll)k * (k - 1) / 2;
        auto r = (ll)k * x / d + (ll)k * (2 * n - k - 1) / 2;
        vec[idx].emplace_back(l, r);
    }

    ll ans = 0;
    for (auto& v : vec) {
        all(sort, v.second);
        ll l, r;
        rep(i, v.second.size()) {
            auto nl = v.second[i].first;
            auto nr = v.second[i].second;
            if (i == 0) {
                l = nl; r = nr;
                continue;
            }

            if (nl <= r) maxs(r, nr);
            else {
                ans += r - l + 1;
                l = nl; r = nr;
            }
        }

        ans += r - l + 1;
    }

    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;
    cin >> n;
    vector<ll> original(n);

    rep(i, n)cin >> original[i];
    deque<ll> q;

    for (int i = 0; i < n; i++) {
        ll o = original[i];
        if (i % 2 == 0) {
            q.push_front(o);
        } else {
            q.push_back(o);
        }
    }

    vector<ll> ans(n);
    copy(q.begin(), q.end(), ans.begin());

    if (n % 2 == 0) reverse(ans.begin(), ans.end());

    for (ll a : ans) {
        cout << a << ' ';
    }
    cout << endl;

}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
const int N=3005;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int n,a[N],A[N];
vector <int> e[N];
bool dfs(int x,int pre){
	bool res=0;
	for (auto y : e[x])
		if (y!=pre)
			res|=a[x]>a[y]&&!dfs(y,x);
	return res;
}
bool check(int x){
	return dfs(x,0);
}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		a[i]=read();
		e[i].clear();
	}
	for (int i=1;i<n;i++){
		int a=read(),b=read();
		e[a].push_back(b);
		e[b].push_back(a);
	}
	for (int i=1;i<=n;i++)
		if (check(i))
			printf("%d ",i);
	return 0;
}

/*

1.	走一个子树，对手只需要在子树里就可以打败你。
2.	可以强制走一个子树使得对手在这个子树里并获胜。
3.	对手可以肛回来打败你。
当且仅当第 2 种情况可以胜利。

*/

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

const int BITS = 32;

char flip(char dir) {
    if (dir == 'L' || dir == 'R')
        return 'L' + 'R' - dir;

    return 'U' + 'D' - dir;
}

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

    int N;
    cin >> N;
    vector<long long> X(N), Y(N);

    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];

        if (abs(X[i] + Y[i]) % 2 != abs(X[0] + Y[0]) % 2) {
            cout << -1 << '\n';
            return 0;
        }
    }

    vector<long long> D;

    for (int p = BITS; p >= 0; p--)
        D.push_back(1LL << p);

    if (abs(X[0] + Y[0]) % 2 == 0)
        D.push_back(1);

    int M = D.size();
    cout << M << '\n';

    for (int i = 0; i < M; i++)
        cout << D[i] << (i < M - 1 ? ' ' : '\n');

    for (int i = 0; i < N; i++) {
        long long x = X[i], y = Y[i];

        for (long long d : D) {
            long long best_sum = abs(x - d) + abs(y);
            char best_dir = 'L';

            long long current = abs(x + d) + abs(y);
            if (current < best_sum) {
                best_sum = current;
                best_dir = 'R';
            }

            current = abs(x) + abs(y - d);
            if (current < best_sum) {
                best_sum = current;
                best_dir = 'D';
            }

            current = abs(x) + abs(y + d);
            if (current < best_sum) {
                best_sum = current;
                best_dir = 'U';
            }

            cout << flip(best_dir);

            if (best_dir == 'L')
                x -= d;
            else if (best_dir == 'R')
                x += d;
            else if (best_dir == 'D')
                y -= d;
            else if (best_dir == 'U')
                y += d;
            else
                assert(false);
        }

        assert(x == 0 && y == 0);
        cout << '\n';
    }
}


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S, T;
	char add;
	bool ans = false;

	cin >> S >> T;
	rep(i, (int)T.length()) {
		if (S == T) ans = true;
		add = S[S.length() - 1];
		S.pop_back();
		S.insert(S.begin(), add);
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <cstdio> 
#include <cstdlib>  
#include <algorithm> 
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    int n;
    cin >> n;
    int cnt = 0;
    bool ans = false;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a == b) cnt++;
        else cnt = 0;
        if (cnt >= 3) ans = true;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int main(){

	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int cnt = 0;
	for(int i=0; i<s.size(); i++){
		if( s[i] != t[i] ) cnt++;
	}
	cout << cnt << endl;
	return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)

int main()
{
	int N;
	vector<int> A;
	int key;
	int j;

	cin >> N;

	A.reserve(N);
	REP(i, N) {
		cin >> A[i];
	}


	// 様子を表示
	REP(k, N) {
		cout << A[k];
		if(k != N - 1) cout << ' ';
		else cout << endl;
	}

	for(int i = 1; i < N; ++i) {

		key = A[i];
		j = i;

		// keyの挿入位置を決める
		while (A[j - 1] > key && j > 0) {
			// key挿入するために一個ずつずらしてく
			A[j] = A[j - 1];
			--j;
		}
		// key挿入
		A[j] = key;

		REP(k, N) {
			cout << A[k];
			if(k != N - 1) cout << ' ';
			else cout << endl;
		}


	}

	return 0;
}

Measured memory_bytes: 1200
def main():
    S=input()
    N=len(S)
    x=[]
    x_append=x.append
    s=1
    for i in range(0,N-1):
        if S[i]==S[i+1]:
            s=s+1
        else:
            x_append(s)
            s=1
    x_append(s)
    ans=[0]*N
    t=0
    for i in range(0,len(x)//2):
        ans[t+x[2*i]-1]+=(x[2*i]+1)//2
        ans[t+x[2*i]]+=(x[2*i])//2
        ans[t+x[2*i]-1]+=(x[2*i+1])//2
        ans[t+x[2*i]]+=(x[2*i+1]+1)//2
        t+=x[2*i]+x[2*i+1]
    print(*ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7152
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
      int l,r;
      int k=0;
      
      // ここにプログラムを追記
      for(int i=0;i<N;i++){
        cin >> l >> r;
        k+=(r-l)+1;
      }
      cout << k << endl;
    }

Measured memory_bytes: 3636
lines = $stdin.read
array = lines.split("\n")
X = array[0].to_i

COINS = [100, 101, 102, 103, 104, 105]

def coin(amount,kind,coins)

  coins = [0].concat(coins)
  dp = Array.new(kind+1).map{Array.new(10**5+1, 0)}
  dp.each{|row| row[0] = 1}

  for i in 1..kind
    for j in 1..amount
      dp[i][j] = dp[i][j - coins[i]] + dp[i-1][j]
    end
  end
  dp
end


dp = coin(X,COINS.length,COINS)
if dp[COINS.length][X] > 0
  puts 1
else
  puts 0
end

Measured memory_bytes: 7292
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

int main(){
    int K,A,B;
    cin>>K;
    cin>>A>>B;
    bool flag = false;
    for(int i = A;i<=B;i++){
        if(i%K==0)flag=true;
    }
    if(flag)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    
    

return 0;

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
int main(void){
    int n,r;
    while(cin>>n>>r,n){
        list<int> deck(n);
        iota(rall(deck),1);
        rep(i,r){
            int p,c;
            cin>>p>>c;
            auto itr=deck.begin();
            rep(j,p+c-2) itr++;
            rep(j,c){
                deck.push_front(*itr);
                itr=deck.erase(itr);
                itr--;
            }
        }
        cout<<deck.front()<<endl;
    }
}

Measured memory_bytes: 3060
// Aizu 1107: Spiral Footrace
// 2017.9.16 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

#define EPS 1e-6

int x[405], y[405];
char f[405];
double ans;

double theta(int x1, int y1, int x2, int y2)
{
    int dx, dy, ax, ay;
    double t;

    dx = x2 - x1;
    ax = dx < 0 ? -dx : dx;
    dy = y2 - y1;
    ay = dy < 0 ? -dy : dy;
    t = (ax + ay == 0) ? 0 : (double)dy/(double)(ax+ay);
    if (dx < 0) t = 2 - t;
    else if (dy < 0) t = 4 + t;
    return t * 90.0;
}

void convexHull(int pn, int *x, int *y)
{
    int i, j, px, py;
    int min;
    double minang, nowang;
    double dist, d, rad;

    min = 0, minang = 90, px = py = 0;
    for (j = 0; j < pn; j++) {
        dist = 0x7ffffff, nowang = minang; minang = -360;
		if (nowang < 0) nowang += 360;
        for (i = 0; i < pn; i++) {
			if (f[i]) continue;
            d = sqrt((x[i]-px)*(x[i]-px)+(y[i]-py)*(y[i]-py));
            rad = theta(px, py, x[i], y[i]);
	        if (d == 0) continue;
			if (rad > nowang) rad -= 360;
            if (rad < nowang+EPS) {
                if (rad - EPS > minang) {
                    dist = d;
                    minang = rad;
                    min = i;
                } else if (fabs(rad-minang) <= EPS && d < dist) {
                    dist = d;
                    minang = rad;
                    min = i;
                }
            }
#if 0
			else if (fabs(rad-nowang) < EPS && d > EPS &&
                       fabs(rad-minang) > EPS || d < dist) {
                dist = d;
                minang = rad;
                min = i;
            }
#endif
        }
		f[min] = 1;
		ans += sqrt((px-x[min])*(px-x[min])+(py-y[min])*(py-y[min]));
		px = x[min], py = y[min];
    }
}

int main()
{
	int n, i;

	while (scanf("%d", &n) && n) {
		memset(f, 0, sizeof(f));
		for (i = 0; i < n; i++) scanf("%d%d", x+i, y+i);
		ans = 0; convexHull(n, x, y);
		printf("%.1lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1836
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

ll T[1000001] = {};
ll c[100] = {};
ll cointype = 0;
void createCoin() {
	ll t = 1;
	ll p = 0;
	rep(i, 0, 6) {
		t *= 6;
		if (t <= 100000) {
			c[p++] = t;
		}
	}
	t = 1;
	rep(i, 0, 6) {
		t *= 9;
		if (t <= 100000) {
			c[p++] = t;
		}
	}
	c[p++] = 1;

	sort(c, c + p);
	cointype = p;
}
int main() {
	ll N; cin >> N;
	createCoin();

	////
	repe(i, 1, N) {
		T[i] = i;
	}
	rep(i, 1, cointype) {
		rep(j, 0, N) {
			T[j + c[i]] = min(T[j] + 1, T[j + c[i]]);
		}
	}
	cout << T[N] << endl;

	return 0;
}

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

Measured memory_bytes: 1728
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
multiset<string>vc;
map<string,int>mp;
int main()
{


    int n;
    cin>>n;
    for(int i=0;i<n;i++){

        string str;
        cin>>str;
        vc.insert(str);

    }
for(auto it=vc.begin(); it!=vc.end();it++ )

       {
           mp[*it]++;
       }
int maxi=0;

for(auto it=mp.begin();it!=mp.end();it++){

maxi=max(it->second,maxi);


}

for(auto it=mp.begin();it!=mp.end();it++){

if(it->second==maxi)cout<<it->first<<endl;}









    return 0;
}

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


typedef long long ll;
int main() {
  string S;
  int count=0;
  cin>>S;
    string ret="Good";
  for(int i=1;i<4;i++){
    char x=S.at(i);
    if(x==S.at(i-1))ret="Bad";
  }
  cout<<ret<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll p[n];
    rep(i, n){
        cin >> p[i];
    }

    ll ans = 0;
    for(ll i = 1; i < n - 1; i++){
        if((p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] < p[i - 1] && p[i] > p[i + 1])){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
ll mod = 1000000007;

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;

    ll ans;
    int index;
    if(s[0] == t[0]){
        index = 1;
        ans = 3;
    }else{
        index = 2;
        ans = 6;
    }

    for(; index < n; index++){
        if(s[index] == t[index]){
            if(s[index-1] == t[index-1])    ans *= 2;
        }else{
            if(s[index-1] == t[index-1])    ans *= 2;
            else                            ans *= 3;
            index++;
        }

        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  string s;
  cin >> s;
  const int n = s.size();
  for (int i = 0; i < n; ++i) {
    cout << 'x';
  } cout << nl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int A,B,C,D,E=0;
    
    scanf("%d%d%d%d",&A,&B,&C,&D);
    
    if(A>=B && C>=D) {
        E = B+D;
     }
     else if(A<=B && C>=D){
        E=A+D;
     }
     else if(A>=B && C<=D){
        E=B+C;
     }
     else if(A<=B && C<=D){
        E=A+C;
     }   
     printf("%d",E);
     
     return 0;
}     

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(ll i=l;i<r;i++)
#define rrep(i,l,r) for(ll i=(r)-1;i>=l;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define range(i) i.begin(),i.end()
#define sum(i) accumulate(range(i),0)
struct start { start() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }start;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head, Tail&&... tail) {
	cin >> head;
	in(move(tail)...);
}
template <class T>
inline void out(T t) {
	cout << t << '\n';
}
template <class Head, class... Tail>
inline void out(Head head, Tail... tail) {
	cout << head << ' ';
	out(move(tail)...);
}
template <class T>
inline void out(vector<T> a){
    rep(i,0,a.size()-1)cout<<a[i]<<' ';
    out(a.back());
}



int main() {
    int a,b;
    in(a);
    out(a<2800?(a<1200?"ABC":"ARC"):"AGC");
} 









Measured memory_bytes: 256
N=int(input())
for i in range(N) :
    x,y,z=map(int,input().split())
    if x**2==z**2+y**2:
        print('YES')
    elif y**2==x**2+z**2:
        print('YES')
    elif z**2==x**2+y**2:
        print('YES')
    else:
        print('NO')
    


Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int max_val = 55555;
    vector<bool> ps(max_val + 1, true);
    ps[0] = false;
    ps[1] = false;
    for(int i = 2; i * i <= max_val; i ++){
        if(! ps[i]){
            continue;
        }
        ps[i] = true;
        for(int j = i * 2; j <= max_val; j += i){
            ps[j] = false;

        }
    }

    for(int i = 2; i <= max_val && N > 0; i ++){
        if(ps[i] && i % 5 == 1){
            cout << i << " ";
            N -- ;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1 ; i*i<=n ; i++){
		if(n%i == 0){
			ret.push_back(i);
			if(i!=1 && i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
int main(){
    ll n,m,ans=114514;cin>>n>>m;
    if(n==1){
        cout<<m<<endl;
        return 0;
    }
    vector<ll> divisor=enum_div(m);
    sort(divisor.begin(),divisor.end());
    reverse(divisor.begin(),divisor.end());
    For(i,0,divisor.size()){
        if(m>=n*divisor.at(i)){
            cout<<divisor.at(i)<<endl;
            return 0;
        }
        else continue;
    }
}

Measured memory_bytes: 256
N = int(input())
S = input()

r,g,b,rg,gb,br,rgb = 0,0,0,0,0,0,0,

for c in S:
    if c == 'R':
        r += 1
        rg += g
        br += b
        rgb += gb
    elif c == 'G':
        g += 1
        rg += r
        gb += b
        rgb += br
    else:
        b += 1
        gb += g
        br += r
        rgb += rg


cnt = 0
for i in range(N):
    s1 = S[i]
    for j in range(1, (N-i-1)//2+1):
        s2, s3 = S[i+j], S[i+j*2]
        if s1 != s2 and s2 != s3 and s1 != s3:
            cnt += 1

print(rgb-cnt)




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

int main(){
  long N,K,i,sum=0;
  cin >> N >> K;
  vector<long> H(N);

  for(i=0;i<N;i++)
  cin >> H.at(i);

  sort(H.begin(),H.end());
  reverse(H.begin(),H.end());

  if(N<=K){
    cout << "0";
  }else{
    for(i=0;i<K;i++){
      H.at(i) = 0;
    }
    for(i=0;i<N;i++){
      sum += H.at(i);
    }
    cout << sum;
  }
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>
#define maxn 2010
using namespace std;
int a[maxn],num[maxn*maxn];
int n,cnt=0,ans;
bitset <maxn*maxn+maxn> s;
int main(){
	scanf("%d",&n);
	s[0]=1;
	int i,j,x;
	for(i=1;i<=n;++i){
		scanf("%d",&x);
		s|=s<<x;
	}
	for(i=1;i<=maxn*maxn;++i){
		if(s[i])  num[++cnt]=i;
	}
	ans=num[(cnt+1)>>1];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11520
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
typedef long long ll;
long long  a[200100],b[200100];
int main ()
{
    int n;
    while(~scanf("%d",&n))
    {
        long long ma=1e17,dd,bb=0;
        long long sum =0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lld %lld",&a[i],&b[i]);
            sum+=a[i];
            if(a[i]>b[i])
            {
                ma=min(ma,b[i]);
            }
            else if(a[i]==b[i])
                bb+=a[i];
        }
        if(ma==1e17)
            printf("%lld\n",0ll);
        else
            printf("%lld\n",sum-ma);
    }
    return 0;
}


//int len,a[10010];
//bool vis[10010]={0};
//void init()
//{
//    a[++len]=2;
//    for(int i=3;i<=1000;i+=2)
//    {
//        if(!vis[i])
//            a[++len]=i;
//        for(int j=i;j;j+=2)
//    }
//}
//int main()
//{
//    len =0;
//    init();
//    int a,b;
//    while(~scanf("%d %d",&a,&b))
//    {
//
//    }
//    return 0;
//}


Measured memory_bytes: 512
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dp[10000][10000];
ll combination(ll n, ll r) {
         if (n == r){dp[n][n] = 1;}
	else if (r == 0) {return dp[n][0] = 1;}
	else if (r == 1) {return dp[n][1]=n;}
	else {dp[n][r]=dp[n - 1][r - 1] % 1000000007 + dp[n - 1][r] % 1000000007;
	return dp[n][r]=combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;}
}
int main() {

	string S;
	cin >> S;
	int N;
	N = S.length();
	int r;
	int l;
	r = 0;
	l = 0;
	for (int i = 0;i < N;i++) {
		if(S.at(i)=='*'){
			for (int j = 0;j < i;j++) {
				if (S.at(j) == '(') { l++; }
				else if (S.at(j) == ')') { l--; }
		}
			for (int k = i+1; k< N;k++) {
				if (S.at(k) == '(') { r--; }
				else if (S.at(k) == ')') { r++; }
			}
			
		}
	}
	if (r > l)r = l;
	cout << r << endl;
	return 0;
}



Measured memory_bytes: 3212
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var x = next(), n = next();
  var p = nexts(n);
  for(var i = 0; i <= n; i++){
    var y = x-i, f = 1;
    for(var j = 0; j < n; j++)if(p[j] === y)f = 0;
    if(f)return y;
    var y = x+i, f = 1;
    for(var j = 0; j < n; j++)if(p[j] === y)f = 0;
    if(f)return y;
  }
}

Measured memory_bytes: 29640
#include<stdio.h>
int main(void){
  int f,j,a[10],i;
  f=0;
  j=0;
  a[9]=0;
  i=0;

  for(f=0;f<10;f++){
    scanf("%d",&a[f]);
}

  for(f=0;f<9;f++)
    {
      for(j=f+1;j<10;j++)
	{
	  if(a[f]<a[j])
	    {
	      i=a[f];
	      a[f]=a[j];
	      a[j]=i;
	    }
	}
    }
  printf("%d\n%d\n%d\n",a[0],a[1],a[2]);

  return 0;
}

Measured memory_bytes: 0
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class weight {
public:
	int coin;
	int pay;
	weight() {
		coin = -1;
		pay = -1;
	}
	bool operator < (const weight& w)const {
		if (coin < w.coin)return true;
		if (coin==w.coin&&pay > w.pay)return true;
		return false;
	}
	bool operator > (const weight& w)const {
		if (coin > w.coin)return true;
		if (coin==w.coin&&pay < w.pay)return true;
		return false;
	}
};

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

	cin >> N;
	while (N) {
		weight ans;
		vector<vector<weight>>dp(N + 1, vector<weight>(N * 999 + 1));
		dp[0][0].coin = 0;
		dp[0][0].pay = 0;
		for (int i = 1; i <= N; i++) {
			cin >> M;
			for (int j = 0; j <= (i - 1) * 999; j++) {
				if (dp[i - 1][j].coin == -1) {
					continue;
				}
				weight box(dp[i - 1][j]);
				dp[i][j] = max(dp[i][j], box);
				box.coin++;
				box.pay += M;
				K = M % 1000;
				if (K&&K <= 500) {
					dp[i][j + 500 - K] = max(dp[i][j + 500 - K], box);
					if (j >= 500+K) {
						dp[i][j - 500 - K] = max(dp[i][j - 500 - K], box);
					}
				}
				else if (K) {
					if (j >= K - 500) {
						dp[i][j - K + 500] = max(dp[i][j - K + 500], box);
					}
					box.coin--;
					dp[i][j + 1000 - K] = max(dp[i][j + 1000 - K], box);
				}
				else {
					if (j >= 500) {
						dp[i][j - 500] = max(dp[i][j - 500], box);
					}
				}
			}
		}
		for (auto i : dp[N]) {
			if (i.coin != -1) {
				ans = max(ans, i);
			}
		}
		cout << ans.coin << " " << ans.pay << endl;
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 82736
#include<iostream>
#include<math.h>
using namespace std;
long number[101];
long numbers[101][21][50];
int N;
int last;
int main(void){

   
  cin >> N;
  N-=1;
  for (int i=0;i<N;i++){
    cin >> number[i];
  }
  cin >> last;
  numbers[0][number[0]][0]=1;
  for(int k=0;k<50;k++){
    for(int i=1;i<N;i++){
      for(int j=0;j<=20;j++){
	if(j+number[i]>=0 && j+number[i] <=20 && numbers[i-1][j][k]!=0){
	  numbers[i][j+number[i]][k]+=numbers[i-1][j][k]%1000000;
	  numbers[i][j+number[i]][k+1]+=numbers[i-1][j][k]/1000000;
	  // cout << i <<" " << j+number[i]<<" "<< j << " " <<numbers[i-1][j][k]<< endl;
	}
	if(j-number[i]>=0 && j-number[i] <=20 && numbers[i-1][j][k]!=0){
	  numbers[i][j-number[i]][k]+=numbers[i-1][j][k]%1000000;
	  numbers[i][j-number[i]][k+1]+=numbers[i-1][j][k]/1000000;
	  // cout << i <<" " << j-number[i]<<" "<< j << " " <<numbers[i-1][j][k]<< endl;
	}
      }
    }
  }
  int checker=0;
  int value;
  for(int k=50;k>=0;k--){

    if(numbers[N-1][last][k]!=0){
      for(int i=1;i<=6;i++){
	value=( (numbers[N-1][last][k]%1000000)+(numbers[N-1][last][k-1]/1000000))%(long)pow(10,7-i)/(long)pow(10,6-i);
	if(checker==1||value!=0){
	cout << value;
	checker=1;
	}
      }
      //  cout << (numbers[N-1][last][k]%1000000)+(numbers[N-1][last][k-1]/1000000);
      /*	if(numbers[N-1][last][k-1]%1000000<10000 && k!=0)// && k-1==0)
	  {
	  	cout << 0 ;
	  }  
      */
 }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 2012
//ABC167C
//https://atcoder.jp/contests/abc167/submissions/13110642
//https://www.sejuku.net/blog/48660

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define inf 10000100


int main(){
    int n,m,x;
    int ans=inf;
    cin>>n>>m>>x;
    int c[n],a[n][m];

    rep(i,n){
        cin>>c[i];
        rep(j,m) cin>>a[i][j];
    }

    rep(s,1<<n){//1<<nは1をn回左にbitシフトしたもの＝2^n
        int cost=0;
        vector<int> d(m,0);//m個のアルゴリズムの能力。0で初期化
        rep(i,n){//s=0〜(2^n-1)まで変化(00000〜11111のようなイメージ)させている中で、
             if(s>>i&1){//各sの各桁の1or0を判定
                cost+=c[i];
                rep(j,m) d[j]+=a[i][j];
            }   
        }
        bool ok=true;
        rep(j,m) if(d[j]<x) ok=false;
        if(ok) ans=min(ans,cost);
    }

    if(ans==inf) cout<<-1<<endl;
    else cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

ll A, B;

struct primeFactor {
  ll p, r;
};

vector<primeFactor> factorization(ll n) {
  vector<primeFactor> res;
  ll m = n;
  for (ll i = 2; i * i <= m; i++) {
    if (m % i) continue;
    primeFactor f = primeFactor{i, 0};
    while (m % i == 0) {
      m /= i;
      f.r++;
    }
    res.push_back(f);
  }
  if (m != 1) {
    res.push_back(primeFactor{m, 1});
  }
  return res;
}

int main() {
  cin >> A >> B;

  vector<primeFactor> fa = factorization(A), fb = factorization(B);
  set<ll> pa, pb, res;
  for (auto &f : fa) pa.insert(f.p);
  for (auto &f : fb) pb.insert(f.p);
  set_intersection(all(pa), all(pb), inserter(res, res.end()));

  cout << res.size() + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
'use strict'

function main(inp) {
  inp = inp.trim().split('\n')
  const NQ = inp.shift().split(' ').map(n => Number(n))
  let ans = new Array(NQ[0]+1).fill(0)
  let ab = {}
  let px = {}

  for (let i = 0; i < inp.length; i++) {
    const arr = inp[i].split(' ').map(n => Number(n))
    let j = arr[0]
    if (i < NQ[0] - 1) {
      if(!(j in ab)) ab[j] = []
      ab[j].push(arr[1])
    } else {
      if(!(j in px)) px[j] = 0
      px[j] += arr[1]
    }
  }

  let stack = [1]
  const countup = n => {
    if (n in px) ans[n] += px[n]
    if (n in ab) {
      for (let i = 0; i < ab[n].length; i++) {
        let j = ab[n][i]
        ans[j] += ans[n]
        stack.push(j)
      }
    }
  }
  while(stack.length) {
    countup(stack.pop())
  }
  ans.shift()

  console.log(ans.join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 128696
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int gdc(int a, int b)
{
	if (a < b)
	{
		std::swap(a, b);
	}
	int c = a%b;
	if (c == 0)return b;
	return gdc(b, c);
}

int main()
{
	int N, M;
	cin >> N >> M;

	for (int i = M / N; i >= 1; --i)
	{
		if ((M - i*N) % i == 0)
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}

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

string s[2];

string eraseElements(string s) {
	string ret;
	bool isin = false;
	
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '"') { isin = !isin; continue; }
		if (!isin) { ret += s[i]; }
	}
	return ret;
}

vector<string> getElements(string s) {
	bool isin = false;
	string tmp;
	vector<string> ret;
	
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '"') { isin = !isin; }
		if (isin && s[i] != '"') { tmp += s[i]; }
		if (!isin) { ret.push_back(tmp); tmp = ""; }
	}
	return ret;
}

string solve() {
	if (s[0] == s[1]) { return "IDENTICAL"; }
	if (eraseElements(s[0]) != eraseElements(s[1])) { return "DIFFERENT"; }
	
	vector<string> t[2];
	t[0] = getElements(s[0]);
	t[1] = getElements(s[1]);
	
	if (t[0].size() != t[1].size()) { return "DIFFERENT"; }
	
	int cnt = 0;
	for (int i = 0; i < t[0].size(); i++) {
		if (t[0][i] != t[1][i]) {
			cnt++;
		}
	}
	if (cnt == 1) return "CLOSE";
	return "DIFFERENT";
}

int main() {
	while (cin >> s[0]) {
		if (s[0] == ".") break;
		cin >> s[1];
		cout << solve() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3220
import sys
 
input = sys.stdin.readline
 
 
def main():
    N, W = map(int, input().split())
    wv = [None] * N
    for i in range(N):
        wv[i] = tuple(map(int, input().split()))
 
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i, (w, v) in enumerate(wv, start=1):
        dp_i = dp[i]
        dp_im = dp[i - 1]
        for j in range(1, W + 1):
            if j < w:
                dp_i[j] = dp_im[j]
            else:
                a = dp_im[j - w] + v
                b = dp_im[j]
                if a > b:
                    dp_i[j] = a
                else:
                    dp_i[j] = b
 
    ans = dp[-1][-1]
    print(ans)
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 493124
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e9;

int LD(string &A, string &B){
  int al = A.length(), bl = B.length(), dp[al + 1][bl + 1];
  REP(i, al + 1) REP(j, bl + 1) dp[i][j] = (i == 0 || j == 0 ? max(i, j) : INF);
  FOR(i, 1, al + 1)
    FOR(j, 1, bl + 1)
      dp[i][j] = min(dp[i][j - 1] + 1, min(dp[i - 1][j] + 1, dp[i - 1][j - 1] + (A[i - 1] == B[j - 1] ? 0 : 1)));
  return dp[al][bl];
}

int main() {
  string a, b; cin >>a >>b;
  cout <<LD(a, b) <<endl;
  return 0;
}

Measured memory_bytes: 5096
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n;
    int m[n][3];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin>>m[i][j];
        }
    }
    for(int i = n-2; i >= 0; i--){
        for(int j = 0; j < 3; j++){
            int x=m[i][j];
            for(int k = 0; k < 3; k++){
                if(k==j)continue;
                m[i][j]=max(m[i+1][k]+x,m[i][j]);
            }
        }
    }
    cout<<max(m[0][0],max(m[0][1],m[0][2]))<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


struct SegmentTree{
private:
    int n;
    vector<P> node;

public:
    SegmentTree(vector<P> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1,mp(INF,-1));
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,P val){
        x += n-1;
        node[x] = val;
        while(x > 0){
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    P getmin(int a, int b, int k=0, int l=0, int r=-1){
        if (r < 0) r = n;
        if(r <= a || b <= l) return mp(INF,-1);
        if(a <= l && r <= b) return node[k];
        P vl = getmin(a, b, 2*k+1, l , (l+r)/2);
        P vr = getmin(a, b, 2*k+2, (l+r)/2,r);
        return min(vl, vr);
    }
};



int main(){
    int n,m;cin >> n >> m;
    string s;cin >> s;
    vector<int> x(n+2,-1);
    SegmentTree seg(vector<P> (n+2,mp(INF,-1)));
    seg.update(0,mp(0,0));
    for (int i = 1; i <= n; i++) {
        if(s[i]=='1') continue;
        P t = seg.getmin(max(0,i-m),i);
        if(t.fs >= INF){
            cout << -1 << endl;
            return 0;
        }
        x[i] = t.sc;
        t = mp(t.fs+1,i);
        seg.update(i,t);
    }
    vector<int> ans;
    int t=n,now=n;
    while(now != 0){
        t = x[now];
        ans.pb(now-t);
        now = t;
    }
    reverse(ALL(ans));
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << (i+1==ans.size()?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  vector<int> sum(26, 0);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(d, vector<int>(26));
  rep(i, d)
    rep(j, 26)
      cin >> s[i][d];
  rep(i, d){
    int maxhuman = 0;
    int maxindex;
    rep(j, 26){
      sum[j] += c[j];
      if(maxhuman < sum[j]){
        maxhuman = sum[j];
        maxindex = j;
      }
    }
    int biggest = 0;
    int bigday;
    rep(j, 26){
      if(biggest < s[i][j]){
      	biggest = s[i][j];
        bigday = j;
      }
    }
    if(maxhuman < biggest){
      cout << bigday+1 << endl;
      sum[bigday] = 0;
    }else{
      cout << maxindex+1 << endl;
      sum[maxindex] = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3672