akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <cmath>
using namespace std;

typedef complex<double> P;


struct coninfo{
	int rnum, cnum, idx;
	double arg;

	coninfo(int cn): rnum(-1), cnum(cn), idx(-1), arg(0.0) {}

	bool operator< (const coninfo &c) const{
		return arg < c.arg;
	}
};

template <class T>
int nextindex(int i, T &v){
	int n = v.size();
	return i + 1 == n ? 0 : i + 1;
}

bool cmpreal(const P &a, const P &b){
	return real(a) < real(b);
}

vector<vector<coninfo> > cls;
int room;

void detroom(int c, int idx){
	while(1){
		int nxtc = cls[c][idx].cnum;
		int nxti = nextindex(cls[c][idx].idx, cls[nxtc]);
		if(cls[nxtc][nxti].rnum != -1){
			break;
		}
		cls[nxtc][nxti].rnum = room;

		c = nxtc;
		idx = nxti;
	}

	++room;
}

int solve(int C, int W){
	vector<P> cpos(C);

	cls.assign(C, vector<coninfo>());
	room = 0;

	int x, y, s, t;
	for(int i = 0; i < C; ++i){
		scanf("%d%d", &x, &y);
		cpos[i] = P(x, y);
	}
	for(int i = 0; i < W; ++i){
		scanf("%d%d", &s, &t);
		cls[s-1].push_back(coninfo(t-1));
		cls[t-1].push_back(coninfo(s-1));
	}

	for(int i = 0; i < C; ++i){
		for(int j = 0; j < cls[i].size(); ++j){
			cls[i][j].arg = arg(cpos[cls[i][j].cnum] - cpos[i]);
		}
		sort(cls[i].begin(), cls[i].end());
	}

	for(int i = 0; i < C; ++i){
		for(int j = 0; j < cls[i].size(); ++j){
			int k;
			for(k = 0; cls[cls[i][j].cnum][k].cnum != i; ++k);
			cls[i][j].idx = k;
		}
	}

	for(int i = 0; i < C; ++i){
		for(int j = 0; j < cls[i].size(); ++j){
			if(cls[i][j].rnum == -1){
				detroom(i, j);
			}
		}
	}

	vector<vector<char> > G(room, vector<char>(room));
	for(int i = 0; i < C; ++i){
		int k = cls[i].size() - 1;
		for(int j = 0; j < cls[i].size(); ++j){
			int a = cls[i][k].rnum;
			int b = cls[i][j].rnum;

			G[a][b] = G[b][a] = 1;
			k = j;
		}
	}

	int minidx = min_element(cpos.begin(), cpos.end(), cmpreal) - cpos.begin();
	int out = cls[minidx][0].rnum;

	vector<int> visit(room, -1);
	queue<int> q;
	q.push(out);
	visit[out] = 0;
	while(!q.empty()){
		for(int i = 0; i < room; ++i){
			if(G[q.front()][i] && visit[i] == -1){
				visit[i] = visit[q.front()] + 1;
				q.push(i);
			}
		}
		q.pop();
	}

	return *max_element(visit.begin(), visit.end());
}

int main(){
	int c, w;
	while(scanf("%d%d", &c, &w), c){
		printf("%d\n", solve(c, w));
	}
}

Measured memory_bytes: 1152
use itertools::izip;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        _n: usize,
        s: String,
        t: String,
    }

    let mut ans = "".to_string();

    for (s, t) in izip!(s.chars(), t.chars()) {
        ans.push(s);
        ans.push(t);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2112
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val ns @ Array(a, b, c) = input.nextLine().split(" ").map(_.toInt)
      if (ns.max == a)
        println(a * 10 + b + c)
      else if (ns.max == b)
        println(a + b * 10 + c)
      else
        println(a + b + c * 10)
    }

  }

}


Measured memory_bytes: 25544
#include <cstdio>
#include <algorithm>
#define LL long long 
using namespace std;

const LL p=1e9+7;
LL n,a,b,ans;

long long pow(long long x,long long y){
    if (y==0) return 1;
    long long z=pow(x,y/2)%p;
    if (y%2==0) return z*z%p;
    return z*z%p*x%p;
}

long long ni(long long x,long long p){
    return pow(x,p-2);
}

long long c(int n,int m,int p){
    long long x=1,y=1;
    for (int i=n;i>=n-m+1;i--) x=x*i%p;
    for (int i=1;i<=m;i++) y=y*i%p;
    return x*ni(y,p)%p;
}

