akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace  std;
typedef long long ll;
const ll Mod=1e9+7;
const ll Maxn=1e6+10;
ll fact[Maxn+10],in_fact[Maxn+10];
ll sum[Maxn+10];
ll qp(ll a,ll b){
    ll sum=1;
    while(b){
        if(b&1) sum=(sum*a)%Mod;
        a=(a*a)%Mod;
        b>>=1;
    }
    return sum;
}
ll C(ll nn,ll mm){
    return fact[nn]*in_fact[mm]%Mod*in_fact[nn-mm]%Mod;
}
int main() {
    fact[0]=in_fact[0]=1;
    for(int i=1;i<=Maxn;i++){
        fact[i]=fact[i-1]*i%Mod;
        in_fact[i]=in_fact[i-1]*qp(i,Mod-2)%Mod;
    }
    ll n;
    cin>>n;
    sum[1]=qp(9,n-1)-qp(8,n-1);
    for(ll i=2;i<n;i++){
        sum[i]=(qp(9,n-i)-qp(8,n-i)+Mod)%Mod;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans=(ans+(C(n,i)*sum[i])%Mod+Mod)%Mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 27020
class Dice:
  def __init__(self, list1):
    self.f = list1
  def spin1(self):#(真上から見て反時計回り)
    self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4]
    self.f[0], self.f[2], self.f[3], self.f[5] = self.f[3], self.f[0], self.f[5], self.f[2]
    self.f[0], self.f[1], self.f[4], self.f[5] = self.f[4], self.f[0], self.f[5], self.f[1]
    return self.f
  def spin2(self):#(方角Eから見て時計回り)
    self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4]
    return self.f
  def spin3(self):#(方角Sから見て半時計回り)
    self.f[0], self.f[2], self.f[3], self.f[5] = self.f[2], self.f[5], self.f[0], self.f[3]
    return self.f

data = list(map(int, input().split()))
data_1 = list(map(int, input().split()))
data_2 = []
data_3 = []
data_4 = []
dice_1 = Dice(data)
for i in range(0, 4):
    a = dice_1.spin2()
    b = a[:]
    data_2.append(b)

for j in data_2:
    dice_2 = Dice(j)
    for k in range(0, 4):
        c = dice_2.spin1()
        d = c[:]
        data_3.append(d)
data_5 = data_2 + data_3

for l in data_5:
    dice_3 = Dice(l)
    for m in range(0, 4):
        e = dice_3.spin3()
        f = e[:]
        data_4.append(f)

if data_1 in data_4:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5616
import sys
from fractions import gcd


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = A[0]
    B = set()
    for i in range(1, N):
        g = gcd(A[i], a)
        if g == 1:
            B.add(1)
        elif g == a:
            continue
        else:
            B.add(g)
    if len(B) == 0:
        print(a)
    else:
        print(min(B))


if __name__ == "__main__":
    main()


Measured memory_bytes: 16240
#include <iostream>
#include <queue>
#include <tuple>
#include <set>

int main() {
    int N, Q;
    std::cin >> N >> Q;

    std::priority_queue<
        std::tuple<int, int, int>,
        std::vector<std::tuple<int, int, int>>,
        std::greater<std::tuple<int, int, int>>
    > que;
    for (int i = 0; i < N; i++) {
        int S, T, X;
        std::cin >> S >> T >> X;
        que.push(std::make_tuple(S - X, 1, X));
        que.push(std::make_tuple(T - X, 0, X));
    }

    std::set<int> s;
    for (int i = 0; i < Q; i++) {
        int D;
        std::cin >> D;

        while (!que.empty()) {
            if (D < std::get<0>(que.top()))
                break;

            if (std::get<1>(que.top()) == 1)
                s.insert(std::get<2>(que.top()));
            else
                s.erase(std::get<2>(que.top()));

            que.pop();
        }

        if (s.empty())
            std::cout << "-1\n";
        else
            std::cout << *s.begin() << "\n";
    }
}

Measured memory_bytes: 15340
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

int main(){
	int n,d,x; cin>>n>>d>>x;
	vvi v(d,vi(n));
	for(auto&l:v)for(auto&i:l)cin>>i;
	rep(k,d-1){
		vi dp(x+1);
		iota(all(dp),0);
		rep(i,n)rep(j,x+1){
			if(j>=v[k][i]) dp[j]=max(dp[j], dp[j-v[k][i]]+v[k+1][i]);
		}
		x=max(0,*max_element(all(dp)));
	}
	cout<<x<<endl;
	return 0;
}



