akhauriyash/Code-Regression huggingface dataset:
#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)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\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, INF2 = 4 * INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vec< int > x;
vec< int > y;
int N, K;
bool exec(int a0, int a1, int a2, int a3) {
  int cnt = 0;
  REP(i, N) {
    if (a0 <= x[i] && x[i] <= a1 && a2 <= y[i] && y[i] <= a3)
      cnt++;
  }

  if (cnt >= K) {
    return true;
  } else {
    return false;
  }
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> N >> K;
  x.resize(N);
  y.resize(N);
  REP(i, N) { cin >> x[i] >> y[i]; }
  int ans = INF2;
  vec< int > xC(x);
  vec< int > yC(y);
  sort(ALL(xC));
  sort(ALL(yC));
  REP(i0, N) {
    FOR(i1, i0 + 1, N) {
      REP(j0, N) {
        FOR(j1, j0 + 1, N) {

          int tmpans = (xC[i1] - xC[i0]) * (yC[j1] - yC[j0]);
          if (tmpans > ans)
            continue;
          bool isUpdate = exec(xC[i0], xC[i1], yC[j0], yC[j1]);
          if (isUpdate) {
            chmin(ans, tmpans);
          }
        }
      }
    }
  }
  print(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stack>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pii pair<pi,int>
#define sqr(x) ((x)*(x))
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int x,y,z;
	x=abs(a-b);
	y=abs(b-c);
	z=abs(a-c);
	cout<<max(x,max(y,z))<<endl;

   // system("pause");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<pair<int,int> > v;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if (k>(n-1)*(n-2)/2)
	{
		printf("-1");
		return 0;
	}
	for (int i=2;i<=n;i++)
	{
		v.push_back({1,i});
		for (int j=k+2;j<i;j++)
		v.push_back({j,i});
		k-=min(i-2,k);
	}
	printf("%d\n",v.size());
	for (auto p:v)
	printf("%d %d\n",p.first,p.second);
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	class Key
	{
		public int Index{get;set;}
		public int Cost{get;set;}
		public int Boxes {get;set;}
	}
	public static void Main(string[] args)
	{
		int[] p = Input().ToInt();
		int n = p[0];
		int m = p[1];
		Key[] keys = new Key[m];
		
		//dp[i,j] := i個までの鍵でj個の宝箱開けられる最小のdp[i,j]円
		for(int i = 0; i < m; i++)
		{
			p = Input().ToInt();
			keys[i] = new Key(){Cost=p[0]};
			int t = p[1];
			
			p = Input().ToInt();
			for(int j = 0; j < t; j++)
			{
				keys[i].Boxes |= 1 << (p[j]-1);
			}
		}
		int[,] dp = new int[m+1, (1 << (n))];
		for(int i = 0; i < m+1; i++)
			for(int j = 0; j < (1<<n); j++)
				dp[i, j] = 999999999;
		dp[0,0]=0;
		for(int i = 0; i < m; i++)
		{
			for(int j = 0; j < (1<<n); j++)
			{
				dp[i+1, j] = Math.Min(dp[i, j], dp[i+1,j]);
				dp[i+1, j | keys[i].Boxes] = Math.Min(dp[i+1, j | keys[i].Boxes], dp[i,j]+keys[i].Cost);
			}
		}
		if(dp[m, (1<<n)-1] == 999999999)
			Console.WriteLine(-1);
		else
			Console.WriteLine(dp[m, (1<<n)-1]);
	}
	
	private static int Check(int max, long t)
	{
		int r = 0;
		for(int i = 0; i < max; i++)
		{
			int k = 1 << i;
			if((t & k) == k)
			{
				r++;
			}
		}
		return r;
	}
	private static void Divisors(long n )
	{
		
		long k = (long)(n/2)+1;
		for(long i = 1; i <= k; i++)
		{
			if(n % i == 0)
			{
			}
		}
	}
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 26976
#include "bits/stdc++.h"

using namespace std;


void Main() {
    int N, M;
    cin >> N >> M;
    map<int, vector<int> > path;
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        if (path.count(a) == 0) {
            path.insert(make_pair(a, vector<int>()));
        }
        path[a].push_back(b);
        if (path.count(b) == 0) {
            path.insert(make_pair(b, vector<int>()));
        }
        path[b].push_back(a);
    }

    vector<int> check(N, -1);
    queue<int> q;
    q.push(0);
    check[0] = 0;
    while (q.size() > 0) {
        int curr = q.front();
        q.pop();
        const vector<int>& to = path[curr];
        for (auto e : to) {
            if (check[e] == -1) {
                q.push(e);
                check[e] = curr;
            }
        }
    }

    bool reachedAll = true;
    for (int i = 0; i < N; ++i) {
        if (check[i] < 0) {
            reachedAll = false;
            break;
        }
    }

    if (reachedAll) {
        cout << "Yes" << endl;
        for (int i = 1; i < N; ++i) {
            cout << check[i] + 1 << endl;
        }
    }
    else {
        cout << "No" << endl;
    }

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 15664
_,m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

# 総投票数
sum = 0
a.each do |x|
  sum += x
end

# 人気商品を選ぶ
border = sum / (4 * m).to_f 

goods = a.sort.reverse

ninki = goods.take(m)

# こたえ
kotae = 0
ninki.each do |g|
  if g >= border
    kotae += 1
  end
end

if kotae >= m
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<vector<pair<ll, ll>>> gridgraph(int h, int w, vector<string> s) {
    vector<vector<pair<ll, ll>>> edge(h * w);
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(i + 1 < h) {
                edge[i * w + j].push_back(make_pair(
                    (s[i][j] == '.') && (s[i + 1][j] == '#'), (i + 1) * w + j));
            }
            if(j + 1 < w) {
                edge[i * w + j].push_back(make_pair(
                    (s[i][j] == '.') && (s[i][j + 1] == '#'), i * w + j + 1));
            }
        }
    }
    return edge;
}
vector<ll> Dijkstra_list(int n, int s, vector<vector<pair<ll, ll>>> &Edge) {
    vector<bool> visited(n, false); //確定済み
    vector<ll> d(n, __LONG_LONG_MAX__ / 3);
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
        que; //頂点とsからの距離
    d[s] = 0;
    que.push(make_pair(0, s));
    while(!que.empty()) {
        auto now = que.top();
        que.pop();
        visited[now.second] = true;
        for(auto e : Edge[now.second]) {
            if(visited[e.second])
                continue;
            if(d[e.second] > d[now.second] + e.first) {
                d[e.second] = d[now.second] + e.first;
                que.push(make_pair(d[e.second], e.second));
            }
        }
    }
    return d;
}
int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++) {
        cin >> s[i];
    }
    auto edge = gridgraph(h, w, s);
    auto d = Dijkstra_list(h * w, 0, edge);
    cout << d.back() + (s[0][0] == '#') << endl;
}

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

