akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  int p[n];
  for(int i=0; i<n; ++i) cin >> p[i];
  
  int count = 0;
  for(int i=0; i<n; ++i){
    if(p[i] != (i+1)){
      ++ count;
    }
  }
  if(count == 0 || count == 2){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
     mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
 init();
 ll h,w,a,b;
 cin>>h>>w>>a>>b;
 mint ans=0;
 for(int i=0;i<h-a;i++){
   ans+=COM(i+b-1,i)*COM(h-i-1+w-b-1,h-1-i);
 }
 cout<<ans<<"\n";
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

//Ｏ(E*V^2)
//最大流アルゴリズム

struct edge{int to,cap,rev;};

const int MAX_V=110;
vector<edge>G[MAX_V];
int level[MAX_V];      //sからの距離
int iter[MAX_V];       //どこまで調べ終わったか

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

//sからの最短距離をＢＦＳで計算する。
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        que.push(e.to);
      }
    }
  }
}

//増加パスをＤＦＳで探す。
int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

//sからtへの最大流を求める。
int max_flow(int s,int t){
  int flow=0;
  while(true){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}


signed main(){
  int V,E;cin>>V>>E;
  for(int i=0;i<E;i++){
    int a,b,c;cin>>a>>b>>c;
    add_edge(a,b,c);
  }

  cout<<max_flow(0,V-1)<<endl;
  return 0;
}



Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <cstdlib>
#include <climits>

using namespace std;

int n;
const int MAX = 15;
const int SMAX = 1 << MAX;

typedef struct KURA
{
	int id, dist, num;
} KURA;

KURA K[MAX];
double cost[SMAX][MAX];
pair<int, int> p[SMAX][MAX];
int w[SMAX];

double get_cost(int i, int j, int s)
{
	return abs(K[i].dist - K[j].dist) / (2000.0 / (70.0+w[s]));
}

void solve()
{
	int smax = 1 << n;

	for(int s=1; s<smax; s++)
	{
		int sum = 0;
		for(int i=0; i<n; i++)
		{
			if(s&(1<<i))
				sum += K[i].num * 20;
		}
		w[s] = sum;
	}

	for(int i=0; i<smax; i++)
	{
		for(int j=0; j<n; j++)
		{
			cost[i][j] = INT_MAX;
			p[i][j] = make_pair(-1, -1);
		}
	}

	for(int i=0; i<n; i++)
	{
		cost[1<<i][i] = 0;
	}

	for(int s=0; s<smax; s++)
	{
		for(int i=0; i<n; i++)
		{
			if(!((1<<i) & s)) continue;

			for(int j=0; j<n; j++)
			{
				if((1<<j) & s) continue;

				//i is visited, j is not visited.
				double new_cost = cost[s][i] + get_cost(i, j, s);

				if(cost[s | (1<<j)][j] > new_cost)
				{
					cost[s | (1<<j)][j] = new_cost;
					p[s | (1<<j)][j] = make_pair(s, i);
				}

			}
		}
	}

	int end = 0;
	for(int i=0; i<n; i++)
	{
		if(cost[smax-1][i] < cost[smax-1][end])
		{
			end = i;
		}
	}

	pair<int, int> pre = make_pair(smax-1, end);
	int path[MAX];
	for(int i=0; pre.first!=-1; pre = p[pre.first][pre.second], i++)
	{
		path[i] = K[pre.second].id;
	}

	for(int i=0; i<n; i++)
	{
		if(i) cout << " ";
		cout <<  path[n-i-1];
	}
	cout << endl;
}

int main(int argc, char** argv)
{
	cin >> n;

	for(int i=0; i<n; i++)
	{
		cin >> K[i].id >> K[i].dist >> K[i].num;
	}

	solve();
}

Measured memory_bytes: 8636
using System;

namespace ALDS1
{
    class Program
    {
        static void Main()
        {
            int l = int.Parse(Console.ReadLine()) - 1;
            int min = int.Parse(Console.ReadLine());
            int max = -999999999;
            for (int i = 0; i < l; i++)
            {
                int a = int.Parse(Console.ReadLine());
                int b = a - min;
                if (b > max) max = b;
                if (a < min) min = a;
            }
            Console.WriteLine(max);
        }
    }
}

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

int vec[100110];
int dp[100110];

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  dp[1]=abs(vec[1]-vec[0]);
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
      if(i>=j){
        if(j==1){
          dp[i]=dp[i-j]+abs(vec[i]-vec[i-j]);
        }
        dp[i]=min(dp[i-j]+abs(vec[i]-vec[i-j]),dp[i]);
      }
    }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int x = Integer.parseInt(str[0]);
    int y = Integer.parseInt(str[1]);
    System.out.println(x+y/2);
  }
}

