akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(a int64, i int) string {
	return fmt.Sprintf("Case %v: %v", i + 1, a)
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

        i := 0
        for {
            a := nextInt()
            if a == 0 { break }
	    res := solve(a, i)
	    fmt.Fprintln(out, res)
            i = i +1
        }
}

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

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}



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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;
#define ll long long int

int main() {

	IOS

	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    Q,H,S,D = map(int, input().split())
    N = int(input())

    yen = 0
    A = [4*Q, 2*H, S]
    if D/2 < min(A):
        if N%2==0:
            return D * N//2
        else:
            return D*(N-1)//2 + min(A)
    else:
        return N * min(A)

if __name__ == '__main__':
    print(main())



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int to[N],n,x,cnt,ans;
map<int,int> Map;
int cmp(int x,int y){
	return x>y;
}
int main(){
	scanf("%d",&n);
	while (n--){
		scanf("%d",&x);
		if (!Map.count(x))to[++cnt]=x;
		Map[x]++;
	}
	sort(to+1,to+cnt+1,cmp);
	for (int i=1;i<=cnt;i++)
		for (int j=0;j<=30;j++)
			if ((1<<j)>to[i])while (Map[to[i]]>0&&Map[(1<<j)-to[i]]>0){
				if (to[i]*2==(1<<j)&&Map[to[i]]==1)break;
				Map[to[i]]--,Map[(1<<j)-to[i]]--,ans++;
			}
	printf("%d\n",ans);
}


Measured memory_bytes: 29824
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long LL;

// count # (<= X)
LL check(const LL N, const LL X){
    LL right = N;
    LL p2 = 1;
    LL res = 0;
    // printf("n = %lld x = %lld\n", N, X);
    while(right > 2){
        // [left, right]
        LL left = right / 3 + 1;
        if(left <= 2) left = 3;

        // [left, mid] (mid, right]
        LL mid = X / p2;
        if(mid > right) mid = right;
        // printf("left = %lld mid = %lld right = %lld\n", left, mid, right);

        // [left, mid]のうち奇数の個数
        if(left % 2 == 0) left++;
        if(mid % 2 == 0) mid--;
        if(left <= mid){
            res += (mid - left) / 2 + 1;
        }

        right = right / 3;
        p2 *= 2;
    }
    if(p2 <= X) res++;

    // printf("-> %lld\n\n", res);
    return res;
}

LL solve(LL N, LL K){
    if(K > (N + 1) / 2) return -1;
    if(N % 2 == 0) N--;
    LL lb = 0;
    LL ub = N;
    while(ub - lb > 1){
        LL x = (ub + lb) / 2;
        if(check(N, x) >= K){
            ub = x;
        }else{
            lb = x;
        }
    }
    return ub;
}
LL f(LL x, LL n){
    LL q = x;
    LL p2 = 1;
    while(3 * x <= n){
        x *= 3;
        p2 *= 2;
    }
    return q * p2;
}
LL solve2(LL N, LL K){
    if(N <= 2){
        if(K == 1) return 1;
        else return -1;
    }
    if(N % 2 == 0) N --;
    vector<LL> v;
    v.push_back(f(2, N));
    for(LL i = 3; i <= N; i += 2){
        v.push_back(f(i, N));
    }
    sort(v.begin(), v.end());
    if(v.size() < K) return -1;
    return v[K - 1];
}
vector<vector<int>> max(int n){
    int max_l = 0;
    vector< vector<int> > res;
    REP(s, 1 << (n - 1)){
        vector<int> v;
        REP(i, n - 1) if(s >> i & 1){
            v.push_back(i + 2);
        }
        bool ok = true;
        REP(i, v.size()) REP(j, i) if(v[i] % v[j] == 0) ok = false;
        if(ok){
            if(max_l < v.size()) {
                max_l = v.size();
                res.clear();
            }
            if(max_l == v.size()){
                res.push_back(v);
            }
        }
    }
    return res;
}
LL solve3(LL N, LL K){
    cout << N << " " << K << endl;
    if(N <= 2) {
        if(K == 1) return 1;
        else return -1;
    }
    vector<vector<int>> res = max(N);
    if(res[0].size() < K) return -1;
    return res[0][K - 1];
}

int main(){
    int C;
    cin >> C;
    while(C--){
        LL N, K;
        scanf("%lld %lld", &N, &K);
        printf("%lld\n", solve(N, K));
    }
    // for(int n = 1; n < 25; n++){
    //     for(int k = 1; k <= n; k++){
    //         printf("n = %d k = %d\n", n, k);
    //         LL x = solve(n, k);
    //         LL y = solve3(n, k);
    //         printf("x = %lld y = %lld\n", x, y);
    //         if(x != y){
    //             assert(false);
    //         }
    //     }
    // }
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	string a,b; cin >> a >> b;
	string s = a + b;
	int ansN = stoi(s);

	bool isSquare = false;

	for (int i = 0; i < 400; ++i)
	{
		if(i*i == ansN) isSquare = true;
	}

	if(isSquare) cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
using System;

namespace _014_Integral
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int width = int.Parse (inputStr);
				int sum = 0;

				for (int x = width; x < 600; x += width)
				{
					sum += x * x * width;
				}

				Console.WriteLine (sum);
			}
		}
	}
}