int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    cout<<a[0]+a[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> L(n);
    for(int i = 0; i < n; i++) {
        cin >> L[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            for(int k = j + 1; k < n; k++) {
                vector<int> v;
                v.emplace_back(L[i]);
                v.emplace_back(L[j]);
                v.emplace_back(L[k]);
                sort(ALL(v));
                if(v[0] == v[1] || v[1] == v[2] || v[2] == v[0]) {
                    continue;
                }
                if(v[0] + v[1] > v[2]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC130A
{
    class Program
    {
        static void Main(string[] args)
        {
            var XA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = XA[0];
            int A = XA[1];
            Console.WriteLine(X < A ? "0" : "10");
        }
    }
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> k;
	int n, a;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		k.push_back(a);
		sum += a;
	}
	int e, el, ell;
	int p = 0, pl = 0, pll = 0;
	int kkk = 1 << 30;
	if (sum % n != 0)
	{
		e = sum / n;
		for (int i = 0; i < k.size(); i++)
			p = p + (k[i] - e) * (k[i] - e);
		kkk = min(p, kkk);
		el = e + 1;
		for (int i = 0; i < k.size(); i++)
			pl = pl + (k[i] - el) * (k[i] - el);
		kkk = min(pl, kkk);
		ell = e - 1;
		for (int i = 0; i < k.size(); i++)
			pll = pll + (k[i] - ell) * (k[i] - ell);
		kkk = min(pll, kkk);
		cout << kkk << endl;
		return 0;
	}
	sum = sum / n;
	int ans = 0;
	for (int i = 0; i < k.size(); i++)
		ans = ans + (k[i] - sum) * (k[i] - sum);
	cout << ans << endl;
	return 0;
}

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

typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(14);

    ld c, H,v ;
    cin >> c >> H >> v;

    if (v <= (c*c*H)/2.0){
        ld h = (v*2)/(H*c);
        ld hip = sqrt(h*h + H*H);
        ld resp = (180*asin(H/hip) / acos(-1));
        cout << fixed << resp << endl;

    }
    else{
        ld h = v/(c*c);
        ld x = 2*h - H;
        ld resp = 90 - (180.0*acos( (H-x)/(sqrt(H*H - 2*H*x + x*x + c*c))) / acos(-1));
        cout << fixed << resp << endl;
    }

}

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

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

void solver() {
  int n;
  cin >> n;

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        int tmp = gcd(i, j);
        ans += gcd(tmp, k);
      }
    }
  }

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

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


Measured memory_bytes: 3668
NN = 1000000007

n, m = gets.chomp.split(" ").map(&:to_i)

if (n-m).abs > 1
  puts 0
  exit
end

def fact(n)
  x = 1
  for i in 2..n
    x = x * i % NN
  end
  return x
end

if n == m
  puts fact(n) ** 2 * 2 % NN
elsif n < m
  puts (fact(n) ** 2 * m) % NN
else
  puts (fact(m) ** 2 * n) % NN
end  




Measured memory_bytes: 1788
#include<stdio.h>
 
int main(){
  int W,H,x,y,s;
  
  
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&s);
  if(x+x == W && y+y == H){
    s=1;
  } else {
    s=0;
  }
  
  printf("%lf %d",(double)W*H/2,s);
  
    
    
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main() {
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);

  if (a == 1 && b == 2) printf ("3");
  else if (a == 1 && b == 3) printf ("2");
  else if(a == 2 && b == 1) printf ("3");
  else if(a == 3 && b == 1) printf ("2");
  else printf ("1");

  return 0;
}


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

