akhauriyash/Code-Regression huggingface dataset:
def read():
    N, A, B = list(map(int, input().strip().split()))
    return N, A, B

def solve(N, A, B):
    if A == 0:
        return 0
    repeats = N // (A + B)
    right = N - (A + B) * repeats
    blues = A * repeats + min(right, A)
    return blues


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)

class UnionFind():
  def __init__(self, n):
    self.par = [i for i in range(n)]

  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    self.par[y] = x

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

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

for i in range(M):
  x, y, z = map(int, input().split())
  uf.unite(x-1, y-1)

ans = set()
for i in range(N):
  ans.add(uf.root(i))
print(len(ans))

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

int main() {
  string s;
  cin>>s;
  int i,sum=700;
  for(i=0;i<s.size();i++){
    if(s.at(i)=='o'){
      sum+=100;
    }
  }
  cout<<sum<<endl;
}



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

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

vector<int> adjList[101010];
int cl[101010];

bool poss;

void dfs(int cur, int par) {
    for(auto nxt:adjList[cur])
        if(nxt != par)
            dfs(nxt, cur);
    if(cl[cur] == -1) {
        cl[cur] = 0;
        if(par == -1) {
            poss = false;
        }
        else if (cl[par] != -1) {
            poss = false;
        }
        else cl[par] = 1;
    }
}

int main()
{
    memset(cl,-1,sizeof(cl));
    poss = true;
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a,b;
    for(int ctr1 = 1; ctr1 < n; ctr1++) {
        cin>>a>>b;
        a--,b--;
        adjList[a].push_back(b);
        adjList[b].push_back(a);
    }
    dfs(0,-1);
    if(!poss)
        cout<<"First";
    else cout<<"Second";
    return 0;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll n;


ll vacay(ll n,ll a[],ll b[],ll c[])
{
    ll dp[n+1][3];
    dp[1][0] = a[0];
    dp[1][1] = b[0];
    dp[1][2] = c[0];

    for(ll i=2;i<=n;i++)
    {
        dp[i][0] = a[i-1] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b[i-1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c[i-1] + max(dp[i-1][0],dp[i-1][1]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int main()
{
    cin>>n;
    ll a[n],b[n],c[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<vacay(n,a,b,c);
}


Measured memory_bytes: 8264
// 2013/06/20 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool prm[250000];

	prm[0] = false;
	prm[1] = false;
	for(int i=2; i<250000; i++){
		prm[i] = true;
	}

	for(int i=2; i<250000; i++){
		if(!prm[i])
			continue;

		for(int j=i+i; j<250000; j+=i){
			prm[j] = false;
		}
	}

	int n_prm[250000];

	int cnt = 0;
	for(int i=0; i<250000; i++){
		if(prm[i]){
			cnt++;
		}

		n_prm[i] = cnt;
	}

	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		cout << n_prm[2*n]-n_prm[n] << endl;
	}

	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    
    int a_i;
    
    int i;
    int min = 1000001, max = -1000001;
    long int sum = 0 ;
    for(i = 0; i < n; i++){
        cin >> a_i;
        if(a_i < min) min = a_i;
        if(max < a_i) max = a_i;
        sum += a_i;
    }
    
    cout << min << " " << max << " " << sum << endl;

    return 0;
}

Measured memory_bytes: 3040
n = int(input())

d = {'AC':0,'WA':0,'TLE':0,'RE':0}
for _ in range(n):
    s = input()
    d[s] += 1
print(f'AC x {d["AC"]}')
print(f'WA x {d["WA"]}')
print(f'TLE x {d["TLE"]}')
print(f'RE x {d["RE"]}')

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int N, W; cin >> N >> W;
    int w[N], v[N];
    int V = 0; // 価値の和
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        V += v[i];
    }

    ll dp[N + 1][V + 1];
    for (int i = 0; i <= V; i++) dp[0][i] = (i == 0 ? 0 : linf);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= V; j++) {
            if (j < v[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
        }
    }

    ll ans;
    for (int i = 0; i <= V; i++) if (dp[N][i] <= W) ans = i;

    cout << ans << endl;

    return 0;
}

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class AHarmony {
public:
    void solve(istream& cin, ostream& cout) {
      int a, b; cin >> a >> b;
      if (abs(a-b)%2 == 1) {
        cout << "IMPOSSIBLE" << endl;
      } else {
        cout << (a+b)/2 << endl;
      }
    }
};

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

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int val = sc.nextInt();
		int index = 1;
		while(val > 0) {
			System.out.println("Case " +  index + ": " + val);
			index++;
			val = sc.nextInt();
		}
	}
}


Measured memory_bytes: 41308
#include<bits/stdc++.h>
using namespace std;
struct UnionFind{
  vector<int> parent;
  vector<int> size;
  