Measured memory_bytes: 21076
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt();

    if (possible(N, A)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  private static boolean possible(int N, int[] A) {
    long sum = 0;
    for (int i = 0; i < N; i++) sum += A[i];
    long NS = (long) N * (N + 1) / 2;
    if (sum % NS != 0) return false;
    long K = sum / NS;
    for (int i = 0; i < N; i++) {
      int j = i == 0 ? N - 1 : i - 1;
      long d = K - (A[i] - A[j]);
      if (d < 0 || d % N != 0) return false;
    }
    return true;
  }
}


Measured memory_bytes: 50080
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
 
int main() {

int X,Y;
cin>>X>>Y;


if(Y-2*X>=0 && Y-2*X<=2*X && (Y-2*X)%2==0){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}


}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int T1 = H1 * 60 + M1;
	int T2 = H2 * 60 + M2;

	int ans = (T2 - T1) - K;
	cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      b--;
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
inline int inv(int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (i == 1 && j == 1) {
        char c;
        cin >> c;
        dp[1][1] = 1;
        continue;
      }
      char c;
      cin >> c;
      if (c == '.') {
        dp[i][j] = dp[i - 1][j];
        add(dp[i][j], dp[i][j - 1]);
      }
    }
  }
  cout << dp[h][w] << '\n';
  return 0;
}

Measured memory_bytes: 4224
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 23 15:58:40 2018

