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

#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, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

ll C(ll n,ll k)
{
  ll x=1,y=1;
  for(int i=1;i<=k;i++)
  {
    x=x*(n-i+1)%mod;
    y=y*i%mod;
  }
  return x * power(y,mod-2) % mod;
}

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

    string s;cin>>s;
    REP(i,3){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import copy

n, m = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
asum = [0]
tmp = 0
for i in range(n):
    tmp += a[i] 
    asum.append(tmp)

lb = 1
ub = 2*10**5 + 1
while ub - lb > 1:
    cx = (ub+lb)//2
    cnt = 0
    total = 0
    for ca in a:
        cy = cx - ca
        ci = bisect.bisect_left(a, cy)
        cnt += n - ci
        total += asum[n] - asum[ci] + (n - ci) * ca
    if cnt >= m:
        lb = cx
        ans = copy.deepcopy(total) - (cnt - m) * cx
    else:
        ub = cx

print(ans)

Measured memory_bytes: 21384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

int H, W;
vector<string> s(500);
vector<vector<bool>> visited(500, vector<bool>(500, false));

int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

void dfs(int x, int y, int &brack, int &white){
  visited[x][y] = true;
  if(s[x][y] == '#') brack++;
  else white++;

  REP(i, 4){
    int xx = x+dx[i];
    int yy = y+dy[i];
    if(OUT(0, xx, H)) continue;
    if(OUT(0, yy, W)) continue;
    if(visited[xx][yy]) continue;
    if(s[x][y] == s[xx][yy]) continue;
    dfs(xx, yy, brack, white);
  }
}

signed main() {
  cin >> H >> W;

  REP(i, H) cin >> s[i];

  int ans = 0;
  REP(i, H) REP(j, W){
    if(visited[i][j]) continue;
    if(s[i][j] == '.') continue;
    int brack = 0;
    int white = 0;
    dfs(i, j, brack, white);
    ans += brack*white;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 18048
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <set>
#include <complex>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

int n;
using R = double;
using P = complex<R>;
constexpr R PI = acos(R(-1));

R cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }
R dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }

P po[100100];
void first() {
    for (int i = 0; i < n; i++) {
        po[i] = polar<R>(1, 2*PI / n * i);
        po[i] -= P(1, 0);
    }
}
R calc(int a, int b) {
    //P l = polar<R>(1, 2*PI / n * a);
    //P r = polar<R>(1, 2*PI / n * b);
    //P base = P(1, 0);
    //return cross(l-base, r-base)/2;
    return cross(po[a], po[b])/2;
}

ll solve(R md) {
    ll ans = 0;
    int q = 1;
    for (int p = 1; p < n; p++) {
        int U = (p+n)/2;
        int l = p, r = U+1;
        while (r-l > 1) {
            int mi = (l+r)/2;
            if (calc(p, mi) < md) {
                l = mi;
            } else {
                r = mi;
            }
        }
        q = r;
        ans += 2*max(0, q-p-1);
        if (q == U+1 && (p+n) % 2 == 0) ans--;
    }
    ans *= n;
    ans /= 3;
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cout.precision(20);
    ll k;
    cin >> n >> k;
    first();
    /*for (int i = 1; i < n; i++) {
        for (int j = i; j < n; j++) {
            cout << calc(i, j) << " ";
        } cout << endl;
    }*/
    R l = -0.1, r = 4;
    for (int i = 0; i < 40; i++) {
        R md = (l+r)/2;
        if (solve(md) < k) {
            l = md;
        } else {
            r = md;
        }
    }
    cout << l << endl;
    return 0;
}



Measured memory_bytes: 1152
#include<stdio.h>
     
    int main(){
      	int n,i,min=1000000,c=0, a[200];
      	scanf("%d", &n);
      for(i=0;i < n; i++){
        scanf("%d", &a[i]);
      }
    for(i=0;i < n; i++){
        c=0;
        while(a[i]>=0){
            if(a[i]%2==0){
                a[i] /= 2;
                c++;
            }else{
                break;
            }
        }
        if(c<min){
            min=c;
        }
    }
      	printf("%d\n", min);
    	return 0;
    }

Measured memory_bytes: 128
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  map<string, int> mp = {{"AC", 0}, {"WA", 0}, {"TLE", 0}, {"RE", 0}};
  rep(i, n){
    string s;cin>>s;
    mp[s]++;
  }
  vector<string> vec = {"AC", "WA", "TLE", "RE"};
  rep(i, 4){
    cout<<vec[i]<<" x "<<mp[vec[i]]<<endl;
  }
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define TOP 0
#define FRONT 1
#define RIGHT 2
#define LEFT 3
#define BACK 4
#define BOTTOM 5
using namespace std;

int dice[6] = {1,2,3,4,5,6};

void rotN(){
  swap(dice[TOP], dice[BACK]);
  swap(dice[TOP], dice[BOTTOM]);
  swap(dice[TOP], dice[FRONT]);
}

void rotE(){
  swap(dice[TOP], dice[RIGHT]);
  swap(dice[TOP], dice[BOTTOM]);
  swap(dice[TOP], dice[LEFT]);
}

void rotS(){
  rotN(), rotN(), rotN();
}

void rotW(){
  rotE(), rotE(), rotE();
}

void rotH(){
  swap(dice[FRONT], dice[RIGHT]);
  swap(dice[FRONT], dice[BACK]);
  swap(dice[FRONT], dice[LEFT]);
}


int main(){
cin >> dice[TOP]>> dice[FRONT]>> dice[RIGHT]>> dice[LEFT]>> dice[BACK]>> dice[BOTTOM];
int q, top, front;
  cin >> q;
  
  for(int j = 0; j < q; j++){
    cin >> top >> front;
    for(int i = 0; i < 3 && dice[TOP] != top; i++) rotN();
    for(int i = 0; i < 3 && dice[TOP] != top; i++) rotE();
    while(dice[FRONT]!=front) rotH();
    cout << dice[RIGHT] << endl;
  }
}


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

# AtCoder Beginner Contest 115：A - Christmas Eve Eve Eve


def main():
    D = int(raw_input().strip())
    if D == 25:
        print 'Christmas'
    elif D == 24:
        print 'Christmas Eve'
    elif D == 23:
        print 'Christmas Eve Eve'
    elif D == 22:
        print 'Christmas Eve Eve Eve'
    else:
        print 'Input Error!'


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	ll a,b,c,d; cin >> a >> b >> c >> d ;
	ll n = b-a+1;
	ll e = c*d/gcd(c,d);
	ll c_num;
	ll d_num;
	ll e_num;
	c_num = b/c - a/c; if(a%c==0) c_num++;
	d_num = b/d - a/d; if(a%d==0) d_num++;
	e_num = b/e - a/e; if(a%e==0) e_num++;

	c_num = n-c_num;
	d_num = n-d_num;
	e_num = n-e_num;

	ll ret = c_num + d_num - e_num;
	out(ret);
}



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

