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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	int k, s;
	ll ans = 0;
	
	scanf("%d %d", &k, &s);
	
	reppp(x, max(0, s-2*k), min(k, s)){
		reppp(y, max(s-x-k, 0), min(k,s)){
			if(s-x-y >= 0 && s-x-y <= k) ans++;
		}
	}
	
	printf("%lld", ans);
}

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

#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN

	int n, i, c = 1;
	string s;
	cin >> n;
	cin >> s;
	for (i = 0; i < n; i++) {
		if (i > 0 and s[i] != s[i - 1])
			c++;
	}
	cout << c << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
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 int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};

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

using P = pair<int, int>;
using data = pair<int, P>;

int dp[110][110][2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    for(int i = 0; i < h; i++) {
        cin >> g[i];
    }
    // (y,x)
    for(int i = 0; i < 110; i++) {
        for(int j = 0; j < 110; j++) {
            for(int k = 0; k < 2; k++) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][g[0][0] == '#'] = (g[0][0] == '#');
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            for(int k = 0; k < 2; k++) {
                int ni = i + dy[k];
                int nj = j + dx[k];
                if(!(0 <= ni && ni < h && 0 <= nj && nj < w)) {
                    continue;
                }
                for(int l = 0; l < 2; l++) {
                    if(dp[i][j][l] == INF) {
                        continue;
                    }
                    if(g[ni][nj] == '#') {
                        chmin(dp[ni][nj][1], dp[i][j][l] + (l == 0));
                    } else {
                        chmin(dp[ni][nj][0], dp[i][j][l]);
                    }
                }
            }
        }
    }
    cout << min(dp[h - 1][w - 1][0], dp[h - 1][w - 1][1]) << endl;
}

