akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#define sc(n) scanf("%d",&n)
#define sc2(x,y) scanf("%d %d",&x,&y)
#define fornt(i,n) for(i=0; i<n; ++i)
using namespace std;


int main ()
{
   int a,sum;
   sc(a);
   sum = 1000*(a/1000) + 1000*(min(1,a%1000));
   sum = sum-a;
   printf("%d\n",sum);
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int r;
	cin >> r;
	cout << r * r << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int h, w, l, r;
multiset<int> val;
map<int, int> from;

int main() {
	fastio; cin >> h >> w;
	FOR(i, 1, w) {
		val.insert(0);
		from[i] = i;
	}
	FOR(i, 1, h) {
		cin >> l >> r;
		auto it = from.lower_bound(l);
		int best = -1;
		while (it != from.end() and it->f <= r+1) {
			best = max(best, it->s);
			val.erase(val.find(it->f - it->s));
			from.erase(it++);
		}
		if (best != -1 and r < w) {
			val.insert(r - best + 1);
			from[r+1] = best;
		}
		cout << (val.empty() ? -1 : *val.begin() + i) << "\n";
	}
}


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

int main() {
  int x = 1, y = 1;
  while (1){
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    int big = (x > y)?x : y;
    int small = (x > y)?y : x;
    cout << small << " " << big << endl;
  }
  return 0;
}

Measured memory_bytes: 3064
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    # A:和、B:差
    A = [0] * N
    B = [0] * N
    for i in range(N):
        x, y = map(int, readline().split())
        A[i] = x+y
        B[i] = x-y

    ans = max(max(A)-min(A), max(B)-min(B))
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int x, n;
    set<int> p;
    int ans = -1;

    cin >> x >> n;
    for (int i = 0;i < n;i++) {
        int input;
        cin >> input;
        p.insert(input);
    }

    for (int i = 0;i < 100;i++) {
        int up = x + i;
        int down = x - i;
        if (p.find(up) == p.end()) {
            ans = up;
        }
        if (p.find(down) == p.end()) {
            ans = down;
        }
        if (ans != -1) break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
import string
a = raw_input()
b = ""
for i in range(len(a)):
    if a[i] in string.ascii_lowercase :
        b = b + a[i].upper()
    elif a[i] in string.ascii_uppercase :
        b = b + a[i].lower()
    else :
        b = b + a[i]

print b

Measured memory_bytes: 6472
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, a, b;
  cin >> n >> a >> b;
  if(a>b or (n==1 and a<b)) {cout << 0 << newl; return 0;}
  
  cout << (b-a)*(n-2)+1 << newl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &e : a) cin >> e;
  for (int i = 0; i + 1 < n; i++) a[i + 1] += a[i];
  ll r = 1e18;
  for (int i = 0; i + 1 < n; i++) r = min(r, abs((a[n - 1] - a[i]) - a[i]));
  cout << r << endl;
}


Measured memory_bytes: 1920
a, b= map(int, input().split())
num = abs(abs(a)-abs(b))
 
if a * b < 0:
    num += 1
elif a * b == 0 and a > b:
    num += 1
elif a * b > 0:
    if a < 0 and abs(a) < abs(b):
        num += 2
    elif a > 0 and abs(a) > abs(b):
        num += 2
print(num)