using namespace std;

int main()
{
    int a, b, c, d, cant = 1;
    cin>>a>>b;
    vector<int> balls;
    vector<bool> red;
    red.assign(a, false);
    red[0] = true;
    balls.assign(a, 1);
    while(b--)
    {
        cin>>c>>d;
        c--;
        d--;
        balls[d]++;
        if(red[c] && !red[d])
        {
            cant++;
            red[d] = true;
        }
        balls[c]--;
        if(balls[c] == 0 && red[c])
        {
            cant--;
            red[c] = false;
        }
    }
    cout<<cant<<endl;
    return 0;
}

Measured memory_bytes: 640
LR = "qwertasdfgzxcvb yuiophjklnm"
while 1:
	key = raw_input()
	if key == "#": break
	c = 0
	h = LR.index(key[0])
	for i in range(1,len(key)):
		p = LR.index(key[i])
		if (h < 16 and p >= 16) or (h >= 16 and p < 16):
			c += 1
			h = p
	print c

Measured memory_bytes: 4216
#include<bits/stdc++.h>
#define ll  long long int
#define fr(i,n) for(ll i=0; i<n; i++)
#define fre(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define pii pair<ll,ll>
#define ve vector
#define piii pair<pii, ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

ll power(ll x, ll n, ll m)
{
    if(n==0)
        return 1;
    if(n==1)
        return x;
    x%=m;
    if(n%2)
        return (x*(power((x*x)%m, n/2, m)%m))%m;
    return power((x*x)%m, n/2, m)%m;
}

int main(){
  
    FAST;
    ll n;
    cin>>n;

    ll a[n], ans[n];
    for(int i=0; i<n; i++)
      cin>>a[i];

    ans[0] = 0;

    for(int i=1; i<n; i++){
      ans[i] = 1e15;
      ans[i] = min(ans[i], ans[i-1] + abs(a[i]-a[i-1]));
      if( i-2 >= 0)
        ans[i] = min(ans[i], ans[i-2] + abs(a[i]-a[i-2]));
    }
    cout<<ans[n-1]<<endl;

}

Measured memory_bytes: 5216
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = (n-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

const int MAX = 1000000;
const long long MOD = 1000000007;
long long fac[MAX], facinv[MAX], inv[MAX];

void facinit(){
    fac[0] = fac[1] = 1;
    facinv[0] = facinv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        facinv[i] = facinv[i - 1] * inv[i] % MOD;
    }   
}

long long Combi(long long a, long long b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (facinv[b] * facinv[a - b] % MOD) % MOD;
}

int main(){
    lint n, m; cin >> n >> m;
    facinit();

    map<lint, lint> fct;
    lint div = 2;
    while(m > 1){
        if(m % div == 0){
            m /= div;
            fct[div]++;
        }
        else div++;
    }

    lint ans = 1;
    for(auto& f : fct){
        ans *= Combi(f.second + n - 1, n - 1);
        ans %= MOD;
    }
    cout << ans << endl;
}

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

const long INF=10000000000;
//関数

