akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int top=0;
int S[1000];

class stack{
    public:
        void push(int x);
        int pop();
        void initialize();
        void solve();
};

void stack::push(int x){
    top++;
    S[top]=x;
}

int stack::pop(){
    int x=S[top];
    top--;
    return x;
}

void stack::initialize(){
    top=0;
    S[top]=0;
}

void stack::solve(){
    cout << S[top] << endl;
}

int main(){
    int x;
    int num1, num2;
    char s[100];
    stack calc;

    while(cin>>s){
        if(s[0]=='+'){
            num2=calc.pop();
            num1=calc.pop();
            calc.push(num1+num2);
        }
        else if(s[0]=='-'){
            num2=calc.pop();
            num1=calc.pop();
            calc.push(num1-num2);
        }
        else if(s[0]=='*'){
            num2=calc.pop();
            num1=calc.pop();
            calc.push(num1*num2);
        }
        else {
            x=atoi(s);
            calc.push(x);
        }
     
    }
    cout << S[top] << endl;
    
    return  0;
}




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

int main(){
    multiset<int> s;
    int q, op, x, y;

    cin >> q;

    while(q-- > 0){
        cin >> op >> x;
        if(op == 0){
            s.insert(x);
            cout << s.size() << endl;
        }else if(op == 1){
            cout << s.count(x) << endl;
        }else if(op == 2){
            s.erase(x);
        }else if(op == 3){
            cin >> y;
            auto l = s.lower_bound(x);
            auto r = s.upper_bound(y);
            for(; l != r; l++)  printf("%d\n", *l);
        }
    }

    return 0;
}


Measured memory_bytes: 12508
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  int N; cin >> N;
  unordered_map<ll, ll> mp;
  ll res = 0;

  for (int i = 1; i <= N; i++) {
    ll h;
    cin >> h;
    mp[i + h]++;
    res += mp[i - h];
  }
  cout << res << endl;
  
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


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

int main(){
	int n;
	cin>>n;
	char a;
	for(int i=1; i<=n; i++){
		cin>>a;
		if(a=='Y'){
			cout<<"Four"<<endl;
			return 0;
		}
	}
	cout<<"Three"<<endl;
	return 0;
}

Measured memory_bytes: 256
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Measured memory_bytes: 160512
#include<bits/stdc++.h>
#define maxn 200005
#define inf 1e18L + 5
#define ll long long
#define MOD 1000000007
#define M 31
#define mat vector < vector < ll > >
using namespace std;

ll n, k;


mat mul(mat  a, mat b){
    mat t(n, vector<ll>(n));
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){
            for(ll l = 0; l < n ; l++){
                t[i][j] += a[i][l] * b[l][j];
                t[i][j] %= MOD;
            }
        }
    }
    return t;
}

mat powM(mat ad, mat I, ll p){
    if(p==0) return I;
    if(p==1) return ad;
    mat r = powM(ad, I, p/2);
    mat res = mul(r, r);
    if(p%2==1){
        res  = mul(res, ad);
    }
    return res;
}

int main(){
    cin >> n >> k;
    mat ad(n, vector<ll>(n)), I(n, vector<ll>(n));
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){
            ll x; cin>> x;
            ad[i][j] = x;
            if(i==j) I[i][i] = 1;
        }
    }
    mat ans = powM(ad, I, k);
    ll res = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){
            res += ans[i][j];
            res %= MOD;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3072
using System;

class Program {
    static void Main(string[] args) {
        string[] s = Console.ReadLine().Split(' ');
        int w = int.Parse(s[0]);
        int a = int.Parse(s[1]);
        int b = int.Parse(s[2]);
        if (a + w < b) {
            Console.WriteLine(b - (a + w));
            return;
        } 
        if (b + w < a) {
            Console.WriteLine(a - (b + w));
            return;
        }
        Console.WriteLine("0");
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
  ll n,k,sum=0;
  cin>>n>>k;
  ll arr[n];
  for(int i=0;i<n;i++)
  cin>>arr[i];
  
  sort(arr,arr+n);
  for(int i=0;i<k;i++)
  {
    sum+=arr[i];
  }
  cout<<sum<<endl;
  return 0;
}
  

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

long long int N, M, a[101010], A;
unordered_map<long long, long long> m;

int main(){
    scanf("%lld%lld", &N, &M);
    for(int i = 1; i <= N; ++i){
        scanf("%lld", a + i);
        a[i] += a[i - 1];
        a[i] %= M;
    }
    sort(a, a + N + 1);
    for(int i = 0; i <= N; ++i)++m[a[i]];
    for(auto i : m){
        A += i.second * (i.second - 1) / 2;
    }
    cout << A << endl;
    return 0;
}

Measured memory_bytes: 4492
ans' n a b =
     let n' = fromIntegral n :: Float
         a' = fromIntegral a :: Float
     in
       b * ceiling ( n' / a' )

ans [n,a,b,c,d] =
    let o1 = ans' n a b
        o2 = ans' n c d
    in
      minimum [ o1, o2 ]

main = do
     l <- getLine
     let i = map read $ words l :: [Int]
         o = ans i
     print o


Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {
  static long a, b, c;

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

    a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt();

    if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
      System.out.println(0);
    }
    else{
      System.out.println(Math.min(a * b, Math.min(b * c, a * c)));
    }
  }
}

