akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), as(n);
    vector<vector<ll>> b(m, vector<ll>(n)), bs(n + 1, vector<ll>(n + 1));
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i];
        as[i + 1] = as[i] + a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> b[j][i];
        }
    }
    for (int i = 0; i < m; i++) {
        vector<P> v;
        set<int> st;
        for (int j = 0; j < n; j++) {
            v.push_back(P(b[i][j], j));
            st.insert(j);
        }
        st.insert(-1);
        st.insert(n);
        sort(all(v));
        for (int j = 0; j < n; j++) {
            int id = v[j].second;
            st.erase(id);
            auto it = st.lower_bound(id);
            int r = (*it) - 1;
            --it;
            int l = (*it) + 1;
           // cout << i << " " << id << " " << l << " " << r << endl;
            bs[l][id] += b[i][id];
            bs[id + 1][r + 1] += b[i][id];
            bs[id + 1][id] -= b[i][id];
            bs[l][r + 1] -= b[i][id];
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            bs[i][j] += bs[i][j - 1];
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            bs[j][i] += bs[j - 1][i];
        }
    }
    ll res = -LINF;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            ll s = bs[i][j] - (as[j] - as[i]);
            chmax(res, s);
        }
    }
    cout << res << endl;
}

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

int main() {
    string s;
    getline(cin, s);

    string keyence="keyence";
    rep(i,7) {
        string first=keyence.substr(0,keyence.size()-i);
        string last=keyence.substr(keyence.size()-i, i);
        string::size_type fpos = s.find(first);
        string::size_type lpos = s.rfind(last);
        if (fpos != string::npos && lpos != string::npos) {
            if (i==0) {
                if (fpos==0 || fpos+7==s.size()) {
                    cout << "YES" << endl;
                    return 0;
                } else {
                    cout << "NO" << endl;
                    return 0;
                }
            } else if (fpos<lpos && fpos==0 && lpos+i==s.size()) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

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

#define MAX 10000

void CountingSort(int *,int  *,int );

int main(){
  int i,k,n,C[MAX+1];

  scanf("%d",&n);

  unsigned short *A, *B;

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);


  scanf("%d",&A[0]);
  k = A[0];
  for(i=1;i<n;i++){
    scanf("%d",&A[i]);
    if(k < A[i])k = A[i];
  }

  for(i=0;i<=k;i++)
    C[i] = 0;

  for(i=0;i<n;i++)
    C[A[i]]++;

  for(i=1;i<=k;i++)
    C[i] = C[i] + C[i-1];

  for(i=n;i>=0;i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i<n)printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 8460
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    elif a[i+1] >= b[i] - a[i]:
        ans += b[i]
        a[i+1] -= (b[i] - a[i])
    else:
        ans += (a[i] + a[i+1])
        a[i+1] = 0

print(ans)


Measured memory_bytes: 19116
#include<bits/stdc++.h>
using namespace std;
int dis[502][502], N;
bool occ[502][502];
typedef pair<int, int>pi;
int dirx[]= {0, 1, 0, -1};
int diry[]= {1, 0, -1, 0};
void bfs(int x, int y)
{
    queue<pi>q;
    q.push({x, y});
    while(!q.empty())
    {
        x= q.front().first;
        y= q.front().second;
        q.pop();
        int z= dis[x][y]+occ[x][y];
        for(int i=0; i<4; i++)
        {
            int x1= x+dirx[i];
            int y1= y+diry[i];
            if(x1>=1 && x1<=N && y1>=1 && y1<=N && dis[x1][y1]>z)
            dis[x1][y1]= z, q.push({x1, y1});
        }
    }
    return;
}
int main()
{
    int x, y, z;
    scanf("%d", &N);
    for(int i=1; i<=N; i++)
    for(int j=1; j<=N; j++)
    dis[i][j]= min(min(i-1, N-i), min(j-1, N-j)), occ[i][j]= 1;
    int res= 0;
    for(int i=1; i<=N*N; i++)
    {
        scanf("%d", &z);
        x= (z+N-1)/N;
        y= z-(x-1)*N;
        res+= dis[x][y];
        occ[x][y]= 0;
        bfs(x, y);
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 4932
program Y042B
    implicit none
    integer(8)::N,ans,Ns,i
    read*,N
    Ns=int(sqrt(real(N)))
    do i=1,Ns+1
        if(i==1)then
            ans=N-1
        else if(mod(N,i)==0)then
            ans=min(ans,i+N/i-2)
        end if
    end do

    print'(i0)',ans
end program Y042B

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    string N;
    cin >> N;
    int size = N.size();
    int dp[size][2];
    for(int i=0;i<size;i++)for(int j=0;j<2; j++) dp[i][j] = INT_MAX/2;

    int di = N[0]-'0';
    dp[0][1] = min(1+(10-(di+1)),di+1);
    dp[0][0] = min(1+(10-(di)),di);

    //cout << dp[0][0] <<"," << dp[0][1]<<endl;
    for(int i = 1 ; i < size; i++){
        int d = N[i]-'0';
        //cout << dp[i-1][1] + (10-d) <<" vs "<< dp[i-1][0] + d << endl;
        dp[i][0] = min(dp[i-1][1]+(10-(d)), dp[i-1][0]+d);
        dp[i][1] = min(dp[i-1][1]+(10-(d+1)), dp[i-1][0]+d+1);
        //cout << dp[i][0] <<","<< dp[i][1]<<endl;
    }
    cout << dp[size-1][0] << endl;
    return 0;
}


Measured memory_bytes: 9220
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays;
import java.math.*;

class Edge {
	public int u, v, w;
	public Edge(int u, int v, int w) {
		this.u = u;
		this.v = v;
		this.w = w;
	}
}

class CompKey_e implements Comparator<Edge> {
	public int compare(Edge x, Edge y) {
		return x.w-y.w;
	}
}

class CompKey implements Comparator<Integer> {
	int[] val;
	public CompKey(int[] val) {	
		this.val = val;
	}
	public int compare(Integer x, Integer y) {
		return this.val[x]-this.val[y];
	}
}

class DisjointSet {
	int[] p;
	public DisjointSet(int n) {
		p = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = -1;
	}
	public int getRoot(int u) {
		if (p[u] == -1) return u;
		return p[u] = getRoot(p[u]);
	}
	public boolean isConnected(int u, int v) {
		u = getRoot(u); 
		v = getRoot(v);
		if (u == v) return true;
		p[u] = v;
		return false;
	}
}

class Main {
	static BufferedReader jvin = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter jvout = new PrintWriter(System.out);
	
	int N;
	int[] X_Coor, Y_Coor;
	Integer[] X_id, Y_id;
	Edge[] E;
	DisjointSet d;
	
	public static void main(String[] args) throws IOException {
		Main instance = new Main();
		instance.passStaticVar();
	}


	public void passStaticVar() throws IOException {
		N = Integer.parseInt(jvin.readLine());
		X_Coor = new int[N]; X_id = new Integer[N];
		Y_Coor = new int[N]; Y_id = new Integer[N];
		for (int i = 0; i < N; ++i) {
			String[] t = jvin.readLine().split(" ");
			X_Coor[i] = Integer.parseInt(t[0]);
			Y_Coor[i] = Integer.parseInt(t[1]);
			X_id[i] = Y_id[i] = i;
		}
		
		Arrays.sort(X_id, new CompKey(X_Coor));
		Arrays.sort(Y_id, new CompKey(Y_Coor));
		E = new Edge[2*N-2];
		int m = 0;
		for (int i = 1; i < N; ++i) {
			E[m++] = new Edge(X_id[i], X_id[i-1], X_Coor[X_id[i]]-X_Coor[X_id[i-1]]);
			E[m++] = new Edge(Y_id[i], Y_id[i-1], Y_Coor[Y_id[i]]-Y_Coor[Y_id[i-1]]);
		}
		Arrays.sort(E, new CompKey_e());
		d = new DisjointSet(N);
		long res = 0;
		for (int i = 0; i < m; ++i) 
			if (!d.isConnected(E[i].u, E[i].v)) 
				res += E[i].w;
		jvout.println(res);
		jvout.flush();
	}
}


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

int main(){
    int n;
    cin >> n;
    string s=to_string(n);
    int sum=0;
    rp(i,s.size()){
        sum += s.at(i)-'0';
    }
    if(n%sum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



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

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  bool b[n]={false};
  b[0]=true;
  int res=0;
  for(int i=0;;){
    if (!b[a[i]-1]){
      if(a[i]!=2){
      b[a[i]-1]=true;
      res++;
      i=a[i]-1;
      }
      else {
        res++;
        cout<<res<<endl;
        return 0;
      }
    }
    else  break; 
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec f(1000000, 0);
  for(ll x=1;x<=sqrt(N);x++){
    for(ll y=1;y<=sqrt(N);y++){
      for(ll z=1;z<=sqrt(N);z++){
        f[x*x + y*y + z*z + x*y + y*z + z*x]++;
      }
    }
  }
  rep(i, N){
    cout << f[i+1] << endl;
  }
  return 0;
}


Measured memory_bytes: 11192
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a: Vec<i64> = vec![0; 6];

    for _ in 0..5 {
        a[read::<usize>()] += 1;
    }

    for i in 0..a.len() {
        let ai = a[i];
        if ai == 0 {
            println!("{}", i);
        }
    }
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define LOCAL
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound
#define lowbit(x) x&(-x)
#define testbit(x,i) x&(1<<i)

inline void checkmin(int &x,int y){x=min(x,y);}
inline void checkmax(int &x,int y){x=max(x,y);}

const int maxn = 1e5 + 10;
int n, m, h[maxn];
vector<int> edge[maxn];

int main() 
{
	#ifndef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>m;
    for(int i = 1; i <= n; i++) {
    	cin>>h[i];
	}
	for(int i = 0; i < m; i++) {
		int u, v;
		cin>>u>>v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		bool flag = true;
		for(auto to : edge[i]) {
			if(h[i] <= h[to]) {
				flag = false;
				break;
			}
		}
		cnt += flag;
	}
	cout<<cnt<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 9160
length, weight = (int(n) for n in input().split(" ") )
dp = [0 for n in range(weight + 1)]
for l in range(length):
    v, w = (int(n) for n in input().split(" ") )
    temp = dp[:]
    for i, d in enumerate(dp):
        if d and i + w <= weight:
            temp[i + w] = max(d + v, dp[i + w])
    dp = temp
    dp[w] = max(v, dp[w])
    # print(dp)
print(max(dp))
            


Measured memory_bytes: 6260
N,M = map(int,input().split())
A = []
B = []
all = []
for _ in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    all.append([a,b])
all = sorted(all,key=lambda x:x[1])
MinBar = 1
abar = all[0][0]
bbar = all[0][1]

for i in range(1,M):
    if all[i][0] < bbar:
        bbar = min(bbar,all[i][1])
    else:
        MinBar += 1
        abar = all[i][0]
        bbar = all[i][1]
print(MinBar)


Measured memory_bytes: 25612
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   string s,t;
   cin>>s>>t;
   t=t.substr(0,t.length()-1);
   if(s == t)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;

}


Measured memory_bytes: 3656
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

const int nax=1e5+5;
ll dp[111][nax];
int n,w;
ll ww[111];
ll val[111];

int main()
{
    cin>>n>>w;
    for(int i=1;i<=n;i++) cin>>ww[i]>>val[i];
    for(int i=0;i<nax;i++) dp[0][i]=1e18;
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<nax;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(val[i]>j) continue;
            dp[i][j]=min(dp[i][j],dp[i-1][j-val[i]]+ww[i]);
        }
    }
    ll res=0;
    for(int i=0;i<nax;i++)
    {
        if(dp[n][i]<=w) res=i;
    }
    cout<<res;
}


Measured memory_bytes: 80128
while true
    numbers = gets.split.map(&:to_i)
    if numbers[0] == 0 && numbers[1] == 0
        break
    else
        puts "#"*numbers[1]
        (numbers[0]-2).times do
            puts "#"+"."*(numbers[1]-2)+"#"
        end
        puts "#"*numbers[1]
    end
    puts ""
end


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

int main() {
  vector<int>color(3);
  int ans;
  ans=0;
  for(int i=0;i<3;i++){
    cin>>color.at(i);
  }
 if(color.at(0)!=color.at(1)){
   ans++;
 }
  if(color.at(1)!=color.at(2)){
    ans++;
  }
  if(color.at(2)!=color.at(0)){
    ans++;
  }
  if(color.at(0)==color.at(1)&&color.at(1)==color.at(2)){
    ans++;
  }
  cout<<ans<<endl;
}

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

void dfs(uint32_t N, std::string str = "", uint32_t last = 0) {
  if (str.size() == N) {
    std::cout << str << std::endl;
    return;
  }

  for (uint32_t i = 0; i <= last; i++)
    dfs(N, str + static_cast<char>('a' + i), std::max(i + 1, last));

  return;
}

int main() {
  uint32_t N = 0;
  std::cin >> N;

  dfs(N);

  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

const int mod=1e9+7;
const int sz=200005;

int fact[sz],inv[sz],ifact[sz];

void make(){
    fact[0]=fact[1]=inv[1]=ifact[0]=ifact[1]=1;
    for(int i=2;i<sz;i++){
        fact[i]=fact[i-1]*i%mod;
        inv[i]=inv[mod%i]*(mod-mod/i)%mod;
        ifact[i]=ifact[i-1]*inv[i]%mod;
    }
}

int comb(int n,int k){
    if(n<k) return 0;
    return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
}

void add(int &a,int b)
{
    a=(a+b)%mod;
}

signed main()
{
    make();

    int N,M,K; cin>>N>>M>>K;
    int ans=0;
    for(int d=1;d<N;d++){
        int tmp=d*(N-d)%mod*M%mod*M%mod*comb(N*M-2,K-2)%mod;
        add(ans,tmp);
    }
    for(int d=1;d<M;d++){
        int tmp=d*(M-d)%mod*N%mod*N%mod*comb(N*M-2,K-2)%mod;
        add(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
A = [list(map(int, input().split())) for _ in range(3)]
ans = [[0 for i in range(3)] for j in range(3)]
N = int(input())
for i in range(N):
  a = int(input())
  for j in range(3):
    for k in range(3):
      if a == A[j][k]:
        ans[j][k] = 1

flag = 0
for i in range(3):
  if sum(ans[i]) == 3:
    flag = 1
  if sum(ans[j][i] for j in range(3)) == 3:
    flag = 1
if ans[0][0] * ans[1][1] * ans[2][2] == 1:
  flag = 1
  
if ans[2][0] * ans[1][1] * ans[0][2] == 1:
  flag = 1

if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3192
N = int(input())
buildings = [[[0 for V in range(10)] for F in range(3)] for B in range(4)]
for i in range(N):
 b, f, r, num = map(int, input().split())
 buildings[b-1][f-1][r-1] += num

for i in range(4):
 for j in range(3):
  for k in range(10):
   print(" {0}".format(buildings[i][j][k]), end="")
  print()
 if i!=3:
  print("####################")

Measured memory_bytes: 7780
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
long long dp[55][2];
int a[55];
int n,i,j;
bool p;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n>>p;
	dp[0][0]=1;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<=n;i++){
		for(j=0;j<2;j++){
			if(dp[i-1][j]!=0) dp[i][(j+a[i])%2]+=dp[i-1][j];
			dp[i][j]+=dp[i-1][j];
		}
	}
	cout<<dp[n][p]<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

A, B = mi()

print(A + B // 2)

Measured memory_bytes: 8876
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   int ans = m - n;
  
 int sum = 0;
  
for(int i = 1;i<= ans;i++){
     

   sum+=i;
}

   cout << sum-m << endl;

  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    // 探索先データを入力
    int data_number = Integer.parseInt(scan.next());
    int data[] = new int[data_number];
    for (int i = 0; i < data_number; i++) {
      data[i] = Integer.parseInt(scan.next());
    }
    // 探索データを入力
    int search_key_number  = Integer.parseInt(scan.next());
    int search_key[] = new int[search_key_number];
    for (int i = 0; i < search_key_number; i++) {
      search_key[i] = Integer.parseInt(scan.next());
    }
    // 探索を開始
    int count = 0;
    for (int i = 0; i < search_key_number; i++) {
      if (BinarySearch(search_key[i], data, data_number) != -1) {
        count++;
      }
    }

    System.out.println(count);
  }

  private static int BinarySearch(int search_key, int data[], int data_number) {
    int left = 0, right = data_number, mid = 0;

    while (left < right) {
      mid = (left + right) / 2;
      if (data[mid] < search_key) {
        left = mid + 1;
      } else if (search_key < data[mid]) {
        right = mid;
      } else {
        return mid;
      }
    }

    return -1;
  }
}



Measured memory_bytes: 70396
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

int N;
int A[2000010];
bool flg[2000010];

void func(int n)
{
	int cur = n;
	while (true)
	{
		flg[cur] = true;
		cur += n;
		if (cur > 2000000)
		{
			break;
		}
	}
}

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];
	ARY_SORT(A, N);


	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (flg[A[i]])
		{
			continue;
		}

		if (i < N - 1 && A[i] == A[i + 1])
		{
			func(A[i]);
			continue;
		}

		ans++;
		func(A[i]);
	}

	cout << ans << endl;
}



Measured memory_bytes: 7152
import math

def to_binary(n,N):
    B=[]
    for i in range(N):
        B=[n%2]+B
        n//=2

    return B

def list_sum(A,N,M,L):
    U=[0 for j in range(M)]
    
    for i in range(N):
        if L[i]==1:
            for j in range(M):
                U[j]+=A[i][j]
    return U

def inner(A,B):
    n=len(A)
    S=0
    for i in range(n):
        S+=A[i]*B[i]
    return S

N,M,X=map(int,input().split())
C=[]
A=[]

for i in range(N):
    T=list(map(int,input().split()))
    C.append(T[0])
    A.append(T[1:])

J=math.inf
for i in range(2**N):
    L=to_binary(i,N)
    U=list_sum(A,N,M,L)
    if min(U)>=X:
        J=min(J,inner(C,L))

if J==math.inf:
    print(-1)
else:
    print(J)
    


Measured memory_bytes: 69812
#include<stdio.h>
int main(){
  char s[100010]={};
  int i,j;
  scanf("%s",s);
  for(i=0;s[i];i++){
    int b[300]={};
    for(j=0;j<8;j++)b[s[i+j]]++;
    if(b['A']==2&&b['I']&&b['D']&&b['U']&&b['N']==2&&b['Y']){
      printf("AIZUNYAN");
      i+=7;
    }
    else printf("%c",s[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 632
from bisect import bisect_left, bisect_right

n = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

count = 0

for b in B:
    a_num = bisect_left(A, b)
    c_num = n - bisect_right(C, b)
    count += a_num * c_num
print(count)


Measured memory_bytes: 23348
#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;

int main(){
    cout<< fixed << setprecision(20);

    double a, b, h, m;
    cin >> a >> b >> h >> m;

    //double rot = m/60 - (h/12 + m/(12*60));
    double rot = (h/12 + m/(12*60)) - m/60;
    //if (rot<0){
    //    rot = -1 * rot;
    //}
    //if (0.5<rot){
    //    rot = 1 - rot;
    //}

    double pi = 3.141592653589793238;
    double cosc;
    cosc = cos(2*pi*rot);

    double c;
    c = sqrt(a*a + b*b - 2*b*c*cosc);
    c = a*a + b*b - 2*a*b*cosc;
    c = sqrt(c);

    //cout << h/12 + m/(12*60) << endl;
    //cout << m/60 << endl;
    //cout << rot << endl;
    //cout << cosc << endl;
    cout << c << endl;
}

Measured memory_bytes: 4188
//╔╗───────────╔╗────────────────────╔╗─
//║║──────────╔╝╚╗──────────────────╔╝╚╗
//║╚═╗╔══╗╔══╗╚╗╔╝╔══╗╔═╗╔╗╔╗╔══╗ ╔╗╚╗╔╝
//║╔╗║║╔╗║║╔╗║─║║─║║═╣║╔╝║╚╝║║╔╗║─╣║─║║─
//║╚╝║║╔╗║║║║║─║╚╗║║═╣║║─║║║║║╚╝║─║║─║╚╗
//╚══╝╚╝╚╝╚╝╚╝─╚═╝╚══╝╚╝─╚╩╩╝╚══╝─╚╝─╚═╝ 

#include <bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
    IO;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d);
    return 0;
}


Measured memory_bytes: 256
import sys
import math

A, B = map(int, sys.stdin.readline().split())
gcd = math.gcd(A, B)


def factrization_prime(number):
    factor = {}
    div = 2
    s = math.sqrt(number)
    # print(s)
    while div < s:
        div_cnt = 0
        while number % div == 0:
            div_cnt += 1
            number //= div
        if div_cnt != 0:
            factor[div] = div_cnt
        div += 1
    if number > 1:
        factor[number] = 1
    return factor

factors = factrization_prime(gcd)
print(len(factors) + 1)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<int64_t>A(N);
  int64_t right=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    right+=A[i];
  }
  int64_t left=0;int64_t ans=9999999999999;
  for(int i=0;i<N;i++){
    left+=A[i];right-=A[i];
    if(abs(right-left)<ans){ans=abs(right-left);}
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
struct cube
{
    vector< string > v;
    int E = 2,S=1,U=0;
    void rotate( char C )
    {
        int a=E, b=S;
        switch(C)
        {
            case 'E':E=U;U=5-a;break;
            case 'S':S=U;U=5-b;break;
            case 'L':E=S;S=5-a;break;
        }
    }
    bool operator==(cube b)
    {
        for( int i = 0; i < 2; i++ )
        {
            for(int i=0;i<4;i++)
            {
                for(int i = 0; i < 4; i++ )
                {
                    if (v[E] == b.v[b.E] && v[5 - E] == b.v[5 - b.E] && v[S] == b.v[b.S] && v[5 - S] == b.v[5 - b.S] && v[U] == b.v[b.U] && v[5 - U] == b.v[5 - b.U])return true;
                    rotate('S');
                }
                rotate('E');
            }
            rotate('L');
        }
        return false;
    }
};
cube s[30];
bool used[30];
main()
{
    int n;
    while( cin >> n, n )
    {
        for( int i = 0; i < n; i++ )
        {
            s[i].v = vector< string > (6);
            for( int j = 0; j < 6; j++ )cin >> s[i].v[j];
            
        }
            vector< int > v[30];
            for( int i = 0; i < n; i++ )
            {
                for( int j = i + 1; j < n; j++ )
                {
                    if( s[i] == s[j] )v[i].emplace_back( j );
                }
            }
            int cnt = 0;
            memset( used, 0, sizeof( used ) );
            for( int i = 0; i < n; i++ )
            {
                if( used[i] )continue;
                cnt++;
                for( int  j : v[i] )
                {
                    used[j] = true;
                }
            }
            printf( "%d\n", n - cnt );
    }
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define s(n) scanf("%d", &n)
#define sc(n) scanf("%c", &n)
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define ss(n) scanf("%s", n)
#define INF (int)1e9
#define EPS 1e-9
#define bitcount __builtin_popcount
#define gcd __gcd
#define n_mod(a, k) ((a % k) + k) % k
#define mod(a, k) (a % k)
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define LSOne(S) (S & (-S))
#define repa(v) lpi(i, 0, sz(v)) lpi(j, 0, sz(v[i]))
#define P(x) cout << #x << " = { " << x << " }\n"
#define PB push_back
#define MP make_pair
#define M_PI 3.14159265358979323846
#define fast_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define file_IO                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<string> vs;
int dcmp(double x, double y)
{
    return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}
const int MAX = 1e5 + 10;
ll memo[110][MAX];
int n, w;
ll wei[110];
ll val[110];
ll dp(int i, int ww)
{
    if (i == n)
    {
        return 0;
    }
    ll &ret = memo[i][ww];
    if (ret != -1)
        return ret;
    ll path1 = -INF;
    ll path2 = -INF;
    if (wei[i] <= ww)
    {
        path1 = dp(i + 1, ww - wei[i]) + val[i];
    }
    path2 = dp(i + 1, ww);
    return ret = max(path2, path1);
}
int main()
{
    // #ifndef ONLINE_JUDGE
    //     file_IO;
    // #else
    //     fast_IO;
    // #endif
    //file_IO;
    fast_IO;
    clr(memo, -1);
    cin >> n >> w;
    lp(i, n)
    {
        cin >> wei[i] >> val[i];
    }
    cout << dp(0, w) << '\n';
}

Measured memory_bytes: 86272
import collections as c
ip = lambda : map(int, input().split())
# ##############

N,K = ip()
R,S,P = ip()
T = input()
ans = 0

p = {'r':P,
     's':R,
     'p':S,
     'c':0}

for i in range(K):
    ans += p[T[i]]
    # print(ans)

for i in range(K,N):
    # print(T[i])
    if T[i] == T[i-K]:
        T = T[:i] + 'c' + T[i+1:]
    else:
        ans += p[T[i]]
    # print(ans)
print(ans)

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dp[1<<20];
int main (){
  int n,m;
  cin >> n >> m;
  int nsum[20][n+1];
  for(int i = 0; i < 20; i++){
    nsum[i][0] = 0;
  }
  for(int i = 1; i < 1<<20; i++){
    dp[i] = 10000009;
  }
  for(int i = 1; i <= n; i++){
    int a;
    cin >> a;
    for(int j = 0; j < m; j++){
      nsum[j][i] = nsum[j][i-1]+(a-1==j);
    }
  }
  for(int i = 0; i < 1<<m;i++){
    for(int j = 0; j < m;j++){
      if(1<<j&i)continue;
      int l = 0;
      for(int k = 0; k < m; k++)if(1<<k&i)l += nsum[k][n];
      dp[i+(1<<j)] = min(dp[i+(1<<j)],dp[i]+nsum[j][n]-(nsum[j][l+nsum[j][n]]-nsum[j][l]));
    }
  }
  cout << dp[(1<<m)-1]<<endl;
}



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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define enter '\n'
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << enter
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << enter
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 304001, mod = 1e9 + 7;
 std::map < pair < int, int >, int > mp;
 int h, w, m, cnt1[ N ], cnt2[ N ], mx1, mx2;
 void Fakemain( )
 {
  srand( time( 0 ) );
  IOS;
  cin >> h >> w >> m;
  int a, b;
  For( i, 1, m )
   cin >> a >> b,
   mp[ make_pair( a, b ) ] = 1,
   mx1 = std::max( mx1, ++cnt1[ a ] ),
   mx2 = std::max( mx2, ++cnt2[ b ] );
  vector < int > v1, v2;
  For( i, 1, h )
   if( cnt1[ i ] == mx1 )
    v1.push_back( i );
  For( j, 1, w )
   if( cnt2[ j ] == mx2 )
    v2.push_back( j );
  random_shuffle( v1.begin( ), v1.end( ) );
  random_shuffle( v2.begin( ), v2.end( ) );
  int ans = 0;
  for( auto &i: v1 )
  {
   for( auto &j: v2 )
   {
    if( !mp[ make_pair( i, j ) ] )
    {
     cout << mx1 + mx2;
     return;
    }
   }
  }
  cout << mx1 + mx2 - 1;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

Measured memory_bytes: 28476
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S,T;

signed main(){
	cin>>S>>T;
	int ans=INF;
	REP(i,S.size()-T.size()+1){
		string s=S.substr(i,(int)T.size());
		int cnt=0;
		REP(j,T.size()){
			if(s[j]!=T[j]){
				cnt++;
			}
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    if(N >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s);i<(e);i++)
#define rep(i,n) REP(i,0,n)

const long long mod = 1000000007;
vector<bool> A;
vector<int> memo;

long long solve(int n) {
  if (n < 0 || A[n]) return 0;
  if (n == 0) return 1;

  if (memo[n] != -1)
    return memo[n];

  memo[n] = (solve(n - 1) + solve(n - 2)) % mod;
  return memo[n];
}

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

  A.resize(N);
  memo.resize(N+1);
  fill(memo.begin(), memo.end(), -1);

  rep(i, M) {
    int a; cin >> a;
    A[a] = true;
  }

  cout << solve(N) << endl;
}


Measured memory_bytes: 5376
#include <iostream>
#include <math.h>
using namespace std;
int main(void){

    
  int K , A , B , rem , diff;  
  cin >> K >> A >> B;
  rem = A % K;
  if(rem != 0)
  	rem = K - rem;
  diff = B - A;
  if(diff >= rem)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3104
n, m = map(int, input().split())
if m%2 == 1:
  for i in range(int((m-1)/2)):
    print(str(i+1) + ' ' + str(m-i))
  for i in range(int((m+1)/2)):
    print(str(m+i+1) + ' ' + str(2*m-i+1))
else:
  for i in range(int(m/2)):
    print(str(i+1) + ' ' + str(m-i+1))
  for i in range(int(m/2)):
    print(str(i+m+2) + ' ' + str(2*m-i+1))

Measured memory_bytes: 9224
n,k=map(int,input().split())
MOD=(10**9)+7

ans=0
for i in range(k,n+2):
    min_sum=i*(i-1)//2
    max_sum=i*(n+(n-i+1))//2
#    print(i,min_sum,max_sum,max_sum-min_sum+1)
    ans=(ans+(max_sum-min_sum+1))%MOD
print(ans)

Measured memory_bytes: 9192
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class  Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int n = Integer.parseInt(sc.nextLine());
            Node[] ns = new Node[n];
            for (int i = 0; i < n; i++) {
                ns[i] = new Node();
            }
            while (sc.hasNext()) {
                int[] id_l_r = Stream.of(sc.nextLine().split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
                ns[id_l_r[0]].left = id_l_r[1];
                ns[id_l_r[0]].right = id_l_r[2];
                if (id_l_r[1] != -1) {
                    ns[id_l_r[1]].parent = id_l_r[0];
                }
                if (id_l_r[2] != -1) {
                    ns[id_l_r[2]].parent = id_l_r[0];
                }
            }
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (ns[i].parent == -1) {
                    r = i;
                }
            }
            System.out.println("Preorder");
            printPreorder(ns, r);
            System.out.println();
            System.out.println("Inorder");
            printInorder(ns, r);
            System.out.println();
            System.out.println("Postorder");
            printPostorder(ns, r);
            System.out.println();
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static class Node {
        Node() {}
        int parent = -1, left = -1, right = -1;
    }

    private static void printPreorder(Node[] ns, int r) {
        System.out.printf(" %d", r);
        if (ns[r].left != -1) {
            printPreorder(ns, ns[r].left);
        }
        if (ns[r].right != -1) {
            printPreorder(ns, ns[r].right);
        }
    }

    private static void printInorder(Node[] ns, int r) {
        if (ns[r].left != -1) {
            printInorder(ns, ns[r].left);
        }
        System.out.printf(" %d", r);
        if (ns[r].right != -1) {
            printInorder(ns, ns[r].right);
        }
    }

    private static void printPostorder(Node[] ns, int r) {
        if (ns[r].left != -1) {
            printPostorder(ns, ns[r].left);
        }
        if (ns[r].right != -1) {
            printPostorder(ns, ns[r].right);
        }
        System.out.printf(" %d", r);
    }
}



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

int powAB(int A, int B){
	int X = A - B;
	if(X < 0) X *= (-1);
	return X;
}

int main(){
	int N;
	cin >> N;
	vector<int> W(N);
	int sum = 0;
	
	for(int i = 0; i < N; i++){
		cin >> W.at(i);
		sum += W.at(i);
	}
	
	int comsum = 0;
	int ans = 101;
	for(int i = 0; i < N; i++){
		comsum += W.at(i);
		int dis = sum - comsum;
		int powN = powAB(dis, comsum);
		ans = min(ans, powN);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>

// Definitions
#define MAXN
#define elif else if
typedef long long int64;
typedef long double num128;
typedef unsigned long long uint64;

// Variables
int n;

// Improve the speed of read-in.
inline bool IsNum(char x) { return ('0' <= x) && (x <= '9'); }
inline int64 ReadNum() {
  int64 sign = 1, val = 0; char tmp = getchar();
  while (!IsNum(tmp)) { if (tmp == '-') {sign = -sign;} tmp = getchar(); }
  while (IsNum(tmp)) { val = val * 10 + tmp - 48; tmp = getchar(); }
  return val * sign;
}

// Functions
inline void ReadIn() {
  n = ReadNum();
}
inline void PrintAns() {
  if (n >= 30) {
    puts("Yes");
  } else {
    puts("No");
  }
}

int main() {
  ReadIn();
  PrintAns();
  return 0;
}
/*

*/


Measured memory_bytes: 3596
N=int(input())

for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*h*n-N*n-N*h
    if tmp==0:
      continue
    else:
      w=N*h*n/tmp
      
    if w>0 and w.is_integer():
      print(h,n,int(w))
      exit()

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

int main(){
  string N;
  cin >> N;
  if(N == "SUN"){
    cout << 7 << endl;
  }
  else if(N == "MON"){
    cout << 6 << endl;
  }
  else if(N == "TUE"){
    cout << 5 << endl;
  }
  else if(N == "WED"){
    cout << 4 << endl;
  }
  else if(N == "THU"){
    cout << 3 << endl;
  }
  else if(N == "FRI"){
    cout << 2 << endl;
  }
  else if(N == "SAT"){
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
	IOS
    int n;
    while(cin>>n)
    {
        int v[n];
        int c[n];
        for(int i=0;i<n;i++)
        {
            cin>>v[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>c[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            if(c[i]<v[i]) sum+= v[i]-c[i];
        }
        cout << sum <<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>
#include <cmath>

#define EPS (1e-6)

void solveSimultaneousEquation(double a, double b, double c, double d, double e, double f, 
                               std::pair<double, double>* pResult)
{
  assert(b * d - a * e != 0);
  std::pair<double, double>& result = *pResult;

  result.first = (b * f - c * e) / (b * d - a * e);
  result.second = (c * d - a * f) / (b * d - a * e);

  if (fabs(result.first) < EPS) {
    result.first = 0.0;
  }
  if (fabs(result.second) < EPS) {
    result.first = 0.0;
  }
}

int main(void)
{
  double a, b, c, d, e, f;

  while (std::cin >> a >> b >> c >> d >> e >> f) {
    std::pair<double, double> result;
    solveSimultaneousEquation(a, b, c, d, e, f, &result);
    std::cout << std::fixed << std::setprecision(3) << result.first << " " << result.second << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1280