@author: masato
"""
a = list(map(int, input().split()))
b = sorted(a)

cnt = 0
c = 0
for i in range(len(b)-1):
    c = abs(b[i]- b[i + 1])
    cnt += c
print(cnt)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define sortv(a) sort(a.begin(),a.end())
#define sorta(a,n) sort(a,a+n);
#define double long double
#define db double
int x[10],y[10];

double co[10][10];

double f(int a){
	double ret=1;
	for(int i=1;i<=a;i++)
		ret*=i;
	return ret;
}

int32_t main(){
	// freopen("i.gir","r",stdin);
	// freopen("o.out","w",stdout);
	int32_t n;
	cin>>n;
	int arr[10];
	for(int i=0;i<n;i++){
		arr[i]=i;
		cin>>x[i]>>y[i];
	}
	double ans=0;
	for(int32_t i=0;i<n;i++){
		for(int32_t j=0;j<n;j++){
			co[i][j]=sqrt((db)(x[i]-x[j])*(db)(x[i]-x[j])+(db)(y[i]-y[j])*(db)(y[i]-y[j]));
		}
	}
	do{
		double temp=0;
		for(int32_t i=0;i<n-1;i++){
			temp+=co[arr[i]][arr[i+1]];
		}
		ans+=temp;
	}while(next_permutation(arr,arr+n));
	cout<<setprecision(18)<<ans/f(n);
}

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

int main(){
  ll a,b,c,k;
  std::cin >> a>>b>>c>>k;
  if(a>=k)std::cout << k << '\n';
  else{
    if(k-a<=b)std::cout << a << '\n';
    else std::cout << a-1*(k-a-b) << '\n';
  }
  return 0;
}


Measured memory_bytes: 3488
#include <stdio.h>

int main(void){
	int i , n , a1 , a2;
	while(scanf("%d" , &n)!=EOF){
		a1 = 2;
		if(n==1){
			printf("%d\n" , a1);
			continue;
		}
		for(i=2;i<=n;i++){
			a2 = a1 + i;
			a1 = a2;
		}
		printf("%d\n" , a2);
	}
	return 0;
}

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

int main() {
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    int n = A * X + B * Y;
    int a = X * 2 * C + abs(X - Y) * B;
    int b = Y * 2 * C + abs(X - Y) * A;
    int all = max(X, Y) * C * 2;
    cout << min({n, a, b, all}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const int N = 5e5 + 10;
const int mod = 1e9 + 7;

ll fac[N];

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = fac[i - 1] * i % mod;
}

ll inv(ll a) {
	return binpow(a, mod - 2);
}

ll A(ll n, ll m) {
	return fac[n] * inv(fac[n - m]) % mod;
}

ll C(ll n, ll m) {
    return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = 0;
    init();
    ans = modpow(2,n,mod);
    ll m1 = 1;
    for(ll i = n-a+1;i<=n;i++){
        m1 *= i;
        m1 %= mod;
    }
    ll m2 = 1;
    for(ll i = n-b+1;i<=n;i++){
        m2 *= i;
        m2 %= mod;
    }
    //cout << m1 << ' '<< m2<<endl;
    ll m = (m1*inv(fac[a])+m2*inv(fac[b])+1)%mod;
    ans = (ans - m + mod)%mod;
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

using namespace std;

typedef long long int lli;
typedef vector<lli> vi;
#define v vector

int main() {
    v<v<v<vi>>> dp(101, v<v<vi>>(4, v<vi>(4, vi(4, 0))));

    int n;
    lli mod = 1000000007;
    cin >> n;

    // A:0 C:1 G:2 T:3
    dp[0][3][3][3] = 1;
    for (int N=0; N<n; N++) {
        for (int i3=0; i3<=3; i3++) {
            for (int i2=0; i2<=3; i2++) {
                for (int i1=0; i1<=3; i1++) {
                    for (int i=0; i<=3; i++) {
                        if (dp[N][i3][i2][i1] == 0) continue;
                        if (i2 == 0 && i1 == 2 && i == 1) continue; // *AGC
                        if (i2 == 2 && i1 == 0 && i == 1) continue; // *GAC
                        if (i2 == 0 && i1 == 1 && i == 2) continue; // *ACG
                        if (i3 == 0 && i2 == 2 && i == 1) continue; // AG*C
                        if (i3 == 0 && i1 == 2 && i == 1) continue; // A*GC
                        
                        dp[N+1][i2][i1][i] += dp[N][i3][i2][i1];
                        dp[N+1][i2][i1][i] %= mod;
                    }
                }
            }
        }
    }

    lli ans = 0;
    for (int i3=0; i3<=3; i3++) {
        for (int i2=0; i2<=3; i2++) {
            for (int i1=0; i1<=3; i1++) {
                ans += dp[n][i3][i2][i1];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const long double eps=1e-9;
const int maxn=3e5+10;
int A[maxn];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int main(){
	int i,j,k,m,n,a,b;
	n=read();a=read();b=read();
	if(a+b>n+1 || 1ll*a*b<1ll*n)return puts("-1"),0;
	for(i=1;i<=b;i++)A[i]=b-i+1;
	if(a==1){
		for(i=1;i<=n;i++)printf("%d%c",A[i],i==n?'\n':' ');
		return 0;
	}
	int val=(n-b)/(a-1),res=(n-b)%(a-1),cur=b,pos=b;
	for(i=1;i<=res;i++){
		cur+=val+1;
		for(j=1;j<=val+1;j++)
			A[++pos]=cur,cur--;
		cur+=val+1;
	}
	for(i=1;i<=a-1-res;i++){
		cur+=val;
		for(j=1;j<=val;j++)
			A[++pos]=cur,cur--;
		cur+=val;
	}
	for(i=1;i<=n;i++)printf("%d%c",A[i],i==n?'\n':' ');
	return 0;
}


Measured memory_bytes: 3328
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<int, int>;
using VP = pair<int, pair<int, int> > ;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;

const int maxE = 200001;
int parent[maxE];
int parent_rank[maxE];


void init(int max_element) {
	for (int i = 0; i < max_element; i++) {
		parent[i] = i;
		parent_rank[i] = 0; 
	}
}

int find(int x) {
	if (x == parent[x]) return x;
	
	parent[x] = find(parent[x]);
	return parent[x];
}

bool same(int x, int y) {
	return find(x) == find(y);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (parent_rank[x] > parent_rank[y]) {
		parent[y] = x;
		return;
	}
	parent[x] = y;
	if (parent_rank[x] == parent_rank[y]) {
		parent_rank[y]++;
	}
}


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

	init(n);

	rep(i, m) {
		int a,b;
		cin >> a >> b;
		unite(a,b);
	}

	vector<int> g(n, 0);

	rep(i,n) {
		g[find(i)] ++;
	}
	int max_v = 0;
	rep(i, n) {
		max_v = max(g[i], max_v);
	}

	cout << max_v << endl;

	return 0;
}


Measured memory_bytes: 5140
#include <stdio.h>
#include <math.h>


int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    int i, x[n];
    for(i = 0 ; i < n ; i++){
        x[i] = 10;
    }
    int xxx, s, c;
    xxx = 1;
    for(i = 0 ; i < m ; i++){
        scanf("%d %d", &s, &c);
        if(x[s-1] != 10 && x[s-1] != c){
            xxx = 0;
        }
        else{
            x[s-1] = c;
        }
    }
    if(n != 1 && x[0] == 0){
        xxx = 0;
    }
    if(n == 1 && x[0] == 10){
        printf("0\n");
        return 0;
    }
    if(xxx == 1){
        if(x[0] == 10){
            x[0] = 1;
        }
        for(i = 1 ; i < n ; i++){
            if(x[i] == 10){
                x[i] = 0;
            }
        }
        double aaa = 0.0;
        for(i = 0 ; i < n ; i++){
            aaa += (double)x[i] * pow(10, n - i - 1);
        }
        int xx = (int)aaa;
        printf("%d\n", xx);
    }
    else{
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main() {
	int a, b, c, d; std::cin >> a >> b >> c >> d;
    std::cout << c - (d - b) << " " <<  d + (c - a) << " " << a - (d - b) << " " << b + (c - a) << std::endl;

	return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 10002
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> pr_int;


int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x;
	cin >> x;
	int n = x/500;
	int y = x-n*500;
	cout << n*1000+y/5*5;
	
	cout << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};


int main() {
    int N; cin>>N;
    cout<<(N-1)/2+1<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

int main() {
  ll a, b, k;
  cin>>a>>b>>k;
  if (a-k>=0){
    cout<<a-k<<" "<<b;
  }else if(b-k+a >= 0){
    cout<<0<<" "<<b-k+a;
  }else cout<<"0"<<" "<<"0";

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	int n, r;
	cin >> n >> r;
	if (n >= 10)cout << r << endl;
	else cout << r + (10-n)*100  << endl;

	return 0;
}

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

int main() {
    int ans = 100000;
    string s,t;
    cin >> s >> t;
    for(int i = 0;i < (s.size() - t.size() + 1);i++){
        int tmp = 0;
        for(int j = 0;j < t.size();j++){
            if(s.at(j + i) != t.at(j)){
                tmp++;
            }
        }
        if(tmp < ans)ans = tmp;
    }

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 n;
vector<i64> h;



int main() {
  cin >> n;
  h.resize(n + 1);
  rep(i,1,n) cin >> h[i];
  vector<vector<double>> dp(n + 1, vector<double>(400, 1e18));

  dp[0][1] = 0;

  rep(i,1,n) {
    rep(a, 1, 300) {
      if(dp[i - 1][a] == 1e18) continue;
      rep(b, 1, 300) {
        double s = 1e18;
        if(a == h[i]) s = abs(b - h[i]) * 1 / 2.0; 
        else if(b == h[i]) s = abs(a - h[i]) * 1 / 2.0;
        else if(a < h[i] && b < h[i]) s = (h[i] - (a + b) / 2.0);
        else if(a > h[i] && b > h[i]) s = (a + b) / 2.0 - h[i];
        else if(a < h[i] && h[i] < b) {
          double x = h[i] - a;
          double y = b - h[i];
          s = x * x / (x + y) + y * y / (x + y);
          s /= 2;
        }
        else {
          double x = a - h[i];
          double y = h[i] - b;
          s = x * x / (x + y) + y * y / (x + y);
          s /= 2;
        }
        dp[i][b] = min(dp[i][b], dp[i - 1][a] + s);
      }
    }
  }

  cout << fixed << setprecision(9) << *min_element(all(dp[n])) << endl;
}



Measured memory_bytes: 3396
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int h1, h2, k1, k2;
    int a, b, c, d;
    int hiro = 0, ken = 0;

    cin >> h1 >> h2 >> k1 >> k2;
    cin >> a >> b >> c >> d;

    hiro = h1 * a + h1 / 10 * c + h2 * b + h2 / 20 * d;
    ken = k1 * a + k1 / 10 * c + k2 * b + k2 / 20 * d;

    OUT(hiro > ken ? "hiroshi" : hiro == ken ? "even" : "kenjiro");

    return 0;
}




Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    set<char> a;
    char c;
    rep(i,3)cin>>c,a.insert(c);
    if(a.size()==3) yn;

    return 0;
}


Measured memory_bytes: 256
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    S = input()
    K = ii()
    for i in range(min(len(S), K)):
        if S[i] != '1':
            print(S[i])
            return
    print(1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61504
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;


int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> v(10, vector<int>(10, 0));
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> v[i][j];
        }
    }
    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
            }
        }
    }
    vector<int> cost(10);
    for (int i = 0; i < 10; ++i) {
        cost[i] = v[i][1];
    }
    ll ans = 0;
    for (int i = 0; i < h*w; ++i) {
        int x;
        scanf("%d", &x);
        if(x != -1) ans += cost[x];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string disp(bool x){
    return x ? "Yes" : "No";
}

int yakusu(int x){
    int cnt = 0;
    rep1(i,x){
        if(x%i == 0) cnt++;
    }
    return cnt;
}
int main(){
    int n;
    cin >> n;
    
    int ans = 0;
    for(int i=1;i<=n;i+=2){
        if(yakusu(i) == 8) ans++;
    }
    
    cout << ans << endl;
}
    
    






Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
    int N;
    cin >> N;
    ll A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    /* しゃくとり法 */
    ll res = 0;
    int right = 0;
    int sum = 0;
    for (int left = 0; left < N; left++) {
        while (right < N && (sum ^ A[right]) == (sum + A[right])) {
            sum += A[right];
            right++;
        }
        res += right - left;
        if (left == right) right++;
        else sum -= A[left];
    }
    cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int x[20][20], y[20][20],a[20];
int main() {
	int n;
	cin >> n;
	rep(i,n) {
		cin >> a[i];
		rep(j,a[i]) {
			cin >> x[i][j] >> y[i][j];
			x[i][j]--;
		}
	}

	int ans = 0;
	rep(bit, (1<<n)) {
		bool ok = true;
		rep(i,n) {
			if (!((bit >> i) & 1)) continue;
			rep(j,a[i]) {
				if (((bit>>x[i][j]) & 1) ^ y[i][j]) ok = false;
			}
		}
		if (ok) ans = max(ans, __builtin_popcount(bit));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
N, M = list(map(int, input().split()))
V = 10 ** 9 + 7
a = [int(input()) for _ in range(M)]
A = set(a)
ANS = [0 for _ in range(N + 5)]

ANS[0] = 1
for i in range(N):
    #ANS[i] %= V
    #if not i + 1 in A:
    if i in A:
        continue
    ANS[i + 1] += ANS[i]
    #ANS[i + 1] %= V
    ANS[i + 2] += ANS[i]
    #ANS[i + 2] %= V
print(ANS[N] % V)


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

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

    int res = 0;
    int array[n];

    for (int i = 0; i < n; i++)
    {
        res += l;
        array[i] = abs(l);
        l++;
    }
    sort(array, array+n);

    if(res>=0){
        cout << res - array[0] << endl;
    }
    else
    {
        cout << res + array[0] << endl;
    }
}

Measured memory_bytes: 256
S = input()
f = ""
N = int(input())
direct = 0
for i in range(N):
  X = input().split()
  if len(X) == 1:
    direct = 1 - direct
  else:
    if (X[1] == "1" and direct == 0) or (X[1] == "2" and direct == 1):
      f += X[2]
    else:
      S += X[2]
print(f[::-1]+S) if direct == 0 else print(S[::-1]+f)


Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())

int main()
{
    int n; cin >> n;
    bool flg = false;
    for (int cake = 0; cake < n; cake++) {
        for (int donut = 0; donut < n; donut++) {
            if(n == cake*4 + donut*7) flg = true;
        }
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;

}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4

output:
1
0
1
1
"""