Measured memory_bytes: 8920
import java.util.*;

class Main{	
	public static void main(String[] args){
    
    	Map<String,String> tommorowWeatherMap = new HashMap<String, String>(){
        	{
            	put("Sunny", "Cloudy");
                put("Cloudy", "Rainy");
                put("Rainy", "Sunny");
            }
        };
    	Scanner sc = new Scanner(System.in);
        String todayWeather = sc.next();
        System.out.println(tommorowWeatherMap.get(todayWeather));
    }
}


Measured memory_bytes: 19796
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007LL
#define eps 1e-8

using namespace std;

ll a[100005];

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	ll n,m,v,p; cin>>n>>m>>v>>p;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	int l=0,r=n-p,k;
	while(l<r){
		k=(l+r)>>1;
		ll tot=(v-1)*m,cur=0;
		priority_queue<int> pq;
		for(int i=0;i<n;i++){
			if(i==k) continue;
			if(a[k]+m<a[i]) tot-=m,cur++;
			else{
				ll tmp=min(m,a[k]+m-a[i]);
				tot-=tmp; pq.push(m-tmp);
			}
		}
		while(tot>0){
			cur++; tot-=pq.top(); pq.pop();
		}
		if(cur>=p) l=k+1;
		else r=k;
	}
	cout<<n-l<<"\n";
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll A[101010];
const ll mo=1000000007;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	ll ret=0;
	FOR(i,N) {
		ret+=A[i]*comb(i,K-1)%mo;
		ret-=A[i]*comb(N-1-i,K-1)%mo;
		ret=(ret%mo+mo)%mo;
	}
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 10368
/*
 * main.cpp
 *
 *  Created on: 2017/05/14
 *      Author: YamajiTakashi
 */

#include <iostream>
#include <string>
#include <stdint.h>
using namespace std;

void print_seq(int32_t *seq_, int32_t len_) {
	string str = "";
	for (int32_t i = 0; i < len_ ; i++) {
		str += to_string(seq_[i]) + ' ';
	}
	str.erase(--str.end());
	cout << str << endl;
}

void insertionSort(int32_t *seq_, int32_t len_) {
	for (int32_t i = 1; i < len_; i++) {
		int32_t v = seq_[i];
		int32_t j = i - 1;
		while(j >= 0 && seq_[j] > v) {
			seq_[j+1] = seq_[j];
			j--;
		}
		seq_[j+1] = v;
		print_seq(seq_, len_);
	}
}

int main(void) {
	uint32_t N;
	cin >> N;
	int32_t *A = new int32_t[N];

	for (int32_t i = 0; i < N; i++) {
		cin >> A[i];
	}

	print_seq(A, N);
	insertionSort(A, N);
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	auto xs = loadMany<int>(n);
	auto dyn = vector<int>(n, 0);
	for (auto i=1; i<n; ++i)
		dyn[i] = min(dyn[i-1] + abs(xs[i]-xs[i-1]), i > 1 ? dyn[i-2] + abs(xs[i]-xs[i-2]) : numeric_limits<int>::max());
	cout << dyn[n-1] << '\n';
	/* yoyo */
}


Measured memory_bytes: 1024
N, T = map(int, input().split())
t = list(map(int, input().split()))
sum = 0
for i in range(N-1):
    if t[i + 1] - t[i] < T:
        sum += t[i + 1] - t[i]
    else:
        sum += T
sum += T
print(sum)


Measured memory_bytes: 26708
#include <iostream>

using namespace std;

int main() {

	int n, y;

	cin >> n >> y;

	for(int i=0;i<=n;i++){
		int k;
		k=n-i;
		for(int j=0;j<=n-i;j++){
			if((i*10000+j*5000+k*1000) == y){
				cout << i << " " << j << " " << k << endl;
						return 0;
			}
			k--;
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int n, cnt=0;
int nums[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n) cin>>nums[i],nums[i]--;
    rep(i,n){
        if(i==nums[nums[i]]) cnt++;
    }
    cout1(cnt/2)
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int ans=753;
int main()
{
  	string s;
  	cin>>s;
  	for(int i=0;i<s.size()-2;i++)
	{
    	int S;
    	int min;
    	S=stoi(s.substr(i,3));
    	min=753-S;
    	if(min < 0) min*=-1;
    	if(min<ans) ans=min;
  	}
  	printf("%d\n",ans);
  	return 0;
}

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

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}}
    return C[n][k];
 }

ll gcd(ll a, ll b){if (b == 0)
        return a;return gcd(b, a % b);}

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}


