akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 a, b, c, k;
    cin >> a >> b >> c >> k;

    if (k <= a + b) cout << MIN(a, k) << "\n";
    else if (a + b < k) cout << a - MIN(k - a - b, c) << "\n";

    return 0;
}



Measured memory_bytes: 3668
#include <vector>
#include <cstddef>

struct union_find {
    using size_type = std::size_t;
private :
    size_type _size;
    std::vector<int> node;
public :
    union_find (size_type n) : node(n, -1), _size(n) { }

    bool unite (size_type x, size_type y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (node[x] > node[y]) std::swap(x, y);
        node[x] += node[y];
        node[y] = x;
        _size--;
        return true;
    }

    bool same (size_type x, size_type y) {
        return (root(x) == root(y));
    }

    size_type root (size_type x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    size_type size (size_type x) {
        return (size_type(-node[root(x)]));
    }

    const size_type &size () const noexcept {
        return _size;
    }

};


#include <iostream>

using usize = std::size_t;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	usize n, q;
	std::cin >> n >> q;
	union_find uf(n);
	for (usize i = 0; i < q; i++) {
		usize type, u, v;
		std::cin >> type >> u >> v;
		if (type == 0) uf.unite(u, v);
		else std::cout << uf.same(u, v) << '\n';
	}
	return 0;
}

Measured memory_bytes: 3848
// a Reard For a Carpenter
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117&lang=jp
//
//
#include <iostream>
#include <cstdio>
using namespace std;

int n, m, a, b, c, d, ans=0, s, g, V, P;
int Cost[32][32]={};
const int inf = 1001001001;

void show(){
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j){
            if(Cost[i][j] == inf) cout << "INF ";
            else cout << Cost[i][j] << " ";
    
            if(j == n) cout << endl;
    } 
}

void solve(){
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                Cost[i][j] = min(Cost[i][j],Cost[i][k] + Cost[k][j]);
    // show();

    cout << V - P - Cost[s][g] - Cost[g][s] << endl;
}

int main(){
    scanf("%d%d",&n,&m);

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j) Cost[i][j] = inf;

    for(int i = 0; i < m; ++i){
        scanf("%d,%d,%d,%d",&a,&b,&c,&d);
        // cerr << "(a, b, c, d) = (" << a << ", " << b << ", " << c << ", " << d << ")" << endl;
        Cost[a][b] = c;
        Cost[b][a] = d;
    }
    scanf("%d,%d,%d,%d", &s, &g, &V, &P);
    // cerr << "(s,g,V,P) = (" << s << ", " << g << ", " << V << ", " << P  << ")" << endl;

    // show();

    solve();
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int main()
{
	dhoom;
	int n;
	cin >> n;
	ll a[n];
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
		a[i] -= (i+1);
	}
	sort(a , a + n);
	ll ans = 0;
	for(int i = 0 ; i < n ; i++){
		ans += abs(a[n/2] - a[i]);
	}
	cout << ans << endl;
	return 0;
} 



Measured memory_bytes: 1792
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
struct STICK{
	ll h,w,id;
};
ll n,m,h,k,ans;
ll rup[100000],lup[100000];
ll rdown[100000],ldown[100000];
ll s[100000];
ll now[100000];
STICK e[100000];
int main()
{while(1){
	cin>>n>>m>>h>>k;
	if(!n) return 0;
	rep(i,n) cin>>s[i];
	rep(i,m){
		e[i].id=i;
		cin>>e[i].w>>e[i].h;
		e[i].w--;
	}
	rep(i,n){
		if(i<k) now[i]=1;
		else now[i]=0;
	}
	sort(e,e+m,
		[](STICK a,STICK b){return a.h<b.h;}
		);
	rep(i,m){
		//rep(i,n) cout<<now[i]<<" ";
		//cout<<endl;
		lup[e[i].id]=now[e[i].w];
		rup[e[i].id]=now[e[i].w+1];
		swap(now[e[i].w],now[e[i].w+1]);
	}
	ans=0;
	rep(i,n){
		if(now[i]==1){
			ans+=s[i];
			//cout<<i<<endl;
		}
		now[i]=s[i];
	}
	sort(e,e+m,
		[](STICK a,STICK b){return a.h>b.h;}
		);
	rep(i,m){
		ldown[e[i].id]=now[e[i].w];
		rdown[e[i].id]=now[e[i].w+1];
		swap(now[e[i].w],now[e[i].w+1]);
	}
	ll cnt=0;
	rep(i,m){
		//cout<<e[i].w<<" "<<e[i].h<<" "<<lup[e[i].id]<<" "<<rup[e[i].id]<<" "<<ldown[e[i].id]<<" "<<rdown[e[i].id]<<endl;
		if(lup[i]==1&&rup[i]==0&&ldown[i]<rdown[i]){
			cnt=max(cnt,rdown[i]-ldown[i]);
		}
		else if(rup[i]==1&&lup[i]==0&&rdown[i]<ldown[i]){
			cnt=max(cnt,ldown[i]-rdown[i]);
		}
	}
	cout<<ans-cnt<<endl;
}}

