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

const unsigned int mod = 1000000007;

vector <bool> pom(1002,0);
vector <vector < bool > > baza(1002,pom);
vector <long long int> pomv(1002,0);
vector <vector <long long int> > val(1002,pomv);
int n,m;

int main(){
	char a;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a;
			if(a=='.')baza[i][j]=true;
			else baza[i][j]=false;
		}
	}
	val[1][1]=1;
	for(int j=1;j<=m;j++){
		for(int i=1;i<=n;i++){
			if(i==1 && j==1)continue;
			if(baza[i][j]==false)continue;
			else{
				if(val[i][j-1]!=0 && val[i-1][j]!=0){
					val[i][j]=val[i][j-1]+val[i-1][j];
				}else if(val[i][j-1]!=0)val[i][j]=val[i][j-1];
				else val[i][j]=val[i-1][j];
				val[i][j]%=mod;
			}
		}
	}
	val[n][m]%=mod;
	cout<<val[n][m];
	
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

//二項係数の計算
const int MAX = 510000;
ll fac[MAX],finv[MAX],inv[MAX];

//テーブルの初期化
void COMinit(){
	fac[0] = fac[1] = 1;//階乗
	finv[0] = finv[1] = 1;//階乗の逆元
	inv[1] = 1;//逆元(1の逆元は1)
	for(int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;//累積積的な感じ
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;//inv[i] = iの逆元(mod mod)
		finv[i] = finv[i - 1] * inv[i] % mod;//階乗の逆元の計算
	}
}
ll COM(int n,int k){//二項係数の計算
	if(n < k){
		return 0;
	}
	if (n < 0 || k < 0){
		return 0;
	} 
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


int main(){
	int n;cin>>n;
	ll m;cin>>m;
	vector<ll> a(n);
	vector<ll> sum(n + 1,0LL);
	ll s = 0;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		s += a[i];
		s %= m;
		sum[i + 1] = s;
	}
	map<ll,ll> q;
	for(int i = 0; i <= n; i++) {
		if (q.find(sum[i]) != q.end()){
			q[sum[i]]++;
		}	
		else{
			q[sum[i]] = 1;
		}
	}
	ll ans = 0;
	for(auto i = q.begin(); i != q.end(); i++) {
		ans += i->second * (i->second - 1) / 2;
	}
	cout << ans << endl;


	return 0;
}

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

int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	int cost[12], A[12][12];
	for (int i = 0; i < n; ++i)
	{
		cin >> cost[i];
		for (int j = 0; j < m; ++j)
		{
			cin >> A[i][j];
		}
	}
	int ans = 1145141919;
	bitset<12> bit;
	for (int i = 0; i < pow(2,n); ++i)
	{
		bit = i;
		int nowCost = 0;
		int nowA[12] = {};
		for (int j = 0; j < n; ++j)
		{
			if(bit[j])
			{
				nowCost += cost[j];
				for (int k = 0; k < m; ++k)
				{
					nowA[k] += A[j][k];
				}
			}
		}
		bool ok = 1;
		for (int j = 0; j < m; ++j)
		{
			if(nowA[j] < x)
			{
				ok = 0;
			}
		}
		if(ok)
		{
			ans = min(ans, nowCost);
		}
	}
	if(ans == 1145141919)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4028
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000000
#define endl "\n"
#define PI 3.14159265358979323846264338327950288

using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;


int main(){
    FAST_IO ;
    char ch ; cin >> ch ;
    cout << char(ch + 1) << endl ;
    
    return 0 ;
  }



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;cin >> x >> y;
	ll ma=1000000000000000;
	cout << min(y-x>=0?y-x:ma,min(y-(-x)>=0?y-(-x)+1:ma,min((-y)-x>=0?(-y)-x+1:ma,(-y)-(-x)>=0?(-y)-(-x)+2:ma))) << endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        y: usize,
    }

    for i in 0..n+1 {
        for j in 0..n+1 {
            if n < i+j {
                continue;
            } else {
                if 10000*i+5000*j+1000*(n-i-j)==y {
                    print!("{} ",i);
                    print!("{} ",j);
                    println!("{}",n-i-j);
                    return;
                }
            }
        }
    }
    println!("-1 -1 -1");
}


