akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll x,y,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1e9,Min=1e9+1;
  string s,t,u;
  bool ok = false;
  cin >> n;
  VI a(n);
  rep(i,n) {
    cin >> a[i];
  }
  sort(ALL(a));
  rep(i,n){
    if(i==n-1){
      break;
    }
    if(a[i] == a[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
 
  cout << "YES" << endl;


  return 0;
}

Measured memory_bytes: 1024
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_A


def solve():
    _ = int(input())
    S = set(map(int, input().split()))
    _ = int(input())
    T = set(map(int, input().split()))

    print(len(S & T))


if __name__ == '__main__':
    solve()



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

int main(){
    long long a, b, c, x ,y;
    cin >> a >> b >> c >> x >> y;
    vector<long long> z(3);
    z[0] = 2 * c * max(x,y);
    z[1] = a*x + b*y;
    if(x >= y)
        z[2] = 2*c*y + a*(x-y);
    
    else
        z[2] = 2*c*x + b*(y-x);

    sort(z.begin(),z.end());

    cout << z[0] << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=200007;
int n;
long long A[N],S[N],T[N],B[N];
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%lld",&A[i]);
	For(i,n+1,n<<1) A[i]=A[i-n];
	For(i,1,n<<1) {
		if(i&1) S[i]=S[i-1]+A[i];
		else S[i]=S[i-1]-A[i];
		if(i&1) T[i]=T[i-1]-A[i];
		else T[i]=T[i-1]+A[i];
	}
	For(i,1,n) {
		if(i&1) B[i]=S[n+i-1]-S[i-1];
		else B[i]=T[n+i-1]-T[i-1];
	}
	For(i,1,n) printf("%lld ",B[i]);
	return 0;
}

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

int main()
{
    int h, n;
    cin >> h >> n;
    rep(i, n)
    {
        int a;
        cin >> a;
        h -= a;
        if (h <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  ll X; cin >> X; ll ans = 0;
  ans+=(X/500)*1000; X-=((X/500)*500);
  ans+=(X/5)*5;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int N,maxnum=-1,minnum=2001;
  cin>>N;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
    if(x[i]<minnum) minnum=x[i];
    if(x[i]>maxnum) maxnum=x[i];
  }
  int dis=maxnum-minnum;
  if(dis%2==1) dis+=1;
  cout<<dis/2<<endl;
  return 0;
}



Measured memory_bytes: 3132
def main():
    N, x = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] > x:
            ans += A[i] - x
            A[i] = x
    for i in range(N-1):
        if A[i] + A[i+1] > x:
            ans += A[i+1] - (x - A[i])
            A[i+1] = x - A[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
N = int(input())
t0, a0 = 1, 1
for _ in range(N):
    t, a = map(int,input().split())
    n = max((t0-1)//t+1, (a0-1)//a+1)
    t0, a0 = n*t, n*a

print(t0+a0)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string[] AB = Console.ReadLine().Split(' ');
            int A = int.Parse(AB[0]);
            int B = int.Parse(AB[1]);
            bool flag=false;

            for (int i = A; i <= B; i++)
            {
                if (i % K == 0)
                {
                    flag = true;
                    break;
                }
            }

            if (flag)
            {
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine("NG");
            }
        }
    }
}


Measured memory_bytes: 17656
n,w = map(int,input().split())

INF = float('inf')
ww = [0]*n
vv = [0]*n
vm = 1000
dp = [[INF]*(n*vm+1) for _ in range(n+1)]

for i in range(n):
  ww[i],vv[i] = map(int,input().split())      

dp[0][0] = 0  
for i in range(1,n+1):
  dp[i][0] = 0
  for j in range(1,n*vm+1):        
    if j < vv[i-1]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-vv[i-1]] + ww[i-1])        

ans = 0
for i in range(n*vm+1):
  if dp[n][i]<=w:
    ans = i
print(ans)    

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

using namespace std;

