akhauriyash/Code-Regression huggingface dataset:
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int h, w;
	scanf("%d %d", &h, &w);
	std::vector<V> a(h, V(w));
	REP(i, 0, h) REP(j, 0, w) scanf("%ld", &a[i][j]);

	std::vector<std::pair<P,P>> ans;
	REP(i, 0, h){
		if(i%2==0){
			REP(j, 0, w-1){
				if(a[i][j]%2){
					ans.emplace_back(P(i,j), P(i,j+1));
					a[i][j]--, a[i][j+1]++;
				}
			}
			if(i<h-1 and a[i][w-1]%2){
				ans.emplace_back(P(i,w-1), P(i+1,w-1));
				a[i][w-1]--, a[i+1][w-1]++;
			}
		}else{
			for(int j=w-1; j>0; j--){
				if(a[i][j]%2){
					ans.emplace_back(P(i,j), P(i,j-1));
					a[i][j]--, a[i][j-1]++;
				}
			}
			if(i<h-1 and a[i][0]%2){
				ans.emplace_back(P(i,0), P(i+1,0));
				a[i][0]--, a[i+1][0]++;
			}
		}
	}
	printf("%ld\n", ans.size());
	for(auto pp: ans){
		printf("%ld %ld %ld %ld\n", pp.fi.fi+1, pp.fi.se+1, pp.se.fi+1, pp.se.se+1);
	}
	return 0;
}



Measured memory_bytes: 8432
import itertools
N, M, Q = [int(_) for _ in input().split()]
l = [i+1 for i in range(M)]
P = itertools.combinations_with_replacement(l, N)
A = []
for i in range(Q):
    a, b, c, d = [int(_) for _ in input().split()]
    A.append([a, b, c, d])
ans = 0
for p in P:
    s = 0
    for a in A:
        if p[a[1]-1] - p[a[0]-1] == a[2]:
            s += a[3]
    ans = max(ans, s)
print(ans)


Measured memory_bytes: 9092
def sieve(n):
    p=[True for i in range(n+1)]
    p[0]=p[1]=False
    end=int(n**0.5)

    for i in range(2,end+1):
        if p[i]:
            for j in range(i*i,n+1,i):
                p[j]=False

    return p

def solve(n):
    if n<2:return 0
    cnt=1
    for i in range(3,n+1,2):
        if p[i]:cnt+=1

    return cnt

p=sieve(int(1e6))

while True:
    try:
        n=int(input())
        print(solve(n))
    except:
        break

