akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int 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);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";
   
void solve(long long a, long long b, long long c){
  if((c-a-b) < 0){cout << NO << endl; return;}
else cout << (4*a*b < (c-a-b)*(c-a-b) ? YES : NO) << endl;
}  

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    solve(a, b, c);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		if(N==25) {
			System.out.println("Christmas");
		}
		if(N==24) {
			System.out.println("Christmas Eve");
		}
		if(N==23) {
			System.out.println("Christmas Eve Eve");
		}
		if(N==22) {
			System.out.println("Christmas Eve Eve Eve");
		}
	}
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

string S, T;

bool isSame(int start) {
    int ind = start;
    for(int i = 0; i < S.length(); ++i) {
        if(T[i] != S[ind]) { return false; }
        ind++;
        if(ind >= S.length()) { ind = 0; }
    }
    return true;
}

signed main()
{
    cin >> S >> T;

    for(int i = 0; i < S.length(); ++i) {
        if(isSame(i)) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

int main()
{
    string s;
    cin >> s;

    if (s.size() < 4)
    {
        cout << "No" << endl;
        return 0;
    }
    if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int A=scan.nextInt();
        int B=scan.nextInt();
        int C=scan.nextInt();
        if(B==1){
            System.out.println("YES");
        }
        else if(A%2==0&&B%2==0&&C%2==1){
            System.out.println("NO");
        }
        else{
            int i;
            for(i=1;i<B;i++){
                if((A*i)%B==C){
                    System.out.println("YES");
                    return ;
                }
            }
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22996
# coding: utf-8
class Dice:
    
    def __init__(self):
        self.data = {"bottom":5, "west": 3, "north" : 4,
                "east": 2, "south" : 1,"top" : 0}
    
    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self,*s):
        for ch in s:
            self.moveOne(ch)
      
    def getSurface(self):
        return self.data["top"]
        
    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])


num = list(map(int,input().rstrip().split()))
s = input().rstrip()
dice = Dice()
dice.movePart(*s)
ret = dice.getSurface()
print(num[ret])


Measured memory_bytes: 5620
from collections import defaultdict
def f(s):
  return int(s) - 1

N, K = map(int, input().split())
P = list(map(f, input().split()))
C = list(map(int, input().split()))

loop = []

first = -1
x = -1
loop_mem = []
cnt = 0
score = 0

rem = set(range(N))

while len(rem) > 0:
  if first < 0:
    first = rem.pop()
    x = first
  loop_mem.append(x)
  if x != first:
    rem.remove(x)
  cnt += 1
  score += C[x]
  if first != P[x]:
    x = P[x]
  else:
    loop.append((loop_mem, cnt, score))
    first = -1
    loop_mem = []
    cnt = 0
    score = 0

ans = -1e10
for loop_mem, cnt, score in loop:
  imax = [-1e10 for _ in range(cnt)]
  imax[0] = 0
  for x in loop_mem:
    tmp = 0
    for j in range(1, cnt):
      tmp += C[x]
      imax[j] = max(imax[j], tmp)
      x = P[x]
  for j in range(2, cnt):
    imax[j] = max(imax[j-1], imax[j])
  if score <= 0:
    ans = max(ans, imax[-1])
  else:
    M = K // cnt
    m = K % cnt
    if M >= 1:
      tmp = max(score * M + max(imax[m], 0), score * (M-1) + imax[-1])
    else:
      tmp = imax[m]
    ans = max(ans, tmp)

print(ans)


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

int n,m,l,r,pre=0,ans=0;
int cf[100005];

signed main()
{
	cin>>m>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>l>>r;
		cf[l]++;
		cf[r+1]--;
	}
	for (int i=1;i<=m;i++)
	{
		pre+=cf[i];
		if (pre>=n)  ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  string sl = s.substr(0, s.size() / 2);
  string sr = s.substr(s.size() / 2 + s.size() % 2, s.size() - 1);
  reverse(sr.begin(), sr.end());
  int count = 0;
  rep(i, sl.size()) if (sl[i] != sr[i]) count++;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
map<int, int> mp;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (mp.find(x) == mp.end()) mp[x] = 0;
		mp[x]++;
	}
	vector<PII> v;
	for (auto p : mp) {
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	if (mp.find(0) == mp.end()) {
		if (mp.size() != 3) cout << "No\n";
		else if ((v[0].first ^ v[1].first) != v[2].first) cout << "No\n";
		else if (v[0].second != v[1].second || v[0].second != v[2].second) cout << "No\n";
		else cout << "Yes\n";
	} else {
		if (mp.size() == 1) cout << "Yes\n";
		else if (mp.size() == 2) {
			if (v[1].second % 2 != 0 || (v[0].second < v[1].second/2)) cout << "No\n";
			else cout << "Yes\n";
		} else cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 4988
// Problem : A - Circle Pond
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int r;
	cin >> r;
	cout << fixed << setprecision(20) << r * M_PI * 2 << endl;
	return 0;
}
 


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n,k,q; cin >> n >> k >> q;
    vector<int> a(q);
    map<int ,int > score;
    rep(i,q) {
        cin >> a[i];
        score[a[i]]+=1;
    }
    FOR(i,1,n) {
        score[i] += k-q;
        cout <<  (score[i] >0 ? "Yes" :"No") << endl; 
    }


}


Measured memory_bytes: 5760
X, N = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
min_abs = 100
for i in range(102):
    if i not in p:
        min_abs = min(min_abs, abs(X-i))

if X - min_abs not in p:
    print(X - min_abs)
else:
    print(X + min_abs)





Measured memory_bytes: 9172
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;

int main(void){
    int n; cin >> n;
    vector<int> L(n);
    for (int i = 0; i < n; i++) {
        cin >> L[i];
    }
    
    sort(L.begin(), L.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int ab = L[i]+L[j];
            int right = lower_bound(L.begin(), L.end(), ab) - L.begin();
            int left = j+1;
            ans += right - left;
        }
    }
    cout << ans << endl;
    
}


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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/////////////////////

