akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll t;
    cin >> t;
    Vi ans;
    while(t--){
        ll n,m,a,b;
        cin >> n >> m >> a >> b;
        ans.pb(atcoder::floor_sum(n,m,a,b));
    }
    for(auto an:ans){
        print(an);
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iomanip>

using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int N;
    cin >> N;
    double p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    double memo[N][N + 1]; //yi回目まででxi回表が出る確率
    for(int yi = 0; yi < N; yi++){
        for(int xi  = 0; xi <= N; xi++){
            memo[yi][xi] = 0;
        }
    }
    memo[0][0] = 1.0 - p[0];
    memo[0][1] = p[0];
    for(int yi = 1; yi < N; yi++){
        for(int xi  = 0; xi <= N; xi++){
                memo[yi][xi] = memo[yi -1][xi] * (1.0 - p[yi]) + ((xi == 0) ? 0 : memo[yi - 1][xi - 1] * p[yi]);
        }
    }
    int tmp = (N / 2) + (N % 2);
    double prob = 0.0;
    for(int xi = tmp; xi <= N; xi++){
        prob += memo[N - 1][xi];
    }
    cout << setprecision(9) << prob << endl;


}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

#define N_MAX 110
#define W_MAX 100010
ll dp[N_MAX][W_MAX];

void solve()
{
  ll N, W; cin >> N >> W;
  
  vector<ll> w(N), v(N); rep(i, N) cin >> w[i] >> v[i];
  ll ans = 0;

  rep(i, N_MAX) {
    rep(j, W_MAX) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  rep(i, N) {
    rep(j, W_MAX) {
      if(j-v[i]>=0) {
	chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
      }
      chmin(dp[i + 1][j], dp[i][j]);
    }
    /*    rep(j, 20) {
      if(dp[i + 1][j]==INF) {
	cerr << "INF ";
      } else {
	cerr << dp[i + 1][j] << " ";
      }
    }
    
    cerr << endl;
    */
  }
  
  
  
  ans = 0;
  rep(j, W_MAX) {
    if(dp[N][j] <= W) ans = j;

  }
  
  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 86272
#include<stdio.h>

int main(){
    int a[100],b[100],i,j,sw,totala,totalb;
    for(i=0;i<20;i++){
        if(i>=0&&i<=9){
            scanf("%d",&a[i]);
        }else if(i>=10&&i<=19){
            scanf("%d",&b[i-10]);
        }
    }
    for(i=0;i<10;i++){
            for(j=i;j<10;j++){
                if(a[i]<=a[j]){
                    sw=a[j];
                    a[j]=a[i];
                    a[i]=sw;
                }
                if(b[i]<=b[j]){
                    sw=b[j];
                    b[j]=b[i];
                    b[i]=sw;
                }
            }
    }
    totala=a[0]+a[1]+a[2];
    totalb=b[0]+b[1]+b[2];
    printf("%d %d\n",totala,totalb);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];

    vector<vector<int>> dp(500, vector<int>(500, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 400; j >= 0; j--) {
            for (int k = 400; k >= 0; k--) {
                dp[j+a[i]][k+b[i]] = min(dp[j+a[i]][k+b[i]], dp[j][k] + c[i]);
            }
        }
    }

    int ans = INF;
    for (int i = 1; i <= 400; i++) {
        for (int j = 1; j <= 400; j++) {
            if (i * Mb == j * Ma) {
                ans = min(ans, dp[i][j]);
            }
        }
    }

    if (ans == INF) cout << -1 << '\n';
    else cout << ans << '\n';
}

Measured memory_bytes: 4600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

void solve()
{

}

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
string s,t;
cin>>s>>t;
int n=s.length();
int ans=0;
rep(i,0,n-1)if(s[i]!=t[i])ans++;
ol(ans);
return 0;
}



Measured memory_bytes: 3792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<deque>
#include<stack>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e5 + 5;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main () {
    std_quick_io();
    int n;
    cin >>n;
    vector<ll> res(n);
    for(int i = 0; i<n;i++) {
        cin >>res[i];
    }
    ll ans = 1e9;
    for(ll i = 1;i <=100;i++) {
        ll sum =0;
        for(int j = 0;j <n;j++) {
            sum += (i- res[j]) *(i - res[j]);
        }
        ans =min(ans,sum);
    }
    cout <<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for(int i = x; i < y; i++)
typedef long long ll;
using namespace std;