Measured memory_bytes: 3196
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if (N == 1) {
      System.out.println("Hello World");
    } else {
      int A = sc.nextInt();
      int B = sc.nextInt();
      System.out.println(A+B);
    }
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  unsigned int n,i,j,a,b,s,d[10];
  scanf("%d",&n);
  while(n--){
    for(i=0;i<9;i++)scanf("%x",&d[i]);//,printf("%d ",d[i]);printf("\n");
    for(i=a=b=0;i<32;i++){
      for(j=s=0;j<8;j++){
	s+=d[j]%2;
	d[j]/=2;
      }
      if((s+b)%2-d[8]%2){
	a+=1<<i;
	b+=8-s;
      }
      else  b+=s;
      b/=2;
      d[8]/=2;
    }
    printf("%x\n",a);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int a,b,i,j;
  char ans[110][110];
  cin >> a >> b;
  for (i=0;i<50;i++) for (j=0;j<100;j++) ans[i][j]='#';
  for (i=50;i<100;i++) for (j=0;j<100;j++) ans[i][j]='.';
  for (i=0;i<50 && a>1;i+=2) for (j=0;j<100 && a>1;j+=2){
    ans[i][j]='.';
    a--;
  }
  for (i=51;i<100 && b>1;i+=2) for (j=0;j<100 && b>1;j+=2){
    ans[i][j]='#';
    b--;
  }
  for (i=0;i<100;i++) ans[i][100]='\0';
  cout << "100 100" << endl;
  for (i=0;i<100;i++) cout << ans[i] << endl;
  return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  string s(b, '0'+a);
  string t(a, '0'+b);
  if(a >= b) cout << t << endl;
  else cout << s << endl;
  return 0;
}


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

signed main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a + b + c == 2 * max(a, max(b, c))){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    int sum = 0;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        sum += x;
    }

    cout << (n >= sum ? n - sum : -1) << "\n";
}


Measured memory_bytes: 3636
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int cash = sc.nextInt();
        int fiveHundredCoin = 0;
        int fiveCoin = 0;
        int Happiness = 0;

        fiveHundredCoin = cash / 500;

        fiveCoin = (cash - fiveHundredCoin * 500)/5;

        Happiness = fiveHundredCoin * 1000 + fiveCoin * 5;

        System.out.println(Happiness);


    }
}

