akhauriyash/Code-Regression huggingface dataset:
import * as fs from 'fs';

function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

const input = fs.readFileSync("/dev/stdin", "utf8");
const pick = Picker(input);

//////////////////////////////////////////

const [r, g, b, n] = [pick.int(), pick.int(), pick.int(), pick.int()];

let c = 0;
for (let i = 0; i <= n / r; ++i) {
  for (let j = 0; j <= (n - i * r) / g; ++j) {
    if ((n - i * r - j * g) % b === 0) {
      c++;
    }
  }
}
console.log(c);

Measured memory_bytes: 7500
#include <iostream>
#include <string>

using namespace std;

int main() {
    string Sp, T;
    cin >> Sp >> T;

    int pos = -1;
    for (int i = 0; i < Sp.size() - T.size() + 1; i++) {
        bool flag = true;
        for (int j = 0; j < T.size(); j++) {
            if (Sp[i + j] != T[j] && Sp[i + j] != '?') {
                flag = false;
                break;
            }
        }
        if (flag) {
            pos = i;
        }
    }

    if (pos == -1) cout << "UNRESTORABLE" << endl;
    else {
        for (int i = 0; i < Sp.size(); i++) {
            if (pos <= i && i < pos + T.size()) {
                Sp[i] = T[i - pos];
            } else if (Sp[i] == '?') {
                Sp[i] = 'a';
            }
        }
        cout << Sp << endl;
    }

    return 0;
}

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

int main()
{
    int n = 0;
    string s, t;
    int h1 = 0;
    int h2 = 0;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
      	cin >> s >> t;
      	int j = 0;
      	while(j < 100 && s[j] && t[j] && s[j] == t[j])
        	j++;
      	if(s[j] - t[j] > 0)
          h1 += 3;
     	else if(s[j] - t[j] < 0)
          h2 += 3;
      	else
        {
          h1++;
          h2++;
        }
    }
    cout << h1 << " " << h2 << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<int,pair<int,int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int D;
vector<ll> c(26);
vector<vector<ll>> s;

ll score(vector<int> t){
  vector<ll> last(26,0);
  ll ans=0;
  for(ll i=0;i<D;i++){
    ans+=s.at(i).at(t.at(i));
    last.at(t.at(i))=i+1;
    for(ll j=0;j<26;j++){
      ans-=c.at(j)*((i+1)-last.at(j));
    }
  }
  return ans;
}


int main(){
  clock_t start,end;
  start=clock();
  cin>>D;
  for(int i=0;i<26;i++){
    cin>>c.at(i);
  }
  s.resize(D);
  for(int i=0;i<D;i++){
    s.at(i).resize(26);
    for(int j=0;j<26;j++){
      cin>>s.at(i).at(j);
    }
  }

  vector<ll> last(26,0);
  vector<int> t(D);
  for(ll i=0;i<D;i++){
    int k=0;
    for(int j=0;j<26;j++){
      if(10000*c.at(j)*((i+1)-last.at(j))-s.at(i).at(j)>10000*c.at(k)*((i+1)-last.at(k))-s.at(i).at(k)){
        k=j;
      }
    }
    t.at(i)=k;
    last.at(k)=i+1;
  }
  ll ans=score(t);

  vector<int> nt=t;
  for(int i=0;i<D;i++){
    int k=0;
    for(int j=0;j<26;j++){
      if(s.at(i).at(k)<s.at(i).at(j)){
        k=j;
      }
    }
    nt.at(i)=k;
    ll sub=score(nt);
    if(sub>ans){
      t=nt;
    }
    end=clock();
  }

  for(int i=0;i<D;i++){
    cout<<t.at(i)+1<<endl;
  }
}


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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}

