akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int V, E, src, snk;
vector<int> la, nxt, oppo, capa;
void init() {
    E = 0;
    la.clear(); nxt.clear(); oppo.clear(); capa.clear();
    la = vector<int>(V, -1);
}
void add(int u, int v, int c) {
    nxt.push_back(la[u]);
    la[u] = E++;
    oppo.push_back(v);
    capa.push_back(c);
}
vector<int> dist;
queue<int> q;
bool bfs() {
    dist = vector<int>(V, -1);
    q.push(src);
    dist[src] = 0;
    while(!q.empty()) {
        int u = q.front(); q.pop();

        for(int i = la[u]; i != -1; i = nxt[i]) {
            int v = oppo[i];
            if(capa[i] && dist[v] == -1) {
                q.push(v);
                dist[v] = dist[u] + 1;
            }
        }
    }
    return dist[snk] != -1;
}
vector<int> laa;
int dfs(int u, int f) {
    if(u == snk) return f;
    for(int i = laa[u]; i != -1; i = nxt[i]) {
        laa[u] = i;
        int v = oppo[i];
        if(capa[i] && dist[v] == dist[u] + 1) {
            if(int tmp = dfs(v, min(capa[i], f))) {
                capa[i] -= tmp;
                capa[i^1] += tmp;
                return tmp;
            }
        }
    }
    return 0;
}
int dinic() {
    int tf = 0;
    while(bfs()) {
        laa = la;
        while(int tmp = dfs(src, 1e9)) tf += tmp;
    }
    return tf;
}

vector<int> pchk;
void getPrime() {
    pchk = vector<int>(10000010, 0);
    for(int i = 2; i < 10000010; i++) {
        if(pchk[i]) continue;
        int mul = 2;
        while(i * mul < 10000010) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
    pchk[0] = 1;
    pchk[1] = 1;
    pchk[2] = 1;
}

int N;
vector<int> X;
vector<int> B;
vector<int> Me, Mo;

int main() {
    getPrime();

    scanf("%d", &N);
    X.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &X[i]);
    }
    for(int i = 0; i < N; i++) {
        if(i == 0 || X[i] != X[i - 1] + 1) {
            B.push_back(X[i]);
        }
        if(i == N - 1 || X[i] + 1 != X[i + 1]) {
            B.push_back(X[i] + 1);
        }
    }
    for(int i = 0; i < B.size(); i++) {
        if(B[i] % 2) Mo.push_back(B[i]);
        else Me.push_back(B[i]);
    }

    V = Me.size() + Mo.size() + 2, src = V - 2, snk = V - 1;
    init();

    for(int i = 0; i < Me.size(); i++) {
        add(src, i, 1);
        add(i, src, 0);
    }
    for(int i = 0; i < Mo.size(); i++) {
        add(Me.size() + i, snk, 1);
        add(snk, Me.size() + i, 0);
    }
    for(int i = 0; i < Me.size(); i++) {
        for(int j = 0; j < Mo.size(); j++) {
            if(!pchk[ abs(Me[i] - Mo[j]) ]) {
                add(i, Me.size() + j, 1);
                add(Me.size() + j, i, 0);
            }
        }
    }
    int K = dinic();
    cout<<K + (((int)Me.size() - K)/2 + ((int)Mo.size() - K)/2)*2 + ((Me.size() - K) % 2)*3;
}


