akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int main() {
	string S;
	cin >> S;
	for (char& c : S) {
		if (c == '?')c = 'D';
	}
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll ans = mod;
    int mn = mod;
    int mx = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(mx < a[i]) mx = a[i];
        if(mn > a[i]) mn = a[i];
    }
    for(int i = mn; i <= mx; i++){
        ll can = 0;
        for(int j = 0; j < n; j++){
            can += pow(i-a[j],2);
        }
        if(ans > can) ans = can;
    }    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int walk(int index, int time, int wayto[101][101], int *d, int *f) {
	int *p;

	d[index] = ++time;
	for (p = wayto[index]; *p != 0; p++) {
		if (!d[*p]) {
			time = walk(*p, time, wayto, d, f);
		}
	}
	f[index] = ++time;
	return time;
}

int main(void) {
	int num, i, j, u, k, tm = 0;
	int d[101] = {0}, f[101] = {0};
	int wayto[101][101] = {{0}};

	scanf("%d", &num);
	for (i = 0; i < num; i++) {
		scanf("%d %d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &wayto[u][j]);
		}
	}

	for (i = 1; i <= num; i++) {
		if (!d[i]) {
			tm = walk(i, tm, wayto, d, f);
		}
	}

	for (i = 1; i <= num; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

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


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c%gcd(a,b)==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
  }

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
main()
{
	int a, b, c, d, f=0;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if (abs(a-c)<=d)
	{
		f=1;
	}
	else if ((abs(a-b)<=d) && (abs(b-c)<=d))
	{
		f=1;
	}
	if (f==1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e6+10;

int a[MAXN];
int main() {
    int n,x,y;
    cin>>n>>x>>y;
    if (x>y)
        swap(x,y);
    for (int i=1;i<=n;i++) {
        for (int j=i+1;j<=n;j++) {
            //要么直接走 要么经过x y 
            int d=min(j-i,abs(i-x)+abs(j-y)+1);
            // cout<<i<<" "<<j<<" "<<d<<endl;
            a[d]++;
        }
    }
    for (int i=1;i<n;i++) 
        cout<<a[i]<<endl;
    return 0;
}   

Measured memory_bytes: 384
N = int(input())
L = []
for i in range(N):
  L.append(list(input().split())+[i])
  L[i][1] = int(L[i][1])

L = sorted(L)
for i in range(N):
  for j in range(N-i):
    if L[i][0] == L[i+j][0] and L[i][1] < L[i+j][1]:
      L[i],L[i+j] =  L[i+j],L[i]

for k in range(N):
  print(L[k][2]+1)
    
    

Measured memory_bytes: 3064
N,k=map(int,input().split())
S=input()

nums=[]
now=1
seq_count=0
for char in S:
    if char in S:
        if char == str(now):
            seq_count+=1
        else:
            now=1-now
            nums.append(seq_count)
            seq_count=1
nums.append(seq_count)
if len(nums)%2==0:
    nums.append(0)
sums=[0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1]=sums[i]+nums[i]

ans=0
for i in range(1,len(sums),2):
    left=i-1
    right = min(i+2*k,len(sums)-1)
    ans=max(ans,sums[right]-sums[left])
print(ans)


Measured memory_bytes: 7884
h,w=map(int,input().split())
l = [input() for i in range(h)]
a = "."*(w+2)
ans="Yes"
for _ in range(h):
  l[_]="."+l[_]+"."
l.append(a)
l.insert(0,a)
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]=="#" and l[i-1][j]=="." and l[i][j-1]=="." and l[i+1][j]=="." and l[i][j+1]==".":
      ans="No"
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
//
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n=sc.nextInt();
		String s =sc.next();
		char[] array = s.toCharArray();
		int ans =0;
		
		for (int i=0;i<(n-2);i++) {
			StringBuilder buf = new StringBuilder();
			buf.append(array[i]);
			buf.append(array[i+1]);
			buf.append(array[i+2]);
			String st =buf.toString();
			if (st.equals("ABC")) {
				ans ++;
			}
		}
		System.out.println(ans);
		
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
	//----------------------------------------
	//置き場
	
	//----------------------------------------
}

Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public struct Pair { public int x, y; public Pair(int a, int b) { y = a; x = b; } }
    public static void Solve()
    {
        int N = NextInt(), M = NextInt();
        Console.WriteLine((500*N < M ? "No" :"Yes"));
    }
    public static long GCD(long a, long b)
    {
        if (a < b) GCD(b, a);
        long d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(long a, long b)
    {
        return a / GCD(a, b) * b;
    }

    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 13268
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
l = li2(N)


'''
# メモ化再帰
dp = dp2(-1, N, N)
def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    if i == j:
        dp[i][j] = 0
        return 0
    if j-i == 1:
        dp[i][j] = l[i][0] * l[i][1] * l[j][1]
        return dp[i][j]
    res = float('inf')
    for k in range(i, j):
        res = min(res, rec(i, k) + rec(k+1, j) + l[i][0] * l[k+1][0] * l[j][1])
    dp[i][j] = res
    return res

print(rec(0, N-1))
'''

# 2次元DP

dp = dp2(float('inf'), N, N)

for i in range(N):
    dp[i][i] = 0

for h in range(1, N):
    for i in range(N):
        if i+h < N:
            if h == 1:
                dp[i][i+h] = l[i][0] * l[i][1] * l[i+h][1]
            else:
                #dp[i][i+h] = dp[i][i+h-1] + l[i][0] * l[i+h][0] * l[i+h][1]
                for r in range(i, i+h):
                    dp[i][i+h] = min(dp[i][i+h], dp[i][r]+dp[r+1][i+h]+l[i][0]*l[r+1][0]*l[i+h][1])
#print(dp)
print(dp[0][N-1])


Measured memory_bytes: 5788
#include <iostream>
int main() {
	int a, b;
	std::cin >> a >> b;
	if (a < b){
		std::cout << "a < b\n";
	}
	else if (a > b) {
		std::cout << "a > b\n";
	}
	else {
		std::cout << "a == b\n";
	}
	return 0;
}


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

int main()
{
	int N;
	scanf("%d", &N);
	std::map<std::string, int64_t> mp;
	for (int i{}; i < N; i++)
	{
		std::string tmp;
		std::cin >> tmp;
		std::sort(tmp.begin(), tmp.end());
		mp[tmp]++;
	}
	int64_t ans{};
	for (auto& e: mp) ans += e.second * (e.second - 1) / 2;
	printf("%lld\n", ans);

	return 0;
}

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

int main(){
    int n, p[100001], pos[100001];
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> p[i];
        pos[p[i]] = i;
    }
    set<int> wall;
    wall.insert(-1);
    wall.insert(0);
    wall.insert(n+1);
    wall.insert(n+2);
    wall.insert(pos[n]);

    int64_t ans = 0;
    for(int i=n-1;i>=1;--i){
        auto ri = wall.lower_bound(pos[i]);
        auto li = ri; --li;
        int64_t l1 = *li, r1 = *ri;
        int64_t l2 = *(--li), r2 = *(++ri);
        int64_t cnt = 0;
        if(l1 >  0) cnt += (l1-l2)*(r1-pos[i]);
        if(r1 <= n) cnt += (pos[i]-l1)*(r2-r1);
        ans += i*cnt;
        wall.insert(pos[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int N, M; ~scanf("%d%d", &N, &M) && N;) {
    int sum[N + 1]; sum[0] = 0;

    int res = 0;
    rep(i, N) {
      int A; scanf("%d", &A); A %= M;
      sum[i + 1] = sum[i] + A;
      sum[i + 1] %= M;
      maximize(res, sum[i + 1]);
    }

    set<int> st = {M};

    REP(i, 1, N + 1) {
      maximize(res, sum[i] + M - *st.upper_bound(sum[i]));
      st.insert(sum[i]);
    }

    cout << res << endl;

  }
  
  return 0;
}

Measured memory_bytes: 4428
n, k = map(int, input().split())
aList = list(map(int, input().split()))
bits0 = [0] * 42
bits1 = [0] * 42
def getBit(a):
    mask = 1
    for i in range(42):
        if mask > a and mask > k:
            break
        if a & mask:
            bits1[i] += 1
        else:
            bits0[i] += 1
        mask <<= 1

for a in aList:
    getBit(a)

ans = 0
for i in range(41, -1, -1):
    cnt1 = bits1[i]
    cnt0 = bits0[i]
    if k < 2 ** i:
        ans += 2 ** i * cnt1
        continue
    if cnt0 <= cnt1:
        ans += 2 ** i * cnt1
    else:
        ans += 2 ** i * cnt0
        k -= 2 ** i
print(ans)

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

int n, k, a[1010];
int main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for(int i = 0; i < k; i++) ans += a[i];
    cout << ans;
}

Measured memory_bytes: 3652
// ※※※ 解答不能 ※※※
// yutaka1999氏.
// https://atcoder.jp/contests/code-festival-2017-qualc/submissions/1704201
#include <bits/stdc++.h>
using namespace std;
#define SIZE 415
#define MOD 1000000007
typedef long long int ll;
typedef pair <int, int> P;

int dp[2][SIZE][SIZE];
int now[SIZE][SIZE];
int A[SIZE], B[SIZE];
int pa[SIZE];
int pb[SIZE];

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &A[i]);
        A[i]--;
        pa[A[i]] = i;
    }
    for(int i = 0; i < n; i++){
        scanf("%d", &B[i]);
        B[i]--;
        pb[B[i]] = i;
    }
    if(A[0] == B[0]){
        puts("0");
        return 0;
    }
    A[n] = n, B[n] = n;
    pa[n] = pb[n] = n + 1;
    int pos = 0;
    memset(dp, 0, sizeof(dp));
    dp[pos][1][1] = 1;
    for(int i = 1; i <= n; i++){
        pos ^= 1;
        memset(dp[pos], 0, sizeof(dp[pos]));
        for(int j = 1; j <= n + 1; j++){
            for(int k = 0; k <= n / 3; k++) now[j][k] = 0;
        }
        for(int j = 1;j <= n; j++){
            for(int k = 0; k <= n / 3; k++){
                int vl = dp[pos^1][j][k];
                if(vl == 0) continue;
                // A[i] を使わないとき
                if(pb[A[i]] < j){
                    // Bに入ってる
                    dp[pos][j][k] += vl;
                    if(dp[pos][j][k] >= MOD) dp[pos][j][k] -= MOD;
                }else if(k > 0){
                    // Cに入れる
                    dp[pos][j][k - 1] += (int)((ll)vl * (ll)k % MOD);
                    if(dp[pos][j][k - 1] >= MOD) dp[pos][j][k - 1] -= MOD;
                }
                // A[i]を使うとき
                if(pb[A[i]] >= j){
                    now[j][k] += vl;
                    if(now[j][k] >= MOD) now[j][k] -= MOD;
                }
            }
        }
        for(int j = 1; j <= n; j++){
            if(A[i] < n && B[j] == A[i]) continue;
            for(int k = 0;k <= n / 3; k++){
                int vl = now[j][k];
                if(vl == 0) continue;
                // B[j] を使わない
                if(pa[B[j]] <= i){
                    now[j + 1][k] += vl;
                    if(now[j + 1][k] >= MOD) now[j + 1][k] -= MOD;
                }else if(k > 0){
                    now[j + 1][k - 1] += (int)((ll)vl * (ll)k % MOD);
                    if(now[j + 1][k - 1] >= MOD) now[j + 1][k - 1] -= MOD;
                }
                //B[j] を使う
                if(pa[B[j]] > i){
                    dp[pos][j + 1][k + 1] += vl;
                    if(dp[pos][j + 1][k + 1] >= MOD) dp[pos][j + 1][k + 1] -= MOD;
                }
            }
        }
    }
    ll ret = dp[pos][n + 1][1];
    for(int i = 0; i < n / 3; i++){
        ret *= (ll)(3 * i + 1);
        ret %= MOD;
        ret *= (ll)(3 * i + 2);
        ret %= MOD;
    }
    printf("%lld\n", ret);
    return 0;
}

