akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)
#define coutline cout<<"------------ ("<<__LINE__<<")"<<endl;

typedef long long ll;

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

    vector<vector<int64_t>> g(H,vector<int64_t>(W,0));
    const int64_t KABE = -1;
    const int64_t YET = 0;
    rep(i,H) {
        string str;
        cin >> str;
        rep (j, str.length()){
            if (str.substr(j,1) == "#") {
                g.at(i).at(j) = KABE;
            } else {
                g.at(i).at(j) = YET;
            }
        }
    }
    
    g.at(0).at(0) = 1;

    rep(i,H) {
        rep(j,W){
            int64_t tmp = 0;
            if (g.at(i).at(j) == KABE) continue;
            if (i != 0 && g.at(i-1).at(j) != KABE) tmp += g.at(i-1).at(j);
            if (j != 0 && g.at(i).at(j-1) != KABE) tmp += g.at(i).at(j-1);
            g.at(i).at(j) += tmp;
            g.at(i).at(j) = g.at(i).at(j) % 1000000007;

            //rep(x,H) {
            //    rep(y,W){
            //        cout << g.at(x).at(y);
            //    }
            //    cout << endl;
            //}
            //cout << endl;
        }
    }

    cout << g.at(H-1).at(W-1) << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
bool cmp(char a,char b)
{
    return a>b;
}
int cmp2(string a,string b)
{
    if(a.size()==b.size())
        return a>b;
    else
        return a.size()>b.size();
}
string max1(string s1,string s2)
{
    if(cmp2(s1,s2)>0)
        return s1;
    else
        return s2;
}
bool inline operator < (const string &a, const string &b)
{
    if (a.size()!= b.size())
        return a.size()<b.size();
    for(int i=0;i<a.size();i++)
    {
        if (a[i]!=b[i])
            return a[i]<b[i];
    }
    return 0;
}
int main()
{
    int n,m;
    string a[]={"0","1","2","3","4","5","6","7","8","9"};
    int a2[]={0,2,5,5,4,5,6,3,7,6};
    int ai[10]={0};
    cin >> n >> m;
    for(int i=0;i<m;i++)
        cin >> ai[i];
    sort(ai,ai+m);
    string dp[10011];
    dp[0]="";
    for(int i=0;i<m;i++)
    {
        dp[a2[ai[i]]]=a[ai[i]];
    }
    for(int i=1;i<=n;i++)
        if(dp[i]!="")
        for(int j=0;j<m;j++)
        {
            string s=dp[i]+a[ai[j]];
            if(s.size()<dp[i+a2[ai[j]]].size())
                continue;
            if(dp[i+a2[ai[j]]]<s)
                dp[i+a2[ai[j]]]=s;
            dp[i+a2[ai[j]]]=max1(dp[i+a2[ai[j]]],s);
        }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 43648
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  //蛇みたいな塗り方をすればO.K.
  int h,w;
  cin>>h>>w;
  int n;
  cin>>n;
  int a[n+1];
  REPP(i,n){
    cin>>a[i];
  }
  int c[h][w];
  int ch=0,cw=0;
  REPP(i,n){
    REP(j,a[i]){
      c[ch][cw]=i;
      if(ch%2==0){
        cw++;
        if(cw==w){
          ch++;
          cw = w-1;
        }
      }else{
        cw--;
        if(cw==-1){
          ch++;
          cw = 0;
        }
      }
    }
  }
  REP(i,h){
    REP(j,w){
      cout<<c[i][j]<<' ';
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  c=B[j]
  if c[i]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Measured memory_bytes: 132864
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N; cin >> N;
    map<int, int> M;
    REP(i, N) {
        int a; cin >> a;
        M[a]++;
    }
    int cnt = 0;
    for (auto& p : M) {
        cnt += p.second;
        if (p.second >= p.first) cnt -= p.first;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c = 0;
    char a;
    while ( cin >> a ) {
        if( a == '+' ) c++;
        else c--;
    }
    cout << c;
}

Measured memory_bytes: 3652
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

bool is_prime(int num){
	for(int i = 2;i<=sqrt(num);i++){
		if(num % i == 0) return false;
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 3624
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;

ll dp[105][55][55];

int main() {
	for (int i = 0; i < 105; i++) {
		for (int j = 0; j < 55; j++) {
			for (int l = 0; l < 55; l++) {
				dp[i][j][l] = -10000000000000;
			}
		}
	}


	ll N,k,v[1000], q;
	cin >> N >> k;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	dp[0][1][N] = 0;
	ll sum = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 1; j <= N; j++) {
			for (int l = N; N-l+j-1<= k; l--) {
				if (j <= l) {
					if (i + 1 <= k && l - 1 >= 0)dp[i + 1][j][l - 1] = max(dp[i][j][l]+v[l-1], dp[i + 1][j][l - 1]);
					if (i + 1 <= k && j + 1<=N+1)dp[i + 1][j + 1][l] = max(dp[i][j][l]+v[j-1],dp[i + 1][j + 1][l]);

					if(i+2<=k&&l-1>=0)dp[i + 2][j][l - 1] = max(dp[i][j][l], dp[i + 2][j][l-1]);
					if(i+2<=k&&j+1<=N+1)dp[i + 2][j+1][l] = max(dp[i][j][l], dp[i + 2][j+1][l]);
					sum = max(sum, dp[i+1][j][l-1]);
					sum = max(sum, dp[i+1][j+1][l]);
					sum = max(sum, dp[i + 2][j + 1][l]);
					sum = max(sum, dp[i + 2][j][l-1]);
				}
			}
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2688
def examA():
    O = SI()
    E = SI()
    ans = ""
    for i in range(len(O)+len(E)):
        if i%2==0:
            ans += O[i//2]
        else:
            ans += E[i//2]
    print(ans)
    return

def examB():
    A = LI()
    A.sort()
    ans = (A[2] - A[0]) // 2 + (A[2] - A[1]) // 2
    if (A[2]-A[0])%2==1:
        ans += 1
        if (A[2]-A[1])%2==0:
            ans += 1
    elif (A[2]-A[1])%2==1:
        ans += 2
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

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

int main(){
     int n,p;
     while(cin>>n>>p,n||p){
	  int step=0;
	  int temoto[n];
	  int wan=p;
	  for(int i=0;i<n;i++)temoto[i]=0;
	  while(1){
	       if(wan>0){
		    --wan;
		    ++temoto[step%n];
	       } else {
		    wan+=temoto[step%n];
		    temoto[step%n]=0;
	       }
	       if(temoto[step%n]==p){
		    break;
	       }
	       ++step;
	  }
	  cout<<step%n<<endl;
     }
}

Measured memory_bytes: 868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc088c
{
    class abc088c
    {
        static void Main(string[] args) {
            var c0 = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
            var c1 = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
            var c2 = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);

            var a0 = c0[0];
            var b1 = c0[1] - a0;
            var b2 = c0[2] - a0;
            var a1 = c1[0];
            var a2 = c2[0];
            if (a1 + b1 != c1[1]
                || a1 + b2 != c1[2]
                || a2 + b1 != c2[1]
                || a2 + b2 != c2[2])
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");

        }
    }
}


Measured memory_bytes: 11220
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int num(State& begin);
int expression(State& begin) {
	vector<int> geko;
	while (*begin != ']') {
		if (*begin == '[') {
			begin++;
			geko.push_back(expression(begin));
		}
		else {
			geko.push_back(num(begin));
		}
	}
	begin++;
	sort(geko.begin(), geko.end());
	int bobo = 0;
	REP(i, (geko.size() + 1) / 2) {
		bobo += geko[i];
	}
	return bobo;
}
int num(State& begin) {
	int ans = 0;
	while (*begin >= '0' && *begin <= '9') {
		ans *= 10;
		ans += *begin - '0';
		begin++;
	}
	return ans/2+1;
}
int main(){
	int query;
	cin >> query;
	REP(i, query) {
		string s;
		cin >> s;
		State hoge = s.begin()+1;
		cout << expression(hoge) << endl;
	}
}


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

int main()
{
    string S;
    cin >> S;
    int count = 0;

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '+') {
            count++;
        } else {
            count--;
        }
    }    
    cout << count;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll x;
    cin >> x;

    ll ans = 0;
    ans += (x/500*1000);
    ans += (x%500)/5*5;

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
void main() {
  problem();
}

void problem() {
  auto N = scan!int;
  auto S = scan!string(N);

  void solve() {
    int[string] count;

    foreach(s; S) {
      count[s]++;
    }

    auto keys = ["AC", "WA", "TLE", "RE"];
    foreach(k; keys) {
      writefln("%s x %s", k, k in count ? count[k] : 0);
    }
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


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

long long expantedEuclid(long long a, long long b, long long &x, long long &y) {
  long long d;
	if (b == 0) {
		d = a;
		x = 1;
    y = 0;
	}
	else {
		d = expantedEuclid(b, a % b, y, x);
		y -= a / b * x;
	}
	return d;
}

int main() {

  long long a, b, x, y;
  cin >> a >> b;

  expantedEuclid(a, b, x, y);

  cout << x << " " << y << endl;

  return 0;

}


Measured memory_bytes: 3120
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; char c; string s;

	int ca = 0, cb = 0, cab = 0, co = 0;
	while (cin >> n >> c >> s) {
		if (s == "A")ca++;
		else if (s == "B")cb++;
		else if (s == "AB")cab++;
		else if (s == "O")co++;
	}
	cout << ca << endl << cb << endl << cab << endl << co << endl;
}


Measured memory_bytes: 2988
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"class UnionFind():\n"
"    def __init__(self,size):\n"
"        self.table=[-1]*size\n"
"    def root(self,x):\n"
"        while self.table[x]>=0:\n"
"            x=self.table[x]\n"
"        return x\n"
"    def unite(self,x,y):\n"
"        s1=self.root(x)\n"
"        s2=self.root(y)\n"
"        if s1!=s2:\n"
"            if self.table[s1]>self.table[s2]:\n"
"                s1,s2=s2,s1\n"
"            self.table[s1]+=self.table[s2]\n"
"            self.table[s2]=s1\n"
"        return\n"
"    def same(self,x,y):\n"
"        return self.root(x)==self.root(y)\n"
"    def size(self,x):\n"
"        return -self.table[self.root(x)]\n"
"input=open(0).readline\n"
"n,m=map(int,input().split())\n"
"*p,=map(int,input().split())\n"
"u=UnionFind(n+1)\n"
"for _ in range(m):\n"
"    u.unite(*map(int,input().split()))\n"
"print(sum(u.same(p[i],i+1)for i in range(n)))\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 14736
#include <bits/stdc++.h>
#define tt this->
#define ll long long
using namespace std;
int main ()
{
    char x;
    cin>>x;
    if(isupper(x))cout<<"A";
    else
        cout<<"a";
    return 0;
}

/*
▀█████████▄     ▄████████    ▄████████    ▄████████
  ███    ███   ███    ███   ███    ███   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
 ▄███▄▄▄██▀    ███    ███  ▄███▄▄▄▄██▀   ███    ███
▀▀███▀▀▀██▄  ▀███████████ ▀▀███▀▀▀▀▀   ▀███████████
  ███    ██▄   ███    ███ ▀███████████   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
▄█████████▀    ███    █▀    ███    ███   ███    █▀
                            ███    ███

*/


Measured memory_bytes: 3584
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
count = make_divisors(n)
a = count[-1]
b = n//a
print(a+b-2)

Measured memory_bytes: 3268
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll n, k;
    cin >> n >> k;
    vl a(n+1);
    rep(i, n) cin >> a[i+1];
    vl b;
    rep(i, n) a[i+1] += a[i];
    rep(l, n) REP(r, l+1, n+1) {
        b.push_back(a[r]-a[l]);
    }
    sort(all(b));
    ll ans = 0LL;
    for(int i = 60; i >= 0; --i) {
        int cnt = 0;
        for(auto&& x : b) {
            if((x&ans) == ans) {
                if(x&(1LL<<i)) cnt++;
            }
        }
        if(cnt >= k) ans |= (1LL<<i);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 6004
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb emplace_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 92233720000000000ll;

void solve()
  {
    int n;
    cin>>n;
    int odd = ceil(n/2.0);
    double prob = 1.0*odd/n;
    cout<<fixed<<setprecision(10);
    cout<<prob;
  }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
int a[3010];long long dp[3010];
const int mod=998244353;
int main()
{
	int n,s;
	cin>>n>>s;
	for(int i=1;i<=n;i++) 
		scanf("%d",&a[i]);
    long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=s-a[i];j>=0;j--)
			dp[j+a[i]]=(dp[j+a[i]]+dp[j])%mod;
		dp[a[i]]+=i;
		ans=(ans+dp[s])%mod;
	}
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int k;
  cin >> k;
  if ( k < 10 ){
    cout << k << endl;
    return 0;
  }
  ll ans;
  queue<ll> q;
  rep(i,9) q.push(i+1);
  while ( k > 0 ) {
    ans = q.front(); q.pop();
    if(ans%10>0) q.push( ans * 10 + ans%10 - 1);
    q.push( ans * 10 + ans%10 );
    if(ans%10<9) q.push( ans * 10 + ans%10 + 1);
    --k;
  }
  cout << ans << endl;
}


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

int main()
{
  int n, ans = 0;
  cin >> n;
  vector<vector<pair<int, int>>> v(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v[i].resize(a);
    for (int j = 0; j < a; ++j) {
      cin >> v[i][j].first >> v[i][j].second;
      --v[i][j].first;
    }
  }
  for (int bit = 0; bit < (1 << n); ++bit)
  {
    bool check = 1;
    for (int i = 0; i < n; ++i)
    {
      if (!(bit & (1 << i)))
        continue;
      for (pair<int, int> xy : v[i])
      {
        int x = xy.first, y = xy.second;
        if (y == 0 and (bit & (1 << x)))
          check = 0;
        else if (y == 1 and !(bit & (1 << x)))
          check = 0;
      }
    }
    if (check)
    {
      int tmp = 0;
      for (int t = 0; t < n; ++t)
      {
        if (bit & (1 << t))
          ++tmp;
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int n;
char s[500];

int main()
{
	scanf("%s\n", s);
	
	n = strlen(s);
	int p = 0;
	while (p < n) {
		if (s[p] == 'R') {
			break;
		}
		p++;
	}
	if (p >= n) {
		printf("0\n");
		return 0;
	}
	int q = p;
	while (q < n) {
		if (s[q] == 'S') {
			q--;
			break;
		}
		q++;
	}
	if (q >= n) q--;
	
	int len = q - p + 1;
	
	printf("%d\n", len);

	return 0;
}




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


void solve(ll N, ll M, ll X, ll Y, vector<ll> x, vector<ll> y)
{
    ll maxx = x[0];
    for(ll t:x)maxx = max(maxx,t);
    ll miny = y[0];
    for(ll t:y)miny = min(miny,t);
    for(int t=X+1;t<=Y;++t)
    {
        if(t > maxx && t <= miny)
        {
            cout<<"No War"<<endl;
            return;
        }
    }
    cout<<"War"<<endl;
}


int main()
{
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    ll X;
    cin >> X;
    ll Y;
    cin >> Y;
    vector<ll> x(N);
    for(int i = 0 ; i < N ; i++)
    {
        cin >> x[i];
    }
    vector<ll> y(M);
    for(int i = 0 ; i < M ; i++)
    {
        cin >> y[i];
    }
    solve(N, M, X, Y, move(x), move(y));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  string A,B;
  cin >> A >> B;
  int as=A.size(), bs=B.size();
  
  if(as>bs) cout << "GREATER" << endl;
  else if(as<bs) cout << "LESS" << endl;
  else{
  	if(A>B) cout << "GREATER" << endl;
    else if(A<B) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int N, W;
    cin >> N >> W;
    vi v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];
    vi cur(W+1, 0);
    rep(i, N) {
        vi nxt = cur;
        for(int j = 0; j+ w[i] < W+1; ++j) chmax(nxt[j+w[i]], cur[j]+v[i]);
        swap(cur, nxt);
    }
    int ans = 0;
    rep(i, W+1) chmax(ans, cur[i]);
    cout << ans << endl;
    return 0;
}


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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define anin(a) printf("%d\n",a);
#define ando(a)printf("%lf\n",a);

int asc(const void *a,const void *b){
	return *(double *)a - *(double *)b;
}

int main(void){
	int n;
	scanf("%d",&n);
	double v[n],ans(0.);
	rep(i,0,n){
		scanf("%lf",&v[i]);
	}
	qsort(v,n,sizeof(double),asc);
	rep(i,0,n - 1){
		if(i == 0) ans = (v[i] + v[i + 1]) / 2.; else ans = (ans + v[i + 1]) / 2.;
	}
	ando(ans);
	return 0;
}

Measured memory_bytes: 256
/**
*    created: 21.06.2020 00:22:50
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int 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++)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, yen;
    cin >> n >> yen;
    int man = yen / 10000;
    int gos = yen / 5000;
    rep(x,man+1) {
        rep(y,gos+1) {
            int z = n - x - y;
            if (z < 0) break;
            if (10000 * x + 5000 * y + 1000 * z == yen) {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	vector<int> S(3);
	cin >>S.at(0)>>S.at(1)>>S.at(2);
	sort(S.begin(),S.end());
	cout<<S.at(0)+S.at(1)+S.at(2)*10;
}


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

typedef long long ll;
#define endl "\n"

const int M = (int) 1e9+7;
int n,k;
ll ans=1;
vector<ll> pos, neg;
int pcnt=0, ncnt=0;

ll solve(){
    cin>>n>>k;
    for (int i=0; i<n; ++i){
        ll foo; cin>>foo;
        if (foo>0) pos.push_back(foo);
        else neg.push_back(abs(foo));
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int P=pos.size(), N=neg.size();
    if (k==n ? N%2==0 : P || k%2==0){
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        for ( ; k; --k){
            if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[ncnt])){
                ans=ans*pos[pcnt]%M; ++pcnt;
            }
            else{
                ans=ans*neg[ncnt]%M; ++ncnt;
            }
        }
        if (ncnt&1){
            ans=1;
            if (pcnt<P && ncnt>=1 && (ncnt>=N || pcnt<1 || pos[pcnt]*pos[pcnt-1]>neg[ncnt]*neg[ncnt-1])){
                for (int tt=0; tt<pcnt+1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt-1; ++tt)
                    ans=ans*neg[tt]%M;
            }
            else{
                for (int tt=0; tt<pcnt-1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt+1; ++tt)
                    ans=ans*neg[tt]%M;
            }
        }
        return ans%M;
    }
    for(ans=1, pcnt=0, ncnt=0; k; --k) {
        if(pcnt<pos.size()&&(ncnt>=neg.size()||pos[pcnt]<neg[ncnt])) {
            ans=ans*pos[pcnt]%M;
            ++pcnt;
        } else {
            ans=ans*neg[ncnt]%M;
            ++ncnt;
        }
    }
    return (M-ans)%M;
}

int main(){
    // INT VS LL
    // freopen("input.txt", "r", stdin);
    //    INT VS LL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<solve();
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int ans=0;
	for(int i=0;i<n;++i){
		int A; cin>>A;
		while(A%2==0)A/=2,++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<assert.h>
#include<set>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<iostream>
#include<bitset>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define rep(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define per(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
using namespace std;
typedef long long LL;
typedef double db;
const int N=5005;
const int P=1000000007;
int p[N],n,m,col[N];
int f[N];
int cnt[2];
void fail(){puts("0");exit(0);}
void dfs(int x){
	cnt[col[x]]++;
	rep(i,x+1,n)if(p[i]<p[x]){
		if(col[i]!=-1){
			if(col[i]==col[x]){
				fail();
			}
		}
		else{
			col[i]=col[x]^1;
			dfs(i);
		}
	}
	rep(i,1,x-1)if(p[i]>p[x]){
		if(col[i]!=-1){
			if(col[i]==col[x]){
				fail();
			}
		}
		else{
			col[i]=col[x]^1;
			dfs(i);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%d",&p[i]);
	memset(col,-1,sizeof col);
	f[0]=1;
	rep(x,1,n)if(col[x]==-1){
		cnt[0]=cnt[1]=0;
		col[x]=0;
		dfs(x);
		//printf("__%d %d\n",cnt[0],cnt[1]);
		per(i,n,0){
			int w=0;
			if(i>=cnt[0])w=(w+f[i-cnt[0]])%P;
			if(i>=cnt[1])w=(w+f[i-cnt[1]])%P;
			f[i]=w;
		}
	}
	int ans=0;
	rep(i,n-m,m)ans=(ans+f[i])%P;
	printf("%d\n",ans);
	return 0;
}








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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define SET(arr) memset(arr, -1, sizeof(arr))
#define CLR(arr) memset(arr, 0, sizeof(arr))

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

#define $ vector< int > :: iterator
#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(int i=0; i<(n); i++)
#define forn(i, n) for (int i = 1; i <=(int)(n); ++i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forba(i, b, a) for (int i = (int)(b); i >= (int)(a); --i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<
#define CS(i) cout<<"Case "<<(int)(i)<<": "

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);
const ld E=2.71828182845904523536;

const int M=2019;

int main() {
Boost;
//READ("in.txt");
//WRITE("out.txt");

        int L,R,rem=M;
        cin>>L>>R;
        int x=ceil((ld)(L+0.0)/M);
        if(x*M<=R) rem=0;
        L%=M;
        R%=M;
        if(L>=R) R+=M;
        for(int i=L;i<=R;i++)
            for(int j=i+1;j<=R;j++)
                rem=min(rem,(i*j)%M);
        cout<<rem<<endl;

return 0;
}


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

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

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	vector<int> rate(9);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a / 400 == 0 && rate[0] == 0) rate[0]++;
		else if (a / 400 == 1 && rate[1] == 0) rate[1]++;
		else if (a / 400 == 2 && rate[2] == 0) rate[2]++;
		else if (a / 400 == 3 && rate[3] == 0) rate[3]++;
		else if (a / 400 == 4 && rate[4] == 0) rate[4]++;
		else if (a / 400 == 5 && rate[5] == 0) rate[5]++;
		else if (a / 400 == 6 && rate[6] == 0) rate[6]++;
		else if (a / 400 == 7 && rate[7] == 0) rate[7]++;
		else if (8 <= a / 400) rate[8]++;
	}
	int min_color_num = 0;
	int max_color_num = 0;
	for (int i = 0; i < 8; i++) min_color_num += rate[i];
	max_color_num = min_color_num + rate[8];
	if (min_color_num == 0) min_color_num = 1;
	cout << min_color_num << " " << max_color_num << endl;
}

Measured memory_bytes: 256
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()


def check(x):
    if x > n - p:
        return True

    for i in range(x + 1, n - p + 1):
        if a[x] + m < a[i]:
            return False

    if v - x - p > 0:
        cnt = 0
        for i in range(x + 1, n - p + 1):
            cnt += min((a[x] + m) - a[i], m)

        if (cnt // (v - x - p)) >= m:
            return True
        else:
            return False
    else:
        return True


lb = -1  # False
ub = n - 1  # True
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        ub = mid
    else:
        lb = mid

# print(a)
# print(lb, ub)
ans = n - ub
print(ans)


Measured memory_bytes: 62576
import numpy as np
def LI():
    return list(map(int, input().split()))

n = int(input())
ab = [LI() for _ in range(n)]
ab = np.array(ab)

def main():
    if n % 2 == 0:
        mi = np.median(ab[:, 0])
        ma = np.median(ab[:, 1]) + 0.5
        ans = (ma - mi) // 0.5
    else:
        mi = np.median(ab[:, 0])
        ma = np.median(ab[:, 1]) + 1
        ans = ma - mi
    print(int(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 66488
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

    if (S.size() == 2)
    {
        cout << S << endl;
    }
    else if (S.size() == 3)
    {
        reverse(S.begin(), S.end());
        cout << S << endl;
    }
}

Measured memory_bytes: 256
/* AOJ 0071
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0071
 *
 */

#include <stdio.h>

#define DEBUG 0

#define true 1
#define false 0


int data[8][8];


void loadline(int row, char* buf){
    int i;
    for(i=0;i<8;i++){
        data[row][i] = buf[i] - '0';
    }
}


void ignite(int x, int y, int t){
    if((0<=x)&&(x<8) && (0<=y) && (y<8)){
        if(data[y][x] == 1){
            data[y][x] = t;
        }
    }
}

void fire(int x, int y,  int t){
    int i;
    if(data[y][x] != t){
        return;
    }
    for(i=-3;i<=3;i++){
        ignite(x+i, y, t+1);
        ignite(x, y+i, t+1);
    }

}

void run(int t){
    int j,k;
    if(DEBUG){
        printf("run %d\n", t);
        for(j=0;j<8;j++){
            for(k=0;k<8;k++){
                printf("%d", data[j][k]);
            }
            printf("\n");
        }
    }

    for(j=0;j<8;j++){
        for(k=0;k<8;k++){
            fire(j, k, t);
        }
    }
}


int has_ignited(int t){
    int j,k;

    for(j=0;j<8;j++){
        for(k=0;k<8;k++){
            if(data[j][k]==t){
                return true;
            }
        }
    }
    return false;
}


int main(){
    int n, x,y;
    int i,j,k;
    int t;
    char buf[20];

    scanf("%d", &n);

    for(i=0; i<n;i++){
        for(j=0;j<8;j++){
            scanf("%s", buf);
            loadline(j, buf);
        }
        scanf("%d", &x);
        scanf("%d", &y);
        if(DEBUG)
            printf("(%d,%d)\n", x, y);

        t = 2;
        data[y-1][x-1] = 1; /* place first bomb */
        ignite(x-1, y-1, t);
        if(DEBUG){
            for(j=0;j<8;j++){
                for(k=0;k<8;k++){
                    printf("%d", data[j][k]);
                }
                printf("\n");
            }
        }
        while(has_ignited(t)){
            run(t);
            t++;
        }
        printf("Data %d:\n",i+1);
        for(j=0;j<8;j++){
            for(k=0;k<8;k++){
                if(data[j][k] == 1){
                    printf("1");
                }else{
                    printf("0");
                }
            }
            printf("\n");
        }

    }

    return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
using std::sort;
inline bool cmp(int a,int b)
{
	return a>b;
}
int n,a[100007],x,y;
int main()
{
	scanf(" %d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf(" %d",&a[i]);
	}
	sort(a+1,a+n+1,cmp);
	for(x=1;a[x+1]>x;++x);
	for(y=x;a[y]>=x;++y);--y;
	printf("%s\n",(((a[x]-x)&1)|((y-x)&1))?"First":"Second");
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int ls=s.size(),lt=t.size();
	int minn=10000;
	for(int i=0;i<=ls-lt;i++)
	{
		int tot=0;
		int k=0;
		for(int j=i;j<i+lt;j++)
		{
			if(s[j]!=t[k]) tot++;
			k++;
		}
		minn=min(minn,tot);
	}
	printf("%d\n",minn);
	return 0;
}

Measured memory_bytes: 3640
n,k = map(int, input().split())
pl = [0] + list(map(int, input().split()))
cl = [0] + list(map(int, input().split()))

ans = (10**18)*(-1)
for start in range(1,n+1):
    val = 0
    vals = []
    already_set = set()
    curr_mass = start
    while True:
        next_mass = pl[curr_mass]
        point = cl[next_mass]
        if next_mass in already_set:
            break
        else:
            vals.append(point)
            already_set.add(next_mass)
            curr_mass = next_mass
    # print(vals)
    if k <= len(vals):
        c_max = vals[0]
        c_val = vals[0]
        # if len(vals) > 1:
        for v in vals[1:k]:
            c_val += v
            c_max = max(c_max, c_val)
        # print(c_max)
        ans = max(c_max,ans)
    else:
        v_sum = sum(vals)
        if v_sum <= 0:
            c_max = vals[0]
            c_val = vals[0]
            # if len(vals) > 1:
            for v in vals[1:]:
                c_val += v
                c_max = max(c_max, c_val)
            # print(c_max)
            ans = max(c_max,ans)
        else:
            if k%len(vals) > 0:
                loop_cnt = k//len(vals)
                rem = k - loop_cnt*len(vals)
                c_max = v_sum*loop_cnt
                c_val = v_sum*loop_cnt
                if rem > 0:
                    for v in vals[:rem]:
                        c_val += v
                        c_max = max(c_max, c_val)
                # print(c_max)
                ans = max(c_max,ans)
            else:
                loop_cnt = k//len(vals) - 1
                rem = len(vals)
                c_max = v_sum*loop_cnt
                c_val = v_sum*loop_cnt
                if rem > 0:
                    for v in vals[:rem]:
                        c_val += v
                        c_max = max(c_max, c_val)
                # print(c_max)
                ans = max(c_max,ans)
    # print(c_max)
print(ans)
# 2939275739


Measured memory_bytes: 168868
import math

_=list(map(int,input().split()))
n,k=_[0],_[1]
W=[]
for i in range(n):
    W.append(int(input()))

def n_cal(num_track,weights,threshold):
    numbers_=0
    for i in range(num_track): #each tracktor
        sum_=0
        while sum_<=threshold and numbers_<=len(weights)-1: #each tracktor's capacity
            sum_+=weights[numbers_] #each tracktor's weight
            if sum_<=threshold:numbers_+=1
            else:pass
    return numbers_

minimum_=max(W)
maximum_=sum(W)
P=range(minimum_,maximum_+1)

left=0;right=len(P)
mid=math.floor((left+right)/2)
while left<right:
    if n_cal(k,W,P[mid])<n:
        left=mid+1
    elif n==n_cal(k,W,P[mid]) and n==n_cal(k,W,P[mid-1]):
        right=mid
    else:break
    mid=math.floor((left+right)/2)
print(P[mid])


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

int main(void) {
  int s, count;
  cin >> s;
  if(s < 3) {
    cout << 4 << endl;
  } else {
    for(count = 1; s != 1; count++) {
      if(s % 2 == 0) {
        s /= 2;
      } else {
        s = 3 * s + 1;
      }
    }
    cout << count + 1 << endl;
  }
  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)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, m, a, b, c[100000], bl, wh, r;
vi e[100000];

bool dfs(int v, int h) {
	c[v] = h;
	if (h>0) bl++;
	else wh++;
	rep(i,e[v].size()) {
		if (c[e[v][i]]==h) return false;
		if (!c[e[v][i]] && !dfs(e[v][i], -h)) return false;
	}
	return true;
}

int main() {
	cin >> n >> m;
	rep(i,m) {
		cin >> a >> b;
		a--, b--;
		e[a].pb(b), e[b].pb(a);
	}
	// 二部グラフなら異なる集合に属する2点間には必ず奇数長のパスが存在する
	if (dfs(0,1)) r = bl*wh - m;
	// 二部グラフじゃないなら任意の2頂点間には必ず長さが偶/奇両方のパスが存在する
	else r = n*(n-1)/2 - m;
	cout << r << ln;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> dists(N), ids(N), cnts(N);
  for (int i = 0; i < N; i++) {
    int id, dist, c;
    cin >> id >> dist >> c;
    dists[i] = dist;
    cnts[i] = 20*c;
    ids[i] = id;
  }

  vector<int> ws(1<<N, 0);
  for (int s = 0; s < (1<<N); s++) {
    for (int i = 0; i < N; i++) {
      if (s & (1<<i)) {
        ws[s] += cnts[i];
      }
    }
  }

  vector<vector<int> > prev(1<<N, vector<int>(N));
  vector<vector<double> > dp(1<<N, vector<double>(N, numeric_limits<double>::max()));
  for (int i = 0; i < N; i++) {
    dp[1<<i][i] = 0;
    prev[1<<i][i] = -1;
  }
  for (int s = 0; s < (1<<N); s++) {
    const double v = 2000.0/(70.0+ws[s]);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (!(s & (1<<i)) || s & (1<<j)) {
          continue;
        }
        const double t = dp[s][i] + abs(dists[i]- dists[j]) / v;
        if (dp[s|(1<<j)][j] > t) {
          dp[s|(1<<j)][j] = t;
          prev[s|(1<<j)][j] = i;
        }
      }
    }
  }

  int last = -1;
  double m = numeric_limits<double>::max();
  for (int i = 0; i < N; i++) {
    if (dp[(1<<N)-1][i] < m) {
      m = dp[(1<<N)-1][i];
      last = i;
    }
  }

  vector<int> ans;
  for (int s = (1<<N)-1, i = last; i >= 0;) {
    ans.push_back(i);
    const int j = prev[s][i];
    s &= ~(1<<i);
    i = j;
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < N; i++) {
    if (i != 0) {
      cout << ' ';
    }
    cout << ids[ans[i]];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 7960
from collections import deque
n = int(raw_input())
edges = []
for i in range(n - 1):
    edges.append(map(int, raw_input().split()))
edge_num = {}
G = [[] for i in range(n)]
ans = [0] * (n - 1)
for i in range(n - 1):
    s, e = edges[i]
    s = s - 1
    e = e - 1
    edge_num[(s, e)] = i
    edge_num[(e, s)] = i
    G[s].append(e)
    G[e].append(s)
vis = set([])
q = deque([0])
vis.add(0)
while q:
    u = q.popleft()
    not_colored = []
    colors = set([])
    for v in G[u]:
        i = edge_num[(u, v)]
        if ans[i] == 0:
            not_colored.append(i)
        else:
            colors.add(ans[i])
        if not v in vis:
            vis.add(v)
            q.append(v)
    color = 1
    for i in not_colored:
        while color in colors:
            color += 1
        ans[i] = color
        color += 1
print len(set(ans))
for i in ans:
    print i

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

 
  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;
 
  if(y==NIL)
    root = z;
  else if(z->key<y->key)
    y->left = z;
  else
    y->right = z;
 
}

void inorder(Node u){
 if(u==NIL)
    return;
   
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
 if(u==NIL)
    return;
   
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040