akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#define SIZE 30
#define CHANGEMAX 8
 
using namespace std;
bool ok(int *p);
void swap(int *p,int i,int j);
int solv(int now,int *p);
 
int main(){
  int n;
  int p[SIZE];
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<SIZE;j++)
      cin>>p[j];
    //cout<<ok(p)<<endl;
    cout<<solv(0,p)<<endl;
  }
  return 0;
}
 
int solv(int now,int *p){
  int tmp;
  int p_tmp_tmp[4][SIZE];
  int res[4];
  
  if(ok(p)==true){
    return now;
  }else if(now>CHANGEMAX){
    return CHANGEMAX+1;
  }
 
  for(int j=0;j<4;j++){
    res[j]=0;
    for(int i=0;i<SIZE;i++){
      p_tmp_tmp[j][i]=p[i];
    }
  }
   
  /*?????¢????????????1*/
  swap(p_tmp_tmp[0],17,12);
  swap(p_tmp_tmp[0],6,21);
  swap(p_tmp_tmp[0],8,23);
  swap(p_tmp_tmp[0],7,22);
  swap(p_tmp_tmp[0],9,11);
  /*?????¢????????????2*/
  swap(p_tmp_tmp[1],0,27);
  swap(p_tmp_tmp[1],1,28);
  swap(p_tmp_tmp[1],2,29);
  swap(p_tmp_tmp[1],14,15);
  swap(p_tmp_tmp[1],18,20);
  /*?????¢????????????3*/
  swap(p_tmp_tmp[2],0,23);
  swap(p_tmp_tmp[2],3,26);
  swap(p_tmp_tmp[2],6,29);
  swap(p_tmp_tmp[2],9,20);
  swap(p_tmp_tmp[2],17,15);
  /*?????¢????????????4*/
  swap(p_tmp_tmp[3],2,21);
  swap(p_tmp_tmp[3],5,24);
  swap(p_tmp_tmp[3],8,27);
  swap(p_tmp_tmp[3],11,18);
  swap(p_tmp_tmp[3],12,14);
 
  for(int i=0;i<4;i++)
    res[i]=solv(now+1,p_tmp_tmp[i]);
 
  if(res[0]<=res[1] && res[0]<=res[2]&& res[0]<=res[3]){
    for(int i=0;i<SIZE;i++)
      p[i]=p_tmp_tmp[0][i];
    return res[0];
  }else if(res[1]<=res[0] && res[1]<=res[2]&& res[1]<=res[3]){
    for(int i=0;i<SIZE;i++)
      p[i]=p_tmp_tmp[1][i];
    return res[1];
  }else  if(res[2]<=res[0] && res[2]<=res[1]&& res[2]<=res[3]){
    for(int i=0;i<SIZE;i++)
      p[i]=p_tmp_tmp[2][i];
    return res[2];
  }else{
    for(int i=0;i<SIZE;i++)
      p[i]=p_tmp_tmp[3][i];
    return res[3];
  }
}
 
bool ok(int *p){
  /* for(int i=0;i<SIZE;i++)
     cout<<p[i]<<" ";
     cout<<endl;
  */
  for(int i=1;i<9;i++){
    if(p[i-1]!=p[i])
      return false;
  }
  for(int i=10;i<12;i++){
    if(p[i-1]!=p[i])
      return false;
  }
  for(int i=13;i<15;i++){
    if(p[i-1]!=p[i])
      return false;
  }
  for(int i=16;i<18;i++){
    if(p[i-1]!=p[i])
      return false;
  }
  for(int i=19;i<21;i++){
    if(p[i-1]!=p[i])
      return false;
  }
  for(int i=22;i<30;i++){
    if(p[i-1]!=p[i])
      return false;
  }
  return true;
}
 
void swap(int *p,int i,int j){
  int temp=p[i];
  p[i]=p[j];
  p[j]=temp;
  return;
}

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

int main() {
	int a,b=0;
	cin >> a;
	a % 10 == 1 ? b += 9 : b += 1;
	a -= a % 10;
	a % 100 == 10? b += 90 : b += 10;
	a -= a % 100;
	a == 100 ? b += 900 : b += 100;
	cout << b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//(char-'0') 数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b;
  ci(a>>b);
  if(a<=0&&b>=0||a==0||b==0)
    co("Zero");
  else if(a>0)
    co("Positive");
  else if(b>0){
    if(abs(b)%2==0)
      co("Positive");
    else
      co("Negative");
  }
  else{
    if((abs(b)-abs(a)-1)%2==0)
      co("Positive");
    else
      co("Negative");
  }
}

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

struct UnionFind{
private:
  std::vector<int> data;

public:
  UnionFind(int n = 0) : data(n, -1){}

