akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    // Your code here!
    int i;
    char str[21];
    scanf("%s",str);
    i=0;
    while (str[i] != '\0'){
        i++;
    }
    while(i != 0){
        printf("%c",str[i-1]);
        i--;
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2108
/*
Author: CNYALI_LK
LANG: C++
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define up(a,b,c) for (long long a(b),end##a(c);a<=end##a;++a)
#define down(a,c,b) for (long long a(b),end##a(c);a>=end##a;--a)
#define uup(a,c,b) for (long long a(b),end##a(c);a<=end##a;++a)
#define udown(a,b,c) for (long long a(b),end##a(c);a>=end##a;--a)
#define endl '\n'
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
struct inout{
	static const long long ibufl=1<<25;
	static const long long obufl=1<<25;
	char in_buf[ibufl],out_buf[obufl],*inf,*ouf;
	void init(){
		fread(in_buf,1,ibufl,stdin);
		inf=in_buf;
		ouf=out_buf;
	}
	inout& operator >>(long long &a){
		long long fh=1;
		while(!(isdigit(*inf)||*inf=='-'))++inf;
		if(*inf=='-')fh=-1,++inf;
		a=0;
		while(isdigit(*inf)){a=a*10+*inf-'0';++inf;}
		a*=fh;
		return *this;
	}
	inout& operator >>(char &a){
		while(*inf==' '||*inf=='\n')++inf;
		a=*inf;
		++inf;
		return *this;
	}
	inout& operator >>(char *a){
		while(*inf==' '||*inf=='\n')++inf;
		while(!(*inf==' '||*inf=='\n')){*a=*inf;++inf;++a;}
		*a='\0';
		return *this;
	}

	inout& operator >>(double &a){
		long long fh=1;
		double s;
		while(!(isdigit(*inf)||*inf=='-'||*inf=='.'))++inf;
		if(*inf=='-')fh=-1,++inf;
		a=0;
		while(isdigit(*inf)){a=a*10+*inf-'0';++inf;}
		if(*inf=='.'){
			s=0.1;
			++inf;
			while(isdigit(*inf)){
				a+=s*(*inf-'0');
				++inf;
				s*=0.1;
			}
		}
		if(*inf=='E'||*inf=='e'){
			long long ss;
			++inf;
			*this>>ss;
			if(ss>0){
				while(ss){
					--ss;
					a*=10;
				}
			}
			if(ss<0){
				while(ss){
					++ss;
					a/=10;
				}
			}
			
		}
		a*=fh;
		return *this;
	}
	void writeint(long long x){
		if(x/10)writeint(x/10);
		*ouf=x%10+'0';
		++ouf;
	}
	inout& operator <<(long long a){
		
		if(a<0){*ouf='-';++ouf;a=-a;}
		writeint(a);
		return *this;
	}
	static const long long sz=7;
	inout& operator <<(char a){
		*ouf=a;++ouf;
		return *this;
	}
	inout& operator <<(char *a){
		while(*a){
			*ouf=*a;
			++ouf;
			++a;
		}
		return *this;
	}
	inout& operator <<(double a){
		if(a<-eps){*ouf='-';++ouf;a=-a;}
		writeint((long long)a);
		a-=(long long)a;
		*ouf='.';
		++ouf;
		up(i,1,sz){
			a=a*10;
			*ouf=(long long)a+'0';
			++ouf;
			a-=(long long)a;
		}
		return *this;
	}
	void out(){
		fwrite(out_buf,1,ouf-out_buf,stdout);	
	}
};
inout io;
long long beg[233333],to[456789],lst[456789],w[456789],e;
void add(long long u,long long v,long long ww){
	to[++e]=v;
	lst[e]=beg[u];
	w[e]=ww;
	beg[u]=e;
}
long long dis[233333];
void dfs(long long x,long long fa){
	for(long long i=beg[x];i;i=lst[i]){
		if(to[i]==fa)continue;
		dis[to[i]]=dis[x]+w[i];
		dfs(to[i],x);
	}
}
int main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	io.init();
	long long n,u,v,w;
	io>>n;
	up(i,1,n-1){
		io>>u>>v>>w;
		add(u,v,w);
		add(v,u,w);
	}
	long long q,k;
	io>>q>>k;
	dfs(k,0);
	while(q){
		--q;
		io>>u>>v;
		io<<dis[u]+dis[v]<<endl;
	}
	io.out();
	return 0;
}


Measured memory_bytes: 24320
#include <iostream> 
using namespace std;
#define ll long long
ll divisors[10000010];
void precal() {
  
  divisors[0] = 0;
  for (ll i=1; i<=10000000; i++) {
    for (ll j=i; j<=10000000; j+=i) {
      divisors[j] ++;
    }
  }
  for (ll i=1; i<=10000000; i++) {
    divisors[i] *= i;
    divisors[i] += divisors[i-1];
  }
}

int main() {
  precal();
  ll n; cin >> n;
  cout << divisors[n] << endl;
}

Measured memory_bytes: 81280
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const double pi = 3.14159265358979;

long long x;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> x;
	long long cur = 100, cnt = 0;
	while(cur < x)
		cur += floor((double)cur * 0.01), cnt++;
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"
#define cv(c) (int)(c-'a')
#define db(x) cerr << #x << ": " << x << " "
#define db2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << " "
#define bn() cerr << endl
#define sep() cerr << "-------" << endl

using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;

    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'C' && cnt == 0){
            cnt++;
        }else if (s[i] == 'F' && cnt == 1){
            cnt++;
        }
    }
    if (cnt == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

int main(){
  	int a,b,c,d;
  	cin>>a>>b;
  	c = max(a,b)-min(a,b);
  	if(c%2==0){
    	cout<<min(a,b)+c/2<<"\n";
    }
  	else{
    	cout<<"IMPOSSIBLE\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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

const ll mod = 1e9+7;

ll modpow(ll a,ll b){
    if(b == 0)return 1;
    if(b % 2 == 0){
        ll k = modpow(a,b/2);
        return k*k%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }
}
int main(void){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    ans += modpow(10,n);
    ans -= 2*modpow(9,n);
    ans += modpow(8,n);
    ans = ((ans%mod)+mod)%mod;

    cout << ans << endl;
    
    

    return 0;
}

Measured memory_bytes: 3616
#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;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long dp[110][100010];
  
int main()
{
  int N, W;
  cin >> N >> W;
  vector<vector<int>> A(N,vector<int>(2));
  REP(i, N){
    REP(j, 2){
      cin >> A.at(i).at(j);
    }
  }
  
  REP(i,110){
    REP(j,100010){
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;

  REP(i,N){
    REP(j,100010){
      if(j-A.at(i).at(1)>=0){
        chmin(dp[i+1][j],dp[i][j-A.at(i).at(1)]+A.at(i).at(0));
      }
      chmin(dp[i+1][j],dp[i][j]);
    }
  }

  int MAX = 0;
  REP(i,100010){
    if(dp[N][i] <= W){
      MAX = max(MAX,i);
    }
  }
  cout << MAX << endl;
}

Measured memory_bytes: 86272
S = input() 

if S == 'SUN':
  print(7)
if S == 'MON':
  print(6)
if S == 'TUE':
  print(5)
if S == 'WED':
  print(4)
if S == 'THU':
  print(3)
if S == 'FRI':
  print(2)
if S == 'SAT':
  print(1)
  

Measured memory_bytes: 3060
import math

a, b, x = map(int, input().split())

L = a*a*b
s = x/a

if L <= x * 2:
	l = 2*(a*b-s)/a
	print(math.degrees(math.atan2(l, a)))
	
else:
	l = 2*s/b
	print(math.degrees(math.atan2(b, l)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

int h, w, n;
int a[100010], b[100010];
int ans[10];

signed main(){
    cin >> h >> w >> n;
    ans[0] = (h - 2) * (w - 2);
    map<P, int> mp;
    rep(i, 0, n){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        rep(j, 0, 3){
            rep(k, 0, 3){
                int y = a[i] - 1 + j;
                int x = b[i] - 1 + k;
                if(!(1 <= y && y < h - 1 && 1 <= x && x < w - 1)) continue;
                //if(!(abs(j - 2) + abs(k - 2) <= 2 && max(abs(j - 2)))) continue;
                P now = P(y, x); 
                mp[now]++;
            }
        }
    }
    for(map<P, int>::iterator it = mp.begin(); it != mp.end(); it++){
        ans[0]--;
        ans[it -> second]++;
        // cout << it -> first.first <<" "<< it -> first.second << " " << it-> second << endl;
    }
    rep(i, 0, 10){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 58112
import java.util.Scanner;

/*
問題文

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int h1 = sc.nextInt();
        int m1 = sc.nextInt();
        int h2 = sc.nextInt();
        int m2 = sc.nextInt();
        int k = sc.nextInt();

        int start = h1 * 60 + m1;
        int end = h2 * 60 + m2;

        int a = end - start;
        int ans = a-k;
        if (ans < 0) {
        	ans = 0;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 35736
//Let Our Voices Echo
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAX=2e5+9;
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	string s;
	cin>>s;
	int res=1e9;
	for (int j='a';j<='z';j++)
	{	
		int ls=-1,ans=0;
		for (int i=0;i<(int)s.size();i++)
			if (s[i]==j)
			{
				ans=max(ans,i-ls-1);
				ls=i;
				res=min(res,max(ans,(int)s.size()-i-1));
			}
	}
	cout<<res;
	return 0;
}

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

int main() {
  int n,sum = 0,c = 0;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
    sum += data[i];
    if(data[i]%10 == 0) c++;
  }
  sort(data.begin(),data.end());
  if(c == n){
    cout << 0 << endl;
    return 0;
  }
  if(sum%10 == 0){
    for(int i = 0;i < n;i++){
      if(data[i]%10 != 0){
        sum -= data[i];
        cout << sum << endl;
        return 0;
      }
    }
  }
  else{
    cout << sum << endl;
  }
}


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

int f(long *a, long k, int l, int r){
  while(l<=r){
    int m=(l+r)/2;
    if(a[m]<k) l=m+1;
    else r=m-1;
  }
  return l;
}

int main(){
  int n, i;
  scanf("%d", &n);
  long *b = calloc(n, sizeof(long)), B=0;
  for(i=0; i<n; i++){
    int a;
    scanf("%d", &a);
    B+=a;
    b[i]=B;
  }
  int l=f(b, (b[n-1]+1)/2, 0, n-1);
  long a0=2*b[l]-b[n-1];
  long a1=b[n-1]-2*b[l-1];
  printf("%ld\n", a0>a1?a1:a0);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e10
#define mod 1000000007
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)
vi graph[100000];
int vis[100000], c[100000], dis[100000];
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
bool func(int x, int y)
{
	return x > y;
}
double f(double h, double m)
{
	// validate the input
	if (h < 0 || m < 0 || h > 12 || m > 60)
		printf("Wrong input");

	if (h == 12) h = 0;
	if (m == 60) m = 0;

	// Calculate the angles moved
	// by hour and minute hands
	// with reference to 12:00
	int hour_angle = 0.5 * (h * 60 + m);
	int minute_angle = 6 * m;

	// Find the difference between two angles
	int angle = abs(hour_angle - minute_angle);

	// Return the smaller angle of two possible angles
	angle = min(360 - angle, angle);

	return angle;
}
double Convert(double radian) {
	double pi = 3.14159;
	return (pi * radian) / 180;
}
double co(double h, double m)
{
	return (30 * h) - (11 * (m / 2));
}
bool distinct(int n)
{
	set<int>se;
	int count = 0;
	while (n != 0)
	{
		se.insert(n % 10);
		count++;
		n /= 10;
	}
	if (se.size() == count)
		return true;
	else
		return false;
}
int32_t main()

{
//	c_p_c();

	int a, b;
	cin >> a >> b;
	cout << a*b;

}








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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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;
};

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

  int N, K;
  cin >> N >> K;
  vl A(N);
  rep(i, 0, N) {
    cin >> A[i];
  }

  sort(All(A));
  reverse(All(A));
  ll ans = 0;
  rep(i, 0, N) {
    if (K) {
      K--;
    } else {
      ans += A[i];
    }
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int n;
	while (1)
	{
		cin >> n;
		if (n == 0)
			break;
		vector<char> check1(n), check2(n);
		for (int i = 0; i != n; ++i)
			cin >> check1[i] >> check2[i];
		int m;
		cin >> m;
		string str;
		for (int i = 0; i != m; ++i)
		{
			char c;
			cin >> c;
			for (int j = 0; j != n; ++j)
			{
				if (c == check1[j])
				{
					c = check2[j];
					break;
				}
			}
			str += c;
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1336
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int r=stdIn.nextInt();
		if(1200>r) System.out.print("ABC");
		else if(2800>r) System.out.print("ARC");
		else System.out.print("AGC");
	}
}

Measured memory_bytes: 21716
N = int(input())
flag = False
answer = 'No'
for i in range(-(-N//4)+1):
    for j in range(-(-N//7)+1):
        res = 4*i + 7*j
        if res == N:
            answer = 'Yes'
            flag = True
            break
    if flag:
        break
print(answer)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// AtCoder Functions
var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}

	ret := 0
	for i := 0; i < N; i++ {
		ret += (a[i] - 1)
	}
	fmt.Println(ret)
}


Measured memory_bytes: 640
A, B, C, D, E, F = [int(_) for _ in input().split()]

maxr = 0
result = 0, 0

for a in range(31):
    for b in range(31):
        l = 100 * a * A + 100 * b * B
        if l <= F:
            maxs100 = E * l
            d = 0
            while d * D * 100 <= maxs100:
                c1 = (maxs100 - d * D * 100) // (C * 100)
                c2 = (F - l - d * D) // C
                c = min(c1, max(0, c2)) 
                s = c * C + d * D
                w = l + s
                if 0 < w <= F:
                    r = 100 * s / w
                    if r >= maxr:
                        maxr = r
                        result = w, s
                d += 1

print(*result)

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

int main()
{
    int l,r,d,i,s;
    s=0;
    scanf("%d %d %d",&l,&r,&d);
    for(i=l;i<=r;i++)
    {
        if(i % d ==0)
        {
            s++;
        }
    }
    printf("%d",s);

return 0;
}

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

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

    int sum_value =0;
    vector<int> weight(n), value(n);

    for(int i=0; i<n; i++){
        cin>>weight[i]>>value[i];
        sum_value+=value[i];
    }

    vector<long long> dp(sum_value+1,1e18L+5);
    dp[0]=0;

    for(int i=0; i<n; i++){
      for(int va = sum_value - value[i]; va>=0; va--){
        dp[va+value[i]] = min(dp[va+value[i]], dp[va]+weight[i]);
      }
      
    }

    long long maxi=0;
    for(int i=0; i<=sum_value; i++){
        if(dp[i]<=W)
            maxi = max((long long) i, maxi);
    }
    cout<<maxi;
}

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

int main() {
    int n,m,s;
    cin >> n >> m >> s;
    struct graph {
        int to, cost, time;
    };
    vector<vector<graph>> g(n);
    rep(i,m) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--;v--;
        g[u].push_back({v, a, b});
        g[v].push_back({u, a, b});
    }
    struct bank{
        int time, money;
    };
    vector<bank> ba(n);
    rep(i,n) {
        int c,d;
        cin >> c >> d;
        ba[i].money = c;
        ba[i].time = d;
    }
    const ll INF = INT64_MAX>>2;
    using T = tuple<ll,int,int>; //時間、銀貨の枚数、場所
    chmin(s, 50*n);
    vector<vector<ll>> dp(n, vector<ll>(50*n+1,INF)); //dp[場所][銀貨の枚数]=時間
    priority_queue<T, vector<T>, greater<T>> pq; 
    pq.emplace(make_tuple(0,s,0));
    dp[0][s] = 0;
    while(!pq.empty()) {
        auto now = pq.top();
        pq.pop();
        ll t = get<0>(now);
        int c = get<1>(now);
        int v = get<2>(now);
        if(t > dp[v][c]) continue;
        int next_money = min(50*n, c+ba[v].money);
        if(dp[v][next_money] > dp[v][c] + ba[v].time) {
            dp[v][next_money] = dp[v][c] + ba[v].time;
            pq.emplace(make_tuple(dp[v][next_money], next_money, v));
        }
        for(auto next: g[v]) {
            if(c-next.cost < 0) continue;
            if(dp[next.to][c-next.cost] > dp[v][c] + next.time) {
                dp[next.to][c-next.cost] = dp[v][c] + next.time;
                pq.emplace(make_tuple(dp[next.to][c-next.cost], c-next.cost, next.to));
            }
        }
    }
    for(int dest = 1; dest < n; dest++) {
        ll ans = INF;
        rep(i,50*n+1) {
            chmin(ans, dp[dest][i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6364
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpr make_pair
#define mt make_tuple
 
using namespace std;
 
const ll N = 3010;
const ll mod = 1e9 + 7;
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; }
ll n, sum;
ll arr[N], dp[N][N][2];

ll solve(int l, int r, int flag){
    if(l > r)   return 0;
    if(dp[l][r][flag] != -1)  return dp[l][r][flag];
    if(flag)    dp[l][r][flag] = min(solve(l+1,r,0) - arr[l], solve(l,r-1,0) - arr[r]);
    else    dp[l][r][flag] = max(arr[l] + solve(l+1,r,1), arr[r] + solve(l,r-1,1));
    return dp[l][r][flag];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sum = 0;
    cin>>n;
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum += arr[i];
    }
    cout<<solve(0,n-1,0)<<endl;
    return 0;
}

Measured memory_bytes: 142080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int x = sc.nextInt();
		if(x < 600) {
			System.out.println(8);
		}else if(x < 800) {
			System.out.println(7);
		}else if(x < 1000) {
			System.out.println(6);
		}else if(x < 1200) {
			System.out.println(5);
		}else if(x < 1400) {
			System.out.println(4);
		}else if(x < 1600) {
			System.out.println(3);
		}else if(x < 1800) {
			System.out.println(2);
		}else {
			System.out.println(1);
		}
	}

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

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

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

	        return tokenizer.nextToken("\n");
	    }

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

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

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

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

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


Measured memory_bytes: 32684
# AOJ 1155: How can I satisfy thee? Let me count
# Python3 2018.7.17 bal4u

def term(idx):
    x, idx = factor(idx)
    op = buf[idx]
    y, idx = factor(idx+1);
    if op == '*':
        if x == 2 and y == 2: x = 2
        elif x == 0 or y == 0: x = 0
        else: x = 1
    else:
        if x == 0 and y == 0: x = 0
        elif x == 2 or y == 2: x = 2
        else: x = 1
    return [x, idx]

def factor(idx):
    global p, q, r
    if buf[idx] == '(': x, idx = term(idx+1)
    elif buf[idx] == '-':
        x, idx = factor(idx+1)
        x = 2-x; idx -= 1
    elif '0'<= buf[idx] <='9': x = int(buf[idx])
    elif buf[idx] == 'P': x = p
    elif buf[idx] == 'Q': x = q
    else: x = r
    return [x, idx+1]

while True:
    buf = list(input())
    if buf[0] == '.': break
    ans = 0
    for p in range(3):
        for q in range(3):
            for r in range(3):
                if factor(0)[0] == 2: ans += 1
    print(ans)



Measured memory_bytes: 5608
#include <iostream>
#include <string>

using namespace std;

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

    for(int i = 0; i < tap.size(); i++) {
        char ch = tap[i];
        if (i % 2 == 0 && ch == 'L') {
            cout << "No" << endl;
            return 0;
        }
        if (i % 2 == 1 && ch == 'R') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
    int a,b,c,n=0;
    scanf("%d %d %d",&a,&b,&c);
    for (; a<=b; a++) {
        if (c%a==0) {
            n+=1;
        }
    }
    
    printf("%d\n",n);
    
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    vector<uint64_t> v(n);
    for(int i = 0; i < n;i++) cin >> v.at(i);
    sort(v.begin(),v.end());
    uint64_t ans = 1;
	bool f = true;
    for(int i = 0; i < n;i++){
        uint64_t t_ans = ans;
        ans *= v.at(i);
        if(v.at(i) == 0){
            ans = 0;
            break;
        }
        if(ans > 1000000000000000000LL || ans < t_ans){
            f = false;
            break;
        }
    }
  if(f) cout << ans << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 4052
using System;
using System.Linq;

namespace study7
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] imput = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int A = 0; A <= 5; A++)
                if (imput[A] == 0)
                {
                    Console.WriteLine(A+1);
                    A = 10;
                }
            

            
               
        }
    }
}

Measured memory_bytes: 18992
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  const solve = memoization(function(i, m) {
    if (m == 0) return true;
    if (i >= n1) return false;
    return solve(i + 1, m) || solve(i + 1, m - arr1[i]);
  });

  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();

function memoization(f) {
  const cache = {};
  return function innerFunc(...param) {
    const c = cache[param];
    return typeof c === 'undefined' ? cache[param] = f(...param) : c;
  }
}



Measured memory_bytes: 24396
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
from math import sqrt
from math import floor

Q = int(input())
A_list = []
B_list = []

for i in range(Q):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

for A, B in zip(A_list, B_list):
    if A == B:
        print(2*A-2)
        continue
    if abs( A - B) == 1:
        print(2*min(A, B)-2)
        continue
    C = int(floor(sqrt(A*B)))
    if C*C >= A*B:
        C -= 1
    if C * (C + 1) >= A*B:
        print(2*C-2)
        continue
    print(2*C-1)

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,count=0,l=0,r;
    cin>>n;
    r=n-1;
    string s;
    cin>>s;
    while(l<r){
        if(s[l]=='W'&&s[r]=='R')
        count++,l++,r--;
        if(s[l]=='R')
        l++;
        if(s[r]=='W')
        r--;
    }
    cout<<count;
    return 0;
}

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

int cnt;
int array[1000000];
int G[100];

void insertionSort(int array[], int n, int g) {
    int i, j, v;
    i = 0;
    
    for (i = g; i < n; i++) {
        v = array[i];
        j = i - g;

        while (j >= 0 && array[j] > v) {
            array[j + g] = array[j];
            j = j - g;
            cnt++;
        }

        array[j + g] = v;
    }
}

void shellSort(int array[], int n) {
    cnt = 0;
    int h;
    int i = 0;
    for (h = 1; ; ) {
        if (h > n) break;
        G[i] = h;
        i++;
        h = 3 * h + 1; 
    }

    int m = i;
    if (m > 100) m = 100;

    printf("%d\n", m);

    i = 0;
    for (i = m-1; i >= 0; i--) {
        printf("%d ", G[i]);
        insertionSort(array, n, G[i]);
    }

    printf("\n%d\n", cnt);

    for (i = 0; i < n; i++) {
        printf("%d\n", array[i]);
    }
}

int main() {

    int n, key;
    scanf("%d", &n);
    key = n;
    
    int i = 0;
    while ( key-- ) {
        scanf("%d", &array[i]);
        i++;
    }

    shellSort(array, n);

    return 0;
}



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

int main() {
    using namespace std;
    unsigned long A, B;
    string S, T, U;
    cin >> S >> T >> A >> B >> U;
    if(S == U)--A;
    if(T == U)--B;
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n,coun[300005][2],minn=300005;
char s[300005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf(" %c",&s[i]);
		coun[i][0]=coun[i-1][0];
		if(s[i]=='W')
			coun[i][0]++;
	}
	for(int i=n;i>=1;i--)
	{
		coun[i-1][1]=coun[i][1];
		if(s[i]=='E')
			coun[i-1][1]++;
		minn=min(minn,coun[i][0]+coun[i][1]);
	}
	minn=min(minn,coun[0][1]);
	printf("%d",minn);
	return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	ll a{},b{},c{},ans{};
	cin>>a>>b>>c;
	if(a==b && b==c && !(a&1))cout<<"-1\n";
	else{
		while(true)
		{
			if(a&1 || b&1 || c&1)break;
			a/=2,b/=2,c/=2;
			int aa=a,bb=b,cc=c;
			a=bb+cc,b=aa+cc,c=aa+bb;
			ans++;
		}
		cout<<ans<<'\n';
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 3612
# import sys
# input = sys.stdin.readline

n = int(input())
C = [list(map(int,input().split())) for i in range(n-1)]

V = [0] * (n+1)
P = [-1] * (n+1)

M = [[] for i in range(n+1)]
for i in range(n-1):
    M[C[i][0]].append(C[i][1])
    M[C[i][1]].append(C[i][0])

Q = [1]
s = 0
V[1] = 1
while s < len(Q):
    i = Q[s]
    for x in M[i]:
        if V[x] == 0:
            V[x] = 1
            P[x] = i
            Q.append(x)
    s += 1
    # print(Q)

# print(P)

aida = [n]
a = n
while a != 1:
    a = P[a]
    aida.append(a)



V = [0] * (n+1)
for i in aida:
    V[i] = 1

aida = aida[::-1]
# print(aida)

fe = 0
su = 0
for j in range(len(aida)):
    ans = 1
    Q = [aida[j]]
    s = 0
    while s < len(Q):
        i = Q[s]
        for x in M[i]:
            if V[x] == 0:
                V[x] = 1
                P[x] = i
                Q.append(x)
                ans += 1
        s += 1
    if j < (len(aida)+1)//2:
        fe += ans
    else:
        su += ans
    # print(aida[j],ans)

# print(fe,su)
if fe > su:
    print("Fennec")
else:
    print("Snuke")

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

using namespace std;

const long long MOD = 1000000000 + 7;
const string abc = "abacaba";

void solve() {
    long long x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (2 * (x % d) == d) {
        cout << x % d;
        return;
    }
    long long cnt = x / d;
    if (cnt >= k) {
        cout << x - k*d;
        return;
    }
    if ((k - cnt) % 2 == 0) {
        cout << x % d;
    } else {
        cout << d - x % d;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    int t;
//    cin >> t;
//    for (int tt = 0; tt < t; tt++) {
//        solve();
//    }
    solve();
    return 0;
}


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

int main() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 < m2) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int mod2 = 998244353;

int main() {
  string s;
  cin >> s;
  s += 'S';
  int onr = 0;
  int onl = 0;
  vector<int> ans(s.size());
  for (int i = 0;i < s.size();i++) {
    if (s[i] == 'R') {
      onr++;
      if (s[i+1] == 'L') {
        int k = i;
        for (int j = i+1;j < s.size();j++) {
          if (s[j] == 'L') onl++;
          else {
            ans[k] = onr - (onr / 2) + (onl / 2);
            ans[k+1] = (onr / 2) + onl - (onl / 2);
            onr = 0;
            onl = 0;
            break;
          }
        }
      }
    }
  }
  for (int i = 0;i < s.size()-1;i++) cout << ans[i] << endl;  
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n,a;
    cin>>n>>a;
    cout<<n*n-a<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

typedef array<int, 4> Tile;

int cntSameRotate(Tile t) {
    Tile t1 = t;
    int ret = 1;
    for (int i = 0; i < 3; ++i) {
        rotate(t1.begin(), t1.begin() + 1, t1.end());
        ret += (t1 == t);
    }
    return ret;
}

Tile minLex(Tile t) {
    Tile ret = t, tx = t;
    for (int i = 1; i < 4; ++i) {
        rotate(tx.begin(), tx.begin() + 1, tx.end());
        ret = min(ret, tx);
    }
    return ret;
}

int64_t comb(int n, int k) {
    int64_t ans = 1;
    for (int i = 1; i <= k; ++i) {
        ans *= (n - i + 1);
    }
    return ans;
}

ostream& operator<<(ostream& o, const Tile& t) {
    o << "{";
    for (int i = 0; i < 3; ++i) {
        o << t[i] << ", ";
    }
    o << t[3] << "}";
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<Tile> tiles(n);
    map<Tile, int> cnt;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            cin >> tiles[i][j];
        }
        tiles[i] = minLex(tiles[i]);
        cnt[tiles[i]]++;
    }

    int64_t ans = 0;
    for (int i = 0; i < n; ++i) {
        Tile t1 = tiles[i];
        cnt[t1]--;
        for (int j = i + 1; j < n; ++j) {
            Tile t2 = tiles[j];
            cnt[tiles[j]]--;
            reverse(t2.begin(), t2.end());
            for (int k = 0; k < 4; ++k) {
                rotate(t2.begin(), t2.begin() + 1, t2.end());
                array<Tile, 4> t;
                for (int i = 0; i < 4; ++i) {
                    t[i] = {t1[(i + 1) & 3], t1[i], t2[i], t2[(i + 1) & 3]};
                    t[i] = minLex(t[i]);
                }
                sort(t.begin(), t.end());
                int64_t add = 1;
                for (int i = 0, j; i < 4; i = j) {
                    for (j = i; j < 4 && t[j] == t[i]; ++j);
                    add *= comb(cnt[t[i]], j - i);
                    for (int x = 0; x < j - i; ++x) {
                        add *= cntSameRotate(t[i]);
                    }
                }
                ans += add;
            }
            cnt[tiles[j]]++;
        }
    }

    cout << ans << '\n';
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 n,m;
    cin >> n >> m;

    vector<i64> x(n),y(m);
    rep(i,0,n) cin >> x[i];
    rep(i,0,m) cin >> y[i];

    i64 s=0,t=0,mod=1000000007;
    rep(i,0,n-1) s=(s+(i+1)*(n-i-1)%mod*(x[i+1]-x[i])%mod)%mod;
    rep(i,0,m-1) t=(t+(i+1)*(m-i-1)%mod*(y[i+1]-y[i])%mod)%mod;

    cout << s*t%mod << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}

int main() {
	ll A, B, C;
	cin >> A >> B ;
	cout << A+B/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,flag=0;cin>>N;
  vector<string> a(N);
  vector<int> b(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  for(int i=0;i<N;i++)b.at(i)=a.at(i).size();
  for(int i=1;i<N;i++){
    if(a.at(i-1).at(b.at(i-1)-1)!=a.at(i).at(0)){
      flag++;
      break;
    }
    for(int j=0;j<i;j++){
      if(a.at(i)==a.at(j)){
        flag++;
        break;
      }
    }
    if(flag>0)break;
  }
  if(flag>0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
    long long int n,i,j=0,k=0,x,f=0,p=0;
    map<long long int,long long int>m;
    vector<long long int>s;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        m[x]++;
        if(m[x]==2)
        {
            s.push_back(x);
            m[x]=0;
        }
    }
    sort(s.begin(),s.end());
    if(s.size()<2)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<s[s.size()-1]*s[s.size()-2]<<endl;
    }
    return 0;
}


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

 using namespace std;
 typedef long long ll;

 int main() {
   int R, G, B, N, r, g, b, ans = 0;
   cin >> R >> G >> B >> N;

   for (int r = 0; r <= N / R; r++) {
     for (int g = 0; g <= (N - r * R) / G; g++) {
        if ((N - (R * r + G * g)) % B == 0) ans++;
     }
   }
   cout << ans << endl;
  }


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()

mod = 1000000007

def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    return p+mod if p < 0 else p

fs = [0] * 5000
ifs = [0] * 5000
fs[0] = 1
for i in range(1, 5000):
    fs[i] = fs[i-1] * i % mod
ifs[-1] = inv(fs[-1], mod)
for i in range(4998, -1, -1):
    ifs[i] = ifs[i+1] * (i+1) % mod

def c(n, r, fs, ifs, mod):
    if r < 0 or n < 0 or r > n: return 0
    return fs[n] * ifs[r] * ifs[n-r] % mod

# C(n-k+1, i)*C(i-1+k-i,k-i)
for i in range(1,k+1):
    print(c(n-k+1, i, fs, ifs, mod) * c(i-1+k-i, k-i, fs, ifs, mod)%mod)


Measured memory_bytes: 43632
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=423;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
char a[maxn][maxn];
int ans[maxn][maxn];
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    k=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='#'){
                k++;
                int J=j+1;
                ans[i][j]=k;
                while(a[i][J]=='.' && J<=m){
                    ans[i][J]=k;
                    J++;
                }
            }
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='#'){
                int J=j-1;
                while(a[i][J]=='.' && J>=1 && ans[i][J]==0){
                    ans[i][J]=ans[i][j];
                    J--;
                }
            }
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int J=i-1;
            while(a[J][j]!='#' && J>=1 && ans[J][j]==0){
                ans[J][j]=ans[i][j];
                J--;
            }
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int J=i+1;
            while(a[J][j]=='.' && J<=n && ans[J][j]==0){
                ans[J][j]=ans[i][j];
                J++;
            }
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<"\n";
    }
    exit(0);
}


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

 using namespace std;
 int main() {
   string S;
   cin >> S;
   if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) cout << "Bad" << endl;
   else cout << "Good" << endl;
 }


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  int ans=1;
  int d=0;
  int j=1;
  for(int i=0; i<N; i++){
    if(a.at(j-1) != 2){
      j = a.at(j-1);
      ans++;
    }
    else{
      d++;
      cout << ans << endl;
      break;
    }
  }
  if(d==0){
    cout << -1 << endl;
  }
  return 0;
}

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

using namespace std;

int aI,aO,aT,aJ,aL,aS,aZ;
int main() {
	scanf("%d%d%d%d%d%d%d",&aI,&aO,&aT,&aJ,&aL,&aS,&aZ);

	long long ans = 0ll + aJ / 2 * 2 + aL / 2 * 2 + aI / 2 * 2 + aO;
	if(aJ && aL && aI) {
		ans = max(ans, 0ll + (aJ - 1) / 2 * 2 + (aL - 1) / 2 * 2 + (aI - 1) / 2 * 2 + aO + 3);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  int a[2][100];
  rep(i,2)rep(j,n)cin>>a[i][j];
  int ans=0;
  rep(i,n){
    int t=0;
    rep(j,n){
      if(j<=i)t+=a[0][j];
      if(j>=i) t+=a[1][j];
    }
    ans=max(ans,t);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
///
// File:  a.cpp
// Author: ymiyamoto
//
// Created on Sat Nov  4 21:35:26 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str1, str2;
  cin >> str1;
  cin >> str2;

  reverse(str1.begin(), str1.end());
  if (str1 == str2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
  int n,h,m,s;
  while(scanf("%d",&n),n){
    vector< pair<int,int> > v;
    for(int i=0;i<n;i++){
      scanf("%d:%d:%d",&h,&m,&s);
      v.push_back(make_pair(h*3600 + m*60 + s,1));

      scanf("%d:%d:%d",&h,&m,&s);
      v.push_back(make_pair(h*3600 + m*60 + s,0));
    }

    sort(v.begin(),v.end());

    int cnt = 0, ans = 0;
    for(int i=0;i<v.size();i++){
      if(v[i].second == 1)cnt++;
      else cnt--;
      ans = max(ans,cnt);
    }

    printf("%d\n",ans);
  }
}
    

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

#include <cmath>    //floor ceil
#include <cstdlib>  //abs
#include <cstdio>
#include <climits>  //INT_MAX
#include <cstring>
#define endl "\n"
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define lli long long int
#define MOD 1000000007
#include <map>
#define mp make_pair
#define mii map<int,int>
/*---------------------------------------------------CODE STARTS FROM HERE---------------------------------------------------*/
lli fact (int n) {
    if(n<=1) return 1;
    else {
        lli f=1;
        for (int i=2;i<n+1;i++) {
            f *= i;
        }
        return f;
    }
}
int main ()
{
    /*int tt;
    cin >> tt;
    while(tt--)
    {

    }*/
    lli ans=0,an=0;
    int n;
    cin >> n;
    int a[n],b[n];
    for (int i=0;i<n;i++) cin >> a[i];
    for (int i=0;i<n;i++) cin >> b[i];

    for (int i=0;i+1<n;i++) {
        int c=0;
        for (int j=i+1;j<n;j++) {
            if(a[j]<a[i]) c++;
        }
        ans += c*fact(n-1-i);
    }
    for (int i=0;i+1<n;i++) {
        int c=0;
        for (int j=i+1;j<n;j++) {
            if(b[j]<b[i]) c++;
        }
        an += c*fact(n-1-i);
    }
    cout<<abs(ans-an)<<endl;
    return 0;
}

Measured memory_bytes: 3604