akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1LL << 60
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> P;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

vector<P>St[256];
int N, M;
ll dp[256][16][128];

ll dfs(int n, int x, int m){
  if(n>=N-1) return 0;
  if(n>=N-2 && m) return 0;
  ll &res = dp[n][x][m];
  if(res >= 0) return res;
  res = INF;
  int pos = St[n][x].first ,slip = St[n][x].second;
  rep(i, St[n+1].size()){
      P tar = St[n+1][i];
      res = min(res, dfs(n+1, i, m)+(ll)(slip+tar.second)*(ll)(abs(pos-tar.first)));
  }
  if(m && n < N-2){
    rep(i, St[n+2].size()){
      P tar = St[n+2][i];
      res = min(res, dfs(n+2, i, m-1)+(ll)(slip+tar.second)*(ll)(abs(pos-tar.first)));
    }
  }
  //  cout << n << " " << x << " "<< m <<" " << res << endl;
  return res;
}

int main(){
  while(scanf("%d%d", &N, &M) && N){
    int k, x, d;
    memset(dp, -1, sizeof(dp));
    rep(i,N) St[i].clear();
    rep(i, N){
      scanf("%d", &k);
      rep(j,k){
	scanf("%d%d", &x, &d);
	St[i].push_back(P(x, d));
      }
    }
    
    ll res = INF;
    rep(i, St[0].size()) res = min(res, dfs(0, i, M));
    if(M) rep(i, St[1].size()) res = min(res, dfs(1, i, M-1));

    printf("%lld\n", res);
  }
  return 0;
}

Measured memory_bytes: 5332
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
//pragma GCC optimize("Ofast")
//pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" )
#include <queue>
#define endl "\n";
#define int long long
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;

void solve() {
	int x, n, y;
	cin >> x >> n;
	set <int> a;
	for (int i = 0; i < n; ++i) {
		cin >> y; a.insert(y);
	}
	if (a.find(x) == a.end()) {cout << x; 
		return;
	}
	y = 1;
	while (true) {
		if (a.find(x - y) == a.end()) {
			cout << x - y; return;
		}
		if (a.find(x + y) == a.end()) {
			cout << x + y; return;
		}
		++y;
	}
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0;
}


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

using namespace std;