int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
// code now
   
    string s,t;
    cin>>s>>t;
    ll n=s.size(),k=t.size();
    s=" "+s;
    t=" "+t;
    ll a[n+1][k+1];
    fori(n+1){a[i][0]=0;}
    fori(k+1) a[0][i]=0;
    char d[n+1][k+1];
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=k;j++){
            if(s[i]==t[j]){
                d[i][j]='D';
                a[i][j]=a[i-1][j-1]+1;
            }else{
                d[i][j]='U';
                a[i][j]=a[i-1][j];
                if(a[i-1][j]<a[i][j-1]){
                    d[i][j]='L';
                                   a[i][j]=a[i][j-1];
                }
            }
        }
    }
    
    string sl;
    ll i=n,y=k;
    while(i>=1&&y>=1){
        if(d[i][y]=='D'){sl.push_back(s[i]);i--;y--;}
        else{
            if(d[i][y]=='U'){i--;}
            else{y--;}
        }
    }
    reverse(sl.begin(), sl.end());
    cout<<sl;
    
//code ends
    return 0;
}


Measured memory_bytes: 79488
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long ll;
using namespace std;

int main() {
	int n, l[2000];
	cin >> n;
	rep(i, n)cin >> l[i];
	sort(l, l + n);

	int sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = n - 1; k > j; k--) {
				bool flag = true;
				if (l[i] >= l[j] + l[k]) {
					flag = false;
					break;
				}
				if (l[j] >= l[k] + l[i]) {
					flag = false;
					break;
				}
				if (l[k] >= l[i] + l[j]) {
					flag = false;
				}
				if (flag)sum++;
			}
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>


using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
int N,M;
pair<int,int> A[202];
pair<int,int> DIFFA[202];
pair<int,int> B[1002];


int main(){
	while(1){
		scanf("%d",&N);
		if(N==0)break;
		rep(i,N){
			scanf("%d %d",&A[i].first,&A[i].second);
			DIFFA[i].first=A[i].first-A[0].first;
			DIFFA[i].second=A[i].second-A[0].second;
		}
		scanf("%d",&M);
		rep(i,M){
			scanf("%d %d",&B[i].first,&B[i].second);
		}
		int ans=-1;
		rep(i,M){
			rep(j,N){
				if(j==0)continue;
				int x=B[i].first+DIFFA[j].first;
				int y=B[i].second+DIFFA[j].second;
				bool s=false;
				rep(k,M){
					if(B[k].first==x&&B[k].second==y){s=true;break;}
				}
				if(!s)break;
				if(j==N-1){ans=i;break;}
			}
		}
		printf("%d %d\n",B[ans].first-A[0].first,B[ans].second-A[0].second);
	}
}

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



int main()
{
    ll n;
    cin >> n;
    ll arr[n - 1];
    for(ll i = 0;i < n - 1;i++) cin >> arr[i];
    ll boss[n + 1];
    for(ll i = 0;i < n + 1;i++)
    {
        boss[i] = 0;
    }
    for(ll i = 0;i < n - 1;i++)
    {
        boss[arr[i]] += 1;
    }
    for(ll i = 1;i < n + 1;i++)
    {
        cout << boss[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6720
#include<stdio.h>
#define MAX 100005
#define NIL -1


typedef struct{
  int p;
  int l;
  int r;
}node;

  node T[MAX];
int n,D[MAX];

void disp(int u){

  int i,c;

  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else{printf("internal node, ");}

  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }

  printf("]\n");
  }

int deps(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL)deps(T[u].r,p);
  if(T[u].l!=NIL)deps(T[u].l,p+1);
  return 1;
}
 
int main(){

  int i,j,d,v,c,l,r;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL;
  }

  for(i=0;i<n;i++){

    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){

      scanf("%d",&c);

      if(j==0)T[v].l=c;
      else {T[l].r=c;}
      l=c;
      T[c].p=v;

    }
  }

  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }

  deps(r,0);

  for(i=0;i<n;i++){
    disp(i);
  }

  return 0;

}
  



Measured memory_bytes: 6412
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#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 <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;

