akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 200006;
int n, m;
vector<string> mat;
bool visited[111][111];
bool del(){
    for(int i = 0; i < (int)mat.size(); i ++){
        bool ok = false;
        for(int j = 0; j < (int)mat[0].size(); j ++){
            if(visited[i][j])continue;
            if(mat[i][j] != '.'){
                ok = false;
                break;
            }
            ok = true;
        }
        if(ok){
            for(int j = 0; j < (int)mat[0].size(); j ++){
                visited[i][j] = true;
            }
            return true;
        }
    }
    return false;
}
bool del2(){
    for(int j = 0; j < (int)mat[0].size(); j ++){
        bool ok = false;
        for(int i = 0; i < (int)mat.size(); i ++){
            if(visited[i][j])continue;
            if(mat[i][j] != '.'){
                ok = false;
                break;
            }
            ok = true;
        }
        if(ok){
            for(int i = 0; i < (int)mat.size(); i ++){
                visited[i][j] = true;
            }
            return true;
        }
    }
    return false;
    
}
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i < n; i ++){
        string s;
        cin >> s;
        mat.push_back(s);
    }
    memset(visited, false, sizeof visited);
    while(true){
        if(!del() and !del2()){
            break;
        }
      
    }
    vector<string> ret;
    for(int i = 0; i < n; i ++){
        string tmp = "";
        for(int j = 0; j < m; j ++){
            if(visited[i][j])continue;
            tmp += mat[i][j];
        }
        if(tmp != "")
            ret.push_back(tmp);
    }
    cout << endl;
    for(int i = 0; i < (int)ret.size(); i ++){
        for(int j = 0; j < (int)ret[0].size(); j ++){
            cout << ret[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if ((A * B) > C) {

			System.out.println(C);

		} else {

			System.out.println(A * B);

		}
	}
}


Measured memory_bytes: 21716
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        String as = Integer.toString(a);
        String bs = Integer.toString(b);
        StringBuilder str = new StringBuilder(b);
        for(int i =0;i<b;i++){
            str.append(as);
        }
        as = str.toString();   
        str = new StringBuilder("");
        for(int i=0;i<a;i++){
            str.append(bs);
        }
        bs = str.toString();
        System.out.println(as.compareTo(bs)<0?as:bs);
        s.close();
    }
}

