akhauriyash/Code-Regression huggingface dataset:
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0],reverse=True)
mainweapon = ab[0]
del ab[0]
new_ab =[]
for i in range(N-1):
    if ab[i][1] > mainweapon[0]:
        new_ab.append(ab[i])
new_ab.sort(key=lambda x:x[1],reverse=True)

attack = 0

for i in range(len(new_ab)):
    H -= new_ab[i][1]
    attack += 1
    if H <= 0:
        break

if H > 0:
    attack += math.ceil((H - mainweapon[1])/mainweapon[0])
    attack += 1

print(attack)


Measured memory_bytes: 29636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  long long n, x, m;
  cin >> n >> x >> m;
  vector<int> vis(m + 1, 0);
  long long ans = 0;
  long long cur = x;
  while (!vis[cur]) {
    vis[cur] = 1;
    cur *= cur;
    cur %= m;
  }
  long long sum_c = 0;
  int cycle = 0;
  long long st = cur;
  do {
    sum_c += cur;
    cur *= cur;
    cur %= m;
    cycle++;
  } while (cur != st);
  cur = x;
  while (cur != st) {
    n--;
    ans += cur;
    cur *= cur;
    cur %= m;
  }
  ans += sum_c * (n / cycle);
  n %= cycle;
  cur = st;
  while (n > 0) {
    n--;
    ans += cur;
    cur *= cur;
    cur %= m;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3736
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    if(s == "SUN"){
        cout << "7";
    }else if(s == "MON"){
        cout << "6";
    }else if(s == "TUE"){
        cout << "5";
    }else if(s == "WED"){
        cout << "4";
    }else if(s == "THU"){
        cout << "3";
    }else if(s == "FRI"){
        cout << "2";
    }else if(s == "SAT"){
        cout << "1";
    }
    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<limits>
#include <bitset>      


#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair


using namespace std;

vector<int> v[100005];
int dp[100005];
int vis[100005];
int n, m;

          void DFS(int i){

                  vis[i] = true;

                  for(int j = 0; j < v[i].size(); j++){
                        if(!vis[v[i][j]]){
                             DFS(v[i][j]);
                           } 
                        dp[i] = max(dp[i], 1 + dp[v[i][j]]);
                     }

               }   


 

int main(){

    cin >> n >> m;

    for(int i = 0; i < m; i++){
           int x, y;
           cin >> x >> y;
           v[x].pb(y);
        }

    int ans = 0;

    for(int i = 1; i <= n; i++){
        if(!vis[i]) DFS(i);
       }
    
    for(int i = 1; i <= n; i++){
         ans = max(ans, dp[i]);
      }

    
    cout <<  ans;
    

    return 0;

}


Measured memory_bytes: 8576
function main(k:number,s:number){
    for(var i =0;i<=k;i++){
        var x = i;
        for(var j =0;j<=k;j++){
            var y=j;
            var z=s-(x+y);
            if(!(z>=0&&z<=k)){
                continue;
            }
            var total:number=x+y+z;
                if(total==s){
                    result++;
                }
            /*for(var l=0;l<=k;l++){
                var z=l;
                var total:number=x+y+z;
                if(total==s){
                    result++;
                }
            }
            */
        }
    }
    console.log(result);
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var array_ks=input.split(" ");
var input_k=array_ks[0];
var input_s=array_ks[1];
var result=0;
if(input_k>=2 && input_k<=2500 && input_s>=0 && input_s<=3*input_k){
    main(input_k,input_s);
}


Measured memory_bytes: 7500
import sys
input = sys.stdin.readline
mod=10**9+7

H,W,N=map(int,input().split())
B=[tuple(map(int,input().split())) for i in range(N)]

B.append((H,W))
B.sort()

FACT=[1]
INVFACT=[1]
for i in range(1,H+W):
    FACT.append(FACT[-1]*i%mod)
    INVFACT.append(INVFACT[-1]*pow(i,mod-2,mod)%mod)

def Combi(n,r):
    return FACT[n]*INVFACT[n-r]*INVFACT[r]%mod


DP=[0]*(N+1)#i-1番目までに触れず、i番目のブロックに触れる経路数

for i in range(N+1):
    h,w=B[i]

    ANS=Combi(h+w-2,h-1)
    
    for j in range(i):
        if B[j][0]>h or B[j][1]>w:
            continue
        ANS=(ANS-DP[j]*Combi(h+w-B[j][0]-B[j][1],h-B[j][0]))%mod

    DP[i]=ANS

print(DP[-1])


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

int main() {
  int A,B,sum;
  cin >> A >> B;
  for(int i=A;i<B+1;i++){
    if(i/10000==i%10 && (i/1000)-(i/10000)*10==(i/10)-(i/100)*10){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    if(s.size()&1)
        return cout<<"No"<<endl,0;
    for(int i=0;i<s.size();i+=2)
        if(s[i]!='h'||s[i+1]!='i')
            return cout<<"No"<<endl,0;
    cout<<"Yes"<<endl;
    return 0;
}

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

int main() {
  int N, K, x, A, B, sum;
  cin >> N >> K;
  sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> x;
    A = (x - 0) * 2;
    B = (K - x) * 2;
    if (A < B)
      sum += A;
    else 
      sum += B;     
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;

int main(){
    int dp[31];
    int i,n;
    dp[0]=1,dp[1]=1,dp[2]=2;
    for(i=3;i<=30;i++){
        dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
    }
    while(cin>>n&&n){
        int ans=(dp[n]-1)/(365*10)+1;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
ll ta[2000][2000],yo[2000][2000];
int main() {
	ll h,w;
	cin>>h>>w;
	char ch[2001][2001];
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			char now;
			cin>>now;
			ch[i][j]=now;
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(ch[i][j]=='.'){
				yo[i][j]=1;
			}
			if(j!=0&&yo[i][j]!=0){
				yo[i][j]+=yo[i][j-1];
			}
		//	cout << yo[i][j];
		}
		//cout <<endl;
	}
	for(ll i=0;i<w;i++){
		for(ll j=0;j<h;j++){
			if(ch[j][i]=='.'){
				ta[j][i]=1;
			}
			if(j!=0&&ta[j][i]!=0){
				ta[j][i]+=ta[j-1][i];
			}
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=1;j<w;j++){
			if(yo[i][w-1-j]!=0&&yo[i][w-j]!=0){
				yo[i][w-1-j]=yo[i][w-j];
			}
		}
	}
	for(ll i=0;i<w;i++){
		for(ll j=1;j<h;j++){
			if(ta[h-j-1][i]!=0&&ta[h-j][i]!=0){
				ta[h-j-1][i]=ta[h-j][i];
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			ans=max(ans,ta[i][j]+yo[i][j]);
		}
	}
	cout <<ans-1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 66688
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main() {
  int N;
  string P = "";
  string Q = "";

  cin >> N;
  for (int i = 0; i < N; i++) {
    char x;
    cin >> x;
    P += x;
  }
  for (int i = 0; i < N; i++) {
    char x;
    cin >> x;
    Q += x;
  }

  int a = 0;
  int b = 0;
  int sum = 0;
  int indexes[N];

  for (int i = 0; i < N; i++) indexes[i] = i+1;
  do {
    string S = "";
    for (int j = 0; j < N; j++) {
      S += char(indexes[j] + '0');
    }
    sum++;
    if (S == P) {
      a = sum;
    }
    if (S == Q) {
      b = sum;
    }
  } while (next_permutation(indexes, indexes + N));

  cout << abs(a - b) << endl;
}


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

int main() {
	int a, b, c, max, mid, min;


	cin >> a >> b >> c;
	min = a;
	mid = b;
	max = c;

	if (a > b) {
		min = b;
		mid = a;
	}
	if (c < mid) {
		max = mid;
		mid = c;
	}
	if (c < min) {
		mid = min;
		min = c;
	}

	cout << min << " " << mid << " "<< max << endl;
	return 0;
}

	

Measured memory_bytes: 3080
# ABC 156 C
from math import ceil,floor
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
x=nl()
# x.sort()
# max_x=max(x)
# min_x=min(x)
# median_1=(max_x+min_x)//2
# median_2=ceil((max_x+min_x)//2)
# ans=0
ans=10**10
for i in range(1,101):
    t=0
    for j in range(n):
        t+=(x[j]-i)**2
    ans=min(ans,t)
print(ans)
    


Measured memory_bytes: 3064
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
int x=0,y=0,z=0,w=0,a=0,b=0;
std::cin >> x;
std::vector<int> v(x);
rep(i,x){
  std::cin >> y>>z;
  if(y%z==0)v[i]=z;
  else v[i]=y%z;
}
rep(i,x){
  std::cout << v[i] << '\n';
}
}



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

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using vi  = vector<ll>;
using pii = pair<ll,ll>;
#define int ll

int n;
vi a;

template<typename T> class BIT{
  vector<T> vec;
  const ll n;
  
public:
  BIT(T _n) : vec(_n + 1), n(_n) {}

  T query(ll x) { /* query for [1, x] */
    T ret = 0;
    for(ll i = x; i > 0; i -= i & (-i)) ret += vec[i];
    return ret;
  }

  void update(ll x, T k) { /* update for [1, x] */
    for(ll i = x; i <= n; i += i & (-i)) vec[i] += k;
  }
};

bool solve(int mid){
  vi s(n+1);
  rep(i,n){
    s[i+1] = (a[i] >= mid) ? 1 : -1;
    s[i+1] += s[i];
  }

  BIT<ll> bit(n*3);
  int inv = 0;
  rep(i,n+1){
    // cout << i << endl;
    inv += bit.query(s[i]+n*2);
    bit.update(s[i]+n*2, 1);
  }

  int tmp = (n+1) * n / 2;
  // cout << (inv >= (tmp+1)/2) << endl;
  if(inv >= (tmp+1) / 2) return true;
  else return false;
}

int bs(int _ok, int _ng){
  int ok = _ok;
  int ng = _ng;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(solve(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  return ok;
}

main(){
  cin >> n;
  a.resize(n); rep(i,n) cin >> a[i];
  int ans = bs(1,1e9+1);
  cout << ans << endl;
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
            int N = Input.ScanInt();
          int Sum = Enumerable.Range(1,N).ToArray().Sum();
          Console.WriteLine(Sum);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

using namespace std ;
using ll = long long;
using p = pair <int , int >;
using V = vector <int> ;
using S = vector <string>;

int lastDigit(int n) 
{ 
    // return the last digit 
    return (n % 10); 
}

int main (){


	int n ;
	cin  >> n;
	if (n > 999){ return 0 ;}
	else {
		if (lastDigit(n) == 3){
			cout << "bon"<< endl;
		}
		else if (lastDigit(n) == 0 ||lastDigit(n) == 1||lastDigit(n) == 6||lastDigit(n) == 8)
		{
			cout << "pon "<< endl;
		}

		else{cout << "hon"<<endl;}
	}

	

	return 0 ;

	}


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, 0, n){
        cin >> p[i];
    }
    int tmp, idx1 = -1, idx2 = -1;
    rep(i, 0, n - 1){
        if(p[i] > p[i+1]){
            idx1 = i;
            break;
        }
    }
    for(int i = n - 2; i > -1; --i){
        if(p[i] > p[i+1]){
            idx2 = i;
            break;
        }
    }
    if(idx1 == -1 || idx2 == -1){
        cout << "YES" << endl;
        return 0;
    }else{
        tmp = p[idx1];
        p[idx1] = p[idx2 + 1];
        p[idx2 + 1] = tmp;
        rep(j, 0, n - 1){
            if(p[j] > p[j+1]){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
string S;

signed main(){
	cin>>S;
	N=S.size();
	string last;
	int ans=0;
	string now;
	REP(i,N){
		now+=S[i];
		if(i==0){
			now="";
			last=S[i];
			ans++;
		}
		else if(last!=now){
			last=now;
			now="";
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

struct Edge {
  int to;
  int cost;
};

// 隣接リスト
vector<Edge> g[200000];
// g[i] = 頂点iから生えてる全ての辺のリスト
// g[i][j].to = 頂点iからtoへの辺
// g[i][j].cost = その辺のコスト

int d[200000]; // 頂点d[v]への最短距離

void dijkstra(int s) {
  d[s] = 0;  // 始点の最短距離 = 0

  // firstを最短距離、secondを頂点番号
  priority_queue<P, vector<P>, greater<P>> pq;

  pq.push(P(d[s], s));

  while (!pq.empty()) {
    int v_cost = pq.top().first;
    int v = pq.top().second;
    pq.pop();

    if (d[v] < v_cost) continue; //無駄な探索を減らす

    for (int i = 0; i < g[v].size(); i++) {
      int c = g[v][i].to;
      int c_cost = g[v][i].cost;  // 辺vcのコスト

      int cost = v_cost + c_cost;  // 頂点cへの合計コスト
      if (d[c] > cost) { // すでに記録されてるものより低コストなら更新
        d[c] = cost;
        pq.push(P(cost, c));
      }
    }
  }
}

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

  int V, E, r;
  cin >> V >> E >> r;

  fill(d, d + V, INF);

  // 隣接リストの作成
  for (int i = 0; i < E; i++) {
    int s, t, cost;
    cin >> s >> t >> cost;

    Edge edge = {t, cost};

    g[s].emplace_back(edge);
  }

  dijkstra(r);

  for (int i = 0; i < V; i++) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 15288
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int a,b;
signed main() {
  IO;
  cin >> a >> b;
  cout << a * b << '\n';
  return 0;
}

Measured memory_bytes: 3616
from itertools import accumulate

n,m=map(int,input().split())
*x,=map(int,input().split())
*y,=map(int,input().split())

acmx=list(accumulate(x))
acmy=list(accumulate(y))
mod=10**9+7
sumx=0
for i in range(n-1):
    sumx+=acmx[n-1]-acmx[i]-(n-i-1)*x[i]
    sumx%=mod

sumy=0
for i in range(m-1):
    sumy+=acmy[m-1]-acmy[i]-(m-i-1)*y[i]
    sumy%=mod

print(sumx*sumy%mod)

Measured memory_bytes: 112236
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>
#define mx 100005
using namespace std;
int dp[mx],h[mx],n;
void min_cost(int i)
{
    if(i>=n)
        return;
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    min_cost(i+1);
}
int main()
{
    int i;
    cin>>n;
    for(i=0; i<n; i++)
        cin>>h[i];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    min_cost(2);
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int n,x,i,m,min=1000;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		x-=m;
		if(m<min){min=m;}
	}
	printf("%d",n+x/min);
	return 0;
}

Measured memory_bytes: 128
from __future__ import division, print_function
from sys import stdin
houses = [[[0] * 10 for _ in range(3)] for _ in range(4)]
separator = '#' * 20
for _ in range(int(stdin.readline())):
    b, f, r, v = (int(s) for s in stdin.readline().split())
    houses[b-1][f-1][r-1] += v
for i, house in enumerate(houses):
    for floor in house:
        print('', *floor)
    if i < 3:
        print(separator)

Measured memory_bytes: 4244
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<assert.h>
#include<stack>
ll z = 1000000007 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b){if(b <= 0) return 1 ; ll c = power(a , b/2) ; if(b%2 == 0) return ((c*c)%z) ; else return ((((c*c)%z)*a)%z) ;}
ll inverse(ll a ,ll n){return power(a , n-2) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
using namespace std ;


//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);

 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	ll h , n ;
	cin >> h >> n ;
	vector<pair<ll ,ll> > v ;
	fo(i , n)
	{
		ll a , b ;
		cin >> a >> b ;
		v.pub(mp(a,b)) ;
	}
	
	ll dp[h+1] ;
	fo(i , h+1)
	{
		dp[i] = 100000000000000000 ;
	}
	dp[0] = 0 ;
	for(ll i = 1 ; i <= h ; i++)
	{
		fo(j , n)
		{
			if(i - v[j].first <= 0)
			{
				dp[i] = min(v[j].second , dp[i]) ;
			}
			else
			{
				dp[i] = min(dp[i - v[j].first] + v[j].second , dp[i]) ;
			}
		}
	}
	cout << dp[h] << endl ;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a,b,t,s;
int main(){
	cin>>a>>b>>t;
	int c=a;
	for(int i=1;i<=t;i++){
		if(i==c){
			s+=b;
			c+=a;	
		} 
	}
	cout<<s<<endl;
	return 0;
}


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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,x,t;
	cin>>n>>x>>t;
	ll a=ceil((float)n/x);
	a*=t;
	cout<<a;

	
	
	
	return 0;
}

Measured memory_bytes: 3632
n = int(input())
s = input()
 
r, b, g = 0, 0, 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    if s[i] == 'G':
        g += 1
    if s[i] == 'B':
        b += 1
ans = r * g * b
 
for i in range(n):
    for j in range(1, n // 2 + 1):
        if i + 2 * j >= n:
            break
        if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+j] != s[i+2*j]:
            ans -= 1
 
print(ans)

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

using namespace std;
const int maxn = 100100; // 字符串最大长度
const int sz = 1010;     // 字符集最大ASCII码

// 下面五个都是求后缀数组时基数排序用的
int cntA[maxn];   
int cntB[maxn];
int A[maxn];
int B[maxn];
int tsa[maxn];

int sa[maxn];     // sa[i]表示字典序第i小的后缀的起始位置
int rk[maxn];       // rk[i]表示第i个字符开始的后缀字典序排第几
int height[maxn];   // height[i]表示字典序排第i的后缀与排第i-1的后缀的最长公共前缀长度
char ch[maxn];      // 待处理字符串，从1到n

// 传入字符串长度,求sa[]，rk[],height[]
void solve(int n)
{
    for (int i = 0; i < sz; i ++) cntA[i] = 0;
    for (int i = 1; i <= n; i ++) cntA[ch[i]] ++;
    for (int i = 1; i < sz; i ++) cntA[i] += cntA[i - 1];
    for (int i = n; i; i --) sa[cntA[ch[i]] --] = i;
    rk[sa[1]] = 1;
    for (int i = 2; i <= n; i ++)
    {
        rk[sa[i]] = rk[sa[i - 1]];
        if (ch[sa[i]] != ch[sa[i - 1]]) rk[sa[i]] ++;
    }
    for (int l = 1; rk[sa[n]] < n; l <<= 1)
    {
        for (int i = 0; i <= n; i ++) cntA[i] = 0;
        for (int i = 0; i <= n; i ++) cntB[i] = 0;
        for (int i = 1; i <= n; i ++)
        {
            cntA[A[i] = rk[i]] ++;
            cntB[B[i] = (i + l <= n) ? rk[i + l] : 0] ++;
        }
        for (int i = 1; i <= n; i ++) cntB[i] += cntB[i - 1];
        for (int i = n; i; i --) tsa[cntB[B[i]] --] = i;
        for (int i = 1; i <= n; i ++) cntA[i] += cntA[i - 1];
        for (int i = n; i; i --) sa[cntA[A[tsa[i]]] --] = tsa[i];
        rk[sa[1]] = 1;
        for (int i = 2; i <= n; i ++)
        {
            rk[sa[i]] = rk[sa[i - 1]];
            if (A[sa[i]] != A[sa[i - 1]] || B[sa[i]] != B[sa[i - 1]]) rk[sa[i]] ++;
        }
    }
    for (int i = 1, j = 0; i <= n; i ++)
    {
        if (j) j --;
        while (ch[i + j] == ch[sa[rk[i] - 1] + j]) j ++;
        height[rk[i]] = j;
    }
}   

bool check(int n, int K)
{
    int minsa = 1e9, maxsa = -1e9;
    for(int i = 1; i <= n; i ++)
        if(height[i] < K)
        {
            minsa = sa[i];
            maxsa = sa[i];
        }
        else 
        {
            minsa = min(minsa,sa[i]);
            maxsa = max(maxsa,sa[i]);
            if(maxsa-minsa >= K)
                return true;
        }
    return false;
}

int main()
{
    #ifdef AFei
    freopen("in.txt", "r", stdin);
    #endif

    int n;
    scanf("%d%s", &n, ch+1);
    
    solve(n);

    int l = 0, r = n;
    int ans = 0;
    while (l <= r)
    {
        int k = l + ((r-l) >> 1);
        if(check(n, k))
        {
            ans = k;
            l = k+1;
        }
        else
        {
            r = k-1;
        }
    }

    cout << ans << endl;
    

    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string S;
    cin >> S;
    
    map<char, int> cnt;
    for (char c : S) {
        ++cnt[c];
    }
    if (cnt.size() > 2) {
        cout << "No" << endl;
        return 0;
    }
    for (auto p : cnt) {
        if (p.second != 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int d(int x,int y){
    return (x<y)?(y-x):(x-y);
}
int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    if((x<0&&y>0)||(x>0&&y<0))printf("%d",d(-x,y)+1);
    else if(x<y)printf("%d",d(x,y));
    else if(x==0||y==0)printf("%d",d(x,y)+1);
    else printf("%d",d(x,y)+2);
    return 0;
}

Measured memory_bytes: 128
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

tmp = attrs.shift
N = tmp[0]
M = tmp[1]
maxL = 0
minR = 10000000
attrs.each do |attr|
  maxL = attr[0] if attr[0] > maxL
  minR = attr[1] if attr[1] < minR
end

if minR >= maxL then
  puts (minR - maxL) + 1
else
  puts 0
end

Measured memory_bytes: 9724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextInt();
        long d = in.nextInt();
        long ans = 0;
        for (long i = 0; i < n; i++) {
            long x = in.nextInt();
            long y = in.nextInt();

            if (d * d >= x * x + y * y) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 59140
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    //length of string
    int N = sc.nextInt();
    String s= sc.next();
    String t=sc.next();
    String ans="";
    for(int i=0;i<N;i++) {
        ans+=String.valueOf(s.charAt(i)+String.valueOf(t.charAt(i)));

    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def io_generator():
	return input()

#+++++++++++++++++++

def ll2l(a_list):
	ret=[]
	for i, v in enumerate(a_list):
		if i == 0 or ret[-1][0] != v:
			ret.append([v,1])
		else: #if ret[-1][0] == v:
			ret[-1][1] += 1
	return ret
		

def main(io):
	a, b = map(int, io().split())
	end_pos=0
	ok='Possible'
	ng='Impossible'
	for i in range(a):
		l = list(io())[:b]
		rr=ll2l(l)
		#print(rr)
		if len(rr) == 0:
			return ng
		elif len(rr) >= 4:
			return ng
		elif len(rr)==1 and rr[0][0] == '.':
			return ng
		elif len(rr)==1:
			st=0
			end = rr[0][1]-1
		elif len(rr) == 2 and rr[0][0]=='.':
			st = rr[0][1]
			end = st + rr[1][1]-1
		elif len(rr) == 2 and rr[0][0]=='#':
			st = 0
			end = rr[0][1] - 1
		elif len(rr) == 3 and rr[0][0]=='#':
			return ng
		else:
			st=rr[0][1]
			end=st + rr[1][1]-1
		#print(st,end)
		if end_pos != st:
			return ng
		end_pos = end
		
	if end_pos==b-1:
		return ok
	return ng
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 3064
import math

MOD = 10 ** 9 + 7

def factorizec(n):
    fct = []
    b = 2
    e = 0
    while b * b <= n:
        while n % b == 0:
            n //= b
            e += 1
        if e > 0:
            fct.append((b, e))
        b += 1
        e = 0
    if n > 1:
        fct.append((n, 1))
    return fct

n = int(input())
fct = factorizec(math.factorial(n))
ans = 1
for i in fct:
    ans *= (i[1] + 1) % MOD
print(ans % MOD)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a) for(i=0;i<a;i++)
using namespace std;

int main(void) {
    int i,H,buf;
    vector<int> A;

    cin >> H;
    rep(i,H){
        cin >> buf;
        A.push_back(buf);
    }
    rep(i,H){
        cout << "node " << i+1 << ": key = " << A[i] << ", ";
        if(i > 0) cout << "parent key = " << A[(i+1)/2-1] << ", ";
        if((i+1)*2-1 < H) cout << "left key = " << A[(i+1)*2-1] << ", ";
        if(2*(i+1) < H) cout << "right key = " << A[2*(i+1)] << ", ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
void print_vec(vector<int> &vec){
    vector<int> cpvec = vec;
    for(int i=0;i<cpvec.size();i++){
        cout << cpvec.at(i);
    }
    cout << endl;
}
int main(){
    string S;
    cin >> S;
    queue<int> que;
    vector<int> sequence(S.size()+1,-1);
    //print_vec(sequence);
    for(int i=0;i<S.size();i++){//0の位置を探す.Sを走査
        if(i==0&&S.at(i)=='<'){
            que.push(i);
            sequence.at(i)=0;
        }
        if(i<S.size()-1&&S.at(i)=='>'&&S.at(i+1)=='<'){
            que.push(i+1);
            sequence.at(i+1)=0;
        }
        if(i==S.size()-1&&S.at(i)=='>'){
            que.push(i+1);
            sequence.at(i+1)=0;
        }
    }
    //print_vec(sequence);
    while(!que.empty()){
        //print_vec(sequence);
        int coodinate = que.front(); que.pop();
        if(coodinate-1>=0&&S.at(coodinate-1)=='>'){
            que.push(coodinate-1);
            sequence.at(coodinate-1) = sequence.at(coodinate) + 1;
        }
        if(coodinate<S.size()&&S.at(coodinate)=='<'){
            que.push(coodinate+1);
            sequence.at(coodinate+1) = sequence.at(coodinate) + 1;
        }
    }
    long long cnt = 0;
    for(int i=0;i<sequence.size();i++){
        cnt+=sequence.at(i);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6524
N = int(input())
S = str(input())
K = int(input())

swap_word = S[K-1]

ans = []
for i in range(N):
  if S[i] != swap_word:
    ans.append("*")
  else:
    ans.append(S[i])

ans_word = ""
for i in range(N):
  ans_word = ans_word + ans[i]

print(ans_word)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n+1);
    set<long> xx;
    long i;
    long m=0;
    long mm[2]={0};
    for(i=0; i<n+1; i++) {
        scanf("%ld", &a[i]);
        if(!xx.insert(a[i]).second) {
            m=a[i];
            mm[1]=i;
        }
    }
    for(i=0; i<n+1; i++) {
        if(m==a[i]) {
            mm[0]=i; break;
        }
    }
    long r = mm[1]-mm[0]-1;

    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    long k;
    for(k=1; k<=n+1; k++) {
        ll ans = comb(n-1, k);
        ans += comb(n-1, k-1)*2;
        ans %= MOD;
        if(k>0) ans+= MOD-comb(n-1-r, k-1);
        ans %= MOD;
        if(k>1) ans+= comb(n-1, k-2);
        ans %= MOD;

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

    return 0;
}


Measured memory_bytes: 11392
import sys

input = lambda: sys.stdin.readline()


def cin_int_list():
    return [int(x) for x in input().split()]


def cin_int_iter():
    return (int(x) for x in input().split())


def cin_int():
    return int(input())


def cout_int_iter(a):
    print(' '.join(map(str, a)))


def iota(n, start=0):
    return list(range(start, n))


def cin_digits_list():
    return [ord(x) - ord('0') for x in input()]


def main():
    a, b, c, k = cin_int_iter()

    ret = 0

    ret += min(a, k)
    k -= min(a, k)

    if k == 0:
        print(ret)
        return

    k -= min(b, k)

    if k == 0:
        print(ret)
        return

    ret -= min(c, k)
    k -= min(c, k)

    print(ret)


main()


Measured memory_bytes: 61888
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 

  int n; cin >> n;

  int res = ~(1 << 31);

  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    int lsb_distance = floor(log2(x & -x));
    res = min(res, lsb_distance);
  }

  cout << res << "\n";
}


Measured memory_bytes: 3700
#include<iostream>

int main() {
	char s[11];
	std::cin >> s;
	int arr[8];
	int j = 0;

	for (int i = 0; i < 10; i++) {
		if (s[i] != '/') { 
			arr[j] = s[i] - '0'; 
			j++;
		}
	}
	
	int val = arr[0];
	for (int i = 1; i < 8; i++) {
		val = val * 10 + arr[i];
	}

	if (val > 20190430)printf("TBD");
	else printf("Heisei");
	system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
  Cin(int, n);
  Cins(int, n, a);
  ll ans = 0;
  For(i, n) for(int j = i+1; j < n; j ++){
    ans += a[i]*a[j];
  }
  Cout(ans);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt, sum int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	for i := 1; i <= N; i++ {
		str := strconv.Itoa(i)
		if len(str)%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) < abs(a[j]) }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"os"
)

func process(in []string) (ret string) {
	count := 0
	for _, v := range in {
		var one, two int
		fmt.Sscanf(v, "%d %d", &one, &two)
		if one == two {
			count++
		} else {
			count = 0
		}
		if count == 3 {
			return "Yes"
		}
	}
	return "No"
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	sc := bufio.NewScanner(os.Stdin)
	in := make([]string, n)
	for i := 0; i < n; i++ {
		if sc.Scan() {
			in[i] = sc.Text()
		}
	}

	ret := process(in)
	fmt.Println(ret)

}


Measured memory_bytes: 1848
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
int n,l,a[100005];
signed main(){
	n=read(),l=read();int p,q=-1;int t=read(),tmp;
	for(register int i=2;i<=n;i++)tmp=read(),(t+tmp>q?p=i,q=t+tmp:0),t=tmp;
	if(q<l)return 0&puts("Impossible");
	puts("Possible");for(register int i=1;i<p-1;i++)printf("%d\n",i);for(register int i=n-1;i>=p-1;i--)printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;
ll N,h,n;
int main()
{
  cin>>N;
  for(ll h=1;h<=3500;h++)
    for(ll n=h;n<=3500;n++)
    {
      ll A=4*h*n-N*(h+n),B=1ll*N*h*n;
      //cout<<h<<" "<<n<<endl;
      //if(h==2 && n==2) cout<<A<<" "<<B<<endl;
      //cout<<A<<" "<<B<<endl;
	  if(A>0 && B%A==0){cout<<h<<" "<<n<<" "<<B/A<<endl; return 0;} 
	}
  return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int N, K;
string S;
void pro(string &T) {
        int cur = 0, dir = 0;
        while (0 <= cur && cur < N) {
                if (T[cur] == 'A') dir = 1 - dir, T[cur] = 'B';
                else T[cur] = 'A';
                if (dir == 0) cur++;
                else cur--;
        }
}

int main() {

        cin >> N >> K >> S;
        int n = N;

        int verify = 'A';
        for (int i = N - 1; i >= 0; i--) {
                if (S[i] == verify) {
                        verify = (int)'B' - verify + 'A';
                        n--;
                } else {
                        break;
                }
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
                char look = S[i];
                int val;
                if (i & 1) look = (int)'B' - look + 'A';
                if (look == 'A') val = 2;
                else val = 1;
                if (K <= cnt + val) {
                        int num = K - cnt;
                        string T;
                        for (int j = i; j < n; j++) {
                                if (i & 1) T += (int)'B' - S[j] + 'A';
                                else T += S[j];
                        }
                        while (T.size() < N) {
                                if ((N - (int)T.size()) & 1) T += 'A';
                                else T += 'B';
                        }
                        //cout << cnt << " " << val << endl;
                        if (num == 1) pro(T);
                        else { pro(T); pro(T); }
                        cout << T << endl;
                        return (0);
                }
                cnt += val;
        }
        K -= cnt;
        string T;
        while (T.size() < N) {
                if ((N - (int)T.size()) & 1) T += 'A';
                else T += 'B';
        }
        if (!(N & 1) || !(K & 1)) cout << T << endl;
        else {
                T[0] = (int)'B' - T[0] + 'A';
                cout << T << endl;
        }

    return (0);
}

Measured memory_bytes: 904
//
//  ALDS1_2_B.cpp
//  
//
//  Created by mk on 2015/11/23.
//
//

#include <stdio.h>
#include <iostream>
using namespace::std;

void selectionSort(int A[], int N){
    int flag = 0;
    int cnt = 0;
    int minj;
    for (int i=0; i<N; i++) {
        minj = i;
        flag = 0;
        for (int j=i; j<N; j++) {
            if (A[minj] > A[j]) {
                minj = j;
                flag = 1;
            }

        }
        if (flag)cnt++;
        
        swap(A[minj], A[i]);
    }
    

    
    for (int i = 0; i < N; i++) {
        cout << A[i];
        if(i != N-1){
            cout << " ";
        }
    }
    cout << endl;
    cout << cnt;
    cout << endl;
}


int main(int argc, const char * argv[]) {
    int n;
    int A[100];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    selectionSort(A, n);
    
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main () {
  int k, n;
  cin >> k >> n;
  int a[n];
  int b[n];
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  for (int j = 0; j < n; j++){
    if (j != n-1){
      b[j] = a[j+1] - a[j];
    }else{
      b[j] = k - (a[j] - a[0]);
    }
  }
  sort(b, b+n, greater<int>());
  cout << k - b[0] << endl;
  return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = Counter(A)
    cnt_common = cnt.most_common()
    ans = 0
    for i in range(len(cnt_common)):
        num, val = cnt_common[i]
        ans += val * (val - 1) // 2
    for i in A:
        c = cnt[i]
        print(ans - c * (c - 1) // 2 + (c-1) * (c-2) // 2 )

if __name__ == '__main__':
    main()

Measured memory_bytes: 29808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

const ll MOD = 1e9+7;
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];

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

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  int n, k;
  cin >> n >> k;

  COMinit();

  for (int i = 1; i <= k; i++) {
    cout << COM(n-k+1, i) * COM(k-1, i-1) % MOD << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

long long int gcd(long long int x, long long int y){
		long long int t;

		while(y!=0){
				t = x % y;
				x = y;
				y = t;
		}
	return x;
}

int main(int argc, char *argv[]){
		long long int a,b;

		while(scanf("%lld %lld",&a,&b) != EOF){
				printf("%lld %lld\n",gcd(a,b),a*b/gcd(a,b));
		}
		return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
*/



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


    ll N,K;
  cin>>N>>K;
  vector<ll> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  for(int i=0;i<N-K;i++){
    if(vec[i]<vec[i+K]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }

  
  
}




Measured memory_bytes: 4832