map<ll,ll> primefactor(ll n){
  map<ll,ll> res;
  for( ll i=2LL ;i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}



int main(){
  ll n;
  cin>>n;
  ll now=0LL;
  for(ll i=1;i<100000000;i++){
    now+=i;
    if(now>=n){cout<<i<<endl;return 0;}
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;

constexpr int64_t num = 1000000000000001;
constexpr int64_t radix = 26;

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


    int64_t n;
    cin >> n;

	string output;
	int64_t tmp;
	while(1){
		--n;
		tmp = n % radix;
		n /= radix;
		output = (char)('a' + tmp) + output;
		if(n == 0){
			break;
		}

	}
	cout << output << "\n";
    
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> T(N);
	for (int i = 0; i < N; ++i) {
		cin >> T[i];
	}
	int M;
	cin >> M;
	vector<int> P(M), X(M);
	for (int i = 0; i < M; ++i) {
		cin >> P[i] >> X[i];
	}

	int total = accumulate(T.begin(), T.end(), 0);
	for (int i = 0; i < M; ++i) {
		cout << total - T[P[i] - 1] + X[i] << endl;
	}
}


Measured memory_bytes: 256
N = int(input())
A = [None] + [int(i) for i in input().split()]
ans = []
choose = [0] * (N+1)

for n in range(N, 0, -1):
  x = sum(choose[2*n::n])
  if x % 2 == A[n]:
    continue
  choose[n] += 1  
  ans.append(str(n))

print(len(ans))
print(' '.join(ans))

Measured memory_bytes: 17220
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int input_num = sc.nextInt();
        String match_msg = sc.next();

        if(3200 <= input_num){
            System.out.println(match_msg);
        }else{
            System.out.println("red");
        }
    }
}


Measured memory_bytes: 23252
import collections
from collections import deque
import sys
input = sys.stdin.readline
 
def bfs(s):
    d = deque()
    d.append(s)
    dis[s]=0
    flag=True
    while len(d):
        x = d.popleft()
        for i,j in vec[x]:
            if dis[i] == INF:
                dis[i]=dis[x]+j
                d.append(i)
 
            else:
                if dis[i]==dis[x]+j:
                    continue
                else:
                    print('No')
                    exit()
    return flag
 
 
n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
vec= [[] for i in range(n)]
 
for i in range(m):
    vec[a[i][0]-1].append((a[i][1]-1,a[i][2]))
    vec[a[i][1]-1].append((a[i][0]-1,-a[i][2]))
 
INF=float('inf')
dis=[INF]*n
 
for i in range(n):
    if dis[i]==INF:
        bfs(i)
print('Yes')

Measured memory_bytes: 109956
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

/* example
    int n=scc.scc();
    scc.build(n,g);
    (g:outside)
*/
struct SCC{
    vector<int> used,cmp,vs;
    vector<vector<int>> ori;
    vector<vector<int>> v,rv;
    SCC(){}
    SCC(int n):used(n),cmp(n,-1),v(n),rv(n){}
 
    void add_edge(int x,int y){
        v[x].push_back(y);
        rv[y].push_back(x);
    }
    void dfs(int x){
        used[x]=true;
        for(auto to:v[x]) if(!used[to]) dfs(to);
        vs.push_back(x);
    }
 
    void rdfs(int x,int k){
        cmp[x]=k;
        for(auto to:rv[x]) if(cmp[to]==-1) rdfs(to,k);
    }
 
    int scc(){
        for(int i=0;i<used.size();i++) if(!used[i]) dfs(i);
        reverse(vs.begin(),vs.end());
        int k=0;
        for(auto x:vs) if(cmp[x]==-1) rdfs(x,k++);

        ori.resize(k);
        for(int i=0;i<used.size();i++) ori[cmp[i]].push_back(i);

        return k;//k:size
    }

    void build(int k,vector<vector<int>> &g){
        g.resize(k);
        for(int i=0;i<v.size();i++){
            for(auto to:v[i]){
                int x=cmp[i],y=cmp[to];
                if(x!=y) g[x].push_back(y);
            }
        }
    }
};

// depends on SCC
// !x:2*x, x:2*x+1
struct two_SAT{
    int N;
    SCC graph;
    vector<bool> answer;

    two_SAT(){}
    two_SAT(int n):N(n),graph(2*N),answer(N){}

    void add_edge(int i,bool f,int j,bool g){
        graph.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
        graph.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
    }
    
    bool satisfiable(){
        int K=graph.scc();
        auto ids=graph.cmp;
        for(int i=0;i<N;++i){
            if(ids[2*i]==ids[2*i+1]) return false;
            answer[i]=(ids[2*i] < ids[2*i+1]);
        }
        return true;
    }

    vector<bool> getAnswer(){
        return answer;
    }
};

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

  int N;
  ll D;
  cin>>N>>D;
  vector<ll> X(N),Y(N);
  rep(i,N) cin>>X[i]>>Y[i];

  two_SAT sat(N);
  for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
      if(abs(X[i]-X[j])<D) sat.add_edge(i,false,j,false);
      if(abs(X[i]-Y[j])<D) sat.add_edge(i,false,j,true);
      if(abs(Y[i]-X[j])<D) sat.add_edge(i,true,j,false);
      if(abs(Y[i]-Y[j])<D) sat.add_edge(i,true,j,true);
  }

  if(sat.satisfiable()==false){
      cout<<"No"<<endl;
      return 0;
  }

  cout<<"Yes"<<"\n";
  vector<bool> ans=sat.getAnswer();
  rep(i,N){
      if(ans[i]) cout<<X[i]<<"\n";
      else cout<<Y[i]<<"\n";
  }

  return 0;
}


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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long num1, num2;
  num1 = N / (A + B);
  num2 = N % (A + B);
  if (num2 >= A) {
    cout << (num1 + 1) * A;
  }
  else {
    cout << num1 * A + num2;
  }
}

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

