akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = new string[n];
        s = Console.ReadLine().Split(' ');
        int[] a = new int[s.Length];
        for (int i = 0; i < s.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }

        for(int i = 0;i < a.Length; i++)
        {
                if(a[0] > a[i])
                {
                    int tmp = a[0];
                    a[0] = a[i];
                    a[i] = tmp;
                    i = -1;
                }
        }
        int min = a[0];

        for (int i = 0; i < a.Length; i++)
        {
            if (a[0] < a[i])
            {
                int tmp = a[0];
                a[0] = a[i];
                a[i] = tmp;
                i = -1;
            }
        }
        int max = a[0];

        long sum = 0;
        foreach (int x in a)
        {
            sum += x;
        }

        Console.WriteLine("{0} {1} {2}", min, max, sum);
    }
}

Measured memory_bytes: 9972
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main(string[] args) {
        var n = cin.ArrayInt(3);
        Console.WriteLine(n[0] * n[1] / 2);
        Console.ReadLine();
    }
}


Measured memory_bytes: 13140
#include <stdio.h>

int main(int argc, char *argv[]){
	int a, b, c;
	int temp;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}

	if(b > c){
		temp = b;
		b = c;
		c = temp;
	}

	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}

	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <cstdint>
#define REP(i, n) for(ll i = 0; i < n; i++)
using ll = long long;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b;
  cin >> a >> b;
    
  cout << a*b << endl;

}
  


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll N;
  scanf("%lld",&N);
  ll K;
  scanf("%lld",&K);
  ll ans=1;
  for (int i=0; i<N; i++) {
    ans = min(ans*2, ans+K);
  }
  cout << ans << endl;
}

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


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

int main() {
 string s;
 cin >> s;
 int a=(s[0]-'0')*10+(s[1]-'0');
 int b=(s[2]-'0')*10+(s[3]-'0');
  if(a==0 && (b==0 || b>=13)){
  cout << "NA" <<endl;
  }
  else if(b==0 && (a==0 || a>=13)){
  cout << "NA" <<endl;
  }
  else if(a==0)cout << "YYMM" << endl;
  else if(b==0)cout << "MMYY" << endl;

  else if(a>=13 && b<=12){
  cout << "YYMM" << endl;
  }
  else if(b>=13 && a<=12){
  cout << "MMYY" << endl;
  }
  else if(a<=12 && b<=12){
  cout << "AMBIGUOUS" << endl;
  }
  else{
    cout << "NA" <<endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    long  long sum = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i+1; j < n; j++) {
            sum += d[i]*d[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3628
import java.util.*;

class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   long n = sc.nextLong();
   long a = sc.nextLong();
   long b = sc.nextLong();
   long ret = 0;
   long rep = (long)(n/(a+b));
   ret += rep*a;
   long remain = n - (rep*(a+b));
  
   System.out.println(ret+Math.max(0,Math.min(a,remain)));
}
}

Measured memory_bytes: 22612
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let div x y = (x + y - 1L) / y

[<EntryPoint>]
let main _ =
    let n = read int64
    let xs = List.init 5 (fun _ -> read int64)
    div n (List.min xs) + 4L
    |> printfn "%i"
    0

Measured memory_bytes: 14160
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
using namespace std;
int n;ll sum;
inline void solve(){
	vector<pii>v1,v2;
	set<int>s1,s2;
	cin>>n;sum=0;
	for(int i=1,l,r,k;i<=n;++i){
		cin>>k>>l>>r;sum+=r;
		if(l>r)v1.push_back({l-r,k});
		else v2.push_back({l-r,k});
	}
	for(int i=1;i<=v1.size();++i)s1.insert(i);
	for(int i=v1.size()+1;i<=n;++i)s2.insert(i);
	sort(v1.rbegin(),v1.rend());
	sort(v2.begin(),v2.end());
	for(pii p:v1){
		auto it=s1.upper_bound(p.second);
		if(it!=s1.begin()){
			--it;
			s1.erase(it);
			sum+=p.first; 
		}
	}
	for(pii p:v2){
		auto it=s2.upper_bound(p.second);
		if(it==s2.end())sum+=p.first;
		else s2.erase(it);
	}
	cout<<sum<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	int T;cin>>T;
	for(;T--;)solve(); 
}

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

int main() {
	int n;
	cin >> n;
	int t,a;
	cin >> t >> a;
	vector <int> v(n);
	rep(i,n) cin >> v[i];
	int index=0;
	rep(i,n){
		if(abs(a-t+v[i]*0.006) < abs(a-t+v[index]*0.006)){
			index = i;
		}
	}
	cout << index+1 << endl;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, readline().split()))