import sys

sys.setrecursionlimit(int(1e5))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
    return init_adj_table


def Tarjan(current, low, dfn, scc_stack, in_scc_stack):
    global timer
    dfn[current] = low[current] = timer
    timer += 1

    scc_stack.append(current)
    in_scc_stack[current] = True

    current_scc_set = set()
    for adj in adj_table[current]:
        # adj unvisited
        if dfn[adj] == -1:
            Tarjan(adj, low, dfn, scc_stack, in_scc_stack)
            low[current] = min(low[current], low[adj])
        # current -> adj: by back-edge or cross-edge
        elif in_scc_stack[adj]:
            low[current] = min(low[current], dfn[adj])

    scc_candidate = -1
    if dfn[current] == low[current]:
        while scc_candidate != current:
            scc_candidate = scc_stack.pop()
            in_scc_stack[scc_candidate] = False
            current_scc_set.add(scc_candidate)

        init_scc_sets_list.append(current_scc_set)

    return None


def scc_cluster():
    dfn = [-1] * vertices
    low = [-1] * vertices
    scc_stack = list()
    in_scc_stack = [False] * vertices

    for v in range(vertices):
        if dfn[v] == -1:
            Tarjan(v, low, dfn, scc_stack, in_scc_stack)

    return init_scc_sets_list