signed main(void){
	scanf("%lld %lld %lld",&n,&a,&b);
	ans=pow(2,n)-1;
	ans+=2*p;
	ans-=c(n,a,p);
	ans-=c(n,b,p);
	printf("%lld\n",ans%p);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

    ull a[n];
    rep(i, n) {
        cin >> a[i];
    }

    ull count = 0;
    rep(i, n) {
        while (a[i]%2 == 0)
        {
            count++;
            a[i] /= 2;
        }
        // cout << count << endl;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 384
local n = io.read("*n")
local t = {}
local z = 0
for i = 1, n do
  t[i] = io.read("*n")
  z = z ~ t[i]
end
local r = {}
for i = 1, n do
  r[i] = z ~ t[i]
end
print(table.concat(r, " "))


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

int main() {
  
  int n;
  cin >> n;
  
  vector<int> x(n);
  vector<int> y(n);
  
  for (int i=0; i<n; i++) {
      cin >> x.at(i);
  }
  for (int i=0; i<n; i++) {
      cin >> y.at(i);
  }
  
  // p = 1
  double D1=0;
  for (int i=0; i<n; i++) {
      int abs;
      abs = x.at(i) - y.at(i);
      if (abs < 0) abs = -abs;
      D1 += abs;
  }
  
  // p = 2
  double D2=0;
  double para2=0;
  for (int i=0; i<n; i++) {
      int dif;
      dif = x.at(i) - y.at(i);
      para2 += dif*dif;
  }
  D2 = sqrt(para2);
  
  // p = 3
  double D3=0;
  double para3=0;
  for (int i=0; i<n; i++) {
      int abs=0;
      abs = x.at(i) - y.at(i);
      if(abs<0) abs = -abs;
      para3 += abs*abs*abs;
  }
  D3 = pow(para3, 1.00/3);
  
  // p = \infty
  double Di=0;
  double max = 0;
  for (int i=0; i<n; i++) {
      int abs;
      abs = x.at(i) - y.at(i);
      if (abs < 0) abs = -abs;
      if (max < abs) max = abs;
  }
  Di = max;
  
  printf("%f\n%f\n%f\n%f\n", D1, D2, D3, Di);
  
  return 0;
}




Measured memory_bytes: 3356
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	int D;
	void ans() {
		cin >> D;
		D -= 25;
		cout << "Christmas ";
		REP(i, -D) {
			cout << "Eve";
			if (i < -D - 1) cout << " ";
		}
		cout << "\n";
	}
};

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

	question q;
	q.ans();

	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    k = getN()
    al = {(7 % k): 1}
    mo = 7
    for i in range(k + 1):
        if mo % k == 0:
            print(i + 1)
            return
        mo = mo * 10 + 7
        mo %= k
        # print(mo, al)
        if mo in al:
            print(-1)
            return
        al[mo] = 1


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

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

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    ll H[200000];
    ll A[200000];
    ll B[200000];
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
    {
        cin >> H[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
    }
    int ans[200000] = {};
    for (int i = 0; i < M; i++)
    {
        if (H[A[i]] > H[B[i]])
        {
            ans[B[i]]++;
        }
        else if (H[A[i]] < H[B[i]])
        {
            ans[A[i]]++;
        }
        else
        {
            ans[A[i]]++;
            ans[B[i]]++;
        }
    }
    ll sum = 0;
    for (int i = 1; i <= N; i++)
    {
        if (ans[i] == 0)
        {
            sum++;
        }
    }
    cout << sum << endl;
}

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

int main() {
  // N 乗客の人数
  // C バスの定員
  // K バスを待てる時間
  int N, C, K;
  cin >> N >> C >> K;

  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }

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

  int ans = 0;
  int departure_time = 0;
  int num_of_passengers = 0;
  // O(N)
  for (int i = 0; i < N; i++) {
    // 乗客を1人ピックアップ
    int arrived_time = T.at(i);
    num_of_passengers++;
    // 一人目の乗客の場合、この乗客が最大限待てる時間が、バスの出発時間となる
    if (num_of_passengers == 1) {
      departure_time = arrived_time + K;
    }

    // 最後の乗客の場合はバスを発車する
    if (i == (N - 1)) {
      ans++;
      continue;
    }

    // バスの乗客が定員に到達した場合は、バスを発車する
    if (num_of_passengers == C) {
      num_of_passengers = 0;
      ans++;
      continue;
    }

    // 次のバスの乗客が、バスの出発時刻に間に合わない場合は、バスを発車する
    if (T.at(i + 1) > departure_time) {
      num_of_passengers = 0;
      ans++;
      continue;
    }
  }

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


Measured memory_bytes: 640
N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] # 万札、五千円札、千円札の枚数の2重リスト

def skip_search(rest_money, rest_n_osatsu):  # 明らかに無理な場合、処理をスキップ
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