typedef long long ll;

using namespace std;

int main(void) {
    char b;
    cin >> b;

    if (b == 'A')
        cout << 'T' << endl;
    else if (b == 'T')
        cout << 'A' << endl;
    else if (b == 'C')
        cout << 'G' << endl;
    else
        cout << 'C' << endl;
}

Measured memory_bytes: 256
class Array
    def *(other)
        map {|i| other[i]}
    end
end

def exp(m, k, mod = nil)
    x = (0..m.size-1).to_a
    r = m
    while k > 0
        x *= r if k & 1 == 1
        r *= r
        if mod
            x %= mod
            r %= mod
        end
        k >>= 1
    end
    x
end

def parse(n, exp)
    if exp == ""
        return (0..n*n-1).to_a
    end

    if exp =~ /^([UDLR])(\d+)/
        k = $&.size
        op, i = $1, $2.to_i - 1
        perm = (0..n*n-1).to_a
        case op
        when ?L then
            (i * n .. i * n + n - 1).each do |k|
                if k == i * n + n - 1
                    perm[k] = i * n
                else
                    perm[k] = k + 1
                end
            end
        when ?R then
            (i * n .. i * n + n - 1).each do |k|
                if k == i * n
                    perm[k] = k + n - 1
                else
                    perm[k] = k - 1
                end
            end
        when ?D then
            (0..n-1).each do |k|
                if k == 0
                    perm[k * n + i] = (n - 1) * n + i
                else
                    perm[k * n + i] = k * n + i - n
                end
            end
        when ?U then
            (0..n-1).each do |k|
                if k == n - 1
                    perm[k * n + i] = i
                else
                    perm[k * n + i] = k * n + i + n
                end
            end
        end
        return parse(n, exp[k..-1]) * perm
    end

    raise if exp[0] != ?(
    i = 1
    paren = 1
    until paren == 0
        paren += 1 if exp[i] == ?(
        paren -= 1 if exp[i] == ?)
        i += 1
    end
    j = i
    j += 1 while exp[j] =~ /\d/

    parse(n, exp[j..-1]) * exp(parse(n, exp[1..i-2]), exp[i..j-1].to_i)
end

n, l = gets.split.map(&:to_i)
ret = parse(n, gets.chomp)
(0..n-1).each do |i|
    puts (0..n-1).map {|j| ret[i * n + j] + 1}.join(" ")
end



Measured memory_bytes: 103396
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

int main() {
	ll N; cin >> N;
	vector<ll> A(N); rep(i, N)cin >> A[i];

	ll cnt = 0;
	rep(i, N) if (A[i] < 0) cnt++;

	ll ans = 0;
	rep(i, N) ans += abs(A[i]);
	
	ll mi = 1e10;
	rep(i, N) mi = min(mi, abs(A[i]));

	if (cnt % 2 == 0) cout << ans << endl;
	else cout << ans - 2 * mi << endl;
}

Measured memory_bytes: 1024
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    a = 0
    for i in range(m): 
        a += A[i]
    ans = n - a
    if ans >= 0:
        print(ans)
    else:
        print(-1)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 68100
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
#include <functional>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back


int main()
{
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	vector<int> a(3);
	a[0] = A;
	a[1] = B;
	a[2] = C;
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < K; i++) {
		a[2] *= 2;
	}
	cout << a[0] + a[1] + a[2] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)

