akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for(int i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	int ans = 0;
	rep(i,3001) rep(j,3001) {
		int nokori = n - r*i - g*j;
		if (nokori>=0 && nokori%b==0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type* arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define all(v) (v.begin(), v.end())
#define tests(x) \
    int x;       \
    cin >> x;    \
    while (x--)
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int INF = 1e18;
const int N = 1e6 + 2;
void run() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("intput.txt", "r", stdin);
    freopen("o2.txt", "w", stdout);
#endif
}

int solve() {
    int n;
    cin>>n;
    return n >=30;
}
int32_t main() {
    run();
    // tests(t) {
    if(solve()) cout<<"Yes\n";
    else cout<<"No\n";
    //}
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main()
{
    int h, w;
    cin >> h >> w;
    v(string) g(h);
    vi a(26), c(4);
    rep(i, h) cin >> g[i];
    rep(i, h) rep(j, w) a[g[i][j]-'a']++;
    
    int g1 = (h%2)*(w%2);
    int g2 = (w%2)*(h/2) + (h%2)*(w/2);
    int g4 = (h/2)*(w/2);
    rep(i, g1){
        rep(j, 26){
            if (a[j]%2 == 1){
                a[j]--;
                break;
            }
        }
    }
    rep(i, g2){
        rep(j, 26){
            if (a[j]%4 == 2){
                a[j]-=2;
                break;
            }
        }
    }
    g4 += max(0, g2-c[2])/2;
    rep(i, g4){
        rep(j, 26){
            if (a[j]%4 == 0 and a[j] > 0){
                a[j] -= 4;
                break;
            }
        }
    }
    rep(i,26){
        if (a[i] > 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int findSum(int n) {
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}


int main(){
   int X,Y ;
   cin >> X;
   Y = findSum(X);
   if(X%Y == 0) cout << "Yes" << endl;
   else cout << "No"<< endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

int main(){

  int n,ans=0;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++) cin >> d[i];

  for(int i=n-1;i>0;i--){
    for(int j=0;j<i;j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans;
  return 0;
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,n,ans=0,t;
	bool a[101];
	fill(a,a+101,false);
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t;
		a[t]=true;
	}
	for (i=1;i<101;i++){
		if (a[i]==true){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !
from collections import deque 

class Node:
    def __init__(self):
        self.id = -1
        self.k = -1
        self.depth = -1
        self.parent = -1
        self.type = 'root'
        self.end = False
        self.children = []
        
def find_root_id(nodes):
    i = 0
    rootid = -1
    while nodes[i].parent != -1:
        nodes[i]
        i += 1
    else:
        rootid = nodes[i].id
        return rootid
        
def set_depth(rootid, nodes):
    que = deque()
    depth = 0
    node = nodes[rootid]
    que = deque(node.children)
    for i in que:
        nodes[i].depth = depth + 1
    depth += 1
    
    while que:
        for i in range(len(que)):
            for child in nodes[que.popleft()].children:
                que.append(child)
        for j in que:
            nodes[j].depth = depth + 1
        depth += 1

n = int(raw_input())
nodes = []
for i in range(n):
    node = Node()
    ls =  map(int, raw_input().split())
    node.id = ls[0]
    node.k = ls[1]
    if node.k == 0:
        pass
    else:
        node.children = ls[2:]
    nodes.append(node)
    
nodes = sorted(nodes, key=lambda node:node.id)
for node in nodes:
    for child in node.children:
        nodes[child].parent = node.id
        
for node in nodes:
    if node.children == []:
        if node.parent != -1:
            node.type = 'leaf'
    else:
        if node.parent != -1:
            node.type = 'internal node'

rootid = find_root_id(nodes)
nodes[rootid].depth = 0

def set_depth(rootid, nodes):
    que = deque()
    depth = 0
    node = nodes[rootid]
    que = deque(node.children)
    for i in que:
        nodes[i].depth = depth + 1
    depth += 1
    
    while que:
        for i in range(len(que)):
            for child in nodes[que.popleft()].children:
                que.append(child)
        for j in que:
            nodes[j].depth = depth + 1
        depth += 1

set_depth(rootid, nodes)
for node in nodes:#sorted(nodes, key=lambda node:node.id):
    print 'node %s: parent = %s, depth = %s, %s, %s'%(node.id,
    node.parent, node.depth, node.type, node.children)

Measured memory_bytes: 139564
#include<bits/stdc++.h>
#define N 100
using namespace std;

int main(){
  int n,m,a[N];
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int k=1;k<=m;k++)
    for(int j=0;j<n-1;j++)
      if(a[j]%k>a[j+1]%k)swap(a[j],a[j+1]);
  for(int i=0;i<n;i++)cout<<a[i]<<endl;
  return 0;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    int h,w,k;
    cin>>h>>w>>k;

    vector<string>c(h);
    rep(i,h)cin>>c[i];

    int res=0;

    rep(bith,1<<h){
        rep(bitw,1<<w){
        int sum=0;
            rep(H,h){
                rep(W,w){
                    if(!(bith&(1<<H))&&!(bitw&(1<<W))){
                            if(c[H][W]=='#')sum++;
                    }
                }
            }
        if(sum==k)res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef pair<int,int> pii;

int hoge(int i, int m) {
  if(i==0) return 0;
  if(i==5) return 6;
  return (i+m)%5+1;
}

int main() {
  int X,Y;
  while(cin >> X >> Y, X+Y) {
    char ba[X][Y];
    vector<pii> v[7];
    int cnt = 0;
    REP(y,Y)REP(x,X) {
      cin >> ba[x][y];
      if (ba[x][y] == 'S') {
        v[0].push_back(pii(x,y));
      } else if (ba[x][y] == 'G') {
        v[6].push_back(pii(x,y));
      } else if (ba[x][y] != '.') {
        if (v[ba[x][y] - '0'].size() == 0) cnt++;
        v[ba[x][y] - '0'].push_back(pii(x,y));
      }
    }
    int aaa = -1;
    if (cnt <4) {
      cout << "NA" << endl;
      continue;
    } else if (cnt == 4) {
      REP(i,5) {
        if (v[i+1].size()==0)
          aaa = i;
      }
    }
    vector<int> dp[7];
    int ans = 0;
    int mi = INF;
    REP(m,5) {
      //    cout << m << endl;
      if (cnt == 4 && aaa != m) continue;
      REP(i,7) dp[i] = vector<int>(v[i].size(), INF);
      dp[0][0] = 0;
      REP(i, 5) {
        int ii = hoge(i, m);
        int jj = hoge(i+1,m);
        //   printf("%d,%d\n",ii,jj);
        REP(j, v[ii].size()) {
          REP(k, v[jj].size()) {
            dp[jj][k] = min(dp[jj][k],
                            dp[ii][j]
                            + abs(v[ii][j].first - v[jj][k].first)
                            + abs(v[ii][j].second - v[jj][k].second));
            //            printf("%d, %d  (%d)\n", jj, k, dp[jj][k]);
          }
        }
      }
      if (mi > dp[6][0]) {
        ans = m+1;
        mi = dp[6][0];
      }
//      cout << dp[6][0] << endl;
    }
    printf("%d %d\n", ans, mi);
  }
}

Measured memory_bytes: 1960
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:
    print(0)
    exit()
r=1
b=0
g=0
pos=3
for i in range(1,n):
    pre=0
    de=0
    if a[i]==r:
        pre += 1
        r += 1
        de=1
    if a[i]==b:
        pre += 1
        if de==0:
            b += 1
            de=1
    if a[i]==g:
        pre += 1
        if de==0:
            g += 1
    
    pos *= pre
print(pos%(10**9+7))


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

using namespace std;

typedef long long ll;

int main(){
	int a[3];
	for(int i = 0; i < 3; i++)cin >> a[i];
	sort(a, a+3);
	int ans = 0;
	ans += a[2]-a[1];
	a[0]+=ans;
	if((a[2]-a[0])%2 == 1)ans+=2;
	ans += (a[2]-a[0])/2;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int64_t solve(int64_t n,int64_t x){
  if (n == -1) return -1;
  return (n/x);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t a, b, x;
  cin >> a >> b >> x;
  cout << solve(b,x) - solve(a-1,x) << endl;
  return 0;
}
//templete by private_yusuke

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

using namespace std;

int main(){

	int t;
	cin>>t;
	for(int m = 0; m < t; m++){
		int n;
		cin>>n;
		int maxUp=0;
		int maxDown=0;
		int t;
		cin>>t;
		int h=t;
		for(int i = 1; i < n; i++){
			int c;
			cin>>c;
			if(h>c){
				maxDown=max(maxDown,h-c);
			}
			else if(c>h){
				maxUp=max(maxUp,c-h);
			}
			h=c;
		}
		cout<<maxUp<<" "<<maxDown<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

auto rec(vector<vector<int>> & ret, vector<int> & sret, int i, int n){
    if(i == n){
        if(find(sret.begin(), sret.end(), 3) != sret.end()  && find(sret.begin(), sret.end(), 5) != sret.end() && find(sret.begin(), sret.end(), 7) != sret.end() && find(sret.begin(), sret.end(), 0) == sret.end()){
            ret.push_back(sret);
        }
        return 0;
    }
    rec(ret, sret, i+1, n);
    sret[i] = 3;
    rec(ret, sret, i+1, n);
    sret[i] = 5;
    rec(ret, sret, i+1, n);
    sret[i] = 7;
    rec(ret, sret, i+1, n);
    sret[i] = 0;
    return 0;
}
vector<vector<int>> bf(int n){
    vector<vector<int>> ret;
    vector<int> sret(n);
    rec(ret, sret, 0, n);
    return ret;
}

int countnumber(int n){
    int digit = log10(n) + 1;
    auto c = 0;
    for(int d = 0; d <= digit; ++d){
    auto p = bf(d);

    for(auto & x : p){
        auto val = 0;
        for(unsigned int i = 0; i < x.size(); ++i){
            val += x[i] * pow(10, static_cast<int>(x.size()) - i - 1);
        }
        if(1<= val && val <= n){
            //cout << val << endl;
            c++;
        }
    }
    }
    return c;
}
int main()
{
    int n;
    cin >> n;
    cout << countnumber(n);
    /*
    auto p = bf(3);
    for( auto & x : p){
        for(auto &y : x){
            cout << y << " ";
        }
        cout << endl;
    }
    */
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  string s;
  cin >> s;
  cout << string(s.begin(),s.begin()+4) << ' ' << string(s.begin()+4,s.begin()+12) << endl;
  return 0;
}


Measured memory_bytes: 384
N, = [int(i) for i in input().split(' ')]

import sys
hs = []
maxh = None
tt = 0
for line in sys.stdin:
    h, = line.strip().split(" ")
    h = int(h)
    tt += h
    if maxh == None:
        maxh = h
    elif h > maxh:
        maxh = h
print(tt - (maxh//2))


Measured memory_bytes: 3060
a1=input()
res=[i for i in a1.split()]
A,B=[float(res[i]) for i in (0,1)]
a,b=A.is_integer(),B.is_integer()
if a and b == True and -100<=(A and B)<=100:
    A,B=int(A),int(B)
    x=A+B
    y=A-B
    z=A*B
    print(max(x,y,z))

Measured memory_bytes: 9008
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    vector<ll> a(n+1);
    vector<ll> b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    ll ans = 0;
    rep(i,n) {
        ll ai = a[i], ai1 = a[i+1], bi = b[i];
        if (ai <= bi) {
            a[i] = 0;
            ans += ai;
            b[i] -= ai;
        } else {
            a[i] -= b[i];
            ans += b[i];
            b[i] = 0;
        }
        if (a[i+1] <= b[i]) {
            a[i+1] = 0;
            ans += ai1;
        } else {
            a[i+1] -= b[i];
            ans += b[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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

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

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

int main() {

  int h, w; cin >> h >> w;
  char s[h][w]; rep(i, h) { rep(j, w) cin >> s[i][j]; }
  char x[h][w]; rep(i, h) { rep(j, w) x[i][j] = '.'; };

  rep(i, h) {
    rep(j, w) {
      if(s[i][j]=='#') {
        if(i+1<h) {
          if(s[i+1][j]=='#') x[i+1][j] = x[i][j] = '#';
        }
        if(i-1>=0) {
          if(s[i-1][j]=='#') x[i-1][j] = x[i][j] = '#';
        }
        if(j+1<w) {
          if(s[i][j+1]=='#') x[i][j+1] = x[i][j] = '#';
        }
        if(j-1>=0) {
          if(s[i][j-1]=='#') x[i][j-1] = x[i][j] = '#';
        }
      }
    }
  }

  rep(i, h) {
    rep(j, w) {
      if(s[i][j]!=x[i][j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts, BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

solve w t = length $ filter (== w) $ words t

main = do
    w <- getLine
    t <- getContents
    print $ solve (toLower <$> w) (toLower <$> t)


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int s, w; cin >> s >> w;

    if (w >= s) {
        puts("unsafe");
    } else {
        puts("safe");
    }
}

Measured memory_bytes: 3676
#include <iostream>
#include <set>
#include <string>
#include <map>

using namespace std;

int n;
set <string> s;
string s1;
map<string, int> map1;
int main()
{
    cin >> n;
    for(int i= 0; i < n; i++)
    {
        cin >> s1;
        map1[s1]++;
    }
    int ma = 0;
    for(map<string,int>::iterator it = map1.begin(); it != map1.end(); it++)
    {
        if(it -> second > ma) ma = it -> second;
    }
    for(map<string,int>::iterator it = map1.begin(); it != map1.end(); it++)
    {
        if(it -> second == ma) s.insert(it -> first);
    }
    for(set<string>::iterator it = s.begin(); it != s.end(); it++)
    {
        cout <<(*it) << endl;
    }
    return 0;
}

Measured memory_bytes: 34560
/* ABC133-C.c
   Takatan */

#include<stdio.h>
#define NUM 2019
int main(void){
    int left, right, min, judge, i, j;

    min = 2018;

    scanf( "%d %d" , &left, &right); /* 入力 */

    if(right>left+NUM){ /* NUMの倍数が含まれるとき */

        printf( "0\n" ); /* あまりの最小値は0になる */

        return 0;

    }

    right = right-left;
    left = left%NUM;
    right = right + left; /* 法NUMとしてleftと合同かつ正の最小値となる値に変換 */

    for(i=left; i < right; i++){

        for(j=i+1; j <= right; j++){

            judge = (i * j) % NUM; /* judgeするあまりを求める */

            if(judge<min){ /* judgeが暫定最小となるとき */

                min = judge; /* 最小値を更新 */

            }

            if(min==0){

                printf( "%d\n" , min);

                return 0;

            }

        }

    }

    printf( "%d\n" , min);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct vect{
	int x, y;
};

bool equals(vector< vect > v1, vector< vect > v2 ){
	bool flg[8];
	bool ret = false;

	if( v1.size() != v2.size() ) return false;

	for(int i = 0; i < 8; i++)
		flg[i] = true;

	for( int i = 0; i < 2; i++ ) {
		int indx;
		for(int j = 0; j < 4; j++) {
			if( i == 0 ) indx = 0;
			else indx = v1.size() - 1;
			for(int _indx = 0; _indx < v2.size(); _indx++) {
				if( j == 0 ) {
					flg[ j + i * 4 ] &= ( v1[indx].x == v2[_indx].x && v1[indx].y == v2[_indx].y );
				} else if( j == 1 ) {
					flg[ j + i * 4 ] &= ( v1[indx].x == -v2[_indx].y && v1[indx].y == v2[_indx].x );
				} else if( j == 2 ) {
					flg[ j + i * 4 ] &= ( v1[indx].x == -v2[_indx].x && v1[indx].y == -v2[_indx].y );
				} else if( j == 3 ) {
					flg[ j + i * 4 ] &= ( v1[indx].x == v2[_indx].y && v1[indx].y == -v2[_indx].x );
				}
				if( i == 0 ) indx ++;
				else indx --;
			}

		}

	}

	for(int i = 0; i < 8; i++)
		ret |= flg[i];

	return ret;
}

int main(void){

	//与えられる座標をベクトルに変換する
	while( 1 ) {
		int n;
		cin >> n;
		if( n == 0 ) break;

		vector< vector< vect > > vv;

		for(int i = 0; i <= n; i++) {
			vector< vect > line;
			int m, px, py;
			cin >> m >> px >> py;
			for(int j = 0; j < m - 1; j++) {
				int x, y;
				cin >> x >> y;
				vect nv;
				nv.x = x - px;
				nv.y = y - py;
				px = x;
				py = y;
				line.push_back( nv );
			}
			vv.push_back( line );
		}

		for(int i = 1; i < vv.size(); i++)
			if( equals( vv[0], vv[i] ) ) cout << i << endl;

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

Measured memory_bytes: 1224
N = int(input())
m = N
for n6 in range(N+1):
  n9 = N - n6
  q6 = n6; q9 = n9
  c6 = c9 = 0
  while q6 > 0:
    c6 += int(q6%6)
    q6 = int(q6//6)
  while q9 > 0:
    c9 += int(q9%9)
    q9 = int(q9//9)
  if m > c9 + c6:
    m = c9 + c6
print(m)

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  std::string T;
  std::cin >> T;
  for (int i = 0; i < T.size(); ++i)
    if (T[i] != '?')
      cout << T[i];
    else
      cout << 'D';
  cout << endl;

  return 0;
}


Measured memory_bytes: 3728
from collections import deque


def bfs(x, w):
    q = deque()
    q.append((x, w))

    while len(q):
        x, w = q.popleft()
        leaves[x] += w
        w = leaves[x]
        for nx in edge[x]:
            if V[nx] == 0:
                V[nx] = 1
                q.append((nx, w))


N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
leaves = [0] * N
V = [0] * N

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

for q in range(Q):
    p, x = map(int, input().split())
    p -= 1
    leaves[p] += x

V[0] = 1
bfs(0, 0)
for i in range(N - 1):
    print(leaves[i], end=' ')
print(leaves[N - 1])


Measured memory_bytes: 58516
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }

int32_t main(){
	IOS;
	map<int,int> cnt;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		cnt[x]++;
	}
	int ans = 0;
	for(int i=(1<<30); i>=2; i/=2){
		for(auto j : cnt){
			int x = j.X;
			int ted = j.Y;
			int y = i - x;
			if(x > y) break;
			if(x == y){
				if(ted >= 2){
					//cout << i << " " << x << " " << ted/2 << endl;
					ans += ted/2;
					cnt[x] -= (ted/2) * 2;
				}
			}
			else{
				int tmp = min(cnt[x], cnt[y]);
				ans += tmp;
				cnt[x] -= tmp;
				cnt[y] -= tmp;
				//if(tmp)
				//	cout << ":D" << i << " " << tmp << endl;
			}
		}		
	}
	cout << ans << endl;
}

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



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

    int ans = 0;
    rep(i,N){
        int x; cin >> x;
        ans += 2*(min(x, abs(K-x)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import queue

N=int(input())
G=[[] for index1 in range(N+1)]
for index in range(1,N):
    a,b=map(int,input().split())
    G[a].append((b,index))
    G[b].append((a,index))

#A[i]=辺iの色
A=[0]*N
q=queue.Queue()

#bfs
#(ノード、色、親)
q.put((1,0,0))
while not q.empty():
    now=q.get()
    i=1 #色
    for next in G[now[0]]:
        if next[0]==now[2]: #親
            continue
        else:
            if i==now[1]:
                i+=1
            A[next[1]]=i    #色を定める
            q.put((next[0],i,now[0]))
            i+=1

    #print(now,(next[0],i,now[0]))


print(max(A))
for j in range(N-1):
    print(A[j+1])


    






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

int main()
{
    int N, Z, W;
    int A[2005];

    cin >> N >> Z >> W;

    for(int i = 0; i < N; i++) cin >> A[i];

    cout << max(abs(W - A[N - 1]), abs(A[N - 1] - A[max(N - 2, 0)])) << endl;
    return (0);
}


Measured memory_bytes: 256
#include <stdio.h>
  
int main(){
        int val[5];
        int valmax,valmin,i,k;

        for(i = 0; i < 5; i++){
                scanf("%d", &val[i]);
        }
        scanf("%d", &k);

        valmax = valmin = val[0];
        for(i = 1; i < 5; i++){
                if(valmax < val[i])valmax = val[i];
                if(valmin > val[i])valmin = val[i];
        }

        if((valmax - valmin) <= k)printf("Yay!\n");
        else printf(":(\n");

        return 0;
}


Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        am: [usize; m],
    }

    let todo: usize = am.iter().sum();

    let ans: i64 = if n >= todo {
        (n - todo) as i64
    } else {
        -1
    };

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


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

int main(){
    while(true){
        int a, b; char op;
        cin >> a >> op >> b;
        if(op == '?') break;
        int ans;
        if(op == '+') ans = a + b;
        if(op == '-') ans = a - b;
        if(op == '*') ans = a * b;
        if(op == '/') ans = a / b;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3096
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 405;
const int mod = 1000000007;

int n;
int A[Maxn], B[Maxn];
bool unA[Maxn][Maxn], unB[Maxn][Maxn];
int cnt[Maxn][Maxn];
bool tk[Maxn];
int dp[Maxn][Maxn][Maxn];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &A[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &B[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)
			unB[i][j] = !tk[B[j]];
		tk[A[i]] = true;
	}
	fill(tk, tk + Maxn, false);
	for (int j = 1; j <= n; j++) {
		for (int i = 1; i <= n; i++)
			unA[i][j] = !tk[A[i]];
		tk[B[j]] = true;
	}
	for (int j = 0; j <= n; j++)
		cnt[0][j] = j;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (!unA[i][j]) cnt[i][j] = cnt[i - 1][j];
			else if (A[i] == B[j]) cnt[i][j] = cnt[i - 1][j - 1] + 1;
			else cnt[i][j] = cnt[i - 1][j] + 1;
	dp[0][1][1] = 1;
	int R = n / 3;
	for (int i = 0; i < R; i++)
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++) if (dp[i][j][k] != 0) {
				if (!unA[j][k]) { dp[i][j + 1][k] = (dp[i][j + 1][k] + dp[i][j][k]) % mod; continue; }
				if (!unB[j][k]) { dp[i][j][k + 1] = (dp[i][j][k + 1] + dp[i][j][k]) % mod; continue; }
				if (A[j] != B[k])
					dp[i + 1][j + 1][k + 1] = (dp[i + 1][j + 1][k + 1] + dp[i][j][k]) % mod;
				int took = cnt[j - 1][k - 1] - 2 * i;
				if (took < 0 || took > i) continue;
				int car = ll(i - took) * dp[i][j][k] % mod;
				if (A[j] == B[k])
					dp[i][j + 1][k + 1] = (dp[i][j + 1][k + 1] + car) % mod;
				else {
					dp[i][j + 1][k] = (dp[i][j + 1][k] + car) % mod;
					dp[i][j][k + 1] = (dp[i][j][k + 1] + car) % mod;
					int spec = ll(i - took) * ll(i - took - 1) % mod * dp[i][j][k] % mod;
					dp[i][j + 1][k + 1] = (dp[i][j + 1][k + 1] - spec + mod) % mod;
				}
			}
	int tot = 0;
	for (int j = 1; j <= n + 1; j++)
		for (int k = 1; k <= n + 1; k++) if (dp[R][j][k] != 0) {
			int cand = dp[R][j][k];
			int lft = n - cnt[j - 1][k - 1];
			while (lft > 0) { cand = ll(cand) * lft % mod; lft--; }
			tot = (tot + cand) % mod;
		}
	int was = 0;
	for (int i = R - 1; i >= 0; i--) {
		was++;
		tot = ll(tot) * was % mod;
		was++;
		tot = ll(tot) * was % mod;
		was++;
	}
	printf("%d\n", tot);
	return 0;
}

Measured memory_bytes: 86656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int k=scan.nextInt(), a=scan.nextInt(), b=scan.nextInt();

		int largest = (b / k) * k;


		if(a <= largest) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}



	}
}


Measured memory_bytes: 26940
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <cmath>
#include <limits>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;

int main() {
  //input
  string s, t;
  cin >> s>> t;
  
  if(s.length() == (t.length()-1) &&
     s == t.substr(0,t.length()-1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  
}

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

using namespace std;

int main() {
	long long n, a[106];
	long long res = -1;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n - 1; ++i)
		for (int j = i + 1; j < n; ++j)
			res = max(res, (long long)abs(a[i] - a[j]));
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int a,b,c,k;cin >> a >> b >> c >>k;
    if ( k <= a){
        cout << k;
    } else if( a < k && k <= a+b){
        cout << a;
    } else if ( a+b < k && k <=a+b+c){
        cout << a - (k-a-b);
    } else {
        cout << a-c;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int n, m, q;
vv(int) V(4, vector<int>(50));

vector<int> A(10);
int ans;

void	dfs(int id, int pre)
{
	if (id == n)
	{
		int now = 0;
		for (int i = 0; i < q; ++i)
			if (A[V[1][i]-1] - A[V[0][i]-1] == V[2][i])
				now += V[3][i];
		ans = max(ans, now);
	}
	else
	{
		for (int i = pre; i <= m; ++i)
		{
			A[id] = i;
			dfs(id+1, i);
		}
	}
}

int		main(void)
{
	cin >> n >> m >> q;

	for (int i = 0; i < q; ++i)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		V[0][i] = a;
		V[1][i] = b;
		V[2][i] = c;
		V[3][i] = d;
	}
	dfs(0, 1);
	cout << ans << endl;
}



Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
    int a;
    cin >> a;
    if(a<1200){
        cout << "ABC"<< endl;
    }else if(a<2800){
        cout << "ARC"<< endl;
    }else{
        cout << "AGC"<< endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
#define int ll
int n, q;
int a[100005], dp[100005];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[2]-a[1]);
    for(int i=3; i<=n; i++){
        int x=dp[1];
        dp[1]=min(dp[1]+abs(a[i]-a[i-1]), dp[0]+abs(a[i]-a[i-2]));
        dp[0]=x;
    }
    cout<<dp[1];
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int ball[9][9][9];
int h[9][9];


int winner(const vector<int> &x, const vector<int> &y, int m){
	memset(**ball, 0, sizeof(ball));
	memset(*h, 0, sizeof(h));

	int clr = 1;
	int p = x.size();
	for(int i = 0; i < p; ++i){
		int xi = x[i];
		int yi = y[i];
		
		ball[xi][yi][++h[xi][yi]] = clr;
		
		int cb[27] = {};
		
		for(int dx = -1; dx <= 1; ++dx)
		for(int dy = -1; dy <= 1; ++dy)
		for(int dz = -1; dz <= 1; ++dz){
			if( !dx && !dy && !dz ) continue;

			int px = xi + dx;
			int py = yi + dy;
			int pz = h[xi][yi] + dz;
			int c = 0;
			while( ball[px][py][pz] == clr ){
				++c;
				px += dx;
				py += dy;
				pz += dz;
			}
			cb[(dx + 1) * 9 + (dy + 1) * 3 + (dz + 1)] = c;
		}
		
		for(int j = 0; j < 13; ++j){
			if( cb[j] + cb[26 - j] + 1 >= m ){
				return i + 1;
			}
		}
		
		clr = 3 - clr;
	}
	
	return 0;
}


int main(){
	int m, p;
	while( scanf("%*d%d%d", &m, &p), m != 0 ){
		vector<int> x(p), y(p);
		for(int i = 0; i < p; ++i){
			scanf("%d%d", &x[i], &y[i]);
		}
		
		int t = winner(x, y, m);
		if( t == 0 ){
			puts("Draw");
		}
		else if( t % 2 == 0 ){
			printf("White %d\n", t);
		}
		else{
			printf("Black %d\n", t);
		}
	}
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
const int MN=100000+5;
using namespace std;
typedef long long ll;
template<typename T>T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	in*=f;return in;
}
int n,m;
int a[MN],b[MN],c[MN];
void input(){
	IN(n),IN(m);
	for(int i=1;i<=m;++i){
		IN(a[i]);
		if(a[i]%2)b[++b[0]]=a[i];
	}
	if(m==1&&a[1]!=1)return printf("%d\n%d\n%d %d",a[1],2,a[1]-1,1),void();
	if(b[0]>2)return puts("Impossible"),void();
	if(b[0])printf("%d ",b[b[0]]),c[++c[0]]=b[b[0]]+1;
	else c[++c[0]]=1;
	for(int i=1;i<=m;++i)if(a[i]%2==0)printf("%d ",a[i]),c[++c[0]]=a[i];
	if(b[0]==2)printf("%d\n",b[1]),c[++c[0]]=b[1]-1;
	else c[c[0]]--,puts("");
	while(!c[c[0]]&&c[0]>1)c[0]--;
	int s=0;
	for(int i=1;i<=c[0];++i)s+=c[i];
	if(s!=n)c[++c[0]]=1;
	printf("%d\n",c[0]);
	for(int i=1;i<=c[0];++i)printf("%d ",c[i]);
}
int main(){
	input();
	return 0;
}

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

int main(){
  string n;
  ll a,b=0;

  cin>>n;

  rep(i, n.size()){
      a = n[i]-'0';
      b+=a;
  
  }

  

  if(b%9==0) cout<<"Yes"<<endl;
  else 
  cout<<"No"<<endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> order(n);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        order[a-1] = i+1;
    }
    cout << order[0];
    for(int i=1; i<n; i++){
        cout << ' ' << order[i];
    }
    cout << endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi p(n);
    REP(i, n)
        cin >> p[i];
    int ans = 0;
    for (int i = 1; i < n - 1; ++i)
    {
        if (min(p[i - 1], p[i + 1]) < p[i] and p[i] < max(p[i - 1], p[i + 1])) {
            ans++;
            // cerr << i << " " << p[i] << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
	char x[101010];
	scanf("%s",x);
	int a=strlen(x);
	int sum1=0,sum2=0;
	for(int i=0;i<a;i++)
	{
		if(x[i]=='0')
		sum1++;
		else if(x[i]=='1')
		sum2++;
	}
	if(sum1>sum2)
	printf("%d\n",sum2*2);
	else
	printf("%d\n",sum1*2);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    int a[n+1]={0};
    for(int j=0;j<m;j++){
        int i;
        cin>>i;
        if(i!=0 || i!=n || i!=x)a[i]=1;
    }
    int ls=0,rs=0;
    for(int i=x;i>=0;i--)ls+=a[i];
    for(int i=x;i<=n;i++)rs+=a[i];
    cout<<min(ls,rs);
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cmath>
#include <algorithm>

using namespace std;

#define INF (1<<28)

bool operator<(const pair<int, int> &a, const pair<int, int> &b) {
    return a.first * b.second < b.first * a.second;
}

void reduce(pair<int, int> &a) {
    int gcd = __gcd(a.first, a.second);
    a.first /= gcd;
    a.second /= gcd;
}

int main() {
    int p, n;
    while (cin >> p >> n) {
        if (p == 0 && n == 0) break;
        double sqrt_p = sqrt(p);

        pair<int, int> lb(0, 1), ub(INF, 1);
        for (int i = 1; i <= n; i++) {
            pair<int, int> l = make_pair(floor(sqrt_p*i), i);
            if (l.first <= n && lb < l) lb = l;
            pair<int, int> u = make_pair(ceil(sqrt_p*i), i);
            if (u.first <= n && u < ub) ub = u;
        }

        reduce(lb); reduce(ub);

        cout << ub.first << '/' << ub.second << ' ';
        cout << lb.first << '/' << lb.second << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}
//最小公倍数
ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
 
 
 
int main() {
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  rep(i,n){
    if(s[i]==s[i+1]){
      continue;
    }
    ans++;
  }
  cout<<ans;
}




Measured memory_bytes: 512
a, b, x = 4, 8, 3
a, b, x = 0, 5, 1
a, b, x = 9, 9, 2
a, b, x = 1, 1000000000000000000, 3

a, b, x = map(int,input().split())


def calculate(a, b, x):
    s1 = (a - 1) // x

    if s1 < 0:
        s1 = 0
    else:
        s1 += 1
    s2 = b // x + 1

    print(s2 - s1)


calculate(a, b, x)


Measured memory_bytes: 9132
#include<stdio.h>
#include<string.h>
int main(){
    static char str[300000];
    static char x[300000];
    static char tmp[300000];

    scanf("%s",str);

    int cnt=1;
    tmp[0]=str[0];
    tmp[1]='\0';
    strcpy(x,"");

    int x_i=0;
    for(int i=1;str[i]!='\0';i++){
        x[x_i++]=str[i];
        x[x_i]='\0';
        if(strcmp(tmp,x)){
            x_i=0;
            //printf("tmp:%s x:%s\n",tmp,x);
            cnt++;
            strcpy(tmp,x);
            strcpy(x,"");
        }
    }
    printf("%d\n",cnt);

    return 0;
}

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

int main() {

    string s; cin >> s;
    int posA = -1, posZ = -1;
    for( int i = 0 ; i < (int)s.size() ; ++i ){
        if( posA == -1 && s[i] == 'A' ) posA = i;
        if( s[i] == 'Z' ) posZ = i;
    }
    //cout << posZ << ' ' << posA << '\n';
    cout << (posZ - posA)+1 << '\n';
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 a,b,c;
    cin >> a >> b >> c;
    cout << max<int32>(0, c - (a - b)) << endl;
    return 0;
}

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

using namespace std;

#define int long long

const int N = 3e3 + 5, inf = 1e18 + 123;
int n, a[N], dp[2][N][N];

int solve (bool _, int l, int r) {
    if (l > r) return 0;
    if (dp[_][l][r] != inf) return dp[_][l][r];
    if (!_) {
        dp[_][l][r] = max(solve(_ ^ 1, l, r - 1) + a[r], solve(_ ^ 1, l + 1, r) + a[l]);
    }
    else {
        dp[_][l][r] = min(solve(_ ^ 1, l, r - 1) - a[r], solve(_ ^ 1, l + 1, r) - a[l]);
    }
    return dp[_][l][r];
}

int32_t main () {
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) scanf("%lld", a + i);

    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) dp[0][i][j] = dp[1][i][j] = inf;

    cout << solve(0, 1, n);

    return 0;
}


Measured memory_bytes: 141440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args)throws IOException{
		Integer[] height=new Integer[10];
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		for(int i=0; i<10; i++){
			height[i]=Integer.valueOf(br.readLine());
		}

		int a=0;

		for(int j=0; j<9; j++){
			for(int k=9; k>j; k--){
				if(height[k]<height[k-1]){
					a=height[k];
					height[k]=height[k-1];
					height[k-1]=a;
				}
			}
		}

		for(int l=0; l<3; l++){
			System.out.println(height[9-l]);
		}
	}
}

Measured memory_bytes: 24292
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let day1 = read_as_vec::<u32>();
    let day2 = read_as_vec::<u32>();

    if day1[0] != day2[0]{
        println!("1");
    }else{
        println!("0");
    }
}


Measured memory_bytes: 4352