akhauriyash/Code-Regression huggingface dataset:
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e3+5;

int n;
int x;
int y;
int visID;
int vist[N];
int dist[N][N];
int ans[N];
vector < int > adj[N];

void dij(int u){
    priority_queue < pair < int , int > > q;
    q.push({0 , u});
    dist[u][u] = 0;
    while(!q.empty()){
        int d = -q.top().first;
        int me = q.top().second;
        q.pop();
        //cout << me <<  " " << d << endl;
        for(int v : adj[me]){
            if(dist[u][me] + 1 < dist[u][v]){
                dist[u][v] = dist[u][me] + 1;
                q.push({-dist[u][v] , v});
            }
        }
    }
    //cout << endl;
}

int main(){
    scanf("%d%d%d" , &n , &x , &y);
    for(int i = 1; i < n; i++){
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            dist[i][j] = 1e9;
    for(int i = 1; i <= n; i++){
        dij(i);
    }
    for(int i = 1; i <= n; i++)
        for(int j = i+1; j <= n; j++){
            ans[dist[i][j]]++;
        }
    for(int i = 1; i < n; i++){
        printf("%d\n" , ans[i]);
    }

}


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

const int INF = 1e9;

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

  int l_ans = 0;
  int r_ans = n+1;
  for (int i=0; i<m; i++) {
    int li, ri;
    cin>>li>>ri;
    l_ans = max(l_ans, li);
    r_ans = min(r_ans, ri);
  }
  if (r_ans >= l_ans) {
    cout<<r_ans-l_ans+1<<endl;
  } else {
    cout<<0<<endl;
  }

}

Measured memory_bytes: 256
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    total = sum([abs(A[i + 1] - A[i]) for i in range(n - 1)])
    for i in range(n):
        if i == 0:
            start = abs(A[1])
            end = abs(A[-1])
            print(total - abs(A[1] - A[0]) + start + end)
        elif i == n - 1:
            start = abs(A[0])
            end = abs(A[-2])
            print(total - abs(A[-2] - A[-1]) + start + end)
        else:
            start = abs(A[0])
            end = abs(A[-1])
            print(total - abs(A[i - 1] - A[i]) -
                  abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i - 1])
                  + start + end)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20692
Module _20190420

    Sub Main()

        '入力を受け取る
        Dim a As String = Console.ReadLine()


        '数値に分解
        Dim Int1 As Integer = CInt(a.Split(" ")(0))
        Dim Int2 As Integer = CInt(a.Split(" ")(1))

        If Int1 = Int2 Then

            '出力
            Console.WriteLine(Int1 + Int2)

        End If

        If Int1 > Int2 Then

            '出力
            Console.WriteLine(Int1 + Int1 - 1)

        End If

        If Int2 > Int1 Then

            '出力
            Console.WriteLine(Int2 + Int2 - 1)


        End If

    End Sub

End Module

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