Measured memory_bytes: 39552
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        int K = Integer.parseInt(input);
        long ans = 0;
        
        for(int a = 1; a <= K; a++){
            for(int b = 1; b <= K; b++){
                for(int c = 1; c <= K; c++){
                    ans += gcd(a, gcd(b, c));
                }
            }
        }
        
        System.out.println(ans);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 35936
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
#define prique priority_queue
int x,t=6,ans;
signed main(){
    cin>>x;
    ans=2*(x/11);
    if(x%11>6)ans+=2;
    else if(x%11) ans++;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c,i,d,f,g;
	string A,B,C;
	cin>>a>>b>>c>>d;

	if(a<b){
		g=a;
	}else{
		g=b;
	}
	if(c<d){
		f=c;
	}else{
		f=d;
	}

	cout<<g+f<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

const int MAX_N = 1000000;

bitset<MAX_N> sieve;
vector<int> primes;
void eratosthenes(){
	sieve[0] = sieve[1] = true;
	for(int i = 2; i < MAX_N; ++i){
		if(sieve[i]){ continue; }
		primes.push_back(i);
		for(int j = i + i; j < MAX_N; j += i){ sieve[j] = true; }
	}
}

int main(){
	eratosthenes();
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		int answer = 0;
		for(int i = n + 1; i <= 2 * n; ++i){
			if(!sieve[i]){ ++answer; }
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from itertools import combinations_with_replacement 

N, M, Q = map(int, input().split())

Qset = []

for i in range(Q):
    a = list(map(int, input().split()))
    Qset.append(a)

ans = 0
for num in combinations_with_replacement(range(1, M+1), N):
    ans_temp = 0
    for j in Qset:
        if j[2] == num[j[1]-1] - num[j[0]-1]:
            ans_temp += j[3]

    ans = max(ans, ans_temp)

print(ans)

Measured memory_bytes: 9140
def f(n, y):
    for i in range(n+1):
        for j in range(n-i+1):
            k = n - i - j
            if k >= 0:
                if y == i*10000 + j*5000 + k*1000:
                    print(i, j, k)
                    return
    print(-1, -1, -1)

n, y = map(int, input().split())
f(n, y)

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

int main(){
  int n;
  cin >> n;
  bool frag=false;
  int ans=1;
  for(int i=1;i<=n;i++){
    if(i*108/100==n){
      frag=true;
      ans=i;
      break;
    }
  }
  if(frag==true){
    cout << ans << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n, k;
    cin >> n >> k;

    ll a;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a >= k){ans++;}
    }
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位


class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};


int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(19);
	int n;
	in(n);
	n-=400;
	int hoge=n/200;
	int ans=8-hoge;
	out(ans);
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ans = 700;
    for(auto& e: S) {
        if (e == 'o') ans += 100;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

std::string dict = "abcdefghijklm";

int N;
std::vector<std::string> ans;

void solve(std::string s, int i, int jmax)
{
    if (i >= N)
    {
        ans.push_back(s);
        return;
    }
    for (int j = 0; j < jmax + 1; ++j)
    {
        auto next = s;
        next[i] = dict[j];
        if (j == jmax)
            solve(next, i + 1, jmax + 1);
        else
            solve(next, i + 1, jmax);
    }
}

int main()
{
    std::cin >> N;
    std::string s(N, 'a');
    solve(s, 1, 1);

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


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    ll ans = 0;
    REP(i, N) {
        if (i % 2 == 0 && A[i] % 2 == 1)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

vector<string> ps;
void permutation(int l, int r, string word)
{
    if (l == r)
    {

        ps.push_back(word);
    }
    else
    {
        for (int i = l; i <= r; ++i)
        {
            swap(word[l], word[i]);
            permutation(l + 1, r, word);
        }
    }
}

int main()
{
    int n;
    cin >> n;
    string a, b;
    rep(i, n)
    {
        char x;
        cin >> x;
        a += x;
    }
    rep(i, n)
    {
        char x;
        cin >> x;
        b += x;
    }
    string cp = a;
    sort(cp.begin(), cp.end());
    permutation(0, n - 1, cp);
    int x = 0;
    int y = 0;
    for (int i = 0; i < ps.size(); ++i)
    {
        if (ps[i] == a)
        {
            x = i + 1;
        }
        if (ps[i] == b)
        {
            y = i + 1;
        }

        if (x > 0 && y > 0)
        {
            break;
        }
    }
    cout << abs(x - y) << endl;
    return 0;
}

Measured memory_bytes: 5316
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int x;
  cin >> x;
  if (x < 1200) cout << "ABC\n";
  else cout << "ARC\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static class Pair {
        int left;
        int right;

        Pair(int l, int r) {
            left = l;
            right = r;
        }
    }

    static int len(int x) {
        if (x == 1) {
            return x;
        }

        return x * len(x - 1);
    }

    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        Pair[] pairs = new Pair[n];
        for (int i = 0; i < n; i++) {
            pairs[i] = new Pair(std.nextInt(), std.nextInt());
        }

        double[][] dp = new double[n+1][n+1];

        for (int i = 0; i < n; i++) {
            Pair start = pairs[i];
            for (int j = 0; j < n; j++) {
                if (j == i) {
                    continue;
                }

                Pair next = pairs[j];
                double l = Math.pow((start.left - next.left), 2);
                double r = Math.pow((start.right - next.right), 2);
                dp[i][j] = Math.sqrt(l + r);
            }
        }

        double ans = 0;

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

        ans /= n;
        System.out.println(ans);
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <cmath>
#define ll long long
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

using namespace std;

int n;
int a[4800];

bool color[8];

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

    int higer_rate = 0;

    REP(i,8) color[i] = false;

    REP(i,n){
        cin >> a[i];

        if (a[i] < 3200) color[(int)floor(a[i]/400)] = true;
        else higer_rate++;
    }

    int true_count = 0;

    REP(i,8) if(color[i]) true_count++;

    int max_count = (higer_rate > 0) ? higer_rate+true_count:true_count;
    int min_count = max(1,true_count);

    cout << min_count << " " << max_count << "\n";
}

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

int prime[1000000+1]; 
int seen[1000000+1]={0};
int arr[1000000];


void SieveOfEratosthenes(int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 

    prime[1] = 2;
	for (int p=2; p<=n; p++) 
		prime[p] = p;
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == p) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                if(prime[i]==i)prime[i] = p;
        } 
    } 
	//for(int i=2; i<=100 ;i++)
		//cout<<i<<" "<<prime[i]<<" ";
} 

