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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    string A,B,C; cin >> A>>B>>C;
    YES(A.back()==B.front()&&B.back()==C.front());
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var N int
	fmt.Scan(&N)

	nums := make([]int, N)

	var first int = 0
	var second int = -1

	for i := 0; i < N ; i++ {
		fmt.Scan(&nums[i])

		if first <= nums[i] {
			second = first
			first = nums[i]
		} else if second <= nums[i] {
			second = nums[i]
		}

	}

	for i := 0 ; i <  N ; i++ {
		if nums[i] != first {
			fmt.Println(first)
		} else {
			fmt.Println(second)
		}
	}
	
}


Measured memory_bytes: 6656
#include <stdio.h>
#include <math.h>

int main(void){
	double x[4], y[4]; int N;
	
	scanf("%d",&N);
	
	for(; N>0; N--){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]);
		if(x[1]-x[0]==0){
			if(x[3]-x[2]==0) printf("YES\n");
			else printf("NO\n");
		}else{
			if((y[1]-y[0])/(x[1]-x[0])==(y[3]-y[2])/(x[3]-x[2])) printf("YES\n");
			else printf("NO\n");
		}
	}
	
	return 0;
}

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

long long kai(long long n) {
  if (n == 1) {
    return 1;
  } else {
    return n * kai(n-1) % (int(1e9) + 7);
  }
}

int main() {
  long long n;

  cin >> n;
  cout << kai(n) << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
#define c(x) cout<<x<<endl
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
map<int,int>num;
int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	int len=s.length();
	int ans=0;
	int tmp=0,p=1;
	num[0]++;
	for(int i=len-1;i>=0;i--){
		tmp=(tmp+(s[i]-'0')*p)%2019;
		tmp=tmp%2019;
		ans+=num[tmp]++;
		p=p*10%2019;
		//cout<<tmp<<endl;
	}
	c(ans);
 	return 0;
}







Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
typedef complex<ll> P;

int n;
P s, t;
P p[1005];
vector<P> G[10005];

void init() {
  rep(i, 10005) G[i].clear();
}

void solve() {
  vector<P> a, b;
  vector<ll> ar, br;
  rep(i, 10005) {
    for (P p: G[i]) {
      if (norm(p - s) < i * i) {
        a.push_back(p);
        ar.push_back(i);
      }
      else {
        b.push_back(p);
        br.push_back(i);
      }
    }
  }
  int ans = 0;
  vector<int> dpa(a.size(), 1), dpb(b.size(), 1);
  rep(i, a.size()) {
    rep(j, i) {
      if (norm(a[i] - a[j]) < (ar[i] - ar[j]) * (ar[i] - ar[j])) {
        chmax(dpa[i], dpa[j] + 1);
      }
    }
    chmax(ans, dpa[i]);
  }
  rep(i, b.size()) {
    rep(j, i) {
      if (norm(b[i] - b[j]) < (br[i] - br[j]) * (br[i] - br[j])) {
        chmax(dpb[i], dpb[j] + 1);
      }
    }
    chmax(ans, dpb[i]);
  }
  rep(i, a.size()) {
    rep(j, b.size()) {
      if (norm(a[i] - b[j]) > (ar[i] + br[j]) * (ar[i] + br[j])) {
        chmax(ans, dpa[i] + dpb[j]);
      }
    }
  }
  cout << ans << '\n';
}

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

  while (cin >> n, n) {
    init();

    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    s = P(sx, sy), t = P(tx, ty);
    rep(i, n) {
      ll px, py, r;
      cin >> px >> py >> r;
      P p = P(px, py);
      if (norm(p - t) < r * r && norm(p - s) < r * r) continue;
      if (norm(p - t) > r * r && norm(p - s) > r * r) continue;
      G[r].push_back(p);
    }

    solve();
  }

  




  
  return 0;
}


Measured memory_bytes: 3500
#include<iostream>
int main() {
	std::string S;
	std::cin >> S;
	long long ans = 0, B = 0;
	for (int i = 0;i < S.length();++ i) {
		if (S[i] == 'B') ++ B; else ans += B;
	}
	std::cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int INF = 1000000000;
void rec(vector< vector< vector<bool> > > &D, vector< vector<int> > &G, vector<int> d, int v, int n){
  int m = 0;
  for(int i = 0; i < 3; ++i) m = max(m, G[v][i]);
  for(int i = 0; i < 3; ++i){
    for(int j = 0; j < n; ++j){
      if(D[i][v][j]){
        if(G[j][i] <= m + 1) continue;
        G[j][i] = m + 1;
        bool f = true;
        for(int k = 0; k < 3; ++k){
          if(G[j][k] == INF){
            f = false;
            break;
          }
        }
        if(f){
          rec(D,G,d,j,n);
        }
      }
    }
  }
}

vector< vector<bool> > matrix_product(vector< vector<bool> > &a, vector< vector<bool> > &b){
  int n = a.size(), m = b[0].size(), l = a[0].size();
  vector< vector<bool> > ret(a.size(),vector<bool>(b[0].size(),false));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      for(int k = 0; k < l; ++k){
        ret[i][j] = (a[i][k]&b[k][j])|ret[i][j];
      }
    }
  }
  return ret;
}