set<ll> v;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    int k = (int)sqrt(n) + 1;
    FOR(i, 1, k) {
        if (n % i == 0) {
            v.insert((ll)(i - 1));
            v.insert((ll)(n / i - 1));
        }
    }
    ll ans = 0;
    for (auto& i : v) {
        if (i == 0) continue;
        if (n / i == n % i) {
            ans += i;
            // cout << i << endl;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
import numpy as np
W, H, N = map(int, raw_input().split())
A = np.ones((W, H), dtype=np.int)
for i in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        A[:x,:] = 0
    elif a == 2:
        A[x:,:] = 0
    elif a == 3:
        A[:,:y] = 0
    elif a == 4:
        A[:,y:] = 0
print np.sum(A)

Measured memory_bytes: 11884
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long a[n];
    for( int i = 0; i < n; ++i )
    	cin >> a[i];
    long long cnt = 0;
    bool bl = false;
    while( 1 )
    {
    	for( int i = 0; i < n; ++i )
    	{
    		if( a[i]%2 == 0 )
    		{
    			a[i] /= 2;
    		} 
    		else 
    		{
    			bl = true;
    			break;
    		}
    	}
    	if( bl )
    		break;
    	cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int counter1 = 0,counter0 = 0;
	String N = sc.next();
	String S[] = new String[N.length()];
		for(int i=0; i<N.length(); i++){
		S[i] = String.valueOf(N.charAt(i));
			if(S[i].equals("1")){
			counter1++;
			}
          	else{
			counter0++;
			}
		}
		System.out.println(Math.min(counter0*2,counter1*2));
		
	}
}	

			

Measured memory_bytes: 31888
A, B, K = map(int,input().split())
for i in range(K):
  if i % 2 == 0:
    if A % 2 == 1:
      A -= 1
    A //= 2
    B += A
  else:
    if B % 2 == 1:
      B -= 1
    B //= 2
    A += B
print(A,B)



Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<cassert>
using namespace std;

int deg(char c){
  if(c>='A')return 10+c-'A';
  return c-'0';
}

long long int gcd(long long int a, long long int b){
  return b==0?a:gcd(b,a%b);
}

long long int lcm(long long int a, long long int b){
  if(a<b){
    return a*(b/gcd(a,b));
  }else{
    return b*(a/gcd(a,b));
  }
}

struct Phrase{
  vector<int> vf;
  Phrase(){}
  Phrase(const string &s){
    for(int i = 0; i < s.length(); i+=2){
      char c1=s[i];
      if(i+1>=s.length())return ;
      char c2=s[i+1];
      vf.push_back((deg(c1)*0x10+deg(c2)));
    }
  }
  Phrase merge(const Phrase &t){
    Phrase ret;
    long long int len = vf.size();
    long long int tlen = t.vf.size();
    long long int LCM = lcm(len,tlen);
    for(int k = 0; k < LCM; ++k){
      int s=0;
      if( k%(LCM/len)==0 )
	s+=vf[k/(LCM/len)];
      if( k%(LCM/tlen)==0 )
	s+=t.vf[k/(LCM/tlen)];
      ret.vf.push_back(s);
    }
    return ret;
  }
  void eraseExtraZeroes(){
    vector<int> non_zero_pos;
    for(int i=1; i <vf.size(); ++i){
      if(vf[i]!=0)non_zero_pos.push_back(i);
    }
    long long int min_gcd=vf.size();
    for(int i=0;i<non_zero_pos.size();++i){
      min_gcd = gcd(non_zero_pos[i],min_gcd);
    }
    if(min_gcd>1){
      int n=0;
      for(int i=0;i<vf.size();i+=min_gcd){
	for(int j=1;j<min_gcd;++j){
	  vf[i+j]=-1;
	}
      }
    }
    Phrase t;for(int i=0;i<vf.size();++i)if(vf[i]>=0)t.vf.push_back(vf[i]);
    *this=t;
  }
  void print(){
    for(int i = 0; i < vf.size(); ++i){
      printf("%02X",vf[i]);
    }
    putchar('\n');
  }
};
  
int main()
{
  int T;
  cin>>T;
  for(int tc=1;tc<=T;++tc){
    int N;
    string s;
    bool toocomplex=false;
    Phrase P;
    
    cin>>N;
    if( N == 0 )break;
    
    int left=N;
    for(int i = 0; i < N; ++i){
      cin>>s;
      Phrase t(s);
      --left;
      
      t.eraseExtraZeroes();
      if(P.vf.size()==0)
	P=t;
      else
	P=P.merge(t);
      P.eraseExtraZeroes();

      if(2*P.vf.size()>2048){
	toocomplex=true;
	break;
      }
    }
    for(int i = 0; i < left; ++i){
      cin>>s;
    }

    if(toocomplex){
      printf("Too complex.\n");
    }else{
      P.print();
    }
  }
  return 0;
}

Measured memory_bytes: 8012
#include<stdio.h>

int main (void){
  int n,q,c = 0;
  int a[100000] = {};
  scanf("%d",&n);
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }


        for(int i = 0;i < 100000;i++){
                if(a[i] == (i + 1)){
                        c = a[i];
                        a[i] = a[i + 1];
                        a[i + 1] = c;
                       q = q + 1;
                }
        }
        printf("%d\n",q);
        return 0;

}

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

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

    string w;
    cin >> w;

    unordered_map<char, int> mp;
    for(int i = 0; i < w.size(); i++){
        mp[w[i]]++;
    }

    for(auto x : mp){
        if(x.second % 2){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  string x;
  stack<char> s;
  cin >> x;
  rep(i, 0, x.length()) {
    if(x[i] == 'S') s.push(x[i]);
    else if(s.size() > 0 && s.top() == 'S') s.pop();
    else s.push(x[i]);
  }

  cout << s.size() << endl;
}


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

int H, W;
vector<vector<int>> LR, UD;
vector<string> S;

int dfsX(int h, int w, int dx){
    // (h,w) ：探索の現在位置。
    //  dx   ：障害物のない領域の左端からこのマスまでの幅。
    if(w+1>=W || S[h][w+1]=='#'){
        // これ以上右へ進めない場合は dx を返す。
        LR[h][w] = dx;
        return dx;
    }

    // まだ右へ行ける場合は、右へ移動し dx を一つ増やす。
    LR[h][w] = dfsX(h,w+1, dx+1);
    return LR[h][w];
}

int dfsY(int h, int w, int dy){
    // dfsX と同じことを H 方向にやる
    if(h+1>=H || S[h+1][w]=='#'){
        UD[h][w] = dy;
        return dy;
    }
    UD[h][w] = dfsY(h+1,w, dy+1);
    return UD[h][w];
}

int main(){
    cin >> H >> W;
    S = vector<string>(H);
    for(int i=0; i<H; i++){
        cin >> S[i];
    }

    // LR と UD を求める。
    LR = vector<vector<int>>(H,vector<int>(W,0));
    UD = vector<vector<int>>(H,vector<int>(W,0));
    for(int h=0; h<H; h++) for(int w=0; w<W; w++){
        // (h,w) が障害物の無い領域の左端 or 上端のときに探索を始める。
        if(S[h][w]=='.'){
            if(w==0 || S[h][w-1]=='#'){
                LR[h][w] = dfsX(h,w,1);
            }
            if(h==0 || S[h-1][w]=='#'){
                UD[h][w] = dfsY(h,w,1);
            }
        }
    }
    
    int ans = 0;
    for(int h=0; h<H; h++) for(int w=0; w<W; w++){
        ans = max(ans, LR[h][w] + UD[h][w] - 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 35968
#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
const int N=2004;
vector<int> E[N];
int DFS(int x,int p,int d,int mx)
{
	int ans=1;
	if(d!=mx)
	{
		for(int y : E[x])
		{
			if(y==p)
				continue;
			ans+=DFS(y,x,d+1,mx);
		}
	}
	return ans;
}
int  main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	int ans=0;
	if(k%2==0)
	{
		for(int v=0;v<=n;v++)
		{
			ans=max(ans,DFS(v,-1,0,k/2));
		}
	}else{
		for(int v=1;v<=n;v++)
		{
			for(int u : E[v])
			{
				ans=max(ans,DFS(v,u,0,k/2)+DFS(u,v,0,k/2));
			}
		}
	}
	ans=n-ans;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
// Problem : D - Lunlun Number
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

ll findNext(ll fst) {
	string s= to_string(fst);
	if (sz(s) == 1) {
		return fst + 1;
	}
	bool f = false;
	FORD(i, sz(s) - 1, 1) {
		if (s[i] - s[i - 1] != 1 && s[i] != '9') {
			s[i]++;
			FOR(j, i + 1, sz(s) - 1) {
				s[j] = max(s[j - 1] - 1, (int)'0');
			}
			f = true;
			break;
		}
	}
	if (f) return stoll(s);
	else {
		int x = s[0] - '0';
		if (x == 9) {
			return 1 * pow(10, sz(s));
		} else {
			//cout << "here" << endl;
			s[0] = x + 1 + '0';
			FOR(j, 1, sz(s) - 1) {
				//cout << s[j - 1] - 1 << " " << (int)'0' << endl;
				s[j] = max(s[j - 1] - 1, (int)'0');
			}
			//cout << s << endl;
			return stoll(s);
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int k;
	cin >> k;
	ll fst = 1;
	REP(i, k - 1) {
		//cout << fst << endl;
		fst = findNext(fst);
	}
	cout << fst << endl;
	return 0;
}
 


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int left = a+b, right = c+d;
  if(left > right)
    cout << "Left" << endl;
  else if(left < right)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
data = {'AC':0,'WA':0,  'TLE':0, 'RE':0}

for i in range(N):
    a = input() 
    data[a] = data[a] + 1

for i, j in zip(data.keys(), data.values()):
    print(i + " x " + str(j))

Measured memory_bytes: 9132
#include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;int main(){int h,w,c[10][10],a;cin>>h>>w;r(i,10)r(j,10)cin>>c[i][j];r(k,10)r(i,10)r(j,10)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);int ans=0;r(i,h)r(j,w){cin>>a;if(a!=-1)ans+=c[a][1];}cout<<ans<<endl;}


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

int main () {

    string S;
    cin >> S;

    int month;
    month = (S[5] - '0') * 10 + (S[6] - '0');

    if (month <= 4) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  string s;
  cin >> s;
  int k;
  cin >> k;

  set<string> st;
  rep(i,s.size()){
    rep1(j,5){
      if(i+j>(int)s.size()) break;
      string ss = s.substr(i,j);
      st.insert(ss);
    }
  }

  int cnt = 1;
  for(auto it=st.begin();it!=st.end();++it){
    //    cout << *it << "\n";
    if(cnt==k){
      cout << *it << "\n";
      break;
    }
    cnt++;
  }
  
  return 0;
}


Measured memory_bytes: 1664
from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t^=1;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)

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

int main(){
  
  int n,x,y;
  cin >> n >> x >> y;
  
  vector<int> a(n);
  
  for(int i=1; i<=n ; i++){
    for(int j=i+1; j<=n; j++){
      
      int d = min(min(abs(i-x)+1+abs(j-y), abs(j-x)+1+abs(i-y)),abs(i-j));
      
      a.at(d)++;
    }
  }
  
  
  for(int i=1; i<n ; i++){
    
    cout << a.at(i) << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void print_data(int data[], int N) {
    cout << data[0];
    for (int i = 1; i < N; i++) cout << " " << data[i];
    cout << endl;
}

void insertion_sort(int data[], int N) {
    for (int i = 1; i < N; i++) {
        int v = data[i];
        int j = i - 1;
        while (j >= 0 && data[j] > v) {
            data[j+1] = data[j];
            j--; 
        }
        data[j+1] = v;
        print_data(data, N);
    }
}

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

    int data[N];
    for (int i = 0; i < N; i++) cin >> data[i];
    print_data(data, N);
    insertion_sort(data, N);
    
    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdbool.h>
using namespace std;
typedef long long ll;
bool dp[100010];
ll r[3];
int main(void) {
	ll n, prv = 0, x;
	cin >> n;
	for (ll i = 1;i <= n;i++) {
		cin >> x;
		if (x % 4 == 0)r[0]++;
		else {
			if (x % 4 == 2)r[1]++;
			else r[2]++;
		}
	}
	if (r[2] == 0) {
		cout << "Yes" << endl;
	}
	else {
		dp[1] = false;
		r[2]--;
		ll prv = 1;//奇数
		for (ll i = 2;i <= n;i++) {
			if (!dp[i-1]) {
				if (prv = 1) {
					if (r[0] > 0) {
						dp[i] = true;
						r[0]--;
						prv = 0;
					}
					else {
						dp[i] = dp[i - 1];
					}
				}
			}
			else {
				if (prv == 1) {
					if (r[0] > 0) {
						prv = 0;
						r[0]--;
						dp[i] = dp[i - 1];
					}
					else {
						dp[i] = false;
					}
				}
				else {
					if (prv == 2) {
						if (r[1] > 0) {
							dp[i] = dp[i - 1];
							r[1]--;
						}
						else {
							if (r[0] > 0) {
								dp[i] = dp[i - 1];
								r[0]--;
								prv = 0;
							}
							else dp[i] = false;
						}
					}
					else {
						if (r[2] > 0) {
							r[2]--;
							prv = 1;
							dp[i] = dp[i - 1];
						}
						else {
							dp[i] = dp[i - 1];
						}
					}
				}
			}
		}
		if (dp[n])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
	SPEED
	string s;
	cin >> s;
	bool flag = true;
	for (int i = 0; i <= 3; ++i)
	{
		if (s[i]==s[i+1])
		{
			cout << "Bad" << '\n';
			flag = false;
			break;
		}
	}
	if (flag)
	{
		cout << "Good" << '\n';
	}
	return 0;
}

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

int main() {
  int N;
  string s;
  int count = 1;
  cin >> N >> s;
  for(int i = 1; i < N; i++) {
    if(s.at(i - 1) != s.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        if(K%2==0)System.out.println((K/2)*(K/2));
        else System.out.println((K/2)*(K/2+1));
    }
}


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

int main() {
	long long N;
	cin >> N;
	vector<long long> A(N), B(N);
	for (int i = 0; i < N; i++) cin >> A[i], A[i]--, B[A[i]]++;
	long long COUNT = 0;
	for (int i = 0; i < N; i++) {
		COUNT += B[i] * (B[i] - 1) / 2;
	}
	for (int i = 0; i < N; i++) {
		long long X = B[A[i]];
		cout << COUNT - (X * (X - 1) / 2 - (X - 1) * (X - 2) / 2) << endl;
	}
}

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

using namespace std;

int main(void)
{
    int64_t n,m,sum=0;
    vector<int64_t> a;
    cin >> n >> m;
    for (size_t i = 0; i < n; i++)
    {
        int64_t buf;
        cin >> buf;
        a.push_back(buf);
        sum+=buf;
    }

    sort(a.begin(), a.end(), greater<int64_t>());

    double m4 = sum / (double)(m * 4);
    bool okflag = true;
    for (size_t i = 0; i < m; i++)
    {
        if(a.at(i) < m4) {okflag = false; break;}
    }
    if (okflag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

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

int main(){
    string s, t;
    cin >> s >> t;
    size_t n = s.length();
    int count = 0;
    for (int i = 0; i < n; ++i){
        if (s[i]!=t[i]){
            count+=1;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
int main(){
  string N;
  cin >> N;
  if(N.at(0) == '1'){N.at(0) = '9';}else{N.at(0) = '1';}
  if(N.at(1) == '1'){N.at(1) = '9';}else{N.at(1) = '1';}
  if(N.at(2) == '1'){N.at(2) = '9';}else{N.at(2) = '1';}
  cout << N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int> a;
  int n,k;
  cin>>n>>k;
  a.resize(n);
  for(auto &i:a)
  {
    cin>>i;
  }
  sort(a.begin(),a.end());
  cout<<accumulate(a.begin(),a.begin()+k,0)<<endl;
}
  

Measured memory_bytes: 3572
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int R;
	cin >> R;
	string s;
	if (R < 1200) s = "ABC";
	else if (R < 2800) s = "ARC";
	else s = "AGC";

	cout << s << endl;
	return 0;
}



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

def ask_judge(asset_now, position):
    if ask[i]:
        position += asset_now // A[i]
        asset_now -= asset_now // A[i] * A[i]    
    return asset_now, position

def bid_judge(asset_now, position):
    if bid[i]:
        asset_now += position * A[i]    
        position = 0
    return asset_now, position


asset_now = 1000

ask = [True if A[i+1] - A[i] > 0 else False for i in range(N-1)]
bid = [True if A[i+1] - A[i] < 0 else False for i in range(N-1)]
position = 0

for i in range(N):
    if i == 0:
        asset_now, position = ask_judge(asset_now, position)
    elif i == N-1:
        if position > 0:
            asset_now += position * A[N-1]
    else:
        asset_now, position = ask_judge(asset_now, position)
        asset_now, position = bid_judge(asset_now, position)

print(asset_now)

Measured memory_bytes: 9256
# coding: utf-8
# Your code here!
import itertools

def main():
    while True:
        n, m = map(int, input().split())
        if n == 0 : break
        ns = list(map(int, input().split()))
        ans = -1
        for p in itertools.permutations(ns, 2):
            if sum(p) <= m:
                ans = max(ans, sum(p))
        if ans == -1:
            print('NONE')
        else:
            print(ans)
main()



Measured memory_bytes: 5788
import java.util.Scanner;

public class Main {

    int a, b;
    int cost;

    public void solve() {
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        cost = sc.nextInt();

        if (a + b >= cost) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

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


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

R=[A[0]]*n
for i in range(n-1):
    R[i+1]=R[i]+A[i+1]

R=[0]+R
from collections import Counter
ans=0
for i in Counter(R).values():
    ans+= i*(i-1)//2
print(ans)

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int h, w;
	cin >> h >> w;
	string s[h];
	bool memo[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			memo[i][j] = false;
		}
	}
	memo[0][0] = true;
	int sum = 0;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		for (int j = 0; j < s[i].size(); j++) {
			if (s[i][j]=='#') {
				sum++;
				memo[i][j] = true;
			}
		}
	}
        P tmp = {0,0};
	queue<P> q;
	q.push(tmp);
	int step = 0;
	while (true) {
		step++;
		if (q.size() == 0) {
			cout << -1 << "\n";
			return 0;
		}
		int size = q.size();
		for (int i = 0; i < size; i++) {
			tmp = q.front();
			q.pop();
			int f = tmp.first;
			int s = tmp.second;
			if (f==h-1&&s==w-1) {
//				cout << step << " " << sum << "\n";
				cout << (h * w) - sum - step << endl;
				return 0;
			}
			if (f-1>=0&&!memo[f-1][s]) {
				q.push(P(f-1,s));
				memo[f-1][s] = true;
			}
			if (s-1>=0&&!memo[f][s-1]) {
				q.push(P(f,s-1));
				memo[f][s-1] = true;
			}
			if (f+1<h&&!memo[f+1][s]) {
				q.push(P(f+1,s));
				memo[f+1][s] = true;
			}
			if (s+1<w&&!memo[f][s+1]) {
				q.push(P(f,s+1));
				memo[f][s+1] = true;
			}
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
// #define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int p;
  int ans;
  for (int i = 0; i < 5; i++) {
    cin >> p;
    if(p==0) ans = i+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define N 100050
typedef long long ll;
int n,a[N],b[N],s[N],V[N],c[N];
void fix(int x,int v) {
	for(;x<=n;x+=x&(-x)) c[x]+=v;
}
int inq(int x) {
	int re=0;
	for(;x;x-=x&(-x)) re+=c[x];
	return re;
}
bool check(int mid) {
	int i,cnt;
	for(i=1;i<=n;i++) {
		if(a[i]<mid) b[i]=-1;
		else b[i]=1;
		s[i]=s[i-1]+b[i];
		V[i]=s[i];
	}
	sort(V+1,V+n+1);
	cnt=unique(V+1,V+n+1)-V-1;
	for(i=1;i<=n;i++) {
		s[i]=lower_bound(V+1,V+cnt+1,s[i])-V;
	}
	ll ans=0;
	memset(c,0,sizeof(c));
	for(i=1;i<=n;i++) {
		ans+=inq(s[i]);
		if(V[s[i]]>=0) ans++;
		fix(s[i],1);
	}
	// printf("%lld\n",ans);
	return ans>=ll(n)*(n+1)/2/2;
}
int main() {
	scanf("%d",&n);
	int i,mx=0;
	for(i=1;i<=n;i++) scanf("%d",&a[i]),mx=max(mx,a[i]);
	int l=0,r=mx+1;
	// check(8); return 0;
	while(l<r) {
		int mid=(l+r)>>1;
		if(check(mid)) l=mid+1;
		else r=mid;
	}
	printf("%d\n",l-1);
}

Measured memory_bytes: 2176
use std::io::{BufRead, Read};

pub struct Scanner<R>
where
    R: BufRead,
{
    reader: R,
}

impl<R> Scanner<R>
where
    R: BufRead,
{
    pub fn new(reader: R) -> Self {
        Self { reader }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: ::std::str::FromStr,
        <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
    {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .unwrap()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut sc = Scanner::new(stdin);

    loop {
        let s: String = sc.next();
        if s.len() == 1 && s == "0" {
            break;
        }
        println!(
            "{}",
            s.chars()
                .map(|c| c.to_digit(10).unwrap())
                .fold(0, |acc, n| acc + n),
        );
    }
}



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

int main() {
	int64_t N, A, B;
	cin >> N >> A >> B;

	int64_t diff, time = 0, da, db;
	diff = B - A - 1;
	da = A - 1;
	db = N - B;
	if (diff % 2 == 0) {
		if (da == db) {
			time += da + 1;
		}
		else time = min(da, db) + 1;
		diff--;
	}
	if (diff % 2 != 0) time += (diff + 1)/2;
	cout << time << endl;
}


Measured memory_bytes: 256
program UOIAUAI
  implicit none
  character(1) :: s
  integer      :: n
  read(*,*) s
  n = ichar(s) - 97
  if (n*(n-4)*(n-8)*(n-14)*(n-20).eq.0) then
    write(*,'(a)') 'vowel'
  else
    write(*,'(a)') 'consonant'
  end if
end program UOIAUAI

Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct node{
  int parent,left,right;
};
node type[25];
int d[25],h[25];

void depth(int r,int x){
  if(r!=-1){
    d[r]=x;
    depth(type[r].left,x+1);
    depth(type[r].right,x+1);
  }
}

int height(int r){
  int hl=0,hr=0;
  if(type[r].left!=-1) hl=height(type[r].left)+1;
  if(type[r].right!=-1) hr=height(type[r].right)+1;
  if(hl<hr) return h[r]=hr;
  return h[r]=hl;
}

int sibling(int x){
  if(type[x].parent==-1) return -1;
  if(type[type[x].parent].left==x) return type[type[x].parent].right;
  return type[type[x].parent].left;
}

void output(int x){
  cout<<"node "<<x<<": ";
  cout<<"parent = "<<type[x].parent<<", ";
  cout<<"sibling = "<<sibling(x)<<", ";
  int deg=0;
  if(type[x].left!=-1) ++deg;
  if(type[x].right!=-1) ++deg;
  cout<<"degree = "<<deg<<", ";
  cout<<"depth = "<<d[x]<<", ";
  cout<<"height = "<<h[x]<<", ";
  if(type[x].parent==-1) cout<<"root"<<endl;
  else if(type[x].left==-1&&type[x].right==-1) cout<<"leaf"<<endl;
  else cout<<"internal node"<<endl;
}

int main(){
  int n,id,l,r; cin>>n;
  for(int i=0;i<n;++i) type[i].parent=-1;
  for(int i=0;i<n;++i){
    cin>>id>>l>>r;
    type[id].left=l;
    type[id].right=r;
    if(l!=-1) type[l].parent=id;
    if(r!=-1) type[r].parent=id;
  }
  int root;
  for(int i=0;i<n;++i)
    if(type[i].parent==-1) root=i;
  depth(root,0);
  height(root);
  for(int i=0;i<n;++i) output(i);
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int main() {
	while(0==0){
		int m,n,t;
		cin >> m >> n;
		if (m==0&&n==0) break;
		if (m>n){
			t=m;
			m=n;
			n=t;
		}
		cout << m << ' ' << n << endl;
	}
	return 0;
}


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

int main(){
  int N,i;
  cin >> N;
  int A[N];
  long long int sum=0,ans=0;
  long long int mod=1000000007;
  for(i=0;i<N;i++){
    cin >> A[i];
    sum+=A[i];
    sum%=mod;
  }
  
  for(i=0;i<N;i++){
    sum-=A[i];
    if(sum<0) sum+=mod;
    ans+=sum*A[i];
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
LL ans = 1;
/**********************************************/

int main(){
    cin >> n;
    FOR(i, 1, n+1){
        ans = (ans * i) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,m,s;
	scanf("%d %d %d %d",&a,&b,&c,&d);

	m=(a+b+c+d)/60;
	s=(a+b+c+d)%60;
	
	printf("%d\n%d\n",m,s);

	return 0;
}

Measured memory_bytes: 1024
/*
 AtCoder XXX 000
 */
 
#include <stdio.h>
 
int main(void){
  unsigned long long n,m;
  
  scanf("%llu %llu",&n,&m);
  if(n==1 && m==1){
    printf("%llu\n",1);
    return 0;
  }
  else if(n==1 || m==1){
    printf("%llu\n",n*m-2);
    return 0;
  }
  else printf("%llu\n",(n-2)*(m-2));
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
 
  int x; cin >> x;

  int u = 0;
  vector<int> f(x);
  for(int i=0; i<x; i++){
    cin >> f.at(i);
  }

  int d = 0;
  vector<int> s(x);
  for(int i=0; i<x; i++){
    cin >> s.at(i);
    d += s.at(i);
  }  
  
  int candy;
  int m = 0;
  for(int i=0; i<x; i++){
    
    u += f.at(i);
    
    if (i > 0) d -= s.at(i-1);
    
    candy = u + d;
    if (candy > m) {
      m = candy;
    }
  }  
  
  cout << m << endl;
  
  
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int dp[2005][2];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n, Z, W;
    cin >> n >> Z >> W;
    VI V(n+1);
    FOR(i, 1, n) {
        cin >> V[i];
    }
    if (n == 1) {
        cout << abs(V[1] - W) << endl;
    } else if (n == 2) {
        cout << max(abs(V[n] - W), abs(V[n - 1] - W)) << endl;
    } else {
        dp[n - 1][0] = abs(V[n] - V[n - 1]);
        dp[n - 1][1] = dp[n - 1][0];
        int mn = dp[n - 1][0];
        int mx = dp[n - 1][0];
        int ans = dp[n - 1][0];
        // dp[n - 2][1] = max(abs(V[n] - V[n - 2]), dp[n - 1][0]);
        for (int i = n - 2; i >= 1; i--) {
            // int mx = 0;
            // for (int j = i + 1; j <= n - 1; j++) {
            //     mx = max(mx, dp[j][0]);
            // }
            dp[i][1] = max(mx, abs(V[n] - V[i]));
            mx = max(dp[i][1], mx);
            // int mn = INT_MAX;
            // for (int j = i + 1; j <= n - 1; j++) {
                // mn = min(mn, dp[j][1]);
            // }
            // dp[i][0] = min(mn, abs(V[n] - V[i]));
            mn = min(mn, dp[i][0]);
            ans = max(ans, dp[i][0]);
        }
        // for (int i = 1; i < n; i++) {
        //     cout << dp[i][0] <<" "<<  dp[i][1] << endl;
        // }
        // int ans = 0;
        // for (int i = 1; i < n; i++) {
        //     ans = max(ans, dp[i][0]);
        // }
        cout << max(abs(V[n] - W), ans) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long int
ll knapSack(ll W, int w[], int v[], int n) {
   ll i, wt;
   ll K[n + 1][W + 1];
   for (i = 0; i <= n; i++) {
      for (wt = 0; wt <= W; wt++) {
         if (i == 0 || wt == 0)
         K[i][wt] = 0;
         else if (w[i - 1] <= wt)
            K[i][wt] = max(v[i - 1] + K[i - 1][wt - w[i - 1]], K[i - 1][wt]);
         else
        K[i][wt] = K[i - 1][wt];
      }
   }
   return K[n][W];
}
int main() {
  
   long long int n, W;
   cin >> n>>W;
   int v[n], w[n];
   for (int i = 0; i < n; i++) {
      cin >> w[i];
	  cin >> v[i];
      
   }
   cout << knapSack(W, w, v, n);
   return 0;
}

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

typedef long long int ll;
typedef pair<ll,ll> P;

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(b-1,n);
    cout<<(ll)(a*x/b)-a*(ll)(x/b);


    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
	int ans = 0;
	if (A + B <= 2 * C) {
		ans += (A + B) * min(X, Y);
	} else {
		ans += 2 * C * min(X, Y);
	}
	if (X >= Y) {
		X -= Y; Y = 0;
	} else {
		Y -= X; X = 0;
	}
	if (X > 0) {
		if (A <= 2 * C) {
			ans += A * X;
		} else {
			ans += 2 * C * X;
		}
	} else if (Y > 0) {
		if (B <= 2 * C) {
			ans += B * Y;
		} else {
			ans += 2 * C * Y;
		}
	} 
	cout << ans << endl;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  char a[A.size()], b[B.size()], c[C.size()];
  for(int i=0; i<A.size(); i++) {
    a[i]=A.at(i);
  }
  for(int i=0; i<B.size(); i++) {
    b[i]=B.at(i);
  }
  for(int i=0; i<C.size(); i++) {
    c[i]=C.at(i);
  }
  
  char j='a';
  int d=0, e=0, f=0;
  for(int i=0; i<1000; i++) {
    if(j=='a') {
      if(d==A.size()) {
        cout << 'A' << endl;
        return 0;
      }
      j=a[d];
      d++;
    }
    else if(j=='b') {
      if(e==B.size()) {
        cout << 'B' << endl;
        return 0;
      }
      j=b[e];
      e++;
    }
    else if(j=='c') {
      if(f==C.size()) {
        cout << 'C' << endl;
        return 0;
      }
      j=c[f];
      f++;
    }
  }
}

Measured memory_bytes: 256
//aea ctmr
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//v.erase(unique(v.begin(),v.end()),v.end());
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 400500;
const ll mod = 1e9 + 7;
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

int wea(int n){
	return (n * n - n) / 2;
}

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

	cout << wea(n) + wea(m) << endl;

	return 0;
}

Measured memory_bytes: 892
MOD = 10 ** 9 + 7
CEIL = 10 ** 6

FACT = Array.new(CEIL, 1)
INV  = Array.new(CEIL, 1)
FINV = Array.new(CEIL, 1)

(2 ... CEIL).each do |i|
  FACT[i] = (FACT[i - 1] * i) % MOD
  INV[i] = MOD - (INV[MOD % i] * (MOD / i)) % MOD
  FINV[i] = (FINV[i - 1] * INV[i]) % MOD
end

def combination_mod(n,k)
    return 0 if n < k
    return 0 if (n < 0 || k < 0)
    
    FACT[n] * (FINV[k] * FINV[n - k] % MOD) % MOD;
end


N, K = gets.split.map(&:to_i)
K_ = N - K

ans = (1 .. K).map do |i|
  b = combination_mod(K -  1, i - 1)
  r = combination_mod(K_ + 1, i)
  (b * r) % MOD
end

puts ans


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


int main() {
int N;
  cin >> N;
  vector<string> W(N);
  for(int i=0;i<N;i++) cin >> W[i];
  for(int i=0;i<N;i++){
   for(int j=0;j<N;j++) {
     if(i != j && W[i] == W[j]) {
      cout << "No" <<endl;
       return 0;
     }
   }
  }
  for(int i=0;i<N-1;i++){
   int s = W[i].size();
    if(W[i][s-1] != W[i+1][0]){
     cout << "No" <<endl;
      return 0;
    }
  }
  cout <<"Yes" <<endl;
  return 0;
}
  


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const N = +lines[0];
	const uvw = Array.from(Array(N-1), (e,i) => lines[i+1].split(" ").map(Number));
	const u = uvw.map(e => e[0]-1);
	const v = uvw.map(e => e[1]-1);
	const w = uvw.map(e => e[2]);
	
	const tree = Array.from(Array(N), () => new Set());
	const color = Array.from(Array(N), () => null);
	
	for(let i=0; i<N-1; i++){
		tree[u[i]].add([v[i], w[i]]);
		tree[v[i]].add([u[i], w[i]]);
	}
	
	const que = [];
	const setColor = (x, col) => {
		color[x] = col;
		for(let e of tree[x]){
			const y = e[0];
			const d = e[1];
			if(color[y]===null){que.push([y, col^(d%2)])}
		}
	}
	
	setColor(0,0);
	while(que.length){
		const y = que.shift();
		setColor(y[0],y[1]);
	}
	
	let ans = color.join("\n");
	
	console.log(ans);
});

Measured memory_bytes: 104260