vi vis, col;
vector<vi> adj;
int cc = 0, odd = 0;
void dfs(int v, int par = -1) {
  //debug(v, par);
  if(par != -1) {
    col[v] = !col[par];
  }
  vis[v] = 1;
  cc++;
  for(auto x: adj[v]) {
    if(x == par) continue;
    if(vis[x]) {
      if(col[x] == col[v]) {
        odd = 1;
      }
      continue;
    }
    dfs(x, v);
  }
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n, m; cin>>n>>m;
  col.resize(n+1);
  vis.resize(n+1);
  adj.resize(n+1, vi(0));
  rep(i,0,m) {
    int u, v; cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  int c1, c2, c3;
  c1 = c2 = 0;
  c3 = 0;
  rep(i,1,n+1) {
    if(!vis[i]) {
      col[i] = 0;
      odd = 0;
      cc = 0;
      dfs(i, -1);
      debug(i, cc);
      if(cc == 1) c3++;
      else if(odd) c1++;
      else c2++;
    }
  }
  lli kk = 2*c3*1LL*n - (c3*1LL*(c3-1)) - c3;
  debug(c3, kk, c1, c2);
  cout<<2*c1*1LL*c2 + c1*1LL*c1 + 2*c2*1LL*c2 + kk<<endl;
}



Measured memory_bytes: 10368
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;
typedef long long ll;

const int MAXN = 1e5+7;

struct Node{
    ll a;
    ll b;
} node[MAXN];

bool cmp(Node a,Node b){
    return a.a < b.a;
}

int main(){
    int N,M;
    while(cin >> N >> M){
        for(int i = 0; i < N; i++){
            cin >> node[i].a >> node[i].b;
        }
        sort(node,node+N,cmp);
        int idx = 0;
        ll sum = 0;
        priority_queue<ll> q;
        for(int i = 1; i <= M; i++){
            while(node[idx].a <= i && idx < N){
                q.push(node[idx].b);
                idx++;
            }
            if(!q.empty()){
                sum+=q.top();
                q.pop();
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 2936
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

MOD = 998244353

def repeatSquares(x, n):  # x^n
    res = 1
    while n != 0:
        if n % 2 == 1:
            res *= x
            res %= MOD  # MOD演算ないなら消していい
        x *= x
        n //= 2
        x %= MOD      # MOD演算ないなら消していい
    return res

N = int(input())
D = [0] + list(map(int, input().split()))

ans = 0
if D[1] == 0:
    D = D[2:]
    D.sort()
    
    ans = 1
    
    now = 1
    preCnt = 1
    cnt = 0
    for e in D:
        if e == now:
            cnt += 1
        else:
            ans *= repeatSquares(preCnt, cnt)
            ans %= MOD

            preCnt = cnt
            
            cnt = 1
            now += 1
            if now != e:
                ans = 0
                break

    ans *= repeatSquares(preCnt, cnt)
    ans %= MOD
print(ans)


Measured memory_bytes: 54444
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0), ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	string s; cin >> s;
	vi sum;
	sum.push_back(0);
	rep(i,n){
		int cnt = 0;
		char tmp = s[i];
		while(s[i] == tmp){
			cnt++;
			i++;
		}
		i--;
		sum.push_back(cnt);
	}
	int sz = sum.size();
	rep(i,sz-1) sum[i+1] += sum[i];
	int ans = 0;
	if(s[0] == '1'){
		rep(i,sz){
			if(i%2) chmax(ans,sum[min(sz-1,i+k*2)]-sum[i]);
			else chmax(ans,sum[min(sz-1,i+k*2+1)]-sum[i]);
		}
	}else{
		rep(i,sz){
			if(i%2) chmax(ans,sum[min(sz-1,i+k*2+1)]-sum[i]);
			else chmax(ans,sum[min(sz-1,i+k*2)]-sum[i]);
		}
	}
	cout << ans;
	cout << "\n";
	return 0;
}


Measured memory_bytes: 4108
#include<bits/stdc++.h>
using namespace std;
#define MN 105
#define inf 0x7f7f7f7f
int fr[MN],nex[MN*MN*2],vi[MN*MN*2],wi[MN*MN*2],tot=0,pi[MN*MN*2];
void Add(int x,int y,int z){
	vi[++tot]=y;wi[tot]=z;nex[tot]=fr[x];fr[x]=tot;
}
void add(int a,int b,int c){
	Add(a,b,c);Add(b,a,0);
}
int v[MN];int n;
int cur[MN],dep[MN],s,t,xr[MN];
void init(){
	++xr[dep[t]=1];
	queue<int> Q;
	Q.push(t);
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		for(int i=fr[x];i;i=nex[i])if(!dep[vi[i]]){
			++xr[dep[vi[i]]=dep[x]+1];
			Q.push(vi[i]);
		}
	}
}
long long dfs(int x,int f){
	if(x==t||f==0)return f;
	int flow=0,fl;
	for(int &i=cur[x];i;i=nex[i]){
		if(dep[x]==dep[vi[i]]+1&&(fl=dfs(vi[i],min(f,wi[i])))>0){
			f-=fl;flow+=fl;wi[i]-=fl;wi[(i&1)?(i+1):(i-1)]+=fl;if(!f)return flow;
		}
	}
	if(!(--xr[dep[x]]))dep[s]=n+3;
	else ++xr[++dep[x]],cur[x]=fr[x];
	return flow;
}
int main(){
	long long sum=0;scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",v+i);
	for(int i=1;i<=n;++i){
		if(v[i]>=0)add(i,n+1,v[i]),sum+=v[i];
		else add(0,i,-v[i]);
		for(int j=2;j*i<=n;++j){
			add(i,j*i,inf);
		}
	}
	s=0;t=n+1;init();for(int i=0;i<=n+1;++i)cur[i]=fr[i];
	// for(int i=0;i<=n+1;++i)cout<<dep[i]<<' ';
	while(dep[s]<=n+2)sum-=dfs(s,inf);
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

W,H,N = map(int, input().split())

x_s,y_s,a_s = [],[],[]
for i in range(N):
  x,y,a = map(int, input().split())
  x_s.append(x)
  y_s.append(y)
  a_s.append(a)
    
x_s = np.array(x_s)
y_s = np.array(y_s)
a_s = np.array(a_s)

if (a_s==1).sum()>=1:
  x_min = x_s[a_s==1].max()
else:
  x_min = 0
  
if (a_s==2).sum()>=1:
  x_max = x_s[a_s==2].min()
else:
  x_max = W
  
if (a_s==3).sum()>=1:
  y_min = y_s[a_s==3].max()
else:
  y_min = 0
  
if (a_s==4).sum()>=1:
  y_max = y_s[a_s==4].min()
else:
  y_max = H
  
if (x_min>=x_max)|(y_min>=y_max):
  ans = 0
else:
  ans = (x_max-x_min)*(y_max-y_min)
  
print(int(ans))


Measured memory_bytes: 12504
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(min(A+1, X//500 + 1)):
    for b in range(min(B+1, (X - 500*a)//100 + 1)):
        tmp = X - 500 * a - 100 * b
        if tmp % 50 == 0 and tmp >= 0 and tmp <= 50 * C:
            ans += 1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b){
        if(b<c){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
}


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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

vll M;

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

ll dfs(ll v){
	if(M[v]>=0) return M[v];

	ll B=0,V=v;
	while(V){
		if(V&1) B++;
		V/=2;
	}

	if(!B){
		M[v]=0;
		return 0;
	}
	if(!(v%B)){
		M[v] = 1;
		return 1;
	}

	ll C = dfs(v%B)+1;
	M[v] = C;
	return C;
}

ll safemod(ll a,ll m){
	return (a%m+m)%m;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	string X=in<string>();
	M.resize(N+1,-1);
	ll C=0;
	REP(i,N){
		if(X[i]=='1'){
			C++;
		}
	}
	ll modP=0,modD=0;
	vll powermodP(N),powermodD(N);
	if(C<N){
		REP(j,N){
			powermodP[j] = powermod(2,j,C+1);
			if(X[N-1-j]=='1'){
				modP += powermodP[j];
				modP %= (C+1);
			}
		}
	}
	if(C>1){
		REP(j,N){
			powermodD[j] = powermod(2,j,C-1);
			if(X[N-1-j]=='1'){
				modD += powermodD[j];
				modD %= (C-1);
			}
		}
	}

	ll K[2]={C-1,C+1};
	REP(i,N){
		ll B;
		ll mod=0;
		if(X[i]=='0'){
			B = 1;
			mod = modP;
			mod += powermodP[N-1-i];
			mod %= K[B];
		}
		else{
			B = 0;
			if(K[B]==0){
				out(0);
				continue;
			}
			mod = modD;
			mod -= powermodD[N-1-i];
			mod = safemod(mod,K[B]);
		}

		ll Z=1;
		while(mod){
			Z++;
			ll P=0,V=mod;
			while(V){
				if(V&1) P++;
				V/=2;
			}
			mod %= P;
		}
		out(Z);
	}


	return 0;
}


Measured memory_bytes: 8312
S = []
A = raw_input().split()

for i in A:
    if i == '+':
        S.append(int(S.pop()) + int(S.pop()))
    elif i == '-':
        S.append(-int(S.pop()) + int(S.pop()))
    elif i == '*':
        S.append(int(S.pop()) * int(S.pop()))
    else:
        S.append(i)

print S[0]

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
string s;
int main(){ _;
  cin>>s;
  map<char,int> m;
  for(char i='a';i<='z';i++) m[i]=0;
  REP(i,s.length())
    m[s[i]]+=1;
  for(char i='a';i<='z';i++){
    if(m[i]>=2){
      cout<<"no"<<endl;
      return 0;
    }
  }
  cout<<"yes"<<endl;
  return 0;
}


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

int main() {
  ll n;
  ll l[105];
  cin >> n;
  rep(i, n) cin >> l[i];
  ll ans = 0;
  for (int x = 0; x < n; x++) {
    for (int y = x + 1; y < n; y++) {
      for (int z = y + 1; z < n; z++) {
        if (l[x] < l[y] + l[z] && l[y] < l[x] + l[z] && l[z] < l[x] + l[y] &&
            l[x] != l[y] && l[y] != l[z] && l[z] != l[x]) {
          // cout << x << " : " << y << " : " << z << endl;
          ans++;
        }
      };
    };
  };
  cout << ans << endl;
  return 0;
}

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

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


	int A;
	string S;
	cin >> A >> S;

	if (A >= 3200) co(S);
	else co("red");

	Would you please return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
diff_x = x2-x1
diff_y = y2-y1
x3 = x2 - diff_y
y3 = y2 + diff_x
x4 = x3 - diff_x
y4 = y3 - diff_y

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#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 x, y, z;
    cin >> x >> y >> z;
    cout <<  z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Pg
{
    static void Main()
    {
        var P = new Prime();
        const int LASTPRIME = 50021;
        var PrmLst = P.GetPrimeNums(LASTPRIME).ToList();

        string line;
        while ((line = Console.ReadLine()) != null)
        {
            var n = int.Parse(line);
            var prev = PrmLst.Where(x => x < n).Max();
            var next = PrmLst.Where(x => x > n).Min();
            Console.WriteLine("{0} {1}", prev, next);
        }
    }
}
class Prime
{
    internal IEnumerable<int> GetPrimeNums(int last)
    {
        for (int i = 0; i <= last; ++i)
        {
            if (IsPrime(i))
                yield return i;
        }
    }
    private bool IsPrime(int num)
    {
        if (num < 2)
            return false;
        else if (num == 2)
            return true;
        else if (num % 2 == 0)
            return false;

        for (int i = 3; i <= Math.Sqrt(num); i += 2)
        {
            if (num % i == 0)
                return false;
        }
        return true;
    }
}




Measured memory_bytes: 16348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int num = 1;

		while(num*2 <= n) {
			num = num*2;
		}

		System.out.println(num);
	}
}


Measured memory_bytes: 21972
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  string s;
  cin >> s;
  int N, S, E, W;

  N = 0; S = 0; E = 0; W = 0;
  for(int i=0;i<s.size();i++){
    char c = s[i];
    if(c == 'N') N++;
    else if(c == 'S') S++;
    else if(c == 'E') E++;
    else if(c == 'W') W++;
  }

  if((N == 0 && S == 0) || (N > 0 && S > 0)){
    if((E == 0 && W == 0) || (E > 0 && W > 0)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  int ret = 0;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ret += min(x, K - x);
  }
  cout << ret * 2 << endl;
}

Measured memory_bytes: 256
//SelecionSort

#include<stdio.h>

int main(void){
  int n,a[100],i,j,count=0,min,temp,flag;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  for(i=0;i<n;i++){
    min=i;
    flag=0;
    for(j=i;j<n;j++){
      if(a[j]<a[min]) {
	min=j;
	flag=1;
      }
    }
    if(flag==1){
    temp=a[min];
    a[min]=a[i];
    a[i]=temp;
    count++;
    }
  }
  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",a[i]);
    else printf("%d ",a[i]);
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 600
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int dp[M+4][2],n;
string s;
int solve(int pos,int is_sml)
{
    if(pos>=n)
    {
        return 1;
    }
    int &ret=dp[pos][is_sml];
    if(ret!=(-1))return ret;
    ret=1;
    if(is_sml)
    {
        ret=gun(3LL,solve(pos+1,is_sml));
    }
    else
    {
         if(s[pos]=='0')
         {
             ret=solve(pos+1,is_sml);

         }
         else
         {
             int x=gun(2LL,solve(pos+1,is_sml));
             int y=solve(pos+1,1);
             ret=ad(x,y);
         }

    }
    return ret%mod;
}
 main()

{
    fast
    memset(dp,-1,sizeof dp);
    cin>>s;
    n=s.size();
    cout<<solve(0,0)<<endl;
    return 0;

}





































Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define rev1(i,n) for(int i=n;i>0;i--)
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int> >
#define vb vector<bool>
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;

void solve(){
  int n;cin>>n;
  int arr[n];rep(i,n) cin>>arr[i];
  sort(arr,arr+n);
  double ans=0.0;
  ans=(arr[0]+arr[1])/2.0;
  for(int i=2;i<n;i++) ans=(ans+arr[i])/2.0;
  cout<<ans;
}
signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 200005;

char t[N];
string s;
int i;

int main() {
scanf("%s", t);
s = t;
for (i=0;i<s.size();i++) if (s[i] == '?') s[i] = 'D';
printf("%s\n", s.c_str());
return 0;
}

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

#define ll long long

int main(){
    string s;
    cin >> s;
    int N = s.size();
    ll ans = 0;
    for(int i = 0; i < (1 <<(N-1)); i++){
        ll sum = 0;
        ll a = s[0] - '0';
        for(int j=0; j<N-1; j++){
            if(i & (1<<j)){
                sum += a;
                a = 0;
            }
            a = a * 10 + s[j+1] -'0';
        }
        sum += a;
        ans += sum;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long int;

int main()
{
    ll l, r;
    cin >> l >> r;
    ll mn = 1 << 30;
    for (ll i = l; i < r; ++i) {
        ll tmp = 0;
        for (ll j = i+1; j <= r; ++j) {
            tmp = (i * j) % 2019;
            if (mn > tmp) mn = tmp;
            if (!tmp) break;
        }
        if (!tmp) break;
    }
    cout << mn << endl;
    return 0;
}

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

int ck(int v1[], int v2[], int n){
    int a=1;;
    for (int i=0; i<n; i++){
        if (v1[i]!=v2[i]){
            a=0;
            break;
        }
    }
    return a;
}
long long a=1,b=1,n,c,d;
string ss,s1,s2;
int main(){
    map<string,int>v;
    v["SUN"]=0;
    v["MON"]=1;
    v["TUE"]=2;
    v["WED"]=3;
    v["THU"]=4;
    v["FRI"]=5;
    v["SAT"]=6;
    cin>>ss;
    cout<<7-v[ss];
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct List {
	struct List *next;
	long long v, num;
} list;

int main()
{
	int i, N, M, A[100001];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	list *h[10007] = {}, d[100001], *p;
	long long ans = 0, sum;
	d[0].v = 0;
	d[0].num = 1;
	d[0].next = NULL;
	h[0] = &(d[0]);
	for (i = 1, sum = 0; i <= N; i++) {
		sum = (sum + A[i]) % M;
		for (p = h[sum%10007]; p != NULL; p = p->next) if (p->v == sum) break;
		if (p != NULL) p->num++;
		else {
			d[i].v = sum;
			d[i].num = 1;
			d[i].next = h[sum%10007];
			h[sum%10007] = &(d[i]);
		}
	}
	for (i = 0; i < 10007; i++) {
		for (p = h[i]; p != NULL; p = p->next) ans += p->num * (p->num - 1) / 2;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main(){
    /*
        Statement:
            it is possible, if and only if we have even number of odds(number of possible i, when A[i] is odd, is even)
        Proof:
            we can show two numbers that have the same parity like this:
            2k + q, 2t + q.
            so this is their sum:
            2k + 2t + q + q = 2(k + t + q)
            so their sum is always even

            with that being saied, if we have even number of odds, we can perform the operation on all of them and endup with a bunch of even numbers.

            if we have odd number of odds, we have and invariance: the number of odd numbers can only decrease by 2. so we cna never achive 0.
            so we have at least one odd number.
            because N > 2, if we get to the existence of only one odd number, we have at least one even number.
            therefore, Takashi can't achive his goal.
    */

    int N;
    cin >> N;
    int A[N];

    int odds = 0;
    for (int i = 0; i < N; i++){
        cin >> A[i];
        if (A[i] % 2 == 1)
            odds++;
    }

    cout << (odds % 2 ? "NO" : "YES") << endl;
    
    return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var r, c int
	fmt.Scan(&r, &c)
	sumcol := make([]int, c+1)
	for i := 0; i < r; i++ {
		var sum int
		for j := 0; j < c; j++ {
			var n int
			fmt.Scan(&n)
			sum += n
			sumcol[j] += n
			fmt.Printf("%d ", n)
			if j == c-1 {
				sumcol[j+1] += sum
				fmt.Println(sum)
			}
		}
		if i == r-1 {
			for k, sums := range sumcol {
				if k != len(sumcol)-1 {
					fmt.Printf("%d ", sums)
				} else {
					fmt.Println(sums)
				}
			}
		}
	}
}



Measured memory_bytes: 1884
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=1001 ;
int main()
{
   fast ;
   ll n,k ;
   cin>>n>>k ;
   vector<ll>v(n) ;
   for(ll i=0;i<n;i++)
    cin>>v[i] ;

   sort(all(v)) ;

   ll ans=0 ;


   reverse(all(v)) ;
   for(ll i=k;i<v.size();i++)
   {
       ans+=v[i] ;
   }
   cout<<ans ;


}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
    double t, x;
    cin >> t >> x;
    cout << (t / x) << 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);

		long a = sc.nextLong(); //1
		long b = sc.nextLong(); //0
		long c = sc.nextLong(); //-1
		long k = sc.nextLong();
		
		long sum = 0;
		
		long take = Math.min(a, k);
		sum += take;
		k -= take;
		
		if(k > 0)
		{
			k -= b;
		}
		
		if(k > 0)
		{
			sum -= k;
		}
		
		System.out.println(sum);
		
		
	}

}


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

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vvint(v, w, n) vector<int> v(n); vector<int> w(n); REP(i,n) cin >> v[i] >> w[i];
#define vlint(v, n) vector<ll int> v(n); REP(i,n) cin >> v[i];
#define vdouble(v, n) vector<double> v(n); REP(i,n) cin >> v[i];
#define vvdoube(v, n1, n2) vector<vector<double> > v(n1, vector<double>(n2, 0)); REP(i,n1) REP(j,n1) cin >> v[i][j];
#define string(x) string x; cin >> x;
#define vstring(v, n) vector<string> v(n); REP(i,n){string a; std::cin >> a; v.push_back(a); }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()
#define len(v) (v).length()
#define FIND(s, n) (s.find(n) != s.end())
#define SORT(a) sort(all(a))

static const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long MOD = 1000000007;
static const double PI=3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[]={0, 0, 1, -1};
static const int dx4[]={1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int G[8][8];

int dfs(int v, int N, bool visited[]){

  bool all_visited=true;
  REP(i, N) if(visited[i]==false) all_visited=false;
  if(all_visited) return 1;

  int ret = 0;

  REP(i, N){
    if(G[v][i]==false) continue;
    if(visited[i]) continue;

    visited[i] = true;
    ret += dfs(i, N, visited);
    visited[i] = false;
  }

  return ret;
}

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

  int N, M;
  cin >> N >> M;

  REP(i, M){
    int A, B;
    cin >> A >> B;
    G[A-1][B-1]=G[B-1][A-1]=true;
  }

  bool visited[8];
  REP(i, N) visited[i]=false;

  visited[0]=true;
  cout << dfs(0, N, visited) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 2e3+1;
const ll mod = 1e9+7;


int main(){

    FASTIO;
    PRECISION; 

    int n;
    cin>>n;
    vector<pair<string,pair<int,int>>>arr(n);
    string s;
    int p;

    for(int i=0;i<n;i++){
        cin>>s>>p;
        arr[i] = {s,{-p,i+1}};
    }

    sort(arr.begin(),arr.end());
    for(auto x: arr){
        cout<<x.second.second<<"\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root,NIL;
int maxh = 0;

Node treeSearch(Node u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;
    }
    else{
      u = u->right;
    }
  }
  return u;
}

void insert(int k){
  int H;
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char com[20];
  Node t;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",com);
    if(strcmp(com,"find") == 0){
      scanf("%d",&x);
      t = treeSearch(root,x);
      if(t != NIL){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
    else if(strcmp(com,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

  



Measured memory_bytes: 20452
n, m = map(int, input().split())
if n < 2 and m < 2:
    ans = 1
elif n < 2:
    ans = m - 2
elif m < 2:
    ans = n - 2
else:
    ans = n * m - (2 * n + 2 * m - 4)
print(ans)


Measured memory_bytes: 2940
import collections
n=int(input())
S=input()
c=collections.Counter(S)
ans=c['R']*c['B']*c['G']
hiku=0
for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>n-1:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
          hiku+=1
print(ans-hiku)

Measured memory_bytes: 9444
#include <stdio.h>
#include <stdlib.h>
#define ll long long
ll max(ll x,ll y){return x<y?y:x;}
ll ceilll(ll x,ll y){if(x%y==0)return x/y;
else return x/y+1;}
int main(void){
	ll n,t,a,i,x,y,m;
	scanf("%lld",&n);
	scanf("%lld %lld",&t,&a);
	for(i=1;i<n;i++){
		scanf("%lld %lld",&x,&y);
		m=max(ceilll(t,x),ceilll(a,y));
		t=m*x;
		a=m*y;
	}
	printf("%lld",t+a);
	return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    REP(i, s.size()) {
        if(i%2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 512
#include<stdio.h>

int main(void){
  int N,K,i,d,tmp,cnt=0;
  int a[101];
  scanf("%d %d\n",&N,&K );
  for(i=0; i<N; i++){
    a[i] = -1;
  }
  for(i=0; i<K ;i++){
    scanf("%d\n",&d );
    for(int j=0; j<d; j++){
      scanf("%d",&tmp );
      a[tmp-1] = 1;
    }
  }
  for(i=0; i<N; i++){
    if(a[i] == -1) cnt++;
  }
  printf("%d\n",cnt );
  return 0;
}

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

using namespace std;
typedef long long ll;

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl;
#else
#define DEBUG(x)
#endif

#define ALL(obj) (obj).begin(), (obj).end()
#define BIT(n) (1LL << (n))

const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    // write code below
    ll X;
    ll K;
    ll D;
    cin >> X >> K >> D;
    X = abs(X);
    ll q = X / D;
    if (K >= q)
    {
        if ((K - q) % 2 == 0)
        {
            cout << X % D << endl;
        }
        else
        {
            cout << min(X % D + D, abs(X % D - D)) << endl;
        }
    }
    else
    {
        cout << abs(X - K * D) << endl;
    }

    // write code above
    return 0;
}


Measured memory_bytes: 3624
import itertools 
N = int(input())
evidence_dit = {} 
for i in range(N):
    A = int(input())
    x_y = []
    if A == 0:
        evidence_dit[i] = []
    for j in range(A):
        x_y.append(list(map(int,input().split())))        
        evidence_dit[i] = x_y 
ans = 0
attribute = [0,1] 
for i in itertools.product(attribute,repeat=N):
    flag = False    
    for j in range(N):
       if i[j] == 1:            
            for k in evidence_dit[j]:
                if i[k[0]-1] != k[1]:
                    flag = True
                    break
            if flag:
                break 
    if flag == False:
        ans = max(ans,sum(i))        
print(ans)
'''
入力:辞書型で置いておくことにした。
{0: [[2, 1], [3, 0]], 1: [[3, 1], [1, 0]], 2: [[1, 1], [2, 0]]}
証言が無い場合に [ ] を入れる。
attribute = [0,1] 
for i in itertools.product(attribute,repeat=N):
正直、不正直のパターンを列挙するところ、itertoolsで0,1の重複順列
for i in range(2 ** N):
    h = [0] * N 
    for j in range(N):
        if (i >> j) & 1:
            h[j] = 1
ビット演算子
i >> j　i を右に j ビットシフト
5 >> 2　5 を右に 2 ビットシフト
　　　　 101｜　➡　001｜01　➡　001
　　　　 右へ２つずらして足りなくなった桁は0にする。　
5 & 1　➡　101 AND 001　➡　001
　　　　　　両方１のところだけ１になる。
if 5 & 1:　5 & 1 の答えが１なら True、他は False
[0, 0, 0] [1, 0, 0] [0, 1, 0] [1, 1, 0] [0, 0, 1] [1, 0, 1] 
[0, 1, 1] [1, 1, 1]、のような0,1の全パターンを出している。
'''

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll memo[51][2];

int main() {
  ll N, P;
  cin >> N >> P;
  vector<ll> A(N);
  vector<ll> cnt(2, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cnt[A[i] % 2]++;
  }
  if (cnt[0] == N) {
    if (P == 0) {
      cout << (1LL << N) << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  cout << (1LL << (N - 1)) << endl;
  return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    int x1, y1;
    int x2, y2;
    int x3, y3;
    int x4, y4;
    int dx, dy;

    cin >> x1 >> y1;
    cin >> x2 >> y2;

    dx = x2 - x1;
    dy = y1 - y2;

    x3 = x2 + dy;
    y3 = y2 + dx;
    x4 = x3 - dx;
    y4 = y3 + dy;

    printf("%d %d %d %d\n", x3, y3, x4, y4);

    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())

dif = b - a #aとbの高さの差 = 柱bの前の柱との差

#前の柱との差を入れると高さを返す関数
def hgt(x):
  return round( (x+1)*x / 2 )

print(hgt(b-a)-b)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int GCD(int x, int y) {if (x % y) {return GCD(y, x % y);} return y;}
int LCM(int x, int y) {return x * y / GCD(x, y);}

int main() {
    int X;
    cin >> X;
    int L = LCM(360, X);
    cout << L / X << "\n";
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int N;cin >> N;
    vector<ll> a(N),b(N),c(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];
    vector<vector<ll>> dp(N+1,vector<ll>(3));
    for(int i=0; i<N; i++){
        dp[i+1][0]=max(dp[i][1]+a[i],dp[i][2]+a[i]);
        dp[i+1][1]=max(dp[i][0]+b[i],dp[i][2]+b[i]);
        dp[i+1][2]=max(dp[i][0]+c[i],dp[i][1]+c[i]);
    }
    cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

void solve(){
	
	int n,x ;
	cin>>n>>x ;

	vector<ll> arr(n) ;

	for(int i=0;i<n;i++){
		cin>>arr[i] ;
	}

	vector<ll> temp(n) ;

	temp=arr ;

	if(arr[0]>x){
		arr[0]=x ; 
	}

	for(int i=0;i<n-1;i++){
		
		if(arr[i]+arr[i+1]>x){
			arr[i+1]=x-arr[i] ;
		}
	}
	/*
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" " ;
	}
	*/
	ll diff=0 ;

	for(int i=0;i<n;i++){
		diff+=temp[i]-arr[i] ;
	}

	cout<<diff ;
}


int main(){


	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 4824
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <int,int>
#define N 300005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int A[N], tree[4 * N];
void build(int l, int r, int i)
{
	if(l == r)
	{
		tree[i] = A[l];
		return;
	}
	int mid = (l + r) / 2;
	build(l, mid, 2 * i);
	build(mid + 1, r, 2 * i + 1);
	tree[i] = __gcd(tree[2 * i], tree[2 * i + 1]);
}
int query(int ql, int qr, int l, int r, int i)
{
	if(ql > r || l > qr || l > r)
		return 0;
	if(ql <= l && r <= qr)
		return tree[i];
	int mid = (l + r) / 2;
	return __gcd(query(ql, qr, l, mid, 2 * i), query(ql, qr, mid + 1, r, 2 * i + 1)); 
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> A[i];
	}
	build(1, n, 1);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		ans = max(ans, __gcd(query(1, i - 1, 1, n, 1), query(i + 1, n, 1, n, 1)));
	}
	cout << ans;
}

Measured memory_bytes: 1664
#include<stdio.h>
int main()
{
  int N,i,j,k,minj,count=0;
  int A[100];

  scanf("%d",&N);
  for(i=0; i<N; i++)
    scanf("%d",&A[i]);

  for(i=0; i<=N-1; i++){
    minj = i;
    for(j=i; j<=N-1; j++){
      if(A[j]<A[minj])
	minj = j;
    }
    if(i != minj){
      count++;
      k = A[i];
      A[i] = A[minj];
      A[minj] = k;
    }
  }

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



Measured memory_bytes: 2128
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


void solve_i(bool&is_found, vi&ans, int n, int m, int c, int d)
{
//	if(is_found) return;

	for(int i=1;i<n;i++)
	{
		int j=(i+c+d-1)%n;

		if(ans[i]) continue;
		if(ans[j]) continue;

		ans[i]=ans[j]=c;
		if(c==m)
		{
			for(int ma:ans) printf("%2d ", ma); printf("\n");
			is_found=true;
//			return;
		}
		else
		{
			solve_i(is_found, ans, n, m, c+1, d);
//			if(is_found) return;

			ans[i]=ans[j]=0;
		}
		ans[i]=ans[j]=0;
	}
}


void solve(vpii&ans, int n, int m)
{
	int h=n/2;

	ans.clear();
	for(int i=0;i<m;i++)
	{
		ans.push_back(make_pair(i+1, n-i));
		if(ans.size()>=m) break;
		ans.push_back(make_pair(h-i, h+2+i));
		if(ans.size()>=m) break;
	}
}


int main(void)
{
	int n, m;
	while(scanf("%d%d", &n, &m)==2)
	{
		vpii ans;

		solve(ans, n, m);
		for(auto&ma:ans) printf("%d %d\n", ma.first, ma.second);
	}
	return 0;
}


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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int a=n%10;
    switch(a){
    case 2:case 4:case 5:case 7:case 9:{cout<<"hon";break;}
    case 0:case 1:case 6: case 8:{cout<<"pon";break;}
    case 3:{cout<<"bon";break;}
    }

return 0;
}


Measured memory_bytes: 3616
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b = Is()

if (a+b) % 2 == 1:
    print("IMPOSSIBLE")
else:
    print(int((a+b)/2))

Measured memory_bytes: 38256
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える 小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

using ll = long long;



int main()
{

	int N; cin >> N;

	ll nnot = 1, all = 1;

	for (int i = 0; i < N; ++i)
	{
		int A; cin >> A;

		if (A % 2 == 0)
		{
			nnot *= 2;
		}
		all *= 3;
	}

	cout << all - nnot << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

#define ll long long

ll lcm(ll x, ll y)
{
    ll xy = x*y;
    if(x<y)swap(x,y);
    ll r;
    r = x%y;
    while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }
  return xy/y;
}

int main()
{
    ll a,b,c,d;
    cin >> a >> b>> c >> d;
    ll div_c;
    ll head;
    ll tail;
    if(a%c!=0) head = a/c+1;
    else head = a/c;
    tail = b/c;
    div_c = tail - head +1;


    ll div_d;
    if(a%d!=0) head = a/d+1;
    else head = a/d;
    tail = b/d;
    div_d = tail - head+1;


    ll div_cd;
    ll cd;
    cd  = lcm(c,d);
    if(a%cd!=0) head = a/cd+1;
    else head = a/cd;
    tail = b/cd;
    div_cd = tail - head +1;
    


    ll answer;
    answer = b-a+1-div_c-div_d+div_cd;
    cout << answer << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  ll a,b,c,k,ans=0; cin >> a >> b >> c >> k;

  ans+=min(a,k);
  k-=a;
  if(k>0){
     ans+=0*min(k,b);
  }
  k-=b;
  if(k>0){
    ans-=min(k,c);
  }
  cout  << ans << endl;
  
}

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

# In[6]:


import numpy as np


# In[33]:


H,W = map(int, input().split())
a = []
for _ in range(H):
    row = input()
    a.append([1 if row[i] == "#" else 0 for i in range(W)])


# In[36]:


a_array = np.array(a)
col_flag = True
row_flag = True
# print(a_array)
while col_flag:
    for col in range(len(a_array)):
        if sum(a_array[col]) == 0:
            a_array = np.delete(a_array, col, 0)
#             print(a_array)
            break
    else:
        col_flag = False
while row_flag:
    for row in range(len(a_array[0])):
        if sum(a_array[:,row]) == 0:
            a_array = np.delete(a_array, row, 1)
#             print(a_array)
            break
    else:
        row_flag = False
for i in range(len(a_array)):
    tmp = ["#" if x == 1 else "." for x in a_array[i]]
    print("".join(tmp))


# In[ ]:






Measured memory_bytes: 21204