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

using namespace std;

const int N = 200100;

vector<int> g[N];

bool mark[N];
int match[N];
int n;

bool dfs(int v) {
  if (mark[v]) {
    return false;
  }
  mark[v] = true;
  for (int to : g[v]) {
    if (match[to] == -1 || dfs(match[to])) {
      match[to] = v;
      match[n + v] = to;
      return true;
    }
  }
  return false;
}

int matching() {
  memset(match, -1, sizeof match);
  while (true) {
    memset(mark, false, sizeof mark);
    bool done = true;
    for (int i = 0; i < n - 1; i++) {
      if (match[n + i] == -1) {
        done &= !dfs(i);
      }
    }
    if (done) {
      break;
    }
  }
  int res = 0;
  for (int i = 0; i < n - 1; i++) {
    res += (match[n + i] != -1);
  }
  return res;
}

vector<pair<int, int>> ed;

int make(int v) {
  int res = 1;
  for (int to : g[n + v]) {
    if (!mark[to]) {
      mark[to] = 1;
      assert(match[n + to] != -1);
      ed[to] = {v, match[n + to]};
      res += make(match[n + to]);
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int c;
    cin >> c;
    while (c--) {
      int x;
      cin >> x;
      --x;
      g[i].push_back(x);
      g[n + x].push_back(i);
    }
  }
  if (matching() != n - 1) {
    cout << -1 << '\n';
    return 0;
  }
  int root = -1;
  for (int i = 0; i < n; i++) {
    if (match[i] == -1) {
      root = i;
      break;
    }
  }
  memset(mark, 0, sizeof mark);
  ed.resize(n - 1);
  if (make(root) != n) {
    cout << -1 << '\n';
  } else {
    for (auto e : ed) {
      cout << e.first + 1 << " " << e.second + 1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 20760
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    print(A^B^C)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
using namespace std;

int _now[1<<20],_next[1<<20];

const int modBase = 100000;

int main(){
	char mapData[21][20];
	int w,h;
	scanf("%d%d",&h,&w);
	
	int* now =_now;
	int* next = _next;
	
	for(int i=0;i<h;i++)
		scanf("%s",mapData[i]);
	for(int i=1;i<(1<<w);i++)
		now[i]=0;
	now[0] = 1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int k=0;k<(1<<w);k++)
				next[k] = 0;
			for(int k=0;k<(1<<w);k++){
				if(mapData[i][j] == 'J' || mapData[i][j] == '?'){
					int idx;
					if(j == 0){
						idx = (1<<(w-1))|(k&(~(1)));
					}else{
						idx = (1<<(w-1))|(k&(~(3<<(j-1))));
					}
					next[idx] += now[k];
					next[idx] %= modBase;
				}
				if(mapData[i][j] == 'O' || mapData[i][j] == '?'){
					int idx;
					if(j == 0){
						idx = (~(1<<(w-1)))&k&(~1);
					}else if(k&(1<<(w-1))){
						idx = (~(1<<(w-1)))&k&(~(1<<j))|(1<<(j-1));
					}else{
						idx = (~(1<<(w-1)))&k&(~(3<<(j-1)));
					}
					next[idx] += now[k];
					next[idx] %= modBase;
				}
				if(mapData[i][j] == 'I' || mapData[i][j] == '?'){
					int idx=0;
					if(j < w-1 &&k & (1<<j)){
						continue;
					}
					if(j==0){
						idx = (~(1<<(w-1)))&k&(~1);
					}else{
						idx = (~(1<<(w-1)))&k&(~(3<<(j-1)));
					}
					next[idx] += now[k];
					next[idx] %= modBase;
				}
			}
			swap(now,next);
		}
	}
	int ans=0;
	for(int i=0;i<(1<<w);i++){
		ans = (ans+now[i])%modBase;
	}
	int all=1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(mapData[i][j] == '?')
				all = (all*3)%modBase;
		}
	}
	printf("%d\n",(all+modBase-ans)%modBase);
}

Measured memory_bytes: 9200
import math
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
	x[i], y[i] = map(int, input().split())

sum = 0
for i in range(n):
	for j in range(i, n):
		sum += math.sqrt((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2)

print(sum * 2 / n)

Measured memory_bytes: 3064
fun main(arr:Array<String>) {
    val src = readLine()!!
    val hint = readLine()!!
    var mtIndex = -1
    for(i in (0..src.length - hint.length)) {
        var mt = true
        for(j in hint.indices) {
            if(src[j+i] == '?') {
                continue
            }
            if(src[j+i] != hint[j]) {
                mt = false
                break
            }
        }
        if(mt) {
            mtIndex = i
        }
    }
    val ans = src.toMutableList()
    if(mtIndex >= 0) {
        for(i in hint.indices) {
            ans[i+mtIndex] = hint[i]
        }
        for(i in ans.indices) {
            if(ans[i] == '?') {
                ans[i] = 'a'
            }
        }
        println(ans.joinToString(""))
    } else {
        println("UNRESTORABLE")
    }

}


Measured memory_bytes: 33568
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

    int ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }

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