Measured memory_bytes: 9428
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    char c;
    cin>>c;
    cout<<(char)('a' + (c - 'a') + 1);
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,k,ans;
int main(){
	cin>>a>>b>>c>>k;
	ans+=min(k,a);
	k-=min(k,a);
	if(k>0){
		k-= min(k,b);
	}
	ans-=k;
	cout<<ans;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>

#include<stack>
#include<queue>
#include<climits>
#include<sstream>
using namespace std;
#define maxn 10005
struct Node{
    int x,y,val;
};
Node g[100010];
int n,m;
int F[maxn];
bool cmp(Node a,Node b){
    return a.val<b.val;
}
int find(int x){
    if(F[x]==-1) return x;
    return F[x]=find(F[x]);
}
int main(){

    int i,j,k;
    cin>>n>>m;
    for(i=0;i<m;i++)
        cin>>g[i].x>>g[i].y>>g[i].val;
    sort(g,g+m,cmp);


    memset(F,-1,sizeof F);
    int cnt=0,ans=0;
    for(i=0;i<m;i++){
        int fx=find(g[i].x);
        int fy=find(g[i].y);
        if(fx!=fy){
            F[fx]=fy;
            cnt++;
            ans+=g[i].val;
        }
        if(cnt==n-1) break;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4312
def resolve():
    import sys

    input = sys.stdin.readline

    n = int(input().rstrip())

    ans = 0


    for a in range(1, n):
        # aがiの田沖の最大のB
        max_b = (n - 1) // a

        if max_b < a:
            ans += (max_b) * 2
        else:
            ans += (a - 1) * 2 + 1


    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 62828
N, A, B = map(int, input().split())

n = 0
for i in range(1, N + 1):
    s = 0
    a = i
    while a > 0:
        s += a % 10
        a = int(a / 10)
    if A <= s and s <= B:
        n += i
print(n)

Measured memory_bytes: 9104
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    LL N;
    GLL(N);
    LL sum=0,ans=0;
    for(LL i=0;sum<N;i++,sum+=i)
        ans++;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int a,b,c;
    while(sf("%d %d %d",&a,&b,&c)==3)
    {
        bool f=true;
        for(int i=1;i<=200;i++)
        {
            int x=(a%b*i%b)%b;
            if(x==c)
            {
                f=false;
                puts("YES");
                break;
            }
        }
        if(f)puts("NO");
    }
    return 0;
}
 









 




























Measured memory_bytes: 256
using System;
using System.Linq;

class ALDS1
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int[] x = new int[a];
        int minj, b, c=0;
        string str = Console.ReadLine();
        for (int i = 0; i < a; i++)
        {
            x[i] = int.Parse(str.Split(' ')[i]);
        }
        for (int i = 0; i < a; i++)
        {
            minj = i;
            for (int j = i; j < a; j++)
            {
                if (x[j] < x[minj])
                {
                    minj = j;
                }
            }
            if (i != minj)
            {
                b = x[i]; x[i] = x[minj]; x[minj] = b;
                c++;
            }
        }
        for (int i = 0; i < a; i++)
        {
            if (i == a - 1) Console.WriteLine(x[i]);
            else Console.Write(x[i]+" ");
        }
        Console.WriteLine(c);
    }
}

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

int main() {
  int N,M,Q;
  cin>>N>>M>>Q;
  vector<vector<int>>p(N+1,vector<int>(N+1));
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    p.at(a).at(b)++;
  }
  vector<vector<int>>q(N+1,vector<int>(N+1));
  for(int i=1;i<=N;i++){
    for(int j=i;j<=N;j++){
      q.at(i).at(j)=q.at(i).at(j-1)+p.at(i).at(j);
    }
  }
  vector<vector<int>>r(N+1,vector<int>(N+1));
  for(int j=1;j<=N;j++){
    r.at(j).at(j)=q.at(j).at(j);
    for(int i=j-1;i>0;i--){
      r.at(i).at(j)=r.at(i+1).at(j)+q.at(i).at(j);
    }
  }
  for(int i=0;i<Q;i++){
    int a,b;
    cin>>a>>b;
    cout<<r.at(a).at(b)<<endl;
  }
}

Measured memory_bytes: 3968
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
index = []
while n > 0:
    index.append(n % 26)
    if n % 26 == 0:
        n -= 26
    n //= 26
index.reverse()
ans = ""
for item in index:
    if item == 0:
        ans += "z"
    else:
        ans += chr(ord("a") + item - 1)
print(ans)

Measured memory_bytes: 9144
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;