int main(){
    int n; cin>>n;
    vector<int> c(100005,0);
    for(int i=0;i<n;i++){
        int a; cin>>a;
        c[a]++;
    }

    int ans=0;
    for(int i=0;i<=100000;i++){
        if(i) ans=max(ans,c[i-1]+c[i]+c[i+1]);
        else ans=max(ans,c[i]+c[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int val,n;
cin>>val>>n;
int ans=0;
while(n--)
{int x;
cin>>x;
    ans+=x;
}
if(ans>val)
{
    cout<<-1<<endl;
}
else
{
    cout<<val-ans<<endl;
}
    return 0;
}


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

using namespace std;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
typedef pair<int, int> ii;

int f[maxn][2], n;
vector<int> a[maxn];

int dp(int u, int color, int p = -1)
{
    int &res = f[u][color];
    if (res != -1) return res;
    res = 1;
    vector<int> F;
    for(int v: a[u])  if (v != p)
        F.push_back((color*dp(v, 0, u) + dp(v, 1, u)) % mod);
    for(int v: F) res = (1LL * res * v) % mod;
    return res;
}

int main()
{
    #ifdef NTMA 
        freopen("abc.inp", "r", stdin);
    #endif
    memset(f, 255, sizeof(f));
    cin >> n;
    for(int i=1; i<n; ++i){
        int u, v; cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    cout << (dp(1, 0) + dp(1, 1)) % mod << endl;   
    return 0;
}

Measured memory_bytes: 19072
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int h[21];

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

    int hmin;
    hmin = h[0];
    int ans = 1;
    for(int i=1; i<n; i++){
        if(hmin <= h[i]){
            ans++;
            hmin = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    T = input()
    N = len(S)

    def check(S, T):
        b = {s for s in S}
        for t in T:
            if t not in b:
                return True  # -1
        return False

    def is_ok(mid, now, ans):
        if ans < now[mid]:
            return True
        else:
            return False

    def binary_search_meguru(now, ans):
        ng = -1
        ok = len(now)-1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid, now, ans):
                ok = mid
            else:
                ng = mid
        return now[ok]

    if check(S, T):
        return print(-1)

    from string import ascii_lowercase

    dic = {a: [] for a in ascii_lowercase}
    for i, s in enumerate(S):
        dic[s].append(i+1)
    ans = 0
    cycle = 0
    for t in T:
        now = dic[t]
        if now[-1] <= ans:
            cycle += 1
            ans = 0
        idx = binary_search_meguru(now, ans)
        ans = idx
    print(ans + N*cycle)


if __name__ == '__main__':
    main()


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

int main(){
    int H,W;
    //複数のデータがあるので1個やったらまたもうひとつやらなきゃいけないのでbreakまで回す。
    while(1){
        cin >> H >> W ;
        //HとWがともに0となるときに限り、プログラムを終了する。
        if(H == 0 && W == 0){
            break;
        }else{
            //中のfor文をH回繰り返す。
            for(int i=0;i<H;i++){
                //W個＃を横に並べた。
                for(int k=0;k<W;k++){
                    if(i == 0 || i == H-1 || k == 0 || k == W-1){
                        cout << "#" ;
                    }else{
                        cout << "." ;
                    }
                }
                //W番目のところで改行した。
                cout << endl;
            }
        }
        //新たな図形との間に空白をつくった。
        cout << endl;
    } 
    return 0;
}




Measured memory_bytes: 2996
#include<iostream>
#include<vector>

void print(int len, std::vector<int>& v)
{
    for(int i=0;i<len;++i)
    {
        std::cout << v[i];
        if(i!=len-1)
        {
            std::cout<< " ";
        }
    }
    std::cout << '\n';
}

void insertion_sort(int len, std::vector<int>& v)
{
    print(len, v);
    int key;
    for(int i=1;i<len;++i)
    {
        key = v[i];
        int j = i - 1;
        for(;j>=0;--j)
        {
            if(key<v[j])
            {
                v[j+1] = v[j];
            }
            else
            {
                break;
            }
        }
        v[j+1] = key;
        print(len, v);
        
    }
}

int main()
{
    std::vector<int> v;
    int len;
    int value;
    std::cin >> len;
    for(int i=0;i<len;++i)
    {
        std::cin >> value;
        v.push_back(value);
    }
    
    insertion_sort(len, v);
    
    return 0;
}


Measured memory_bytes: 3108
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include <cstdlib>
#include <cstring>
#include<iostream>

using namespace std;

int main(){
	char s[3];
	int a = 0, b = 0, c = 0;
	scanf("%s", s);
	for (int i = 0; i < 3; i++){
		if (s[i] == 'a'){
			a++;
		}
		else if (s[i] == 'b'){
			b++;
		}
		else{
			c++;
		}
	}
	if (a*b*c == 1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
int main( void ){
	int N, M; cin >> N >> M;
	vector<vector<bool>> Nm(N, vector<bool>(N)), Mm(M, vector<bool>(M));
	rep(i,0,N){
		rep(j,0,N){
			char c; cin >> c;
			Nm[i][j] = (c == '.');
		}
	}
	rep(i,0,M){
		rep(j,0,M){
			char c; cin >> c;
			Mm[i][j] = (c == '.');
		}
	}
	rep(i,0,N-M+1){
		rep(j,0,N-M+1){
			bool is_correct = true;
			rep(x, 0, M){
				rep(y, 0, M){
					if (Nm[i+x][j+y] != Mm[x][y])
						is_correct = false;
				}
			}
			if (is_correct){
				cout << "Yes\n" << endl;
				return 0;
			}
		}
	}
	cout << "No\n" << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main(void) {
  int h, w;
  cin >> h >> w;
  char c[h][w];
  rep(i,h) {
    rep(j,w) {
      cin>> c[i][j];
    }
  }
  rep(i,h) {
    rep(j,w) {
      cout << c[i][j];
    }
    cout << endl;
    rep(j,w) {
      cout << c[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct{int x,y;}point;
int main(){
    int n,x,y,del=-1,max_y=-1,ans=0;
    cin>>n;
    vector<point>a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
    sort(a.begin(),a.end(),[](const point& a,const point& b){return a.x!=b.x?a.x<b.x:a.y<b.y;});
    for(int i=0;i<n;i++)cin>>b[i].x>>b[i].y;
    sort(b.begin(),b.end(),[](const point& a,const point& b){return a.x!=b.x?a.x<b.x:a.y<b.y;});
    for(int i=0;i<n;del=max_y=-1,i++){
        for(int j=0;j<a.size();j++)if(a[j].x<b[i].x&&a[j].y<b[i].y&&max_y<a[j].y)max_y=a[j].y,del=j;
        if(del>=0){a.erase(a.begin()+del);ans++;}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#define inf pow(10, 9)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  ll X;
  ci(X);
  ll c = 100;
  int a = 0;
  wh(true){
    a ++;
    c *= 1.01;
    if(c >= X){
      co(a);
      rt 0;
    }
  }
}

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

int main(){
  int D,G;
  int i;

  cin>>D>>G;

  vector<int> p(D);
  vector<int> c(D);

  for(i=0;i<D;i++)
  cin>>p.at(i)>>c.at(i);
  // for(i=0;i<D;i++)
  // cout<<p.at(i)<<" "<<c.at(i)<<endl;

  int sum,cnt;
  int min=0;
  bool hand=false;
  for(i=0;i<D;i++)
  min+=p.at(i);

  for(int bit=0;bit<(1<<D);bit++){
    hand=false;
    sum=0;
    cnt=0;
    for(i=0;i<D;i++){
      if(bit&(1<<D-1-i)){
        // if(bit==16){
        //   cout<<i<<endl;
        // }
        sum+=(100*(D-i)*p.at(D-1-i)+c.at(D-1-i));
        cnt+=p.at(D-1-i);
      }
    }
    // if(bit==16)
    // cout<<"kita "<<sum<<" "<<cnt<<endl;
    if(sum>=G){
      // cout<<bitset<8>(bit)<<endl<<"only bo-nasu"<<sum<<" "<<cnt<<endl;
      if(min>cnt)
      min=cnt;
    }
    else{
      for(i=0;i<D;i++){
        // if(bit==16)
        // cout<<"simasu "<<bitset<8>(bit)<<endl;
        if(!(bit&(1<<D-1-i))){
          // if(bit==16)
          // cout<<"ahha----n"<<endl;
          for(int j=1;j<p.at(D-1-i);j++){
            sum+=100*(D-i);
            cnt++;
            // if(bit==16)
            // cout<<"kita "<<sum<<" "<<cnt<<endl;
            if(sum>=G){
              // cout<<bitset<8>(bit)<<endl<<sum<<" "<<cnt<<endl;
              if(min>cnt)
              min=cnt;
              hand=true;
              break;
            }
          }
        }
        // if(bit==16)
        // cout<<"tsugi"<<endl;
        if(hand==true)
         break;
      }
    }
  }

  cout<<min<<endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio> 
#include <algorithm>
#include <cstdlib> 
#include <cstring>
#include <bitset>
using namespace std;

//?意：
//有一个??器可以?r行c列的煎?，煎?可以正面朝上（用1表示）也可以背面朝上（用0表示）。
//一次可将同一行或同一列的煎?全部翻?。?在需要把尽可能多的煎?翻成正面朝上，?最多能使多少煎?正面朝上？?
//?入：
//多??入，??第一行?二整数r, c (1 ? r ? 10, 1 ? c ? 10 000)，剩下r行c列表示煎?初始状?。r=c=0表示?入?束。?
//?出：
//?于???入，?出最多能使多少煎?正面朝上。 


//思路：
//??上下翻的?首先想到bitset（flip功能），把?个煎?当成二?制数中的一位 
//由于翻?同?的行和列?，翻??序?煎?的最?朝向没有影?，所以可以先判断所有的横行是否翻?，然后求出??横行翻法??的煎?朝上数的最大?。
//?了得到最大?，希望?个?行在翻?后朝上的煎?数都?加，否?不翻?。
//最后?比??横行翻法的最大?，从中取最大?就是答案 

bitset<10000> cookie[10];
int r,c,i,j,ans,result,up;

int max(int a,int b)
{
	return a>b?a:b;
}

void dfs(int k)
{
	if(k==r){
		result=0;
		for(i=0;i<c;i++){
			up=0;
			for(j=0;j<r;j++){
				if(cookie[j][i])  up++;
			}
			result+=max(up,r-up);
		}
		ans=max(ans,result);
		return;
	}
	dfs(k+1);
	cookie[k].flip();
	dfs(k+1);
 } 

int main()
{
	while(scanf("%d %d",&r,&c) && r && c){
		getchar();
		ans=0; 
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				bool a; 
				cin>>a;
				getchar();
				cookie[i][j]=a;
			}
		}
		ans=0;
		dfs(1);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>

using namespace std;

void solve(int N, int M, int S) {
    int dp[2][M+1][S+1];

    dp[0][0][0]=0;
    dp[1][0][0]=0;
    for(int j=1; j<=M; ++j) {
        dp[0][j][0]=0;
        dp[1][j][0]=0;
        for(int k=1; k<=S; ++k) {
            dp[1][j][k]=(k<=j?1:0);
            dp[0][j][k]=0;
        }
    }
    for(int i=2; i<=N*N; ++i) {
        dp[i%2][0][0]=0;
        for(int j=1; j<=M; ++j) {
            for(int k=1; k<=S; ++k) {
                if(i>j) dp[i%2][j][k]=0;
                else if(k<i*(i+1)/2) dp[i%2][j][k]=0;
                else if(k-j<=0) dp[i%2][j][k]=dp[i%2][j-1][k];
                else dp[i%2][j][k]=dp[i%2][j-1][k]+dp[(i-1)%2][j-1][k-j];
                dp[i%2][j][k]%=100000;
            }
        }
    }

    cout << dp[(N*N)%2][M][S] << endl;

    return;
}

int main() {
    int N,M,S;
    while(true) {
        cin >> N >> M >> S;
        if(N==0 && M==0 && S==0) break;
        solve(N,M,S);
    }
    return 0;
}


Measured memory_bytes: 49944
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <cassert>
#include <utility>

using namespace std;

typedef pair<int, int> P;

#define mp(a,b) make_pair(a,b)
#define DEBUG(x) cerr<<#x<<":"<<x<<endl;

int W, H;
int SX, SY, GX, GY;

int field[100][100];

inline bool inRange(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}

void setBlock(int c, int d, int x, int y) {
	if(d == 0) {
		for(int dy = 0; dy < 2; dy++) {
			for(int dx = 0; dx < 4; dx++) {
				field[x + dx][y + dy] = c;
			}
		}
	}
	else if(d == 1) {
		for(int dy = 0; dy < 4; dy++) {
			for(int dx = 0; dx < 2; dx++) {
				field[x + dx][y + dy] = c;
			}
		}
	}
	else
		assert(false);
}

void pv() {
	cerr << endl;
	cerr << "-----" << endl;
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < H; x++)
			cerr << field[x][y];
		cerr << endl;
	}
	cerr << "-----" << endl;
}

bool visit[100][100];

int main() {
	for(; cin >> W >> H, W || H;) {
		cin >> SX >> SY >> GX >> GY;
		SX--, SY--, GX--, GY--;

		memset(field, 0, sizeof field);
		memset(visit, 0, sizeof visit);
		
		int N; cin >> N;
		for(int i = 0; i < N; i++) {
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			x--, y--;
			setBlock(c, d, x, y);
		}

		queue<P> Q;
		Q.push(mp(SX, SY));
		visit[SX][SY] = true;

		int C = field[SX][SY];

		bool f = false;
		while(!Q.empty()) {
			P p = Q.front(); Q.pop();
			if(p.first == GX && p.second == GY) {
				f = true;
				break;
			}
			for(int i = 0; i < 4; i++) {
				int dx[4] = {1, 0, -1, 0};
				int dy[4] = {0, 1, 0, -1};
				int nx = p.first + dx[i];
				int ny = p.second + dy[i];
				if(inRange(nx, ny) && field[nx][ny] == C && visit[nx][ny] == false) {
					visit[nx][ny] = true;
					Q.push(mp(nx, ny));
				}
			}
		}

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

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> c(N);
    int a[12][12];

    for(int i=0; i<N; i++){
        cin >> c[i];
        for(int j=0; j<M; j++){
            cin >> a[i][j];
        }
    }

    int ans = 2147483647;
    for(int bit=0; bit < (1<< N); bit++){
        int cost = 0;
        vector<int> d(M);
        for(int i=0; i<N; i++){ // 各桁について
            if (bit & (1 << i) ){ // 1が立っていれば
                cost += c[i];
                for(int j=0; j<M; j++){
                    d[j] += a[i][j];
                }
            }
        }

        bool ok = true;
        for(int i=0; i<M; i++){
            if(d[i]<X) ok = false;
        }

        if(ok){
            ans = min(ans,cost);
        }
    }

    if(ans == 2147483647){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }

}


Measured memory_bytes: 3632
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    X = int(input())
    
    res = 1000 * (X // 500)
    X = X % 500
    res += 5 * (X // 5)

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 66028
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
const int M=1e5+5;
vi adj[M];
int dfs(int v,int p=0){
	int ret=0;
	for(int u:adj[v]) if(u!=p) ret^=(dfs(u,v)+1);
	return ret;
}
int32_t main()
{
	int n; cin>>n;
	for(int i=1;i<n;i++){
		int u,v; cin>>u>>v;
		adj[u].pb(v),adj[v].pb(u);
	}
	return cout<<(dfs(1)?"Alice":"Bob")<<endl,0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include <algorithm>
#include <numeric>
using namespace std;
# define maxh 50
# define maxw 50
# define maxn 100000
using ll = long long;
int main() {
  int H,W;
  char s[maxh][maxw];
  cin>>H>>W;
  for (int h(0);h<H;h++)
    for (int w(0);w<W;w++)
      cin>>s[h][w];

  for (int h(0);h<H;h++){
    for (int w(0);w<W;w++){
      if (s[h][w]=='#'){
        char ue = (h==0)? '.' : s[h-1][w];
        char sita = (h==H-1)? '.' : s[h+1][w];
        char left = (w==0)? '.' : s[h][w-1];
        char right = (w==W-1)? '.' : s[h][w+1];
        if (ue!='#' && sita!='#' && left!='#' && right!='#'){
          cout<< "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <cstring>

#define loop(i, num)  for (int i = 0; i < num; i++)

using namespace std;

long long n, ans, c[4];

int main() {
    
    loop (i, 4) {
        
        cin >> c[i];
        
    }
    
    cin >> n;
    
    for (int i = 1; i < 4; i++) {
        
        c[i] = min(c[i], c[i - 1] * 2);
        
//        cout << c[i] << ' ';
        
    }
    
//    cout << endl;
    
    ans = (n / 2 * c[3]) + (n % 2 ? c[2]: 0);
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), T = sc.nextInt();
        int food[][] = new int[N][2];
        for(int i=0;i<N;i++){
            food[i][0]=sc.nextInt();//time
            food[i][1]=sc.nextInt();//delicious
        }
        sc.close();
        int dp[][] = new int[N+1][T+1];
        for(int i=0;i<N;i++){
            for(int j=0;j<T+1;j++){
                int time = food[i][0], deli = food[i][1];
                if(j>=time){
                    dp[i+1][j]=Math.max(dp[i][j],dp[i][j-time]+deli);
                }else{
                    dp[i+1][j]=dp[i][j];
                }
            }
        }

        int dp2[][] = new int[N+1][T+1];
        for(int i=0;i<N;i++){
            for(int j=0;j<T+1;j++){
                int time = food[N-1-i][0], deli = food[N-1-i][1];
                if(j>=time){
                    dp2[i+1][j]=Math.max(dp2[i][j],dp2[i][j-time]+deli);
                }else{
                    dp2[i+1][j]=dp2[i][j];
                }
            }
        }

        int max = 0;
        for(int i=0;i<N;i++){
            int ans = 0;
            for(int t=0;t<T;t++){
                int tmp = 0;
                tmp = dp[i][t] + dp2[N-i-1][T-1-t];
                ans = Math.max(ans, tmp);
            }
            ans += food[i][1];
            max = Math.max(ans,max);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 122728
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	bool flag = false;
	bool* f,* g;
	f = (bool*)malloc(sizeof(bool) * N);
	g = (bool*)malloc(sizeof(bool) * N);
	int tempA, tempB;
	while (cin >> tempA >> tempB) {
		if (tempA == 1) {
			f[tempB] = true;
		}
		if (tempB == N) {
			g[tempA] = true;
		}
	}
	for (int i = 0; i < N; i++) {
		if (f[i] == true && g[i] == true) {
			flag = true;
		}
	}
	if (flag == true) {
		cout << "POSSIBLE";
	}
	else {
		cout << "IMPOSSIBLE";
	}

	free (f);
	free (g);
	return 0;
}

Measured memory_bytes: 640