long cost(vector<long> point, vector<long> l,long A,long B, long C){//xは空でない
    long one=0,two=0,three=0,a=0,b=0,c=0;//one two three>0
    for(int i=0;i<point.size();i++){
        if(point.at(i)==1) {
            one++;
            a+=l.at(i);
        }
        if(point.at(i)==2) {
            two++;
            b+=l.at(i);
        }
        if(point.at(i)==3) {
            three++;
            c+=l.at(i);
        }
    }
    
    return abs(A-a)+abs(B-b)+abs(C-c)+(one+two+three-3)*10+(one==0||two==0||three==0)*INF;
    
}

long mincost(vector<long> point,long k,long N,vector<long> l,long A,long B, long C){
    if(k==N-1){
        return cost(point,l,A,B,C);
    }else{
        long result=INF;
        for(int i=0;i<4;i++){
            point.at(k+1)=i;
            result=min(result,mincost(point,k+1,N,l,A,B,C));
        }
        return result;
    }
}


//main関数
int main() {
    
    
    //入力
    long N,A,B,C;
    cin>>N>>A>>B>>C;
    vector<long> l(N);
    for(int i=0;i<N;i++){
        cin>>l.at(i);
    }
    
    //計算
    vector<long> point(N,0);
    
    

    //出力
    cout<<mincost(point,-1,N,l,A,B,C)<<endl;
}

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

int main() {
	// your code goes here
	int n, x, y;
	cin >> n >> x >> y;
	unordered_map<int, int> m;
	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			int dist;
			if(i>=x && j<=y && i<=y && j>=x)
				dist=min(j-i, i-x+y-j+1);
			else if(j>=x && j<=y && i<x)
				dist=min(j-i, y-j+1+x-i);
			else if(i>=x && i<=y && j>y)
				dist=min(j-i, i-x+1+j-y);
			else if(i<=x && j>=y)
				dist=x-i+j-y+1;
			else
				dist=j-i;
			m[dist]++;
		}
	}
	for(int k=1; k<=n-1; k++)
		cout << m[k] << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    string s;
    int a = 0;
    cin >> s;
    for (int i = 0; i < s.length() / 2; i++) {
        if (s[i] != s[s.length() - 1 - i]) {
            a++;
        }
    }
    cout << a;
}

Measured memory_bytes: 256
n=gets.to_i
pn=gets.split.map(&:to_i)
count = 0
(n-2).times do |index|
  localPn = pn[index..(index+2)]
  count += 1 if localPn[0] < localPn[1] && localPn[1] < localPn[2]
  count += 1 if localPn[0] > localPn[1] && localPn[1] > localPn[2] 
end
puts count

Measured memory_bytes: 1788
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
  if p[i-1]<p[i] and p[i]<p[i+1]:
    cnt+=1
  elif p[i-1]>p[i] and p[i]>p[i+1]:
    cnt+=1
print(cnt)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int ei=0,cho=0,don=0;
while(true){
int[] a=new int[3];
a[0]=Integer.parseInt(sc.next());
a[1]=Integer.parseInt(sc.next());
a[2]=Integer.parseInt(sc.next());
Arrays.sort(a);
int temp=a[0]+a[1];
int sq1=a[0]*a[0];
int sq2=a[1]*a[1];
int sq3=a[2]*a[2];
int l=sq1+sq2;
if(temp>a[2]){
if(sq3>l){
ei++;
}else if(sq3==l){
cho++;
}else if(sq3<l){
don++;
}

        }else{
    System.out.println((don+cho+ei)+" "+cho+" "+don+" "+ei);
    break;
    }
}

}
}


Measured memory_bytes: 26044
#include <iostream>
#include <set>

#define maxN 101