int main() {
	int N,t = 0,k = 0;
	int a[200000];
	int b;

	cin >> N;

	for (int i = 0; i < N; i++) {

		cin >> a[i];
	}

	k = a[0];


	 for (int i = 1; i < N; i++) {//任意のi

		 if (k >= a[i]) {
			 t++;
		 }
		 k = min(k, a[i]);

	}

	cout << t + 1;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

using Graph = vector<set<ll>>;
vector<ll> h;
ll cnt = 0;

void print_graph(Graph graph)
{
    for (int i = 0; i < graph.size(); i++)
    {
        ll high = h[i];
        bool flag = false;
        for (auto itr = graph[i].begin(); itr != graph[i].end(); ++itr)
        {
            if (high <= h[*itr])
            {
                flag = true;
            }
        }
        if (!flag)
        {
            cnt++;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        h.pb(x);
    }
    Graph G(n);
    for (int i = 0; i < m; i++)
    {
        ll a, b;
        cin >> a >> b;
        G[a - 1].insert(b - 1);
        G[b - 1].insert(a - 1);
    }

    print_graph(G);
    cout << cnt << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define read freopen("in.c", "r", stdin)
#define write freopen("out.c", "w", stdout)
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define ff first
#define ss second
#define left(x) ((x) + (x) + 1)
#define right(x) ((x) + (x) + 2)
#define pb push_back
#define pp pop_back
#define eps 1e-15
#define mx 100005
#define mmod 1000000007
#define inf (INT_MAX - 5)
#define cs(p) printf("Case %d:", (p)++)
#define nl puts("")
#define sp printf(" ")
#define out(a) printf("%lld", (ll)(a))
#define SET(a) memset((a), -1, sizeof(a))
#define CLR(a) memset((a), 0, sizeof(a))

ll bgm(ll a, ll b, ll m)
{
    a %= m;
    ll rem = 1;
    while(b)
    {
        if(b&1)
            rem = (rem * a) % m;
        a = (a * a)%m;
        b >>= 1;
    }
    return rem;
}

ll in()
{
    ll a;
    if(scanf("%lld", &a) == EOF) return EOF;
    return a;
}

ll dl()
{
    double a;
    if(scanf("%lf", &a) == EOF) return EOF;
    return a;
}

const int MAX = 200005;

int n;
ll s;
ll ara[MAX];

map<ll, ll> cnt;

int main()
{
    n = in(), s = 0;
    for(int i = 1; i <= n; i++) ara[i] = in();

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

    for(int i = 0; i <= n; i++) cnt[ara[i]]++;

    ll ans = 0;

    for(int i = 0; i < n; i++)
    {
        cnt[ara[i]]--;
        ll k = ara[i] + s;
        ans += cnt[k];
    }
    out(ans), nl;

    return 0;
}



Measured memory_bytes: 14336
S = input()[::-1]
remain_table = [0] * 2019
remain_table[0] = 1
d = 1
chk = 0
for s in S:
    chk += int(s) * d
    chk = chk % 2019
    remain_table[chk] += 1
    d *= 10
    d %= 2019

ans = 0
for r in remain_table:
    ans += r * (r - 1) // 2
print(ans)

Measured memory_bytes: 9388
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;


int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; ++i)
    {
        cin >> a[i];
    }
    map<char, ll> m;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            m[a[i][j]]++;
        }
    }
    
    map<ll, ll> c;
    c[1] = 0;
    if (h % 2 && w % 2)
    {
        c[1] = 1;
    }
    c[2] = 0;
    if (h % 2)
    {
        c[2] += w;
    }
    if (w % 2)
    {
        c[2] += h;
    }
    c[2] -=  2 * c[1];
    c[4] = h * w - c[2] - c[1];
    
    for (auto itr = m.begin(); itr != m.end(); ++itr)
    {
        if (itr->second % 2)
        {
            c[1]--;
            itr->second--;
        }
        
        if (itr->second % 4 != 0 && itr->second >= 2)
        {
            c[2] -= 2;
            itr->second -= 2;
        }
        
        if (c[1] < 0 || c[2] < 0 || c[4] < 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

#整数の入力
#a = int(input())
#b = int(input())
#スペース区切りの整数の入力
a, b = input().split()
#文字列の入力
#s1 = input()

if a < b:
    print("<")
elif a == b:
    print("=")
else :
    print(">")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, M;
vector<int>v[1000], u;
int vis[1000], t[1000];

bool dfs(int x) {
	vis[x] = 2;
	u.push_back(x);
	for (int i : v[x]) {
		if (vis[i] == 2) {
			u.push_back(i);
			return true;
		}
	}
	for (int i : v[x]) {
		if (!vis[i]) {
			if (dfs(i)) {
				return true;
			}
		}
	}
	u.pop_back();
	vis[x] = 1;
	return false;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		v[a - 1].push_back(b - 1);
	}
	for (int i = 0; i < N; ++i) {
		if (dfs(i)) {
			vector<int>w;
			for (int j = 0; j < u.size(); ++j) {
				if (u[j] == u.back()) {
					for (int k = j + 1; k < u.size(); ++k) {
						w.push_back(u[k]);
					}
					break;
				}
			}
			for (int j = 0; j < N; ++j) {
				vis[j] = 0;
			}
			u = w;
			do {
				w = u;
				for (int j = 0; j < u.size(); ++j) {
					t[u[j]] = j + 1;
				}
				u.clear();
				int p = w[0];
				while (true) {
					if (vis[p]) {
						u.push_back(p);
						break;
					}
					u.push_back(p);
					vis[p] = 1;
					pair<int, int>PP = { -1,-1 };
					for (int j : v[p]) {
						if (t[j]) {
							PP = max(PP, mkp(signed((t[j] - t[p] + u.size()) % u.size()), j));
						}
					}
					p = PP.second;
				}
				vector<int>tmp;
				for (int j = 0; j < u.size(); ++j) {
					if (u[j] == u.back()) {
						for (int k = j + 1; k < u.size(); ++k) {
							tmp.push_back(u[k]);
						}
						break;
					}
				}
				u = tmp;
				for (int j : w) {
					vis[j] = 0;
					t[j] = 0;
				}
			} while (u == w);
			cout << u.size() << endl;
			for (int j : u) {
				cout << j + 1 << endl;
			}
			return 0;
		}
		else {
			for (int j = 0; j < N; ++j) {
				vis[j] = false;
			}
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
#define CoutV(vec)     \
    for (auto v : vec) \
        Cout(v);
#define CoutVV(vecvec)      \
    for (auto vec : vecvec) \
        CoutV(vec);

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

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;
//int t[10010];

int main()
{

    int n;
    cin >> n;

    int ans = 0;
    for (int i = n; i <= 1111; i++)
    {
        bool ok = true;

        int pre = i % 10;
        int now = i;
        while (now > 0)
        {
            int d = now % 10;
            if (pre != d)
            {
                ok = false;
                break;
            }
            now /= 10;
        }
        if (ok)
        {

            ans = i;
            break;
        }
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 256
N,X=map(int,input().split())
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)

lx=list(map(int,input().split()))
ans=abs(lx[0]-X)
for i in range(1,N):
    ans=gcd(ans,abs(lx[i]-X))
print(ans)


Measured memory_bytes: 14252
package main

import (
	"fmt"
)

// A - Frog 1
// https://atcoder.jp/contests/dp/tasks/dp_a

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	h := [100000]int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h[i])
	}
	var dp = [100000]int{}
	dp[0] = 0
	dp[1] = Abs(h[1] - h[0])
	var tmp1 int
	var tmp2 int
	for i := 2; i < n; i++ {
		tmp1 = dp[i-2] + Abs(h[i]-h[i-2])
		tmp2 = dp[i-1] + Abs(h[i]-h[i-1])
		if tmp1 < tmp2 {
			dp[i] = tmp1
		} else {
			dp[i] = tmp2
		}
	}
	fmt.Printf("%d\n", dp[n-1])
}


Measured memory_bytes: 7116
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;
const double EPS=1e-8;
inline int sign(double a){return a<-EPS?-1:a>EPS;}
inline int cmp(double a,double b){return sign(a-b);}
//点
struct P{
    double x,y;
    P(){}
    P(double _x,double _y):x(_x),y(_y){}
    P operator + (P p){return P(x+p.x,y+p.y);}
    P operator - (P p){return P(x-p.x,y-p.y);}
    P operator * (double k){return P(x*k,y*k);}
    P operator / (double k){return P(x/k,y/k);}
    double dot(P p){return x*p.x+y*p.y;}
    double det(P p){return x*p.y-y*p.x;}
    double distTo(P p){return (*this-p).abs();}
    double alpha(){return atan2(y,x);}
    void read(){scanf("%lf%lf", &x, &y);}
    void write(){printf("%.10lf %.10lf\n", x, y);}
    double abs(){return sqrt(abs2());}
    double abs2(){return x*x+y*y;}
    P rot90(){return P(-y,x);}
    P unit(){return *this/abs();}
    int quad(){return sign(y)==1||(sign(y)==0&&sign(x)>=0);}
    P rot(double an){return P(x*cos(an)-y*sin(an),x*sin(an)+y*cos(an));}
    bool operator < (P p)const{int c=cmp(x,p.x);if(c)return c==-1;return cmp(y,p.y)==-1;}
    bool operator == (P o)const{return cmp(x,o.x)==0&&cmp(y,o.y)==0;}
};

int main(int argc, char const *argv[])
{
    P p0, p1, p2, p3;
    int q;
    scanf("%d", &q);
    while (q--) {
        p0.read(); p1.read(); p2.read(); p3.read();
        if(min(max(p0.x, p1.x), max(p2.x, p3.x)) < max(min(p0.x, p1.x), min(p2.x, p3.x)))   printf("0\n");
        else if(min(max(p0.y, p1.y), max(p2.y, p3.y)) < max(min(p0.y, p1.y), min(p2.y, p3.y)))  printf("0\n");
        else {
            if(sign((p1-p0).det(p2-p0)) == sign((p1-p0).det(p3-p0))) {
                if(sign((p1-p0).det(p2-p0)) == 0)    printf("1\n");
                else    printf("0\n");
            }
            else if(sign((p3-p2).det(p0-p2)) == sign((p3-p2).det(p1-p2)))   printf("0\n");
            else    printf("1\n");
        }
    }
    return 0;
}


Measured memory_bytes: 3200
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
    
    io
    
    ll n;
    cin>>n;
    ll s=0;
    rep(i,1,n+1)
    {
        if(i%3==0 && i%5==0)
        {
            continue;
        }
        if(i%3==0 )
        {            
            continue;
        }
        if(i%5==0)
        {
            continue;
        }
        s+=i;
    }
    cout<<s;
}

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

int main(){
  long long S;
  cin >> S;
  vector<long> ss(8,0);
  int i=0;
  while(S>99){
    ss.at(i)=S%1000;
    S/=10;i++;
  }
  long m,M=700;
  for(int j=0;j<8;j++){
    m=abs(ss.at(j)-753);
    M=min(m,M);
  }
  cout << M;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf (1<<16)

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

  int ans=inf;
  for(int i=0;i<=n;++i){
    int six =1;
    int nine=1;
    int a=i;
    int b=n-i;
    int v_ans=0;
 
    while(nine*9<=a)nine*=9;
    while(nine!=1){
      v_ans+=a/nine;
      a%=nine;
      nine/=9;
    }
    v_ans+=a;

    while(six*6<=b)six*=6;
    while(six!=1){
      v_ans+=b/six;
      b%=six;
      six/=6;
    }
    v_ans+=b;

    ans=min(ans,v_ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"



const int mod = 1000000007;

string st;
int a;
pair<int, int>getexpr();
pair<int, int>getval() {
	assert(st[a] == 'x');
	a++;
	int num = 0;
	while (a!=st.size()&&isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return make_pair(1, 1);
}
pair<int, int>getfact() {
	if (st[a] == '~') {
		a++;
		auto p = getfact();
		return make_pair(p.second, p.first);
	}
	else if (st[a] == '(') {
		a++;
		auto p(getexpr());
		a++;
		return p;
	}
	else {
		auto p(getval());
		return p;
	}
}
pair<int, int>getterm() {
	auto p=getfact();
	while (a != st.size()) {
		if (st[a] == '|'||st[a]==')')return p;
		else if (st[a] == '&') {
			a++;
			auto q = getfact();
			long long 	int aa = p.first, ab = p.second, ba = q.first, bb = q.second;
			long long int fst = ba*aa;
			long long int scd =  (aa + ab)*(ba + bb) - ba*aa;

			p = make_pair(fst%mod, scd%mod);
		}
	}
	return p;
}
pair<int, int> getexpr() {
	auto p(getterm());
	while (a != st.size()) {
		if (st[a] == '|') {
			a++;
			auto q = getterm();
			long long 	int aa = p.first, ab = p.second, ba = q.first, bb = q.second;
			long long int fst = (aa + ab)*(ba + bb) - bb*ab;
			long long int scd = bb*ab;
			p = make_pair(fst%mod, scd%mod);
		}
		else if(st[a]==')'){
			break;
		}
		else {
			break;
			assert(false);
		}
	}
	return p;
}
long long int eord, enew;
int main() {
	const int SZ = 128 * 1024 * 1024;
	void *p = malloc(SZ);
	enew = (long long)p + SZ - 1;

	__asm__("mov %rsp, eord");
	__asm__("mov enew, %rsp");

	cin >> st;
	a = 0;
	int ans = getexpr().first;
	cout << ans << endl;
	__asm__("mov eord, %rsp");
	return 0;
}

Measured memory_bytes: 58576
#!/usr/bin/env python
# -*- coding: utf-8 -*-
H,W = map(int,raw_input().split(" "))

lista = []
for i in range(H):
	lista.append([map(str,raw_input().split(" "))])

result = []
stre = ""
for i in range(W+2):
	stre = stre + "#"

print stre

for i in lista:
	stre1 = "#"
	for k in i:
		stre1 = stre1 + k[0]
	stre1 = stre1 + "#"
	print stre1

print stre

Measured memory_bytes: 2568
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int[] a=cin.ArrayInt(N,0);
        string ans ="APPROVED";
        for(int i=0;i<N;i++)
        {
            if((a[i]%2==0&&a[i]%3!=0)&&(a[i]%2==0&&a[i]%5!=0))ans="DENIED";
            
        }
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
N = gets.chomp.to_i

ans = "Yes"
words = []
N.times do |i|
  word = gets.chomp
  if words.include?(word)
    ans = "No"
  end
  words << word
end

unless ans == "No"
  for i in 1..(words.size - 1) do
    word = words[i]
    if word[0] != words[i-1][-1]
      ans = "No"
      break
    end
  end
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> A(n);
  for (int& a : A)
    cin >> a;
  int sum = accumulate(A.begin(), A.end(), 0);
  cout << (sum >= h ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 640
N = int(input())
num = list(map(int, input().split()))

ans = 0
r = 0
sumz = 0
for l in range(N):
    if r < l: r = l

    while (r < N) and (num[r] + sumz) == (sumz ^ num[r]):
        sumz += num[r]
        r += 1

    ans += r-l
    sumz -= num[l]

print(ans)


Measured memory_bytes: 32196
s = input()
C_flag = 0
F_flag = 0
for i in range(len(s)):
  if C_flag == 0:
    if s[i] == "C":
      C_flag = 1
  else:
    if s[i] == "F":
      F_flag = 1
if C_flag == 1 and F_flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 2940
import bisect
from collections import deque

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    tmp = list(map(int,input().split()))
    bc.append(tmp[::-1])

a.sort()
a = deque(a)
bc.sort(reverse=True)

ans = 0
num = 0
for i in range(m):
    index = bisect.bisect_left(a,bc[i][0])
    if index == 0:
        break
    if bc[i][1] > index:
        ans += bc[i][0] * index
        num = index
    else:
        ans += bc[i][0] * bc[i][1]
        num = bc[i][1]
    for _ in range(num):
        a.popleft()

print(ans + sum(a))


Measured memory_bytes: 25176
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;


int main() {
	int n;
	int b[1000];
	int f[1000];
	int r[1000];
	int v[1000];
	int k[1000];
	int room[11][13];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b[i] >> f[i] >> r[i] >> v[i];
	}
	for (int i = 0; i < n; i++) {
		k[i] = (b[i] - 1) * 3 + f[i];
	}
	for (int i = 1; i <= 10; i++) {
		for (int j = 1; j <= 12; j++) {
			room[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		room[r[i]][k[i]] += v[i];
	}
	for (int i = 1; i <= 12; i++) {
		if (i % 3==1&&i!=1) cout << "####################"<<endl;
		for (int j = 1; j <= 10; j++) {
			cout << ' ' << room[j][i];
		}
		cout << endl;
	}
	cin >> n;
}

Measured memory_bytes: 1180
N = int(input())

count = 0
if N<10:
  print(N)
elif N<100:
  print(9)
elif N<1000:
  print(9+N-99)
elif N<10000:
  print(909)
elif N<100000:
  print(909+N-10000+1)
else:
  print(909+100000-10000)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
constexpr int INF = 1e9;
using namespace std;
using YX = pair<int, int>;

istream &operator>>(istream &is, YX &p) {
    is >> p.first >> p.second;
    return is;
}

int dist[1003][1003];

int bfs(vector<string> maize, int r, int c, deque<YX> que) {
    const vector<YX> MOVES = {
        make_pair(-1, 0),  // up
        make_pair(0, 1),   // right
        make_pair(0, -1),  // left
        make_pair(1, 0)    // bottom
    };
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            dist[i][j] = INF;  // 未到達をINFで初期化
        }
    }
    for (YX p : que) {
        dist[p.first][p.second] = 0;
    }

    int res = 0;
    while (!que.empty()) {
        YX prev = que.front();
        que.pop_front();

        for (YX p : MOVES) {
            int y = prev.first + p.first;
            int x = prev.second + p.second;
            // maizeの外ならskip
            if (y < 0 || y >= r || x < 0 || x >= c) continue;
            // 黒ならskip
            if (maize[y][x] == '#') continue;
            // 通過済みならskip
            if (dist[y][x] != INF) continue;

            // 直前のノードまでの最短距離+1
            dist[y][x] = dist[prev.first][prev.second] + 1;
            res        = dist[y][x];
            // このノードから距離1で到達できるところを探したいのでqueueに突っ込む
            que.push_back(make_pair(y, x));
        }
    }
    return res;
}

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> A(H);
    for (int i = 0; i < H; ++i) {
        cin >> A.at(i);
    }

    deque<YX> blacks;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (A.at(i).at(j) == '#') blacks.push_back(make_pair(i, j));
        }
    }

    cout << bfs(A, H, W, blacks) << endl;

    return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SIZE 1000000001

void all_search(int a, int b, int c, int x, int y, int *ans)
{
    REP(i, x + 1)
    { //aピザの枚数
        REP(j, y + 1)
        { //bピザの枚数
            if (a * i + b * j + c * 2 * max(x - i, y - j) <= *ans)
                *ans = a * i + b * j + c * 2 * max(x - i, y - j);
        }
    }
}

void all_search_revised(int a, int b, int c, int x, int y, int *ans)
{
    if (a + b >= 2 * c)
    {
        *ans = 2 * c * min(x, y);

        if (x >= y)
        {
            if (a > 2 * c)
                *ans += (x - y) * 2 * c;
            else
                *ans += (x - y) * a;
        }
        else
        {
            if (b > 2 * c)
                *ans += (y - x) * 2 * c;
            else
                *ans += (y - x) * b;
        }
    }
    else
    {
        *ans = x * min(2 * c, a) + y * min(2 * c, b);
    }
}

int main(void)
{
    int a, b, c, x, y, ans = SIZE;
    //scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
    cin >> a >> b >> c >> x >> y;

    all_search_revised(a, b, c, x, y, &ans);

    //printf("%d\n",&ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		LightScanner in = new LightScanner(inputStream);
		LightWriter out = new LightWriter(outputStream);

		int H = in.ints();
		int W = in.ints();
		int A = in.ints();
		int B = in.ints();

		char[][] answer = new char[H][W];
		for (int i = 0; i < B; i++) {
			Arrays.fill(answer[i], 0, A, '0');
			Arrays.fill(answer[i], A, W, '1');
		}
		for (int i = B; i < H; i++) {
			Arrays.fill(answer[i], 0, A, '1');
			Arrays.fill(answer[i], A, W, '0');
		}
		for (char[] row : answer) {
			out.printLine(row).ln();
		}

		out.close();
	}

	static class LightScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public LightScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}

		public String string() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public long longs() {
			return Long.parseLong(string());
		}

		public int ints() {
			return Integer.parseInt(string());
		}
	}

	static class LightWriter implements AutoCloseable {
		private final Writer out;
		private boolean autoflush = false;
		private boolean breaked = true;

		public LightWriter(Writer out) {
			this.out = out;
		}

		public LightWriter(OutputStream out) {
			this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
		}

		public LightWriter print(char c) {
			try {
				out.write(c);
				breaked = false;
			} catch (IOException ex) {
				throw new UncheckedIOException(ex);
			}
			return this;
		}

		public LightWriter print(String s) {
			try {
				out.write(s, 0, s.length());
				breaked = false;
			} catch (IOException ex) {
				throw new UncheckedIOException(ex);
			}
			return this;
		}

		public LightWriter ans(String s) {
			if (!breaked) {
				print(' ');
			}
			return print(s);
		}

		public LightWriter printLine(char[] array) {
			return print(new String(array));
		}

		public LightWriter ans(int i) {
			return ans(Integer.toString(i));
		}

		public LightWriter ans(long i) {
			return ans(Long.toString(i));
		}

		public LightWriter ln() {
			print(System.lineSeparator());
			breaked = true;
			if (autoflush) {
				try {
					out.flush();
				} catch (IOException ex) {
					throw new UncheckedIOException(ex);
				}
			}
			return this;
		}

		public void close() {
			try {
				out.close();
			} catch (IOException ex) {
				throw new UncheckedIOException(ex);
			}
		}

	}
}