S = sum(A)

x = [0] * N
x[0] = S - 2 * sum(A[i] for i in range(N) if i % 2 == 1)

for i in range(1, N):
    x[i] = 2 * A[i - 1] - x[i - 1]
for i in x:
    print(i)

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

using namespace std;
typedef long long ll;
const int MAXN = 2100;

int N;
string S;
vector <int> edge[MAXN];
int nnode[MAXN], ddep[MAXN], dmin[MAXN];
int ans;

void flood (int cloc, int last)
{
    int ntot = 0, nbest = 0, nmin = 0;
    nnode[cloc] = S[cloc] - '0';
    ddep[cloc] = 0;
    for (int neigh : edge[cloc])
    {
        if (neigh == last) continue;
        flood (neigh, cloc);

        nnode[cloc] += nnode[neigh];
        int nb = ddep[neigh] + nnode[neigh];
        ddep[cloc] += nb;
        ntot += nb;
        nbest = max (nbest, nb);
        nmin = max (nmin, dmin[neigh] + nnode[neigh]);
    }

    dmin[cloc] = max (0, nbest + nmin - ntot);
}

void solve_root (int x)
{
    flood (x, -1);
    if (dmin[x] == 0 && ddep[x] % 2 == 0)
        ans = min (ans, ddep[x]);
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> S;
    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    ans = 1e9;
    for (int i = 0; i < N; i++)
    {
        solve_root (i);
    }
    if (ans > 1e8)
        cout << "-1\n";
    else
        cout << ans / 2 << "\n";
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]>rank[ry]) par[ry]=rx;
        else par[rx]=ry;
        if(rank[rx]==rank[ry]) rank[ry]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    int cnt(int n){
        int res=0;
        for(int i=0;i<n;++i){
            if(root(i)==i) res++;
        }
        return res;
    }
};