Measured memory_bytes: 2304
import java.util.*;
public class Main {

	static long mod = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i <= 2000; i++) Arrays.fill(dp[i], -1);
		for(int i = 0; i <= 2000; i++){
			for(int j = 0; j <= 2000; j++){
				calcc(i,j);
			}
		}
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a = k, b = n-k;
		for(int i = 1; i <= k; i++){
			long x = (calc(b, i+1) * calc(a, i)) % mod;
			long y = (calc(b, i-1) * calc(a, i)) % mod;
			long z = ((2 * calc(b, i)) % mod * calc(a, i)) % mod;
			System.out.println(((x + y) % mod + z) % mod);
		}
	}
	static long[][] dp = new long[2001][2001];
	static long calc(int m, int k){//m balls in k spaces, at least one ball per space
		if(m < k) return 0;
		else return calcc(m-k, k);
	}
	static long calcc(int m, int k){//m balls in k spaces, in whichever way
		if(dp[m][k] >= 0) return dp[m][k];
		if(m == 0) return dp[m][k] = 1;
		if(k == 0) return dp[m][k] = 0; //??
		if(k == 1) return dp[m][k] = 1;
		else{
			return dp[m][k] = (calcc(m, k-1) + calcc(m-1, k)) % mod;
		}
	}
}