Measured memory_bytes: 22868
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long[] c = new long[m];
        long[] d = new long[m];
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            long min = Long.MAX_VALUE;
            for (int j = 0; j < m; j++) {
                if (min > Math.abs(c[j] - a[i]) + Math.abs(d[j] - b[i])) {
                    min = Math.abs(c[j] - a[i]) + Math.abs(d[j] - b[i]);
                    ans[i] = j + 1;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int sum = 0;
    int N;
    vector<long long> A;
    cin >> N;
    A.resize(N);
    for( int i = 0; i < N; i++ ) {
        long long a;
        cin >> a;
        
        if ( a%4 == 0 ) { A[i] = 2;}
        else if ( a%2 == 0 ) { A[i] = 1;}
        else { A[i] = 0; }
    }
    
    for( int i = 0; i < N; i++ ) {
        sum += A[i];
    }
    
    bool ans;
    if ( N%2 == 0 ) { ans = sum >= N; }
    else { ans = sum >= N-1; }
    
    cout << (ans ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 1152
import itertools
N,M,Q = map(int,input().split())
X = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    X.append([a,b,c,d])
Y = [i for i in range(1,M+1)]
Z = list(itertools.combinations_with_replacement(Y,N))
#print(Z)
ans = 0
for z in Z:
    #print(z)
    tmp = 0
    for x in X:
        #print(x)
        if z[x[1]-1] - z[x[0]-1] == x[2]:
            tmp += x[3]
    #print(tmp)
    if tmp > ans:
        ans = tmp
print(ans)


Measured memory_bytes: 21540
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
 
// replace ll with pair if multiset needed
typedef tree<pair<int,int>, null_type, greater<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;
 
const ll INF = 1e9 + 9;
const ll MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<int> gen(0,n-1);

const int SIZE = 1e3 + 6;

long long dp[SIZE][SIZE];
long long tab[SIZE][SIZE];

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

	int n,m; cin >> n >> m;	

	for(int i = 0; i < n; i++){
		string s; cin >> s;	
		for(int j = 0; j < m; j++)
			tab[i][j] = s[j];
	}

	dp[0][0] = 1;
	for(int i = 1; i < n; i++) if(tab[i][0] != '#') dp[i][0] = dp[i-1][0];

	for(int i = 1; i < m; i++) if(tab[0][i] != '#') dp[0][i] = dp[0][i-1];

	for(int i = 1; i < n; i++){
		for(int j = 1; j < m; j++){
			if(tab[i][j] != '#'){
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % (ll)(1e9 + 7);
			}
		}
	}

	cout << dp[n-1][m-1];



}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

void add() {

}

void solve(long long N, long long K, std::vector<long long> A) {
    auto f = [A, K](long long D) {
        deque<long long> B(A.begin(), A.end());
        long long sm = 0;
        for (int i = 0; i < A.size(); i++) {
            B[i] %= D;
        }
        sort(B.begin(), B.end());
        ll tot = 0;
        while (B.size()) {
            if (B.front() == 0) {
                B.pop_front();
                continue;
            }
            if (B.back() == 0) {
                B.pop_back();
                continue;
            }
            if (B.size() == 1) return false;

            long long w = min(B.front(), D - B.back());
            B.front() -= w;
            B.back() += w;
            tot += w;
            B.back() %= D;
        }
        return tot <= K;
    };

    ll sum = 0;
    for (int i = 0; i < A.size(); i++)
        sum += A[i];

    vector<ll> v;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            v.push_back(sum / i);
            v.push_back(i);
        }
    }
    ll ans = 0;
    for (auto i : v) {
        if (f(i)) {
            ans = max(ans, i);
        }
    }
    cout << ans << endl;

}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


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 rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s[i]-'A'+n<=25)s[i]=s[i]+n;
        else s[i]='A'+n-(26-(s[i]-'A'));
    }
    cout<<s<<endl;
}

