akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int n, h;
int X[100010], Y[100010];

int get(int a, int c) {
	if(c == 0) return a;
	else return h + c;
}

int flip(int x){return x > h ? x - h : x + h; }

int p[110000], z[440], z2[440];
int cnt[420];
int Find(int x){return p[x] == x ? x : p[x] = Find(p[x]); }

void add(int x, int y) {
	x = Find(x), y = Find(y);
	if(x != y) p[x] = y, z2[y] += z2[x] + 1;
	else z2[x]++;
}

void solve(){
	scanf("%d%d", &n, &h);
	for(int i=1;i<=n+h+h;i++) p[i] = i;
	for(int i=1;i<=n;i++) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x = get(a, c);
		int y = get(b, d); y = flip(y);
		cnt[x]++; cnt[y]--;
		add(x, y);
	}
	for(int i=1;i<=h+h;i++) z[Find(i)] += abs(cnt[i]);
	for(int i=1;i<=h+h;i++) if(Find(i) == i && z[i] == 0 & z2[i] > 0) { puts("NO"); return; }
	for(int i=1;i<=h;i++) if(cnt[i] < 0) { puts("NO"); return; }
	for(int i=1;i<=h;i++) if(cnt[h+i] > 0) { puts("NO"); return; }
	puts("YES");
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		// printf("Case #%d: ", tc);
		solve();
	}
	return 0;
};