def solve(_scc_sets_list):
    for question in q_list:
        flag = False
        ele1, ele2 = map(int, question)
        for each in _scc_sets_list:
            if (ele1 in each) and (ele2 in each):
                flag = True
                break
        if flag:
            print('1')
        else:
            print('0')

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:edges + 1])
    q_num = int(_input[edges + 1])
    q_list = map(lambda x: x.split(), _input[edges + 2:])

    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    init_scc_sets_list = []
    scc_sets_list = scc_cluster()

    solve(scc_sets_list)

Measured memory_bytes: 26504
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;


int main(){
    long long int a,b,c;
    cin >> a >> b >> c;

    if(c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b)){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    

    return 0;
}

Measured memory_bytes: 256
#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 q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int k;
    cin >> k;
    int tv = n;
    int fv = -1;
    while (tv - fv > 1){
      int mv = (tv + fv) / 2;
      if (a[mv] >= k){
        tv = mv;
      } else {
        fv = mv;
      }
    }
    cout << tv << endl;
  }
}


Measured memory_bytes: 3108
B = [0] * 8
n = int(input())
A = list(map(int, input().split()))
t = 0
for i in A:
    if i < 3200:
        a = i//400
        B[a] += 1
    else:
        t += 1

c = 0
for i in B:
    if i!= 0:
        c += 1