  UnionFind(int n){
    parent.resize(n+5);
    size.resize(n+5);
    for(int i=0; i<n+5; i++){
      size[i]=1;
      parent[i]=i;
    }
  }
  int getRoot(int x){//所属する木の根を求める
    if(parent[x]==x){
      return x;
    }
    return parent[x]=getRoot(parent[x]);
  }
  int getSize(int x){//木の大きさを求める
    return size[getRoot(x)];
  }
  bool isUnited(int x,int y){
    return (getRoot(x)==getRoot(y));
  }//同じ木に所属しているか判定
  bool unite(int x, int y){//木+木=木
    if(isUnited(x,y))return false;//同じ木だったら中断
    int rootX=getRoot(x);//木々の
    int rootY=getRoot(y);//  根同士を比較したい
    if(size[rootX] < size[rootY])swap(rootX,rootY);//大きい木にくっつけるようにしたい
    size [rootX]+=size[rootY];//木+木をしてサイズ更新
    parent[rootY]=rootX;//木の根をつけかえする
    return true;
  }
};
UnionFind uf(100005);
int main()
{
    int n,m,k,ans=0,flg=0;
    int rec,ac,bx;
    int bel[100005];
    cin>>n>>m>>k;
    memset(bel,0,sizeof(bel));
    for(int i=0; i<k; i++){
        cin>>rec>>ac>>bx;
        if(rec==1){
            if(bel[uf.getRoot(ac)] == bel[uf.getRoot(bx)]){
                uf.unite(ac,bx);
            }else if(bel[uf.getRoot(ac)]==0  && bel[uf.getRoot(bx)]!=0){
                bel[uf.getRoot(ac)] = bel[uf.getRoot(bx)];
            }else if(bel[uf.getRoot(ac)]!=0  && bel[uf.getRoot(bx)]==0 ){
                bel[uf.getRoot(bx)] = bel[uf.getRoot(ac)];
            }else{
                flg=i+1;
            }
        }else{
            if(bel[uf.getRoot(ac)]==bx || bel[uf.getRoot(ac)]==0){
                bel[uf.getRoot(ac)]=bx;                
            }else{
                flg=i+1;
            }
        }

        if(ans==0 && flg!=0)ans=flg;
    }

    cout<<ans<<'\n';
    return 0;

}


Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001;
const int NMAX=8;
const int mod = 1000000007;

int main()
{
  string s;
  cin>>s;
  int n=s.size();
  int f=(n-1)/2;
  int b=(n+3)/2;
  string S=s;
  reverse(S.begin(),S.end());

  string s1=s.substr(0,f);
  string s2=s.substr(b-1,n-b+1);
  string s3=s1;
  reverse(s3.begin(),s3.end());
  string s4=s2;
  reverse(s4.begin(),s4.end());
  string ans="Yes";
  if (s!=S)ans="No";
  if (s1!=s3)ans="No";
  if (s2!=s4)ans="No";
  cout<<ans;

}


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

const int N = 1e5 + 100, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if (a < 0)
		a += MOD;
	else if (a >= MOD)
		a -= MOD;
	return a;
}
int mul(int a, int b) {
	return 1LL * a * b % MOD;
}
void _sum(int &a, int b) {
	a = sum(a, b);
}
void _mul(int &a, int b) {
	a = mul(a, b);
}

int n, ans = 1, out[N], cnt[N], fac[N], inv[N], val[N], have[N], power[3][N];
bool mark[N];
vector<int> in[N];

void ZERO() {
	cout << "0\n";
	exit(0);
}

void pre_pro() {
	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = mul(fac[i - 1], i);
	inv[0] = inv[1] = 1;
	for (int i = 2; i < N; i++)
		inv[i] = mul(MOD - MOD / i, inv[MOD % i]);
	for (int i = 2; i < N; i++)
		_mul(inv[i], inv[i - 1]);
	val[0] = 1;
	for (int i = 1; i < N; i++)
		val[i] = mul(2 * i - 1, val[i - 1]);
	for (int i = 1; i <= 2; i++) {
		power[i][0] = 1;
		for (int j = 1; j < N; j++)
			power[i][j] = mul(power[i][j - 1], i);
	}
}

int c(int m, int n) {
	return (m > n? 0: mul(fac[n], mul(inv[m], inv[n - m])));
}

void input() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> out[i];
		in[--out[i]].push_back(i);
	}
}

void check() {
	for (int i = 0; i < n; i++)
		if (in[i].size() > 2)
			ZERO();
}

void go(int v, int now = 0) {
	if (cnt[v])
		ZERO();
	cnt[v] = now;
	if (in[v].size() > 1)
		return;
	mark[v] = true;
	go(out[v], now + 1);
}

void set_len() {
	for (int i = 0; i < n; i++)
		if (in[i].empty())
			go(i);
}

void dfs(int v, vector<int> *vec) {
	mark[v] = true;
	vec->push_back(v);
	if (mark[out[v]] == false)
		dfs(out[v], vec);
}

bool cycle(vector<int> vec) {
	for (int v: vec)
		if (cnt[v])
			return false;
	return true;
}

void f(vector<int> vec) {
	vector<int> X;
	for (int i = 0; i < vec.size(); i++)
		if (cnt[vec[i]])
			X.push_back(i);
	X.push_back(X[0]);
	for (int i = 1; i < X.size(); i++) {
		int a = (X[i] - X[i - 1] + vec.size()), b = cnt[vec[X[i]]];
		if (a > vec.size())
			a -= vec.size();
		if (b > a)
			ZERO();
		else if (b < a)
			_mul(ans, 2);
	}
}

void find_cycles() {
	for (int v = 0; v < n; v++)
		if (mark[v] == false) {
			vector<int> vec;
			dfs(v, &vec);
			if (cycle(vec))
				have[vec.size()]++;
			else
				f(vec);
		}
}

