akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
int m,n;
cin>>m>>n;
int a[n+1];
for(int i=1;i<=n;i++){
    int p;
    cin>>p;
    a[i]=p;
}

int ans=0;
int ans2=0;

if(m==2){
    for(int i=1;i<=n;i++){
        if(i%2==0){
            if(a[i]!=2){
                ans++;
            }
            
        }
        else{
            if(a[i]!=1){
                ans++;
            }
        }
        
    }
    
     for(int i=1;i<=n;i++){
        if(i%2==0){
            if(a[i]!=1){
                ans2++;
            }
            
        }
        else{
            if(a[i]!=2){
                ans2++;
            }
        }
        
    }
    
    ans=min(ans, ans2);
    cout<<ans<<endl;
    return 0;
    
}

int now=1;
for(int i=2;i<=n;i++){
if(a[i]!=a[i-1] || i==n){
    if(a[i]==a[i-1]&&i==n){
        now++;
    }
    ans+=now/2;
    now=1;
}
else{now++;}
}

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


Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#ifdef ONLINE_JUDGE
#define filename(_ST_) \
		freopen(_ST_".in", "r", stdin); \
		freopen(_ST_".out", "w", stdout);
#else
#define filename(_ST_)
#endif
template <typename T>
inline void read(T &x) {
	x = 0;
	char ch = 0;
	bool sign = false;
	while (ch < '0' || '9' < ch) sign |= ch == '-', ch = getchar();
	while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	x = sign ? -x : x;
}
template <typename T>
inline void print(T x) {
	static char outp[64];
	if (!x) { putchar('0'); return; }
	if (x < 0) putchar('-'), x = -x;
	int tot = 0;
	while (x) outp[tot++] = x % 10 + '0', x /= 10;
	while (tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rint it = f; it <= e; ++it)
#define per(it, f, e) for (rint it = f; it >= e; --it)
int main() {
	//filename("");
	//ios::sync_with_stdio(false);
	//cin.tie(NULL), cout.tie(NULL);
	int n, k;
	cin >> n >> k;
	if (n & 1) ++n;
	puts(k * 2 > n ? "NO" : "YES");
	return 0;
}
  

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

bool IsPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i == 0){return false;}
	}
	return true;
}

int main(void) {
	int count =0;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int p;
		cin >> p;
		if(IsPrime(p)){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;
int upcmpii(const void *a, const void *b){
        return (*(int*)a == *(int*)b ? 0 : (*(int*)a > *(int*)b ? 1 : -1));
    }
    void sort_ui(int *a, int n){ qsort(a, n, sizeof(int), upcmpii);}

int main(){
    //input
    int n;
    scanf("%d", &n);
    int a[101010];
    rep(i, n) scanf("%d", a+i);

    //solve
    sort_ui(a, n);
    int tmp[101010], cnt[101010] = {0}, idx = 0;
    tmp[0] = a[0];
    cnt[0] = 1;
    rep(i, n-1){
        if(tmp[idx] != a[i+1]){
            idx++;
            tmp[idx] = a[i+1];
        }
        cnt[idx]++;
    }

    //output
    int ng = 0;
    if(idx >= 3) ng = 1;
    else if(idx == 2){
        if(n%3 != 0 || cnt[0] != n/3 || cnt[1] != n/3 || cnt[2] != n/3 || ((tmp[0]^tmp[1]^tmp[2]) != 0))
            ng = 1;
    }else if(idx == 1){
        if(n%3 != 0 || tmp[0] != 0 || cnt[1] != 2*n/3)
            ng = 1;
    }else{
        if(tmp[0] != 0)
            ng = 1;
    }
    if(ng) puts("No");
    else puts("Yes");
}

Measured memory_bytes: 2608
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
int mod=1e9+7;





int32_t main() {
    int T;
    T=1;
    //cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n],b[n],c[n];
        for(int i=0;i<n;i++){
            cin>>a[i]>>b[i]>>c[i];
        }
       int dp[n][3];
       dp[0][0]=a[0], dp[0][1]=b[0], dp[0][2]=c[0];
       for(int i=1;i<n;i++){
           dp[i][0]=a[i]+max(dp[i-1][1], dp[i-1][2]);
           dp[i][1]=b[i]+max(dp[i-1][0], dp[i-1][2]);
           dp[i][2]=c[i]+max(dp[i-1][0], dp[i-1][1]);
       }
       cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
        cout<<'\n';
    }
	return 0;
}

Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define kakkei vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{return f<p.f;};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
ten shaei(ten p,chokusen l){
	v2 a=l.p2-l.p1;
	return l.p1+a*a.naiseki(p-l.p1)/a.abs2();
}
ten hansha(ten p,chokusen l){return shaei(p,l)*2-p;}
ld tenchoku(ten p,chokusen l){
	v2 a=l.p2-l.p1;
	return abs(a.gaiseki(p-l.p1))/a.abs();
}
ld tensen(ten p,senbun s){
	if((p-s.p1).naiseki(s.p2-s.p1)<0)return (p-s.p1).abs();
	if((p-s.p2).naiseki(s.p1-s.p2)<0)return (p-s.p2).abs();
	return tenchoku(p,s);
}
ll ccw(ten p0,ten p1,ten p2){
	v2 a=p1-p0,b=p2-p0;
	if(a.gaiseki(b)>MIN)return -1;//012反時計回り
	if(a.gaiseki(b)<-MIN)return 1;//012時計回り
	if(a.naiseki(b)<-MIN)return -2;//102
	if(a.abs2()<b.abs2())return 2;//012
	return 0;//021
}
bool majiwaru(senbun s,senbun t){return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2)<=0&&ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2)<=0;}
ld sensen(senbun s,senbun t){
	if(majiwaru(s,t))return 0;
	return min({tensen(s.p1,t),tensen(s.p2,t),tensen(t.p1,s),tensen(t.p2,s)});
}
void solve(){
	ll n;cin>>n;
	cout<<sep(10);
	rep(i,0,n){
		senbun s1,s2;
		ld a,b,c,d;
		cin>>a>>b>>c>>d;
		s1={{a,b},{c,d}};
		cin>>a>>b>>c>>d;
		s2={{a,b},{c,d}};
		cout<<sensen(s1,s2)<<kai;
	}
}