int main(){
    int h,w,d; cin>>h>>w>>d;
    int a;
    int ah[90001]={0},aw[90000]={0};
    FOR(i,0,h){
        FOR(j,0,w){
            cin>>a;
            ah[a-1]=i;
            aw[a-1]=j;
        }
    }
    int q; cin>>q;
    int l[100000]={0}, r[100000]={0};
    FOR(i,0,q){
        cin>>l[i]>>r[i];
    }
    int cost[90001]={0};
    FOR(i,d,h*w){
        cost[i]=cost[i-d]+abs(ah[i]-ah[i-d])+abs(aw[i]-aw[i-d]);
    }
    int ans=0;
    FOR(i,0,q){
        cout<<cost[r[i]-1]-cost[l[i]-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 2944
import sys
import heapq


def input():
    return sys.stdin.readline().strip()


def dijkstra(start, n_nodes, edge):
    dist = [float("inf")] * n_nodes
    prev = [-1] * n_nodes
    dist[start] = 0
    # 優先度キューの準備
    q = [(dist[start], start)]
    heapq.heapify(q)
    while q:
        # スタートから最も最短距離のものを取り出す
        d, i = heapq.heappop(q)
        # 記録してある情報よりも，取り出した要素に入っている距離情報の方が大きければ
        # 打ち切り．次の要素を取り出す操作に戻る
        if dist[i] < d:
            continue
        # そこから移動できる頂点を探し，最短距離が更新できるものがあれば，
        # 距離を更新して，その頂点への距離と頂点の方法を優先度キューにpush
        for cost, j in edge[i]:
            if dist[j] > dist[i] + cost:
                dist[j] = dist[i] + cost
                prev[j] = i
                heapq.heappush(q, (dist[j], j))
    return dist, prev


def main():
    N, M = map(int, input().split())
    node = [[] for _ in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        node[a - 1].append((1, b - 1))
        node[b - 1].append((1, a - 1))
    d, p = dijkstra(0, N, node)
    for i in range(N):
        if d[i] == float("inf"):
            print("No")
            return
    print("Yes")
    for i in range(1, N):
        print(p[i] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 64112
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int a[100005],n; 
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	rep(i,0,n)cin>>a[i];
	int ans=-1e17,l,r,t;
	rep(i,1,n){
		l=0;r=n-1;t=0;
		if(r%i==0){
			while(l<r){
				t+=a[l]+a[r];
				gmax(ans,t);
				l+=i;r-=i;
			}
		}else{
			while(r>i){
				t+=a[l]+a[r];
				gmax(ans,t);
				l+=i;r-=i;
			}
		}
	}
	cout<<ans<<'\n';
	RE 0;
}




Measured memory_bytes: 1024
using System;
using System.Linq;
class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        string r = "";
        bool b;
        if (s.Contains(t)) r = s.Replace('?', 'a');
        for (int i = s.Length - t.Length; i >= 0; i--)
        {
            b = true;
            for (int j = 0; j < t.Length; j++)
            {
                if (!(s[i + j] == '?' || t[j] == s[i + j]))
                {
                    b = false;
                    break;
                }
            }
            if (b)
            {
                char[] rarray = s.Replace('?', 'a').ToArray();
                for (int j = 0; j < t.Length; j++)
                {
                    rarray[i + j] = t[j];
                }
                r = new string(rarray);
                break;
            }
        }
        if (r == "")
        {
            r = "UNRESTORABLE";
        }
        Console.WriteLine(r);
    }
}

Measured memory_bytes: 13268
#!/usr/bin/env python3
import sys
from collections import deque
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(K: int):

    h = deque([])

    for i in range(1, 10):
        h.append(i)

    for i in range(K-1):
        s = h.popleft()
        for j in range(-1, 2):
            add = (s % 10)+j
            if 0 <= add <= 9:
                h.append(s*10+add)
    print(h.popleft())
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12404
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
#define mod 1000000007
typedef long long ll;

/*
unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}
*/


int main(){


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

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len;
	ll C, D, N, M, K, num_R, num_G, num_B, temp;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count = 0, Q, W, X, flag=0;
	ll  A, B, *H, *ans;



	ll temp1, temp2;


	cin >> X;
	


	for (i = -200; i <= 200; i++){
		for (j = -200; j <= 200; j++){
			if ((i*i*i*i*i - j*j*j*j*j) == X){
				cout << i << " " << j << endl;
				return 0;
			}

		}
	}

//	cout << "nakatta" << endl;
	return 0;


}//1 2 3 4 5 6
    

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vint p(n);
    rep(i, n) {
        cin >> p[i];
        --p[i];
    }
    UnionFind uf(n);
    int x, y;
    rep(i, m) {
       cin >> x >> y;
       uf.unite(--x, --y);
    }
    int ans = 0;
    rep(i, n) {
        if (i == p[i] || uf.same(i, p[i])) ans++;
    }

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

Measured memory_bytes: 1024
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[float('inf')]*n
def sub(l):
  return(abs(l-h[0]))
if n-1<=k:
  lst=list(map(sub,h))
  del lst[0]
  print(min(lst))
  sys.exit()  
c[0]=0
m=n-k
for i in range(m):
  for j in range(1,k+1):
    c[i+j]=min(c[i+j],c[i]+abs(h[i+j]-h[i]))
    
for i in range(n-k,n-1):
  for j in range(1,n-i):
    c[i+j]=min(c[i+j],c[i]+abs(h[i+j]-h[i]))
print(c[n-1])

  


Measured memory_bytes: 55648
import java.util.Scanner;

public class Main {

	private Main() {
		Scanner in = new Scanner(System.in);
		long a,b;
		while(in.hasNext()){
			a = in.nextInt();
			b = in.nextInt();
			System.out.println(gcd(a,b)+" "+lcm(a,b));
		}
	}

	public long gcd(long a, long b) {
		if(a==b){
			return a;
		} else if(a>b) {
			return gcd(b,a-b);
		} else {
			return gcd(a,b-a);
		}
	}

	public long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}

	public static void main(String[] args) {
		new Main();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
/*----------------------------------------------------------------------*/

const int N = 1e5+5;
int h[N],dp[N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    int n,k;
    cin>>n>>k;
    F(i, 1, n+1) {
    	cin>>h[i];
    	dp[i]=INF;
    }
    dp[1]=0; dp[2]=abs(h[2]-h[1]);
    F(i, 3, n+1) {
    	int val = INT_MAX;
    	F(j, 1, k+1) {
    		if(i-j > 0) {
    			val = min(val, dp[i-j] + abs(h[i]-h[i-j]));
    		}
    	}
    	dp[i]=val;
    }
    cout<<dp[n];

    return 0;
}/*

*/


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int H, W;
int m[100][100];

void del(int x, int y, int k) {
	if (x < 0 || x >= W || y < 0 || y >= H) return;
	if (m[y][x] != k) return;

	m[y][x] = 0;

	del(x+1, y, k);
	del(x-1, y, k);
	del(x, y+1, k);
	del(x, y-1, k);
}

int main() {
	while (cin >> H >> W, H || W) {
		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x)
				m[y][x] =
					  str[x] == '#' ? 1
					: str[x] == '@' ? 2
					: str[x] == '*' ? 3
					: 0
					;
		}

		int ans = 0;
		for (int y = 0; y < H; ++y)
			for (int x = 0; x < W; ++x)
				if (m[y][x]) {
					++ans;
					del(x, y, m[y][x]);
				}


		cout << ans << endl;
	}
}

Measured memory_bytes: 1876
#include <stdio.h>

void show(int* taro, int n, int* hana, int m){
  int i;
  printf("taro:"); for(i=0;i<n;i++) printf("%d ", taro[i]); printf("\n");
  printf("hana:"); for(i=0;i<m;i++) printf("%d ", hana[i]); printf("\n");
}

int sum(int* arr, int len) {
  int i, sum=0;
  for(i=0;i<len;i++) sum+=arr[i];
  return sum;
}

int member(int* arr, int len, int el){
  int i;
  for(i=0;i<len;i++)
    if(arr[i]==el) return 1;

  return 0;
}

void solve(int* taro, int n, int* hana, int m){
  int sub = sum(taro,n)-sum(hana,m);
  int i, min=200, tt, hh, t=-1, h=-1;

  if(sub%2 != 0) {
    printf("-1\n");
    return;
  }
  
  for(i=0;i<n;i++){
    tt=taro[i];
    hh=-sub/2+tt;
    if(member(hana, m, hh) && (min>tt+hh)){
      min = tt+hh;
      t = tt;
      h = hh;
    }
  }

  if(t!=-1 && h!=-1)
    printf("%d %d\n", t, h);
  else
    printf("-1\n");

  return;
}

int main(){
  int i, n, m, taro[100], hana[100];

  while(1){
    scanf("%d %d", &n, &m);
    if(n==0 && m==0) break;

    for(i=0;i<n;i++) scanf("%d", &taro[i]);
    for(i=0;i<m;i++) scanf("%d", &hana[i]);
    
    solve(taro, n, hana, m);
  }
  
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

string s,t;
int m[27],pos[27];

int main()
{
	SPEED;
	cin>>s>>t;
	for(int i=0;i<27;i++)m[i] = i,pos[i] = i;
	for(int i=0;i<s.size();i++){
		if(m[s[i]-'a']!=(t[i]-'a')){
			swap(m[pos[t[i]-'a']],m[s[i]-'a']);
			swap(pos[m[pos[t[i]-'a']]],pos[m[s[i]-'a']]);
		}
	}
	for(int i=0;i<s.size();i++){
		if(m[s[i]-'a']!=(t[i]-'a')){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 916
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb emplace_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 31000000
// #define M 19
 
// #define mod  11092019
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef int ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll mul(ll a, ll b, ll mod) { return (long long) a*b%mod;}
inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b: a+b-mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
	return ret;
}
static inline void read(ll &x) { cin>>x;}

int main(){
	fastio;
	ll a, b, c, d, e;
	cin>>a>>b>>c>>d>>e;
	vi v;
	v.pb(a), v.pb(b), v.pb(c), v.pb(d), v.pb(e);
	FER(i, 0, 5){
		if(v[i] == 0){
			cout<<i+1<<"\n";
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

#define INF (1<<29)

int main()
{
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; ; j++) {
	int c = a[i] * j;
	if (c > m) break;
	b[i] = c;
      }      
    }
    int bmin = *min_element(b.begin(), b.end());

    vector<int> num;
    for (int i = 0; i < n; i++) {
      if (bmin == b[i]) {
	num.push_back(i);
      }
    }
    
    if (num.size() == 1) {
      cout << num[0] + 1 << endl;
    } else {
      int amin = INF;
      for (int i = 0; i < (int)num.size(); i++) {
	amin = min(amin, a[num[i]]);
      }
      vector<int> num2;
      for (int i = 0; i < (int)num.size(); i++) {
	if (amin == a[num[i]]) {
	  num2.push_back(num[i]);
	}
      }
      if (num2.size() == 1) {
	cout << num2[0] + 1 << endl;
      } else {
	cout << n << endl;
      }
    }
  } 
  return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int a[100000];
	rep(i,n) scanf("%d",a+i);

	int mx=*max_element(a,a+n),mid=0;
	rep(i,n) if(abs(2*a[i]-mx)<abs(2*mid-mx)) mid=a[i];
	printf("%d %d\n",mx,mid);

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
int n, k;
const int maxn = 300000;
int p[maxn], s[maxn], b[maxn];
int pre[maxn];
#define valid(l, r) (p[l] == s[l] and p[r] == b[r])
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	for(int i = 1;i <= n;++i)cin >> p[i];
	p[0] = -1;
	{
		deque<pair<int,int>> mon;
		for(int i = 1, j = 1;i <= n;++i){
			while(mon.size() and mon.front().second < i)mon.pop_front();
			for(;j <= n and j-k < i;++j){
				while(mon.size() and mon.back().first <= p[j])mon.pop_back();
				mon.emplace_back(p[j], j);
			}
			b[i] = mon.front().first;
		}
	}
	{
		deque<pair<int,int>> mon;
		for(int i = 1, j = 1;i <= n;++i){
			while(mon.size() and mon.front().second < i)mon.pop_front();
			for(;j <= n and j-k < i;++j){
				while(mon.size() and mon.back().first >= p[j])mon.pop_back();
				mon.emplace_back(p[j], j);
			}
			s[i] = mon.front().first;
		}
	}
	for(int i = 1;i <= n;++i)pre[i] = pre[i-1] + (p[i] < p[i-1]);
	int non = 0, cnt = 0;
	for(int l = 1, r = k;r <= n;++l, ++r){
		if(s[l-1] != p[l-1] || b[l] != p[r]){
			if(pre[r]-pre[l])++cnt;
			else non = 1;
		}
	}
	cout << non + cnt << '\n';
}	

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S ="",T="";
  int A=0,B=0;
  string U="";
  cin >> S >> T >>A>>B>>U;
 
 if(U==S){
     A--;
 }
 else if(U==T){
     B--;
 }
 
  cout << A <<" "<<B << endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0 && a[i] % 2 != 0) ++res;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3628
class Counter(dict):
    def __missing__(self, i):
        return 0

n = int(input())
a = list(map(int, input().split()))
q = int(input())

total = sum(a)

bucket = Counter()

for item in a:
    bucket[item] += 1

for i in range(q):
    b, c = map(int, input().split())
    taken = bucket[b]
    total -= bucket[b]*b
    bucket[c] += bucket[b]
    bucket[b] = 0
    total += taken*c
    print(total)


Measured memory_bytes: 88160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int pt[123456], n;
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
signed main() {
	int n, q; cin >> n >> q;
	for (int i = 0; i < n; i++)pt[i] = i;
	for (int i = 0; i < q; i++) {
		int a, b, c; cin >> a >> b >> c;
		if (a)cout << (root(b) == root(c) ? 1 : 0) << endl;
		else unite(b, c);
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	vector<ll> a(n);REP(i, n)cin >> a[i];
	vector<ll> b(n);REP(i, n)cin >> b[i];
	vector<ll> c(n);REP(i, n)c[i] = i+1;

	ll aa = 0;
	ll bb = 0;
	do {
		//SHOW1d(c, n);
		REP(i, n){
			if(a[i] < c[i]){
				aa++;
				break;
			}
			else if(a[i] > c[i])break;
		}
		REP(i, n){
			if(b[i] < c[i]){
				bb++;
				break;
			}
			else if(b[i] > c[i])break;
		}
	}while(next_permutation(ALL(c)));

	cout << abs(aa - bb) << endl;

	return 0;
}


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

class Edge {
public:
	int v1, v2, d;
};

int n, k=0, V[100];
Edge E[5000];

void Sort() {
	for (int i = 1; i < k; i++) {
		Edge v = E[i];
		int j = i - 1;
		while (j >= 0 && E[j].d > v.d) {
			E[j + 1] = E[j];
			j--;
		}
		E[j + 1] = v;
	}
}

int Kruskal() {
	int m = 0;
	for (int i = 0; i < k; i++) {
		Edge e = E[i];
		if (V[e.v1] != V[e.v2]) {
			int v = V[e.v1], u = V[e.v2]; m += e.d;
			for (int j = 0; j < n; j++) {
				if (V[j] == u) V[j] = v;
			}
		}
	}
	return m;
}

int main() {
	int g;
	cin >> n;
	for (int i = 0; i < n; i++) {
		V[i] = i;
		for (int j = 0; j < n; j++) {
			cin >> g;
			if (i < j && g > -1) {
				E[k].v1 = i; E[k].v2 = j; E[k].d = g; k++;
			}
		}
	}

	Sort();

	cout << Kruskal() << endl;
}


Measured memory_bytes: 3148
loop do
  ans = 0
  a, b, c = [1, 2, 3]
  n, x = gets.split.map(&:to_i)
  break if n == 0 && x == 0
  loop do
    ans += 1 if a + b + c == x
    if c < n && a + b + c < x
      c += 1
    else
      if b+1 == c
        if a+1 == b
          break
        else
          a += 1
          b = a+1
          c = b+1
        end
      else
        b += 1
        c = b+1
      end
    end
  end
  puts ans
end

Measured memory_bytes: 6104
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    cnt = [0] * N
    mx = int(N ** 0.5)
    for x in range(1, mx):
        for y in range(1, mx):
            Z = N - (x ** 2 + y ** 2 + x * y)
            if Z <= 0: continue
            Z = int(Z ** 0.5)
            for z in range(1, Z + 1):
                n = f(x, y, z)
                if n <= N:
                    cnt[n - 1] += 1

    for c in cnt:
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;
    vector<ll>arr(n);
    for(ll i=0;i<n;i++)cin>>arr[i];
    ll x=arr[0];
    for(ll i=1;i<n;i++)x^=arr[i];
    vector<ll>ans;
    for(ll i=0;i<n;i++){
        ans.push_back(x^arr[i]);
    }
    for(auto i:ans)cout<<i<<" ";
    return 0;
}


Measured memory_bytes: 6788
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=20010,M=210;
const int mod=998244353;
int f[M][N];int a[N],b[N],cj[N],inv[N],Root[N],IRoot[N],bitrev[N];
int INV,curn,L;int ans;int n,m;

int power(int x,int y){
	int ret=1;
	for(;y;y>>=1,x=1ll*x*x%mod){
		if(y&1)	ret=1ll*ret*x%mod;
	}
	return ret;
}

void init(){
	int i;
	cj[0]=1;rep(i,1,n)	cj[i]=1ll*cj[i-1]*i%mod;
	inv[n]=power(cj[n],mod-2);inv[0]=1;
	for(i=n-1;i;i--)	inv[i]=1ll*inv[i+1]*(i+1)%mod;
	for(curn=1,L=0;curn<2*n;curn<<=1,L++);
	rep(i,0,curn-1)	bitrev[i]=bitrev[i>>1]>>1|((i&1)<<L-1);
	Root[0]=IRoot[0]=1;
	Root[1]=power(3,(mod-1)/curn);IRoot[1]=power(Root[1],mod-2);
	rep(i,2,curn)	Root[i]=1ll*Root[i-1]*Root[1]%mod;
	rep(i,2,curn)	IRoot[i]=1ll*IRoot[i-1]*IRoot[1]%mod;
	INV=power(curn,mod-2);
}
	
void DFT(int a[],int n,int w[]){
	int i,j,k,x,y;
	rep(i,0,n-1)	if(i<bitrev[i])	swap(a[i],a[bitrev[i]]);
	for(i=1;i<n;i<<=1){
		for(j=0;j<n;j+=(i<<1)){
			for(k=0;k<i;k++){
				x=a[j+k];y=1ll*a[j+k+i]*w[curn/(i<<1)*k]%mod;
				a[j+k]=(x+y)%mod;a[j+k+i]=(x-y+mod)%mod;
			}
		}
	}
}

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	register int i,j;
	scanf("%d%d",&n,&m);
	init();
	rep(j,0,n-2)	b[j]=inv[j+2];
	DFT(b,curn,Root);
	f[m+1][0]=1;
	for(i=m;i;i--){
		rep(j,0,n)	f[i][j]=1ll*(n-j+1)*f[i+1][j]%mod;
		rep(j,0,n)	a[j]=1ll*cj[n-j]*f[i+1][j]%mod;
		rep(j,n+1,curn-1)	a[j]=0;
		DFT(a,curn,Root);
		rep(j,0,curn-1)	a[j]=1ll*a[j]*b[j]%mod;
		DFT(a,curn,IRoot);
		rep(j,0,n-2) f[i][j]=(f[i][j]+1ll*a[j]*INV%mod*inv[n-j-2])%mod;
	}
	//for(i=m;i;i--)	rep(j,0,n)	printf("f[%d][%d]=%d\n",i,j,f[i][j]);
	rep(i,0,n)	ans=(ans+f[1][i])%mod;
	printf("%d\n",ans);
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		

Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


ll dp[3001][3001];

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

    string s, t;
    vector<int> ind;
    cin >> s >> t;

    int slen = s.length();
    int tlen = t.length();

    s = " " + s;
    t = " " + t;

    dp[0][0] = 0;
    
    rep(i, slen){
        rep(j, tlen){
            if(s[i+1] == t[j+1]) dp[i+1][j+1] = dp[i][j] + 1;
            else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }

    int ss=slen, tt=tlen;
    string res = "";
    while(ss>=1 && tt>=1){
        if(s[ss] == t[tt]){
            res = s[ss] + res;
            ss--; tt--;
        }else{
            if(dp[ss-1][tt] > dp[ss][tt-1]) ss--;
            else tt--;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  bool flag = false;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=="Y") flag=true;
  }
  if(flag) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		m[a] = i + 1
	}
	var buffer bytes.Buffer
	for i := 1; i <= n; i++ {
		buffer.WriteString(strconv.Itoa(m[i]))
		if i != n {
			buffer.WriteString(" ")
		}
	}
	fmt.Println(buffer.String())
}

Measured memory_bytes: 8704
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, M;
	std::vector<int> result;

	std::cin >> N >> M;
	result.resize(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		std::cin >> a >> b;
		++result[a-1];
		++result[b-1];
	}

	for (auto r : result) {
		std::cout << r << "\n";
	}
}


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

int main(){
    int a=0,b=0;
    for (int i = 0; i < 4; ++i) {
        int t;
        cin>>t;
        a+=t;
    }
    for (int i = 0; i < 4; ++i) {
        int t;
        cin>>t;
        b+=t;
    }
    cout<<max(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 3096
main = interact $ unlines . map (show . joseph . map read . words) . init . lines

joseph [n,m] = joseph' [1..n]
 where
  joseph' [x] = x
  joseph' xs = joseph' (filter (/= x) (take (length xs) xs'))
   where (x:xs') = (drop (m-1) (cycle xs))

Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

#define PI 3.141592653589793

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

    int a, b, h, m; cin >> a >> b >> h >> m;
    double degh = 0;
    rep(i, h) degh += 30.0;
    rep(i, m) degh += 0.5;

    debug(degh);
    double radh = degh * PI / 180.0;
    double yh = cos(radh)*a;
    double xh = tan(radh)*yh;
    // cout << fixed << setprecision(10) << xh << " " << yh << endl;

    double degm = 0;
    rep(i, m) degm += 6;
    double radm = degm * PI / 180.0;
    double ym = cos(radm)*b;
    double xm = tan(radm)*ym;
    // cout << fixed << setprecision(10) << xm << " " << ym << endl;

    double ans = pow((xh-xm)*(xh-xm)+(yh-ym)*(yh-ym), 0.5);
    cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 4436
#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 FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int a,b,c;cin >> a >> b >> c;
   if((a == b) && (b == c) && (c == a))cout << "Yes";
   else cout << "No";
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

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

int main() {
  string s, t;
  cin >> s >> t;
  Rep(i, s.size()) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main(){
	
	string S;

    cin >> S;
    int count = 0;
    for (int i = 0 ; i < S.length()/2; i++){
        if (S[i] != S[S.length()-1-i]){
            count++;
        }
    }

    cout << count << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    double a ,b;
    int l[4] = {0}, r[4] = {0};
    while(cin >> a >> b){
        if(a >= 1.1){
            l[0]++;
        }else if(a < 1.1 && a >= 0.6){
            l[1]++;
        }else if(a < 0.6 && a >= 0.2){
            l[2]++;
        }else if(a < 0.2){
            l[3]++;
        }
        if(b >= 1.1){
            r[0]++;
        }else if(b < 1.1 && b >= 0.6){
            r[1]++;
        }else if(b < 0.6 && b >= 0.2){
            r[2]++;
        }else if(b < 0.2){
            r[3]++;
        }
    }
    rep(i,4){
        cout << l[i] << ' ' << r[i] << endl;
    }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
bool cmp(long long n,long long m)
{
	return n > m;
}
int main()
{
	long long x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	long long s1[a+1], s2[b+1], s3[c+1];
	for (long long i=1; i<=a; i++) cin >> s1[i];
	for (long long i=1; i<=b; i++) cin >> s2[i];
	for (long long i=1; i<=c; i++) cin >> s3[i];
	sort (s1+1, s1+a+1, cmp);
	sort (s2+1, s2+b+1, cmp);
	sort (s3+1, s3+c+1, cmp);
	long long p[x+y+c+1];
	for (long long i=1; i<=x; i++) p[i]=s1[i];
	for (long long i=x+1; i<=x+y; i++) p[i]=s2[i-x];
	for (long long i=x+y+1; i<=x+y+c; i++) p[i]=s3[i-x-y];
	sort (p+1, p+x+y+c+1, cmp);
	long long t=0;
	for (long long i=1; i<=x+y; i++) t+=p[i];
	cout << t << endl;
	return 0;
}

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

struct UnionFind{
    vector<int> par;
    
    UnionFind(int n): par(n,-1){}
    
    int root(int x){
        if(par[x] < 0)return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x,int y){
        return root(x) == root(y);
    }
    
    bool merge(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y)return false;
        if(par[x] > par[y])swap(x,y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x){
        return -par[root(x)];
    }
    
};

using pint = pair<int,int>;
int main(){
    int N,M,K;
    cin >> N >> M >> K;
    vector<set<int>> dame(N);
    UnionFind uf(N);
    
    for(int i = 0; i < M; i++){
        int a,b; cin >> a >> b; --a,--b;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a,b);
    }
    
    for(int i = 0; i < K ; ++i){
        int c,d; cin >> c >> d; --c, --d;
        if(!uf.issame(c,d))continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }
    
    for(int i = 0; i < N; ++i){
        int mem = uf.size(i) - 1;
        mem -= dame[i].size();
        cout << mem << " ";
    }
    cout << endl;
}


Measured memory_bytes: 24704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){

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

    int h,w,n; cin>>h>>w>>n;
    vector<vector<int>> vec(w,vector<int>(1,-1));
    rep(i,n){
        int x,y; cin>>x>>y;
        vec.at(y-1).push_back(x-1);
    }
    rep(i,w){
        sort(all(vec.at(i)));
        vec.at(i).push_back(h);
    }

    int ans=vec.front().at(1);
    vector<int> first(w,INF);
    first.front()=0;
    for(int i=1; i<w; i++){
        int tmp=first.at(i-1)+1;
        if(tmp>=h)break;
        rep(j,vec.at(i).size()-1){
            if(vec.at(i).at(j+1)>tmp and vec.at(i).at(j)<vec.at(i).at(j+1)-1){
                first.at(i)=max<int>(tmp,vec.at(i).at(j)+1);
                break;
            }
        }
    }

    for(int i=1; i<w; i++){
        // cout<<first.at(i)<<' '<<lower_bound(all(vec.at(i)),first.at(i))-vec.at(i).begin()<<endl;
        if(first.at(i)==INF)continue;
        chmin(ans,vec.at(i).at(lower_bound(all(vec.at(i)),first.at(i))-vec.at(i).begin()));
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 16768
import collections as c
ip = lambda : map(int, input().split())

#################
N = int(input())
count_ab = 0
unchi = 0
clis = [0,0,0] # [f,b,f and b]

for i in range(N):
    s = input()
    if s[0] == 'B' and s[-1] == 'A':
        clis[2] += 1
    elif s[0] == 'B':
        clis[0] += 1
    elif s[-1] == 'A':
        clis[1] += 1
    for i in range(len(s)-1):
        if s[i:i+2] == 'AB':
            count_ab+=1
if clis[0] == 0 and clis[1] == 0 and clis[2] > 0:
    unchi = -1

#print(count_ab,clis)
print(min(clis[0:2]) + clis[2] + count_ab + unchi)

Measured memory_bytes: 3316
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
	int n;
	cin>>n;
	int ans=3;

	for (int i=1;i<=n;i++){
		string s;
		cin>>s;
		if (s=="Y"){
			ans=4;
		}
	}
	if (ans==4) cout<<"Four";
	else cout<<"Three";
	
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		char direction[]=new char[N];
		String people=sc.next();
		for(int i=0;i<N;i++) {
			direction[i]=people.charAt(i);
		}
		//System.out.println(direction);
		System.out.println(happiness(direction,K));
	}
	public static int happiness(char[] directions,int K) {
		int happy=0;
		int k=0;
		for(int i=0;i<directions.length;i++) {
			if(i==0) {
				if(directions[0]=='R'&&directions[1]=='R')happy++;
			}else if(i==directions.length-1) {
				if(directions[i]=='L'&&directions[i-1]=='L')happy++;
			}else {
				if(directions[i]=='R'&&directions[i+1]=='R') {
					happy++;
				}
				if(directions[i]=='L'&&directions[i-1]=='L') {
					happy++;
				}
			}
			if(i!=0) {
				if(directions[i-1]!=directions[i]) {
					k++;
				}
			}
		}
		//System.out.println(k+","+happy);
		if(K*2<k) {
			happy+=K*2;
		}else {
			happy+=k;
		}
		return happy;
	}


}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

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

    char c[200005];
    for(ll i = 0; i < n; i++) {
        cin >> c[i];
    }

    // 全部白
    ll cnt1 = 0;
    for(ll i = 0; i < n; i++) {
        if(c[i] == 'R') {
            cnt1++;
        }
    }

    // 全部赤
    ll cnt2 = 0;
    for(ll i = 0; i < n; i++) {
        if(c[i] == 'W') {
            cnt2++;
        }
    }

    // 左に赤を持っていく
    ll cnt3 = 0;
    for(ll i = 0; i < cnt1; i++) {
        if(c[i] == 'W') {
            cnt3++;
        }
    }

    minc = min(cnt1, cnt2);
    minc = min(minc, cnt3);
    cout << minc << endl;

    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
T GCD(T x, T y)
{
    if (x < y)
    {
        const T a = x;
        x = y;
        y = a;
    }
    T b = 100000;
    while (b)
    {
        b = x % y;
        x = y;
        y = b;
    }
    return x;
}
template<typename T>
T lcm(T x, T y)
{
    T g = GCD(x, y);
    return x / g * y;
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    ll divac = a / c;
    ll divad = a / d;
    ll divbc = b / c;
    ll divbd = b / d;
    ll divacd = a / lcm(c,d);
    ll divbcd = b / lcm(c,d);
    ll adivable = divac + divad - divacd;
    ll bdivable = divbc + divbd - divbcd;
    cout << (b - a) -(bdivable - adivable) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod =1e9+7;
ll qui(ll n,ll m){
    ll ans =1;
    while(m){
        if(m&1){
            ans *=n;
            ans %=mod;
        }
        m >>=1;
        n *=n;
        n %=mod;
    }
    return ans;
}
int main(){
    ll n;
    cin>>n;
    ll res =qui(10,n)-qui(9,n)*2+qui(8,n);
    res =(res%mod+mod)%mod;
    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 3604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>


using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

class AABD {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a;
    string ans = "ABC";
    cin >> a;
    if(a>=1000) ans = "ABD";
    cout << ans << endl;
}
};


int main() {
	AABD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3568