int main()
{
	SieveOfEratosthenes(1000000);
	
	int n;
	string answer;
	bool ans = true;
	cin >> n;
	int i,j;
	int gc = 0;
	unordered_set<int> st;
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
		gc = __gcd(gc,arr[i]);
	}

	for(i=0;i<n;i++)
	{
		if(arr[i]==1) continue;
		while(arr[i]!=1)
		{
			int pf = prime[arr[i]];
			if(seen[prime[arr[i]]]==1)
				{ans = false; break;}
			seen[prime[arr[i]]] = 1;
			//cout<<arr[i]<<" "<<prime[arr[i]]<<endl;
			while(arr[i]%pf == 0){
				arr[i]/=pf;
				//cout<<arr[i]<<" "<<prime[arr[i]]<<endl;
			}
				
			
		}
		if(ans== false) break;
	}
	if(ans == true)
	 answer = "pairwise coprime\n";
	else if(gc ==1)
		answer = "setwise coprime\n";
	else
		answer = "not coprime\n";
	cout<<answer;
}


Measured memory_bytes: 11760
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif
using namespace std;

int main() {
    ll N;
    string S;
    cin >> N >> S;
    for(char &c : S) {
        ll n = N;
        while(n--) {
            if(c == 'Z') c = 'A';
            else c++;
        }
    }
    cout << S << endl;
    return 0;
}


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

int main()
{
	int H, W, A, B;
	scanf("%d%d%d%d", &H, &W, &A, &B);
	if (W < 2 * A || H < 2 * B)
	{
		puts("No");
		return 0;
	}
	for (int i{}; i < H; i++)
	{
		for (int j{}; j < W; j++)
			if ((i < B) ^ (j < A))
				putchar('1');
			else
				putchar('0');
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<long double>v(N);
  REP(i,N)cin>>v[i];
  sort(ALL(v));
  long double ans=v[0];
  FOR(i,1,N){
    ans=(ans+v[i])/2.0;
  }
  cout<<setprecision(15)<<ans<<endl;
}


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

using namespace std;

char a[105][105];

char x, y;
void process(int i, int j)
{
    a[i][j] = x;

    a[i][j + 1] = y;
    a[i][j - 1] = y;
    a[i + 1][j] = y;
    a[i - 1][j] = y;
    a[i - 1][j - 1] = y;
    a[i - 1][j + 1] = y;
    a[i + 1][j - 1] = y;
    a[i + 1][j + 1] = y;
}

main()
{
    int wh, bl, c = 0;

    int n = 99;

    cin >> wh >> bl;

    x = '.', y = '#';

    if (bl < wh)
    {
        swap(x, y);
        c = wh - bl + 1;
        wh = bl - 1;
    }
    else
    {
        c = bl - wh + 1;
        if (bl == wh)
            c = 1;
        bl = wh - 1;
    }

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

    bool fl = 0;
    for (int i = 0; i < n; i += 2)
    {
        for (int j = 0; j < n; j += 2)
        {
            if (c == 0)
            {
                fl = 1;
                break;
            }
            a[i][j] = y;
            c--;
            if (c == 0)
            {
                fl = 1;
                break;
            }
        }
        if (fl)break;
    }

    fl = 0;
    for (int i = n - 2; i >= 0; i -= 4)
    {
        for (int j = n - 2; j >= 0; j -= 4)
        {
            if (bl * wh == 0)
            {
                fl = 1;
                break;
            }
            process(i, j);
            wh--;
            bl--;
            if (max(wh, bl) == 0)
            {
                fl = 1;
                break;
            }
        }
        if (fl)
            break;
    }
    cout << n << " " << n << endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << a[i][j];
        }
        cout << endl;
    }
}




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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    cout << N / 3 << endl;
    return 0;
}

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