Measured memory_bytes: 256
import numpy as np
import sys

input = sys.stdin.readline

N,K,Q = [int(a) for a in input().split()]

score = np.full(N, K, dtype=int)

for i in range(Q):
    p = int(input())
    score[p-1] += 1 

score -= Q

is_win = score > 0

res = ["Yes" if a else "No" for a in is_win]

print("\n".join(res) + "\n")


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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}


// constants
const long double eps = 1e-9;
const ll inf = 1e18;
const int modn = 1e9+7;
const int MAX = 1e5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n;
	cin>>n;
	vector<ll> a(n+1);
	vector<ll> psum(n+1);
	vector<vector<ll>> dp(n+1, vector<ll>(n+1));
	assignVV(dp, (ll)-1);
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		psum[i]=psum[i-1]+a[i];
	}
	
	function<ll(int, int)> solve = [&](int i, int j)
	{
		if(j-i<=1) return psum[j]-psum[i-1];
		ll &memo=dp[i][j];
		if(memo!=-1) return memo;
		
		memo=inf;
		memo=min(memo, solve(i+1, j)+psum[j]-psum[i-1]);
		memo=min(memo, solve(i, j-1)+psum[j]-psum[i-1]);
		for(int k=i+1; k<=j-2; k++) {
			ll ans=solve(i, k)+solve(k+1, j)+psum[j]-psum[i-1];
			memo=min(memo, ans);
		}
		return memo;
	};
	cout<<solve(1, n)<<"\n";
	//~ printVV(dp);
    return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    int a[n][m], b[m][l];

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

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    long long int sub = 0;
    while (sub < n) {
        for (int j = 0; j < l; j++) {
            long long int sum = 0;
            for (int i = 0; i < m; i++) {
                sum += a[sub][i] * b[i][j];
            }
            cout << sum;
            if (j != l-1) {
                cout << " ";
            }
            else {
                cout << endl;
            }
        }
        sub++;
    }
}