Measured memory_bytes: 82516
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        double a = 0;
        double b = 0;
        double x = double.Parse(Console.ReadLine());
        for(double i = -118; i<= 119; i++)
        {
            for(double j = -118; j <= 119; j++)
            {
               if(Math.Pow(i,5) - Math.Pow(j,5) == x)
                {
                    a = i;
                    b = j;
                    break;
                }
            }
        }
        Console.WriteLine("{0} {1}" , a , b);
        

    }




}





Measured memory_bytes: 19000
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)
 
 
//C++で提出
 
 
 
// string s="AAA";    s.size() =3    (sのサイズ) ...1
// vector <int> a;    配列a(サイズは0) ...2
// a.push_back(10);   配列のサイズが一つ増えて一番後ろに10を代入 ...2
// A.pop_back();   最後の要素が消去される
// sort(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)より前までを小さい順に並び替えてa[0]から代入していく...3
// reverse(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)までを逆の順にしてa[0]から代入していく
// s.substr(3,2)   配列s[3]から2個の文字を抜き出した文字列 (s[3]とs[4]) ...4
// strcmp(s1,s2)  文字列が等しければ0を出力　s1>s2なら1 s1<s2なら-1を出力　C言語用なので配列は、s1[100]にする...5
 
 
 
 
/*
const int MAX = 100;
int main() {
	int N, M;
	string s, t;
	map<string, int> m;
	m["apple"] = 10;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> s;
		m[s]++;
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		cin >> t;
		m[t]--;
	}
	
	int max=0;
 
	for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
		if (max < (i->second)) max = i->second;
	}
 
	if (max < 0) cout << "0";
	else cout << max;
 
	return 0;
}
 
*/
 