Measured memory_bytes: 2200
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << n + n * n + n * n * n << endl;
}


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 3e5 + 5, INF = 0x3f3f3f3f;

int main() {
	int n; rd(n);
	vector<int> a(n);
	for (int& i : a) rd(i);

	int x = 0;
	for (int i = 0; i < n; i++) x ^= a[i];

	for (int i = 0; i < n; i++) {
		printf("%d ", x^a[i]);
	}
	puts("");

}

Measured memory_bytes: 3892
n,*h=map(int,open(0).read().split())
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]+=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 13876
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    int S = 0;
    int x[110];
    for (int i = 0; i < N; i++) {
        cin >> x[i];
        S += x[i];
    }
    sort(x, x+N);
    if (S % 10 != 0) {
        cout << S << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        if (x[i] % 10 != 0) {
            S -= x[i];
            break;
        }
    }
    if (S % 10 == 0) S = 0;
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n, m;
    cin >> n >> m;
    int s[m], c[m];
    for (int i = 0; i < m; i++) {
        cin >> s[i] >> c[i];
    }

    char num[5];
    for (int i = 0; i < 5; i++) {
        num[i] = 0;
    }
    bool ok = true;
    for (int i = 0; i < m; i++) {
        if ((s[i] == 1) && (c[i] == 0)) {
            ok = false;
            break;
        } else if ((num[s[i]] != 0) && (num[s[i]] != c[i] + '0')) {
            ok = false;
            break;
        } else {
            num[s[i]] = c[i] + '0';
        }
    }
    if (num[1] == 0) {
        num[1] = '1';
    }
    for (int i = 2; i <= n; i++) {
        if (num[i] == 0) {
            num[i] = '0';
        }
    }

    bool zero = false;
    if (n == 1) {
        zero = true;
        if (m == 0) {
            ;
        } else {
            for (int i = 0; i < m; i++) {
                if (c[i] != 0) {
                    zero = false;
                    break;
                }
            }
        }
    }
    if (ok && !zero) {
        for (int i = 1; i <= n; i++) {
            cout << num[i];
        }
        cout << endl;
    } else if (zero) {
        cout << 0 << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int l[1000],r[1000];
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>l[i]>>r[i];
    sum=sum+(r[i]-l[i])+1;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;

public class Program
{
    public static long loop;

    static long n;

    static long[] d;

    static string output;

    public static void Main(string[] args)
    {
        loop = 0;

        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        n = long.Parse(input[0]);

        // スペース区切りの整数の入力(横、配列)
        input = Console.ReadLine().Split(' ');

        d = new long[n];
        for (long idx = 0; idx < n; idx++)
        {
            d[idx] = long.Parse(input[idx]);
        }

    }

    static void Proc()
    {
        long sum = 0;

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

        // プラスマイナス0に相当する n * xMax の値を出力(0個選択の分を除外するため-1)
        output = sum.ToString();
    }

    static void Output()
    {
        // 出力
        Console.WriteLine(output);
        output = string.Empty;
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n],b[n]={},i=0,j=1;
  while(cin>>a[i])i++;
  i=0;
  while(a[i]!=2){
    if(b[i]==1){j=-1;break;}
    b[i]=1;
    i=a[i]-1;
    j++;
  }
  cout<<j;
}

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

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}


Measured memory_bytes: 3544
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int x;
  cin >> x;
  
  int p_max = (int)sqrt(x);
  int max_num = 0;
  int num;
  for(int i = 1; i <= p_max; i++){
    for(int j = 1; j <= 10; j++){
      num = pow(i, j); //cout << num << " ";
      if(num <= x && num > max_num) max_num = num;
      if(num > x) break;
    }
  }
  //cout << endl;
  
  cout << max_num << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

typedef struct{
    ll to;
    ll cost;
} edge;