int main(){
  double w, h, x, y;  cin >> w >> h >> x >> y;
  double ans = w*h/2.0;
  printf("%.6f", ans);
  cout << " ";
  if(w/2.0==x && h/2.0==y) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,k = map(int,input().split())
for i in range(k):
    if i%2==0:
        if a%2==1:
            a -= 1
            a //=2
            b+=a
        else:
            a //=2
            b+=a
    else:
        if b%2==1:
            b -= 1
            b //=2
            a+=b
        else:
            b //=2
            a+=b
print(a,b)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		int num = stdIn.nextInt();
		
		for(int r = 0; r < num; r++) { //読み込み&分割
			StringBuilder str = new StringBuilder(stdIn.next());
			TreeSet<String> ans = new TreeSet<String>();
			for(int c = str.length() - 2; c >= 0; c--) {
				StringBuilder str1 = new StringBuilder(str.substring(0, c + 1));
				StringBuilder str2 = new StringBuilder(str.substring(c + 1));
				
				StringBuilder strbuf1 = new StringBuilder(str1.toString());
				StringBuilder strbuf2 = new StringBuilder(str2.toString());
				strbuf1.reverse();
				strbuf2.reverse();
				ans.add((str1.toString()    + str2.toString()));
				ans.add((str2.toString()    + str1.toString()));
				
				ans.add((strbuf1.toString() + str2.toString()));
				ans.add((str2.toString()    + strbuf1.toString()));
				
				ans.add((str1.toString()    + strbuf2.toString()));
				ans.add((strbuf2.toString() + str1.toString()));
				
				ans.add((strbuf1.toString() + strbuf2.toString()));
				ans.add((strbuf2.toString() + strbuf1.toString()));
			}
			System.out.println(ans.size());
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}
}

Measured memory_bytes: 56592
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;