Measured memory_bytes: 26928
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}

Measured memory_bytes: 3592
N, K = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
two = (-1 * (mod//2)) % mod
cnt = 0
for i in range(N):
    for j in range(N):
        if a[i] > a[j]:
            cnt += 1
ans = cnt * (K - 1) * K * two % mod
for i in range(N - 1):
    for j in range(i + 1, N):
        if a[i] > a[j]:
            ans += K
print(ans % mod)

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

void solve() 
{
    int n;cin>>n;
    vector<pair<int,int> >vp;
    REP(i,n){
        int x,l;cin>>x>>l;
        vp.push_back({x+l,x-l});
    }
    sort(vp.begin(),vp.end());
    int ans=0,tmp=-(int)1e9-10;
    REP(i,n)if(tmp<=vp[i].second)ans++,tmp=vp[i].first;
    cout<<ans<<endl;
}

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

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();

		long ab = a + b;
		long ans = n / ab * a;
		ans += Math.min(n % ab, a);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



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

	for (int i = 0; i < (1 << 3); i++) {
		vector<string> v(3);
		for (int j = 0; j < 3; j++) {
			if (i & (1<<j)) {
				v[j] = '+';
			}
			else {
				v[j] = '-';
			}
		}

		int temp = s[0]-'0';
		rep(k, 0, 3) {
			if (v[k] == "+") {
				temp += s[k + 1] - '0';
			}
			else {
				temp -= s[k + 1] - '0';
			}
		}
		if (temp == 7) {
			rep(l, 0, 7) {
				if (l%2 == 0) {
					cout << s[l/2];
				}
				else {
					cout << v[(l-1) / 2];
				}
			}
			cout << "=7"<< endl;
			exit(0);
		}
	}
	return 0;

}

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

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

    char al;
    cin >> al;

    if('a'<= al && al<='z') puts("a");
    else puts("A");

    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include <math.h>
int main(){
  int n,d,i,j,k,c=0;
  double dist,tmp;
  scanf("%d %d", &n, &d);
  int p[n][d];
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d", &p[i][j]);
    }
  }
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      tmp=0;
      for(k=0;k<d;k++){
        tmp+=pow(p[i][k]-p[j][k],2);
      }
      dist=sqrt(tmp);
      if(ceil(dist)==floor(dist)){
        c++;
      }
    }
  }
  printf("%d", c);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int N = scan.nextInt();
      
      int n = N / 1000;
      if(N % 1000 != 0){
        n++;
      }
      System.out.println(n * 1000 - N);
    
    }
}