const int MaxN = 1e4 + 10;
const int inf = 0x3f3f3f3f;

struct edge
{
    int next, to;
};

char s[MaxN];
edge e[MaxN];
int n, ans, cnt;
int a[MaxN], head[MaxN], dis[MaxN], size[MaxN], f[MaxN];

void init()
{
    for (int i = 1; i <= n; i++)
        dis[i] = size[i] = f[i] = 0;
}

void add_edge(int u, int v)
{
    ++cnt;
    e[cnt].to = v;
    e[cnt].next = head[u];
    head[u] = cnt;
}

inline int read()
{
    int x = 0;
    char ch = getchar();
    while (ch > '9' || ch < '0')
        ch = getchar();
    while (ch <= '9' && ch >= '0')
        x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x;
}

void dfs(int u, int fa)
{
    size[u] = a[u];
    int maxp = 0;
    for (int i = head[u]; i; i = e[i].next)
    {
        int v = e[i].to;
        if (v == fa) continue;
        dfs(v, u), size[u] += size[v], dis[v] += size[v];
        dis[u] += dis[v], maxp = ((dis[maxp] > dis[v]) ? maxp : v);
    }    
    if(!maxp) return (void) (f[u] = 0);
    if(dis[u] >= 2 * (dis[maxp])) f[u] = (dis[u] / 2);
    else f[u] = dis[u] - dis[maxp] + std::min(f[maxp], (2 * dis[maxp] - dis[u]) / 2);
}

int main()
{
    ans = inf;
    n = read(), scanf("%s", s + 1);
    for (int i = 1; i <= n; i++)
        a[i] = s[i] - '0';
    for (int i = 1; i < n; i++)
    {
        int u = read(), v = read();
        add_edge(u, v), add_edge(v, u);
    }
    for (int i = 1; i <= n; i++)
    {
        init(), dfs(i, 0);
        if(dis[i] & 1) continue;
        if (f[i] * 2 >= dis[i]) ans = std::min(ans, dis[i] / 2);
    }
    printf("%d\n", (ans == inf) ? -1 : ans);
    return 0;
}

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