int main()
{

    char st[10];
    scanf("%s",st);
    int ans=0;
    for (int i=0;i<3;++i)
        if (st[i]=='R'){
            int tmp=1;
            while (st[i+tmp]=='R')
                tmp++;
            if (tmp>ans)
                ans =tmp;
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
string S;

int main(){
	cin >> S;
	vector<bool> ok(S.size()+1);
	ok[0] = true;

	for(int i=0; i<=S.size(); i++){
		if(i >= 5 && ok[i-5] && S.substr(i-5, 5) == "dream"){
			ok[i] = true;
		}
		else if(i >= 7 && ok[i-7] && S.substr(i-7, 7) == "dreamer"){
			ok[i] = true;
		}
		else if(i >= 5 && ok[i-5] && S.substr(i-5, 5) == "erase"){
			ok[i] = true;
		}
		else if(i >= 6 && ok[i-6] && S.substr(i-6, 6) == "eraser"){
			ok[i] = true;
		}
	}

	// cout << S << endl;
	// for(int i=0; i<ok.size(); i++) cout << ok[i];
	// cout << endl;

	cout << (ok[S.size()] ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 640
/**
 *    viet the nay ko phai bat chuoc tourist
 *    ma la muon noi rang
 *	 doc code ban khac la suc vat khong phai con nguoi
**/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef pair<ll, pair<ll,ll> > iii;
typedef vector<ll> vi;

const int kn = 2e5 + 1;
const int N = 1e5 + 1;
const ll mod = 1e9 + 7;

//#define x first
//#define y second
#define _it iterator
#define pb push_back
#define f(i,a,b) for(int i=a;i<=b;i++)
#define ff(i,n) for(int i=1;i<=n;i++)
#define ms(val,a) memset(a,val,sizeof(a))
#define _ff(i,n) for(int i=n;i>=1;i--)
#define _f(i,a,b) for(int i=b;i>=a;i--)
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll n, a[N], b[N];
ll dp[N][2];

int main() {
	cin >> n;
	ff(i,n) cin >> a[i];
	dp[2][0] = a[1] + a[2]; dp[2][1] = -a[1] - a[2];
	for(int i = 3; i<= n; i++)
	{
		dp[i][0] = max(dp[i-1][1], dp[i-1][0]) + a[i];
		if(i>3) dp[i][1] = max(dp[i-2][0],dp[i-2][1]) + a[i-1]*(-1) + a[i]*(-1);
		else dp[i][1] = -99999999;
		dp[i][1] = max(dp[i][1], dp[i-1][1] - a[i-1]*(-1) +a[i-1] + a[i]*(-1));
		dp[i][1] = max(dp[i][1], dp[i-1][0] - a[i-1] + a[i-1]*(-1) + a[i]*(-1));
		//cout << i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
	}
	cout << max(dp[n][1],dp[n][0]);
	
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    string s;
    cin>>s;
    s[3]='8';
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public string via { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var map = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            var s =Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == '#') map[i, j] = true;
        }
        Console.WriteLine(goDfs(map) ? "Possible": "Impossible");
    }
    public static bool   goDfs (bool[,] map)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        var st = new Stack<P>();
        st.Push(new P { x = 0, y = 0, via = "" });
        while (st.Count() > 0)
        {
            var t = st.Pop();
            if (t.x == h - 1 && t.y == w - 1 && checkVia(map, t.via)) return true;
            if (t.y + 1 < w && map[t.x, t.y +1] )  st.Push(new P { x = t.x, y = t.y + 1, via = t.via + "r" });
            if (t.x + 1 < h && map[t.x+1, t.y ]) st.Push(new P { x = t.x+1, y = t.y , via = t.via + "d" });
        }
        return false;   
    }
    public static bool checkVia (bool [,] map , string a)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        var map2 = new bool[h, w];
        var x = 0;  var y = 0;  map2[0, 0] = true;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == 'r') y++;
            else x++;
            map2[x, y] = true;
        }
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (map[i, j] != map2[i, j]) return false;
        return true;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

const int V=200005;
int p[V];

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  fill(p, p + V, -1);
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      p[e.to] = idx;  // 直前の頂点を保持
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}
WeightedGraph<int> g;
vi v;


int n,m;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m;
    
    g.resize(n);
    REP(i,m){
        int a,b;
        cin>>a>>b;
        a--; b--;
        g[a].emplace_back(b,1);
        g[b].emplace_back(a,1);
    }

    v = dijkstra<int>(g,0);

    bool ok=true;
    REP(i,n){
        if(v[i]==numeric_limits< int >::max()){
            ok=false;
            break;
        }
    }
    //DEBUG_VEC(v);
    if(!ok){
        cout<<"No"<<endl;
        return 0;
    }
    
    cout<<"Yes"<<endl;
    FOR(i,1,n){
        //cout<<v[i]<<endl;
        cout<<p[i]+1<<endl;
    }
    //DEBUG_ARR(p,10);
    //vi hoge;
    //dfs(1,0,hoge);
    //DEBUG_VEC(ro);
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15752
from itertools import combinations

N = int(input())
*L, = map(int, input().split())
ans = 0

for a, b, c in combinations(L, 3):
    if a==b or b==c or a==c:
        continue
    if a+b>c and b+c>a and a+c>b:
        ans += 1

print(ans)