vector< vector<bool> > matrix_pow(vector< vector<bool> > &G, int n){
  vector< vector<bool> > ret = G;
  for(int i = 0; i < n-1; ++i){
    ret = matrix_product(ret,G);
  }
  return ret;
}

int main(){
  int n, m, a, b, c;
  cin >> n >> m >> a >> b >> c;
  int u, v;
  vector< vector<bool> > G(n, vector<bool>(n,false));
  for(int i = 0; i < m; ++i){
    cin >> u >> v;
    --u;--v;
    G[v][u] = 1;
  }
  
  vector< vector< vector<bool> > > D(3);
  vector<int> d = {a,b,c};
  for(int i = 0; i < 3; ++i) D[i] = matrix_pow(G,d[i]);
  /*
  for(int i = 0; i < 3; ++i){
    cout << "--------------------" << d[i] << "----------------------------" << endl;
    for(int j = 0; j < n; ++j){
      for(int k = 0; k < n; ++k){
        cout << D[i][j][k] << " " ;
      }cout << endl;
    }
  }
  */
  vector< vector<int> > G_(n, vector<int>(n,INF));
  for(int i = 0; i < 3; ++i) G_[n-1][i] = 0;

  rec(D,G_,d,n-1,n);
  if(G_[0][0] == INF || G_[0][1] == INF || G_[0][2] == INF) cout << "IMPOSSIBLE" << endl;
  else cout << max({G_[0][0],G_[0][1],G_[0][2]}) << endl;
  return 0;
}

Measured memory_bytes: 3200
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();
    let n = list[0];
    let n2 = list[1];

    //10000
    let mut x = 0;
    //5000
    let mut y = 0;
    //1000
    let mut z = n2 / 1000;

    loop {
        if x + y + z == n {
            return format!("{} {} {}", x, y, z);
        }

        if x + y + z < n {
            return "-1 -1 -1".to_string();
        }

        if z >= 5 && n + 4 <= x + y + z {
            z -= 5;
            y += 1;
        } else if y >= 2 {
            y -= 2;
            x += 1;
        } else {
            return "-1 -1 -1".to_string();
        }
    }
}

