akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

struct Dice
{
	vi d;
	static const int top = 0, frt = 1, rit = 2, lft = 3, bck = 4, btm = 5;
	Dice(){
		rep(i, 6) d.pb(i + 1);
	}
	Dice(vi d):d(d){}
	Dice(int _d[]){
		rep(i, 6) d.pb(_d[i]);
	}
	void spin(int f1, int f2, int f3, int f4){
		int tmp = d[f1];
		d[f1] = d[f2];
		d[f2] = d[f3];
		d[f3] = d[f4];
		d[f4] = tmp;
	}
	void spinN(){
		spin(top, frt, btm, bck);
	}
	void spinS(){
		spin(top, bck, btm, frt);
	}
	void spinE(){
		spin(top, lft, btm, rit);
	}
	void spinW(){
		spin(top, rit, btm, lft);
	}
	void spinCW(){
		spin(frt, rit, bck, lft);
	}
	void spinCCW(){
		spin(frt, lft, bck, rit);
	}

	void spin(char c){	
		if(c == 'N') spinN();
		else if(c == 'S') spinS();
		else if(c == 'E') spinE();
		else if(c == 'W') spinW();	
	}
	void spin(string s){
		for(char c : s){
			spin(c);
		}
	}
	void spin(int t, int f){
		rep(i, 4){
			if(d[top] == t) break;
			spinN();
		}
		rep(i, 4){
			if(d[top] == t) break;
			spinE();
		}
		rep(i, 4){
			if(d[frt] == f) break;
			spinCW();
		}
	}
	void spinTop(int f){
		if(f == frt) spinN();
		else if(f == btm) rep(i, 2) spinN();
		else if(f == bck) spinS();
		else if(f == lft) spinE();
		else if(f == rit) spinW();
	}

	void spinSmall(){
		Dice tmp(d);
		rep(i, 6){
			if(tmp[top] < d[i]) continue;
			Dice d2(d);
			d2.spinTop(i);
			rep(j, 4){
				if(d2 < tmp) tmp.d = d2.d;
				d2.spinCW();
			}
		}
		d = tmp.d;
	}

	int operator[] (int n) const{
		return d[n];
	}
	bool operator == (const Dice& dice) const{
		rep(i, 6){
			if(d[i] != dice[i]) return false;
		}
		return true;
	}
	bool operator < (const Dice& dice) const{
		rep(i, 6) {
			if(d[i] != dice[i]) return d[i] < dice[i];
		}
		return false;
	}
};