int main()
{
    long long int a,b;
    cin>>a>>b;
    if(a%2==b%2)
    {
        cout<<(a+b)/2<<endl;
    }
    else
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

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

const int MOD = 1000000007;

int main() {
	//入力
	string s;
	cin >> s;

	//処理

	//出力
	string ans;
	if (s[s.size() - 1] == 's')
		ans = s + "es";
	else
		ans = s + "s";

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
//#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

const int inf = 1e9 + 7;
bool used[300];
int n, m, gr[300][300], l, q;
pair <int, int> dp[300][300], ans[300][300], ra[300];

void relax(pair <int, int>& a, int b, int c)
{
	if (a.first > b || (a.first == b && a.second < c))
		a = mp(b, c);
}

void dijkstra(int v)
{
	for (int i = 0; i < n; i++)
	{
		used[i] = false;
		ra[i] = mp(inf, 0);
	}
	ra[v] = mp(0, l);
	while (true)
	{
		int to = -1, min_zapr = inf, fuel_left = 0;
		for (int i = 0; i < n; i++)
			if (!used[i])
			{
				if (min_zapr > ra[i].first || (min_zapr == ra[i].first && fuel_left < ra[i].second))
				{
					to = i;
					min_zapr = ra[i].first;
					fuel_left = ra[i].second;
				}
			}
		if (to == -1)
			return;
		used[to] = true;
		ans[v][to] = mp(min_zapr, fuel_left);
		for (int i = 0; i < n; i++)
			if (!used[i] && gr[to][i] <= l)
			{
				if (gr[to][i] <= fuel_left)
					relax(ra[i], min_zapr, fuel_left - gr[to][i]);
				else
					relax(ra[i], min_zapr + 1, l - gr[to][i]);
			}
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("bst.in", "r", stdin);
	//freopen("bst.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
		{
			gr[i][j] = inf;
			ans[i][j] = mp(inf, 0);
		}
	for (int i = 0; i < n; i++)
	{
		gr[i][i] = 0;
		ans[i][i] = mp(0, l);
	}
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		cin >> gr[u][v];
		gr[v][u] = gr[u][v];
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if(gr[i][j] <= l)
				dp[i][j] = mp(0, l - gr[i][j]);
			else
				dp[i][j] = mp(inf, 0);
	for (int i = 0; i < n; i++)
		dijkstra(i);
	cin >> q;
	while (q--)
	{
		int u, v;
		cin >> u >> v;
		if (ans[u - 1][v - 1].first == inf)
			cout << -1 << '\n';
		else
			cout << ans[u - 1][v - 1].first << '\n';
	}
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

struct P{double x; double y;};

// 2点間の距離の二乗
double dist(P p1, P p2){
	double dx = p1.x - p2.x;
	double dy = p1.y - p2.y;
	return dx*dx + dy*dy;
}

void mainsolve(){

	ll n;
	cin >> n;
	vector<P> ps(n);
	rep(i,n){
		double x,y;
		cin >> x >> y;
		ps[i] = P{x,y};
	}

	// (x,y)を中心としたときの最遠点との距離
	auto f = [&](double x, double y){
		P center = P{x,y};
		double res = 0;
		rep(i,n){
			res = max(res, dist(center, ps[i]));
		}
		return res;
	};

	// fにおいてxを固定したときのfの最小値
	auto g = [&](double x){
		double l = 0;
		double r = 1000;
		rep(i,100){
			double p1 = (l*2+r)/3;
			double p2 = (l+r*2)/3;
			if(f(x,p1) > f(x,p2)) l = p1;
			else r = p2;
		}
		return f(x,l);
	};

	double l = 0;
	double r = 1000;
	rep(i,100){
		double p1 = (l*2+r)/3;
		double p2 = (l+r*2)/3;
		if(g(p1) > g(p2)) l = p1;
		else r = p2;
	}

	printf("%.10f\n", sqrt(g(l)));
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int n;
char pet[303][303];
char pet2[303][303];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int n; cin >> n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			cin >> pet[i][j];
	
	int res = 0;
	for(int a = 0; a < n; a++)
	{
		// cout << "something\n"; fflush(stdout);
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				// cout << i << " " << j << "\n"; fflush(stdout);
				int _i = i+a;
				if(_i > n) _i %= n;
				pet2[i][j] = pet[_i][j];
			}
		}
		int bol = 1;
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				// cout << pet2[i][j];
				if(pet2[i][j] != pet2[j][i])
					bol = 0;
			} 
			// cout << "\n";
		}
		res += bol*n;
	}
	cout << res << "\n";
}






Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    static final long mod = 1000000007L;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long k = in.nextLong();

        long total = 0;
        for (long i = k; i <= n + 1; i++) {
            total = (total + (i * (n - i + 1) % mod + 1)) % mod;
        }

        System.out.println(total);
    }
}


Measured memory_bytes: 35772
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var cnt int

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := range a {
		// fmt.Scan(&a[i])
		s := nextLine()
		tmp, _ := strconv.Atoi(s)
		a[i] = tmp
	}

	shellSort(a, len(a))

	fmt.Println(cnt)

	for _, v := range a {
		fmt.Println(v)
	}
}

func shellSort(a []int, n int) {
	//https://ja.wikipedia.org/wiki/%E3%82%B7%E3%82%A7%E3%83%AB%E3%82%BD%E3%83%BC%E3%83%88#cite_note-Knuth-5
	g := []int{}

	i := 1
	for {
		tmp := (intPow(3, i) - 1) / 2
		if tmp > n {
			break
		}
		g = append(g, tmp)
		i++
	}
	fmt.Println(len(g))

	for i := len(g) - 1; i >= 0; i-- {
		fmt.Print(g[i])
		insertionSort(a, n, g[i])
		if i > 0 {
			fmt.Print(" ")
		} else {
			fmt.Println()
		}
	}
}

func insertionSort(a []int, n, g int) {
	//g=iの時通常のinsertionSort
	for i := g; i < n; i++ {
		v := a[i]
		j := i - g
		for j >= 0 && a[j] > v {
			a[j+g] = a[j]
			j = j - g
			cnt++
		}
		a[j+g] = v
	}
}