Measured memory_bytes: 24020
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define ll long long

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n), y(n), a(n);
  int rect[w][h]={0};
  for(int i=0; i<n; ++i) {
    cin >> x[i] >> y[i] >> a[i];
  }
  for(int i=0; i<n; ++i) {
    if(a[i]==1) {
      for(int j=0; j<x[i]; ++j) {
        for(int k=0; k<h; ++k) {
          rect[j][k]=1;
        }
      }
    } else if(a[i]==2) {
      for(int j=x[i]; j<w; ++j) {
        for(int k=0; k<h; ++k) {
          rect[j][k]=1;
        }
      }
    } else if(a[i]==3) {
      for(int j=0; j<w; ++j) {
        for(int k=0; k<y[i]; ++k) {
          rect[j][k]=1;
        }
      }
    } else {
      for(int j=0; j<w; ++j) {
        for(int k=y[i]; k<h; ++k) {
          rect[j][k]=1;
        }
      }
    }
  }
  int ans=0;
  for(int i=0; i<w; ++i) {
    for(int j=0; j<h; ++j) {
      if(rect[i][j]==0) {
        ++ans;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

class solution{
public:
    bool taketime(int D, int T, int S){
        float timetaken = (float)D/S;
        if(timetaken <= T) return true;
        else return false;
    }
};

int main(){
    solution solve = solution();
    int D,T,S;
    cin>>D>>T>>S;
    if(solve.taketime(D,T,S)) cout<<"Yes\n";
    else cout<<"No\n";
}

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx;
  int dy = ty - sy;

  // 1回目 行き
  cout << string(dy, 'U');
  cout << string(dx, 'R');

  // 1回目 帰り
  cout << string(dy, 'D');
  cout << string(dx, 'L');

  // 2回目 行き 左から抜けて上から到達する
  cout << "L";
  cout << string(dy + 1, 'U');
  cout << string(dx + 1, 'R');
  cout << "D";

  // 2回目 帰り 右から抜けて下から到達する
  cout << "R";
  cout << string(dy + 1, 'D');
  cout << string(dx + 1, 'L');
  cout << "U" << endl;
}

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

using namespace std;

bool possib(vector<int> &vs, int chars) {
    map<int, int> seen;
    int last = vs[0];
    for (size_t i = 1; i < vs.size(); ++i) {
        if (vs[i] <= last) {
            if (chars == 1) return false;
            int modify = vs[i];
            seen[modify] += 1;
            if (seen[modify] >= chars) {
                while (modify > 0 && seen[modify] >= chars) {
                    seen[modify] = 0;
                    modify -= 1;
                    seen[modify] += 1;
                }
                if (modify == 0) return false;
            }
            last = vs[i];
        } else {
            auto it = seen.upper_bound(last);
            seen.erase(it, seen.end());
            last = vs[i];
        }
    }
    return true;
}

int main() {
    int n; cin >> n;
    vector<int> vs(n);
    for (int i = 0; i < n; ++i) cin >> vs[i];
    int lo = 1;
    int high = n;

    while (lo < high) {
        int mid = (lo + high) / 2;
        /* cout << lo << " " << mid << " " << high << endl; */
        if (possib(vs, mid)) {
            high = mid;
        } else {
            lo = mid + 1;
        }
    }

    cout << lo << endl;
    return 0;
}



Measured memory_bytes: 9856
while True:
    m, f, r = map(int, input().split())
    s = m + f
    if s + r == -3:
        break
    
    if s < 30 or m == -1 or f == -1:
        print('F')
    elif 80 <= s:
        print('A')
    elif 65 <= s:
        print('B')
    elif 50 <= s or (s <= 30 and 50 <= r):
        print('C')
    else:
        print('D')


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    vector<set<int>> tree(n);
    int ans = 0;
    if(a[0] != 0) ans++;
    for(int i = 1; i < n; i++)
    {
        tree[a[i]].insert(i);
    }
    function<int(int)> dfs = [&](int v)
    {
        int num = 0;
        for(int nx : tree[v])
        {
            num = max(num, dfs(nx));
        }
        if(v != 0 && tree[0].find(v) == tree[0].end() && num == k-1)
        {
            ans++;
            return 0;
        }
        return num + 1;
    };
    dfs(0);
    cout << ans << endl;
}


Measured memory_bytes: 20788
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    cin >> n;
    P(lcm(2,n));
    return  0;
}


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

int bublleSort(int*,int);

int main()
{
  int N;
  int i;
  int arr[100];
  int kai;
  
  scanf("%d",&N);
  if(N < 1 || N > 100) exit(1);
  for(i = 0; i < N; i++)
    {
      scanf("%d",&arr[i]);
      if(arr[i] < 0 || arr[i] > 100) exit(1);
    }
  kai = bublleSort(arr,N);

  for(i = 0; i < N; i++)
    {
      if(i) printf(" ");
      printf("%d",arr[i]);  
    }
  printf("\n");
  printf("%d\n",kai);
  
  return 0;
}

int bublleSort(int* A,int N)
{
  int flag = 1;
  int j;
  int count=0;
  int temp;
  
  while(flag)
    {
      flag = 0;
      for(j = N - 1; j >= 1; j--)
	{
	  if(A[j] < A[j-1])
	    {
	      temp = A[j];
	      A[j] = A[j-1];
	      A[j - 1] = temp;
	      count++;
	      flag = 1;
	    }
	}
    }
  
  return count;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
vector<int> B;
bool f(int m) {
	vector<pair<int,int>> a(B.size()+1);
	int na = 1;
	a[0] = {1,1};
	for (auto x : B) {
			while (na > 1 && a[na-1].first > x) -- na;
			//for (int j = 0; j < na; ++ j) cerr << a[j].first << " " << a[j].second << " "; cerr << endl;
			if (a[na-1].first == x && a[na-1].second == m) {
				bool ok = false;
				for (int i = x; i >= 1; -- i) {
					if (a[na-1].first == i) {
						if (a[na-1].second == m) {
							if (na == 1) break;
							-- na;
						} else {
							++a[na-1].second;
							ok = true;
							break;
						}
					} else {
						a[na++] = {i, 2};
						ok = true;
						break;
					}
				}
				if (!ok) return false;
			} else if (a[na-1].first == x) {
				++a[na-1].second;
			} else {
				a[na++] = {x, 2};
			}
			//for (int j = 0; j < na; ++ j) cerr << a[j].first << " " << a[j].second << " "; cerr << endl;
	}
	return true;
}
int g() {
	int r = 1;
	vector<pair<int,int>> a(B.size()+1);
	int na = 1;
	a[0] = {1,1};
	for (auto x : B) {
			while (na > 1 && a[na-1].first > x) -- na;
			//for (int j = 0; j < na; ++ j) cerr << a[j].first << " " << a[j].second << " "; cerr << endl;
			if (a[na-1].first == x) {
				r = max(r, ++a[na-1].second);
			} else {
				r = max(r, 2);
				a[na++] = {x, 2};
			}
			//for (int j = 0; j < na; ++ j) cerr << a[j].first << " " << a[j].second << " "; cerr << endl;
	}
	return r;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) cin >> x;
	for (int i = 1; i < N; ++ i) {
		if (A[i] <= A[i-1]) B.push_back(A[i]);
	}
	int mi = 1, ma = g();
	while (ma-mi > 1) {
		int m = (ma+mi)/2;
		//cerr << "f" << m << endl;
		if (f(m)) {
			ma = m;
		} else {
			mi = m;
		}
	}
	cout << ma << endl;
}


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