int main()
{
	int n, d, p, q, s, t;
	
	while(cin>>n&&n){
		vector<bool> vec[5];
		
		while(n--){
			cin >> d >> p >> q;
			q--;
			if(d == 1){
				t = -1;
				for(int i = q, k = 0; k < p; i++, k++){
					for(int j = vec[i].size()-1; j >= 0; j--){
						if(vec[i][j]){
							t = max(t, j);
						}
					}
				}
				
				for(int i = q, k = 0; k < p; i++, k++){
					if(vec[i].size() <= (t+1)){
						while(vec[i].size() < (t+1)){
							vec[i].push_back(false);
						}
						vec[i].push_back(true);
					} else {
						vec[i][t+1] = true;
					}
				}
			} else {
				t = -1;
				for(int i = vec[q].size()-1; i >= 0; i--){
					if(vec[q][i]){
						t = i;
						break;
					}
				}
				s = 0;
				for(int i = t+1; i < vec[q].size() && s < p; i++, s++){
					vec[q][i] = true;
				}
				for(;s < p; s++){
					vec[q].push_back(true);
				}
			}
			t = vec[0].size();
			for(int i = 1; i < 5; i++){
				s = vec[i].size();
				t = min(s, t);
			}

			for(int i = t-1; i >= 0; i--){
				bool f = true;
				for(int j = 0; j < 5; j++){
					if(!vec[j][i]){
						f = false;
						break;
					}
				}
				
				if(f){
					for(int j = 0; j < 5; j++){
						vec[j].erase((vec[j].begin()+i));
					}
				}
			}
		}
		
		t = 0;
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < vec[i].size(); j++){
				if(vec[i][j]){
					t++;
				}
			}
		}
		
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