int main(){
	int n;
	vi v(6);
	vector<Dice> dices;
	cin>>n;
	rep(i, n){
		rep(j, 6) cin>>v[j];
		dices.pb(Dice(v));
		dices[i].spinSmall();
	}
	sort(all(dices));
	bool f = true;
	rep(i, dices.size()-1){
		if(dices[i] == dices[i+1]){
			f =false;
			break;
		}
	}
	cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int N;
const int MAX_N = 100000;
vector<int> tree[MAX_N + 100];
vector<int> dis;

void dfs(int v,int depth = 0,int root = -1)
{
    dis[v] = depth;
    for(int u : tree[v])
    {
        if(u == root)continue;
        dfs(u,depth+1,v);
    }
}

vector<int> calc(int s)
{
    dis = vector<int>(N);
    dfs(s);
    return dis;
}

int main()
{
    cin >> N;
    int u,v;
    cin >> u >> v;
    u--;
    v--;
    for(int i = 0;i < N - 1;i++)
    {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> DisU = calc(u);
    vector<int> DisV = calc(v);
    int maxi = 0;
    for(int i = 0;i < N;i++)
    {
        if(DisU[i] < DisV[i])
            maxi = max(maxi,DisV[i]);
    }
    cout << maxi - 1 << '\n';
    return 0;
}

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);

int main() {
    fastio;

    int n;
    cin >> n;
    int minV = 1e8;
    int maxV = -1;
    FOR(i, 0, n) {
        int x;
        cin >> x;
        minV = min(minV, x);
        maxV = max(maxV, x);
    }
    cout << maxV-minV << "\n";
    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void solve(long A, long B, long C, long D){
	writeln(min(A, B) + min(C, D));
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
	auto input = stdin.byLine.map!split.joiner;

	long A;
	A = input.front.to!long;
	input.popFront;

	long B;
	B = input.front.to!long;
	input.popFront;

	long C;
	C = input.front.to!long;
	input.popFront;

	long D;
	D = input.front.to!long;
	input.popFront;

	solve(A, B, C, D);
	return 0;
}


Measured memory_bytes: 256
import sys

def dfs(hands, pair):
    hands.sort()

    if not hands:
        return True
    target = hands[0]
    # sequence
    if all(map(lambda x: x in hands, range(target, target + 3))):
        for i in range(target, target + 3):
            hands.remove(i)
        if dfs(hands, pair):
            return True
        for i in range(target, target + 3):
            hands.append(i)
    # triple
    if hands.count(target) >= 3:
        for i in range(3):
            hands.remove(target)
        if dfs(hands, pair):
            return True
        for i in range(3):
            hands.append(target)
    # pair
    if not pair and hands.count(target) >= 2:
        for i in range(2):
            hands.remove(target)
        if dfs(hands, True):
            return True
        for i in range(2):
            hands.append(target)
    return False

for line in filter(lambda line: line.strip(), sys.stdin.readlines()):
    result = []
    data = [int(ch) for ch in line.strip()]
    for num in filter(lambda x: data.count(x) < 4, range(1, 10)):
        data_cp = list(data)
        data_cp.append(num)
        data_cp.sort()
        if dfs(data_cp, False):
            result.append(num)
    if result:
        print " ".join(map(str, result))
    else:
        print 0

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

int main()
{
  char c; cin >> c;
  if (c == 'A') cout << 'T' << endl;
  if (c == 'T') cout << 'A' << endl;
  if (c == 'C') cout << 'G' << endl;
  if (c == 'G') cout << 'C' << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
struct arr
  {
   int aa,bb;
  }a[100010];
int n;
long long b[100010];
int cmp(arr x,arr y)
  {
   if (x.aa!=y.aa) return x.aa>y.aa;
   return x.bb<y.bb;
  }
signed main()
  {
   scanf("%lld",&n);
   for (int i=1;i<=n;i++)
     {
      scanf("%lld",&a[i].aa);
      a[i].bb=i;b[i]=0;
	 }
   sort(a+1,a+1+n,cmp);
   int maxa=1;int maxb=1;
   while (true)
     {
      while ((a[maxb].aa==a[maxa].aa) && (maxb<=n)) maxb=maxb+1;
      if (maxb>n) break;
      b[a[maxa].bb]+=(maxb-1)*(a[maxa].aa-a[maxb].aa);
      a[maxa].aa=a[maxb].aa;
	  if (a[maxa].bb>a[maxb].bb) maxa=maxb;
	 }
   b[a[maxa].bb]+=a[maxa].aa*n;
   for (int i=1;i<=n;i++) printf("%lld\n",b[i]);
   return 0;
  } 

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

int main(void){
 long N;
 cin>>N;
 long retval=0;
 for(long i=1;i<=N;i++){
   long n=N/i;
   retval+=i*n*(n+1)/2;
 }
 cout<<retval<<endl;
}


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

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int M, D;
	cin >> M >> D;

    int ans = 0;
    for (int i = 22; i <= D; i++) {
        int d1 = i % 10; if (d1 < 2) continue;
        int d10 = i / 10; if (d10 < 2) continue;
        if (d1 * d10 <= M) ans++;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int cnt4 = 0, cnt2 = 0;
    rep(i,n){
        ll x;
        cin >> x;
        if(x%4==0) cnt4++;
        else if(x%2==0) cnt2++;
    }
    if(cnt4*2+1>=n) cout << "Yes" << endl;
    else if(cnt4*2+cnt2>=n) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var K,S int

	fmt.Scan(&K,&S)

	cnt:=0

	for x:=0;x<=K;x++{

		for y:=0;y<=K;y++{

			z := S-x-y

			if 0<= z && z<=K{

				cnt++
			}
		}

	}

	fmt.Println(cnt)

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
typedef pair<lint, lint> P;

signed main(){
	lint N, sum_before = 0, sum_after = 0; cin >> N;
	vector<lint> a(3 * N);
	for(int i = 0; i < a.size(); i++) cin >> a[i];
	priority_queue<lint>  que_after;
	priority_queue<lint, vector<lint>, greater<lint> > que_before;
	vector<lint> before(N + 1, 0), after(N + 1, 0);

	for(int i = 0; i < N; i++) que_before.push(a[i]), sum_before += a[i];
	before[0] = sum_before;
	for(int x = 0; x < N; x++){
		que_before.push(a[N + x]); sum_before += a[N + x];
		sum_before -= que_before.top(); que_before.pop();
		before[x + 1] = sum_before;
	}

	for(int i = 2 * N; i < 3 * N; i++) que_after.push(a[i]), sum_after += a[i];
	after[0] = sum_after;
	for(int x = 0; x < N; x++){
		que_after.push(a[2 * N - x - 1]); sum_after += a[2 * N - x - 1];
		sum_after -= que_after.top(); que_after.pop();
		after[x + 1] = sum_after;
	}
	lint ans = -1e18;
	for(int i = 0; i <= N; i++) ans = max(ans, before[i] - after[N - i]);
	cout << ans << endl;
}

Measured memory_bytes: 6516
#include<stdio.h>
#ifdef DEBUG
#include<conio.h>
#endif // DEBUG


int main () {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif // DEBUG
    
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a < b && b < c) printf("Yes\n");
    else
    {
        printf("No\n");
    }

#ifdef DEBUG
    getch();
#endif // DEBUG
    return 0;
}




Measured memory_bytes: 2068
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, k; cin >> n >> k;
	vector<pi> v;
	rep(i, k){
		int a, b; cin >> a >> b;
		if(a > b) swap(a, b);
		v.emplace_back(a - 1, b - 1);
	}
	const int mod = 1e9 + 7;
	const int N = 2 * n;
	vector<vi> inner(N, vi(N)), inter(N, vi(N));
	vector<vi> dp(N, vi(N));
	vi count(N + 1);
	
	count[0] = 1;
	for(int i = 2; i <= N; i += 2) count[i] = count[i - 2] * (i - 1ll) % mod;
	
	rep(i, N) for(int j = i; j < N; j++){
		for(pi p : v){
			if(i <= p.first && p.second <= j) inner[i][j]++;
			if((i <= p.first && p.first <= j) != (i <= p.second && p.second <= j)) inter[i][j]++;
		}
	}
	
	ll ans = 0;
	
	for(int w = 1; w < N; w++) rep(i, N){
		int j = i + w;
		if(j >= N) break;
		if(inter[i][j]) continue;
		
		int f = w + 1 - 2 * inner[i][j];
		assert(0 <= f && f <= w + 1);
		
		dp[i][j] = count[f];
		if(!dp[i][j]) continue;
		
		//dbg(i, j, dp[i][j], inner[i][j]);
		
		for(int l = i + 1; l + 1 < j; l++){
			if(inter[l + 1][j]) continue;
			int fr = j - l - 2 * inner[l + 1][j];
			assert(0 <= fr && fr <= j - l);
			dp[i][j] = (dp[i][j] + mod - (ll)dp[i][l] * count[fr] % mod) % mod;
		}
		
		int frem = N - w - 1 - 2 * (k - inner[i][j]);
		assert(0 <= frem && frem <= N - w - 1);
		//dbg(i, j, dp[i][j], inner[i][j], frem);
		
		ans += dp[i][j] * (ll)count[frem] % mod;
	}
	cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 4608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<iterator>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#define lli long long int
#define mp make_pair
#define FLASH ios_base::sync_with_stdio(false); cin.tie(0)
#define PI  3.141592653589793
#define fo(i,n) for(lli i=0;i<(n);i++)
#define FO(i,x,n) for(lli i=(x);i<(n);i++)
#define pb push_back
#define FI first
#define SE second
#define vi vector<lli>
#define pi pair<lli,lli>
#define vii vector<pi >
#define Endl endl
#define ITA 200005
#define ROH 100005
using namespace std;
lli mod = 1e9 +7,test; 
lli max(lli a,lli b){return a>b?a:b;}
lli min(lli a,lli b){return a>b?b:a;}

lli gcd(lli a, lli b) { 
   if (b == 0) return a; 
   return gcd(b, a % b);  
} 

void solve(){

lli n;
cin>>n;
vi a(n);
fo(i,n){
  cin>>a[i];
}
vi dp(n,-1);
dp[0] = 0;
fo(i,n-1){
  if(i+1<n){
    if(dp[i+1]==-1){dp[i+1] = dp[i] + abs(a[i]-a[i+1]);}
    dp[i+1] = min(dp[i+1], dp[i] + abs(a[i] - a[i+1]));
  }
  if(i+2<n){
    if(dp[i+2]==-1){dp[i+2] = dp[i] + abs(a[i]-a[i+2]);}
    dp[i+2] = min(dp[i+2], dp[i] + abs(a[i] - a[i+2]));
  }
}
cout<<dp[n-1]<<endl;


}


int main(){
    FLASH;
    lli t =1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;

}





Measured memory_bytes: 1792
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b < 10) {
		cout << a + b << endl;
		return 0;
	}
	cout << "error" << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if(m == -1 && f == -1 && r == -1)break;
            if(m == -1 || f == -1 || (m + f) < 30)System.out.printf("F\n");
            else if((m + f) >= 80)System.out.printf("A\n");
            else if((m + f) >= 65 && (m + f) < 80)System.out.printf("B\n");
            else if(((m + f) >= 50 && (m + f) < 65) || ((m + f) >= 30 && (m + f) < 50 && r >= 50))System.out.printf("C\n");
            else if(((m + f) >= 30 && (m + f) < 50) || ((m + f) >= 30 && (m + f) < 50 && r < 50))System.out.printf("D\n");

        }
    }
}