  int find(int x){
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }

  bool unite(int x, int y){
    x = find(x); y = find(y);

    if(x == y) return false;
    else{
      if(data[x] > data[y]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
      return true;
    }
  }

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

  int size(int x){
    return -data[find(x)];
  }
};

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  UnionFind uf(N);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    --a; --b;
    
    uf.unite(a, b);
  }
  
  int groups = 0;
  for(int i = 0; i < N; i++){
    groups = max(uf.size(i), groups);
  }
  
  cout << groups << endl;
  
  return 0;
}

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

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

int main() {
    ll n; cin >> n;
    vector<ll> s(n);
    for(ll i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    ll count = 0;
    for(ll i = 0; i < n; i++) {
        ll min = i;
        for(ll j = i; j < n; j++) { 
            if( s.at(min) > s.at(j)) {
                min = j;
            }
        }
        if( s.at(min) < s.at(i)) {
            swap(s.at(min), s.at(i));
            count++;
        }
    }

    for (ll j = 0; j < n-1; j++) { cout << s.at(j) << ' '; }
    cout << s.at(n-1) << endl;
    cout << count << endl;
    return 0;
}





Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main(){
  int M, N;
  cin >> M >> N;
  vector< vector< pair<int, int> > > V(M, vector< pair<int,int> >(N,pair<int,int>(0,101)));
  for(int i = 0; i < M; ++i){
    int K;
    cin >> K;
    for(int j = 0; j < K; ++j){
      int s, t;
      string c;
      cin >> s >> c >> t;
      --s;
      if(c == ">="){
        if(V[i][s].second < t){
          cout << "No" << endl;
          return 0;
        }
        V[i][s].first = max(t, V[i][s].first);
      }else{
        if(V[i][s].first > t){
          cout << "No" << endl;
          return 0;
        }
        V[i][s].second = min(t, V[i][s].second);
      }
    }
  }
  vector< vector<bool> > G(M, vector<bool>(M,false));
  for(int i = 0; i < M; ++i){
    for(int j = 0; j < M; ++j){
      bool f = true;
      for(int k = 0; k < N; ++k){
        if(V[i][k].first > V[j][k].second){
          f = false;
          break;
        }
      }
      G[i][j] = f;
    }
  }
  vector<int> D(M,0);
  for(int i = 0; i < M; ++i){
    bool f = true;
    for(int j = 0; j < M; ++j){
      int d = M - i;
      for(int k = 0; k < M; ++k){
        d -= G[j][k];
      }
      if(!d){
        f = false;
        for(int k = 0; k < M; ++k){
          G[j][k] = false;
          G[k][j] = false;
        }
        break;
      }
    }
    if(f){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 3304
import java.util.*;
class Main{
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
    	
        while(true) {
        	
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
        	
        	if(op.equals("?"))break;
        	
        	int ans =0;

        	
        	switch(op) {
        	case "+" : ans = a+b;
        	break;
        	case "-" : ans = a-b;
        	break;
        	case "*" : ans = a*b;
        	break;
        	case "/" : ans = a/b;
        	break;
        		
        		
        		
        	}
        	
        		System.out.println(ans);

        }
    }
}



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

int main()
{
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }
    int res[26] = {};
    for(auto c: s){
        res[c-'a']++;
    }
    for(int i=0; i<25; i++){
        if(res[i] == 0){
            cout << s << char('a'+i) << endl;
            return 0;
        }
    }
    string org = s;
    next_permutation(s.begin(), s.end());
    while(s.substr(0, s.size()-1) > org){
        s = s.substr(0, s.size()-1);
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
} uft(200000);

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        --x;
        --y;
        if(!(z&1)) {
            uft.unite(2*x, 2*y);
            uft.unite(2*x+1, 2*y+1);
        } else {
            uft.unite(2*x+1, 2*y);
            uft.unite(2*x, 2*y+1);
        }
    }

    set<int> se;
    rep(i, 2*n) {
        se.insert(uft.root(i));
    }

    cout << ((int)se.size())/2 << endl;
}

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

#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz size()
#define endl "\n"
#define pb push_back
#define pp pop_back
#define mp make_pair
#define REP(I,n) for(int I = 0; I < n; I++)
#define REP_1(I,n) for(int I = 1; I <= n; I++)
#define w(t) int t; cin>>t; while(t--)

#define MOD 1000000007
#define INF 1e9 + 7

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef set<int> si;
typedef set<string> ss;

typedef long long ll;

template<class T>
istream &operator>>(istream &in,vector<T> &arr) {
	for(auto &x : arr)
		in>>x;
	return in;
}

bool sortbylen(string a,string b) {
	return a.length() < b.length();
}
void solve() {
	int s,w;
	cin>>s>>w;

	if(w >= s) 
		cout<<"unsafe";
	else
		cout<<"safe";	
}
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	solve();
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 1000000007
#define ll long long
using namespace std;

int main(){
    ll n,x,m; cin>>n>>x>>m;
    map<ll,int> mp;
    ll pos=x;
    ll count=1;
    ll sum_=x;
    ll rec=-1;
    vector<ll> vec;
    while(true){
        pos=pow(pos,2);
        pos=pos%m;
        sum_+=pos;
        count++;
        mp[pos]++;
        if(count==n){
            cout<<sum_<<endl;
            return 0;
        }
        if(mp[pos]==2){ 
            vec.push_back(pos);
            if(rec==-1) rec=count-1;
        }
        if(mp[pos]==3) break;
    }
    
    ll sumsum=0;
    for(ll i=0; i<vec.size(); i++) sumsum+=vec[i];
    rec-=vec.size();
    
    pos=x;
    ll ans=x;
    for(ll i=1; i<rec; i++){
        pos=pow(pos,2);
        pos=pos%m;
        ans+=pos;
    }
    //cout<<ans<<endl;
    ll p=n-rec;
    p/=vec.size();
    ll q=n-rec-p*vec.size();
    
    ans+=sumsum*p;
    
    for(ll i=0; i<q; i++){
        ans+=vec[i];
    }
    
    //cout<<p<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 7040
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int array_num=sc.nextInt();
		//int[] array=new int[array_num];
		ArrayList<Integer> array=new ArrayList<Integer>();
		for(int i=0;i<array_num;i++){
			array.add(Integer.valueOf(sc.nextInt()));
		}
		Collections.reverse(array);
		for(int i=0;i<array_num;i++){
			System.out.print(array.get(i));
			if(i!=array_num-1){
				System.out.print(" ");
			}
		}
		System.out.println();
	}

}



