akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		boolean[] h2 = new boolean[h];
		boolean[] w2 = new boolean[w];
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			String s = sc.next();
			a[i] = s;
			if (s.contains("#")) {
				h2[i] = true;
			}
			
			for (int j = 0; j < s.length(); j++) {
				if (s.charAt(j) == '#') {
					w2[j] = true;
				}
			}
		}
		
		for (int i = 0; i < h; i++) {
			if (h2[i]) {
				for (int j = 0; j < w; j++) {
					if (w2[j]) {
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 24404
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
int main()
{
	int N, bits = 0;
	cin >> N;
	vector<int>v(N);
	for (auto&i : v) {
		cin >> i;
		bits ^= i;
	}
	for (auto i : v) {
		cout << (bits^i) << " ";
	}
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
using namespace std;
string A;
int len,cnt[30];
long long Ans;
int main()
{
	cin>>A;
	len=A.length();
	Ans=1ll*(len-1)*len/2;
	for(int i=0;i<len;i++)cnt[A[i]-'a']++;
	for(int i=0;i<26;i++)
	{
		Ans-=1ll*(cnt[i]-1)*cnt[i]/2;
	}
	cout<<Ans+1;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    if(K > (N-1)*(N-2)/2){
        cout << -1 << endl;
        return 0;
    }
    // if(K < N-1){
    //     cout << -1 << endl;
    // }

    cout << N-K+(N-1)*(N-2)/2 - 1 << endl;
    
    for(ll i=2; i<=N; i++){
        cout << 1 << " " << i << endl;
    }
    ll count = (N-1)*(N-2)/2;
    for(ll i=2; i<= N-1; i++){
        for(ll j=i+1; j<=N; j++){
            if(count == K){
                return 0;
            }
            cout << i << " " << j << endl;
            count--;
        }
    }
    return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  
  if (A + B < C + D) {
    cout << "Right" << endl;
  }  
}


Measured memory_bytes: 256
#include<stdio.h>


int main(void)
{

   int a[100], i, n, min, max;

   scanf("%d", &n);
   for(i=0;i<n;i++)
      scanf("%d", &a[i]);

   max=a[0]; min=a[0];

   for(i=1;i<n;i++){
      if(a[i]>max) max=a[i];
      else if(a[i]<min) min=a[i];
      }

   printf("%d", max-min);
   return 0;
}

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

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

#define INF (1e9)
int main() {
    int A, B, Q;
    cin >> A >> B >> Q;

    vi s(A), t(B), x(Q);
    for (int i = 0; i < A; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> x[i];
    }

    for (int i = 0; i < Q; i++) {
        ll ans = INF * INF;
        ll _x = x[i];

        auto y = lower_bound(s.begin(), s.end(), _x);
        auto z = lower_bound(t.begin(), t.end(), _x);

        // stx
        if (y > s.begin() and z > t.begin())
            ans = min(ans, max(_x - *(y - 1), _x - *(z - 1)));

        // sxt
        if (y > s.begin() and z < t.end())
            ans = min(ans, min(_x - 2 * *(y - 1) + *z, 2 * *z - _x - *(y - 1)));

        // txs
        if (y < s.end() and z > t.begin())
            ans = min(ans, min(_x - 2 * *(z - 1) + *y, 2 * *y - _x - *(z - 1)));

        // xst
        if (y < s.end() and z < t.end())
            ans = min(ans, max(*y - _x, *z - _x));

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
#
# abc176 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """20 12 6"""
        output = """12"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1000 1 1000"""
        output = """1000000"""
        self.assertIO(input, output)


def resolve():
    N, X, T = map(int, input().split())
    print((N+X-1)//X * T)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds; 
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int h[505][505];
bool s[505][505];
int n;
bool valid(int x, int y){
	return (x >= 0) && (x < n) && (y >= 0) && (y < n);
}
void ff(int x, int y){
	for (int d = 0; d < 4; d++){
		int nx = x + dx[d], ny = y + dy[d];
		if (!valid(nx, ny)) continue;
		if (h[nx][ny] > h[x][y] + s[x][y]){
			h[nx][ny] = h[x][y] + s[x][y]; ff(nx, ny);
		}
	}
}
int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			h[i][j] = min(min(i, n - 1 - i), min(j, n - 1 - j)); s[i][j] = 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < n * n; i++){
		int id; cin >> id; id--; 
		int x = id / n, y = id % n;
		s[x][y] = 0; ans += h[x][y]; ff(x, y);
	}
	cout << ans << endl;
}

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

int main()
{
    ll n;
    cin>>n;
    //cout<<n%26<<" "<<n/26;
    string s="";
    if(n>=1 && n<=26) s+='a'+n-1;
    else
    {
        while(n)
        {
            int t=n%26;
            if(t==0)
                t=26;
            s+='a'+t-1;
            n-=t;
            n/=26;

            //cout<<t<<" "<<s<<" "<<n<<endl;
        }

    }
    reverse(s.begin(),s.end());
cout<<s<<endl;
    //main();

}


Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            for (int i = 1; i <= Math.min(9, N); i++) {
                if (N % i == 0 && N / i < 10) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }
}



Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
int h[201];

struct edge{
	int f,t,c;
	edge(){}
	edge(int ff,int tt,int cc){
		f=ff;
		t=tt;
		c=cc;
	}
	bool operator<(const edge& e1)const{
		return c<e1.c;
	}
};

int par[1001],rank[1001];

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

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

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

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

int main(void){
	while(1){
		scanf("%d %d",&n,&m);
		if(n+m==0)break;
		init();
		vector<int> index;
		for(int i=0;i<n;i++){
			scanf("%d",&h[i]);
			index.push_back(h[i]);
		}
		sort(index.begin(),index.end());
		index.erase(unique(index.begin(),index.end()),index.end());
		int land=0;
		for(int i=0;i<n;i++){
			h[i]=lower_bound(index.begin(),index.end(),h[i])-index.begin();
			if(h[i]==index.size()-1)land=i;
		}
		vector<edge> G;
		for(int j=0;j<m;j++){
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			a--;
			b--;
			G.push_back(edge(a,b,c));
		}
		sort(G.begin(),G.end());
		int last=index.size();
		for(int i=index.size()-1;i>=0;i--){
			for(int j=0;j<m;j++){
				if(h[G[j].f]<i || h[G[j].t]<i)continue;
				if(!same(G[j].f,G[j].t))unite(G[j].f,G[j].t);
			}
			bool flag=true;
			for(int j=0;j<n;j++){
				if(!same(land,j) && h[j]>=i)flag=false;
			}
			if(!flag)last=i;
		}
		if(last==0){
			printf("0\n");
		}else{
			init();
			int res=0;
			for(int i=last-1;i>=0;i--){
				for(int j=0;j<m;j++){
					if(h[G[j].f]<i || h[G[j].t]<i)continue;
					if(!same(G[j].f,G[j].t)){
						unite(G[j].f,G[j].t);
						res+=G[j].c;
					}
				}
			}
			printf("%d\n",res);
		}
	}
	return 0;
}

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

typedef long long ll;

template <typename T>
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s) {
    const auto INF = numeric_limits<T>::max();
    vector<T> dist(g.size(), INF);

    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while (!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if (dist[idx] < cost) continue;
        for (auto &e : g[idx]) {
            auto next_cost = cost + e.cost;
            if (dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main() {
    int V, E, r;
    cin >> V >> E >> r;
    WeightedGraph<ll> G(V);
    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s].emplace_back(t, d);
    }
    const ll INF = numeric_limits<ll>::max();
    vector<ll> dist = dijkstra(G, r);
    for (int i = 0; i < V; i++) {
        if (dist[i] == INF)
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
}


Measured memory_bytes: 19400
def gcd(a, b)
	b == 0 ? a: gcd(b, a % b)
end

def pd(n)
	results = []
	i = 2
	while i * i <= n
		if n % i == 0 then
			n = n.div(i)
			results.push(i)
		else
			i = i + 1
		end
	end
	if n != 1 then
		results.push(n)
	end
	return results
end

a, b = gets.chomp.split(" ").map(&:to_i)
d = gcd(a, b)
results = pd(d)
p results.uniq.length + 1


Measured memory_bytes: 1788
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int N;
    long long A[200010];
    
    // 入力
    cin >> N;
    for (int i=0;i<N;i++) cin >> A[i];
    
    long long total = 0;
    for (int i=0;i<N;i++) {
        total += A[i];
    }
    
    
    //cout << total << endl;
    
    long long now = 0;
    long long length_before, length_after;
    for (int i=0;i<N;i++) {
        now += A[i];
        if (now*2 >= total) {
            length_after = 2*now - total;
            length_before = 2*A[i] - length_after;
            break;
        }
    }
    

    
    cout << min(length_after,length_before) << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

#define N 100000

//UnionFind木
int parent[N];
void init(int n) {
  for (int i=0; i<n; i++) parent[i] = -1;
}
int root(int a) {
  if (parent[a] < 0) return a;
  else return parent[a] = root(parent[a]);
}
int size(int a) {
  return -parent[a];
}
void unite(int a, int b) {
  int ra=root(a), rb=root(b);
  if (ra == rb) return ;
  if (size(ra) > size(rb)) {
    parent[ra] += parent[rb];
    parent[rb] = ra;
  } else {
    parent[rb] += parent[ra];
    parent[ra] = rb;
  }
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int p[n], x, y;
  for (int i=0; i<n; i++) scanf("%d", p+i);
  init(n);
  for (int i=0; i<m; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    unite(x, y);
  }
  int ans=0;
  for (int i=0; i<n; i++) {
    if (root(i) == root(p[i]-1)) ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 896
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

map<int, int> mp[2];
int a[N];

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		mp[i & 1][a[i]]++;
	}
	vector<pii> v[2];
	v[0].pb({0, -1});
	v[1].pb({0, -2});
	for (int j = 0; j < 2; ++j) {
		for (auto &i : mp[j]) {
			v[j].pb({i.second, i.first});
		}
	}
	sort(v[0].begin(), v[0].end(), greater<pii>());
	sort(v[1].begin(), v[1].end(), greater<pii>());
	int ans = n - v[0][0].first - v[1][0].first;
	if (v[0][0].second == v[1][0].second) {
		ans -= max(v[0][1].first - v[0][0].first, v[1][1].first - v[1][0].first);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6524
/*
 Akhil Saini
 DP : Atcoder DP Series Problem 1 : Frog 1
*/
#include<bits/stdc++.h>
using namespace std;
#define f0(i,n)            for(i=0;i<n;i++)
#define flast(i,n)         for(i=n-1;i>=0;i--)
#define f1(i,n)            for(i=1;i<=n;i++)
#define f(i,a,n)           for(i=a;i<=n;i++)
#define fit(v)             for(auto itr=v.begin();itr!=v.end();itr++)
#define ump(a,b)           unordered_map<a,b>
#define ll                 long long int
#define endl               "\n"
#define fir                first
#define sec                second
#define pb                 push_back
#define bp                 __builtin_popcount
#define bit()              bitset<62>(x).to_string()
#define binstr_to_num(x)   stoll(x,nullptr,2)
#define mod                1000000007
#define inf                1e18+1
#define all(v)             v.begin(),v.end()
#define debug              cout<<"Hello"<<endl
typedef                    vector<ll> vll;
const double pi=acos(-1.0);

//You can only take 1 or 2 steps then in
//how many ways you can reach to the nth stairs.

ll dp[100001],k;
vector<ll> v;

//Function to store ans of each stairs. 
ll dp_function(ll n)
{
    if(n==0)
    return 0;
    if(n==1)
    return abs(v[0]-v[1]);

    if(dp[n]!=-1) return dp[n];

    ll mini=inf,xx,i;
    f1(i,k)
    {
        if(n-i>=0)
        mini=min(mini,dp_function(n-i)+abs(v[n-i]-v[n]));
    }

    dp[n]=mini;//min(dp_function(n-1)+abs(v[n-1]-v[n]),dp_function(n-2)+abs(v[n-2]-v[n]));
    return dp[n];
}

void solve()
{
    ll n,x,i;
    cin>>n>>k;
    v.clear();
    f0(i,n) { cin>>x; v.push_back(x); }
    dp[1]=abs(v[1]-v[0]);
    cout<<dp_function(n-1)<<endl;
    //f0(i,n) cout<<dp[i]<<" ";
}

void fast()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int main()
{
    fast();
    int t=1,i;
    //cin>>t;
    while(t--)
    {
        f1(i,100000) dp[i]=-1;
        solve();
    }
    return 0;
}

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

void chmax(ll &a, ll b) { if (a < b) a = b; return; }
using pll = pair<ll,ll>;

int main() {
    int n; cin >> n;
    vector<pll> a(n); rep(i,n) cin >> a[i].first, a[i].second = i;
    sort(all(a),greater<pll>());

    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    rep(i,n) rep(j,n-i){
        chmax(dp[i+1][j], dp[i][j] + a[i+j].first * (a[i+j].second - i));
        chmax(dp[i][j+1], dp[i][j] + a[i+j].first * ((n-1-j) - a[i+j].second));
    }
    ll ans = 0;
    rep(i,n+1) chmax(ans, dp[i][n-i]);
    cout << ans << endl;
}

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	set<string> ans;
	string s;
	cin >> s;
	int K;
	cin >> K;
	for (int i(0); i < s.size(); ++i)
	{
		string cur = "";
		for (int j(i); j < s.size(); ++j)
		{
			cur += s[j];
			ans.insert(cur);
			if (ans.size() > K)
				ans.erase(--ans.end());
		}
	}
	cout << *ans.rbegin() << endl;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int ans = 0;
    if( a + b + 1 < c )
        ans = a + b + 1 + b;
    else
        ans = b + c;

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

Measured memory_bytes: 256
import collections
n = int(raw_input())
mod = ( 10 ** 9 ) + 7
def f(u):
	cu = collections.Counter()
	cur = 2
	while(u != 1):
		if u % cur == 0:
			while(u % cur == 0):
				cc[cur] +=1
				u/= cur
		cur +=1
	return cu
cc = collections.Counter()
for u in range(2, n + 1):
	for k,v in f(u).iteritems(): cc[k]+=cu[k]
ans = 1
for k in cc:
	ans *= (cc[k] + 1) 
	ans %= mod
print ans

Measured memory_bytes: 72128
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

nums = np.array(read().split(), np.int64)

A = nums[:9]

for x in nums[10:]:
    A[A == x] = 0

def check(A):
    for i, j, k in ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7),
                    (2, 5, 8), (0, 4, 8), (2, 4, 6)):
        if A[i] == A[j] == A[k] == 0:
            return True
    return False

print('Yes' if check(A) else 'No')

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> t(n);
	rep(i, n) cin >> t[i];
	int m;
	cin >> m;
	rep(i, m) {
		int p, x;
		cin >> p >> x;
		p--;
		int temp = t[p];
		t[p] = x;
		int sum = 0;
		rep(j, n) sum += t[j];
		cout << sum << endl;
		t[p] = temp;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
char a[10][10];
int h,w;
signed main() {
    cin >> h >> w;
    rep(i,h) {
        string s;
        cin >> s;
        rep(j,w) {
            a[i][j]=s[j];
        }
    }
    rep(i,h) {
        rep(j,w) {
            if(a[i][j]=='#') {
                bool f = true;
                FOR(k,i+1,h) {
                    rep(l,j) {
                        if(a[k][l]=='#') {
                            //cout << k<<" "<<l << endl;
                            f = false;
                        }
                    }
                }
                if(!f) {
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
    }
    
    cout << "Possible" << endl;
    return 0;
}



Measured memory_bytes: 3592
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;

#define INF 1000000000000
#define MOD 10000007
//#define int long long
#define pb push_back

void YesNo(bool b) { b ? cout << "Yes" << endl : cout << "No" << endl; return; }
void YESNO(bool b) { b ? cout << "YES" << endl : cout << "NO" << endl; return; }
void yesno(bool b) { b ? cout << "yes" << endl : cout << "no" << endl; return; }

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

Measured memory_bytes: 3596
n=int(input())
tsk=[]
for i in range(n):
  a,b=list(map(int,input().split()))
  tsk.append([b,a])
tsk.sort()
tot=0
r="Yes"
for i in range(n):
  tot += tsk[i][1]
  if tot > tsk[i][0]:
    r="No"
    break
print(r)

Measured memory_bytes: 37716
#include<bits/stdc++.h>
using namespace std;
 
main(){
 
    int n,m,d,count=0,left,right,up,down;
    
    scanf("%d %d %d",&n,&m,&d);
    
    char table[110][110];
 
    for(int i=0;i<n;i++)
	{
        scanf("%s",table[i]);
    }
 
 	for(int i=0;i<n;i++)
	{

        for(left=0;left<m && table[i][left]=='#';left++);
 
   //     if(left==m)continue;
 
       	for(;;)
		{
            for(right=left;right<m && table[i][right]!='#';right++);
            
            if(right-left>=d)
			{
                count+=(right-left-d+1);
            }
 
            if(right==m) break;
			
            for(left=right+1;left < m && table[i][left] == '#';left++);
            
            if(left==m)break;
        }
        
    }
 	
 	
    for(int i=0;i<m;i++)
	{
 
        for(up=0;up<n && table[up][i]=='#';up++);
 
  //      if(up==n)continue;
 
        for(;;)
		{
            for(down=up;down<n && table[down][i]!='#';down++);
            
            if(down-up>=d)
			{
                count+=(down-up-d+1);
            }
 
            if(down==n) break;
            for(up=down+1;up<n && table[up][i]=='#';up++);
            
            if(up==n) break;
        }
    }
 
 
    printf("%d\n",count);
}


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

using namespace std;

#define MAX_N 10000 + 1

int n, m, a;
string dp[MAX_N];
map<int, char> cvmap; // cvmap[cost] = value;

int getCost(const char value)
{
    switch (value)
    {
    case '1':
        return 2;
    case '7':
        return 3;
    case '4':
        return 4;
    case '2':
    case '3':
    case '5':
        return 5;
    case '6':
    case '9':
        return 6;
    case '8':
        return 7;
    default:
        return 0;
    }
}

void inputCVMap(const char value)
{
    int c = getCost(value);
    if (cvmap.count(c) == 0 || (cvmap.count(c) > 0 && cvmap[c] < value))
        cvmap[c] = value;
}

string cmp(string &a, string &b)
{
    // sort(a.begin(), a.end(), greater<char>());
    // sort(b.begin(), b.end(), greater<char>());

    if (a.size() < b.size())
        return b;
    else if (a.size() > b.size())
        return a;

    return a < b ? b : a;
}

void printans()
{
    sort(dp[n].begin(), dp[n].end(), greater<char>());
    cout << dp[n] << "\n";
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int a;
        scanf("%d", &a);
        inputCVMap(a + '0' - 0);
    }

    // Initialize
    for (auto cvp : cvmap)
    {
        dp[cvp.first] += cvp.second;
    }

    for (int i = 1; i <= n; i++)
    {
        if (dp[i] == "")
            continue;

        for (auto cvp : cvmap)
        {
            if (i + cvp.first <= n)
            {
                string v = dp[i];
                v += cvp.second;
                dp[i + cvp.first] = cmp(dp[i + cvp.first], v);
            }
        }
    }

    printans();
    return 0;
}


Measured memory_bytes: 44928
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);++(i))
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);--(i))
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();

int main(){
    int n, p;
    cin >> n >> p;
    int e = 0, o = 0;
    REP(i,0,n){
        int a;
        cin >> a;
        if (a % 2) o++;
        else e++;
    }

    ll ans = 1;
    if (o == 0){
        if (p == 1) cout << 0 << endl;
        else{
            REP(i,0,n){
                ans *= 2;
            }
            cout << ans << endl;
        }
        return 0;
    }else{
        REP(i,0,n - 1){
            ans *= 2;
        }
        cout << ans << endl;
        return 0;
    }

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
double rota = M_PI * 60.0 / 180.0;//旋转的角度
struct Point{
	double x,y;
};

void printPoint(Point* p){
	printf("%.8f %.8f\n", p->x,p->y);
}

void koch(int n, Point *p1,Point *p2){
	if(n-- == 0)return;
	Point koch1,koch2,koch3;
	koch1.x = (2 * p1 -> x + p2 -> x) / 3;
	koch1.y = (2 * p1 -> y + p2 -> y) / 3;
	koch3.x = (2 * p2 -> x + p1 -> x) / 3;
	koch3.y = (2 * p2 -> y + p1 -> y) / 3;
	koch2.x = (koch3.x - koch1.x) * cos(rota) - (koch3.y - koch1.y) * sin(rota) + koch1.x;
	koch2.y = (koch3.x - koch1.x) * sin(rota) + (koch3.y - koch1.y) * cos(rota) + koch1.y;
	koch(n, p1, &koch1);
	printPoint(&koch1);
	koch(n, &koch1, &koch2);
	printPoint(&koch2);
	koch(n, &koch2, &koch3);
	printPoint(&koch3);
	koch(n, &koch3, p2);
}

int main(){
	int n;
	Point p1,p2;
	p1.x=0.0;p1.y=0.0;
	p2.x=100.0;p2.y=0.0;
	scanf("%d", &n);
	printPoint(&p1);
	koch(n,&p1,&p2);
	printPoint(&p2);
	scanf("%d", &n);
	return 0;
}


Measured memory_bytes: 2916
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	LL n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

using namespace std;

int main()
{
    int n,M,k,a;
    cin>>n>>M;
    unordered_map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        for(int j=0;j<k;j++)
        {
            cin>>a;
            m[a]++;
        }
    }
    int ans=0;
    for(auto it=m.begin();it!=m.end();it++)
    {
        if(it->second==n)
            ans++;
    }
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 18;
int n, a[maxn * 2 + 10], cnt[26];
typedef long long ll;
ll ans;

map<pair<ll, ll>, int> mp;

ll hsh(const vector<int> &p) {
	ll now = 0;
	for (int i = 0; i < p.size(); ++i)
		now = now * 131 + p[i];
	return now;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n * 2; ++i) {
		char c = getchar();
		while (!isgraph(c)) c = getchar();
		++cnt[c]; a[i] = c;
	}
	for (int i = 0; i < 1 << n; ++i) {
		vector<int> fir, sec;
		for (int j = 1; j <= n; ++j)
			if (i >> (j - 1) & 1) fir.push_back(a[j]);
			else sec.push_back(a[j]);
		++mp[make_pair(hsh(fir), hsh(sec))];
	}
	for (int i = 0; i < 1 << n; ++i) {
		vector<int> fir, sec;
		for (int j = 1; j <= n; ++j)
			if (i >> (j - 1) & 1) fir.push_back(a[j + n]);
			else sec.push_back(a[j + n]);
		reverse(fir.begin(), fir.end());
		reverse(sec.begin(), sec.end());
		ans += mp[make_pair(hsh(fir), hsh(sec))];
	}
	printf("%lld", ans);
	
}

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

int main() {
    int n, m, a[100005], b, c, x=0;
    long long ans=0;
    cin >> n >> m;
    for(int i=0; i<n; i++) cin >> a[i];
    vector<pair<int, int>> s(m);
    for(int i=0; i<m; i++) {
        cin >> b >> c;
        s[i]=make_pair(c, b);
    }
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());

    priority_queue<int, vector<int>, greater<int>> pq;
    while(pq.size()<n) {
        b=s[x].first;
        c=s[x].second;
        pq.push(b);
        s[x].second--;
        if(s[x].second==0) x++;
        if(x==m) break;
    }

    for(int i=0; i<n; i++) {
        if(pq.size()<n) {
            pq.push(a[i]);
        }
        else if(pq.top()<a[i]) {
            pq.pop();
            pq.push(a[i]);
        }
    }
    while(!(pq.empty())) {
        ans+=pq.top();
        pq.pop();
    }
    cout << ans;


}

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define LOOP while(true)
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(void){
	string S;
	cin >> S;
	SORT(S);
	cout << ((S == "abc") ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{

	int winvc,jppg,mathpg,dojp,domath;
	
	scanf("%d",&winvc);
	scanf("%d",&jppg);
	scanf("%d",&mathpg);
	scanf("%d",&dojp);
	scanf("%d",&domath);
	
	int a=jppg/dojp;
	int b=mathpg/domath;
	int c=jppg%dojp;
	int d=mathpg%domath;
	if (c!=0)a++;
	if (d!=0)b++;
	if (a>b)printf("%d\n",winvc-a);
	if (a<b)printf("%d\n",winvc-b);
	if (a==b)printf("%d\n",winvc-a);
	return 0;
	
	
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
char t[1510];
int main(){
	int i,j;
	int n,m;
	int	cnt=0;
	int h;
	while(scanf("%s",&t)){
		// printf("%s\n",t);
		if(strcmp(t,"-")==0) break;
		n=strlen(t);
		for(i=0;i<n;i++){
			t[n+i]=t[i];
		}
		scanf("%d",&m);
		cnt=0;
		for(i=0;i<m;i++){
			scanf("%d",&h);
			cnt+=h;		
		}
		cnt%=n;
		for(i=0;i<n;i++){
			printf("%c",t[i+cnt]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 584
#include<cstdio>
#include<cstring>
using namespace std;
char a[60][60];
int H,W;
int main(){
  scanf("%d%d\n",&H,&W);
  memset(a,0,sizeof(a));
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      a[i][j]=getchar();
      if(a[i][j]=='.') a[i][j]='0';
    }
    getchar();
  }
  for(int i=0;i<H;++i)
    for(int j=0;j<W;++j){
      if(a[i][j]=='#'){
        for(int x=-1;x<=1;++x)
          for(int y=-1;y<=1;++y){
            int nx=i+x,ny=j+y;
            if(nx>=0&&nx<H&&ny>=0&&ny<W&&a[nx][ny]!='#') ++a[nx][ny];
          }
      }
    }
  for(int i=0;i<H;++i) puts(a[i]);
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int cnt=0;
    long long ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            ans+=i-cnt;
            cnt++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
a = list()
for i in range(n):
    a.append(list(map(int, input().split())))
b = list()
for i in range(m):
    b.append(int(input()))
for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j] * b[j]
    print(ans)


Measured memory_bytes: 6012
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(void){
    int n; cin >> n;
    string s; cin >> s;
    for(int i=0;i<s.length();i++){
        cout << char('A'+(s[i]-'A'+n)%('Z'-'A'+1));
    }cout << endl;
    return 0;
}

Measured memory_bytes: 256
def modInverse(a,m):
    m0 = m 
    y = 0
    x = 1
  
    if (m == 1) : 
        return 0
  
    while (a > 1) : 
        q = a // m 
        t = m 
        m = a % m 
        a = t 
        t = y 
        y = x - q * y 
        x = t 
  
    if (x < 0) : 
        x = x + m0 
  
    return x 

def main():
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    mod = 10**9+7
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            if arr[i] > arr[j]:
                ans += 1

    ans = ans*k
    ans = ans%mod

    dist = {}
    for i in arr:
        if i not in dist.keys():
            dist[i] = 1
        else:
            dist[i] += 1

    arr = []
    for i in dist.keys():
        arr.append((i,dist[i]))

    arr.sort(reverse = True)
    count = 0
    total = 0
    for i in arr:
        total += i[1]

    #print(arr)
    for i in arr:
        total -= i[1]
        count += total*i[1]

    count = count*k*(k-1)
    count = count%mod
    count = count*modInverse(2,mod)
    count = count%mod
    ans += count
    print(ans%mod)
    


main()


Measured memory_bytes: 41820
n = int(input())
pre_t, pre_x, pre_y = [0, 0, 0]
ok = True
for i in range(n):
  t, x, y = map(int, input().split())
  d = (t-pre_t) - abs(x-pre_x) - abs(y-pre_y)
  if d < 0 or d % 2 != 0:
    ok = False
    break
  pre_t, pre_x, pre_y = [t, x, y]
  
if ok:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

int main(){
  int i,j,k;
  int A[3];
  scanf("%d %d %d",&A[0],&A[1],&A[2]);
  scanf("%d",&k);
  int tmp;
  for (i=0; i<3; ++i) {
    for (j=i+1; j<3; ++j) {
      if (A[i] > A[j]) {
        tmp =  A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }

  for(i=0;i<k;i++)
    A[2]*=2;
  
  printf("%d\n",A[0]+A[1]+A[2]);
  return 0;
}


Measured memory_bytes: 128
from collections import deque
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
# 目印置くリスト
me = [0 for _ in range(n+1)]
me[1] = 1
miti = [[] for _ in range(n+1)]
tansaku = [0 for i in range(n+1)]
tansaku[1]=1
for i,j in l:
  miti[j].append(i)
  miti[i].append(j)
a = deque()
for i in miti[1]:
  a.append(i)
  me[i] = 1
  tansaku[i]=1
while len(a)!=0:
#  print(a)
  w = a.popleft()
  for j in miti[w]:
    if tansaku[j]==0 :
          a.append(j) 
          tansaku[j] = 1
          me[j] = w
 # print(w,tansaku,me,a)
  
print("Yes")
for i in range(len(miti)-2):
  print(me[i+2])

Measured memory_bytes: 58604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

/*ここから*/

vector<LL> d;
LL D;//約数の個数
LL D2;
void divisor(LL x){
    for(LL i=1;i*i<=x;i++){
        if(x%i==0){d.push_back(i);}
    }
    D=d.size();
    for(LL i=D-1;i>=0;i--){
        if(d[i]*d[i]<x){d.push_back(x/d[i]);}
    }
    D=d.size();
}

/*ここまで*/

int main()
{ 
    LL n;
    cin>>n;
    if(n==2){cout<<1<<endl;return 0;}
    LL cnt=0;
    LL m=0;
    for(LL i=2;i*i<=n;i++){
        LL x=n;
        while(x>=i){
            if(x%i==0){x=x/i;}
            else{x=x%i;}
        }
        if(x==1){cnt++;}
        if(i>m){m=i;}
    }
    divisor(n-1);
    for(int i=0;i<d.size();i++){
        if(d[i]>m){cnt++;}
    }
    cout<<cnt+1<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

data class Tuple(val a: Long, val b: Int): Comparable<Tuple> {
    override fun compareTo(other: Tuple): Int =
        a.compareTo(other.a).let {
            if (it == 0) b.compareTo(other.b) else it
        }
}

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val a = Array(n){Tuple(long(), it)}
    a.sort()
    val set = TreeSet<Int>()
    var ret = 0L
    for ((item, i) in a) {
        val left = set.lower(i) ?: -1
        val right = set.higher(i) ?: n
        val ld = i - left
        val rd = right - i
        ret += ld.toLong() * rd * item
        set.add(i)
    }
    println(ret)
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }

    inline fun println(block: IO.() -> Any) {
        println(block())
        out.flush()
    }
}
// endregion

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

bool isGu(string S){
    rep(i,S.size()/2){
        if(S[i]!=S[i+S.size()/2]) return false;
    }
    return true;
}

int main(){
    string S;
    cin >> S;
    int n = S.size();
    for(int i=0;i<n;i+=2){
        S = S.substr(0,S.size()-2);
        if(isGu(S)){
            cout << S.size() << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math
x = int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
if x == 2:
    print(x)
    exit()
elif x % 2 == 0:
    x += 1

while True:
    if is_prime(x):
        print(x)
        exit()
    else:
        x += 2



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    int N;
    string s;
    cin>>s;
    N=s.length();
    
    //check false pattern
    if(s[0]=='0'||s[N-2]=='0'||s[N-1]=='1'){
        cout<<-1<<endl;
        return 0;
    }
    for(int i = 0;i*2<=N-2;i++){
        if(s[i]!=s[N-2-i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    int temp = 1;
    for (int i = 1;i <= N-1;i++){
        cout<<temp<<" "<<i+1<<endl;
        if(s[i-1]=='1'){
            temp = i+1;
        }
    }
}


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

class F
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int r1 = h[0] - 1, c1 = h[1] - 1, r2 = h[2], c2 = h[3];
		invs = Enumerable.Range(0, c2 + 2).Select(i => ((MInt)i).Inv()).ToArray();
		Console.WriteLine(Sum(r2, c2) + Sum(r1, c1) - Sum(r1, c2) - Sum(r2, c1));
	}

	static MInt[] invs;
	static MInt Sum(int r, int c)
	{
		MInt t = 1, v = 0;
		for (int i = 1; i <= c + 1; i++)
		{
			t *= (r + i) * invs[i];
			v += t;
		}
		return v;
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x) => x;
	public static MInt operator -(MInt x) => -x.V;
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);
	public override string ToString() => $"{V}";

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 27104
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,input,x,q,xx,xxx;
    cin>>n;
    set<long long>v;
    while(n--)
    {

        cin>>input;
        if(input == 0)
        {
            cin>>x;
            v.insert(x);
            cout<<v.size()<<endl;
        }
        else if(input == 1)
        {
            cin>>xx;
            v.count(xx)?cout<<"1"<<endl:cout<<"0"<<endl;
        }

    }
    return 0;
}



Measured memory_bytes: 12368
import math
h = int(input())
w = int(input())
n = int(input())

done=0
count=0
while True:
  if h>w:
    if w==0:
      exit()
    else:
      done+=h
      count+=1
      w-=1
  else:
    if h==0:
      exit()
    else:
      done+=w
      count+=1
      h-=1
  if done>=n:
    print(count)
    exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int s[maxn];
int main()
{
    int a,b,k,j=0;
    scanf("%d%d%d",&a,&b,&k);
    for(int i=1;i<=100;i++)
    {
        if(a%i==0&&b%i==0) s[j++]=i;
    }
    printf("%d\n",s[j-k]);
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<queue>
#include<vector>
using namespace std;

int main()
{
	while (1)
	{
		priority_queue<int> GAP;
		priority_queue<int> PQ;
		int m, n_min, n_max;
		scanf("%d%d%d", &m, &n_min, &n_max);
		if (m == 0)break;
		for (int i = 0; i < m; i++)
		{
			int k;
			scanf("%d", &k);
			PQ.push(k);
		}
		int index = 0;
		for (int i = n_min; i <= n_max; i++)
		{
			priority_queue<int> tPQ = PQ;
			for (int l = 0; l < i-1; l++)
			{
				tPQ.pop();
			}
			int temp = tPQ.top();
			tPQ.pop();
			int gap = temp - tPQ.top();
			GAP.push(gap);
			if (gap == GAP.top())index = i;
		}
		printf("%d\n",index);
	}
	return 0;
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int r;
  cin >> r;
  if(r<1200)
    cout << "ABC" << endl;
  else if(r<2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}

Measured memory_bytes: 256
import math
 
N, K = map(int, input().strip().split(' '))
 
ans = 0
count = int(math.log(K,2)-math.log(N,2))
if count < 0:
    count = 0
val = 2**count
 
for n in range(N, 0, -1):
    while n*val < K:
        val *= 2
        count *= 2
    #print('COUNT=', count)
    ans += 1.0/val
 
print(ans/N)

Measured memory_bytes: 38640
#include <iostream>

int f(int x);

int main()
{
    int delta;
    while (std::cin >> delta) {
        int ans = 0;
        for (auto i = delta; i < 600; i += delta) {
            ans += delta * f(i);
        }
        std::cout << ans << std::endl;
    }

    return 0;
}

int f(int x)
{
    return (x * x);
}

Measured memory_bytes: 1160
#include "iostream"
using namespace std;

int main()
{
	char a;
	int n, b; 
	bool card[4][13] = {};
	//Sが0、Hが1、Cが2、Dが3
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		switch (a)
		{
		case 'S':
			card[0][b - 1] = true;
			break;
		case 'H':
			card[1][b - 1] = true;
			break;
		case 'C':
			card[2][b - 1] = true;
			break;
		case 'D':
			card[3][b - 1] = true;
			break;
		}
	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			if (card[i][j] == false)
			{
				switch (i)
				{
				case 0:
					cout << "S";
					break;
				case 1:
					cout << "H";
					break;
				case 2:
					cout << "C";
					break;
				case 3:
					cout << "D";
					break;
				}
				cout << " " << j + 1 << endl;
			}
		}
	}
}



Measured memory_bytes: 3088
/* Author rumoisen */
/* created 2018/11/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    int m;
    cin>>m;
    cout<<24+(24-m)<<endl;
}

Measured memory_bytes: 256
N,P = map(int,input().split())
S = input()

def solve(S,N,P):
    if P == 2:
        ans = 0
        for i in range(N):
            if int(S[i])%P == 0:
                ans += i+1
        return ans
    if P == 5:
        ans = 0
        for i in range(N):
            if int(S[i])%P == 0:
                ans += i+1
        return ans
    
    S = S[::-1]
    mod_list = [0]*P
    mod_list[0] = 1

    mod = P
    tmp = 0

    for i in range(N):
        tmp = (tmp + int(S[i])*pow(10,i,mod))%mod
        mod_list[tmp] += 1
    
    ans = 0
    for i in mod_list:
        ans += i*(i-1)//2
        
    return ans

print(solve(S,N,P))

Measured memory_bytes: 3560