int main(){
    int t;
    while(cin >> t, t){
        int n;
        cin >> n;
        int sum = 0;
        for(int i=0;i<n;i++){
            int s,f;
            cin >> s >> f;
            sum += f-s;
        }
        if(sum<t) cout << t-sum << endl;
        else cout << "OK" << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll n,k,a[100010],x;
    cin>>n>>k;
    ll b=n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(b==n&&a[i]>=0){
            b=i;
        }
    }
    ll d1[100010]={},d2[100010]={};
    for(int i=b;i<n;i++){
        d1[i-b+1]=a[i];
    }
    for(int i=b-1;i>=0;i--){
        d2[b-i]=-a[i];
    }
    ll z1=n-b,z2=b;
    ll ans=1e12;
    for(int i=0;i<=k&&i<=n-b;i++){
        if(k-i>b) continue;
        ans=min(ans,max(d1[i],d2[k-i])+2*min(d1[i],d2[k-i]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
        int a,b,c;
        cin >> a >> b >> c;
        if(a==b){
                cout << c << endl;
                return 0;
        }
        if(b==c){
                cout << a << endl;
                return 0;
        }
        if(a==c){
                cout << b << endl;
                return 0;
        }
        return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
LS = list(S)
hantei = False

for i in range(len(S)):
    temp1 = LS[0]
    LS[0] = LS[-1]
    #print("i = ", i, "回目：", "".join(LS))
    for j in range(1, len(S)):
        if j % 2 != 0:
            temp2 = LS[j]
            LS[j] = temp1
            #print("j = ", j, "回目：", "".join(LS))
        else:
            temp1 = LS[j]
            LS[j] = temp2
            #print("j = ", j, "回目：", "".join(LS))
    LStoS = "".join(LS)
    #print(LStoS)
    if LStoS == T:
        hantei = True
        break

if hantei:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

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

int gcd(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main() {
    int k;
    long sum = 0;

    cin >> k;

    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd(a, b, c);
            }
        }
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3624
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))

    pmod={}
    cummod=0
    for num in a:
        cummod+=num
        cummod%=m
        if cummod not in pmod:
            pmod[cummod]=1
        else:
            pmod[cummod]+=1
    
    if 0 in pmod:
        ans=pmod[0]
    else:
        ans=0
        
    for i in pmod:
        if pmod[i] >=2 :
            ans+=pmod[i]*(pmod[i]-1)//2
    
    print(ans)

if __name__=='__main__':
    main()

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

int main() {
  
  int H, W;
  cin >> H >> W;

  vector<char> C(H*W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> C.at(i*W+j);
      //cout << C.at(i*W+j) << endl;
    }
  }
  
  vector<char> COUT(H*2*W);
  for(int i = 0; i < H*2; i++) {
    for(int j = 0; j < W; j++) {
      COUT.at(i*W+j) = C.at(i/2*W+j);
      //cout << i/2*W+j;
      //cout << COUT.at(i*W+j);
    }
    //cout << endl;
  }
  
  for(int i = 0; i < H*2; i++) {
    for(int j = 0; j < W; j++) {
      cout << COUT.at(i*W+j);
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k, a, b, R;
  cin >> k >> a >> b;
  
  for(int i = 1; R <= b; i++){
    R = k * i;
    if(a <= R && R <= b){
      cout << "OK" << endl;
      break;
    }
  }
  
  if(b < R) cout << "NG" << flush;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>

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

ll gcd(ll a, ll b)
{
  if( a < b ) 
  {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}

void calcCd(ll x, vector<ll>& cd)
{
  cd.emplace_back(1);
  if(x == 1)
  {
    return;
  }
  for(ll i = 2; i <= sqrt(x); ++i)
  {
    bool push = false;
    while(x%i == 0)
    {
      x /= i;
      push = true;
    }
    if(push) cd.emplace_back(i);
  }
  if(x != 1)cd.emplace_back(x);
}

int main()
{
  ll a, b;
  cin >> a >> b;
  ll gcdab = gcd(a, b);
  vector<ll> cd;
  calcCd(gcdab, cd);

  cout << cd.size() << endl;
  return 0;
}


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

const int mxn = 100005;
int n, h[mxn], ff[mxn];

int dfs( int pos ) 
{
  if( pos == 0 ) return 0;
  if( ff[pos] != -1 ) return ff[pos];
  
  ff[pos] = 0;
  if( pos > 1 ) 
    ff[pos] = abs(h[pos - 1] - h[pos]) + dfs( pos - 1 );
  if( pos > 2 )
    ff[pos] = min(ff[pos], abs(h[pos - 2] - h[pos]) + dfs( pos - 2 ));
    
  return ff[pos];
}

int main()
{
  scanf("%d", &n);
  for(int i = 1; i <= n; i++)
  {
    scanf("%d", h + i);
  }  
  memset(ff, -1, sizeof ff);
  printf("%d\n", dfs( n ));
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int t = N;
  int sum = 0;
  while(t > 0) {
    sum += t % 10;
    t /= 10;
  }
  if ((N % sum) == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	ll n, k = -1;
	cin >> n;
	rep(i, 0, n + 1) {
		if (i * (i + 1) / 2 == n) {
			k = i + 1;
			break;
		}
	}
	if (k == -1) {
		puts("No"); return 0;
	}
	puts("Yes");
	vector<vector<ll>> ans(k);
	int x = 0, y = 1;
	rep(i, 1ll, n + 1) {
		ans[x].push_back(i);
		ans[y].push_back(i);
		y++;
		if (y == k)x++, y = x + 1;
	}
	printf("%lld\n", k);
	rep2(it, ans) {
		printf("%d", it.size());
		rep2(v, it)printf(" %lld", v);
		puts("");
	}
	return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define output_to_error freopen("error.txt" , "w" ,stderr)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'


int main()
{
	#ifdef LOCAL
        input_from_file;
        output_to_file;
        output_to_error;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n ; cin >> n ; 
	cout << ceil(n/2.0);


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    if (n%1000==0) cout<<0;
    else cout<<1000-n%1000;
    return 0;
}

Measured memory_bytes: 3624
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :dp

  def initialize
    @n = gets.to_s.to_i
    @a = Array.new(n+1, 0)
  end

  def solve
    rec
    @a
  end

  def rec
    max = (Math.sqrt(n) * 1.3).to_i
    1.upto(max) do |x|
      1.upto(max) do |y|
        1.upto(max) do |z|
          m = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
          next if n < m
          @a[m] += 1
        end
      end
    end
  end

  def show(ans)
    1.upto(n) do |i|
      puts ans[i]
    end
  end
end

Problem.new.instance_eval do
  show(solve)
end


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

#define int long long

char* Solve(string S)
{
    stack<char> s;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '(') s.push(')');
        else if (S[i] == '[') s.push(']');
        else if (S[i] == ')' || S[i] == ']')
        {
            if (s.empty() || s.top() != S[i]) return "no";
            s.pop();
        }
    }
    if (!s.empty()) return "no";
    return "yes";
}

signed main()
{
    string S;
    while (getline(cin, S), S != ".")
    {
        printf("%s\n", Solve(S));
    }
    return 0;
}

Measured memory_bytes: 1180
A, B, K = map(int, input().split())
s = [A+i for i in range(K) if A+i <= B]
b = [B-i for i in range(K) if B-i >= A]
s.sort()
b.sort()
for i in s:
    print(i)
for i in b:
    if i not in s:
        print(i)

Measured memory_bytes: 3060
#include<stdio.h>
#define N 10000

int main(void){
  int i,num,j;
  int l[3],s1,s2;
  int swp,swpc;
  int n,r;
  int ans[N];

  for(i=0;;){
    scanf("%d%d%d",&l[0],&l[1],&l[2]);
    if(l[0]==0)
      break;
    for(;;){
      swpc=0;
      for(j=0;j<2;j++){
        if(l[j]>l[j+1]){
          swpc=1;
          swp=l[j];
          l[j]=l[j+1];
          l[j+1]=swp;
        }
      }
      if(swpc==0)
        break;
    }
    s1=l[0];
    s2=l[1];
    scanf("%d",&n);
    for(j=0;j<n;j++){
      scanf("%d",&r);
      if(4*r*r>(s1*s1+s2*s2)){
        ans[i]=1;
      }else{
        ans[i]=0;
      }
      i++;
    }
  }

  num=i;
  for(i=0;i<num;i++){
    if(ans[i]==1)
      printf("OK\n");
    else
      printf("NA\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(i,s,n) for(int i=s;i<=n;i++)
#define ford(j,s,n) for(int i=n;i>=s;i--)
#define pb push_back
#define TEST int t; cin>>t; for(int T=1;T<=t;T++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,d,ans=0,a,b;
    vi num;
    map <pi,int> mp;
    cin>>n>>m;
    vector <vi> p(n+1);
    fori(i,0,n-1){
    	cin>>a;
    	num.pb(a);
    }
    fori(i,0,m-1){
    	cin>>a>>b;
    	mp[{a,b}]++;
    	if(mp[{a,b}]==1){
    		p[a].pb(b);
    		p[b].pb(a);
    	}
    }
    fori(i,1,n){
    	int h=num[i-1];
    	for(auto j:p[i]){
    	   if(num[j-1]>=h){
    			h=-1; break;
    		}
    	}
    	if(h!=-1) ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 15048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		int ans = A - (2 * B);
		if (ans < 0){
			ans = 0;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
N,M = map(int,input().split())
S = []
for i in range(M):
    k = list(map(int,input().split()))
    S.append(k[1:])
P = list(map(int,input().split()))

ans = 0
for i in range(2**N):
    judge = 0
    for j in range(M):
        c = 0
        for k in S[j]:
            if ((i>>(k-1)) & 1):
                c += 1
        if c % 2 != P[j]:
            judge = 1
            break
    if judge == 0:
       ans += 1

print(ans)

Measured memory_bytes: 41072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
	int k;
	cin >> k;
	cout << a[k - 1] << endl;
	return 0;
}


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

class Dice {
  int U, D, N, E, S, W;

  void goN() {
    int tmp = U;
    U = S;
    S = D;
    D = N;
    N = tmp;
  }

  void goE() {
    int tmp = U;
    U = W;
    W = D;
    D = E;
    E = tmp;
  }

  void goS() {
    int tmp = U;
    U = N;
    N = D;
    D = S;
    S = tmp;
  }

  void goW() {
    int tmp = U;
    U = E;
    E = D;
    D = W;
    W = tmp;
  }

  public:
  Dice(vector<int> label) {
    U = label.at(0);
    S = label.at(1);
    E = label.at(2);
    W = label.at(3);
    N = label.at(4);
    D = label.at(5);
  }

  void go(char way) {
    switch(way) {
      case 'N':
        goN();
        break;
      case 'E':
        goE();
        break;
      case 'S':
        goS();
        break;
      case 'W':
        goW();
        break;
    }
  }

  string getPos(int label, string avoid) {
    string pos = "";
    if (U == label && avoid.find("U") == string::npos) pos += "U";
    if (D == label && avoid.find("D") == string::npos) pos += "D";
    if (N == label && avoid.find("N") == string::npos) pos += "N";
    if (E == label && avoid.find("E") == string::npos) pos += "E";
    if (S == label && avoid.find("S") == string::npos) pos += "S";
    if (W == label && avoid.find("W") == string::npos) pos += "W";
    return pos;
  }

  int getLabel(char pos) {
    if (pos == 'U') return U;
    else if (pos == 'D') return D;
    else if (pos == 'N') return N;
    else if (pos == 'E') return E;
    else if (pos == 'S') return S;
    else if (pos == 'W') return W;
    return -1;
  }
};

bool isSameAllSurf(Dice &d1, Dice &d2) {
  if (d1.getLabel('U') == d2.getLabel('U') &&
    d1.getLabel('D') == d2.getLabel('D') &&
    d1.getLabel('N') == d2.getLabel('N') &&
    d1.getLabel('E') == d2.getLabel('E') &&
    d1.getLabel('S') == d2.getLabel('S') &&
    d1.getLabel('W') == d2.getLabel('W')) return true;
  return false;
}

bool isSame(Dice &d1, Dice &d2) {
  for (int i = 0; i < 4; ++i) {
    d1.go('S');
    for (int j = 0; j < 4; ++j) {
      d1.go('E');
      if (isSameAllSurf(d1, d2)) return true;
    }
  }
  d1.go('E');
  d1.go('S');
  for (int i = 0; i < 4; ++i) {
    d1.go('E');
    if (isSameAllSurf(d1, d2)) return true;
  }
  d1.go('S');
  d1.go('S');
  for (int i = 0; i < 4; ++i) {
    d1.go('E');
    if (isSameAllSurf(d1, d2)) return true;
  }

  return false;
}

int main() {
  int n;
  cin >> n;
  vector<int> label(6);
  vector<Dice> dices;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 6; ++j) {
      cin >> label.at(j);
    }
    Dice d(label);
    dices.push_back(d);
  }

  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (isSame(dices.at(i), dices.at(j))) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,k;cin>>n>>k;
  vector<ll> A(n+1);
  A[0] = 0;
  ll ans = 0;
  reps(i,n){
    cin>>A[i];A[i]--;
  }
  vector<ll> B(n+1);
  map<ll,ll> mp;
  reps(i,n){
    B[i] = A[i] + B[i-1];
    B[i] %= k;
    mp[B[i]] = 0;
  }
  

  int b=0, e=0;
  while(e < n+1){
    if(e - b == k){
      mp[B[b]]--;
      b++;
    }
    ans += mp[B[e]];
    mp[B[e]]++;
    e++;
    //cout<<e-1<<" "<<ans<<endl;
  }

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

Measured memory_bytes: 15872
a,b,c,x,y = map(int,input().split())

if a + b > c * 2:
    buf = min(x,y) * c * 2
    buf2 = max(x,y) * c * 2
    if x > y:
        tmp = buf + (x-y) * a
    else:
        tmp = buf + (y-x) * b
    ans = min(buf2,tmp)
else:
    ans = x * a + y * b

print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  int cnt=0;
  int n; cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int q; cin >> q;
  for(int i=0;i<q;i++){
    int key; cin >> key;
    int left=0,right=n;
    while(left<right){
      int mid=(left+right)/2;
      if(a[mid]==key){
        cnt++;
        break;
      }else if(key<a[mid]){
        right=mid;
      }else{
        left=mid+1;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3436
n = int(input())
input_list = [list(input()) for i in range(n)]

and_ = set(input_list[0])
for lists in input_list:
    and_ = and_ & set(lists) 
and_ = list(and_)
and_.sort()

ans = ""
for char in and_:
    f = [i.count(char) for i in input_list]
    ans += min(f) * char
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int sum=0,min=1001;
  while(k!=0)
  {
    for(int i=0;i<n;i++)
    {
      if(min>arr[i])
      {
        min=arr[i];
      }
    }
    sum+=min;
    for(int i=0;i<n;i++)
    {
      if(min==arr[i])
      {
        arr[i]=1001;
        break;
      }
    }
    k--;
    min=1002;
  }
  cout << sum;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const double uni = 3.305785;
double a, b;

int main()
{
  scanf(" %lf %lf", &a, &b);

  printf("%.15f\n", a * b / uni);

  return 0;
}

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

int main(){
    int cards[4][14] =  {0};
    int n, num, i=0;
    string mark;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> mark >> num;
        if (mark == "S") cards[0][num] = 1;
        if (mark == "H") cards[1][num] = 1;
        if (mark == "C") cards[2][num] = 1;
        if (mark == "D") cards[3][num] = 1;
    }
    for (int i=1;i<14;i++){
        if (cards[0][i] == 0) cout << "S" << " " << i << endl;
    }
    for (int i=1;i<14;i++){
        if (cards[1][i] == 0) cout << "H" << " " << i << endl;
    }
    for (int i=1;i<14;i++){
        if (cards[2][i] == 0) cout << "C" << " " << i << endl;
    }
    for (int i=1;i<14;i++){
        if (cards[3][i] == 0) cout << "D" << " " << i << endl;
    }

    return 0;
}


Measured memory_bytes: 3144
import sys
input = sys.stdin.readline
A, B = (int(i) for i in input().split())

def mygcd(a, b):
    while b!=0:
        a,b = b, a%b
    return a

gcd = mygcd(A, B)
temp = gcd
count = 1
for i in range(2, int(-(-gcd**0.5//1))+1):
    if temp%i == 0:
        cnt = 0
        while temp%i ==0:
            cnt +=1
            temp //= i
        count +=1
if temp != 1:
    count +=1

print(count)


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

int main(){

    int n;
    cin >> n;
    vector<tuple<int,int>> ab(n);
    int a,b;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        ab.at(i)=make_tuple(b,a);
    }

    sort(ab.begin(),ab.end());

    int time=0;
    string ans="Yes";
    for(int i=0; i<n; i++){
        time+=get<1>(ab.at(i));
        if(time>get<0>(ab.at(i))){
            ans="No";
            break;
        }
        //cout << time << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4720
from fractions import gcd
from copy import deepcopy as dc
N, K = map(int, input().split())
A = list(map(int, input().split()))
def divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort()
  return divisors
div = divisors(sum(A))
def check(g):
  Atemp = dc(A)
  for i in range(N):
    Atemp[i] %= g
  Atemp.sort()
  i = len(A) - sum(Atemp) // g
  #print(g, i, max(sum(Atemp[: i]), len(Atemp[i: ]) * g - sum(Atemp[i: ])))
  if max(sum(Atemp[: i]), len(Atemp[i: ]) * g - sum(Atemp[i: ])) <= K:
    return True
  else:
    return False

res = 1
for d in div:
  if check(d) == True:
    res = d
print(res)

Measured memory_bytes: 74712
#include<iostream>
using namespace std;
int main(){
  int a[5],i,j,k,flag;
  flag=0;
  for(i=0;i<5;i++){
    cin >> a[i];
  }
  cin >> k;
  
  for(i=0;i<4;i++){
    for(j=i+1;j<5;j++){
      if(a[j]-a[i]>k){
        flag=1;
      }
    }
  }
  
  if(flag){
    cout << ":(" << endl;
  }
  else{
    cout << "Yay!" << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h_L = list(map(int,input().split()))

dp = [10**9] * n
dp[0] = 0
dp[1] = abs(h_L[1] - h_L[0])

for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h_L[i-1] - h_L[i]),dp[i-2]+abs(h_L[i-2] - h_L[i]))

print(dp[n-1])

Measured memory_bytes: 52208
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    auto s = readln.split.to!(int[]).sum();
    writeln(s >= 22 ? "bust" : "win");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a[100], b;
    cin >> b;
    for (int i = 0; i < b; i++)
    {
        cin >> a[i];
    }
 
    for (int i = b-1 ; i >= 0 ;i--)
    {
        cout << a[i];
        if (i > 0)
        {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
import sys
from collections import Counter


def main():
    N,M = list(map(int, sys.stdin.readline().split()))
    AB_list = [ list(map(int, sys.stdin.readline().split())) for _ in range(M) ]


    ##############################
    # Union Find
    parents = [-1] * (N + 1)

    def find(x :int) -> int:
        if parents[x] < 0:
            return x
        
        parents[x] = find( parents[x] )
        return parents[x]

    def union(x,y):
        root_x = find(x)
        root_y = find(y)

        if root_x == root_y:
            return
        
        depth_x = parents[root_x]
        depth_y = parents[root_y]

        if depth_x <= depth_y:
            parents[root_y] = root_x

            if depth_x == depth_y:
                parents[root_x] -= 1

        else:
            parents[root_x] = root_y
    ##############################


    for a,b in AB_list:
        union(a,b)
    
    group = [ find(num) for num in range(1,N+1) ]
    cnt = Counter(group)
    
    print(cnt.most_common(1)[0][1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 49552
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;


int A[1000000];
int l,n;
long long cnt;
vector<int> G;

void insertionsort(int A[],int n,int g){
	for(int i=g;i<n;i++){
		int v=A[i];
		int j=i-g;
		while(j>=0&&A[j]>v){
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}

void shellsort(int A[],int n){
	for(int h=1;;){
		if(h>n)	break;
		G.push_back(h);
		h=h*3+1;
	}
	
	for(int i=G.size()-1;i>=0;i--){
		insertionsort(A,n,G[i]);
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)	scanf("%d",&A[i]);
	cnt=0;
	
	shellsort(A,n);
	
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--){
		printf("%d",G[i]);
		if(i)printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++)	printf("%d\n",A[i]);
	
	return 0;
} 



Measured memory_bytes: 7192
#include <iostream>
#include <cstdio>
using namespace std;
int t, p, q;
#define M 200
inline int sqr(int x) {
    return x * x;
}
bool check() {
    int cnt = 0;
    for(int m = -M; m <= M; m++) {
        for(int n = -M; n <= M; n++) {
            int r = sqr(m) + sqr(n);
            if(r == 0) continue;
            if((m * p + n * q) % r == 0 && (m * q - n * p) % r == 0) cnt++;
            if(cnt > 8) return false;
        }
    }
    return true;
}
int main() {
    scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &p, &q);
        puts(check() ?"P": "C");
    }
    return 0;
}

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

using namespace std;
using i64 = std::int_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  i64 N, D, A;
  cin >> N >> D >> A;
  vector<i64> X(N), H(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> H[i];
    H[i] = (H[i] + A - 1) / A;
  }

  vector<int> idx(N);
  for (int i = 0; i < N; i++) {
    idx[i] = i;
  }
  sort(idx.begin(), idx.end(), [&](int i, int j) { return X[i] < X[j]; });

  i64 res = 0, n = 0;
  queue<pair<i64, i64>> que;
  for (int i : idx) {
    while (!que.empty() && que.front().first < X[i]) {
      n -= que.front().second;
      que.pop();
    }
    H[i] -= n;
    if (H[i] <= 0) continue;
    res += H[i];
    que.push(make_pair(X[i] + 2 * D, H[i]));
    n += H[i];
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 5760
K=int(input())
from math import gcd
# サイズは最大8*10^6だけどOK(これくらいが限界ギリギリOKだよぉ)
lis = [gcd(gcd(a,b),c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1)]
print(sum(lis))

Measured memory_bytes: 71556
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;

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

  ll sum = 0;
  ll counter = 0;
  // 偶数番目が正
  for(ll i = 0; i < n; i++) {
    sum += A[i];

    if(i % 2 == 0) {
      while(sum <= 0){
        sum++;
        counter++;
      }
    } else {
      while(sum >= 0){
        sum--;
        counter++;
      }
    }
  }

  ll counterNeg = 0;
  sum = 0;
  for(ll i = 0; i < n; i++) {
    sum += A[i];

    if(i % 2 == 1) {
      while(sum <= 0){
        sum++;
        counterNeg++;
      }
    } else {
      while(sum >= 0){
        sum--;
        counterNeg++;
      }
    }
  }

  cout << min(counter, counterNeg) << endl;
  return 0;
}


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

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    double ret;
    if (2 * x < a * a * b) {
        ret = atan(a * b * b / 2 / x);
    } else {
        ret = atan((b - x / a / a) * 2 / a);
    }
    ret = ret * 180 / M_PI;
    cout << fixed << setprecision(12);
    cout << ret << endl;
    return 0;
}


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

using namespace std;
const int N = 212345;

int f1[N],f2[N];

map<pair<int,int>,int>mp;

int Find1(int x) {
    if (x != f1[x]) f1[x] = Find1(f1[x]);
    return f1[x];
}

int Find2(int x) {
    if (x != f2[x]) f2[x] = Find2(f2[x]);
    return f2[x];
}

void Join2(int x,int y) {
    int fx = Find2(x);
    int fy = Find2(y);
    if (fx != fy) {
        f2[fx] = fy;
    }
}

void Join1(int x,int y) {
    int fx = Find1(x);
    int fy = Find1(y);
    if (fx != fy) {
        f1[fx] = fy;
    }
}

int main() {
    int n, k, l;
    scanf("%d%d%d", &n, &k, &l);
    for (int i = 0; i <= n; i++) {
        f1[i] = i;
        f2[i] = i;
    }
    for (int i = 0; i <= k - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        Join1(x, y);
    }
    for (int i = 0; i <= l - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        Join2(x, y);
    }
    for (int i = 1; i <= n; i++) {
        mp[make_pair(Find1(i), Find2(i))]++;
    }
    for (int i = 1; i <= n; i++) {
        if (i == 1)printf("%d", mp[make_pair(Find1(i), Find2(i))]);
        else printf(" %d", mp[make_pair(Find1(i), Find2(i))]);
    }
    return 0;
}

Measured memory_bytes: 13568
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    a = []
    a.append([int(x) for x in input().split()])
    a.append([int(x) for x in input().split()])
    a.append([int(x) for x in input().split()])
    N = int(input())
    for i in range(N):
        b = int(input())
        for j in range(3):
            for k in range(3):
                if a[j][k] == b:
                    a[j][k] = -1
    tate = [0, 0, 0]
    yoko = [0, 0, 0]
    naname = [0, 0]
    for i in range(3):
        for j in range(3):
            tate[i] += a[i][j]
            yoko[j] += a[i][j]
        naname[0] += a[i][i]
        naname[1] += a[i][2 - i]
    # print(tate)
    # print(yoko)
    # print(naname)
    if -3 in tate or -3 in yoko or -3 in naname:
        return "Yes"
    return "No"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 3816
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-8
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;

int main(){
	int N;
	scanf("%d",&N);
	const int hoge = N;
	rep(n,hoge){
		int field[10][10];
		bool fail[10][10]={{0}};
		rep(i,9){
			rep(j,9){
				scanf("%d",&field[i][j]);
			}
		}
		//よこ
		rep(i,9){
			int cnt[10]={0};
			rep(j,9){
				cnt[field[i][j]]++;
			}
			rep(j,10){
				if(cnt[j]>1){
					rep(k,9){
						if(field[i][k]==j)fail[i][k]=1;
					}
				}
			}
		}
		//たて
		rep(i,9){
			int cnt[10]={0};
			rep(j,9){
				cnt[field[j][i]]++;
			}
			rep(j,10){
				if(cnt[j]>1){
					rep(k,9){
						if(field[k][i]==j)fail[k][i]=1;
					}
				}
			}
		}
		//わく
		for(int i = 0; i < 9;i+=3){
			for(int j = 0; j < 9; j+=3){
				int cnt[10]={0};
				reps(k,i,i+3){
					reps(l,j,j+3){
						cnt[field[k][l]]++;
					}
				}
				rep(m,10){
					if(cnt[m]>1){
						reps(k,i,i+3){
							reps(l,j,j+3){
								if(field[k][l] == m)fail[k][l]=1;
							}
						}
					}
				}
			}
		}
		rep(i,9){
			rep(j,9){
				printf("%c%d",fail[i][j]==1?'*':' ',field[i][j]);
			}
			puts("");
		}
		n == hoge-1?printf(""):puts("");
	}
	return 0;
}

Measured memory_bytes: 1196
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val M = sc.nextInt()
val X = sc.nextInt()
val Y = sc.nextInt()

fun main(args: Array<String>) {
    val xMax = Array(N) { sc.nextInt() }.sorted().max() ?: 0
    val yMin = Array(M) { sc.nextInt() }.sorted().min() ?: 0

    if (xMax < Y && X < yMin && xMax < yMin) {
        println("No War")
    } else {
        println("War")
    }
}


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

int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((a+b) > (c+d)) cout << "Left\n";
    else if((a+b)==(c+d)) cout << "Balanced\n";
    else cout << "Right\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>
 
using namespace std;
 
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
 
int Y,X,obj,cnt;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
 
void dfs2(int y, int x, int now, int next, vector< vector<int> >& state){
  int i;
 
  cnt++;
  state[y][x] = next;
  REP(i,4){
    int my = y + dy[i];
    int mx = x + dx[i];
    if(0 <= my && my < Y && 0 <= mx && mx < X && state[my][mx] == now) dfs2(my,mx,now,next,state);
  }
}
 
int dfs(int now, int next, int depth, vector< vector<int> > state){
  int res=0,i;

  cnt = 0;
  dfs2(0,0,now,next,state);
 
  if(now == obj && depth == 5) return cnt;
 
  REP(i,7) if(i != 0 && i != next){
    if(depth == 5) continue;
    res = max(res, dfs(next,i,depth+1,state));
  }
 
  return res;
}
 
int main(){
  int i,j;
  vector< vector<int> > board;
 
  while(1){
    cin >> Y >> X >> obj;
    if(X == 0 && Y == 0 && obj == 0) break;
 
    board.resize(Y);
    REP(i,Y) board[i].resize(X);
    REP(i,Y) REP(j,X) cin >> board[i][j];
 
    int res = 0, now = board[0][0];
    REP(i,7) if(i != 0 && now != i) res = max(res,dfs(now,i,0,board));
 
    cout << res << endl;
  }
 
  return 0;
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    vector<ll> s(M);
    vector<ll> c(M);
    vector<ll> m(N,-1);
    rep(i,M){
        cin >>s[i]>>c[i];
        s[i]--;
        if(m[s[i]] != -1 && m[s[i]] != c[i] || (s[i] ==0 && c[i] ==0 && N!=1)){
            cout << -1 << endl;
            return 0;
        }
        m[s[i]] =c[i];
    }
    

    rep(i,N){
        if(m[i] == -1 && i == 0 && N==1){
            cout<<0;
        }else if(m[i] == -1 && i == 0){
            cout <<1;
        }else if(m[i] == -1){
            cout<<0;
        }else{
            cout<<m[i];
        }
    }
    cout<<endl;


    return 0;
    

}

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

using namespace std;

const int MAX = 111;
int n, k;
int x[MAX];

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += min(abs(x[i]) * 2, abs(x[i] - k) * 2);
  }
  cout << ans << endl;
  return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vector<vvi> F(N, vvi(5, vi(2)));
    vvi P(N, vi(11));
    REP(i, N)
    {
        REP(j, 5)
        {
            REP(k, 2)
            {
                cin >> F[i][j][k];
            }
        }
    }
    REP(i, N)
    {
        REP(j, 11)
        {
            cin >> P[i][j];
        }
    }

    int ans = -INF;
    for(int n = 1; n < 1024; n++)
    {
        int p = 0;
        REP(i, N)
        {
            int count = 0;
            REP(j, 5)
            {
                REP(k, 2)
                {
                    if(F[i][j][k] && (1 << (j + 5*k)) & n) count++;
                }
            }
            p += P[i][count];
        }
        ans = max(ans, p);
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
import itertools

def check(lis, a):
    return sum([i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]])
   
n, m, q = map(int, input().split())
a = [[int(i) for i in input().split(" ")] for j in range(q)]
ans = 0
for i in itertools.combinations_with_replacement(range(m), n):
    ans = max(ans, check(i, a))
print(ans)


Measured memory_bytes: 9120