func intPow(b, x int) int {
	p := 1
	for i := 0; i < x; i++ {
		p *= b
	}
	return p
}



Measured memory_bytes: 17444
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

for i in range(M):
    A,B = map(int, input().split())
    union.union(A-1,B-1)

print(-min(union.parents))


Measured memory_bytes: 14584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String in = sc.next();
			
			if("-".equals(in)){
				break;
			}
			
			LinkedList<Character> red = new LinkedList<Character>();
			LinkedList<Character> green = new LinkedList<Character>();
			for(char c : in.toCharArray()){
				red.add(c);
			}
			for(char c : sc.next().toCharArray()){
				green.add(c);
			}
			LinkedList<Character> right = new LinkedList<Character>();
			char[] down = sc.next().toCharArray();
			
			char center = green.poll();
			final int size = green.size() + red.size();
			int cur_d = 0;
			for(int count = 0; count < size; count++){
				//System.out.print(center);
				
				if(cur_d < down.length && down[cur_d] == center){
					center = red.poll();
					cur_d++;
				}else{
					right.add(center);
					center = green.poll();
				}
			}
			right.add(center);
			
			for(char r : right){
				System.out.print(r);
			}
			System.out.println();
		}
		
	}

}

Measured memory_bytes: 17376
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G){
  const T INF = numeric_limits<T>::max();
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}

//INSERT ABOVE HERE
signed main(){
  Int n,m,k;
  cin>>n>>m>>k;
  vector<Int> ps(n),cs(n),js(n);
  for(Int i=0;i<n;i++) cin>>ps[i];
  for(Int i=0;i<n;i++) cin>>cs[i],cs[i]--;
  for(Int i=0;i<n;i++) cin>>js[i];

  using P = pair<Int, Int>;
  vector< vector<P> > G(n+1);
  for(Int i=0;i<m;i++){
    Int u,v,t;
    cin>>u>>v>>t;
    u--;v--;
    G[u].emplace_back(v,t);
    G[v].emplace_back(u,t);
  }

  auto ds=dijkstra(0,G);

  const Int OFS = 2e9;
  for(Int i=0;i<n;i++)
    G[n].emplace_back(i,ds[i]-ps[i]+OFS);

  auto dt=dijkstra(n,G);
  const Int INF = 1e18;
  vector<Int> ans(k,-INF);
  for(Int i=0;i<n;i++)
    chmax(ans[cs[i]],js[i]-(dt[i]-OFS+ds[i]));

  for(Int x:ans) cout<<x<<"\n";
  cout<<flush;
  return 0;
}



Measured memory_bytes: 24468
#include <stdio.h>

int main() {
    int n, min = 1000000, max = -1000000;
    long long int sum = 0;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum += a[i];
        if (min > a[i]) min = a[i];
        if (max < a[i]) max = a[i];
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2708
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

using namespace std;

const int N=1e5+5;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

ll n, dp[N][2];
vector<ll>adj[N];

void dfs(ll u, ll p)
{
    ll ret0=1, ret1=1;
    for(auto v:adj[u])
        if(v!=p)
        {
            dfs(v, u);
            ret1*=dp[v][1];
            ret1%=MOD;
            ret0*=(dp[v][1]+dp[v][0])%MOD;
            ret0%=MOD;
        }
    dp[u][0]=ret1;
    dp[u][1]=ret0;
}

int main() 
{
    inlld(n);
    for(ll a=1; a<n; a++)
    {
        ll u, v;
        inlld2(u, v);
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1, 1);
    printf("%lld\n", (dp[1][1]+dp[1][0])%MOD);
    return 0;
}



Measured memory_bytes: 14208
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

/*
 * ref. [Union-Find](https://www.slideshare.net/chokudai/union-find-49066733)
 * ref. [AtCoder ABC 157 - AtCoder Live](https://www.youtube.com/watch?v=TdR816rqc3s)
 */
class UnionFind {
    public:
        UnionFind(int n = 0): d(n, -1) {}

        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        int find(int x) {
            if (d[x] < 0) return x;
            return d[x] = find(d[x]);
        }

        // Return false if x and y are alreday in the same group, otherwise return true.
        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        bool unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) swap(x, y);
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        bool same(int x, int y) {
            return find(x) == find(y);
        }

        // 0-index, [0, n) in other words
        // Time complexity: O(1)
        int size(int x) {
            return -d[find(x)];
        }

    private:
        vector<int> d;
};