int main(){
    map<int, int> mp;
    int s, i;
    cin >> s;
    
    i = 1;
    while (mp[s] != 1) {
        mp[s] = 1;
        s = (s%2 == 0 ? s/2 : 3*s + 1);
        i++;
    }
    
    cout << i << endl;
    return (0);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	ll n;
	cin >> n;
	string ans = "";
	ll t = n;
	while (t > 0) {
		t -= 1;
		int d = t % 26;
		ans += 'a' + d;
		t /= 26;
	}
	reverse(ALL(ans));
	cout << ans << endl;
}

Measured memory_bytes: 3620
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program
{
    public static long ReadInt()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] ReadInts()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
       
     
        var input = ReadInts();
        var N = input[0];
        var K = input[1];
        var s = Console.ReadLine().ToCharArray();
        s[K - 1] = (char)(s[K - 1] - ('A' - 'a'));
        foreach (char c in s)
            Console.Write(c);
        Console.Out.Flush();
    }
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define print(v) for(auto it=(v).begin();it!=(v).end();it++) {cout<<*it<<" ";}
#define ll long long
#define w(t) ll t;cin>>t;while(t--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    if(t.substr(0,t.length()-1)==s&&s.length()+1==t.length())
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  int m;cin>>m;
  int mod=1e9+7;

  vector<ll>sumx(n+1),x(n);
  rep(i,n){
    cin>>x[i];
  }
  rep(i,n)sumx[n-i-1]=sumx[n-i]+x[n-i-1];
  ll xx=0;
  //rep(i,n)cout<<sumx[i]<<endl;
  rep(i,n){
    xx+=sumx[i]-(n-i)*x[i];
    xx%=mod;
  }
  vector<ll>sumy(m+1),y(m);
  rep(i,m){
    cin>>y[i];
  }
  rep(i,m)sumy[m-i-1]=sumy[m-i]+y[m-i-1];
  ll yy=0;
  rep(i,m){
    yy+=sumy[i]-(m-i)*y[i];
    yy%=mod;
  }
  //cout<<xx<<endl;
//  cout<<yy<<endl;
  cout<<xx*yy%mod<<endl;

}


Measured memory_bytes: 3456
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int32_t main(void){
	scanf("%lld %lld",&n,&m);
	printf("%lld\n",min(n%m,m-(n%m)));
	return 0;
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    if (a * a * b / 2 == x) {
        cout << 45.0 << EOL;
        return;
    }

    if (a * a * b / 2 > x) {
        double y = 2 * x / (a * b);
        cout << 90 - atan2(y, b) * 180 / M_PI  << EOL;
    } else {
        double y = -(2 * x / a / a) + 2 * b;
        cout << 90 - atan2(a, y) * 180 / M_PI  << EOL;
    }

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
# 0: 1:増加 2:減少
state = 0
count = 1
for i in range(1, n):
  if state == 0:
    if a[i-1] < a[i]:
      state = 1
    elif a[i-1] > a[i]:
      state = 2
  elif state == 1:
    if a[i-1] > a[i]:
      state = 0
      count += 1
  else:
    if a[i-1] < a[i]:
      state = 0
      count += 1
print(count)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  vector<int> dishes = {a, b, c, d, e};
  sort(dishes.begin(), dishes.end());
  int ans = 1000;
  do {
    int sum = 0;
    for (int i = 0; i < dishes.size() - 1; i++) {
      sum += ((dishes[i] / 10) + 1) * 10;
      if (dishes[i] % 10 == 0) sum -= 10;
    }
    sum += dishes.back();
    ans = min(ans, sum);
  } while (next_permutation(dishes.begin(), dishes.end()));
  cout << ans << endl;
  return 0;
}


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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003
#define MM 1000000000
#define MN 1000000000000000000
int main()
{
    ios;
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double wh=30,wm=6;
    double dh=wh*(h+m/60);
    double dm=wm*m;
    double theta=abs(dh-dm);
    double radians=theta*M_PI;
    radians/=180;
    double x=a*a+b*b;
    double y=cos(radians);
    y=y*2*a*b;
    x-=y;
    double ans=sqrt(x);
    cout<<setprecision(10)<<ans;
    return 0;
}