int handle(int l) {
	int res = 0;
	int p = 1 + ((l & 1) && (l > 1));
	int now = 1;
	for (int i = 0; 2 * i <= have[l]; i++) {
		_sum(res, mul(mul(c(2 * i, have[l]), val[i]), mul(power[p][have[l] - 2 * i], now)));
		_mul(now, l);
	}
	return res;
}

void check_cycles() {
	for (int i = 1; i < N; i++)
		_mul(ans, handle(i));
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	pre_pro();
	input();
	check();
	set_len();
	find_cycles();
	check_cycles();
	cout << ans;
}


Measured memory_bytes: 13048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

int main() {
	ll n, k;
	cin >> n >> k;
	mint ans = 0;
	ll pre = 0, suf = 0;
	for(int i= 0; i < n+1; i++) {
		pre += i;
		suf += n-i;
		if(i+1 >= k) ans += suf - pre + 1;
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define MAX 100001
typedef long long ll;
int main(){
	int n;
	cin >> n;
	int a;
	int A[MAX] = {};

	rep(i,n){
		cin >> a;
		A[a]++;
	}

	int ma = 0;
	rep(i,MAX-2){
		int sub = A[i]+A[i+1]+A[i+2];
		ma = max(ma,sub);
	}
	cout << ma << endl;
	return 0;
}


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

int n, m;
vector<int> G[1000];
bool rec(int from, vector<int>& v, vector<int>& used) {
  if (used[from] == 1) return false;
  if (used[from] == 2) {
    while (v.front() != from) {
      v.erase(v.begin());
    }
    return true;
  }
  used[from] = 2;
  v.push_back(from);
  for (int to : G[from]) {
    if (rec(to, v, used)) return true;
  }
  v.pop_back();
  used[from] = 1;
  return false;
}

vector<int> init() {
  vector<int> v;
  vector<int> used(n);
  for (int i = 0; i < n; ++i) {
    if (used[i] == 1) continue;
    if (rec(i, v, used)) return v;
  }
  return {};
}

vector<int> update(const vector<int>& s) {
  vector<int> in(n, -1);
  vector<int> nxt(n, -1);
  for (int i = 0; i < s.size(); ++i) {
    in[s[i]] = i;
    nxt[s[i]] = s[(i + 1) % s.size()];
  }
  
  for (int from : s) {
    for (int to : G[from]) {
      if (nxt[from] != to && in[to] != -1) {
        vector<int> ret;
        for (int i = in[to]; s[i % s.size()] != from; ++i) {
          ret.push_back(s[i % s.size()]);
        }
        ret.push_back(from);
        return ret;
      }
    }  
  }
  return s;
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
  }
  
  auto s = init();
  if (s.empty()) {
    cout << -1 << endl;
  } else {
    while (true) {
      auto t = update(s);
      if (t.size() == s.size()) {
        break;
      }
      s = move(t);
    }

    cout << s.size() << endl;
    for (int a : s) {
      cout << a + 1 << endl;
    }
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_map>
#include<iterator>
using namespace std;

int main()
{
    int N, AC=0, WA=0, TLE=0, RE=0, i;
    string str;
    cin>>N;
    for(i=0;i<N;i+=1)
    {
        cin>>str;
        if(str.compare("AC")==0)
        {
            AC+=1;
        }
        else if(str.compare("WA")==0)
        {
            WA+=1;
        }
        else if(str.compare("TLE")==0)
        {
            TLE+=1;
        }
        else
        {
            RE+=1;
        }
    }
    cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;
}

Measured memory_bytes: 3628
integer(8)::a(9)=[1,2,4,7,12,20,29,38,52],f(10)=0
read*,n
f(3)=1
do i=4,n
 f(i)=f(i-1)*(a(i-2)+a(i-3)+1)
enddo
do i=1,n
 do j=1,n
  print*,merge(0_8,f(max(i,j))*a(min(i,j))+1,i==j)
 enddo
enddo
end

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
int n,k,arr[MAXN+5],xam;
deque<int> deq;
int res(){
    if((long long)deq.front()*deq.back() >= 0)return abs(max(abs(deq.front()),abs(deq.back())));
    else{
        return min(abs(2*deq.front()) + abs(deq.back()), abs(2*deq.back()) + abs(deq.front()));
    }
}

int main(){
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++){
        scanf("%d", &arr[i]);
    }
    for(int i = 0; i < k; i++){
        deq.push_back(arr[i]);
    }
    xam = res();
    int cur = k;
    while(cur < n){
        deq.pop_front();
        deq.push_back(arr[cur]);
        cur++;
        xam = min(xam,res());
    }
    printf("%d\n", xam);
}


Measured memory_bytes: 1024
#include <stdio.h>
#define N 100
 
int main()
{
  int array[N], n, i, j, position, swap,count;
 
   scanf("%d", &n);
 
   for ( i = 0 ; i < n ; i++ )
      scanf("%d", &array[i]);
 
   for ( i = 0 ; i <  n - 1  ; i++ )
   {
      position = i;
 
      for ( j = i + 1 ; j < n ; j++ )
      {
         if ( array[position] > array[j] )
            position = j;
      }
      if ( position != i )
      {
         swap = array[i];
         array[i] = array[position];
         array[position] = swap;
	 count ++;
      }
   }
 
  
   for ( i = 0 ; i < n - 1 ; i++ )
     {
      printf("%d ", array[i]);
     }
  
   printf("%d\n",array[i]);
   printf("%d\n",count);
   return 0;
}

Measured memory_bytes: 2744
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        a: u32,
        b: u32,
        c: u32,
        x: u32,
    }
    let mut ans = 0;
    for i in 0..a + 1 {
        for j in 0..b + 1 {
            for k in 0..c + 1 {
                if i * 500 + j * 100 + k * 50 == x {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 2196
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define lc (seg+seg+1)
#define rc (seg+seg+2)

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

const int inf=1e16+10;
const int maxn=100100;

int n,e,t;

int x[maxn];

int mn[maxn*4];

int dp[maxn];

void cng(int seg,int ls,int rs,int ind,int x)
{
  if(ind+1<=ls or rs<=ind)
    return;
  if(ls==rs-1)
    {
      mn[seg]=x;
      return;
    }
  int mid=(ls+rs)>>1;
  cng(lc,ls,mid,ind,x);
  cng(rc,mid,rs,ind,x);
  mn[seg]=min(mn[lc],mn[rc]);
}

int mnr(int seg,int ls,int rs,int l,int r)
{
  if(r<=ls or rs<=l or r<=l)
    return inf;
  if(l<=ls and rs<=r)
    return mn[seg];
  int mid=(ls+rs)>>1;
  return min(mnr(lc,ls,mid,l,r),
	     mnr(rc,mid,rs,l,r));
}

int32_t main()
{
  memset(mn,63,sizeof mn);
  
  ios::sync_with_stdio(0);cin.tie(0);

  cin>>n>>e>>t;
  t+=t;

  int N=n+3;

  x[0]=-inf;
  for(int i=1;i<=n;i++)
    {
      cin>>x[i];
      x[i]+=x[i];
    }

  for(int i=1;i<=n;i++)
    {
      int j=lower_bound(x,x+n+1,x[i]-t/2)-x;
      dp[i]=dp[j-1]+t;
      if(x[j]==x[i]-t/2)
	j++;
      dp[i]=min(dp[i],mnr(0,0,N,0,j)+x[i]*2);
      cng(0,0,N,i,dp[i-1]-x[i]-x[i]);
    }

  cout<<dp[n]/2+e<<endl;
  
  return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int a[32], L;
	
	while (scanf("%d %d", &a[0], &L) && L){
		int idx = 0;
		while (1){
			int M, m;
			char buf[1024];
			sprintf(buf, "%0*d", L, a[idx]);
			sort(buf, buf + L);
			sscanf(buf, "%d", &m);
			reverse(buf, buf + L);
			sscanf(buf, "%d", &M);
			
			a[++idx] = M - m;
			
			for (int i = 0; i < idx - 1; i++){
				if (a[idx - 1] == a[i]){
					printf("%d %d %d\n", i, a[i], idx - 1 - i);
					goto next;
				}
			}
		}
next:;
	}
	
	return (0);
}

Measured memory_bytes: 1068
class Program
    {
        static void Main(string[] args)
        {
            var temp = System.Console.ReadLine().Split(' ');
            var S = temp[0];
            var T = temp[1];

            temp = System.Console.ReadLine().Split(' ');
            var table = new System.Collections.Generic.Dictionary<string, int>();
            table[S] = int.Parse(temp[0]);
            table[T] = int.Parse(temp[1]);

            var U = System.Console.ReadLine();
            --table[U];

            System.Console.WriteLine(table[S] + " " + table[T]);
        }
    }

Measured memory_bytes: 13152
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    string s;
    cin >> s;
    string t;
    t = s;
    reverse(t.begin(), t.end());
   if(s==t){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	void merge(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}
};

int main() {
//	cout << fixed << setprecision(15);
	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	vi ans;
	rep(i, q) {
		int com, x, y;
		cin >> com >> x >> y;
		if(com == 0) uf.merge(x, y);
		else ans.push_back(uf.issame(x, y));
	}
	for(auto i: ans) cout << i << endl;
}



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

int main(){
  int t=0;
  string s;
  cin >> s;

  int result=s.length();
  for(int i=0; i<s.length()-1; i++){
    if(s[i]!=s[i+1]){
      t= max(i+1, (int)s.length()-i-1);
      result = min(t, result);
    }
  }


  cout << result << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	int a;
	string s;
	cin>>a;
	cin>>s;
	if (a>=3200){
		cout<<s<<endl;
	}else{
		cout<<"red"<<endl;
	}

	return 0;
}

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

void visit(int kyori[], vector<list<int> > adj){
    int k;
    queue<int> que;
    list<int>::iterator t;
    que.push(1);
    while(!que.empty()){
        k = que.front();
        que.pop();
        for(t = adj[k].begin(); t != adj[k].end(); ++t){
            if(kyori[*t] == -1){
                kyori[*t] = kyori[k] + 1;
                que.push(*t);
            }
        }
    }

}

int main(){
    //input
    int n;
    cin >> n;
    int u, k, v;
    int i, j;
    list<int> list_sub;
    vector<list<int> > adj;
    for(i = 0; i <= n; i++){
        adj.push_back(list_sub);
    }
    for(i = 1; i <= n; i++){
        cin >> u >> k;
        for(j = 1; j <= k; j++){
            cin >> v;
            adj[i].push_back(v);
        }
    }

    //calc
    int kyori[n+1];
    for(i = 2; i <= n; i++){
        kyori[i] = -1;
    }
    kyori[1] = 0;
    visit(kyori, adj);

    //answer
    for(i = 1; i <= n; i++){
        cout << i << " " << kyori[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

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

    rep(loop, n) {
	int h, w;
	cin >> h >> w;

	vector<string> board;
	inputVector(board, h);

	int minX[27], maxX[27], minY[27], maxY[27];
	rep(i, 27) {
	    minX[i] = INT_MAX;
	    maxX[i] = -INT_MAX;
	    minY[i] = INT_MAX;
	    maxY[i] = -INT_MAX;
	}

	rep(y, h) {
	    rep(x, w) {
		if (board[y][x] == '.') continue;
		int arg = board[y][x] - 'A';
		minX[arg] = min(minX[arg], x);
		maxX[arg] = max(maxX[arg], x);
		minY[arg] = min(minY[arg], y);
		maxY[arg] = max(maxY[arg], y);
	    }
	}

	int cnt = 0;
	rep(i, 27) if (minX[i] != INT_MAX) cnt++;

	bool ok = true;
	rep(tmp, cnt) {
	    bool dflag = false;
	    rep(i, 27) {
		if (minX[i] == INT_MAX) continue;
		bool flag = true;
		REP(y, minY[i], maxY[i]) {
		    REP(x, minX[i], maxX[i]) {
			if (board[y][x] != '?' && board[y][x] != (char)(i + 'A')) {
			    flag = false;
			    break;
			}
		    }
		}
		if (!flag) continue;
		dflag = true;
		REP(y, minY[i], maxY[i]) {
		    REP(x, minX[i], maxX[i]) {
			board[y][x] = '?';
		    }
		}
		minX[i] = INT_MAX;
		break;
	    }
	    if (!dflag) {
		ok = false;
		break;
	    }
	}
	cout << (ok ? "SAFE" : "SUSPICIOUS") << endl;
    }

    return 0;
}

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

ll get_sum(vector<int> a, ll ans, ll sum) {
  for (int i = 1; i < a.size(); i++) {
    if (sum > 0) {
      sum += a[i];
      if (sum > -1) {
        ans += sum + 1;
        sum = -1;
      }
    } else {
      sum += a[i];
      if (sum < 1) {
        ans += -sum + 1;
        sum = 1;
      }
    }
  }

  return ans;
}

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

  ll ans;
  ll sum;

  //first plus
  if (a[0] > 0) {
    ans = 0;
    sum = a[0];
  } else {
    ans = abs(a[0]) + 1;
    sum = 1;
  }
  ll ans1 = get_sum(a, ans, sum);

  //first minus
  if (a[0] < 0) {
    ans = 0;
    sum = a[0];
  } else {
    ans = abs(a[0]) + 1;
    sum = -1;
  }
  ll ans2 = get_sum(a, ans, sum);

  cout << min(ans1, ans2) << endl;

  return 0;
}


Measured memory_bytes: 1028
/* UserName - ankit_S
  author -Ankit kumar
*/

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
const ll int MOD=1e9+7;

int main()
{
    FAST
    int n,k;
    cin>> n >> k;
    vector<int> stone(n);
    for(int i=0;i<n;i++){
    	cin>> stone[i];
   	}
    vector<bool>dp(k+1,false);
    dp[0]=true;
    for(int i=1;i<=k;i++ ){
        for(int j=0;j<n;j++){
            if(i>=stone[j]){
                if(i==stone[j])dp[i]=true;
                else {
                    dp[i]=dp[i]|(!dp[i-stone[j]]);
                }
            }
        }
       
    }
    // for(auto i:dp)cout<<i<<" ";
    // cout<<endl;
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl;   
 
    return 0;
}


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

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    int ans = 1e9;
    for(int i=0; i+k-1<n; i++){
        ans = min(ans,v.at(i+k-1)-v.at(i));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#define INF 1000000000000000000
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> P;

int main() {
	
	int a[10000] = { 0 };
	int n;
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		int c = 0;
		while (a[i] % 2 == 0) {
			a[i] = a[i] / 2;
			c++;
		}

		ans = ans + c;

	}

	cout << ans << endl;

	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,a[310],s,x,res,dp[70][2]; 

int main()
{
	cin>>n;
	rep(i,n) cin>>a[i];
	for(int i=2;i<n;i++) x^=a[i];
	s=a[0]+a[1];
	if(s-x<0||(s-x)%2==1)
	{
		puts("-1");
		return 0;
	}
	res=(s-x)/2;
	rep(i,65) rep(j,2) dp[i][j]=-1;
	dp[51][0]=0;
	for(int i=50;i>=0;i--)
	{
		if(dp[i+1][0]!=-1)
		{
			rep(j,2)
			{
				rep(k,2)
				{
					if((a[0]&(1LL<<i))>=j&&(j&k)==(int)((res&(1LL<<i))>0)&&(j^k)==(int)((x&(1LL<<i))>0))
					{
						if(j<(int)((a[0]&(1LL<<i))>0)) dp[i][1]=max(dp[i][1],dp[i+1][0]+(1LL<<i)*j);
						else dp[i][0]=max(dp[i][0],dp[i+1][0]+(1LL<<i)*j);
					}
				}
			}
		}
		if(dp[i+1][1]!=-1)
		{
			rep(j,2)
			{
				rep(k,2)
				{
					if((j&k)==(int)((res&(1LL<<i))>0)&&(j^k)==(int)((x&(1LL<<i))>0))
					dp[i][1]=max(dp[i][1],dp[i+1][1]+(1LL<<i)*j);
				}
			}
		}
	}
	if(dp[0][0]!=-1) cout<<0<<endl;
	else if(dp[0][1]!=-1&&dp[0][1]!=0) cout<<a[0]-dp[0][1]<<endl;
	else puts("-1");
	return 0;
}

Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)

	var a, k int

	xs := make([]int, m)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &k)
		for i := 0; i < k; i++ {
			fmt.Scanf("%d", &a)
			xs[a-1]++
		}
	}

	var z int
	for _, x := range xs {
		if x == n {
			z++
		}
	}

	fmt.Println(z)
}

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

int main(){
    int n;cin >> n;
    int f = n % 10;
    int t = n % 100 / 10;
    int h = n/100;

    if (f == 9){
        f = 1;
    } else if (f == 1){
        f = 9;
    }

    if (t == 9) {
        t = 1;
    } else if (t == 1){
        t = 9;
    }

    if (h == 1) {
        h = 9;
    } else if (h == 9){
        h = 1;
    }

    cout << h << t << f << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
S = str(input())
if len(S) < 1 or len(S) > 10 ** 5:
    sys.exit()
if not S.islower():
    sys.exit()

array_a_to_z = [chr(ord('a') + i) for i in range(26)]

for I in array_a_to_z:
    if I not in S:
        print(I)
        sys.exit()
print("None")

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

#define MOD 1000000007
#define int long long

int32_t main() {
    int n; 
    while(cin >> n) {
        int cnt[65];
        memset(cnt, 0, sizeof cnt);
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            for(int i = 0; i <= 60; i++){
                if( x & ( 1LL << i))cnt[i]++;
            }
        }
        int ans = 0;
        int p = 1;
        for(int i = 0; i <= 60; i++){
            ///cout << i << " " << cnt[i] << endl;
            int temp = (cnt[i]*(n-cnt[i])) % MOD;
            ///cout <<i << " " << temp*p << "\n";
            ans = (ans + (temp * p) % MOD) % MOD;
            p = (2 * p) % MOD;
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static int A, B, AB, X, Y;

	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(f.readLine());
		A = Integer.parseInt(st.nextToken());
		B = Integer.parseInt(st.nextToken());
		AB = Integer.parseInt(st.nextToken());
		X = Integer.parseInt(st.nextToken());
		Y = Integer.parseInt(st.nextToken());
		int res = 0;
		if (X >= Y) {
			int t = X;
			X = Y;
			Y = t;
			t = A;
			A = B;
			B = t;
		}
		// System.out.println(A + " " + B + " " + AB + " " + X + " " + Y);
		if (2 * AB <= B) {
			res = Y * (2 * AB);
		} else if (2 * AB < A + B) {
			res += X * (2 * AB);
			Y -= X;
			res += Y * B;
		} else {
			res = X * A + Y * B;
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 22996
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;


public class Main{
	public static void main(String args[]) throws IOException{
		Scanner bf = new Scanner(System.in);
		int[] list = new int[101];
		for(int i=0; i<101; i++){
			list[i] = 0;
		}
		while(bf.hasNext()){
			list[Integer.parseInt(bf.nextLine())]++;
		}
		ArrayList<Integer> ans = new ArrayList<Integer>();
		int max = 0;
		for(int i=1; i<=100; i++){
			if(list[i] == max) ans.add(i);
			else if(list[i] > max){
				ans.clear();
				max = list[i];
				ans.add(i);
			}
		}
		for(int i=0; i<ans.size(); i++){
			System.out.println(ans.get(i));
		}
	}
}

Measured memory_bytes: 17424
#include<bits/stdc++.h> 
using namespace std;
int n,m,a,b,c,dp[4100];
int main(){
	cin>>n>>m;
	int s=(1<<n);
	dp[0]=0;
	for(int i=1;i<s;i++)dp[i]=99999999;
	while(m--){
		cin>>a>>b;
		int t=0;
		while(b--)
		{
			cin>>c;
			t|=(1<<--c);
		}
		for(int i=0;i<s;i++){
			if(dp[i]!=99999999)dp[i|t]=min(dp[i|t],dp[i]+a);
		}	
	}
	if(dp[s-1]==99999999) 	cout<<-1;
	else cout<<dp[s-1];
	
}

Measured memory_bytes: 256
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
// use std::cmp::*;
use std::collections::*;

fn main() {
  input! {
     N:usize,
     c:Chars
  }
  // 例 N=7
  //  W,W,W,W,W,W,R
  // ^ ^ ^ ^ ^ ^ ^ ^
  //         4
  let mut i = 0;
  let mut j = N;
  let mut ans = 0;
  while i < j {
    while i < N && c[i] == 'R' {
      i += 1;
    }
    while j > 0 && c[j - 1] == 'W' {
      j -= 1;
    }
    if i >= j {
      break;
    }
    ans += 1;
    i += 1;
    j -= 1;
  }
  println!("{}", ans);
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int kol(int n)
{
    ll cnt = 0;
    while(n > 0)
    {
        cnt ++;
        n /= 10;
    }
    return cnt;
}

int main()
{
    ll n, cnt = 0;
    cin >> n;
    for(ll i = 1; i <= n; i ++)
    {
        if(kol(i) % 2 == 1)
        {
            cnt ++;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  
  for(int i=100; i>0; i--)
  {
    if(a%i==0 && b%i==0)
    {
//        cout << i << endl;
      k--;
      if(k==0)
      {
        cout << i << endl;
        return 0;
      }
    }
  }
  
  return 0;
}

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

int main(void)
{
   int n;
   cin >> n;
   ll ans = 0;
   for(int i = 1; i < n+1; i++) {
       if(i%3 == 0 || i%5 == 0) continue;
       ans += i;
   }
   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<iomanip>

#define ll long long

using namespace std;

int gcd(int a,int b){
    int tmp;
    if(a<b){
        tmp=b;
        b=a;
        a=tmp;
    }
    while(a-b>=0){
        a=a%b;
        if(a==0){
            return b;
        }
        if(a<b){
            tmp=b;
            b=a;
            a=tmp;
        }
    }
    return 1;
}

int main(){
    int N,X;
    cin >> N >> X;
    vector<int> x(N,0);
    for(int i=0;i<N;i++){
        cin >> x[i];
        x[i]=abs(x[i]-X);
    }
    int ans=x[0];
    for(int i=1;i<N;i++){
        ans=gcd(ans,x[i]);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int ones=0,zeros=0;
    for(int i = 0 ; i < s.size() ;i++)
    {
        if(s[i]=='0')
        {
            zeros++;
        }
        else
            ones++;
    }
    cout << min(zeros,ones)*2 ;
   return 0;
}


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

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

    vector<int> button(n);
    for (int i=0; i<n; i++) {
        cin >> button.at(i);
    }

    int cnt = -1;
    int button_light = 1;
    for (int i=0; i<n; i++) {
        button_light = button.at(button_light - 1);
        if (button_light == 2) {
            cnt = i + 1;
            break;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int H[MAXN],P[MAXN],id[MAXN],N;
int64 sum[MAXN];
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
	read(H[i]);read(P[i]);id[i] = i;
    }
    sort(id + 1,id + N + 1,[](int a,int b) {
	    if(H[a] < H[b] - P[a]) return true;
	    if(H[b] < H[a] - P[b]) return false;
	    return H[a] + P[a] < H[b] + P[b];
    });
    for(int i = 1 ; i <= N ; ++i) sum[i] = 1e18;
    for(int i = 1 ; i <= N ; ++i) {
	int u = id[i];
	for(int j = N ; j >= 1 ; --j) {
	    if(H[u] >= sum[j - 1]) {
		sum[j] = min(sum[j],sum[j - 1] + P[u]);
	    }
	}
    }
    for(int i = N ; i >= 1 ; --i) {
	if(sum[i] != 1e18) {out(i);enter;return;}
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int gcd(int p, int q){
  if(p % q == 0)
    return q;
   return gcd(q, p % q);
}

signed main(){
  int k;
  cin >> k;
  long sum = 0;
  for(int a = 1; a <= k; a++){
    for(int b = 1; b <= k; b++){
      for(int c = 1; c <= k; c++){
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int x;
    cin >> x;
    if (x == 1)
        cout << 0 << "\n";
    else if (x == 0)
        cout << 1 << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3640
// Crt. 2019-12-08  11:38:25
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 400005
using namespace std;
const int Mod = 1e9 + 7;

inline int fsp(int x, int p = Mod - 2) {
    int res = 1;
    while (p) {
        if (p & 1) res = 1ll * res * x % Mod;
        x = 1ll * x * x % Mod, p >>= 1;
    } return res;
}

inline void inc(int &x, int y) {
    x += y, x -= x >= Mod ? Mod : 0;
}

int n, m, a, b, fac[N], ifac[N];

inline int C(int x, int y) {
    return 1ll * fac[x + y] * ifac[x] % Mod * ifac[y] % Mod;
}

inline int walk(int x, int y, int xx, int yy) {
    return C(xx - x, yy - y);
}

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    n = 2e5;

    for (int i = fac[0] = 1; i <= n; ++i)
        fac[i] = 1ll * fac[i - 1] * i % Mod;
    ifac[n] = fsp(fac[n]);
    for (int i = n; i >= 1; --i)
        ifac[i - 1] = 1ll * ifac[i] * i % Mod;

    cin >> n >> m >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n - a; ++i) {
        inc(ans, 1ll * walk(1, 1, i, b) * walk(i, b + 1, n, m) % Mod);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 13, 2020 08:25:55 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = [-1]+list(map(int, input().split()))

  D = [-1]*(N+1)
  for i in range(N, 0, -1):
    if i > int(N/2):
      D[i] = A[i]
    else:
      temp_sum = 0
      for j in range(N//i, 1, -1):
        temp_sum += D[i*j]
      D[i] = (temp_sum % 2) ^ A[i]

  print(sum(D[1:]))
  for i in range(1, N+1):
    if D[i]:
      print(i)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 98836
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n: usize=read();
    let mut a=vec![0;n+1];

    a[1]=0;

    let mut ans: u64 = 0;

    for i in 1..=n{
        let mut j=i;
        while j<=n{
            a[j]+=1;
            j+=i;
        }
        ans+=i as u64*a[i];
    }

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

Measured memory_bytes: 80128
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[w,h]=i2()
p=[]
q=[]
import bisect
for i in range(w):
 p.append(i1())
for i in range(h):
 q.append(i1())
x=p[:]
x.sort()
d=[x[i] for i in range(w)]
for i in range(w-1):
  d[i+1]+=d[i]
ans=0
for i in range(h):
 dd=bisect.bisect_right(x,q[i])
 if dd>0:
    ans+=d[dd-1]

 ans+=(w-dd)*q[i]
for i in range(h):
 ans+=q[i]
print(ans+d[w-1])

Measured memory_bytes: 72420
using System;

namespace P0007_DebtHell
{
    class Program
    {
        static void Main(string[] args)
        {
            int week = int.Parse(Console.ReadLine());

            decimal debt = 100000;

            for (int i = 1; i <= week; i++)
            {

                debt *= (decimal)1.05;

                if (!int.Parse(debt.ToString("0")).ToString().EndsWith("000")) 
                {
                    debt = Math.Ceiling(debt / 1000) * 1000;
                }

            }

            Console.WriteLine(debt.ToString("0"));


        }
    }
}

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

int main() {
    int a, b, c, t;
    cin >> a >> b >> c;
    if (a > b) {
        t = a;
        a = b;
        b = t;
    }
    if (b > c) {
        t = b;
        b = c;
        c = t;
    }
    if (a > b) {
        t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3096
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

k = int(input())
sum = 0
for a in range(k):
    for b in range(k):
        gcd_ab = gcd(a + 1, b + 1)
        for c in range(k):
            sum += gcd(gcd_ab, c + 1)
print(sum)

Measured memory_bytes: 9128
#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>

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() {
  int x, y, z;
  cin >> x >> y >> z;
  int ret = (x - z) / (y + z);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define N 500005
#define LL long long
#define oo (1<<30)
using namespace std;
int n,q,ans,f[27][N],F[20][N]; char st[N];
int main()
{
	int i,j,l,r;
	scanf("%s",st+1);
	n = strlen(st+1);
	for(i=1;i<=n;i++)
		f[st[i]-'a'][i]=i;
	for(i=n-1;i>=1;i--){
		for(j=st[i]-'a'+1;j<=26;j++)
			f[j][i]=f[j-1][f[j-1][i] ? f[j-1][i]+1 : 0];
		for(j=0;j<st[i]-'a';j++)
			f[j][i]=f[j][f[26][i] ? f[26][i]+1 : 0];
	  }
	for(i=1;i<=n;i++)
		F[0][i]=f[26][i] ? f[26][i]+1 : 0;
	for(i=1;i<20;i++)
		for(j=1;j<=n;j++)
			F[i][j]=F[i-1][F[i-1][j]];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&l,&r),ans=0;
		for(i=19;i>=0;i--)
			if(F[i][l]<=r+1&&F[i][l])
				l=F[i][l];
		if(l>r) printf("Yes\n");
		else printf("No\n");
	  }
	return 0;
}


Measured memory_bytes: 92928
data = input().split(" ")
N = int(data[0])
M = int(data[1])
answer = 0

if N == 0:
  answer = (M*(M-1))/2
elif M == 0:
  answer = (N*(N-1))/2
else:
  mth1 = (N*(N-1))/2
  mth2 = (M*(M-1))/2
  answer = mth1 + mth2
print(int(answer))

Measured memory_bytes: 3060
S = input()
flag = 'Yes'
for i,s in enumerate(S):
  if (i%2 == 0)&(s=='L'):
    flag = 'No'
    break
  elif (i%2 == 1)&(s=='R'):
    flag = 'No'
    break
  else:
    flag = 'Yes'
    continue

print(flag)

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


typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;

void cpc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}

int main()
{
	// cpc();
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// lli t;
	// cin >> t;
	// while (t--)
	// {
	char s;

	cin >> s;
	if (s == '7')
	{
		cout << "Yes" << endl;
		return 0;
	}
	cin >> s;
	if (s == '7')
	{
		cout << "Yes" << endl;
		return 0;
	}
	cin >> s;
	if (s == '7')
	{
		cout << "Yes" << endl;
		return 0;
	}
	else
		cout << "No" << endl;
	// }
	return 0;
}

Measured memory_bytes: 3620
n,k = map(int,input().split())

if n == k:
  print(0)
  exit()
  
if n > k:
  if n%k == 0:
    print(0)
    exit()
  else:
    if n%k > abs(n%k-k):
      print(abs(n%k-k))
    else:
      print(n%k)

if n < k:
  if n > abs(n-k):
    print(abs(n-k))
    exit()
  else:
    print(n)
    exit()

Measured memory_bytes: 3064