Measured memory_bytes: 3288
n = gets.chomp.to_i
l = gets.split.map(&:to_i)

max_l = l.max
index_max_l = l.index(max_l)

sum = 0
n.times do |i|
  if i != index_max_l
    sum += l[i]
  end
end

if max_l < sum
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
import java.io.*;
class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader  br=new BufferedReader(new InputStreamReader(System.in));
    boolean i=true;
    while(i){
      String str=br.readLine();
      String[] data=str.split(" ");
      int m=Integer.parseInt(data[0]);
      int f=Integer.parseInt(data[1]);
      int r=Integer.parseInt(data[2]);
      if(m==-1 && f==-1 && r==-1){
        i=false;
      }else if(m!=-1 && f!=-1){
          int score= m + f;
          if(score >=80)  System.out.println("A");
          else if(score >=65)  System.out.println("B");
          else if(score >=50)  System.out.println("C");
          else if(score >=30){
              if(r >=50)  System.out.println("C");
              else  System.out.println("D");
          }else   System.out.println("F");
      }else     System.out.println("F");
    }
    br.close();
}
}

Measured memory_bytes: 24380
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define ort ((bas+son+1ll)/2ll)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
int t,nf = 0;
string s;
 
int main() {
	
	cin >> s;
	if(s.length() % 2 != 0) t = s.length()/2 + 1;
	else  t = s.length()/2;
	for(int i = 0; i < t; i++)
	{
		if(s[i] != s[s.length() - i - 1])
		{
		    nf++;
		}    
		
	}
	cout << nf;
	
	
	return 0;
}


Measured memory_bytes: 256
#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;

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

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

int main(){
  string s;
  int ans=0;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s[i] == '1')ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int n, p;
    long cnt;
    cin >> n;

    cnt = 0;
    vector<int> a(n+1);
    vector<int> b(n);

    REP(i, n+1){
        cin >> a.at(i);
    }
    REP(i, n){
        cin >> b.at(i);
    }

    int prev_power = 0;

    for(int i = 0; i < n; i++){
        cnt += min(prev_power, a.at(i));
        a.at(i) -= min(prev_power, a.at(i));

        cnt += min(a.at(i), b.at(i));
        prev_power = max(0, b.at(i) - a.at(i));
    }

    cnt += min(prev_power, a.at(n));

    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
int n;
ll tot;
ll a[2*MAX];
int main(){FAST;
cin>>n;
for(int i=1;i<=n;i++){
  cin>>a[i];
  tot+=a[i];
}
ll l = 0;
ll ans = INF;
for(int i=1;i<=n-1;i++){
  l+=a[i];
  ll r = tot-l;
  ans=min(ans,abs(r-l));
}
cout<<ans;
return 0;
}

Measured memory_bytes: 1792
//超都観光

#include "bits/stdc++.h"

using namespace std;

#define int long long

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int dp[100010];

signed main()
{
    while(true)
    {
    int N,K;
    cin >> N >> K;
    
    if(N == 0 && K ==0 ) break;

    int s = 0;

    REP(i, N)
    {
        int a;
        cin >> a;
        s += a;
        dp[i] = s;
    }

    int maxx = 0;

    REP(i, (N - K))
    {
        maxx = max(dp[i + K] - dp[i], maxx);
    }

    cout << maxx << endl;
    }
    return 0;
}