using namespace std;
int N,M;
ll a[2010], b[2010], c[2010];
vector<edge> tree[2010];
ll dist[2010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    rep(i,0,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        c[i] *= -1;
        edge ed = {b[i], c[i]};
        tree[a[i]].push_back(ed);
    }
    rep(i,0,N){
        dist[i] = 1e18;
    }
    dist[0] = 0;
    rep(i,0,N-1){
        rep(j,0,M){
            if(dist[a[j]] == 1e18) continue;
            if(dist[b[j]] > dist[a[j]] + c[j]){
                dist[b[j]] = dist[a[j]] + c[j];
            }
        }
    }
    rep(i,0,N-1){
        rep(j,0,M){
            if(dist[a[j]] == 1e18) continue;
            if(dist[b[j]] > dist[a[j]] + c[j]){
                dist[b[j]] = dist[a[j]] + c[j];
            }
        }
    }
    bool is_negative[2010];
    rep(i,0,N){
        is_negative[i] = false;
    }
    rep(i,0,N){
        rep(j,0,M){
            if(dist[a[j]] == 1e18) continue;
            if(dist[b[j]] > dist[a[j]] + c[j]){
                dist[b[j]] = dist[a[j]] + c[j];
                is_negative[b[j]] = true;
            }
            if(is_negative[a[j]]){
                is_negative[b[j]] = true;
            }
        }
    }
    if(is_negative[N-1]){
        print("inf");
    }else{
        print(-dist[N-1]);
    }







}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    unsigned long long S;
    cin >> S;
    // S 10^18
    // X2*Y2 - Y2*X3 = S
    // v * Y2 - X3 = S
    // -X3 = S (mod v)
    // v-X3 = S(mod v)
    // X3 - v = v-S(mod v)
    // X3 = 2*v-S(mod v)
    const long long v = 1000000000;
    unsigned long long X3 = (v - S % v) % v;
    if(S % v == 0) {
        X3 = 0;
    }
    unsigned long long Y3 = (S + X3) / v;

    cout << fixed << setprecision(0) << 0 << " " << 0 << " " << v << " " << 1
         << " " << X3 << " " << Y3 << endl;
    return 0;
}

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

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

  int ans = 0;

  for (int i = 0; i < 10; i++) {
    int x1 = 0;
    while (s[x1] != '0' + i && x1 < n) {
      x1++;
    }
    if (x1 == n) {
      continue;
    }

    for (int j = 0; j < 10; j++) {
      int x2 = x1 + 1;
      while (s[x2] != '0' + j && x2 < n) {
        x2++;
      }
      if (x2 == n) {
        continue;
      }

      for (int k = 0; k < 10; k++) {
        int x3 = x2 + 1;
        while (s[x3] != '0' + k && x3 < n) {
          x3++;
        }
        if (x3 != n) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int cnt=0;
  if(a==b)cnt++;
  if(b==c)cnt++;
  if(a==c)cnt++;
  if(cnt==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int h,w;
char c[11][11];

string urdl="URDL";
// URDL
int dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};

int o_ct=0;

#define IN(x,y) (0<=x && x<w && 0<=y && y<h)
string ans;
void dfs(string now, int x, int y, int d)
{
    if(now.size()==o_ct)
    {
        ans=now;
        return;
    }

    for(int i=-1; i<=1; ++i)
    {
        int nd = (d+i+4)%4;
        for(int k=1; k<10; ++k)
        {
            int nx = x+k*dx[nd], ny = y+k*dy[nd];
            if(IN(nx,ny) && c[ny][nx]=='o')
            {
                c[y][x]='.';
                dfs(now+urdl[nd], nx, ny, nd);
                c[y][x]='o';
                break;
            }
        }
    }
}

int main()
{
    scanf(" %d %d", &h, &w);
    rep(i,h) scanf(" %s", c[i]);

    int sx,sy,dir;
    rep(i,h)rep(j,w)
    {
        if(c[i][j]!='.' && c[i][j]!='o')
        {
            sx=j;
            sy=i;

            if(c[i][j]=='U') dir=0;
            else if(c[i][j]=='R') dir=1;
            else if(c[i][j]=='D') dir=2;
            else if(c[i][j]=='L') dir=3;
        }
        else if(c[i][j]=='o') ++o_ct;
    }

    dfs("",sx,sy,dir);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    cout << 0 << endl;
    string S;
    cin >> S;
    string A;
    if(S == "Vacant") return 0;
    else A = S;
    int left = 0,right = N-1;
	int P = 20;
    while(P--){
        int mid = left + abs(right - left)/2;
        cout << mid << endl;
        cin >> S;
        if(S == "Vacant") return 0;
        else if(S == A && mid % 2 == 0) left = mid+1;
        else if(S != A && mid % 2 == 1) left = mid+1;
        else right = mid-1;
    }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int a, b;
    cin >> a >> b;

    cout << a + b/2 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a,b;
    cin >> a >> b;
    cout<<(a-1)*(b-1)<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
string s,a; 
int main()
{
	cin>>s;
	for(int i=0; i<s.length(); i++)
	{
		if(s[i]=='B')
		{
			if(a.length()!=0) a.erase(a.length()-1,1);
		}
		else a+=s[i];
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>

using namespace std;

int main() {
        int a[55][55],t[55];
	int H, W;
	cin >> H >> W;
	getchar();
	int i, j;
	char ch;
	for(i = 1; i <= H; i++) {
		for(j = 1; j <= W; j++) {
			ch = getchar();
			a[i][j] = (ch == '#')? 1 : 0;
		}
		getchar();
	}
	int no = 0;
	for(i = 2; i < H; i++) {
		for(j = 2; j < W; j++) {
			if(a[i][j - 1] == 0 && a[i][j] == 1 && a[i][j + 1] == 0
			&& a[i - 1][j] == 0 &&a[i + 1][j] == 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;

int main() {
    int ind = 0;
    long long ans = 0, B = 0;
    string s;
    cin >> s;

    while (s[ind] == 'W' && ind < s.size())
        ind++;
    for (int i = ind; i < s.size(); i++) {
        if (s[i] == 'B')
            B++;
        else
            s[i] = 'B', s[ind] = 'W', ans += B, ind++;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 640
n = int(input())
lst = []
for _ in range(n):
    a = int(input())
    lst.append([[int(i) for i in input().split()] for _ in range(a)])
m = 0
for i in range(2 ** n):
    a = True
    for j in range(n):
        if i >> j & 1:
            for x, y in lst[j]:
                if (i >> (x - 1) & 1) != y:
                    a = False
                    break
    if a:
        m = max(m, sum(map(int, bin(i)[2:])))
print(m)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(ll i=0;i<n;i++)
#define repp(j, n) for(ll j=0;j<n;j++)
#define reppp(i, m, n) for(ll i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

ll digit_sum(ll n, ll b){
    ll ret = 0;
    while(n >= b){
        ret += (n % b);
        n /= b;
    }
    ret += n;
    return ret;
}

signed main(){
    ll n, s;
    cin >> n >> s;
    
    if(n == s){
        cout << n+1;
        return 0;
    }

    reppp(b, 2, (ll)sqrt((double)n)){
        if(digit_sum(n, b) == s){
            cout << b;
            return 0;
        }
    }

    ll p = min(s, (ll)sqrt((double)n)), b;
    while(p > 0){
        if((n-s)%p == 0){
            b = (n-s)/p + 1;
            if(b > p && b > (s-p)){
                cout << b;
                return 0;
            }
        }
        p--;
    }

    cout << -1;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define p push_back
#define endl "\n"
#define l long long int
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    l n,stock=0,rs=1000 ;
    cin>>n;
    vector<l>v;
    for(l i=0;i<n;i++){
        l s;
        cin>>s;
        v.p(s);
    }
    vector<l>::iterator start; 
    start = unique(v.begin(), v.begin() + v.size());
    v.resize(std::distance(v.begin(), start)); 
    for(l i=0;i<v.size()-1;i++){
        if(v[i]<v[i+1]){
            // buy
          if(rs>v[i]){
            stock+=rs/v[i];
            rs-=stock*v[i];
          }
        }
        else{
            // sell
            rs+=stock*v[i];
            stock=0;
        }
    }
  if(stock!=0){
   	 rs+=v[v.size()-1]*stock;
    stock=0;
  }
    cout<<rs;
    return 0;
}


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

int main() {
    int N; cin >> N;
    double S = 0;
    for(int i = 0; i < N; i++) {
        double x; cin >> x;
        S += (1/x);
    }
    cout << 1/S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N,X;
vector<ll> S;

ll dp[220][100010];

int main(){
  cin>>N>>X;
  S.resize(N,0);
  for(int i=0;i<N;i++) cin>>S[i];
  sort(S.begin(),S.end());

  dp[0][X]=1;
  for(int i=0;i<N;i++){
      for(int j=0;j<=X;j++){
          if(dp[i][j]){
              for(int k=0;k<N;k++){
                  if(S[k]<=j){
                      dp[i+1][j%S[k]]+=dp[i][j];
                      dp[i+1][j%S[k]]%=MOD;
                  }else{
                      ll z=dp[i][j]*(N-i-k)%MOD;
                      dp[i+1][j]+=z;
                      dp[i+1][j]%=MOD;
                      break;
                  }
              }
          }
      }
  }

  ll ans=0;
  for(int i=0;i<=X;i++){
      ans=(ans+dp[N][i]*i%MOD)%MOD;
      ans=(ans+MOD)%MOD;
  }
  cout<<(ans+MOD)%MOD<<endl;

  return 0;
}


Measured memory_bytes: 150400
def factorize(a):
    x=2
    ret=[]
    rt_a=a**0.5
    while x<=a:
        if(x>=rt_a):
            ret.append(a)
            break
        if(a%x==0):
            ret.append(x)
        while a%x==0:
            a//=x
        x+=1
    return ret

def gcd(a,b):
    tmp=a
    a=max(a,b)
    b=min(tmp,b)
    if(a%b==0):
        return b
    return gcd(b,a%b)

a,b=map(int,input().split())
print(len(set(factorize(gcd(a,b))))+1)

Measured memory_bytes: 3064
mod = 10**9+7
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [0]*(K+1)
dp[0] = 1
for a in A:
    dp2 = [0]*(K+1)
    for i in range(K+1):
        dp2[i] += dp[i]
        if i + a + 1 <= K:
            dp2[i+a+1] -= dp[i]
    for i in range(1, K+1):
        dp2[i] = (dp2[i-1] + dp2[i]) % mod
    dp = dp2[:]
print(dp[-1])

Measured memory_bytes: 86036
n = int(input())
a = list(map(int, input().split()))
import math
sunuke = 0
kuma = sum(a)

memo = abs(2*a[0] - sum(a))
ans = abs(2*a[0] - sum(a))

for i in range(n):
    sunuke += a[i]
    kuma -= a[i]
    if abs(sunuke-kuma) > memo:
        ans = memo
    else:
        memo = abs(sunuke-kuma)

print(ans)
    

Measured memory_bytes: 30716
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	int rect = 0;
	int rhombus = 0;
	
	while ( stdin.hasNextLine() ) {
	    final String[] input = stdin.nextLine().split(",");
	    int w = Integer.parseInt(input[0]);
	    int h = Integer.parseInt(input[1]);
	    int d = Integer.parseInt(input[2]);


	    if ( w * w + h * h == d * d ) {
		rect++;
	    } else if ( w == h ) {
		rhombus++;
	    }
	}

	System.out.println(rect);
	System.out.println(rhombus);
	
    }
    
}

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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

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

const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;

	vector<ll> a(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];

	vector<ll> pre(n), suf(n);

	pre[0] = a[0];
	suf[n-1] = a[n-1];

	for(int i = 1; i < n; i++)
		pre[i] = pre[i-1] + a[i];

	for(int i = n-2; i >= 0; i--)
		suf[i] = suf[i+1] + a[i];

	ll ans = LLONG_MAX;

	for(int i = 1; i < n; i++)
		ans = min(ans, abs(suf[i]-pre[i-1]));

	cout << ans << endl;
	return 0;	
}

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

int main() {
	int n;
	int min = 9999;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int temp, count;
		count = 0;
		cin >> temp;
		while (temp % 2 == 0) {
			temp /= 2;
			count++;
		}
		if (count < min)min = count;
	}

	cout << min;
}

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

using namespace std;

struct StronglyConnectedComponents
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};

int main()
{
  int V, E, Q;
  cin >> V >> E;
  StronglyConnectedComponents g(V);
  while(E--) {
    int x, y;
    cin >> x >> y;
    g.add_edge(x, y);
  }

  vector< vector< int > > dag;
  g.build(dag);

  cin >> Q;
  while(Q--) {
    int x, y;
    cin >> x >> y;
    cout << (g[x] == g[y]) << endl;
  }
}

Measured memory_bytes: 4720
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int k = Integer.parseInt(input[1]);
        int ans = k;
        
        for(int i = 0; i < n - 1; i++){
            ans *= k - 1;
        }
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 32540
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,e,k,i,j,p[5];
  for(i=0;i<5;i++)cin>>p[i];cin>>k;
  for(i=0;i<4;i++)for(j=i+1;j<5;j++)if(abs(p[j]-p[i])>k){cout<<":(";return 0;}
                     cout<<"Yay!";}
                     


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>l(N);
  for(int i=0;i<N;i++){
    cin>>l.at(i);
  }
  
  sort(l.begin(),l.end());
  
  int sum=0;
  
  for(int i=N-1;i>=N-K;i--){
    sum+=l.at(i);
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main(){
 int N;
 cin>>N;
 for(int i = 0;i <= 9;++i){
 	for(int ii = 0;ii <=9;++ii){
		if(ii * i == N){
			cout<<"Yes\n";
			return 0;
		}
	}
 }

	 cout<<"No\n";
 
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int mod=1e9+7;
LL dp[3005][3005][2];
int main(){ 
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0;i<=n;i++){
        if(i!=0)
        dp[0][i][0]=1;
        else
        dp[0][i][1]=1;
    }
    for(int i= 0;i<m;i++){
        for(int j = 0;j<=n;j++){
            dp[i][j][0]%=mod;
            dp[i][j][1]%=mod;
            if(j!=0){
                dp[i+1][j][j==1]+=dp[i][j][0];
                dp[i+1][j][1]+=dp[i][j][1];
                dp[i+1][j-1][j==1]+=dp[i][j][0];
                dp[i+1][j-1][1]+=dp[i][j][1];
            }
            if(j!=n){
                dp[i+1][j][0]+=dp[i][j][0];
                dp[i+1][j][1]+=dp[i][j][1];
                dp[i+1][j+1][0]+=dp[i][j][0];
                dp[i+1][j+1][1]+=dp[i][j][1];
            }
        }
    }
    LL ans=0;
    for(int j=0;j<=n;j++){
    //    printf("%d\n",dp[m][j][1]);
        ans+=dp[m][j][1];
    }
    printf("%lld\n",ans%mod);
}
/*
1 2 2 3 3 3 4
2 2 1
3 2 3
4 2 4 4 7
 
1 1
*/

Measured memory_bytes: 141184
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    # tmp = 1
    # for i in range(K):
    #     tmp *= A[i]
    # print(tmp)

    for i in range(K,N):
        # n = tmp * A[i] / A[i-K]
        n = A[i]/A[i-K]
        if n > 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
typedef pair <int, int> pp;
#define MAXN 500005
#define MP make_pair
#define PB push_back
#define A first
#define B second
const ll INF = 2e9;
const ll MOD = 1e9+7;
int ar[MAXN];
int p1[MAXN], p2[MAXN];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	string s;
	cin >> s;
	for(int i=1; i<=N; i++) {
		if(s[i-1] == 'W') ar[i] = 2;
		else ar[i] = 1;
	}
	for(int i=1; i<=N; i++) {
		p1[i] = p1[i-1] + (ar[i] == 1);
		p2[i] = p2[i-1] + (ar[i] == 2);
	}
	int ans = N-1;
	for(int i=1; i<=N; i++) {
		ans = min(ans, p2[i-1] + p1[N] - p1[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5012
#include <stdio.h>


int main()
{
	int i, j, temp;
	int arr[3] = { 1,0,0 };
	char ch1, ch2;

	while (scanf("%c,%c", &ch1, &ch2) != EOF)
	{
		switch (ch1)
		{
		case 'A':i = 0; break;
		case 'B':i = 1; break;
		case 'C':i = 2; break;
		default:break;
		}
		switch (ch2)
		{
		case 'A':j = 0; break;
		case 'B':j = 1; break;
		case 'C':j = 2; break;
		default:break;
		}


		temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;

		i = j = ch1 = ch2 = 0;
	}

	if (arr[0])
	{
		printf("A\n");
	}
	else if (arr[1])
	{
		printf("B\n");
	}
	else
	{
		printf("C\n");
	}

	return 0;
}


Measured memory_bytes: 524
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int m;
    while(cin>>m&&m){
        map<pair<int,int>,bool> mp; //pairの座標に点があるかどうか
        vector<pair<int,int>> a(m); //星座の構成点の座標
        rep(i,0,m)cin>>a[i].fi>>a[i].se;
        int n; cin>>n;
        vector<pair<int,int>> b(n); //フィールドに存在する全ての点の座標
        rep(i,0,n){
            cin>>b[i].fi>>b[i].se;
            mp[pair<int,int>(b[i].fi,b[i].se)]=true;
        }

        rep(i,0,n){
            //存在する全ての点を全探索し、まずは星座を構成する一つの点に対する移動距離をdに保存。
            pair<int,int> d=make_pair(b[i].fi-a[0].fi,b[i].se-a[0].se);
            bool ok=true;
            rep(j,0,m){ //星座の構成要素を全探索し、移動量dを加えた先に点が存在するかどうかを確認。１つでも無ければok=false
                pair<int,int> p=make_pair(a[j].fi+d.fi,a[j].se+d.se);
                if(!mp[p])ok=false;
            }
            //okがtrueのまま降りてこれば、dを出力して終了
            if(ok){
                cout<<d.fi<<" "<<d.se<<endl;
                break;
            }
        }
    }

    
}


/*
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0
*/



Measured memory_bytes: 10904
w, h, n = map(int,input().split())

xl, xr = 0, w
yl, yu = 0, h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xr = min(xr, x)
    elif a == 3:
        yl = max(yl, y)
    else:
        yu = min(yu, y)
        
print((xr-xl)*(yu-yl)) if xl < xr and yl < yu else print(0)

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

int selectionSort(int A[], int N) {
	int n = 0;
	int minj;
	for (int i = 0; i < N; i++) {
		minj = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		if ( i != minj ) n++;
		swap(A[i], A[minj]);
	}
	return n;
}

int main() {
	int A[100];
	int N;

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

	int n = selectionSort(A, N);
	
	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}

	cout << endl;
	cout << n << endl;

	return	0;
}

Measured memory_bytes: 3108
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

int main() {
        long long k;
        cin >> k;


        long long syou = k / 50;
        long long amari = k % 50;

        long long init = syou + 49;

        long long minx = init - amari;
        long long maxx = init - amari + 51;

        vector<long long> ans(50);
        rep(i, 0, 50-amari) {
            ans[i] = minx;
        }

        rep(i, 50 - amari, 50) {
            ans[i] = maxx;
        }


        cout << 50 << endl;
        rep(i, 0, 50) {
            cout << (i == 0 ? "" : " ") << ans[i];
        }
        cout << endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (!(i & 1) && a & 1) sum++;
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    if (data.back() != 2) {cout << -1 << endl; return 0; }
    int yui = 2;
    for (int i = n-2; i >= 0; i--) {
        yui = ((yui / data[i]) + !!(yui % data[i])) * data[i];
    }
    rep(i, n) {
        yui -= yui % data[i];
    }
    if (yui != 2) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 2;
    for (int i = n-2; i >= 0; i--) {
        int tmp = (ans / data[i]) + !!(ans % data[i]);
        ans = data[i] * tmp;
    }
    int num = 4;
    for (int i = n-2; i >= 0; i--) {
        //cout << num << endl;
        /*
        if (num <= data[i]) {
            cout << -1 << endl;
            return 0;
        } else {
        */
            int tmp = num / data[i] + !!(num % data[i]);
            num = (data[i] * tmp);
        //}
    }
    cout << ans << " " << num-1 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(A.begin(), A.end(), greater<int>());
  ll ans = 0, cnt = 0;
  ans += A[0];  // 1,2回目
  for (int i = 1; i < N; i++) {
    if (N - 2 <= cnt) break;
    if (cnt + 4 <= N) {
      ans += A[i] * 2;
    } else {
      ans += A[i];
    }
    cnt += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
vg arr;
ll n;
vg dp;
ll func(ll ind,ll act) {
	if(dp[ind][act]!=-1)
		return dp[ind][act];
	if(ind == n - 1)
		return arr[ind][act];
	ll i;
	ll res = -1;
	for(int i = 0; i < 3; i++) {
		if(i == act)
			continue;
		res = max(res,arr[ind][act] + func(ind + 1,i));
	}
	return dp[ind][act] = res;
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	ll i,j;
	arr.assign(n,vector<ll>(3,0));
	dp.assign(n,vector<ll>(3,-1));
	for(i = 0 ; i < n ; i ++) {
		for(j = 0 ; j < 3 ; j++)
			cin >> arr[i][j];
	}
	ll res = -1;
	for(i = 0 ; i < 3 ; i++) {
		res = max(res,func(0,i));
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 19072
X, Y = gets.split.map(&:to_i)

ans = (X.abs - Y.abs).abs

if X * Y < 0
  ans += 1
elsif X == 0
  ans += Y < 0 ? 1 : 0
elsif Y == 0
  ans += X < 0 ? 0 : 1
elsif X >= 0 && Y >= 0 && Y < X
  ans += 2
elsif X <= 0 && Y <= 0 && X > Y
  ans += 2
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

string s;
int d;
int dp[10010][110][2];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> d;
    int n = s.size();
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            for(int k = 0; k < 10; k++){
                (dp[i + 1][(j + k) % d][1] += dp[i][j][1]) %= mod;
                if(s[i] -'0' == k) (dp[i + 1][(j + k) % d][0] += dp[i][j][0]) %= mod;
                else if(s[i] - '0' > k) (dp[i + 1][(j + k) % d][1] += dp[i][j][0]) %= mod;
            }
        }
    }
    cout << (dp[n][0][0] + dp[n][0][1] - 1 + mod) % mod << endl;
}

Measured memory_bytes: 17408
using System;
class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            string[] data = Console.ReadLine().Split(' ');
            int m = int.Parse(data[0]);
            int f = int.Parse(data[1]);
            int r = int.Parse(data[2]);
            if (m == -1 && f == -1 && r == -1)
            {
                return;
            }
            if (m == -1 || f == -1)
            {
                Console.WriteLine("F");
                continue;
            }
            int mf = m + f;
            if (79 < mf)
            {
                Console.WriteLine("A");
            }
            else if (64 < mf)
            {
                Console.WriteLine("B");
            }
            else if (49 < mf)
            {
                Console.WriteLine("C");
            }
            else if (29 < mf)
            {
                if (49 < r)
                {
                    Console.WriteLine("C");
                }
                else
                {
                    Console.WriteLine("D");
                }
            }
            else
            {
                Console.WriteLine("F");
            }
        }
    }
}

Measured memory_bytes: 5296
X = int(input())
limit = int(X ** 0.5)
ans = -1
prob_ans = []

if X == 1:
    ans = 1
for i in range(2, limit+1):
    p = 2
    while True:
        tmp = i ** p
        if tmp > X:
            break
        ans = max(ans, tmp)
        p += 1

print(ans)


Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AXORCircle solver = new AXORCircle();
        solver.solve(1, in, out);
        out.close();
    }

    static class AXORCircle {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int[] ar = new int[n];
            for (int i = 0; i < n; i++) ar[i] = in.scanInt();
            int xor = 0;
            for (int i = 0; i < n; i++) xor ^= ar[i];
            if (xor == 0) out.println("Yes");
            else out.println("No");
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

int main() {
  int n,m;cin >> n >> m;
  vector<int> a(n);
  int sum=0;
  rep(i,n){cin >> a[i];sum+=a[i];}
  int ans=0;
  rep(i,n){
    if(4*m*a[i]-sum>=0)ans++;
  }
  cout<<(ans>=m?"Yes":"No")<<endl;
}

Measured memory_bytes: 256