int main(void){
    string s;
    int sum = 700;
    for(int i = 0; i < 3; i++){
        cin >> s[i];
        if(s[i] == 'o')
            sum += 100;
        else if(s[i] == 'x')
            sum = sum;
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.readline
w = input().rstrip()
dic = {}
for i in w:
	if not i in dic:
		dic[i] = 1
	else:
		dic[i] += 1
for word in dic:
	if dic[word]%2 != 0:
		print("No")
		break
else:
	print("Yes")

Measured memory_bytes: 3060
package main

import "fmt"

func main() {

	var n, min, max, sum, temp int
	fmt.Scan(&n)
	fmt.Scan(&temp)
	min = temp
	max = temp
	sum = temp

	for i:=1; i<n; i++ {
		fmt.Scan(&temp)
		if temp < min {
			min = temp
		}
		if temp > max {
			max = temp
		}
		sum += temp
	}
	fmt.Println(min, max, sum)
}



Measured memory_bytes: 1704
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int nmax=100005;
vector<int> v[nmax];
int c[nmax];
int cate,bp,n,m,i,j,a,b;
long long iz,cc,nr_bp,ans;
void dfs(int x,int col)
{
    c[x]=col;cate++;
    for(int i=0;i<v[x].size();i++)
    {
        if(!c[v[x][i]])
          dfs(v[x][i],3-col);
        if(c[v[x][i]]==col)
          bp=0;
    }
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int s=1;s<=n;s++)
        if(!c[s])
    {
        cate=0;bp=1;
        dfs(s,1);
        if(bp&&cate>1) nr_bp++;
        if(cate==1) iz++;
        else cc++;
    }
    ans=1LL*iz*n+n*iz-iz*iz;
    ans+=1LL*cc*cc+nr_bp*nr_bp;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 9984
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const int MOD = 1000000007;

int main() {
    int N,M;
    cin >> N >> M;
    int ans = 0;
    vector<P> edge(M);
    REP(i,M) cin >> edge[i].first >> edge[i].second;
    REP(i,M) {
        vecveci G(N);
        REP(j,M) {
            if(i != j) {
                int a = edge[j].first;
                int b = edge[j].second;
                a--;
                b--;
                G[a].push_back(b);
                G[b].push_back(a);
            }
        }

            vector<int> dist(N,-1);
            queue<int> que;
            int count = 0;
            for(int v = 0; v < N; v++) {
                if(dist.at(v) != -1) continue;
                dist.at(v) = 0;
                que.push(v);
                while(!que.empty()) {
                    int v = que.front(); 
                    que.pop();
                    for(auto w:G.at(v)) {
                        if(dist.at(w) != -1) continue;
                        que.push(w);
                        dist.at(w) = dist.at(v) + 1;
                    }
                }
                count++;
            }
            if(count > 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];


			var friendships = createLongTuppleList(M);

			var map = new List<long>[N];

			for (int i = 0; i < N; i++) {
				map[i] = new List<long>();
			}

			for (int i = 0; i < M; i++) {
				var fs = friendships[i];
				map[fs.Item1 - 1].Add(fs.Item2-1);
				map[fs.Item2 - 1].Add(fs.Item1 - 1);
			}

			//各グループの所属人数を表す
			var groupCounts = new List<long>();

			_map = map;
			_used = Enumerable.Repeat(false, (int)N).ToArray();


			for (int i = 0; i < N; i++) {
				if (_used[i]) {
					continue;
				}
				
				_count = 0;
				DFS(i);
				groupCounts.Add(_count);
			}

			//答えの出力
			var ans = groupCounts.Max();
			Console.WriteLine(ans);

		}

		private static List<long>[] _map;
		private static bool[] _used;
		private static int _count;



		private static void DFS(long from) {

			_count++;
			_used[from] = true;

			var friends = _map[from];

			foreach (var friend in friends) {
				if (_used[friend]) {
					continue;
				}
				DFS(friend);
			}
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}

Measured memory_bytes: 73424
import itertools
N, M = map(int, input().split())
A = [set(map(int, input().split())) for _ in range(M)]
ans = 0
for p in itertools.permutations(range(2, N+1)):
    q = list(p) + [1]
    for i in range(N-1):
        if not {q[i], q[i+1]} in A:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
N = int(input())
s = []
l = 1
z = 0
s = [input() for _ in range(N)]
for i in range(0,N):
    s[i] = ''.join(sorted(s[i]))
s.sort()
for i in range(0,N-1):
    if s[i] == s[i+1]:
        l += 1
    else:
        z += l*(l-1)/2
        l = 1
z += l*(l-1)/2
print(int(z))


Measured memory_bytes: 63320
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use im_rc::HashMap;

#[fastout]
fn main() {
    input! {
    n: usize,
    mut sp: [(String, usize); n]
    }
    let mut map = HashMap::new();
    for i in 0..n {
        map.insert(sp[i].clone(), i + 1);
    }
    sp.sort();
    let mut w = "";
    let mut l = 0;
    for i in 0..n {
        if w != &sp[i].0 {
            sp[l..i].sort_by(|a, b| b.partial_cmp(a).unwrap());
            l = i;
            w = &sp[i].0;
        }
    }
    if l != n {
        sp[l..n].sort_by(|a, b| b.partial_cmp(a).unwrap());
    }
    for i in 0..n {
        if let Some(x) = map.get(&sp[i]) {
            println!("{}", x);
        }
    }
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,x,y,f=0;
	cin>>n;
	for(x=0;x<=n/4;x++)
	  for(y=0;y<=n/7;y++)
	    if(x*4+y*7==n){
	    	f=1;break;
	    }
	if(f)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

#define ll long long
#define NIL 0
#define INF 1e18
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vl vector<ll>
#define vvl vector<vector<ll>> 
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pb push_back
#define F first
#define S second
#define pp pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rpk(i,k,n) for(int i=k;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++) 
#define RPK(i,k,n) for(int i=k;i<=n;i++) 
#define ritr(i,gr) for(auto i=gr.begin();i!=gr.end();i++)

const int M = 1e9+7;

int V, E, i, j, k, u, v, x, y, p, q, r, t, n,m;
vi *g;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cin>>n;
    
    ll amsk = 1<<n, msk=0;
    bool pr[n][n];
    rep(i,n) rep(j,n) cin>>pr[i][j];
    vl dp(amsk, 0);
    dp[0]=1;
    
    rep(msk,amsk) {
        bitset<22> b1(msk); 
        int nbits = b1.count();
        rep(j,n) {
            if((pr[nbits][j]==true&&(msk&(1<<j))==0)) {
                dp[msk|(1<<j)] = (dp[msk|(1<<j)]+ dp[msk]+M)%M;
            }
        }
    }
    cout<<dp[amsk-1]<<endl;
}
    
    
    

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

int main() {
  std::string x(1, ' ');
  std::string y(1, ' ');
  scanf("%s", &x[0], x.size());
  scanf("%s", &y[0], y.size());
  if (x[0] < y[0]) {
    printf("<");
  } else if (x[0] == y[0]) {
    printf("=");
  } else {
    printf(">");
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* UnionFind */

struct UnionFind{
  vector<int> data;
  UnionFind(int s):data(s, -1) {}

  int root(int x){
    if(data[x] < 0) return x;
    return data[x] = root(data[x]);
  }

  bool set(int x, int y){
    x = root(x); y = root(y);
    if (x == y) return false;
    //if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  bool check(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int main() {
  int N, M;

  cin >> N >> M;

  UnionFind uf(N);

  int ans = N;

  for (int i=0; i<M; i++) {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    ans -= uf.set(X-1, Y-1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {

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

    static class Task {


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


            int[] a = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray();

            out.println(Math.min(a[1] / a[0], a[2]));

        }

    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            //reader = new BufferedReader(new FileReader(stream), 32768);
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "";
        }

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

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

        public void close() {
        }

    }
}


Measured memory_bytes: 26836
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<vector>

using namespace std;

#define N 201000
#define ll long long
#define ls (now<<1)
#define rs ((now<<1)|1)
#define RG register

inline int read(){
    RG int x=0,o=1; RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=((x<<3)+(x<<1))+ch-'0',ch=getchar();
    return x*o;
}

int n,m,val[N],fa[N],vis[N],siz[N],tot; ll sum[N];
struct navi { int x,y,w; } a[N],b[N];
inline bool cmp(navi x,navi y) { return x.w<y.w; }
inline int Find(int x) { if(fa[x]^x) return Find(fa[x]); return fa[x]; }

struct joker { int i,w; } cps[N],cpz[N],cpf[N];
inline void Cp(int op,int i,int w,int id){
	if(op==1) cps[id]=(joker) { i,w };
	if(op==2) cpz[id]=(joker) { i,w };
	if(op==3) cpf[id]=(joker) { i,w };
}

int main(){
	n=read(),m=read();
	for(RG int i=1;i<=n;++i) val[i]=read(),fa[i]=i,sum[i]=val[i],siz[i]=1;
	for(RG int i=1;i<=m;++i) a[i]=(navi) { read(),read(),read() };
	sort(a+1,a+1+m,cmp);
	for(RG int i=1;i<=m;++i){
		int fx=Find(a[i].x),fy=Find(a[i].y);
		if(fx^fy){
			b[++tot]=a[i];
			if(siz[fx]<siz[fy]) Cp(1,fy,sum[fy],tot),Cp(2,fy,siz[fy],tot),Cp(3,fx,fa[fx],tot),
									fa[fx]=fy,siz[fy]+=siz[fx],sum[fy]+=sum[fx];
			else Cp(1,fx,sum[fx],tot),Cp(2,fx,siz[fx],tot),Cp(3,fy,fa[fy],tot),
					 fa[fy]=fx,siz[fx]+=siz[fy],sum[fx]+=sum[fy];
		}
	}   int cp=0,ans=0;
	for(RG int i=tot;i;--i){
		int Y=Find(b[i].y); if(sum[Y]>=b[i].w) continue ; vis[i]=1;
		siz[cpz[i].i]=cpz[i].w,sum[cps[i].i]=cps[i].w,fa[cpf[i].i]=cpf[i].w;
	}	for(RG int i=1;i<=tot;++i) if(!vis[i]) b[++cp]=b[i];
	for(RG int i=1;i<=m;++i){
		int fx=Find(a[i].x),fy=Find(a[i].y);
		if((fx^fy)||(sum[fx]<a[i].w)) { ++ans; continue ; }
	}   printf("%d\n",ans);
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, s, n, m) for(ll i = s; i < (ll)(n); i+=m)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<P> p(N);
    rep(i, 0, N, 1) { 
        ll A, B;
        cin >> A >> B;
        p[i] = make_pair(A, B);
    }
    sort(all(p));
    ll pos = 0;
    ll cnt = 0;
    priority_queue<ll> pq;
    ll tmp = 1;
    while(tmp <= M) {
        while(pos < N && p[pos].first <= tmp) {
            pq.push(p[pos].second);
            pos++;
        }
        tmp++;
        if (pq.empty()) continue;
        cnt += pq.top();
        pq.pop();
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    long long int ans = 1;
    const int mod = 1000000007;
    for (int i = 1; i <= N; i++){
        ans = ans * i;
        ans = ans % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// ABC_173_B

#include <iostream>
#include <vector>

using namespace std;

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

  vector<string> s(n);
  for(int i = 0; i < n; ++i) cin >> s[i];

  int a = 0, b = 0, c = 0, d = 0;
  for(int i = 0; i < n; ++i) {
    if(s[i] == "AC") ++a;
    else if (s[i] == "WA") ++b;
    else if(s[i] == "TLE") ++c;
    else ++d;
  }

  cout << "AC" << " x " << a << "\n";
  cout << "WA" << " x " << b << "\n";
  cout << "TLE" << " x " << c << "\n";
  cout << "RE" << " x " << d << "\n";

  return 0;

}

Measured memory_bytes: 6372
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n,k;
  cin>>n>>k;
  ll i;
  ll a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  ll dp[n];
  dp[0]=0;
  dp[1]=llabs(a[0]-a[1]);
  for(i=2;i<n;i++){
    ll m=10000000000000000;
    for(ll j=1;j<=k;j++)
    if(i-j>=0)
    m=min(dp[i-j]+llabs(a[i-j]-a[i]),m);
    dp[i]=m;
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace std;


int main(void) {
    mp::cpp_int n;
    cin >> n;

    vector<mp::cpp_int> arr(6); // 移動時間
    vector<mp::cpp_int> term(6); // ターン数
    arr[0] = INT64_MAX;
    term[0] = 0; // dummy
    for(int i = 0 ; i < 5 ; ++i) {
        cin >> arr[i + 1];
    }

    for(int i = 0 ; i < 5 ; ++i) {
        if (arr[i + 1] > arr[i]) {
            // 前回の移動手段のほうが遅いので、そっちに引っ張られる
            term[i + 1] = term[i] + 1; // +1は1ターンのディレイ
        } else {
            mp::cpp_int t = (n / arr[i + 1]) + (n % arr[i + 1] == 0 ? 0 : 1) + i;
            mp::cpp_int recent = term[i] + 1;
            term[i + 1] = t < recent ? recent : t;
        }
    }
    auto result = term[term.size() - 1];
    cout << result << endl;
    return 0;
}

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

int main()
{
	int N, M, a, b;
	cin >> N >> M;
	vector<int> res(N);
	while (M--) {
		cin >> a >> b;
		res[a - 1]++;
		res[b - 1]++;
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void DICE(char x, int *dice1, int *dice2, int *dice3, int *dice4, int *dice5, int *dice6){
    int tmp1, tmp2, tmp3, tmp4;
    if(x=='S'){
        tmp1=*dice1;
        tmp2=*dice2;
        tmp3=*dice5;
        tmp4=*dice6;
        *dice1=tmp3;
        *dice2=tmp1;
        *dice5=tmp4;
        *dice6=tmp2;
    }
        else if(x=='W'){
        tmp1=*dice1;
        tmp2=*dice3;
        tmp3=*dice4;
        tmp4=*dice6;
        *dice1=tmp2;
        *dice3=tmp4;
        *dice4=tmp1;
        *dice6=tmp3;
    }
    else if(x=='N'){
        tmp1=*dice1;
        tmp2=*dice2;
        tmp3=*dice5;
        tmp4=*dice6;
        *dice1=tmp2;
        *dice2=tmp4;
        *dice5=tmp1;
        *dice6=tmp3;
    }
    else if(x=='E'){
        tmp1=*dice1;
        tmp2=*dice3;
        tmp3=*dice4;
        tmp4=*dice6;
        *dice1=tmp3;
        *dice3=tmp1;
        *dice4=tmp4;
        *dice6=tmp2;
    }
}


int main(void){
    int dice1, dice2, dice3, dice4, dice5, dice6, i, j, n, top, front;
    
    scanf("%d %d %d %d %d %d\n%d", &dice1, &dice2, &dice3, &dice4, &dice5, &dice6, &n);
    
    for(i=1; i<=n; i++){
        scanf("%d %d", &top, &front);
        if(front!=dice2){
            for(j=1; j<=6; j++){
                DICE('N', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(front==dice2) break;
            }
            if(front!=dice2){
                DICE('E', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
            }
            for(j=1; j<=6; j++){
                DICE('N', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(front==dice2) break;
            }
        }
        
        if(top!=dice1){
            for(j=1; j<=6; j++){
                DICE('E', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(top==dice1) break;
            }
        }
        
        printf("%d\n", dice3);
    }
    

    return 0;
    
}



Measured memory_bytes: 2104
n,m,v,p=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
ap=a[p-1]
iok=p-1
ing=n
while ing-iok>1:
  x=(ing+iok)//2
  if x<=p-1:
    iok=x
  else:
    if a[x]+m<ap:
      ing=x
    else:
      if (p-1+n-x)*m+(x-(p-1))*(a[x]+m)-sum(a[p-1:x])>=m*v:
        iok=x
      else:
        ing=x
print(iok+1)

Measured memory_bytes: 14484
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int N;
    string str;

    cin >> N >> str;

    int ans = 0;
    rep(i, N) {
        string a = str.substr(0, i), b = str.substr(i);

        int cnt[2][26] = { 0 };
        rep(j, a.size()) ++cnt[0][a[j]-'a'];
        rep(j, b.size()) ++cnt[1][b[j]-'a'];

        int tmp = 0;
        rep(j, 26) tmp += (cnt[0][j] > 0 && cnt[1][j] > 0 ? 1 : 0);
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vectors<decltype(inner)>(x, inner); }
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define MP make_pair
signed main(){
    int N; cin >> N;
    vector<int>v(N);
    vector<int>box(N,0);
    rep(i,N) cin >> v[i];
    int Q; cin >> Q;
    rep(i,Q){
        int t,x,d; cin >> t >> x >> d;
        if(t == 2){
            if(box[x-1]<d){ cout<<x<<endl;return 0;}
            else box[x-1] -= d;
        } else {
            if(box[x-1]+d>v[x-1]) {cout << x << endl;return 0;}
            else box[x-1]+=d;
        }
    }
    cout << 0 << endl;
    return 0;
}


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


namespace AtCoder.BeginnersSelections
{
    class Test
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int count = 0;

            for (int i = 0; i < n - 2; i++)
            {
                if (p[i] > p[i + 1] && p[i + 1] > p[i + 2] ||
                    p[i] < p[i + 1] && p[i + 1] < p[i + 2])
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13268
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Measured memory_bytes: 98604
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n) cin>>a.at(i);
  int ma=0;
  int sum=0;
  rep(i,n) ma=max(ma,a.at(i));
  rep(i,n)sum+=a.at(i);
  sum -= ma;
  if(ma < sum) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define nl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int n;
    cin>>n;
    int k;
    int sum=0;
    cin>>k;
    int arr[n];
    for(int i=0; i<n; i++)cin>>arr[i];
    sort(arr , arr+n);
    for(int i=0; i<k; i++)sum += arr[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 3656