akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    string str;
    cin >> str;

    int res = 1;
    for (int i = 1; i < n; i++) {
        if (str[i - 1] != str[i]) ++res;
    }

    cout << res << endl;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<char> even = {'R', 'U', 'D'};
  vector<char> odd = {'L', 'U', 'D'};

  rep(i,s.size()){
    bool ok = false;
    if(i%2 == 0){
      for(char ch:even) if(ch == s[i]) ok = true;
    }else{
      for(char ch:odd) if(ch == s[i]) ok = true;
    }
    if(ok == false){cout << "No" << "\n"; return 0;}
  }
  cout << "Yes" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<functional>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;
typedef vector<long long int> vll;

int main() {
	int n;
	cin >> n;
	int odd = 0, two = 0, four = 0;
	rep(i, 0, n) {
		i64 a;
		cin >> a;
		if (a % 4 == 0) four++;
		else if (a % 2 == 0) two++;
		else odd++;
	}
	if (two == 0) {
		if (odd <= four + 1)cout << "Yes\n";
		else cout << "No\n";
	}
	else {
		if (odd <= four)cout << "Yes\n";
		else cout << "No\n";
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int h, w;
	cin >> h >> w;
	vector<string> g(h);
	for(int i = 0; i < h; i++) {
		cin >> g[i];
	}
	vector<vector<bool>> vis(h, vector<bool>(w));
	vector<vector<int>> check(h, vector<int>(w));
	int c = 0;
	long long ans = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(vis[i][j]) continue;
			c++;
			long long cnt_b = 0, cnt_w = 0;
			queue<pair<int, int>> que;
			que.push(make_pair(i, j));
			vis[i][j] = true;
			if(g[i][j] == '#') cnt_b++;
			else cnt_w++;
			while(que.size()) {
				int x = que.front().first;
				int y = que.front().second;
				que.pop();
				check[i][j] = c;
				int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
				for(int k = 0; k < 4; k++) {
					int xx = x + dx[k];
					int yy = y + dy[k];
					if(xx < 0 || xx >= h || yy < 0 || yy >= w || vis[xx][yy] || g[xx][yy] == g[x][y]) continue;
					vis[xx][yy] = true;
					if(g[xx][yy] == '#') cnt_b++;
					else cnt_w++;
					que.push(make_pair(xx, yy));
					check[xx][yy] = c;
				}
			}
			ans += cnt_b * cnt_w;
		}
	}
	/*for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cout << check[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize ("O3")
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      ll n;
      cin>>n;
      ll a[n+1];
      rep1(i,n) cin>>a[i];
      multiset<ll> t{0,0,n+1,n+1};
      ll index[n+1];
      rep1(i,n) index[a[i]]=i;
      ll ans=0;
      for(ll j=n;j>=1;j--){
            auto itr=t.lower_bound(index[j]);
            --itr;
            --itr;
            ll x0=*(itr);
            ll x1=*(++itr); 
            ll x2=*(++itr); 
            ll x3=*(++itr);
            ans+=(j*((x1-x0)*(x2-index[j])+(index[j]-x1)*(x3-x2)));
            //cout<<ans<<endl;
            t.insert(index[j]);
            //cout<<x0<<" "<<x1<<" "<<x2<<" "<<x3<<endl;
      }
      cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    }
 
    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
ll num=1, ans=0, count=0, sum=0;

int main() {
  ll K;
  cin >> K;
  
  string str;
  bool Lunlun =true;
  while(K>1) {
    if(Lunlun) num++;
    str = to_string(num);
    
    Lunlun = true;
    rep(i, str.size()-1) {
      if(str[i+1]-str[i]>1) {
        string copy;
        rep(j, i+1) copy += str[j];
        num = stoll(copy)+1;
        rep(j, str.size()-i-1) num *= 10;
        Lunlun = false;
        break;
      } else if(str[i]-str[i+1]>1) {
        str[i+1]=str[i]-1;
        num = stoll(str);
        Lunlun = false;
        break;
      }
    } 
    
    if(Lunlun) K--;
  }
  
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int getSum(char st[]);

int main(int argc, const char * argv[]) {
    // insert code here...
    while(1){
        char st[1000];
        scanf("%s",st);
        
        if(st[0] == '0'){
            break;
        }
        
        printf("%d\n",getSum(st));
        
    }
    
    return 0;
}

int getSum(char st[]){
    int sum = 0;
    
    int i;
    for(i=0;i<1000;i++){
        if(st[i] == '\0'){
            break;
        }
        else{
            sum += (int)st[i] - 48;
        }
    }
    
    
    return sum;
}

Measured memory_bytes: 536
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }

int n, k, a[200000], tmp[200000];
//merge [l,m) with [m,r)
void Merge(int l, int m, int r) {
    int i = l, j = m, k = l;
    for (; i < m || j < r; ++k) {
        if (i == m)
            tmp[k] = a[j++];
        else if (j == r)
            tmp[k] = a[i++];
        else if (a[i] < a[j])
            tmp[k] = a[i++];
        else
            tmp[k] = a[j++];
    }
    for (k = l; k < r; ++k)
        a[k] = tmp[k];
}

void MergeSort() {
    for (int range = 1; range < n; range *= 2) {
        for (int i = 0; i < n; i += range * 2) {
            if (i + range < n)
                Merge(i, i + range, min(i + range * 2, n));
        }
    }
}

int main() {
    init();
    
    cin >> n >> k;
    FOR(i, 0, n)cin >> a[i];
    MergeSort();
    ll ans = 0;
    FOR(i, 0, n - k)ans += a[i];
    print(ans);

    return 0;
}

Measured memory_bytes: 5168
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL ec = 0,hed[10005] = {0},nxt[20005],to[20005];
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL n,sum = 1LL;
LL an1 = INF,an2 = INF;
LL mxd[10005],dep[10005],deg[10005],ans[10005];
LL eu[10005],ev[10005];

void dfs(LL u,LL f){
	dep[u] = dep[f] + 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		deg[u] ++;
	}
	ans[dep[u]] = max(ans[dep[u]],deg[u]);
}

int main(){
	LL u,v,tmp = INF;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> eu[i] >> ev[i];
		add_edge(eu[i],ev[i]);
		add_edge(ev[i],eu[i]);
	}
	
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= n;j ++) ans[j] = 0,deg[j] = 0;
		tmp = 0; sum = 1LL; dfs(i,0);
		for(LL j = 1;j <= n;j ++) tmp = max(tmp,dep[j]),sum *= (ans[j] ? ans[j] : 1LL);
		if(tmp == an1) an2 = min(an2,sum);
		if(tmp < an1){ an1 = tmp; an2 = sum; }
	}
	for(LL i = 1;i < n;i ++){
		u = eu[i],v = ev[i];
		for(LL j = 0;j <= n;j ++) ans[j] = 0,deg[j] = 0;
		tmp = 0; sum = 1LL; dep[u] = 0; dfs(v,u); dep[v] = 0; dfs(u,v);
		for(LL j = 1;j <= n;j ++) tmp = max(tmp,dep[j]),sum *= (ans[j] ? ans[j] : 1LL);
		sum <<= 1;
		if(tmp == an1) an2 = min(an2,sum);
		if(tmp < an1){ an1 = tmp; an2 = sum; }
//		for(LL i = 1;i <= n;i ++) cout << i << ',' << ans[i] << endl;
	}
	
	cout << an1 << ' ' << an2 << endl;
	return 0;
}

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

int main()
{
    int N;

    cin >> N;
    vector<vector<int>> G(N);
    vector<pair<int, int>> vp;
    
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        vp.push_back(make_pair(a, b));
    }
    
    int K = 0;
    map<pair<int, int>, int> I;
    vector<int> cs(N, 0);
    vector<int> used(N, 0);
    queue<int> que;
    used[0] = 1;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();
        K = max(K, (int)G[v].size());

        int cur = 1;

        for (int u : G[v]) {
            if (used[u]) continue;
            if (cur == cs[v]) cur++;
            cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
            used[u] = 1;
            que.push(u);
        }
    }
    printf("%d\n", K);
    for (auto p : vp) cout << I[p] << endl;
    return 0;
}

Measured memory_bytes: 20084
# include <iostream>
# define DIM 100010
using namespace std;
int v[DIM],n,k,i,nr,ok;
int main () {
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>v[i];
    k=v[1];
    for(i=1;i<=n;i++)
        if(v[i]<=k-2||v[i]>=k+2){
            cout<<"No\n";
            return 0;
        }
    for(i=1;i<=n;i++)
        if(v[i]==k+1)
            k++;
    for(i=1;i<=n;i++)
        if(v[i]==k-2){
            cout<<"No\n";
            return 0;
        }
    for(i=1;i<=n;i++)
        if(v[i]==k-1)
            nr++;
    ok=1;
    for(i=1;i<=n;i++)
        if(v[i]!=k)
            ok=0;
    if(ok&&k==n-1){
        nr=n;
        k++;
    }
    if(nr>k){
        cout<<"No\n";
        return 0;
    }
    if(nr+2*(k-nr)>n){
        cout<<"No\n";
        return 0;
    }
    if(nr==n&&n!=k){
        cout<<"No\n";
        return 0;
    }
    if(nr==k&&k!=n){
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    return 0;
}


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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
int n,a[200001],b[200001],k;
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	rep(i,n){
		cin>>a[i];
	}
	if(n%2==0){
		k=1;
		b[n/2+1]=a[1];
		rep(i,n/2-1){
			k++;
			b[n/2+1-i]=a[k];
			k++;
			b[n/2+1+i]=a[k];
		}
		b[1]=a[n];
	}
	else{
		k=1;
		b[n/2+1]=a[1];
		rep(i,n/2){
			k++;
			b[n/2+1+i]=a[k];
			k++;
			b[n/2+1-i]=a[k];
		}
	}
	rep(i,n){
		cout<<b[i]<<' ';
	}
	return 0;
}

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

#define M 100000
int main(){
  int n,a[M],i;

  int c=0;
  cin>>n>>a[0];
  for(i=1;i<n;i++){
    cin>>a[i];
    if(a[i]>a[i-1])c++;
  }

  cout<<c<<endl;
  return 0;
}



Measured memory_bytes: 3488
import java.io.*;
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
    int i=0;
    int[] answer = new int[26];
    
    Scanner scan = new Scanner(System.in);
    while(scan.hasNext()){
    try{
      String line = scan.nextLine();
      for(i = 0;i < 1200;i++){
        int n = line.charAt(i);
        if(n >= 97 && n <= 122){
          answer[n - 97] += 1;
        }else if (n >= 65 && n <= 90){
          answer[n - 65] += 1;
        }else{

        }
      }
      
		}catch(Exception e){
    }
  }
  for(i = 0;i<26;i++){
    char c= (char) ('a' + i);
    System.out.println(c + " : "+answer[i]);
  }
  

  }
}


Measured memory_bytes: 26096
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i=0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)

int main()
{
    int p,q,r;
    cin >> p >> q >> r;
    int t = min(r+p, min(p+q, q+r));
    cout << t << endl;
    return 0;
}

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

int main(){
  int N;
  string s;
  cin >> N >> s;
  int r=0;
  int b=0;
  for (int i;i<N;i++){
    if(s[i]=='R'){
      r++;
    }
    else{
      b++;
    }
  }
  if(r>b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;

#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)





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

  vector<ll> r;
  vector<ll> g;
  vector<ll> b;

  REP(i,n){
    if(s.at(i)=='R'){
      r.push_back(i);
    }else if(s.at(i)=='G'){
      g.push_back(i);
    }else if(s.at(i) == 'B'){
      b.push_back(i);
    }
  }

  ll count =r.size()*g.size()*b.size();

  REP(i,n){
    REP1(j,n){
      if(i+2*j<n){
        if(s.at(i)!=s.at(i+j) && s.at(i+j)!=s.at(i+2*j) 
        && s.at(i)!=s.at(i+2*j)){
          count--;
        }
      }
    }
  }

  cout << count << endl;
 
}

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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=1e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);


int main()
{
    string s;
    cin>>s;
    for(int i=0;i<3;i++)
        cout<<s[i];
    return 0;
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2






int queue[MAX], color[MAX], M[MAX][MAX], d[MAX];
int end, top;

void enqueue(int n){


 if(end == MAX)
   end = 0;

   queue[end] = n;
   end++;

}

int dequeue(){
int retval;

  if(top == MAX)
   top = 0;


  retval = queue[top];

  top++;

  return retval;
}

void bfs(int s, int f){
int u, count = 0;
 enqueue(s);

  while(end != top){
   u = dequeue();
   color[u] = BLACK;
    while(M[u][count] != 0){
     if(color[M[u][count]] == WHITE){
      enqueue(M[u][count]);
      color[M[u][count]] = GRAY;
      d[M[u][count]] = d[u] + 1;
     }
     count += 1;
 }

    count = 0;
  }

}

int main(){
int count = 0, n, count2, id, num;
 scanf("%d", &n);
 for(count; count < n; count++){
  scanf("%d %d", &id, &num);
   for(count2 = 0; count2 < num; count2++){
     scanf("%d", &M[id][count2]);
   }

 }


 bfs(1, 0);

 for(count2 = 0; count2 < n; count2++){
   if(d[count2 + 1] != 0 || count2 == 0)
   printf("%d %d\n", count2+1, d[count2+1]);
   else
   printf("%d %d\n", count2+1, -1);

 }


 return 0;
}

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

int main(){

int a; cin >> a;
string s; cin >> s;

if( a >= 3200 ){
  cout << s;
}
else{
  cout << "red";
}

return 0;

}

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

int main(){
    string str;
    int i = 0;

    cin >> str;
    
    while(str[i] != '\0'){
        if(str[i] == ','){
            str[i] = ' ';
        }
        i++;
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){
  if ((B+A) % 2 == 0) {
    cout << (B+A) / 2 << endl;
  } else {
    cout << NO << endl;
  }
}

signed main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
}


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

using namespace std;

int main(){
    int V,H;
    char camp[50][50];
    int step[50][50];
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};

    cin>>V>>H;

    for(int i=0;i<V;i++){
        for(int j=0;j<H;j++){
            cin>>camp[i][j];
        }
    }

    bool can = true;

    for(int i=0;i<V;i++){
        for(int j=0;j<H;j++){
            if(camp[i][j] == '#'){
                int count = 1;
                for(int k=0;k<4;k++){
                    if(camp[i+dy[k]][j+dx[k]] == '#'){
                        count++;
                    }
                }
                if(count < 2) can = false;
            }
        }
    }

    if(can) cout<<"Yes\n";
    else cout<<"No\n";



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    int x, y, z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;


    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;
// mp::cpp_int
// mp::cpp_dec_float_100



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  ll k, a, b;
  cin >> k >> a >> b;
  
  bool ans = false;
  rep(i, a, b+1) {
    if(i%k==0) ans = true;
  }
  cout << (ans ?"OK" :"NG") << "\n";
}

Measured memory_bytes: 3640
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s = input()

a, b = list(map(int, input().split()))
hoge = 100000
ans = 0
if a == 1 and b == 1:
    ans = 1000000
else:
    if a <= 3:
        ans += (4-a) * hoge
    if b <= 3:
        ans += (4-b) * hoge


print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    vint cnt(M);
    REP(i,N){
        int K; cin>>K;
        REP(j,K){
            int a; cin>>a;
            cnt[a-1]++;
        }
    }
    
    int ans=0;
    REP(i,M){
        if(cnt[i]==N) ans++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
struct node {
	int to,next,v;
}a[1000001];
int head[100001],cnt,dis[1000001],vis[100001],f[100001];
void add(int x,int y,int v){
	a[++cnt].next=head[x];
	a[cnt].to=y;
	a[cnt].v=v;
	head[x]=cnt;
}
void dfs(int x,int c){
	vis[x]=c;
	for(int i=head[x];i;i=a[i].next){
		int v=a[i].to;
		if(vis[v]==-1) dfs(v,c^1);
		else if(vis[v]!=(c^1)) puts("-1"),exit(0);
	}
}
queue<int> q;
void spfa(int s){
	q.push(s);
	memset(dis,127/3,sizeof(dis));
	f[s]=1,dis[s]=0;
	while(!q.empty()){
		int now=q.front();
		q.pop(),f[now]=0;
		for(int i=head[now];i;i=a[i].next){
			int v=a[i].to;
			if(dis[v]>dis[now]+a[i].v){
				dis[v]=dis[now]+a[i].v;
				if(!f[v]) q.push(v),f[v]=1;
			}
		}
	}
}
char s[1001];
main(){
    //file("");
	int n=read(),maxx=0,x;
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=n;j++){
			x=s[j]-'0';
			if(x==1) add(i,j,1);
		}
		vis[i]=-1;
	}
	dfs(1,0);
	for(int s=1;s<=n;s++){
		spfa(s);
		for(int i=1;i<=n;i++)
			maxx=max(maxx,dis[i]);
	}
	cout<<maxx+1;
}


Measured memory_bytes: 11008
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){
 
  ll w, h, n;
  cin>>w>>h>>n;

  ll start_x, start_y, end_x, end_y;
  start_x = 0;
  start_y = 0;
  end_x = w;
  end_y = h;

  REP(i, n){
    ll x, y, a;
    cin>>x>>y>>a;
    if(a== 1){
      if(start_x < x ) start_x = x; 
    }else if(a==2){
      if(end_x > x) end_x = x;
    }else if(a==3){
      if(start_y < y ) start_y = y;
    }else{
      if(end_y > y ) end_y = y;
    }
  }

  if(start_x>end_x || start_y > end_y){
    cout<<"0"<<endl;
  }else{
    cout<<(end_x-start_x)*(end_y-start_y)<<endl;
  }

  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;

vint G[111111];

signed main(){
    cin>>N>>M;
    vint deg(N);
    rep(i,N-1+M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        deg[b]++;
    }

    vint ans(N,-1);

    queue<int>que;
    rep(i,N)if(deg[i]==0)que.push(i);
    while(que.size()){
        int v=que.front();
        que.pop();
        for(auto u:G[v]){
            if(--deg[u]==0){
                ans[u]=v;
                que.push(u);
            }
        }
    }
    rep(i,N)cout<<ans[i]+1<<endl;
    return 0;
}


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

int main(){

    int n,k,x,y,ans;
    cin >> n >> k >> x >> y;
    if (k < n){
        ans = k*x + (n-k)*y;
    }else{
        ans = n*x;
    }
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	int num;
	scanf("%d", &num);
	string s;
	cin >> s;
	for (int p = 0; p < 2; p++)
	{
		for (int q = 0; q < 2; q++)
		{
			vector<int>ans;
			ans.push_back(p), ans.push_back(q);
			for (int i = 0; i < num; i++)
			{
				if (s[i] == 'o')ans.push_back(ans[i] ^ ans[i + 1]);
				else ans.push_back(ans[i] ^ ans[i + 1] ^ 1);
			}
			if (ans[num] == p&&ans[num + 1] == q)
			{
				for (int i = 1; i <= num; i++)printf(ans[i] ? "W" : "S");
				printf("\n");
				return 0;
			}
		}
	}
	printf("-1\n");
}

Measured memory_bytes: 1392
import math as mt
import itertools as it
import functools as ft
import random as rnd

stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), input().split(sep)))
joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)

a = stdin()

print("YES" if set(a) == set([1,9,7,4]) else "NO")

Measured memory_bytes: 5212
#include<cstdio>

int main(){
    char x;
    scanf("%c", &x);
    int sum = 0;
    while(x == '1' || x == '2' || x == '3' || x == '4' || x == '5' || x == '6' || x == '7' || x == '8' || x == '9' || x == '0'){
        int n = x - '0';
        sum += n;
        scanf("%c", &x);
    }
    sum = sum % 9;
    if(sum == 0) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 1668
import java.util.*;
import java.util.Collections;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = 0;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      max = Math.max(max, list.get(i));
    }
    if (max < list.stream().mapToInt(x -> x).sum() - max) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  public static void primeFactorization(int num) {
    int Z = 0;
    for (int i = 2; num > i; i++) {
      while (num % i == 0) {
        System.out.println(i);
        num /= i;
        Z = num;
      }
    }
    System.out.println(Z);
  }

  public static boolean isPrime(int num) {
    if (num < 2)
      return false;
    else if (num == 2)
      return true;
    else if (num % 2 == 0)
      return false;

    for (int i = 3; i < num; i += 2) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 28240
n = int(raw_input())
l = map(int, raw_input().split())
ll = [False for _ in range(8)]
o = 0
for i in l:
    if i/400 < 8:
        ll[i/400] = True
    else:
        o += 1
c = ll.count(True)
if c == 0:
    print 1,o
else:
    print c,c+o


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

long long _min(long long a, long long b, long long c) {
    long long t = a < b ? a : b;
    return t < c ? t : c;
}
long long sec(long long a, long long b, long long c) {
    if (a < b)
        return a < c ? (b < c ? b : c) : a;
    else
        return b < c ? (a < c ? a : c) : b;
}
long long _max(long long a, long long b, long long c) {
    long long t = a < b ? b : a;
    return t < c ? c : t;
}


long long gcd(long long s, long long g) {
    if (g % s == 0)
        return s;
    else
        return gcd(g % s, s);
}

long long get_gcd(long long ***table, long long a, long long b, long long c) {
    long long one = _min(a,b,c), two = sec(a,b,c), three = _max(a,b,c);
    if (table[one][two][three] == 0)
        table[one][two][three] = gcd(gcd(one, two), three);
    // printf("%lld, %lld, %lld: %lld\n", one, two, three, table[one][two][three]);
    return table[one][two][three];
}



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

    long long sum = 0;
    long long ***table = (long long ***)calloc(210, sizeof(long long **));
    for (int i = 0; i < 210; i++) {
        table[i] = (long long **)calloc(210, sizeof(long long *));
        for (int j = 0; j < 210; j++) {
            table[i][j] = (long long *)calloc(210, sizeof(long long));
        }
    }


    for (long long i = 1; i <= K; i++) {
        for (long long j = 1; j <= K; j++) {
            for (long long k = 1; k <= K; k++) {
                sum += get_gcd(table, i, j, k);
            }
        }
    }

    cout << sum << endl;

}


Measured memory_bytes: 77016
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 5005

ll N,K;
ll A[SIZE];
int dp[SIZE][SIZE],dp2[SIZE][SIZE];

int main(){

	scanf("%lld %lld",&N,&K);

	ll sum = 0;
	for(int i = 0; i < N; i++){

		scanf("%lld",&A[i]);
		sum += A[i];
	}

	if(sum < K){

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

	vector<ll> L,R;

	for(int i = 0; i < N; i++){
		if(A[i] >= K)continue;

		L.push_back(A[i]);
		R.push_back(A[i]);
	}

	sort(L.begin(),L.end());
	sort(R.rbegin(),R.rend());

	for(ll i = 0; i <= L.size(); i++){
		for(ll a = 0; a <= K-1; a++){

			dp[i][a] = 0;
			dp2[i][a] = 0;
		}
	}

	dp[0][0] = 1;
	for(ll i = 0; i < L.size(); i++){
		//足さない
		for(ll a = 0; a <= K-1; a++){

			dp[i+1][a] = dp[i][a];
		}
		//足す
		for(ll a = 0; a+L[i] <= K-1; a++){
			if(dp[i][a] == 0)continue;

			dp[i+1][a+L[i]] = 1;
		}
	}
	/*for(ll i = 1; i <= 3; i++){
		printf("i:%lld\n",i);
		for(int a = 0; a <= 8; a++){
				if(dp[i][a] == 1){

					printf("%dが作れる\n",a);
				}
			}
		}*/

	//累積和にする
	for(ll i = 0; i <= L.size(); i++){
		for(ll a = 1; a <= K-1; a++){
			dp[i][a] += dp[i][a-1];
		}
	}




	dp2[0][0] = 1;
	for(ll i = 0; i < R.size(); i++){
		//足さない
		for(ll a = 0; a <= K-1; a++){

			dp2[i+1][a] = dp2[i][a];
		}
		//足す
		for(ll a = 0; a+R[i] <= K-1; a++){
			if(dp2[i][a] == 0)continue;

			dp2[i+1][a+R[i]] = 1;
		}
	}
	/*printf("dp2\n");
	for(ll i = 1; i <= 3; i++){
			printf("i:%lld\n",i);
			for(int a = 0; a <= 8; a++){
					if(dp2[i][a] == 1){

						printf("%dが作れる\n",a);
					}
				}
			}*/
	//累積和にする
	for(ll i = 0; i <= R.size(); i++){
		for(ll a = 1; a <= K-1; a++){
			dp2[i][a] += dp2[i][a-1];
		}
	}


	int ans = 0;
	for(ll i = 0; i < L.size(); i++){

		bool FLG = false;
		//printf("L[%lld]:%lld\n",i,L[i]);

		for(ll a = 0; a <= K-1; a++){
			if(a == 0 || (a > 0 && dp[i][a]-dp[i][a-1] == 1)){

				ll left = max(0LL,(K-L[i])-a);
				ll right = (K-1)-a;

				//printf("a:%lld left:%lld right:%lld\n",a,left,right);

				ll tmp;

				if(left == 0){

					tmp = dp2[R.size()-(i+1)][right];

				}else{

					tmp = dp2[R.size()-(i+1)][right]-dp2[R.size()-(i+1)][left-1];
				}
				if(tmp > 0){
					FLG = true;
					break;
				}
			}
		}
		if(!FLG){ //「L[i]が無ければ良い集合にならない集合」がない

			ans++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 196096
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 size(self, x):
        if self.parents[x] < 0:
            return -self.parents[x]
        else:
            self.parents[x] = self.size(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

n = int(input())
A = [list(map(int,input().split())) for i in range(n)]
M = [[j for j in i] for i in A]

for k in range(n):
    for i in range(n):
        for j in range(n):
            M[i][j] = min(M[i][j], M[i][k] + M[k][j])

b = 0
if A != M:
    print(-1)
else:
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            b = 0
            for k in range(n):
                if k != i and k != j and M[i][j] == M[i][k] + M[k][j]:
                    b = 1
                    break
            if b == 0:
                ans += A[i][j]
    print(ans)

Measured memory_bytes: 45532
(defun solver ()
  (let* ((a (read)) (b (read)) (c (read))
         (k (read)) (result 0) (max (max a b c))
         (max2 (* (expt 2 k) max)))
    (cond ((= a max) (setf result (+ max2 b c)))
          ((= b max) (setf result (+ a max2 c)))
          ((= c max) (setf result (+ a b max2))))
    (format t "~a~%" result)))

(solver)

Measured memory_bytes: 13280
a, b, n = list(map(int,input().split()))

c = []
for i in range(n):
    c.append(list(map(int,input().split())))

aa =0
ab =a
ac =0
ad =b

for i in range(n):
    if c[i][2] == 1:
        aa = max(aa,c[i][0])
    elif c[i][2] == 2:
        ab = min(ab,c[i][0])
    elif c[i][2] == 3:
        ac = max(ac,c[i][1])
    else:
        ad = min(ad,c[i][1])

if ab-aa > 0 and ad-ac > 0:
    print((ab-aa)*(ad-ac))
else:
    print(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, m;
	cin >> n >> m;
	vvi a(n, vi(m));
	rep(i, n)rep(j, m)cin >> a[i][j];

	int ans = n;
	set<int> se;
	se.insert(INF);

	rep(i, m - 1) {

		map<int, int> mp;

		rep(j, n) {
			int k = 0;
			while (true) {
				if (*se.lower_bound(a[j][k])== a[j][k]) { k++;continue; }
				break;
			}
			mp[a[j][k]]++;
		}

		int hoge = 0;
		int piyo = 0;
		for (auto x : mp)if (x.second > hoge) { hoge = x.second;piyo = x.first; }

		ans = min(ans, hoge);
		se.insert(piyo);

	}

	cout << ans << endl;

}

Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;

int main() 
{
    string N;
    cin >> N;
    if(N[0] >= 'A' && N[0] <= 'Z')
    {
        cout << "A" <<endl;
        return 0;
    }
    else
    {
        cout << "a" << endl;
        return 0;
    }
    
}

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

int main(){
	ll k,x;
	cin >> k >> x;
	rep(i,2*k-1){
		cout << x - k + 1 + i << " ";
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
int n;
int a[111111];
int b[111111];
int x=0;
int ans=0;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i];
	for(int i=n-1;i>=0;i--){
		a[i]+=x;
		if(a[i]%b[i]){
			ans+=b[i]-(a[i]%b[i]);
			x+=b[i]-(a[i]%b[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1920
"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append((K-A[i]+A[0]))
    else:
        theta.append((A[i+1]-A[i]))
#print("sum",sum(theta))
theta.remove(max(theta))
#print(theta)
s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=s
print(l_min)

Measured memory_bytes: 50988
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            cout << "NO" <<endl;
            return 0;
        }
    }
    cout << "YES" <<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define ll long long
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c)<<endl;
	return 0;
}

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

using namespace std;

int main()
{
	vector<int> values;
	copy(istream_iterator<int>(cin), istream_iterator<int>(), back_inserter(values));

	sort(values.begin(), values.end(), greater<int>());

	for (size_t i = 0; i < values.size(); ++i) {
		if (i > 0) {
			cout << ' ';
		}
		cout << values[i];
	}
	cout << endl;

	return 0;
}

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

int main(){
    int a,b;
    double mean;
    int c;

    cin >> a >> b;

    mean = (a + b)/2.0;
    c = mean;

    if(mean-c==0){
        cout << mean << endl;
    }
    else{
        cout << c + 1 << endl;
    }

}

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

int main(){

	int a, b, j, tmp, gcd, lcm;
	
	while(cin >> a >> b){
	
		if(a > b){
			tmp = a;
			a = b;
			b = tmp;
		}
	
		gcd = a;
		for(int i=2;; i++){
			if(b % gcd == 0 || gcd == 1) break;
			else{
				for(j=i; a % j != 0; j++);
				gcd = a / j;
			}
		}
		
		lcm = b;
		for(int i=2;; i++){
			if(lcm % a == 0) break;
			else{
				lcm = b * i;
			}
		}
	
		cout << gcd << " " << lcm <<endl;
	
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int num, k, i, sum = 0;
	cin >> num >> k;
	vector<int> d(num);
	for (i = 0; i < num; i++)
		sum += k + i;
	if (k <= 0 && abs(k) < num)
		printf("%d\n", sum);
	else if(k < 0)
		printf("%d\n", sum - k - num + 1);
	else
		printf("%d\n", sum - k);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n;
    int h[100020];
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }

    int max=h[0];
    int flag=0;

    for(int i=1;i<n;i++){
        if(max < h[i])  max=h[i];
        else if((max-h[i])>=2){
            flag=1;
            break;
        }
    }

    if(flag)    cout << "No" << endl;
    else        cout << "Yes"<< endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
    int h,w;
    int i,j;
    while(1){
        scanf("%d %d", &h,&w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2080
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	long long int q, h, s, d;
	cin >> q >> h >> s >> d;
	long long int n;
	cin >> n;
	long long int two = min(min(q * 8, h * 4), min(s * 2, d));
	long long int one = min(q * 4, min(h * 2, s));
	if (two > one*2) {
		cout << n * one;
	}
	else {
		cout << n / 2 * two + n % 2 * one;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first               // For pairs
#define ss second              // For pairs
#define sz(a) int((a).size())  // Function to determine size of any container
#define pb push_back           // Pushback to vector
#define mp make_pair           // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)  //traversing macro
#define present(c, x) (c.find(x) != c.end())

using namespace std;
typedef vector<ll> vi;            // Vector of long long
typedef vector<vi> vvi;           // Vector of vi
typedef vector<pair<ll, ll>> ii;  // Vector of pairs
typedef vector<ii> vii;           // Vector of ii
int main() {
    ll n, k;
    cin >> k >> n;
    vi a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (n == 2) {
        cout << min(a[1] - a[0], k - a[1] + a[0]) << "\n";
    } else {
        ll ans = a[n - 1] - a[0];
        for (int i = 0; i < n - 1; i++) {
            ans = min(k - a[i + 1] + a[i], ans);
        }
        cout << ans << "\n";
    }
    return 0;
}

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

bool sosu(int num){
   if (num < 2) return false;
   else if (num == 2) return true;

   double sqrtNum = sqrt(num);
   for (int i = 3; i <= sqrtNum; i += 2) {
      if (num % i == 0) {
         return false;
      }
   }
   return true;
}


int count(int n){
   int c = 0;
   for(size_t i = 1; i <= n; i++){
      if(n % i==0){
         c++;
      }
   }
   return c;
}


int main() {
   int n;
   std::cin >> n;
   //std::cout <<"?" << count(n) << '\n';

   int c = 0;
   if (n < 105) {
      std::cout << "0" << '\n';
      return 0;
   }
   for (size_t i = 105; i <= n; i+=2) {
      if (count(i) == 8) {
         c++;
         //std::cout << "!" << i << '\n';
      }
   }
   std::cout << c << '\n';

}


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

using namespace std;

int func(long long n){
  int ans = 0;
  while(n >0){
    ans++;
    n = n/10;
  }
  return ans;
}

int main() {
  long long n;
  cin >> n;
  int ans=100;
  for(long long a=1;a<=sqrt(n);a++){
    if(n%a == 0){
      ans = min(ans,max(func(a),func(n/a)));
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256