Measured memory_bytes: 73596
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int c[200][200];
int N;
void solve()
{
    /*
    int n = 22;
    for (int i = 1; i <= n; i++) {
        FORR(j, i, n)
        {
            c[i][j] = (c[i][j - 1] ^ (j % 12 + j / 12));
        }
    }
    FORR(i, 1, n)
    {
        FORR(j, 1, n)
        {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
    */
    int n = N;
    while (n) {
        if (n % 2 == 1) {
            if (n == 1ll) {
                cout << "No" << endl;
                return;
            }
            break;
        }
        n = n >> 1ll;
    }
    n = N;
    int m = 1;
    while (n) {
        n = n >> 1ll;
        m = m << 1ll;
    }
    m = m / 2;
    m = N - m;
    int x = N % 4;
    // cout << m << endl;
    if (N <= 2 || N == 4) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        if (/*m <= 2*/ x != 0) {
            //n = N - m - 1;
            if (x != 3)
                n = N - x - 1;
            else
                n = N;
            FORR(i, 1, n - 1)
            {
                cout << i << " " << i + 1 << endl;
                cout << i + N << " " << i + N + 1 << endl;
            }
            cout << n << " " << N + 1 << endl;
            if (x == 1 || x == 2) {
                cout << 1 << " " << n + 1 << endl;
                cout << n + 1 << " " << n + 2 << endl;
                cout << 1 << " " << N + n + 2 << endl;
                cout << N + n + 2 << " " << N + n + 1 << endl;
            }
            if (x == 2) {
                cout << N + n + 2 << " " << N + n + 3 << endl;
                cout << 2 << " " << n + 3 << endl;
            }
        } else {
            int q = 0;
            FOR(i, 1, N)
            {
                if (N == ((N - 1) ^ i)) {
                    q = i;
                    break;
                }
            }
            FORR(i, 1, N - 2)
            {
                if (i == q) {
                    continue;
                }
                if (q - 1 == i) {
                    cout << q - 1 << " " << q + 1 << endl;
                    cout << q - 1 + N << " " << q + 1 + N << endl;

                } else {
                    cout << i << " " << i + 1 << endl;
                    cout << i + N << " " << i + 1 + N << endl;
                }
            }
            cout << N - 1 << " " << q << endl;
            cout << N - 1 + N << " " << q + N << endl;
            cout << q << " " << 1 + N << endl;
            cout << N - 1 << " " << N << endl;
            cout << q << " " << N * 2 << endl;
        }
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    solve();
    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

	int A[10005];
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}

	for (int i = 0; i < M; i++) {
		N -= A[i];
	}

	if (N < 0) {
		N = -1;
	}
	cout << N << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
vi in;
vvi dp;
int n;
int f(int a,int b){
	if(a<0||a>=n||b<=0||b>n)return 0;
	if(dp[a][b]!=-inf)return dp[a][b];
	int out=0;
	{
		int t=f(a+1,b-2);
		if(t>0&&abs(in[a]-in[a+b-1])<=1)out=t+2;
	}
	rep(i,b-1){
		int s=f(a,i+1);
		int t=f(a+i+1,b-i-1);
		if(s>0&&t>0)out=max(out,s+t);
	}
	if(b==2&&abs(in[a]-in[a+1])<=1)out=2;
	return dp[a][b]=out;
}
int main(){
	while(cin>>n,n){
		in=vi(n);
		rep(i,n)cin>>in[i];
		dp=vvi(n,vi(n+1,-inf));
		f(0,n);
//		rep(i,n){rep(j,n+1)cout<<" "<<dp[i][j];cout<<endl;}
//		cout<<endl;
		vi out(n+1);
		rep(i,n){
			if(i)out[i]=max(out[i],out[i-1]);
//			cout<<out[i]<<" ";
			rep(j,n+1)if(dp[i][j]>0){
				out[i+j]=max(out[i+j],out[i]+dp[i][j]);
			}
		}
		cout<<max(out[n-1],out[n])<<endl;
	}
}

