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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

int N;
string S;
int R[4001],B[4001];
ll dp[4001][4001];

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

  cin>>S;
  N=S.size();
  rep(i,N){
    if(S[i]=='0'){
      R[i+1]=R[i]+2;
      B[i+1]=B[i];
    }
    if(S[i]=='1'){
      R[i+1]=R[i]+1;
      B[i+1]=B[i]+1;
    }
    if(S[i]=='2'){
      R[i+1]=R[i];
      B[i+1]=B[i]+2;
    }
  }

  dp[0][0]=1;
  rep(i,2*N)rep(j,R[N]+1){
    if(dp[i][j]==0)continue;
    // dbg(i); dbg(j); dbg(dp[i][j]);
    if(i>=N){
      if(R[N]>=j+1)(dp[i+1][j+1]+=dp[i][j])%=mod;
      if(B[N]>=i-j+1)(dp[i+1][j]+=dp[i][j])%=mod;
    }else{
      { // red
        if(R[i+1]>=j+1)(dp[i+1][j+1]+=dp[i][j])%=mod;
      }
      { // blue
        if(B[i+1]>=i-j+1)(dp[i+1][j]+=dp[i][j])%=mod;
      }
    }
  }

  cout<<dp[2*N][R[N]]<<endl;

  return 0;
}


Measured memory_bytes: 123520
n,t = gets.split.map(&:to_i)
list = (1..n).map{gets.split.map(&:to_i)}.sort
dp = [0]*(t)
ans = 0
list.each{|a,b|
  if ans < tmpans=dp[t-1]+b
    ans = tmpans
  end
  (0..t-1-a).reverse_each{|ti|
    if dp[tia=ti+a] < dpb=dp[ti]+b
      dp[tia] = dpb
    end
  }
}
p ans

Measured memory_bytes: 41464
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n;
    cin >> n;
    if(!n)
        return false;

    vector<int> v(n);
    vector<vector<int>> t(n, vector<int>(n));
    for(int i = 0; i < n; ++i){
        cin >> v[i];
        for(int j = 0; j < n; ++j)
            cin >> t[i][j];
    }

    vector<int> dp(1 << n, MOD);
    dp[0] = 0;
    for(int i = 0; i < (1 << n); ++i){
        for(int j = 0; j < n; ++j){
            if(i & 1 << j)
                continue;
            int time = v[j];
            for(int k = 0; k < n; ++k)
                if(i & (1 << k))
                    chmin(time, t[j][k]);
            chmin(dp[i | (1 << j)], dp[i] + time);
        }
    }
    cout << dp.back() << endl;

    return true;
}

signed main(){
    while(solve());
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin>>n;

	ll num = n;

	ll div = 0;

	while(n>0)
	{
		div += n%10;

		n /= 10;
	}

	

	if(num % div == 0)
	{
		cout<<"Yes"<<endl;
	}

	else
	{
		cout<<"No"<<endl;
	}

}


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

#define N 10001

int main(){
  int loop;
  int Counter[N];
  int  *Before,*After;
  int i;

  
  scanf("%d",&loop);
  
  Before=malloc(sizeof(int)*loop+1);
  After=malloc(sizeof(int)*loop+1);
  
  for(i=0;i<N+1;i++){
    Counter[i]=0;
  }

  for(i=1;i<loop+1;i++){
    scanf(" %d",&Before[i]);
    Counter[Before[i]]++;
  }
  
  for(i=1;i<N+1;i++){
    Counter[i]=Counter[i]+Counter[i-1];
  }

  for(i=loop;i>=1;i--){
    After[Counter[Before[i]]]=Before[i];
    Counter[Before[i]]--;
  }

  for(i=1;i<loop;i++){
    printf("%d ",After[i]);
  }

  printf("%d\n",After[loop]);
  
  return 0;
}





Measured memory_bytes: 17472
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,j,n) for(int i = (int)(j); i < (int)(n); i++)
#define mrep(i,n) for (int i = (int)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll MAX=1e18;

int main() {
	int n; cin >> n;
	if(n%2==0) cout << n << endl;
	else cout << n*2 << endl;
}

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

int n,m,ans;
int h[100005],a,b;
int flag[100005];