Measured memory_bytes: 384
from scipy.sparse import*
H,*S=open(0)
H,W,*A=map(int,H.split())
for i in range(m:=H*W):A+=[m*2,h:=i//W,I:=m*3,m*2,w:=i%W+m,I]*((c:=S[h][w-m])=='S')+[h,I,I,w,I,I]*(c=='T')+[h,w,1,w,h,1]*(c>'T')
print([-1,f:=csgraph.maximum_flow(csr_matrix((A[2::3],(A[::3],A[1::3])),[I+1]*2),m*2,I).flow_value][f<I])

Measured memory_bytes: 40472
import sys
input = sys.stdin.readline
maxa=10**10
L=list()
N,K=map(int,input().split())
for i in range(N):
  S=int(input())
  L.append(S)
L=sorted(L)
for i in range(N-K+1):
  maxa=min(maxa,L[i+K-1]-L[i])
print(maxa)

Measured memory_bytes: 14012
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int powmod(int a, int b, int c = MOD){
    int ans = 1;
    while(b){
        if(b&1){
            ans = (ans*a)%c;
        }
        a = (a*a)%c;
        b >>= 1;
    }
    return ans;
}

void solve(){
    int n, k; cin>>n>>k;
    vector<int> a(n);
    vector<int> pos, neg;
    int ans = 1;
    int cur = 1;
    For(i, 0, n){
        cin>>a[i];
        if(a[i] < 0){
            neg.pb(abs(a[i]));
            cur *= -1;
            a[i] += MOD;
            ans *= a[i];
        }
        else{
            pos.pb(a[i]);
            ans *= a[i];
        }
        ans %= MOD;
    }
    if(k == n){
        cout<<ans;
        return;
    }
    sort(all(neg)); sort(all(pos));
    ans = 1;
    if(k % 2 && sz(pos) == 0){
        For(i, 0, k){
            ans *= neg[i];
            ans %= MOD;
        }
        ans *= (MOD-1);
        ans %= MOD;
        cout<<ans;
        return;
    }
    else if(k % 2){
        ans *= pos.back();
        pos.pop_back();
        k--;
    }
    reverse(all(pos)); reverse(all(neg));
    int pp = 0, np = 0;
    For(i, 0, k/2){
        int pv = -1, nv = -1;
        if(pp + 1 < sz(pos)){
            pv = pos[pp]*pos[pp+1];
        }
        if(np + 1 < sz(neg)){
            nv = neg[np]*neg[np+1];
        }
        assert(pv!=-1 || nv!=-1);
        if(pv > nv){
            pv %= MOD;
            ans *= pv;
            ans %= MOD;
            pp += 2;
        }
        else{
            nv %= MOD;
            ans *= nv;
            ans %= MOD;
            np += 2;
        }
    }
    cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 6952
#include <cstdio>

const int MAXN = 2e5 + 19;

inline int f(int x){
	int res = 0;
	while(x)
		++res, x %= __builtin_popcount(unsigned(x));
	return res;
}

int n, pop;
int low[MAXN], val_low;
int hig[MAXN], val_hig;
char s[MAXN];

int main(){
	std::scanf("%d%s", &n, s + 1);
	for(int i = 1; i <= n; ++i)
		if(s[i] == '1')
			++pop;
	low[1] = 1, hig[1] = 1;
	for(int i = 2; i <= n; ++i){
		if(pop - 1)
			low[i] = low[i - 1] * 2 % (pop - 1);
		hig[i] = hig[i - 1] * 2 % (pop + 1);
	}
	for(int i = 1; i <= n; ++i)
		if(s[n - i + 1] == '1'){
			if(pop - 1)
				val_low = (val_low + low[i]) % (pop - 1);
			val_hig = (val_hig + hig[i]) % (pop + 1);
		}
	for(int i = 1, val; i <= n; ++i)
		if(s[i] == '1'){
		//	if(check(i))
		//		continue;
			if(pop == 1){
				std::puts("0");
				continue;
			}
			val = (val_low - low[n - i + 1]) % (pop - 1);
			val += pop - 1;
			val %= pop - 1;
			std::printf("%d\n", f(val) + 1);
		}
		else{
		//	if(check(i))
		//		continue;
			val = (val_hig + hig[n - i + 1]) % (pop + 1);
			val += pop + 1;
			val %= pop + 1;
			std::printf("%d\n", f(val) + 1);
		}
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;

int k;
cin >> k;

int output=0;
if(k <= a){
output= k;
}else if(k <= a + b){
output = a;
}else{
output = a * 1 + (k - a - b) * -1;
}

cout<< output << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
 
 
void func()
{
  bool ch[4]={};
  ll a,b;
  cin>>a>>b;
  ch[a]=1;
  ch[b]=1;
  f(i,1,4)
  {
    if(ch[i]==0)
    {
      cout<<i<<endl;
    }
  }
}
 
int main() 
{
    fast
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    
    ll q=1;
    //cin>>q;
    while(q)
    {
      func();
      q--;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int m,f,b;
    cin>>m>>f>>b;
    if(m+f<b){
      cout<<"NA"<<endl;
    }
    if(m+f>=b&&m<b){
      cout<<b-m<<endl;
    }
    if(m>b){
      cout<<0<<endl;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
string b[1000000];
bool cmp(string a, string b)
{
    return a < b;
}
int main()
{
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);

    int n,l;
    cin >> n >> l;
    for(int i = 1;i <= n;++i)
        cin >> b[i];
    sort(b + 1,b + 1 + n,cmp);
    for(int i = 1;i <= n;++i)
        cout << b[i];
    return 0;
}

Measured memory_bytes: 8064
# coding: utf-8
n=int(input())
l = list(map(int,input().split()))
heikin=sum(l)/n
tmp=float('inf')
ans=n-1
for i in range(n-1,-1,-1):
    if abs(l[i]-heikin) <= tmp:
        ans=i
        tmp=abs(l[i]-heikin)
print(ans)

Measured memory_bytes: 9192
a, b, c, d, e, f = map(int, input().split())


cap = e / (100 + e)
max_noudo = 0
sugar_ans, water_ans = 0, 0
for i in range(f//(100*a)+1):
    for j in range((f - (100 * a * i)) // (100 * b) + 1):
        water = 100 * (i * a + j * b)
        for k in range(((i * a + j * b)*e)//c+1):
            for l in range(((i * a + j * b)*e - k*c)//d+1):
                sugar = k * c + l * d
                if f < water + sugar or water == 0:
                    continue
                else:
                    noudo = sugar / (water + sugar)
                    if max_noudo <= noudo <= cap:
                        max_noudo = noudo
                        sugar_ans = sugar
                        water_ans = water
print(water_ans+sugar_ans, sugar_ans)


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<vector<VI>> dp(4,vector<VI>(4 ,VI(4)));
	dp[0][0][0] = 1;
	rep(i, n){
		vector<vector<VI>> np(4,vector<VI>(4 ,VI(4)));
		rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4){
			if((b==1 && c==2 && d==3) || (b==2 && c==1 && d==3) ||
				(b==1 && c==3 && d==2) || (a==1 && c==2 && d==3) ||
				(a==1 && b==2 && d==3)) continue;
			(np[b][c][d] += dp[a][b][c]) %=MD;
		}
		swap(np, dp);
	}
	ll ans = 0;
	rep(a, 4) rep(b, 4) rep(c, 4) (ans += dp[a][b][c]) %=MD;
	cout << ans <<"\n";
	return 0;
}


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

int main()
{
    int x;
    cin>>x;
    for(int i = 1; i <= 360; i++)
    {
        if ((x*i)%360 == 0)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String n = sc.next();

		int sum = 0;
		for (int i = 0; i < n.length(); i++) {
			sum += n.charAt(i) - '0';
		}

		System.out.println(Integer.parseInt(n) % sum == 0 ? "Yes" : "No");

		sc.close();
	}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
	lli a,v,b,w,t,d1=0,an=0;
	cin>>a>>v>>b>>w>>t;
    d1=abs(a-b);
    if(v>w)
    {
        an=v-w;
    }
    if(an*t>=d1)
    {
        cout<<"YES";
    }
    else
    cout<<"NO";
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=1e5+10;

ll dpin[maxn],dpout[maxn],mod;
int n,father[maxn];
vector <int> g[maxn];

void dfs1(int x,int fa){
	father[x]=fa;
	ll ret=1ll;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa) continue;
		dfs1(to,x);
		ret=(ret*dpin[to])%mod;
	}
	dpin[x]=(ret+1)%mod;
}

void dfs2(int x,int fa){
	vector <ll> v1,v2;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa) v1.pb(1ll),v2.pb(1ll);
		else v1.pb(dpin[to]),v2.pb(dpin[to]);
	}
	for(int i=1;i<v1.size();i++) v1[i]=(v1[i-1]*v1[i])%mod;
	for(int i=v2.size()-2;i>=0;i--) v2[i]=(v2[i+1]*v2[i])%mod;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa) continue;
		ll ret=1;
		if(i>0) ret=(ret*v1[i-1])%mod;
		if(i<v2.size()-1) ret=(ret*v2[i+1])%mod;
		ret=(ret*dpout[x])%mod;
		ret=(ret+1)%mod;
		dpout[to]=ret;
		dfs2(to,x);
	}
}

int main(){
	cin>>n>>mod;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		u--; v--;
		g[u].pb(v); g[v].pb(u);
	}
	dfs1(0,-1);
	dpout[0]=1ll; dfs2(0,-1);
	for(int i=0;i<n;i++){
		ll ans=dpout[i];
		for(int j=0;j<g[i].size();j++){
			int to=g[i][j];
			if(to==father[i]) continue;
			ans=(ans*dpin[to])%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 24704
#include<bits/stdc++.h>
using namespace std;
int main(){long long a,b,c,m=0,e,i,r;
cin>>a>>b;
r=b*10;
for(i=r;i<r+10;i++){
    c=((i*8)/100);
    if(c==a){
        e=i;m=1;break;
    }
}if(m==1)
cout<<e;
else
cout<<-1;


  return 0;
}


Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean f = true;
		StringBuilder s = new StringBuilder();
		Set<Character> t = new TreeSet<Character>();
		int[] a = new int[256];
		while (n-->0) {
			Set<Character> o = new TreeSet<Character>();
			int[] b = new int[256];
			for (char ch : sc.next().toCharArray()) {
				o.add(ch);
				if (f) a[ch]++;
				else b[ch]++; 
			}
			if (f) { t.addAll(o); f=false; }
			else t.retainAll(o);
			for (char ch : t) if (a[ch]!=0 && b[ch]!=0) a[ch] = Math.min(a[ch], b[ch]);
		}
		for (char ch : t) while (a[ch]-->0) s.append(ch);
		System.out.println(s);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

int main() {
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;++i)cin>>a[i];
	int m;cin>>m;
	vector<int> b(m);
	bool ok = true;
	for(int i=0;i<m;++i){
		cin>>b[i];
		ok &= binary_search(a.begin(),a.end(),b[i]);
	}
	cout<<(ok?1:0)<<endl;
  return 0;
}



Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> E(N);
  for (int i = 0; i < M; i++){
    int L, R, D;
    cin >> L >> R >> D;
    L--;
    R--;
    E[L].push_back(make_pair(D, R));
    E[R].push_back(make_pair(-D, L));
  }
  vector<int> d(N);
  vector<int> comp(N, -1);
  bool ok = true;
  for (int i = 0; i < N; i++){
    if (comp[i] == -1){
      comp[i] = i;
      d[i] = 0;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (auto P : E[v]){
          int dist = P.first;
          int w = P.second;
          if (comp[w] != -1){
            if (d[w] != d[v] + dist){
              ok = false;
            }
          } else {
            comp[w] = i;
            d[w] = d[v] + dist;
            Q.push(w);
          }
        }
      }
    }
  }
  if (ok){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 12668
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    vector<int> c(n);
    rep(i, n) {
        cin >> p[i];
        --p[i];
    }
    rep(i, n) cin >> c[i];
    ll ans = -1e18;
    rep(si, n) {
        int x = si;
        vector<int> s;
        ll tot = 0;
        while(1) {
            x = p[x];
            s.pb(c[x]);
            tot += c[x];
            if(x == si) break;
        }
        int l = s.size();
        ll t = 0;
        rep(i, l) {
            t += s[i];
            if(i + 1 > k) break;
            ll now = t;
            if(tot > 0) {
                ll e = (k - i - 1) / l;
                now += tot * e;
            }
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3692
/*
 *  author: chw0501
 *  reference: https://jinpyo.kim/EducationalDP-solution
 *  created: 25.04.2020 05:15:49(UTC)
*/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define MOD 1000000007 
#define INF 987654321 

int n;
ll m;
vector<int> adj[100010];
ll dp1[100010];
ll dp2[100010];
ll l[100010];
ll r[100010];
int p[100010];

ll solve1(int i){
	ll& ret=dp1[i];
	if(ret!=-1ll) return ret;
	ret=1;
	for(int next:adj[i]){
		if(next!=p[i]){
			ret=(ret*(1+solve1(next)))%m;
		}
	}
	return ret;
}
void f(int i){
	int len=adj[i].size();
	l[0]=1;
	for(int k=0;k<len;k++){
		if(adj[i][k]==p[i]){l[k+1]=l[k]; continue;}
		l[k+1]=(l[k]*(1+dp1[adj[i][k]]))%m;
	}
	r[len+1]=1;
	for(int k=len;k>=1;k--){
		if(adj[i][k-1]==p[i]){r[k]=r[k+1]; continue;}
		r[k]=(r[k+1]*(1+dp1[adj[i][k-1]]))%m;
	}
	for(int k=1;k<=len;k++){
		int next=adj[i][k-1];
		if(next==p[i]) continue;
		dp2[next]=(1+dp2[i]*((l[k-1]*r[k+1])%m))%m;
	}
	for(int next:adj[i]){
		if(next!=p[i]) f(next);
	}
}

void dfs(int i,int prev){
	p[i]=prev;
	for(int next:adj[i])
		if(next!=prev) dfs(next,i);
}

int main(){
	cin>>n;
	cin>>m;
	if(n==1){
		puts("1");
		return 0;
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1,0);
	memset(dp1,-1ll,sizeof(dp1));
	for(int i=1;i<=n;i++) solve1(i);
	dp2[1]=1;
	f(1);
	for(int i=1;i<=n;i++){
		printf("%lld\n",(dp1[i]*dp2[i])%m);
	}
	return 0;
}

Measured memory_bytes: 12032
x1, y1, x2, y2 = list(map(int, input().split()))

edge = [x2-x1, y2-y1]

if edge[0] >= 0  and edge[1] >= 0:
    x3, y3 = x2  - abs(edge[1]), y2 + abs(edge[0])
    x4, y4 = x3  - abs(edge[0]), y3 - abs(edge[1])
elif edge[0] >= 0 and edge[1] < 0:
    x3, y3 = x2  + abs(edge[1]), y2 + abs(edge[0])
    x4, y4 = x3  - abs(edge[0]), y3 + abs(edge[1])
elif edge[0] < 0 and edge[1] >=0:
    x3, y3 = x2  - abs(edge[1]), y2 - abs(edge[0])
    x4, y4 = x3  + abs(edge[0]), y3 - abs(edge[1])
else:
    x3, y3 = x2  + abs(edge[1]), y2 - abs(edge[0])
    x4, y4 = x3  + abs(edge[0]), y3 + abs(edge[1])
    
print(x3, y3, x4, y4)

Measured memory_bytes: 3064
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
ab = [lr() for i in range(n)]
ab.sort(key = lambda x:x[0]+x[1], reverse=True)
ans = 0
for i in range(n):
    if i%2 == 0:
        ans+=ab[i][0]
    else:
        ans-=ab[i][1]
print(ans)

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

int n;
double arr[300][2];

int main() {
	while(true) {
		scanf("%d",&n);
		if(n<=0) break;
		for(int i = 0; i < n; i++) {
			scanf("%lf%lf",&arr[i][0],&arr[i][1]);
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			double x1 = arr[i][0];
			double y1 = arr[i][1];
			for(int j = i+1; j < n; j++) {
				double x2 = arr[j][0];
				double y2 = arr[j][1];
				double dx = x2-x1;
				double dy = y2-y1;
				double dlen = dx*dx+dy*dy;
				if(dlen>=4.0) continue;
				double len = sqrt(1-dlen/4.0);
				double cx1 = (x1+x2)/2.0+dy/sqrt(dlen)*len;
				double cy1 = (y1+y2)/2.0-dx/sqrt(dlen)*len;
				double cx2 = (x1+x2)/2.0-dy/sqrt(dlen)*len;
				double cy2 = (y1+y2)/2.0+dx/sqrt(dlen)*len;
				int _ans1 = 0;
				int _ans2 = 0;
				for(int k = 0; k < n; k++) {
					double x3 = arr[k][0];
					double y3 = arr[k][1];
					if((cx1-x3)*(cx1-x3)+(cy1-y3)*(cy1-y3)<=1.0000001) _ans1++;
					if((cx2-x3)*(cx2-x3)+(cy2-y3)*(cy2-y3)<=1.0000001) _ans2++;
				}
				ans = fmax(ans,_ans1);
				ans = fmax(ans,_ans2);
			}
		}
		printf("%d\n",(ans==0)?1:ans);
	}
}



Measured memory_bytes: 2748
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
S=get_nsp
ans=0
1.upto(N-1) do|i|
  x=S[0..i-1]
  y=S[i..N-1]
  val=(x&y).size
  ans=val if ans<val
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
using ll=long long;


int main(){
    int N;
    cin>>N;
    ll len[N+1];
    for(int i=1;i<=N;i++){
        cin>>len[i];
    }
    ll sum=0;
    for(int i=1;i<=N-2;i++){
        for(int j=i+1;j<=N-1;j++){
            if(len[i]==len[j]){
                continue;
            }
            for(int k=j+1;k<=N;k++){
                if(len[i]==len[k]){
                    continue;
                }else if(len[j]==len[k]){
                    continue;
                }
                if(len[i]>len[k]){
                    if(len[i]>len[j]){
                        if(len[i]<len[j]+len[k]){sum++;}
                    }else{
                        if(len[j]<len[i]+len[k]){sum++;}
                    }
                }else{
                    if(len[k]>len[j]){
                        if(len[k]<len[j]+len[i]){sum++;}
                    }else{
                        if(len[j]<len[i]+len[k]){sum++;}
                    }
                }
                
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  int N,K; cin>>N>>K;
  set<int> S;
  rep(i,0,K){
    int M; cin>>M;
    rep(j,0,M){
      int X; cin>>X;
      S.insert(X);
    }
  }
  int ans=S.size();
  cout<<N-ans<<endl;
}

Measured memory_bytes: 3636
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int a,b,c,target,ans=0; 
    cin>>a>>b>>c>>target; 
    for (int i=0;i<=a;i++){
      for (int j=0;j<=b;j++){
        for (int k=0;k<=c;k++){
          if (i*500+j*100+k*50==target) ans++;
        }
      }
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3608
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
ans=0
a.each_cons(2).with_index(1) do |aa,i|
  #can't use aa
  if i!=n-1 && a[i-1]==i ||
     i==n-1 && (a[i-1]==i ||a[i]==i+1)
    a[i-1],a[i]=a[i],a[i-1]
    ans+=1
  end
end
puts ans


Measured memory_bytes: 10628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
#include <bits/stdc++.h>
using namespace std;
ll calc(ll n) 
{   
  
    switch(n & 3)
    { 
    case 0: return n;   
    case 1: return 1;   
    case 2: return n + 1;    
    case 3: return 0;    
    } 
} 

int main()
{
    ll a,b;
    cin>>a>>b;
    a = calc(a-1);
    b = calc(b)^a;
    cout<<b;	
//    cout<<x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 2e5+2;

int n;
ll k, a[MM], f[MM];

bool test(ll m){
    ll cnt = 0;
    for(int i = 0; i < n; i++){
        ll na = m/f[i];
        if(na < a[i])
            cnt += a[i]-na;
    }
    return cnt <= k;
}

int main(){
    
    scan(n, k);
    
    for(int i = 0; i < n; i++)
        scan(a[i]);
    sort(a, a+n);
    for(int i = 0; i < n; i++)
        scan(f[i]);
    sort(f, f+n, greater<int>());
    
    ll l = 0, m, r = 1e12+1;
    while(l <= r){
        m = (l+r)/2;
        if(test(m))
            r = m-1;
        else
            l = m+1;
    }
    
    print(l);
    
    return 0;
}

Measured memory_bytes: 3456
n=gets.to_i
ab= n.times.map { gets.split.map(&:to_i) }
ab_sort = ab.sort_by{|a,b| b}
ab_sum = []
n.times do |i|
  if i == 0
    sum = ab_sort[0][0]
    if sum > ab_sort[i][1]
      puts "No"
      exit 0
    else
      ab_sum << sum
    end
  else
    sum = ab_sum[i-1] + ab_sort[i][0]
    if sum > ab_sort[i][1]
      puts "No"
      exit 0
    else
      ab_sum << sum
    end
  end
end
puts "Yes"

Measured memory_bytes: 22520
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll a, b;
	scanf("%lld%lld", &a, &b);
	int r = 0;
	for (;;)
	{
		if (a <= b)r++, a *= 2;
		else break;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 128
#include<stdio.h>
int a[2];
int main()
{
    long long int i,j,k,m,n,l;
    while(scanf("%lld%lld",&m,&n)!=EOF)
    {
        for(i=0,k=0; i<m-1; i++)
        {
            if(i==0)scanf("%lld%lld",&a[0],&a[1]);
            if(i!=0)scanf("%lld",&a[1]);
            if(a[0]+a[1]<=n)a[0]=a[1];
            else
            {
                if(a[0]>n)
                    k=k+a[0]-n,a[0]=n;
                if(a[0]+a[1]<=n)
                    a[0]=a[1];
                else
                    k=k+a[0]+a[1]-n,a[0]=n-a[0];
            }
        }
        printf("%lld\n",k);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}



int main() {
	int n,k; cin >> n >> k;
	if(k==1) cout << 0 << endl;
	else cout << n - k << endl;


}

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

using namespace std;
#define REP(i, n) for(int i=0; i < (int)(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)

using ll = long long;

int main(){
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1){
        ans += 300000;
    }
    else if(X == 2){
        ans += 200000;
    }
    else if(X == 3){
        ans +=100000;
    }
    if(Y == 1){
        ans += 300000;
    }
    else if(Y == 2){
        ans += 200000;
    }
    else if(Y == 3){
        ans +=100000;
    }
    if(X == 1 && Y==1){
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000;
int cnt[3], b[3], c[3];
void get() {
    if( cnt[0] >= cnt[1] && cnt[1] >= cnt[2] )
        c[b[0] = 2] = 0, c[b[1] = 1] = 1, c[b[2] = 0] = 2;
    else if( cnt[0] >= cnt[2] && cnt[2] >= cnt[1] )
        c[b[0] = 2] = 0, c[b[2] = 1] = 2, c[b[1] = 0] = 1;
    else if( cnt[1] >= cnt[0] && cnt[0] >= cnt[2] )
        c[b[1] = 2] = 1, c[b[0] = 1] = 0, c[b[2] = 0] = 2;
    else if( cnt[1] >= cnt[2] && cnt[2] >= cnt[0] )
        c[b[1] = 2] = 1, c[b[2] = 1] = 2, c[b[0] = 0] = 0;
    else if( cnt[2] >= cnt[0] && cnt[0] >= cnt[1] )
        c[b[2] = 2] = 2, c[b[0] = 1] = 0, c[b[1] = 0] = 1;
    else if( cnt[2] >= cnt[1] && cnt[1] >= cnt[0] )
        c[b[2] = 2] = 2, c[b[1] = 1] = 1, c[b[0] = 0] = 0;
}
int lst[MAXN + 5], nxt[MAXN + 5];
int a[MAXN + 5], n;
void erase(int x) {
    lst[nxt[x]] = lst[x], nxt[lst[x]] = nxt[x];
    cnt[a[x]]--;
}
char s[MAXN + 5];
vector<int>v;
int main() {
    scanf("%s", s + 1), n = strlen(s + 1);
    for(int i=0;i<=n+1;i++)
        lst[i] = i - 1, nxt[i] = i + 1;
    a[0] = a[n + 1] = -1;
    for(int i=1;i<=n;i++) {
        cnt[a[i] = s[i] - 'A']++;
        if( a[i] == a[i-1] ) erase(i);
    }
    get();
    for(int i=nxt[0];i!=n+1;i=nxt[i])
        if( a[i] == c[2] && a[lst[i]] != a[nxt[i]] )
            v.push_back(i);
    for(int i=0;i<v.size()&&cnt[c[2]]!=cnt[c[1]];i++)
        erase(v[i]);
    v.clear();
    for(int i=nxt[0];i!=n+1;i=nxt[i])
        if( a[i] == c[2] && a[lst[i]] == c[0] && a[nxt[i]] == c[0] )
            v.push_back(i);
    for(int i=0;i<v.size()&&cnt[c[2]]!=cnt[c[1]];i++)
        erase(v[i]), erase(nxt[v[i]]);
    v.clear();
    for(int i=nxt[0];i!=n+1;i=nxt[i])
        if( a[i] == c[2] && a[nxt[i]] == c[1] )
            v.push_back(i);
    for(int i=0;i<v.size()&&cnt[c[0]]!=cnt[c[1]];i++)
        if( a[lst[v[i]]] != c[0] || a[nxt[nxt[v[i]]]] != c[0] )
            erase(v[i]), erase(nxt[v[i]]);
    v.clear();
    for(int i=nxt[0];i!=n+1;i=nxt[i])
        if( a[i] == c[2] && a[lst[i]] == c[1] )
            v.push_back(i);
    for(int i=0;i<v.size()&&cnt[c[0]]!=cnt[c[1]];i++)
        if( a[nxt[v[i]]] != c[0] || a[lst[lst[v[i]]]] != c[0] )
            erase(v[i]), erase(lst[v[i]]);
    v.clear();
    if( cnt[0] == cnt[1] && cnt[0] == cnt[2] ) {
        for(int i=nxt[0];i!=n+1;i=nxt[i])
            putchar(a[i] + 'A');
    }
}

Measured memory_bytes: 15344
// Candies - Educational DP Contest [Cloned] - M
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e2 + 5;
const int K = 1e5 + 5;

int n, k;
int a[N];
int dp[N][K];

int add(int x, int y) {
    int ret = x + y;
    return ret >= MOD ? ret % MOD : ret;
}

int sub(int x, int y) {
    int ret = x - y;
    return ret < 0 ? ret + MOD : ret;
}

void computeDP() {
    dp[0][0] = 1;
    for(int idx = 1; idx <= n; idx++) {
        for(int candy = 0; candy <= k; candy++) {
            int &sol = dp[idx][candy];
            sol = add(dp[idx][candy - 1], dp[idx - 1][candy]);
            sol = sub(sol, (candy - a[idx] - 1 >= 0 ? dp[idx - 1][candy - a[idx] - 1] : 0));
        }
    }
}

void solve() {
    int T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    for(int tc = 1; tc <= T; tc++) {
        cin >> n >> k;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        computeDP();
        cout << dp[n][k] << "\n";
    }
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}
// for(int i = 0; i <= a[idx]; i++) {
//     if(candy - i >= 0)
//         sol = add(sol, dp[idx - 1][candy - i]);
// }

Measured memory_bytes: 42464
N, A, B = input().split()
A = int(A)
B = int(B)
k_sum = 0
ans = 0
for j in range(1, int(N)+1):
  j = str(j)
  k_sum = 0
  for i in range(len(j)):
  	k_sum += int(j[i])
  if k_sum >= A and k_sum <= B:
    ans += int(j)
print(ans)

Measured memory_bytes: 3064
#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
typedef long long ll;
typedef pair<int,int> pint;

double PI=acos(-1.0);
double a,b,x;
int main(){
    cin>>a>>b>>x;
    double ans;
    if(a*a*b<x*2){
        double y=x*2/a/a-b;
        ans=atan((b-y)/a);
    }
    else{
        double y=x*2/a/b;
        ans=atan(b/y);
    }
    cout<<setprecision(10)<<fixed<<ans/PI*180<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
	
	int N,i;
	int most=0;
	int V[20],C[20],le[20];

	scanf("%d",&N);
	
	for(i=0;i<N;i++)
		scanf("%d",&V[i]);
	for(i=0;i<N;i++)
		scanf("%d",&C[i]);
	
	for(i=0;i<N;i++)
	le[i]=V[i]-C[i];
	
	for(i=0;i<N;i++)
		if(le[i]>0)
			most+=le[i];
	
	printf("%d",most);
	return 0;
}

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x) cout << #x << " = " << (x) << endl
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

ll digsum(ll n, ll k) {
    ll res = 0;
    while(n > 0) {
        // 各桁の和 (k進数)
        // res += n%k;
        // 桁数 (k進数)
        res++;
        n /= k;
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        if(digsum(i, 10) % 2 != 0) {
            ans++;
        }
    }

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

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
static const int MAX=200000;

int main(){
int n;
cin>>n;
vector<int> vec(n);
for (int i = 0; i < n; i++) {
  cin >> vec.at(i);
}
for(int j=0;j<n;j++) cout << vec[j] << (j==n-1?'\n':' ');
for(int i=1;i<n;i++){
    int v;
    v=vec[i];
    int j;
    j=i-1;
    while(j>=0&&vec[j]>v){
        vec[j+1]=vec[j];
        j--;
    }
    vec[j+1]=v;
    for(j=0;j<n;j++) cout << vec[j] << (j==n-1?'\n':' ');
}

return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する


int main(){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
	int N;
	cin>>N;
	vint ans(N);
	rep(i,N){
		int a;cin>>a;
		ans[a-1]=i;
	}
	rep(i,N){
		if(i)cout<<" ";
		cout<<ans[i]+1;
	}cout<<endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    bool flag = true;
    REP(i, N) if(A[i] != B[i]) flag = false;
    if(flag){
    	cout << 0 << endl;
    	return 0;
    }

    ll sum = 0;
    REP(i, N) sum += A[i];

    ll mi = (1ll << 60);
    REP(i, N) if(A[i]>B[i]) mi = min(mi, B[i]);

    cout << sum - mi << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    if (D1 > D2)
        cout << 1 << endl;
    else
        cout << 0 << 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;
using P = pair<int,int>;

int main() {
  string a, b;
  cin >> a >> b;
  if (a.size() > b.size()) cout << "GREATER" << endl;
  else if (a.size() < b.size()) cout << "LESS" << endl;
  else {
    bool finished = false;
    rep(i, a.size()) {
      if (a[i] > b[i]) {
        cout << "GREATER" << endl;
        finished = true;
        break;
      } else if (a[i] < b[i]) {
        cout << "LESS" << endl;
        finished = true;
        break;
      }
    }
    if (!finished) cout << "EQUAL" << endl; 
  }
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="SUN")cout<<"7"<<endl;
    if(s=="MON")cout<<"6"<<endl;
    if(s=="TUE")cout<<"5"<<endl;
    if(s=="WED")cout<<"4"<<endl;
    if(s=="THU")cout<<"3"<<endl;
    if(s=="FRI")cout<<"2"<<endl;
    if(s=="SAT")cout<<"1"<<endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

import java.io.*;
import java.math.BigInteger;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] ad;
	static ArrayList<Long>[] pre, suf;
	static int n, m;
	static long[] par, ans;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		ad = new ArrayList[n];
		pre = new ArrayList[n];
		suf = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			ad[i] = new ArrayList<>();
			pre[i] = new ArrayList<>();
			suf[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			ad[a].add(b);
			ad[b].add(a);
		}
		par = new long[n];
		ans = new long[n];
		idc=new int [n];
		dfs(0, -1);
		up(0, -1);
		for (int i = 0; i < n; i++)
			out.println(ans[i] * par[i] % m);
		out.flush();
	}

	static void dfs(int u, int p) {
		par[u] = 1;
		for (int v : ad[u])
			if (v != p) {
				dfs(v, u);
				par[u] = par[u] * (par[v] + 1)%m;
				idc[v]=pre[u].size();
				pre[u].add(par[v] + 1);
				suf[u].add(par[v] + 1);
			}
		for (int i = 1; i < pre[u].size(); i++)
			pre[u].set(i, pre[u].get(i) * pre[u].get(i - 1) % m);
		for (int i = suf[u].size() - 2; i >= 0; i--)
			suf[u].set(i, suf[u].get(i) * suf[u].get(i + 1) % m);
	}
static int []idc;
	static void up(int u, int p) {
		if (p != -1) {	
			ans[u]=ans[p];
			if(idc[u]!=0)
				ans[u]=ans[u]*pre[p].get(idc[u]-1)%m;
			if(idc[u]!=pre[p].size()-1)
				ans[u]=ans[u]*suf[p].get(idc[u]+1)%m;
		}
		ans[u]++;
		for (int v : ad[u])
			if (v != p)
				up(v, u);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 129748
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

x = [0]*5
for i in range(5):
    x[i] = I()
k = I()

ans = 'Yay!'
for i in range(5):
    for j in range(i+1,5):
        if abs(x[i]-x[j])>k:
            ans = ':('

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vvint ct(n,vint(26,0));
    rep(i,n) {
        string s; cin >> s;
        rep(j,s.size()) ct[i][s[j]-'a']++;
    }
    vint tmp(26);
    rep(i,26) {
        int count = inf;
        rep(j,n) count = min(count,ct[j][i]);
        tmp[i] = count;
    }
    rep(i,26) {
        rep(j,tmp[i]) cout << char(i+'a');
    }
    cout << endl;
}

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

int main(void) {
  int N;
  cin >> N;

  bool ans = false;
  for (int i = 0; i <= N / 4; i++) {
    for (int j = 0; j <= N / 7; j++) {
      if (4 * i + 7 * j == N) {
        ans = true;
      }
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll N = 30 + 3;

ll n, m, k, x, cnt[N], r;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for (ll i = 1; i <= n; ++i) {
		cin >> k;
		while (k--) {
			cin >> x;
			++cnt[x];
		}
	}
	
	for (ll i = 1; i <= m; ++i) {
		if (cnt[i] == n) ++r;
	}
	cout << r;
	
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    
    else if (i == N - 1) {
      cout << "Three" << endl;
    }
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

ll T[100010];
int main()
{
	int N;
	ll C, K;
	cin >> N >> C >> K;
	for (int i = 0; i < N; i++) cin >> T[i];
	sort(T, T + N);
	ll ans = 0, count = 0, limit = 0;
	int i = 0;
	while (i < N) {
		count = 0;
		limit = T[i] + K;
		while (count < C && T[i] <= limit && i < N) {
			count++;
			i++;
		}
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024