akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int a,b,c;
  cin>>a>>b>>c;
  string ans="No";
  if(a+b>=c)ans="Yes";
  cout(ans);
  return 0;
}

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

int x, y;

int main()
{
	cin >> x >> y;
	ll sol = 0;
	if ( x == 3 )
		sol += 1e5;
	if ( x == 2 )
		sol += 2e5;
	if ( x == 1 )
		sol += 3e5;
	
	if ( y == 3 )
		sol += 1e5;
	if ( y == 2 )
		sol += 2e5;
	if ( y == 1 )
		sol += 3e5;
	
	if ( x == 1 && y == 1 )
		sol += 4e5;
	cout << sol << "\n";
	return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        int i = 1;
        while (i < 10) {

            for (int s = 1;s < 10; s++){
                System.out.println(i + "x"+ s +"=" +(i*s));
                
            }
            i++;
        }
            
        
        
        
        
        
        
        
        
    
        
    
    
    
    }
}



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

// N = (aK+1) * K^b
// という形なので、K が N の約数である場合は、N/K mod K == 1 であるならOK
// K が N の約数ではない場合は、
//  N = (aK+1) * K^0 = aK + 1
//  N-1 = aK
// という形をしているので、N-1 の約数ならば OK
// N と N-1 は互いに素なので、上記2つが重複することはないので、独立に数えてOK

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

  ll ans = 0;

  // N-1の約数列挙
  for (ll k=1; k*k<=N-1; k++) {
    if ( (N-1)%k == 0 ) {
      ans++;
      // 1 は除外。K^2=N の場合は1個だけ
      if ( (k!=1) && ((k*k)!=(N-1)) ) ans++;
//     cout << "A : " << ans << endl;
    }
  }

  for (ll k=1; k*k<=N; k++) {
    if ( N%k == 0 ) {
//      cout << "A : " << k << endl;
      // N の約数の場合
      ll t = N;
      while( k!=1 && t%k==0 ) t /= k;
      if ( t % k == 1 ) {
        ans++;
//        cout << "  y " << k << endl;
//     cout << "B : " << ans << endl;
      }
      if ( k*k != N ) {
        ll tk = N/k;
        t = N;
        while( t%tk==0 ) t /= tk;
        if ( t % tk == 1 ) {
          ans++;
//        cout << "  y " << tk << endl;
//     cout << "C : " << ans << endl;
        }
      }
    }
  }
  if ( N==2 ) ans--;
  cout << ans << endl;
}


Measured memory_bytes: 256
D=zeros(Int,10,10)
for i=1:parse(Int,readline())
	x=i
	while x>=10
		x=div(x,10)
	end
	D[x+1,i%10+1]+=1
end
ans=0
for i=1:10,j=1:10
	ans+=D[i,j]*D[j,i]
end
println(ans)


Measured memory_bytes: 171912
A, B, C = map(int, input().split())

ans = 0
if A&1 or B&1 or C&1:
    print(ans)
    exit(0)

if A == B == C:
    print(-1)
    exit(0)

while True:
    if A&1 or B&1 or C&1:
        break
    nA = B//2 + C//2
    nB = A//2 + C//2
    nC = B//2 + A//2
    ans += 1
    A = nA
    B = nB
    C = nC

print(ans)



Measured memory_bytes: 9128
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n,d;
  cin >>n>>d;
  int a=2*d+1;
  if(n%a==0) cout<<n/a<<endl;
  else cout<<n/a+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Z> map<Z, int> factorize(Z n) {
  map<Z, int> res;
  for (Z i = 2; i * i <= n; ++i) while (n % i == 0) ++res[i], n /= i;
  if (n != 1) ++res[n];
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint a, b; cin >> a >> b;
  auto mp = factorize(__gcd(a, b));
  cout << mp.size() + 1 << '\n';
}

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

#define INF 1e9

using namespace std;

struct Edge {
	int to, cost;
};
struct Node {
	int now, rest, cost;
};
bool operator <(const Node& n1, const Node& n2) {
	return n1.cost < n2.cost;
}