Measured memory_bytes: 3172
#include<stdio.h>
//#define lli long long int 
int main(){
    long long int n,k,q;
    scanf("%lld %lld %lld",&n,&k,&q);
    long long int i;
    long long int j;
    long long int A[100000];
    int B[100000];
    for(i=1;i<=q;i++){
        scanf("%lld",&A[i]);
    }

    for(i=1;i<=n;i++){
        B[i]=k-q;    
    }
    for(i=1;i<=q;i++){
        B[A[i]]=B[A[i]]+1;
       // for(j=1;j<=n;j++){
       // printf("%d ",B[j]);
        //}
        //printf("\n");
    }
    //for(i=1;i<=n;i++){
    //    printf("%d ",B[i]);
    //}
    for(i=1;i<=n;i++){
        if(B[i]<=0){
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vvi a(2,vi(n));
	rep(i, 0, 2) {
		rep(j, 0, n) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	rep(i, 0, n) {
		int x;
		int sum = 0;
		rep2(j, 0, i) {
			x = j;
			sum += a[0][j];
		}
		rep(j, x, n) {
			sum += a[1][j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

using i64=long long;

const i64 INF=1LL<<61;

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> r(n), c(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d %d", &r[i], &c[i]);

    vector<vector<i64>> dp(n, vector<i64>(n, INF));
    for (size_t i=0; i<n; ++i) dp[i][i] = 0;

    for (size_t k=1; k<n; ++k)
        for (size_t i=0; i+k<n; ++i) {
            size_t j=i+k;
            for (size_t m=i; m<j; ++m) {
                i64 tmp=dp[i][m]+dp[m+1][j]+r[i]*c[j]*c[m];
                if (dp[i][j] > tmp)
                    dp[i][j] = tmp;
            }
        }

    printf("%lld\n", dp[0][n-1]);
    return 0;
}

Measured memory_bytes: 2780
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{  
	fast;
	ll R;
	cin>>R;
	cout << 2*pi*R << endl;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
  int n,m;
  cin  >> n >> m;
  vector<int> a(n+1,0),b(n+1,1);
  a.at(1)=1;
  rep(i,m){
    int x,y;
    cin >> x >> y;
    if (a.at(x)==1){
      a.at(y)=1;
      if (b.at(x)==1) {
        a.at(x)=0;
      }
    }
    b.at(x)--;
    b.at(y)++;
  }
  int ans=0;
  rep(i,n+1){
    if (a.at(i)==1) ans++;
  }
  cout << ans << endl;
  }

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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>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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N;
  cin>>N;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  ll ans=INF;
  REP(m,2){
    ll cnt=0,sum=0,si=2*m-1;
    REP(i,N){
      sum+=A[i];
      if(si==1){
        if(sum<=0) cnt+=1-sum,sum=1;
      }
      else{
        if(sum>=0) cnt+=1+sum,sum=-1;
      }
      si*=-1;
    }
    chmin(ans,cnt);
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

const int inf = 0x7fffffff;
const int maxn = 1000 + 5;
char maze[maxn][maxn];
int d[maxn][maxn];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int w, h, n;
struct Node {
	int x;
	int y;
} node[10 + 5];

int bfs(Node a, Node b) {
	queue<Node> que;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			d[i][j] = inf;
	d[a.x][a.y] = 0;
	que.push(a);
	while(!que.empty()) {
		Node pre = que.front();
		que.pop();
		if(pre.x == b.x && pre.y == b.y)
			break;
		for(int i = 0; i < 4; i++) {
			Node now;
			now.x = pre.x + dx[i];
			now.y = pre.y + dy[i];
			if(0 <= now.x && now.x < h && 0 <= now.y && now.y < w && maze[now.x][now.y] != 'X' && d[now.x][now.y] == inf) {
				que.push(now);
				d[now.x][now.y] = d[pre.x][pre.y] + 1;
			}
		}
	}
	return d[b.x][b.y];
}
int main() {
//ios::sync_with_stdio(false);
#ifdef LOCAL
freopen("lll.in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
	cin >> h >> w >> n;
	memset(maze, 0, sizeof maze);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> maze[i][j];
			if(maze[i][j] == 'S') {
				node[0].x = i;
				node[0].y = j;
			}
			if(isdigit(maze[i][j])) {
				//cout << maze[i][j] << endl;
				//cout << i << " " << j << endl;
			node[maze[i][j] - '0'].x = i;
			node[maze[i][j] - '0'].y = j;
			}
		}
	}
	long long ans = 0;
	for(int i = 0; i < n; i++) {
		ans += bfs(node[i], node[i + 1]);
	}
	cout << ans << endl;
}




Measured memory_bytes: 7932
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	ll n;
	cin >> n;
	if (n / 10 == 9 || n % 10 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}


/*
木にすべき
N-1本

最小全域木を作りたい

可能性のある道は、x,yそれぞれで隣接した辺のみで合計候補2nぐらい
これにクラスカル?
*/


const int  MAX_N = 100000;
int par[MAX_N];
int rk[MAX_N];

//配列が長さnのものとして0で初期化する
void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rk[i] = 0;
    }
}

//xの親の要素の番号を返す
int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

//要素を併合する
//木の高さrkが低いほうを高いほうの親につなげる
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rk[x] < rk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rk[x] == rk[y]) rk[x]++;
    }
}

//要素が同じ集合に属しているかどうかを返す
bool same(int x, int y) {
    return find(x) == find(y);
}



const int MAX_E = 2e5;
struct edge {int u, v, cost;};
bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}
edge es[MAX_E];
int V, E;

//クラスカル法 UNION_FINDを使って既に同じ木にあるかどうか判定する
ll kruskal() {
    sort(es, es + E, comp);
    init(V);
    int res = 0;
    for (int i = 0; i < E; i++) {
        edge e = es[i];
        if (!same(e.u, e.v)) {
            unite(e.u,e.v);
            res += (ll)e.cost;
        }
    }
    return res;
}

int main() {

    int N; cin >> N;
    vector<pair<ll,ll> > x(N), y(N);
    for (int i = 0; i < N; i++) {
        ll s,t; cin >> s >> t;
        x[i] = make_pair(s,i);
        y[i] = make_pair(t,i);
    }
    //argsortしないとだめ
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    for (int i = 0; i < N-1; i++) {
        edge e1, e2;
        e1.u = x[i].second; e2.u = y[i].second;
        e1.v = x[i+1].second; e2.v = y[i+1].second;
        e1.cost = abs(x[i].first-x[i+1].first);
        e2.cost = abs(y[i].first-y[i+1].first);
        es[i] = e1; es[i+N-1] = e2;
    }

    V = N; E = 2 * N - 2;

    ll res = kruskal();
    cout << res << endl;


}


Measured memory_bytes: 6528
x, y, z, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
b = gets.split.map(&:to_i).sort.reverse
c = gets.split.map(&:to_i).sort.reverse
puts a.product(b).map { |x, y| x + y }.sort.reverse[0, k].product(c).map{ |x, y| x + y }.sort.reverse[0, k]

Measured memory_bytes: 287464
#include <iostream>
#include <cmath>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) {
    LL t;
    while(b != 0) {
        t = a % b;
        a = b;
        b = t;
    }

    return a;
}

LL lcm(LL a, LL b) {
    if(a * b == 0) {
        return 0;
    }

    return (a*b / gcd(a,b));
}

