akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>> s;
    int l=s.size(),ans=0;
    bool f=true;
    /*FOR(i,1,l){
        if(f&&s[i]==s[l-1])ans++;
        else if(!f && s[i]==s[0])f=true;
    }
    if(l-ans*2)*/
    if((s[0]==s[l-1]&&l%2==0) or (s[0]!=s[l-1] && l%2==1)){
        cout << "First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }

    return 0;
}


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

int main() {
    int n = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        bool print_i = false;
        int x = i;
        if (x % 3 == 0) {
            print_i = true;
        }
        while (x > 0) {
            if (x % 10 == 3) {
                print_i = true;
            }
            x /= 10;
        }
        if (print_i) {
            cout << " " << i;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <limits>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

double calc_dist(double Xa, double Ya, double Ra, double Xb, double Yb, double Rb) {
  double dX = Xa - Xb, dY = Ya - Yb;
  return max(sqrt(dX * dX + dY * dY) - Ra - Rb, 0.0);
}

int main() {
  double Xs, Ys, Xt, Yt;
  cin >> Xs >> Ys >> Xt >> Yt;
  int N;
  cin >> N;
  vector<double> X(N), Y(N), R(N), dist(N);
  vector<bool> visited(N, false);
  priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> q;
  REP(i, N) {
    cin >> X[i] >> Y[i] >> R[i];
    double d = calc_dist(Xs, Ys, 0, X[i], Y[i], R[i]);
    dist[i] = d;
    q.push(make_pair(d, i));
  }
  while(!q.empty()) {
    auto item = q.top();
    q.pop();
    double td = item.first;
    int idx = item.second;
    if(td > dist[idx]) continue;
    visited[idx] = true;
    REP(i, N) {
      if(visited[i]) continue;
      double newdist = td + calc_dist(X[idx], Y[idx], R[idx], X[i], Y[i], R[i]);
      if(newdist < dist[i]) {
        dist[i] = newdist;
        q.push(make_pair(newdist, i));
      }
    }
  }
  
  double ret = calc_dist(Xt, Yt, 0, Xs, Ys, 0);
  REP(i, N) {
    double newdist = dist[i] + calc_dist(Xt, Yt, 0, X[i], Y[i], R[i]);
    ret = min(ret, newdist);
  }
  cout << fixed << setprecision(9) << ret << endl;
}

Measured memory_bytes: 6260
unittest
{
	assert( [ "2 7" ].solve == 4 );
	assert( [ "1 1" ].solve == 0 );
	assert( [ "50 4321098765432109" ].solve == 2160549382716056 );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto x = 0L;
	input.front.formattedRead!"%s %s"( n, x );
	
	auto bs = new long[ 1 + n ];
	auto ps = new long[ 1 + n ];
	ps[ 0 ] = 1;
	foreach( i; 0 .. n )
	{
		bs[ i + 1 ] = bs[ i ] * 2 + 2;
		ps[ i + 1 ] = ps[ i ] * 2 + 1;
	}
	
	auto ans = 0L;
	foreach_reverse( i; 1 .. n + 1 )
	{
		auto h = ( bs[ i ] + ps[ i ] ) / 2;
		if( h <= x )
		{
			auto c = h < x;
			ans += ps[ i - 1 ] + c;
			x -= h + c;
			if( x <= 0 ) break;
		}
		else
		{
			x--;
		}
	}
	if( 0 < x ) ans++;
	return ans;
}


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


int main(void){
    char s[100];
    scanf("%s",s);
    int l=strlen(s);
    
    if(
        (s[l-7]=='k'&&s[l-6]=='e'&&s[l-5]=='y'&&s[l-4]=='e'&&s[l-3]=='n'&&s[l-2]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[l-6]=='e'&&s[l-5]=='y'&&s[l-4]=='e'&&s[l-3]=='n'&&s[l-2]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[1]=='e'&&s[l-5]=='y'&&s[l-4]=='e'&&s[l-3]=='n'&&s[l-2]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[l-4]=='e'&&s[l-3]=='n'&&s[l-2]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[l-3]=='n'&&s[l-2]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[l-2]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[l-1]=='e')||
        (s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[6]=='e')
        )
        
        
        {
        printf("YES");
        
        }
    else printf("NO");
    
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bitset>
#include<map>
#include<algorithm>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef int Def;
typedef vector<Def> vi;
typedef pair<Def,Def> pii;
typedef vector<pii> vp;
int main(){
	int n;
	while(cin>>n,n){
		vp in(n);
		rep(i,n)cin>>in[i].first>>in[i].second;
		sort(all(in));
		int sum=0;
		rep(i,n-1)sum+=in[i].first;
		if(sum<in[n-1].first){
			int t=in[n-1].first-sum;
			int s=0;
			rep(i,n)s+=in[i].second;
			bitset<1000010>bs;
			bs[0]=1;
			rep(i,n-1)bs=bs|bs<<in[i].second;
			int ma=0;
			rep(i,t+1)if(bs[i])ma=i;
			cout<<2*in[n-1].first+s-ma<<endl;
		}else{
			int s=0;
			rep(i,n)s+=in[i].first+in[i].second;
			cout<<s<<endl;
		}
	}
}


Measured memory_bytes: 3624
N,K = map(int,input().split())
 
mx = (N - 1) * (N - 2) // 2
ls = []
if mx < K:
    print(-1)
else:
    M = (N*(N -1) // 2 - K)
    print(M)
    for i in range(1,N+1):
       for j  in range(2,N+1):
           if i < j:
               ls.append([i,j])
               M -= 1
               if M == 0:
                   break
       if M == 0:
           break

if mx >= K:
    for i,j in ls:
        print(i,j)

Measured memory_bytes: 4120
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
S = input()
dp = [[0] * 5005 for _ in range(5005)]

for i in range(N - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j - i)
        ans = max(now, ans)
print(ans)

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


Measured memory_bytes: 5596
s = input()

def check(s):
    for i in range((len(s)+1)//2):
        if s[i]!=s[-i-1]:
            return False
    return True

# print(s[:(len(s)-1)//2])
# print(s[(len(s)+3)//2-1:])

if check(s)==True and check(s[:(len(s)-1)//2])==True and check(s[(len(s)+3)//2-1:])==True:
    print("Yes")
else:
    print("No")


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;
const double eps = 1e-6;

int n, y;

int main()
{
    scanf("%d%d", &n, &y);
    y /= 1000;

    for(int i = 0; i <= n && i <= y / 10; i++)
        for(int j = 0; j <= n && j <= (y - 10 * i) / 5; j++)
        {
            int k = y - 10 * i - 5 * j;
            if(i + j + k == n)
            {
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
        }

    puts("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define M_PI 3.14159265358979323846
template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
	while (*sdbg != ',')cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
	os << "["; for (auto& vv : V) os << vv << ","; os << "]";
	return os;
}

template<class T> ostream& operator<<(ostream& os, set<T> V) {
	os << "["; for (auto& vv : V) os << vv << ","; os << "]";
	return os;
}

template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif
const int mx = (int)1e6;

vector<int> dSum(mx+ 1);

int digitSum(int k) {
	int r = 0;
	while (k) {
		r += k % 10;
		k /= 10;
	}
	return r;
}

vector<int> vis(mx);
int mlen = -1;
PII cut(int a) {
	static int dupa = (int)pow(10LL, mlen);
	int toAdd = dSum[a / dupa];
	int rem = a % dupa;
	return{ toAdd, rem };
}

int len(int a) {
	int r = 0;
	while (a) {
		a %= 
		r++;
	}
	return r;
}

vector<int> dyn(mx);

int32_t main(int32_t argc, char ** argv) {
	ios_base::sync_with_stdio(0);
	FOR(i, 1, mx - 1) {
		dSum[i] = i % 10 + dSum[i / 10];
	}
	int k;
	cin >> k;
	if (k == 1e5) {
		cout << 1 << endl;
		return 0;
	}
	int bestScore = dSum[k];
	VI przejscia;
	set<PII> stany;
	REP(i, 9) {
		przejscia.push_back((i + 1) * k);
	}
	stany.insert({ 0, k });
	vector<bool> vis(mx);
	while (!stany.empty()) {
		PII p = *stany.begin();
		stany.erase(stany.begin());
		if (vis[p.nd]) {
			continue;
		}
		vis[p.nd] = 1;
		if (p.second == 0) {
			cout << p.first << endl;
			return 0;
		}
		//stany.insert({ p.first + p.second % 10, p.second / 10 });
		REP(i, 10) {
			int tmp = p.second + i * k;
			int cost = p.first + tmp % 10;
			tmp /= 10;
			stany.insert({ cost, tmp });
			//debug(stany, tmp);
		}
	}
	return 0;
}

Measured memory_bytes: 77952
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

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

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    // bを中心に考える
    ll int ans = 0;
    for(int i=0;i<n;i++){
        ll int num_a = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
        ll int num_c = c.end() - upper_bound(c.begin(),c.end(),b[i]);
        ans += num_a * num_c;
    }
    cout << ans;
}

Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
//datatypes
	#define int long long
	#define vi vector<int>
	#define si set<int>
	#define vii vector<ii>
	#define ii pair<int,int>
	#define mii map<int,int>
	#define M 1000000007
	#define pi 3.141592653589793
	#define in(x) int x; cin>>x;
	#define sz(x) (int)x.size()
	#define fr first
	#define sc second
	#define pb push_back
	#define mkp make_pair
	#define inputFile \
	    freopen("input.txt", "r", stdin); 
	#define outputFile \
	    freopen("output.txt", "w", stdout)
	#define rep(i,a,b) for(int i=a; i<b; i++)
	#define trav(a) for(auto &x:a)
	#define test cout<<"hello\n";
	#define all(x) (x).begin(),(x).end()
	#define mem0(x) memset(x, 0, sizeof(x))
	#define mem1(x) memset(x, -1, sizeof(x))
	#define sa(x) std::sort(all(x))
	#define sd(x) std::sort(all(x),greater<int>())
#define rep(i,a,b) for(int i=a; i<b; ++i)
signed solve()
{
	int n; cin>>n;
	int a[n][3];
	rep(i,0,n)
	{
		rep(j,0,3)
		cin>>a[i][j];
	}
	int dp[n][3]={};
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];

	for(int i=1; i<n; ++i)
	{
		rep(j,0,3)
		{
			dp[i][j]= a[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
		}
	}
	/*rep(i,0,n){
		rep(j,0,3)
		cout<<dp[i][j]<<" ";
		cout<<endl;}*/
	cout<<max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]);
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	//cout << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 4992
import java.util.*;
import java.io.*;
 
public class Main {
    static int n,g;
    static int[] p,c;
    static int ans = Integer.MAX_VALUE;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        n = sc.nextInt();
        g = sc.nextInt();
        p = new int[n];
        c = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        dfs(0,0,0,0);
        System.out.println(ans);
    }
    
    public static void dfs(int index, int unusedmax, int point, int count){
        if(n == index){
            if(point >= g){
                ans = Math.min(ans,count);
            }else if(point < g &&unusedmax != 0){
                int tmp = (g-point)/unusedmax;
                tmp += (g-point)%unusedmax != 0 ? 1 : 0;
                if(tmp <= p[unusedmax/100-1]){
                    ans = Math.min(ans,count+tmp);
                }
            }
            return;
        }
        dfs(index+1,unusedmax,point+(index+1)*100*p[index]+c[index], count+p[index]);
        dfs(index+1,(index+1)*100,point,count);
        return;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23252
# -*- coding: utf-8 -*-
a,b,k = map(int,input().split())

"""
for i in range(a, b + 1):
    if a + k - 1 >= i or b - k + 1 <= i:
        print(i)
"""
tmp = []
for i in range(k):
    if a + i <= b:
        print(a + i)
        tmp.append(a + i)
for i in range(k):
    i = k - i - 1
    if (b - i >= a) and (not((b - i) in tmp)):
        print(b - i)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,W;
  int v[100];
  int w[100];
  int m[100];
  cin>>n>>W;
  for(int i=0;i<n;i++)
    cin>>v[i]>>w[i]>>m[i];
  int dp[10001]={};
  for(int i=0;i<n;i++){
    for(int k=0;m[i]>0;k++){
      int t=min(m[i],(1<<k));
      m[i]-=t;
      int nv=v[i]*t;
      int nw=w[i]*t;
      for(int j=W;j>=nw;j--){
	dp[j]=max(dp[j],dp[j-nw]+nv);
      }
    }
  }
  int ans=0;
  for(int i=0;i<=W;i++)
    ans=max(ans,dp[i]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3140
import networkx as nx

H, W = map(int, input().split())
S = [input() for _ in range(H)]

G = nx.Graph()
G.add_nodes_from([(h, w) for h in range(H) for w in range(W)])
for h in range(H - 1):
    for w in range(W):
        if S[h][w] != S[h + 1][w]:
            G.add_edge((h, w), (h + 1, w))
for h in range(H):
    for w in range(W - 1):
        if S[h][w] != S[h][w + 1]:
            G.add_edge((h, w), (h, w + 1))

ans = 0
for component in nx.connected_components(G):
    black, white = 0, 0
    for h, w in component:
        if S[h][w] == '#':
            black += 1
        else:
            white += 1
    ans += black * white
print(ans)


Measured memory_bytes: 295464
n = int(input())
sum = 1
dict = {}
for i in range(2, n+1):
    j = 2
    while i > 1:
        if i%j == 0:
            i = i//j
            if j in dict:
                dict[j] += 1
            else:
                dict[j] = 1
            j -= 1
        j += 1
for i in dict.values():
    sum *= (i+1)
print(sum%1000000007)

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

int main() {
    string s;
    cin >> s;
    bool judge = false;
    for(int i = 0; i < 3; i++){
        if(s[i] == s[i + 1]){
            judge = true;
        }
    }
    if(judge){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	s64 H, W;
	cin >> H >> W;

    u64 Ch, Cw;
    cin >> Ch >> Cw;
    Ch--; Cw--;

    u64 Dh, Dw;
    cin >> Dh >> Dw;
    Dh--; Dw--;

    vector<vector<bool>> HW(H, vector<bool>(W));

    for(s64 i=0; i<H; i++) {
        for(s64 j=0; j<W; j++) {
            char c;
            cin >> c;
            HW[i][j] = (c == '.');
        }
    }
    
    vector<vector<u64>> M(H, vector<u64>(W, UINT64_MAX));
    M[Ch][Cw] = 0;

    deque<pair<u64, u64>> F;
    F.push_back(make_pair(Ch, Cw));

    while(!F.empty()) {
        s64 Fh = F.front().first;
        s64 Fw = F.front().second;
        F.pop_front();

        for(s64 i=-2; i<3; i++) {
            s64 h = Fh + i;
            if(h < 0) continue;
            if(h >= H) break;
            
            for(s64 j=-2; j<3; j++) {
                s64 w = Fw + j;
                if(w < 0) continue;
                if(w >= W) break;
                
                if(!HW[h][w]) continue;

                if(abs(i) + abs(j) > 1) { // warp
                    if(M[h][w] > M[Fh][Fw] + 1) {
                        M[h][w] = M[Fh][Fw] + 1;
                        F.push_back(make_pair(h, w));
                    }
                } else { // walk
                    if(M[h][w] > M[Fh][Fw]) {
                        M[h][w] = M[Fh][Fw];
                        F.push_front(make_pair(h, w));
                    }
                }
            }
        }
    }

    if(M[Dh][Dw] == UINT64_MAX) {
        cout << -1 << endl;
    } else {
        cout << M[Dh][Dw] << endl;
    }

    return 0;
}


Measured memory_bytes: 11796
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, allxor;
    cin >> n;
    vector<int> a(n);
    cin >> a[0];
    allxor = a[0];
    for(int i = 1; i < n; i++) {
        scanf("%d", &a[i]);
        allxor ^= a[i];
    }
    cout << (allxor ^ a[0]) << flush;
    for(int i = 1; i < n; i++) {
        printf(" %d", allxor ^ a[i]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

typedef struct Point{
    int x;
    int y;
} P;

int main() {
    int n,y;
    cin>>n>>y;
    rep(i,0,n+1){
        rep(j,0,n+1){
            if(i*1000+j*5000+(n-i-j)*10000==y&&(n-i-j)>=0){
                
                cout<<(n-i-j)<<" "<<j<<" "<<i<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    
    
    
    return 0;
}




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

#define ll long long int
#define pb push_back
#define mp make_pair
#define all(X) X.begin(), X.end()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    int a;
    string s;
    cin >> a >> s;

    if(a < 3200)
        cout << "red" <<endl;
    else
        cout << s << endl;

    return 0;
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, double> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {

//    ifstream infile("C:\\Users\\riku\\Downloads\\in1.txt");

    ll n;
    cin >> n;
    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];
    ll sum = accumulate(numbers.begin(), numbers.end(), 0ll);
    vector<ll> cs(n, 0), rt(n, 0);
    ll one = n * (n + 1) / 2;
    if (sum % one != 0) {
        cout << "NO" << endl;
        ret();
    }
    ll count = sum / one;
    rep(i, n) {
        ll prev = (i + n - 1) % n;
        ll s = numbers[prev] - numbers[i];
        if ((s + count) % n != 0) {
            cout << "NO" << endl;
            ret();
        }
        if ((s + count) / n < 0) {
            cout << "NO" << endl;
            ret();
        }

        cs[i] = (s + count) / n;
    }

    rep(i, n) rt[0] += cs[i] * ((n - i) % n + 1);
    rep(i, n) if (i > 0) rt[i] = rt[i - 1] - cs[i] * n + count;

    rep(i, n) {
        if (rt[i] != numbers[i]) {
            cout << "NO" << endl;
            ret();
        }
    }
    cout << "YES" << endl;
}




Measured memory_bytes: 2560
import itertools as itr
N, M, Q = map(int, input().split())
req = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    a -= 1; b -= 1;
    req.append((a, b, c, d))


ans = -1
for pattern in itr.combinations_with_replacement(range(1, M+1), N):
    A = pattern
    tmp = 0
    for reqirements in req:
        a, b, c, d = reqirements
        if A[b] - A[a] == c:
            tmp += d

        ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 67616
n,m = gets.split.map(&:to_i)

s = []
m.times do 
    _,*y = gets.split.map(&:to_i)
    s << y
end

pp = gets.split.map(&:to_i)

ans = 0
(2 ** n).times do |i|
    bs = "%0#{n}b" % i
    
    k = false
    m.times do |j|
        count = 0
        s[j].each{|e| count += 1 if bs[e-1] == "1"}
        if count % 2 != pp[j]
            k = true
            break
        end
    end

    next if k
    ans += 1
end

puts ans

Measured memory_bytes: 1788
<?php
  fscanf(STDIN,"%d %d",$n,$m);
  $h = explode(" ",trim(fgets(STDIN)));

  $road=[];
  for($i=0; $i<$m; $i++){
    fscanf(STDIN,"%d %d",$a,$b);
    $road[$a][] = $b;
    $road[$b][] = $a;
  }
  $good = [];
  foreach ($road as $ten => $r){
    $mm = [];
    for($i=0; $i<count($r); $i++){
      $mm[] = $h[$r[$i]-1];
    }
    $max = max($mm);
    if($h[$ten-1] > $max){
      $good[$ten] = true;
    }else{
      $good[$ten] = false;
    }
  }

  $count=0;
  for($i=1; $i<=$n; $i++){
    if(!isset($road[$i])){
      $good[$i] = true;
    }
    if($good[$i]){
      $count++;
    }
  }
  //var_dump($road);
  //var_dump($good);
 echo $count."\n";

Measured memory_bytes: 63948
n, x0 = [int(_) for _ in input().split(' ')]
x = [abs(int(_) - x0) for _ in input().split(' ')]

def gcm(p, q):
    if p % q == 0:
        return abs(q)
    else:
        return gcm(q, p % q)

if n == 1:
    print(x[0])
else:
    answer = x[0]
    for i in range(n - 1):
        answer = gcm(answer, x[i + 1])
    print(answer)


Measured memory_bytes: 14224
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

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

	clock_t startTime=clock();

	ll n,sum=0;
	cin>>n;
    ll arr[n];
    map <ll,ll> mp;
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    ll k;
    cin>>k;
    for(ll i=0;i<k;i++)
    {
    	ll a,b;
        cin>>a>>b;

        sum-=a*mp[a];
        sum+=b*mp[a];
        mp[b]+=mp[a];
        mp[a]=0;
        cout<<sum<<endl;
    }

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 10468
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n; cin >> n;
  
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      if(i*j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 10000000000000000
ll n,m;
vector<vector<ll>>v;
vector<ll>dp;
//頂点iのlongest path
ll solve(ll i){
    if(v[i].size()==0)return dp[i]=0;
    ll ans=0;
    rep(j,v.at(i).size()){
        if(dp[v[i][j]]!=-1)ans=max(ans,dp[v[i][j]]+1);
        else ans=max(ans,solve(v[i][j])+1);
    }
    return dp[i]=ans;
}
int main(void){
    ll x,y;cin>>n>>m;rep(i,n){v.push_back({});dp.push_back(-1);}
    rep(i,m){cin>>x>>y;x--;y--;v[y].push_back(x);}
    ll ans=0;
    rep(i,n)ans=max(ans,solve(i));
    cout<<ans;
    
}

Measured memory_bytes: 11056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N,M; cin >> N >> M;
    vector<pair<int,int>> shop(N);

    REP(i,N)
    {
        int tmpa,tmpb; cin >> tmpa >> tmpb;
        shop[i] = make_pair(tmpa,tmpb);
    }
    sort(shop.begin(), shop.end());
    LL ans = 0;
    int count = 0;
    while(M != 0)
    {
        dump(count)
        if(shop[count].second >= M)
        {
            ans += shop[count].first * 1LL * M;
            dump(ans)
            M = 0;
        }
        else
        {
            ans += shop[count].first * 1LL * shop[count].second;
            M -= shop[count].second;
            dump(ans)
            dump(M)
        }
        count++;

    }
    cout << ans << endl;


}


Measured memory_bytes: 1024
/// b.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,k;
    fi>>n>>k;
    static int s[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    static bitset < 5005 > D1[5555],D2[5555];
    D1[0][0] = 1;
    for (int i = 1;i <= n;++i)
        D1[i] = D1[i - 1] | (D1[i - 1] << s[i]);
    D2[n + 1][0] = 1;
    for (int i = n;i;--i)
        D2[i] = D2[i + 1] | (D2[i + 1] << s[i]);
    int ans = 0;
    for (int i = 1;i <= n;++i)
    {
        int ok = 0;
        int sum = 0;
        for (int j = max(0,k - s[i]);j < k;++j)
            sum += D1[i - 1][j];
        for (int j = 0;j < k;++j)
        {
            if (D2[i + 1][j])
                ok |= sum != 0;
            if (k - s[i] - j >= 1)
                sum += D1[i - 1][k - s[i] - j - 1];
            if (k - 1 - j >= 0)
                sum -= D1[i - 1][k - 1 - j];
        }
        ans += 1 - ok;
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 8448
N = int( input() )

isTravel = True
t, x, y = 0, 0, 0
for i in range( N ):
    ti, xi, yi = map( int, input().split() )
    if abs(xi-x)+abs(yi-y) > ti-t or (abs(xi-x)+abs(yi-y)) % 2 != (ti-t) % 2:
        isTravel = False
    t, x, y = ti, xi, yi

if isTravel: print( 'Yes' )
else:        print( 'No' )

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

int main(){
    int H, W;
    cin >> H >> W;
    char jooj[H+2][W+2];
    for (int i =1; i <= H; ++i ) {
        for ( int j = 1; j <= W; ++j ) {
            cin >> jooj[i][j];
            // branco = .
            // preto = #
        }
    }

    for ( int i = 1; i <= H; ++i ) {
        for ( int j = 1; j <= W; ++j ) {
            if (jooj[i][j]=='#' and jooj[i+1][j]=='.' and jooj[i][j+1]=='.' and jooj[i-1][j] == '.' and jooj[i][j-1]=='.'){
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
ll dp[200][2][10000 + 100];
int main() {
  string S;
  int N;
  cin >> S >> N;
  dp[0][0][0] = 1;
  dp[0][1][0] = 1;
  REP(i, S.size()) {
    REP(j, N) {
      if (i != 0) {
        REP(k, 10) {
          int n = j + k;
          dp[n % N][0][i + 1] += dp[j][0][i];
          dp[n % N][0][i + 1] %= MOD;
        }
      }
    }
    REP(j, N) {
      int a = S[i] - '0';
      REP(k, a + 1) {
        int n = j + k;
        if (a != k) {
          dp[n % N][0][i + 1] += dp[j][1][i];
          dp[n % N][0][i + 1] %= MOD;
        } else {
          dp[n % N][1][i + 1] += dp[j][1][i];
          dp[n % N][1][i + 1] %= MOD;
        }
      }
    }
  }
  cout << (dp[0][0][S.size()] + dp[0][1][S.size()] + MOD - 1) % MOD << endl;
}


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

using namespace std;
using ll = long long;

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

	int n;
	string s;
	cin >> n;
	cin >> s;

	ll r = 0, g = 0, b = 0;
	ll ans = 0;

	for (auto c : s) {
		if (c == 'R')r++;
		else if (c == 'G')g++;
		else b++;
	}

	ll all = r * g * b;
	ll sub = 0;

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j])continue;
			int k = j * 2 - i;
			if (k >= n || s[k] == s[i] || s[k] == s[j]) continue;
			sub++;
		}
	}

	ans = all - sub;

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int l,m,n;
  while(cin>>l&&l){
    int stack=0,ans=-1;
    for(int i=0;i<12;i++){
      cin>>m>>n;
      stack+=(m-n);
      if(stack>=l&&ans==-1)ans=i+1;
    }
    if(ans!=-1)cout<<ans<<endl;
    else cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 1160
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    input()
    s=input()
    print(s.count("ABC"))
main()

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

int main(){
    vector<int> vec;
    int n;
    while(true){
        
        cin>>n;
    
        if(n==0){
            break;
        }
        
        vec.push_back(n);
    }
    
 
    
    for(int i=0;i<vec.size();++i){
        cout<<"Case "<<i+1<<": "<<vec.at(i)<<endl;
    }
    return 0;
}
    


Measured memory_bytes: 3268
#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>
#include <cmath>

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

int64_t N, K;
int64_t A[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> K;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i];
	}
	int64_t resX = 0;
	int64_t x = (int64_t(1) << 60);
	while (x > K) { x >>= 1; }
	bool over = false;
	for (; x > 0; x >>= 1)
	{
		int32_t count = 0;
		for (size_t i = 0; i < N; i++)
		{
			if ((A[i]&x) == 0) {
				++count;
			}
		}

		if (over)
		{
			if (count > N / 2) {
				resX += x;
			}
		}
		else
		{
			if ((K&x) != 0) {
				if (count > N / 2) {
					resX += x;
				}
				else {
					over = true;
				}
			}
			else {
				//0
			}
		}
	}
	int64_t res = 0;
	for (size_t i = 0; i < N; i++)
	{
		res += (A[i] ^ resX);
	}
	
	out << res << endl;

	return 0;
}
#endif


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    ll m1 = 0,m2 = 0;
    for(int i = N-1;i > 0;i--){
        if(A[i] == A[i-1]){
            if(m1 == 0){
                m1 = A[i];
                i--;
            }else{
                m2 = A[i];
                break;
            }
        }
    
    }
    cout << (m1 * m2) << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-


def main():
    x1, y1, x2, y2 = list(map(int, input().split()))
    x3 = x2 - (y2 - y1)
    y3 = x2 - x1 + y2
    x4 = x1 - (y2 - y1)
    y4 = y1 + (x2 - x1)
    print(x3, y3, x4, y4)


if __name__ == '__main__':
    main()


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

using namespace std;
int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> l;
  for (int i = 0; i < n; i++)
  {
    int t;
    cin >> t;
    l.push_back(t);
  }

  sort(l.begin(), l.end(), [](int a, int b) {
    return a > b;
  });
  int ans = 0;
  for (int i = 0;(i < n && i < k);i++)
  {
    ans += l[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function moveup(x::Array{Int,1},n);k=length(x);for i in 1:k-1;if x[k-i+1]>n-1;x[k-i]+=div(x[k-i+1],n);x[k-i+1]%=n;end;end;x[1]>n-1 ? 0 : x;end

function main()
	n,m,x = readline() |> split |> parseMap
	c = Tuple{Int,Array{Int,1}}[(0,[]) for i in 1:n]
	for i in 1:n
		t =readline() |> split |> parseMap
		cx=t[1]
		b = zeros(Int,m)
		for j in 1:m
			b[j]=t[j+1]
		end
		c[i]=(cx,b)
	end
	ans = 10^18
	w = zeros(Int,n)
	while w!=0
		sx=zeros(Int,m)
		ct=0
		for i in 1:n
			if w[i]==1
				ct+=c[i][1]
				for j in 1:m
					sx[j]+=c[i][2][j]
				end
			end
		end
		f = 0
		for i in 1:m
			if sx[i]<x
				f=1
			end
		end
		if f==0
			ans=min(ans,ct)
		end
		w[n]+=1
		w=moveup(w,2)
	end
	println(ans==10^18 ? -1 : ans)
end

main()

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

using namespace std;
using LL = long long;

int main() {
	int n, k;
	cin >> n >> k;
	double chance = 0;
	for (int i = 1; i <= n; ++i) {
		double x = 1.0 / n;
		int j = i;
		while (j < k) {
			j *= 2;
			x /= 2.0;
		}
		chance += x;
	}

	cout << setprecision(10) << chance << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define fore(i,a) for(auto &i:a)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }


int A[2][101][101];
int W, H, T, P;

//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> W >> H >> T >> P) {
        if (W == 0) return;
        
        rep(t, 0, 2) rep(y, 0, 101) rep(x, 0, 101) A[t][y][x] = 0;
        rep(y, 0, H) rep(x, 0, W) A[0][y][x] = 1;

        rep(t, 0, T) {
            int d, c; cin >> d >> c;
            rep(y, 0, 101) rep(x, 0, 101) A[(t + 1) % 2][y][x] = 0;

            if (d == 1) {
                rep(y, 0, H) rep(x, 0, W) A[(t + 1) % 2][y][x] = A[t % 2][y][x + c];
                rep(x, 0, c) rep(y, 0, H) A[(t + 1) % 2][y][x] += A[t % 2][y][c - 1 - x];
            } else {
                rep(y, 0, H) rep(x, 0, W) A[(t + 1) % 2][y][x] = A[t % 2][y + c][x];
                rep(x, 0, W) rep(y, 0, c) A[(t + 1) % 2][y][x] += A[t % 2][c - 1 - y][x];
            }
        }

        rep(p, 0, P) {
            int x, y; cin >> x >> y;
            printf("%d\n", A[T % 2][y][x]);
        }
    }
}




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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
string k;
ll d;
cin>>k>>d;
ll n=k.size();
mint dp[n+5][d+5][2];//0未満
dp[0][0][1]=1;
rep(i,n)rep(j,d){
  ll K=(k[i]-'0');
  /*
  if (K==0){
    mint temp=10*dp[i][j][0];
    dp[i+1][now][0]+=temp;
    dp[i+1][now][1]+=dp[i][j][1];
  }
  */
//  else{
    rep(z,10){
      ll now=(j+z)%d;
      if(z<K){
        dp[i+1][now][0]+=dp[i][j][0];
        dp[i+1][now][0]+=dp[i][j][1];

      }
      else if (z==K){
        dp[i+1][now][0]+=dp[i][j][0];
        dp[i+1][now][1]+=dp[i][j][1];

      }
      else{
        dp[i+1][now][0]+=dp[i][j][0];
      }
    //  cout<<"i"<<i<<"j"<<j<<"z"<<z<<endl;
//cout<<dp[i+1][now][0]<<" "<<dp[i+1][now][1]<<"now"<<now<<endl;
    }


  //}



}mint ans=0;
ans+=dp[n][0][0];
ans+=dp[n][0][1];
ans-=1;
cout<<ans;


}


Measured memory_bytes: 19856
#include<bits/stdc++.h>
using namespace std;
int a[1000001],n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int f[100001];
	f[1]=0;
	f[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
		f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
	cout<<f[n];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  cout << n*(n-1)/2 + m*(m-1)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int ans=1;
    REP(i,n)ans=(ans*(i+1))%((int)1e9 + 7);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque

SA = deque(list(input()))
SB = deque(list(input()))
SC = deque(list(input()))

turn = 'a'

while True:
    if turn == 'a' and len(SA) == 0:
        ans = 'A'
        break
    elif turn == 'b' and len(SB) == 0:
        ans = 'B'
        break
    elif turn == 'c' and len(SC) == 0:
        ans = 'C'
        break

    if turn == 'a':
        turn = SA.popleft()
    elif turn == 'b':
        turn = SB.popleft()
    else:
        turn = SC.popleft()

print(ans)

Measured memory_bytes: 3316