Measured memory_bytes: 26400
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

struct state{
    state(){}
    ll a,b,c,d;
    bool operator>(state rhs){
        return d > rhs.d;
    };
    bool operator<(state rhs){
        return d < rhs.d;
    };
};
void print() {
    cout << endl;
}

// template <class Head, class... Tail>
// void print(Head&& head, Tail&&... tail) {
//     cout << head;
//     if (sizeof...(tail) != 0) cout << " ";
//     print(forward<Tail>(tail)...);
// }

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i,k-1)cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    cout << p.first << " " << p.second << "\n";
}

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n,m,q; cin >> n >> m >> q;
    vector<state> v(q);
    rep(i,q){
        cin >> v[i].a >> v[i].b >> v[i].c >> v[i].d;
        v[i].a--;v[i].b--;
    }
    vector<ll> a(n, 1);
    auto f = [&](){
        a[n-1]++;
        rreps(i,n-1)if(a[i] > m){
            a[i] = 0;
            a[i-1]++;
        }
        reps(i,n-1)a[i] = max(a[i], a[i-1]);
    };
    ll cnt = 0;
    ll ans = 0;
    while(a[0] <= m){
        ll temp = 0;
        rep(i,q){
            if(a[v[i].b] - a[v[i].a] == v[i].c)temp += v[i].d;
        }
        chmax(ans, temp);
        f();
    }

    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <unordered_map>

using namespace std;

constexpr long MAXC = 2E9;

void finddist(int pwd, int parent, vector<unordered_map<int, long>> &edge, vector<long> &kdistance) {
    kdistance[pwd] = kdistance[parent] + edge[parent][pwd];
    for (auto&& itr : edge[pwd]) {
        if (itr.first == parent) continue;
        finddist(itr.first, pwd, edge, kdistance);
    }
}

int main() {
    int nodes;
    cin >> nodes;
    vector<unordered_map<int, long>> edge(nodes + 1);
    for (int i = 0; i < nodes - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].emplace(b, c);
        edge[b].emplace(a, c);
    }

    int problems, k;
    cin >> problems >> k;
    vector<long> kdistance(nodes + 1, MAXC);
    kdistance[k] = 0;

    for (auto&& itr : edge[k]) {
        finddist(itr.first, k, edge, kdistance);
    }

    for (int i = 0; i < problems; i++) {
        int x, y;
        cin >> x >> y;
        cout << kdistance[x] + kdistance[y] << endl;
    }
}


Measured memory_bytes: 25216
n,x,y = map(int,input().split())
dists = [0]*(n)
for i in range(1,n+1):
    for j in range(1,i):
        dist = min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))
        dists[dist] = dists[dist]+1
    