vector<int> ps;

int main(void) {
    int N, M;
    cin >> N >> M;

    ps.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> ps[i];
        ps[i]--;
    }

    UnionFind uf(N);

    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }

    map<int, set<int>> ns;
    map<int, set<int>> inds;

    for (int i = 0; i < N; i++) {
        int p = ps[i];
        ns[uf.find(i)].insert(p);
        inds[uf.find(i)].insert(i);
    }

    // for (auto pa : ns) {
    //     printf("ns[%d]: \n", pa.first);
    //     for (auto x : pa.second) {
    //         cout << x << " ";
    //     }
    //     cout << endl;
    // }

    // for (auto pa : inds) {
    //     printf("inds[%d]: \n", pa.first);
    //     for (auto x : pa.second) {
    //         cout << x << " ";
    //     }
    //     cout << endl;
    // }

    int ans = 0;
    for (auto pa : ns) {
        for (auto x : pa.second) {
            if (inds[pa.first].find(x) != inds[pa.first].end()) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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


int main() {
	int n,k;
	cin >> n >> k;
	int x = 1,y=1,z=n;
	while (x  < k&&y<=z) {
		x *= 2;
		n -= 1;
		y += 1;
	}
	for(int i = 0; i < n; i++) {
		x += k;
	}
	cout << x;
	return 0;
}










Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n,k;
	cin >> n>>k;
    string s;
    cin >> s;
    int num=0;
    fr(i,n-1){
      if(s[i]!=s[i+1])num++;
    }
    num=max(num-k*2,0);
    
      cout << n-num-1 << endl;
}

Measured memory_bytes: 512
import glob

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\169\\E'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:
    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index - 1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        N = int(self.input_data())
        A = [[0, 0] for i in range(N)]
        B = [[0, 0] for i in range(N)]

        for i in range(N):
            tmp = self.input_data().split()
            A[i][0] = i
            A[i][1] = int(tmp[0])
            B[i][0] = i
            B[i][1] = int(tmp[1])

        # 最小値群と最大値群を個別に並び替える
        A_sorted = sorted(A, key=lambda x: x[1])
        B_sorted = sorted(B, key=lambda x: x[1])
        '''
        if N % 2 == 0:
            for i in range(N):
                for j in range(N):
                    if A_sorted[j][0] == i:
                        min = A_sorted[j]
                        break
                for j in range(N):
                    if B_sorted[j][0] == i:
                        max = B_sorted[j]
                        break
                

            pass
        else:
            pass
        '''
        if N % 2 == 0:
            median_min = A_sorted[int(N/2)][1] + A_sorted[int(N/2)-1][1]
            median_max = B_sorted[int(N/2)][1] + B_sorted[int(N/2)-1][1]
        else:
            median_min = A_sorted[int(N/2)][1]
            median_max = B_sorted[int(N/2)][1]
        result = median_max - median_min + 1

        print(str(result))



solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 69876
# B - 1 21　つなげて読んだ数値が平方数かどうか判定する

inputNum = int(input().replace(' ', ''))

# 素因数分解　入力される２つの数字は1～100の整数

primeNums = []

# 素数をさがす
cnt = 0
for i in range(2, 101):
    cnt = 0
    for j in range(2, 101):
        if i % j == 0:
            cnt += 1
    if cnt == 1:
        primeNums.append(i)

dic = {}

#print(inputNum)
#print(primeNums)

# 素因数分解
for primeNum in primeNums:
    cnt = 0
    if inputNum % primeNum == 0:  # 素数で割る
        cnt += 1
        work = inputNum / primeNum
        while (work % primeNum == 0):  # １回割れたら割り切れるまで割る
            cnt += 1
            work = work / primeNum
        dic[primeNum] = cnt

#print(dic)
word = "Yes"
for key in dic :
    if dic[key] % 2 != 0:
        word = "No"

print(word)

Measured memory_bytes: 3064
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

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

int v,e,r,s[500010],t[500010],d[500010],c[100010];
const int inf=1000000000;

int main(){
    cin>>v>>e>>r;
    for(int i=0;i<e;i++){
        cin>>s[i]>>t[i]>>d[i];
    }
    for(int i=0;i<100010;i++){c[i]=inf;}
    c[r]=0;
    for(int i=0;i<v;i++){
        int a=0;
        for(int j=0;j<e;j++){
            int s1=s[j],t1=t[j],d1=d[j];
            if(c[s1]<inf && c[t1]>c[s1]+d1){
                c[t1]=c[s1]+d1;
                a=1;
            }
        }
        if(!a){break;}
    }
    for(int i=0;i<v;i++){
        if(c[i]==inf){cout<<"INF"<<endl;}
        else{cout<<c[i]<<endl;}
    }
}


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

int main(){
    string s;
    cin >> s;
    // s = "1902";
    vector<char> c1;
    vector<char> c2;

    c1.push_back(s[0]);
    c1.push_back(s[1]);
    c2.push_back(s[2]);
    c2.push_back(s[3]);

    string s1(c1.begin(), c1.end());
    string s2(c2.begin(), c2.end());
    int n1 = atoi(s1.c_str());
    int n2 = atoi(s2.c_str());

    if ((n1 > 12) || (n1 < 1)){
        if (n2 >= 1 && n2 <= 12){
            cout << "YYMM" << endl;
        }
        else{
            cout << "NA" << endl;
        }
        return 0;
    }
    if ((n2 > 12) || (n2 < 1)){
        if (n1 >= 1 && n1 <= 12){
            cout << "MMYY" << endl;
        }
        else{
            cout << "NA" << endl;
        }
        return 0;
    }

    cout << "AMBIGUOUS" << endl;
    return 0;
}

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

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



bool f(string t){
	string u = t;
	reverse(t.begin(), t.end());
	if (t == u){
		return true;
	}
	return false;
}


int main() {
	string s;
	cin >> s;

	string c2 = s.substr(0,((s.size()-1)/2));
	string c3 = s.substr(((s.size()+2)/2),s.size());

	if(f(s) && f(c2) && f(c3)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, M; cin >> N >> M;
	vi sum(N, 1), hasRed(N, 0);
	hasRed[0] = 1;

	REP(i, M) {
		int x, y; cin >> x >> y;
		--x, --y;
		if (hasRed[x] == 1) {
			hasRed[y] = 1;
		}
		if (sum[x] == 1) {
			hasRed[x] = 0;
		}
		sum[x] -= 1;
		sum[y] += 1;
	}
	int res = 0;
	REP(i, N) {
		if (hasRed[i] == 1) ++res;
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0)
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
	IOS;
    int test = 1; //cin>>test;
    for(int tt = 1; tt <= test; tt++){
    	int n;
    	cin >> n;
    	int a[n];
    	for(int i = 0; i < n; i++){
    		cin >> a[i];
    	}
    	int count = 0;
    	for(int i = 0; i < n; i++){
    		for(int j = i+1; j < n; j++){
    			for(int k = j+1; k < n; k++){
    				int a1 = a[i], b1 = a[j], c1 = a[k];
    				if(a1!=b1 && b1!=c1 && a1 != c1 && a1+b1 > c1 && b1+c1 > a1 && a1+c1 > b1){
    					count++;
    				}
    			}
    		}
    	}
    	cout << count << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
}


Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void solveforthiscase(const int & test)
{//deb(test);
ll r,g,b;
cin>>r>>g>>b;
cin>>n;
ll sum=0;
ll ans=0;
for(int i=0;i<=3000;i++)
{
    for(int j=0;j<=3000;j++)
    {
       sum=r*i+j*b;
       if(sum>n)
       continue;
       if((n-sum)%g==0)
       ans++;
    }
}
cout<<ans;




return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


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

	for (int i = 0; i < N / 2; i++) {
		if (N % 2 == 1) {
			cout << "No" << endl;
			break;
		}
		 else if (S.at(i) == S.at(N / 2 + i) && i + 1 < N / 2) {
			continue;
		}
		else if (S.at(i) == S.at(N / 2 + i) && i + 1 == N / 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
			break;
		}
		}
	if (N == 1) {
		cout << "No" << endl;
	}
	}

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

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

		long long n1 = n;

		long long temp = n;
		for (long long i = 2; i <= sqrt(n1); i++) {
				if (n % i == 0) {
						temp = temp * (i - 1) / i;
						while(n % i == 0) {
								n /= i;
						}
				}
		}
		if (n > 1) {
				temp = temp *  (n - 1) / n;
		}

		cout << temp << endl;

		return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<algorithm>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn = 1e3+5;

int main(){
	double n; scanf("%lf",&n);
	double a = n / 3;
	printf("%lf\n",a*a*a);
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H,W,K = map(int,input().split())
r1,c1,r2,c2 = map(lambda x:int(x)-1,input().split())
C = [input() for i in range(H)]

def solve():
    from collections import deque
    dxy = [(0,1),(1,0),(0,-1),(-1,0)]
    INF = float('inf')
    dists = [[INF]*W for _ in range(H)]
    dists[r1][c1] = 0
    q = deque([(r1,c1)])
    while q:
        y,x = q.popleft()
        if y==r2 and x==c2:
            print(dists[y][x])
            exit()
        for dx,dy in dxy:
            for i in range(1,K+1):
                nx,ny = x+dx*i,y+dy*i
                if not 0 <= nx < W: break
                if not 0 <= ny < H: break
                if C[ny][nx] == '@': break
                if dists[ny][nx] <= dists[y][x]: break
                if dists[ny][nx] <= dists[y][x] + 1: continue
                dists[ny][nx] = dists[y][x] + 1
                q.append((ny,nx))
    print(-1)
solve()

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

int main() {
  int A, B, C, K; cin >> A >> B >> C >> K;
  if (K<=A) cout << K << endl;
  else if (K<=A+B) cout << A << endl;
  else cout << A-(K-A-B) << endl;
}


Measured memory_bytes: 3636
let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in
  get

let () = Scanf.scanf "%d\n" @@ fun n ->
  let abcs = Array.init n @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun a b c -> [| a; b; c |] in
  let dp = memoize (3 * n) @@ fun dp -> function
    | (0, i) -> abcs.(0).(i)
    | (i, 0) -> abcs.(i).(0) + max (dp (i - 1, 1)) (dp (i - 1, 2))
    | (i, 1) -> abcs.(i).(1) + max (dp (i - 1, 2)) (dp (i - 1, 0))
    | (i, 2) -> abcs.(i).(2) + max (dp (i - 1, 0)) (dp (i - 1, 1)) in
  Printf.printf "%d\n" @@ max (dp (n - 1, 0)) @@ max (dp (n - 1, 1)) (dp (n - 1, 2))


Measured memory_bytes: 37504
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        long[] all = new long[n+1];
        long[] pate = new long[n+1];
        all[0] = 1;
        pate[0] = 1;
        for(int i = 1; i <= n; i++) {
            all[i] = all[i-1] * 2 + 3;
            pate[i] = pate[i-1] * 2 + 1;
        }
        System.out.println(dfs(n, x, all, pate));
    }
    private static long dfs(int n, long x, long[] all, long[] pate) {
        if(n == 0) return 1;
        long pateCount = 0;
        // bans
        if(x > 0) x--;
        // level n-1
        if(x > 0) {
            if(x >= all[n-1]) {
                x -= all[n-1];
                pateCount += pate[n-1];
            } else {
                pateCount += dfs(n-1, x, all, pate);
                x = 0;
            }
        }
        // pate
        if(x > 0) {
            x--;
            pateCount++;
        }
        // level n-1
        if(x > 0) {
            if(x >= all[n-1]) {
                x -= all[n-1];
                pateCount += pate[n-1];
            } else {
                pateCount += dfs(n-1, x, all, pate);
                x = 0;
            }
        }
        // bans
        if(x > 0) x--;
        return pateCount;
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

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

  int n;
  cin >> n;
  vi a(n);
  int ones = 0;
  rep(i,n) {
    cin >> a[i];
    if(a[i] == 1)ones++;
  }

  int d = a[0];
  rep(i,n){
    d = gcd(d,a[i]);
  }

  if(d != 1) cout << "not coprime" << endl;

  else {
    if(n > 78498 + ones) cout << "setwise coprime" << endl;
    else {
      vi prime;
      vi flag(1000);
      flag[0] = flag[1] = 1;
      rep(i,1000){  
        if(flag[i] == 0){
          prime.push_back(i);
          for(int j = i;j <= 1000;j += i){
            flag[j] = 1;
          }
        }
      }

      bool sw = false;
      map<int,int> cnt;

      rep(i,n){
        rep(j,prime.size()){
          int p = prime[j];
          if(a[i]%p == 0){
            cnt[p]++;
            if(cnt[p] > 1)sw = true;
            while(a[i]%p == 0) a[i] /= p;
          }
        }
        if(a[i] != 1){
          cnt[a[i]]++;
          if(cnt[a[i]] > 1)sw = true;
        }
      }

      if(sw) cout << "setwise coprime" << endl;
      else cout <<"pairwise coprime" << endl;
    }
  }
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int h, w, n;

int main() {
	scanf("%d %d %d", &h, &w, &n);
	printf("%d\n", (int)ceil((double)n/max(h,w)));
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**9)


def main():
    N = input()
    A_sorted = sorted(list(map(int, input().split())))

    result = True
    previous = -1
    for a in A_sorted:
        if previous == a:
            result = False
            break
        previous = a

    print("YES" if result else "NO")


if __name__ == "__main__":
  main()


Measured memory_bytes: 34188
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
using namespace std;

long long R, S, P;
long long getScore(char c) {
    if (c == 's') {
        return R;
    }
    if (c == 'p') {
        return S;
    }
    return P;
}

int main() {
    long long N, K;
    cin >> N >> K;
    cin >> R >> S >> P;
    string str;
    cin >> str;
    vector<char> pre;
    pre.reserve(K);
    long long current = 0;
    long long score = 0;
    while (current < K) {
        score += getScore(str[current]);
        pre.push_back(str[current]);
        current ++;
    }
    long long index;
    while (current < N) {
        index = current % K;
        if (str[current] != pre[index]) {
            score += getScore(str[current]);
            pre[index] = str[current];
        } else {
            pre[index] = 'a';
        }
        current++;
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
//A - Kyu in AtCoder
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353
#define pi 3.1415926535897932384626433832

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  int x;
  scanf("%d", &x);
  if(400<=x && x<=599){
    printf("8\n");
  }
  if(600<=x && x<=799){
    printf("7\n");
  }
  if(800<=x && x<=999){
    printf("6\n");
  }
  if(1000<=x && x<=1199){
    printf("5\n");
  }
  if(1200<=x && x<=1399){
    printf("4\n");
  }
  if(1400<=x && x<=1599){
    printf("3\n");
  }
  if(1600<=x && x<=1799){
    printf("2\n");
  }
  if(1800<=x && x<=1999){
    printf("1\n");
  }

  return 0;
}


Measured memory_bytes: 1660
import bisect

keys=[]

q=int(input())
d={}

def find(x):
    index=bisect.bisect_left(keys,x)
    if index==len(keys):
        return -1
    if keys[index]==x:
        return index
    else:
        return -1


for _ in range(q):
    query=input().split(" ")
    if query[0]=="0":
        if find(query[1])!=-1:
            pass
        else:
            bisect.insort_left(keys, query[1])
        d[query[1]]=query[2]
    elif query[0]=="1":
        if find(query[1])!=-1:
            print(d[query[1]])
        else:
            print(0)
    elif query[0]=="2":
        while find(query[1])>=0:
            keys.pop(find(query[1]))
    else:
        L,R=query[1],query[2]
        indL=bisect.bisect_left(keys,L)
        indR=bisect.bisect_right(keys,R)
        for s in keys[indL:indR]:
            print(s,d[s])



Measured memory_bytes: 43152
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007 
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>12)
		cout<<b;
	if(a>=6 && a<=12)
		cout<<b/2;
	else if(a < 6)
		cout<<0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
constexpr int N = 10;
int c[N][N];

int main()
{
    int h, w, a, ans = 0;
    cin >> h >> w;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            cin >> c[i][j];
        }
    }
    for (int k = 0; k < N; k++)
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a;
            if (a == -1)
                continue;
            ans += c[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
def solve():
  r,g,b,n = (int(i) for i in input().split())
  ans = 0
  for i in range(0,1+n//r):
    for j in range(0,1+n//g):
        rest = n-(i*r + j*g)
        #print(rest)
        if rest%b == 0 and rest >= 0:
          ans += 1
  print(ans)
solve()

Measured memory_bytes: 40684
use std::io;

fn main() {
    let mut st = String::new();

    io::stdin().read_line(&mut st).ok();
    let st = st.trim_right().to_owned();

    let mut odd = 0;
    let mut even = 0;
    for (i, s) in st.chars().enumerate() {
        if i % 2 == 0 {
            if s == '0' {
                odd += 1;
            } else {
                even += 1;
            }
        } else {
            if s == '0' {
                even += 1;
            } else {
                odd += 1;
            }
        }
    }

    if odd > even {
        println!("{}", even);
    } else {
        println!("{}", odd);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5+5;
const int mod = 1e9+7;

int dp[MAX];

bitset<MAX> bs;
vi primes;

void sieve() {
	bs.set();
	bs[0] = bs[1] = 0;

	for (ll i = 2; i < MAX; i++) {
		if (bs[i])
			primes.pb(i);

		for (ll j = 0; j < primes.size() && i*primes[j] < MAX; j++) {
			bs[i*primes[j]] = 0;

			if (i%primes[j] == 0)
				break;
		}
	}
}

bool sim(int n) {
	return bs[n] && bs[(n+1)/2];
}

int q, l, r, ans = 0;

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//#ifndef ONLINE_JUDGE
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//#endif

	sieve();

	for (int i = 3; i < MAX; i++) {
		dp[i] = dp[i-1];

		if (i%2)
			dp[i] += sim(i);
	}

	cin >> q;



	while (q-- && cin >> l >> r)
		cout << dp[r]-dp[l-1] << endl;
	

	return 0;
}


Measured memory_bytes: 1152
while True:
	k=map(int,raw_input().split(" "))
	if k[0]==k[1]==0:
		break
	ct=0
	max=k[0]
	sum=k[1]
	a=max+1

	while True:
		a-=1
		b=a-1
		c=sum-a-b
		if not a>c:
			print ct
			break
		while b>c:
			if c>0:
				ct+=1
			b-=1
			c+=1
			

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


int main()
{
	int n, x,cnt;
	while (1) {
		cin >> n >> x;
		cnt = 0;
		if (n==0 && x==0)break;

		for (int i = 1; i <= n - 2; i++)
			for (int j = i + 1; j <= n - 1; j++)
				for (int k = j + 1; k <= n; k++)if (i + j + k == x)cnt++;
		cout << cnt << endl;

	}
	return 0;
}


Measured memory_bytes: 3092
#include<stdio.h>
#include <string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(void){
char S[1000];
int i,N,count;
count=0;
scanf("%s",S);
N=strlen(S);
int m=N/2;
for (i=0;i<m;i++){
if(S[i]!=S[N-1-i]){
	count++;
}
}
printf("%d",count);
}

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

const int MAX = 100000, white = 0;
int n, colors[MAX], color = 0;
vector<int> G[MAX];

void dfs(int v){
    colors[v] = color;
    for (int i = 0; i < G[v].size(); i++)
    {
        if (colors[G[v][i]] == white)
        {
            dfs(G[v][i]);
        }
    }
}

void classification(){
    for (int i = 0; i < n; i++)
    {
        if (colors[i] == white)
        {
            color++;
            dfs(i);
        }
    }
}

int main(){
    int m, q;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int s, t;
        cin >> s >> t;
        G[s].emplace_back(t);
        G[t].emplace_back(s);
    }
    classification();
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int s, t;
        cin >> s >> t;
        if (colors[s] == colors[t])
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }
    
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n,m,i,d,c=0; string a;
    cin>>n>>m>>d;
    for(i=n;i<=m;i++) if(i%d==0) c++;
    cout<<c el;

}

main()
{
//    fastio();
//    test _case();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0||i==h-1||j==0||j==w-1)
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


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

int main(){
  int A, B, C;
  int X;
  cin >>A;
  cin >>B;
  cin >>C;
  cin >>X;
  
  int ans=0;
  for (int i=0; i<A+1; i++){
    for (int j=0; j<B+1; j++){
      for (int k=0; k<C+1; k++){
        if( 500*i + 100*j + 50*k == X){
          ans++;
        }        
      }
    }
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 256