Measured memory_bytes: 3848
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]): Unit = {

    val Array(r, c) = readLine().split(" ").map(_.toInt)
    val matrix = Array.fill(r, c)(0)
    0 until r foreach {
      matrix(_) = readLine().split(" ").map(_.toInt)
    }

    val totalRow = Array.ofDim[Int](c + 1)
    matrix.foreach { row =>
      println(s"${row.mkString(" ")} ${row.sum}")
      row.zipWithIndex.foreach { case(cellValue, cellIndex) =>
        totalRow(cellIndex) += cellValue
      }
      totalRow(c) += row.sum
    }
    println(s"${totalRow.mkString(" ")}")
  }
}


Measured memory_bytes: 49064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int a,b,c;cin>>a>>b>>c;
    rep1(i,b){
        int na=a*i;
        if(na%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i;
    cin >>n;
    vector <int> a={1,2,4,8,16,32,64};
    for(i=6;i>=0;i--){
        if(a[i]<=n){
            cout <<a[i];
            break;
        }
        }
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>d(n,0);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    d[a-1]++;
    d[b-1]++;
  }
  for(int i=0;i<n;i++){
    cout<<d[i]<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;  

const int mo = 1e9 + 7;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

int n;

int main() {
	scanf("%d", &n);
	ll ans = 0;
	fo(i, 1, n) ans = (ans + ksm(ksm(3, i) * (n - i + 1) % mo, mo - 2)) % mo;
	ans = ans * ksm(n, mo - 2) % mo;
	pp("%lld\n", ans);
}


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

S = sum(A)
damu_sum = sum(A[1::2])
ans = S - 2 * (damu_sum)

ans_list = [ans]

for i in range(N-1):
    ans = 2 * A[i] - ans
    ans_list.append(ans)
print(*ans_list)

Measured memory_bytes: 20664
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    if(s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
 
int32_t main()
{
  BOOST;
	int x,y;
	cin>>x>>y;
	int b=(y-2*x)/2;
	int a=x-b;
	if (a>=0 && b>=0 && (y-2*x)%2==0)cout<<"Yes";
	else cout<<"No";
  return 0;
}

Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

ll INF = 100100100100;

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

	ll ans = INF;
	ll maxVal = max(X, Y);
	for (int ii = 0; ii <= maxVal; ++ii){
		ll anum = max(X-ii, 0LL);
		ll bnum = max(Y-ii, 0LL);
		ll abnum = ii * 2;
		ll val = anum*A + bnum*B + abnum*C;
		ans = min(ans, val);
	}

	cout << ans << "\n";

	return 0;
}


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

const int maxn=2e5;
int n,m,t,h[maxn],f[maxn];
bool mark[maxn],ans[maxn];
vector<int>G[maxn];

void dfs(int v)
{
  mark[v]=true;
  f[v]=h[v];
  for(int i=0;i<G[v].size();i++)
    {
      int u=G[v][i];
      if(!mark[u])
	{
	  h[u]=h[v]+1;
	  dfs(u);
	  if(v==0) t++;
	  if(v!=0 && f[u]>=h[v])
	    ans[v]=true;
	  f[v]=min(f[v],f[u]);
	}
      else if(h[u]<h[v]-1)
	f[v]=min(f[v],h[u]);
    }
}

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      int v,u;
      cin>>v>>u;
      G[v].push_back(u);
      G[u].push_back(v);
    }
  dfs(0);
  if(t>1) ans[0]=true;
  for(int i=0;i<n;i++)
    if(ans[i]) cout<<i<<endl;
}



Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
int a[101][101],h,w,b[101][101]={0};
int main()
{
	int i,j,k,l;
	char c;
	cin>>h>>w;
	for(i=0;i<h;i++)
	for(j=0;j<w;j++)
	{
		cin>>c;
		if(c=='.')
		a[i][j]=0;
		else
		a[i][j]=1;
	}
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			if(j!=0&&i!=0)
			{
			    k=(a[i-1][j]<a[i][j])?1:0;
			    l=(a[i][j-1]<a[i][j])?1:0;
			    b[i][j]+=min(k+b[i-1][j],l+b[i][j-1]);
			    
			}
			else if(j==0&&i!=0)
			{
				b[i][j]=((a[i][j]>a[i-1][j])?1:0)+b[i-1][j];
			}
			else if(i==0&&j!=0)
			{
				b[i][j]=((a[i][j]>a[i][j-1])?1:0)+b[i][j-1];
			}
			else if(i==0&&j==0)
			{
			    b[i][j]=a[i][j];
			}
			//cout<<b[i][j]<<" ";
		}
	//cout<<endl;
	}
	cout<<b[h-1][w-1];
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
//setprecision(12)
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, x, y; cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n,0);
    rep(i,n-1) {
        REP(j,i+1,n) {
            int dist = min(j-i,abs(j-y)+abs(i-x)+1);
            ans[dist]++;
        }
    }
    REP(i,1,n) cout << ans[i] << endl;

    return 0;
}

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