Measured memory_bytes: 3556
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int k = sc.nextInt();
            int[][] val = new int[n+1][m+1];
            for(int i=0 ; i<k ; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                int z = sc.nextInt();
                val[x][y] = z;
            }

            long[][][] dp = new long[n+1][m+1][4];

            for(int i=1 ; i<=n ; i++) {
                for(int j=1 ; j<=m ; j++) {
                    for(int x=0 ; x<=3 ; x++) {
                        dp[i][j][x] = dp[i][j-1][x];
                    }

                    for(int x=1 ; x<=3 ; x++) {
                        dp[i][j][x] = Math.max(dp[i][j][x], val[i][j] + dp[i][j-1][x-1]);
                    }

                    long max = 0;
                    for(int x=0 ; x<=3 ; x++) {
                        max = Math.max(max, dp[i-1][j][x]);
                    }

                    for(int x=0 ; x<=3 ; x++) {
                        dp[i][j][x] = Math.max(max, dp[i][j][x]);
                    }
                    dp[i][j][1] = Math.max(max + val[i][j], dp[i][j][1]);
                }
            }

            long ans = 0;
            for(int i=0 ; i<=3 ; i++) {
                ans = Math.max(ans, dp[n][m][i]);
            }
            pw.println(ans);

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 688208
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

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

int main()
{
    long long  t;
    //int n=100;
    cin>>t;
    vector<long long> a(t+1,0);
    //int x=1,y=1,z=1;
    
        for(int x=1;x*x<=t;x++)
        {
            for(int y=1;y*y<=t;y++)
            {
                for(int z=1;z*z<=t;z++)
                {
                    
                    if(x*x+y*y+z*z+x*y+y*z+x*z<=t){
          a[x*x+y*y+z*z+x*y+y*z+x*z]++;}
          //else
          //break;
                }
            }
        }    
        // for(int i=1;i<=n;i++)
        // {
            
        //     int k=(i+i)*(i+i)+(i+i)*(i+i)+(i+i)*(i+i);
        //     a[k/2]++;
            
            
        // }
        
    //int t;
    //cin>>t;
    for(long long  i=1;i<=t;i++)
    {
        cout<<a[i]<<"\n";
    }
    
    

    return 0;
}


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