int main() {
    LL a, b, number_of_sweets;

    cin >> a >> b;
    number_of_sweets = lcm(a, b);
    // a,bの最小公倍数を求める
    cout << number_of_sweets << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 1050;
const long long INF = 1e18;

int n, m;
long long x[MAXN], y[MAXN], z[MAXN];
long long dp[MAXN][MAXN];
long long ans = -INF;

int getBit(long long x, int pos) {
  return (x & (1ll << pos)) > 0 ? 1 : 0;
}

int main() { 

  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
  }

  for (int mask = 0; mask < (1 << 3); mask++) {
    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < n; i++) {
      if (getBit(mask, 0)) {
        x[i] = -x[i];
      }
      if (getBit(mask, 1)) {
        y[i] = -y[i];
      }
      if (getBit(mask, 2)) {
        z[i] = -z[i];
      }
    }

    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        dp[i][j] = -INF;
      }
    }

    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= min(i, m); j++) {
        if (i > 1) {
          dp[i][j] = dp[i - 1][j];
        }
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + x[i - 1] + y[i - 1] + z[i - 1]);
      }
    }

    for (int i = 0; i < n; i++) {
      if (getBit(mask, 0)) {
        x[i] = -x[i];
      }
      if (getBit(mask, 1)) {
        y[i] = -y[i];
      }
      if (getBit(mask, 2)) {
        z[i] = -z[i];
      }
    }

    ans = max(ans, dp[n][m]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8832
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val suretu = readLine()!!.split(" ").map { it.toLong() }
    val count = mutableMapOf<Long,Int>()
    for(num in suretu) {
       if(count.containsKey(num)) {
           count[num] = count[num]!! + 1
       } else {
           count[num] = 1
       }
    }
    var ans = 0L
    for((key,v) in count) {
        if(key == v.toLong()) {
            continue
        }
        if(key > v.toLong()) {
            ans += v.toLong()
        } else {
            ans += v.toLong() - key
        }
    }
    println(ans)

}


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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)


int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   ull N,K;
   cin >> N >> K;
   FOR(i,N){
      int a;
      cin >> a;
   }
   if(N==K)cout << 1 << endl;
   else cout << 1 + (N-K)/(K-1) + ((N-K)%(K-1)!=0) << endl;
   return 0;
}


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

int main()
{
  long long a, b, k;
  scanf("%lld%lld%lld", &a, &b, &k);
  long long t = std::min(a, k);
  a -= t;
  k -= t;
  if (k > 0)
  {
    b -= std::min(b, k);
  }
  printf("%lld %lld\n", a, b);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>

const int MaxN = 200000 + 5, MaxM = 200000 + 5;

int N, M;
std::map<int, long long> Mp[MaxN];

struct SegTree {
  int L[MaxN * 4], R[MaxN * 4];
  long long Max[MaxN * 4], Tag[MaxN * 4];

  void pushDown(int i) {
    if (Tag[i] != 0) {
      int ls = i << 1, rs = i << 1 | 1;
      Max[ls] += Tag[i];
      Max[rs] += Tag[i];
      Tag[ls] += Tag[i];
      Tag[rs] += Tag[i];
      Tag[i] = 0;
    }
  }

  void buildTree(int left, int right, int i) {
    L[i] = left, R[i] = right;
    if (L[i] == R[i]) return;
    int mid = (L[i] + R[i]) >> 1;
    buildTree(left, mid, i << 1);
    buildTree(mid + 1, right, i << 1 | 1);
  }

  void updateTree(int left, int right, long long val, int i) {
    if (L[i] == left && R[i] == right) {
      Tag[i] += val;
      Max[i] += val;
      return;
    }
    pushDown(i);
    int mid = (L[i] + R[i]) >> 1;
    if (right <= mid) updateTree(left, right, val, i << 1);
    else if (left > mid) updateTree(left, right, val, i << 1 | 1);
    else updateTree(left, mid, val, i << 1), updateTree(mid + 1, right, val, i << 1 | 1);
    Max[i] = std::max(Max[i << 1], Max[i << 1 | 1]);
  }

  void updateTree(int pos, long long val, int i) {
    if (L[i] == R[i]) {
      Max[i] = std::max(Max[i], val);
      return;
    }
    pushDown(i);
    int mid = (L[i] + R[i]) >> 1;
    if (pos <= mid) updateTree(pos, val, i << 1);
    else updateTree(pos, val, i << 1 | 1);
    Max[i] = std::max(Max[i << 1], Max[i << 1 | 1]);
  }

  long long queryTree(int left, int right, int i) {
    if (L[i] == left && R[i] == right) return Max[i];
    pushDown(i);
    int mid = (L[i] + R[i]) >> 1;
    if (right <= mid) return queryTree(left, right, i << 1);
    else if (left > mid) return queryTree(left, right, i << 1 | 1);
    else return std::max(queryTree(left, mid, i << 1), queryTree(mid + 1, right, i << 1 | 1));
  }
};
SegTree T;

void init() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= M; ++i) {
    int l, r, a;
    scanf("%d %d %d", &l, &r, &a);
    Mp[r][l] += a;
  }
}

void solve() {
  T.buildTree(0, N, 1);
  for (int r = 1, preR = 0; r <= N; ++r) {
    bool fir = true;
    for (auto p : Mp[r]) {
      int l = p.first; long long a = p.second;
      if (fir == true) {
        for (int i = preR + 1; i <= r; ++i)
          T.updateTree(i, T.queryTree(0, r - 1, 1), 1);
        preR = r;
      }
      fir = false;
      T.updateTree(l, r, a, 1);
//      printf("l = %d, r = %d, a = %lld\n", l, r, a);
//      for (int i = 0; i <= N; ++i)
//        printf("F[%d] = %lld\n", i, T.queryTree(i, i, 1));
    }
  }
  printf("%lld\n", T.queryTree(0, N, 1));
}

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