print(max(c, 1),c+t)

Measured memory_bytes: 38256
import sys
N = int(input())
array_list = []
for I in range(N):
    array_list.append(list(map(int,input().split())))

if N < 1 or N > 1000:
    sys.exit()

number = 0
for J in array_list:
    number += (J[1] - J[0] + 1)

print(number)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<vector<int>> sushi(N);
    rep(i, N) {
        int t, d;
        cin >> t >> d;
        t--;
        sushi[t].push_back(d); // おいしさを種類ごとにまとめる
    }

    vector<int> y0, y1; // y0:種類ごとでおいしさが２番目以降のもの、y1:種類ごとでおいしさが１番のもの
    rep(i, N) { // i:寿司の種類
        if (sushi[i].size() == 0) continue;
        sort(sushi[i].begin(), sushi[i].end());
        y1.push_back(sushi[i].back()); // 種類の中で最大のおいしさのもの
        sushi[i].pop_back();
        y0.insert(y0.end(), sushi[i].begin(), sushi[i].end()); // 種類の中で２番目以降のおいしさのものをy0にいれる
    }

    sort(y0.rbegin(), y0.rend());
    sort(y1.rbegin(), y1.rend());

    ll ans = 0;
    // 取り出す種類数を試す
    ll Y = max(0LL, K - (ll) (y0.size())); // 取り出す種類数の初期値
    ll X = 0; // おいしさの総和
    rep(i, Y) X += y1[i];
    rep(i, K - Y) X += y0[i];
    while (1) {
        chmax(ans, X + Y * Y);
        if (Y >= K || Y >= y1.size()) break;
        X += y1[Y];
        X -= y0[K - Y - 1];
        ++Y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

int main (void) {
	int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d) cout << "Left" << endl;
  if(a+b==c+d) cout << "Balanced" << endl;
  if(a+b<c+d) cout << "Right" << endl;
	return 0;
}

Measured memory_bytes: 764
N, K = map(int, input().split())

if N % K == 0:
    print(0)

else:
    while True:
        if N // K == 0:
            # print('N % K = ' + str(N % K) + ', abs(N - K) = ' + str(abs(N - K)))
            print(N % K) if N % K < abs(N - K) else print(abs(N - K))
            break;

        else:
            # print('N % K = ' + str(N % K) + ', abs(N - K) = ' + str(abs(N - K)))
            N = abs(N - K * (N//K))


Measured memory_bytes: 38256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        boolean a[] = new boolean[n + 1];
        boolean b[] = new boolean[n + 1];
        boolean c[] = new boolean[n + 1];

        int x = scan.nextInt();
        for (int i = 0; i < x; ++i) {
            int user = scan.nextInt();
            a[user] = true;
        }

        int y = scan.nextInt();
        for (int i = 0; i < y; ++i) {
            int user = scan.nextInt();
            b[user] = true;
        }

        int z = scan.nextInt();
        for (int i = 0; i < z; ++i) {
            int user = scan.nextInt();
            c[user] = true;
        }

        int answer = 0;

        for (int user = 1; user <= n; user++) {
            if (!a[user] && c[user] || b[user] && c[user]) {
                answer++;
            }
        }

        System.out.println(answer);
    }

}