int const N = 2e5 + 41;
int const K = 26;

int n;
string s;
int nxt[N][K];
string ans;

int d[N][K], dp[N];

void solve(){
	cin >> s;
	n = sz(s);
	fr(i, 0, N) fr(k, 0, K) nxt[i][k] = N;
	fdr(i, 0, n){
		if(s[i] >= 'a' && s[i] <= 'z') nxt[i][s[i]-'a'] = i;
		fr(j, 0, K) nxt[i][j] = min(nxt[i][j], nxt[i+1][j]);
	}

	fr(i, 0, N) fr(k, 0, K) d[i][k] = 1, dp[i] = 0;

	fdr(i, 0, n){
		if(i == 0){
			int as = 1;
		}
		fdr(k, 0, K){
			int np = nxt[i][k];
			if(np != N){
				np += 1;
				d[i][k] = 1 + d[np][dp[np]];
			}else{
				d[i][k] = 1;
			}
		}
		fr(k, 0, K){
			if(d[i][k] < d[i][dp[i]]) dp[i] = k;
		}
	}

	string ans = "";
	int p = 0;
	while(p < n){
		ans += (char)(dp[p] + 'a');
		p = nxt[p][dp[p]] + 1;
	}

	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    if (tmp == "Y") {
      cout << "Four" << endl;
      exit(0);
    }
  }
  
  cout << "Three" << endl;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int x, y; scan(x, y);
      Int res = y - x + y;
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int S, h, m, s;
   
   cin >> S ;
   h=S/3600;
   m=S%3600/60;
   s=S%60;
   cout << h << ":" << m << ":" << s << endl;
   
   
   return 0;
}


Measured memory_bytes: 3120
n = int(input())
li = []
for i in range(n):
    li.append(int(input())-1)
cnt = 0
# p ... 現在光っているライトの座標
# l ... 次光るライトの座標
p = 0
l = li[0]
i = 0
while i < n:
# l = l[0] にしているので cnt の位置をここにしないと答えより 1 少なくなる
    cnt += 1
    p = l
    if p == 1:
        print(cnt)
        break
    l = li[l]
    i += 1