int main() {
 
	int N;
	int i;
	
	string s;
	map<string, int> m;
	// m["apple"] = 10;
	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> s;
		m[s]++;
		
	}
	
	
	int max = 0;
	string t;
 
	for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
		if (max < (i->second)) { max = i->second;}
		
	}
 
	vector<string> mm;
 
	for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
		if (max == (i->second)) {  mm.push_back( i->first); }
	}
	
	sort(mm.begin(), mm.end());
 
	for (i = 0; i < mm.size(); i++) cout << mm[i]<<endl;
 
	return 0;
}

Measured memory_bytes: 26868
import numpy as np
import itertools

n = int(input())

xys = [ list(map(int,input().split())) for _ in range(n) ]
# print(xys)

l = 0
# cnt = 0.0
for path in itertools.permutations(xys, n):
    # print(path)
    # l = 0.0
    for i in range(n-1):
        nx = path[i+1][0]
        ny = path[i+1][1]
        x  = path[i][0]
        y  = path[i][1]
        l += np.sqrt((nx-x)**2.0 + (ny-y)**2.0)
        # print(l)
    # print(l)
    # cnt += l
    
for i in range(n):
    l /= (i+1)

print(l)

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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
char ch;
int ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>ch;
		ans+=ch=='B';
	}
	if(ans<n-ans)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
a = input()
b = input()
c = input()

la = len(a)
lb = len(b)
lc = len(c)

na = 1
nb = 0
nc = 0

now = a[0]

while True:
    if now == 'a':
        if na == la:
            print('A')
            break
        else:
            now = a[na]
            na += 1
    elif now == 'b':
        if nb == lb:
            print('B')
            break
        else:
            now = b[nb]
            nb += 1
    else:
        if nc == lc:
            print('C')
            break
        else:
            now = c[nc]
            nc += 1

Measured memory_bytes: 61924
#include "bits/stdc++.h"

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n;
ll dp[410][410],a[410];
ll rui[410];

ll dfs(int l,int r){
	if(dp[l][r]!=INF)return dp[l][r];
	if(r-l<=1)return INF;
	ll res=INF;
	for(int i=l+1;i<r;i++){
		res=min(res,dfs(l,i)+dfs(i,r)+rui[r]-rui[l]);
	}
	return dp[l][r]=res;
}

void input(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	return;
}

void solve(){
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=INF;
		}
	}
	for(int i=0;i<n;i++){
		rui[i+1]=rui[i]+a[i];
	}
	for(int i=0;i<n;i++){
		dp[i][i+1]=a[i];
	}
	cout<<dfs(0,n)-rui[n]<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int A;
  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    cin >> A;
    que.push(A);
  }
  for (int i = 0; i < M; i++) {
    int B = que.top();
    que.pop();
    B /= 2;
    que.push(B);
  }
  long long ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, M, P;
	cin >> N >> M >> P;
	double p = P / 100.0;
	vector<int> a(M), b(M);
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	vector<double> dp(1<<(N - 1), 1);
	for (int S = 0; S < 1<<(N - 1); S++) {
		int _S = (S<<1) + 1;
		for (int T = S; T;) {
			T = (T - 1) & S;
			int _T = (T<<1) + 1;
			double x = 1;
			for (int i = 0; i < M; i++)
				if ((_S>>a[i] & 1) && (_S>>b[i] & 1) && ((_T>>a[i] & 1) ^ (_T>>b[i] & 1)))
					x *= p;
			dp[S] -= dp[T] * x;
		}
	}
	printf("%.15f\n", dp[(1<<(N - 1)) - 1]);
}