Measured memory_bytes: 26748
import sys
input = sys.stdin.readline

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(a[K-1])

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] t = sc.IntArray();
        int[] m = sc.IntArray();
        int[] b = sc.IntArray();

        t = t.OrderBy(i => i).ToArray();
        m = m.OrderBy(i => i).ToArray();
        b = b.OrderBy(i => i).ToArray();

        long answer = 0;

        for (int i = 0; i < n; i++)
        {
            long tCount = 0;
            {
                int ok = -1; // 解が存在する値
                int ng = n; // 解が存在しない値
                while (Math.Abs(ok - ng) > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (t[mid] < m[i]) // midのチェック 
                    {
                        ok = mid;
                    }
                    else
                    {
                        ng = mid;
                    }
                }
                tCount = ok + 1;
            }

            long bCount = 0;
            {
                int ok = n; // 解が存在する値
                int ng = -1; // 解が存在しない値
                while (Math.Abs(ok - ng) > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (b[mid] > m[i]) // midのチェック 
                    {
                        ok = mid;
                    }
                    else
                    {
                        ng = mid;
                    }
                }
                bCount = n - ok;
            }

            answer += tCount * bCount;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 44180
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for (int i=0;i<N;i++) {
            int A = sc.nextInt();
            if (A%2==0) {
                if (A%3!=0 && A%5!=0) {
                    System.out.println("DENIED");
                    return;
                }
            }
        }
        System.out.println("APPROVED");
    }
}

Measured memory_bytes: 23252
#include <iostream>

using namespace std;

static const int TYPE_COST =0;
static const int TYPE_TIME =1;
static const int INF =100000000;
static const int MAX_N = 300;
static const int MAX_M = 100;
int C[MAX_M][MAX_M];
int T[MAX_M][MAX_M];

void init(int type, int n);

int main(int argc, char** argv)
{
	while( 1 ){
		int n, m, from, to, c, t, type;
		cin >> n;
		cin >> m;
		if(n==0 && m==0) break;
		init(TYPE_COST, m);
		init(TYPE_TIME, m);
		for(int i=0; i<n; i++)
		{
			cin >> from;
			cin >> to;
			cin >> c;
			cin >> t;
			C[from-1][to-1] = C[to-1][from-1] = c;
			T[from-1][to-1] = T[to-1][from-1] = t;
		}
		
		for(int k=0; k<m; k++){
			for(int i=0; i<m; i++){
				for(int j=0; j<m; j++){
					C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
					T[i][j] = min(T[i][j], T[i][k] + T[k][j]);
				}
			}
		}
		
		cin >> m;
		for(int i=0; i<m; i++){
			cin >> from;
			cin >> to;
			cin >> type;
			if(type == TYPE_COST) cout << C[from-1][to-1] << endl;
			if(type == TYPE_TIME) cout << T[from-1][to-1] << endl;
		}
	}
	
	return 0;
}

void init(int type, int n)
{
	if(type==TYPE_COST){
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(i==j) C[i][j] = 0;
				else C[i][j] = INF;
			}
		}
	}
	
	if(type==TYPE_TIME){
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(i==j) T[i][j] = 0;
				else T[i][j] = INF;
			}
		}
	}
}

Measured memory_bytes: 944
n, m = map(int, input().split())
p_dict = {}
# value = [ac, wa]
for i in range(m):
    p, s = input().split()
    if p not in p_dict:
        if s == 'AC':
            p_dict[p] = [1, 0]
        elif s == 'WA':
            p_dict[p] = [0, 1]
    else:
        if s == 'WA' and p_dict[p][0] == 0:
            p_dict[p][1] = p_dict[p][1] + 1
        if s == 'AC' and p_dict[p][0] == 0:
            p_dict[p][0] = 1

ac = 0
wa = 0
for key, value in p_dict.items():
    ac = ac + value[0]
    if value[0] == 1:
        wa = wa + value[1]

print(ac, wa)

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

