akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b)
{
	return a%b==0?b:gcd(b,a%b);
}
long long T,A,n;
int main()
{
	scanf("%lld\n",&n);
	scanf("%lld %lld",&T,&A);
	for(long long i=2;i<=n;i++)
	{
		long long a,b;
		scanf("%lld %lld",&a,&b);
		long long cc=(T+a-1)/a;
		long long ee=(A+b-1)/b;
		long long O=max(cc,ee);
		T=a*O;
		A=b*O;
	}
	printf("%lld\n",T+A);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



int main(){
   int n;
   string s;
   cin >> n >> s;
   int count=0;
   for(int i=0; i<n-2; i++){
       if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C'){
           count ++;
       }
   }

    cout << count << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include<bits/stdc++.h>
#define INF 2147483647
using namespace std;
int n,q,a,b,c,N=1;
vector<int>v;
void update(int b,int c){
    b+=N-1;
    v[b]=c;
    while(b>0){
        b=(b-1)/2;
        v[b]=min(v[2*b+1],v[2*b+2]);
    }
    return ;
}
int find(int b,int c,int N,int r,int l){
    if(l<=b||c<=r)return INF;
    else if(b<=r&&l<=c)return v[N];
    else {
        int c1=find(b,c,2*N+1,r,(r+l)/2);
        int c2=find(b,c,2*N+2,(r+l)/2,l);
        return min(c1,c2);
    }
}

int main(void){
    cin>>n>>q;
    while(N<n){
        N*=2;
    }
    v=vector<int>(N*2-1,INF);
    for(int i=0;i<q;i++){
        cin>>a>>b>>c;
        if(a==0)update(b,c);
        if(a==1)cout<<find(b,c+1,0,0,N)<<endl;;
    }
}



Measured memory_bytes: 4988
#include <iostream>
#include <vector>
char x[10000];
int main()
{
    long long n;
    scanf("%lld", &n);
    n--;
    int l = 1;
    long long x = 26;
    while (x <= n)
    {
        n -= x;
        x *= 26;
        l++;
    }
    for (int i = 0; i < l; i++)
    {
        ::x[l - 1 - i] = 'a' + n % 26;
        //printf("%c", 'a' + n % 26);
        n /= 26;
    }
    printf("%s\n", ::x);
    return 0;
}

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

vector<string> to = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main() {
    string s;
    cin >> s;
    int ans;
    rep(i,7) {
        if (s == to[i]) {
            ans = 7 - i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int i,a,b,c;
    for (i=1;i<=3000;i++)
{    cin >> a >> b;
if ( a==0 && b==0)
break;
    if( a > b )
    {
    c=a;
    a=b;
    b=c;
    }
    
    cout<< a << " " << b << endl;
}
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }

template <class T> inline auto __lcm(T &a, T &b)
{ return a * b / __gcd(a, b); }


int main() {
    ll N;
    cin >> N;

    ll cnt = 0;
    vector<ll> v;
    for (ll i = 1; i <= 26; ++i){
        double tmp = pow(5, i) * 2;
        //print("tmp" << tmp);
        v.push_back(tmp);
    }
    rep(i, v.size()) {
        cnt += N / v[i];
    }
    
    if (N % 2 == 0) {
        print(cnt);
    } else {
        print(0);
    }

    return 0;
}


Measured memory_bytes: 256
import sys
imput=sys.stdin.readline
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
q=int(input())
x=[0]*q;y=[0]*q
for i in range(q):
    x[i],y[i]=map(int,input().split())
l=[]
for i in range(min(x),max(y)+1,2):
    d=prime_factorize(i)
    e=prime_factorize((i+1)//2)
    #print(d)
    if d==[i] and e==[(i+1)//2]:
        l.append(i)
#print(l)
for i in range(q):
    ans=0
    for j in range(len(l)):
        if x[i]<=l[j]<=y[i]:
            ans+=1
    print(ans)

Measured memory_bytes: 65368
from queue import *


d = [(1,0),(0,1),(-1,0),(0,-1)]
temp={}

while True:
    W,H = (int(x) for x in input().split())
    mmap=[]
    visited=[]
    flag=0
    count=1
    
    q = Queue()
    
    if W==0 & H==0:
        break
    for i in range(0,H):
        mmap.append(list(input()))
    for i in range (0,H):
        for j in range(0,W):
            if mmap[i][j] == '@':
                start=[i,j]
    
    q.put(start)
    visited.append(list(start))
    while not q.empty():
        now = q.get()
        for myd in d:
            now2 = list(now)
            now2[0] += myd[0]
            now2[1] += myd[1]
            if not(now2[0]==-1 or now2[0]==H or now2[1]==-1 or now2[1]==W) :
                if mmap[now2[0]][now2[1]] != '#' :
                    flag=0
                    for v in visited:
                        if now2 == v :
                            flag=1
                            break
                    if flag==0:
                        count+=1
                        q.put(now2)
                        visited.append(list(now2))
    
    print(count)



Measured memory_bytes: 6884
#include<set>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int a[11],b[10],d[26],e[26];
int fn(int p,int q){
  int i;
  int ct=0;
  if(a[p+1]==-1){
    if(0){
    }else if(q==0&&d[a[p]]==0){
      for(i=e[a[p]];i<10;i++){
	if(b[i])
	  ct++;
      }
    }else if(q==0){
      if(b[0]&&e[a[p]]==0)
	ct=1;
    }else if(d[a[p]]==0){
    }else{
      for(i=e[a[p]];i<10;i++){
	if(b[i]&&q+i*d[a[p]]==0)
	  ct++;
      }
    }
  }else{
    for(i=e[a[p]];i<10;i++){
      if(b[i]){
	b[i]=0;
	ct+=fn(p+1,q+i*d[a[p]]);
	b[i]=-1;
      }
    }
  }
  return ct;
}
int main(){
  int i,j;
  int n;
  memset(b,-1,sizeof(b));
  while(cin>>n&&n){
    int mx=0;
    set<int> f;
    memset(d,0,sizeof(d));
    memset(e,0,sizeof(e));
    for(i=0;i<n;i++){
      string s;
      cin>>s;
      int ln=s.length();
      if(i==n-1)
	mx=(mx<=ln);
      else
	mx=max(mx,ln);
      for(j=0;j<ln;j++){
	f.insert(s[j]-'A');
	if(j==0&&ln>1)
	  e[s[j]-'A']=1;
	if(i<n-1)
	  d[s[j]-'A']+=(int)pow(10,ln-j-1);
	else
	  d[s[j]-'A']-=(int)pow(10,ln-j-1);
      }
    }
    if(mx){
      set<int>::iterator it;
      i=0;
      for(it=f.begin();it!=f.end();it++){
	a[i]=*it;
	i++;
      }
      a[i]=-1;
      cout<<fn(0,0)<<endl;
    }else{
      cout<<0<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 956
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x, t; cin >> x >> t;
    cout << max(0, x - t) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int X[N];
  REP(i,N)cin>>X[i];
  int ans=1e9;
  REP(x,101){
    int temp=0;
    REP(i,N)temp+=(X[i]-x)*(X[i]-x);
    ans=min(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;
#define ull unsigned long long
#define llong long long

int main() {
	llong n;
	cin >> n;
	vector<llong> lu(100, 0);
	lu[0] = 2;
	lu[1] = 1;
	for (int i = 2; i <= n; i++) {
		lu[i] = lu[i - 1] + lu[i - 2];
	}
	cout << lu[n];
	return 0;
}





Measured memory_bytes: 256
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int a;
    cin >> a;
    int ans=a+a*a+a*a*a;
    cout << ans << endl;
}

int main(){
    solve();
    return 0;
}




Measured memory_bytes: 3596
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
struct UnionFind{
  vector<int>d;
  UnionFind(int n=0):d(n,-1){}
  int find(int x){
    if(d[x]<0)return x;
    return d[x]=find(d[x]);
  }
  bool unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y)return false;
    if(d[x]>d[y])swap(x,y);
    d[x]+=d[y];
    d[y]=x;
    return false;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  int size(int x){return -d[find(x)];}
};
int main(){ 
  int a,d=0;cin>>a;
  map<string,int>b;
  string c;
  rep(i,a){
    cin>>c;
    if(b.count(c)==false){
      d++;
      b[c]=1;
    }
  }
  cout<<d;
}


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

int main() {
    int A[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) cin >> A[i][j]; 
    }
    int n; cin >> n;
    int b[n+1];
    for (int i = 0; i < n; i++) cin >> b[i];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < n; k++) {
                if (A[i][j] == b[k]) { A[i][j] = 0; break; }
            }
        }
    }

    int sum;
    for (int i = 0; i < 3; i++) {
        sum = 0;
        for (int j = 0; j < 3; j++) {
            if (A[i][j]) sum += A[i][j];
        }
        if (sum == 0) { puts("Yes"); return 0; }
    }

    for (int i = 0; i < 3; i++) {
        sum = 0;
        for (int j = 0; j < 3; j++) {
            if (A[j][i]) sum += A[j][i];
        }
        if (sum == 0) { puts("Yes"); return 0; }
    }
    sum = 0;
    for (int i = 0; i < 3; i++) {
        sum += A[i][i];
    }
    if (sum == 0) { puts("Yes"); return 0; }
    sum = 0;
    for (int i = 0; i < 3; i++) {
        sum += A[i][2-i];
    }
    if (sum == 0) { puts("Yes"); return 0; }
    puts("No");
}

Measured memory_bytes: 256
// Aizu Vol-6 0610: Weather Forecaster
// 2017.9.5 bal4u@uu

#include <stdio.h>

char map[103][103];
int ans[103][103];

int main()
{
	int h, w, x, y, p;

	scanf("%d%d", &h, &w);
	for (y = 0; y < h; y++) scanf("%s", map[y]);
	for (y = 0; y < h; y++) for (p = -1, x = 0; x < w; x++) {
		if (map[y][x] == 'c') p = x;
		ans[y][x] = p < 0 ? -1 : x - p;
	}
	for (y = 0; y < h; y++) {
		printf("%d", ans[y][0]);
		for (x = 1; x < w; x++) printf(" %d", ans[y][x]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1888
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

int a[200222];
int bc[200222];
int ob[200222];
int ans[200222];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
		if(s[i]=='A')a[i]=1;
		else if(i<s.length()-1&&s[i]=='B'&&s[i+1]=='C')
		{
			bc[i]=1;
			i++;
		}
		else ob[i]=1;
	}
	/*
	for(int i = 0; i < s.length(); i++){
		cout << ob[i] ;
	}
	cout << endl;
	*/
	for(int i = s.length()-1; i>=0; i--){
		if(bc[i]){
			for(int j = i-1; j>=0; j--){
				if(bc[j]){
					bc[j]+=bc[i];
					i=j+1;
					break;
				}else if(ob[j])break;
			}
		}
	}
	int ptr = 0;
	for(int i = s.length()-1; i>=0; i--){
		if(bc[i])ptr = bc[i];
		else if(ob[i])ptr = 0;
		ans[i] = ptr;
	}
	/*
	for(int i = 0; i < s.length(); i++){
		cout << i << " " << ans[i] << endl;
	}
	*/
	ll answ = 0;
	for(int i = 0; i < s.length(); i++){
		if(a[i])answ+=ans[i];
	}
	cout << answ << endl;
}	


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

int main(){
  int plus=0;
  int minus=0;
  char a[4];
  for(int i=0;i<4;i++){
    cin >> a[i];
    if(a[i]=='+'){
      plus++;
    }else{
      minus++;
    }
  }

  cout << plus-minus << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using std::cin;
using std::cout;

const int N = 105;

int f[N][N][N], g[N][N], p[N][N], mo;

signed main() {
	int n, m, k; 
	cin >> n >> m >> k >> mo;
	f[0][0][0] = 1;
	for (int i = 0; i <= 100; ++ i) {
		g[i][0] = 1;
		for (int j = 1; j <= i; ++ j) {
			g[i][j] = (g[i - 1][j] + g[i - 1][j - 1]) % mo;
		}
	}
	for (int i = 0; i <= 100; ++ i) {
		p[i][0] = 1;
		for (int j = 1; j <= 100; ++ j)  {
			p[i][j] = p[i][j - 1] * i % mo;
		}
	}
	for (int h = 1; h <= k; ++ h) {
		for (int i = 0; i <= n; ++ i) {
			for (int j = 0; j <= m; ++ j) {
				for (int t = (p[k - h + 1][j] * ((p[h][m - j] - p[h - 1][m - j] + mo) % mo)) % mo, s = 1, l = i; l <= n; ++ l) {
					(f[h][l][j] += (s * g[n - i][l - i] % mo * f[h - 1][i][j] % mo)) %= mo;
					(s *= t) %= mo;
				}
			}
		}
		for (int i = 0; i <= n; ++ i) {
			for (int j = m; ~j; -- j) {
				for (int t = (p[h][n - i] * ((p[k - h + 1][i] - p[k - h][i] + mo) % mo)) % mo, s = 1, l = j + 1; l <= m; ++ l) {
					(s *= t) %= mo;
					(f[h][i][l] += (s * g[m - j][l - j] % mo * f[h][i][j] % mo)) %= mo;
				}
			}
		}
	}
	cout << f[k][n][m] << '\n';
	return 0;
}

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

vector<pair<int, int>> counter(map<int, int> m) {
  vector<pair<int, int>> v;
  for (auto&& i : m) {
    v.push_back(make_pair(i.first, i.second));
  }
  return v;
}

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

  int n;
  cin >> n;
  int v[100000];
  rep(i, n) cin >> v[i];

  map<int, int> a;
  map<int, int> b;
  rep(i, n) {
    if (i%2 == 0) {
      a[v[i]]++;
    } else {
      b[v[i]]++;
    }
  }

  vector<pair<int, int>> A = counter(a);
  vector<pair<int, int>> B = counter(b);
  sort(A.begin(), A.end(), [](pair<int, int> a, pair<int, int> b){return a.second > b.second;});
  sort(B.begin(), B.end(), [](pair<int, int> a, pair<int, int> b){return a.second > b.second;});

//  for (auto&& i : A) {
//    cout << i.first << " " << i.second << endl;
//  }
//  cout << endl;
//  for (auto&& i : A) {
//    cout << i.first << " " << i.second << endl;
//  }

  int ans;
  if (A[0].first == B[0].first) {
    int a1 = (A.size() == 1 ? 0 : A[1].second);
    int b1 = (B.size() == 1 ? 0 : B[1].second);
    ans = n - max(A[0].second+b1, B[0].second+a1);
  } else {
   ans = n - A[0].second - B[0].second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8828
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int cnt=0;
  int ans;
  for(int i=min(a,b);i>0;i--){
    if(a%i==0&&b%i==0)cnt++;
    //cout<<i<<endl;
    if(cnt==c){
      ans=i;
      break;
    }
  }
  
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for one in A:
    tmp = [x * y for x, y in zip(one, B)]
    if sum(tmp) + c > 0:
        ans += 1
print(ans)


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

int main() {
  int N, l, r, ans;
  cin >> N;

  ans = 0;
  for (int i=0; i<N; i++) {
      cin >> l >> r;
      ans += r - l + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n], sum=0;
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    sum+=a[i];
  }
  double t=(double) sum/(4*m);
  int cnt=0;
  for(int i=0; i<n; i++)if((double) a[i]>=t)cnt++;
  if(cnt>=m)printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int m, k, n;
	bool s = false;
	cin >> n >> m >> k;
	rep(i, n+1) {
		rep(j, m+1) {
			//cout << i*j + (n - i)*(m - j) << endl;
			if (i*j + (n - i)*(m - j)==k) s = true;
		}
	}
	cout << (s ? "Yes" : "No") << endl;
}

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

int l;

int ma_f(vector<int> a) {

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

    int b = 1;
    rep(i, l-1) b *= 10;

    int res=0;
    rep(i, l) {
        res += b * a[i];
        b /= 10;
    }

    return res;
}

int mi_f(vector<int> a) {

    sort(a.begin(), a.end());

    int b = 1;

    int res=0;
    for (int i=l-1; i>=0; --i) {
        res += b * a[i];
        b *= 10;
    }

    return res;
}


int main() {

    int a;
    while (cin >> a >> l, (a or l)) {

        vector<int> z;
        z.push_back(a);

        bool update = true;
        int cnt = 1;
        int b = 1;
        rep(i, l-1) b *= 10;

        while (update) {

            vector<int> t(l);

            int tb = b;
            rep(i, l) {
                t[i] = a / tb;
                a -= (a / tb) * tb;
                tb /= 10;
            }

            a = ma_f(t) - mi_f(t);
            rep(i, z.size()) {
                if (a == z[i]) {
                    cout << i << ' ' << a << ' ' << cnt-i << endl;
                    update=false;
                    break;
                }
            }
            z.push_back(a);

            cnt++;

        }


    }
}

Measured memory_bytes: 3124
#include <iomanip>
#include <iostream>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
#define MAX_N 100010
int parent[MAX_N];
int length[MAX_N];
void init(int n) {
  rep(i, n) {
    parent[i] = i;
    length[i] = 1;
  }
}
int find(int x) {
  while (parent[x] != x) x = parent[x];
  return x;
}
bool isSame(int x, int y) { return (find(x) == find(y)); }
bool unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return false;
  if (length[x] < length[y]) swap(x, y);
  parent[y] = x;
  length[x] += length[y];
  return true;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  init(N);
  vector<int> F(N + 1, 0);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    unite(a, b);
    F[a]++;
    F[b]++;
  }
  vector<int> B(N + 1, 0);
  rep(i, K) {
    int c, d;
    cin >> c >> d;
    if (isSame(c, d)) {
      B[c]++;
      B[d]++;
    }
  }

  for (int i = 1; i <= N; ++i) {
    cout << length[find(i)] - 1 - F[i] - B[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
'''
nCk mod pを求める。

nCk= n!/k!(n-k)!を考えるが、単純計算だと途中の桁が膨大になり計算が間に合わない。
そこで計算中にmodをとるが、割り算にmodを適用するためには逆元を求める必要がある。


'''

from collections import defaultdict,deque
import sys, bisect, math, itertools
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


class combination():
    def __init__(self, mod):
        '''
        modを指定して初期化
        '''
        self.mod=mod
        self.fac = [1, 1]  # 階乗テーブル
        self.ifac = [1, 1]  # 階乗の逆元テーブル
        self.inv = [0, 1]  # 逆元計算用

    def calc(self,n,k):
        '''
        nCk%modを計算する
        '''
        if k < 0 or n < k:
            return 0
        self.make_tables(n) #テーブル作成
        k = min(k, n - k)
        return self.fac[n] * (self.ifac[k] * self.ifac[n - k] % self.mod) % self.mod

    def make_tables(self, n):
        '''
        階乗テーブル・階乗の逆元テーブルを作成
        '''
        for i in range(len(self.fac), n + 1):
            self.fac.append((self.fac[-1] * i) % self.mod)
            self.inv.append((-self.inv[self.mod % i] * (self.mod // i)) % self.mod)
            self.ifac.append((self.ifac[-1] * self.inv[-1]) % self.mod)

comb = combination(mod)

x, y = inpl()
if x > y:
    x, y = y, x
dist = x + y
if dist % 3:
    print(0)
    exit()
total = int((x + y) // 3)
n = x - total
if y > 2 * x:
    print(0)
    exit()

print(comb.calc(total, n))

Measured memory_bytes: 82812
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

vector<int> con;
vector<vector<pair<int,int>>> C;

void check(int x, int depth, int num){
	if(depth == C[x].size()){
		con[num]++;
		return;
	}
	for(int i = 0, k = C[x][depth].first; i < C[x][depth].second; i++, k *= C[x][depth].first){
		check(x, depth+1, num*k);
	}
	check(x, depth+1, num);
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, M;
	vector<int> A, B, D, used;
	vector<vector<int>> E;
	
	cin>>N;
	
	A.resize(N+10);
	con.resize(N+10);
	
	C.resize(N+10);
	used.resize(N+10);
	
	for(int i = 2; i <= N; i++){
		if(C[i].size()) continue;
		
		for(int j = i; j <= N; j += i){
			int con = 0, num = j;
			
			while(num%i == 0){
				con++;
				num /= i;
			}
			C[j].push_back(make_pair(i,con));
		}
	}


	for(int i = 1; i <= N; i++){
		cin>>A[i];
	}
	
	for(int i = N; i >= 1; i--){
		if(A[i] != con[i]%2){
			B.push_back(i);
			check(i,0,1);
		}
	}
	
	cout<<B.size()<<endl;
	
	if(B.size() == 0) return 0;
	
	for(int i = 0; i < B.size(); i++){
		
		if(i)cout<<" ";
		cout<<B[i];
	}
	cout<<endl;
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> Term(1,0);
  vector<int> Num(0);
  
  for(int i = 0; i < N; i++){
  cin >> S.at(i);
  }
  
  sort(S.begin(),S.end());
  if(N == 1){
  cout << S.at(0) << endl;
  }else{
  	for(int i = 1; i < N; i++){
  		if(S.at(i-1) != S.at(i)){
        Term.push_back(i);
        }
  	}
    
    int k = Term.size();
    
    if(k == 1){
      cout << S.at(0) << endl;
    }else{
    
    		for(int i = 1; i < k; i++){
    		Num.push_back(Term.at(i)-Term.at(i-1));
    		}
      Num.push_back(N - Term.at(k-1));
  	}
  
    int max = 0;
    for(int i = 0;i<Num.size(); i++){
      if(Num.at(i) > max){
      max = Num.at(i);
      }
    }
    
    for(int i = 0;i<Num.size(); i++){
    if(Num.at(i) == max){
    cout << S.at(Term.at(i)) << endl;
    }
    }
  }
}


Measured memory_bytes: 15992
import heapq
V,E,r = map(int,input().split())
adj = [ [] for _ in range(V) ]

for _ in range(E):
  u,v,w = map(int,input().split())
  adj[u].append((v,w))

def dijkstra():
  dist = [float('inf')] * V
  dist[r] = 0
  visited = [False] * V

  pq = [(0,r)]
  while pq:
    w,n = heapq.heappop(pq)
    visited[n] = True

    for nei,wei in adj[n]:
      if visited[nei]: continue
      if w+wei < dist[nei]:
        dist[nei] = w+wei
        heapq.heappush(pq, (w+wei, nei))

  return dist

for d in dijkstra():
  if d == float('inf'):
    print("INF")
  else:
    print(d)



Measured memory_bytes: 91208
#include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n && n;){
		int a[n];
		for(int i=0;i<n;i++) cin>>a[i];
		
		for(int i=1;i<=int(1e8);i++){
			int c=0;
			for(int j=0;j<n;j++)
				c+=a[j]%i==0;
			if(c==n)
				cout<<i<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
from heapq import heappush, heappop

N = int(input())
P = [int(i) for i in input().split()]

dpl = [[] for _ in range(N)]
dpr = [[] for _ in range(N)]
q = []
for i in range(N-1, -1, -1) :
    L = []
    while len(q) > 0 and q[0][0] < P[i] :
        v, j = heappop(q)
        if len(dpl[j]) == 0 :
            L.append([v, j])
        dpl[j].append(i)
    for v, j in L :
        heappush(q, [v, j])
    heappush(q, [P[i], i])

q = []
for i in range(N) :
    L = []
    while len(q) > 0 and q[0][0] < P[i] :
        v, j = heappop(q)
        if len(dpr[j]) == 0 :
            L.append([v, j])
        dpr[j].append(i)
    for v, j in L :
        heappush(q, [v, j])
    heappush(q, [P[i], i])

for i in range(N) :
    for _ in range(2-len(dpl[i])) :
        dpl[i].append(-1)
    for _ in range(2-len(dpr[i])) :
        dpr[i].append(N)
    dpl[i].sort()
    dpr[i].sort()

ret = 0
for i in range(N) :
    ret += (dpl[i][1]-dpl[i][0]) * (dpr[i][0]-i) * P[i]
    ret += (i-dpl[i][1]) * (dpr[i][1] - dpr[i][0]) * P[i]

print(ret)

Measured memory_bytes: 99848
#include<stdio.h>
#include<string.h>

int main(void){
    char s[101];
    int i;
    for (i = 0;i<101;i++) {
        s[i] = '\0';
    }
    scanf("%s",&s);
    char s0[1];
    s0[0] = s[0];
    printf("%c%d%c",s0[0],strlen(s) - 2,s[strlen(s)-1]);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(void)
{
    int  a,b[200000],i,j,n=0,m,x,y,z=0;
    char c[10100],s[10100];

    scanf("%s",&s);
    x=strlen(s);
    for (size_t i = 0; i < x; i=i+2)
    {
     if(s[i]=='L')   {printf("No"); return 0;}

     if(s[i+1]=='R')   { printf("No"); return 0;}
    }
    
    printf("Yes");
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

#define N 100000

typedef struct{
  int par, left_child, right_sibling, depth;
  char status[15];
}Node;

Node tree[N];
int n, nchild[N];
char root[N];

void calc_depth(int p, int d){
  tree[p].depth = d;
  if(tree[p].right_sibling != -1) calc_depth(tree[p].right_sibling, d);
  if(tree[p].left_child != -1) calc_depth(tree[p].left_child, d+1);
}

void print_node(int p, int cnt, int size){
  if(cnt + 1 == size) printf("%d", p);
  else{
    printf("%d, ", p);
    print_node(tree[p].right_sibling, cnt + 1, size);
  }
}

main(){
  int i, j, r;
  scanf("%d", &n);
  memset(root, 1, n);
  for(i=0;i<n;i++) tree[i].left_child = tree[i].right_sibling = -1;
  for(i=0;i<n;i++){
    int idx;
    scanf("%d", &idx);
    scanf("%d", &nchild[idx]);
    if(nchild[idx] == 0) strcpy(tree[idx].status, "leaf");
    else strcpy(tree[idx].status, "internal node");
    for(j=0;j<nchild[idx];j++){
      int in, pre;
      scanf("%d", &in);
      tree[in].par = idx;
      root[in] = 0;
      if(j == 0) tree[idx].left_child = in;
      else tree[pre].right_sibling = in;
      pre = in;
    }
  }
  for(i=0;i<n;i++) if(root[i]) r = i;
  tree[r].par = -1;
  strcpy(tree[r].status, "root");
  calc_depth(r, 0);
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, %s, [", i, tree[i].par, tree[i].depth, tree[i].status);
    if(tree[i].left_child != -1) print_node(tree[i].left_child, 0, nchild[i]);
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 6764
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			
			int S = sc.nextInt();
			int T = sc.nextInt();
			int C =0;
			if(S>T) {
				C=T;
			}else {
				C=S;
			}
			
			
			int l =1;
			for(int i=C;i>1;i--) {
			if(Math.floorMod(S, i)==0) {
					if(Math.floorMod(T, i)==0){
						l=i;
						break;

					}
				}
			}
	
			
			System.out.println((long)S*(long)T/l);
	}	

}


Measured memory_bytes: 35796
import math
N=list(map(int,input().split()))
a=['X' for _ in range(int(N[0]))]
A=0
for i in range(int(N[0])):
    a[i]=list(map(int,input().split()))
    for t in range(int(i)):
        if i!=t:
            Y=[]
            for s in range(int(N[1])):
                Y+=[(a[i][s]-a[t][s])**2]
            Z=sum(Y)
            if (math.sqrt(Z))- int(math.sqrt(Z))==0:
                A+=1
        else:
            continue
print(A)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  vector<int> p(3), a(3);
  for (int i = 0; i < 3; ++i) p[i] = i;
  for (int i = 0; i < 3; ++i) {
    scanf("%d", &a[i]);
  }
  int ret = INF;
  do {
    int cost = 0;
    for (int i = 1; i < 3; ++i) {
      cost += abs(a[p[i - 1]] - a[p[i]]);
    }
    ret = min(ret, cost);
  } while (next_permutation(p.begin(), p.end()));
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
r,g,b = gets.strip.split.map(&:to_i)
k = gets.strip.to_i
#g * 2** gg > r
#b * 2** bb > gn
#gg+bb <= k
#gg = log2(r/g) = log2(r) - log2(g)

c = 0
while g <= r
  g *= 2
  c += 1
end
while b <= g
  b *= 2
  c += 1
end
if c > k
  puts "No"
else
  puts "Yes"
end


Measured memory_bytes: 14364
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max({x,y,z})
#define MX4(x,y,z,p) max({x,y,z,p})
#define MX5(x,y,z,p,q) max({x,y,z,p,q})
#define MN3(x,y,z) min({x,y,z})
#define MN4(x,y,z,p) min({x,y,z,p})
#define MN5(x,y,z,p,q) min({x,y,z,p,q})
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

char arr[10010];

void solve() {

    int n;
    SI(n);
    scanf("%s", arr);
    int len = strlen(arr);
    for(int i = 0 ; i < len ; i++) {
        int now = arr[i] - 'A';
        now += n;
        now %= 26;
        arr[i] = now + 'A';
    }
    printf("%s\n", arr);

}

void init() {
    


}

int main () {
    init();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

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

    int ans = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) ans ++;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3124
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int N, M;
string S, T;

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

int main(){
	cin >> N >> M;
	cin >> S >> T;
	if(S[0] != T[0]){
		cout << -1 << endl;
		return 0;
	}
	ll lcm = (ll)N / (ll)gcd(N, M) * (ll)M;
	int div1 = N / gcd(N, M), div2 = M / gcd(N, M);
	for(int i = 0; i < gcd(N, M); i++){
		if(S[i * div1] != T[i * div2]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << lcm << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

template <typename T>
long long largest_rectangle_hist(vector<T> &height) {
    stack<int> st;
    height.emplace_back(0);
    vector<int> left(height.size());
    long long ret = 0;
    for (int i = 0; i < height.size(); i++) {
        while (!st.empty() && height[st.top()] >= height[i]) {
            ret = max(ret, 1LL * (i - left[st.top()]) * height[st.top()]);
            st.pop();
        }
        left[i] = st.empty() ? 0 : st.top() + 1;
        st.emplace(i);
    }
    return ret;
}

int main() {
    int N; cin >> N;
    vector<int> h(N);
    for (int &hi: h) cin >> hi;
    cout << largest_rectangle_hist(h) << endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	map<int,int>num;
	int ans = 0;
	for (int i = 0;i < n;i++) {
		int x;
		cin >> x;
		if (x > n)ans++;//次のfor文をn回で済ませられるようにn以上のxは除く
		else num[x - 1]++;//xの個数を数えていく 
	}
	for (int i = 0;i < n;i++) {
		if (num[i] > i + 1)ans += num[i] - i - 1;//n<=xの場合
		if (num[i] < i + 1)ans += num[i];//n<xの場合
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DRemainderReminder {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N, K;
        in >> N >> K;
        ll answer = 0;
        REP(b,K+1, N+1) {
            answer += (N / b) * (b - K);
            if (K==0) answer--;
            if (N % b >= K) {
                answer += N % b - K + 1;
            }
        }
        out << answer << "\n";
    }
};


signed main() {
    DRemainderReminder solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {  
        for (int b = 0; b + a <= N; ++b) { 
            int c = N - a - b;  
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {  
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int x, t;
    cin >> x >> t;
    int ans = max(x-t, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int N;
int ans[40];
int tens[40];

struct keta{
    int big;
    int least;
    int num;
};

signed main(void) {

    cin >> N;

    rep(i,40){
        ans[i] = 0;
    }

    keta nums[40];
    int start = 1;
    rep(i,40){

        nums[i].num = start;
//        cout << nums[i].num <<endl;
        start *= -2;
    }

    int a = 2;
    nums[0].big = 1;
    nums[1].big = 1;
    while(a<40){
        nums[a].big = nums[a-2].big + nums[a].num;
        nums[a+1].big = nums[a-2].big + nums[a].num;
//        cout << nums[a].big << endl;
        a += 2;
    }

    int b = 3;
    nums[0].least = 0;
    nums[1].least = -2;
    nums[2].least = -2;
    while(b < 39){
        nums[b].least = nums[b-2].least + nums[b].num;
        nums[b+1].least = nums[b-2].least + nums[b].num;
//        cout << nums[b].least << endl;
        b += 2;
    }

    nums[b].least = nums[b-2].least + nums[b].num;

//cout << "yes" << endl;
    for(int i = 39; i >=1; i-- ){
//        cout << i << endl;
        if(N > nums[i-1].big || N < nums[i-1].least) {
            ans[i] = 1;
//            cout << i << endl;
            N -= nums[i].num;
        }
    }
    if(N==1){
        ans[0] = 1;
    }

    int bigans = 0;
    rep(i,40){
        if(ans[i]==1){
            bigans = i;
        }
    }

    while(bigans >= 0){
        cout << ans[bigans];
        bigans--;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import math
from math import gcd

mod = 1000000007
 
N = int(sys.stdin.readline().strip())
zero = 0
mp = {}
for _ in range(N):
    a, b = map(int, sys.stdin.readline().strip().split())

    if a == 0 and b == 0:
        zero += 1
        continue
 
    g = gcd(a, b)
    a = a // g
    b = b // g
 
    if b < 0:
        a = -a
        b = -b
    if b == 0 and a < 0:
        a = -a
    if a <= 0:
        a, b = b, -a
        if (a, b) in mp:
            mp[(a, b)][0] += 1
        else:
            mp[(a, b)] = [1, 0]
    else:
        if (a, b) in mp:
            mp[(a, b)][1] += 1
        else:
            mp[(a, b)] = [0, 1]
 
ans = 1
for key in mp:
    s, t = mp[key]
    ans *= pow(2, s, mod) + pow(2, t, mod) - 1
    ans %= mod
print((zero - 1 + ans) % mod)

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli wSum[400000];
lli eSum[400000];

void func(long long N, std::string S){

    lli wCnt=0,eCnt=0;
    REP(i,0,N){
        eSum[i+1] += eSum[i];
        wSum[i+1] += wSum[i];
        if(S[i]=='E')eSum[i+1] += 1;
        else wSum[i+1] += 1;
    }

    REP(i,0,N+1){
        LOG3(i,eSum[i],wSum[i]);
    }

    lli ans = INF;
    REP(i,1,N+1){
        ans = min(ans,eSum[N]-eSum[i]+wSum[i-1]);
    }

    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    func(N, S);
    return 0;
}


Measured memory_bytes: 7044
#include <stdio.h>
int main(void){
    while(1){
    
         int a,n,i;
        scanf("%d",&n);
        if(n==0)
        break;
        int count0=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0;

        for(i=1;i<=n;i++){
            scanf("%d ",&a);
        
            if(a>=60) count6++;
            else if(a<60&&a>=50) count5++;
            else if(a<50&&a>=40) count4++;
            else if(a<40&&a>=30) count3++;
            else if(a<30&&a>=20) count2++;
            else if(a<20&&a>=10) count1++;
            else if(a<10) count0++;
        }    
    printf("%d\n",count0);
    printf("%d\n",count1);
    printf("%d\n",count2);
    printf("%d\n",count3);
    printf("%d\n",count4);
    printf("%d\n",count5);
    printf("%d\n",count6);
    }
}


Measured memory_bytes: 2048
from math import sin,cos,pi

def rad(ang):
  return pi/180 * ang

x = y = 0
ang = 90

while True:
  dist, next_ang = map(int, input().split(','))
  x += dist * cos(rad(ang))
  y += dist * sin(rad(ang))
  ang += -1 * next_ang
  if dist == 0 and next_ang ==0:
    break

print(int(x))
print(int(y))

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

int main(){
	int n, m;
	char a, b;
	map<char, char> ma;

	while(cin >> n, n){
		ma.clear();
		for(int i=0; i < n; i++){
			cin >> a >> b;
			ma[a] = b;
		}

		cin >> m;
		for(int i=0; i < m; i++){
			cin >> a;
			if(ma[a] != '\0') cout << ma[a];
			else cout << a;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1188
n, m = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])
s = sorted(l, key=lambda x:x[0])
ans = 0
for i in range(n):
  a, b = s[i]
  if b <= m:
    ans += a*b
    m -= b
  else:
    ans += a*m
    break
print(ans)

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

int main () {
  long long N,H;
  cin >> N >> H;
  
  vector<long long>a(N);
  vector<long long>b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  long long A = a.at(0);
  
  long long countb = 0;
  long long sumB = 0;
  for (int i = 0; i < N; i++) {
    if (b.at(i) > A){
      countb++;
      sumB += b.at(i);
      if (sumB >= H){
        cout << countb << endl;
        return 0;
      }
    }
    else {
      break;
    }
  }
  cout << (H - sumB + A - 1)/A + countb << endl;
}
  
  
  
 
  
   

Measured memory_bytes: 4716
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n, t;
    cin >> n >> t;
    vec<pair<int, int>> v(n);

    for (auto &e : v)
    {
        cin >> e.first >> e.second;
    }

    sort(v.begin(), v.end());

    bool found{};
    for (auto e : v)
    {
        if (e.second <= t)
        {
            cout << e.first << endl;
            found = true;
            break;
        }
    }

    if (!found)
    {
        cout << "TLE" << endl;
    }

    return 0;
}

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

int main(void){
    long a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({b*d,a*c,a*d,b*c}) << endl;
}

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

int main()
{
  while(true)
  {
    int a, b;
    char op;
    cin>>a>>op>>b;
    switch (op) 
    {
      case '+':{
        cout<<a+b<<endl;
        break;
      }
      case '-' :{
        cout<<a-b<<endl;
        break;
      }
      case '*' :{
        cout<<a*b<<endl;
        break;
      }
      case '/' :{
        cout<<a/b<<endl;
        break;
      }
      default :{
        return 0;
      }
    }
  }

}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, x[55], y[55];
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
	long long ret = 1LL << 62;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				for (int l = 0; l < N; l++) {
					if (x[i] <= x[j] && y[k] <= y[l]) {
						int cnt = 0;
						for (int p = 0; p < N; p++) {
							if (x[i] <= x[p] && x[p] <= x[j] && y[k] <= y[p] && y[p] <= y[l]) cnt++;
						}
						if (cnt >= K) ret = min(ret, 1LL * (x[j] - x[i]) * (y[l] - y[k]));
					}
				}
			}
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(0, N-1):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
        count += 1

print(*A)
print(count)


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

using namespace std;
priority_queue <int> q;
int main()
{
    int n,m,x;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        q.push(x);
    }
    while(m)
    {
        x=q.top();
        q.pop();
        x/=2;
        q.push(x);
        m--;
    }
    long long  s=0;
    while(!q.empty())
    {
        s+=q.top();
        q.pop();
    }
    cout<<s;
    return 0;
}


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

int main() {
  long long n;
  cin >> n;
  long long sqn = sqrt(n);
  long long a, b;
  for (int i = sqn; i >= 0; i--) {
    if (n % i == 0) {
      a = i;
      b = n/i;
      break;
    }
  }

  long long ans = a + b - 2;
  cout << ans;
}

Measured memory_bytes: 256