def is_answer(n_10000, n_5000, n_1000): # 正答ならばそれを出力して終了
    if n_10000 + n_5000 + n_1000 == N_n_osatsu and n_10000*10000 + n_5000*5000 + n_1000*1000 == Y_sum_money:
        print(n_10000, n_5000, n_1000)
        exit()

for n_10000 in range(min(Y_sum_money//10000, N_n_osatsu)+1): # 万札枚数。0枚からスタート
    is_answer(n_10000, 0, 0)
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    for n_5000 in range(min(rest_money//5000, rest_n_osatsu)+1): # 万札枚数決定後に5000円の枚数を探索。5000円0枚からスタート
        is_answer(n_10000, n_5000, 0)
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = rest_money//1000
        is_answer(n_10000, n_5000, n_1000)

print("-1 -1 -1")

Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, Y = map(int, input().split())

    result = [-1, -1, -1]
    for i in range(N + 1):
        for j in range(N - i + 1):
            k = (N - i - j)
            yen = i * 10**4 + j * 5 * 10**3 + k * 10**3
            if Y == yen:
                result = [i, j, k]
    print(*result)


if __name__ == "__main__":
    main()


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

void call(int n){
  for(int i=1;i<=n;i++){
    int x=i;
    if(x%3==0){
      cout << " " << i;
      continue;
    }
    while(x){
      if(x%10==3){
        cout << " " << i;
        break;
      }
      x/=10;
    }
  }

  cout << endl;
}

int main(){
  int v;
  cin>>v;
  call(v);
}


Measured memory_bytes: 3080
#include<iostream>
#include<math.h>
#include<cmath>
#include <iomanip>
int main(void) {
	double a, b, c, d;
	std::cin >> a >> b >> c >> d;
	std::cout << std::fixed
		<< std::setprecision(9) <<
		std::sqrt((c - a)*(c - a) + (d - b)*(d - b))<<std::endl;
	//system("pause");
	return 0;
}

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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


int main() {
  lint n; cin >> n;
  vector<lint> a(n); for(lint i=0;i<n;i++) { cin >> a[i]; }

  lint sum=0;
  map<lint,lint> mp;
  for(lint i=0;i<n;i++) { mp[a[i]]++; }
  for(map<lint,lint>::iterator i=mp.begin();i!=mp.end();i++) { sum += i->second*(i->second-1)/2; }

  for(lint i=0;i<n;i++) { cout << sum-(mp[a[i]]-1) << endl; }

  return 0;
}

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

vector<long long> divisor(long long n) {
  vector< long long > ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}

int main(){
  long long n;
  cin >> n;
  long long ans = 0;
  vector<long long> v;

  v = divisor(n);
  for(int i = 1; i < v.size(); i++){//v[0] == 1
    if(n % (v[i] - 1) == n /(v[i] - 1))ans += v[i] - 1;
  }
  
  cout << ans << endl;

  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    ll N;
    cin >> N;
    ll A,B;
    cin >> A >> B;
    //
    ll num_Blue_set = N / (A+B);
    ll ans;
    ans = num_Blue_set * A;
    ll num = N % (A + B);
    if(num > 0){
        if(num <= A){
            ans = ans + num;
        }
        else{
            ans = ans + A;
        }
    }
    cout << ans << endl;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()





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

  int A;
  bool flag = true;
  rep(i, 0, N){
    cin >> A;
    if (A%2 == 0)
    {
      if (A%3 != 0 && A%5 != 0)
      {
        flag = false;
        break;
      }
    }
  }

  if (flag)
  {
    cout << "APPROVED" << endl;
  }else
  {
    cout << "DENIED" << endl;
  }
  
  
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x;
	for(int i=0;i<n;++i){
		cin>>x;
		if(x%2==0&&x%3!=0&&x%5!=0){
			cout<<"DENIED"<<endl;
			return 0;
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
h=int(input())
w=int(input())
n=int(input())
if h>w:
  if n%h==0:
    print(n//h)
  else:
    print(n//h+1)
else:
  if n%w==0:
    print(n//w)
  else:
    print(n//w+1)

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


void solve() {
  char s[101];
  scanf("%s", &s);
  int n = strlen(s);
  string ans = "Yes";
  for (size_t i = 1; i <= n; i++) {
    if (i%2==0 && s[i-1] == 'R') {
      ans = "No";
    } else if (i%2==1 && s[i-1]=='L') {
      ans = "No";
    }

  }

  cout << ans << "\n";
}

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


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

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

typedef long long int ll;

int read_int()
{
    int a;
    scanf("%d", &a);
    return a;
}

int read_lint()
{
    ll a;
    scanf("%lld", &a);
    return a;
}

int read_float()
{
    float a;
    scanf("%f", &a);
    return a;
}

int read_double()
{
    double a;
    scanf("%lf", &a);
    return a;
}

#define N 200001

char s[N], t[N];

int main()
{
    scanf("%s", &s);
    scanf("%s", &t);

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (s[i] == 0)
        {
            break;
        }
        if (s[i] != t[i])
        {
            ans++;
        }
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 2112
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
#include <cstdlib>
#include <iterator>
using namespace std;
const int N= 1e5 + 7;
int a[N];
//#define TEST
int main()
{
#ifdef TEST
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n) {
		for (int i = 1; i <= n; ++i)
			cin >> a[i];
		sort(a + 1, a + n + 1);
		int aa = 0, b = 0, c = a[n];
		for (int i= n -1; i >= 0; --i) {
			if(a[i] == c) {
				if(b == 0) b = a[i];
				else if(aa == 0) aa = a[i];
				else break;
				c = a[--i];
			}
			else c = a[i];
		} 
		//cout << aa << " " << b << endl;
		cout << (long long)aa * (long long)b << endl;
	}
	return 0;
}


Measured memory_bytes: 640
n, k = gets.split.map(&:to_i)

aa = gets.split.map(&:to_i)

h = aa.inject({}) {|acc, a|
  acc[a] ||= 0
  acc[a] += 1
  acc
}

if h.size <= k
  puts 0
else
  puts h.values.sort.first(h.size - k).inject(&:+)
end

Measured memory_bytes: 32880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,ans;
int main()
{
    cin >> n >> k;
    for (ll a=max(k,1LL),rt=1;a<=n;++a) {
        while ((rt+1) * (rt+1) <= a)
            ++rt;
        for (ll b = 1; b <= rt; ++b)
            ans += a % b >= k;
        for (ll x = 1; x <= rt; ++x) {
            ll l = a / (x+1) + 1, r = (a - k) / x;
            l = max(l, rt+1);
            if (l <= r)
                ans += r - l + 1;
        }
        ans += n-a;
    }
    cout << ans << endl;
}


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

long long super_sum(vector<long long> s){
    if(s.size()== 1){
        return s.at(0);
    }
    else{
        long long a = s.at(0);
        long long b = s.at(1);
        vector<long long> t(s.size()-1);
        vector<long long> u(s.size()-1);
        t.at(0) = a*10 + b;
        u.at(0) = b;
        for (int i = 1; i < s.size()-1; i++)
        {
            t.at(i) = s.at(i+1);
            u.at(i) = s.at(i+1);
        }
        //return super_sum(t) + super_sum(u) + a * 2^(s.size()-2);
        long long xxx = super_sum(t);
        long long yyy = super_sum(u);
        return xxx + yyy + a * pow(2,s.size()-2);
    }
}

int main(){

    string s;
    cin >> s;
    int size = s.size();

    vector<long long> g(0);
    for (int i = 0; i < size; i++)
    {
        int x = s.at(i)-48;
        g.push_back(x);
    }
    cout << super_sum(g) << endl;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

bool expr(string s, int &i) {
    if (s[i] != 'm') return true;
    ++i;
    if (!expr(s, i)) return false;
    if (s[i] != 'e') return false;
    ++i;
    if (!expr(s, i)) return false;
    if (s[i] != 'w') return false;
    ++i;
    return true;
}

void _main() {
    string s;
    cin >> s;
    int i = 0;
    bool ans = expr(s, i);
    cout << (ans && (i == s.size()) ? "Cat" : "Rabbit") << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a < b)
{
printf("a < b\n");
}
else if(a > b)
{
printf("a > b\n");
}
else if(a == b)
{
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m,ans,kyori,k;
  cin>>n>>m;
  vector<pair <long,long> > student(n);
  vector<pair <long,long> > check(m);
  for(long i=0; i<n; i++){
    cin>>student.at(i).first;
    cin>>student.at(i).second;
  }
  for(long i=0; i<m; i++){
    cin>>check.at(i).first;
    cin>>check.at(i).second;
  }
  for(long i=0; i<n; i++){
    kyori=800000000;
    for(long j=0; j<m; j++){
      k=abs(student.at(i).first-check.at(j).first)+abs(student.at(i).second-check.at(j).second);
      if(k<kyori){
        kyori=k;
        ans=j+1;
      }
    }
    cout<<ans<<endl;
  }
}
      

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

int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int hw = h*w;
    vector<vector<int>> c(h, vector<int>(w, 0));
    vector<int> a(n);
    int cx = 0, cy = 0;
    int flag = 0;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) {
        int c_number = i+1;
        //cout << i+1 << " " << a[i] << endl;
        rep(j, 0, a[i]) {
            c[cx][cy] = c_number;
            if(cx+1 < h && flag == 0) {
                cx++;
            }
            else if(cx+1 >= h && flag == 0) {
                cy++;
                flag = 1;
            }
            else if(cx-1 >= 0 && flag == 1) {
                cx--;
            }
            else if(cx-1 < 0 && flag == 1) {
                flag = 0;
                cy++;
            }
        }
    }

    rep(i, 0, h) {
        rep(j, 0, w) {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1
#define j0 gray_cat_j0

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 1e6 + 5;
char c[MAXN], d[MAXN];

int logg[MAXN];

int rec_sol(int v, int offset) {
	if (v == 0) {
		return d[offset];
	}
	int nxt = v - (1 << logg[v]);
	return rec_sol(nxt, offset) ^ rec_sol(nxt, offset + (1 << logg[v]));
}

void solve(){
	int n;
	scanf("%d%s", &n, &c[0]);
	REP(i, 0, n - 1) {
		d[i] = abs(c[i] - c[i + 1]);
	}
	n--;
	int fl = 0;
	REP(i, 0, n) {
		if (d[i] == 1) {
			fl = 1;
		}
	}
	if (fl) {
		REP(i, 0, n) {
			d[i] &= 1;
		}
	}
	
	
	logg[1] = 0;
	REPN(i, 2, n) {
		logg[i] = logg[i >> 1] + 1;
	}
	
	int ans = rec_sol(n - 1, 0);
	printf("%d\n", ans);
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define ll long long
int main() {
    int n;
    cin>>n;
    int ar[n-1];
    REP(i,n-1)
    cin>>ar[i];
    ll c=0;
   if(n==2)
   {cout<<2*ar[0]<<endl;return 0;}
    for(int i=0;i<n-1;i++)
    {
        if(i==0)
        {c+=ar[i];continue;}
        
        c+=min(ar[i],ar[i-1]);
       
    } c+=ar[n-2];
    cout<<c<<endl;
}

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

int main() {
    string str;
    vector<vector<char>> table(2, vector<char>(3));
    rep(i, 2) {
        cin >> str;
        rep(j, 3) table.at(i).at(j) = str.at(j);
    }
    bool flag = true;
    rep(i, 3) {
        if(table.at(0).at(i) != table.at(1).at(2 - i)) flag = false;
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,d,cnt=0; cin>>n>>d;
    rep(i,n){
        double dist,x,y;
        cin>>x>>y;
        dist=sqrt(x*x+y*y);
        if(dist<=d) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3800
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

const int N = 1e+6+5;

char s[N],t[N];
int n;
int pre[N],que[N];

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);scanf("%s",t+1);
	bool pd=1;
	fo(i,1,n)pd&=(s[i]==t[i]);
	if (pd)return printf("0\n"),0;
	int w=n;
	fd(i,n,1){
		w=min(w,i);
		for(;w&&s[w]!=t[i];w--);
		if (!w)return printf("-1\n"),0;
		pre[i]=w;
	}
	int he=1,ta=0,ans=1;
	fd(i,n,1)
	if(pre[i]>pre[i-1]){
		while(he<=ta&&que[he]-(ta-he+1)+1>i)he++;
		if(i!=pre[i]){
			que[++ta]=pre[i];
			ans=max(ans,ta-he+2);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> tax(50000, 0);
    for (int i = 1; i <= 50000; i++){
        tax[i] = i + (i * 8) / 100;
    }
    int ans = 0;
    for (int i = 1; i <= 50000; i++){
        if (N == tax[i]) ans = i;
    }
    if (ans == 0) cout << ":(" << endl;
    else cout << ans << endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<vector<vector<int> > > F(N, vector<vector<int> >(5, vector<int>(2)));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 2; k++) {
                cin >> F[i][j][k];
            }
        }
    }

    vector<vector<int> > P(N, vector<int>(11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    long long ans = INT_MIN;
    for (int i = 1; i < pow(2, 10); i++) {
        vector<int> meet(N, 0);
        for (int j = 0; j < 10; j++) {
            if ((i & (1 << j)) == 0) {
                continue;
            }

            for (int k = 0; k < N; k++) {
                if (F[k][j / 2][j % 2] == 1) {
                    meet[k]++;
                }
            }
        }
        long long benefit = 0;
        for (int k = 0; k < N; k++) {
            benefit += P[k][meet[k]];
        }
        ans = max(ans, benefit);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, t_ = map(int, input().split())
cost_min = 1000
flag = 0
for _ in range(n):
    c,t = map(int, input().split())
    if t <= t_:
        cost_min = min(cost_min, c)
        flag = 1

if flag:
    print(cost_min)
else:
    print('TLE')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long N;
  cin >> N;
  
  long long count = 0;
  for(int i = 1; i < N; i++){
    int j = 1; 
    while(i*j < N) {
      count ++;
      j ++;
    }
  }
  
  
  cout << count << endl;
    
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,k,n,ans=0;
    cin >> k >> n;
    int a[n+5];
    cin >> a[1];
    for(i=2;i<=n;i++)
    {
        cin >> a[i];
        ans=max(ans,a[i]-a[i-1]);
    }
    ans=max(ans,k-a[n]+a[1]);
    cout << k-ans;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define skip continue
#define all(x) x.begin(), x.end()
#define NAME "code"

using namespace std;
 
typedef long long ll;
typedef double ld;
typedef pair<ld, ld> pdd;
const int maxn = 2e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e14;
const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};

ll n, k, a[maxn], sum;

int main(){

cin >> n >> k;

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

sort(a, a + n);

for(int i = 0; i < n; ++i){
	sum += a[i];
	if(sum > k){cout << i; return 0;}
}
cout << n - (sum < k);


return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdlib.h>
#include<cmath>
using namespace std;
	long long ans = 0;
void dfs(long long s,long long n)
{
	if (s == 0) ans+=n;
	else {
		int t = log10(s);
		//ans += s;
		while (t >= 0)
		{
			long long a = s / pow(10, t);
			//ans += a+n;
			// cout << a << endl;
			long long b = s - a*pow(10, t);
			dfs(b, a + n);
			t--;
		}
	}
}
int main()
{
	long long s;
	cin >> s;
	dfs(s,0);
	cout << ans;

}

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

namespace ABC142D_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = ReadInt();
            int N = NK[0];
            int K = NK[1];
            int mod = 1000000007;

            long[] anss = new long[K];
            for (int i = 1; i <= K; i++)
            {
                if (i > N - K + 1)
                {
                    break;
                }
                anss[i - 1] = (nCk(N - K + 1, i, mod) * nCk(K - 1, i - 1, mod)) % mod;
            }

            foreach (var a in anss)
            {
                Console.WriteLine(a);
            }
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }

        /// <summary>
        /// a^n (mod p)
        /// nが非常に大きい時に有効
        /// </summary>
        /// <param name="a"></param>
        /// <param name="n"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        public static long ModPow(long a, long n, long p)
        {
            if (n == 0) return 1;
            if (n == 1) return a % p;
            if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p;

            long t = ModPow(a, n / 2, p);
            return (t * t) % p;
        }

        /// <summary>
        /// 組み合わせ個数
        /// </summary>
        /// <param name="n"></param>
        /// <param name="k"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static long nCk(long n, long k, long p)
        {
            long ans = 1;
            k = Math.Min(k, n - k);
            for (long i = n; i > n - k; i--)
            {
                ans = (ans * i) % p;
            }

            for (long i = 1; i <= k; i++)
            {
                ans = (ans * ModPow(i, p - 2, p)) % p;
            }

            return ans;
        }
    }
}


Measured memory_bytes: 13396
N=int(input())
A=[int(input()) for _ in range(N)]
MAX1=max(A)
for n in range(N):
    if MAX1==A[n]:
        A[n]=0
        break
MAX2=max(A)
A[n]=MAX1
for a in A:
    if MAX1==a:
        print(MAX2)
    else:
        print(MAX1)

Measured memory_bytes: 12532
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

class UnionFind{

private:
    vector<int> rank,p;

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

  public:
      UnionFind(){};
      UnionFind(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i = 0; i < size; i++){
          makeSet(i);
        }
      }

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

    void unite(int x, int y){
      link(find(x), find(y));
    }

    int find(int x){
      if(x != p[x]) p[x] = find(p[x]);
      return p[x];
    }

private:
    void link(int x, int y){
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]) rank[y]++;
      }
    }

};


struct edge{
    int from, to, cost;

    bool operator<(const edge& e) const {
        return cost < e.cost;
    }

};

int ret;
bool kruskal(vector<edge> es, int v){

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

     UnionFind uf(v);

     ret = 0;

     for(int i = 0 ; i < es.size() ; i++){

         edge e = es[i];

         if(!uf.same(e.from, e.to)){
             uf.unite(e.from, e.to);
             ret = max(ret, e.cost);
         }

     }

     bool c = true;
     rep(i,v)if(uf.same(0,i) == false)c = false;
     return c;
}

signed main(void) {
    int i,j;
    int n,m;
    while(cin >> n >> m,n){
        vector<edge> in(m);
        rep(i,m){
            cin >> in[i].from >> in[i].to >> in[i].cost;
            in[i].from--;
            in[i].to--;
        }
        int ans = LINF;
        rep(i,10001){
            vector<edge> e;
            rep(j,m)if(in[j].cost >= i){
                e.push_back(in[j]);
            }
            if(kruskal(e,n)){
                ans = min(ans,ret-i);
            }
        }
        if(ans == LINF) cout << -1 << endl;
        else cout << ans << endl;
    }

}



Measured memory_bytes: 3308
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main()
{
  int n, l;
  cin >> n >> l;
  vector<int>taste(n,0);
  int m = numeric_limits<int>::max();
  for(int i = 0; i < n; i++){
    taste[i] = l+i;
    if(abs(m) > abs(taste[i])){
      m = taste[i];
    }
  }
  int sum = accumulate(taste.begin(),taste.end(),0);
  
  cout << sum - m;
  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

N, M = map(int,input().split())

# works[i] : M-i日に報酬が得られるリスト
works = [[] for _ in range(10**6)]

for _ in range(N):
    A, B = map(int,input().split())
    # 報酬が得られる日付に応じて格納
    works[A].append(B)

hq = []
ans = 0

for i in range(1,M+1):
    # M-i日から降順に仕事の候補リストを作る
    for w in works[i]:
        # 大きいものから選びたいのでマイナスをかける
        heappush(hq, -w)
    # M-i日の時点で報酬が最大の仕事を選ぶ
    if hq:
        ans += -heappop(hq)

print(ans)

Measured memory_bytes: 82656
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;


public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int h = s.nextInt();
		int w = s.nextInt();
		s.nextLine();
		int n = s.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		int x = 0, y = 0;
		int turn = 0;
		int[][] move = {{1, 0}, {-1, 0}};
		int[][] d = new int[h][w];
		
		for (int i = 0; i < n; i++) {
			while (arr[i] != 0) {
				
				arr[i]--;
				d[x][y] = i + 1;
				x += move[turn % 2][0];
				y += move[turn % 2][1];
				if (x < 0 || y < 0 || x == h || y == w) {
					turn++;
					y++;
					x += move[turn % 2][0];
					y += move[turn % 2][1];
				}
				
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if(j==0)
				System.out.print(d[i][j]);
				else System.out.print(" "+d[i][j]);
			}
			System.out.println();
		}
		
		
	}
}

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

using namespace std;
using i64 = long long int;
using P = pair<i64, i64>;

i64 gcd(i64 a, i64 b){
    //
    // Euclidean Algorithm (かっこいい) O(logN)
    // i64 a, i64 b: GCDを求める数 a > b を仮定している
    //
    if(a % b == 0) return b;
    else return gcd(b, a % b);
}

i64 modpow(i64 x, i64 n){
    const i64 mod = 1000000007;
    i64 res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

void NTL_1_B(){
    i64 m, n;
    cin >> m >> n;
    cout << modpow(m, n) << endl;
}

int main(){
    NTL_1_B();
}


Measured memory_bytes: 3084
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  /*arr1 := make([]int, 9)
  arr := make([][]int, 3)
  for i := 0; i < 3; i++ {
    arr[i] = make([]int, 3)
  }*/

  c11 := nextInt()
  c12 := nextInt()
  c13 := nextInt()
  c21 := nextInt()
  c22 := nextInt()
  c23 := nextInt()
  c31 := nextInt()
  c32 := nextInt()
  c33 := nextInt()
  flg := false
  if ( c11 - c12  == c21 - c22 && c21 - c22 == c31 - c32) {
    if ( c12 - c13  == c22 - c23 && c22 - c23 == c32 - c33) {
      if ( c13 - c11  == c23 - c21 && c23 - c21 == c33 - c31) {
        if ( c11 - c21  == c12 - c22 && c12 - c22 == c13 - c23) {
          if ( c21 - c31  == c22 - c32 && c22 - c32 == c23 - c33) {
            if ( c31 - c11  == c32 - c12 && c32 - c12 == c33 - c13) {
				flg = true
            }
          }
        }
      }
    }
  }
  if flg {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }

}

func nextString() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}


Measured memory_bytes: 640
package main

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

type City struct {
	id, x, y int
}

type Edge struct {
	u, v, cost int
}

func main() {
	N := ReadInt()
	cities := make([]*City, N)
	for i := 0; i < N; i++ {
		cities[i] = &City{
			id: i,
			x:  ReadInt(),
			y:  ReadInt(),
		}
	}
	edges := make([]*Edge, 0)
	sort.Slice(cities, func(i, j int) bool {
		return cities[i].x < cities[j].x
	})
	for i := 0; i < N-1; i++ {
		edges = append(edges, &Edge{
			u:    cities[i].id,
			v:    cities[i+1].id,
			cost: Dist(cities[i], cities[i+1]),
		})
	}
	sort.Slice(cities, func(i, j int) bool {
		return cities[i].y < cities[j].y
	})
	for i := 0; i < N-1; i++ {
		edges = append(edges, &Edge{
			u:    cities[i].id,
			v:    cities[i+1].id,
			cost: Dist(cities[i], cities[i+1]),
		})
	}
	sort.Slice(edges, func(i, j int) bool {
		return edges[i].cost < edges[j].cost
	})
	sum := 0
	uf := MakeUnionFind(N)
	for _, edge := range edges {
		if uf.Connected(edge.u, edge.v) {
			continue
		}
		uf.Unite(edge.u, edge.v)
		sum += edge.cost
	}
	fmt.Println(sum)
}

type UnionFind []int

func MakeUnionFind(size int) UnionFind {
	parent := make([]int, size)
	for i := 0; i < size; i++ {
		parent[i] = i
	}
	return parent
}
func (uf UnionFind) Unite(x, y int) {
	if x, y = uf.Root(x), uf.Root(y); x != y {
		uf[x] = y
	}
}
func (uf UnionFind) Connected(x, y int) bool { return uf.Root(x) == uf.Root(y) }
func (uf UnionFind) Root(x int) int {
	if uf[x] == x {
		return x
	}
	uf[x] = uf.Root(uf[x])
	return uf[x]
}

func Dist(a, b *City) int {
	return Min(
		Abs(a.x-b.x),
		Abs(a.y-b.y),
	)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

int vet[120];

int main(){
	int n;
	
	cin >> n;
	
	vet[0] = 1;
	for(int i=0; i<=n; i++)
		if(vet[i])
			vet[i+4] = 1;
	
	for(int i=0; i<=n; i++)
		if(vet[i])
			vet[i+7] = 1;
	if(vet[n] == 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N, X;

    scanf("%d", &N);
    X = -1;
    for (int i = N; i > (N / 2); i--)
    {
        if ((int)(i * 1.08) == N)
        {
            X = i;
            break ;
        }     
    }
    if (X != -1)
        printf("%d\n", X);
    else
        printf(":(\n");
    return 0;
}

Measured memory_bytes: 128
def main():
    A,B,M = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ans = min(a) + min(b)
    coupon = [list(map(int,input().split())) for _ in range(M)]
    for i in range(M):
        tmp = a[coupon[i][0]-1] + b[coupon[i][1]-1] - coupon[i][2]
        ans = min(tmp,ans)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 80620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {


	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), a = in.nextInt();
			int[] x = in.nextIntArray(n);

			long[][][] dp = new long[n+1][n+1][n*a+1];

			dp[0][0][0] = 1;

			for (int j = 1; j <= n; j++) {
				for (int k = 0; k <= j; k++) {
					for (int s = 0; s <= n*a; s++) {
						if (s-x[j-1] >= 0 && k > 0) {
							dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]];
						} else {
							dp[j][k][s] = dp[j-1][k][s];
						}
					}
				}
			}

			long ans = 0;

			for (int i = 1; i <= n; i++) {
				ans += dp[n][i][i*a];
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


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

int main()
{
	int w, n;
	int a[30], b[30];
	
	cin >> w >> n;

	for (int i = 0; i < n; i++) {
		char s;
		cin >> a[i] >> s >> b[i];
	}

	for (int i = 0; i < w; i++) {
		int g = i + 1;

		for (int j = n - 1; j >= 0; j--) {
			if (a[j] == g)
				g = b[j];
			else if (b[j] == g)
				g = a[j];
		}

		cout << g << endl;
	}

	return 0;
}


Measured memory_bytes: 3012
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 55

const int INF = 1e9 + 7;


int n, m;
int mp[ARRAY_MAX][ARRAY_MAX];
bool visited[ARRAY_MAX];
vector<int> a, b;


void dfs(int now) {

	//cout << "now = " << now << endl;
	visited[now] = true;//今いる頂点をチェックする
	
	for (int i = 0; i < n; i++)
	{
		int next = mp[now][i];
		if (next == 0)continue;//経路がない
		if (visited[i] == true)continue;//既に訪れた
		dfs(i);
	}
}




int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int ta, tb;
		cin >> ta >> tb;
		ta--;
		tb--;
		a.push_back(ta);
		b.push_back(tb);
		mp[ta][tb] = mp[tb][ta] = 1;
	}
	
	int ans = 0;
	for (int i = 0; i < m; i++) {
		//i本目の橋を取り除いてdfsをして連結かどうかを調べる
		//橋を消す
		mp[a[i]][b[i]] = mp[b[i]][a[i]] = 0;
		dfs(0);
		bool flag = true;
		for (int j = 0; j < n; j++)
		{
			flag &= visited[j];
		}

		if (flag == false)
		{
			//cout << "i= " << i << endl;
			ans++;
		}

		for (int j = 0; j < ARRAY_MAX; j++)
		{
			//初期化
			visited[j] = false;
		}
		mp[a[i]][b[i]] = mp[b[i]][a[i]] = 1;
		//橋を戻す
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256