if p != 1:
    print(-1)

Measured memory_bytes: 7084
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int M = in.nextInt();
    Pair[] p = new Pair[N];
    for (int i = 0; i < N; i++) {
      p[i] = new Pair(in.nextInt(), in.nextInt());
    }
    Arrays.sort(p, (s, t) -> s.a - t.a);
    long ans = 0;
    for (int i = 0; i < N; i++) {
      long cnt = Math.min(M, p[i].b);
      ans += (long) p[i].a * cnt;
      M -= (int) cnt;
      if (M == 0) {
        break;
      }
    }
    System.out.println(ans);
  }
}

class Pair {
  int a, b;

  public Pair(int a, int b) {
    this.a = a;
    this.b = b;
  }
}

Measured memory_bytes: 92272
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;









int main() {
	string s;
	cin >> s;

	
	int cnt = 0;
	rep(i, 1, s.size()) {
		if (s[i] != s[i - 1]) {
			cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		boolean[][] card = new boolean[4][13];
		int m = 0;
		int r = 0;
		String mark;

		for (int i = 0; i < n; i++) {
			mark = sc.next();
			if (mark.equals("S")) {
				m = 0;
			} else if (mark.equals("H")) {
				m = 1;
			} else if (mark.equals("C")) {
				m = 2;
			} else if (mark.equals("D")) {
				m = 3;
			}

			r = sc.nextInt() - 1;

			card[m][r] = true;
		}

		for (int j = 0; j < 4; j++) {
			for (int i = 0; i < 13; i++) {
				if (!card[j][i]) {
					switch (j) {
					case 0:
						System.out.print("S ");
						break;
					case 1:
						System.out.print("H ");
						break;
					case 2:
						System.out.print("C ");
						break;
					case 3:
						System.out.print("D ");
						break;
					default:
						break;
					}
					System.out.println(i + 1);
				}

			}
		}

	}
}


Measured memory_bytes: 26308
#include <iostream>

int main() {
  int n, a, b;
  std::cin >> n;

  if (n == 1) {
    std::cout << "Hello World" << std::endl;
  } else {
    std::cin >> a >> b;
    std::cout << (a + b) << std::endl;
  }

  return 0;
}

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

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

typedef long long ll;

int main() {
    int n;cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    
    sort(a,a+n,greater<ll>());
    ll b = a[0];
    ll tmp = b/2;
    ll tmp_m = a[1];

    rep(i,n-1){
        if(abs(tmp_m - tmp)>abs(a[i+1] - tmp)){
        tmp_m = a[i+1];
        }
    }
    
    cout<<b<<" "<<tmp_m<<endl;
	return 0;
}

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

int main(){
	int n,d;
	cin>>n>>d;
	int x[n][d];
	rep(i,n)rep(j,d)cin>>x[i][j];
	int count=0;
	rep(i,n-1){
		for(int k=i+1;k<n;k++){
		double sum=0;
		rep(j,d){
			sum+=(x[i][j]-x[k][j])*(x[i][j]-x[k][j]);
		}
		double val = sqrt(sum);
		
		if(val-(int)val==0)count++;
		}
	}
	puts(count);
}


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

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	vector<ll> S(n+1),X(n+1);
	for(int i = 0; i < n; i++){
		S[i+1] = S[i]+a[i];
		X[i+1] = X[i]^a[i];
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		int l = i+1,r = n+1;
		while(r-l>1){
			int mid = (r+l)/2;
			if((S[mid]-S[i]) == (X[mid]^X[i])) l = mid;
			else r = mid;
		}
		ans += l-i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
import sys
input = sys.stdin.buffer.readline
import numpy as np

D = int(input())
c = np.array(input().split(), dtype=np.int32)
s = np.array([input().split() for _ in range(D)], dtype=np.int32)
last = np.zeros(26, dtype=np.int32)
# print(s)
# print(s.shape)

ans = []
point = 0
for i in range(D):
    down = (i+1-last)*c
    loss = down * 4 + s[i,:]
    idx = np.argmax(loss)
    ans.append(idx+1)
    last[idx] = i+1
    down = (i+1-last)*c
    point += s[i, idx] - down.sum()
    # print(loss)
    # print(point)

for i in range(D):
    print(ans[i])

Measured memory_bytes: 27456
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(string, s, t);

    const int lens = s.length();
    const int lent = t.length();

    auto dp = makeV(-1, lens+1, lent+1);

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

    int i = lens;
    int j = lent;
    string ans = "";
    while (i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            ans += s[i-1];
            --i;
            --j;
        } else {
            if (dp[i][j] == dp[i-1][j]) --i;
            else --j;
        }
    }

    reverse(all(ans));
    print(ans);

    return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

struct unionfind {
    int n;
    vector<int> par,rank;
    unionfind(int n):n(n),par(n,-1),rank(n,0) {}
    int root(int x) {
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool same(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(rank[x] < rank[y]) swap(x,y);
        if(rank[x] == rank[y]) rank[x]++;
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool connect() {
        rep(i,n-1) {
            if(!same(i,i+1)) return false;
        }
        return true;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vector<P> v(m);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        v[i] = {a,b};
    }
    int ans = 0;
    rep(i,m) {
        unionfind uf(n);
        rep(j,m) {
            if(j == i) continue;
            uf.merge(v[j].first,v[j].second);
        }
        if(!uf.connect()) ans++;
    }
    cout << ans << endl;
}


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

int main(){
    int R;
    cin>>R;
    if(R<1200){
        cout<<"ABC"<<endl;
    }
    else if(2800<=R){
        cout<<"AGC"<<endl;
    }
    else{
        cout<<"ARC"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n,l;
    cin >> n;
    cin >> l;
    vector<string> s;
    for(int i=0; i<n; i++) {
        string inps;
        cin >> inps;
        s.push_back(inps);
    }
    
    sort(s.begin(), s.end());
    
    string ans = "";
    for(int i = 0; i < n; i++){
        ans = ans + s[i];
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
-- Strongly Connected Component Decomposition
local n, m = io.read("*n", "*n")
local edge = {}
local edge_asked = {}
local invedge = {}
local invedge_asked = {}
for i = 1, n do
  edge[i] = {}
  edge_asked[i] = 0
  invedge[i] = {}
  invedge_asked[i] = 0
end
local edgeinfo = {}
for i = 1, m do
  local a, b = io.read("*n", "*n")
  a, b = a + 1, b + 1
  edgeinfo[i] = {a, b}
  table.insert(edge[a], b)
  table.insert(invedge[b], a)
end

local asked = {}
local sccd_root = {}
for i = 1, n do
  asked[i] = false
  sccd_root[i] = 0
end

local function SCCD_dfs(spos, dfs_way)
  local tasks = {spos}
  while 0 < #tasks do
    local src = tasks[#tasks]
    asked[src] = true
    table.remove(tasks)
    if edge_asked[src] == #edge[src] then
      table.insert(dfs_way, src)
    else
      table.insert(tasks, src)
      edge_asked[src] = edge_asked[src] + 1
      local dst = edge[src][edge_asked[src]]
      if not asked[dst] then
        table.insert(tasks, dst)
      end
    end
  end
end

local function SCCD_invdfs(spos, rootid)
  local tasks = {spos}
  while 0 < #tasks do
    local src = tasks[#tasks]
    sccd_root[src] = rootid
    table.remove(tasks)
    while invedge_asked[src] < #invedge[src] do
      invedge_asked[src] = invedge_asked[src] + 1
      local dst = invedge[src][invedge_asked[src]]
      if asked[dst] and sccd_root[dst] == 0 then
        table.insert(tasks, src)
        table.insert(tasks, dst)
        break
      end
    end
  end
end

local function SCCD_make()
  for src = 1, n do
    if not asked[src] then
      local dfs_way = {}
      SCCD_dfs(src, dfs_way)
      for i = #dfs_way, 1, -1 do
        local src = dfs_way[i]
        if sccd_root[src] == 0 then
          SCCD_invdfs(src, src)
        end
      end
    end
  end
end

SCCD_make()

local gsize = {}
local gedge, ginvedge = {}, {}
local glen = {}
local gmember = {}
for i = 1, n do
  gsize[i] = 0
  gedge[i], ginvedge[i] = {}, {}
  glen[i] = 0
  gmember[i] = {}
end
for i = 1, n do
  local r = sccd_root[i]
  gsize[r] = gsize[r] + 1
  table.insert(gmember[r], i)
end
for i = 1, m do
  local a, b = edgeinfo[i][1], edgeinfo[i][2]
  local ra, rb = sccd_root[a], sccd_root[b]
  if ra ~= rb then
    table.insert(gedge[ra], rb)
    table.insert(ginvedge[rb], ra)
  end
end
local topo_tasks = {}
local topo_asked_cnt = {}
local retcnt = 0
for i = 1, n do
  topo_asked_cnt[i] = 0
  if 0 < gsize[i] then retcnt = retcnt + 1 end
  if 0 < gsize[i] and #ginvedge[i] == 0 then
    table.insert(topo_tasks, i)
  end
end
print(retcnt)
local topo_done = 0
while topo_done < #topo_tasks do
  topo_done = topo_done + 1
  local g = topo_tasks[topo_done]
  io.write(#gmember[g])
  for i = 1, #gmember[g] do
    io.write(" " .. gmember[g][i] - 1)
  end
  io.write("\n")
  for i = 1, #gedge[g] do
    local dst = gedge[g][i]
    topo_asked_cnt[dst] = topo_asked_cnt[dst] + 1
    if topo_asked_cnt[dst] == #ginvedge[dst] then
      table.insert(topo_tasks, dst)
    end
  end
end


Measured memory_bytes: 318332
#include <iostream>
using namespace std;
int main(void)
{
    int a, b, w, ans;
    cin >> w >> a >> b;
    
    if(b>=a && b<=a+w) ans=0;
    else if(b+w>=a && b+w<=a+w) ans=0;
    else if(b>=a+w) ans=b-(a+w);
    else ans=a-(b+w);

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        System.out.println(solve(S));
    }

    private static String solve(String S) {
        char[] T = S.toCharArray();

        for (int i=0; i<S.length(); i++) {
            if (T[i] == '?') {
                T[i] = 'D';
            }
        }

        return String.valueOf(T);
    }
}

Measured memory_bytes: 41688
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
using namespace std;

const int MOD = 1000000007;

int main() {

	int A, B, C;
	cin >> A >> B >> C;

	if (A <= C&&C <= B)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n;
	double x[2][100] = {0};
	double d[5] = {0};
	cin >> n;
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin >> x[i][j];
		}
	}
	cout << fixed << setprecision(8);
	for (int i = 1; i <= 3; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			d[i] += pow(sqrt(pow(x[0][j] - x[1][j], 2.0)), (double)i);
		}
		d[i] = pow(d[i], 1.0/i);
		cout << d[i] << endl;
	}
	for (int i = 0; i < n; ++i)
	{
		if(d[4] < sqrt(pow(x[0][i] - x[1][i], 2.0))){
			d[4] = sqrt(pow(x[0][i] - x[1][i], 2.0));
		}
	}
	cout << d[4] << endl;
}

Measured memory_bytes: 1352
/*
------------____________----------------
--------------CRISTIANO-----------------
SUUUUUUUUUIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
GOOOOOOOOOOOOOOAAAAAAAALLLLLLLLLLLLLLLLL
 
Author- Shubham Jha
IIIT- ALLAHABAD
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl "\n"
int main()
{
  ll h,n,i,j;
  cin>>h>>n;
  ll arr[n][2];
  ffor(i,0,n)
  cin>>arr[i][0]>>arr[i][1];
  ll dp[20005];
  for(i=0;i<20005;i++)
    dp[i]=1010101010101010;
  dp[0]=0;
  for(i=1;i<20005;i++)
  {
      for(j=0;j<n;j++)
      {
          if(i-arr[j][0]>=0)
            dp[i]=min(dp[i],dp[i-arr[j][0]]+arr[j][1]);
          else 
            dp[i]=min(dp[i],arr[j][1]);
      }
  }
  ll ans=1010101010101010;
  for(i=h;i<20005;i++)
    ans=min(ans,dp[i]);
  cout<<ans;
}

Measured memory_bytes: 384
<?php

$rooms     = array_fill_keys(range(1, 10), 0);
$floors    = array_fill_keys(range(1, 3), $rooms);
$buildings = array_fill_keys(range(1, 4), $floors);

fscanf(STDIN, '%d', $n);

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);

    $buildings[$b][$f][$r] += $v;
}

foreach ($buildings as $floors) {
    $floor = array();
    foreach ($floors as $rooms) {
        $floor[] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
    }
    $tenant[] = implode('', $floor);
}

printf('%s', implode(str_repeat('#', 20) . "\n", $tenant));

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<ll> numB(N+1, 1LL);
  vector<bool> possR(N+1);
  possR.at(1) = true;

  for (ll i = 0; i < M; i++) {
    ll x, y; cin >> x >> y;
    if (possR.at(x)) {
      possR.at(y) = true;
      if (numB.at(x) == 1) possR.at(x) = false;
    }
    numB.at(x)--; numB.at(y)++;
  }
  ll cnt = 0;
  for (ll i = 1; i <= N; i++) if (possR.at(i)) cnt++;
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3972
#include <cstdio>

using namespace std;

int gcd(int x,int y)
{
	if (y == 0) return x;
	return gcd(y,x%y);
}

int main(int argc,char * argv[])
{
	int n,m;
	int cur = 0;
	bool tf = false;
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= n;++i)
	{
		int x;
		scanf("%d",&x);
		cur = gcd(cur,x);
		if (x >= m) tf = true;
	}
	if (tf && m % cur == 0) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 128
x = int(input())

if 400 <= x < 600:
    print(8)
elif 600 <= x < 800:
    print(7)
elif 800 <= x < 1000:
    print(6)
elif 1000 <= x < 1200:
    print(5)
elif 1200 <= x < 1400:
    print(4)
elif 1400 <= x < 1600:
    print(3)
elif 1600 <= x < 1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 61640
#!/usr/bin/env python


def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]

    cost = 0
    prev = 0
    for a in A:
        cost += abs(a - prev)
        prev = a
    cost += abs(prev)

    for i in range(1, N + 1):
        if (A[i - 1] <= A[i] <= A[i + 1]) or A[i - 1] >= A[i] >= A[i + 1]:
            print(cost)
        else:
            x = abs(A[i - 1] - A[i]) + abs(A[i + 1] - A[i])
            y = abs(A[i - 1] - A[i + 1])
            print(cost - (x - y))


if __name__ == '__main__':
    # print(main())
    main()

Measured memory_bytes: 14040
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B

readIntLL = map(unfoldr(B.readInt.B.dropWhile(==' '))).B.lines<$>B.getContents

psi (x,y) a = (x+a, y-a)

main=do
    [n]:(a:as):_ <- readIntLL
    --
    print $ minimum $ map (\(x,y) -> abs $ x-y) $ take (n-1) $ scanl' psi (a, sum as) as


Measured memory_bytes: 17788
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

path = [1]
checked = [False] * N
detect_loop = False

current_pos = 1
while not detect_loop:
    current_pos = A[current_pos - 1]

    if checked[current_pos - 1]:
        detect_loop = True

    path.append(current_pos)
    checked[current_pos - 1] = True

loop = path[(idx := path.index(current_pos)):-1]
straight = path[:idx]

if K < len(straight):
    print(straight[K])
else:
    print(loop[(K - len(straight)) % len(loop)])



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

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int pown = n * n;
    int sum = 0;
    vector<int> gcd_two(pown, 0);
    int idx = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            gcd_two[idx++] = gcd(i, j);
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < pown; j++) {
            sum += gcd(i, gcd_two[j]);
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<vector>
using namespace std;
class UnionFind {
  //子供は親を、おやは-(グループのサイズ)
  vector<int> Parent;
public:
  UnionFind(int n) {
    Parent = vector<int>(n, -1);
  }
  int get(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = get(Parent[A]);
  }
  int size(int A) {
    return -Parent[get(A)];
  }
  bool connect (int A, int B) {
    A = get(A);
    B = get(B);
    if (A == B) return false; // 親が一緒なら何もしない
    if (size(A) > size(B)) {
      Parent[A] = -(size(A) + size(B));
      Parent[B] = A;
      return true;
    }
    Parent[B] = -(size(A) + size(B));
    Parent[A] = B;
    return true;
  }
};
      
int main () {
  int N, M;
  cin >> N >> M;
  long long max = (long long)N * (N - 1) / 2;
  vector<int>A(M);
  vector<int>B(M);
  for (int i = 0; i < M; i ++) {
    int j, k;
    cin >> j >> k;
    A[i] = j - 1;
    B[i] = k - 1;
  }
  UnionFind jun(N);
  vector<long long>ans(M);
  ans [M - 1] = max;
  for (int i = M - 1; i > 0; i --) {
    ans[i - 1] = ans[i] - jun.size(A[i]) * jun.size(B[i]);
    if (!jun.connect(A[i], B[i])) {
      ans[i - 1] = ans[i];
    }
  }
  for (int i = 0; i < M; i ++) cout << ans[i] << endl;
}



Measured memory_bytes: 3328
import sys

N,Q=map(int, sys.stdin.readline().split())
S=raw_input()
L=[ map(int, sys.stdin.readline().split())  for i in range(Q) ] 

W=[0]

for i in range(N-1):
	if S[i]=="A" and S[i+1]=="C":
		W.append( W[-1]+1 )
	else:
		W.append( W[-1] )	


for x, y in L:
	print W[y-1]-W[x-1]


Measured memory_bytes: 51612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

int dx[]={0,1,2,2,2,1,0,-1,-2,-2,-2,-1},dy[]={2,2,1,0,-1,-2,-2,-2,-1,0,1,2};

main(){
  int sx,sy;
  while(cin>>sx>>sy){
    if(sx==0 && sy==0)break;
    int n;
    cin>>n;
    PI sp[n];
    rep(i,n)cin>>sp[i].f>>sp[i].s;

    queue<pair<PI,int> > Q;
    Q.push(mp(mp(sx,sy),0));

    int maxn=0;

    while(!Q.empty()){
      int x=Q.front().f.f,y=Q.front().f.s,te=Q.front().s;
      Q.pop();
      maxn=te;
      if(te==n)break;
      rep(i,12){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx<0 || nx>9 || ny<0 || ny>9 || abs(nx-sp[te].f)>1 || abs(ny-sp[te].s)>1)continue;
        Q.push(mp(mp(nx,ny),te+1));
      }
    }
    if(maxn==n)puts("OK");
    else puts("NA");
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	cin>>n;
	vector< pair<int,int> > r(n),b(n);
	for(i=0;i<n;i++){cin>>r[i].second>>r[i].first;}
	for(i=0;i<n;i++){cin>>b[i].first>>b[i].second;}
	sort(r.begin(),r.end());
	sort(b.begin(),b.end());
	vector<int> a(n);
	int mj,ans=0;
	for(i=0;i<n;i++)
	{
		bool f=false;
		for(j=0;j<n;j++)
		{
			if(r[j].second<b[i].first&&r[j].first<b[i].second)
			{
				if(a[j]==0)
				{
					f=true;
					mj=j;
				}
			}
		}
		if(f)
		{ans++;a[mj]=1;}
	}
	cout<<ans<<endl;
	return 0;
}

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

// edge = xi -> yi
// 有向グラフの直径(最大のパス)
fun solve(N: Int, M: Int, x: IntArray, y: IntArray) {
    val edges = Array(N){ ArrayDeque<Int>() }
    // val revEdges = Array(N){ ArrayDeque<Int>() }
    for (i in 0 until M){
        edges[x[i] - 1].addLast(y[i]-1)
    }
    val memo = mutableMapOf<Int, Long>()
    fun dfs(index: Int): Long{
        memo[index]?.let{ return it }
        val nextNodes = edges[index]
        val length = when(nextNodes){
            null -> 0L
            else -> nextNodes.map{ 1 + dfs(it) }.max()?: 0L
        }
        memo[index] = length
        return length
    }
    (0 until N).map{ dfs(it) }.max()?.let{ println(it) }
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val x = IntArray(M)
    val y = IntArray(M)
    for (i in 0 until M) {
        x[i] = sc.next().toInt()
        y[i] = sc.next().toInt()
    }
    solve(N, M, x, y)
}


Measured memory_bytes: 92836
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    ll n;
    cin>>n;

    if(n==0){cout<<'a'<<endl;return 0;}

    string s;
    while(n>0){
        n--;
        ll t = n%26;
        n/=26;

        s+=char('a'+(t));
    }

//    if(n!=0){
//        s+=char('a'+(n));
//    }

    reverse(s.begin(),s.end());
    cout<<s<<endl;


    return 0;
}


Measured memory_bytes: 3628
'use strict';

function Main(input) {
  const N = Number(input.split('\n')[0].split(' ')[0]);
  const X = Number(input.split('\n')[0].split(' ')[1]);
  let list = input.split('\n')[1].split(' ').map(n => Math.abs(Number(n) - X));

  list.sort((a, b) => (a > b ? 1 : -1));

  const gcd = (m, n) => {
    if(n === 0) {
      return m;
    } else {
      return gcd(n, m % n);
    }
  }

  if(list.length === 1) {
    console.log(list[0]);
  } else {
    let gcdans = gcd(list[0], list[1]);
    for(let k=2; k<N; k++) {
      gcdans = gcd(gcdans, list[k]);
    }
    console.log(gcdans);
  }


};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 28752
// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N; string S; cin>>N>>S;
	map<char,int> rgb;
	rep(i, N) rgb[S[i]]++;
	long long ans = (long long)rgb['R'] * rgb['G'] * rgb['B'];
	rep(i, N) rep(d, N){
		int j = i + d, k = j + d;
		if(k >= N) break;
		if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ans--;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	int i,check=0;
	if(a < b){
		for(i=a;i<=b;i++){
			//printf("%d\n",i);
			if(i == c){
				check = 1;
				//printf("find C\n");
			}
		}
	}else{
		for(i=b;i<=a;i++){
			//printf("%d\n",i);
			if(i == c){
				check = 1;
				//printf("find C\n");
			}
		}
	}
	if(check == 1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
s=input()
n=len(s)
c=0
for i in range((n-1)//2):
    if s[i]!=s[n-1-i]:
        c=1
        break
if c>0:
    print('No')
else:
    for i in range((n-1)//2):
        if s[i]!=s[(n-1)//2-i-1]:
            c=1
            break
    if c>0:
        print('No')
    else:
        for i in range((n+3)//2,n):
            if s[i]!=s[n-i-1]:
                c=1
                break
        if c>0:
            print('No')
        else:
            print('Yes')

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

typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll sum=0;
  for(ll i=1;i<=n;i++)
    for(ll j=1;j<=n;j++)
      for(ll k=1;k<=n;k++)
        sum+=__gcd(i,__gcd(j,k));
  cout<<sum;
  return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  vector<int> xp;
  vector<int> yp;
  int tmp;
  for(int i = 0;i<n;i++){
    cin>>tmp;
    xp.push_back(tmp);
  }
  for(int i = 0;i<m;i++){
    cin>>tmp;
    yp.push_back(tmp);
  }
  sort(xp.begin(),xp.end());
  sort(yp.begin(),yp.end());
  // cout<<xp[n-1]<<","<<yp[0]<<endl;
  if(yp[0]-xp[n-1]>=0){
    for(int i = x+1;i<=y;i++){
      if(xp[n-1]<i && i <= yp[0]){
	cout<<"No War"<<endl;
	return 0 ;
      }
      
    }
    cout<<"War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256