Measured memory_bytes: 4244
#include<bits/stdc++.h>
#define N 200005
using namespace std;

int n,tot,fst[N],pnt[N],nxt[N],d[2][N];
void add(int x,int y){
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs(int x,int *d){
	int i,y;
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (d[y]==-1){
			d[y]=d[x]+1; dfs(y,d);
		}
	}
}
int main(){
	scanf("%d",&n);
	int i,x,y;
	for (i=1; i<n; i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	memset(d,-1,sizeof(d));
	d[0][1]=d[1][n]=1;
	dfs(1,d[0]); dfs(n,d[1]);
	int tmp=0;
	for (i=1; i<=n; i++) if (d[0][i]<=d[1][i]) tmp++; else tmp--;
	puts((tmp>0)?"Fennec":"Snuke");
	return 0;
}


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

int main()
{
    string n; cin >> n;
    rep(i,3) {
    if (n[i] == '1') cout << "9";
    else if (n[i] == '9') cout << "1";
    }
    cout << endl;


}


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

int main()
{
    string word;
    cin >> word;

    if((word[0]==word[1] && word[1]==word[2]) && word[2]==word[3])
        cout <<"No" << endl;
    else if((word[0]==word[1]) && (word[2]==word[3]))
        cout<<"Yes" << endl;
    else if((word[0]==word[2]) && (word[1]==word[3]))
        cout <<"Yes" << endl;
    else if((word[0]==word[3]) && (word[1]==word[2]))
        cout <<"Yes" << endl;
    
    else 
        cout <<"No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct deve{
	long long k;
	long long l;
	long long r;
} deva[200005]; bool us1[200005], us2[200005];
long long n, ans, ki, li, ri; 
multiset<pair<long long, int> > prve, zadnje;
bool sort_deve(deve a, deve b){
	if (a.k!=b.k) return a.k<b.k;
	return a.l > b.l;
}
void solve(){
	cin >> n; ans=0;
	zadnje.clear(); prve.clear();
	for (int i=0; i<n; i++){
		cin >> ki >> li >> ri;
		deva[i].k=ki;
		deva[i].l=li;
		deva[i].r=ri;
		us1[i]=0; us2[i]=0;
	}
	sort(deva, deva+n, sort_deve);
	for (int i=0; i<n; i++){
		if (deva[i].l > deva[i].r){
			long long razlika = deva[i].l-deva[i].r;
			prve.insert(make_pair(razlika, i)); 
			ans+=deva[i].l; us1[n-i-1]=1;
			if (prve.size()==deva[i].k+1){
				ans-=deva[(*prve.begin()).second].l;
				us1[n-(*prve.begin()).second-1]=0;
				prve.erase(prve.find(*prve.begin()));
			}
		}
	}
	reverse(deva, deva+n);
//	cout << "DEVA: " << deva[0].k << " " << deva[0].l << " " << deva[0].r << endl;
	for (int i=0; i<n; i++){
		if (deva[i].r > deva[i].l){
			long long razlika = deva[i].r-deva[i].l;
			zadnje.insert(make_pair(razlika, i)); 
			ans+=deva[i].r; us2[i]=1;
			if (zadnje.size()==(n-deva[i].k+1)){
				ans -= deva[(*zadnje.begin()).second].r;
				us2[(*zadnje.begin()).second]=0;
				zadnje.erase(zadnje.find(*zadnje.begin()));
			}
		}
	}
	for (int i=0; i<n; i++) 
		if (!(us1[i] or us2[i])) 
			ans+=min(deva[i].r, deva[i].l);
	cout << ans << endl;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--)
	solve();
return 0;
}


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


class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int S = in.nextInt();
        int s = S%60;S/=60;
        int m = S%60;S/=60;
        int h = S;
        System.out.println(""+h+":"+m+":"+s);
    }
    
}