int main(){
  	char ch;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >> ch;
			if(i==j) cout << ch;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include<string>
#include<algorithm>
#include<cmath>
#define REP(i,n) for(int i=0; i<int(n); i++)
using namespace std;
int main() {
	int A1, A2, A3;
	cin >> A1 >> A2 >> A3;
	if (A1 + A2 + A3 >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
}

Measured memory_bytes: 256
# cook your dish here
import sys
 
sys.setrecursionlimit(100005)
MOD = 1000000007
 
 
def dfs(v, a):
    w, b = 1, 1
    # print(w,b,v);
    for u in links[v]:
        if u == a:
            continue
        cw, cb = dfs(u, v)
        w *= cw + cb
        b *= cw
        w %= MOD
        b %= MOD
        # print(w,b,u,cw,cb);
    return w, b
 
 
n = int(input())
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    links[x].add(y)
    links[y].add(x)
 
print(sum(dfs(0, None)) % MOD)

Measured memory_bytes: 112464
while True:
    N, A, B, C, X = map(int, input().split())
    if N == 0 and A == 0 and B == 0 and C == 0 and X == 0:
        break
    Y = list(map(int, input().split()))

    done_frame = -1
    cur_reel = 0
    cur_X = X

    for i in range(10001):
        if cur_X == Y[cur_reel]:
            if cur_reel == N - 1:
                done_frame = i
                break
            else:
                cur_reel += 1
        cur_X = (A * cur_X + B) % C

    if done_frame >= 0:
        print(done_frame)
    else:
        print(-1)






Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin >> n;
    int a[n],b[n];
    int ma[n],mb[n];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    int res=0;
    rep(i,29){
        int cnt=0;
        int mod = 1<<i+1;
        DEBUG{cout << "mod " << mod << endl;}
        rep(j,n){
            ma[j]=a[j]%mod;
            mb[j]=b[j]%mod;
        }
        sort(ma,ma+n);
        sort(mb,mb+n);
        rep(j,n){
            rep(k,2){
                auto from = lower_bound(mb,mb+n,mod/2*(2*k+1)-ma[j]);
                auto to = lower_bound(mb,mb+n,mod/2*(2*k+2)-ma[j]);
                cnt+= int(to-from);
            }
        }
            DEBUG{cout << "cnt " << cnt << endl;}
            res+=(1<<i)*(cnt&1);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3328
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
N = int(input())
ret = make_divisors(N)
if ret[-1]**2 == N:
    ret.append(ret[-1])

min = 9999999999999
for i in range(int(len(ret)/2)):
    now = (ret[i*2] -1) + (ret[i*2+1] -1)
    min = now if now < min else min
    
print(min)




Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
char s[1000100];
struct Node{
	int cnt; char x;
	inline bool operator < (const Node& rhs) const {
		return cnt < rhs.cnt; 
	}
} a[5];
int c[300],to[300],ban[1000010];
int fr[1000010],ne[1000010];
inline void del(int x){
	ban[x]=1;
	ne[fr[x]]=ne[x];
	fr[ne[x]]=fr[x];
	--a[to[s[x]]].cnt;
}
int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	rep(i,1,n){
		c[s[i]]++;
	}
	rep(i,'A','C'){
		a[i-'A'+1]=(Node){c[i],i};
	}
	sort(a+1,a+4);
	rep(i,1,3){
		to[a[i].x]=i;
	}
	rep(i,1,n){
		fr[i]=i-1;
		ne[i]=i+1;
	}
	rep(i,1,n)if(s[i]==s[fr[i]]){
		del(i);
	}
	sort(a+1,a+4);
	rep(i,1,3){
		to[a[i].x]=i;
	}
	if(a[2].cnt!=a[3].cnt){
		rep(i,1,n)if(s[i]==a[3].x&&!ban[i]){
			if(s[fr[i]]!=s[ne[i]]){
				del(i);
				if(a[2].cnt==a[3].cnt)break;
			}
		}
		if(a[2].cnt!=a[3].cnt){
			rep(i,1,n)if(s[i]==a[3].x&&!ban[i]){
				if(s[fr[i]]==a[1].x&&s[ne[i]]==a[1].x){
					del(fr[i]),del(i);
					if(a[2].cnt==a[3].cnt)break;
				}
			}
		}
		if(a[2].cnt!=a[3].cnt){
			return 0;
		}
	}
	
	if(a[1].cnt!=a[2].cnt){
		rep(i,1,n)if(!ban[i]){
			if(s[i]==a[2].x&&s[ne[i]]==a[3].x){
				if(s[fr[i]]==a[1].x&&s[ne[ne[i]]]==a[1].x) continue;
				del(ne[i]),del(i);
				if(a[1].cnt==a[2].cnt)break;
			}
		}
		if(a[1].cnt!=a[2].cnt){
			rep(i,1,n)if(!ban[i]){
				if(s[i]==a[3].x&&s[ne[i]]==a[2].x){
					if(s[fr[i]]==a[1].x&&s[ne[ne[i]]]==a[1].x) continue;
					del(ne[i]),del(i);
					if(a[1].cnt==a[2].cnt)break; 
				}
			}	
		}
	}
	if(a[1].cnt!=a[2].cnt){
		return 0;
	}
	rep(i,1,n)if(!ban[i]){
		printf("%c",s[i]);
	}
}

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

int main(void){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i)cin>>a[i];
  for(int j=0;j<n;++j)cout<<a[j]<<((j==n-1)?"\n":" ");
  for(int i=1;i<n;++i){
    int key=a[i],j=i-1;
    for(;j>=0 && a[j]>key;--j){
      a[j+1]=a[j];
    }
    a[j+1]=key;
    for(int j=0;j<n;++j)cout<<a[j]<<((j==n-1)?"\n":" ");
  }
  return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

int main(){
	
	int n, k;
	int valor = 1;
	
	scanf("%d%d", &n, &k);
	
	for (int i = 0; i < n; ++i){
		if ((valor + k) >= (valor * 2))
			valor *= 2;
		else 
			valor += k;
	}
	
	printf("%d\n", valor);
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

int main() {
	int s, w;
	cin >> s >> w;
	puts(w >= s ? "unsafe" : "safe");

	return 0;
}

Measured memory_bytes: 3596