Measured memory_bytes: 8620
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.Split.Int;
            var a = line[0];
            var b = line[1];
            var c = line[2];


            var nokori1 = a - b;
            if (nokori1 > c) return 0;
            else return c - nokori1;
        }

        struct Point
        {
            public int x;
            public int y;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> SplitString { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 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; }
//------------------------------------------------------------------------------


/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
const int MAX_N = 55555;
array<bool, MAX_N + 1> isPrime;
vector<int> primes;
//------------------------------------------------------------------------------
void _main()
{
    isPrime.fill(true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= MAX_N; ++i)
    {
        if (isPrime[i])
        {
            primes.push_back(i);
            for (int j = 2; i * j <= MAX_N; ++j)
            {
                isPrime[i * j] = false;
            }
        }
    }

    int N;
    cin >> N;

    int num = 0;
    for (const int prime : primes)
    {
        if (prime % 5 == 1)
        {
            cout << prime << " ";
            if (++num == N) break;
        }
    }
    cout << endl;
}


Measured memory_bytes: 384
/***************************************************
 * Problem Name : A.cpp
 * Problem Link :
 * Contest Name :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2019-09-07
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<ll,ll>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    int n;
    cin >> n;
    int ans = n*n*n;
	
	cout << ans << "\n";
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
int main() {
    int x;
    cin >> x;
    vector<int> a;  
    for(int i=2; i<=100003; ++i){
        int flag = 0;
        for(int j=2; j<i; ++j){
            if(i%j==0){
                flag = 1;
                break;
            }
        }
        if(flag==0){
            a.push_back(i);
        }
    }
    auto Iter = lower_bound(a.begin(),a.end(),x);
    cout << *Iter << endl;
}


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

void GatheringChildren(int& N, std::string S)
{
    // Easy access to even/odd index counts...
    int parityCounts[2];
    parityCounts[0] = 0;
    parityCounts[1] = 0;

    // Our result/answer array
    int ans[N];

    for (int i = 0; i < N; i++) ans[i] = 0;

    char currentChar = 'R';

    int lastPair = -1;

    for (int i = 0; i < N; i++)
    {
        if (S[i] == currentChar) parityCounts[i % 2]++;

        else
        {
            // Here we have a new pivot/lastPair point, so just keep track of this new pivot index, and accumulate parities in our answer array...
            if (S[i] == 'L')
            {
                lastPair = i - 1;
                ans[lastPair] += parityCounts[lastPair % 2];
                ans[lastPair+1] += parityCounts[(lastPair+1) % 2];
            }

            // This basically means we have currentChar as an 'L' and S[i] == 'R', so we need to have KEPT track of last pivot pair/lastPair point
            // as the L's all go to the left to converge at the prior 'RL' pivot point
            else
            {
                ans[lastPair] += parityCounts[lastPair % 2];
                ans[lastPair+1] += parityCounts[(lastPair+1) % 2];
            }
            
            // Reset counts now that we have just hit and accounted for pivot/lastPair...
            parityCounts[0] = 0;
            parityCounts[1] = 0;

            // Account for current character's parity...
            parityCounts[i % 2]++;

            // Update current character...
            currentChar = S[i];
        }
    }

    ans[lastPair] += parityCounts[lastPair % 2];
    ans[lastPair+1] += parityCounts[(lastPair+1) % 2];

    for (int i = 0; i < N-1; i++) printf("%d ", ans[i]);
    printf("%d\n", ans[N-1]);
}

int main()
{
    std::ios::sync_with_stdio(false);

    std::string S;

    std::cin >> S;

    int N = S.length();

    GatheringChildren(N, S);

    return 0;
}

Measured memory_bytes: 1104
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0

for i in range(q):
    L = 0
    R = n
    key = T[i]
    while R-L >= 1:
        i = int((L+R)/2)
        if S[i] == key:
            ans += 1
            break
        elif  S[i] > key:
            R = i
        else:
            L = i+1

print(ans)
        
        


Measured memory_bytes: 16712
#include<iostream>
#include<math.h>
using namespace std;
int n,k,a[1000001];
long long f[1000001];
main()
{
	cin>>n>>k;
	for(int i = 0;i < n;i++)cin>>a[i];
	f[0] = 0;
	f[1] = abs(a[0]-a[1]);
	for(int i = 2;i < n;i++)
	{
		f[i] = f[i-1]+abs(a[i-1]-a[i]);
		for(int j = 2;j <= k;j++)
		if(i-j>=0)
		f[i] = min(f[i],f[i-j]+abs(a[i-j]-a[i]));
	}
	cout<<f[n-1];
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
	int data,j;
	char data_m[10],a[2]="3";
	cin >> data;
	for (int i = 1; i <= data; i++) {
		sprintf(data_m, "%d", i);
		if (i % 3 == 0||strstr(data_m,a)!=NULL) {
			cout << " " << i;
		}
	}
	cout << endl;
	return 0;
}

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

int check(string s, string t)
{
	rep(i, t.size())
	{
		if (s[i] == '?')
			s[i] = t[i];
	}
	if (t == s)
		return 1;
	return 0;
}

int  main()
{
	string s; cin >> s;
	string t; cin >> t;
	int t_len = t.size();
	bool ans = false;
	// rep(i, (s.size() - t_len) + 1)
	// {
	// 	string ss = s.substr(i, t_len);
	// 	if (check(ss, t))
	// 	{
	// 		s.replace(i, t_len, t);
	// 		ans = true;
	// 	}
	// }
	for (int i = s.size()-1; i >= (t_len-1); i--)
	{
		string ss = s.substr(i - (t_len-1), t_len);
		if (check(ss, t))
		{
			s.replace(i - (t_len - 1), t_len, t);
			ans = true;
			break;
		}
	}
	if (ans)
	{
		rep(i, s.size())
		{
			if (s[i] == '?')
				s[i] = 'a';
		}
		cout << s << endl;
	}
	else
		cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
 
int main(){
  int n;
  cin>>n;
  vector<vector<int>> a(n+100,vector<int>(3));
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  vector<vector<int>> dp(n+100,vector<int>(3));
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  for(int i=0;i<n-1;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k){
          continue;
        }
        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i+1][k]);
      }
    }
  }
  int t=0;
  for(int i=0;i<3;i++){
    t=max(t,dp[n-1][i]);
  }
  cout<<t<<endl;
  
}


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <climits>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

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

	if((int)s.size() <= k){
		cout << s << endl;
	}else{
		cout << s.substr(0, k) << "..." << endl;
	}
}


Measured memory_bytes: 3628
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		Set<String> set = new HashSet<String>();

		for (int i = 0; i < N; i++) {
			set.add((sc.next()));
		}
		System.out.println(set.size());
	}
}


Measured memory_bytes: 66092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int ans[maxn];

int f(int x,int y,int z){
	return x*x + y*y + z*z + x*y + y*z + x*z;
}

int32_t main(){
    fast_io;
    int n;
    cin>>n;
    fo(i,1,100){
    	fo(j,1,100){
    		fo(k,1,100) {
    			int temp = f(i,j,k);
    			if(temp < maxn) ans[temp]++;
    		}
    	}
    }
    fo(i,1,n){
    	show(ans[i]);
    }
    return 0;
}

Measured memory_bytes: 4004
import sys

def solve(a, b):
    if a > 0:
        print('Positive')
    elif a <= 0 and b >= 0:
        print('Zero')
    elif (b - a) % 2 == 0:
        print('Negative')
    else:
        print('Positive')

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    a = int(ws[0])
    b = int(ws[1])
    return (a, b,)

def main():
    solve(*readQuestion())

# Uncomment before submission
main()


Measured memory_bytes: 2940
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

dp=[-1]*100100
G=[[] for _ in range(100100)]

def dfs(v):
  if dp[v]!=-1:
    return dp[v]
  dp[v]=r=max(dfs(w) for w in G[v])+ 1 if G[v] else 0
  return r

def main():
  n,k=LI()

  for _ in range(k):
    a,b=LI()
    a-=1
    b-=1
    G[a].append(b)

  return max(dfs(v) for v in range(n))

# main()
print(main())


Measured memory_bytes: 108672
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


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;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

void printVector(const vector<int>& vec) {
	for (int value : vec) {

		cout << value << " ";
	}
	cout << endl;
}


int main() {
	int n;
	vector<int> p, q,test;
	cin >> n;
	//p.resize(n);
	q.resize(n);
	
	rep(i, n) {
		int x;
		cin >> x;
		//cin >> p[i];
		p.push_back(x);
		test.push_back(x);
	}
	rep(i, n) cin >> q[i];
	sort(test.begin(), test.end());
	int cnt = 0, p_cnt=0, q_cnt=0, ans_p=0, ans_q=0;
	do {
		cnt++;
		for (int i = 0; i < n; i++) {
			if (test[i] == p[i]) p_cnt++;
		}
		for (int i = 0; i < n; i++) {
			if (test[i] == q[i]) q_cnt++;
		}
		if (p_cnt == n)  ans_p = cnt;
		if (q_cnt == n) ans_q = cnt;
		p_cnt = 0;
		q_cnt = 0;
	} while (next_permutation(test.begin(), test.end()));

	cout << abs(ans_p - ans_q) << endl;

	return 0;
}


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

int main( void ) {
    int n;
    cin >> n;
    for( int i = 3; i <= n; ++i ) {
        if( i % 3 == 0 ) cout << ' ' << i;
        else {
            int x = i;
            bool ok = false;
            while( x ) {
                if( x % 10 == 3 ) ok = true;
                x /= 10;
            }
            if( ok ) cout << ' ' << i;
        }
    }
    cout << '\n';
    return 0;
}



Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<stdio.h>
#define INF 50000000
using namespace std;

int graf[20][20];
int kyo[20];
bool use[20];

void dijk(int ve, int st) {
	fill(kyo, kyo + ve, INF);
	fill(use, use + ve, false);
	kyo[st] = 0;

	while (1) {
		int v = -1;
		for (int i = 0;i < ve; i++) {
			if (!use[i] && (v == -1 || kyo[i] < kyo[v]))v = i;
		}
		if (v == -1)break;
		use[v] = true;
		for (int i = 0;i < ve;i++) {
			kyo[i] = min(kyo[i], kyo[v] + graf[v][i]);
		}
	}
	return;
}


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

	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++)graf[i][j] = INF;
	}

	for (int i = 0;i < m;i++) {
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		graf[a - 1][b - 1] = c;
		graf[b - 1][a - 1] = d;

	}
	int s, g, V, P;
	scanf("%d,%d,%d,%d", &s, &g, &V, &P);
	int sum = 0;

	dijk(n, s - 1);
	sum += kyo[g - 1];

	dijk(n, g - 1);
	sum += kyo[s - 1];
	cout << V - P - sum << endl;
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,a;
	cin >> h >> a;
	cout << (h-1+a)/a << endl;
} 
 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, k;

int f(int b) {
	int x = b - k;
	int y = (n - k) / b;
	return x * y + min(x, n - (y * b + k) + 1);
}

signed main() {
	cin >> n >> k;
	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}
	
	int ans = 0;
	for (int b = k + 1; b <= n; b++) {
		ans += f(b);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

# gcdを求める
def findGCD(a:int, b:int) -> int:
    # ユークリッドの互除法
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a
            
a,b,c = li()
gcd = findGCD(a,b)

if c % gcd == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>

int main()
{
	int n;
	int ans = 1000000;
	std::cin >> n;
	std::vector<int> w(n);
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
			std::cin >> w[i];
		else
		{
			int x;
			std::cin >> x;
			w[i] = w[i - 1] + x;
		}		
	}
	for (int t = 0; t < n; t++)
		ans = std::min(ans, std::abs(w[t] - w[n - 1] + w[t]));
	std::cout << ans << '\n';
	return (0);
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<cstdlib>
#define LEN 500005

typedef struct pp{
    char name[100];
    int t;
}Process;

Process Q[LEN+1];
int head, tail, n;

void itit(){
    head = tail = 0;
}

int isEmpty(){
    return head == tail ? 1 : 0;
}

int isFull(){
    return head == (tail + 1) % (LEN+1) ? 1 : 0;
}


void enqueue(Process x){
    if (isFull()) {
        printf("Queue is Full\n");
    }else{
        Q[tail] = x;
        if(tail+1 == LEN+1){
            tail = 0;
        }else{
            tail++;
        }
    }
}

Process dequeue(){
    if(isEmpty()){
        printf("Queue is Empty\n");
        exit(1);
    }else{
        if (head+1 == LEN+1) {
            head = 0;
        }else{
            head++;
        }
        return Q[head-1];
    }
}



int main(){
    int elaps = 0, elaps_Whole = 0, c; // elapse : 経過時間
    int i, q; // q : クオンタム
    Process tmp;
    
#ifdef D
    scanf("%d %d", &n, &q);
    
    for ( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
        enqueue(Q[i]);
    }
    
    for (i = 0; i < n; i++) {
        tmp = dequeue();
        printf("%s %d\n",tmp.name, tmp.t);
    }
#endif
    
    
    scanf("%d %d", &n, &q);
    
    for ( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
        elaps_Whole += Q[i].t; // 全部で必要な時間を先に計算しておく
        enqueue(Q[i]);
    }
    
    
    
    
    while (elaps != elaps_Whole) {
        // プロセス終了までの時間がクオンタム以下ならprintfしてdequeue
        if (Q[head].t <= q) {
            elaps += Q[head].t;
            printf("%s %d\n",Q[head].name, elaps);
            dequeue();
        }else{
            Q[head].t -= q;
            elaps += q;
            // headにあるキューを最後尾に持ってくる
            tmp = dequeue();
            enqueue(tmp);
        }
    }
    
    return 0;
}





















Measured memory_bytes: 21836
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    int count = n;
    vector<char> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    for (int i = 0; i < n - 1; i++) {
        if (s.at(i) == s.at(i + 1)) {
            count--;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int e;
	cin >> e;
	vi dbl(1001);
	FOR(i, 1, 1001) {
		dbl[i] = i * i;
	}
	while (e != 0) {
		int ans = INF;
		REP(z,e+1) {
			int cur = e - z * z * z;
			if (cur == 0) {
				chmin(ans, z);
				break;
			}
			else if (cur < 0) {
				break;
			}
			int y = distance(dbl.begin() + 1, upper_bound(ALL(dbl),cur));
			int x = cur - y * y;
			chmin(ans, x + y + z);
		}
		cout << ans << endl;
		cin >> e;
	}
	return 0;
}



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

using namespace std;

using ll = long long;
const ll INF = 1e18L + 5;

vector < ll > pre, dp;

void rec (int i, const vector < int >& not_taken, ll score_so_far, int mask, int group) {
  if (i == (int)not_taken.size()) {
    dp[mask] = max (dp[mask], score_so_far + pre[group]);
    return;
  }
  rec (i + 1, not_taken, score_so_far, mask, group);
  rec (i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]), group ^ (1 << not_taken[i]));
}

int main () {
  int n;
  cin >> n;
  vector < vector < ll > > in (n, vector< ll >(n));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      cin >> in[i][j];
  pre.resize (1 << n);
  for (int mask = 0; mask < (1 << n); ++mask)
    for (int i = 0; i < n; ++i)
      if (mask & (1 << i))
        for (int j = i + 1; j < n; ++j)
            if (mask & (1 << j))
              pre[mask] += in[i][j];
  dp.resize (1 << n, -INF);
  dp[0] = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    vector < int > not_taken;
    for (int i = 0; i < n; ++i)
      if (!(mask & (1 << i)))
        not_taken.emplace_back(i);
    rec (0, not_taken, dp[mask], mask, 0);
  }
  cout << dp[(1 << n) - 1];
}


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

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

  vector<int64_t> v(N + 1, 0);
  v.at(1) = 1;

  if (N == 0) {
    cout << 2 << endl;
    return 0;
  } else if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  v.at(0) = 2;
  v.at(1) = 1;

  for (int i = 2; i < N + 1; i++) {
    v.at(i) = v.at(i - 1) + v.at(i - 2);
  }

  cout << v.at(N) << endl;
}

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

int main() {
  std::string x(3, ' ');
  std::string y(3, ' ');
  scanf("%s", &x[0], x.size());
  scanf("%s", &y[0], y.size());
  if (x[0] == y[2] && x[1] == y[1] && x[2] == y[0])
    printf("YES");
  else
    printf("NO");
}


Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    min_devide_num = -1
    for a in A:
        count = 0
        while a % 2 == 0:
            a /= 2
            count += 1
        if min_devide_num == -1 or min_devide_num > count:
            min_devide_num = count
    return min_devide_num


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3812
def gcd(a,b):
    if b>a:
        return gcd(b,a)
    if b == 0:
        return a
    return gcd(b,a%b)


def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return w[0],w[1]


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

dp = [[0]*401 for _ in range(201)]
for i in range(1,n+1):
    dp[i][0] = i
    dp[i][1] = q[i-1]

for j in range(2,401):
    for i in range(1,n+1):
        dp[i][j] = dp[dp[i][j-1]][1]

ab = [[0,0] for _ in range(n)]
for i in range(n):
    pi = p[i]
    bi = -1
    for b in range(401):
        if dp[pi][b] == i+1:
            bi = b
            break
    if bi == -1:
        print(-1)
        exit()
    
    ai = -1
    for a in range(1,401):
        if dp[pi][a] == pi:
            ai = a
            break
    ab[i] = [ai,bi]

tmp_a = ab[0][0]
tmp_b = ab[0][1]
for i in range(1,n):
    A = tmp_a
    B = ab[i][0]
    C = ab[i][1]-tmp_b

    G= gcd(A,B)
    if C%G != 0:
        print(-1)
        exit()
    K1,K2 = extgcd(A//G,B//G)
    tmp_a = G*(A//G)*(B//G)
    K1 *= C//G
    tmp_b = A * K1 + tmp_b
    tmp_b = (tmp_b % tmp_a + tmp_a) % tmp_a
print(tmp_b)


Measured memory_bytes: 6252
#include <stdio.h>
int main(void){
    // Your code here!

    int n;
    int j;
    
    scanf("%d",&n);
    for(int i=1; i<=n; i++){
      j = i;
      if(i%3==0)
        printf(" %d",i);
      else{
        do{
          if(j%10==3){
            printf(" %d",i);
            break;
          }
          j/=10;
        }while(j>0);
      }
    }
    printf("\n");
    
}



Measured memory_bytes: 1968
using System;

namespace AtCoder
{
	public class ProblemA
	{
		public static void Main(string[] args)
		{
			string[] line = Console.ReadLine().Split(' ');
			int n = int.Parse(line[0]);
			int m = int.Parse(line[1]);

			int[] connections = new int[n];

			for (int i = 0; i < m; i++)
			{
				line = Console.ReadLine().Split(' ');
				int a = int.Parse(line[0]) - 1;
				int b = int.Parse(line[1]) - 1;

				connections[a] |= 1 << b;
				connections[b] |= 1 << a;
			}

			int ans = Hop(n, 0, 0, connections);
			Console.WriteLine(ans);
		}

		private static int Hop(int n, int node, int bit, int[] connections)
		{
			bit |= 1 << node;

			int mask = (1 << n) - 1;

			if ((bit & mask) == mask)
				return 1;

			int con = connections[node];

			int ans = 0;

			for (int i = 0; con > 0; i++, con >>= 1)
			{
				if ((con & 1) == 0)
					continue;

				// 訪問済みなら飛ばす
				if ((bit & (1 << i)) > 0)
					continue;

				ans += Hop(n, i, bit, connections);
			}

			return ans;
		}
	}
}


Measured memory_bytes: 27448
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


#define MAX_V 120000

struct edge { int to, cost; }; //cost >= 0

int V, E, r; //頂点数、辺数、始点
vector<edge>G[MAX_V]; //グラフ情報
int d[MAX_V]; //最短距離

void dijkstra() { //始点rから各頂点への最短距離を求める
	priority_queue<P, vector<P>, greater<P>>q; //小さい順に取り出す(確定した頂点を見るから)
	fill(d, d + V, INF); //初期化
	d[r] = 0; //始点から始点までの距離は0
	q.push(P(0, r)); //firstは最短距離、secondは頂点の番号

	while (!q.empty()) {
		P p = q.top();
		q.pop();
		int v = p.second; //今見ている頂点番号
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) { //頂点e.toまでの最短距離よりも、頂点vを経由する経路の距離のほうが短かったら
				d[e.to] = d[v] + e.cost; //更新
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

signed main() {
	cin >> V;
	rep(i, V - 1) {
		int s, t, d;
		edge e;
		cin >> s >> t >> d;
		s--; t--;
		e.to = t;
		e.cost = d;
		G[s].push_back(e);
		e.to = s;
		G[t].push_back(e);
	}
	int Q;
	cin >> Q >> r;
	r--;
	dijkstra();
	vector<int>ans(Q);
	rep(i, Q) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		ans[i] = d[x] + d[y];
	}
	rep(i, Q)cout << ans[i] << endl;
}

Measured memory_bytes: 11632
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;
#define ONE_BILLION_SEVEN 1000000007

long fact(long n)
{
    if (n <= 1)
        return 1;
    long p = 1;
    for (long i = 2; i <= n; i++)
        p = p * i % ONE_BILLION_SEVEN;

    return p;
}

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

    if (abs(n - m) == 0) {
        cout << 2 * fact(n) % ONE_BILLION_SEVEN *
            fact(m) % ONE_BILLION_SEVEN
             << endl;
    } else if (abs(n - m) == 1) {
        cout << fact(n) * fact(m) % ONE_BILLION_SEVEN
             << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x;
    cin >> x;
    int h = 0;
    int temp = x / 500;
    h += temp * 500;
    temp = x / 5;
    h += temp * 5;
    cout << h << endl;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

void dfs(ll now, ll p, const vector<vector<pll>>& g, vl& path_bit) {
  for (auto&& i : g[now]) {
    if (i.first != p) {
      path_bit[i.first] |= path_bit[now] | (1LL << i.second);
      dfs(i.first, now, g, path_bit);
    }
  }
}

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

  ll n, m;
  cin >> n;
  vl a(n-1), b(n-1);
  vector<vector<pll>> g(n);

  rep(i, n-1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].emplace_back(b[i], i);
    g[b[i]].emplace_back(a[i], i);
  }

  cin >> m;
  vl u(m), v(m);
  rep(i, m) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
  }

  vl path_bit(n, 0);
  dfs(0, 0, g, path_bit);
  rep(i, n) {
    //cerr << bitset<10>(path_bit[i]) << endl;
  }

  ll ans = 0;
  rep(bit, 1LL<<m) {
    ll edge_bit = 0;
    rep(i, m) {
      if (bit >> i & 1) {
        edge_bit |= (path_bit[u[i]] xor path_bit[v[i]]);
      }
    }
    ll cnt = __builtin_popcountll(bit);
    ans += (cnt%2 ? -1 : 1) * (1LL << (n-1-__builtin_popcountll(edge_bit)));
    //cerr << ans << endl;
  }
    assert(ans >= 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i)cin>>vec[i];
	int x = vec[0];
	int res = 0;
	for(int i = 1; i < n; ++i){
		if(vec[i] >= x){
			res++;
			x = vec[i];
		}
	}
	cout<<res+1<<endl;   
	return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  if( S == "Sunny" ){
    cout << "Cloudy" << endl;
  }else if( S == "Cloudy" ){
    cout << "Rainy" << endl;
  }else if( S == "Rainy" ){
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   	int n;
   	char s[10000001];
   	scanf("%d", &n);
   	scanf("%s", s);
   	
   	for(int i = 0; s[i] != '\0'; i++){
   		for(int j = 0; j < n; j++){
		 	if(s[i] == 90){
			 	s[i] -= 26;	
			 	s[i]++;
		    } 
            else{
		    	s[i]++;
			}
		}
		printf("%c", s[i]);	
	}
	
	return 0;
} 

Measured memory_bytes: 1672
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().GroupBy(s => s).ToArray();
            Console.WriteLine(S.Count()==2&&S.First().Count()== S.Skip(1).First().Count() ? "Yes":"No");
        }
    }
}


Measured memory_bytes: 13524
#include <stdio.h>

int main(){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0)
		break;
		
		for(int i = 0; i < x; i++){
			for(int j = 0; j < y; j++){
				if((i + j) %2 == 0){ //偶数の場合
					printf("#");
				}else {              //奇数の場合
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1996
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1 << 30;
const int MAXN = 40;

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

	int N, MA, MB, A, B, C;
	cin >> N >> MA >> MB;
	int dp[2][MAXN*10][MAXN*10];
	int idx = 0;
	for (int i = 0; i < MAXN*10; i++) {
		fill(dp[idx][i], dp[idx][i]+MAXN*10, INF);
	}
	dp[idx][0][0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> A >> B >> C;
		idx ^= 1;
		memcpy(dp[idx], dp[idx^1], sizeof(dp[idx^1]));
		for (int j = 0; j < MAXN*10; j++) {
			for (int k = 0; k < MAXN*10; k++) {
				if (dp[idx^1][j][k] < INF) {
					dp[idx][j+A][k+B] = min(dp[idx][j+A][k+B], dp[idx^1][j][k] + C);
				}
			}
		}
	}
	int res = INF;
	for (int i = 1; i < MAXN*10; i++) {
		for (int j = 1; j < MAXN*10; j++) {
			if (i * MB == j * MA) res = min(res, dp[idx][i][j]);
		}
	}
	if (res == INF) res = -1;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
/*
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>
*/

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n;  cin >> n;
    map<string,ll> ana;
    ll ans = 0;

    for(int i=0;i<n;i++){
        string s; cin >> s;
        sort(ALL(s));
        ana[s]++;
    }

    for(auto itr=ana.begin();itr!=ana.end();itr++){
        ans += itr->second * (itr->second -1) /2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(long long x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
ll gcd(ll x, ll y){ll a,b; if(x>y){a=x; b=y;} else{a=y;b=x;} return (a%b==0 ? b: gcd(b,a%b));}
ll lcm(ll x, ll y){return x/gcd(x,y) * y;}

int main(){
  int N; cin >> N;
  ll r = 1;
  ll t;
  REP(i,N){
    cin >> t;
    r = lcm(t,r);
  }
  printf("%Ld\n",r);
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int north(int dice[6])
{
	int d[6];
	for(int i=0;i<6;i++)	d[i]=dice[i];
	dice[0]=d[1];
	dice[1]=d[5];
	dice[2]=d[2];
	dice[3]=d[0];
	dice[4]=d[4];
	dice[5]=d[3];
	return dice[0];
}

int south(int dice[6])
{
	int d[6];
	for(int i=0;i<6;i++)	d[i]=dice[i];
	dice[0]=d[3];
	dice[1]=d[0];
	dice[2]=d[2];
	dice[3]=d[5];
	dice[4]=d[4];
	dice[5]=d[1];
	return dice[0];
}

int east(int dice[6])
{
	int d[6];
	for(int i=0;i<6;i++)	d[i]=dice[i];
	dice[0]=d[4];
	dice[1]=d[1];
	dice[2]=d[0];
	dice[3]=d[3];
	dice[4]=d[5];
	dice[5]=d[2];
	return dice[0];
}

int west(int dice[6])
{
	int d[6];
	for(int i=0;i<6;i++)	d[i]=dice[i];
	dice[0]=d[2];
	dice[1]=d[1];
	dice[2]=d[5];
	dice[3]=d[3];
	dice[4]=d[0];
	dice[5]=d[4];
	return dice[0];
}

int right(int dice[6])
{
	int d[6];
	for(int i=0;i<6;i++)	d[i]=dice[i];
	dice[0]=d[0];
	dice[1]=d[2];
	dice[2]=d[3];
	dice[3]=d[4];
	dice[4]=d[1];
	dice[5]=d[5];
	return dice[0];
}

int left(int dice[6])
{
	int d[6];
	for(int i=0;i<6;i++)	d[i]=dice[i];
	dice[0]=d[0];
	dice[1]=d[4];
	dice[2]=d[1];
	dice[3]=d[2];
	dice[4]=d[3];
	dice[5]=d[5];
	return dice[0];
}

int main()
{
	for(int n;cin>>n,n;){
		int dice[6]={1,2,3,5,4,6},sum=1;
		while(n--){
			char s[16];	cin>>s;
			switch(s[0]){
				case 'N':	sum+=north(dice);	break;
				case 'E':	sum+=east(dice);	break;
				case 'W':	sum+=west(dice);	break;
				case 'S':	sum+=south(dice);	break;
				case 'R':	sum+=right(dice);	break;
				case 'L':	sum+=left(dice);	break;
			}
		}
		cout<<sum<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
from collections import defaultdict

def main():
    d = defaultdict(int)
    n, m = [int(i) for i in input().split()]
    py = {}

    for i in range(m):
        p, y = [int(i) for i in input().split()]
        py[i] = (p, y)

    res = [''] * m
    for v in sorted(py.items(), key=lambda x:x[1]):
        d[v[1][0]] += 1
        res[v[0]] = str(v[1][0]).zfill(6) + str(d[v[1][0]]).zfill(6)
    for r in res:
        print(r)

if __name__ == '__main__':
    main()



Measured memory_bytes: 54272