Measured memory_bytes: 40832
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
double X,Y;
  cin >> X >> Y;
  double a=(Y-2*X)/2, b=X-a;
    if (ceil(a)==floor(a)&&
       ceil(b)==floor(b)&&
      a <= X &&
        b <= X&&
       a>=0&&
        b>=0){
         cout << "Yes" << endl;
       }
          else{
            cout << "No" << endl;
          }
}

Measured memory_bytes: 3748
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    ll ans = 0;
	int n;
	vector <int> p(100000);
	vector <int> d(100001, INF);
	cin >> n;
	REP(i, n) {
		cin >> p[i];
		d[p[i]] = i;
	}
	set<int> st;
	for(ll i = n; i>=1; i--){
		//cout << d[i] << endl;
		st.insert(d[i]);
		auto it = st.find(d[i]);
		ll l[2]= {-1,-1}, r[2] = {n,n};
		REP(j,2){
			if(it == st.begin()) break;
			it--;
			l[j] = *it;
		}
		it = st.find(d[i]);
		REP(j,2){
			it++;
			if(it == st.end()) break;
			r[j] = *it;
		}
		//cout << l[1] << " " << l[0] << " "  
		//<< d[i] << " "  << r[0] << " "  << r[1] << endl;
		ans += i * (l[0] - l[1]) * (r[0] - d[i]);
		ans += i * (r[1] - r[0]) * (d[i] - l[0]);	
	}

    cout << ans << endl;
}

Measured memory_bytes: 5760
s = input()
l = len(s)

total = [0] * (l + 1)
count = [1] * (l + 1)

for i in range(l - 1, -1, -1):
    total[i] = sum(int(s[i:j]) * count[j] + total[j] for j in range(i + 1, l + 1))
    count[i] = sum(count[j] for j in range(i + 1, l + 1))

print(total[0])


Measured memory_bytes: 3060
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
}


class Solve{


	 public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 String N = sc.next();
		 int win =0;

		 for(int i=0;i<N.length();i++) {
			 char ch=N.charAt(i);
			 if(ch=='o') {
				 win++;
			 }
		 }

		 if(win+15-N.length()>=8) {
		 System.out.println("YES");
		 }else {
		 System.out.println("NO");
		 }

	 }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int a,b,c,k;cin>>a>>b>>c>>k;
  rep(i,k){
    if(b<=a)b*=2;
    else if(c<=b)c*=2;
  }
  if(a<b&&b<c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
    

Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	ll A, B, K;
	cin >> A >> B >> K;

	A -= K;
	if (A < 0) {
		B += A;
	}

	cout << max(A,(ll)0) << " " << max(B,(ll)0) << endl;
	return 0;
} 


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

int main()
{
  int n,k;
  cin >> n >> k;
  vector<long long int> v(n);
  vector<long long int> w(n);
  
  for(int i = 0;i<n;i++)
    cin >> w[i] >> v[i];

  vector<vector<long long int> > dp(n+1,vector<long long int>(k+1,0));
  
  for(int i = 1; i <= n ; i++)
  {
    for(int j = 1; j <= k; j++)
    {
      if( j >= w[i-1] )
        dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]] + v[i-1]);
      else
        dp[i][j] = dp[i-1][j];           
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}


Measured memory_bytes: 83108
use std::cmp::min;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read_vec::<i32>();
    let f = n.contains(&1);
    let s = n.contains(&7);
    let t = n.contains(&9);
    let k = n.contains(&4);
    let ans = if f && s && t && t && k { "YES" } else { "NO" };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int k,t;
  cin >> k >> t;
  vector<int> n(t);
  for(int i = 0;i < t;i++)cin >> n[i];
  sort(n.begin(),n.end());
  cout << max(0,n[t - 1] - (k - n[t - 1]) - 1) << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
char c[210];
int k, n, dp[110][5][2];
int dfs(int now, int cnt, bool equalN){
    if(now == n + 1)
        return cnt == k;            
    if(cnt > k)                     
        return 0;
    if(dp[now][cnt][equalN] >= 0 && !equalN)   
        return dp[now][cnt][equalN];
    int maxx = equalN ? c[now] - '0' : 9, sum = 0;
    for(int i = 0; i <= maxx; i++) 
        sum += dfs(now + 1, cnt + (i != 0), equalN && (i == maxx));
    return dp[now][cnt][equalN] = sum;
}
int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%s\n%d", c + 1, &k);
    n = strlen(c + 1);
    printf("%d\n", dfs(1, 0, 1));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define FOR(i,a,n) for(int i=(a); i<(n); ++i)

struct Rect {
	int x1, x2, y1, y2;
};
map<char, Rect> item;
vector<string> img;
int t, H, W;

