akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int a[30],b[30],dp[31][1<<16];

int count(int bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits =(((bits >> 4) + bits) & 0x0f0f0f0f);
  bits += bits >> 8;
  return (bits + (bits >> 16)) & 0xff;
}

int main(void){
  
  int n,c,in;
  
  while(cin >> n >> c,n|c){
    
    fill(a,a+n,0);
    fill(b,b+c,0);

    for(int i=0;i<n;i++){
      for(int j=0;j<16;j++){
	cin >> in;
	a[i] |= in<<(15-j);
      }
    }

    for(int i=0;i<c;i++){
      for(int j=0;j<16;j++){
	cin >> in;
	b[i] |= in<<(15-j);
      }
    }

    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;

    for(int i=0;i<n;i++){
      for(int j=0;j<(1<<16);j++){
	if(dp[i][j]<0)continue;

	int now=a[i]|j;
	for(int k=0;k<c;k++){
	  int next=now & ~b[k];
	  dp[i+1][next]=max(dp[i+1][next],dp[i][j]+count(now & b[k]));
	}
      }
    }

    int ans=0;
    for(int i=0;i<(1<<16);i++){
      ans=max(ans,dp[n][i]);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 9104
class String
  def to_ia
    self.split(/\s+/).map {|s| s.to_i}
  end
end

def gcd(xy)
  xy.sort!
  x = xy[0]
  y = xy[1]
  r = y % x
  if r > 0
    gcd([x, y % x].sort)
  else
    x
  end
end

puts gcd(STDIN.readline.to_ia)

Measured memory_bytes: 8692
#include <iostream>

using namespace std;

int main(){
  int money;
  while(cin >> money && money !=0){
    int count =0;
    int res = 1000 - money;
    for(int i=0;i<3;i++){
      //      cout << res << endl;
      count +=res %10;
      if(res % 10 >4){ count -= 4;}
      res /=10;
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int n,m,l,i,j,k;
	int A[100][100] = {0}, B[100][100] = {0} ;
	long C[100][100] = {0} ;
	scanf("%d %d %d",&n,&m,&l);
	for (i=0; i<n; i++) {
		for (j=0; j<m; j++) {
			scanf("%d",&A[i][j]);
		}
	}
	for (j=0; j<m; j++) {
		for (k=0; k<l; k++) {
			scanf("%d",&B[j][k]);
		}
	}
	for (i=0; i<n; i++) {
		for (k=0; k<l; k++) {
			for (j=0; j<m; j++) {
				C[i][k] += A[i][j] * B[j][k] ;
			}
		}
	}
	for (i=0; i<n; i++) {
		for (k=0; k<l-1; k++) {
			printf("%ld ",C[i][k]);
		}
		printf("%ld\n",C[i][l-1]);
	}
	return 0;
}

Measured memory_bytes: 764
x,y,z,k = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)

d = []
for i in range(min(x,int(k*1.4))):
    for j in range(min(y,int(k*1.4))):
        d.append(a[i]+b[j])

d = sorted(d, reverse=True)
d = d[0:min(k,len(d))]
w = len(d)

e = []
for i in range(min(k,z)):
    for j in range(w):
        e.append(c[i]+d[j])

e = sorted(e, reverse=True)
for f in e[0:k]:
    print(f)


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

int main () {
  string s;
  cin >> s;
  bool flag = true;
  bool done = false;
  int count = 0;
  int len = s.size();
  while(flag) {
    done = false;
    for (int i = 0; i < s.size(); ++i) {
      if ((s[i] == '0' && s[i+1] == '1') or (s[i] == '1' && s[i+1] == '0')) {
        s.erase(s.begin() + i, s.begin() + i + 2);
        count += 2;
        done = true;
        if (i >= 1) i -= 2;
      }
    }
    if(!done) flag = false;
  }
  cout << count << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() 
{
	int a, b, C;
	double S, L, h, PI;
	PI = 3.14159265358979;
	cin >> a >> b >> C;
	S = 0.5 * a * b * sin(C * PI / 180);
	L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(C * PI / 180));
	h = b * sin(C * PI / 180);
	cout << fixed << setprecision(8) << S << endl;
	cout << fixed << setprecision(8) << L << endl;
	cout << fixed << setprecision(8) << h << endl;
	return 0;
}


Measured memory_bytes: 3508
#include<bits/stdc++.h>
using namespace std;
long int dp[11][11][11];
long int n,m,q;
long int ans=0;
void fun(long int ind,long int val,long int sum,vector<int> a)
{
    if(ind==n)
    {
        ans=max(ans,sum);
        return ;
    }
    if(val>m)
    return ;
    vector<int> b=a;
    for(long int i=val;i<=m;i++)
    {
        long int ss=sum;
         b.push_back(i);
         for(long int j=0;j<ind;j++)
         {
            ss+=dp[ind][j][i-b[j]];
         }
         fun(ind+1,i,ss,b);
         b.pop_back();
    }
}
int main()
{
    long long int n;
    cin>>n;
    long long int a[n];
    long int ans=0;
    map<long long int,int> p;
    for(long int i=0;i<n;i++)
    {
      cin>>a[i];
      if(p.find(i-a[i])!=p.end())
      ans+=p[i-a[i]];
      if(p.find(i+a[i])==p.end())
      p[i+a[i]]=0;
      p[i+a[i]]++;
    }
   cout<<ans;
}


Measured memory_bytes: 17616
//https://cpprefjp.github.io/reference/numeric/iota.html ->iota

#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>

int main(){

    int n;
    std::cin>>n;
   
   
    std::vector<int> array;
    for(int i=0;i<n;i++){
        array.push_back(i+1);
    }
   
/*
    std::vector<int> array(n);
    std::iota(array.begin(),array.end(),1);
*/

    for(int i=0;i<n;i++){
        std::cout<<(i?" ":"")<<array[i];
        }
        std::cout<<std::endl;

    while(std::next_permutation(array.begin(),array.end())){
        for(int i=0;i<n;i++){
            std::cout<<(i?" ":"")<<array[i];
        }
        std::cout<<std::endl;
    
    }

/*
    do{
        for(int i=0;i<n;i++){
            std::cout<<(i?" ":"")<<array[i];
        }
        std::cout<<std::endl;;
    }while(std::next_permutation(array.begin(),array.end()));
*/
    return 0;

}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    if((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
        return 0;
    } else {
        ll ans = (B - A) / 2 + 1 + A - 1;
        chmin(ans, (B - A) / 2 + 1 + (N - B));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
unordered_map<int,int> M;
unordered_map<int, int> vis;
const ll INF = 1e9;
int ans = 0;

int dfs(ll x, ll p) {
	vis[x]++;
	int tot = 0;
	ll s = 1;
	while (s <= x) s <<= 1;
	for (; s-x <= INF; s <<= 1) {
		ll y = s-x;
		if (y == p) continue;
		if (M.count(y)) tot += dfs(y,x); 
	}
	ans += min(M[x], tot);
	
	return max(0, M[x]-tot);
}
const int N = 2e5+10;
int a[N];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		M[x]++;
		a[i] = x;
	}
		
	for (ll x = 1; x <= 10*INF; x <<= 1) {
		ans+=dfs(x,x)/2;		
	}
	
	for (int i = 0; i < n; i++) {
		if (!vis.count(a[i])) dfs(a[i],a[i]);
	}
	
	
	printf("%d\n", ans);
}

Measured memory_bytes: 18248
#include<stdio.h>

long long gcm(long long a,long long b)
{
 if(b==0)
 {
   return a;
 }
  else
  {
  return gcm(b,a%b);
  } 
}

long long lcm(long long a,long long b)
{
  long long x;
  
  x=a/gcm(a,b)*b;
  
  return x;
}
  

int main()
{
  int n;
  
  scanf("%d",&n);
  
  long long t[n];
  int i;
  long long ans;
  
  for(i=0;i<n;i++)
  {
    scanf("%lld",&t[i]);
  }
  
  ans=t[0];
  for(i=0;i<n-1;i++)
  {
    ans=lcm(ans,t[i+1]);
  }
  
  printf("%lld\n",ans);
  
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if(S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  else if(S == "Rainy"){
    cout << "Sunny" << endl;
  }
   
}


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

int main(){
	long long sum=0;
	int n;
	cin>>n;
	int mx;cin>>mx;n--;
	while(n--){
		int a;
		cin>>a;
		sum+=max(0,mx-a);
		mx=max(mx,a);
	}
	cout<<sum;
}

Measured memory_bytes: 3628
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn dfs(lv: &Vec<i32>, n: usize, a: i32, b: i32, c: i32, i: usize, x: i32, y: i32, z: i32) -> i32 {
    if i == n {
        return if x == 0 || y == 0 || z == 0 {
            a + b + c
        } else {
            (x - a).abs() + (y - b).abs() + (z - c).abs() - 30
        };
    }
    return vec![
        dfs(lv, n, a, b, c, i + 1, x, y, z),
        dfs(lv, n, a, b, c, i + 1, x + lv[i], y, z) + 10,
        dfs(lv, n, a, b, c, i + 1, x, y + lv[i], z) + 10,
        dfs(lv, n, a, b, c, i + 1, x, y, z + lv[i]) + 10,
    ]
    .into_iter()
    .min()
    .unwrap();
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let a: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let b: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let c: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut lv = vec![0i32; n];
    for i in 0..n {
        lv[i] = read(&mut stdin_lock, &mut buf, b'\n');
    }

    let ans = dfs(&lv, n, a, b, c, 0, 0, 0, 0);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n;
 	cin >> n;
 	if(n%100<13&&n%100!=0){
 		if(n/100<13&&n/100!=0){
 			cout << "AMBIGUOUS" << endl;
 		}else{
 			cout << "YYMM" << endl;
 		}
 	}else{
 		if(n/100<13&&n/100!=0){
 			cout << "MMYY" << endl;
 		}else{
 			cout << "NA" << endl;
 		}
 	}
 }

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

void solve() {
    int X;
    cin >> X;
    int dX = 2 * X;
    vector<bool> is_prime(dX, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < dX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = 2 * i; j < dX; j += i) {
            is_prime[j] = false;
        }
    }
    for (int k = X; k < dX; ++k) {
        if (is_prime[k]) {
            cout << k << endl;
            return;
        }
    }
}

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


Measured memory_bytes: 384
#include <iostream>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b, c, x, y;

int main() {
	cin >> a >> b >> c >> x >> y;
	
	ll ans = -1;
	if(2*c < a && 2*c < b){ans = 2*c*max(x, y);}
	if(2*c >= a && 2*c < b){ans = 2*c*y+a*max(x-y, (ll) 0);}
	if(2*c < a && 2*c >= b){ans = 2*c*x+b*max(y-x, (ll) 0);}
	if(2*c >= a && 2*c >= b && 2*c < a+b){ans = 2*c*min(x, y); ans += (x > y)? a*(x-y) : b*(y-x);}
	if(2*c >= a+b){ans = a*x+b*y;}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define MAX_DATA 100100
typedef long long ll;

struct queue
{
    int arr[MAX_DATA];
    int first; //次にpopする配列の添え字
    int last;  //次にpushする配列の添え字
};

int push(struct queue *que, int input)
{
    if (que->arr[que->last] <= MAX_DATA)
    {
        que->arr[que->last] = input;
        que->last++;
        //printf("push:%d\n", input);
        return 0;
    }
    else
    {
        printf("これ以上データを追加できません。\n");
        return -1;
    }
}

int pop(struct queue *que)
{
    int output = que->arr[que->first];

    if (output != -1)
    {
        que->arr[que->first] = -1;
        que->first++;
        //printf("pop:%d\n", output);
        return output;
    }
    else
    {
        printf("データがありません。\n");
        return -1;
    }
}

void init_queue(struct queue *que)
{
    int i;

    for (i = 0; i < MAX_DATA; i++)
        que->arr[i] = -1;

    que->first = 0;
    que->last = 0;
}

void show_queue(struct queue *que, int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        if (que->arr[i] != -1)
            printf("%d ", que->arr[i]);
    }

    printf("\nfirst:%d last%d\n\n", que->first, que->last);
}

int main(void)
{
    long *graph[100001], cnt[100001] = {0};
    long n, m;

    scanf("%ld%ld", &n, &m);
    rep(i, m)
    {
        long a, b;
        scanf("%ld%ld", &a, &b);

        graph[a] = (long *)realloc(graph[a], sizeof(long) * (cnt[a] + 1));
        graph[a][cnt[a]] = b;
        cnt[a]++;

        graph[b] = (long *)realloc(graph[b], sizeof(long) * (cnt[b] + 1));
        graph[b][cnt[b]] = a;
        cnt[b]++;
    }
    graph[0] = (long *)realloc(graph[0], sizeof(long) * (cnt[0] + 1));
    graph[0][cnt[0]] = 0;
    cnt[0]++;
    /*
    rep(i, n + 1)
    {
        printf("graph[%d]={ ", i);
        rep(j, cnt[i])
            printf("%ld ", graph[i][j]);
        printf("} cnt:%ld\n", cnt[i]);
    }
*/
    // 初期化してから先頭に1をpush
    struct queue que;
    init_queue(&que);
    push(&que, 1);

    // -1：未発見の頂点
    // 頂点1を初期ノードとして初期化
    int dist[n + 1];
    rep(i, n + 1)
        dist[i] = -1;
    dist[1] = 0;

    int ans[n + 1] = {0};
    // queが空になるまで探索
    while (que.first != que.last)
    {
        // queから先頭頂点を取り出す
        int v = pop(&que);

        // vから訪問できる頂点を調べる
        rep(i, cnt[v])
        {
            // graphから頂点を取得し発見済みは探索しない
            int nv = graph[v][i];
            if (dist[nv] != -1)
                continue;

            // 未発見の頂点nvについて距離を更新してqueにpush
            dist[nv] = dist[v] + 1;
            ans[nv] = v;
            push(&que, nv);
        }
        //show_queue(&que, n);
    }

    puts("Yes");
    for (int i = 2; i < n + 1; i++)
        printf("%d\n", ans[i]);

    return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <limits>
using namespace std;
typedef complex<double> P;

#define EPS (1e-10)
#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()

typedef double Weight;
const Weight WEIGHT_INFTY = numeric_limits<Weight>::max() / 4;
struct Edge {
    int src, dst;
    Weight weight;
		Edge(int a,int b){
			src = a;
			dst = b;
		}
};
bool operator<(const Edge& a, const Edge& b) {
    return (a.weight < b.weight);
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool augment(const Graph& g, int u,
    vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L, Edges& matching) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  REP(u, L) if (matchTo[u] >= 0) // make explicit matching
    matching.push_back( Edge(u, matchTo[u]) );
  return match;
}
 
int gcd(int x,int y){
	return y ? gcd(y,x%y) : x ;
}
int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		vector<int> l,r;
		Graph g;
		REP(i,n){ int a; cin>>a; l.push_back(a); }
		REP(i,m){ int a; cin>>a; r.push_back(a); }
		
		REP(i,l.size()){
			vector<Edge> node;
			REP(j,r.size())if( gcd(l[i],r[j])>1 ){
				node.push_back( Edge(i,j+n) );
			}
			g.push_back( node );
		}
		REP(i,r.size()){
			vector<Edge> node;
			REP(j,l.size())if(gcd(r[i],l[j])>1){
				node.push_back( Edge(i+n,j) );
			}
			g.push_back( node );
		}
		/*
		REP(i,g.size()){
			REP(j,g[i].size()){
				printf("%d:(%d,%d)\n",i,g[i][j].src,g[i][j].dst);
			}
		}*/
		Edges ed;
		int ret = bipartiteMatching(g, n, ed);
		/*
		REP(i,ed.size()){
			printf("%d -> %d\n",ed[i].src,ed[i].dst);
		}
		*/
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 4672
#include <iostream>
#include <vector>

using namespace std;

const long long int MOD=998244353;

long long int modinv(long long int a, long long int m) {
    long long int b = m, u = 1, v = 0;
    while (b) {
        long long int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
    long long int N, M, K;
    cin >> N >> M >> K;
    
    vector<long long int> C(N, 1);
    vector<long long int> pow(N, 1);
    for(int n=1; n<N; n++) {
        C[n] = C[n-1];
        C[n] *= (N-n);
        C[n] %= MOD;
        C[n] *= modinv(n, MOD);
        C[n] %= MOD;
        
        pow[n] = pow[n-1]*(M-1);
        pow[n] %= MOD;
    }
    
    long long int ans=0;
    for(int k=0; k<=K; k++) {
        long long int tmp=C[k]*pow[N-1-k];
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    ans *= M;
    ans %= MOD;
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 6332
/* ****_hela**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define pi           3.1415
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n,m;
		cin>>n>>m;
		ll int sum=0;
		rep(i,0,m)
		{
			int a;
			cin>>a;
			sum+=a;
		}
		if(sum>n)cout<<-1;
		else cout<<n-sum;
	}
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int H,W,K;
	char s[301][301];
	int ans[301][301]={};
	//int x[100000],y[100000];
	int now=1;
	scan(H>>W>>K);
	rep(i,H){
		scan(s[i]);
		int flag=0;
		rep(j,W){
			if(s[i][j]=='#'){
				//x[now]=j,y[now]=i;
				ans[i][j]=now;
				now++;
				flag=1;
			}
		}
		if(flag){
			rep(j,W-1){
				if(ans[i][j]!=0&&ans[i][j+1]==0) ans[i][j+1]=ans[i][j];
			}
			brep(j,W-1){
				if(ans[i][j]==0&&ans[i][j+1]!=0) ans[i][j]=ans[i][j+1];
			}
		}
	}
	rep(j,W){
		rep(i,H-1){
			if(ans[i][j]!=0&&ans[i+1][j]==0) ans[i+1][j]=ans[i][j];
		}
		brep(i,H-1){
			if(ans[i][j]==0&&ans[i+1][j]!=0) ans[i][j]=ans[i+1][j];
		}
	}
	rep(i,H){
		rep(j,W){
			printf("%d ",ans[i][j]);
		}
		kaigyo;
	}
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];
	reverse(h.begin(), h.end());

	vector<ll> sa(n - 1);
	rep(i, n - 1) {
		sa[i] = h[i + 1] - h[i];
		if (sa[i] > 1) {
			cout << "No\n";
			return 0;
		}
		if (sa[i] == 1) {
			h[i + 1]--;
		}
	}
	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 1792
from collections import Counter

S = str(input())
T = str(input())

s_counter = Counter(S)
t_counter = Counter(T)

# print(s_counter)
# print(t_counter)

dict_S_to_T = {}
dict_T_to_S = {}

for s, t in zip(S, T):
    if s not in dict_S_to_T.keys():
        dict_S_to_T[s] = t
    else:
        if dict_S_to_T[s] != t:
            print('No')
            exit()
    if t not in dict_T_to_S.keys():
        dict_T_to_S[t] = s
    else:
        if dict_T_to_S[t] != s:
            print('No')
            exit()

print('Yes')


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

int main(void){
  int n, a[2][100], i, j, d=0, maxd=0, max=0, ans=0;
  scanf("%d",&n);
  for(i=0;i<2;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]);
  for(i=0;i<n-1;i++){
    d+=a[1][n-2-i]-a[0][n-1-i];
    if(maxd<d){max=i; maxd=d;}
  }
  max = n-2-max;  if(max<0) max=0;
  //printf("max: %d...",max);
  for(i=0;i<n;i++){
    if(i<=max) ans+=a[0][i];
    if(i>=max) ans+=a[1][i];
  }
  printf("%d\n",ans);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//BEGIN CUT HERE
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
//END CUT HERE

signed main(){
  int n,m;
  int d;
  cin>>n>>m;
  vector<int> p(n);
  rep(i,n){
    cin>>d;
    p.at(i) = d-1;
  }


  UnionFind uf(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    uf.unite(x-1,y-1);
  }
  int c=0;
  rep(i,n){
    if(uf.same(i,p.at(i))) c++;
  }
  cout << c << endl;

}




Measured memory_bytes: 1408
var N = 8
var row = Array.from(Array(N), () => -1);
var col = new Array(N);
var dpos = new Array(2 * N - 1);
var dneg = new Array(2 * N - 1);

function search(r) {
  if (r === N) {
    printBoard();
    return true;
  }

  if (row[r] !== -1) return search(r + 1);
  for (let c = 0; c < N; c++) {
    if (col[c] || dpos[r + c] || dneg[r - c + N - 1]) continue;
    changeBoard(r, c, true);
    search(r + 1);
    changeBoard(r, c, false);
  }
  return false;
}

function changeBoard(r, c, flg) {
  if (flg) {
      row[r] = c;
  } else {
      row[r] = -1;
  }
  col[c] = dpos[r + c] = dneg[r - c + N - 1] = flg;
}

function printBoard() {
  for (let r = 0; r < N; r++) {
     for (let c = 0; c < N; c++) {
       process.stdout.write(row[r] === c ? 'Q' : '.');
     }
     console.log();
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const k = Number(lines.shift());

  let r, c;
  for (let i = 0; i < k; i++) {
    [r, c] = lines.shift().split(' ').map(Number);
    changeBoard(r, c, true);
  }
  search(0);
})();



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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<vector<int> > a(2, vector<int>(N));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a.at(i).at(j);
    }
  }

  for (int i = 1; i < N; i++) {
    a.at(0).at(i) += a.at(0).at(i - 1);
  }
  a.at(1).at(0) += a.at(0).at(0);
  for (int i = 1; i < N; i++) {
    a.at(1).at(i) += max(a.at(1).at(i - 1), a.at(0).at(i));
  }

  cout << a.at(1).at(N - 1) << endl;
}

int main() {
  answer1();
}


Measured memory_bytes: 256
#include<stdio.h>
#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;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#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())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(long long N, long long M){
    long long tmp;
    if(N>M){
        tmp=N;
        N=M;
        M=tmp;
    }
    if(N==1&&M==1){
        cout<<1<<endl;
        return;
    }
    else if(N==1&&M!=1){
        cout<<(M-2)<<endl;
        return;
    }
    else{
        cout<<(M-2)*(N-2)<<endl;
        return;
    }

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

using ll = long long;

int main() {
    int N;
    ll x, y;
    cin >> N;
    vector<pair<ll, ll>> xy(N);
    int ans = N;
    rep(i, N) {
        cin >> x >> y;
        xy[i] = make_pair(x, y);
    }
    sort(xy.begin(), xy.end());
    rep(i, N) rep(i0, N) {
        if (i == i0) continue;
        ll p = xy[i0].first - xy[i].first;
        ll q = xy[i0].second - xy[i].second;
        if (p < 0 || (p == 0 && q < 0)) {
            p = -p;
            q = -q;
        }
        int cost = 0;
        int doneN = 0;
        vector<bool> done(N, false);
        //cout << "i=" << i << " p=" << p << " q=" << q << endl;
        while (doneN < N) {
            rep(j, N) {
                if (done[j]) continue;
                //cout << "j=" << j << endl;
                x = xy[j].first;
                y = xy[j].second;
                cost++;
                doneN++;
                done[j] = true;
                //cout << "x=" << x << " y=" << y << endl;
                break;
            }
            //cout << " x=" << x << " y=" << y << endl;
            bool f = true;
            while (f) {
                x += p;
                y += q;
                f = false;
                rep(k, N) {
                    if (done[k]) continue;
                    if (xy[k].first == x && xy[k].second == y) {
                        doneN++;
                        done[k] = true;
                        f = true;
                        break;
                    }
                }
            }
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
while True:
    d, e = map(int, input().split())
    if d == 0:
        break
    ans = 10**5
    for x in range(d + 1):
        y = d - x
        ans = min(ans, abs((x**2 + y**2)**0.5 - e))
    print(ans)



Measured memory_bytes: 5656
#include <iostream>
#include <stdint.h>
#include <limits.h>
#include <utility>
#include <map>

using namespace std;
 
int main()
{
  unsigned N, M;
  cin >> N >> M;
 
  multimap<unsigned,unsigned> A;
 
  for (unsigned n=0; n<N; ++n) {
    unsigned a;
    cin >> a;
    auto itr = A.find(a);
    if (itr!=A.end())
      ++itr->second;
    else
      A.emplace(make_pair(a,1));
  }

  for (unsigned m=0; m<M; ++m) {
    unsigned B, C;
    cin >> B >> C;

    auto itr = A.find(C);
    if (itr!=A.end())
      itr->second += B;
    else
      A.emplace(make_pair(C,B));
  }
 
  uint64_t sum = 0;
  unsigned count = 0;
  for (auto itr=A.rbegin(); itr!=A.rend() && count<N; ++itr) {
    sum += (uint64_t)itr->first * min(N-count, itr->second);
    count += itr->second;
  }
 
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int main() {
    int k, a, b, c = 0;
    scanf("%d%d%d", &k, &a, &b);
    
    for (int i = a; i < b + 1; ++i)
        if (i % k == 0)
            c = 1;
    
    if (c)
        printf("OK");
    else
        printf("NG");
    
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<string.h>
using namespace std;
int main() {
	string s;
	bool b[4]= {false,false,false,false};
	cin>>s;
	for(int i=0; i<s.size(); i++) {
		if(s[i]=='N') {
			b[0]=true;
		}
		if(s[i]=='S') {
			b[1]=true;
		}
		if(s[i]=='W') {
			b[2]=true;
		}
		if(s[i]=='E') {
			b[3]=true;
		}
	}
	if(b[0]!=b[1]||b[2]!=b[3]){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  n <- getInt
  ps <- getIntVec n

  let solve i res | i < n-1  = if i + 1 == ps V.! i
                               then solve (i+2) (res+1)
                               else solve (i+1) res
                  | i == n-1 = if i + 1 == ps V.! i
                               then solve (i+1) (res+1)
                               else solve (i+1) res
                  | otherwise = res

  print $ solve 0 0

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


const ll INF = 1LL<<62;


ll fnc(int n, ll k, const VI& x){
	ll cur[2] = {0, -INF};
	repr(i, 42, 0){
		ll ks = 1LL<<i;
		int ct = count_if(all(x), [i](ll z){return z>>i & 1;});
		int ct2 = n -ct;
		ll nxt[2] = {-INF, -INF};

		if((k>>i) &1) amax(nxt[1], cur[0] + ks * ct );
		amax(nxt[0], cur[0] + ks *( (k>>i &1)? ct2: ct) );
		amax(nxt[1], cur[1] + ks * max(ct, ct2) );
		
		swap(cur, nxt);
	}
	return max(cur[0], cur[1]);
}

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	
	int n; ll k;
	cin >>n >>k;
	vector<ll> x(n);
	rep(i, n) cin >>x[i];

	
	cout << fnc(n,k,x) <<"\n";
	return 0;
}
/*
4 567
12345 656 34567 67432
*/

Measured memory_bytes: 1024
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
if a[0] > x:
    ans = a[0]-x
    a[0] = x
for i in range(1,n):
    temp = a[i-1] + a[i]
    if temp > x:
        a[i] -= temp-x
        ans += temp-x
print(ans)

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

class Cube{
    public:
        int f[6];
        Cube(){}
        void roll_x(){roll(0,1,5,4);}
        void roll_y(){roll(0,2,5,3);}
        void roll_z(){roll(1,2,4,3);}
        void roll(int i,int j,int k,int l){
            int t=f[i];
            f[i]=f[j];
            f[j]=f[k];
            f[k]=f[l];
            f[l]=t;
        }
};

bool eq(Cube c1,Cube c2){
    for(int i=0;i<6;i++){
        if(c1.f[i]!=c2.f[i])return false;
    }
    return true;
}

bool equal(Cube c1,Cube c2){
    for(int i=0;i<6;i++){
        for(int j=0;j<4;j++){
            if(eq(c1,c2)) return true;
            c1.roll_z();
        }
        if(i%2==0)c1.roll_y();
        else c1.roll_x();
    }
    return false;
}

int main(){
    Cube c1,c2;
    
    for(int i=0;i<6;i++)cin>>c1.f[i];
    for(int i=0;i<6;i++)cin>>c2.f[i];
    
    if(equal(c1,c2)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3108
#include <stdio.h>

int main (){
    char l[1],r[1];
    scanf("%s",l);
    scanf("%s",r);
//    l[0]='A';
//    r[0]='A';
    if(l[0]>r[0])
    	printf(">\n");
    else if(l[0]<r[0])
    	printf("<\n");
    else
    	printf("=\n");
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x
      
def lcm(x, y, MOD):
  return x * y // gcd(x, y)

X = 1
ans = 0
for i in range(N):
  X = lcm(X, A[i], MOD)
for i in range(N):
  ans = (ans + X*pow(A[i], MOD-2, MOD))%MOD
print(ans)

Measured memory_bytes: 74068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mods[100005];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, p;
    string x;
    cin >> n >> p >> x;
    ll ans = 0;
    if (p == 2 || p == 5) {
        ll add = 0;
        for (int i = n - 1; i >= 0; i--) {
            if ((x[i] - '0') % p == 0) add++;
            ans += add;
        }
    }
    else {
        ll curr = 0, pow = 1;
        for (int i = n - 1; i >= 0; i--) {
            curr += (pow * (x[i] - '0')) % p;
            curr %= p;
            pow *= 10;
            pow %= p;
            ans += curr == 0;
            ans += mods[curr];
            mods[curr]++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    string s,t; cin >> s >> t;
    int ans = 0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3896
use proconio::input;
use proconio::marker::Chars;
use itertools::iproduct;

#[proconio::fastout]
pub fn main() {
    input!{
    h:usize,
    w:usize,
    k:usize,
    c:[Chars;h],
    }
    let ans = iproduct!(0..1<<h,0..1<<w)
        .filter(|&(rs, cs)| {
            iproduct!((0..h).filter(|&y|rs>>y&1==1),
            (0..w).filter(|&x|cs>>x&1==1))
                .filter(|&(y, x)| c[y][x] == '#')
                .count()
                == k
        }).count();
    println!("{}", ans);
}


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


const int MAX_N = 30000;
int N;
char S[MAX_N];

void Main() {
  cin >> N;
  cin >> S;

//  int pin[10][10][10];
  int ans = 0;

  int next[MAX_N][10];
  fill(next[0], next[MAX_N - 1], -1);
  for (int i = N - 1; i >= 0; --i) {
    for (int j = 0; j < 10; ++j) next[i][j] = next[i+1][j];
    next[i][S[i] - '0'] = i;
//    cout << S[i] - '0' << endl;
  }

//  cout << next[0][0] << endl;

  rep(i, 10) {
    rep(j, 10) {
      rep(k, 10) {
        int ind = next[0][i];
//        cout << ind << endl;
        if (ind == -1 || ind >= N - 2) continue;
        ind = next[ind + 1][j];
//        cout << ind << endl;
        if (ind == -1 || ind >= N - 1) continue;
        ind = next[ind + 1][k];
//        cout << ind << endl;
        if (ind == -1) continue;
        ans++;
      }
    }
  }

  cout << ans << endl;

//  set<string> num;
//  for (int i = 0; i < N - 2; ++i) {
//    for (int j = i + 1; j < N - 1; ++j) {
//      for (int k = j + 1; k < N; ++k) {
//        string s = {S[i], S[j], S[k]};
//        num.insert(s);
//      }
//    }
//  }
//
//  cout << num.size() << endl;
}

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

Measured memory_bytes: 1408
#include<cstdio>
#include<cctype>

int main() {
	char c[1200] = {};
	int i = 0;
	int alpha[26] = {};

	while (scanf("%c", &c[i]) != EOF) 
	{
		if (isalpha(c[i])) {
			if (islower(c[i]))	alpha[c[i] - 'a']++;
			else alpha[c[i] - 'A']++;
		}
		i++;
	}

	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", i + 'a', alpha[i]);
	}

	return 0;
}

Measured memory_bytes: 980
gets
ary = []
ARGF.each do |line|
  a = line.split.map(&:to_i)
  b = a.inject(:+)

  puts "#{a.join("\s")} #{b}"
  ary << a.push(b)
end
puts ary.transpose.collect{|row| row.inject(:+)}.join("\s")

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9

using namespace std;
const db pi = acos(-1.0);
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
#define Node(a, b, c, d) mp(a,mp(b,mp(c,d)))
map <pair<int, pair<int, pii> >, ll> cnt;
const int N = 500;

int A[N][4];
int n, num[4];

void fz(pair<int, pair<int,pii> > t)
{
    num[0] = t.X;
    num[1] = t.Y.X;
    num[2] = t.Y.Y.X;
    num[3] = t.Y.Y.Y;
}

pair<int, pair<int,pii> > stand(pair<int, pair<int,pii> > t)
{
    fz(t);
    pair<int, pair<int,pii> > tmp[4];
    rep(s, 0, 3)
        tmp[s] = Node(num[(s + 0) % 4], num[(s + 1) % 4], num[(s + 2) % 4], num[(s + 3) % 4]);
    sort(tmp, tmp + 4);
    return tmp[0];

}

void update(int id,int val)
{
    pair<int, pair<int,pii> > now = stand(Node(A[id][0], A[id][1], A[id][2], A[id][3]));
    cnt[now] += val;
}

int cal(pair<int, pair<int,pii> > t)
{
     fz(t);
    pair<int, pair<int,pii> > tmp[4];
    rep(s, 0, 3) tmp[s] = Node(num[(s + 0) % 4], num[(s + 1) % 4], num[(s + 2) % 4], num[(s + 3) % 4]);
    int c = 0;
    rep(s, 0, 3) if(tmp[s] == tmp[0]) c ++;
    return c;

}

int main()
{
    n = read();
    rep(i, 1, n)
    {
        rep(j, 0, 3) A[i][j] = read();
        update(i, 1);
    }

    ll res = 0;
    rep(i, 1, n)
    {
        update(i, -1);
        rep(j, i + 1, n)
        {
            update(j, -1);
            int Down[4];
            rep(x, 0, 3) Down[x] = A[i][x];
            int Up[4];
            rep(us, 0, 3)
            {
            	rep(y, 0, 3) Up[y] = A[j][(us - y + 4) % 4];
                ll now = 1;
                pair<int, pair<int,pii> > X[4];
                rep(k, 0, 3)
                {
                    X[k] = stand(Node(Down[k], Up[k], Up[(k + 1) % 4], Down[(k + 1) % 4]));
                    ll num = cal(X[k]);
                    now *= num * cnt[X[k]];
                    cnt[X[k]] --;
                }

                res += now;
	 	rep(k, 0, 3) cnt[X[k]] ++;
            }
            update(j, 1);
        }
        update(i, 1);
    }
    printf("%lld\n",res / 3);
    return 0;
}


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

int main() {
  int A, B, C, X, Y, sum = 0;
  cin >> A >> B >> C >> X >> Y;
  if (X < Y) {
    swap(X, Y);
    swap(A, B);
  }
  sum += min(A + B, 2 * C) * Y;
  sum += min(A, 2 * C) * (X - Y);
  cout << sum << endl;
}


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

typedef long long ll;

ll T;
ll N;
vector<ll> A;
string S;
vector<ll> M;

ll solve() {
  M.clear();
  for (ll i = N - 1; i >= 0; --i) {
    ll a = A[i];
    for (ll j = 0; j < M.size(); ++j) {
      a = min(a, M[j] ^ a);
    }
    if (a != 0) {
      if (S[i] == '0') {
        M.push_back(a);
        sort(M.begin(), M.end(), greater<ll>());
      } else {
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  cin >> T;
  for (ll t = 0; t < T; ++t) {
    cin >> N;
    A.resize(N);
    for (ll i = 0; i < N; ++i) cin >> A[i];
    cin >> S;
    cout << solve() << endl;
  }
  return 0;
}


Measured memory_bytes: 3576
import sys
input=sys.stdin.readline

l=list(map(int,input().split()))
a,b,c=sorted(l)
#print(a,b,c)
if a%2==b%2 and a%2==c%2:
    print((2*c-a-b)//2)
elif a%2==b%2:
    print((2*c-2-a-b)//2+1)
else:
    print((2*c+1-a-b)//2+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=3e5+5;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int fa[MAXN],n,m,k,Mod,g,v,vis[2][MAXN*5];
vector<pint>G[MAXN];
inline int id(int x,int y,int z){return (x-1)*6+2*y+z+1;}
inline void pre(int s,int Mod){for(int i=0,j=s;i<(Mod<<1);j=(j*2)%Mod,i++)vis[i&1][j]=1;}
int gf(int x){return fa[x]==x?x:fa[x]=gf(fa[x]);}
inline void Merge(int x,int y){fa[gf(y)]=gf(x);}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read(),k=read(),Mod=read();
	for(int last=-1,i=1;i<=m;i++){
		int x=read(),y=read(),z=read();
		G[x].push_back(mk(y,z)),G[y].push_back(mk(x,z));
		if(~last)g=gcd(g,abs(z-last));last=z;
	}if(!g)g=Mod;Mod=gcd(Mod,3*g),v=G[1][0].sec%g,pre(v,Mod);
	Rep(i,1,6*n)fa[i]=i;
	Rep(i,1,n)for(int j=0,len=G[i].size();j<len;j++){
		int y=G[i][j].fir,v=G[i][j].sec/g;
		Rep(k,0,2)Merge(id(i,k,0),id(y,(2*k+v)%3,1)),Merge(id(i,k,1),id(y,(2*k+v)%3,0));
	}Rep(i,1,k){
		int x=read(),y=read(),z=(read()+v)%Mod,flg=0;
		Rep(j,0,2)Rep(k,0,1)if(vis[k][(z-j*g%Mod+Mod)%Mod]&&gf(id(y,0,0))==gf(id(x,j,k)))flg=1;
		puts(flg?"YES":"NO");
	}
	return 0;
}



Measured memory_bytes: 21140
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){

    int k;
    vector<int> v;

    for(int i = 0; i < 5; i++){
        int tmp;
        cin >> tmp;

        v.push_back(tmp);
    }

    cin >> k;

    bool ans = true;
    
    for(int i = 0; i < 4; i++){
        for(int j = i + 1; j < 5; j++){
            if(v[j] - v[i] > k) ans = false;
        }
    }

    if(ans){
        cout << "Yay!" << endl;
    }else cout << ":(" << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a >= 1 && c <= 10)
	{
		if (a == 5 && b ==5 && c == 7)
		{
			printf("YES");
		}
		else if(a == 5 && b ==7 && c == 5)
		{
			printf("YES");
		}
		else if(a == 7 && b ==5 && c == 5)
		{
			printf("YES");
		}
		else
		{
			printf("NO");
		}
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int r;
    cin >> r;
    if(r < 1200){
        cout << "ABC" << endl;
    }else if(r < 2800){
        cout << "ARC" << endl;
    }else {
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 3548