namespace ABC122C
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = int.Parse(Console.ReadLine().Split(' ')[1]);

            var input = Console.ReadLine();

            var pos = new int[100000];

            var flag = false;
            var index = 0;
            var cnt = 0;
            foreach (var c in input)
            {
                if (flag && c == 'C')
                {
                    pos[index++] = ++cnt;
                    flag = false;
                    continue;
                }

                if (c == 'A')
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }

                pos[index++] = cnt;
            }

            for (var i = 0; i < q; i++)
            {
                var lr = Console.ReadLine().Split(' ').Select(int.Parse).Select(x => x - 1).ToArray();

                var num = pos[lr[1]] - pos[lr[0]];

                Console.WriteLine(num);
            }

        }
    }
}


Measured memory_bytes: 18040
#include<stdio.h>
#include<stdlib.h>
#define MAX 200000
#define INF 2000000000

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

int main(){
	int n,m;
	int a[MAX+1];
	int b[MAX+1];
	int j=0,k=0;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	a[n]=INF;
	
	qsort(a,n,sizeof(int),compare_int);
	
	scanf("%d",&m);
	for(int i=0;i<m;i++)
		scanf("%d",&b[i]);
	b[m]=INF;
	
	qsort(b,m,sizeof(int),compare_int);
	
	for(int i=0;i<n+m;i++){
	
		if(a[j]==INF || b[k]==INF)break;
		
		if(a[j] == b[k]){
			printf("%d\n",a[j]);
			int temp=a[j];
			while(a[j]==temp)j++;
			while(b[k]==temp)k++;
		}
		
		else if(a[j] < b[k])
			j++;
			
		else if(a[j] > b[k])
			k++;
		
		
	}
	
	return 0;
	
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

//vector<LLi>を出力
void PV(vector<int> pvv) {
	rep(i, (int)pvv.size()-1) cout << pvv[i] SP;
	cout<< pvv[(int)pvv.size()-1] <<endl;
}

int main(){

	int n, l=0, lm=0, sm=0;
	vector<int> a;
	cin>> n;
  
  	a.resize(n);
  	rep(i, n){
      	cin>> a[i];
      //if(a[i]!=99997) cout<< a[i] <<endl;
      	l=max(l, a[i]);
    }
  
  //cout<< "l=" << l <<endl;
  
  	rep(i, n){
      	if(a[i]==l) lm++;
      	if(a[i]==l-1) sm++;
    }
  
  //cout<< "lm=" << lm << " sm=" << sm <<endl;
  
  	if(n!=lm+sm){
      	cout<< "No" <<endl;
      	return 0;
    }
  
  	if(sm==0){
      	if(l==1){
      		cout<< "Yes" <<endl;
      		return 0;
    	}
  		if(l==n-1){
      		cout<< "Yes" <<endl;
      		return 0;
    	}
  		if(l*2<=n) cout<< "Yes" <<endl;
      	else cout<< "No" <<endl;
      	return 0;
    }
  
  	if(l==2 && 1<sm){
      	cout<< "No" <<endl;
      	return 0;
    }
  
  	//if(sm<=l-1 && lm<=2*n-l) cout<< "Yes" <<endl;
  	if(sm<=l-1 && l<=sm+lm/2) cout<< "Yes" <<endl;
    else cout<< "No" <<endl;
  
     return 0;
}

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

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

    vector<int> l(n);
    rep(i, n) cin >> l.at(i);

    int d=0;
    for(int i=1;i<n+1;i++){
        d += l.at(i-1);
        if(d>x){
            cout << i << endl;
            return 0;
        }
    }
    cout << n+1 << endl;
    return 0;
}

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