Measured memory_bytes: 26372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string res = "No";
  for (int i=1; i<10; i++) {
    if ( N / i < 10 && N % i == 0) res = "Yes";
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;


int main() {

	int x, n;

	int ans, temp, check;

	cin >> x >> n;

	vector<int> p(n);
	vector<int> comp(102);

	for (int i = 0; i <= 101; i++) {
		comp[i] = i;
	}

	check = 5000;


	for (int i = 0; i < n; i++) {
		cin >> p[i];
		comp[p[i]] = 500;
	}

	for (int i = 101; i >= 0; i--) {

		if (comp[i] >= x) {
			temp = comp[i] - x;
		}
		if (x >= comp[i]) {
			temp = x - comp[i];
		}
		if (temp <= check) {

			ans = comp[i];
			check = temp;
		}

	}

	cout << ans;
}


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

int main(){
	int n;
	cin >> n;
	map<int,int> mp;
	rep(i,n){
		int a;
		cin >> a;
		if(a <= 399) mp[0]++;
		else if (a <= 799) mp[1]++;
		else if (a <= 1199) mp[2]++;
		else if (a <= 1599) mp[3]++;
		else if (a <= 1999) mp[4]++;
		else if (a <= 2399) mp[5]++;
		else if (a <= 2799) mp[6]++;
		else if (a <= 3199) mp[7]++;
		else mp[8]++;
	}
	int count = 0;
	rep(i,8){
		if(mp[i] != 0) count++;
	}
	int m = count;
	if(count == 0){
		m = 1;
	}
	count += mp[8];
	cout << m << " " << count << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    }

}

Measured memory_bytes: 31028
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

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

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int D;
double E;

bool input(){
  cin>>D>>E;
  return D;
}