int main() {
	int c, n, l, s, d;
	while ( cin >> c >> n >> l >> s >> d, c || n || l || s || d ) {
		--s, --d;

		vector<Edge> m[100];
		for (int i = 0; i < l; ++i) {
			int a, b, f; cin >> a >> b >> f; --a, --b;
			m[a].push_back( (Edge){ b, f } );
			m[b].push_back( (Edge){ a, f } );
		}

		int ans[100][11]; fill(&ans[0][0], &ans[0][0]+100*11, INF);
		priority_queue<Node> Q; Q.push( (Node){s, c, 0} );
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			if (node.cost >= ans[node.now][node.rest]) continue;
			ans[node.now][node.rest] = node.cost;

			for (int i = 0; i < m[node.now].size(); ++i) {
				Edge& e = m[node.now][i];
				if (node.cost+e.cost < ans[e.to][node.rest]) {
					Q.push( (Node){ e.to, node.rest, node.cost+e.cost } );
				}

				if (node.rest > 0) {
					if (node.cost+e.cost/2 < ans[e.to][node.rest-1]) {
						Q.push( (Node){ e.to, node.rest-1, node.cost+e.cost/2 } );
					}
				}
			}
		}
		int a = INF;
		for (int i = 0; i <= c; ++i) a = min(a, ans[d][i]);
		cout << a << endl;
	}
}

Measured memory_bytes: 1360
n,m,q = map(int,input().split())

import itertools
data = []
nums = [i for i in range(m)]
for balls in itertools.combinations_with_replacement(nums, n):
    data.append(balls)

#print(data)

qa = []
for i in range(q):
    qa.append(list(map(int,input().split())))
    
ans = 0
for i in data:
    si = 0
    for j in qa:
        if (i[j[1]-1]-i[j[0]-1]) == j[2]:
            si += j[3]
    ans = max(si,ans)
print(ans)

Measured memory_bytes: 21648
//****** @author mdazmat9 **********
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}