int main() {
  int x;
  cin >> x;
  if (x == 1) cout << "Hello World" << endl;
  else {
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
  return 0;
}


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


int main() {
    int n;
    cin >> n;
    vector<int> a(n+2, 0);
    rep(i,n) cin >> a[i+1];
    int sum = 0;
    rep(i,n+1){
        sum += abs(a[i] - a[i+1]);
    }

    rep(i,n){
        cout << sum
                + abs(a[i] - a[i+2])
                - abs(a[i] - a[i+1])
                - abs(a[i+1] - a[i+2]) << endl;
    }
}


Measured memory_bytes: 1664
from collections import deque
N,M = map(int,input().split())
to = [[] for _ in range(N*3)]
for i in range(M):
  a,b = map(int,input().split())
  a-=1;b-=1
  to[a*3].append(b*3+1)
  to[a*3+1].append(b*3+2)
  to[a*3+2].append(b*3)
start,end = map(int,input().split())
start -= 1;end -= 1
#print(to)
INF = float("inf")
Q = deque([start*3])
visit = [INF for _ in range(N*3)]
visit[start*3] = 0
while Q:
  v = Q.popleft()
  for w in to[v]:
    if visit[w] != INF:
      continue
    visit[w] = visit[v]+1
    if w == end*3:
      print(visit[w]//3)
      exit()
    Q.append(w) #step歩目でwにいて次vへ行く。

#print(visit)
if visit[end*3] == INF:
  ans = -1
else:
  ans = visit[end*3]//3
print(ans)

Measured memory_bytes: 128148
#include<stdio.h>
int main()
{
	char *cls[11]=
	{{"light fly"},
	{"fly"},
	{"bantam"},
	{"feather"},
	{"light"},
	{"light welter"},
	{"welter"},
	{"light middle"},
	{"middle"},
	{"light heavy"},
	{"heavy"}};
	int dif[10]={30,30,30,30,40,50,60,60,100,1},t,x,i;
	float w = 0.0;
	while(scanf("%f",&w)!=EOF)
	{
/*
		t=480,x=(int)((w+0.001)*10);
		for(i=0;i<10&&x>t;i++)
		{
			t+=dif[i];
		}
		printf("%s\n",cls[i]);
*/
        if (!(w > 48.0)) puts("light fly"); else
        if (!(w > 51.0)) puts("fly"); else
        if (!(w > 54.0)) puts("bantam"); else
        if (!(w > 57.0)) puts("feather"); else
        if (!(w > 60.0)) puts("light"); else
        if (!(w > 64.0)) puts("light welter"); else
        if (!(w > 69.0)) puts("welter"); else
        if (!(w > 75.0)) puts("light middle"); else
        if (!(w > 81.0)) puts("middle"); else
        if (!(w > 91.0)) puts("light heavy"); else
        puts("heavy");
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};
std::streamsize precision = 20;


int main(void){
    ll N,K;
    cin >> N >> K;
    double ans = 0.0;
    
    for(int i = 1; i <= N; i++){
        ll cnt = 0;
        ll I = i;
        while(I < K){
            I *= 2;
            cnt++;
        }
        ans += pow(0.5, cnt) / N;
    }
    
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;

int a[300100];

int main(){
	cin>>n;
	REP(i,3*n)
		cin>>a[i];
	
	sort(a,a+3*n,greater<int>());
	ll ans=0;
	for(int i=1;i<2*n;i+=2)
		ans+=(ll)a[i];
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#define L 6
char c[L];
inline void pl(int a){
    register long i=L-2;
    do{ c[i]=a%10+48; a/=10; i--; }while(a>0);
    stdout->_IO_write_ptr += L-1-i;
    char* p = stdout->_IO_write_ptr;
    do{ ++i; p[i-L] = c[i]; }while(i<L-1);
}

static void solve(const int n, const int a, const int b, int mask, const int common){
    const int t = a^b;
    const int d = t&(-t);
    mask ^= d;
    const int aa = a & mask, ab = aa ^ (mask&(-mask));
    if(n==2){
        if(__builtin_expect(stdout->_IO_write_ptr+4*L >= stdout->_IO_write_end,0)){
            fflush_unlocked(stdout);
        }
        pl(common|a);
        pl(common|ab|(a&d));
        pl(common|ab|(b&d));
        pl(common|b);
    }else{
        solve(n-1, aa, ab, mask, common|(a&d));
        solve(n-1, ab, b&mask, mask, common|(b&d));
    }
}

int main(void){
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    if(__builtin_expect(__builtin_parity(a)==__builtin_parity(b),0)){
        puts("NO");
    }else{
        puts("YES");
        if(__builtin_expect(n==1,0)){
            printf("%d %d\n", a, b);
        }else{
            c[L-1]=' ';
            solve(n, a, b, -1, 0);
        }
    }
    return 0;
}

Measured memory_bytes: 896
n,m,l = gets.split.map {|s| s.to_i}
a = Array.new
b = Array.new
for i in 1..n
  c = gets.split.map {|s| s.to_i}
  a.push(c)
end
for j in 1..m
  c = gets.split.map {|s| s.to_i}
  b.push(c)
end
for i in 1..n
  for j in 1..l
    print " " unless j == 1
    s = 0
    for k in 1..m
      s += a[i-1][k-1] * b[k-1][j-1]
    end
    print s
  end
  print "\n"
end


Measured memory_bytes: 8880
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    int cur=s.size()-1;
    while(cur>=0){
        if(cur-4>=0&&(s.substr(cur-4,5)=="dream"||s.substr(cur-4,5)=="erase")){
            cur-=5;
        }
        else if(cur-5>=0&&s.substr(cur-5,6)=="eraser") cur-=6;
        else if(cur-6>=0&&s.substr(cur-6,7)=="dreamer") cur-=7;
        else{
            cout<<"NO"<<endl;return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

// 辺を表す構造体 {行先、容量、逆辺}
struct edge { int to; ll cap; int rev; };
#define V 1010
int s, t; //sがstart, tがgoal
vector< vector<edge> > G(V, vector<edge>());; //グラフの隣接リスト表現
vector<bool> used(V); //DEFで調べたかのフラグ

					  //fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, ll cap) {
	edge a;
	a.to = to; a.cap = cap; a.rev = G[to].size();
	G[from].push_back(a);
	a.to = from; a.cap = 0; a.rev = G[from].size() - 1;
	G[to].push_back(a);
}

ll dfs(int v, int t, ll f) {
	if (v == t) {
		return f;
	}
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			ll d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(int s, int t) {
	ll flow = 0;
	while (true) {
		fill(used.begin(), used.end(), false);
		ll f = dfs(s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}

int main() {
	int n, i, j;
	cin >> n;
	vl a(n);
	ll sum = 0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		sum += max(a[i], 0LL);
	}
	for (i = 1; i <= n; i++) {
		for (j = 2; i*j <= n; j++) {
			add_edge(i, i*j, INF);
		}
	}
	for (i = 0; i < n; i++) {
		if (a[i] < 0) {
			add_edge(0, i + 1, -a[i]);
		}
		else {
			add_edge(i + 1, n + 1, a[i]);
		}
	}
	cout << sum - max_flow(0, n + 1) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
//const int WASTE=∞;
//#define int long long
int power(int a,int b,int m){
	int i=1;
	while(b){
		if(b%2)
			i=(i*a)%mod;
		b/=2;
		a=(a*a)%mod;
	}
	return i;	
}
const int N=1e5+5;
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<ceil((double)a/b);

	return 0;
}

Measured memory_bytes: 256
class DisjointSet(object):
    rank = []
    p = []

    def __init__(self, size):
        for i in range(size):
            self.makeSet(i)

    def makeSet(self, x):
        DisjointSet.p.insert(x, x)
        DisjointSet.rank.insert(x, 0)


    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)


    def unite(self, s, y):
        self.link(self.findSet(x), self.findSet(y))


    def link(self, x, y):
        if DisjointSet.rank[x] > DisjointSet.rank[y]:
            DisjointSet.p[y] = x
        else:
            DisjointSet.p[x] = y
            if DisjointSet.rank[x] == DisjointSet.rank[y]:
                DisjointSet.rank[y] += 1


    def findSet(self, x):
        if x != DisjointSet.p[x]:
            DisjointSet.p[x] = self.findSet(DisjointSet.p[x])
        return DisjointSet.p[x]



if __name__ == '__main__':
    # ??????????????\???
    n, q  = input().split(' ')
    data = []
    for i in range(int(q)):
        data.append(list(map(int, input().split(' '))))

    ds = DisjointSet(int(n))
    for d in data:
        command, x, y = d
        if command == 0:
            ds.unite(x, y)
        elif command == 1:
            result = ds.same(x, y)
            if result:
                print('1')
            else:
                print('0')

Measured memory_bytes: 32988
#define loop(i,j,k) for(long long i = j;i < k;i++)

#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <list>
#include <stack>
#include <set>
using namespace std;

typedef long long int int64;

int main(int argc,char** argv) {
    int n,m,xmax,ymin;
    cin >> n >> m >> xmax >> ymin;
    loop(i,0,n) {
        int t;
        cin >> t;
        xmax = max(xmax,t);
    }
    loop(i,0,m) {
        int t;
        cin >> t;
        ymin = min(ymin,t);
    }
    if(xmax < ymin) cout << "No War";
    else cout << "War";
    return 0;
}


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

int main(void)
{
    int n;
    long long int k;
    cin >> n >> k;

    Graph G(n);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        --a;
        G[i].push_back(a);
    }

    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    vector<int> llp;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする
    llp.push_back(0);

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {

            llp.push_back(nv);
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
/*
    for(int i = 0; i < llp.size(); ++i)
    {
        cout << llp.at(i) << endl;
    }
    cout << " size " << llp.size() << endl;
*/

    int last = llp.at(llp.size()-1);
    vector<int>::iterator iter = find(llp.begin(), llp.end(), last);
    int index = std::distance(llp.begin(), iter);

//    cout << llp.size() << last << index << endl;

    if(k >= index)
    {
        k -= index;
        long long int ttttmp = llp.size() - index -1;
        k = k % ttttmp;
    //    cout << k << endl;    
        cout << llp.at(index + k) + 1 << endl;
    }
    else
    {
        cout << llp.at(k) + 1 << endl;
    }
    


    return 0;
}



Measured memory_bytes: 16048
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
string a;
int s=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a;
	int n=a.size();
	for (int i=0;(i<<1|1)<n;i++)
		if (a[i]!=a[n-1-i])
			s++;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

INPUT_LINE = gets.chomp!.split(' ').map!(&:to_i)
# puts INPUT_LINE
min_number = INPUT_LINE[0]
max_number = INPUT_LINE[1]
div_number = INPUT_LINE[2]
# puts div_number
count = 0
(min_number..max_number).each do |num|
  count += 1 if num % div_number == 0
  #   puts num % div_number
end
puts count


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

typedef long long int64;
const int MAX = 2e5 + 5;
const int MOD = 1e9 + 7;
int n, k;
int64 f[MAX], inv[MAX];

int64 exp(int64 a, int64 n) {
	int64 ans = 1;
	while(n > 0) {
		if(n % 2LL == 1LL)
			ans = ans * a % MOD;
			
		a = a * a % MOD;
		n /= 2LL;
	}
	
	return ans;
}

int64 comb(int n, int k) {
	int64 ans = f[n] * inv[k] % MOD;
	ans = ans * inv[n - k] % MOD;
	return ans;
}

int main() {
	scanf("%d%d", &n, &k);

	f[0] = inv[0] = 1;
	for(int i = 1; i <= n; i++) {
		f[i] = f[i - 1] * i % MOD;
		inv[i] = exp(f[i], MOD - 2);
	}

	int64 ans = 0;
	for(int x = 0; x <= min(k, n - 1); x++) {
		int64 v = comb(n, x) * comb(n - 1, n - x - 1) % MOD;
		ans = (ans + v) % MOD;
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
from collections import deque

n, m = map(int, input().split())
links = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

ans = [-1] * n
q = deque([(0, -2)])
while q:
    v, p = q.popleft()
    if ans[v] != -1:
        continue
    ans[v] = p
    for u in links[v]:
        if ans[u] != -1:
            continue
        q.append((u, v))

print('Yes')
print('\n'.join(str(v + 1) for v in ans[1:]))


Measured memory_bytes: 71012
n, k = map(int, input().split())
dice = [int(p) for p in input().split()]
S = [ 0 for i in range(n+1)]

for i in range(1, n+1):
  S[i] = S[i-1] + (dice[i-1]+1)/2.0
  #期待値計算

ans = 0
for i in range(n-k+1):
  tmp = S[i+k] - S[i]
  ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 25188
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

int main() {
  int n; cin >> n;
  ll x[55], y[55];

  map<pll, ll> mp;

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

  for (int i = 0; i < n; i++) {
    for (int j = 0 ; j < n; j++) {
      if (i == j) { continue; }
      ll tx = x[j] - x[i];
      ll ty = y[j] - y[i];
      mp[make_pair(tx, ty)]++;
    }
  }
  int ans = 0;

  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans = max(ans, int(it->second) );
  }

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

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// 1 + 2 + 3 + 4 + 5;

int main() {
    ll x;
    cin >> x;
    ll p = x % 100;
    ll cnt = x / 100;

    if (p <= cnt * 5) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,x[100005],y[100005],mod=1e9+7;
ll calc(ll a[],ll n){
    ll ans =0 ;
    for(ll i=0;i<n-1;i++)a[i]=a[i+1]-a[i];
    n-=1;
    for(ll i=0;i<n;i++){
        ans = ans  + (i+1)*(n-i)%mod*a[i]%mod;
        ans%=mod;
    }
    return ans;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(ll i=0;i<n;i++)cin>>x[i];
    for(ll i=0;i<m;i++)cin>>y[i];
    cout<< (calc(x,n) * calc(y,m) )%mod;
}

Measured memory_bytes: 1792
#include <stdio.h>

int MATRIX[101][101] = {0};

int main() {
	int r,c, i, j;
	int tmp = 0;
	
	scanf(" %d %d", &r, &c);
	for (i = 0; i < r; ++i) {
		for (j = 0; j < c; ++j) {
			scanf(" %d", &MATRIX[i][j]);
			MATRIX[i][c] += MATRIX[i][j];
			MATRIX[r][j] += MATRIX[i][j];
			tmp += MATRIX[i][j];
		}
	}
	MATRIX[r][c] = tmp;
	
	for (i = 0; i < r + 1; ++i) {
		for (j = 0; j < c + 1; ++j) {
			printf("%d%c", MATRIX[i][j], j==c?'\n':' ');
		}
//		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
D eps=1e-9;
inline D dot(P a,P b){
	return real(conj(a)*b);
}
inline D cro(P a,P b){
	return imag(conj(a)*b);
}
int ccw(P a,P b,P c){
	if(cro(b-a,c-a)>eps) return 1;
	if(abs(abs(a-c)+abs(c-b)-abs(a-b))<eps) return 0;
	return -1;
}
inline P perp(L l,P p){
	D t=dot(p-l.fs,l.fs-l.sc)/norm(l.fs-l.sc);
	return l.fs+t*(l.fs-l.sc);
}
inline bool iSP(L s,P p){
	P a=s.fs,b=s.sc,c=p;
	return abs(abs(a-c)+abs(c-b)-abs(a-b))<eps;
}
inline D dSP(L s,P p){
	P q=perp(s,p);
	return iSP(s,q) ? abs(p-q) : min(abs(p-s.fs),abs(p-s.sc));
}
inline P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+t*(b.sc-b.fs);
}
int N;
Pol pol;
P p[100];
bool contain(Pol pol,P p){
	bool in=false;
	rep(i,N){
		P a=pol[i]-p,b=pol[(i+1)%N]-p;
		if(ccw(a,b,P(0,0))==0) return false;
		if(imag(a)>imag(b)) swap(a,b);
		if(imag(a)<=eps && eps<imag(b) && ccw(P(0,0),a,b)==1) in=!in;
	}
	return in;
}
bool check(D m){
	rep(i,N) rep(k,i){
//		show(i);
		P a=p[i],b=p[(i+1)%N],c=p[k],d=p[(k+1)%N];
		P x=(b-a)*P(0,1),y=(d-c)*P(0,1);
		x=x/abs(x)*m,y=y/abs(y)*m;
		L l1=L(a+x,b+x),l2=L(c+y,d+y);
		P q=intLL(l1,l2);
		if(!contain(pol,q)) continue;
		int cnt=0;
		rep(j,N){
//			show(j);
			L l=L(p[j],p[(j+1)%N]);
//			show(dSP(l,q));
//			show(m);
			if(dSP(l,q)+eps<m) cnt++;
		}
//		show(cnt);
		if(cnt==0) return false;
	}
	return true;
}

int main(){
	while(true){
		cin>>N;
		if(N==0) break;
		pol.clear();
		rep(i,N){
			int xx,yy;
			cin>>xx>>yy;
			p[i]=P(xx,yy);
			pol.pb(p[i]);
		}
		D ub=10000,lb=0;
		rep(tt,40){
			D m=(ub+lb)/2;
			if(check(m)) ub=m;
			else lb=m;
		}
//		check(2.0);
/*		if(abs(ub-1.1965)<1e-2){
			cout<<N<<endl;
			rep(i,N){
				cout<<p[i].real()<<" "<<p[i].imag()<<endl;
			}
		}*/
		printf("%.12f\n",ub);
	}
}

Measured memory_bytes: 1236
from collections import defaultdict

N = int(input())
V = list(map(int, input().split()))

d1 = defaultdict(int)
d2 = defaultdict(int)
for i, v in enumerate(V):
    if i % 2 == 0:
        d1[v] += 1
    else:
        d2[v] += 1
d1 = sorted(d1.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
d2 = sorted(d2.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

best = 10 ** 10
for d1, d2 in ((d1, d2), (d2, d1)):
    ans = N // 2 - d1[0][1]
    val = d1[0][0]
    if d2[0][0] != val:
        ans += N // 2 - d2[0][1]
    else:
        ans += d2[0][1]
        if 2 < len(d2):
            ans += N // 2 - d2[0][1] - d2[1][1]
    best = min(best, ans)
print(best)

Measured memory_bytes: 21304
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
// #define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
    if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int MAXN = 1e5+7;

// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/
ld euclid(ld x,ld y,ld i,ld j)
{
  return sqrt(abs(x*x-i*i)+abs(y*y-j*j));
}
void solve()
{
 ll n;
 cin>>n;
 std::vector<ll> v(n);
 ll ans = hell;
 ll i,j;
 for(i=0;i<n;i++)
  cin>>v[i];
 for(i=1;i<=100;i++)
 {
  ll curr=0;
  for(j=0;j<n;j++)
    curr+=((v[j]-i)*(v[j]-i));
  // trace(curr);
  ans = min(ans,curr);
 }
 cout<<ans;
}
int main()
{ 
  // ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

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


int main() {
    int N;
    cin>>N;
    vector<pair<pair<string,int>,int>>p(N);
    rep(i,N){
        string s;
        int a;
        cin >>s>>a;
        p[i]=make_pair(make_pair(s,-a),i+1);
    }
    sort(p.begin(),p.end());
    for(auto b:p){
        cout<<b.second<<endl;
    }
}

Measured memory_bytes: 256