#[test]
fn test() {
    let tests = vec![
        ("9 45000", "0 9 0"),
        ("20 196000", "-1 -1 -1"),
        ("1000 1234000", "2 54 944"),
        ("2000 20000000", "2000 0 0"),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


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

int main() {
    ll N,A,B,m=0,l,r;
    cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i,N) {
        cin >> h.at(i);
        m = max(m, h.at(i));
    }
    l=1, r=m/B;
    if(m%B)
        ++r;

    while(r-l > 1) {
        ll x=(l+r)/2, dc=0;
        rep(i,N) {
            ll rd=h.at(i)-B*x, ad=0;
            if(rd > 0) {
                ad = rd/(A-B);
                if(rd%(A-B))
                    ++ad;
            }
            dc += ad;
        }
        if(dc <= x)
            r = x;
        else
            l = x;
    }

    cout << r << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
	int n, tot = 0;
	cin >> n;
	for (int i = 1; i <= n; i+=2)
	{
		int x = i, nr = 0;
		for (int d = 1; d <= x; d++)
			if (x%d == 0)
				nr++;
		if (nr == 8)
			tot++;
	}
	cout << tot;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
MAIN = []
for i in range(N):
    S,P = map(str,input().split())
    MAIN.append([i+1,S,int(P)])

def swap(i,j):
    x = MAIN[i]
    MAIN[i] = MAIN[j]
    MAIN[j] = x

update = True
while update == True:
    update = False
    for i in range(1,N):
        if MAIN[i][1] > MAIN[i-1][1]:
            continue
        elif MAIN[i][1] == MAIN[i-1][1]:
            if MAIN[i][2] > MAIN[i-1][2]:
                swap(i,i-1)
                update = True
        else:
            swap(i,i-1)
            update = True


for m in MAIN:
    print(m[0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  string s;
  cin>>n>>s;
  map<char,ll> p;
  rep(i,n){
    p[s[i]]++;
  }
  ll ans=1;
  for(auto u:p){
    ans*=(u.S+1);
    ans%=MOD;
  }
  COUT(ans-1);
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main(){
    int a,b,c,ta,tb,tc,i,N=100010;
    scanf("%d %d %d",&a,&b,&c);
    for(i=1;i<=N;i++){
        if(a%2||b%2||c%2) break;
        if((b+c)%2||(a+b)%2||(a+c)%2) break;
        ta=(b+c)/2;
        tb=(a+c)/2;
        tc=(a+b)/2;
        a=ta;b=tb;c=tc;
    }
    if(i>N) printf("-1\n");
    else printf("%d\n",i-1);
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[][] desire = new int[M][2];
		for(int i=0; i<M; i++) {
			desire[i][0] = sc.nextInt();
			desire[i][1] = sc.nextInt();
		}

		Arrays.sort(desire, (a, b) -> a[1] - b[1]);

		int index = 0;
		int ans = 0;
		while(index < M) {
			int end = desire[index][1];
			ans++;
			index++;

			while(index < M && desire[index][0] < end)
				index++;
		}

		System.out.println(ans);
	}
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

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

vector<int> vvv(const string&s){
  map<int,int>mp;
  for(auto e:s){
    mp[e]++;
  }
  vector<int>v;
  for(auto e:mp){
    v.push_back(e.second);
  }
  sort(v.begin(), v.end());
  return v;
}

int main(){
  vector<int> v;
  v.push_back(1);
  {
    int t = 6;
    while(t <= 100000){
      v.push_back(t);
      t *= 6;
    }
    t = 9;
    while(t <= 100000){
      v.push_back(t);
      t *= 9;
    }
  }
  int dp[100001] = {};
  for(int i = 0; i < 100001; ++i)dp[i] = 1001001001;
  dp[0] = 0;
  dp[1] = 1;
  int n; cin >> n;
  for(int i = 2; i <= n; ++i){
    for(auto e:v){
      int j = i - e;
      if(j >= 0)dp[i] = min(dp[i],dp[j]+1);
    }    
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3944
#include "bits/stdc++.h"
using namespace std;

vector<int> divisor(int n){
	vector<int> num;
	for(int i=1;i*i<=n;++i){
		if(n%i==0){
			num.push_back(i);
			if(i*i!=n)num.push_back(n/i);
		}
	}
	return num;
}

int main(){
	int n,m,ans=1;
	cin>>n>>m;
	vector<int> v=divisor(m);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		if(v[i]>=n){
			ans=m/v[i];
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
int N;
int board[6005][6];//たて:1~5000,よこ:1~5;
int mxcol[6];

int setblock(int d,int p,int q)
{
  int setheight=0;
  if(d==1)
    {
      for(int i=q;i<p+q;i++)
	{
	  setheight=max(setheight,mxcol[i]);
	}
      //cout << setheight << endl;
      for(int row=q;row<p+q;row++)
	{
	  board[setheight+1][row]=1;
	}
      for(int i=q;i<p+q;i++) mxcol[i]=setheight+1;
    }
  else if(d==2)
    {
      setheight=mxcol[q];
      for(int col=setheight;col<setheight+p;col++)
	{
	  board[col+1][q]=1;
	}
      mxcol[q]=setheight+p;
    }
  return setheight+1;
}

void vanishcheck(int minheight,int p,vector<int> &vanishcol)
{
  bool vanish;
  for(int col=minheight;col<minheight+p;col++)
    {
      vanish=true;
      for(int row=1;row<=5;row++)
	{
	  if(board[col][row]==0) vanish=false;
	}
      if(vanish)
	{
	  for(int row=1;row<=5;row++) board[col][row]=0;
	  vanishcol.push_back(col);
	}
    }
  return;
}

void aftervanish(vector<int> vanishcol)
{
  int mxrow=0;
  for(int i=1;i<=5;i++)
    {
      mxrow=max(mxrow,mxcol[i]);
    }
  for(int i=0;i<int(vanishcol.size());i++)
    {
      for(int j=1;j<=5;j++) mxcol[j]--;
      for(int row=vanishcol[i]-i;row<=mxrow;row++)
	{
	  for(int col=1;col<=5;col++)
	    {
	      swap(board[row][col],board[row+1][col]);
	    }
	}
    }
  for(int row=1;row<=5;row++)
    {
      for(int col=mxcol[row];col>=0;col--) 
	{
	  if(board[col][row]==1 || col==0)
	    {
	      mxcol[row]=col;
	      break;
	    }
	}
    }
}

int main(void)
{
  int minheight;
  while(cin >> N && N)
    {
      int ans=0;
      memset(board,0,sizeof(board));
      memset(mxcol,0,sizeof(mxcol));
      for(int i=0;i<N;i++)
	{
	  int d,p,q;
	  cin >> d >> p >> q;
	  minheight=setblock(d,p,q);
	  vector<int> vanishcol;
	  if(d==1)
	    {
	      vanishcheck(minheight,1,vanishcol);
	    }
	  else if(d==2)
	    {
	      vanishcheck(minheight,p,vanishcol);
	    }
	  if(int(vanishcol.size()!=0))
	    {
	      sort(vanishcol.begin(),vanishcol.end());
	      aftervanish(vanishcol);
	    }
	  /*
	  cout << "NOWcol" << endl;
	  for(int row=1;row<=5;row++)
	    {
	      cout << mxcol[row] << ' ';
	    }
	  cout << endl;
	  for(int col=10;col>=1;col--)
	    {
	      for(int row=1;row<=5;row++)
		{
		  cout << board[col][row];
		}
	      cout << endl;
	      }*/
	}
      for(int i=1;i<=6000;i++)
	{
	  for(int j=1;j<=5;j++)
	    {
	      if(board[i][j]==1) ans++;
	    }
	}
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3172
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
c=UnionFind(n)
for _ in range(m):
    a,b=map(int,input().split())
    c.union(a-1,b-1)
ans=0
for i in range(n):
    ans=max(ans,c.size(i))
print(ans)

Measured memory_bytes: 14568
#include <stdio.h>
#include <string.h>

int min(int a, int b) {
  return a < b ? a : b;
}

int main(void) {
  int i, j, ans[26], cnt[26], n;
  char s[60];
  scanf("%d", &n);
  for(i = 0; i < 26; ++i) ans[i] = 100;
  for(i = 0; i < n; ++i) {
    scanf("%s", s);
    for(j = 0; j < 26; ++j) cnt[j] = 0;
    for(j = 0; j < strlen(s); ++j) cnt[s[j] - 'a']++;
    for(j = 0; j < 26; ++j) ans[j] = min(cnt[j], ans[j]);
  }
  for(i = 0; i < 26; ++i) for(j = 0; j < ans[i]; ++j) printf("%c", i + 'a');
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;

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

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

    int ans = 0;
    // i個とる
    for(int i=K; i>=0; i--){
        int right = i;
        int left = 0;
        bool used[N];
        vector<int> all;
        while(right >= 0){
            fill(used, used+N, false);
            all.clear();
            for(int j=N-1; j>=N-right; j--){
                if(j<0) continue;
                if(!used[j]){
                    all.push_back(V[j]);
                    used[j] = true;
                }
            }
            for(int j=0; j<left; j++){
                if(j>=N) continue;
                if(!used[j]){
                    all.push_back(V[j]);
                    used[j] = true;
                }
            }
            right--;
            left++;

            sort(all.begin(), all.end());

            int sum = 0;
            for(auto num : all) sum += num;

            int cnt = 0;
            int pos = lower_bound(all.begin(), all.end(), 0) - all.begin();
            for(int j=0; j<pos; j++){
                cnt++;
                if(cnt+i > K) break;
                sum -= all[j];
            }
            ans = max(sum, ans);
        }
   }

    cout << ans << endl;

    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  int n = s.length();
  int dif = 1000;
  for (int i = 0; i < n-2; i++)
  {
    int a,b,c;
    a = s[i]-'0';
    b = s[i+1]-'0';
    c = s[i+2]-'0';
    int tmp = 100*a+10*b+c;
    dif = min(dif,abs(tmp-753));
  }
  cout << dif << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define ITR(i,x) for(auto i=(x).begin();i!=(x).end();++i)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const ll mod = 1000000007;

ll mpow(ll x, ll n){ //x^n(mod) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
ll inv_mod(ll a){return mpow(a,mod-2);}
template<ll mod> class modll {
 private:
  ll _num;
  modll set(ll num){ _num = num % mod; return *this; }
 public:
  modll(){ _num = 0; }
  modll(ll num){ _num = num % mod; }

  modll operator= (ll x){ return set(x % mod); }
  modll operator+ (ll x){ return modll<mod>(_num + (x % mod)); }
  modll operator- (ll x){ return modll<mod>(_num - (x % mod)); }
  modll operator* (ll x){ return modll<mod>(_num * (x % mod)); }
  modll operator+=(ll x){ return set(_num + (x % mod)); }
  modll operator-=(ll x){ return set(_num - (x % mod)); }
  modll operator*=(ll x){ return set(_num * (x % mod)); }

  explicit operator ll() { return _num; }
  friend ostream& operator<<(ostream &os, const modll<mod> &x){ os << x._num; return os; }
};
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

class Factorial{//階乗とその逆元を求めて計算に利用するクラス
 private:
    vector<ll> fac;
 public:
    
    Factorial(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};

int main(){
    int N,X;
    cin>>N>>X;
    vector<int> L(N);
    REP(i, N) cin >> L[i];
    int D=0;
    int ans=1;
    REP(i,N){
        D+=L[i];
        if(D<=X) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  ll x,a,b;cin>>x;
  for(ll i=1;i<1000;i++){
    for(ll j=-1000;j<1000;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){a=i;b=j;break;}
    }
  }
  cout <<a<<" "<<b<<endl;
    
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
using fint64 = int_fast64_t;
struct Combination {
	const int MAX = 5000010;
	const int MOD;
	vector<fint64> FAC;
	vector<fint64> INV;
	vector<fint64> FAC_INV;
	Combination(fint64 MOD) :
		MOD(MOD),
		FAC(vector<fint64>(MAX)),
		INV(vector<fint64>(MAX)),
		FAC_INV(vector<fint64>(MAX))
		{
			FAC[0] = INV[1] = FAC_INV[0] = 1;
			for(int i = 1; i < MAX; ++i) {
				FAC[i] = FAC[i - 1] * i % MOD;
				if(i > 1) INV[i] = MOD - INV[MOD % i] * (MOD / i) % MOD;
				FAC_INV[i] = FAC_INV[i - 1] * INV[i] % MOD;
			}
		}
	fint64 C(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[r] % MOD * FAC_INV[n - r] % MOD;
	}
	fint64 P(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[n - r] % MOD;
	}
	fint64 H(int n, int r) {
		if(r == 0) return 1;
		return C(n + r - 1, r);
	}
};
signed main(){
    int x,y;
    cin>>x>>y;
    int sx=x,sy=y;
    int counta=0,countb=0;
    counta=(2*y-x)/3;
    countb=(2*x-y)/3;
    if((2*y-x)%3!=0 or (2*x-y)%3!=0) cout<<0<<endl;
    else{
        Combination com(INT_MOD);
        cout<<com.C(counta+countb,counta)<<endl;
    }
    return 0;
}

Measured memory_bytes: 117376
<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
$array = [1,2,3,$a,$b];
sort($array);
if($array[0] === $array[1] && $array[3] === $array[4]){
   echo 2;
}elseif($array[1] === $array[2] && $array[3] === $array[4]){
   echo 1;
}else{
   echo 3;
}
?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a[5];
    REP(i,5) cin >> a[i];
    REP(i,5) if ( a[i]==0 ) {
        cout << i+1 << '\n';
        break;
    }
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a>b)swap(a,b);
    rep(a,i,b+1){
        if(i==c){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 256
/*
 * FileName:     priority_queue_fix
 * CreatedDate:  2020-08-19 22:46:16 +0900
 * LastModified: 2020-08-19 23:10:38 +0900
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define m 2000000

void heapify(int *Q, int index){
    if(index/2==0){
        return;
    }
    if(Q[index]>Q[index/2]){
        int tmp = Q[index];
        Q[index] = Q[index/2];
        Q[index/2] = tmp;
        heapify(Q, index/2);
    }
}
void reheapify(int *Q, int index, int H){
    if(2*index>H){
        return;
    }
    int key=index;
    if(2*index<=H && Q[index]<Q[2*index]){
        key=2*index;
    }
    if(2*index+1<=H && Q[key]<Q[2*index+1]){
        key=2*index+1;
    }
    if(key!=index){
        int tmp = Q[index];
        Q[index] = Q[key];
        Q[key] = tmp;
        reheapify(Q, key, H);
    }

}
int extract(int *Q, int index){
    int ans =  Q[1];
    Q[1] = Q[index-1];
    reheapify(Q, 1, index-1);
    return ans;
}
void print(int *Q, int H){
    for(int i=1; i<H; i++){
        printf("%d ", Q[i]);
    }
    printf("\n");
}
int main(void){
    int *S = malloc(m*sizeof(int));
    memset(S, -1, sizeof(S));
    int index = 1;
    while(1){
        char command[10];scanf("%s", command);
        if(command[0]=='i'){
            int k;scanf("%d", &k);
            S[index] = k;
            heapify(S, index++);
//            print(S, index);
        }
        else if(command[1]=='x'){
            printf("%d\n", extract(S, index--));
//            print(S, index);
        }
        else{
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    long long int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int ticket[3];
	int i;
	
	for (i = 0; i < 3; i++){
		scanf("%d", ticket + i);
	}
	if (ticket[0] == ticket[1] && ticket[1] != ticket[2]){
		puts("Open");
	}
	else {
		puts("Close");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll n, m;
vector<ll> c;
vector<ll> x;
vector<vector<ll>> table;

ll clip(ll x, ll minv, ll maxv) {
  return min(max(x, minv), maxv);
}

ll dfs(ll i, ll y=128) {
  if (table[i][y] != -1) return table[i][y];

  if (i == n) return table[i][y] = 0;

  ll minv = 1ll << 60;
  for (auto v: c) {
    ll value = clip(y + v, 0, 255);
    ll diff = value - x[i];
    minv = min(minv, dfs(i + 1, value) + diff * diff);
  }
  return table[i][y] = minv;
}

bool solve() {
  cin >> n >> m;
  if (n == 0 && m == 0) return false;

  c = vector<ll>(m);
  x = vector<ll>(n);
  REP(i, m) cin >> c[i];
  REP(i, n) cin >> x[i];
  table = vector<vector<ll>>(n + 1, vector<ll>(256, -1));

  cout << dfs(0) << endl;
  return true;
}

int main() {
  while(solve());
}



Measured memory_bytes: 86432
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		HashMap<Integer, HashMap<Integer, Integer>> edge = new HashMap();
		for (int i=0 ;i<n-1; i++) {
			String[] arr = sc.nextLine().split(" ");
			int u = Integer.parseInt(arr[0]);
			int v = Integer.parseInt(arr[1]);
			int w = Integer.parseInt(arr[2]);

			if (! edge.containsKey(u-1)) {
				edge.put(u-1, new HashMap<Integer, Integer>());
			}
			edge.get(u-1).put(v-1, w);
			if (! edge.containsKey(v-1)) {
				edge.put(v-1, new HashMap<Integer, Integer>());
			}
			edge.get(v-1).put(u-1, w);
		}
		sc.close();

		int[] res = new int[n];
		Arrays.fill(res, -1);
		LinkedList<Integer> stack = new LinkedList<Integer>();
		stack.push(0);
		res[0] = 0;

		while(! stack.isEmpty()) {
			int target = stack.pop();
			for(int key: edge.get(target).keySet()) {
				if (res[key] != -1) {
					continue;
				}
				stack.push(key);
				if (edge.get(target).get(key) % 2 == 0) {
					res[key] = res[target];
				} else {
					res[key] = res[target] == 0 ? 1 : 0;
				}
			}
		}
		for(int i=0; i<n; i++) {
			System.out.println(res[i]);
		}
	}
}


Measured memory_bytes: 190460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		long a = Long.parseLong(strlist[0]);
		long b = Long.parseLong(strlist[1]);
		long c = Long.parseLong(strlist[2]);
		long[] abc = {a, b, c};
		Arrays.sort(abc);

		if(a%2==0 || b%2==0 || c%2==0){
			System.out.println(0);
		}else{
			Long long1 = abc[0];
			Long long2 = abc[1];
			BigInteger big1 = new BigInteger(long1.toString());
			BigInteger big2 = new BigInteger(long2.toString());
			System.out.println(big1.multiply(big2));
		}
	}
}


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

int main(){
  while(1){
    int d,n,m;
    cin>>d;
    if(d==0)
      break;
    cin>>n>>m;
    vector<int> sp(n+1,0),dp(m);

    sp[n]=d;
    for(int i=1;i<n;i++){
      cin>>sp[i];
    }
    sort(sp.begin(),sp.end());

    int sum=0;
    for(int i=0;i<m;i++){
      cin>>dp[i];
      int j=0;
      while(!(sp[j]<=dp[i] && dp[i]<=sp[j+1]) && j<n)
        j++;
      sum+=min(abs(sp[j]-dp[i]),abs(sp[j+1]-dp[i]));
    }
    cout<<sum<<endl;
  }
}


Measured memory_bytes: 3320
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <cstdio>
#include<algorithm>
#include <utility>
#include<string>
using namespace std;
string str[10000] = { "" };
char ch[10000];
int input();
int main() {
	int a,most=0;
	a = input();
	string  longest;
	int m[10000] = { 0 }, l;
	for (int i = 0; i <= a + 1; i++) {
		for (int j = i + 1; j <= a; j++) {
			if (str[i] == str[j]) {
				m[i]++;
			}
		}
	}int k,ma=0,locate,memo;
	for (k = 0; k <= a+1; k++) {
		if (m[k] > ma) {
			ma = m[k];
			locate= k;
		}
	}
	for (int f = 0; f <= a+1; f++) {
		if (str[f].size()> most) {
			most = str[f].size();
			memo = f;
		}
	}
	longest = str[memo];
	cout << str[locate] << " " << longest << endl;
	return 0;
}
int input() {
	int i = 0, j = 0;
	while (1) {
		scanf("%c", &ch[i]);
		if (isupper(ch[i])) {
			ch[i] += 'a' - 'A';
		}
		if (ch[i] == ' ') {
			j++;
		}
		else if (ch[i] == '\n') {
			break;
		}
		else {
			str[j] += ch[i];
		}
		
	}
	return j;
}

Measured memory_bytes: 3320
import itertools
n,m,q=(int(x) for x in input().split())

i = itertools.combinations_with_replacement(range(1,m+1),n)
score = 0
a,b,c,d = [0]*q,[0]*q,[0]*q,[0]*q
for j in range(q):
    a[j],b[j],c[j],d[j]=(int(x) for x in input().split())
for array in i:
    tmp = 0
    for j in range(q):
        tmp += d[j] if array[b[j]-1] - array[a[j]-1] == c[j] else 0
    score = max(tmp,score)
print(score)

Measured memory_bytes: 9112
A,B,C=list(map(int,input().split()))

max = max([A,B,C])
dif_sum = 3*max -A-B-C

cnt=0
if dif_sum % 2 == 0:
    cnt = dif_sum / 2
else:
    cnt = (dif_sum+1) / 2
    cnt += 1
print(int(cnt))

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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

string s;

int main() {
    ll k;

    cin >> s >> k;

    if(s.size() == 1) {
    	printf("%lld\n", k/2);
    	return 0;
    }

    ll cnt = 0, ans = 0;

    vector<ll> c, c2;
    for(ll i = 1; s[i]; i++) {
    	if(s[i] == s[i-1]) cnt++;
    	else {
    		if(cnt) c.push_back(cnt+1);
    		cnt = 0;
    	}
    }

    if(cnt) c.push_back(cnt+1);

    for(auto x : c)
    	ans += x/2;
    if(k == 1) {
    	printf("%lld\n", ans);
    	return 0;
    }

    if(c.size() == 1 && c[0] == s.size()) {
    	printf("%lld\n", ((ll)c[0]*k)/2);
    	return 0;
    }

    if(s[0] != s[s.size()-1]) {
    	printf("%lld\n", ans*k);
    	return 0;
    }

    ll i = 0, j = s.size()-1;
    ll spec = 0;
    while(i < s.size() && s[i] == s[j])
    	spec++, i++;

    ans = spec/2;

    i--;
    while(j >= 0 && s[i] == s[j])
    	spec++, j--;
    j++;
    ans += (s.size() - j)/2;
    ans += ((ll)spec/2)*((ll)k-1);

    cnt = 0;
    while(i+1 < j) {
    	if(s[i+1] == s[i]) cnt++;
    	else ans += ((cnt+1)/2)*k, cnt = 0;
    	i++;
    }

    if(cnt) ans += ((cnt+1)/2)*k;

    printf("%lld\n", ans);

    return 0;
}


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

int H[4], W[4];
int S[4][4][4] = {0};

bool solve(){
    int A[4][10] = {0};
    for(int i=0; i<4; i++){
        string s;
        cin >> s;
        for(int j=0; j<10; j++) if(s[j] == '#') A[i][j] = 1;
    }

    vector<pair<int, int>> avail[4];
    for(int k=0; k<4; k++){
        for(int i=0; i<=4-H[k]; i++) for(int j=0; j<=10-W[k]; j++){
            bool ok = true;
            for(int x=0; x<H[k]; x++) for(int y=0; y<W[k]; y++) if(S[k][x][y] && A[i+x][j+y]) ok = false;
            if(ok) avail[k].emplace_back(i, j);
        }
    }

    for(int ex=0; ex<4; ex++){
        vector<int> use;
        for(int k=0; k<4; k++) if(k != ex) use.push_back(k);

        for(auto& p0 : avail[use[0]]){
            bool ok0 = true;
            int i0 = p0.first, j0 = p0.second, k0 = use[0];
            for(int x=0; x<H[k0]; x++) for(int y=0; y<W[k0]; y++) if(S[k0][x][y]) {
                A[i0+x][j0+y]++;
                if(A[i0+x][j0+y] > 1) ok0 = false;
            }

            if(ok0) for(auto& p1 : avail[use[1]]){
                bool ok1 = true;
                int i1 = p1.first, j1 = p1.second, k1 = use[1];
                for(int x=0; x<H[k1]; x++) for(int y=0; y<W[k1]; y++) if(S[k1][x][y]){
                    A[i1+x][j1+y]++;
                    if(A[i1+x][j1+y] > 1) ok1 = false;
                }

                if(ok1) for(auto& p2 : avail[use[2]]){
                    bool ok2 = true;
                    int i2 = p2.first, j2 = p2.second, k2 = use[2];
                    for(int x=0; x<H[k2]; x++) for(int y=0; y<W[k2]; y++) if(S[k2][x][y]){
                        A[i2+x][j2+y]++;
                        if(A[i2+x][j2+y] > 1) ok2 = false;
                    }
                    if(ok2) return true;
                    for(int x=0; x<H[k2]; x++) for(int y=0; y<W[k2]; y++) if(S[k2][x][y]){
                        A[i2+x][j2+y]--;
                    }
                }

                for(int x=0; x<H[k1]; x++) for(int y=0; y<W[k1]; y++) if(S[k1][x][y]){
                    A[i1+x][j1+y]--;
                }
            }

            for(int x=0; x<H[k0]; x++) for(int y=0; y<W[k0]; y++) if(S[k0][x][y]){
                A[i0+x][j0+y]--;
            }
        }
    }
    return false;
}

int main(){
    for(int k=0; k<4; k++){
        cin >> H[k] >> W[k];
        for(int i=0; i<H[k]; i++){
            string s;
            cin >> s;
            for(int j=0; j<W[k]; j++) if(s[j] == '#') S[k][i][j] = 1;
        }
    }
    int N;
    cin >> N;
    while(N--) cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 3216
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define exists(x,m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

vi primes;
vector<bool> composite;

void prime_sieve(int lim) {
	composite = vector<bool>(lim+1);
	for (int num = 2; num <= lim; num++) {
		if (!composite[num]) primes.pb(num);
		for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) {
			composite[num * primes[i]] = true;
			if (num % primes[i] == 0) break;
		}
	}
}

umap<int, int> prime_fact(int x, vi& prime_list) {
	umap<int, int> divisors = umap<int, int>();
	int lim = ceil(sqrt(x)) + 1;
	for (int i = 0; prime_list[i] <= lim; i++) {
		int p = prime_list[i];
		while (x % p == 0) {
			divisors[p]++;
			x /= p;
		}
	}
	if (x != 1) divisors[x]++;
	return divisors;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	vi A = vi();
	int maxx = 0;
	rep(i, n) {
		int x; cin >> x;
		A.pb(x);
		maxx = max(maxx, x);
	}	
	prime_sieve(min(1e3+100, ceil(sqrt(maxx)) + 100));
	umap<int, int> prime_freq = umap<int, int>();
	for (const int& a : A) {
		for (const auto& [div, fre] : prime_fact(a, primes)) {
			prime_freq[div] += 1;
		}
	}
	int max_freq = 0;
	for (const auto& [p, freq] : prime_freq) {
		max_freq = max(max_freq, freq);
	}
	if (max_freq <= 1) {
		cout << "pairwise coprime";
	} else {
		cout << (max_freq < n ? "setwise coprime" : "not coprime");
	}
}

Measured memory_bytes: 10532
function main()
  
  S = split(readline(),"")
  
  check = false
  
  for i in 1:3
    
    if S[i] == S[i+1]
      check = true
      println("Bad")
      break
    end
    
  end
  
  if check == false
    
    println("Good")
    
  end
  
end

main()

Measured memory_bytes: 167236
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int n,sum=0,minnum=1000,ans=0,psum=0; cin >> n;
    vector<int> vec(n);
    for(int i = 0; i<n; i++){
        cin >> vec[i];
        sum += vec[i];
    }
    for(int j = 0; j<n-1; j++){
        psum += vec[j];
        minnum = min(abs(sum-psum*2),minnum);
    }
    cout << minnum << endl;



    return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if(n == 0) break;
			HashMap<Long, Integer> map = new HashMap<Long, Integer>();
			int p=0;
			long[] val = new long[n];
			long[] ids = new long[n];
			for(int i=0;i<n;i++) {
				long id = sc.nextInt(), k = sc.nextInt(), c = sc.nextInt();
				if(map.containsKey(id)) {
					val[map.get(id)] += k * c;
				}
				else {
					map.put(id, p);
					ids[p] = id;
					val[p++] = k * c;
				}
			}
			ArrayList<Long> ans = new ArrayList<Long>();
			for(int i=0;i<n;i++) if( val[i] >= 1000000 ) ans.add(ids[i]);
			if(ans.isEmpty()) {
				System.out.println("NA");
			}
			else {
				for(long l: ans) System.out.println(l);
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 25320
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long z = sc.nextLong();
      long w = sc.nextLong();
      long[] ar = new long[n];
      for(int i = 0; i < n; i++){
         ar[i] = sc.nextLong();
      }
      
      if(n == 1){
         System.out.println(Math.abs(ar[0] - w));
      }
      else {
         long ans = 0;
         for(int i = 1; i < ar.length; i++){
            ans = Math.max(Math.abs(ar[i] - w), Math.abs(ar[i] - ar[i-1]));
         }
         System.out.println(ans);
      } 
   }
}

Measured memory_bytes: 25556
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i

def solve(a, b, c, d, e)
  a + (10 - a % 10) % 10 + b + (10 - b % 10) % 10 + c + (10 - c % 10) % 10 + d + (10 - d % 10) % 10 + e
end

min = 1000

[A, B, C, D, E].permutation(5) { |a, b, c, d, e|
  min = [min, solve(a, b, c, d, e)].min
}

puts min


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Character;
import java.util.Scanner;


public class Main {


	/**
	 * main
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scan = new Scanner(System.in);
		int[] cnt = new int[26];//??¢??????????????????26??????????????????
		int num = 0;		//???????????¨????????°
		String line = "";
		
		while(scan.hasNext()){
			line = scan.nextLine();
		    String st = line.toLowerCase();
		    for(int i = 0 ; i < st.length() ; i++){
			char c = st.charAt(i);
			if('a' <= c && c <= 'z') cnt[c - 'a']++;
			else continue;
			}
		}
		
		//??¨???
		for (int i = 0; i < cnt.length; i++) {
			System.out.println((char)('a'+i) + " : " + cnt[i]);
		}
	}
	
}

Measured memory_bytes: 17332
#include <bits/stdc++.h>
using namespace std;
#define maxn 200010
typedef long long ll;
struct Edge{
	int v,nxt;
}e[maxn<<1];
int head[maxn],cnt_e;
void add(int u,int v){
	e[++cnt_e].v=v;
	e[cnt_e].nxt=head[u];
	head[u]=cnt_e;
}
int n;
ll fa[maxn];
void dfs(int x){
	for(int i=head[x];i;i=e[i].nxt){
		int v=e[i].v; if(v==fa[x]) continue;
		fa[v]=x; dfs(v);
	}
}
int main(){
	//freopen("data.in","r",stdin);
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d %d",&u,&v);
		add(u,v); add(v,u);
	}
	dfs(1);
	ll ans=n;
	for(int i=2;i<=n;i++){
		//cout<<"i= "<<i<<" "<<fa[i]<<endl;
		if(fa[i]>i){
			ans=ans+(fa[i]-i)*i;
		}
		else{
			ans=ans+(i-fa[i])*(n-i+1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 18452
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;
int main()
{
    ll n,k,i;
    cin>>k>>n;
    (k*500>=n)?cout<<"Yes"<<endl:cout<<"No"<<endl;
    return 0;
}





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

int main() {
  int N, M, X;
  cin >> N >> M >> X;

  int list[N + 1];
  memset(list, 0, sizeof(list));

  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    list[a] = 1;
  }
  int s[N + 1];
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= N; i++) {
    s[i] = s[i - 1] + list[i];
  }

  cout << min(s[X] - s[0], s[N] - s[X]) << endl;
  return 0;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc138/tasks/abc138_c
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    long n = readln.chomp.to!long;
    long[] v = readln.split.map!(to!long).array;

    v.sort;

    double answer = v[0];
    for(int i = 1; i < n; i++) {
        answer += double(v[i]);
        answer /= 2.0;
    }

    writefln("%.9f", answer);
}



Measured memory_bytes: 3040