void solve() {
    ll n,a,b;
    cin >> n>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
    } else{
        ll op1=max(a-1,b-1);
        ll op2=max(n-a,n-b);
        ll op3=a-1;
        ll tb=b-op3-1;op3++;;
        op3+=(tb-1)/2;
        ll op4=n-b;
        ll ta=a+op4+1;op4++;
        op4+=(n-ta)/2;
        cout<<min({op1,op2,op3,op4});
    }

}
int main()
{
    IOS;
    ll test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
int a,b,c,ans,max=0;
scanf("%d%d%d",&a,&b,&c);
ans=a+b+c;
if(max<a)max=a;
if(max<b)max=b;
if(max<c)max=c;
printf("%d\n",ans-max);
return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		String ans ="";
		Scanner scan_1 = new Scanner(System.in);
		int num  = scan_1.nextInt();
		String str = scan_1.next();


		int nagasa = str.length();

		if(nagasa <= num) {
			ans = str;
		}else {
			ans = str.substring(0, num)+"...";
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 38660
import bisect
import heapq
import sys
N,Q = [int(x) for x in sys.stdin.readline().split()]

hitos = []
ans = [-1 for _ in range(Q)]
queries =[]
jump = ans[::]



queries = [[int(x) for x in sys.stdin.readline().split()] for i in range(N)]
hitos = [int(sys.stdin.readline()) for i in range(Q)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


queries.sort(key=lambda x:x[2])





for l,r,x in queries:
     lind  = bisect.bisect_left(hitos,l-x - 0.5)
     rind  = bisect.bisect_left(hitos,r -x - 0.5)
     while lind < rind:
         if ans[lind] == -1:
            ans[lind] = x
            jump[lind] = rind
            lind += 1
         else:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp

for i  in ans:
    print(i)


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


signed main(){
  int n;
  string words[100];
  cin >> n;
  bool isWrong = false;
  cin >> words[0];
  char last = words[0][words[0].size() - 1];

  for(int i = 1; i < n; i++){
    cin >> words[i];
    char nextLast = words[i][words[i].size() - 1];
    if(last != words[i][0]){
      isWrong = true;
      break;
    }
    last = nextLast;
    for(int j = 0; j < i; j++){
      if(words[i] == words[j]){
        isWrong = true;
        break;
      }
    }
  }

  if(isWrong){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int m1,m2,d1,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;

    if(m1 != m2){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 小さい方をリターンする関数
# dpに使う
def chmin(a,b):
    if a>b:
        return b
    else:
        return a

# 小さい方をリターンする関数
# dpに使う
def chmax(a,b):
    if a<b:
        return b
    else:
        return a

N = int(input())
h = list(map(int,input().split()))

f_inf = float("inf")
dp = [f_inf]*N
dp[0] = 0

for i in range(1,N):
    if i == 1:
        dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])





Measured memory_bytes: 52208
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n, 0);
  for (int i = 0; i < k; i++){
    ll d;
    cin >> d;
    
    for (int j = 0; j < d; j++){
      ll b;
      cin >> b;
      b--;
      a[b]++;
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; i++){
    if (a[i] == 0)
      ans++;
  }
  cout << ans << endl;
  
  

  return 0;
}


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

int main(){
    int x;
    cin>>x;
    if(x<600){
        cout<<8<<endl;
    }
    else if(x<800){
        cout<<7<<endl;
    }
    else if(x<1000){
        cout<<6<<endl;
    }
    else if(x<1200){
        cout<<5<<endl;
    }
    else if(x<1400){
        cout<<4<<endl;
    }
    else if(x<1600){
        cout<<3<<endl;
    }
    else if(x<1800){
        cout<<2<<endl;
    }
    else{
        cout<<1<<endl;
    }
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long int n, k;
	cin >> n >> k;
	cout << min(n%k, abs(k-n%k)) << "\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] x = new int[n];
			for(int i = 0 ; i < n ; i++) {
				x[i] = sc.nextInt();
			}
			int ans = Integer.MAX_VALUE;
			for(int i = 1 ; i <= 100 ; i++) {
				int p = 0;
				for(int j = 0 ; j < n ; j++) {
					p += (x[j] - i) * (x[j] - i);
				}
				ans = Math.min(ans, p);
			}
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 24020
#include <cstdio>
#include <algorithm>

using namespace std ;
typedef long long ll ;

int n,m ;
ll ans ;

ll get_ans(ll a, ll b, ll c) {
	ll tt[3] ;
	tt[0] = a ; tt[1] = b ; tt[2] = c ;
	sort(tt,tt+3) ;
	return abs(tt[0]-tt[2]) ;
}

void solve(int n, int m, ll &a, ll &b) {
	ll ra, rb, mincha = -1 ;
	for(int i=n/2-10; i<=n/2+10; i++ ) {
		if(i>=1&&i<=n-1) {
			ll tmp1 = abs(i*m-(n-i)*m) ;
			if(mincha==-1) { mincha = tmp1 ; ra = (ll) i*m; rb = (ll)(n-i)*m ; }
			else {
				if(mincha>tmp1) {
					mincha = tmp1 ; ra = (ll)i*m; rb = (ll)(n-i)*m ;
				}
			}
		}
	}
	for(int i=m/2-10; i<=m/2+10; i++) {
		if(i>=1&&i<=m-1) {
			ll tmp1 = abs(i*n-(m-i)*n) ;
			if(mincha==-1) { mincha = tmp1 ; ra = (ll)i*n; rb = (ll)(m-i)*n ; }
			else {
				if(mincha>tmp1) {
					mincha = tmp1 ; ra =(ll) i*n; rb = (ll)(m-i)*n;
				}
			}
		}
	
	}
	a = ra ; b = rb ;
}

int main(void) {
	scanf("%d%d",&n,&m) ;
	if(n%3==0||m%3==0) {
		printf("0\n") ;
		return 0 ;
	}
	ans = (ll)1e10+10 ;
	for(int i=n/3-10; i<=n/3+10; i++) {
		if(i>=1&&i<=n-1) {
			ll a,b ;
			solve(n-i,m,a,b) ;
//			printf("%d %lld %lld\n",i,a,b) ;
			ans = min(ans,get_ans((ll)i*m,a,b)) ;
		}
	}
	for(int i=m/3-10; i<=m/3+10; i++) {
		if(i>=1&&i<=m-1) {
			ll a,b ;
			solve(n,m-i,a,b) ;
			ans = min(ans,get_ans((ll)i*n,a,b)) ;
		}
	}
	printf("%lld\n",ans) ;

	return 0 ;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
    int n; cin>>n;
    int ht[n], dp[n];
    memset(dp, 0, sizeof dp);
    for(int i=0; i<n; i++) cin>>ht[i];
    dp[1] = abs(ht[0] - ht[1]);
    for(int i=2; i<n; i++) {
        int d1 = abs(ht[i] - ht[i-1]);
        int d2 = abs(ht[i] - ht[i-2]);
        dp[i] = min(dp[i-1] + d1, dp[i-2] + d2);
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 5084
class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)

    def same(self, x, y):
        return (self.find(x) == self.find(y))

    def size(self, x):
        return -self.data[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(N + M + 1)
used = [False] * (M + 1)
for i in range(1, N + 1):
    K, *L = map(int, input().split())
    for l in L:
        uf.union(i, l + N)
        used[l] = True

if uf.size(1) - sum(used) == N:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9660
/*author : Yashvardhan
Sunday, May 10, 2020
10:06 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}

const int N = 1e5 + 5;
vpi arr[N];

signed main()
{

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

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,m;
	cin >> n >> m;

	for(int i = 0; i < m; i++){
		int p,y;
		cin >> p >> y;
		arr[p].pb({y,i});
	}

	vector<string> ans(m);
	for(int i = 1; i <= n; i++){
		sort(all(arr[i]));
		string pnum = to_string(i);
		int rem = 6 - pnum.size();
		string ls = "";
		for(int j = 0; j < rem; j++) ls += "0";
		ls += pnum;
		for(int j = 1; j <= arr[i].size(); j++){
			string curr = to_string(j);
			string rs = "";
			rem = 6 - curr.size();
			for(int it = 0; it < rem; it++) rs += "0";
			rs += curr;
			ans[arr[i][j - 1].ss] = ls + rs;
		}
	}

	for(auto i : ans){
		cout << i << endl;
	}



	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



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

int main()
{
    int n_input_01, n_input_02;
    cin >> n_input_01 >> n_input_02;

    if(n_input_01 < n_input_02)
    {
        cout << "a < b" << endl;
    }
    else if(n_input_01 > n_input_02)
    {
        cout << "a > b" << endl;
    }
    else
    {
        cout << "a == b" << endl;
    }

    return 0; 
}

Measured memory_bytes: 1156
A,B,C,D = list(map(int, input().split()))
if A % D == 0:
    takahashi = A // D #takahashiを0にするのにに必要な攻撃数
else:
    takahashi = A // D + 1

if C % B == 0:
    aoki = C // B #takahashiを0にするのにに必要な攻撃数
else:
    aoki = C // B + 1


if takahashi >= aoki:
    print('Yes')
else:
    print('No')

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

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    int ans = 0;
    for (P a : mp) {
        ans += a.first <= a.second ? a.second - a.first : a.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7996
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int hmax = -1;
			double m = 0;
			double max = 0;
			int y = sc.nextInt();
			for(int i = 0 ; i < n ;i++){
				int b = sc.nextInt();
				int r = sc.nextInt();
				int t = sc.nextInt();
				if(t == 1){
					m = 1+y*r/100.;
				} else {
					m = Math.pow(1 + r/100.,y);
				}
				if(max < m ){
					max = m; 
					hmax = b;
				}
			}
			System.out.println(hmax);
		}
		sc.close();
	}

}

Measured memory_bytes: 35728
#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){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
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);}

template <class T>
class Cumulative2DSum {
    // query[sx,gx),[sy,gy)
public:
    vector<vector<T>>sum;
    T e;
    Cumulative2DSum(vector<vector<T>>&v,T e) {
        // W is x, H is y
        int W = v.front().size();
        int H = v.size();
        ++H , ++W;
        sum = vector<vector<T>>(H,vector<T>(W,e));
        
        for(int i = 0; i < v.size(); ++i){
            for(int j = 0; j < v[i].size(); ++j){
                sum[i + 1][j + 1] +=  v[i][j];
            }
        }
        for(int i = 1; i < sum.size(); ++i){
            for(int j = 1; j < sum[i].size();++j){
                sum[i][j] += sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
            }
        }
    }
    T query(int sx,int sy,int gx,int gy){
        return sum[gy][gx] - sum[sy][gx] - sum[gy][sx] + sum[sy][sx];
    }
};


signed main(){
    int n,m,Q;
    cin >> n >> m >> Q;
    vector<vector<int>>grid(n,vector<int>(n,0LL));
    rep(_,m){
        int l,r; cin >> l >> r;
        --l,--r;
        grid[l][r]++;
    }
    auto dcm = Cumulative2DSum<int>((grid),0LL);
    rep(_,Q){
        int l,r; cin >> l >> r;
        --l,--r;
        cout << dcm.query(l,l,r+1,r+1) <<endl;
    }
}



Measured memory_bytes: 4864
#include<cstdio>
#include<cstdlib>
#include<stack>
using namespace std;
int main()
{
	stack<int> S;
	int a,b;
	char s[1000];
	for(;scanf("%s",s)!=EOF;)
	{
		if(s[0]=='+')
		{
			b=S.top();S.pop();
			a=S.top();S.pop();
			S.push(a+b);
		}
		else if(s[0]=='-')
		{
			b=S.top();S.pop();
			a=S.top();S.pop();
			S.push(a-b);
		}
		else if(s[0]=='*')
		{
			b=S.top();S.pop();
			a=S.top();S.pop();
			S.push(a*b);
		}
		else
		{
			S.push(atoi(s));
		}
	}
	printf("%d\n",S.top());
	return 0;
}

Measured memory_bytes: 2748
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline

N,M=map(int,input().split())
A=list(map(int,input().split()))

data=[]
for i,a in enumerate([2,5,5,4,5,6,3,7,6]):
    if i+1 in A:
        data.append([a,i+1])

dic={}
for a,i in reversed(data):
    dic[i]=0
dp=[copy.copy(dic) for i in range(N+1)]

def main(dic1,dic2):
    dic1=sorted([[str(i),dic1[i]] for i in dic],key=lambda x:x[0],reverse=True)
    dic2=sorted([[str(i),dic2[i]] for i in dic],key=lambda x:x[0],reverse=True)
    for a,b in zip(dic1,dic2):
        if a[1]>b[1]:
            return(0)
        if a[1]<b[1]:
            return(1)
    return(0)

def _sum(dic):
    count=0
    for i in dic:
        count+=dic[i]
    return(count)


for a,n in data:
    tempdic=copy.copy(dic)
    tempdic[n]+=1
    if len(dp)-1>=a:
        flag=main(dp[a],tempdic)
        if flag:
            dp[a]=tempdic
    for i in range(len(dp)):
        if i>=a and _sum(dp[i-a]):
            if _sum(dp[i])<_sum(dp[i-a])+1:

                tempdic=copy.copy(dp[i-a])
                tempdic[n]+=1
                dp[i]=tempdic
            elif _sum(dp[i])==_sum(dp[i-a])+1:
                dp[i-a][n]+=1
                flag=main(dp[i],dp[i-a])
                dp[i-a][n]-=1
                if flag:
                    tempdic=copy.copy(dp[i-a])
                    tempdic[n]+=1
                    dp[i]=tempdic
dic=dp[N]
a=""
dic=sorted([[str(i),dic[i]] for i in dic],key=lambda x:x[0],reverse=True)
for i,z in dic:
    for m in range(z):
        a+=i
print(a)


Measured memory_bytes: 13916
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
#include <cmath>
#include <stack>

using namespace std;

#define int long long

signed main() {
    int n, k;
    cin >> n >> k;
    vector<bool> flag(n, false);
    for(int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++) {
            int a; 
            cin >> a;
            a--;
            flag[a] = true;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(!flag[i]) ans++;
    }

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

Measured memory_bytes: 3648
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	string a,b;
	cin>>a>>b;
	int n=a.size();
	if(b==string(n,'0')){
		cout<<(a==b?0:-1)<<endl;
		return 0;
	}
	vector<int> ls(n),rs(n);
	string bb=b+b;
	rep(i,n){
		reps(j,i,n*2){
			if(bb[j]=='1') break;
			++rs[i];
		}
		rreps(j,0,n+i+1){
			if(bb[j]=='1') break;
			++ls[i];
		}
	}
	//	out(ls,rs,1);
	int re=MOD;
	auto dist=[&](int x,int y){
		int re=x-y;
		re=(re%n+n)%n;
		return min(re,n-re);
	};
	rep(d,n){
		vector<pii> ps{{0,0}};
		rep(i,n)if(a[i]!=bb[d+i]) ps.eb(ls[i],rs[i]);
		sort(rall(ps));
		int r=0;
		for(pii p:ps){
			int l=p.X;
			MN(re, l+l+r+dist(d,r) + (int)ps.size());
			MN(re, r+r+l+dist(d,-l) + (int)ps.size());
			MX(r,p.Y);
		}
	}
	cout<<re-1<<endl;
  return 0;
}


Measured memory_bytes: 384
[A, B, C, X] = list(map(int, [input() for i in range(4)]))
count = 0
for i in range(0, A+1):
  for j in range(0, B+1):
    for k in range(0, C+1):
      if (500*i + 100*j + 50*k) == X:
        count += 1

print(count)

Measured memory_bytes: 3060
def hit_blow(a,b):
    hit = 0
    blow = 0
    for i in range(4):
        if a[i] == b[i]:
            hit += 1
    for i in range(4):
        for j in range(4):
            if a[i] == b[j]:
                blow += 1
    blow -= hit
    print(hit,blow)
    return 0

while True:
    try:
        a = list(map(int,input().split()))
        b = list(map(int,input().split()))
        hit_blow(a,b)
    except EOFError:
        break

Measured memory_bytes: 7664
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<stdbool.h>

typedef struct tag_hint{
    int x,y;
}hint;

int main(void){
    int n;
    scanf("%d",&n);
    int a[n];
    hint hints[n/*speaker*/][n - 1/*hint*/];
    for(int i = 0;i < n;i++){
        scanf("%d",&a[i]);
        for(int j = 0;j < a[i];j++)scanf("%d %d",&hints[i][j].x,&hints[i][j].y);
    }
    uint16_t bs = (uint16_t)0b0000000000000000;//gcc
    uint16_t max = (uint16_t)0b1111111111111111;//gcc
    uint16_t masks[15];
    int ans_max = 0,tmp_max = 0;
    for(int i = 0;i < 15;i++){
        masks[i] = 0b0000000000000001;
        masks[i] <<= i;
    }
    bool pass_flag;
    for(int i = 0;i < (16 - n);i++)max >>= 1;  
    for(;bs <= max;bs++){
        pass_flag = true;
        tmp_max = 0;
        for(int i = 0;i < n;i++){
            if((bs & masks[i])){
                tmp_max++;
                for(int hi = 0;hi < a[i];hi++){
                    if(hints[i][hi].y != ((bs & masks[hints[i][hi].x - 1])?1:0))pass_flag = false;
                }
            }
        }
        if(pass_flag && ans_max < tmp_max)ans_max = tmp_max;
    }
    printf("%d",ans_max);
    return 0;
}

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

#define pb push_back
#define ll long long
using namespace std;



int main() {
   int n; cin >> n;
   while(n) {
     int a = n%10;
     if(a == 7) {
        cout << "Yes" << endl;
        return 0;
     }
     n /= 10;
   }
   cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
ll n; 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	ll res = 2,t;
	if(n == 2){
		res = 1;
	}else{
		for(ll i = 2;i <= sqrt(n);i++){
			t = n;
			while(t >= i){
				if(t % i == 0){
					t /= i;
				}else{
					t %= i;
				}
			}
			if(t == 1){
				res++;
			}
			if((n - 1) % i == 0 && i != sqrt(n - 1)){
				res++;
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
x = list(map(int,input().split()))

point = sum(x)//n
sum1 = 0;sum2 = 0
for i in range(n):
    sum1 += (point - x[i])**2
    sum2 += (point+1 - x[i])**2
print(min(sum1,sum2))


Measured memory_bytes: 2940
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	switch n % 10 {
	case 2, 4, 5, 7, 9:
		fmt.Fprintln(writer, "hon")
	case 0, 1, 6, 8:
		fmt.Fprintln(writer, "pon")
	case 3:
		fmt.Fprintln(writer, "bon")
	}
}


Measured memory_bytes: 1804
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

struct UnionFind {
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int N,M;
    cin >> N >> M;
    vector<P> res(M);
    int ans = 0;

    REP(i,M) {
        int a,b; cin >> a >> b;
        a--;b--;
        res[i] = P(a,b);
    }

    UnionFind UF(N);

    REP(i,M) {
        UF.init(N);

        REP(j,M) {
            if(i != j) {
                int a,b;
                a = res[j].first;
                b = res[j].second;
                UF.merge(a,b);
            } else continue;
        }
        if(UF.size(0) < N) ans++;
    }
    cout << ans << endl;
}


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin,(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string s;
vector<char> v;
bool removablep(int i){
  if(v[i]=='0'&&v[i+1]=='1' ||
      v[i]=='1'&&v[i+1]=='0')
    return true;
  return false;
}

void solve(int i){
  if(i==s.length()) return;
  v.push_back(s[i]);
  while(removablep(v.size()-2)){
    v.pop_back();
    v.pop_back();
  }
  return solve(i+1);
}

int main(){
  cin >> s;
  solve(0);
  cout << s.length()-(int)v.size() << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
from pprint import pprint

def solve(s, t, a, b, u):
    if u == s:
        a -= 1
    if u == t:
        b -= 1
    print(a, b)

if __name__ == '__main__':
    s, t = sys.stdin.readline().strip().split(" ")
    a, b = map(int, sys.stdin.readline().strip().split(" "))
    u = sys.stdin.readline().strip()
    solve(s, t, a, b, u)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
using namespace std;
//擒贼先擒王，找boss
//断桥问题 只要断开一条边boss就肯定有不相同的了
int N, M, a[55], b[55], par[55];
int root(int x)
{
    if (x == par[x]) return x;   //连接到他自己本身那么他自己就是boss
    return par[x] = root(par[x]);  //这里又开始递归，找更强的boss
}
void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    par[x] = y;
}
int main()
{
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> a[i] >> b[i], a[i]--, b[i]--;
    int ret = 0;
    //对所有边进行遍历检索
    for (int i = 0; i < M; i++)
    {
        //一开始默认每个点自己都是boss
        for (int j = 0; j < N; j++) par[j] = j;
        //对剩下其他边处理（相当于把i所在的边空余出来，i边相当于断掉了）
        for (int j = 0; j < M; j++)
        {
            if (i != j) unite(a[j], b[j]); //找两个点间的boss
        }
        bool f = false;
        //因为对于点两两作比较所以是1->n-1
        for (int j = 1; j < N; j++)
        {
            if (root(j - 1) != root(j)) f = true;   //如果两点间的boss不同那么存在断点，符合题意，计数器加一
        }
        if (f) ret++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin>>n>>k;
  ll ans=0;
  if(k==0){
    ans=n*n;
    cout<<ans<<endl;
    return 0;
  }
  for(ll i=k+1;i<=n;i++){
    ll am=(n+1)/i;
    ans+=(i-k)*am+max((ll)0,n-(k+i*am)+1);
  }
  cout<<ans<<endl;
}
    

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

int main() {
  int X;
  cin>>X;
  if (X==7) {
    cout<<"YES"<<endl;
  }
  else if (X==5) {
    cout<<"YES"<<endl;
  }
  else if (X==3) {
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	int ans=1145141919;
	if(x==-y) ans = min(ans,1);
	if(x==y) ans = min(ans,0);
	if(x<y) ans = min(ans,y-x);
	if(-x<y) ans = min(ans,y+x+1);
	if(x<-y) ans = min(ans,-y-x+1);
	if(-x<-y) ans = min(ans,-y+x+2);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    std::string S;
    std::cin >> S;

    for(int i=0;i<=1;++i){
        bool isSame = true;

        for(int j=0;j<3;++j){
            if(S[i + j] != S[i]){
                isSame = false;
            }
        }

        if(isSame){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;    
}


Measured memory_bytes: 768
#include <stdio.h>

int main(){
  int i,j,n,a[100000],x,tmp;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  x=a[n-1];
  i=0;
  for(j=0;j<n-1;j++){
    if(a[j]<=x){
      tmp=a[i];
      a[i]=a[j];
      a[j]=tmp;
      i++;
    }
  }
  a[n-1]=a[i];
  a[i]=x;
  for(j=0;j<n-1;j++){
    if(j==i) printf("[%d] ",a[i]);
    else printf("%d ",a[j]);
  }
  printf("%d\n",a[n-1]);
  
  return 0;
}



Measured memory_bytes: 2100
from math import sqrt
from collections import defaultdict

N = int(input())

def prime_factorize(n):
    a = defaultdict(int)
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a
  
ps = prime_factorize(N)

def func2(k):
  n = 1
  count = 1
  while count * (count+1) // 2 <= k:
    count += 1
  return count-1

res = 0

for value in ps.values():
  if value > 0:
    res += func2(value)

print(res)

Measured memory_bytes: 9480
def f_must_be_rectangular(N, Positions):
    # 参考: https://atcoder.jp/contests/abc131/submissions/6086451
    # x軸, y軸をまとめて1つのリストで扱う
    import sys
    sys.setrecursionlimit(10**6)

    vertex_maxsize = 10**5 + 5
    target = [[] for _ in range(2 * vertex_maxsize)]
    is_visited = [False] * (2 * vertex_maxsize)
    for x, y in Positions:
        y += vertex_maxsize  # 1つのリストで扱う都合上、ずらす
        target[x].append(y)
        target[y].append(x)

    def dfs(v):
        if is_visited[v]:
            return
        is_visited[v] = True
        count[v // vertex_maxsize] += 1  # vがx軸とy軸のどっちを指しているか
        for u in target[v]:
            dfs(u)  # 頂点vに接続されている頂点へ向かう

    ans = 0
    for i in range(2 * vertex_maxsize):
        if is_visited[i]:
            continue
        count = [0] * 2
        dfs(i)  # 頂点iにつながっている頂点を調べる
        # x座標とy座標のそれぞれについて、ペアにすると矩形が完成する
        # 座標がいくつあるか。その積が解となる
        ans += count[0] * count[1]
    return ans - N  # 最初に与えられた座標の分、引く

N = int(input())
Positions = [[int(i) for i in input().split()] for j in range(N)]
print(f_must_be_rectangular(N, Positions))

Measured memory_bytes: 111780
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=3000+10;

int n,a[N];

struct edge { int v,nxt; } e[N<<1];
int head[N];
inline void addEdge(int u,int v) {
    static int cnt=0;
    e[++cnt]=(edge){v,head[u]},head[u]=cnt;
}

int f[N];
inline void dfs(int u,int fa) {
    f[u]=0;
    for (re int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v; if (v==fa||a[v]>=a[u]) continue;
        dfs(v,u); if (!f[v]) f[u]=1;
    }
}

int main() {
    n=read();
    for (re int i=1;i<=n;++i) a[i]=read();
    for (re int i=1;i<n;++i) {
        int u=read(),v=read();
        addEdge(u,v),addEdge(v,u);
    }
    for (re int i=1;i<=n;++i) {
        dfs(i,0);
        if (f[i]) printf("%d ",i);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 384
<?php
fscanf(STDIN, "%d %d", $N, $M);
$a = array_pad(array(), $N, 0);
$k = array_pad(array(), $N, null);
$bool = true;
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $s, $c);
    if (is_null($k[$s - 1])) {
        $a[$s - 1] = $c;
        $k[$s - 1] = true;
    } else if ($a[$s - 1] !== $c) {
        $bool = false;
    }
}
if ($N > 1 && $a[0] === 0 && $k[0] === null) {
    $a[0] = 1;
}
if ($a[0] === 0 && $N > 1) {
    $bool = false;
}
echo $bool ? implode("", $a) : "-1";

Measured memory_bytes: 4856
#include<stdio.h>
#include<string.h>
int main()
{
    char S[100];
    gets(S);
    int i,j,l,k=0;
    l=strlen(S);
    for(i=0,j=l;i<l/2;i++,j--){
        if(S[i]!=S[j-1]){
            k=k+1;
        }

    }
    printf("%d\n",k);
    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

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

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else
	{
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 256