Measured memory_bytes: 26264
import bisect
n = int(input())
*A, = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n - 1):
    x, y = map(int, input().split())
    G[x - 1].append(y - 1)
    G[y - 1].append(x - 1)
inf = 10**10
DP = [inf for i in range(n)]
L = [0 for i in range(n)]
Q = [(-1, 0, None)]
while Q:
    p, x, b = Q.pop()
    if x == -1:
        DP[p] = b
        continue
    i = bisect.bisect_left(DP, A[x])
    Q.append((i, -1, DP[i]))
    DP[i] = A[x]
    L[x] = bisect.bisect_left(DP, inf)
    for y in G[x]:
        if y != p:
            Q.append((x, y, None))
print(*L, sep='\n')


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

int main(){
  int n;
  string st;
  cin >> n;
  int a[4] = {0};
  for(int i=0;i<n;i++){
    cin >> st;
    if(st == "AC"){
      a[0]++;
    }
    else if(st == "WA"){
      a[1]++;
    }
    else if(st == "TLE"){
      a[2]++;
    }
    else{
      a[3]++;
    }
  }
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
  return 0;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(10**7)

def no_of_paths(i, j, arr, dp):

  if dp[i][j] is not None:
    return dp[i][j]

  if arr[i][j] == '#':
    return 0

  if i == 0 and j == 0:
    return dp[i][j]

  count = 0

  if i-1 >= 0:
    count  += no_of_paths(i-1, j, arr, dp) % (10**9 + 7)
  if j-1 >= 0:
    count += no_of_paths(i, j-1, arr, dp) % (10**9 + 7)

  dp[i][j] = count % (10**9 + 7)
  return dp[i][j]

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

data = []
for _ in range(H):
  data.append(input())

dp = [[None]*W for _ in range(H)]
dp[0][0] = 1
print(no_of_paths(H-1, W-1, data, dp))

Measured memory_bytes: 44768
N = int(input())

S = [''.join(sorted(input())) for _ in range(N)]

table = {}

ans = 0
for s in S:
    if s in table:
        table[s] += 1
    else:
        table[s] = 1

for k in table:
    ans += table[k] * (table[k] - 1)

ans //= 2
print(ans)

Measured memory_bytes: 23620
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

class UnionFind
{
public:
    vector<int> par;
    vector<int> sz;

    UnionFind(int N){
        par = vector<int>(N);
        REP(i, N) par[i] = i;
        sz = vector<int>(N, 1);
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(sz[x] < sz[y]) swap(x, y);

        par[y] = x;
        sz[x] += sz[y];
    }

    bool is_union(int x, int y){
        x = find(x);
        y = find(y);
        return x == y;
    }

    int union_size(int x){
        return sz[find(x)];
    }

};


signed main(){

    int N; cin >> N;
    vec x(N), y(N);
    static int M = 100000;
    mat m(M);
    UnionFind UF(M);
    REP(i, N){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        m[x[i]].pb(y[i]);
    }
    REP(i, M)if(SZ(m[i])){
        for(int v: m[i]) UF.unite(m[i][0], v); 
    }
    int ans = 0;
    REP(i, M)if(SZ(m[i])) ans += UF.union_size(m[i][0]);
    ans -= N;
    Out(ans);

    return 0;
}


Measured memory_bytes: 7552
import math
while 1:
  n = input()
  if n==0: break
  x = []
  for _ in [0]*n:
    i,h,w = map(int, raw_input().split())
    x.append([i,abs(w/math.pow((h/100.0),2)-22)])
  x = sorted(x, key = lambda a: (a[1], a[0]))
  print x[0][0]

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  string ans;
  rep(i,n){
    ans += 'x';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4){
        if(s[i] == '+') ans++;
        if(s[i] == '-') ans--;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;
int tab[MAXN];

int main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int a,n;
    cin >> n >> a;
    n%=500;
    cout << (n<=a ? "Yes" : "No");
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

void main(){
    foreach(i; 0..readln.chomp.to!int){
        int count;
        bool[string] memo;
        string input = readln.chomp;
        foreach(j; 1..input.length){
            auto current = input;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = (input[0..j] ~ input[j..$].dup.reverse).idup;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = (input[0..j].dup.reverse ~ input[j..$]).idup;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = (input[0..j].dup.reverse ~ input[j..$].dup.reverse).idup;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = input[j..$] ~ input[0..j];
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = (input[j..$] ~ input[0..j].dup.reverse).idup;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = (input[j..$].dup.reverse ~ input[0..j]).idup;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
            current = (input[j..$].dup.reverse ~ input[0..j].dup.reverse).idup;
            if(!(current in memo)){
                ++count;
                memo[current] = true;
            }
        }
        count.writeln;
    }
}

Measured memory_bytes: 1988
fn main() {
    let mut s: Vec<char> = readln();
    s[3] = '8';
    let mut ans = String::new();
    ans.extend(s.iter()); // s.iter().collect::<String>() (after 1.17)
    println!("{}", ans);
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 4352
function main(input) {
  const args = input.split('\n')
  const src = args[0]
  const target = args[1]
  const result = String(src).split('').reverse().join('') === String(target) ? 'YES' : 'NO';

  console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22084
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}
template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
double dist(pair<int,int> p1, pair<int,int> p2){
    double ans = (p1.first - p2.first) * ( p1.first - p2.first) + (p1.second -p2.second) * (p1.second - p2.second);
    return sqrt(ans);
}
void solve(){
    string s;
    read(s);
    int count1(0), count0(0);
    REP(i, s.size()){
        if( s[i] == '1'){
            count1++;
        }else{
            count0++;
        }
    }
    cout << 2 * min(count1, count0) << endl;
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3808
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    int cnt = 0;

    for (int i = 1; i <= N; i++) {
      int tmp = i;
      int tmpCnt = 0;
      while (true) {
        if (tmp % 2 == 0) {
          tmp = tmp / 2;
          tmpCnt++;
        } else {
          break;
        }
      }

      if (Math.max(cnt, tmpCnt) == tmpCnt) {
        ans = i;
        cnt = tmpCnt;
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
from collections import defaultdict, deque

#入力受け取り
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
outE = defaultdict(list)
inE = defaultdict(int)

for i in range(N + M - 1):
	u, v = getlist()
	outE[u - 1].append(v - 1)
	inE[v - 1] += 1

Q = deque()
for i in range(N):
	if inE[i] == 0:
		Q.append(i)
top = []
while Q:
	v1 = Q.popleft()
	top.append(v1)
	for v2 in outE[v1]:
		inE[v2] -= 1
		if inE[v2] == 0:
			Q.append(v2)

parent = [0] * N
for i in top:
	for j in outE[i]:
		parent[j] = i + 1
for i in range(N):
	print(parent[i])

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


int main(){
    int n; cin >> n;
    int a[n+1]={0};

    int x;
    for(int i = 0; i < n-1; i++){
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  print(N * (N - 1) / 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[100005],weight[100005],dp[105][100005],n,w;


ll dfs(ll x,ll c)
{
	ll ans1=0,ans2=0;
	if(x==n+1)
		return 0;
	if(dp[x][c]!=-1)
		return dp[x][c];
	if(c+weight[x]<=w)
		ans1=arr[x]+dfs(x+1,c+weight[x]);
	ans2=dfs(x+1,c);
	dp[x][c]=max(ans1,ans2);
	return dp[x][c];
}


int main()
{
	boost
	cin>>n>>w;
	memset(dp,-1,sizeof(dp));
	for(ll i=1;i<=n;i++)
		cin>>weight[i]>>arr[i];
	ll ans1=arr[1]+dfs(2,weight[1]);
	ll ans2=dfs(2,0);
	cout<<max(ans1,ans2);
	return 0;
}


Measured memory_bytes: 82304
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

int main(void){
	int N;
	int A[100002],B[100001];
	long money=0;
	scanf("%d", &N);
	A[0] = 0;
	A[N+1] = 0;
	for(int i=1;i<=N;i++){
		scanf("%d",&A[i]);
		B[i-1] = abs(A[i] - A[i-1]);
		money += (long)B[i-1]; 
	}
	B[N] = abs(A[N+1] - A[N]); 

	money += (long)B[N];
	for(int i = 0; i< N;i++){
		printf("%ld\n",money - (long)B[i] - (long)B[i+1] + (long)abs(A[i+2] - A[i]));
	}
	fflush(stdout);

	return 0;
}

Measured memory_bytes: 2048
#include <cstdio>
#include <cstring>
#include <utility>
#include <stack>
#include <vector>
#include <algorithm>

int main(void)
{
  char s[20001];
  scanf("%s", s);
  std::stack<int> st;
  std::stack<std::pair<int, int> > st_;
  int len = strlen(s), ans = 0;
  for(int i = 0; i < len; i++) {
    if(s[i] == '\\') {
      st.push(i);
    } else if(s[i] == '/' && !st.empty()) {
      ans = i - st.top();
      while(!st_.empty() && st_.top().first > st.top()) {
        ans += st_.top().second;
        st_.pop();
      }
      st_.push(std::make_pair(st.top(), ans));
      st.pop();
    }
  }
  int sum = 0;
  std::vector<int> a;
  for(int i = 0, i_len = st_.size(); i != i_len; i++) {
    sum += st_.top().second;
    a.push_back(st_.top().second);
    st_.pop();
  }
  printf("%d\n%d%c", sum, a.size(), a.size() ? ' ' : '\n');
  std::reverse(a.begin(), a.end());
  for(int i = 0, i_len = a.size(); i != i_len; i++) {
    printf("%d%c", a[i], (i + 1 == i_len ? '\n' : ' '));
  }
  return 0;
}


Measured memory_bytes: 2880
from sys import stdin, setrecursionlimit
from collections import defaultdict

setrecursionlimit(10 ** 9)


def input():
    return stdin.readline().strip()


def binary_search(n):
    left, right = 0, 10 ** 10
    while right - left > 1:
        mid = (left + right) // 2
        if mid ** 5 <= n:
            left = mid
        else:
            right = mid

    return left


X = int(input())
for i in range(10 ** 1000):
    B = i
    A5 = X + B ** 5
    n = binary_search(A5)
    if n ** 5 == A5:
        print(n, B)
        break

    B = -i
    A5 = X + B ** 5
    if A5 >= 0:
        n = binary_search(A5)
    else:
        n = -binary_search(-A5)
    if n ** 5 == A5:
        print(n, B)
        break


Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
long long dp[105][100005];
long long knapsack(int wt[],int val[],int W,int n)
{
	if(n==0 || W==0)
  		return 0;
  
  if(dp[n][W]!=-1)
    return dp[n][W];
  
  if(wt[n]<=W)
    return dp[n][W]=max((val[n]+knapsack(wt,val,W-wt[n],n-1)),(knapsack(wt,val,W,n-1)));
  else
     return knapsack(wt,val,W,n-1);
                        
 }

int main()
{
  int n,W;
  cin>>n>>W;
  int val[n+1],wt[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>wt[i]>>val[i];
  }
  memset(dp,-1,sizeof dp);
  cout<<knapsack(wt,val,W,n);
  
  return 0;
}

Measured memory_bytes: 85600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define PI 3.1415926535897932384626
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define forn(i,n) for(int i=0;i<n;i++)
int main()
{
       boost;
       ll a,b,c,x,y,cost=0;
       cin>>a>>b>>c>>x>>y;
       while(x && y)
       {
             ll p=a+b;
             ll q=2*c;
             cost+=min(p,q);
             x--;
             y--;
       }
       if(x || y)
       {
             if(x)
             {
                   while(x)
                   {
                         cost+=min(a,2*c);
                         x--;
                   }
             }
             if(y)
             {
                   while(y)
                   {
                         cost+=min(b,2*c);
                         y--;
                   }
             }
       }
       cout<<cost<<endl;
}     


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

#define ll long long

#define pii std::pair<int,int>
#define mp std::make_pair
#define fi first
#define se second

#define SZ(x) (int)(x).size()
#define pb push_back

template<class T>inline void chkmax(T &x, const T &y) {if(x < y) x = y;}
template<class T>inline void chkmin(T &x, const T &y) {if(x > y) x = y;}

template<class T>
inline void read(T &x) {
    char c;int f = 1;x = 0;
    while(((c=getchar()) < '0' || c > '9') && c != '-');
    if(c == '-') f = -1;else x = c-'0';
    while((c=getchar()) >= '0' && c <= '9') x = x*10+c-'0';
    x *= f;
}
static int outn;
static char out[(int)2e7];
template<class T>
inline void write(T x) {
    if(x < 0) out[outn++] = '-', x = -x;
    if(x) {
        static int tmpn;
        static char tmp[20];
        tmpn = 0;
        while(x) tmp[tmpn++] = x%10+'0', x /= 10;
        while(tmpn) out[outn++] = tmp[--tmpn];
    }
    else out[outn++] = '0';
}

const int MOD = 1e9 + 7;

int n;

int main() {
	read(n);
	int ans = 1;
	for(int i = 1, k = 0, x; i <= n; ++i) {
		read(x);
		if(x >= 2 * k + 1) ans = (ll)ans * (++k) % MOD;
		else ans = (ll)ans * (k + 1) % MOD;
	}
	std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: i64,
    }

    let mut burger_size = vec![0i64; 51];
    let mut patty_count = vec![0i64; 51];
    burger_size[0] = 1;
    patty_count[0] = 1;

    for i in 1..=50 {
        burger_size[i] = burger_size[i - 1] * 2 + 3;
        patty_count[i] = patty_count[i - 1] * 2 + 1;
    }

    struct Ctx {
        burger_size: Vec<i64>,
        patty_count: Vec<i64>,
    }

    fn eat(e: &Ctx, n: usize, rem: i64) -> i64 {
        if n == 0 {
            1
        } else {
            let Ctx { burger_size, patty_count } = e;
            if rem <= 1 {
                0
            } else if rem <= 1 + burger_size[n - 1] {
                eat(e, n - 1, rem - 1)
            } else if rem == 1 + burger_size[n - 1] + 1 {
                patty_count[n - 1] + 1
            } else if rem <= 1 + burger_size[n - 1] + 1 + burger_size[n - 1] {
                patty_count[n - 1] + 1 + eat(e, n - 1, rem - 1 - burger_size[n - 1] - 1)
            } else {
                patty_count[n]
            }
        }
    }

    println!("{}", eat(&Ctx{ burger_size, patty_count }, n, m));
}


Measured memory_bytes: 2160
#include <cstdio>

int main(void) {
    long long int a, b, x, ans=0;
    long long int ax, bx;
    scanf("%lld %lld %lld", &a, &b, &x);
    ax=(a%x)?a/x+1:a/x;
    bx=b/x;
    ans=bx-ax+1;
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
    char x,y,z,b;
    cin>>x>>y>>z>>b;
    if (x==y||y==z)
        cout <<"Bad";
        else if (z==b)
          cout <<"Bad";
    else
        cout<<"Good";




    return 0;
}


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

class E
{
	static void Main()
	{
		var s = Console.ReadLine();
		var n = s.Length;

		if (s[0] != '1' || s[^1] != '0' || Enumerable.Range(0, n / 2).Any(i => s[i] != s[^(i + 2)])) { Console.WriteLine(-1); return; }

		var dp = new int[n];
		for (int t = n, i = 1; i < n; dp[i] = t, t = s[i - 1] == '1' ? i : t, i++) ;
		Console.WriteLine(string.Join("\n", dp.Select((x, i) => $"{x} {i}").Skip(1)));
	}
}


Measured memory_bytes: 27652
a=map(int,raw_input().split())
n=int(raw_input())
b=[4,2,1,0.5]
c = zip(a,b)
c = sorted(c,key=lambda x : x[0]*x[1])
res = 0
if c[0][1] < 0.7 :
    res = (n//2)*c[0][0] + ((n%2)*c[1][1])*c[1][0]
else :
    res = n*c[0][1]*c[0][0]
print res

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    char a, b;
    cin >> a >> b;
    if(a > b)
        cout << ">" << endl;
    else if(a == b)
        cout << "=" << endl;
    else
       cout << "<" << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    long long H = 0 , W = 0 , MOD = 1000000007 ;
    cin >> H >> W ;
    char grid[H+1][W+1] ;
    long long ways[H+1][W+1] ;
    for(long long i = 1 ; i <= H ; i++)
        for(long long j = 1 ; j <= W ; j++)
            cin >> grid[i][j] , ways[i][j] = 0 ;
    for(long long i = 1 ; i <= H ; i++){
        if(grid[i][1] == '#') break ;
        ways[i][1] = 1 ;
    }
    for(long long i = 1 ; i <= W ; i++){
        if(grid[1][i] == '#') break ;
        ways[1][i] = 1 ;
    }
    for(long long i = 2 ; i <= H ; i++)
        for(long long j = 2 ; j <= W ; j++)
            if(grid[i][j] != '#')
                ways[i][j] = (ways[i-1][j] % MOD + ways[i][j-1] % MOD) % MOD ;
    cout << ways[H][W] ;
}

Measured memory_bytes: 12372
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <iomanip>
#include <tuple>
#include <functional>
#include <map> 
#include <numeric> 
#include <math.h>
 
using namespace std;
 
 
#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define vp vector<pi>
#define msa(A, a, n) memset(A, a, n*sizeof(A))
#define msv(A, a) fill(A.begin(), A.end(), a);
#define msc(A, n) memset(A, '\0', n)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#define pern(i, b) per(i, b - 1, 0)
#define repn(i, b) rep(i, 0, b)
#define repe(i, a, b) for(int i = a; i <= b; i++)
#define repen(i, b) repe(i, 1, b)
#define fast ios_base::sync_with_stdio();cin.tie(0);
#define endl "\n"
//#define MYDEBUG 
 
void my_return(int code)
{
#ifdef MYDEBUG
	std::cout << "\n\nTime = " << fixed << std::setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}
 
int main()
{
	fast
#ifdef MYDEBUG
		freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 
	int n;
	cin >> n;
	cout << ((n >= 30) ? "Yes" : "No");
 
	my_return(0);
 
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

template< class T >
struct BinaryIndexedTree
{
    vector< T > data;

    BinaryIndexedTree(int sz)
    {
        data.assign(++sz, 0);
    }

    T sum(int k)
    {
        T ret = 0;
        for(++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x)
    {
        for(++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

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

    int2(n, m);
    vector<vp> data(m+1);
    rep(i, n) {
        int2(a, b);
        data[b-a+1].pb({a, b});
    }

    BinaryIndexedTree<int> bit(m+2);
    int sum = n;
    Rep(i, m+1) {
        rep(j, data[i].size()) {
            bit.add(data[i][j].fir, 1);
            bit.add(data[i][j].sec+1, -1);
        }
        sum -= data[i].size();
        int ret = sum;
        for (int j = i; j <= m; j += i) {
            ret += bit.sum(j);
        }
        std::cout << ret << std::endl;
    }

    return 0;
}



Measured memory_bytes: 11136
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */
/* include {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;
/* }}} */

// #define int long long

/* cpp template {{{ */
/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

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

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

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

  for (int n; cin >> n, n;){
    vi a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    RREP(i, a.size() - 2) ans += a[i];
    print(ans / (a.size() - 2));
  }

  return (0);
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,cnt0=0,prod=1,flag=0;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            cnt0++;
        }
    }
    if(n%2==1)
    {
        if(cnt0!=1)
        {
            cout<<0;
            flag=1;
        }
        else
        {
            sort(a,a+n);
            for(ll i=1;i<n;i=i+2)
            {
                if(a[i]==a[i+1])
                {
                    prod=(prod*2)%1000000007;
                }
                else
                {
                    cout<<0;
                    flag=1;
                    break;
                }
            }
        }
    }
    else
    {
        if(cnt0>0)
        {
            cout<<0;
            flag=1;
        }
        else
        {
            sort(a,a+n);
            for(int i=0;i<n;i=i+2)
            {
                if(a[i]==a[i+1])
                {
                    prod=(prod*2)%1000000007;
                }
                else
                {
                    cout<<0;
                    flag=1;
                    break;
                }
            }
        }
    }
    if(flag==0)
    {
    cout<<prod;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l;
  cin >> n >> l;
  priority_queue<string, vector<string>, greater<string> > pq;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    pq.push(s);
  }
  string ans;
  for(int i=0; i<n; i++){
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int A, B;

    scanf("%d %d", &A, &B);

    if((A >= 1 && A <= 8) && (B >= 1 && B    <= 8))
    {
        printf("Yay!\n");
    }
    else
    {
        printf(":(\n");
    }

    return 0;
}

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

void sort(int A[],int n){
	int tmp;
	int count=0;
	for(int i=0;i<(n-1);i++){
		for(int j=(n-1);j>i;j--){
			if(A[j-1]>A[j]){
				count++;
				tmp=A[j-1];
				A[j-1]=A[j];
				A[j]=tmp;
			}
		}
	}

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

int main(){
    int n;
	int *A;

	scanf("%d",&n);
	A=(int*)malloc(sizeof(int)*n);

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

	sort(A,n);


	
	return 0;
}


Measured memory_bytes: 2104