void solve(){
  double d=1000000000.0, m;
  REP(i, D/2+1) {
    m = abs(sqrt(i*i*1.0+(D-i)*(D-i)*1.0)-E);
    if(m<d)d=m;
  }
  cout<<d<<endl;
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

Measured memory_bytes: 3132
#include <stdio.h>
#include <math.h>



#ifndef DEBUG 
#define fprintf (void)
#endif 

int main(void){
	
	double a,b,c,d,e,f;
	double x,y,div;
	int xd[5],yd[5];
	int i;
	double megax,megay;
	int recx,recy;
	

	while(scanf("%lf",&a)!=EOF){
		scanf("%lf",&b);
		scanf("%lf",&c);
		scanf("%lf",&d);
		scanf("%lf",&e);
		scanf("%lf",&f);
		
		div=b*d-a*e;
		x=(b*f-c*e)/div;
		y=(c*d-a*f)/div;
		
		megax=x*10000;
		megay=y*10000;
		
		if(x==-0){
			fprintf(stdout,"yabaix\n");
			x=fabs(x);
		}
		
		if(y==-0){
			fprintf(stdout,"yabaiy\n");
			y=fabs(y);
		}
		
		recx=(int) fabs(megax);
		
		for(i=4;i>0;i--){
		xd[i]=recx%10;
		recx/=10;
		}
		
		xd[0]=recx;
	
		if(xd[4]>=5){
			xd[3]++;
		}
		
		if(xd[3]>=10){
			xd[2]++;
			xd[3]=0;
		}
		
		if(xd[2]>=10){
			xd[1]++;
			xd[2]=0;
		}
		
		if(xd[1]>=10){
			xd[0]++;
			xd[1]=0;
		}
		
		recy=(int) fabs(megay);
		
		for(i=4;i>0;i--){
		yd[i]=recy%10;
		recy/=10;
		}
		
		yd[0]=recy;
	
		if(yd[4]>=5){
			yd[3]++;
		}
		
		if(yd[3]>=10){
			yd[2]++;
			yd[3]=0;
		}
		
		if(xd[2]>=10){
			yd[1]++;
			yd[2]=0;
		}
		
		if(yd[1]>=10){
			yd[0]++;
			yd[1]=0;
		}

		if(x<0){
			xd[0]*=-1;
		}
		
		if(y<0){
			yd[0]*=-1;
		}

		
		printf("%d.%d%d%d %d.%d%d%d\n",xd[0],xd[1],xd[2],xd[3],yd[0],yd[1],yd[2],yd[3]);
	}
	
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  string s;
  cin >> s;

  REP(i, s.size()){
    ll now = s[i]-'A';
    char ans ='A' + (now+n)%26;
    cout << ans;
  }

  cout << endl;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    map<int,int> m;
    int n; cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    rep(i,n) m[a[i]]++;

    bool isok = true;
    rep(i,n){
        if(m[a[i]] > 1){
            isok = false;
            break;
        }
    }
    if(isok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 13552
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

vll bls, whs;
vvll to;
void dfs(ll u) {
  ll wh = 1, bl = 1;
  bls[u] = bl;
  for (auto v : to[u]) {
    if (bls[v] != -1) continue;
    dfs(v);
    bl = (bl * whs[v]) % mod;
    wh = (wh * ((bls[v] + whs[v]) % mod)) % mod;
  }
  bls[u] = bl;
  whs[u] = wh;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  bls.resize(n, -1);
  whs.resize(n, -1);
  to.resize(n);
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  cout << (bls[0] + whs[0]) % mod << endl;

  return 0;
}


Measured memory_bytes: 14208
#include<iostream>
using namespace std;
int main(){
	int a[31],n;
	a[1]=1;
	a[0]=1;
	a[2]=2;
	for(int i=3;i<=30;i++){
		a[i]=a[i-1]+a[i-2]+a[i-3];
	}
	while(cin>>n,n){
		if(a[n]%3650==0)
		cout<<a[n]/3650<<endl;
		else
		cout<<a[n]/3650+1<<endl;
	}
	return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL max_k = 1LL;

void solve(long long M, long long K){
    REP(i, M){
        max_k *= 2LL;
    }
    max_k--;

    if(K == 0){
        REP(i, max_k+1) {
            cout << i << " ";
        }
        RREP(i, max_k) cout << i << (i != 0 ? " " : "\n");
    } else if (K <= max_k && 1 < M) {
        cout << "0 " << K << " 0 ";
        for(int i = max_k; i > 0; i--) {
            if(i != K) cout << i << " ";
        }
        cout << K << " ";
        REP1(i, max_k+1) {
            if(i != K) cout << i << (i != max_k ? " " : "\n");
            if(i == max_k && i == K) cout << endl;
        }
    } else {
        cout << -1 << endl;
    }
}

int main(){
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    solve(M, K);
    return 0;
}


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

const int maxn = 1e4 + 5; 

int n;
int a[maxn];

bool find(int key){
	for(int i = 1;i <= n; i++){
		if(a[i] == key)return true;
	}
	return false;
}

int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n; i++){
		scanf("%d",&a[i]);
	}
	int m;
	scanf("%d",&m);
	int ans = 0;
	for(int i = 1;i <= m; i++){
		int k;
		scanf("%d",&k);
		if(find(k))ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    int ans=1;
    while(ans*2<=N) ans*=2;

    cout<<ans<<endl;
}


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


void trace(int A[], int N){
  int i;
  for (i=0; i<N; i++){
    if (i>0)printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int bubbleSort(int A[], int N){
  int sw = 0;
  bool flag = true;
  for (int i=0; flag; i++){
    flag = false;
    for (int j=N-1; j>i; j--){
      if (A[j] < A[j-1]){
        swap(A[j], A[j-1]);
        flag = true;
        sw ++;
      }
    }
  }
  return sw;

}

int main() {
  int N, i, ans;
  int A[100];

  scanf("%d", &N);
  for (i=0; i<N; i++) scanf("%d", &A[i]);

  // trace(A, N);
  ans = bubbleSort(A, N);
  trace(A, N);

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 2740
#include<stdio.h>
#include<string.h>
int main(void){
  char str[4];
  int i,bai,a[4],b[4],tmp,j,n,l,s,cnt=0;
  scanf("%s",str);
  while(1){
    n=0;
    for(i=0,bai=1000;i<4;i++,bai/=10){
      a[i]=str[i]-'0';
      b[i]=a[i];
      n+=a[i]*bai;
    }
    if(n==6174){
      printf("%d\n",cnt);
      return main();
    }
    for(i=0;i<3;i++){
      for(j=3;j>i;j--){
	if(a[j]>a[j-1]){
	  tmp=a[j];
	  a[j]=a[j-1];
	  a[j-1]=tmp;
	}
	if(b[j]<b[j-1]){
	  tmp=b[j];
	  b[j]=b[j-1];
	  b[j-1]=tmp;
	}
      }
    }

    for(l=0,s=0,i=3,bai=1;i>=0;bai*=10,i--){
      l+=a[i]*bai;
      s+=b[i]*bai;
    }
    cnt++;
    n=l-s;
    for(i=0,bai=1000;i<4;i++,bai/=10){
      str[i]=n/bai+'0';
      n%=bai;
    }
    if(l==1111||l==2222||l==3333||l==4444||l==5555||l==6666||l==7777||l==8888||l==9999){
      printf("NA\n");
      return main();
    }
    else if(l==0000)return 0;
  }
  return 0;
}

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

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

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

template<typename T>
void fill_all(T& ar,const T& v){
	ar=v;
}
template<typename T,size_t N,typename U>
void fill_all(T(& ar)[N],const U& v){
	for(auto&i:ar){fill_all(i,v);}
}

int w,h;
int map[10][10];
bool passed[10][10];
int gx,gy;
int count_max;
int func(int x,int y, int count)
{
	if(count>0)
	{
		#ifdef DEBUG
		//std::cout << "IN:"<<x<<' '<<y<<' '<<count<<'\n';
		#endif
		if(x==gx&&y==gy){return 0;}
		if(count==count_max){
			auto DP = [&](){};//{std::cout <<x<<' '<<y<<'\n'; };
			for(int nx = 0;nx<w;++nx){
				if(map[nx][y]==2){DP();return 1;}
			}
			for(int ny = 0;ny<h;++ny){
				if(map[x][ny]==2){DP();return 1;}
			}
			return 0;
		}
		passed[x][y]=true;
	}
	int res = 0;
	for(int nx = x-1;nx>=0;--nx){
		if(!passed[nx][y] && map[nx][y]==1){
			res += func(nx,y,count+1);
			break;
		}
	}
	for(int nx = x+1;nx<w;++nx){
		if(!passed[nx][y] && map[nx][y]==1){
			res += func(nx,y,count+1);
			break;
		}
	}
	for(int ny = y-1;ny>=0;--ny){
		if(!passed[x][ny] && map[x][ny]==1){
			res += func(x,ny,count+1);
			break;
		}
	}
	for(int ny = y+1;ny<h;++ny){
		if(!passed[x][ny] && map[x][ny]==1){
			res += func(x,ny,count+1);
			break;
		}
	}
	passed[x][y]=false;
	return res;
}

int main()
{
	for(;;){
	std::cin >> w>>h;if(w==0&&h==0){break;}
	count_max=0;
	for(int y=0;y<h;++y)for(int x=0;x<w;++x){
		std::cin >> map[x][y];
		if(map[x][y]==1){++count_max;}
		if(map[x][y]==2){gx=x;gy=y;}
	}
	//std::cout << "a:"<<gx<<' '<<gy<<' '<<count_max<<'\n';
	
	int res = 0;
	std::cout << func(gx,gy,0)<<std::endl;
}
}

Measured memory_bytes: 3084
#include<cstdio>

using namespace std;

int main(){
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    int ans = 0;
    x -= z;
    while(x >= y + z){
        x -= y;
        x -= z;
        ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  ll n;
  cin >> n;
  vector<int> v(n);
  cins(n,v);
  sort(all(v));
  cout << v[n/2]-v[n/2-1] << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int d=sc.nextInt();
		int t=sc.nextInt();
		int s=sc.nextInt();
		if((double)d/s<=t) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35684
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int ka[2145140],inv[2145140];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
signed main(){
	int x,y;
	cin>>x>>y;
	setkaijo(2100000);
	setinv(2100000);
	if( (x+y) % 3 != 0 ){
		cout<<0<<endl;
		return 0;
	}
	int ki = x - (x+y)/3;
	int kj = y - (x+y)/3;
	if( ki < 0 || kj < 0 ){
		cout<<0<<endl;
		return 0;
	}
	int ans = comb( ki + kj, ki );
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 33536
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int t[maxn],F,n,ind[maxn],ans[maxn];
vector <int> mp[maxn];

int main()
{
	n=read();
	rep(i,1,(n-1))
	{
		int u=read(),v=read();
		mp[u].pb(v); mp[v].pb(u); ind[u]++; ind[v]++;
	}
	rep(i,1,n)
	{
		for(int j=0;j<mp[i].size();j++)
		{
			int v=mp[i][j];
			t[i]+=(ind[v]==1);
		}
	}
	rep(i,1,n)
	{
		if(t[i]==0&&ind[i]!=1)
		for(int j=0;j<mp[i].size();j++)
		{
			int v=mp[i][j];
			ans[i]+=(t[v]>=1);
		}
		if(ans[i]==mp[i].size()) F=1;
	}
	rep(i,1,n) if(t[i]>=2) F=1;
	if(F||n%2==1) puts("First"); else puts("Second");
	return 0;
}

Measured memory_bytes: 32128