int main(){
    ll N;cin>>N;
    vector<pair<ll,ll>> t(N);
    for (ll i = 0; i < N; i++){
        ll a,b; cin>>a>>b;
        t[i]=make_pair(b,a);
    }
    sort(t.begin(),t.end());
    ll time=0;
    for (ll i = 0; i < N; i++){
        ll x=t[i].second;
        time+=x;
        //cout<<time<<" "<<t[i].first<<endl;
        if(time>t[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int h,w;cin>>h>>w;
	vector<int>a,b;
	rep(i,h){
		int d;cin>>d;
		a.push_back(d);
	}
	rep(i,w){
		int d;cin>>d;
		b.push_back(d);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	ll cnt=0;
	for(int i:a){
		ll d=w-(lower_bound(b.begin(),b.end(),i)-b.begin());
		cnt+=d*i;
	}
	for(int i:b){
		ll d=h-(upper_bound(a.begin(),a.end(),i)-a.begin());
		cnt+=d*i;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3912
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();
	bool A[200001] = {}, B[200001] = {};
	rep(i, M) {
		int a = getint(), b = getint();
		if (a == 1) A[b] = 1;
		if (b == N) B[a] = 1;
	}

	int ikeru = 0;
	rep1(i, N) if (A[i] && B[i]) ikeru = 1;

	if (ikeru) printf("POSSIBLE");
	else printf("IMPOSSIBLE");

	Would you please return 0;
}

Measured memory_bytes: 640
def main():
    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys
    import heapq
    # from math import *
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline()
    def mdata(): return map(float, data().split())
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9) + 7

    n = int(data())
    P = list(mdata())
    dp = [0.0] * (n // 2 + 2)
    dp[1] = float(1)
    for i in range(n):
        p=P[i]
        for j in range(len(dp) - 1, 0, -1):
            dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)
    print(sum(dp))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include<cstdio>
using namespace std;
const int MAX = 100 + 10;
char a[MAX], b[MAX], c[MAX];
int main () {
    int n;
    scanf("%d", &n);
    scanf("%s %s %s", a, b, c);
    int ans = 0;
    for(int i = 0 ; i < n ; i++) {
        if(a[i] != b[i]) {
            if(a[i] == c[i] || b[i] == c[i]) ans++;
            else ans += 2;
        } else if(a[i] != c[i]) {
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int n; cin >> n;
    vector<vector<vector<int>>> room(4,vector<vector<int>>(3,vector<int>(10)));
    rep(i,n){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;
        room.at(a).at(b).at(c) += d;
    }
    rep(i,4){
        rep(j,3){
            rep(k,10){
                cout << " ";
                cout << room.at(i).at(j).at(k);
            }
            cout << endl;
        }
        if(i != 3){
            rep(l,20) cout << '#';
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3156
s = input()
t = input()

ls = len(s)
lt = len(t)
max = 0
for i in range(ls-lt+1):
  k = 0
  for j in range(i,i+lt):
    if s[j] == t[j-i]:
      k += 1
  if max < k:
    max = k
    
print(lt-max)    
  

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

using namespace std;

int M, T, P, R;

struct DATA{
  int id, t, sv;
  vector<int> pr, pt;
  DATA(int id_): id(id_), t(0), sv(0), pr(P,false), pt(P,0){} 
  bool operator ==(const DATA& a){
    return (sv==a.sv && t==a.t);
  }
};

bool comp(const DATA& a, const DATA& b){
  if(a.sv != b.sv) return a.sv > b.sv;
  if(a.t != b.t) return a.t < b.t;
  return a.id > b.id;
}

int main(){
  int m, t, p, is;
  vector<DATA> data;
  while(1){
    cin >> M >> T >> P >> R;
    if(!M && !T && !P && !R) break;
    data.clear();
    for(int i=1; i<=T; ++i) data.push_back(DATA(i));
    for(int i=0; i<R; ++i){
      cin >> m >> t >> p >> is;
      --t; --p;
      if(is){
	++data[t].pt[p];
      }else if(!data[t].pr[p]){
	data[t].t += m + 20 * data[t].pt[p];
	++data[t].sv;
	data[t].pr[p] = true;
      }
    }
    sort(data.begin(), data.end(), comp);
    cout << data[0].id;
    for(int i=1; i<data.size(); ++i){
      cout << (data[i]==data[i-1] ? '=' : ',') << data[i].id;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

map<int,int64_t> Prime;

void Factori(int n){
    for(int i=2;i+i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                Prime[i]++;
                n/=i;
            }
        }
    }
    if(n!=1) Prime[n]++;
}

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

    rep(i,2,N+1) Factori(i);

    int64_t ans=1;
    for(auto p:Prime){
        ans*=p.second+1;
        ans%=MOD;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256