Measured memory_bytes: 3260
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,m;
    cin>>n>>m;
    ll a=0,b=pow(10,5),l,r;
    REP(i,m){
        cin>>l>>r;
        if(a<l){
            a=l;
        }
        if(r<b){
            b=r;
        }
    }
    if(b-a+1>=0){
        cout<<b-a+1;
    }else{
        cout<<0;
    }
    return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)
for i in range(N-1):
    if S[i] == S[i+1]:
        print(i+1, i+2)
        break
else:
    for i in range(N-2):
        if S[i] == S[i+2]:
            print(i+1, i+3)
            break
    else:
        print(-1, -1)


Measured memory_bytes: 3316
Program LongestPath;
uses math;
type Rec=record
     x:longint;
     y:longint;
     end;
var Head,Adj,F :array[0..100005] of longint;
    E:array[1..100005] of Rec;
    Avai:array[1..100005] of boolean;
    n,m,res,i,maxx:longint;
    fi,fo:text;
//------------------------------------------
procedure DFS(i:longint);
var j:longint;
begin
Avai[i]:=false;
for j:=Head[i]+1 to Head[i+1] do begin
                                 if not Avai[adj[j]] then F[i]:=max(F[i],F[adj[j]]+1)
                                 else DFS(adj[j]);
                                 F[i]:=max(F[i],F[adj[j]]+1);
                                 end;
end;
//------------------------------------------
begin
//assign(fi,'LongestPath.inp');reset(fi);
readln(n,m);
for i:=1 to m do begin
                 With E[i] do begin
                              readln(x,y);
                              inc(Head[x]);
                              end;
                 end;
for i:=1 to n do begin
                 Head[i]:=Head[i]+Head[i-1];
                 end;
for i:=m downto 1 do begin
                     With E[i] do begin
                                  Adj[Head[x]]:=y;
                                  dec(Head[x]);
                                  end;
                     end;
Head[n+1]:=m;
fillchar(Avai,sizeof(Avai),true);
for i:=1 to n do begin
                 if Avai[i] then
                 DFS(i);
                 end;
for i:=1 to n do begin
                 maxx:=max(maxx,F[i]);
                 end;
Writeln(maxx);
//readln;
end.



Measured memory_bytes: 3584
h,w = map(int,input(). split())
if (h == 1) or (w == 1):
  answer = 1
  print(answer)
elif (h%2 == 1) and (w%2 == 1):
 
  answer = ((h*w)+1)//2
  print(answer)
else:
  answer = h*w//2
  print(answer)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

vector<vector<int>> memo;

int grundy(ll x,ll y) {
    if (memo[x][y] != -1) return memo[x][y];
    set<int> st;
    for (ll k = 1; k * 2 <= x; k++) {
        st.insert(grundy(x - 2 * k, y + k));
    }
    for (ll k = 1; k * 2 <= y; k++) {
        st.insert(grundy(x + k, y - k * 2));
    }
    int i = 0;
    while (st.find(i) != st.end()) i++;
    return memo[x][y] = i;
}