bool ok(Rect &r, char c) {
	FOR(i,r.y1,r.y2+1) FOR(j,r.x1,r.x2+1) {
		if (img[i][j] != c && img[i][j] != '#') {
			return false;
		}
	}
	return true;
}

void fill(Rect &r, char c) {
	FOR(i,r.y1,r.y2+1) FOR(j,r.x1,r.x2+1) img[i][j] = c;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> t;
	while (t--) {
		cin >> H >> W;
		img.resize(H);
		FOR(i,0,H) cin >> img[i];

		FOR(i,0,H) FOR(j,0,W) {
			char c = img[i][j];
			if (c != '.') {
				if ( ! item.count(c)) {
					item[c] = (Rect){j, j, i, i};
				} else {
					item[c].x1 = min(item[c].x1, j);
					item[c].x2 = max(item[c].x2, j);
					item[c].y1 = min(item[c].y1, i);
					item[c].y2 = max(item[c].y2, i);
				}
			}
		}

		map<char, Rect>::iterator it = item.begin();
		while (it != item.end()) {
			char c = (*it).first;
			Rect &r = (*it).second;
			if (ok(r, c)) {
				fill(r, '#');
				item.erase(c);
				it = item.begin();
				continue;
			}
			++ it;
		}
		cout << (item.empty() ? "SAFE" : "SUSPICIOUS") << endl;
		item.clear();
	}
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int a,b,c; cin>>a>>b>>c;
  int ans=3;
  if(a==b) ans-=1;
  if(a==c) ans-=1;
  if(b==c) ans-=1;
  if(a==b && b==c) ans+=1;
  cout<<ans;
  
 
  return 0;
}


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

using namespace std;

#define pi  3.141592653589793

int main(){

	int a, b;
  double theta;
  cin >> a >> b >> theta;
  theta =pi*theta/180;
 
  double S = a * b * sin(theta)/2;
 
  double c = sqrt(a*a + b*b - 2*a*b*cos(theta));
  double L = a + b + c;
  double h = S*2/a;
  printf("%.8lf \n", S);
  printf("%.8lf \n", L);
  printf("%.8lf \n", h);
return 0;
}

Measured memory_bytes: 1248
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  bool ok = true;
  if(S[0]!='A') ok = false;
  int cnum = 0;
  for(int i=2;i<S.size()-1;++i) {
    if(S[i]=='C') cnum++;
  }
  if(cnum!=1) ok = false;
  int tmp = 0;
  for(int i=0;i<S.size();++i) {
    if('A'<=S[i] && S[i]<='Z') tmp++;
  }
  if(tmp!=2) ok = false;
  if(ok) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}



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

int main(){
	string num;
	while (1){
		int sum=0;
		cin >> num;
		if(num=="0") break;
		for(int i=0 ; i<num.size() ; i++){
			sum+=num[i]-0x30;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1188
#include <stdio.h>

struct Translate
{
    char src;
    char dst;
};

int main () {
    int n, m, i;
    char a, b;
    struct Translate table[256];

    while (1) {
        scanf("%d", &n);
        if(n == 0) break;

        for (i = 0; i < n; i++) {
            scanf(" %c %c", &a, &b);
            table[i].src = a;
            table[i].dst = b;
        }

        scanf("%d", &m);

        while (m--) {
            scanf(" %c", &a);
            for (i = 0; i < n; i++) {
                if (a == table[i].src) {
                    a = table[i].dst;
                    break;
                }
            }
            printf("%c", a);
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 2664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int x=sc.nextInt(),y=sc.nextInt();
        int area=x*y,length=2*x+2*y;
        System.out.println(area+" "+length);
sc.close();
    }
    
}


Measured memory_bytes: 26280
#include <stdio.h>
int main()
{
  int i,j,n,count=0;
  char s[4],t[4];
  
  scanf("%s",s);
  scanf("%s",t);

  for(i=0;i<3;i++)
    {
      if(s[i]==t[i])
	{
	  count++; 
	}
    }

  printf("%d\n",count);
  
  
  

  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

  if (N < 1e1) {
    cout << N;
  } else if (N < 1e2) {
    cout << 9;
  } else if (N < 1e3) {
    cout << 9 + (N - 99);
  } else if (N < 1e4) {
    cout << 909;
  } else if (N < 1e5) {
    cout << 909 + (N - 9999);
  } else {
    cout << 90909;
  }

  return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int h, w;
    int arr[50][50] = {};
    string s[50];
    bool f = true;
    vector<pair<int, int>> v;
    v.push_back(make_pair(-1, 0));
    v.push_back(make_pair(0, -1));
    v.push_back(make_pair(1, 0));
    v.push_back(make_pair(0, 1));

    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> s[i];

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            arr[i][j] = (s[i])[j];
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            bool ff = false;
            for (int k = 0; k < 4; k++)
            {
                int tmp_x = j + v[k].first;
                int tmp_y = i + v[k].second;
                if (arr[i][j] == '.')
                {
                    ff = true;
                    break;
                }
                if (tmp_x < 0 || tmp_y < 0 || tmp_x >= w || tmp_y >= h)
                    continue;
                if (arr[tmp_y][tmp_x] == '#')
                    ff = true;
            }
            if (ff == false)
            {
                // cout << j << "," << i << endl;
                f = false;
            }
        }
    }
    if (f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main() {
  string s;
  cin >> s;
  bool a=s.at(0)=='R';
  bool b=s.at(1)=='R';
  bool c=s.at(2)=='R';
 
  if(a and b and c)
  cout <<3<< endl;
  else if((a and b) or (b and c))
    cout<<2<<endl;
  else if(a or b or c)
    cout<<1<<endl; 
  else
    cout<<0<<endl;
  
}


Measured memory_bytes: 3608
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
'''
ここはテスト用
D=365
C=[0]*26
S=[[0]*26 for i in range(D)]
for i in range(26):
  C[i]=randrange(0,101)
for i in range(D):
  for j in range(26):
    S[i][j]=randrange(0,20001)
'''
X=[0]*26
XX=X[:]
Y=X[:]
YY=X[:]
P=[]
SC=0
N,M,L,O,NN,MM=0,0,0,0,0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  N,M=-1,-10**20
  L,O=N,M
  NN,MM=N,M
  for j in range(26):
    if Y==-1:
      N,M=0,X[0]+S[i][0]
    if M<X[j]+S[i][j]:
      NN,MM=L,O
      L,O=N,M
      N,M=j,X[j]+S[i][j]
    elif O<X[j]+S[i][j]:
      NN,MM=L,O
      L,O=j,X[j]+S[i][j]
    elif MM<X[j]+S[i][j]:
      NN,MM=j,X[j]+S[i][j]
  XX[N]-=X[N]
  X[N]=0
  P.append([N,L,NN])
  SC+=X[N]
for i in range(D):
  SC2=SC
  d,q=i,P[i][1]
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d]=[P[d][1],P[d][0],P[d][2]]
    XX=YY[:]
    SC=SC2
  SC2=SC
  d,q=i,P[i][2]
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d]=[P[d][2],P[d][0],P[d][1]]
    XX=YY[:]
    SC=SC2
  SC2=SC
  d,q=i,P[i][1]
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d]=[P[d][1],P[d][0],P[d][2]]
    XX=YY[:]
    SC=SC2
  SC2=SC
  d,q=i,P[i][2]
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d]=[P[d][2],P[d][0],P[d][1]]
    XX=YY[:]
    SC=SC2
