akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int Pow(int a,int b){return b?Pow(a*a,b>>1)*(b&1?a:1):1;}
int main()
{
  int N,now,len=0,A[1000001],B[600001];
  char T[1000001],S[1000001];
  now=scanf("%d %s",&N,T);len=strlen(T);
  int pw3=Pow(3,N),x=Pow(3,N>>1),y=Pow(3,N-(N>>1));
  rep(i,pw3)B[i]=B[i/3]*3+(3-i%3)%3;
  rep(i,x)
  {
    int temp=i;now=0;
    rep(j,len)
    {
      if(T[j]=='S'){temp=B[temp];if(S[now]=='S')--now;else S[++now]='S';}
      else{++temp;if(temp==x)S[++now]='R',temp=0;}
    }
    rep(j,y)
    {
      int keep=j;
      rep(k,now)
      {
        if(S[k+1]=='S')keep=B[keep];
        else if(S[k+1]=='R')if((++keep)==y)keep=0;
      }
      A[i+j*x]=temp+keep*x;
    }
  }
  rep(i,pw3)printf("%d%c",A[i],i+1==pw3?'\n':' ');
}

Measured memory_bytes: 8276
#include<stdio.h>
int main(){
  int x,y,tmp,r;
 
  scanf("%d %d", &x, &y);
 
   if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
 
  /* ユークリッドの互除法 */
  r = x%y;
  while(r!=0){
    x = y;
    y = r;
    r = x%y;
  }
 
  /* 最大公約数を出力 */
  printf("%d\n", y);

  return 0;
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  ll ans = 0;

  // 60bitまで
  REP(i,60) {
    ll x = 0;
    REP(j,n) if (a[j]>>i&1) x++;
    ll now = x*(n-x)%MOD; // (1の数)*(0の数): 0と1のペアを選ぶ
    REP(j,i) now = now*2%MOD;
    ans += now;
    ans %= MOD;
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 5540
/**
 * @author torith
 * @date 2019-02-09
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

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

    int K; cin >> K;
    int A; cin >> A;
    int B; cin >> B;

    if(B - A < 2) cout << K + 1 << "\n";
    else {
        ll ans = 1;
        int i = 0;
        while(i < K){
            if(A <= ans && i != K-1){
                ans = ans - A + B;
                i += 2;
            }else{
                ans++;
                i++;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] data = new int[n+1];

    for(int i = 1;i <= n;i++) {
      int x = sc.nextInt();
      data[x] = i;
    }

    for(int i = 1;i <= n;i++) {
      System.out.println(data[i]);
    }

  }

}


Measured memory_bytes: 60436
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;

int n,m,ar[maxn];
bool vis[maxn];
int ans[maxn];
int main()
{
    int mx=0;
    char ch[100];
    scanf("%s",ch);
    n=strlen(ch);
    set<char> s;
    s.insert('A');
    s.insert('C');
    s.insert('G');
    s.insert('T');
    int ins=0;
    for(int i=0;i<n;i++){
        if(s.count(ch[i])){
            ins++;
        }
        else{
            ins =0;
        }
        mx=max(mx,ins);
    }
    printf("%d\n",mx);

    return 0;
}


Measured memory_bytes: 256
def add(x, y):
    return x+y

def diff(x, y):
    return x-y
    
def mul(x, y):
    return x*y
    
def div(x, y):
    return int(x/y)

op = {"+" : add , "-" : diff, "*" : mul, "/" : div}

st = input()
s = st.split()
while(not s[1] == '?'):
    print(op[s[1]](int(s[0]), int(s[2])))
    st = input()
    s = st.split() 

Measured memory_bytes: 7688
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  map<pll,ll> p;
  for(int i=1;i<=n;i++){
    ll k=i;
    ll cu=0;
    while(k/10!=0){
      k/=10;
    
    }
    ll u=i;
    while(u%10!=0){
      cu++;
      u--;
    }
    if(cu==0) continue;
    p[pll(k,cu)]++;
  }
  ll ans=0;
  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      ans+=p[pll(i,j)]*p[pll(j,i)];
    }
  }
  COUT(ans);
}

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

using namespace std;


template <class T>
std::istream& operator>>(std::istream& in, std::vector<T>& data) {
    for (auto& item : data) {
        in >> item;
    }
    return in;
}

template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& data) {
    bool first = true;
    for (const auto& item : data) {
        if (!first) {
            out << " ";
        }
        out << item;
        first = false;
    }
    return out;
}


int main() {
#ifdef LOCAL
    freopen("atcoder/2/input.txt", "r", stdin);
#endif

    int n;
    cin >> n;

    vector<int64_t> cities(n + 1);
    vector<int64_t> heroes(n);
    cin >> cities >> heroes;

    vector<int64_t> can_defeat(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        int64_t need_defeat = cities[i] - can_defeat[i];

        can_defeat[i] = min(can_defeat[i] + heroes[i], cities[i]);
        can_defeat[i + 1] = min(can_defeat[i + 1] + max((int64_t)0, heroes[i] - need_defeat), cities[i + 1]);
    }

    int64_t res = 0;
    for (int num : can_defeat) {
        res += num;
    }

    cout << res << "\n";

    return 0;
}











Measured memory_bytes: 2560
import itertools

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


l = [i for i in range(1,n+1)]

x = [j for j in itertools.permutations(l)]

a = x.index(tuple(p))
b = x.index(tuple(q))

print(abs(a-b))


Measured memory_bytes: 45040
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    int n; cin >> n;
    V<double> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    V< V<double> > dp(n + 1, V<double>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dp[i + 1][j] += (1.0 - p[i]) * dp[i][j];
            dp[i + 1][j + 1] += p[i] * dp[i][j];
        }
    }
    double ans = 0;
    for (int i = n; i >= 0; i--) {
        if (n - i >= i) break;
        ans += dp[n][i];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 73756
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int n;
        scanf("%d",&n);
    
    if (1999 > n && n > 999){
        printf ("ABD");
    }else if(n > 0){
        printf("ABC");
    }else{
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 5000000
#define NIL -1
int heap_size;
struct Node{
  int p;
  int l;
  int r;
  int k;
};
struct Node T[MAX];
void maxHeapify(int i){
	int r, l;
	int largest;
	int tmp;
	l=2*i;
	r=2*i+1;
	if( l<= heap_size && T[l].k>T[i].k ) largest=l;
	else largest=i;
	if( r<=heap_size && T[r].k>T[largest].k ) largest=r;
	if( largest!=i ){
		tmp=T[i].k;
		T[i].k=T[largest].k;
		T[largest].k=tmp;
		maxHeapify(largest);
	}
}
void buildMaxHeap(void){
	int i;
	for( i=heap_size/2; i>0; i-- ){
		maxHeapify(i);
	}
}
int main(void){
  int i;
  scanf("%d", &heap_size);
  if( heap_size>=MAX) return 0;
  for ( i=1; i<=heap_size; i++ ) T[i].p=T[i].l=T[i].r=T[i].k=NIL;
  for ( i=1; i<=heap_size; i++ ){
    scanf("%d", &T[i].k);
  }
  for( i=1; i<=heap_size; i++ ){
    T[i].p=T[i/2].k;
    T[i].l=T[2*i].k;
    T[i].r=T[2*i+1].k;
  }
  buildMaxHeap();
  for ( i=1; i<=heap_size; i++ ){
	  printf(" %d", T[i].k);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 16980
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <vector>
using namespace std;
#define ll long long
ll gcd(ll a, ll b) {
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	cout << (a * b) / gcd(a, b);
	system("pause>0");
	return 0;
}


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

#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define RFOR(i,a,b) for (lli i=(b)-1;i>=(a);i--)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define RREP(i,n) for (lli i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> P;

const lli INF = INT_MAX/3;
const double EPS = 1e-14;
const lli dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const lli dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

lli gcd(lli a, lli b) {
  return b == 0 ? a : gcd(b, a % b);
}

lli extgcd(lli a, lli b, lli& x, lli& y) {
  lli g = a; x = 1; y = 0;
  if (b) g = extgcd(b, a%b, y, x), y -= (a / b) * x;
  return g;
}

lli abss(lli x) {
  return x > 0 ? x : -x;
}

int main() {
  cout << fixed << setprecision(10);
  lli a, b, d;
  while (cin >> a >> b >> d and d) {
    lli g = gcd(a, b);
    a /= g, b /= g, d /= g;
    lli x, y;
    extgcd(a, - b, x, y);
    x *= d, y *= d;
    lli xpy = abss(x) + abss(y),
        axpby = a * abss(x) + b * abss(y);
    lli ansx = x, ansy = y;
    FOR(k, -100001, 100001) {
      lli xx = abss(b * k + x), yy = abs(a * k + y);
      lli p = xx + yy, q = a * xx + b * yy;
      if (p < xpy || (p == xpy && q < axpby)) {
        ansx = xx, ansy = yy;
        xpy = p;
        axpby = q;
      }
    }
//    cout << "#(" << a << "," << b << ","  << d << ") " << x << " " << y << endl;
    cout << abss(ansx) << " " << abss(ansy) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Threading.Tasks;
 
static class Program
{
  static void Main()
  {
    var inputVal = Console.ReadLine().Split(' ');
    int r = int.Parse(inputVal[0]);
    int D = int.Parse(inputVal[1]);
    int val = int.Parse(inputVal[2]);

    for (int i = 0; i < 10; i++)
    {
      val = val * r - D;
      Console.WriteLine(val);
    }
  }
}

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

const int N = 1010;
int n, m, a, b;
vector<int> adj[N], ans(N + 1);

vector<int> minCircle(int s) {
    vector<int> visited(N, 0), parent(N, 0);
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (int to : adj[from]) {
            if (visited[to] == 0) {
                parent[to] = from;
                visited[to] = 1;
                q.push(to);
            }
        }
        if (visited[s]) break;
    }
    int p = parent[s];
    vector<int> ret;
    ret.push_back(s);
    while (p && p != s) {
        ret.push_back(p);
        p = parent[p];
    }
    return ret;
}

int main() {
    cin >> n >> m;
    while (m--) {
        cin >> a >> b;
        adj[a].push_back(b);
    }
    for (int i = 1; i <= n; i++) {
        vector<int> t = minCircle(i);
        if (t.size() > 1 && t.size() < ans.size()) ans = t;
    }
    if (ans.size() == N + 1)
        puts("-1");
    else {
        cout << ans.size() << endl;
        for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;
    }
}


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

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int maxLength = 0;
		int length = 0;

		for (int i = 0; i < s.length(); i++) {

			char c = s.charAt(i);

			switch (c) {
			case 'A':
			case 'C':
			case 'G':
			case 'T':
				length++;
				break;
			default:
				length = 0;
				break;
			}

			if (length > maxLength) {
				maxLength = length;
			}
		}

		System.out.println(maxLength);

		sc.close();
	}
}


Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};



int main() {
	int n,k;
	cin>>n>>k;
	if(k>(n-2)*(n-1)/2){
		print(-1);
		return 0;
	}else{
		print((n-2)*(n-1)/2+n-1-k);
		rep(i,2,n+1)print(1<<" "<<i);
		int step=0;
		while(1){
			rep(i,2,n){
				rep(j,i+1,n+1){
					if(step>=(n-2)*(n-1)/2-k)break;
					print(i<<" "<<j);
					step++;
				}
				if(step>=(n-2)*(n-1)/2-k)break;
			}
			if(step>=(n-2)*(n-1)/2-k)break;
		}
		return 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
         
int main(void){
         
int a[3],i,j,tmp;
       
scanf("%d %d %d",&a[0],&a[1],&a[2]);
  
   for (i = 0; i < 2; i++)
        for (j = i + 1; j < 3; j++)
        if (a[j] < a[i])       /*  <: ??????,  >: ??????  */
            {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            };
   
printf("%d %d %d\n",a[0],a[1],a[2]);
       
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int N,K;
    string S;
//    cin >> N >> K;
//    vector<int> A(N);
    rep(i, 0, 5){
        int tmp;
        cin >> tmp;
        if(!tmp){
            int ans = i+1;
            cout << ans << endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
  ll a, b;
  int ans = 0;
  cin >> a >> b;
  for (ll i = a; i <= b; i++)
  {
    string buf = to_string(i);
    if (
        (buf[0] == buf[1] && buf[1] == buf[3] && buf[3] == buf[4]) ||
        (buf[0] == buf[4] && buf[1] == buf[3]))
    {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int modpow(int a, int b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b & (1 << i)) != 0) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

int Div(int a, int b, long long m) {
	return (1LL * a * modpow(b, m - 2, m)) % m;
}

long long mod = 998244353;
long long dp1[10000007];
long long dp2[10000007];

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

	// dp1 の計算
	dp1[0] = 1; dp1[1] = -2; dp1[2] = 0; dp1[3] = 16;
	long long val1 = 20, val2 = 2, p1 = 14, p2 = 2;
	for (int i = 4; i <= (N >> 1); i++) {
		dp1[i] = dp1[i - 1] * Div(val1 % mod, val2 % mod, mod);
		dp1[i] %= mod;
		p1 += 8; p2++;
		val1 += p1; val2 += p2;
	}

	// dp2 の計算
	dp2[0] = 1;
	for (int i = 1; i <= (N >> 1); i++) {
		dp2[i] = 9LL * dp2[i - 1] + dp1[i];
		dp2[i] = (dp2[i] + mod) % mod;
	}

	cout << dp2[N / 2] << endl;
	return 0;
}

Measured memory_bytes: 82176
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, m;
int r;
vector<int> e[100010];
vector<int> topo;
bool used[100010];
int parent[100010];

void init() {

}

void dfs(int i) {
  if (used[i]) return;
  used[i] = true;
  REP(j, SZ(e[i])) dfs(e[i][j]);
  topo.push_back(i);
}

void makeTopo() {
  topo.clear();
  REP(i, n) dfs(i);
  reverse(ALL(topo));
}

void input() {
  REP(i, 100010) {
    e[i].clear();
    parent[i] = -1;
  }
  cin >> n >> m;
  REP(i, n+m-1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
  }
  makeTopo();
  REP(i, n) {;
    REP(j, SZ(e[topo[i]])) {
      parent[e[topo[i]][j]] = topo[i];
    }
  }
  REP(i, n) cout << parent[i] + 1 << endl;
}

void solve() {

}

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


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long

int main() {
  int a , b , c , d ;
  cin >> a >> b >> c >> d ;
  
  cout << max(a*b,c*d);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 200005;
int n, a[mx], b[mx];
vector<int> ans;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", a+i+1);
	for(int i = n; i > 0; i--){
		int t = 0;
		for(int j = i*2; j <= n; j += i) t ^= b[j];
		if(t ^ a[i]){
			ans.push_back(i);
			b[i] = 1;
		}
	}
	printf("%d\n", ans.size());
	for(int it: ans) printf("%d\n", it);
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int factorial(int n) {
    int f = 1;
    REP(i, 1, n + 1)
    f *= i;
    return f;
}

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N), A(N);
    REP(i, 0, N) cin >> P[i];
    REP(i, 0, N) cin >> Q[i];
    REP(i, 0, N) A[i] = i + 1;

    int f = factorial(N), a, b;
    REP(i, 0, f) {
        bool isA = true, isB = true;
        REP(i, 0, N) {
            if (A[i] != P[i]) isA = false;
            if (A[i] != Q[i]) isB = false;
        }
        if (isA) a = i + 1;
        if (isB) b = i + 1;

        next_permutation(ALL(A));
    }
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            out.println((in.nextInt() * 3 + in.nextInt()) / 2);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 21460
#include <stdio.h>
#include <string.h>

int main (int argc, char* argv[]) {
  char a[10], b[10], c[10];
  scanf("%s %s %s", a, b, c);

  if (a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0]) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    string s; cin>>s;
    if(n%2==1)cout<<"No"<<endl;
    else{
        bool iftrue=true;
        rep(i,n/2){
            if(s[i]!=s[i+n/2])iftrue=false;
        }
        if(iftrue)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

int main(void){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    rep(i,h){
        rep(j,w){
            char x;
            cin >> x;
            a[i][j] = x;
        }
    }
    bool flag = 1;
    rep(i,h){
        flag = 1;
        rep(j,w){
            if(a[i][j]=='#'){
                flag = 0;
                break;
            }
        }
        if(flag ==1){
            rep(j,w){
                a[i][j] = '0';
            }
        }
    }
  
    rep(j,w){
        flag = 1;
        rep(i,h){
            if(a[i][j]=='#'){
                flag = 0;
                break;
            }
        }
        if(flag == 1){
            rep(i,h){
                a[i][j] = '0';
            }
        }
    }
  	
  	
    rep(i,h){
      int sum = 0;
        rep(j,w){
            if(a[i][j] != '0'){
                cout << a[i][j];
            }
          	else{
              sum++;
            }
        }
      if(sum!=w){
        cout << endl;
      }
    }
    
    
    
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
	int n,x[100],y[100],i,t;
	double d1=0,d2=0,d3=0,di=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&y[i]);
	}
	for(i=0;i<n;i++){
		t=x[i]-y[i];
		if(t<0)
			t=-t;
		d1+=t;
		d2+=t*t;
		d3+=t*t*t;
		if(di<t) di=t;
	}
	d2=pow(d2,1./2);
	d3=pow(d3,1./3);
	printf("%.6f\n%.6f\n%.6f\n%.6f\n",d1,d2,d3,di);
	return 0;
}

Measured memory_bytes: 684
#include <stdio.h>

int main(void) {
	int n = 0;
	int k = 0;

	int p[1005] = { 0 };

	scanf("%d", &n);
	scanf("%d", &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	int min = 10000;
	int result = 0;
	int num = 0;
	for (int i = 0; i < k; i++) {
		min = 10000;
		for (int j = 0; j < n; j++)
		{
			if (p[j] < min && p[j]>0) {
				min = p[j];
				num = j;
			}
		}
		p[num] = 0;
		result += min;
	}
	
	printf("%d", result);

	return 0;
}

Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }


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

  ll n;
  cin >> n;

  ll ans = INF;
  for(ll i = 1; i*i <= n; i++){
    //cout << i << endl;
    if(n % i == 0){
      ll a = i;
      ll b = n / i;
      chmin(ans, a-1 + b-1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N,X=gets.split.map(&:to_i)
def getn(dim)
  if dim==0 then return 1
  else return 2**(dim+2)-3 end
end
def getallp(dim)
  if dim==0 then return 1
  else return 2**(dim+1)-1 end
end
def getp(dim,num)
  if dim==0 then return 1 end
  if num<dim then return 0 end
  if num==getn(dim-1)+1 then return getallp(dim-1)+1 end
  if getn(dim-1)+1>num then
    return getp(dim-1,num-1)
  else
    return getallp(dim-1)+1+getp(dim-1,num-getn(dim-1)-2)
  end
end
p getp(N,X-1)

Measured memory_bytes: 1788
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		arr[u-1] = make([]int, n)
		for j := 0; j < k; j++ {
			n := scanInt()
			arr[u-1][n-1] = 1
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for _, col := range arr {
		fmt.Fprintln(w, strings.Trim(fmt.Sprint(col), "[]"))
	}
	w.Flush()
}



Measured memory_bytes: 1364
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7

ans = 0
for i in range(64):
    tmp = (A >> i) & 1
    #print(tmp)
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)


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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>

void solve(){
	int n, m;
	cin >> n >> m;
	pii key[m];
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		key[i] = {a, 0};
		for (int j = 0; j < b; ++j) {
			int x;
			cin >> x;
			key[i].s |= (1 << x - 1);
		}
	}
	int dp[(1 << n)];
	dp[0] = 0;
	for (int mask = 1; mask < (1 << n); ++mask) {
		dp[mask] = 1e9;
		for (int j = 0; j < m; ++j) {
			// cout << ' ' << mask << ' ' << key[j].s << ' ' << dp[mask ^ (mask & key[j].s)] << endl;
			dp[mask] = min(dp[mask], key[j].f + dp[mask ^ (mask & key[j].s)]);
		}
		// cout << dp[mask] << endl;
	}
	if (dp[(1 << n) - 1] >= 1e9) {
		cout << -1 << endl;
		exit(0);
	}
	cout << dp[(1 << n) - 1] << endl;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
import scala.math.abs

object Main extends App {
  val Array(n, x, y) = io.StdIn.readLine().split(' ').map(_.toInt)

  val count = Array.fill(n)(0)
  for (i <- 1 until n; j <- i+1 to n) {
    val len = Seq(abs(i-j), abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)).min
    count(len) += 1
  }
  for (a <- count.drop(1)) println(a)
}

Measured memory_bytes: 114308
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");

	var count = 0;
	var oldOne = input[0].substring(0,1);
	for(var i = 1;i<input[0].length;i++){
		if(oldOne != input[0].substring(i,i+1)){
			count++;
			oldOne = input[0].substring(i,i+1);
		}
	}
	
	console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7928
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/


signed main(){
	int n;
	cin>>n;
	vi a(n);
	rep(i,n)cin>>a[i];

	int ans=0;
	rep(i,n){
		if(i%2==0&&a[i]%2==1) ans++;
	}

	cout<<ans<<endl;


  return 0;
}


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

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main(){
    int A,B;
    cin>>A>>B;
    if((A+B)%2==1){
        cout << "IMPOSSIBLE";
    }else{
        cout<<(A+B)/2;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		String ans = "No";

		try {
			Integer.parseInt(s.substring(0, a));

			Integer.parseInt(s.substring(a + 1));
			if (s.length() == a + b + 1) {
				if (s.charAt(a) == '-') {
					ans = "Yes";
				}
			}
		} catch (NumberFormatException e) {
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 22736
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;

vector<char> copp(vector<char> b){
	vector<char> a(10);
	rep(i,0,10){
		a[i] = b[i];
	}
	return a;
}

bool compare(vector<char> a,vector<char> b){
	rep(i,0,10){
		if(a[i] != b[i]) return false;
	}
	return true;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<char>> s(n,vector<char>(10));
	rep(i,0,n){
		rep(j,0,10) cin >> s[i][j];
		sort(all(s[i]));
	}
	sort(all(s));
	vector<char> tmp(10);
	tmp = copp(s[0]);
	
	vector<int> comp;
	ll ans=0;
	bool cont = false;
	rep(i,1,n){
		bool br = compare(tmp,s[i]);
		if(br && (!cont)){
			comp.push_back(2);
			cont = true;
		}else if(br && cont){
			*(comp.end()-1) += 1;
		}else{
			tmp = copp(s[i]);
			cont = false;
		}
	}
	for(auto itr=comp.begin();itr!=comp.end();++itr){
		ans += (ll)((*itr)) * (ll)((*itr-1)) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5888
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>

using namespace std;

char s[111111];
int len;
int v[111111];

void solve(char ch) {
  int c = 0;
  // printf("%c\n", ch);
  for (int i = 0; i < len; i++) {
    if (s[i] == ch) {
      c += 1;
    } else {
      c -= 1;
    }
    v[i] = c;
  }
  for (int i = 0; i < len; i++) {
    // printf("%3d ", v[i]);
  }
  // puts("");
  multiset<int> t;
  t.insert(v[len-1]);
  for (int i = len-2; i >= 0; i--) {
    // printf("i:%d\n", i);
    auto it = t.upper_bound(i>0 ? v[i-1] : 0);
    if (it != t.end()) {
      for (int j = i+1; j < len; j++) {
        if (v[j] > v[i-1]) {
          printf("%d %d\n", i+1, j+1);
          exit(0);
        }
      }
      // exit(1);
    }
    t.insert(v[i]);
  }
}

int main(void) {
  scanf("%s", s);
  len = strlen(s);
  for (int i = 'a'; i <= 'z'; i++) {
    solve(i);
  }
  puts("-1 -1");
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int a[60], b[60], c[60], d[60];
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < M; i++) cin >> c[i] >> d[i];

  for (int i = 0; i < N; i++) {
    int mini = 1000000000, p = -1;
    for (int j = 0; j < M; j++) {
      int m = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (m < mini) {
        p = j + 1;
        mini = m;
      }
    }
    cout << p << endl;
  }
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

k,s = nm()
res = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            res += 1

print(res)

Measured memory_bytes: 3064
while(n,m=l=gets.split.map(&:to_i))[0]>c=0
a=(1..m).map{gets.tr ?\n,?.}<<?.*n*2
q=[l]
r=[]
(x,y=q.shift
[[x,y+1],[x,y-1],[x+1,y],[x-1,y]].map{|i,j|i%=n+1;j%=m+1
d=a[j][i]
k=".#".index d
k&&(a[j][i]=?a;[q,r][k-c%2]<<[i,j])
d==?&&&(q=r=[];break)})while q[0]||(q,r=r.uniq,[];c+=1;q)[0]
p c/2
end

Measured memory_bytes: 6184
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>

using namespace std;

using ull_t = unsigned long long;

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

    string s(n, 'a');
    cout << s << endl;

    function<bool(int i , int j)> proc;
    proc = [&](int i, int j)
    {
        ++s[j];
        char c = 'a';
        for (int k = 1; k < j; ++k)
            c = max(c, s[k]);
        
        if (s[j] > c + 1)
        {
            s[j] = 'a';
            if (i == j)
                return false;
            return proc(i, j - 1);
        }
        else
            return true;
    };

    for (int i = n - 1; i > 0; --i)
    {
        ++s[i];
        if (i < n - 1)
            s[i + 1] = 'a';
        cout << s << endl;
        
        if (i < n - 1)
            while (proc(i, n - 1))
                cout << s << endl;
    }
    cerr << "end." << endl;
}


Measured memory_bytes: 1536
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        int cnt = 0;
        int u = 0;
        for (int i = n.length() - 1; i >= 0; i--) {
            int m = n.charAt(i) - '0';
            if (m + u <= 4) {
                cnt += m + u;
                u = 0;
            }
            else if (m + u == 5) {
                cnt += 5;
                u = 0;
                if (i > 0) {
                    int mm = n.charAt(i - 1) - '0';
                    if (mm >= 5) u = 1;
                }
            }
            else if (m + u <= 9) {
                cnt += 10 - (m + u);
                u = 1;
            }
        }
        if (u == 1) cnt++;
        System.out.println(cnt);
    }
}

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


int main() {
  int K, A, B;
  cin >> K >> A >> B;
  bool ok = false;
  rep(i, 1000){
      if(K*(i+1) >= A &&  K*(i+1) <= B) ok = true;
  } 
  if(ok) cout << "OK" << endl;
  else cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define P pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N=605;
int n,d1,d2;
int c[N][N],su[9];
bool vi[N][N];
vector<P>b[3];
void get(int x,vector<P>&b){
	fo(i,0,n*2){
		int a=x-i*i;
		if(x<0)break;
		int c=sqrt(a);
		if(c*c==a){
			b.pb(P(i,c));
			b.pb(P(i,-c));
			b.pb(P(-i,c));
			b.pb(P(-i,-c));
		}
	}
}
void go(int x,int y,int o,int o2){
	vi[x][y]=1;
	c[x][y]|=o2;
	for(P i:b[o]){
		int xx=x+i.fi,yy=y+i.se;
		if(xx>=0&&yy>=0&&xx<n*2&&yy<n*2&&!vi[xx][yy])
			go(xx,yy,o,o-o2);
	}
}
int main(){
	cin>>n>>d1>>d2;
	get(d1,b[1]);
	get(d2,b[2]);
	fo(i,1,2){
		memset(vi,0,sizeof vi);
		fo(j,0,n*2-1)
			fo(k,0,n*2-1)
				if(!vi[j][k])go(j,k,i,0);
	}
	fo(j,0,n*2-1)
		fo(k,0,n*2-1)
			su[c[j][k]]++;
	int mx=0,cnt=0;
	fo(i,1,3)if(su[i]>su[mx])mx=i;
	fo(j,0,n*2-1)
		fo(k,0,n*2-1)
			if(c[j][k]==mx){
				printf("%d %d\n",j,k);
				if(++cnt==n*n)return 0;
			}
}

Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        double[] std = new double[100];
        int cnt=0;
        double sum=0;
        double mean;
        while(true){
            int n;
            n = sc.nextInt();
            if(n == 0)
                break;
            sum=0;
            mean=0;
            double[] s = new double[n];
            for(int i=0; i<n; i++){
                s[i] = sc.nextInt();
                sum += s[i];
            }
            mean = sum/n;
            sum = 0;
            for(int i=0; i<n; i++){
                sum += Math.pow((s[i] - mean), 2); 
            }
            mean = sum/n;
            std[cnt] = Math.sqrt(mean);
            cnt++;
        }

        for(int i=0; i<cnt; i++){
            System.out.printf("%.8f\n", std[i]);
        }

        sc.close();
    }
}


Measured memory_bytes: 33960
package main

import (
	"fmt"
)

func main() {
	var r, d, x0 int
	fmt.Scan(&r, &d, &x0)
	//
	x := x0
	for i := 0; i < 10; i++ {
		x = r*x - d
		fmt.Println(x)
	}
}


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

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int l=max(s1.size(),s2.size());
    int c=0;
    for(int i=0; i<l ;i++)
    {
        if(s1[i]!=s2[i]){
            c++;
        }
    }

    cout<<c<<endl;
}


Measured memory_bytes: 3832
#include<stdio.h>
#include<math.h>
int main()
{
    double a,b,c,sinc,A,cosc;
    scanf("%lf%lf%lf",&a,&b,&c);
    sinc=sin(c*3.1415926535897932384626433832795028841971/180);
    A=(0.5*a*b*sinc);
    cosc=cos(c*3.1415926535897932384626433832795028841971/180);
    double lenc=sqrt(a*a+b*b-2*a*b*cosc);
    printf("%lf\n%lf\n%lf\n",A,a+b+lenc,2*A/a);
}



Measured memory_bytes: 3124
#include <iostream>
#include <map>
#include <vector>

using namespace std;

template <class T>
T gcm(T a, T b) {
    if (a < b) {
        T w = a;
        a = b;
        b = w;
    }

    while (b != 0) {
        T w = a % b;
        a = b;
        b = w;
    }

    return a;
}

template <class T>
T lcm(T a, T b) {
    return a / gcm(a, b) * b;
}

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

    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    map<int, int> pat;
    for (int i = 0; i < n; i++) {
        int p = 0;
        for (int j = a[i] / 2; j % 2 == 0; j /= 2) {
            p++;
        }
        pat[p]++;
    }

    if (pat.size() == 1) {
        long long a_lcm = a[0] / 2;
        for (int i = 1; i < n; i++) {
            a_lcm = lcm(a_lcm, a[i] / 2);
        }

        cout << (m / a_lcm) / 2 + (m / a_lcm) % 2 << endl;
    } else {
        cout << "0" << endl;
    }
}


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

int main() {
	int a, b, c, after=INT_MIN, ans = INT_MAX, tmp;
	int mid[3];
	cin >> a >> b >> c;
	mid[0] = a; mid[1] = b; mid[2] = c;
	sort(&mid[0], &mid[3]);
	for (int i = 0; 1; i++) {
		after = min({ a,b,c }) + 2 * i;
		if (after > mid[1])break;
		if (a < after)tmp = (after - a) / 2; else tmp = a - after;
		if (b < after)tmp += (after - b) / 2; else tmp += b - after;
		if (c < after)tmp += (after - c) / 2; else tmp += c - after;
		ans = min(ans, tmp);
	}
	cout << ans << "\n";
}

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

int main()
{
    int n,i,a;
    cin>>a;
    if(a<10)
    {
        printf("%d\n",a%10); return 0;
    }
    if(a<100)
    {
        n=9;printf("%d\n",n);return 0;
    }
    if(a/100<10)
    {
        i=((a/100)-1)*100;n=i+(a%100)+10;printf("%d\n",n);return 0;
    }
    if(a/1000<10)
    {
        n=909;printf("%d\n",n);return 0;
    }
    if(a/10000<10)
    {
        i=((a/10000)-1)*10000;n=i+910+(a%10000);printf("%d\n",n);return 0;
    }
    if(a/100000<10)
    {
        n=90909;printf("%d\n",n);return 0;
    }
    if(a/1000000<10)
    {
        i=((a/1000000)-1)*1000000;n=i+90910+(a%1000000);printf("%d\n",n);return 0;
    }
    if(a/10000000<10)
    {
        n=9090909;printf("%d\n",n);return 0;
    }
    if(a/100000000<10)
    {
        i=((a/100000000)-1)*100000000;n=i+9090910+(a%100000000);printf("%d\n",n);return 0;
    }
    if(a/1000000000<10)
    {
        n=909090909;printf("%d\n",n);return 0;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int T;
ll A, B, C, D;

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;	
}

ll gcd(ll a, ll b){return b?gcd(b, a%b):a;}
 
int main()
{
//	freopen("1.out", "w", stdout);
	read(T);
	while(T--)
	{
		read(A); read(B); read(C); read(D);
		ll cnt=(A-C)/B;
		ll rest=A-B*(cnt+1);
		if(A<B || B>D)
		{
			puts("No");
			continue;
		}
		if(rest+D<B)
		{
			puts("No");
			continue;
		}
		ll d=gcd(B, D);
		ll qaq=rest+D;
		ll qwq=C+1+(qaq-C-1)%d;
//		printf("%lld %lld\n", rest+D, qwq);
		if(qwq<B) puts("No");
		else puts("Yes");
	}
}

Measured memory_bytes: 256
ENV[A='RUBY_THREAD_VM_STACK_SIZE']||exec({A=>?5*8},'ruby',$0);F=->c{H[c].all?{|e|Z[e]?Z[c]^Z[e]>0:(Z[e]=1^Z[c];F[e])}};N,M=gets.split.map &:to_i;H=Hash.new{|h,k|h[k]=[]};Z={1=>0};$<.map{|e|a,b=e.split.map &:to_i;H[a]<<b;H[b]<<a};p (F[1]?(x,y=Z.partition{|k,v|v>0};x.size*y.size):N*~-N/2)-M

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

const int INF=1<<30;

int n,m;

int dp[5000];
int a[100000];
int b[1000];
int c[1000];

void solve(){
    cin>>n>>m;
    for(int i=1; i<5000; i++){
        dp[i]=INF;
    }
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i];
        int in;
        for(int j=0; j<b[i]; j++){
            cin>>in;
            c[i]+=1<<(in-1);    
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<(1<<n); j++){
            dp[j | c[i]]=min(dp[j | c[i]], dp[j]+a[i]);
        }
    }
    if(dp[(1<<n)-1]==INF){
        cout<<-1<<endl;
    }else{
        cout<<dp[(1<<n)-1]<<endl;
    }

    /*for(int i=0; i<5000; i++){
        if(dp[i]!=INF){
            cout<<i<<endl;
        }
    }*/
}

int main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
/* ----------------------- reclone_rk -------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}


signed main()
{
	int a, b, c, k;
	cin>>a>>b>>c>>k;
	int sum = 0;
	while(k>0)
	{
		for(int i=0; i<a; i++)
		{
			if(k>0)
			{
				sum += 1;
				k--;
			}
			else
				break;
		}
		for(int i=0; i<b; i++)
		{
			if(k>0)
			{
				k--;
			}
			else
				break;
		}
		for(int i=0; i<c; i++)
		{
			if(k>0)
			{
				sum = sum - 1;
				k--;
			}
			else
				break;
		}
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 3584
#include<stdio.h>

int main(void)
{
	int h[10];
	int i,j,s;

	for(i=0;i<10;i++){
		scanf("%d",&h[i]);
	}
	
	for(j=0;j<10;j++){
		for(i=j+1;i<10;i++){
		
			if(h[i]<h[j]){
				s=h[i];
				h[i]=h[j];
				h[j]=s;
			}

		}
	}
	printf("%d\n%d\n%d\n",h[9],h[8],h[7]);
	
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define int long long int
 #define hi ios_base :: sync_with_stdio(false); cin.tie(0);cout.tie(0);
int i,j,k,mo;

main()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   int ar[4];
   ar[0]=a*c;
   ar[1]=b*c;
   ar[2]=a*d;
   ar[3]=b*d;
   sort(ar,ar+4);
   cout<<ar[3]<<endl;

}


Measured memory_bytes: 3620