Measured memory_bytes: 14560
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String l1 = br.readLine();
    	String l2 = br.readLine();
		int n = Integer.parseInt(l1);
		int k = Integer.parseInt(l2);
    	String l3 = br.readLine();
    	String[] l3array = l3.split(" ");
		int sum = 0;
		for(int i = 0; i < l3array.length; i++) {
			int la = Math.abs(Integer.parseInt(l3array[i]));
			int lb = Math.abs(Integer.parseInt(l3array[i]) - k);
			if(la - lb > 0) {
				sum += lb * 2 ;
			} else {
				sum += la * 2;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 20692
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.L;
		long p=0;
		for(int i = 1;;i++) {
			p+=n;
			if(p%360==0){
				Console.WriteLine(i);
				return;
			}
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27536
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] ^= a[i][k] & b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;

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

int main() {
  ll N = 0, ans = 0;
  ll c = 0;
  ll l = -1;
  cin >> N;
  REP(i, N) {
    ll a;
    cin >> a;
    if (i != 0 && l != a) {
      ans += c / 2;
      c = 1;
    } else {
      c++;
    }
    l = a;
  }
  ans += c / 2;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

void __print(int x) {cerr << x;}; void __print(long x) {cerr << x;}; void __print(long long x) {cerr << x;}; void __print(unsigned x) {cerr << x;}; void __print(unsigned long x) {cerr << x;}; void __print(unsigned long long x) {cerr << x;}; void __print(float x) {cerr << x;}; void __print(double x) {cerr << x;}; void __print(long double x) {cerr << x;}; void __print(char x) {cerr << '\'' << x << '\'';}; void __print(const char *x) {cerr << '\"' << x << '\"';}; void __print(const string &x) {cerr << '\"' << x << '\"';}; void __print(bool x) {cerr << (x ? "true" : "false");}

#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
#define pb              push_back
#define all(x)          x.begin(),x.end()
#define ff              first
#define ss              second
#define in(arr)         for(int i=0;i<(int)(sizeof(arr)/sizeof(int));i++) cin >> arr[i];
#define out(arr)        for(int i=0;i<(int)(sizeof(arr)/sizeof(int));i++) cout << arr[i];

//Some Helpful Function
int powmod(int a, int b) {int res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
int string_to_int(string s) {int ans = 0; int p = 1; for (int i = s.size() - 1; i >= 0; i--) {ans += (s[i] - '0') * p; p *= 10;} return ans;}
int fast_pow(int a, int b) {if (b == 1) return a; if (b == 0) return 1; int x = fast_pow(a, b / 2); x *= x; if (b & 1) x *= a; return x;}

//DEBUGGING-LINES
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("inp.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif*/
	int n; cin >> n;
	if(n>=30){
		cout << "Yes" << endl;
	}
	else{
		cout<< "No" << endl;
	}
}

int32_t main()
{
	t_c_c();
	return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    vector<vector<int>> c(3, vector<int>(3));
    rep(i, 3)rep(j, 3) cin >> c[i][j];

    vector<int> a(3), b(3);
    a[0] = 0;
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    bool flag = true;
    rep(i, 3)rep(j, 3){
        if(c[i][j] != a[i] + b[j]) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//一个万能库
using namespace std;
int a,b,c,len;
int main()
{
    cin>>a>>b,c=b;
    while(c>0)
    {
        c/=10,len++;
    }
    a=a*pow(10,len)+b;
    if(sqrt(a)==floor(sqrt(a)))printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n);
  int minus = 0, plus = 0;
  rep(i,n){
    cin >> a[i];
    if(0 < a[i]) plus++;
    if(a[i] < 0) minus++;
  }
  sort(all(a));
  int cnt = 0;
  vi x,y;
  while(1 < minus && a.size() != 1){
    cnt++;
    if(a.back() < 0) minus--;
    x.push_back(a.back());
    y.push_back(a[0]);
    a.back() -= a[0];
    minus--;
    a.erase(a.begin());
  }
  if(a.size() == 1){
    cout << a[0] << endl;
    rep(i,cnt) cout << x[i] << " " << y[i] << endl;
    return 0;
  }

  if(minus == 0 && a.size() == 2){
    cout << a[1]-a[0] << endl;
    cout << a[1] << " " << a[0];
    return 0;
  }
  int num = a[0];
  a.erase(a.begin());
  if(minus == 0){
    cnt++;
    x.push_back(num);
    y.push_back(a[0]);
    num -= a[0];
    a.erase(a.begin());
  }
  while(a.size() != 1){
    cnt++;
    x.push_back(num);
    y.push_back(a[0]);
    num -= a[0];
    a.erase(a.begin());
  }
  cnt++;
  x.push_back(a[0]);
  y.push_back(num);
  a[0] -= num;
  cout << a[0] << endl;
  rep(i,cnt) cout << x[i] << " " << y[i] << endl;
  // cout << "\n";
  return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=1e5+5;
int n,s,x[MAXN];
ll p[MAXN];
int main() {
	n=read();s=read();
	for(int i=1;i<=n;++i)x[i]=read(),p[i]=read();
	int l=1,r=n,lst=-1;
	ll ans=0;
	while(l<=r){
		if(x[r]<s||(x[l]<s&&p[l]<p[r])){
			if(lst!=-1)ans+=abs(x[l]-lst);
			lst=x[l];
			p[r]+=p[l++];
		}else{
			if(lst!=-1)ans+=abs(x[r]-lst);
			lst=x[r];
			p[l]+=p[r--];
		}
	}
	ans+=abs(s-lst);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
double dis(pair<double,double> x,pair<double,double> y){
  return sqrt(pow(abs(x.first-y.first),2.0)+pow(abs(x.second-y.second),2.0));
}
int al(int x){
  if(x==1) return 1;
  else return x*al(x-1);
}
int main(){
  int n,i;scanf("%d",&n);
  pair<double,double> p[n];double ans = 0;int r[n];
  for(i=0;i<n;i++) r[i] = i;
  for(i=0;i<n;i++) scanf("%lf%lf",&p[i].first,&p[i].second);
  do{
    for(i=1;i<n;i++) ans += dis(p[r[i-1]],p[r[i]]);
  }while(next_permutation(r,r+n));
  printf("%.7lf\n",ans/al(n));
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1005
 
main(){
  int i,j,n,c[N][N],m,k,l;
  char str1[N],str2[N];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
	str1[0]='0';
	str2[0]='0';
    scanf("%s%s",str1+1,str2+1);

  m=strlen(str1+1);
  k=strlen(str2+1);
     
  for(l=0;l<=m;l++){
    c[i][0]=0;
  }
 
  for(j=0;j<=k;j++){
    c[0][j]=0;
  }
   
  for(l=1;l<=m;l++){
    for(j=1;j<=k;j++){
      if(str1[l]==str2[j]){
		 c[l][j]=c[l-1][j-1]+1;
	 }
      else if(c[l-1][j]>=c[l][j-1]){
		 c[l][j]=c[l-1][j];
	 }
      else{
		 c[l][j]=c[l][j-1];
      }
	}
  }
  printf("%d\n",c[l-1][j-1]);
 }
  return 0;
}

Measured memory_bytes: 4544
cards=input()
new=cards.split()
a=int(new[0])
b=int(new[1])
c=int(new[2])
k=int(new[3])
if a>k:
    print(k)
else:
    if a+b>k:
        print(a)
    else:
        sum=a+(k-(a+b))*(-1)
        print(sum)


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

int main() {
	string s;
	long long n, q;
	cin >> n >> q;
	cin >> s;
	long long a, b, num = 0;
	long long c[n];
	for(int i = 0;i < n; i++){
		c[i] = 0;
	}
	for(int i = 0; i < n - 1; i++){
		if(s[i] == 'A' && s[i + 1] == 'C'){
			num++;
			
		}
		c[i + 1] = num;
	}
	c[n-1] = num;
	
	for(int i = 0; i < q; i++){
		cin >> a >> b;
		cout << c[b -1] - c[a - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

#define MIN(a,b) ((a)<(b)?(a):(b))

long long f(long long  N, long long  a, long long  b) {
	return a * N + b * ((N == 0 ? 1 : (long long)log10(N)) + 1);
}

bool isOK(long long   index, long long   key, long long  a, long long  b) {
	cerr << f(index, a, b) << ":" <<key<<":"<< index << endl;
	cerr << (f(index, a, b) <= key ? "OK" : "NG") << endl;;
	return f(index, a, b) <= key;
}

// 汎用的な二分探索のテンプレ
long long  binary_search(long long   key, long long  a, long long  b) {
	long long   ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	long long   ok = 10e9 + 1; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	long long index = -1;
	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		long long   mid = (ok + ng) / 2;
		if (isOK(mid, key, a, b)) ng = mid;
		else ok = mid;
		index = ng;
		cerr << index << ":" << ok << ":" << ng << endl;
	}
	return index;
}



/*
}*/

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b;


	return 0;
}

Measured memory_bytes: 3164
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
ss = list(set(s))
tmp = 0
ans = 0
for i in range(len(ss)):
    tmp = s.count(ss[i]) - t.count(ss[i])
    ans = max(ans, tmp)
print(ans)

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

ll at(ll a) {
	if (a == 1) return 1;
	else return 2 * at(a / 2)+1;
}

int main() {
	ll h;
	cin >> h;
	cout << at(h) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define ULL unsigned long long
 
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) (((l)+(r))>>1)
 
const int MOD = (int) 1e9 + 7;
const double eps = (double) 1e-8;
const int maxn = (int) 3e5 + 20;
const double pi = (double) acos(-1.0);
 
void work()
{
    int n, k;
    cin >>n >>k;
    double ans = 0;
    double p = 1.0 / n;
    for(int i = 1; i <= n; i++)
    {
        double tmp = 1.0;
        int j = i;
        while(j < k)
        {
            tmp *= 0.5;
            j <<= 1;
        }
        ans += tmp;
    }
    printf("%.12f\n", ans * p);
//    cout <<ans <<endl;
}
 
 
int main()
{
#ifdef yukihana0416
freopen("in.txt", "r" ,stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
 
    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}

Measured memory_bytes: 256
// complete graph with N nodes
// each edge has an positive integer as weight
// for any node i , if we travell by edges with same node , when we return to i
// each edge in our tour has been used even number time
// assign weights to each edge st the maximal weight is minimzed

#include <iostream>
using namespace std;

int N;



int main(){
  cin >> N;
  for(int i = 1; i <= N - 1; ++i){
    for(int j = i + 1; j <= N; ++j){
      int k = i ^ j;
      for(int x = 0; x < 30; ++x){
        if((1 << x) & k){
          cout << x + 1 << " ";
          break;
        }
      }
    }
    cout << endl;
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    set<string> st;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19156
#include <iostream>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <vector>
#include <math.h>

long long int Get_C(int i,int n)
{
	if(i < n - i)
		i = n - i;
	long long int t = 1;
	int k = 1;
	for(int j = i + 1; j <= n; ++j)
	{
		t *= j;
		t /= k++;
	}
	return t;
}

int main()
{
	int n,p,t,c0 = 0,c1 = 0;
	long long int res = 0,rt = 0;
	scanf("%d %d",&n,&p);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d",&t);
		if(t % 2 == 0)
			c0++;
		else
			c1++;
	}
	if(p == 1)
	{
		if(c1 == 0)
			res = 0;
		else
		{
			for(int i = 1; i <= c1; i += 2)
				res += Get_C(i,c1);
			for(int i = 0; i <= c0; ++i)
				rt += Get_C(i,c0);
			res *= rt;
		}
	}
	else
	{
		for(int i = 0; i <= c1; i += 2)
			rt += Get_C(i,c1);
		for(int i = 0; i <= c0; ++i)
			res += Get_C(i,c0);
		res *= rt;
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 256
s=int(input())

l=[s]*(10**6)
for i in range(10**6):
    if l[i]%2==0:
        l[i+1]=l[i]//2
    else:
        l[i+1]=3*l[i]+1
    if l[i]==4:
        print(i+4)
        exit()
    if l[i]==1:
        print(i+4)
        exit()
    if l[i]==2:
        print(i+4)
        exit()


Measured memory_bytes: 10868
H, W = gets.split.map(&:to_i)
board = H.times.map { gets.chomp.chars }

board.each.with_index do |row, i|
  row.each.with_index do |col, j|
    next if col == '.'
    can_draw =
      (i > 0 && board[i - 1][j] == '#') || # 上
      (i < H - 1 && board[i + 1][j] == '#') || # 下
      (j > 0 && board[i][j - 1] == '#') || # 左
      (j < W - 1 && board[i][j + 1] == '#') # 右
    unless can_draw
      puts 'No'
      exit
    end
  end
end
puts 'Yes'


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n;
long long mx = -2e9;
long long temp[2];
vector<long long>v,ans;
int main(){
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	v.resize(n);
	for(int i = 0;i < n;i++)scanf("%lld",&v[i]),temp[i&1]+=max(v[i],0LL),mx = max(mx,v[i]);
	if(mx <= 0 && mx > -2e9){	
		cout << mx << endl << n - 1 << endl;
		int id = -1;
		for(int i = 0;i < n;i++)if(v[i] == mx)id = i;
		for(int i = n - 1;i > id;i--)cout << i + 1 << endl;
		for(int i = 0;i < id;i++)cout << 1 << endl;
		return 0;
	}
	cout << max(temp[0],temp[1]) << endl;
	bool lol = temp[0] < temp[1];
	while(v.size() >= 3){
		if((lol&1) == (v.size()&1))v.pop_back(),ans.push_back(v.size() + 1);
		else if(v.back() <= 0)v.pop_back(),ans.push_back(v.size() + 1);
		else{
			if(v[v.size() - 3] < 0){
				ans.push_back(v.size() - 2);
				if(v.size() - 3 == 0)v.erase(v.begin());
				else{
					v[v.size() - 3] = v[v.size() - 4] + v[v.size() - 2];
					v.erase(v.begin() + v.size() - 2);
					v.erase(v.begin() + v.size() - 3);
				}
			}
			else{
				ans.push_back(v.size() - 1);
				long long sum = v.back() + v[v.size() - 3];
				for(int i = 0;i < 3;i++)v.pop_back();
				v.push_back(sum);
			}
		}
	}
	if(v.size() > 1)
		if(v.front() < v.back())ans.push_back(1);
		else ans.push_back(2);
	printf("%d\n",ans.size());
	for(auto i : ans)printf("%lld\n",i);
}

Measured memory_bytes: 256
using System;
using System.Collections;
public class KukuC{
    public static void Main(){
        ulong N = ulong.Parse(Console.ReadLine());
        ulong so = (ulong)Math.Floor(Math.Sqrt(N));
        ulong ans = N-1;
        for(ulong i=so; i>1; i--){
            if(N%i == 0){
                ans = i+N/i-2;
                break;
            }
        }
            Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
n=int(input())
A=list(map(int,input().split()))

asum = sum(A)
S={}
for i in range(len(A)):
    if A[i] in S:
        S[A[i]]+=1
    else:
        S[A[i]]=1

D=[]
q=int(input())
for i in range(q):
    diff=0
    b,c =map(int,input().split())
    if not c in S:
        S[c]=0
    if b in S:
        diff = (S[b]*c-S[b]*b)
        S[c]+=S[b]
        S[b]=0

    asum+=diff
    D.append(asum)

for d in D:
    print(d)




Measured memory_bytes: 22540
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
lint extGCD(lint a, lint b, lint &x, lint &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    lint d = extGCD(b, a % b, y, x); 
    y -= a / b * x;
    return d;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  N *= 2;
  if(N == 1) {
    cout << 1 << endl;
    return 0;
  }
  lint ans = N-1;
  vector<lint> rem;
  for(lint i=2; i*i<=N; i++) {
    if(N%i == 0) {
      rem.push_back(1);
      while(N%i == 0) {
        N /= i;
        rem[rem.size()-1] *= i;
      }
    }
  }
  if(N > 1) rem.push_back(N);
  REP(bit, 1<<rem.size()) {
    lint a = -1;
    lint b = 1;
    REP(i, rem.size()) {
      if(bit>>i&1) a *= rem[i];
      else b *= rem[i];
    }
    lint x, y;
    extGCD(a, b, x, y);
    //cout << a << " " << b << " " << -a*x << " " << b*y << endl;
    if(-a*x > 0 && -a*x + 1 == b*y) {
      ans = min(ans, -a*x);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h + 1);
    vector<int> num_s(h + 1);
    vector<pair<int, int>> layer;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') num_s[i]++;
        }
    }
    num_s[h] = 1;
    bool flag = false;
    int front = 0;
    queue<pair<int, int>> task;
    for (int i = 0; i <= h; i++) {
        if (num_s[i] != 0) {
            if (flag) {
                task.push(make_pair(front, i));
                front = i;
            } else {
                flag = true;
            }
        }
    }
    vector<vector<int>> ans(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        s[i] = s[i] + '#';
    }
    int n = 1;
    while (!task.empty()) {
        bool flag2 = false;
        int front2 = 0;
        auto now = task.front();
        task.pop();
        for (int i = 0; i <= w; i++) {
            int temp = 0;
            for (int j = now.first; j < now.second; j++) {
                if (s[j][i] == '#') {
                    temp++;
                }
            }
            if (temp > 0) {
                if (flag2) {
                    for (int k = now.first; k < now.second; k++) {
                        for (int l = front2; l < i; l++) {
                            ans[k][l] = n;
                        }
                    }
                    n++;
                    front2 = i;
                } else {
                    flag2 = true;
                }
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vi t(n);
    rep(i, n) cin >> t[i];
    int m;
    cin >> m;

    vi p(m), x(m);
    rep(i, m) cin >> p[i] >> x[i];

    int sum = 0;
    rep(i, n) sum += t[i];

    rep(i, m)
    {
        cout << sum - t[p[i] - 1] + x[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
import sys

n, jL = map(int, input().split())
values = list(map(int, input().split()))

dp = [sys.maxsize]*n
dp[0] = 0

for i in range(n):
    for j in range(i + 1, i + jL + 1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(values[i]-values[j]))

print(dp[n-1])

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

const int MX = 100005;

int a[MX];
int n, m, v, p;

bool can(int x)
{	
	ll rem = (v - 1) * 1LL * m;
	
	int cc = p - 1;
	for (int j = 1; j <= n; j++) {
		if (j == x) continue;
		if (cc) {
			rem -= m;
			cc--;
		}
		else {
			rem -= min(m, a[x] + m - a[j]);
			if (a[x] + m < a[j]) return false;
		}
	}
		
	return rem <= 0;
}

int main()
{
	ignore = scanf("%d %d %d %d", &n, &m, &v, &p);
	
	for (int i = 1; i <= n; i++) {
		ignore = scanf("%d", a + i);
	}
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	
	int L = 1, R = n;
	int ans = 0;
	
	while (L <= R) {
		int M = (L + R) / 2;
		if (can(M)) {
			ans = M;
			L = M + 1;
		}
		else {
			R = M - 1;
		}
	}
	printf("%d\n", ans);
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s,t;
	cin >> s >> t;
	int n=s.length();
	bool ok = 0;
	for(int i=0; i<n&&!ok; i++){
		string ss = s.substr(i,n-i)+s.substr(0,i);
		if(ss==t)ok=1;
	}
	if(ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B, C;
    cin >> A >> B >> C;
    if (((A==B)&&(C!=A))
        ||((A==C)&&(B!=A))
        ||((B==C)&&(A!=B)))
        cout << "Yes";
    else
        cout << "No";
}

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

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<int> page;
        for(int i=0; i<n; i++){
            int tmp;
            cin >> tmp;
            page.push_back(tmp);
        }
        int i = 0;
        while(i<page.size()){
            int cnt = 0;
            while(cnt+i+1 != page.size() && page[cnt+i+1] == page[cnt+i]+1) cnt++;
            if(i != 0) cout << " ";
            if(cnt == 0){
                cout << page[i];
                i++;
            }else{
                cout << page[i] << "-" << page[i+cnt];
                i += cnt + 1;
            }
        }
        cout << endl;
    }
    return 0;
}

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

long long dp[110][100010];
int w[110],v[110];

int main(){
    int N,W;
    cin>>N>>W;
    for(int i=1;i<=N;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            dp[i+1][j]=dp[i][j];
            if(w[i+1]<=j){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i+1]]+v[i+1]);
            }
        }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int main() {
  int n;
  cin>>n;
  vector<int> A(n),B(n),C(n);
  rep(i,n) cin >> A[i];
  rep(i,n) cin >> B[i];
  rep(i,n) cin >> C[i];
  int sum = 0;
  rep(i,n) {
    sum += B[A[i]-1];
    if( i + 1 < n && A[i] + 1 == A[i+1] ) {
      sum += C[A[i]-1];
    }
  }
  cout << sum << endl;
  compute();
  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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    vector<int> D(K);
    for (int i = 0; i < K; i++) cin >> D[i];
    int ans = N;
    int tmp;
    bool flag;
    while (true) {
        tmp = ans;
        flag = true;
        while(tmp > 0) {
            if (binary_search(D.begin(), D.end(), tmp%10)) {
                flag = false;
                break;
            }
            tmp /= 10;
        }
        if (flag) {
            cout << ans << endl;
            return 0;
        }
        else ans++;
    }
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string c,ans;
	deque<string>s;
	int n,q,f,sf=0;
	cin>>c>>n;
	s.push_back(c);
	for(int i=0;i<n;i++){
		cin>>q;
		if(q==1){
			sf++;
		}else{
			cin>>f>>c;
			if(f==1){
				if(sf%2==0){
					s.push_front(c);
				}else{
					s.push_back(c);
				}
			}else{
				if(sf%2==0){
					s.push_back(c);
				}else{
					s.push_front(c);
				}
			}
		}
	}
	for(int i=0;i<s.size();i++){
		ans+=s.at(i);
	}
	if(sf%2!=0){
		reverse(ans.begin(),ans.end());
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 12080
import sys
from collections import deque
from operator import itemgetter
import math

input = sys.stdin.readline

N, A, B, C, D = map(int, input().split())
S = input()
S = '.' + S
if '##' in S[A:C] or '##' in S[A:D]:
    print('No')
    exit()
if D > C:
    print('Yes')
    exit()
if '...' in S[B-1:D+2]:
    print('Yes')
    exit()
else:
    print('No')

Measured memory_bytes: 3892
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        long h = sc.nextLong();
        long w = sc.nextLong();
        long ans = h * w / 2;
        if (h * w % 2 == 1) {
            ans++;
        }
        if (h == 1 || w == 1) {
            ans = 1;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        IslandsWar solver = new IslandsWar();
        solver.solve(1, in, out);
        out.close();
    }

    static class IslandsWar {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            List<Pair> list = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                list.add(new Pair(a, b));
            }
            Collections.sort(list);
            int border = 0;
            long result = 0;
            for (Pair p : list) {
                if (border <= p.left) {
                    border = p.right;
                    result++;
                }
            }
            out.println(result);
        }

        public class Pair implements Comparable<Pair> {
            int left;
            int right;

            public Pair(int left, int right) {
                this.left = left;
                this.right = right;
            }

            public int compareTo(Pair o) {
                // 昇順
                return Integer.compare(this.right, o.right);
            }

        }

    }
}



Measured memory_bytes: 62784
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    let p: Vec<i32> = (0..n).map(|_| iter.next().unwrap().parse().unwrap()).collect();
    let mut minvalue : i32 = std::i32::MAX;
    let mut ans = 0;
    for x in p {
        minvalue = std::cmp::min(minvalue, x);
        if x == minvalue {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

void Suhaib_Sawalha (){

    ll a , b , k;
    cin >> a >> b >> k;
    ll n = min (a,k);
    a -= n;
    k -= n;
    n = min (b,k);
    k -= n;
    b -= n;
    cout << a << ' ' << b;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
int main () {
	char s[51],t[51];
	scanf("%s",s);
	scanf("%s",t);
	int slen = strlen(s),tlen = strlen(t),sp = slen;
	for(int i = slen - tlen;i >= 0;i--) {
		int check = 0;
		for(int j = 0;j < tlen;j++) {
			if(s[i + j] != t[j] && s[i+j] != '?') {
				check = 1;
				break;
			}
		}
		if(check == 0) {
			sp = i;
			break;
		}
	}
	if(sp ==slen) printf("UNRESTORABLE\n");
	else {
		for(int m = 0;m < tlen;m++) s[sp + m] = t[m];
		for(int k = 0;k < slen;k++) {
			if(s[k] == '?') s[k] = 'a';
		}
		printf("%s\n",s);
	}
	return 0;
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;

#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let mut s: VecDeque<_> = get_word().chars().collect();
    let q: usize = get();
    let mut rev = false;
    for _ in 0..q {
        let ty: i32 = get();
        if ty == 1 {
            rev = !rev;
        } else {
            let f: i32 = get();
            let c: char = get_word().chars().next().unwrap();
            if (f == 1) ^ rev {
                s.push_front(c);
            } else {
                s.push_back(c);
            }
        }
    }
    let mut s = s.into_iter().collect::<Vec<_>>();
    if rev {
        s.reverse();
    }
    println!("{}", s.into_iter().collect::<String>());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main(){
    int a[5000], n, i, j;
    while (cin >> n && 1 <= n && n <= 5000){
        int maximum = -100000;
        for(i = 0; i < n; i++){
            cin >> a[i];
         }
        for(i = 0; i < n; i++){
            int sum = 0;
            for (j = i; j < n; j++){
                sum += a[j];
                maximum = max(maximum, sum);
            }
        }
        cout << maximum << endl;
    }
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int n,k; ll arr[101010],fac[101010],ans;
const ll MOD=1000000007;
ll factorial(int p)
{
	if(p==0) return fac[0]=1;
	return fac[p]=(factorial(p-1)*p)%MOD;
} ll pow(ll p,int q)
{
	if(q==0) return 1;
	if(q==1) return p;
	ll ret=pow(p,q/2);
	if(q%2) return (((ret*ret)%MOD)*p)%MOD;
	return (ret*ret)%MOD;
}
ll combi(int p,int q)
{
	if(p<q) return 0;
	ll imsi=(fac[q]*fac[p-q])%MOD;
	imsi=pow(imsi,1000000005); 
	return (fac[p]*imsi)%MOD;
}
main()
{
	cin>>n>>k; factorial(n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",arr+i);
	} sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
	{
		ans+=arr[i]*(combi(i-1,k-1)-combi(n-i,k-1)); 
		ans=(ans+MOD*10)%MOD;
	} printf("%d",ans);
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

double distance(double x1, double y1, double x2, double y2)
{
	double dx = x1-x2;
	double dy = y1-y2;
	return sqrt(dx*dx+dy*dy);
}

double distance_between_point_line(double x, double y, double a, double b, double c)
{
	return abs(a*x + b*y + c) / sqrt(a*a+b*b);
}

int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		double x[100];
		double y[100];
		for (int i = 0; i < n; ++i)
			scanf("%lf,%lf", x+i, y+i);

		int ans = 1;
		for (int i = 0; i < n-1; ++i)
		{
			for (int j = i+1; j < n; ++j)
			{
				double a, b, c;
				a = x[i] - x[j];
				b = y[i] - y[j];
				c = -(x[i]*x[i]-x[j]*x[j] + y[i]*y[i]-y[j]*y[j]) / 2;
				double r = 1;

				vector<pair<double, double> > cross;
				double d = distance_between_point_line(x[i], y[i], a, b, c);
				if (d > r)
					continue;

				double for_unit = sqrt(a*a+b*b);
				double cx, cy;
				cx = (x[i]+x[j])/2;
				cy = (y[i]+y[j])/2;

				double h = sqrt(r*r - d*d);
				int sign[] = { 1, -1 };
				for (int k = 0; k < 2; ++k)
				{
					double xx = cx + sign[k] * h*b/for_unit;
					double yy = cy + sign[k] * h*-a/for_unit;
					cross.push_back(make_pair(xx, yy));
				}

				if (cross.size() != 0 && ans < 2)
					ans = 2;
				vector<int> counter;
				for (int k = 0; k < cross.size(); ++k)
					counter.push_back(2);

				for (int k = 0; k < n; ++k)
				{
					if (k == i || k == j)
						continue;

					for (int l = 0; l < cross.size(); ++l)
					{
						if (distance(cross[l].first, cross[l].second, x[k], y[k]) - 1.0 < 1e-6)
							++counter[l];
					}
				}
				for (int k = 0; k < counter.size(); ++k)
					ans = max(ans, counter[k]);
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = list(map(int, input().split()))
a.sort(key = lambda x: x[1], reverse = True)

#print(a)
now = a[0][1]
for time, lmt in a:
    now = min(now, lmt)
    now -= time
if now < 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 53848
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

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

bool my_strncmp(string S, int index, string T, int n){
    int i = 0;
    bool same = true;
    while(i < n){
        if(S[i+index] != T[i] && S[i+index] != '?')
            same = false;
        i++;
    }
    return same;
}

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

    int SL = S.length();
    int TL = T.length();
    int index = SL - TL;
    while(index >= 0){
        if(my_strncmp(S, index, T, TL)) {
            REP(i,TL) S[index+i] = T[i];
            goto next;
        }
        index--;
    }
    cout << "UNRESTORABLE" << endl;
    return 0;

next:
    REP(i, SL){
        if(S[i] == '?')
            S[i] = 'a';
    }

    cout << S << endl;
    return 0;

}


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

#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;

int32_t main()
{
    fast;
    int k ,t ; cin >> k >> t ;
    int mx = -1;
    for(int i = 0 ; i< t ; ++i){
        int a ; cin >> a;
        mx = max(mx,a);
    }
    cout << max(0LL,2*mx-k-1) << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int M = nextInt();
  vector<int> X(M);
  REP(i, M) X[i] = nextInt();
  sort(ALL(X));
  vector<int> d;
  REP(i, M-1) d.push_back(X[i+1] - X[i]);
  sort(ALL(d));
  ll ans = 0;
  for (int i = 0; i < (M - N); i++)
    ans += d[i];
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

ll lcm(set<ll> S,set<ll> U){
    ll temp,ans =0;
    set<ll> T,V;
    V=S;
    if(S.size()==1) return *begin(S);
    if(U.size()==0){
        while(S.size()!=1){
            ll n = *begin(S);
            S.erase(n);
            set<ll> T;
            for(auto v2:S){
                ll m = v2%n;
                if(m!=0) T.insert(m);
            }
            S = T;
            S.insert(n);
        }
        return *begin(S);
    }
    for(auto v1:U){
        S = V;
        S.erase(v1);
        while(S.size()!=1){
            ll n = *begin(S);
            S.erase(n);
            set<ll> T;
            for(auto v2:S){
                ll m = v2%n;
                if(m!=0) T.insert(m);
            }
            S = T;
            S.insert(n);
        }
        temp = *begin(S);
        if(temp>ans) ans =temp;
    }
    return ans;
}

int main(){
    int N,m=0;
    cin >>N;
    vl A(N);
    set<ll> S,T,U;
    rep(i,N) {
        cin >>A[i];
        S.insert(A[i]);
        if(S.size()+m !=i+1){
            m++;
            T.insert(A[i]);
        }
    }
    for(auto value:S){
        if(!T.count(value)) U.insert(value);
    }

    cout << lcm(S,U)<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	long long n;
	cin >> n;
	vector<long long> a(5),b(5,0);
	
	long long mi_num=INF;
	int mi_i;
	for(int i=0;i<5;i++){
		cin >> a[i];
		if(mi_num>a[i]){
			mi_num=a[i];
			mi_i=i;
		}
	}
	
	long long ans=0;
	long long m=n;
	for(int i=4;i>=0;i--){
		b[i]=min(m,mi_num);
		m-=b[i];
		if(m<0)m=0;
	}
	ans+=5;
	ans+=(m+(mi_num-1))/mi_num;
	
	int temp=0;
	for(int i=0;i<5;i++){
		if(b[i]==0)temp++;
	}
	temp=4-temp;
	ans+=temp;

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


Measured memory_bytes: 256
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, C, D = map(int, input().split())

    while 1:
        C -= B
        A -= D
        if C <= 0:
            print('Yes')
            break
        if A <= 0:
            print('No')
            break


main()


Measured memory_bytes: 9176