Measured memory_bytes: 35752
// Shift-JIS（シフトジス）

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

int gcd(long long a, long long b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

int lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

int main()
{   
    int N, D;
    cin >> N >> D;
    cout << (N - 1) / (2 * D + 1) + 1 << endl;;
}

Measured memory_bytes: 256
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=4e6+9;
ll cnt,a=-1,b=-1;
int x,y;
ll f[sz];
ll mod=1e9+7;
ll add(ll a,ll b){return ((a%mod+b%mod)%mod+mod)%mod;}
ll mul(ll a,ll b){return (a%mod*b%mod)%mod;}
ll modpow(ll b,ll p){
	if(!b) return 0;
	if(!p) return 1;
	ll u=modpow(b,p>>1);
	u=mul(u,u);
	if(p&1) return mul(u,b);
	return u;
}

bool ok;

int main(){
	cin>>x>>y;
	for(ll i=0;i<=x;i++){
		a=i;
		b=y-2*a;
		if(x==a+2*b&&b>=0){
			ok=1;
			break;
		}
	}
	if(!ok){
		puts("0");
		return 0;
	}
	cnt=a+b;
	f[0]=f[1]=1;
	for(int i=2;i<=cnt;i++){
		f[i]=mul(i,f[i-1]);
	}
	ll ans=f[cnt];
	ans=mul(ans,modpow(f[a],mod-2));
	ans=mul(ans,modpow(f[b],mod-2));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6400
N = int(input())
arr = []
for i in range(N):
    arr.append(list(map(int, input().split())))

arr = sorted(arr, key=lambda x:x[1])

isYes = True
totalA = 0
for i in range(N):
    totalA += arr[i][0]
    if totalA > arr[i][1]:
        isYes = False

if isYes:
    print('Yes')
else:
    print('No')

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

char grade(int m, int f, int r);

int main() {
	int m, f, r;
	while (cin >> m >> f >> r){
		if (m==-1 && f==-1 && r==-1) break;
		cout << grade(m, f, r) << endl;
	}
	return 0;
}

char grade(int m, int f, int r){
	if (m == -1 || f == -1) return 'F';
	if (m + f >= 80) return 'A';
	if (m + f >= 65) return 'B';
	if (m + f >= 50) return 'C';
	if (m + f >= 30){
		if (r >= 50) return 'C';
		return 'D';
	}
	return 'F';
}

Measured memory_bytes: 1152
n=int(input())
a=[]
b=[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
a.sort()
b.sort()
m=int(n//2)
if n%2==0:
  a_av=(a[m]+a[m-1])/2
  b_av=(b[m]+b[m-1])/2
  ans=int(b_av*2-a_av*2+1)
else:
  ans=int(b[m]-a[m]+1)
print(ans)

Measured memory_bytes: 25476
import bisect

N = int(input())
L = [int(_) for _ in input().split()]
L.sort()

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        r = L[i] + L[j]
        # 同じ長さでも違う棒はOK
        ri = bisect.bisect_left(L, r)
        ans += ri - j - 1

print(ans)

Measured memory_bytes: 42972
#include <stdio.h>

#define MAX 100000

void swap(int*,int*);
void Partition(int,int,int*);

int main(){
  int n,i,A[MAX];
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  Partition(0,n-1,A);
  return 0;
}

void swap(int *a,int *b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void Partition(int l,int r,int *A){
  int x = A[r],i = l,j;
  for(j = l ; j < r ; j++){
    if(A[j] <= x){
      swap(&A[i++],&A[j]);
    }
  }
  swap(&A[i],&A[r]);
  for(j = l ; j <= r ; j++){
    if(j > l){ printf(" "); }
    if(j == i){
      printf("[%d]",A[j]);
    }else{
      printf("%d",A[j]);
    }
  }
  printf("\n");
}



Measured memory_bytes: 2140
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    	int num = input.nextInt();
    	for(int i = 0 ; i < num ; i++){
    		double x1 = input.nextDouble();
    		double y1 = input.nextDouble();
    		double r1 = input.nextDouble();
    		double x2 = input.nextDouble();
    		double y2 = input.nextDouble();
    		double r2 = input.nextDouble();
    		System.out.println(circle(x1,y1,r1,x2,y2,r2));
    	}
    }
    
    static int circle(double x1,double y1,double r1, double x2,double y2, double r2){
    	double r = Math.sqrt(Math.pow((x1-x2),2)+Math.pow((y1-y2), 2));
    	double rl = r1+r2;
    	if(r > rl){
    		return 0;
    	}else if(r < r1-r2){
    		return 2;
    	}else if(r < r2-r1){
    		return -2;
    	}else{
    		return 1;
    	}
    }
}

Measured memory_bytes: 20656