Measured memory_bytes: 9160
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    int MAX = 1073741823;
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m){
           cin >> a[i][j]; 
        }
    }
    int all = (1<<n);
    int ans = MAX/2;
    for(int s = 1; s < all; s++){
        vector<int> got(m,0);
        int need = 0;
        for (int i = 0; i < n; i++){
            if (s>>i & 1){
                need += c[i];
                for(int j = 0; j < m; j++){
                    got[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if (got[j] < x) ok = false;
        }
        if (ok) ans = min(ans,need);
    }
    
    if (ans == MAX/2) cout << -1;
    else cout << ans;
    
}










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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+1;
const int M = 1e9+7;

int n, W[100], val[100], w;
ll dp[MAX];
int main()
{
    _upgrade;
    cin>>n>>w;

    fill(dp, dp+w+1, -1);
    FOR(i, 0, n)
        cin>>W[i]>>val[i];
    dp[0] = 0;
    FOR(i, 0, n)
        for(int j = w; j-W[i] >= 0; --j)
            if(dp[j-W[i]] != -1)
                dp[j] = max(dp[j], dp[j-W[i]] + val[i]);
    ll res = 0;
    FOR(i, 0, w+1)
        res = max(res, dp[i]);
    cout<<res;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,m; cin >> n >> m;
	vi a(n); rep(i,n) cin >> a[i];
	int sum = 0;
	rep(i,n) sum += a[i];
	int thd = (sum+4*m-1) / (4*m);
	int cnt = 0;
	rep(i,n){
		if(a[i]>=thd) cnt++;
	}
	if(cnt>=m) cout << "Yes" << endl;
	else cout << "No" << endl;
}




Measured memory_bytes: 256
#import numpy as np
import sys
import math
from collections import defaultdict
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
coordinate = []
[coordinate.append(list(map(int,input().split()))) for _ in range(N)]

ans = 0
fa = 0

for x in list(itertools.permutations( [i for i in range(1,N+1)] , N)):
    for i in range(N-1):
        xx = coordinate[x[i]-1][0] - coordinate[x[i+1]-1][0]
        y = coordinate[x[i]-1][1] - coordinate[x[i+1]-1][1]
        ans += math.sqrt(xx**2 + y ** 2)
    fa += 1
print(ans/fa)



Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int n;
    cin>>n;
    int sum=0,pos=0;
    for(int i=1;i<=n;i++){
        sum=i*(i+1)/2;
        if(sum>=n) {
            pos=i;
            break;
        }
    }
    for(int i=1;i<=pos;i++){
        if(sum-n!=i)cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] classroom = new String[9];
		int[][] sum = new int[2][9];
		
		for(int i = 0; i < 9; i++){
			classroom[i] = sc.next();
			sum[0][i] = sc.nextInt();
			sum[1][i] = sc.nextInt();
		}
		for(int i = 0; i < 9; i++){
			System.out.println(classroom[i] + " " + (sum[0][i] + sum[1][i]) + " " + (sum[0][i] * 200 +  sum[1][i] * 300));
		}
		sc.close();
	}
}

Measured memory_bytes: 17176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main(){
  int N ;
  cin >> N ;
  vector<int> V(N) ; 
  vector<int> C(N) ;
   
  rep(i,N) cin >> V.at(i) ;
  rep(i,N) cin >> C.at(i) ;
  int sum = 0 ;
  rep(i,N)  if( V.at(i) - C.at(i) >= 0 ) sum += V.at(i) - C.at(i) ;
  cout << sum << endl ;
}
  

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int N, A, B, C;
int ans = INT_MAX;