SC2=0
'''
ここちょっと消してみる
for i in range(10**5*3):
  d,q=randrange(0,D),randrange(0,26)
  SC2=SC
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d][0]=q
    XX=YY[:]
    SC=SC2
'''
T=0
X=[0]*26
SC=0
for i in range(D):
  T=P[i][0]+1
  SC+=S[i][T-1]
  for j in range(26):
    X[j]+=C[j]
  X[T-1]=0
  SC-=sum(X)
  print(T)
#print(max(SC+10**6,0))

Measured memory_bytes: 85680
//2019/12/1.
//Math.
#include<iostream>
using namespace std;

int main(){
	int x;
	cin>>x;
	
	int cnt=x/100;
	int rest=x%100;
	
	int cntt=rest/5;
	int restt=rest%5;
	
	int ans=(cntt<cnt or (cntt<=cnt and restt==0));
	cout<<ans<<endl;
}


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

void out_put(int ans[], int d) {
  for ( int i = 0; i < d; i++ ) {
    printf("%d\n", ans[i]+1);
  }
}

double now_time(clock_t start, clock_t end) {
  return ((double)(end - start) / CLOCKS_PER_SEC);
}

int main() {
  clock_t start = clock();

  int d;
  int c[26];
  int last[26];
  scanf("%d", &d);
  for ( int i = 0; i < 26; i++ ) {
    scanf("%d", &c[i]);
    last[i] = 0;
  }
  int s[d][26];
  for ( int i = 0; i < d; i++ ) {
    for ( int j = 0; j < 26; j++ ) {
      scanf("%d", &s[i][j]);
    }
  }

  // greedy
  int now = 0;
  int val = 0;
  int t[d];
  while ( now < d ) {
    int mx = - (1e9 + 7);
    int select;
    for ( int k = 0; k < 26; k++ ) {
      int val_tmp = val;
      int now_tmp = now;
      int contest = k;
      val_tmp += s[now_tmp][contest];
      now_tmp++;
      for ( int i = 0; i < 26; i++ ) {
        if ( contest == i ) { continue; }
        val_tmp -= c[i]*(now_tmp-last[i]);
      }
      if ( val_tmp > mx ) {
        mx = val_tmp;
        select = contest;
      }
    }
    t[now] = select;
    now++;
    last[select] = now;
    val = mx;
  }

  // local search
  clock_t end;
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand_day(0, d-1);
  uniform_int_distribution<> rand_contest(0, 25);

  end = clock();
  while ( now_time(start, end) < 1.0 ) {
    int change_day = rand_day(mt);
    int after_contest = rand_contest(mt);
    int val_tmp = val;

    int bef_contest = t[change_day];
    t[change_day] = after_contest;
    val_tmp -= s[change_day][bef_contest];
    val_tmp += s[change_day][after_contest];
    
    int last_bef_front = -1;
    for ( int i = change_day-1; i >= 0; i-- ) {
      if ( t[i] == bef_contest ) { last_bef_front = i; break; }
    }
    int last_bef_back = d;
    for ( int i = change_day+1; i < d; i++ ) {
      if ( t[i] == bef_contest ) { last_bef_back = i; break; }
    }
    val_tmp += c[bef_contest]*((change_day-last_bef_front)*(2+(change_day-last_bef_front-1))/2);
    val_tmp += c[bef_contest]*((last_bef_back-change_day)*(2+(last_bef_back-change_day-1))/2);
    val_tmp -= c[bef_contest]*((last_bef_back-last_bef_front)*(2+(last_bef_back-last_bef_front-1))/2);

    int last_after_front = -1;
    for ( int i = change_day-1; i >= 0; i-- ) {
      if ( t[i] == after_contest ) { last_after_front = i; break; }
    }
    int last_after_back = d;
    for ( int i = change_day+1; i < d; i++ ) {
      if ( t[i] == after_contest ) { last_after_back = i; break; }
    }
    val_tmp -= c[after_contest]*((change_day-last_after_front)*(2+(change_day-last_after_front-1))/2);
    val_tmp -= c[after_contest]*((last_after_back-change_day)*(2+(last_after_back-change_day-1))/2);
    val_tmp += c[after_contest]*((last_after_back-last_after_front)*(2+(last_after_back-last_after_front-1))/2);

    if ( val_tmp > val ) {
      val = val_tmp;
    } else {
      t[change_day] = bef_contest;
    }

    end = clock();
  }

  // ans
  out_put(t, d);

  return 0;
}