for i in range(len(dists) - 1):
    print(dists[i+1])

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       long f = 100;
       int answer = 0;
       long x = sc.nextLong();
       while(x > f){
           f += f / 100;
           answer++;
       }
       System.out.println(answer); 
    }
}

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

int main(){
    string w;
    cin >> w;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        string op;
        int a, b;
        cin >> op >> a >> b;
        if (op == "replace"){
            string rep;
            cin >> rep;
            w = w.replace(a, b-a+1, rep);
        }
        else if (op == "reverse"){
            string tmp = w.substr(a, b-a+1);
            for (int j = 0; j < tmp.size(); j++){
				string c = tmp.substr(tmp.size()-j-1, 1);
                w = w.replace(a+j, 1, c);
            }
        }
        else if (op == "print"){
            cout << w.substr(a, b-a+1) << endl;
        }
    }
}


Measured memory_bytes: 3208
#include <stdio.h>

int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	int sum = 0;
	for (int i = 0; i < 2; i++) {
		if (a > b) sum += a--;
		else sum += b--;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();
		long a = 0;
		long b = 0;
		long dis = Long.MAX_VALUE;
		for(int i = 1; i <= Math.sqrt(n); i++) {
			if(n%i == 0) {
				long num1 = i;
				long num2 = n/i;
				if(dis>Math.abs(num1-num2)) {
					dis = Math.abs(num1-num2);
					a = num1;
					b = num2;
				}
			}
		}
		System.out.println((a-1)+(b-1));
	}
}

Measured memory_bytes: 25172
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

char a[1000000];
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf(" %c",&a[i]),a[i]--;

    int one = 0;
    for (i = 0; i < N; i++) {
        if (a[i] == '1') one = 1;
    }
    if (one) {
        for (i = 0; i < N; i++) {
            if (a[i] == '2') a[i] = '0';
        }
    }
    int ans = 0;
    for (i = 0; i < N; i++) {
        if ((i & (N-1)) == i) ans ^= (a[i]-'0');
    }
    printf("%d\n",ans);

    return 0;
}



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

using namespace std;

int main() {
		
	long n;
	cin >> n;
	vector<long> h(n + 1);
	for (long  i = 1; i <= n; i++){
		cin >> h[i];
	}

	vector<long> dp(n + 1);

	dp[0] = 0; dp[1] = 0; dp[2] = abs(h[2] - h[1]);

	for (long i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[n] << endl;
	return 0;

}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int a, n;
  cin >> n >> a;
  int b = n % 500;
  if (b <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n).map{Array.new(n,0)}
for i in 0..n-1
  ans = ""
  input = gets.split(' ').map(&:to_i)
  if input.size > 2
    for j in 2..input.size-1
      a[i][input[j]-1] = 1
    end
  end
  for k in 0..a.size-1
    ans += "#{a[i][k]}"
    ans += " " if k != a.size - 1
  end
  puts ans
end

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

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

    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    long long total = 0;
    for (int i = 0; i < K; i++) {
        if (T[i] == 'r')
            total += P;
        else if (T[i] == 'p')
            total += S;
        else
            total += R;

        char prev = T[i];
        for (int j = i + K; j < N; j += K) {
            if (T[j] == prev)
                prev = 0;
            else {
                if (T[j] == 'r')
                    total += P;
                else if (T[j] == 'p')
                    total += S;
                else
                    total += R;
                prev = T[j];
            }
        }
    }
    cout << total << '\n';

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a<0&&b<=0){
		printf("%d\n",c*(b-a));
	}else if(a<0&&b>0){
		printf("%d\n",(-a)*c+d+b*e);
	}else{
		printf("%d\n",(b-a)*e);
	}
	return 0;
}