int main(){
    int N,K;cin>>N>>K;
    if(K>(N-1)*(N-2)/2){
        cout<<-1<<endl;
        return 0;
    }
    int M=N*(N-1)/2-K;
    cout<<M<<endl;
    int i=1,j=2;
    while(M--){
        cout<<i<<' '<<j++<<endl;
        if(j>N){
            i++;
            j=i+1;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
c[2];i;m;main(j,s)char*s;{gets(s);for(gets(s);s[++i];m=fmax(__builtin_popcount(*c&=c[1]),m))for(*c=c[1]=j=0;s[j];)c[j<i]|=1<<s[j++]-97;printf("%d",m);}

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

static const int MAX = 100000;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
int n;
vector<int> G[MAX], color(MAX);
// main関数からこれらを削除すること

void dfs(int u) {
  color[u] = 1; // GRAY
  for(int i = 0; i < G[u].size(); i++){
    int v = G[u][i];
    if(color[v] == 0) dfs(v);
  }
  color[u] = 2; // BLACK
}

int main() {
// 無向(有向)グラフの隣接リスト
  int m, u, v, w;
  cin >> n >> m;
  
  for(int i = 0; i < m; i++){
    cin >> u >> v >> w;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(color[i] == 0){
      dfs(i);
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 10752
#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;

vector<int> first;
vector<int> second;
vector<pair<int,int> > isl;
int n,m;
int MAX = 200000;
int i,j,k;

int main(){
    for(i = 0; i < MAX; i++){
        first.push_back(0);
        second.push_back(0);
    }
    cin >> n >> m;
    for(i = 0; i < m; i++){
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        isl.push_back(pair<int,int>(tmp1, tmp2));
    }
    for(i = 0; i < m; i++){
        pair<int, int> tmp = isl[i];
        if(tmp.first == 1){
            first[tmp.second] = 1;
        }
    }
    for(i = 0; i < m; i++){
        pair<int, int> tmp = isl[i];
        if(tmp.second == n && first[tmp.first] == 1){
            cout << "POSSIBLE" << "\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << "\n";
}


Measured memory_bytes: 3948
#include <iostream>
#include<vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main(void)
{
	
	vector<char> data(4);
	for (int i = 0; i < 4; i++)
	{
		cin >> data[i];
	}
	sort(data.begin(), data.end());
	if (data[0] == data[1] && data[2] == data[3] && data[1] != data[2])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  
  string left,right,s,a;
  int len=0;
  cin >> s;
  
  if(s.size()%2 != 0){
    len = s.size()-1;
  }
  else{
    len = s.size()-2;
  }
  
  for(int i=0;i<len/2;i++){
    left += s[i];
  }
  for(int i=len/2;i<len;i++){
    right += s[i];
  }
  left += '\0';
  right += '\0';
  
  while(left != right){
    len -= 2;  
    left = right = a;
    for(int i=0;i<len/2;i++){
      left += s[i];
    }
    left+='\0';
    for(int i=len/2;i<len;i++){
      right += s[i];
    }
    right+='\0';
  }

  cout << left.size()*2-2 << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

namespace Project
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            char[] s = Console.ReadLine().ToCharArray();
            int k = int.Parse(Console.ReadLine());
            char r = s[k - 1];
            foreach(char c in s)
            {
                Console.Write(c == r ? r : '*');
            }
        }
    }
}


Measured memory_bytes: 11092
using System;

class Program
{
	static void Main(string[] args)
	{
      	const int MOD = 1000000007;
      
      	string[] param = Console.ReadLine().Split(' ');
      	int N = int.Parse(param[0]);
        int M = int.Parse(param[1]);
      	bool[] stairs = new bool[N+1];
      	
      	for (int i = 0; i < M; i++) {
          	int broke = int.Parse(Console.ReadLine());
     		stairs[broke] = true;
        }
      
      	int[] dp = new int[N+1];
      	dp[N] = 1;
      
      	for (int i = (N-1); i >= 0; i--) {
          if (stairs[i] == true) {
            dp[i] = 0;
            continue;
          }
          int tmp = 0;
          if (i == (N-1)) {
            tmp = dp[i+1];
          }
          else {
            tmp = dp[i+1] + dp[i+2];
          }
          
          if (tmp == 0) {
            dp[0] = 0;
            break;
          }
          dp[i] = (tmp % MOD);
        }
      
      	Console.WriteLine(dp[0]);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i = 0; i < M; i++) cin >> B[i];
    vector<vector<int>> A(N,vector<int>(M));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            cin >> A[i][j];
        }
    }
    int Count = 0;
    int S;
    for(int i = 0; i < N; i++){
        S = 0;
        for(int j = 0; j < M; j++){
            S += A[i][j] * B[j];
        }
        if(S + C > 0) Count++;
    }
    cout << Count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
inline int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')c=getchar(),k=-1;
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(int x){if (x<0)putchar('-'),x=-x;if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(int x){write(x);puts("");}
struct lsg{int x,y;}f[1000010];
int n,a[1000010],sum;
lsg hb(lsg x,lsg y){if (x.x<y.x)return lsg{y.x,max(x.x,y.y)};else return lsg{x.x,max(y.x,x.y)};}
signed main(){
	n=1ll<<read();for (int i=0;i<n;i++)a[i]=read(),f[i].x=a[i];
	for (int i=1;i<=n;i<<=1)
		for (int j=0;j<n;j++)if (j&i)
			f[j]=hb(f[j],f[j-i]);
	for (int i=1;i<n;i++){
		sum=max(sum,f[i].x+f[i].y);
		writeln(sum);
	}
}




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

int main(){
    string s;
    cin >> s;
    if (s == "ARC")cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

void judge();

int point[110];

int main()
{
  int a, b;
  while(cin >> a >> b)
  {
    if(a == 0 && a == b)
    {
      judge();
      continue;
    }
    point[a]++;
    point[b]++;
  }
}

void judge()
{
  bool ans = true;
  if(point[1] % 2 == 0)
    ans = false;
  if(point[2] % 2 == 0)
    ans = false;
  point[1] = point[2] = 0;
  for(int i = 3; i < 110; i++)
  {
    if(point[i] % 2)
      ans = false;
    point[i] = 0;
  }

  cout << (ans ? "OK" : "NG") << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ld = long double;

ld fctr(ld x) {
    ld X = x;
    if (x != 0) {
        while (x != 1) {
            x--;
            X *= x;
        }
        return X;
    }
    else { return 1; }
}
int main() {
    ld N; cin >> N;
    vector<pair<ld, ld>> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p.at(i).first >> p.at(i).second;
    }
    ld sum = 0, ave;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (j == i) {
                continue;
            }
            else {
            sum += sqrt(pow(p.at(i).first - p.at(j).first, 2) + pow(p.at(i).second - p.at(j).second, 2));
            }
        }
    }
    ave = sum * fctr(N - 2) * (N - 1) / fctr(N);
    cout << fixed << setprecision(7);
    cout << ave << endl;
}

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

using namespace std;

int main(void){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a == c){
    cout << 0 << endl;
  }
  else 
    cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: usize = sc.read();
    let b: usize = sc.read();
    let m: usize = sc.read();
    let mut a_v: Vec<usize> = sc.vec(a);
    let mut b_v: Vec<usize> = sc.vec(b);
    let xyc: Vec<(usize, usize, usize)> = (0..m)
        .map(|_| {
            let x: usize = sc.read();
            let y: usize = sc.read();
            let c: usize = sc.read();
            (x - 1, y - 1, c)
        })
        .collect();
    let mut result = 1usize << 50;
    for &(x, y, c) in xyc.iter() {
        result = std::cmp::min(result, a_v[x] + b_v[y] - c);
    }
    a_v.sort();
    b_v.sort();
    result = std::cmp::min(result, a_v[0] + b_v[0]);
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 14716
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int N = 0, M = 0, L = 0;
string result;
char temp_char[1024];
void add_edge(int from, int to, int weight)
{
	sprintf(temp_char, "%d %d %d\n", from, to, weight);
	result += temp_char;
	M++;
}

int max_r(int num)
{
	int p = 0;
	while( (1L << p) <= num)
	{
		p++;
	}
	return p - 1;
}
int main(int argc, char *argv[]) {
	cin >> L;
	int r = max_r(L);
	N = r + 1;
	for(int i = 1; i <= r; i++)
	{
		add_edge(i, i + 1, (1 << (i - 1)));
		add_edge(i, i + 1, 0);
	}
	
	int current = 1 << r;
	int remind = L - current;
	while(remind)
	{
		int p = max_r(remind);
		add_edge(p + 1, N, current);
		current += 1 << p;
		remind = L - current;
	}
	cout << N << " " << M << endl;
	cout << result;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
-- end of templete

wf :: IOUArray (Int,Int) Int -> [Int] -> IO ()
wf arr range = do
    forM_ range $ \k -> do
        forM_ range $ \i -> do
            forM_ range $ \j -> do
                u <- readArray arr (i,k)
                v <- readArray arr (k,j)
                d <- readArray arr (i,j)
                when (u/=(-1) && v/=(-1)) $ do
                  let w = u + v
                  when (d==(-1) || w<d) $ writeArray arr (i,j) w 



main = do
    n <- getInt
    m <- getInt
    arr <- newArray ((1,1),(n,n)) (-1) :: IO (IOUArray (Int,Int) Int)
    replicateM_ m $ do
        [a,b,c,d] <- map readInt . wordsBy (==',') <$> getLine
        writeArray arr (a,b) c
        writeArray arr (b,a) d
    wf arr [1..n]
    [s,g,v,p] <- map readInt . wordsBy (==',') <$> getLine
    x <- (+) <$> readArray arr (s,g) <*> readArray arr (g,s)
    print $ v - p - x

Measured memory_bytes: 5132
while true
 
	aryMondai = gets.split();
 
	num1 = aryMondai[0].to_i;
	op =  aryMondai[1];
	num2 = aryMondai[2].to_i;
 
	if op == "?" then
		break;
	end
 
	if op == "+" then
 
		puts (num1 + num2).to_s;
 
	elsif op == "-" then
 
		puts (num1 - num2).to_s;
 
	elsif op == "*" then
 
		puts (num1 * num2).to_s;
 
	elsif op == "/" then
 
		puts (num1 / num2).to_s;
 
	end
 
end

Measured memory_bytes: 8688
a = []

while True:
    a.append(list(map(int, input().split())))
    if a[-1] == [0, 0]:
        a.pop(-1)
        break

for i in range(0, len(a)):
    for j in range(0, a[i][0]):
        print('#' * a[i][1])
    print('')



Measured memory_bytes: 5628
import java.util.*;	
public class Main {	
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      Integer n = sc.nextInt();
      String linew = sc.nextLine();
      boolean flg = false;
      int s = 0;
      int x = 0;
      int y = 0;
      for(int i=0;i<n;i++){
        String line = sc.nextLine();
        String str[] = line.split(" ");
        s = Integer.parseInt(str[0]) - s ;
        x = Integer.parseInt(str[1]) - x ;
        y = Integer.parseInt(str[2]) - y ;

        if(s >= x+y && ((s-(x+y))%2==0)){
          flg = true;
        }else{
          flg = false;
          break;
        }    
      }
      if(flg){System.out.println("Yes");
      }else{System.out.println("No");
      }
    }
}

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

int main (void) {
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> graph(N, vector<pair<int, int>>());
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].emplace_back(v, w);
    graph[v].emplace_back(u, w);
  }

  // 頂点の色
  vector<int> color(N, -1);

  // 順に色を塗っていく
  // とりあえず0で始める
  stack<int> st;
  st.push(0);
  color[0] = 0;

  vector<bool> visited(N, false);

  while (!st.empty()) {
    const int u = st.top(); st.pop();
    const int u_color = color[u];
    for (const auto& edge : graph[u]) {
      const int v = edge.first, w = edge.second;
      if (!visited[v]) {
        const int next_color = w % 2 == 0 ? u_color : 1 - u_color;
        color[v] = next_color;
        st.push(v);
        visited[v] = true;
      }
    }
  }
  for (const auto& c : color) {
    assert(c != -1);
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 6784
import sys
import math
import numpy as np


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


def dist(y, z, d):
    ret = 0.0
    for i in range(d):
        ret += pow(y[i] - z[i], 2)
    return pow(ret, 0.5)


def main():
    n, d = [int(e) for e in input().split()]
    x = [[int(e) for e in input().split()] for _ in range(n)]

    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist_yz = dist(x[i], x[j], d)
            if math.ceil(dist_yz) == math.floor(dist_yz):
                ans += 1
    print(ans)


main()


Measured memory_bytes: 12344
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int ans = 0;
	eREP(i, A)eREP(j, B)eREP(k, C) {
		if (500 * i + 100 * j + 50 * k == X)ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
# ITP1_2_C
a, b, c = input().split()
a, b, c = int(a), int(b), int(c)

if (a > b):
  a, b = b, a
  if (b > c):
    b, c = c, b
    if (a > b):
      a, b = b, a
else:
  if (b > c):
    b, c = c, b
  else:
    if (a > c):
      a, c = c, a
print("{} {} {}".format(a, b, c))



Measured memory_bytes: 5600
#include <bits/stdc++.h>                                                                 
using namespace std;   
string s;
int main(){
	cin>>s;
	int len=s.length();
	if(s[0]==s[len-1])
        if(len%2==0) cout<<"First"<<endl;
        else cout<<"Second"<<endl;
    else
        if(len%2==0) cout<<"Second"<<endl;
        else cout<<"First"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}

signed main (){
    int a,b;cin>>a>>b;
    if(b%a==0)cout<<b+a<<endl;
    else cout<<b-a<<endl;
}
/*
00001
00110
00011

00122
*/


Measured memory_bytes: 256
//#define txtout
//#define debug
#include<bits/stdc++.h>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int M=1e5+10;
int n;
LL a[M];
set<LL> dp[2];
set<LL>::iterator it;
LL solve(){
    sort(a,a+n);
    LL sum=0;
    for(int i=0;i<n;i++){
        if(a[i]>sum+1) return sum+1;
        sum+=a[i];
    }
    return sum+1;
}
int main(){
    #ifdef txtout
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // txtout
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%lld",&a[i]);
        }
        printf("%lld\n",solve());
    }
    return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;


int main(){
	string s;
	cin>>s;
	int q;
	cin>>q;
	int t;
	int rev=0;
	string fro;
	string bac;
	REP(i,q){
		cin>>t;
		rev=(rev+t)%2;
		if(t==2){
			int f;
			cin>>f;
			string c;
			cin>>c;
			if(rev==1){
				f=f%2+1;
			}
			if(f==1){
				fro=c+fro;
			}else{
				bac=bac+c;
			}
		}
	}
	s=fro+s+bac;
	if(rev==1) reverse(ALL(s));
	OUT(s);
	return 0;
}

Measured memory_bytes: 1512
#065_C
n,m=map(int,input().split())
mod=10**9+7
f=[i for i in range(max(n,m)+1)]
for i in range(1,max(n,m)):
    f[i+1]=(f[i+1]*f[i])%mod
ans=0

if abs(n-m)==1:
    ans=(f[n]*f[m])%mod
elif n==m:
    ans=(f[n]**2)*2%mod
    
print(ans)

Measured memory_bytes: 7064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        double min = 999;
        int minidx = 0;
        for (int i = 0; i < n; i++) {
            double sa = Math.abs(a-(t-sc.nextInt()*0.006));
            if (min > sa) {
                min = sa;
                minidx = i;
            }
        }
        System.out.println(minidx+1);

    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
#define ALL(v) v.begin(), v.end()


ll t[100010];
ll h[100010];

ll root(ll x){
    if(t[x]==x){
        return x;
    }else{
        return t[x]=root(t[x]);
    }
}

int main(){
    ll N;
    cin>>N;
    
    vector<ll> H(N);
    
    REP(i,N){
        cin>>H[i];
    }
    
    ll cnt;
    while(true){
        cnt=0;
        sort(H.begin(),H.end());
        for(ll i=0;H[i]<=0;i++)cnt++;
        if(cnt>=N-1){
            break;
        }
        
        FOR(i,cnt+1,N){
            H[i]%=H[cnt];
        }
    }
    cout<<H[cnt];
    return 0;
    
    // REP(i,N){
    //     t[i]=i;//t.push_back(i);
    //     h[i]=0;//h.push_back(0);
    // }
    // REP(ttttt,Q){
    //     ll q;
    //     cin>>q;
    //     if(q==0){
    //         ll a,z;
    //         cin>>a>>z;
    //         ll mi=min(root(a),root(z));
    //         ll ma=max(root(a),root(z));
    //         if(a!=z){
    //             if(h[mi]==h[ma]){
    //                 t[ma]=mi;
    //                 h[mi]++;
    //             }else if(h[mi]>h[ma]){
    //                 t[ma]=mi;
    //             }else{
    //                 t[mi]=ma;
    //             }
    //         }
    //     }else{
    //         ll a,z;
    //         cin>>a>>z;
    //         cout<<(root(a)==root(z)?"Yes":"No")<<endl;
    //     }
    // }
    // REP(i,N){
    //     sl(i,":",t[i],h[i]);
    // }
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 4064
#include <iostream>
#include <vector>
using namespace std;
#define MAX 7368791+2

int main(){
	while(1){
		int m,n;
		cin >> m >> n;
		if(n==0) break;
		
		vector<bool> year(MAX, false);
		int last;
		for(int i=m,count=0; count<n ; i++){
			if(!year[i]){
				count++;
				last = i;
				for(int j=i; j<MAX; j+=i){
					year[j]=true;
				}
			}
		}
		for(int i=last; i<MAX; i++){
			if(!year[i]){
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 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; }

int main()
{
	ll N;
	cin >> N;
	vector<vector<ll>> tree(N, vector<ll>());
	REP(i, N-1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	vector<ll> c(N);
	REP(i, N) cin >> c[i];
	sort(ALL(c));
	ll M = 0;
	REP(i, N-1) {
		M += c[i];
	}
	reverse(ALL(c));
	vector<bool> visited(N,false);
	queue<ll> que;
	que.push(0);
	visited[0] = true;
	vector<ll> ans(N);
	ll cnt = 1;
	ans[0] = c[0];
	while(!que.empty()) {
		ll t = que.front();
		que.pop();
		REP(i, tree[t].size()) {
			if (!visited[tree[t][i]]) {
				que.push(tree[t][i]);
				visited[tree[t][i]] = true;
				ans[tree[t][i]] = c[cnt];
				cnt++;
			}
		}
	}
	PRINT(M);
	REP(i, N) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
#define LINF 1e9+10
typedef long long ll;

using namespace std;

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

ll fnc(ll h){
      if(h <= 1) return 1;
      else return 1 + 2*fnc(h/2);
}

ll f[30] = {};
int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      ll h; cin >> h;
      cout << fnc(h) << endl;

      return 0;
}


Measured memory_bytes: 256
def bfs(G,start):
    from collections import deque
    dist = [-1] * n
    dist[start] = 0
    parent = [-1] * n
    parent[start] = 0
    q = deque([start])
    add,pop=q.append,q.popleft
    while q:
        v = pop()
        for nv in G[v]:
            if dist[nv] < 0:
                dist[nv] = dist[v]+1
                parent[nv] = v+1
                add(nv)
            # 2部グラフ判定
            # else:
            #     if dist[v]%2 == dist[nv]%2:
            #         is_bipartite = False
    return dist,parent

import numpy as np
import math
n,m = map(int,input().split())
roads = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    roads[a-1].append(b-1)
    roads[b-1].append(a-1)
dist, parent = bfs(roads,0)
if -1 in dist:
    print('No')
else:
    print('Yes')
    for i in parent[1:]:
        print(i)

Measured memory_bytes: 55964
/*
    総当たり
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_A
*/
#include <bits/stdc++.h>
using namespace std;

int n, A[50];

int solve(int i, int m) {
    if (m == 0)
        return 1;
    if (i >= n)
        return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

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

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> A[i];

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int input;
        cin >> input;
        if (solve(0, input))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


Measured memory_bytes: 3200
#include <stdio.h>

int main()
{
  int age;
  int money;
  scanf("%d",&age);
  scanf("%d",&money);
  if(age>=13){
  printf("%d",money);
  }else if(age<=12 && age>=6){
  printf("%d",money/2);
  }else{
  printf("%d",money*0);
  }
  return 0;
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.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))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N; cin >> N;
    vec A(N); readv(A);

    vec count(N, 0);
    REP(i, N) count[A[i]]++;

    vec ans(N, 0);
    if(N % 2 == 0){
        REP(i, N / 2) ans[2 * i + 1] = 2;
    }else{
        REP(i, N / 2) ans[2 * i + 2] = 2;
        ans[0] = 1;
    }

    bool f = true;
    REP(i, N) if(ans[i] != count[i]) f = false;
    if(f) cout << fastpow(2, N / 2, 1000000007);
    else cout << 0;
    
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define LL long int

const LL MOD = pow(10,9) + 7;



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

    vector<int> a(m);
    for(int i = 0; i < m; ++i) cin >> a[i];

    vector<int> dp(n + 1,0);

    dp[0] = 1;
    dp[1] = 1;
    int k = 0;

    if(!a.empty() && a[k] == 1){
        dp[1] = 0;
        k++;
    }

    for(int i = 2; i <= n; ++i){
        dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        if(!a.empty() && i == a[k]){
            dp[i] = 0;
            k++;
        }
    }

    cout << dp[n] << endl;


    return 0;
}


Measured memory_bytes: 1024
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = tail . words
printer = unlines . (:[]) . show

solver ps = length $ L.group $ L.sort ps

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

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

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

    map<int, long long> c;
    for (auto i: mp){
        c[i.first] = (i.second - 1) * (i.second) / 2LL;
        sum += c[i.first];
    }

    for (int i = 0; i < n; i++){
        if (mp[a[i]] <= 1)
            cout << sum - c[a[i]] << endl;
        else
            cout << sum - c[a[i]] + ((mp[a[i]] - 1) * (mp[a[i]] - 2)) / 2LL << endl;
    }



    return 0;
}


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

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
const int  p=31,po=1,N=50001, M=(ll)1e9+1 ;
const int mod = (ll)1e9 +7;
// struct node{
//   ll prefixsum,suffixsum,bettersum,totalsum;
//   void create(ll val){
//     prefixsum=suffixsum=bettersum=val;
//   }
//   void Merge(node& a,node &b){
//     prefixsum=max(a.prefixsum,a.totalsum+b.prefixsum);
//     suffixsum=max(b.suffixsum,a.suffixsum+b.sum);
//     totalsum=a.totalsum+b.totalsum;
    
//   }
// }
//ll dp[2][100];
vl compute(string s){
        vl has(s.length());
        ll i;

        for(i=0;i<s.length();i++){
            if(i==0){
                has[i]=((s[i]-'a'+1))%mod;
            }
            else
                has[i]=(has[i-1]*p + (s[i]-'a'+1))%mod;
        }
        return has;
}


int main(){
 ios_base::sync_with_stdio(0);
  ll i,n,j,k;
  cin >> n;
  ll v[n+1][4];
  for(i=1;i<=n;i++){
    ll a,b,c;
    cin >> a >> b >> c;
    if(i==1){
      v[i][1]=a, v[i][2]=b, v[i][3]=c;
      continue;
    }
    v[i][1]=a+max(v[i-1][2],v[i-1][3]);
    v[i][2]=b+max(v[i-1][1],v[i-1][3]);
    v[i][3]=c+max(v[i-1][1],v[i-1][2]);
  }
  cout << max(max(v[n][1],v[n][2]),v[n][3]);
    return 0;
}



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

using namespace std;
int N;
string S, T;
int main(void) {

	cin >> N >> S >> T;

	string ans = "";

	for (int i = 0; i < N; i++) {
		ans += S[i];
		ans += T[i];
	}

	cout << ans << endl;
	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[]a =new int[n];
	    
		
	    for(int i=0;i<n;i++) {
	    	a[i]=sc.nextInt();
	    }
	    
	   Arrays.sort(a);
	   int last=a[n-1]+1;
	   int[] l=new int[last];
	   
	    
	   for(int i=0;i<n;i++) {
		   int c=a[i];
	    	while(c<last) {
	    		l[c]++;
	    		c+=a[i];
	    	}
	    }
	   int ans=0;
	   for(int i=0;i<n;i++) {
		   if(l[a[i]]==1) {
			   //System.out.println(a[i]);
			   ans++;
		   }
		   
	   }
		System.out.println(ans);
	}
}


Measured memory_bytes: 60856
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int N, K;
Graph G;

int dfs(int v, int pre, int d) {
    if (d < 0) return 0;
    int ret = 1;
    for (auto&& nxt : G[v]) {
        if (nxt != pre) {
            ret += dfs(nxt, v, d - 1);
        }
    }
    return ret;
}

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

    cin >> N >> K;
    G.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    int alive = -1;
    if (K % 2 == 0) {
        rep(i, N) {
            alive = max(alive, dfs(i, -1, K / 2));
        }
    } else {
        rep(i, N) {
            for (auto&& j : G[i]) {
                alive = max(alive, dfs(i, j, (K - 1) / 2) + dfs(j, i, (K - 1) / 2));
            }
        }
    }

    cout << N - alive << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll res = INF;
  for (int bit = 0; bit < (1 << n); bit++) {
    if (__builtin_popcount(bit) != k) continue;
    ll tmp = 0;
    int prev = 0;
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        if (prev == 0) prev = a[i] - 1;
        tmp += max(prev - a[i] + 1, 0);
        prev = a[i] + max(prev - a[i] + 1, 0);       
      }
      prev = max(prev, a[i]);
    }
    res = min(res, tmp);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
def grundy(a, k):
    while a >= k and a % k:
        b = a % k
        c = a//k + 1
        a += c * (-b // c)
    if a % k == 0:
        return a // k
    return 0
    
N = int(input())
s = 0
for _ in range(N):
    a, k = map(int, input().split())
    s ^= grundy(a, k)

print("Takahashi" if s else "Aoki")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	int n, k;
	string test;

	cin >> n >> k >> test;
	
	test[k - 1] += 'a' - 'A';

	cout << test;

	return 0;
}

Measured memory_bytes: 256