int main() {
    /*
    memo.resize(1000, vector<int>(1000, -1));
    REP(i, 10) {
        REP(j, 10) {
            cout << grundy(i, j) << " ";
        }
        cout << endl;
    }
    */
    ll x, y; cin >> x >> y;
    if (abs(x - y) <= 1) {
        puts("Brown");
    }
    else {
        puts("Alice");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int R, C; cin >> R >> C;

    int N; cin >> N;
    vector< vector< pair<int, int> > > edgesR(R), edgesC(C);
    for (int i = 0; i < N; ++i) {
        int r, c, a; cin >> r >> c >> a;
        --r; --c;
        edgesR[r].emplace_back(c, a);
        edgesC[c].emplace_back(r, a);
    }

    vector<bool> usedR(R, false), usedC(C, false);
    vector<int> valueR(R), valueC(C);
    vector<int> componentR, componentC;

    queue< pair<bool, int> > Q;
    for (int i = 0; i < R; ++i)
        if (!usedR[i]) {
            if (edgesR[i].empty())
                continue;
            Q.emplace(true, i);
            valueR[i] = 0;
            componentR.clear();
            componentC.clear();
            usedR[i] = true;
            while (!Q.empty()) {
                bool isRow; int node;
                tie(isRow, node) = Q.front();
                Q.pop();
                if (isRow) {
                    componentR.emplace_back(node);
                    for (auto &c : edgesR[node]) {
                        if (usedC[c.first]) {
                            if (valueC[c.first] + valueR[node] != c.second) {
                                cout << "No\n";
                                return 0;
                            }
                            continue;
                        }
                        usedC[c.first] = true;
                        valueC[c.first] = c.second - valueR[node];
                        Q.emplace(false, c.first);
                    }
                } else {
                    componentC.emplace_back(node);
                    for (auto &r : edgesC[node]) {
                        if (usedR[r.first]) {
                            if (valueR[r.first] + valueC[node] != r.second) {
                                cout << "No\n";
                                return 0;
                            }
                            continue;
                        }
                        usedR[r.first] = true;
                        valueR[r.first] = r.second - valueC[node];
                        Q.emplace(true, r.first);
                    }
                }
            }

            int maxt = numeric_limits<int>::max();
            int mint = 0;
            for (auto &v : componentR)
                mint = max(mint, -valueR[v]);
            for (auto &v : componentC)
                maxt = min(maxt, valueC[v]);
            if (maxt < mint) {
                cout << "No\n";
                return 0;
            }
        }
    cout << "Yes\n";
}


Measured memory_bytes: 12032
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n),b(n);
ll sum_a = 0, sum_b = 0;
rep(i,n){
    cin >> a[i];
    sum_a += a[i];
}
rep(i,n) {
    cin >> b[i];
    sum_b += b[i];
}
if(sum_a < sum_b){
    cout << -1 << endl;
    return 0;
}
vector<ll> c(n);
rep(i,n){
    c[i] = b[i];
    sum_a -= b[i];
}
vector<P> idx;
rep(i,n){
    if(a[i] > b[i])
        idx.emplace_back(a[i] - b[i], i);
}
sort(idx.begin(),idx.end());
rep(i,idx.size()){
    if(sum_a - idx[i].first >= 0){
        c[idx[i].second] = a[idx[i].second];
        sum_a -= idx[i].first;
    }
}
ll cnt = 0;
rep(i,n){
    if(a[i] != c[i]){
        cnt++;
    }
}
cout << cnt << endl;
}

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

int main(){
 int n;
 cin >> n;
 map<string, int >  mp;
 for(int i =0; i<n;i++){
 string s;
 cin >> s;
 mp[s]++;
 }
int ans = 0;
for(auto& x : mp){
   if(x.second) ans++;
}
cout << ans <<endl;
return 0;
}

Measured memory_bytes: 19092
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<int> G[100010];
int dp[100010];

int f(int now){
    if(dp[now] != -1) return dp[now];
    if(G[now].size() == 0) return dp[now] = 0;
    vector<int> tmp;
    rep(i, 0, G[now].size()){
        int child = G[now][i];
        tmp.push_back(f(child));
    }
    sort(all(tmp));
    reverse(all(tmp));
    int res = -1;
    rep(i, 0, tmp.size()){
        chmax(res, tmp[i] + i + 1);
    }
    return dp[now] = res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n + 1) dp[i] = -1;
    rep(i, 1, n){
        cin >> a[i];
        a[i]--;
        G[a[i]].push_back(i);
    }
    cout << f(0) << endl;
}

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

  int cnt = 0;

  while(1) {

    if(l[0] == l[4] && l[1] == l[3]) cnt++;
    if(l == r) break;

    if(l[4] == '9') {
      l[4] = '0';
      if(l[3] == '9') {
	l[3] = '0';
	if(l[2] == '9') {
	  l[2] = '0';
	  if(l[1] == '9') {
	    l[1] = '0';
	    l[0]++;
	  } else {
	    l[1]++;
	  }
	} else {
	  l[2]++;
	}
      } else {
	l[3]++;
      }
    } else {
      l[4]++;
    }    

  }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1000+10;
const int MAXNA=20000+20;
long long n,ans;
long long dp[MAXNA];
struct p
{
	int w;
	int s;
	int v;
}A[MAXN];
bool cmp(p a,p b)
{
	return (a.w+a.s)<(b.w+b.s);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>A[i].w>>A[i].s>>A[i].v;
	}