int main() {
	/* code */
	int x , n,tmp;
	std::set<int> input;
	std::cin>>x>>n;
	for(int i =0; i < n; i++)  {
		std::cin>>tmp;
		input.insert(tmp);
	}
	int l = x - 1, r = x + 1, ans =x;
	bool check = (input.find(ans) != input.end());
	while(check) {
		if (input.find(l) == input.end()) {
			ans = l;
			break;
		}
		else if (input.find(r) == input.end()) {
			ans = r;
			break;
		}
		else {
			l--;
			r++;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

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

using namespace std;

int main() {
  int N, K;
  vector<double> exp_list_sum;
  
  cin >> N >> K;
  
  double sum = 0.0;
  
  exp_list_sum.push_back(0.0);
  
  for (int i = 0; i < N; i++) {
    int d;
    
    cin >> d;
    
    sum += (d + 1) / 2.0;
    exp_list_sum.push_back(sum);
  }
  
  double max_sum = 0.0;
  for (int i = K; i < N + 1; i++) {
    max_sum = max(max_sum, exp_list_sum[i] - exp_list_sum[i - K]);
  }
  
  cout << setprecision(8) << max_sum << endl;
  
  return 0;
}

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

int main(){
  int a,b,c,maxv;
  double ans;
  cin >> a >> b >> c;
  maxv = max(a,b);
  maxv = max(maxv,c);
  ans = a*b*c/maxv/2;
  cout << ans;
}

Measured memory_bytes: 256
import sys
def 解():
    iN,iM = [int(_) for _ in input().split()]
    aAB = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    dT = {}
    def addTree(dT,a,b):
        if a in dT:
            dT[a].add(b)
        else:
            dT[a] = {b}
    for a,b in aAB:
        addTree(dT,a,b)
        addTree(dT,b,a)
    if  1 not in dT or iN  not in dT:
        print("IMPOSSIBLE")
    elif 0 < len(dT[1] & dT[iN]) :
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
解()


Measured memory_bytes: 104548
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> H(100000);
int main() {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> H.at(i);
    }

    bool flag = true;

    for(int i = 1; i < N; ++i) {
        if(H.at(i-1) < H.at(i)) {
            H.at(i) -= 1;
        }else if(H.at(i-1) == H.at(i)) {

        }else {
            if(H.at(i) - 1 != H.at(i-1)) {
                flag = false;
                break;
            }
        }
    }

    if(flag) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
//#define int long long
using ll = long long;
const int MX = 1e6;
const ll inf = 1e13;
const int mod = 1e9+7;
map<ll, ll> prime_factors(ll n) {
    map<ll, ll> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(ll i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
signed main() {
    string s,t;
    cin >> s>> t;
    int n = s.length();
    int m = t.length();
    int ans = 0;
    rep(i,n-m+1) {
        string tmp = s.substr(i,m);
        //cout << tmp << endl;
        int cnt = 0;
        rep(j,m) {
            if(tmp[j]==t[j]) {
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << m-ans << endl;
    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int ans=0;
  string s;
  cin>>s;
  for(int i=1; i<s.size(); i++){
    if(s[i-1]==s[i]){
      if(s[i]=='1'){
	s[i]='0';
      }else{
	s[i]='1';
      }
      ans++;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/

const ll MOD=1000000007;

ll min(ll a, ll b){
	if(a>=b){
		return b;
	}
	else{
		return a;
	}
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a>0 && c>0){
		cout << b * d << endl;
	}
	else{ 
		if(a>0){
			if(d>0){
				cout << d * b << endl;
			}else{
				cout << a * d << endl;
			}
		}else if(c>0){
			if(b>0){
				cout << d * b << endl;
			}else{
				cout << c * b << endl;
			}
		}else{
			if(b<0 && d<0){
				cout << a * c << endl;
			}
			else{
				if(b>0){
					if(d>0){
						if(b*d>a*c){
							cout << b * d << endl;
						}else{
							cout << a *c << endl;
						}
					}else{
						cout << a * c << endl;
					}
				}else if(d>0){
					if(b>0){
						if(b*d>a*c){
							cout << b * d << endl;
						}
						else{
							cout << a * c << endl;
						}
					}else{
						cout << a * c << endl;
					}
				}
				else{
					cout << a * c << endl;
				}
			}
		}

	}
}

int main(){
	
	solve();
	
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n ,ans = 0;
    cin>>n;
    ll arr[n+1];
    for(int i = 1;i<=n;i++)
    {
        cin>>arr[i];
        if(i%2==1&&arr[i]%2==1)
        ans++;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3580
#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() {
    int n, cnt = 0;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        if (n - i > i) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3532
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		int[][] f = new int[10][10];int[] c={0,1,2,4},p=new int[3];int n=0,m=0;
		String t;String[] d;
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)f[i][j]=0;
		while((t=bf.readLine())!=null){
			d=t.split(",");
			for(int i=0;i<3;i++)p[i]=Integer.parseInt(d[i]);
			for(int i=0;i<10;i++)
				for(int j=0;j<10;j++)
					if((j-p[0])*(j-p[0])+(i-p[1])*(i-p[1])<=c[p[2]])f[i][j]++;
		}
		for(int i=0;i<10;i++)for(int j=0;j<10;j++){
			if(m<f[i][j])m=f[i][j];
			if(f[i][j]==0)n++;
		}
		System.out.println(n);
		System.out.println(m);
	}
}

Measured memory_bytes: 9164
#include <iostream>
#include <stack>

#define UNDEF -1
#define IS_RD -2
#define INF 1073741824

using namespace std;

int M[1001][1001],H,W;
int dp[1001][1001];
stack<int> callX;
stack<int> callY;

int getM(int x,int y)
{
	if(x >= 0 && y >= 0 && x < W && y < H)
	{
		return M[x][y];
	}
	else
	{
		return INF;
	}
}

void calc(int _x,int _y)
{
	int x,y;
	callX.push(_x);
	callY.push(_y);
	while(!callX.empty())
	{
		endfn:
		x = callX.top();
		y = callY.top();
		if(dp[x][y] == UNDEF)
		{
			int a[4] = {INF,INF,INF,INF};
			if(getM(x+1,y) < getM(x,y))
			{
				if(dp[x+1][y] == UNDEF)
				{
					callX.push(x+1);
					callY.push(y);
					goto endfn;
				}
				else
				{
					a[0] = dp[x+1][y];
				}
			}
			if(getM(x-1,y) < getM(x,y))
			{
				if(dp[x-1][y] == UNDEF)
				{
					callX.push(x-1);
					callY.push(y);
					goto endfn;
				}
				else
				{
					a[1] = dp[x-1][y];
				}
			}
			if(getM(x,y+1) < getM(x,y))
			{
				if(dp[x][y+1] == UNDEF)
				{
					callX.push(x);
					callY.push(y+1);
					goto endfn;
				}
				else
				{
					a[2] = dp[x][y+1];
				}
			}
			if(getM(x,y-1) < getM(x,y))
			{
				if(dp[x][y-1] == UNDEF)
				{
					callX.push(x);
					callY.push(y-1);
					goto endfn;
				}
				else
				{
					a[3] = dp[x][y-1];
				}
			}
			if(a[0] == INF && a[1] == INF && a[2] == INF && a[3] == INF)
			{
				dp[x][y] = (x*1000)+y;
				goto endok;
			}
			else
			{
				for(int i = 0;i < 3;i++)
				{
					for(int ii = i+1;ii < 4;ii++)
					{
						if(a[i] != INF && a[ii] != INF && a[i] != a[ii])
						{
							dp[x][y] = IS_RD;
							goto endok;
						}
					}
				}
				for(int i = 0;i < 4;i++)
				{
					if(a[i] != INF)
					{
						dp[x][y] = a[i];
						goto endok;
					}
				}
			}
		}
		endok:
		callX.pop();
		callY.pop();
	}
}

int main(void)
{
	cin >> H >> W;
	for(int i = 0;i < H;i++)
	{
		for(int ii = 0;ii < W;ii++)
		{
			cin >> M[ii][i];
		}
	}
	for(int x = 0;x < 1001;x++)
	{
		for(int y = 0;y < 1001;y++)
		{
			dp[x][y] = UNDEF;
		}
	}
	int res = 0;
	for(int x = 0;x < W;x++)
	{
		for(int y = 0;y < H;y++)
		{
			calc(x,y);
		}
	}
	for(int x = 0;x < W;x++)
	{
		for(int y = 0;y < H;y++)
		{
			if(dp[x][y] == IS_RD)
				res++;
		}
	}
	
	cout << res << endl;
}

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

using namespace std;

bool clear(char a[4]){
    for(int i=0 ; i<2 ;i++){
        if(a[i] == a[i+1] && a[i+1] == a[i+2])
            return true;
    }
    return 0;
}

int main(){
    char a[4]; cin >> a;
    
    if(clear(a) == true)
        cout << "Yes" << endl;
    
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
flag = 0
for a in range(1,3501):
    if flag ==1:
        break
    for b in range(1,3501):
        if 4*a*b - a*N - b*N != 0:
            if a*b*N // (4*a*b - a*N - b* N) > 0 and a*b*N % (4*a*b - a*N - b* N) ==0:
                c = int(a*b*N / (4*a*b - a*N - b* N))
                print(a, b, c)
                flag = 1
                break

Measured memory_bytes: 40812
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  int min_hight = 1e9;
  for(int i = 0; i < N - K + 1; i++) {
    min_hight = min(min_hight, h[i + K - 1] - h[i]);
  }
  cout << min_hight << endl;
  return 0;
}


Measured memory_bytes: 3692
s = input()
q = int(input())

cnt = 0
left = []
right = []
for j in range(q):
    a = [str(i) for i in input().split()]
    if a[0] == '1':
        cnt += 1
    else:
        if (a[1] == '1' and cnt % 2 == 0) or (a[1] == '2' and cnt % 2 == 1):
            right.append(a[2])
        else:
            left.append(a[2])

if cnt % 2 == 0:
    print(''.join(reversed(right)) + s + ''.join(left))
else:
    print(''.join(reversed(left)) + ''.join(list(reversed(s))) + ''.join(right))


Measured memory_bytes: 73560
import itertools
n, m, q=map(int, input().split())

l=[[0]*4 for i in range(q)]

for i in range(q):
    l[i][0],l[i][1],l[i][2],l[i][3]=map(int,input().split())

a=[]
for i in range(1,m+1):
    a.append(i)
arr=list(itertools.combinations_with_replacement(a,n))

mx=0
for mask in range(len(arr)):
    tpl=arr[mask]
    ans=0
    for i in range(q):
        if tpl[l[i][1]-1]-tpl[l[i][0]-1]==l[i][2]:
            ans+=l[i][3]
    mx=max(ans,mx)

print(mx)

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

#define int long long

int32_t main()
{
	int n;
	cin >> n;
	int x[n];

	int mi = INT_MAX, ma = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
		mi = min(mi, x[i]);
		ma = max(ma, x[i]);
	}
	
	int ans = INT_MAX;
	for (int i = mi; i <= ma; ++i)
	{
		int cost = 0;

		for (int j = 0; j < n; ++j)
		{
			cost += (x[j] - i) * (x[j] - i);
		}

		if (cost < ans)
			ans = cost;
	}

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

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

int main() {
  int n, p;
  cin >> n >> p;
  string s;
  cin >> s;
  if (10 % p == 0) { // p == 2 || p == 5
    ll ans = 0;
    rep(r, 0, n)  { // r右端
      if ((s[r]- '0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<int> d(n+1);
  int ten = 1; // 10の何乗か
  for (int i = n - 1; i >= 0; --i) {
    int a = (s[i] - '0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }

  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) { //i = n: % p == 0を先にcntで一つカウントしてあげる
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }

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


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

using namespace std;

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(args...) { string _s = #args; replace(ALL(_s), ',', ' '); stringstream ss(_s); cerr << endl;_debug(ss, args); }
#define _rg auto it = next(v.begin()); it != v.end(); it++
#define _input ostream& operator <<(ostream& out

template<typename T, typename U>
_input, const pair<T, U>& p) {
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}

#define cont(c) template<typename T> _input, const c<T>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}
				
#define cont2(c) template<typename T, typename U> _input, const c<T, U>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}

cont(vector) cont(set) cont(multiset) cont(queue) cont2(map)

template<typename T, size_t n, typename= enable_if_t<!is_same<T, char>::value>>
_input, const T(&v)[n]) {
	if (n == 0) return out;
	out << "[" << v[0];
	for (int i = 1; i < (int)n; i++) out << ", " << v[i];
	out  << "]"; return out;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T &arg) {
	string name; ss >> name;
	cerr << name << " = " << arg << endl;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T& arg, const Ts&... args) {
	string name; ss >> name; 
	cerr << name << " = " << arg << ", ";
	if (is_class<T>::value || is_array<T>::value) cerr << endl;
	_debug(ss, args...);
}

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;

	int n;
	cin >> n;
	
	map<int, int> m;
	
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			m[i]++;
			n/=i;
		}
	}
	if (n > 1) {
		m[n]++;
		n /= n;
	}
	
	int cnt = 1;
	int ans = 0;
	
	
	while (true) {
		vii list;
		for (ii p: m) {
			if (p.second >= cnt) list.PB(p);
		}
		
		if ((int)list.size() == 0) break;
		
		for (ii x: list) {
			m[x.first] -= cnt;
			ans += 1;
		}
		cnt++;
	}
	
	cout << ans << endl;
	
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


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

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

    if(B > A) swap(A, B);

    if((A - B) % 2 == 0){
        cout << (A-B)/2 << endl;
    } else {
        Int to1 = (B-1) + 1 + (A-B-1)/2;
        Int toN = (N-A) + 1 + (A-B-1)/2;
        cout << min(to1, toN) << endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

const static int INF = 1e8;
const static D EPS = 1e-8;

int main(){
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n), mina(n);
  rep(i,n) cin >> a[i], mina[i] = a[i];

  ll ans = accumulate(all(a),0LL);
  rep(l,n){
    ll sum_cost = x * l;
    rep(i,n){
      sum_cost += mina[i];
    }
    if(ans > sum_cost) ans = sum_cost;

    rep(i,n){
      chmin(mina[i], a[(i+n-1-l)%n]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));
$avg = array_sum($a) / count($a);
$diff = PHP_INT_MAX;

for ($i = 0; $i < $N; $i++) {
    $d = abs($a[$i] - $avg);
    if ($diff > $d) {
        $ans = $i;
        $diff = $d;
    }
}

echo $ans;

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define N 1116

int n,m,k,d[N][N];
char a[N][N];
queue<pair<int,int> > q;
int dx[]={-1,0,0,1},dy[]={0,-1,1,0};

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();k=read();
	memset(d,0x3f,sizeof(d));
	for (int i=1;i<=n;i++){
		scanf(" %s",a[i]+1);
		for (int j=1;j<=m;j++)
			if (a[i][j]=='S')
			d[i][j]=0,q.push(make_pair(i,j));
	}
	while (!q.empty()){
		int x=q.front().first,y=q.front().second;q.pop();
		for (int i=0;i<4;i++){
			int tx=x+dx[i],ty=y+dy[i];
			if (a[tx][ty]=='.'&&d[tx][ty]==0x3f3f3f3f)
			d[tx][ty]=d[x][y]+1,q.push(make_pair(tx,ty));
		}
	}
	int ans=0x3fffffff;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (d[i][j]<=k)
			ans=min(ans,1+(min(min(i-1,n-i),min(j-1,m-j))+k-1)/k);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6016
n=int(input())
s=[]
for i in range(n):
    s.append([str(input()),1])
m=int(input())
for i in range(m):
    s.append([str(input()),-1])
s.sort()
x=s[0][0]
max_s=0
a=0
for i in range(n+m):
    if x==s[i][0]:
        a+=s[i][1]
    else:
        x=s[i][0]
        max_s=max(max_s,a)
        a=s[i][1]
print(max(a,max_s))

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

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const int INF=0x3f3f3f3f;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

int main()
{
	vivek_ghosh;
	
	cin>>n>>m>>k;
	
	ans = min(n*m,k);
	cout<<ans<<endl;
	
	
	
	
	
	

	
	return 0;
}






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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<int> m(q);
  for (int i = 0; i < q; i++) {
    cin >> m[i];
  }
  vector<int> dp(2100, 0);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 2000; j >= 0; j--) {
      if (j - a[i] >= 0) {
        dp[j] |= dp[j - a[i]];
      }
    }
  }
  for (int i = 0; i < q; i++) {
    if (dp[m[i]] == 1) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

void place_vtx(vector<int> &d, int x) {
  for (auto pos = d.begin(); pos != d.end(); ++pos) {
    if (*pos == x) {
      d.erase(pos);
      return;
    }
  }
  cout << "Impossible";
  exit(0);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  int diam = 0;
  for (int &x : a) {
    cin >> x;
    diam = max(diam, x);
  }
  if (count(a.begin(), a.end(), diam) == 1 || (diam == 1 && n > 2)) {
    cout << "Impossible";
    return 0;
  }
  sort(a.begin(), a.end());
  int cur = diam;
  while (cur >= (diam + 1) / 2) {
    if (cur == (diam + 1) / 2) {
      place_vtx(a, cur);
      if (diam % 2 != 0) {
        place_vtx(a, cur);
      }
      break;
    } else {
      place_vtx(a, cur);
      place_vtx(a, cur);
    }
    cur--;
  }
  if (a.empty() || a[0] > cur) {
    cout << "Possible";
  } else {
    cout << "Impossible";
  }
  return 0;
}

Measured memory_bytes: 3580
Card = Struct.new(:suit, :value) do
  include Comparable

  def <=>(other)
    value <=> other.value
  end

  def to_s
    [suit, value].join(' ')
  end
end

def merge_sort(arr)
  return arr if arr.size <= 1

  mid = arr.size / 2

  arr1 = arr[0...mid]
  arr2 = arr[mid..-1]

  merge(merge_sort(arr1), merge_sort(arr2))
end

def merge(arr1, arr2)
  ret = []

  until arr1.empty? || arr2.empty?
    if arr1.first <= arr2.first
      ret << arr1.shift
    else
      ret << arr2.shift
    end
  end

  unless arr1.empty?
    ret.push(*arr1)
  end

  unless arr2.empty?
    ret.push(*arr2)
  end

  ret
end

def partition(arr, p, r)
  x = arr[r]
  i = p - 1
  p.upto(r - 1) do |j|
    if arr[j] <= x
      i += 1
      arr[i], arr[j] = arr[j], arr[i]
    end
  end
  arr[i + 1], arr[r] = arr[r], arr[i + 1]
  return i + 1
end

def quick_sort(arr, p, r)
  if p < r
    q = partition(arr, p, r)
    quick_sort(arr, p, q - 1)
    quick_sort(arr, q + 1, r)
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i
  arr1 = []
  arr2 = []

  n.times do
    suit, value = gets.split
    card = Card.new(suit.to_sym, value.to_i)
    arr1 << card
    arr2 << card
  end

  quick_sort(arr1, 0, n - 1)
  arr2 = merge_sort(arr2)

  stable = true

  n.times do |i|
    if arr1[i].suit != arr2[i].suit
      stable = false
      break
    end
  end

  puts stable ? 'Stable' : 'Not stable'

  arr1.each do |card|
    puts card
  end
end

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

int main() {
    int H, N, A;
    cin >> H >> N;
    string ret = "No";
    REP(i, N) {
        cin >> A;
        H -= A;
        if(H<=0) {
            ret = "Yes";
            break;
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		int[][] connect = new int[m][n];
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			for (int j = 0; j < l; j++) {
				connect[i][sc.nextInt()-1] = 1;
			}
		}
		int[] p = new int[m];
		for (int i = 0; i < m; i++) p[i] = sc.nextInt();
		int[] light; int count = 0; boolean flag;
		String format = "%".concat(String.valueOf(n)).concat("s");
		String s;
		for (int i = 0; i < 1<<n; i++) {
			s = String.format(format, Integer.toString(i,2)).replace(' ', '0');
			light = new int[m]; flag = true;
			for (int j = 0; j < n; j++) {
				if(s.charAt(j)=='1') {
					for (int k = 0; k < m; k++) {
						if(connect[k][j]==1)light[k]++;
					}
				}
			}
			for (int j = 0; j < m; j++) {
				if(light[j]%2!=p[j]) flag = false;
			}
			if(flag) count++;
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 25500
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();

        const string hitachiChars = "hi";

        int count = 0;
        int strLength = s.Length;
        string result = "No";

        if (strLength % 2 == 0)
        {
            while(count < strLength)
            {
                string str = s.Substring(count,2);
                if(str != hitachiChars) {
                    break;
                }
                count += 2;
            }
            if (count == strLength)
            {
                result = "Yes";
            } 
        }    
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13140
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>

using namespace std;

void Solution()
{
    int H, W;
    
    while(cin>>H>>W)
    {
        if (H == 0 || W == 0)
        {
            break;
        }
        
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                cout<<"#";
            }
            
            cout<<endl;
        }
        
        cout<<endl;
    }
    
    
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1152
#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() {
  vector<int>a(3);
  rep(i,3) cin >> a.at(i);
  sort(a.begin(),a.end());
  if(a.at(0)+a.at(1)==a.at(2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;

const int A = 100 + 10;
char s[A];

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    scanf("%s",s);

    int len = strlen(s);
    if(s[a] != '-'){
        puts("No");
        return 0;
    }
    for(int i=0 ;i<len ;i++){
        if(i!=a && (s[i]<'0' || s[i]>'9')){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a, b, t;
  	int n = 0;

  	scanf("%d %d %d", &a, &b, &t);
	
  	for (int i = 1; i * a <= t; i++) {
    	n += b;
    }
  	
  	printf("%d", n);
  
  
	return 0;
}


Measured memory_bytes: 128
def C():
    n,m = list(map(int, input().split()))
    ans = [0]*n
    for s,c in (list(map(int,input().split())) for _ in range(m)):
        if ans[s-1] != 0 and ans[s-1] != c:
            print(-1)
            return
        if s-1 == 0 and n != 1 and c == 0:
            print(-1)
            return
        if ans[s-1] == 0:
            ans[s-1] = c
    if ans[0] == 0 and n != 1:
        ans[0] = 1
    print("".join(map(str,ans)))
C()

Measured memory_bytes: 3064
# vim: fileencoding=utf-8

import math


def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    n = math.ceil(x / d)
    r = 0
    if n > k:
        r = x - (k * d)
    else:
        r = x - (n * d)
        k2 = k - n
        if k2 % 2 == 1:
            r += d
    print(abs(r))


if __name__ == "__main__":
    main()


Measured memory_bytes: 62012
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
ll W,v[50],w[50];
pair<ll,ll> ps[1<<20];

int main()
{
	scanf("%d%lld",&N,&W);
	for(int i=0;i<N;i++)scanf("%lld%lld",&v[i],&w[i]);
	int n2 = N/2;
	for(int S=0;S<1<<n2;S++){
		ll v1=0,w1=0;
		for(int i=0;i<n2;i++){
			if(S>>i&1){
				v1 += v[i];
				w1 += w[i];
			}
		}
		ps[S] = make_pair(w1,v1);
	}
	sort(ps,ps+(1<<n2));
	//無駄な要素をけす（wが大きくvが小さいものをなくす）
	int m=1;
	for(int S=1;S<1<<n2;S++){
		if(ps[m-1].second < ps[S].second){
			ps[m++] = ps[S];
		}
	}
	ll res=0;
	for(int S=0;S<1<<(N-n2);S++){
		ll v2=0,w2=0;
		for(int i=0;i<N-n2;i++){
			if(S>>i&1){
				v2 += v[n2+i];
				w2 += w[n2+i];
			}
		}
		if(w2<=W){
			ll V = (upper_bound(ps,ps+m,make_pair(W-w2,INF))-1) -> second;
			res = max(res,V+v2);
		}
	}
	printf("%lld\n",res);
	return 0;
}



Measured memory_bytes: 19136
import Data.List (sort,nub)
import Data.List.Split
import Data.Map (Map, (!))
import qualified Data.Map.Strict as Map
main = do
  s <- getContents
  let t = span (\x->x /= "0,0") . lines $ s
  let (d',q') = t
  let d = map (\x->(head x, last x)) . map (map read . splitOn ",") $ d'
  let vals = reverse . nub . sort . map (\(x,y)->y) $ d
  let dd = Map.fromList d
  let q = map read . tail $ q'
  let q2= map (solv vals 1 . (dd !)) q
  mapM_ (putStrLn . show) q2

solv::[Int] -> Int -> Int -> Int
solv [] a _ = a
solv (x:xs) a qv
  | x > qv = solv xs (a+1) qv 
  | otherwise = a

Measured memory_bytes: 4136
bingo_card = [input().split() for _ in range(3)]

N = int(input())

for _ in range(N):
    b = input()
    for i in range(3):
        if b in bingo_card[i]:
            j = bingo_card[i].index(b)
            bingo_card[i][j] = "O"
            break

def check_h():
    for line in bingo_card:
        for s in line:
            if s != "O":
                break
        else:
            return True
    return False

def check_v():
    for i in range(3):
        for j in range(3):
            if bingo_card[j][i] != "O":
                break
        else:
            return True
    return False

def check_d():
    for x in [True, False]:
        for i in range(3):
            if x:
                if bingo_card[i][i] != "O":
                    break
            else:
                if bingo_card[i][2 - i] != "O":
                    break
        else:
            return True
    return False

checks = [check_h, check_v, check_d]
for check in checks:
    if check():
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 9184