void go(const vi& len, vi& use, int inx) {
    if (inx == N) {
        int a = 0, b = 0, c = 0;
        int ap = 0, bp = 0, cp = 0;

        for (int i = 0; i < N; i++) {
            if (use[i] == 1) a += len[i], ap++;
            else if (use[i] == 2) b += len[i], bp++;
            else if (use[i] == 3) c += len[i], cp++;
        }
        if (ap == 0 || bp == 0 || cp == 0) return;

        int cost = (ap + bp + cp - 3) * 10;
        cost += abs(A - a) + abs(B - b) + abs(C - c);
        ans = min(ans, cost);
    } else {
        for (use[inx] = 0; use[inx] < 4; use[inx]++)
            go(len, use, inx + 1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> N >> A >> B >> C;

    vi len(N);
    for (int i = 0; i < N; i++) {
        cin >> len[i];
    }

    vi use(N);
    go(len, use, 0);
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

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

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

int main() {
	string s;
	char a[25];
	int b,c;
	c = 0;
	cin >> s;
	b = s.size();
	for (int x = 0; x < b; ++x) {
		a[x] = s[x];
		for (int y = 0; y < x; ++y) {
			if (s[x] == a[y]) {
				c = 1;
			}
			if (c == 1)break;
		}
		if (c == 1)break;
	}
	if (c == 1)cout << "no" << endl;
	else cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define F first
#define S second
int X,Y,Z,A,B,C,N;
int imos[2][1111];
void add(int f,int x,int l,int k){
  //if(!f&&k) cout<<"-"<<f<<":"<<x<<" "<<l<<" "<<k<<endl;
  imos[f][x]+=k;
  if(x+l<=N) imos[f][x+l]-=k;
  else{
    int y=(x+l)%N;
    imos[f][N]-=k;
    imos[f][0]+=k;
    imos[f][y]-=k;
  }
}
P  calc(P p,P q){
  int x=p.F,y=p.S;
  int a=q.F,b=q.S;
  return P(((x-y)-(a-b))/2,((x+y)-(a+b))/2);
}
signed main(){
  cin>>X>>Y>>Z>>A>>B>>C>>N;
  
  memset(imos,0,sizeof(imos));
  for(int i=0;i<(X+Y-1);i++){
    int all=0;
    P ub(i,0);
    if(i>=X) ub=P(X-1,i-(X-1));
    P lb(0,i);
    if(i>=Y) lb=P(i-(Y-1),Y-1);

    /*/
    cout<<i<<":"<<endl;
    cout<<ub.F<<" "<<ub.S<<endl;
    cout<<lb.F<<" "<<lb.S<<endl;
    //*/    

    if(abs(A+B-i)%2){
      P p=calc(ub,P(A-1,B));
      P q=calc(lb,P(A-1,B));
      //cout<<p.F<<" "<<p.S<<":"<<q.F<<" "<<q.S<<endl;
      assert(p.S==q.S);
      int x=abs(p.S);
      if(0<p.S) x--;
      int u=p.F,v=q.F;
      //cout<<u<<" "<<v<<" "<<x<<endl;
      if(0<u){
	u--;
	add(1,x%N,1,min(u+1,x+1));
	if(x<u){
	  int k=u-x;
	  all+=k/N;
	  add(1,(x+1)%N,k%N,1);
	}
	u++;
      }
      v--;
      if(0<v){
	v--;
	add(1,x%N,1,-min(v+1,x+1));
	if(x<v){
	  int k=v-x;
	  all-=k/N;
	  add(1,(x+1)%N,k%N,-1);
	}
	v++;
      }
      v++;
      if(v<=0){
	add(1,x%N,1,min(-v+1,x+1));
	if(x<-v){
	  int k=-v-x;
	  all+=k/N;
	  add(1,(x+1)%N,k%N,1);
	}
      }
      u++;
      if(u<=0){
	add(1,x%N,1,-min(-u+1,x+1));
	if(x<-u){
	  int k=-u-x;
	  all-=k/N;
	  add(1,(x+1)%N,k%N,-1);
	}
      }
      u--;
      add(1,0,N,all);
    }else{
      P p=calc(ub,P(A,B));
      P q=calc(lb,P(A,B));
      //cout<<p.F<<" "<<p.S<<":"<<q.F<<" "<<q.S<<endl;
      assert(p.S==q.S);
      int x=abs(p.S);
      int u=p.F,v=q.F;
      if(v<=0&&0<=u) add(0,x%N,1,1);
      //cout<<u<<" "<<v<<" "<<x<<endl;
      if(0<u){
	add(0,x%N,1,min(u,x));
	if(x<u){
	  int k=u-x;
	  all+=k/N;
	  add(0,(x+1)%N,k%N,1);
	}
      }
      v--;
      if(0<v){
	add(0,x%N,1,-min(v,x));
	if(x<v){
	  int k=v-x;
	  all-=k/N;
	  add(0,(x+1)%N,k%N,-1);
	}
      }
      v++;
      if(v<0){
	add(0,x%N,1,min(-v,x));
	if(x<-v){
	  int k=-v-x;
	  all+=k/N;
	  add(0,(x+1)%N,k%N,1);
	}
      }
      u++;
      if(u<0){
	add(0,x%N,1,-min(-u,x));
	if(x<-u){
	  int k=-u-x;
	  all-=k/N;
	  add(0,(x+1)%N,k%N,-1);
	}
      }
      u--;
      add(0,0,N,all); 
    }
  }

  for(int k=0;k<2;k++) 
    for(int i=0;i<N;i++)
      imos[k][i+1]+=imos[k][i];
  
  int e[N];
  memset(e,0,sizeof(e));
  for(int k=0;k<2;k++) 
    for(int i=0;i<N;i++)
      e[(i*2+k)%N]+=imos[k][i];

  //for(int i=0;i<N;i++) cout<<i<<":"<<e[i]<<endl;
  
  int g[N];
  memset(g,0,sizeof(g));
  for(int i=0;i<Z;i++) g[abs(C-i)%N]++;

  int ans[N];
  memset(ans,0,sizeof(ans));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      ans[(i+j)%N]+=e[i]*g[j];
  for(int i=0;i<N;i++)
    cout<<ans[i]<<" \n"[i==N-1];
  return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector <string> VS;
typedef vector <int> VI;
typedef vector <VI> VVI;
template <class T> T gcd( T a, T b ) { return !b ? a : gcd( b, a % b ); }
template <class T> T lcm( T a, T b ){ return a / gcd( a, b ) * b; }
template <class T> string print_v( vector<T> v ) { OSS oss; for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++ it_i ) { oss << *it_i << ", "; } return oss.str(); }

int main() {
    int sa = 0, sb = 0;
    for ( int i = 0; i < 4; ++ i ) {
        int a;
        cin >> a;
        sa += a;
    }
    for ( int i = 0; i < 4; ++ i ) {
        int b;
        cin >>  b;
        sb += b;
    }
    cout << max( sa, sb ) << endl;
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    int x;
    cin >> x;
    int ans;
    bool flag = true;
    while(flag) {
        if(IsPrime(x)) {
            ans = x;
            flag = false;
        }
        else {
            x++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

dist = [-1]*n
q = deque([])
cnt = 0

#連結成分のカウント

for i in range(n):
    if dist[i] != -1:
        continue
    dist[i] = 0
    q.append(i)
    while q:
        v = q.pop()
        s = g[v]
        for j in s:
            if dist[j] != -1:
                continue
            dist[j] = 0
            q.append(j)
    cnt += 1

print(cnt - 1)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, T;
    cin >> N >> T;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    sort(items.begin(), items.end());
    vector<vector<ll>> dp(N + 1, vector<ll>(6005, 0));
    rep(i, N) {
        P p = items[i];
        rep(j, T + 3005) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j < T) {
                dp[i + 1][j + p.first] = max(dp[i + 1][j + p.first], dp[i][j] + p.second);
            }
        }
    }
    ll ans = 0;
    rep(i, 6005) {
        ans = max(ans, dp[N][i]);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 141184
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    let c: usize = scan(tokens);
    if a + b + c <= 21 {
        println!("win");
    } else {
        println!("bust");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long ll;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    int ans = 0;
    int MIN = 1e9 + 7;
    for (int i = 0; i < N; i++) {
        MIN = min(MIN, P[i]);
        if (P[i] <= MIN) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll a,b,c,k;
     cin>>a>>b>>c>>k;
     if(k<=a)
        cout<<k<<endl;
     else if(k>a && k<=a+b)
        cout<<a<<endl;
     else if(k>a+b)
     {
         cout<<a-(k-(a+b))<<endl;
     }
}



Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x,y,sum=1,n=0;//存储两个整数
    scanf("%d%d",&x,&y);
//采取累加的办法
    while(sum<y)
    {
      sum+=x-1;
      ++n;
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

 class Main {

	public static void main(String[] args) {

		// get user input
		List<List<Integer>> userInputs = getUserInputs();
		for (List<Integer> triangleSides : userInputs) {
			// check whether triagle is rightAngleTriable or not
			boolean isRightAngleTrangle = isRightAngleTraingle(triangleSides);
			if (isRightAngleTrangle) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}


	private static boolean isRightAngleTraingle(List<Integer> intList) {
		if(intList == null || intList.isEmpty() || intList.size() != 3){
			return false;
		}
		Collections.sort(intList);
		
		int aSide = intList.get(0);
		int bSide = intList.get(1);
		int cSide = intList.get(2);
		if ((cSide * cSide) == ((aSide * aSide) + (bSide * bSide))) {
			return true;
		}
		return false;
	}

	
	private static List<List<Integer>> getUserInputs() {
		int repetation = 0;
		List<List<Integer>> returnList = new ArrayList<>();

		// get user input
		List<String> userList = new ArrayList<String>();
		{
			Scanner in = new Scanner(System.in);
			String sNum = in.nextLine();
			repetation = Integer.parseInt(sNum);
			
			for (int i = 0; i < repetation; i++) {
				userList.add(in.nextLine());
			}
		}
		// convert string into Integer
		{

			for (String input : userList) {
				input = input.trim();
				if(input.length() == 0){
					continue;
				}
				String array[] = input.split("\\s+");
				ArrayList<Integer> intList = new ArrayList<Integer>();
				for (int i = 0; i < array.length; i++) {
					String num = array[i];					
					intList.add(Integer.parseInt(num.trim()));
				}
				returnList.add(intList);
			}
		}
		return returnList;
	}

}

Measured memory_bytes: 33176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<31;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

int main() {
    int n; cin >> n;
    mint ans = 0;
    ans += mint(10).pow(n) + mint(8).pow(n) - mint(9).pow(n)*2;
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (a+b==c+d)
		cout<<"Balanced";
	if (a+b<c+d)
		cout<<"Right";
	if (a+b>c+d)
		cout<<"Left";
	return 0;
}

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

if N == 2:
    if K == 0:
        print (1)
        print (1, 2)
        exit()
    else:
        print (-1)
        exit()

if N == 3:
    if K == 0:
        print (3)
        print (1, 2)
        print (2, 3)
        print (1, 3)
        exit()
    elif K == 1:
        print(2)
        print (1, 2)
        print (2, 3)
        exit()
    else:
        print (-1)
        exit()

if N == 4:
    if K == 0:
        print (6)
        for i in range(1, 5):
            for j in range(i + 1, 5):
                print (i, j)
        exit()
    elif K == 1:
        print (5)
        for i in range(1, 5):
            for j in range(i + 1, 5):
                if i == 3 and j == 4:
                    pass
                else:
                    print (i, j)
        exit()
    elif K == 2:
        print (3)
        for i in range(1, 4):
            print (i, i + 1)
        exit()
    elif K == 3:
        print (3)
        for i in range(2, 5):
            print (1, i)
        exit()
    else:
        print (-1)
        exit()

edge = [[0] * N for _ in range(N)] #1: 辺あり, 0: 辺なし
# print (edge) 

#必要な辺が多すぎるとき
if ((N - 1) * (N -2))//2 < K:
    print (-1)
    exit()

def output(lst): #リストをもらって答えをアウトプットする
    count = 0
    for i in lst:
        for j in i:
            if j == 1:
                count += 1
    print (count)
    for i in range(N):
        for j in range(N):
            if lst[i][j] == 1:
                if i <= j:
                    print (i + 1, j + 1)
                else:
                    print (j + 1, i + 1)
    return

if N >= 5:
    if False:
        for i in range(N): #多角形を作成
            edge[i][(i+1)%N] = 1
        for i in range(N - K):
            edge[i][(i+2)%N] = 1
        output(edge)
        # print (edge)
        exit()
    else: # K > Nのとき
        for i in range(1, N): #1からすべての点に伸ばし、トータルで(n-1)C2の組を作る
            edge[0][i] = 1
        #あと何組減らさないといけないか
        res = ((N - 1) * (N - 2)) //2 - K
        #組を減らす必要があるときTrue
        if res > 0:
            flag = True
        else:
            flag = False
        
        tmp = 0
        while flag:
            tmp += 1
            for i in range(1, N):
                if res == 0:
                    flag = False
                    output(edge)
                    exit()
                if i + tmp < N:
                    if i != i + tmp and edge[i][i + tmp] == 0 and edge[i + tmp][i] == 0:
                        edge[i][i + tmp] = 1
                        res -= 1
                else:
                    if i != ((i + tmp) % N) + 1 and edge[i][((i + tmp) % N) + 1] == 0 and edge[((i + tmp) % N) + 1][i] == 0:
                        edge[i][((i + tmp) % N) + 1] = 1
                        res -= 1
        output(edge)
        exit()



Measured memory_bytes: 3848
s = input()
t = input()
change = len(t)
for x in range(len(s) - len(t) + 1):
    temp_change = 0
    for y in range(len(t)):
        if s[x+y] != t[y]:
            temp_change += 1
    if change > temp_change:
        change = temp_change
print(change)


Measured memory_bytes: 9084
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 1000000007;


int main() {
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i += 2) {
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
int n,m,l;
int p;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

int main(){
  cin >> n;
  ll ans = 0;
  n *= 2;
  rep(i,0,n)cin >> d[i];
  sort(d,d+n);
  int i = 0;
  while(1){
    if(i >= n)break;
    ans += min(d[i],d[i+1]);
    i += 2;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,S[50];
int combi(int,int);

int main()
{
  int num,key,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&num);
  for(i=0;i<num;i++)
    {
      scanf("%d",&key);
      if(combi(0,key)) printf("yes\n");
      else printf("no\n");
    }
  return 0;
}

int combi(int i,int k)
{
  int judge;
  if(k==0) return 1;
  if(i>=n) return 0;
  judge= combi(i+1,k) || combi(i+1,k-S[i]);
  return judge;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
int n;

string changes(int n){
	string res;
	stringstream ss;
	ss << n;
	ss >> res;
	return res;
}

int main(){
	while (cin >> n&&n){
		cin >> s;
		string t;
		REP(i, n){
			t = "";
			int co = 0;
			char c = s[0];
			REP(j, s.size()){
				if (s[j] != c){
					t += changes(co) + c;
					co = 1;
					c = s[j];
				}
				else co++;
				//cout << t << endl;
			}
			if (co > 0){
				t += changes(co) + c;
			}
			s = t;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
const int N=100001;
int n,c,ss[N],tt[N],cc[N],pre[2*N],a[2*N];
int main(){
    cin>>n>>c;
    for(int i=0;i<n;i++){
        cin>>ss[i]>>tt[i]>>cc[i];
    }
    memset(a,0,sizeof(a));
    for(int i=1;i<=c;i++){
        memset(pre,0,sizeof(pre));
        for(int j=0;j<n;j++){
            if(cc[j]!=i)continue;
            pre[ss[j]*2-1]++;
            pre[tt[j]*2]--;
        }
        for(int j=1;j<=2*N-2;j++){
            pre[j]+=pre[j-1];
            if(pre[j]>0)a[j]++;
        }
    }
    int ans=0;
    for(int i=1;i<=2*N-2;i++)ans=max(ans,a[i]);
    cout<<ans<<'\n';
}


Measured memory_bytes: 2944
#include<stdio.h>
int main(void){
    int w,h,i,j;
    while(1){
        scanf("%d %d",&h,&w);
        if(h==0&&w==0){
            break;
        }
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

void print(ll p){
    cout<<p<<endl;
}

int main(){
	ll n;cin>>n;
    ll w;cin>>w;
    vector<vector<ll>> dp(n+1,vector<ll>(w+10));
    rep(i,1,n+1){
        ll x,y;cin>>x>>y;
        rep(j,1,w+1){
            dp[i][j] = dp[i-1][j];
            if (j-x>=0) dp[i][j] = max(dp[i-1][j-x]+y,dp[i][j]);
        }
    }
    print(dp[n][w]);
}

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

int digit_sum(int n);

int main()
{
    int N;
    cin >> N;
    if (N % digit_sum(N) == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}
int digit_sum(int n)
{
    if (n < 10)
        return n;
    return digit_sum(n / 10) + n % 10;
}

Measured memory_bytes: 3612
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    nm = 0
    l = [int(i) for i in ipt().split()]
    for i in range(n):
        li = l[i]
        for j in range(i+1,n):
            lj = l[j]
            for k in range(j+1,n):
                lk = l[k]
                if li == lj or lj == lk or lk == li or li >= lj+lk or lj >= li+lk or lk >= lj+li:
                    continue
                else:
                    nm += 1

    print(nm)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 75440
import java.io.*
import java.util.*

const val MOD = 1000000007L
// K個の飴をN人で分け合う方法の数
// 各飴の数はai以下
// N~100, K~1e5

fun <T, R> Iterable<T>.scanLeft(initial: R, operation: (acc: R, T) -> R): Sequence<R> {
    var last = initial
    return this.asSequence().map { last = operation(last, it); last }
}

fun solve(N: Int, K: Int, a: IntArray) {
    // dp[i][j] i番目まででj個を分ける方法の数
    // dp[i][j] = sum(dp[i-1][j-k]){k=0~a[i]}
    val dp = Array(N + 1) { LongArray(K + 1) }
    val cumSum = Array(N + 1) { LongArray(K + 1) }
    dp[0][0] = 1L
    for (x in 0..K) cumSum[0][x] = 1L
    for (i in 1..N) {
        for (j in 0..K) {
            dp[i][j] = (cumSum[i - 1][j] - cumSum[i - 1].getOrElse(j - a[i-1] - 1) { 0L }) % MOD
            cumSum[i][j] = cumSum[i].getOrElse(j-1){ 0L } + dp[i][j]
        }
    }
    println(dp[N][K])
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val K = sc.next().toInt()
    val a = IntArray(N)
    for (i in 0 until N) {
        a[i] = sc.next().toInt()
    }
    solve(N, K, a)
}


Measured memory_bytes: 242620
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    int a = n/1000;
    int b = (n/100)%10;
    int c = (n/10)%10;
    int d = n%10;

    rep(i,2){
        rep(j,2){
            rep(k,2){
                int s = a;
                if(i)s += b;
                else  s -= b;
                if(j)s += c;
                else  s -= c;
                if(k)s += d;
                else  s -= d;
                if(s == 7){
                    cout << a;
                    if(i)cout << "+";
                    else  cout << "-";
                    cout << b;
                    if(j)cout << "+";
                    else  cout << "-";
                    cout << c;
                    if(k)cout << "+";
                    else  cout << "-";
                    cout << d;
                    cout << "=7" << endl;
                    return 0;
                }
            }
        }
    }

    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://abc079.contest.atcoder.jp/tasks/abc079_c
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d, p;
    int x, y;

    cin >> a >> b >> c >> d >> p;

    x = a * p;

    p <= c ? y = b : y = b + ((p - c) * d);

    cout << (x < y ? x : y) << endl;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e4 + 6;
ll dp[N][4];
int a[5], arr[5] =
{ 500, 100, 50 };
ll solve(int n, int ind)
{
	if (n == 0)
		return 1;
	if (n < 0 || ind == 3)
		return 0;
	ll &ret = dp[n][ind];
	if (ret != -1)
		return ret;
	ret = 0;
	for (int i = 0; i <= a[ind]; i++)
		ret += solve(n - (i * arr[ind]), ind + 1);
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	memset(dp, -1, sizeof dp);
	cin >> a[0] >> a[1] >> a[2];
	int x;
	cin >> x;
	cout << solve(x, 0);
	return 0;
}


Measured memory_bytes: 896
n,p = map(int,input().split())
a = [int(i) for i in input().split()]
odd = 0
evil = 0
for i in a:
    if i % 2== 0:
        evil += 1
    else:
        odd += 1
if p==1 and odd ==0:
    print(0)
elif evil ==n:
    print(pow(2,n))
else:
    print(pow(2,n-1))

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>

std::vector<long long> v;

bool isprime() {
	v.push_back(2);
	for (long long i = 3; i * i <= 1000000000000LL; i += 2)
	{
		bool flag = true;
		for (long long j = 3; j * j < i; j += 2)
		{
			if (j % i == 0) {
				flag = false;
			}
		}

		if (flag) {
			v.push_back(i);
		}

	}
	return true;
}

int main() {
	int r;
	

	std::cin >> r;

	std::cout << 3 * r * r << std::endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	k := nextInt()
	x := nextInt()
	for i := x - k + 1; i < x+k; i++ {
		if i >= -1000000 && i <= 1000000 {
			fmt.Print(i)
			if i != x+k-1 {
				fmt.Print(" ")
			}
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

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

    ll v[n+1],w[n+1],dp[n+1][W+1];

    loop(i,1,n+1)
        cin>>w[i]>>v[i];

    memset(dp,0,sizeof(dp)); 

    loop(i,1,n+1)
    {
        loop(j,1,W+1)
        {
            if(w[i]<=j)
                dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);

            else
                dp[i][j]=dp[i-1][j];
        }
    } 

    d1(dp[n][W]); 
}

Measured memory_bytes: 79104
#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++)
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;

int main() {
    string s, a;
    cin >> s >> a;
    int ans = 0;

    int n = s.size();
    rep(i, n) {
        if (s[i] != a[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3868
n,m=map(int,input().split())
cnt=[0]*26
for i in range(n):
	for j in input():
		cnt[ord(j)-ord('a')]+=1
if n%2==1: n,m=m,n
c4,c1=(n//2)*(m//2),m%2
if n%2:
	c2=(n//2)+(m//2)
elif m%2:
	c2=n//2
else:
	c2=0
for i in range(26):
	while c4>0 and cnt[i]>=4:
		cnt[i]-=4
		c4-=1
	while c2>0 and cnt[i]>=2:
		cnt[i]-=2
		c2-=1
	while c1>0 and cnt[i]>=1:
		cnt[i]-=1
		c1-=1
	if cnt[i]>0:
		print("No")
		quit()
print("Yes")

Measured memory_bytes: 39664
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, a, b;


int main()
{
	scanf("%d%d%d", &n, &a, &b);
	int ta = n * a;
	if (ta > b)
		printf("%d\n", b);
	else
		printf("%d\n", ta);
	
	return 0;
}


Measured memory_bytes: 128
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let n = io.read::<usize>();
    let mut a = io.readn::<i64>(n);
    let mut mx = INF;
    for &x in a.iter() {
        let mut y = x;
        let mut ret = 0;
        while y & 1 == 0 {
            y >>= 1;
            ret += 1;
        }
        mx = min(mx, ret);
    }
    io.writeln(mx);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2168