//	cout<<"\n";
	sort(A,A+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		for(int j=A[i].s;j>=0;j--)
		{
			dp[j+A[i].w]=max(dp[j+A[i].w],dp[j]+A[i].v);
		}
	}
	for(int i=0;i<=MAXNA-1;i++)
	{
		ans=max(ans,dp[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,e,f,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>a>>b>>c>>d>>e>>f;
    ans=a+b*5+c*10+d*50+100*e+f*500;
    if(ans>=1000)Cout(1);
    else Cout(0);
    return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,x;cin>>a>>b>>x;
    cout << b/x-a/x+(a%x?0LL:1LL)<<endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int c[100100];

int main(){
	int n = in.nextInt();
	vi a(n), b(n);
	rep(i, n) a[i] = in.nextInt(), b[i] = in.nextInt();

	vector<pii> p;
	rep(i, n) p.pb({a[i], b[i]});
	sort(all(p));

	int ans = 0;

	int idx1 = 0, idx2 = 0;
	for(int i = 0; i < n + 1; i++){
		//i + 1 nin de ikeru tomodachi no kazu
		int idx = upper_bound(all(p), mp(i + 1, INF)) - p.begin();
		//c[x] := x nin ijou ha dame
		for(int j = idx1; j < idx; j++){
			if(p[j].se < i) c[i]++;
			else c[p[j].se]++;
		}
		idx1 = idx;
		if(i > 0) c[i] += c[i-1];
		// i + 1 nin atumaranai
		if(i > idx || i > idx - c[i]) continue;
		//tomodachi ha i nin
		ans = max(ans, i);
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 4916
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	flag := false
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a%2 == 0 && !(a%3 == 0 || a%5 == 0) {
			flag = true
		}
	}
	if flag {
		fmt.Println("DENIED")
	} else {
		fmt.Println("APPROVED")
	}
}


Measured memory_bytes: 512
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

const int MAX_N = 200000+5;
int uf_rank[MAX_N]; //depth of uf_rank
int uf_par[MAX_N]; //uf_parent


//initialize number of elements n
void init(int n) {
	rep(i, n) {
		uf_par[i] = i;
		uf_rank[i] = 0;

	}
}

//find root
int find(int x) {
	if (uf_par[x] == x) {
		return x;
	}
	else {//not uf_parent -> search uf_parent ,and substitution
		return uf_par[x] = find(uf_par[x]);
	}
}


//unite set
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (uf_rank[x] < uf_rank[y]) {
		uf_par[x] = y;
	}
	else {
		uf_par[y] = x;
		if (uf_rank[x] == uf_rank[y]) uf_rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}


int main(void) {

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

	int n;
	cin >> n;
	init(n);

	int m;
	cin >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		unite(a, b);
	}


	vector<int> c(n);

	rep(i, n) find(i);

	rep(i, n) {
	
		c[uf_par[i]] += 1;
		//cout << uf_par[i] << endl;
	}

	int ans = 0;
	rep(i, n) {
		ans = max(ans, c[i]);
	}
	
	cout << ans << endl;



	return 0;
}


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

const int MAXN = 2010;
typedef std::bitset<MAXN> B;
B out[MAXN], tar[MAXN], vis[MAXN * MAXN / 2];
int mx[MAXN][MAXN], cnt;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
} B son[MAXN];
int up[MAXN];
void dfs1(int u, int fa = 0) {
	son[u].reset(); son[u].set(u);
	if (fa) up[u] = up[fa] ? up[fa] : u;
	(tar[u] = tar[fa]).set(u);
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa) {
			dfs1(to[i], u);
			son[u] |= son[to[i]];
		}
	tar[u] |= son[u];
}
int n, m;
typedef std::pair<int, int> pi;
std::queue<pi> q;
void append(int t1, int t2) {
	q.emplace(t1, t2);
	out[t1][t2] = out[t2][t1] = true;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	for (int i = 1; i <= n; ++i) {
		up[i] = 0, dfs1(i);
		for (int j = 1; j <= n; ++j) if (j != i) {
			tar[j] |= son[i] ^ son[up[j]];
			if (!mx[i][j]) {
				mx[i][j] = mx[j][i] = ++cnt;
				vis[cnt] = tar[j];
			}
		}
	}
	for (int i = 1, t1, t2; i <= m; ++i)
		std::cin >> t1 >> t2, append(t1, t2);
	for (int i = 1; i <= n; ++i) out[i][i] = true;
	int ans = 0;
	static B can;
	while (!q.empty()) {
		int x, y; std::tie(x, y) = q.front(); q.pop(); ++ans;
		can = (out[x] ^ out[y]) & vis[mx[x][y]];
		for (int i = can._Find_first(); i != MAXN; i = can._Find_next(i))
			append(out[x][i] ? y : x, i);
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 534964
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define MAXN 500005
#define mod 1000000007ll

long long f[MAXN]={1ll};

long long power(long long x,long long p){
	if(p==1ll) return x%mod;
	if(p==0ll) return 0ll;
	long long t=power(x,p/2ll);
	if(p&1ll) return t*t%mod*x%mod;
	else return t*t%mod;
}

long long c(long long n,long long m){
	if(m==0||m==n) return 1ll;
	if(n<m) return 0ll;
	return f[n]*power(f[m],mod-2ll)%mod*power(f[n-m],mod-2ll)%mod;
}

long long n,m;
long long a,b;
int main(){
	scanf("%lld %lld",&n,&m);
	scanf("%lld %lld",&a,&b);
	for(long long i=1;i<=m+n;i++)
		f[i]=f[i-1]*i%mod;
	long long ans=c(m+n-2,m-1);
	long long i=n-a+1,j=b;
	while(i<=n&&j>=1){
		ans=((ans-c(i+j-2,j-1)*c(m+n-i-j,m-j))%mod+mod)%mod;
		i++;j--;
	}
	printf("%lld",ans);
	system("pause");
}






Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int fi[111][111];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H, N;
    cin >> W >> H >> N;
    while(N--){
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1){
            for(int w = x-1;w>=0;w--) for(int h=0;h<H;h++) fi[w][h] = 1;
        }
        else if(a == 2){
            for(int w = x;w<W;w++) for(int h=0;h<H;h++) fi[w][h] = 1;
        }
        else if(a == 3){
            for(int h = y-1;h>=0;h--) for(int w=0;w<W;w++) fi[w][h] = 1;
        }
        else{
            for(int h = y;h<H;h++) for(int w=0;w<W;w++) fi[w][h] = 1;
        }
    }
    ll ans = 0;
    for(int i=0;i<W;i++) for(int j=0;j<H;j++) if(fi[i][j] == 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define		vii 			vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
#define     test(i)        cout<<i<<endl
int dx[] = {-1 , 1 , 0 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 0 , 1 ,-1 ,-1 , 1 ,-1 , 1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
const int mxN=2e5+5,oo=0x3f3f3f3f,mod=1e9+7;
int n,w;
ll arr[mxN][2],dp[105][mxN];
ll go(int idx,int rem){
    if(idx==n)
        return 0;
    ll &ret=dp[idx][rem];
    if(~ret)
        return ret;
    if(rem-arr[idx][0]>=0)
        ret=go(idx+1,rem-arr[idx][0])+arr[idx][1];
    return ret=max(ret,go(idx+1,rem));
}
void solve(){
    cin>>n>>w;
    loop(n,i,0)
        cin>>arr[i][0]>>arr[i][1];
    mem(dp,-1);
    cout<<go(0,w)<<endl;
}
int main() {
    fast();
    solve();
}

Measured memory_bytes: 166144
from math import factorial
from operator import mul
from functools import reduce

def comb2(n,r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def pff(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf

N, M = map(int, input().split())
L = pff(M)


anst = int(1)
for i in L.values():
    anst *= comb2(i+N-1, i)
    anst = anst%1000000007

ans = anst
print(ans)

Measured memory_bytes: 3680
#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<string>
#include<math.h>
#include<vector>
#include <algorithm>
 
#include <bits/stdc++.h>
using namespace std;

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A-B>C)
        cout<<0;
    else
        cout<<(C-(A-B));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;

int main(){
	int ans = 1000000;
	int n;
	int max = 0;
	cin >> n;
	int x[101];
	for (int i = 1; i <= n; i++){
		cin >> x[i];
		if (x[i] > max){
			max = x[i];
		}
	}
	for (int i = 1; i <= max; i++){
		int sum = 0;
		for (int j = 1; j <= n; j++){
			sum += (x[j] - i)*(x[j] - i);
		}
		if (ans > sum){
			ans = sum;
		}
	}
	cout << ans << endl;
	return 0; 
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << end
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vl p(n);
    rep(i,n)cin >> p[i];
    ll res = 0;
    for(int i=1;i+1<n;i++){
        if(p[i-1]<p[i] && p[i] < p[i+1])res++;
        if(p[i-1]>p[i] && p[i] > p[i+1])res++;
    }
    cout << res << endl;
}


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

bool solve(const vector<string> &w) {
    int n = w.size();
    for (int i = 0; i < n - 1; i++) {
        if (w[i].back() != w[i + 1].front()) {
            return false;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (w[i] == w[j]) return false;
        }
    }
    return true;
}

int main() {
    int n; cin >> n;
    vector<string> w(n);

    for (int i = 0; i < n; i++) cin >> w[i];

    if (solve(w)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;

int main()
{
	int N;
	char S[110] = { 0, };
	scanf("%d%s", &N, S);
	if (N % 2 == 0) {
		int i = 0;
		for (; i < N / 2; i++) {
			if (S[i] != S[i + N / 2]) break;
		}
		if (i == N / 2) {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128