Measured memory_bytes: 3896
#include <stdio.h>

void makeCombination();
void rec();


int n,A[50];

int solve(int i, int m){

  if( m == 0 )
    return 1;
  if( i >= n )
    return 0;

  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;

}



int main(int argc, char const *argv[]) {

  int i;
  int q,M;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for( i = 0 ; i < q ; i++ ){
    scanf("%d",&M);


    if( solve(0,M) )
      printf("yes\n");
    else
      printf("no\n");

  }

  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
stack<char>s;
char a[Max];
int main()
{
    scanf("%s",a);
    int ans=0;
    for(int i=0;a[i];i++)
	{
		if(s.empty())
			s.push(a[i]);
		else if(s.top()=='0' && a[i]=='1')
		{
			s.pop();
			ans++;
		}
		else if(s.top()=='1' && a[i]=='0')
		{
			s.pop();
			ans++;
		}
		else
		{
			s.push(a[i]);
		}
	}
	printf("%d\n",ans*2);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int answer = 0;
	for(int i = 1; i < n - i; ++i){ ++answer; }
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int a, b, k;
	cin >> a >> b >> k;

	set<int> st;
	for(int i = a; i <= min(a + k - 1, b); i++) st.insert(i);
	for(int i = max(a, b - k + 1); i <= b; i++) st.insert(i);

	for(auto x : st) cout << x << endl;

}


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

using namespace std;

bool is_valid(string s) {
  int n = s.size();
  for (int i = 0; i < (n + 1) / 2; ++i) {
    if (s[i] != s[n - 1 - i]) return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string one = s.substr(0, (n - 1) / 2);
  int t = (n + 3) / 2;
  string two = s.substr(t - 1);
  if (!is_valid(s) || !is_valid(one) || !is_valid(two)) {
    cout << "No" << '\n';
  } else {
    cout << "Yes" << '\n';
  }
  
  return 0;
}



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

 ll dp[1000000];

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

    int n;
    cin>>n;
    int a;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin>>a;
        mp[a]++;
    }
    int m;
    cin>>m;
    int b;
    int ans =0 ;
    for(int i=0;i<m;i++){
        cin>>b;
        if(mp[b]) ans++;
    }
    cout << ans << endl;
    
    

    
}


Measured memory_bytes: 3180
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    in_arr(ll, a, n);
    if(n == 2){
        cout << abs(a[0] - a[1]) << endl;
        return 0;
    }
    ll s = 0, ar = 0, ans = LLONG_MAX;
    for(int i = 0; i < n; ++i){
        ar += a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        s += a[i];
        ar -= a[i];
        ans = min(ans, abs(s - ar));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n;
int a[maxn];
int ind[20];
int main()
{
	memset(ind,0,sizeof(ind));
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	long long res=0;
	int x=0;
	for(int i=0;i<n;i++)
	{
		res+=(long long)(i+1); 
		for(int k=0;k<20;k++)
		{
			int u=a[i]&(1<<k);
			if(ind[k]>0&&u)
			{
				x=max(x,ind[k]);
			}
			if(u)
			{
				ind[k]=i+1;
			}
		}
		res-=(long long)x;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024