int main()
{	
	cin>>n>>m;
	for(int i=1;i<=n;i++)flag[i]=1;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	while(m--){
		cin>>a>>b;
		if(h[a]<=h[b])flag[a]=0;
		if(h[a]>=h[b])flag[b]=0;
	}
	for(int i=1;i<=n;i++)if(flag[i])ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4416
use std::io::{stdin, Read};

macro_rules! parse {
    ($iter: ident) => {
        $iter.next().unwrap().parse().unwrap()
    };
    ($iter: ident,2) => {
        (parse!($iter), parse!($iter))
    };
    ($iter: ident,3) => {
        (parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident,4) => {
        (parse!($iter), parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident, $n: ident) => {
        $iter.take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let n: Vec<usize> = iter
        .next()
        .unwrap()
        .chars()
        .map(|x| x.to_digit(10).unwrap() as usize)
        .collect();
    let mut k: usize = parse!(iter);
    let mut res = 0;
    for (i, &ni) in n.iter().enumerate() {
        let i = n.len() - i - 1;
        if k == 0 {
            res += 1;
            break;
        }
        if ni == 0 {
            continue;
        }
        res += f(i, k);
        if i != 0 {
            res += (ni - 1) * f(i, k - 1);
        } else {
            res += ni * f(i, k - 1);
        }
        k -= 1;
    }
    println!("{}", res);
}
fn f(i: usize, k: usize) -> usize {
    match k {
        0 => 1,
        1 => 9 * i,
        2 => 81 * i * (i - 1) / 2,
        3 => 729 * i * (i - 1) * (i - 2) / 6,
        _ => 0,
    }
}


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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    ll ans = 0;
    for (int i = 0; i < (1 << (N - 1)); ++i) {
        ll sum = 0, t = S[0] - '0';
        for (int j = 1; j < N; ++j) {
            if (((i >> (j - 1)) & 1) == 1) sum += t, t = S[j] - '0';
            else t *= 10, t += S[j] - '0';
        }
        sum += t;
        ans += sum;
    }
    cout << ans << endl;
}

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> m;
	string a[60], b[60];
	rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i];

	f = 0;
	s = "No";
	rep(i, n-m+1)	{
		rep(j, n-m+1){
			for(k=0; k<m; k++){
				for(l=0; l<m; l++){
					if(a[k+i][l+j] != b[k][l]){
						f = 1;
					}
				}
			}
			if(f == 0){
				s = "Yes";
				break;
			}
			f = 0;
		}
	}

	cout << s << endl;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define ALL(x) x.begin(), x.end()

void Main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (auto &x : v) {
    cin >> x;
  }
  int ans = 0;
  rep(i, min(n, k)) {
    rep(j, min(n - i, k - i)) {
      int sum = accumulate(v.begin(), v.begin() + i, 0) +
                accumulate(v.rbegin(), v.rbegin() + j, 0);
      /* DUMP(sum); */

      vector<int> v1(v.begin(), v.begin() + i);
      vector<int> v2(v.rbegin(), v.rbegin() + j);
      std::copy(v2.begin(), v2.end(), back_inserter(v1));
      sort(ALL(v1), greater<int>());
      for(int l = 0; l < std::min(n, k - (i + j)); ++l) {
        if (v1.empty())
          break;
        int m = v1.back();
        if (m >= 0)
          break;
        else {
          sum -= m;
          v1.pop_back();
        }
      }
      /* DUMP(i); */
      /* DUMP(j); */
      /* DUMP(sum); */
      if (sum > ans) {
        ans = sum;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            int n = int.Parse(input1[0]), z = int.Parse(input1[1]), w = int.Parse(input1[2]);
            string[] input2 = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i<n; i++) a[i] = int.Parse(input2[i]);

            int ans;
            if (n>1) ans = Math.Max(Math.Abs(a[n-1] - w), Math.Abs(a[n-2] - a[n-1]));
            else ans = Math.Abs(a[n-1] - w);
            Console.WriteLine(ans);
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 11220
count = 0
flg = 0
n = input()
a = list(map(int,input().split()))

while True:
	for i in a:
		if i%2 != 0:
			flg = 1

	if flg == 0:
		a = list(map(lambda x: int(x/2), a))
		count += 1
	else:
		break
         
print(count)

Measured memory_bytes: 3060
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

N,Q=map(int,input().split())
*A,=map(int,input().split())

bit=Bit(N)
for i in range(1,N+1):
    bit.add(i,A[i-1])

from sys import stdin
abc=[list(map(int,stdin.readline().split()))for _ in range(Q)]

for a,b,c in abc:
    if a:print(bit.sum(c)-bit.sum(b))
    else:bit.add(b+1,c)

Measured memory_bytes: 145848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int a, b; cin >> a >> b;

  ll ans = 0;
  if (a < b) {
    for (int i = 0; i < b; i++) {
      ans += pow(10, i) * a;
    }
  } else {
    for (int i = 0; i < a; i++) {
      ans += pow(10, i) * b;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#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,k;
  cin >> n >> k;

  priority_queue<ll> que;
  ll l;
  REP(i, n){
    cin >> l;
    que.push(l);
  }

  ll ans = 0;
  REP(i, k){
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $a, $b);

$area   = getArea($a, $b);
$circum = getCircum($a, $b);

printf("%d %d%s", $area, $circum, PHP_EOL);

function getArea($length, $breadth)
{
    return $length * $breadth;
}

function getCircum($length, $breadth)
{
    return ($length + $breadth) * 2;
}

Measured memory_bytes: 6556
fun main() {
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(" ").map { it.toInt() }
    var cnt = 0
    for (i in 0 until n) {
        for (j in i + 1 until n) {
            for (k in j + 1 until n) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if (check(l[i], l[j], l[k])) cnt++
                }
            }
        }
    }
    println(cnt)
}

fun check(a: Int, b: Int, c: Int): Boolean = when {
    a + b <= c -> {
        false
    }
    a + c <= b -> {
        false
    }
    b + c <= a -> {
        false
    }
    else -> true
}


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

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

    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        cin >> C.at(i);
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if ((V.at(i) - C.at(i)) > 0)
        {
            ans += (V.at(i) - C.at(i));
        }
        
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

const string YES = "Yes";
const string NO = "No";

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

  double l;
  cin >> l;
  l /= 3;
  cout << fixed << setprecision(9);
  cout << l * l * l << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int a,b,c,d,e;
    cin >>a >>b >>c >>d >>e;
    int ans=0;
    for(int i=a; i<b; ++i)
    {
        if(i<0) ans+=c;
        else if(i>0) ans+=e;
        else ans+=d+e;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3060
def main():
	A, B, C = map(int, input().split())
	haiku = False
	if A == 5:
		if (B==5 and C==7) or (B==7 and C==5):
			haiku = True
	else:
		if (B==5 and C==5):
			haiku = True
	if haiku:
		print("YES")
	else:
		print("NO")


if __name__ == '__main__':
	main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, a[MAXN];

inline bool Solve()
{
	int cnt[2] = {0, 0}, d = 0;
	for (int i = 1; i <= n; i ++)
		cnt[a[i] & 1] ++;
	if (cnt[0] & 1)
		return true;
	if (cnt[1] ^ 1)
		return false;
	for (int i = 1; i <= n; i ++)
		if ((a[i] & 1) && (a[i] ^ 1))
		{
			a[i] --;
			for (int j = 1; j <= n; j ++)
				d = __gcd(d, a[j]);
			for (int j = 1; j <= n; j ++)
				a[j] /= d;
			return Solve() ^ 1;
		}
	return false;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read();
	if (n == 1)
		return puts("Second"), 0;
	return puts(Solve() ? "First" : "Second"), 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
// -----------------------------------------------

signed main(){

    fastIO

    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < (int)s.size(); i++) {
    	sum += s[i] - '0';
    }
    cout << (sum%9 == 0 ? "Yes\n" : "No\n");
    
    return 0;
}

Measured memory_bytes: 3768
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;

struct edge{
	int l,r,h;
	bool operator<( const edge& right ) const {
        return h == right.h ? r < right.r : h < right.h;
    }
};


int main(){
	int n,m,a;
	int ar[101];
	
	
	while(cin>>n>>m>>a){
		if(n==0&&m==0&&a==0)break;
		REP(i,n+1)ar[i]=i;
		vector<edge>ed;
		REP(i,m){
			edge e;int h;
			cin>>h>>e.l>>e.r;
			e.h=-h;
			ed.PB(e);
		}
		sort(ALL(ed));
		REP(i,m){
			swap(ar[ed[i].l],ar[ed[i].r]);
		}
		REP(i,n)if(ar[i+1]==a)cout<<i+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>

#define MAX 500000
#define INFTY 2000000000

void marge(int *,int,int,int);
void margeSort(int *,int,int);

int L[MAX];
int R[MAX];
int sort_count=0;

int main(){
  int i=0;
  int j=0;
  int n=0;
  int S[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  margeSort(S,0,i);

  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    printf("%d",S[i]);
  }
  printf("\n");
  printf("%d\n",sort_count);
  
  return 0;
}

void marge(int *S,int left,int mid, int right){
  int i=0;
  int j=0;
  int n_S=0;
  int n_left=0;
  int n_right=0;
  
  n_left=mid-left;
  n_right=right-mid;
  
  for(i=0;i<n_left;i++){
    L[i]=S[left+i];
  }
  
  for(i=0;i<n_right;i++){
    R[i]=S[mid+i];
  }
  
  L[n_left]=INFTY;
  R[n_right]=INFTY;
  i=0;
  j=0;
  
  for(n_S=left;n_S<right;n_S++){
    sort_count++;
    if(L[i]<=R[j]){
      S[n_S]=L[i];
      i++;
    }
    else{
      S[n_S]=R[j];
      j++;
    }
    
  }

}

void margeSort(int *S,int left,int right){
  int mid=0;
  if(left+1<right){
    mid=(left+right)/2;
    margeSort(S,left,mid);
    margeSort(S,mid,right);
    marge(S,left,mid,right);
  }
}



Measured memory_bytes: 5708
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a[100010],b[100010];
map<int,int> mpa;


int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    
    for(int i=0;i<n;i++){
        b[a[i]]++;b[a[i]+1]++;b[a[i]-1]++;
    }
    
    for(int i=0;i<100000;i++){
        m=max(m,b[i]);
    }
    
    C m E;
    
}

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

int main(void){
  int a,b,c,n;
  cin >> a >> b >> c;
  if (a > b){
    n = a;
    a = b;
    b = n;
  }
  if (b > c)
  {
    n = b;
    b = c;
    c = n;
  }
  if (a > b)
  {
    n = a;
    a = b;
    b = n;
  }
  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 3092
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        Map<Integer, Integer> food = new HashMap<>();
        for (int i = 0; i < n; ++i) {
            int k = scanner.nextInt();
            for (int j = 0; j < k; ++j) {
                int a = scanner.nextInt();
                int likes = food.getOrDefault(a, 0);
                food.put(a, likes + 1);
            }
        }
        long res = food.entrySet().stream()
                .filter(foodLikes -> foodLikes.getValue() == n)
                .count();
        System.out.println(res);
    }
}


Measured memory_bytes: 28756
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>


using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	long long res = 1;
	for (int i = 2; i <= n; ++i)
		res *= i;
	printf("%lld\n", res);

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int a,b,c,d,i,s=0;
	scanf("%d %d %d", &a, &b, &c);
	if (b > a){
		d = a;
		a = b;
		b = d;
	}
	for (i = b+1; i < a; i++){
		if (i == c)
			s++;
	}
	if (s >= 1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#define rep(i,n) for(int i = 0; i < (long int)n; i++)
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if(s[i] == s[i+1]){
      cout << "Bad";
      return 0;
    }
  }
  cout << "Good";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
#define MOD 1000000007

#define MAX_N 1005
#define MAX_M 10005

int tm[MAX_M][MAX_N];//tm[人数][時間]

int main(){

    int a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    while(b > 0 && c > 0){
        c--;
        b--;
        ans+=2;
    }
    while(a > 0 && c > 0){
        c--;
        a--;
        ans++;
    }

    if(c > 0){
        ans++;
    }
    //bが余った場合は全て食べる

    while(b > 0){
        b--;
        ans++;
    }

    cout << ans << endl;


    return 0;
}


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

int main(void)
{
  int n;
  int i;
  double d1=0,d2=0,d3=0,dd=0;
  double *x;
  double *y;
  
  scanf("%d",&n);

  x = (double *)malloc(sizeof(double) * n);
  y = (double *)malloc(sizeof(double) * n);

  for(i=0; i<n; i++){
    scanf("%lf",&x[i]);
  }
  for(i=0; i<n; i++){
    scanf("%lf",&y[i]);
  }

  for(i=0; i<n; i++){
    //d1????°????
    d1 = d1 + fabs(x[i] - y[i]);
    //d2^2????°????
    d2 = d2 + fabs(x[i] - y[i])*fabs(x[i] - y[i]);
    //d3^3????°????
    d3 = d3 + fabs(x[i] - y[i])*fabs(x[i] - y[i])*fabs(x[i] - y[i]);
    //dd????°????
    if(fabs(x[i] - y[i]) > dd){
      dd = fabs(x[i] - y[i]);
    }    
  }

  d2 = sqrt(d2);
  d3 = cbrt(d3);
  
  printf("%f\n",d1);
  printf("%f\n",d2);
  printf("%f\n",d3);
  printf("%f\n",dd);
  
  free(x);
  free(y);
  
  return(0);
}

Measured memory_bytes: 1100
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> da(n);
    for(int i=0;i<n;i++){
        cin >> da[i];
        da[i]-=i+1;
    }
    sort(da.begin(),da.end());
    long long mo=da[n/2],ans=0;
    for(int i=0;i<n;i++){
        ans+=(long long)abs(da[i]-mo);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        a[0] -= 1;
        for(int i=1; i<n; i++) {
          if(a[i]-1 >= a[i-1]) a[i]-=1;
          if(a[i] < a[i-1]) {
            out.println("No");
            out.close(); System.exit(0);
          }
        }
        // int n = Integer.parseInt(st.nextToken());
        out.println("Yes");
        out.close(); System.exit(0);
    }
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  int p = 0;
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    p += vec.at(i);
  }
  
  p = p * 10 / n;
  if (p % 10 >= 5)
    p = p / 10 + 1;
  else
    p = p / 10;
  
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int tmp = vec.at(i) - p;
    sum += tmp * tmp;
  }
  
  cout << sum << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
#define pb push_back
#define sort(x) sort((x).begin(), (x).end())
using ll = long long;
const int INF = 1e9+7;
const int EPS = -1e6;
inline void fastio() {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}
const int maxn = 100000+5;

int N,M;
set<int> ans;

void intersection(set<int> &des, const set<int> &src){
    set<int> t;
    for(auto itr = src.begin(); itr != src.end(); ++itr){
        if(des.find(*itr) != des.end())
            t.insert(*itr);
    }
    des = t;
}

int main(){
    //freopen("input.txt", "r", stdin);
    fastio();

    cin>>N>>M;
    vector<set<int>> pl;
    for(int i =0; i < N; ++i){
        int K; cin>>K;
        set<int>t;
        for(int j = 0;j < K; ++j){
            int a;
            cin>>a;
            t.insert(a);
        }
        pl.push_back(t);
    }

    for(int i = 1; i <= M; ++i)
        ans.insert(i);

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

    cout<<ans.size()<<endl;

    return 0;
}


Measured memory_bytes: 256
# your code goes here
N,M = map(int,input().split())

S = input()
T = input()

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

if gcd(N,M) == 1:
	if S[0]==T[0]:
		print(N*M)
	else:
		print(-1)
else:
	tmp = gcd(N,M)

	ans = True
	for i in range(tmp):
		if S[N//tmp*i] != T[M//tmp*i]:
			ans = False
	if ans == True:
		print(N * M // tmp)
	else:
		print(-1)

Measured memory_bytes: 3316
//
// Created by yuu on 2019-06-19.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;



int main(void){
    //std::cout<<std::fixed<<std::setprecision(10);

    while (1){
        int D,E;
        cin>>D>>E;
        if(D==0 && E==0){
            break;
        }

        double min = abs(sqrt(pow(D,2)) - E) + 10;
        for (int x = 0; x <= D; ++x) {
            int y = D - x;
            long long temp = pow(x,2) + pow(y, 2);
            double ru_to = sqrt(temp);
            double cost = abs(ru_to - E);

            if(cost < min){
                min = cost;
            }

        }

        //printf("%lf\n", min);

        cout<<min<<endl;

    }


    return 0;
}


Measured memory_bytes: 3260
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
	int N1 = (A1 - B1) * T1;
	int N2 = N1 + (A2 - B2) * T2;
	if (A1 == B1 || N2 == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	if (N1 < 0 && N2 < 0 || N1 > 0 && N2 > 0) {
		cout << 0 << endl;
		return 0;
	}
	if (N2 < 0) {
		N1 *= -1;
		N2 *= -1;
	}
	//cout << N1 << " " << N2 << endl;
	vector< int > knext;
	knext.push_back(N2);
	int ans = 0;
	while (1) {
		knext.push_back(knext[knext.size() - 1] * 2);
		if (knext[knext.size() - 1] > -N1)
			break;
	}
	//cout << knext.size() << endl;
	//cout << knext;
	int tmp = 0;
	for (int k = knext.size() - 1; k >= 0; k--) {
		if (tmp + knext[k] <= -N1) {
			ans += (1LL << k) * 2;
			tmp += knext[k];
		}
		//cout << k << " " << ans << endl;
	}
	//cout << endl;
	if (tmp != -N1)
		ans += 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    n, q = map(int, sys.stdin.readline().split())
    ds = [[i] for i in range(n)]
    n2s = [i for i in range(n)]
    ans = []

    for lp in range(q):
        c, x, y = map(int, sys.stdin.readline().split())

        if c == 0:
            merge(ds, n2s, x, y)
        else:
            ans.append(1 if n2s[x] == n2s[y] else 0)

    print(*ans, sep='\n')

def merge(ds, n2s, x, y):
    u = n2s[x]
    v = n2s[y]

    if u == v:
        return None

    if len(ds[u]) < len(ds[v]):
        ds[v].extend(ds[u])
        for w in ds[u]:
            n2s[w] = v
        del ds[u][:]
    else:
        ds[u].extend(ds[v])
        for w in ds[v]:
            n2s[w] = u
        del ds[v][:]

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 11272
object Main {

  import java.util.Scanner

  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    var str = scanner.next()
    var sum = 0
    val n = str.toInt

    str = scanner.next()
    val k = str.toInt
    str = scanner.next()
    val x = str.toInt
    str = scanner.next()
    val y = str.toInt
    if(k < n){
      sum = k * x + (n - k) * y
    } else {
      sum = n * x
    }

    println(sum)

  }
}

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

int main(){
  
  int N;
  cin >> N;
  
  string S = "Three";
  
  for(int i = 0; i < N; i++){
    string x;
    cin >> x;
    
    if(x == "Y"){
      S = "Four";
    }
   }
  
  cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll X;
    cin >> X;
    ll b, cnt;
    b = 100;
    cnt = 0;

    while (b < X){
        b += floor(b*0.01);
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3624
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for xi, yi, hi in all_input_list:
            if (hi != max(H - abs(cx - xi) - abs(cy - yi), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

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

/*
解説とかを参考に、次のようにすればよいことが分かった。

与えられた正の整数Nに対して、
u = a xor b
v = a  +  b, v <= N
となるような非負整数a,bが存在するような(u,v)の組が何通りあるかを数えたい。

a,bからu,vを計算するために筆算を行うことを考える：
(例)
a = 11010...
b = 10011...
すると、各桁ごとに、aとbのうちその桁が1であるようなものが何個(0,1,2)あるかのみを数えれば、
u,vは計算できることが分かる。

逆に、各桁ごとの1の個数を並べて得られる数列が異なるようなa,bの組に対しては、u,vも異なることが示せる(たぶん)。

したがって、「各桁ごとの1の個数を並べて得られる数列」であって、そこから和vを計算したときに、
vがN以下であるようなものの個数を数えればよい。そのために、この数列の値を上の桁から決めていくことにする。
このとき、決めた値とNが十分に離れていれば、それ以降はN以下という制約を気にしなくてもよい。
実際、下のi桁の和の最大値は、1111...11 + 1111...11 = 1111...110 (1がi個)であるから、
i+1桁目以上の部分において、Nのi+1桁目との差が2以上であれば、制約は気にしなくてもよいということになる。

したがって、どう数えればよいかというと、
a[i][j]を、「上からi桁までを決めたとき、
決めた分の上からi桁目で定まる値と、Nの上からi桁目までの値の差が、min(j,2)以上であるような決め方の総数」とする。

i番目まで決めたとき、差が2以上だったら、i+1番目はどうでもよいので、
a[i][2]　→　0,1,2どれでもa[i+1][2]
a[i][1] →　Nのi+1桁目が0→0ならa[i+1][2] 1ならa[i+1][1] 2ならa[i+1][0]
                        1→0ならa[i+1][2] 1ならa[i+1][2] 2ならa[i+1][1]
a[i][0] →　Nのi+1桁目が0→0ならa[i+1][0] 
                        1→0ならa[i+1][1] 1ならa[i+1][0]

により、Nのi+1桁目が0なら、
a[i+1][2] = a[i][2] + a[i][1]
a[i+1][1] = a[i][1] 
a[i+1][0] = a[i][0] + a[i][1]

Nのi+1桁目が1なら、
a[i+1][2] = a[i][2] + 2*a[i][1]
a[i+1][1] = a[i][1] + a[i][0]
a[i+1][0] = a[i][0] 

a[0][0] = 1, a[0][1] = a[0][2] = 0である。
この漸化式を使って順次計算していけばok。

最終的に、a[64][0] + a[64][1] + a[64][2]が答えである。
*/

/*
なんかたまに弾かれるなって思ったら割り算のmodを間違えていた…
*/

long long sum(long long a, long long b) {
	return (a + b) % 1000000007;
}

int main(void) {
	long long a[65][3];
	long long N,M;
	int i,j,p[64];
	long long ans;
	scanf("%lld", &N);
	M = N;
	for (i = 0; i < 64; i++) {
		p[63 - i] = M % 2;
		M = M / 2;
	}

	a[0][0] = 1; 
	a[0][1] = 0;
	a[0][2] = 0;
	for (i = 1; i < 65; i++) {
		if (p[i-1] == 0) {
			a[i][2] = (3*a[i - 1][2]+ a[i - 1][1]) % 1000000007;
			a[i][1] = a[i - 1][1];
			a[i][0] = (a[i - 1][0]+ a[i - 1][1]) % 1000000007;
		}
		else {
			a[i][2] = (3 * a[i - 1][2] + a[i - 1][1] + a[i - 1][1]) % 1000000007;
			a[i][1] = (a[i - 1][1]+ a[i - 1][0]) % 1000000007;
			a[i][0] = a[i - 1][0];
		}
		/*printf("p[%d] = %d, a[%d][0] = %lld\n	", i, p[i], i, a[i][0]);*/
	}

	ans = 0;
	ans = (a[64][0] + a[64][1] + a[64][2]) % 1000000007;

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



	return 0;
}

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

int main() {
	int a, b, c,x;
	cin >> a >> b >> c;
	if (a>b) {
		x = a;
		a = b;
		b = x;
	}
	if(b>c){
		x = b;
		b = c;
		c = x;
	}
	if (a>b) {
		x = a;
		a = b;
		b = x;
	}
	cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int sum1;
	int sum2;
	sum1=a*b;
	sum2=c*d;
	if(sum1>sum2)
	    printf("%d\n",sum1);
	else
	    printf("%d\n",sum2);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


LL iabs(LL n){
    if(n < 0) return -n;
    return n;
}

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    LL mid = a[(n-1)/2];
    LL total = 0;
    for(LL i = 0; i < n; ++i){
        total += iabs(a[i] - mid) * 2;
    }
    if(n % 2 == 0){
        cerr << "total2=" << total << endl;
        LL ans = total - iabs(mid - a[(n-1)/2+1]);
        cout << ans << endl;
    }else{
        cerr << "total1=" << total << endl;
        LL ans = max<LL>(total - iabs(mid - a[n/2-1]), total - iabs(mid - a[n/2+1]));
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t DP[100001];
int32_t func(int32_t n)
{
	if (n == 0) { return 0; }
	if (DP[n] != -1) { return DP[n]; }

	int32_t min = func(n - 1)+1;
	for (int32_t tmp = 6; tmp <= n; tmp *= 6)
	{
		min = std::min(min, func(n - tmp) + 1);
	}
	for (int32_t tmp = 9; tmp <= n; tmp *= 9)
	{
		min = std::min(min, func(n - tmp) + 1);
	}
	return DP[n] = min;
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);
	fill_all(DP, -1);
	in >> N;
	out << func(N) << endl;

	return 0;
}
#endif


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int n, m = 0;;
	bool f = 1;
	cin >> n;
	vector<int> h(n);
	//vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
		if (h.at(i) > m)m = h.at(i);
		if (m - h.at(i) >= 2)f = 0;
	}
	if (f == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3788
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		while (t-- > 0) {
			g = new char[12][6];
			ps = new boolean[12][6];
			for (int y = 0; y < 12; y++)
				g[y] = scanner.next().toCharArray();
			for (int i = 0;; i++) {
				boolean co = false;
				for (int j = 0; j < 12; j++) {
					Arrays.fill(ps[j], false);
				}

				for (int y = 0; y < 12; y++) {
					for (int x = 0; x < 6; x++) {
						step = 0;
						if (!cn(y, x, g[y][x]))
							continue;
						cr(y, x, g[y][x]);
						co = true;
					}
				}
				if (!co) {
					System.out.println(i);
					break;
				}
				for (int j = 0; j < 11; j++)
					for (int y = 0; y < 11; y++)
						for (int x = 0; x < 6; x++) {
							if (g[y][x] != '.' && g[y + 1][x] == '.') {
								char tmp = g[y][x];
								g[y][x] = g[y + 1][x];
								g[y + 1][x] = tmp;
							}
						}
			}
		}
	}

	private void cr(int y, int x, char p) {
		if (g[y][x] != p)
			return;
		g[y][x] = '.';
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!isOK(nx, ny))
				continue;
			if (g[ny][nx] == 'O') {
				g[ny][nx] = '.';
				continue;
			}
			cr(ny, nx, p);

		}
	}

	private boolean cn(int y, int x, char p) {
		if (p == 'O' || p == '.' || p != g[y][x] || ps[y][x])
			return false;
		step++;
		if (step == 4)
			return true;
		ps[y][x] = true;
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!isOK(nx, ny))
				continue;
			
			if (cn(ny, nx, p))
				return true;
		}
		return false;
	}

	private boolean isOK(int nx, int ny) {
		return 0 <= nx && nx < 6 && 0 <= ny && ny < 12;
	}
	int step;
	char[][] g;
	boolean[][] ps;
	int dx[] = { 1, 0, -1, 0 };
	int dy[] = { 0, 1, 0, -1 };

}

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

int main()
{
	while (1) {
	int a, b,ans;
	string o;
	
		cin >> a >> o >> b;
		if (o == "?" )break;
		if (o == "+") { ans = a + b; }
		else if (o == "-") { ans = a - b; }
		else if (o == "*") { ans = a * b; }
		else if (o == "/") { ans = a / b; }
		cout << ans << endl;
	}
    return 0;
}




Measured memory_bytes: 3144
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, c[1009], s[510009], t[510009], cnt[32777], sum[32777];
int main() {
	while (scanf("%d%d", &n, &m), n) {
		for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
		sort(c, c + n);
		int b = 0;
		for (int i = 0; i <= n; i++) {
			for (int j = i; j <= n && c[i] + c[j] <= m; j++) {
				s[b++] = c[i] + c[j];
			}
		}
		for (int i = 0; i < 30; i += 15) {
			fill(cnt, cnt + 32768, 0); sum[0] = 0;
			for (int j = 0; j < b; j++) cnt[(s[j] >> i) & 32767]++;
			for (int j = 0; j < 32768; j++) sum[j + 1] = sum[j] + cnt[j];
			for (int j = 0; j < b; j++) t[sum[(s[j] >> i) & 32767]++] = s[j];
			for (int j = 0; j < b; j++) s[j] = t[j];
		}
		int r = b - 1, ret = 0;
		for (int i = 0; i < b && i <= r; i++) {
			while (r > 0 && s[i] + s[r] > m) r--;
			ret = max(ret, s[i] + s[r]);
		}
		printf("%d\n", ret);
	}
	return 0;
}

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

public class Hello
{
    private const ulong MOD9 = 1000000007;

    public static void Main()
    {
        Console.ReadLine();

        var b = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
        var answer = new List<int>(b.Count);

        for (var count = b.Count; count > 0; --count)
        {
            var i = count - 1;
            for (; i >= 0; --i)
            {
                if (b[i] == i + 1)
                    break;
            }

            if (i < 0)
            {
                Console.WriteLine(-1);
                return;
            }

            answer.Add(i + 1);
            b.RemoveAt(i);

#if false
            Console.WriteLine("a : {0}", string.Join(",", answer.Select(_ => _.ToString()).ToArray()));
            Console.WriteLine("b : {0}", string.Join(",", b.Select(_ => _.ToString()).ToArray()));
            Console.WriteLine();
#endif

            continue;
        }

        for (var i = answer.Count - 1; i >= 0; --i)
            Console.WriteLine(answer[i]);
    }
}


Measured memory_bytes: 13268