akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

int cday[1024][16][32];

int main(void){
  int n, y, m, d;
  int cnt = 0;
  reps(i,1,1000){
    reps(j,1,10){
      reps(k,1,20){
        if(i%3 != 0 && j%2 == 0 && k > 19)break;
        cday[i][j][k] = ++cnt;
      }
    }
  }
  cin >> n;
  rep(l,n){
    cin >> y >> m >> d;
    cout << cday[1000][1][1] - cday[y][m][d] << endl;
  }

  return 0;
}

Measured memory_bytes: 5064
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>

using namespace std;

int main(void)
{
	int N;
	vector <int> a;
	int res,temp,sum,m=9999999;
	sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> temp;
		a.push_back(temp);
		sum += temp;
	}

	sort(a.begin(), a.end());
	res = 0;
	temp = sum / N;


	for (; temp <= a[N - 1]; temp++)
	{
		res = 0;
		for (int i = 0; i < N; i++)
		{
			res += (a[i] - temp)*(a[i] - temp);
		}
		m = min(res, m);
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
import bisect
N,K=map(int,input().split())
A=list(map(int,input().split()))

#全ての丸太を長さt以下にするのに必要な切断数が
#k以下であるような最大のtを求める
ok=max(A)
ng=0

def isok(t):
  res=0
  for i in range(N):
    res+=A[i]//t-(A[i]%t==0)
  return res<=K

while abs(ok-ng)>1:
  mid=(ok+ng)//2
  if isok(mid):
    ok=mid
  else:
    ng=mid

print(ok)


Measured memory_bytes: 93964
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    string board[6];
    REP(i, H) cin >> board[i];

    ll ans = 0;
    REP(h, 1 << H) REP(w, 1 << W) {
        ll cnt = 0;
        REP(i, H) {
            if ((h >> i) & 1) continue;

            REP(j, W) {
                if ((w >> j) & 1) continue;
                if (board[i][j] == '#') cnt++;
            }
        }
        if (cnt == K) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
 
int main(){
  int A,B,C,D,K;
  	cin >>A;
  K=A;
 	A=A/1000;
  	B=(K-A*1000)/100;
  	C=(K-A*1000-B*100)/10;
  	D=(K-A*1000-B*100-C*10);
  
  	if((A+B+C+D)==7) cout << A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7";
  else if((A+B+C-D)==7) cout << A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7";
   else if((A+B-C+D)==7) cout << A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7";
   else if((A-B+C+D)==7) cout << A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7";
   else if((A-B-C+D)==7) cout << A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7";
   else if((A+B-C-D)==7) cout << A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7";
   else if((A-B+C-D)==7) cout << A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7";
   else if((A-B-C-D)==7) cout << A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7";

  
  
  
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int,int);
int main(){
  int x,y,z,ans;
  scanf("%d%d",&x,&y);
  if(x<y){
    z=x;
    x=y;
    y=z;
  }
  ans=gcd(x,y);
  printf("%d\n",ans);
  return 0;
}
int gcd(int x,int y){
  if(x%y==0) return y;
  return gcd(y,x%y);
}
  



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



int main(){
    int A, B, C;
    cin >> A >> B >> C;

    int res = C - (A - B);
    if(res < 0){
        cout << 0 << endl;
    }else{
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

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>
bool isPrime(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 binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

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

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

	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		int left = min(a[i], b[i]);
		a[i] -= left;
		b[i] -= left;
		ans += left;

		int right = min(b[i], a[i + 1]);
		b[i] -= right;
		a[i + 1] -= right;
		ans += right;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
ll d[300005]={};
ll fa[300005]={};
ll ea[300005]={};
int n;
void addx(int k,int m){
	while(k<300005){
		d[k]+=m;
		k+=k&-k;
	}
	return;
}
int sumx(int k){
	int r=0;
	while(k>0){
		r+=d[k];
		k-=k&-k;
	}
	return r;
}
bool ex(int k){
	while(k>0){
		if(d[k]>0)return true;
		k-=k&-k;
	}
	return false;
}

int main() {
	ll a[300003]={};
	cin>>n;
	vector<ll> v;
	for(int i=0;i<3*n;++i){
		cin>>a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());

	ll tf=0;
	for(int i=0;i<n;++i){
		tf+=a[i];
		auto it=upper_bound(v.begin(),v.end(),a[i]);
		int k1=it-v.begin();
		addx(k1,1);
//		cout<<k1<<endl;
	}
	fa[n-1]=tf;
	for(int i=n;i<2*n;++i){
		auto it=upper_bound(v.begin(),v.end(),a[i]);
		int k1=it-v.begin();
		if(sumx(k1)>0){
			tf+=a[i];
			addx(k1,1);
			int ub=300003,lb=0;
			while(ub-lb>1){
				int mid=(ub+lb)/2;
				if(ex(mid)){
					ub=mid;
				}else{
					lb=mid;
				}
			}
			addx(ub,-1);
			tf-=v[ub-1];
		}
		fa[i]=tf;
	}
	for(int i=0;i<300005;++i)d[i]=0;
	tf=0;
	for(int i=2*n;i<3*n;++i){
		tf+=a[i];
		auto it=upper_bound(v.begin(),v.end(),a[i]);
		int k1=it-v.begin();
		addx(k1,1);
	}
	ea[2*n]=tf;
	for(int i=2*n-1;i>=n;--i){
		auto it=upper_bound(v.begin(),v.end(),a[i]);
		int k1=it-v.begin();
		if(sumx(k1)<n){
			tf+=a[i];
			int ub=300003,lb=0;
			while(ub-lb>1){
				int mid=(ub+lb)/2;
				if(sumx(mid)<n){
					lb=mid;
				}else{
					ub=mid;
				}
			}
			addx(ub,-1);
			tf-=v[ub-1];
			addx(k1,1);
		}
		ea[i]=tf;
	}
	ll t=-100000000000000;
	for(int i=0;i<n+1;++i){
//		cout<<fa[n+i-1]<<" "<<ea[n+i]<<endl;
		t=max(t,fa[n+i-1]-ea[n+i]);
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 12524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }

int main(){
  int n,m; cin>>n>>m;
  cout<<(1900*m+100*(n-m))*(1<<m)<<endl;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int K, N; cin >> K >> N;
        if(K % 2 == 0) {
            cout << K / 2;
            rep(i, N - 1) cout << " " << K;
            cout << endl;
        } else {
            int left = (N - 1 + 1) / 2;
            vector<int> ans(N);
            rep(i, N) ans[i] = K / 2 + 1;
            rep(i, left) {
                if(ans.back() == 1) {
                    ans.pop_back();
                } else {
                    ans.back()--;
                    while(ans.size() != N) ans.push_back(K);
                }                
            }            
            rep(i, ans.size()) cout << (i == 0 ? "" : " ") << ans[i];
            cout << endl;
        }        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	int ans = 0;
	int n = t.length();
	int l = s.length();
	for(int i=0; i+n<=l; i++) {
		string a = s.substr(i, i+n);
		int cek = 0;
		for(int j=0; j<n; j++) {
			if(t[j] == a[j]) cek++;
		}
		ans = max(ans, cek);
	}
	printf("%d", n - ans);
	
	return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define forr(i,n) for(int i(0);i<n;++i)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define count(x) __builtin_popcount(x) 
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

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

int main(){
	int n;
	cin >> n;
	int arr[n];
	forr(i,n) cin >> arr[i];
	int m1=0;
	forr(i,n){
		if(i&1) m1-=arr[i];
		else m1+=arr[i];
	}
	int go[n];
	go[0]=m1;
	for(int i(1);i<n;++i){
		go[i]=2*arr[i-1]-go[i-1];
	}
	for(int i(0);i<n;++i){
		cout << go[i] << " ";
	}
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c;
  cin>>a>>b>>c;
  int sum = a + b + c;
  if(sum >= 22){
    cout<<"bust"<<endl;
  }else{
    cout<<"win"<<endl;

  }

  return 0;
}


Measured memory_bytes: 256
// C++ program to count common subsequence in two strings 
#include <bits/stdc++.h> 
using namespace std; 
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

// return the number of common subsequence in 
// two strings 
ll dp[2001][2001]; 
ll mod = 1e9+7;
ll CommomSubsequencesCount(vector<ll> &s, vector<ll> &t) { 
	int n1 = s.size(); 
	int n2 = t.size(); 

	for (int i = 0; i <= n1; i++) { 
		for (int j = 0; j <= n2; j++) { 
			dp[i][j] = 0; 
		} 
	} 

	// for each character of S 
	for (int i = 1; i <= n1; i++) { 

		// for each charcater in T 
		for (int j = 1; j <= n2; j++) { 

			// if character are same in both 
			// the string 
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = 1;
				dp[i][j] = (dp[i][j]+ dp[i][j - 1])%mod;
				dp[i][j] = (dp[i][j]+ dp[i-1][j])%mod;
			}
			else{
				dp[i][j] = dp[i][j - 1]%mod;
				dp[i][j] = (dp[i][j] + dp[i - 1][j])%mod;
				dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + mod)%mod;			 
			}
		} 
	} 

	return dp[n1][n2]%mod; 
} 

int main(){
	int n,m;
	cin>>n>>m;
	vector<ll> a,b;
	for(int i=0;i<n;i++){
		int u;
		cin>>u;
		a.pb(u);
	}			
	for(int i=0;i<m;i++){
		int u;
		cin>>u;
		b.pb(u);
	}
	ll ans = (CommomSubsequencesCount(a,b)+1ll)%mod;
	cout<<ans<<endl;
}


Measured memory_bytes: 31616
N = int(input())
A = [int(i) for i in input().split()] 
mod = 10**9 + 7

b = [0]*N #
b[0] = A[0]
for n in range(1,N):
    b[n] = A[n] ^ b[n-1]
#print('累積論理和',b)
m = max(b)
dp = [[0]*(m+1) for j in range(2)]
dp[0] = [True]*(m+1)
dp[1] = [False]*(m+1)
cnt = [0]*(m+1)
z = 0

for i in range(N):
    if b[i] == 0:
        z +=1
    dp[0][b[i]] += dp[1][b[i]]*(z-cnt[b[i]])
    dp[0][b[i]] %= mod
    dp[1][b[i]] += dp[0][b[i]]
    dp[1][b[i]] %= mod
    cnt[b[i]] = z


if b[N-1]:
    print(dp[0][b[N-1]])
else:
    ans = pow(2, z-1, mod)
    for i in range(1,m+1):
        ans += dp[1][i]
        ans %= mod
    print(ans)

Measured memory_bytes: 138528
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n);
    vector<ll> cnt(m);
    REP(i, n){
        cin >> x[i];
        cnt[x[i] % m]++;
    }
    ll ans = 0;
    ans += cnt[0] / 2;
    cnt[0] %= 2;
    for(ll i = 1; i < (m + 1) / 2; i++){
        ll tmp = min(cnt[i], cnt[m - i]);
        ans += tmp;
        cnt[i] -= tmp;
        cnt[m - i] -= tmp;
    }
    if(m % 2 == 0){
        ans += cnt[m / 2] / 2;
        cnt[m / 2] %= 2;
    }
    sort(x.begin(), x.end());
    REP(i, n - 1){
        if(x[i] == x[i + 1] && cnt[x[i] % m] >= 2){
            cnt[x[i] % m] -= 2;
            ans++;
            i++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
def main(N, A):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j += -1
        A[j+1] = v
        print(' '.join(map(str, A)))
    return A


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)



Measured memory_bytes: 5604
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
M = max(a)
cands = [0]*M

ans = 0
for num in a:
    if cands[num-1] >= 2:
        continue
    for i in range(num, M+1, num):
        cands[i-1] += 1
        
for num in a:
    if cands[num-1]==1:
        ans+=1
print(ans)

Measured memory_bytes: 32228
import sys
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    else:
        for i in range(h):
            for j in range(w):
                if (i + j)%2 == 0:
                    sys.stdout.write("#")
                else:
                    sys.stdout.write(".")
            print()
        print()

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        { 
            var input=Console.ReadLine();
            var a = int.Parse(input);
            Console.Write(a + a * a + a * a * a);
        }
    }
}


Measured memory_bytes: 17600
n, m = map(int, input().split())
d = dict.fromkeys(list(range(1, n + 1)), 0)
for i in range(m):
    a, b = map(int, input().split())
    d[a] += 1
    d[b] += 1
for i in range(1, n + 1):
    print(d[i])


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

const int N = 3004;
string s, t, res = "";
int dp[N][N];

void track(){

}

int main(){
	memset(dp, 0, sizeof dp);

	cin >> s >> t;

	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < t.size(); j++){
			if(i == 0){
				if(s[i] == t[j]) dp[i][j] = 1;
				else dp[i][j] = dp[i][j-1];
			}
			else{
				if(s[i] != t[j]) dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
				else dp[i][j] = dp[i-1][j-1]+1;
			}
		}
	}

	int tar = dp[s.size()-1][t.size()-1], i = s.size()-1, j = t.size()-1;
	while(tar > 0){
		if(s[i] == t[j]){
			res = s[i] + res;
			tar--;
			i--;
			j--;
		}
		else{
			if(i-1 >= 0 && dp[i-1][j] == tar) i--;
			else j--;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 35456
n,k = map(int, input().split())
p = list(map(int, input().split()))
p = [i-1 for i in p]
c = list(map(int, input().split()))
loops = []
used = set()
for i in range(n):
    if i in used:
        continue
    used.add(i)
    tmp = [i]
    nxt = p[i]
    while nxt not in used:
        tmp.append(nxt)
        used.add(nxt)
        nxt = p[nxt]
    loops.append(tmp)

def calc(l,r,cs):
    if r == 0:
        return 0
    tmp = -float("inf")
    for i in range(2*l):
        for j in range(i+1, min(2*l, i+r)+1):
            x = cs[j] - cs[i]
            if tmp < x:
                tmp = x
    return tmp

ans = -float("inf")

for loop in loops:
    s = sum(c[i] for i in loop)
    l = len(loop)
    tmp_loop_score = [c[i] for i in loop]
    for i in loop:
        tmp_loop_score.append(c[i])

    tmp_ans_max = max(tmp_loop_score)
    ans = max(ans, tmp_ans_max)

    cs = [0]
    for i in range(2*l):
        cs.append(cs[-1] + tmp_loop_score[i])

    if s > 0:
        m = k//l
        tmp_ans = m*s
        r = k%l
        tmp_ans += calc(l,r,cs)
        r = min(l, k)
        tmp_ans = max(tmp_ans, calc(l,r,cs))
        if m > 0:
            tmp = (m-1)*s
            r = (k%l) + l
            tmp += calc(l,r,cs)
            tmp_ans = max(tmp, tmp_ans)
    else:
        r = min(2*l, k)
        tmp_ans = calc(l,r,cs)

    ans = max(ans, tmp_ans)
print(ans)



Measured memory_bytes: 70308
#include<stdio.h>

char func(int* n){
    int x = *(n) / -2;
    if(*(n) - x*(-2) == -1){
        x++;
    }
    char dst;
    if(*(n) - x*(-2)){
        dst = '1';
    }else{
        dst = '0';
    }
    *(n) = x;
    return dst;
}

int main(){
    int n;
    scanf("%lld", &n);
    if(n == 0){
        printf("0");
    }else{
        char s[1000];
        int x = 0;
        while(n != 0){
            s[x++] = func(&n);
        }
        for(int i=x-1; i>=0; i--){
            printf("%c", s[i]);
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef std::string str;
#define elif else if

void FAST() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main() {
    FAST();
    int n;
    cin >> n;
    int r = n % 10;
    if (r == 3) {
        cout << "bon\n";
    }
    elif (r == 0 || r == 1 || r == 6 || r == 8) {
        cout << "pon\n";
    }
    else {
        cout << "hon\n";
    }
}

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

using namespace  std;

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

int main(){
    int N;
    while(cin >> N, N){
        vector<vector<bool> > know(N, vector<bool>(N));
        rep(i, N){
            int M;
            cin >> M;
            while(M--){
                int p;
                cin >> p;
                p--;
                know[i][p] = true;
            }
        }
        vector<bool> leak(N, true);
        int K;
        cin >> K;
        while(K--){
            int l;
            cin >> l;
            l--;
            rep(i, N)if(leak[i] && !know[i][l])leak[i] = false;
        }
        cout << (count(all(leak), true) != 1? -1: find(all(leak), true) - leak.begin() + 1) << '\n';
    }
    return 0;
}

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

using namespace std;
int main(){
    string S1, S2;
    bool check=true;

    cin>>S1;
    cin>>S2;
    
    if(S2.length()-S1.length()!=1){
        cout<<"No\n";
    }
    else{
        for(int i=0; i<S1.length(); i++){
            if(S1[i] != S2[i]){
                check = false;
                break;
            }
        }
        if(check){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
    

    return 0;
}



Measured memory_bytes: 3596
function main()
  
  N = split(chomp(readline()),"")
  M = map(x -> parse(Int,x), N)

  check1 = parse(Int,join(N))
  check2 = sum(M)

  if check1 % check2 == 0
    println("Yes")
  else
    println("No")
  end
  
end

main()

Measured memory_bytes: 116364
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

struct edge {int to, cost; };
vector<edge> G[100010];
int L[100010];

void dfs(int V, int prev, int cost) {
    L[V] = cost;
    rep(i, G[V].size()) {
        if (G[V][i].to == prev) continue;
        dfs(G[V][i].to, V, cost + G[V][i].cost);
    }
}
 
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    rep(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    rep(i, 100010) L[i] = INF;
    int Q, K;
    cin >> Q >> K;
    L[K] = 0;
    dfs(K, -1, 0);
    int x[Q], y[Q];
    rep (i, Q){
        cin >> x[i] >> y[i];
        cout << L[x[i]] + L[y[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 15872
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

ans = 'Christmas'
eve=' Eve'
N = int(readline())

print(ans+eve*(25-N))


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

int main() {
  int n,m;
  cin >> n >> m;
  int a[n],b[n],c[m],d[m];
  REP(i,n) cin >> a[i] >> b[i];
  REP(i,m) cin >> c[i] >> d[i];

  REP(i,n) {
    int md = 1001001001;
    int ans = 0;
    REP(j,m) {
      int dd = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dd < md) { ans = j+1; md = dd; }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    int m=min(a.length(),b.length());
    for(int i=0;i<m;i++){
        cout << a[i] << b[i];
    }
    if(a.length()>b.length()){
        for(int i=m;i<a.length();i++){
            cout << a[i];
        }
    }
    if(b.length()>a.length()){
        for(int i=m;i<b.length();i++){
            cout << b[i];
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		if(n%2==0) {
			String flag = "t";
			for(int i=0;i<n/2;i++) {
				if(a[i*2]!=a[i*2+1]){
					flag = "f";
				}
			}
			if(flag.equals("f")) {
				System.out.println(0);
			}else {
				long ans= 1;
				for(int i=0;i<n/2;i++) {
					ans *= 2;
					ans %= 1000000007;
				}
				System.out.println((int)ans);
			}
		}else {
			if(a[0]==0) {
				String flag = "t";
				for(int i=0;i<n/2;i++) {
					if(a[i*2+1]!=a[i*2+2]){
						flag = "f";
					}
				}
				if(flag.equals("f")) {
					System.out.println(0);
				}else {
					long ans= 1;
					for(int i=0;i<n/2;i++) {
						ans *= 2;
						ans %= 1000000007;
					}
					System.out.println((int)ans);
				}
			}else {
				System.out.println(0);
			}
		}
	}

}

Measured memory_bytes: 49456
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  long long int k,s;
  cin>>k>>s;
  long long int ans=0;
  for(int x=0; x<=k; x++){
    for(int y=0; y<=k; y++){
      if(s-x-y<=k&&s-x-y>=0){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {

    int n, m, l, k,t,H,D;
    scanf("%d%d",&n,&m);
    l=n+m;
    if(l<24){
        printf("%d\n",l);
    }
    else if(l>24){
       printf("%d\n",l-24);
    }
    else{
       printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long> a(n);
	long long sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		sum += a[i];
		sum %= 1000000007;
	}

	long long ans = 0;
	for (int i = 0;i < n;i++) {
		sum -= a[i];
		if (sum <= 0) {
			sum += 1000000007;
		}
		ans += a[i] * sum;
		ans %= 1000000007;
	}

	if (ans < 0) {
		ans += 1000000007;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> i >> j;
    if(i == 1 && j == 1){
        cout << 1000000 << endl;
        return;
    }
    long long ans = 0;
    if(i < 4) ans += (4-i)*100000;
    if(j < 4) ans += (4-j)*100000;
    cout << ans << endl;
}

int main(){
    solve();
}


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

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

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

	for (int i = 1; i < n; i++) {
		for (int k = 0; k < n; k++) {
			cout << a[k];
			if (k != n - 1) cout << " ";
		}
		cout << "\n";
		int key = a[i];
		// insert a[i] into the sorted sequence a[0..j-1]
		int j = i - 1;
		while (j >= 0 & a[j] > key) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = key;
	}
	for (int k = 0; k < n; k++) {
		cout << a[k];
		if (k != n - 1) cout << " ";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

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

const ll inf = 2e9;
const ll mod = 998244353;
const int N = 3e3 + 11;
const int NMAX = 3e2 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

//ifstream in(".in");
//ofstream out(".out");

int n, m, dp[N][N];
char sir[N];

void solve(){

    string s,t;

    cin >> s >> t;

    for(int i = 1; i <= sz(s); i++){
        for(int j = 1; j <= sz(t); j++){
            if(s[i - 1] == t[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    int i = sz(s), j = sz(t), k = 0;
    while(i){
        if(s[i - 1] == t[j - 1]){
            sir[++k] = s[i - 1];
            i--;
            j--;
        }else
        if(dp[i - 1][j] < dp[i][j - 1])j--;else i--;
    }

    reverse(sir + 1, sir + k + 1);

    for(int i = 1; i <= k; i++)cout << sir[i];
}


int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //cout << setprecision(20) << fixed;

    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 74140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,j,y=0,z,w,t=0;
  cin>>m;
  vector<int> x(m);
  for(j=0;j<m;j++){
    cin>>x[j];
    y+=x[j];
  }
  z=abs(y);
  w=z/m;
  if(z%m*2>m) w++;
  if(y<0) w*=-1;
  for(j=0;j<m;j++) t+=(x[j]-w)*(x[j]-w);
  cout<<t<<endl;
}

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


using namespace std;

int main() {

    
    int col, row, counter = 0, i, j, k, count = 0;
    cin >> row >> col;
    char arr[row][col];
    for (i=0;i<row;i++) {
        for (j=0;j<col;j++) {
            cin >> arr[i][j];
            if (arr[i][j] == '.') counter++;
        }
        if (counter == col) {
            i--;
            row--;
        }
        counter = 0;
    }
    for (i=0;i<row;i++) {
        for (j=0;j<col;j++) {
            for (k=0;k<row;k++) {
                if (arr[k][j]=='.') 
                    count++;
            }
            if (count != row) {
                cout << arr[i][j];
            }
            count = 0;
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 256
/*
Date: 2017/02/25 19:33:11 Saturday
*/
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=555,M=111111;
int l,m,n,t,C;
int a[N][N];
char ch;
int main(){
#ifdef LOCAL
	freopen("B.in","r",stdin);//freopen("B.out","w",stdout);
#endif
	scanf("%d",&n);rep(i,1,n)rep(j,1,n)gc(ch),a[i][j]=ch=='.'?0:1,l+=a[i][j];
	if(l==0){puts("-1");return 0;}
	int ans=n+n;
	rep(i,1,n){
		int s=0,ok=0;
		rep(j,1,n)s+=a[i][j]==0;
		rep(j,1,n)ok+=a[j][i];if(!ok)++s;
		rep(j,1,n){
			int t=0;rep(k,1,n)t+=a[k][j]==0;
			s+=!!t;
		}
		MIN(ans,s);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

const int MAX_N = 500010;

class BIT {
public:
  BIT(int N_) {
    N = N_;
    bit = vector<int>(MAX_N, 0);
  }
  ~BIT() {
  }

  int sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= (i & -i);
    }
    return s;
  }

  int sum(int l, int r) {
    return sum(r) - sum(l - 1);
  }

  void add(int i, int x) {
    while (i <= N) {
      bit[i] += x;
      i += i & -i;
    }
  }

  int N;
  vector<int> bit;
};

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

  vector<BIT> bits(26, BIT(N));
  for (int pos = 0; pos < N; pos++) {
    char c = S[pos];
    bits[c - 'a'].add(pos + 1, +1);
  }

  for (int i = 0; i < Q; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      cin >> pos;
      pos--;
      char c = S[pos];
      bits[c - 'a'].add(pos + 1, -1);
      cin >> c;
      S[pos] = c;
      bits[c - 'a'].add(pos + 1, +1);
    } else {
      int l, r;
      cin >> l >> r;
      int answer = 0;
      for (int k = 0; k < 26; k++) {
	if (bits[k].sum(l, r) > 0) {
	  answer++;
	}
      }
      cout << answer << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 53764
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int sum = 0;
    rep(i, n) {
        int l, r; cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}
    


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int hm = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= hm) {
            hm = h;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

typedef pair<int, int> Range;
typedef pair<Range, string> Pair;

int main() {
  int n, q, query, based, western;
  string name;
  Pair pairs[1000];
  while (true) {
    cin >> n >> q;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> name >> based >> western;
      pairs[i].first = Range(western - based, western);
      pairs[i].second = name;
    }
    sort(pairs, pairs + n);
    for (int i = 0; i < q; ++i) {
      cin >> query;
      for (int j = 0; j < n; ++j) {
        if (pairs[j].first.first < query and query <= pairs[j].first.second) {
          cout << pairs[j].second << " " << query - pairs[j].first.first << endl;
          goto last;
        }
      }
    cout << "Unknown" << endl;
last:
    continue;
    }
  }
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int a,b; cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
    return 0;
}

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

using namespace std;

int main()
{

	int n;
	cin>>n;

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

	long mx=arr[0],ans=0;
	for(int i=1;i<n;i++)
	{
		if(arr[i]>=mx)
			mx=arr[i];

		else ans+=(mx-arr[i]);
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 4396
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>

void work() {
    int n;
    cin >> n;
    LL ansx = 1, ansy = 1;
    for (int i = 1; i <= n; ++i) {
        LL a, b;
        cin >> a >> b;
        LL k1 = 1;
        if (a < ansx) {
//            k1 = max(k1, (LL)ceil(1.0 * ansx / a));
            k1 = (ansx + a - 1) / a;
        }
        if (b < ansy) {
//            k1 = max(k1, (LL)ceil(1.0 * ansy / b));
            k1 = max(k1, (ansy + b - 1) / b);
        }
        ansx = a * k1;
        ansy = b * k1;
    }
    cout << ansx + ansy << endl;
}

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work();
    return 0;
}


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

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& (a) : (x))
#define all(x) (x).begin (), (x).end ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair<int, int> pii;
#define f first
#define s second
#define mp(x) make_pair ((x))

typedef vector<int> vi;
#define pb(x) push_back ((x))

#define DEBUG 0
#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

#define EXIT ddprintf ("Time elapsed %lf\n", 1.0 * clock() / CLOCKS_PER_SEC); exit (0)

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x3f3f3f3f3f3f3f3f;
const int  INFi  =  0x3f3f3f3f;
const ll   MAXN  =  1e+6+7;

vector <pii> dl;
vector <vi> dp;
int m;

int ks (int t, int w)
{
    ddprintf ("t:%9d | w:%9d\n", t, w);
    if (t == sz (dl))
        return 0;
    if (dp[t][w+m] != -1)
        return dp[t][w+m];
    if (w <= 0)
    {
        dp[t][w+m] = ks(t + 1, w);
        ddprintf ("r:%9d |\n", dp[t][w+m]);
        return dp[t][w+m];
    }
    int v1 = ks(t + 1, w), v2 = ks(t + 1, w - dl[t].f) + dl[t].s;
    dp[t][w+m] = max (v1, v2);
    ddprintf ("r:%9d | 1:%9d | 2:%9d\n", dp[t][w+m], v1, v2);
    trav (a, dp)
    {
        trav (b, a)
            ddprintf ("%4d ", b);
        ddprintf ("\n");
    }
    return max (v1, v2);
}

int main ()
{
    int i, j;
    int N, T;
    m = 0;
    scanf ("%d %d", &N, &T);
    dl.resize (N);
    trav (a, dl)
    {
        scanf ("%d %d", &a.f, &a.s);
        m = max (m, a.f);
    }
    sort (all (dl));
    dp = vector <vi> (N + 1, vi (T + 1 + m, -1));
    trav (a, dl)
        ddprintf ("%d %d\n", a.f, a.s);
    trav (a, dp)
    {
        trav (b, a)
            ddprintf ("%d ", b);
        ddprintf ("\n");
    }
    ddprintf ("\n");
    printf ("%d\n", ks (0, T));
    

    EXIT;
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define endl "\n"
using Edge = pair<int,ll>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  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 {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(void){
  int n,k; cin >> n >> k;
  combination c(n+5);

  mint ans = 0;
  FOR(i,0,min(k,n)){
    mint res = c(n,i);
    res *= c(n-1,i);
    ans += res;
  }
  cout << ans.x << endl;

  
}




Measured memory_bytes: 3328
#include <iostream>
     #include <string>
     #include <vector>
     #include <algorithm>
     #include <utility>
     #include <map>
     using namespace std;
     typedef long long ll;
     #define rep(i, n) for (int i=0;i < (int)(n);i++)
     ll dp[1001][1001];
     char maze[1001][1001];
     const ll mod =1e9+7;
     int main(){
          int h,w;
          cin >> h >> w;
          rep(i,h) rep(j,w) cin >> maze[i][j];
          string s;
          dp[0][0]=1;
          rep(i,h){
               rep(j,w){
                    if (maze[i][j]=='#') continue;
                    if (j-1 >= 0  && j-1 < w && maze[i][j-1]!='#') {
                         dp[i][j]+=dp[i][j-1];
                         dp[i][j]%=mod;
                    }
                    if (i-1 >= 0 && i-1 < h && maze[i-1][j]!='#') {
                         dp[i][j]+=dp[i-1][j];
                         dp[i][j]%=mod;
                    }
               }
          }
          //rep(i,h){
          //     rep(j,w) cout << dp[i][j];
          //     printf("\n");
          //}
          cout << dp[h-1][w-1]%mod << endl;
          
          return 0;
     
     }


Measured memory_bytes: 9088
(n,*c),a,*q=$<.map{_1.split.map &:to_i}
b=(0..n).map{_1&-_1}
d=b.map{[]}
u=i=k=0
z=q.map{d[_2]<<[_1-1,~k-=1]}
a.map{t=c[_1]||n+u+=1
(b[t]-=1;t+=t&-t)until t>n
d[c[_1]=i+=1].map{|x,y|z[y]=u
(z[y]-=b[x];x&=x-1)while x>0}}
p *z

Measured memory_bytes: 179904
#include<bits/stdc++.h>
using namespace std;
int q,p,w[1000001],u[1000001],o;
string a;
int main()
 {
     cin>>a;
     for (int i=0;i<a.size();i++)
     {
         if (a[i]=='C') 
         {
             p++;
             u[p]=i+1;
         }
         else if (a[i]=='F')
         {
            q++;
             w[q]=i+1;
         }
     }
     if (q>=1 && p>=1)
     {
     for (int i=1;i<=p;i++)
     {
         for (int j=1;j<=q;j++)
         {
             if (u[i]<w[j])
             {
                 o=1;
             }
         }
     }
     if (o==1) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;   
     }
     else cout<<"No"<<endl;
 }

Measured memory_bytes: 2812
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	d := max(0, c-(a-b))
	fmt.Println(d)
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 512
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
A.sort(reverse=True)
line = (1/(4*M))*sum(A)
flag = False
for i in range(M):
    if A[i] >= line:
        flag = True
    else:
        flag = False
if flag == True:
    print('Yes')
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>

int SelectionSort(int [],int n);
int min(int, int);

int main()
{
  int n;
  int i;
  int A[110];
  int cnt=0;
  
  scanf("%d",&n);
  for(i=0;i < n;i++){
    scanf("%d",&A[i]);
  }

  cnt = SelectionSort(A,n);
  printf("%d\n",cnt);
  return 0;
}

int SelectionSort(int A[],int n)
{
  int i,j;
  int cnt = 0;
  
  int mini;
  int temp;
  
  for(i=0;i < n;i++){
    mini = i;
    
    for(j = i+1;j < n;j++){
      if(A[j] < A[mini]) mini = j;
    }
    
    temp = A[mini];
    A[mini] = A[i];
    A[i] = temp;
    if(mini != i) cnt++;
  }
  
  for(i=0;i < n;i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  
  return cnt; 
}

int min(int a, int b)
{
  if(a < b) return a;
  else return b;
}



Measured memory_bytes: 2760