Measured memory_bytes: 2712
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n){
        cin >> a[i];
    }
    bool box[n];
    int m = 0;
    for (int i = n; i > 0; i--){
        int num = 0;
        for (int j = 2 * i; j <= n; j += i){
            if(box[j-1]) num++;
        }
        // cout << i << " " << num << endl;
        if(num % 2 != a[i-1]) {
            box[i-1] = true;
            m++;
        }else box[i-1] = false;
    }
    // rep(i, n){
    //     if(box[i]) cout << 1 << endl;
    //     else cout << 0 << endl;
    // }
    cout << m << endl;
    rep(i, n){
        if(box[i]) cout << i + 1 << " ";
    }cout << endl;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{

  int r,D,x;
  cin>>r>>D>>x;
  int Y = x;
  for (int i = 0; i < 10; i++)
  {
    Y = r*x -D;
    cout<< Y <<endl;
    x = Y;
  }
  
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
using namespace std;
int main() {
	int x, y, ans = 0;
	cin >> x >> y;
	if (x < 4) {
		ans += (4 - x) * 100000;
	}
	if (y < 4) {
		ans += (4 - y) * 100000;
	}
	if (x == 1 && x == y) {
		ans += 400000;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <cassert>
using namespace std;
typedef long long ll;
ll inf = 1e18;

class network_flow{
public:
	int N;
	struct edge{int to; ll cap; int rev; bool is_rev,used; int num;};
	vector<vector<edge>> G;
	vector<int> level,iter;
	void bfs(int s){
		for(int i=0;i<=N;i++) level[i] = -1;
		queue<int> Q;
		level[s] = 0;
		Q.push(s);
		while(!Q.empty()){
			int v = Q.front(); Q.pop();
			for(int i=0;i<G[v].size();i++){
				edge &e = G[v][i];
				if(e.cap > 0 && level[e.to]<0 && !e.used){
					level[e.to] = level[v]+1;
					Q.push(e.to);
				}
			}
		}
	}
	ll dfs(int v,int t,ll f){
		if(v==t) return f;
		for(int &i=iter[v];i<G[v].size();i++){
			edge &e = G[v][i];
			if(level[v]<level[e.to] && e.cap>0 && !e.used){
				ll d = dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
public:
	network_flow(int n){
		N = n;
		G = vector<vector<edge>>(N+1);
		level = iter = vector<int>(N+1);
	}
	void add_edge(int from, int to,ll cap,int num){
		G[from].push_back((edge){to,cap,(int) G[to].size(),false,false,num});
		G[to].push_back((edge){from,0,(int) G[from].size()-1,true,false,num});
	}
	void reset(){
		for(int i=0;i<N;i++){
			for(auto& x:G[i]) x.cap = (!x.is_rev);
		}
	}
	ll max_flow(int s,int t){
		ll flow = 0;
		for(;;){
			bfs(s);
			if(level[t]<0) return flow;
			for(int i=0;i<=N;i++) iter[i] = 0;
			ll f;
			while((f=dfs(s,t,inf))>0) flow += f;
		}
	}
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> A(N+1,vector<int>(M+1,-1));
    vector<vector<int>> B(N+1,vector<int>(M+1,-1));
    vector<vector<int>> C(N+1,vector<int>(M+1,-1));
    for(int i=1;i<=N;i++) for(int j=1;j<=M;j++){
        cin >> A[i][j];
    }
    network_flow flow(2*N+2);
    for(int i=1;i<=N;i++){
		flow.add_edge(0,i,1,0);
		flow.add_edge(N+i,2*N+1,1,0);
		for(int j=1;j<=M;j++){
			flow.add_edge(i,N+(A[i][j]+M-1)/M,1,A[i][j]);
		}
    }
	for(int t=1;t<=M;t++){
		int res = flow.max_flow(0,2*N+1);
		assert(res==N);
		for(int i=1;i<=N;i++){
			for(auto& x:flow.G[i+N]){
				if(!x.used && x.is_rev && x.cap==1){
					B[x.to][t] = x.num;
					x.used = true;
					flow.G[x.to][x.rev].used = true;
					break;
				}
			}
		}
		flow.reset();
	}
	for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) cout << B[i][j] << (j!=M? " ":"\n");
	for(int j=1;j<=M;j++) for(int i=1;i<=N;i++) for(int k=1;k<=N;k++){
		if((i-1)*M<B[k][j] && B[k][j]<=i*M){
			C[i][j] = B[k][j];
			break;
		}
	}
	for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) cout << C[i][j] << (j!=M? " ":"\n");
	
}

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

int main() {
    string s;
    cin >> s;
    if ((s[0] == s[1] and s[1] == s[2]) or (s[1] == s[2] and s[2] == s[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    n = int(input())
    s = []
    ans = 0
    now = 1
    for i in range(n):
        s.append(int(input()))
    for i in s:
        now = s[now-1]
        ans += 1
        if now == 2:
            print(ans)
            break
    else:
        print(-1)

Measured memory_bytes: 12944
#include<bits/stdc++.h>
using namespace std;
#define int long long int
void solve()
{
    int n,d,x,y,cnt=0;

cin>>n>>d;
while(n--)
{
    cin>>x>>y;
    if(sqrt(x*x+y*y)<=d)
        cnt++;
}
cout<<cnt<<"\n";
}

signed main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 cout.tie(NULL);
 int t=1;
//cin>>t;
while(t--)
{
  solve();
}
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string s; cin >> s;
	
	if(s[0] == '9' or s[1] == '9') printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
N,x=map(int, input().split())
if x==1 or x==2*N-1:
  print('No')
  exit()
print('Yes')
if N>2:
  n=2*N-1
  ans=[0]*n
  if x>2:
    num=1
    ans[N-3]=x-1
    ans[N-2]=x+1
    ans[N-1]=x    
    ans[N]=x-2
    for i in range(2*N-1):
      if ans[i]!=0:
        print(ans[i])
      else:
        if num==x-2:
          num+=4
        print(num)
        num+=1
  else:
    num=2*N-1
    ans[N-3]=3
    ans[N-2]=1
    ans[N-1]=2    
    ans[N]=4
    for i in range(2*N-1):
      if ans[i]!=0:
        print(ans[i])
      else:
        print(num)
        num-=1
else:
  for i in range(1,4):
    print(i)

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

int main(){
	int a[3];rep(i,3)cin>>a[i];
	sort(a,a+3);
	cout<<a[0]*a[1]/2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

const int m = 1e6, M = 1e9+7;
ll inverse[3*m], fact[3*m], invfact[3*m];

ll nCr(ll n, ll r){
    ll ans = fact[n]*invfact[r]%M;
    return (ans*invfact[n-r]%M); 
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll h, n, x, sum = 0;
    cin>>h>>n;
    loop(n){
        cin>>x;
        sum += x;
    }
    if(sum>=h)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

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

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

int needed_kaisu(long long a, long long N, long long *A) {
	int count = 0;
	for (long long i = 0; i < N; i++) {
		count += (A[i]+a-1) / a -1;
	}
	return count;
}


int main() {


	long long A[1000010], N, max, ans;
	
	cin >> N;
	max = 0;
	ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (max < A[i]) {
			max = A[i];
		}
		if (i != 0) {
			ans += -A[i] + max;
		}
	}


	cout << ans <<endl;

	cin >> N;

	return 0;


}



Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;;
	cin>>n;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			int a=i;
			int b=n/i;
			if(a<=9&&b<=9) {cout<<"Yes"; return 0;}
		}
	}
	cout<<"No";
}

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

using namespace std;
using ll = long long;

int main(){
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k <= a) cout << k << endl;
  else if(k <= a+b) cout << a << endl;
  else cout << a - (k - (a+b)) << endl;
  return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  string s;
  cin>>s;
  int N = int(s.size());
  int cnt[3] = {0};
  for(int i(0);i<N;i++){
    if (s[i] == 'a') cnt[0]++;
    if (s[i] == 'b') cnt[1]++;
    if (s[i] == 'c') cnt[2]++;
  }
  int maxi = max(cnt[0],max(cnt[1],cnt[2]));
  int mini = min(cnt[0],min(cnt[1],cnt[2]));
  if(maxi - mini <= 1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


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

const int N = 2e5 + 7;

int bit[N], f[N], ans[N];

vector <pair <int, int> > Q[N];

void update(int idx, int value) {
	for(int i = idx; i < N; i += i & -i) {
		bit[i] += value;
	}
}

int query(int idx) {
	int res = 0;
	for(int i = idx; i > 0; i -= i & -i) {
		res += bit[i];
	}
	return res;
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		int l, r; cin >> l >> r;
		f[r - l]++;
		Q[r - l].push_back(make_pair(l, r));
	}

	for(int i = N - 2; i >= 0; i--) {
		f[i] += f[i + 1];
	}

	for(int i = 1; i <= m; i++) {
		if(i - 2 >= 0) {
			for(auto z: Q[i - 2]) {
				int l, r; tie(l, r) = z;
				update(l, +1);
				update(r + 1, -1);
			}
		}
		ans[i] += f[i - 1];
		for(int j = i; j <= m; j += i) {
			ans[i] += query(j);
		}
		cout << ans[i] << "\n";
	}
}

Measured memory_bytes: 14340
#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=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }

constexpr ll mod = 1e9+7;
const int dx[]={0,1,0,-1} ,dy[] = {1,0,-1,0};

int h,w;

class Node{
public:
    int cost,x,y,pre;
    Node(){}
    Node(int a,int b,int c,int d){
        cost = a;
        x = b;
        y = c;
        pre = d;
    }

    bool operator < (const Node& nd) const{
        return cost < nd.cost;
    }
    bool operator > (const Node& nd) const{
        return cost > nd.cost;
    }
    bool operator == (const Node& nd) const{
        return cost==nd.cost;
    }

    void print() const{
        printf("Node : cost(%d) , (x,y)=(%d,%d), pre=%d\n",cost,x,y,pre);
    }
};

int move(int dir,int m){
    if(m==0){
        return dir;
    }else if(m==1){
        return (dir+1)%4;
    }else if(m==2){
        return (dir+2)%4;
    }else if(m==3){
        return (dir-1+4)%4;
    }else{
        assert(false);
    }
    return -1;
}

void solve(){
    using P = tuple<int,int,int,int>;
    vvi s(h,vi(w));
    vi c(4);
    rep(i,h) rep(j,w) cin>>s[i][j];
    rep(i,4) cin>>c[i];

    int d[32][32][5];
    rep(i,32) rep(j,32) rep(k,5) d[i][j][k]=INF;


    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push(Node(0,0,0,0));
    while(!que.empty()){
        Node p = que.top();
        que.pop();
        int cost=p.cost,x=p.x,y=p.y,pre=p.pre;

        if(x==h-1 and y==w-1){
            cout << cost << endl;
            return;
        }

        rep(i,4){
            int ndir = move(pre,i);
            int nx=x+dx[ndir];
            int ny=y+dy[ndir];
            if(nx<0 or nx>=h or ny<0 or ny>=w) continue;

            if(i==s[x][y]){
                if(cost < d[nx][ny][ndir]) {
                    d[nx][ny][ndir] = cost;
                    que.push(Node(cost,nx,ny,ndir));
                }
            }else{
                if(cost + c[i] < d[nx][ny][ndir]){
                    d[nx][ny][ndir] = cost + c[i];
                    que.push(Node(cost+c[i],nx,ny,ndir));
                }
            }
        }
    }

}

int main(){
    while(cin>>w>>h){
        if(h==0 and w==0) break;
        solve();
    }
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    ll to = 0;
    ll on = 0;
    vector<int> ten(10);
    ten[0] = 1;
    REP(i,9)ten[i+1] = 10*ten[i];
    REP(i,N){
        if(to_string(i+1)[0] == to_string((i+1)%10)[0]){
            if(to_string(i+1).size() > 2){
                REP(l,to_string(i+1).size()-2){
                    on += ten[l];
                }
                on += ((i+1)%ten[to_string(i+1).size()-1]-(i+1)%10)/10;
            }
            if(i+1>10)on++;//1
            to++;
        }else if((i+1)%10 == 0){
            continue;
        }else{
            if(to_string(i+1)[0] < to_string((i+1)%10)[0]){
                if(to_string(i+1).size()>2)REP(l,to_string(i+1).size()-2){
                    on += ten[l];
                }
            }else{
                REP(l,to_string(i+1).size()-1){
                    on += ten[l];
                }
            }
        }
    }
    int answer = 2*on + to;
    cout <<answer<< "\n";
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(input[0].split(" ")[1]);
  grid=new Array(100);
  for(i=0;i<100;i++){
    if(i<50){
    tmp=new Array(100).fill(".");
    }else{
      tmp= new Array(100).fill("#");
    }
    grid[i]=tmp;
  }
  for(i=0;i<B-1;i++){
    grid[Math.floor(i/50)*2][(i%50)*2]="#";
  }
  for(i=0;i<A-1;i++){
    grid[99-Math.floor(i/50)*2][(i%50)*2]=".";
  }
  gridrow=new Array(101);
  gridrow[0]="100 100";
  for(i=0;i<100;i++){
    gridrow[i+1]=grid[i].join("");
  }
  var ans=gridrow.join("\n");


  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int n;lint nt=1,na=1,t,a;
	cin>>n;
	rep(i,n){
		cin>>t>>a;
		lint x=(nt+t-1)/t,y=(na+a-1)/a,z=max(x,y);
		nt=z*t;na=z*a;
	}
	cout<<nt+na<<endl;
}


Measured memory_bytes: 256
'use strict'

function Main(input) {
  const N = Number(input.split("\n")[0])
  const list = input.split("\n").slice(1).map(x => x.split(" ").map(x => Number(x)))
  list.sort((a, b) => a[1] < b[1] ? -1 : 1)
  
  let now = 0
  for(const job of list) {
    now += job[0]
    if(now > job[1]) {
      console.log("No")
      return
    }
  }
  console.log("Yes")

}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())

Measured memory_bytes: 79528
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
// clang-format on

using vvvi = vector<vvi>;

main {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vvvi dp(n + 1, vvi(500, vi(500, INF)));
  dp[0][0][0] = 0;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    rep(j, 400) rep(k, 400) {
      cmin(dp[i + 1][j][k], dp[i][j][k]);
      cmin(dp[i + 1][j + a][k + b], dp[i][j][k] + c);
    }
  }
  int mini = INF;
  loop(j, 1, 401) loop(k, 1, 401) if (j * mb == k * ma) cmin(mini, dp.back()[j][k]);
  cout << (mini == INF ? -1 : mini) << endl;
}


Measured memory_bytes: 83072
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
const int N(1005);
const int dx[] {0,  0, 1, -1};
const int dy[] {1, -1, 0,  0};
int n, m, a, b, c, d, dp[N][N], x, y;
char mat[N][N];
priority_queue<tuple<int, int, int>> q;
inline bool Inside(int X, int Y) {
    if (X < 1 || X > n || Y < 1 || Y > m)
        return false;
    return true;
}
int32_t main() {
    DAU
    cin >> n >> m >> a >> b >> c >> d;
    for (int i = 1; i <= n; ++i)
        cin >> (mat[i] + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            dp[i][j] = 1e9;
    dp[a][b] = 0;
    q.emplace(0, a, b);
    while (!q.empty()) {
        tie(ignore, x, y) = q.top();
        q.pop();
        int xv, yv;
        for (int dir = 0; dir < 4; ++dir) {
            xv = x + dx[dir];
            yv = y + dy[dir];
            if (Inside(xv, yv) && mat[xv][yv] == '.' && dp[xv][yv] > dp[x][y]) {
                dp[xv][yv] = dp[x][y];
                q.emplace(-dp[xv][yv], xv, yv);
            }
        }
        for (xv = x - 2; xv <= x + 2; ++xv)
            for (yv = y - 2; yv <= y + 2; ++yv)
                if (Inside(xv, yv) && mat[xv][yv] == '.' && dp[xv][yv] > dp[x][y] + 1) {
                    dp[xv][yv] = dp[x][y] + 1;
                    q.emplace(-dp[xv][yv], xv, yv);
                }
    }
    if (dp[c][d] == 1e9)
        dp[c][d] = -1;
    cout << dp[c][d];
    PLEC
}


Measured memory_bytes: 8588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if (N == 1){
    cout << "Hello World" << endl;
  }
  else {
    int A,B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}
  
 

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int s; cin >> s;
    
    map<int,int> mp;
    int a = s;
    int m = -1;
    for(int i = 1; i < 1000001; i++){
        //cout << a << endl;
        if(mp[a] == 0){
            mp[a]++;
        }
        else{
            m = i; 
            break;
        }
        if(a % 2 == 0){
            a = a/2;
        }else{
            a = 3*a+1;
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 256
sizeI, sizeJ, k = map(int, input().split())
a = [input().strip() for _ in range(sizeI)]
ret = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
id = 1
for i in range(sizeI):
    for j in range(sizeJ):
        if a[i][j] == '#':
            ret[i][j] = id
            for jj in range(j - 1, -1, -1):
                if a[i][jj] == '#' or ret[i][jj]:
                    break
                ret[i][jj] = id
            for jj in range(j + 1, sizeJ):
                if a[i][jj] == '#' or ret[i][jj]:
                    break
                ret[i][jj] = id
            id += 1
for i in range(sizeI):
    for j in range(sizeJ):
        if ret[i][j]:
            id = ret[i][j]
            for ii in range(i - 1, -1, -1):
                if a[ii][j] == '#' or ret[ii][j]:
                    break
                ret[ii][j] = id
            for ii in range(i + 1, sizeI):
                if a[ii][j] == '#' or ret[ii][j]:
                    break
                ret[ii][j] = id
for row in ret:
    print(*row)


Measured memory_bytes: 7584
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	int[] a = new int[3];
	for (int i = 0; i < a.length; i++) {
	    a[i] = sc.nextInt();
	}
	if (a[0] > a[1]) {
	    int buf = a[0];
	    a[0] = a[1];
	    a[1] = buf;
	}
	if (a[1] > a[2]) {
	    int buf = a[1];
	    a[1] = a[2];
	    a[2] = buf;
	}
	if (a[0] > a[1]) {
	    int buf = a[0];
	    a[0] = a[1];
	    a[1] = buf;
	}
	System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}

Measured memory_bytes: 12000
n,i,j,r,S[12],C[12];
main(){
	for(;scanf("%d",&n),n;){
		for(i=0;i<n;i++)
			scanf("%d",C+i);
		r=0;
		do{
			memcpy(S,C,sizeof(S));
			for(i=0;i<n;i++){
				C[i]=0;
				for(j=0;j<n;j++)
					C[i]+=S[i]==S[j];
			}
			r++;
		}while(memcmp(S,C,sizeof(S))!=0);
		printf("%d\n",r-1);
		for(i=0;i<n;i++){
			if(i)
				putchar(' ');
			printf("%d",S[i]);
		}
		puts("");
	}
	exit(0);
}

Measured memory_bytes: 0
import sys
import math
import bisect

def main():
    ans = 0
    for _ in range(int(input())):
        a, b = input().split()
        a = float(a)
        if b == 'JPY':
            ans += a
        elif b == 'BTC':
            ans += a * 380000
    print('%.10f' % ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384