int main(){
    cout<<std::fixed<<std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define P           pair<int, int>
#define dint        long double

const int N = 1e5+5;
vector<int> g[N];
int h[N];
int bad[N];

void solve() {
    int n, m; cin >> n >> m;
    for(int i=1; i<=n; i++) cin >> h[i];
    for(int i=0; i<m; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v); g[v].push_back(u);
    }
    int ans = 0;
    for(int i=1; i<=n; i++) {
        if(bad[i] == 1) continue;
        bool ok = 1;
        for(int v : g[i]) {
            if(h[v] < h[i]) {
                bad[v] = 1;
            } else {
                ok = 0; break;
            }
        }
        ans += ok;
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}



Measured memory_bytes: 11004
n=int(input())
a=list(map(int,input().split()))
d=[0 for i in range(n+1)]
ans=[0 for i in range(n+1)]
for i in range(n,0,-1):
  c=0
  for j in range(i*2,n+1,i):
    c+=ans[j]
  if (c%2)^a[i-1]:
    ans[i]=1

r=""
c=0
for i in range(1,n+1):
  if ans[i]:
    c+=1
    r+=str(i)+" "
print(c)
print(r[:-1])
  


Measured memory_bytes: 15616
#include <stdio.h>

int main()
{
  int x, y, z, r, gcd;

  scanf("%d%d", &x, &y);

  if(x < y){
    z = x;
    x = y;
    y = z;
  }
  while( y > 0 ){
    r = x % y;
    x = y;
    y = r;
  }

  printf("%d\n", x);
  
  return 0;
}
  

Measured memory_bytes: 592
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Bits
import Data.List
import qualified  Data.ByteString as B
import Data.Ord


bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt

bsToIntList :: BS.ByteString -> [Int]
bsToIntList = map bsToInt . BS.words


main :: IO ()
main = do 
    n:k:_ <- bsToIntList <$> BS.getLine
    let t1 = [i*(n+1-i)+1 | i<-[k..n+1]]
    print $ (sum t1 `mod` (10^9 + 7))


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

int main(void) {
	int H,W,i,x,y;
	int walk[100][100];
	char map[100][101];
	
	while(scanf("%d %d",&H,&W)){
		if(!(H+W)) break;
		for(i = 0;i < H;i++){
			scanf("%s",map[i]);
		}
		memset(walk,0,sizeof(walk));
		
		x = 0;
		y = 0;
		while(1){
			walk[y][x] = 1;
			if(map[y][x] == '.'){
				printf("%d %d\n",x,y);
				break;
			}else{
				switch(map[y][x]){
					case '>':
						x++;
						break;
					case '<':
						x--;
						break;
					case '^':
						y--;
						break;
					case 'v':
						y++;
						break;
				}
				if(walk[y][x]){
					printf("LOOP\n");
					break;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 672
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

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


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#define sf(n) scanf("%d",&n);
#define sfl(n) scanf("%lld",&n);
#define pf(n) printf("%d",n);
#define pfl(n) printf("%lld",n);
#define pr printf("\n");
#define LL long long
using namespace std;

const LL maxn=2*1e5+5;
LL num[maxn];
LL sum[maxn];

int main(){
    LL n;
    scanf("%lld",&n);
    for(LL i=0;i<n;i++)
        scanf("%lld",&num[i]);

    sum[0]=num[0];

    for(LL i=1;i<n;i++){
        sum[i]+= (sum[i-1]+num[i]);
    }
    LL x,y;
    LL Min=1e18;

    for(LL i=0;i<n-1;i++){
        x=sum[i];
        y=sum[n-1]-sum[i];
        Min=min(Min,abs(x-y));
    }
    printf("%lld\n",Min);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void process(vector<int> &dp) {
    int N;
    cin >> N;
    while(N--) {
        string s;
        int v;
        cin >> s >> v;
        if(s == "D" || s == "DD") {
            const int cost = s.size();
            for(int i = (int)dp.size() - 1; i >= cost; --i) {
                if(dp[i-cost] != -1) {
                    dp[i] = max(dp[i], dp[i-cost] + v);
                }
            }
        }
    }
}

bool solve() {
    int D;
    if(!(cin >> D)) return false;

    vector<int> dp(D+1, -1);
    dp[0] = 0;
    process(dp);
    process(dp);
    cout << *max_element(begin(dp), end(dp)) << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <math.h>

int main () {
    int tmp, cnt = 0;

    int s;
    scanf("%d", &s);

    for (int i = 2; 0 <= i; i--) {
        tmp = s / pow(10, i);
        cnt += tmp;
        s -= tmp * pow(10, i);
    }

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

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }
    else{
        int a,b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}


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


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

    ll W, H;
    cin >> W >> H;
    ll P[W], Q[H];
    for(ll i=0; i<W; i++){
      cin >> P[i];
    }
    for(ll i=0; i<H; i++){
      cin >> Q[i];
    }
    sort(P, P+W);
    sort(Q, Q+H);
    ll w = 0, h = 0;
    ll p = 0, q = 0;
    ll nokori = (W+1)*(H+1);
    ll cost = 0;
    while(nokori >= 2){
      if(p >= W){
        cost += Q[q]*(W+1-w);
        nokori -= (W+1-w);
        h++;
        q++;
      }else if(q >= H){
        cost += P[p]*(H+1-h);
        nokori -= (H+1-h);
        w++;
        p++;
      }else if(Q[q] < P[p]){
        cost += Q[q]*(W+1-w);
        nokori -= (W+1-w);
        h++;
        q++;
      }else if(P[p] < Q[q]){
        cost += P[p]*(H+1-h);
        nokori -= (H+1-h);
        w++;
        p++;
      }else if(P[p] == Q[q]){
        if((W+1-w) > (H+1-h)){
          cost += Q[q]*(W+1-w);
          nokori -= (W+1-w);
          h++;
          q++;
        }else{
          cost += P[p]*(H+1-h);
          nokori -= (H+1-h);
          w++;
          p++;
        }
      }else{
        exit(-1);
      }
      //cout << cost << " " << nokori << " " << w << " " << h << endl;
    }
    cout << cost << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    double mi = 999999999999999.0 / 135;
    ll ten = 1e10;
    vector<ll> ans;
    rep(loop, 8){
        ll tmp = 100000;
        while(tmp > 10000){
            ll x = tmp * ten - 1;
            ll cnt = 0;
            ll xx = x;
            rep(j,20){
                cnt += xx % 10;
                xx /= 10;
            }
            if((double)x / cnt <= mi){
                ans.push_back(x);
                mi = (double)x / cnt;
            }
            tmp--;
        }
        ten /= 10;
    }

    drep(i,10000000){
        if(i == 0)break;
        ll x = i;
        ll cnt = 0;
        ll xx = x;
        rep(j,20){
            cnt += xx % 10;
            xx /= 10;
        }
        if((double)x / cnt <= mi){
            ans.push_back(x);
            mi = (double)x / cnt;
        }
    }
    reverse(ans.begin(), ans.end());
    rep(i,n)cout << ans[i] << endl;
    return 0;
}
 
 


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

using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}

	int length = 1;
	int L[n];
	L[0] = A[0];
	for (int i = 1; i < n; ++i) {
		if (A[i] > L[length - 1]) {
			L[length] = A[i];
			++length;
		} else {
			int left = 0;
			int right = length;
			while (left < right) {
				int mid = (left + right) / 2;
				if (L[mid] >= A[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
			}
			L[right] = A[i];
		}
	}

	cout << length << endl;

	return 0;
}

Measured memory_bytes: 3908
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll power(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n%2) res=(res*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return res;
}
ll inv(ll x)
{
    return power(x,mod-2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    sort(v.begin(),v.end());
    ll fact[100005];
    fact[0]=1;
    for(ll i=1;i<100005;i++) fact[i]=(fact[i-1]*i)%mod;
    ll dp[n+1];
    dp[k-2]=1;
    for(ll i=k-1;i<=(n-2);i++)
    {
        dp[i]=((fact[i]*inv(fact[k-2]))%mod*inv(fact[i-(k-2)]))%mod;
    }
    //for(int i=0;i<n;i++) cout<<dp[i]<<" ";
    for(ll i=k-1;i<=n-2;i++)
        dp[i]=(dp[i-1]+dp[i])%mod;
    ll ans=0;
    ll x=n-2;
    for(int i=n-1;i>=0;i--)
        {   if(x==k-3) break;
            ans=(ans+(v[i]*dp[x--])%mod)%mod;}
    //cout<<ans<<" ";
    x=n-2;
    for(int i=0;;i++){
            if(x==k-3) break;
        ans=(ans-(v[i]*dp[x--])%mod+mod)%mod;}
    cout<<ans;

}


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

using namespace std;
using ll = long long;


int main()
{
    int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;
    int k; cin >> k;
    cout << (h2 * 60 + m2) - (h1 * 60 + m1) - k << endl; 
}

Measured memory_bytes: 3676
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,j,N,M,f=0,ans=0;
  cin>>N>>M;
  vec v(N),cnt(40,0);
  rep(i,N){
    cin>>v[i];
    rep(j,40){
      if(v[i]&1LL<<j){
        cnt[j]++;
      }
    }
  }
  brep(i,40){
    if(f||(M&1LL<<i)){
      if(cnt[i]*2<N){
        cnt[i]=N-cnt[i];
      }else{
        f=1;
      }
    }
    ans+=cnt[i]<<i;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))

    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a

    def union(self, a, b):
        self.parent[self.find(b)] = self.find(a)

n, m = map(int, input().split())
UF = UnionFind(n)
for _ in range(m):
    a,b = map(int, input().split())
    UF.union(a-1,b-1)
o=set()
for i in range(n):
    o.add(UF.find(i))
print(len(o) - 1)

Measured memory_bytes: 79212
#include<iostream>
#include<stack>

int main()
{
	std::stack<int> s;
	int x;
	while( std::cin >> x ){
	 	if( x ) s.push( x );
		else{
		 	std::cout << s.top() << std::endl;
			s.pop();
		}
	}

 	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#include<queue>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define FOR(i,a,b) for(int i = (a);i < (b);++i)
typedef long long ll;
int main(){
    
    int counts = 0;
    int countr = 0;
  	char S[100];
    int N; cin >> N;
  	for(int i = 0;i < N;i++){
          cin >> S[i];
      if(S[i] == 'R'){
          countr++;
      }else{
          counts++;
      }
    }
  if(countr > counts) cout << "Yes" << endl;
  else cout << "No"<< endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int flag1 = 0, flag2 = 0;

		for(int i=0; i<s.length(); i++){
			if(s.charAt(i)=='C') flag1 = 1;
			if(s.charAt(i)=='F' && flag1==1) flag2 = 1;
		}

		System.out.println((flag2==0)?"No":"Yes");
	}
}

Measured memory_bytes: 10064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n; ll k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];

  vi s;
  vi ord(n+1, -1);
  int c = 1, l = 0;
  {
    int v = 1;
    while (ord[v] == -1) {
      ord[v] = s.size();
      s.push_back(v);
      v = a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];
  }
  if (k < l) cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[k+l] << endl;
  }
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ps[n + 1];
    ps[0] = 0;
    ll tmp2 = 0;
    rep(i, n){
        int tmp1;
        cin >> tmp1;
        tmp2 += tmp1;
        ps[i+1] = tmp2;
    }
    double tmp3 = 0;
    rep(i, n - k + 1){
        tmp3 = max(tmp3, double(ps[i+k] - ps[i]));
    }
    cout << fixed << setprecision(10) << (tmp3 + double(k)) / 2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
P dp[101][50001];

void Max(P &a,P b){a=max(a,b);}

int main(){
  int n,p[101];
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>p[i];
    
    memset(dp,-1,sizeof(dp));
    dp[0][0]=P(0,0);
  
    for(int i=0;i<n;i++)
      for(int j=0;j<50000;j++){
	if(dp[i][j]==P(-1,-1))continue;
	int coin=dp[i][j].first, ncost=dp[i][j].second-p[i];
	Max(dp[i+1][j],dp[i][j]);
	if(p[i]%1000<500&&p[i]%1000)Max(dp[i+1][j+(500-p[i]%500)],P(coin+1,ncost));
	if(p[i]%1000==0&&j>=500) Max(dp[i+1][j-500],P(coin+1,ncost));
	
	if(p[i]%1000>=500) {
	  if(j>=p[i]%500)Max(dp[i+1][j-p[i]%500],P(coin+1,ncost));
	  else Max(dp[i+1][j+(500-p[i]%500)],P(coin,ncost));
	}
      }
    
    P ans=P(0,0);
    for(int i=0;i<50000;i++)Max(ans,dp[n][i]);
    cout <<ans.first<<" "<<-ans.second<<endl;
    
  }	
  return 0;
}

Measured memory_bytes: 42500
#include <bits/stdc++.h>
using namespace std;
const int N=201000;
char str[N],str2[N];
int n,cnt1[N],cnt2[N],used[30];
int main(){
	int i,j;
	memset(cnt1,0,sizeof(cnt1));memset(used,0,sizeof(used));
	scanf("%s",str);scanf("%s",str2);
	int len=strlen(str);
	for (i=0;i<len;++i) ++used[str[i]-'a'];
	for (i=0;i<26;i++) cnt1[used[i]]++;
	memset(used,0,sizeof(used));memset(cnt2,0,sizeof(cnt2));
	for (i=0;i<len;++i) ++used[str2[i]-'a'];
	for (i=0;i<26;i++) cnt2[used[i]]++;
	for (i=0;i<=len;++i) if (cnt1[i]!=cnt2[i]) {puts("No");return 0;}
	puts("Yes");
	return 0;
}

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

using namespace std;

template <class T>
using lim = numeric_limits<T>;

typedef long long ll;
typedef long double ld;

const int maxN = 10e5;

struct Attack{
	int a;
	int b;
	
	Attack(){
		a = 0;
		b = 0;
	}
	
	Attack(int myA, int myB){
		a = myA;
		b = myB;
	}
	
	bool operator<(const Attack& other)const{
		return b > other.b;
	}
};

Attack damage[maxN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, h; cin >> n >> h;
	
	int bigA = 0;
	for (int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		damage[i] = Attack(a,b);
		
		if (a > bigA){
			bigA = a;
		}
	}
	
	sort(damage, damage+n);
	
	int counter = 0;
	for (int i = 0; i < n; i++){
		int toMinus = damage[i].b;
		if (toMinus < bigA) break;
		if (h - toMinus > 0){
			h -= toMinus;
			counter++;
		}
		else{
			h -= toMinus;
			counter++;
			cout << counter << endl;
			return 0;
		}
	}

	counter += h/bigA + (h%bigA!=0);
	
	cout << counter << endl;
}


Measured memory_bytes: 8064
M,D=map(int,input().split())
ans=0
for i in range(1,M+1):
  for j in range(22,D+1):
    j=str(j)
    j1=int(j[0])
    j2=int(j[1])
    if i==j1*j2 and j2>=2:
      ans+=1
print(ans)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
#define N 100100

int a[N][3];
int dp[N][3];

int main(){
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(int i = 1;i<=n;i++)
    {
        for(int j = 0;j<=2;j++)
        {
            for(int k = 0;k<=2;k++)
            {
                if(j!=k)
                {
                    dp[i][k] =max(dp[i][k],dp[i-1][j]+a[i][k]);
                    //dp[i][k]=max(dp[i][k],x);
                }
            }
        }
    }
    int u=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<u<<endl;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return (ret);
}

int main() {
  int N;
  cin >> N;
  map< int, int > mp;
  for(int i = 2; i <= N; i++) {
    auto p = prime_factor(i);
    for(auto &v : p) mp[v.first] += v.second;
  }
  int64 mul = 1;
  for(auto &p : mp) (mul *= p.second + 1) %= mod;
  cout << mul << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

    private static final double TAX = 1.05;

    /**
     * <p> [機能] n を入力したとき、n 週間後の借金の残高を出力し終了するプログラム。n は 100 以下。</p>
     * <p> [説明] 特になし。</p>
     * <p> [備考] 特になし。</p>
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        String week = new BufferedReader(new InputStreamReader(System.in)).readLine();

        int totalAmount = 100000;
        int i = Integer.parseInt(week);
        // 入力された数値分返済額を増額する。
        for (int count = 0; count < i; count++) {
            totalAmount = new BigDecimal(totalAmount * TAX).setScale(-3, BigDecimal.ROUND_UP).intValue();
        }
        // 返済額を出力する。
        System.out.println(totalAmount);
    }
}

Measured memory_bytes: 15136
n=int(input())
abc=[[int(i) for i in input().split()] for j in range(n)] 
dp=[[abc[0][0],abc[0][1],abc[0][2]],[abc[0][0],abc[0][1],abc[0][2]]]

for i in range(1,n):
    for j in range(3):
        for k in range(3):
            if j!=k:
                dp[1][k]=max(dp[1][k] ,dp[0][j]+abc[i][k])
    dp[0][0]=dp[1][0]
    dp[0][1]=dp[1][1]
    dp[0][2]=dp[1][2]
print(max(dp[1]))

Measured memory_bytes: 24308
#include<bits/stdc++.h>
using namespace std;
priority_queue<int>q;
int n,m,ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		q.push(x);
	}
	for(int i=1;i<=m;i++)
	{
		ans+=q.top();
		q.pop();
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

char getop(char s) {
    if (s == '0') return '1';
    else return '0';
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        string s = ins();
        ll ans = 0;
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == s[i + 1] && s[i] == s[i + 2]) {
                s[i + 1] = getop(s[i + 1]);
                ans++;
            }
            else if (s[i] == s[i + 1]) {
                s[i + 1] = getop(s[i + 1]);
                ans++;
            }
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
digit = ['']*N
flag = True
for _ in range(M):
    s, c = map(int, input().split())
    s-=1
    if digit[s] == '':
        digit[s] = str(c)
        continue
    elif digit[s] != str(c):
        flag = False
        break
if digit[0] == '0' and N>=2:
    flag = False
if not flag:
    print(-1)
else:
    if digit[0] == '':
        if N>=2:
            digit[0] = '1'
        else:
            digit[0] = '0'
    for i in range(1, N):
        if digit[i]== '':
            digit[i] = '0'
    print(int(''.join(digit)))


Measured memory_bytes: 38324
#!/usr/bin/env python3
import sys
from functools import reduce
import numpy as np
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, a: "List[int]"):

    def gcd_base(a: int, b: int):
        while b:
            a, b = b, a%b
        return a

    def gcd(*numbers):
        return reduce(gcd_base, numbers)
    
    def lcm_base(a: int, b:int):
        return a*b // gcd_base(a,b)

    def lcm(*numbers):
        return reduce(lcm_base, numbers, 1)

    def div_of_2(x: int):
        c = 0
        while x%2 == 0:
            c += 1
            x /= 2
        return c

    x = lcm(*a)
    t = x // 2
    y = div_of_2(a[0])

    if t > M or any([y != div_of_2(i) for i in a]):
        print(0)
        exit()

    ans = 1
    ans += (M-t)//x
    
    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

ll dp[10010][110][2]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string k;cin>>k;
  ll d;cin>>d;

  dp[0][0][0]=1;
  rep(i,0,siz(k)){
    rep(j,0,d){
      rep(l,0,10){
        if(l+'0'<k[i]){
          (dp[i+1][(j+l)%d][1]+=dp[i][j][0]+dp[i][j][1])%=mod;
        }else if(k[i]<l+'0'){
          (dp[i+1][(j+l)%d][1]+=dp[i][j][1])%=mod;
        }else{
          (dp[i+1][(j+l)%d][0]+=dp[i][j][0])%=mod;
          (dp[i+1][(j+l)%d][1]+=dp[i][j][1])%=mod;
        }
      }
    }
  }
  cout<<(dp[siz(k)][0][0]+dp[siz(k)][0][1]+mod-1)%mod<<ENDL;//except zero
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> a(n);

  rep(i,n){
    if(s[i] == 'R') a[i] = 0;
    if(s[i] == 'G') a[i] = 1;
    if(s[i] == 'B') a[i] = 2;
  }

  vector<ll> cnt(3);
  rep(i,n) cnt[a[i]]++;
  ll ans = 1;
  rep(i,3) ans *= cnt[i];
  rep(j,n)rep(i,j){
    int k = j + (j - i);
    if(k < n){
      if(a[i] == a[j]) continue;
      if(a[j] == a[k]) continue;
      if(a[k] == a[i]) continue;
      ans--;
    }
  }

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


Measured memory_bytes: 3628
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll k = n / (a+b);
    ll ans = k * a;
    n -= k * (a+b);
    if (n >= a) {
        ans += a;
    } else {
        ans += n;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = input()

if len(n) > 1:
    first = int(n[-1])
else:
    first = int(n)
        
if first in [2,4,5,7,9]:
    print('hon')
elif first in [0,1,6,8]:
    print('pon')
elif first in [3]:
    print('bon')

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

int main(){
	int A,B;
	cin >> A >>B;
	if (A <= 8 && B <= 8){
		cout << "Yay!" << endl;
	}
	else{
		cout << ":(" << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    
    int B[M];
    for (int i = 0; i < M; i++) cin >> B[i];

    int count = 0;
    for (int i = 0; i < N; i++){
        int sum = C;
        for (int j = 0; j < M; j++){
            int a; cin >> a;
            sum += a * B[j];
        }
        if (sum > 0) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i,a,b,c,kazu=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if((c%i)==0){
			kazu++;
		}
	}
	printf("%d\n",kazu);	
	return 0 ;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int f = 0;
  int a = A;
  for (int i = A-1; i < B; i++){
    if ((a%10 == a/10000) && (a%100/10 == a/1000%10)){
      f++;
      a++;
      continue;
    }
    else{
      a++;
      continue;
    }
  }
  cout << f << endl;
}

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

int main(){
 long long N,A,B,c,d,p,ans,ans2,k;
cin>>N;
  ans=0;
  vector<long long>a(N);
  cin>>a[0];
  ans2=0;
 for(int i=1;i<N;i++){
   cin>>a[i];
   if(a[i-1]>=a[i]){
     ans2++;
   }
   else{
     ans=max(ans,ans2);
     ans2=0;
   }
 }
      ans=max(ans,ans2);
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;

long long n, a, b, sum;

int main()
{
	scanf("%lld%lld%lld", &n, &a, &b);
	long long x = n / (a + b), y = n % (a + b);
	if (y <= a) sum += y;
	else sum += a;
	printf("%lld", sum + x * a);
	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
As = gets.split.map(&:to_i)

h= Hash[As.sort.chunk(&:itself).map{|n, a| [n, a.size]}]
h.default = 0
puts Range.new(*h.keys.minmax).map{|n| h[n - 1] + h[n] + h[n + 1]}.max

Measured memory_bytes: 22256
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    int r;
    cin >> r;
    cout << r*r << endl;
}


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

int main() {
	int A,B,C,D;
    cin >> A >> B >> C >> D;
    int L = A+B;
    int R = C+D;
    if(L>R){
      cout << "Left" << endl;
    }
    else if(L==R){
      cout << "Balanced" << endl;
    }
    else{
      cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())
H = [int(x) for x in input().split()]
AB = [deque([]) for _ in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    AB[A-1].append(H[B-1])
    AB[B-1].append(H[A-1])
ans = 0
for i in range(N):
    if len(AB[i]) == 0:
        ans += 1
        continue
    if H[i] > max(AB[i]):
        ans += 1
print(ans)

Measured memory_bytes: 77352
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
//const int MAX=;



int main(){
	int N,M;
	cin>>N>>M;
	int S[2005][2005];
	rep(i,N)rep(j,M){
		char z;
		cin>>z;
		if(z=='.')S[i][j]=0;
		if(z=='#')S[i][j]=1;
	}
	int pt[2005][2005];
	rep(i,N-1)rep(j,M-1){
		int sm=S[i][j]+S[i+1][j]+S[i][j+1]+S[i+1][j+1];
		if(sm%2==0)pt[i][j]=1;
		else pt[i][j]=0;
	}
	int ln[2005][2005];
		rep(i,N-1)rep(j,M-1){
		if(i==0){
			if(pt[i][j]==1)ln[i][j]=1;
			if(pt[i][j]==0)ln[i][j]=0;
		}
		else{
			if(pt[i][j]==1)ln[i][j]=ln[i-1][j]+1;
			if(pt[i][j]==0)ln[i][j]=0;

		}
	}
	int ans=max(N,M);
	rep(i,N-1){
		ln[i][M-1]=0;
		stack<P> st;
		rep(j,M){
			while(true){
				if(st.empty()){
					st.push(make_pair(j,0));
					break;
				}
				else{
					P p=st.top();
					if(ln[i][p.first]<ln[i][j]){
						st.push(make_pair(j, p.first+1));
						break;
					}
					else{
						ans=max(ans, (ln[i][p.first]+1)*(j-p.second+1));
                      	st.pop();
					}
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 47360
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	cout << N*N*N << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

#define rep(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define rep2(i,j,n) for(int (i)=(j);(i)<=(n);(i)++)
#define all(i) (i).begin(),(i).end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef long long i64;

int main() {
	map<int, int> mp;
	set<int> st;

	int n;
	cin >> n;
	rep(i, 0, n) {
		int a;
		cin >> a;
		st.insert(a);
		if (!mp.count(a)) mp[a] = 0;
		mp[a]++;
	}
	int ans = 0;
	for (auto ite : st) {
		int x = ite;
		int cou = mp[x];
		if (mp.count(x - 1)) cou += mp[x - 1];
		if (mp.count(x + 1)) cou += mp[x + 1];
		ans = max(ans, cou);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6144
#include <stdio.h>

int solve(int,int);

int A[2000],n;

int main(){
  int i,q,m;

  scanf("%d",&n);
  if(n > 20)return 0;
  
  for(i = 0;i < n; i++){
    scanf("%d",&A[i]);
    if(A[i] < 1 || A[i] >2000)return 0;
  }
  scanf("%d",&q);
  if(q > 200)return 0;
  
  for(i = 0;i < q; i++){
    scanf("%d",&m);
    if(m < 1 || m > 2000)return 0;
    if(solve(0,m)== 1)printf("yes\n");
    else printf("no\n");
   }
  return 0;
}

int solve(int i,int m){
  int res;
  
  if(m == 0)return 1;
  if(i >= n)return 0;
  
  res = solve(i + 1,m) || solve(i + 1, m - A[i]);
  
  return res;
 }



Measured memory_bytes: 2048