Measured memory_bytes: 768
N=int(input())
*A,=map(int,input().split())
A.sort()
A=A[::-1]
if N%2==0:
    ans=A[0]+sum(A[1:N//2])*2
else:
    ans=A[0]+sum(A[1:N//2])*2+A[N//2]
print(ans)

Measured memory_bytes: 31736
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

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

    int d = N%10;
    if(d==2 || d==4 || d==5 || d==7 || d==9) {
        cout << "hon" << endl;
    } else if(d==0 || d==1 || d==6 || d==8) {
        cout << "pon" << endl;
    } else cout << "bon" << endl;

    return 0;
}

Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = nextInt(scanner);
        int m = nextInt(scanner);
        int x = nextInt(scanner);
        int[] c = new int[n];
        int[][] a = new int[n][m];
        for (int i = 0; i < n; i++) {
            c[i] = nextInt(scanner);
            for (int j = 0; j < m; j++) {
                a[i][j] = nextInt(scanner);
            }
        }

        int finalPrice = -1;
        for (int i = 0; i < Math.pow(2, n); i++) {
            int[] points = new int[m];
            int price = 0;
            for (int j = 0; j < n; j++) {
                if ((1 & i >> j) == 1) {
                    for (int k = 0; k < m; k++) {
                        points[k] += a[j][k];
                    }
                    price += c[j];
                }
            }
            boolean isPass = true;
            for (int point: points) {
                if (point < x) {
                    isPass = false;
                    break;
                }
            }
            if (isPass) {
                if (finalPrice > price || finalPrice == -1) {
                    finalPrice = price;
                }
            }
        }
        System.out.println(finalPrice);
    }

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


Measured memory_bytes: 37012
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;

void main(){
    string input = readln.chomp;
    long keta = input.length.to!int;
    long max_keta_num = input[0].to!string.to!long;
    auto answer = input.all_nine ? 9L * (keta - 1L) + max_keta_num : 9L * (keta - 1L) + max_keta_num - 1L;
    writeln(answer);
}

bool all_nine(in string input){
    foreach(c; input[1..$]) {
        if(c != '9'){
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N ,M;
    cin >> N >> M;
    u_int ans = 0;
    for(int i = 0; i < N; i++){
        int k; cin >> k;
        u_int temp = 0;
        for(int j = 0; j < k; j++){
            int bit;
            cin >> bit;
            temp = temp | (1 << bit);
//            cout << temp << endl;
        }
        
        if(i == 0) ans |= temp;
        else ans &= temp;
//            cout << "ans" << ans << endl;
    }
    
    int count = 0;
//    printf("%d\n", ans);
    for(int k = 0; k <= M; k++){
        if( ans & (1 << k)){
            count++;
        }
    }

    cout << count << endl;        
}

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

int main(void){
    string s;
    string t;
    cin >> s;
    cin >> t;
    int count = 0;

    for(int i = 0; i < 3; i++){
        if(s[i] == t[3-i-1])
            count++;
    }
    if(count == 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys
input = sys.stdin.readline

# Union-Findデータ構造
class UnionFind:
    def __init__(self, numV):
        self.pars = list(range(numV))
        self.ranks = [0] * numV
    def find(self, x):
        if self.pars[x] == x: return x
        else:
            self.pars[x] = self.find(self.pars[x])
            return self.pars[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.ranks[x] < self.ranks[y]:
            self.pars[x] = y
        else:
            self.pars[y] = x
            if self.ranks[x] == self.ranks[y]:
                self.ranks[x] += 1
    def same(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

M = 10**5
UF = UnionFind(2*M)
for x, y in xys:
    x, y = x-1, y-1
    UF.union(x, y+M)

for x in range(2*M):
    UF.find(x)

cntX = Counter(UF.pars[:M])
cntY = Counter(UF.pars[M:])

ans = 0
for v in cntX.keys():
    ans += cntX[v] * cntY[v]

print(ans - N)


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int p=in.nextInt();
		int q=in.nextInt();
		int r=in.nextInt();
		int a=q+Math.min(p,r);
		int b=p+Math.min(q,r);
		int c=r+Math.min(p,q);
		System.out.println(Math.min(a,Math.min(b,c)));
	}
}
	

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

const int M=105;
int a[M];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n,greater<int>());
	for(int i=0;i<m;i++)
	{
		if(a[i]*4*m<sum)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
static const int INF = 999999;
int V, E;
struct SEdge
{
	int From;
	int To;
	int Cost;
};
vector<SEdge> Edge;

vector<int> par;
vector<int> rank;

void init(int n)
{
	par.clear();
	rank.clear();
	par.resize(n);
	rank.resize(n);
	for(int i = 0; i < n; ++i)
	{
		par[i] = i;
		rank[i] = 0;
	}
}

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

void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if(x == y)
	{
		return;
	}
	if(rank[x] < rank[y])
	{
		par[x] = y;
	}
	else
	{
		par[y] = x;
		if(rank[x] == rank[y])
		{
			++rank[x];
		}
	}
}

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

bool comp(const SEdge& e1, const SEdge& e2)
{
	return(e1.Cost < e2.Cost);
}

int Kruskal()
{
	init(V);
	sort(Edge.begin(), Edge.end(), comp);
	int res = 0;
	for(int i = 0; i < E; ++i)
	{
		SEdge e = Edge[i];
		if(!same(e.From, e.To))
		{
			unite(e.From, e.To);
			res += e.Cost;
		}
	}
	return(res);
}

void solve()
{
	while(cin >> V >> E, V || E)
	{
		Edge.clear();
		Edge.resize(E);
		for(int i = 0; i < E; ++i)
		{
			SEdge e;
			cin >> e.From >> e.To >> e.Cost;
			Edge[i] = e;
		}
		cout << Kruskal() << endl;
	}
}

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

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)

int n,S;

int main(){
	while (scanf("%d", &n), n){
		S = n;
		std::vector<int> num(n);
		rep(i, n)num[i] = i + 1;
		int s = 0, t = 0, sum = 0;
		int ans = 0;
		for (;;){
			while (t < n && sum < S){
				sum += num[t++];
			}
			if (sum < S) break;
			if(sum == S)ans++;
			//res = std::min(res, t - s);
			sum -= num[s++];
		}
		printf("%d\n", ans-1);
	}
	return 0;
}

Measured memory_bytes: 1032
#include<iostream>
#include<string>
#include<map>
using namespace std;
int StoI(string s)
{
	int r=0,i;
	for(i=0;i<s.size();++i)
		r=(r<<1)+s[i]-'0';
	return r;
}
int main()
{
	map<char,string> m1;
	m1[' ']="101";
	m1['\'']="000000";
	m1[',']="000011";
	m1['-']="10010001";
	m1['.']="010001";
	m1['?']="000001";
	m1['A']="100101";
	m1['B']="10011010";
	m1['C']="0101";
	m1['D']="0001";
	m1['E']="110";
	m1['F']="01001";
	m1['G']="10011011";
	m1['H']="010000";
	m1['I']="0111";
	m1['J']="10011000";
	m1['K']="0110";
	m1['L']="00100";
	m1['M']="10011001";
	m1['N']="10011110";
	m1['O']="00101";
	m1['P']="111";
	m1['Q']="10011111";
	m1['R']="1000";
	m1['S']="00110";
	m1['T']="00111";
	m1['U']="10011100";
	m1['V']="10011101";
	m1['W']="000010";
	m1['X']="10010010";
	m1['Y']="10010011";
	m1['Z']="10010000";
	char m2[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
	string s1,s2,s3;
	int i;

	while(getline(cin,s1))
	{
		s2=s3="";
		for(i=0;i<s1.size();++i)
			s2+=m1[s1[i]];
		s2.insert(s2.end(), (5-s2.size()%5)%5, '0');
		for(i=0;i<s2.size();i+=5)
			s3+=m2[ StoI(s2.substr(i,5)) ];
		cout << s3 << endl;
	}
	return 0;
}

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

int main()
{
	unordered_set<int> S;
	int C = 0;

	const auto f = [](const auto g) {
		int n, x;
		scanf("%d", &n);
		while (n--) {
			scanf("%d", &x);
			g(x);
		}
	};

	f([&](int x){S.emplace(x);});

	f([&](int x){if(S.find(x) != S.end()) C++;});

	printf("%d\n", C);
}



Measured memory_bytes: 6440
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    G = [list(map(int, readline().split())) for _ in range(N)]

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            needed = True
            for k in range(N):
                if k == i or k == j:
                    continue
                if G[i][j] > G[i][k] + G[k][j]:
                    print(-1)
                    return
                if G[i][j] == G[i][k] + G[k][j]:
                    needed = False
            if needed:
                ans += G[i][j]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 42332
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    char c; cin >> c;
    cout << (char)(c+1) << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 150;
int N, K, M;
int add(int a, int b) {return (a + b)%M;}
int mul(int a, int b) {return 1LL*a*b%M;}
int f[MAXN + 5][MAXN + 5];
void solve1() {
	K /= 2, f[0][0] = 1;
	for(int i=1;i<=N;i++) {
		for(int j=0;j<=K;j++)
			f[i][0] = add(f[i][0], f[i-1][j]);
		for(int j=0;j<K;j++)
			f[i][j+1] = add(f[i][j+1], f[i-1][j]);
	}
	int ans1 = 0, ans2 = 0;
	for(int i=0;i<=K;i++)
		ans1 = add(ans1, f[N/2][i]);
	for(int i=0;i<=K;i++)
		ans2 = add(ans2, f[(N+1)/2][i]);
	printf("%d\n", mul(ans1, ans2));
}
int g[2*MAXN + 5][MAXN + 5][MAXN + 5];
void solve2() {
	int p; g[0][0][0] = 1;
	for(int i=2;i-K<=N;i+=2) {
		for(int j=0;j<=N;j++)
			for(int k=0;k<=K+1;k++)
				g[i][0][0] = add(g[i][0][0], g[i-2][j][k]);
		if( i <= N ) {
			for(int j=0;j<=N;j++)
				for(int k=0;k<=K+1;k++)
					g[i][j+1][0] = add(g[i][j+1][0], g[i-2][j][k]);
		}
		if( i - K >= 1 ) {
			for(int j=0;j<=N;j++) {
				for(int k=1;k<=K;k++)
					g[i][0][k+1] = add(g[i][0][k+1], g[i-2][j][k]);
				g[i][0][0] = add(g[i][0][0], g[i-2][j][0]);
			}
		}
		if( i <= N && i - K >= 1 ) {
			for(int j=0;j<=N;j++)
				for(int k=0;max(k,j+1)<=K;k++)
					g[i][j+1][max(k+1,j+2)] = add(g[i][j+1][max(k+1,j+2)], g[i-2][j][k]);
		}
		p = i;
	}
	int ans = 0;
	for(int j=0;j<=N;j++)
		for(int k=0;k<=K+1;k++)
			ans = add(ans, g[p][j][k]);
	printf("%d\n", ans);
}
int main() {
	scanf("%d%d%d", &N, &K, &M);
	if( K % 2 == 0 ) solve1();
	else solve2();
}

Measured memory_bytes: 9228
#include<stdio.h>
#include<vector>
#include<set>
int main()
{
	int n,m,i,j,k;
	while(scanf("%d%d",&n,&m),n)
	{
		std::vector<std::vector<int> >v(n+1);
		for(i=0;i<m;++i)scanf("%d%d",&j,&k),v[j].push_back(k),v[k].push_back(j);
		std::set<int>s;
		for(i=0;i<v[1].size();++i)for(k=v[1][i],s.insert(k),j=0;j<v[k].size();++j)s.insert(v[k][j]);
		printf("%d\n",(i=s.size())>0?i-1:0);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int n;
	int max = -1;
	int max_num = -1;
	
	scanf("%d", &n);
	while (n-- > 0){
		int a, v;
		scanf("%d %d", &a, &v);
		
		if (max == -1 || max < v){
			max = v;
			max_num = a;
		}
		else if (max == v && max_num > a){
			max_num = a;
		}
	}
	printf("%d %d\n", max_num, max);
	
	return 0;
}

Measured memory_bytes: 600
# ABC133 D-Rain flows into dams

N = int(input())
A = list(map(int, input().split()))

X = [0]*(N+1) # ふった雨の量を入れるリスト
S = sum(A)
X[0] = S - 2*(sum(A[1::2]))
X[N] = X[0]
for i in range(N):
    if i == 0:
        continue
    else:
        X[i] = 2*A[i-1] - X[i-1]
        
print(*X[:N])

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

int main(){
    int N,M;
    while(1){
        cin >> N >> M;
        if(!N&&!M) return 0;
        int r;cin >> r;
        vector<vector<int>> T(M,vector<int> (1300,0));
        for(int i=0;i<r;i++){
            int t,n,m,s;cin >> t >> n >> m >> s;
            m--;
            if(s==1) T[m][t]++;
            else T[m][t]--;
        }
        for(int i=0;i<M;i++){
            for(int j=0;j<=1260;j++){
                T[i][j+1] += T[i][j];
            }
        }
        int q;cin >> q;
        for(int i=0;i<q;i++){
            int ts,te,m;cin >> ts >> te >> m;
            m--;
            int ans=0;
            for(int j=ts;j<te;j++){
                if(T[m][j]>=1) ans++;
            }
            cout << ans << endl;
        }
    }
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int r, d, x;
	cin >> r >> d >> x;
	FOR(it, 0, 10)
	{
		x = x * r - d;
		cout << x << endl;
	}
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}



int main(){
fastio();

   int cnt=0;
   map<ll,ll>mp;
     for(int i=1;i*i<=1e4;i++)
     {
         for(int j=1;j*j<=1e4;j++)
         {
             for(int k=1;k*k<=1e4;k++)
             {
                 ll temp=i*i+j*j+k*k+i*j+i*k+j*k;

                 mp[temp]++;


             }
         }
     }

     int n;
     cin>>n;

     for(int i=1;i<=n;i++)
        cout<<mp[i]<<endl;



return 0;
}


Measured memory_bytes: 6032
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n, a, b; readV(n, a, b);
  int[] h; readC(n, h);

  auto calc(int x)
  {
    auto t = h.dup;
    t[] -= b*x;
    auto y = t.filter!"a>0".map!(ti => (ti+a-b-1)/(a-b).to!long).sum;
    return y <= x;
  }

  auto bs = iota(1, (h.reduce!max+b-1)/b+1).map!(x => tuple(x, calc(x))).assumeSorted!"a[1] < b[1]";
  writeln(bs.upperBound(tuple(0, false)).front[0]);
}


Measured memory_bytes: 5244
#include<stdio.h>

#define LINE_MAX 6

int main(){
    char a[ LINE_MAX + 1 ];
    int m, m1, m2, m3;
    int c;

    m1 = m2 = m3 = 0;
    c = 0;

    while ( ( c < 10 ) && ( NULL != fgets( a, LINE_MAX, stdin ) ) ) {
        m = atoi( a );
        if ( m > m1 ) {
            m3 = m2;
            m2 = m1;
            m1 = m;
        }
        else {
            if ( m > m2 ) {
                m3 = m2;
                m2 = m;
            }
            else {
                if ( m > m3 ) {
                    m3 = m;
                }
            }
        }
        c ++;
    }

    printf( "%d\n%d\n%d\n", m1, m2, m3 );
    return 0;
}

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

int main()
{
  int A, B, unuse, count;
  unuse = 1;
  count = 0;
  cin >> A >> B;
  while(unuse < B){
    unuse--;
    unuse += A;
    count++;
  }  
  cout << count << endl;
}

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

using namespace std;

int main(){

  int n;
  cin>>n;
  
  int cost[n][3];
  for(int i=0;i<n;i++){cin>>cost[i][0]>>cost[i][1]>>cost[i][2];}
  
  int dp[n][3];
  dp[0][0] = cost[0][0];
  dp[0][1] = cost[0][1];
  dp[0][2] = cost[0][2];
  
  for(int i=1;i<n;i++){
  	dp[i][0] = cost[i][0] + max(dp[i-1][1],dp[i-1][2]);
    dp[i][1] = cost[i][1] + max(dp[i-1][0],dp[i-1][2]);
    dp[i][2] = cost[i][2] + max(dp[i-1][0],dp[i-1][1]);
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  
return 0;
}


Measured memory_bytes: 2560
def solve():
    import sys
    input = sys.stdin.readline

    class FenwickTree:
        def __init__(self, size):
            self.size = size
            self.array = [0]*size
    
        def add(self, index, value):
            while index < self.size:
                self.array[index] += value
                index += index&(-index)
    
        def sum(self, index):
            answer = 0
            while index > 0:
                answer += self.array[index]
                index -= index&(-index)
            return answer
    
        def rangesum(self, start, end):
            return self.sum(end)-self.sum(start-1)


    N, Q = map(int, input().split())
    *c, = map(int, input().split())
    tree = FenwickTree(N+1)
    m = [tuple(map(int, input().split()))+(i,) for i in range(Q)]
    m.sort(key=lambda x:x[1])

    right = 0
    pos = [-1] * (N+1)
    ans = [None] * (Q)

    for l, r, idx in m:
        for i in range(right, r):
            x = pos[c[i]]
            if x != -1:
                tree.add(x, -1)
            pos[c[i]] = i+1
            tree.add(i+1, 1)
        ans[idx] = tree.rangesum(l, r)
        right = r
    for i in ans:
        print(i)


solve()


Measured memory_bytes: 237028
n = int(input())
a = [int(i) for i in input().split()]

for i in range(n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print(" ".join(map(str, a)))

Measured memory_bytes: 7720
#include<bits/stdc++.h>
#include<iterator>
using namespace std;
typedef long long int lli;
lli n;
int main()
{
    vector<lli>v;
    cin >> n;
    for(lli i=0;i<n;i++)
    {
        lli k ;cin >>k;v.push_back(k);
    }
    vector<lli>sum1;
    sum1.push_back(0);
    for(lli i=1;i<=n;i++)
    {
        sum1.push_back(v[i-1] + sum1[i-1]);
    }
    lli dp[n+2][n+2];
    for(int i=0;i<=n+1;i++)
    {
        for(int j=0;j<=n+1;j++)
        {
            dp[i][j]=0;
        }
    }
    // fill(&dp[0][0] ,&dp[0][0] + sizeof(dp),0);
    for(int i=0;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(j+i <= n)
            {

                dp[j][j+i] = sum1[j+i] -sum1[j-1] - min(dp[j][j+i-1],dp[j+1][j+i]);  
                // cout << j <<" "<< i << " "<<sum1[j+i] <<" "<< sum1[j-1] <<" "<<dp[j][j+i-1] <<" "<<dp[j+1][j+i] <<"\n";
            }
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<=n;j++)
    //     {
    //         cout << dp[i][j]<<" ";
    //     }
    //     cout <<"\n";
    // }
    // cout << sum1[n] << dp[1][n] << endl;
    lli p =(sum1[n] - 2*dp[1][n]);p*=-1;
    cout << p <<"\n";
}

Measured memory_bytes: 70784
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var a, sum int
	for i := 0; i < m; i++ {
		fmt.Scan(&a)
		sum += a
	}

	if n-sum < 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(n - sum)
}


Measured memory_bytes: 2356
n = int(input())
v = list(map(int, input().split()))

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

ans = n - val0[0] - val1[0]

if key0[0] == key1[0]:
    tmp0=tmp1=1000000000000000
    if len(items0) > 1:
        tmp0 = n - val0[1] - val1[0]
    if len(items1) > 1:
        tmp1 = n - val0[0] - val1[1]
    ans = min(tmp0, tmp1)
    if len(items0) == 1 and len(items1) == 1:
        ans=n//2
print(ans)


Measured memory_bytes: 21212
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void){
    int n, i;
    double D, max = 0;
    int x[1001], y[1001];

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    for(i = 0; i < n; i++){
        scanf("%d", &y[i]);
    }
    
    D = 0;
    for(i = 0; i < n; i++){
        D += abs(x[i] - y[i]);
    }
    printf("%f\n", D);

    D = 0;
    for(i = 0; i < n; i++){
        D += pow(abs(x[i] - y[i]), 2);
    }
    printf("%f\n", sqrt(D));

    D = 0;
    for(i = 0; i < n; i++){
        D += pow(abs(x[i] - y[i]), 3);
    }
    printf("%f\n", pow(D, 1.0/3.0));

    for(i = 0; i < n; i++){
        if(max < abs(x[i] - y[i])) max = abs(x[i] - y[i]);
    }
    printf("%f\n", max);

    return 0;
}


Measured memory_bytes: 3368
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> d(N);  repp(i, 0, N) cin >> d[i];
    ll res = 0;
    repp(i, 0, N) {
        repp(j, i + 1, N) {
            res += d[i] * d[j];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	ll n,i;
   	cin >> n;
   	ll a[n],cnt=1;
   	for(i=0;i<n;i++) {
   		cin >> a[i];
   		if(a[i]==cnt) cnt++;
   	}
   	if(cnt>1)cout << n-cnt+1 << "\n";
   	else cout << -1 << "\n";
    return 0;
}



Measured memory_bytes: 1920
#include <cstdio>
#include <vector>

#define MOD 1000000007

typedef long long ll;

using namespace std;

vector<ll> d;

ll mulMod(ll a, ll b) { return a * b % MOD; }

ll powMod(ll n, ll r) {
    if (r == 0) return 1;
    if (r % 2) return mulMod(n, powMod(n, r - 1));
    ll temp = powMod(n, r / 2);
    return mulMod(temp, temp);
}

ll divMod(ll a, ll b) { return mulMod(a, powMod(b, MOD - 2)); }

ll combMod(ll n, ll r) { return divMod(d.at(n), mulMod(d.at(r), d.at(n - r))); }

int main() {
    ll h, w, a, b, ans = 0;
    scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
    d.resize(h + w);
    d.at(0) = 1;
    for (int i = 1; i < h + w; ++i) d.at(i) = mulMod(i, d.at(i - 1));
    for (ll i = 0; i < h - a; ++i) ans += mulMod(combMod(b - 1 + i, i), combMod(w - b - 1 + h - 1 - i, h - 1 - i)), ans %= MOD;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
b_li = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if i == 0:
        ans+=b_li[0]
    else:
        ans += min(b_li[i],b_li[i-1])
ans += b_li[len(b_li)-1]
print(ans)

Measured memory_bytes: 3060
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

al = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    al[a].append(b)
    al[b].append(a)

block = [[] for i in range(N+1)]
for i in range(K):
    c, d = map(int, input().split())
    block[c].append(d)
    block[d].append(c)

seen = [0 for i in range(N+1)]
num_connect = [0 for i in range(N+1)]
cluster = [0 for i in range(N+1)]

def bfs(u, c):
    visited = []
    stack = deque([u])
    seen[u] = 1
    count = 1

    while len(stack) > 0:
        v = stack.popleft()
        visited.append(v)
        cluster[v] = c
        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                count += 1
                seen[w] = 1

    for v in visited:
        num_connect[v] = count

c = 1
for i in range(1,N+1):
    if seen[i] == 0:
        bfs(i, c)
        c += 1

for i in range(1,N+1):
    bl = 0
    for d in block[i]:
        if cluster[i] == cluster[d]:
            bl += 1
    print(num_connect[i] - 1 - len(al[i]) - bl, end=" ")
print()


Measured memory_bytes: 128068
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (1LL<<61)

using namespace std;

typedef unsigned long long ull;

int main(void){
	
	int n;
	cin >> n;
	
	ull cost[4001];
	for(int i=0;i<n;i++){
		cin >> cost[i];
		if(i>0)cost[i]+=cost[i-1];
	}
	
	static ull dp[4001][4001],k[4001][4001];
	fill(dp[0],dp[4001],INF);
	
	for(int i=0;i<n;i++)dp[i][i]=0,k[i][i]=i;
	
	for(int w=1;w<=n;w++){
		for(int i=0,j=i+w;j<n;i++,j++){
			for(int r=k[i][j-1];r<=k[i+1][j];r++){
				ull c=dp[i][r]+dp[r+1][j]+cost[j]-((i>0)?cost[i-1]:0);
				if(dp[i][j]>c)dp[i][j]=c,k[i][j]=r;
			}
		}
	}
	cout << dp[0][n-1] << endl;
	
	return 0;
}

Measured memory_bytes: 251076
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string s = readln.chomp;
    string t = "CF";

    while (!t.empty) {
        if (s.empty) {
            writeln("No");
            return;
        }

        if (t.front == s.front) {
            t.popFront();
        }

        s.popFront();
    }

    writeln("Yes");
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
s=input()
a=int(s[0:2])
b=int(s[2:])
if 1<=a<=12 and 1<=b<=12:
    print('AMBIGUOUS')
elif 1<=b<=12:
    print('YYMM')
elif 1<=a<=12:
    print('MMYY')
else:
    print('NA')

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,a,n) for(int i = a ; i < (int)n ; i++)
typedef long long int ll;

int sign(int a){
    return a/abs(a);
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll a[100001];
int n;
cin>>n;

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

ll sum=0;
ll c=1;
ll c1=0,c2=0;
//奇数番目を正とする
rep(i,n){
    sum+=a[i];
    if(sum*c<=0){
        c1+=abs(sum)+1;
        sum=c;
    }
    c*=-1;
}
//奇数番目を偶数とする
c=-1;
sum=0;
rep(i,n){
    sum+=a[i];
    if(sum*c<=0){
        c2+=abs(sum)+1;
        sum=c;
    }
    c*=-1;
}
cout<<min(c1,c2)<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 1024
n = int(input())
txy = []
for _ in range(n):
    t, x, y = map(int, input().split())
    txy.append((t, x, y))
pt = px = py = 0
for t, x, y in txy:
    l = abs(x-px)+abs(y-py)
    if l>t-pt or (t-pt-l)%2==1:
        print('No')
        break
    pt, px, py = t, x, y
else:
    print('Yes')

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

int main()
{
	string S;
	int N;
	cin >> N >> S;
	int ans = 0;
	rep(i,N-2)
	{
		if (S.substr(i,3) == "ABC") ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int a,b;
    cin >> a >> b;
    
    cout << ((a*b));
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3656
S = [int(x) for x in list(input())]

min_0 = 0 # min_0 = 01010...
min_1 = 0 # min_1 = 10101...

for i in range(len(S)):
    if i % 2 ==0:
        if not (S[i] == 0):
            min_0 += 1
        else:
            min_1 += 1
    if i % 2 ==1:
        if not (S[i] == 1):
            min_0 += 1
        else:
            min_1 += 1
                
times = min([min_0, min_1])
print(times)


Measured memory_bytes: 4652
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , a[N] , b[N];

int main(){
  scanf("%d",&n);
  rep(i,0,n) scanf("%d%d",a+i,b+i);
  ll add = 0;
  per(i,0,n) {
    ll x = a[i] + add;
    x %= b[i];
    if(x) add += b[i] - x;
  }
  cout << add << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

// #define DEBUG 1
#define DFILE "t1.1"

long long bk(long long n) {}

int main() {
  long long int n;
  int i, j;

#ifdef DEBUG
#define cin fin
  fstream fin(DFILE);
#endif

  cin >> n;
  long long int m, r, md, acc, last;
  int c = 0;
  acc = 0;
  last = 0;
  for (r = 1; r < sqrt(n); r++) {
    if (n % r == 0) {
      m = n / r - 1;
      if (r < m) {
        acc += m;
      }
    }
  }
  cout << acc << endl;
  return 0;
}

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

int main() {
 string s;
 cin >> s;
 int sum = 0;

 if(s.at(0) == '1'){
     sum++;
 }
 if(s.at(1) == '1'){
     sum++;
 }
 if(s.at(2) == '1'){
     sum++;
 }

 cout << sum << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

constexpr int64_t INF = 10000000000; 

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

    vector<int64_t> A(N), B(N);
    int64_t sum = 0;
    int64_t bmin = INF;
    for(int i = 0; i < N; ++i){
        cin >> A[i] >> B[i];
        if(A[i] > B[i]){
            bmin = min(bmin, B[i]);
        }
        sum += A[i];
    }
    if(bmin != INF){
        cout << sum - bmin << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  
  long long n;
  cin>>n;
  long long a[n];
  long long b[n];
  bool flag = true;
  for(long long i=0;i<n;i++){
    cin>>a[i];
    b[i] = i-a[i];
    if(b[i]<0 || b[i]>i)flag = false;
  }
  for(long long i=1;i<n;i++){
    if(b[i-1]>b[i])flag = false;
  }
  if(!flag){
    cout<<-1<<endl;
    return 0;
  }
  long long temp=-1;
  long long ans=0;
  for(long long i=n-1;i>=0;i--){
    if(temp==b[i])continue;
    temp = b[i];
    ans += i-b[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;
int main() {
    int N;
    string S;
    cin >> N >> S;
    ll count_R = 0, count_G = 0, count_B = 0;
    rep(i, 0, N){
        if(S[i] == 'R') count_R++;
        if(S[i] == 'G') count_G++;
        if(S[i] == 'B') count_B++;
    }
    ll ans = count_R*count_G*count_B;
    rep(i, 0, N){
        rep(k, i+1, N){
            int j = k + (k-i);
            if(j >= N) continue;
            if(S[i] != S[k] && S[i] != S[j] && S[k] != S[j]) ans--;
        }
    }
    cout << ans << endl;
}

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


int main(void){
  int x,y;
  char x_ans='a',y_ans='a';

  cin>>x>>y;
  int a=(1,3,5,7,8,10,12);
  int b=(4,6,9,11);
  int c=(2);


    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)x_ans='b';
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)y_ans='b';

  if(x==2)x_ans='c';
  if(y==2)y_ans='c';

  if(x_ans==y_ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

students = [[(i+1)] for i in range(N)]

A = list(map(int, input().split()))
for i in range(N):
    students[i].append(A[i])

students.sort(key=lambda x: x[1])

ans = ""
for student in students:
    ans += str(student[0]) + " "
    
ans = ans.rstrip()

print(ans)

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

int main(){
  int n;cin>>n;
  int lim = pow(n,0.5);
  int ans = 0;
  if(n<4)ans = n;
  for(int i=2;i<=lim;i++){
    for(int j=2;(int)pow(i,j)<=n;j++){
      ans = max((int)pow(i,j),ans);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
x = []
y = []
#z不要

for _ in range(m):
    X,Y,Z = map(int, input().split( ))
    x.append(X-1)
    y.append(Y-1)

UF = [i for i in range(n)]

for i in range(m):
    xi = x[i]
    yi = y[i]
    xL = [xi]
    yL = [yi]
    root_x = UF[xi]
    root_y = UF[yi]
    while root_x != xi:
        xi = root_x
        root_x = UF[xi]
        xL.append(xi)
    while root_y != yi:
        yi = root_y
        root_y = UF[yi]
        yL.append(yi)
    if xi!=yi:
        for xs in xL:
            UF[xs] = yi
ans = 0
for i in range(n):
    if UF[i] == i:
        ans += 1
print(ans)

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

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) <<  " " <<max((long long)0,a+b-n) << endl;
    cin >> n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
#define N 100005
string s;
ll n;
ll dp[N][15];
ll a[N];
ll solve(ll index,ll rem)
{
     if(index==n+1)
     {
          if(rem%13 ==5)   return 1;
          else         return 0;
     }
     ll ans = dp[index][rem];
     if(ans!=-1)    return ans;
     ans = 0;
     if(s[index]!='?')  
     {
          ll temp = (rem + a[n-index]*(s[index]-'0'))%13;
          ans += solve(index+1,temp);
          ans %= MOD;
     }
     else
     {
          for(ll i=0;i<10;i++)
          {
               ll temp = (rem + (i*a[n-index]))%13;
               ans += solve(index+1,temp);
               ans %= MOD;
          }
     }
     return dp[index][rem] = ans;
}
int main()
{
    a[0] = 1;
    ll x = 10;
    for(ll i=1;i<N;i++,x = (x*10)%13)   a[i] = x%13;
    cin>>s;
    n=s.size();
    s = '0' + s;
    memset(dp,-1,sizeof(dp));
    ll final = solve(0,0);
    cout<<final;
}

Measured memory_bytes: 19324
# coding: utf-8
s='+'.join(list(input()))
ans=0
memo=set()
def check(w,n):
    global ans
    if w in memo:
        return
    memo.add(w)
    ans+=eval(w)
    for i in range(1,n+1):
        count=0
        for j in range(len(w)):
            if w[j]=='+':
                count+=1
                if count==i:
                    check(w[:j]+w[j+1:],n-1)

check(s,(len(s)-1)//2)
print(ans)

Measured memory_bytes: 3064
import math
import decimal
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

class Library():
    @staticmethod
    def Swap(a,b):
        return [b,a]

    @staticmethod
    def myRound(a,dig=0): # 四捨五入
        p = 10 ** dig
        return (a * p * 2 + 1) // 2 / p

    @staticmethod
    def Roundup(a,dig=0): # 切り上げ
        if a < 0:
            return int(a)
        else:
            return int(a + 0.9)

    @staticmethod
    def Gcd(a,b): #最大公約数
        if (a<b):
            a,b = Library.Swap(a,b)
        if (b==0):
            return a
        else:
            return Library.Gcd(b,a%b)

    @staticmethod
    def Lcm(a,b): #最小公倍数
        return a//Library.Gcd(a,b)*b

    @staticmethod
    def Divisors(a): # 約数列挙
        divisors = []
        for i in range(1,int(a**0.5)+1):
            if a%i==0:
                divisors.append(i)
                if i!=a//i:
                    divisors.append(a//i)
        divisors.sort()
        return divisors

class Prime():
    # コンストラクタ
    # エラストテネスの篩
    def __init__(self,num):
        self.num = num
        self.sieve = [0] * (self.num + 1)
        self.sieve[0] = -1
        self.sieve[1] = -1
        for i in range(2,self.num + 1):
            if not self.sieve[i]:
                self.sieve[i] = i
                for j in range(i * i,self.num + 1,i):
                    if self.sieve[j]:
                        self.sieve[j] = i
    
    # 素数判定
    def isPrime(self,num = None):
        if num is None:
            num = self.num
        if self.sieve[num] == num:
            return True
        else:
            return False
    
    # 素数列挙
    def PrimeNum(self,num = None):
        if num is None:
            num = self.num
        prime = []
        for i in range(2,num):
            if self.sieve[i] == i:
                prime.append(i)
        return prime
    
    # 素因数分解
    def PrimeFact(self,num = None):
        if num is None:
            num = self.num
        fact = []
        while self.sieve[num] != num:
            fact.append(self.sieve[num])
            num //= self.sieve[num]
        fact.append(num)
        return fact

def main():
    s = input()
    for i in range(len(s) - 1):
        if s[i] == 'A' and s[i + 1] == 'C':
            print('Yes')
            return
    print('No')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 59340
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

std::pair<int, int> dfs(int i, int prev, int n, const std::vector<int>& A, std::vector<int>& memo)
{
  if(0 <= memo[i])
  {
    return {i, prev};
  }
  memo[i] = n;
  return dfs(A[i], i, n + 1, A, memo);
}

int dfs1(int i, int n, const std::vector<int>& A)
{
  if(n == 0)
    return i;
  return dfs1(A[i], n - 1, A);
}

int main()
{
  long long N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  for(auto& val: A)
  {
    std::cin >> val;
    --val;
  }
  std::vector<int> memo(N, -1);
  auto p = dfs(0, 0, 0, A, memo);
  int i = p.first;
  int j = p.second;
  int d = memo[i];
  if(K <= d)
  {
    std::cout << dfs1(0, K, A) + 1 << std::endl;
    return 0;
  }
  K -= d;
  long long l = memo[j] - memo[i] + 1;
  if(l == 1)
  {
    std::cout << i + 1 << std::endl;
    return 0;
  }
  K %= l;
  std::cout << dfs1(i, K, A) + 1 << std::endl;
  return 0;
}



Measured memory_bytes: 4776
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for k in range(w):
            if i == 0 or i == h - 1 or k == 0 or k == w - 1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a < 10 && b < 10) cout << a * b;
	else cout << -1;
}

Measured memory_bytes: 256