akhauriyash/Code-Regression huggingface dataset:
N=int(input())
from collections import defaultdict
dic=defaultdict(int)
dic[(0,0)]=dic[(0,1)]=0
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]-1
ans%=mod
print(ans)


Measured memory_bytes: 46700
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
        long int n;
        long int num[200000];
        long int max=-1000000000;
        long int min=1000000000;
        long int sub;
        long int i;  
        cin>>n;
        for(i=0;i<n;i++){
                cin>>num[i];        
        }   
        min=num[0];
        for(i=1;i<n;i++){
                sub=num[i]-min;
                if(num[i]<min){
                        min=num[i];
                }   
                if(sub>max){
                        max=sub;
                }   
        }   
        cout<<max<<endl;
        return 0;
}

Measured memory_bytes: 4636
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}

	S := 1000
	C := 0
	for i := 1; i < N; i++ {
		if A[i] > A[i-1] {
			C += S / A[i-1]
			S = S % A[i-1]
		} else {
			S += C * A[i-1]
			C = 0
		}
	}
	S += C * A[N-1]
	fmt.Fprintf(out, "%d\n", S)
}


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

using namespace std;

using ll = long long;

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

    std::vector<ll> A(N);
    for (ll i = 0; i < N; ++i) {
        cin >> A[i];
    }

    const auto calc_gcd = [](const ll a, const ll b) -> ll {
        if (a <= 0 && b <= 0) { return -1; }

        if (a <= 0) { return b; }

        if (b <= 0) { return a; }

        return std::__gcd(a, b);
    };

    std::vector<ll> right(N, -1);
    right[N - 1] = -1;
    for (ll i = N - 2; i >= 0; --i) {
        right[i] = calc_gcd(right[i + 1], A[i + 1]);
    }

    std::vector<ll> left(N, -1);
    left[0] = -1;
    ll ans = calc_gcd(left[0], right[0]);
    for (ll i = 1; i < N; ++i) {
        left[i] = calc_gcd(left[i - 1], A[i - 1]);
        ans = std::max(ans, calc_gcd(left[i], right[i]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;
void merge(int A[],int n,int left,int mid,int right){
    int n1=mid-left;
    int n2= right-mid;
    for(int i=0;i<n1;i++)L[i]=A[left+i];
    for(int i=0;i<n2;i++)R[i]=A[mid+i];
    L[n1]=R[n2]=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
        }
    }


void mergesort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid = (left+right)/2;
        mergesort(A,n,left,mid);
        mergesort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
    
    int A[MAX],n,i;
    cnt=0;
    cin>>n;
    for(i=0;i<n;i++)cin>>A[i];
    
    mergesort(A,n,0,n);
    for(i=0;i<n;i++){
        if(i)cout << " ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
    
    
    
}




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

using namespace std;

template <typename T, typename U>
string zpad(T n, U k) {
  ostringstream ss;
  ss << setw(k) << setfill('0') << n;
  string s(ss.str());
  return s;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = 0;
  for (int i = 0; i < 1000; i++) {
    string pass = zpad(i, 3);
    bool f1 = 0, f2 = 0;
    string ss = s;
    for (auto&& c : ss) {
      if (!f1 && pass[0] == c) {
        f1 = 1;
        c = '_';
      };
      if (f1 && !f2 && pass[1] == c) {
        f2 = 1;
        c = '_';
      };
      if (f2 && pass[2] == c) {
        ans++;
        // cerr << pass << endl;
        break;
      };
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
const int mx=123456;
#define ll long long
#define p push_back
#define ff first
#define ss second
ll n ;
int main(){
    string s;
    string t;
    cin>>s>>t;
    n=s.size();
    for(int i=0;i<n;i++){
        string te;
        for(int j=i;j<i+n;j++){
            te+=s[j%n];
        }
        if(te==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  string s,t;
  cin>>s>>t;
  cout<<t<<s;
}

Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

//累乗(aのk乗)
ll matpow(ll a,int k){
    ll dp=1,mt=a;
    while(k>0){
        if(k & 1)dp=(dp*mt)%mod;
        mt=(mt*mt)%mod;
        k/=2;
    }
    return dp;
}

int main(){
    int N = 3; ll K; scanf("%lld", &K);
    ll ans = K;
    vec dp(K+1); dp[K]=1;
    for(int i=K-1; i>0; i--){
        dp[i] = matpow(K/i, N);
        ll res = 0;
        FOR(j, 2, K/i+1){
            res = (res + dp[i*j]) % mod;
        }
        dp[i] = (dp[i] - res + mod) % mod;
        ans = (ans + i * dp[i]) % mod; 
    }
    printf("%lld\n", ans);
}

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

int main(){
  int N;
  int d[110];
  cin >> N;
  for(int i= 0;i<N;i++){
    cin >> d[i];
  }
  
  int num[110] = {0};
  for(int i = 0;i<N;i++){
    num[d[i]]++;
  }
  int res = 0;
  for(int i= 1;i<=100;i++){
    if(num[i]){
      res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3596
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <int,int> cnt;
    int n,m; cin>>n; 
    while (n--){
        int a; cin>>a;
        cnt[a]++;
    } cin>>m;
    bool ok=true;
    while (m--){
        int a; cin>>a;
        cnt[a]--;
        if (cnt[a]<0) ok=false;
    }
    cout << (ok==true?"YES":"NO") << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 16056
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int total = 0;
		for(int i = 1;i <= n;i++) {
		    int sum = 0;
		    int tmp = i;
		    while(tmp > 0) {
		        sum += tmp % 10;
		        tmp /= 10;		        
		    }
		    
		    if(sum >= a && sum <= b) total += i;
		}
		
		System.out.println(total);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

using namespace std;
int K,even,odd,ans;

int main(){
    cin >> K;
    even=K/2;
    if(K%2==1){
        odd=K/2+1;
    }
    else{
        odd=even;
    }
    ans = even*odd;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int s = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = s <= w;
        String result = judge ? "unsafe" : "safe";

        // 出力
        System.out.println(result);
    }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<bool> row(H, 0);
  vector<bool> col(W, 0);
  vector<vector<char>> date(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> date.at(i).at(j);
      if (date.at(i).at(j) == '#') {
        row.at(i) = 1;
        col.at(j) = 1;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    if (row.at(i)) {
      for (int j = 0; j < W; j++) {
        if (col.at(j)) cout << date.at(i).at(j);
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt();
        System.out.printf("a %s b\n",a == b ? "==" : a > b ? ">" : "<");
        sc.close();
    }

}

Measured memory_bytes: 26072
#include <iostream>
#include <cstdio>
#include <string>
#include <bits/stdc++.h>
#include <set>
#include <list> //list<???> a; a.push_back ,insert(追加したい要素),a.sort(),参照できない
#include <vector> //vector<???> a; a.push_back,sort(a.begin(),a.end());a[i]
//配列 int a[N];a[i]=追加したい要素;sort(a,a+N);a[i]
const int MOD = 1e9+7;
using namespace std;
typedef long  ll;
#define rep(i,n) for(int i=0;i<(n);i++)


//using namespace std;
//


int main(){
  int A,B;cin>>A>>B;
  if(A==B){
    cout<<"Draw"<<endl;
  }else if(A==1 && A!=B){
    cout<<"Alice"<<endl;
  }else if(B==1 && B!=A){
    cout<<"Bob"<<endl;
  }else if(A<B){
    cout<<"Bob"<<endl;
  }else if(B<A){
    cout<<"Alice"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll r, c, n;
    cin >> r >> c >> n;
    vector<pll> syujo;
    rep(i,n){
        ll x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        bool b11 = (x1 == 0 || x1 == r), b12 = (y1 == 0 || y1 == c);
        bool b21 = (x2 == 0 || x2 == r), b22 = (y2 == 0 || y2 == c);
        if ((b11||b12)&&(b21||b22)){
            ll z1, z2;
            if (b11){
                if (x1==0){
                    z1 = 2 * (r + c) - y1;
                }
                else{
                    z1 = r + y1;
                }
            }
            else{
                if (y1==0){
                    z1 = x1;
                }
                else{
                    z1 = 2 * r + c - x1;
                }
            }
            if (b21){
                if (x2==0){
                    z2 = 2 * (r + c) - y2;
                }
                else{
                    z2 = r + y2;
                }
            }
            else{
                if (y2==0){
                    z2 = x2;
                }
                else{
                    z2 = 2 * r + c - x2;
                }
            }
            syujo.eb(mp(z1, i));
            syujo.eb(mp(z2, i));
        }
    }
    int m = syujo.size();
    if (m==0){
        cout << "YES" << ENDL;
        return 0;
    }
    sort(all(syujo));
    //隣接してたら消す。xyxyみたいな並びがなければOK。
    //隣接要素がどこかにある。そこから左右に見て同じだけ取る。
    //()の対応みたく考えられそう。
    //１周するやつも同じ感じで考えればよい
    set<int> app;
    vii ap2;
    rep(i,m){
        if (app.count(syujo[i].S)==0){
            ap2.eb(syujo[i].S);
            app.insert(syujo[i].S);
        }
        else{
            if (ap2.back()==syujo[i].S){
                ap2.pop_back();
            }
            else{
                cout << "NO" << ENDL;
                return 0;
            }
        }
    }
    cout << "YES" << ENDL;
}

Measured memory_bytes: 8684
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	vector<unsigned long long> a(n + 1), aa(n + 1), aaa(n);
	rep(i, n) {
		cin >> aaa[i];
		a[i + 1] = a[i] + aaa[i];
	}
	repr(i, n - 1) {
		aa[i] = aa[i + 1] + aaa[i];
	}
	unsigned long long ans = LINF;
	rep1(i, n - 1) {
		ans = min(ans, max(aa[i], a[i]) - min(a[i], aa[i]));
	}
	cout << ans << endl;
	Please AC;
}


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

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

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

    int X,A,B;
    cin >> X >> A >> B;

    if(A >= B) cout << "delicious" << endl;
    else if(B-A <= X) cout << "safe" << endl;
    else cout << "dangerous" << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		int x = i * 1.08;
		if (x == n) {
			cout << i << endl;
			return 0;
		}
	}









	cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod=1e9+7;         
const int N=2e3+4;         
ll dp[N][N];
int main()                  
{
    int n,m;
    scn(n);scn(m);
    int a[n],b[m];
    rep(i,1,n+1)
    scn(a[i]);
    rep(i,1,m+1)
    scn(b[i]);
    //dp[0][0]=1;
    rep(i,1,n+1)
    {
        rep(j,1,m+1)
        {
            ll val=(dp[i-1][j]+dp[i][j-1])%mod;
            dp[i][j]=(val-dp[i-1][j-1]+mod)%mod;
            if(a[i]==b[j])
            dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
        }
    }
    dp[n][m]=(dp[n][m]+1)%mod;
    lpri(dp[n][m]);
    return 0;   
}

Measured memory_bytes: 31616
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();
    int d[] = new int[k];

    for (int i = 0; i < k; i++) {
      d[i] = sc.nextInt();
    }

    int n_max = 100000;

    for (int i = n; i < n_max; i++) {
      String nStr = String.valueOf(i);

      boolean isInclude = false;
      for (int j = 0; j < d.length; j++) {
        String dStr = String.valueOf(d[j]);
        if (nStr.contains(dStr)) {
          isInclude = true;
          break;
        }
      }

      if (!isInclude) {
        System.out.println(i);
        break;
      }
    }
  }
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



//#define int int64_t
signed main()
{
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i];
	vector<int> ans(n);
	int sum{};
	int halfsum{};

	//editorialのやり方
	for(int i = 0; i < n; ++i){
		//全体の和と奇数のダムの和
		sum+=a[i];
		if(i&1) halfsum += a[i];
	}
	//最初のダム
	ans[0]=sum - 2*halfsum;
	//残りを漸化式で
	for(int i = 0; i < n-1; ++i){
		ans[i+1] = 2*a[i] - ans[i];
	}

	for(int i = 0; i < n; ++i){
		cout << ans[i] << '\n';
	}

}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll a,b;
    cin >> a >> b;
    if(a>b){
        swap(a,b);
    }
    if(a==1){
        if(b==1)cout << 1 << endl;
        else cout << b-2 << endl;
    }else{
        cout << (a-2)*(b-2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define Rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Rep2(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)
#define POS(i,j) ((i)*w+(j))

char *board;
int h,w;

void SwapChar(char* v1,char* v2){
    char sw = *v1;
    *v1=*v2;
    *v2=sw;
}

int func(int i,int j){
  Rep(k,h) if(board[POS(k,i)]!=board[POS(h-1-k,j)]) return 0;
  return 1;
}

int calcCol(){
  int flag[16];
  Rep(i,w) flag[i]=0;
  int useCenter=0;
  Rep(i,w){
    if(flag[i]) continue;
    Rep2(j,i+1,w-1){
      if(flag[j]) continue;
      if(func(i,j)){
		flag[i]=1;
		flag[j]=1;
		break;
      }
    }
    if(!flag[i]){
      if(w%2==0 || useCenter) return 0;
      Rep(j,h-1-j){
		if(board[POS(j,i)]!=board[POS(h-1-j,i)]) return 0;
      }
      useCenter=1;
      flag[i]=1;
    }
  }
  return 1;
}

void swapRow(int a,int b){
  Rep(i,w) SwapChar(&board[POS(a,i)],&board[POS(b,i)]);
}

int loopRow(int d){
  if(d>=h-1-d) return calcCol();
  Rep2(i,d+1,h-1-d){
    if(h%2==1 && i==h/2) continue;
    swapRow(i,h-1-d);
    if(loopRow(d+1)) return 1;
    swapRow(i,h-1-d);
  }
  return 0;
}

int calc(void){
  if(h%2==0) return loopRow(0);
  int center=h/2;
  Rep(i,h){
    swapRow(i,center);
    if(loopRow(0)) return 1;
    swapRow(i,center);
  }
  return 0;
}

int main(){
  scanf("%d%d",&h,&w);
  board=(char *)malloc(sizeof(char)*(h*w+1));
  Rep(i,h) scanf("%s",board+POS(i,0));
  printf("%s\n",calc()?"YES":"NO");
  free(board);
  return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int d;
  int a;
  vector<bool> S(N, true);
  for(int i = 0; i < K; i++){
    cin >> d;
    for(int i = 0; i < d; i++){
      cin >> a;
      S.at(a-1) = false;
    }
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(S.at(i)){
      count ++;
    }
  }
  cout << count << endl;
}


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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

const Int INF = 1e15;
Int a,e,s,r;
const Int MAX = 111;
Int dp[MAX][MAX];
Int calc(Int p,string x,string y){
  Int n=x.size(),m=y.size();
  x=x.substr(p)+x.substr(0,p);  
  x+='%';y+='^';

  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)         
      dp[i][j]=INF; 
  
  dp[0][0]=0; 
  for(Int i=0;i<=n;i++){
    for(Int j=0;j<=m;j++){
      chmin(dp[i+1][j+1],dp[i][j]+(x[i]==y[j]?0:r));
      chmin(dp[i+1][j],dp[i][j]+(i<n-p?e:e-s));
      chmin(dp[i][j+1],dp[i][j]+a);      
    }
  }
  return dp[n][m];
}

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

  string x,y;
  while(cin>>x,x!="#"){
    cin>>y;
    //!!!!gyaku!!!!
    cin>>a>>e>>r>>s;
  
    Int n=x.size();
    Int ans=INF;
    for(Int p=0;p<n;p++)
      chmin(ans,s*p+calc(p,x,y));
    
    cout<<ans<<endl;          
  }
  
  return 0;
}



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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  const int vmax = 100010;

  int n, wlim;
  cin >> n >> wlim;

  vi w(n), v(n);
  rep(i, 0, n){
    cin >> w[i] >> v[i];
  }

  vvi dp(n+1, vi(vmax, inf));
  dp[0][0] = 0;
  rep(i, 0, n){
    rep(j, 0, vmax){
      chmin(dp[i+1][j], dp[i][j]);
      if(j+v[i] < vmax) chmin(dp[i+1][j+v[i]], dp[i][j]+w[i]);
    }
  }

  int ans = 0;
  rep(i, 0, vmax) if(dp[n][i] <= wlim) ans = i;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80256
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(K) : #108-A
    x = K//2
    if K%2==0 :
        return x**2
    else :
        y = x+1
        return x*y
# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    return int(line)

def main():
    n = readQuestion()
    answer = solve(n)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	private double x, y;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			double x1 = scan.nextDouble();
			double y1 = scan.nextDouble();
			double x2 = scan.nextDouble();
			double y2 = scan.nextDouble();
			double x3 = scan.nextDouble();
			double y3 = scan.nextDouble();
			double xp = scan.nextDouble();
			double yp = scan.nextDouble();
			
			double[] b12 = {x2 - x1, y2 - y1};
			double[] b13 = {x3 - x1, y3 - y1};
			double[] b1p = {xp - x1, yp - y1};
			
			matrix(b12[0], b13[0], b12[1], b13[1], b1p[0], b1p[1]);
			
			//debug();
			if (this.x < 0 || this.y < 0) {
				System.out.println("NO");
				continue;
			}
			
			double[] b21 = {x1 - x2, y1 - y2};
			double[] b23 = {x3 - x2, y3 - y2};
			double[] b2p = {xp - x2, yp - y2};
			
			matrix(b21[0], b23[0], b21[1], b23[1], b2p[0], b2p[1]);
			
			//debug();
			if (this.x < 0 || this.y < 0) {
				System.out.println("NO");
				continue;
			}
			
			System.out.println("YES");
		}
	}
	
	private void debug() {
		System.out.println(x + " " + y);
	}
	
	private void matrix(double a, double b, double c, double d, double e, double f) {
			if (a * d - b * c != 0) {
				this.x = (e * d - b * f) / (a * d - b * c);
				this.y = (a * f - e * c) / (a * d - b * c);
			}else {
				this.x = -1;
				this.y = -1;
			}
	}

}

Measured memory_bytes: 23164
#include<iostream>
using namespace std;
int main()
{
	long long a,b,c,d,ans=0;
	cin>>a>>b>>c>>d;
	for(long long i=0;i<=a;i++)
		for(long long j=0;j<=b;j++)
			for(long long k=0;k<=c;k++)
			{
		//		cout<<500*a+100*b+50*c<<endl;
				if(500*i+100*j+50*k==d) 
					ans++;
			}
				
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
### main

n = gets.strip.to_i

n.times do
  x, y, bn, pn = gets.strip.split(' ').map{|s| s.to_i}

  if bn >= 5 && pn >= 2
    cost = (x * bn + y * pn) * 4 / 5
  else
    cost0 = x * bn + y * pn
    bn1 = [bn, 5].max
    pn1 = [pn, 2].max
    cost1 = (x * bn1 + y * pn1) * 4 / 5
    cost = [cost0, cost1].min
  end
  puts cost
end

Measured memory_bytes: 6112
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; int i; bool used; };
 
int MOD = 1000000007;

int main() {
	int d, n, b; cin >> d >> n >> b;
	vector<int> p(n), h(n);
	for (int i = 0; i < n; i++) cin >> p[i] >> h[i];
	double ans = 1000000;
	for (int t = 1; t <= b + 1; t++) {
		double l = (double)d / t;
		double lb = 0, ub = 1000000;
		for (int k = 0; k < 100; k++) {
			double vy = (lb + ub) / 2;
			double vx = l / (vy * 2);
			bool flag = true;
			for (int i = 0; i < n; i++) {
				double x = fmod(p[i], l);
				double y = x * vy / vx - x * x / (vx * vx * 2);
				if (y < h[i]) flag = false;
			}
			if (flag) ub = vy;
			else lb = vy;
		}
		double vy = max(lb, sqrt(l / 2)), vx = l / (vy * 2);
		ans = min(ans, sqrt(vx * vx + vy * vy));
	}
	printf("%.10f\n", ans);
} 

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  if(n > 81) cout << "No" << endl;
  else
  {
    for(int i = 1; i < 10; i++)
    {
      if(n%i == 0 && (n / i) < 10)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
      cout << "No" << endl;
  }
  
  return 0;
}


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

int main(){
  int  n, d;
  cin >> n >> d;
  
  int mon = 1 + d * 2;
  int ans = n / mon;
  
  if(n % mon == 0){
    cout << ans;
    return 0;
  }
  cout << ans + 1;
  return 0;
}

Measured memory_bytes: 256
/*
 * Matheus Oliveira
 * 09:20:02 12/04/2020
 * d.cpp
*/

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

#define EPS
#define INF
#define MAXN 14040
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) printf("%s: ", #x); for(int i = bg; i < ed; i++) printf("%d%c", x[i], (i == ed-1) ? '\n' : ' ');

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

char inp[MAXN];
int r[MAXN], g[MAXN], b[MAXN];

char getLast(char f, char s) {
	if('R' != f and 'R' != s) return 'R';
	if('G' != f and 'G' != s) return 'G';
	return 'B';
}

int main() {
	char last;
	int n, dist;

	scanf("%d", &n);
	getchar();
	
	scanf("%s", inp);
	ll ans = 0;

	for(int i = 0; i < n; i++) {
		if(i == 0) {
			r[i] = (inp[i] == 'R');
			g[i] = (inp[i] == 'G');
			b[i] = (inp[i] == 'B');
		}
		else {
			r[i] = r[i-1] + (inp[i] == 'R');
			g[i] = g[i-1] + (inp[i] == 'G');
			b[i] = b[i-1] + (inp[i] == 'B');
		}
	}

	for(int i = 0; i < n; i++) {
		for(int j = i+1; j < n; j++) {
			if(inp[i] != inp[j]) {
				last = getLast(inp[i], inp[j]);
				dist = j - i;

				if(last == 'R') ans += ((ll) (r[n-1] - r[j]) - (inp[j+dist] == 'R'));
				if(last == 'G') ans += ((ll) (g[n-1] - g[j]) - (inp[j+dist] == 'G'));
				if(last == 'B') ans += ((ll) (b[n-1] - b[j]) - (inp[j+dist] == 'B'));
			}
		}
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3884
a, b = map(int, input().split())
ans = 0

# 最後の一個 + 追加の分
# a + (a-1) * ans >= b

sub = b - a

if sub % (a-1) == 0:
    ans = sub // (a-1)
else:
    ans = sub // (a-1) + 1

print(ans + 1)


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int r = int.Parse(Console.ReadLine().Trim());
            Console.WriteLine(r * r);
        }
    }
}


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

int main(){
	int n; cin >> n;
	set<string> str;
	for(int i=0; i<n; i++){
		string command; cin >> command;
		string s; cin >> s;
		if(command=="insert"){
			str.insert(s);
		}
		else{
			if(str.find(s) != str.end()){
				cout << "yes" << endl;
			}
			else
				cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 32148
let input = require("fs").readFileSync("/dev/stdin", "utf8")

function main({ input, load, yesno, math_sum }) {

    const [N] = load()
    const A = load(N)

    let Ai_max = 0
    for(const a of A) if(a > Ai_max) Ai_max = a

    const nums = new Array(Ai_max + 1).fill(0)

    for(const a of A) nums[a]++

    for(let i = 1; i <= Ai_max; i++) {
        if(!nums[i]) continue
        for(let j = i * 2; j <= Ai_max; j += i) {
            nums[j] = 0
        }
    }

    console.log(nums.filter(n => n === 1).length)
}

let inputs = input.split(/[\s\n]/)
main({
    input,
    yesno: value => value ? 'Yes' : 'No',
    load(rows = 1, cols = 1, is_number = true) {
        const length = rows * cols
        let result = inputs.splice(0, length)
        if(is_number) result = result.map(Number)
        if(cols > 1) {
            const arrays = new Array(cols)
            for(let col = 0; col < cols; col++) {
                arrays[col] = new Array()
                for(let row = 0; row < rows; row++) {
                    arrays[col].push(result[row * cols + col])
                }
            }
            result = arrays
        }
        return result
    },
    inifinite_loop_preventer() {
        throw new Error("Infinite loop")
    },
    math_sum(numbers) {
        return numbers.reduce((acc, cur) => acc + cur, 0)
    },
})


Measured memory_bytes: 70392
#!/usr/local/gnu/bin/bash
read n m c
read -a b
v=0
for i in `seq $n`
do
    read -a a
    x=0
    for j in `seq 0 $((m-1))`
    do
        x=$((x+a[j]*b[j]))
    done
    ((x+c>0)) && v=$((v+1))
done
echo $v


Measured memory_bytes: 608
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		
		for(int n = 1; n <= a; n++) {
			int num = 0;
			int count = (int)(Math.sqrt(n)/Math.sqrt(6) + 1);
			final double log = Math.sqrt(n);
			for(int x = 1; x <= count; x++) {
				int yO = (int)(((n - x*x)/(2*x+3))+ 1);
				for(int y = x; y <= yO; y++) {
					int D = 2*(x + y) - 4*(x*x + y*y + x*y - n);
					if(D < 0) {
						break;
					}
					for(int z = y; z <= log; z++) {
						if(x*x + y*y + z*z + x*y + y*z + z*x == n) {
							if(x == y) {
								if(y == z) {
									num++;
								} else {
									num += 3;
								}
							} else if(y == z) {
								num += 3;
							} else if(z == x) {
								num += 3;
							} else {
								num += 6;
							}
						}
					}
				}
			}
			System.out.println(num);
		}
	}

}


Measured memory_bytes: 30032
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#include <bits/stdc++.h>
#define pii pair<string,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e5+5;
const double PI=acos(-1);
const double e=2.718281828459;

map<string,int>MP;
string s;
vector<pii>v;

int main()
{
    int n,mx=-1,j;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        cin>>s;
        mx=max(mx,++MP[s]);
    }
    for(auto it=MP.begin();it!=MP.end();it++){
        j=it->second;
        if(j==mx){
            v.pb(mp(it->first,j));
        }
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++){
        cout<<v[i].f<<endl;
    }
    return 0;
}


Measured memory_bytes: 29424
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C
 */
#include <iostream>
#include <string>
#include <vector>

using namespace std;

constexpr int
getindex(const char c)
{
    return c == 'T' ? 4 : c == 'G' ? 3 : c == 'C' ? 2 : 1;
}

int
gethash(const string &s, const int st)
{
    int hash = 0;
    for (int i = st; i < s.length(); i++) {
        hash = getindex(s.at(i)) + (hash * 5);
    }
    return hash;
}

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

    vector<bool> dict(244140625);
    for (int i = 0; i < n; i++) {
        string line;
        getline(cin, line);

        if (line[0] == 'f') {
            cout << (dict[gethash(line, 5)] ? "yes" : "no") << endl;
        } else {
            dict[gethash(line, 7)] = true;
        }
    }

    return 0;
}

Measured memory_bytes: 32680
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

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

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        int a = Integer.valueOf(arr01[0]);
        int b = Integer.valueOf(arr01[1]);
        int c = Integer.valueOf(arr01[2]);

        int cnt = 0;

        //        System.out.println(a + " " + b + " " + c);

        if (c >= a) {
            cnt += a;
            c -= a;
            a = 0;
        } else {
            cnt += c;
            a -= c;
            c = 0;

        }

        //        System.out.println(a + " " + b + " " + c + " " + cnt);

        if (c >= b) {
            //cnt += c;
            cnt += b * 2;
            c -= b;
            b = 0;

            if (c > 0) {
                cnt += 1;
            }
            //            c = 0;
            //            b = 0;
        } else {
            cnt += b;
            cnt += c;
        }

        //        System.out.println(a + " " + b + " " + c + " " + cnt);
        System.out.println(cnt);

    }

}


Measured memory_bytes: 23124
#include<stdio.h>
#define MAX 2000000
 
int n;
int A[MAX+1];

void swap(int *,int *);
void maxHeap(int);
 
int main(){

  int i;
   
  scanf("%d",&n);
 
  for(i = 1;i <= n;i ++)
    {
      scanf("%d",&A[i]);
    }
  
  for(i = n / 2; i >= 1;i --) maxHeap(i);
 
  for(i = 1; i <= n; i++)
    {
      printf(" %d",A[i]);
    }
  printf("\n");
 
  return 0;
}

void swap(int *a, int *b){

  int temp;
  
  temp = *a;
  *a = *b;
  *b = temp;
}

void maxHeap(int i){

  int l, r, largest;

  l = 2 * i;
  r = 2 * i + 1;
 
  if(l <= n && A[l] > A[i])largest = l;

  else largest = i;

  if(r <= n &&A[r] > A[largest])largest = r;
 
  if(largest != i)
    {
      swap(&A[i], &A[largest]);
      maxHeap(largest);
    }
  
}

Measured memory_bytes: 2556
t1,t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1,b2 = map(int, input().split())

if a1 > b1 and a2 > b2:
    print(0)
    exit()

if b1 > a1 and b2 > a2:
    print(0)
    exit()

if a1 < b1 and a2 > b2:
    a1,b1 = b1,a1
    a2,b2 = b2,a2 


diff1 = abs(a1-b1)
diff2 = abs(a2-b2)

first_dist = diff1*t1
second_dist = diff2*t2

down = second_dist - first_dist
if down < 0:
    print(0)
    exit()
if down == 0:
    print('infinity')
    exit()

if first_dist%down != 0:
    ans = (first_dist//down) * 2 + 1
else:
    ans = ((first_dist//down)-1) * 2 + 2

print(ans)

Measured memory_bytes: 62060
"""S,W = map(int,input().split())
if S<=W:
    print('unsafe')
else:
    print('safe')

N = int(input())
S = [input() for i in range(N)]
print(len(set(S)))



S = list(input())[::-1]
N = len(S)
M = [(int(S[i])*10**i)%2019 for i in range(N)]
SS = [M[0]]
for i in range(1,N):
    
    SS.append((SS[-1]+M[i])%2019)
count = [0]*2019
for i in range(N):
    count[SS[i]] += 1

ans = 0
for c in range(len(count)):
    if c==0:
        ans += (count[c] * (count[c] + 1)) // 2
    ans += (count[c] * (count[c] - 1)) // 2

print(ans)
"""
A,B,C,D = map(int,input().split())
f = True
while True:
    if C-B>0:
        C-=B
    else:
        f = True
        break
    if A-D>0:
        A -= D
    else:
        f = False
        break
    
if f:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

ll C[51][51];

ll COM(int n, int k) {
	if(k < 0 || k > n) return 0;
	if(k == 0 || k == n) return 1;
	if(C[n][k] != -1) 
		return C[n][k];
	return C[n][k] = COM(n-1,k-1) + COM(n-1,k);
}

void precal() {
	rep(i,0,51) rep(j,0,51) C[i][j] = -1;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	precal();
	int n, a, b;
	cin >> n >> a >> b;
	vl v(n);
	rep(i,0,n) {
		cin >> v[i];
	}
	sort(v.rbegin(), v.rend());
	if(v[0] == v[a-1]) {
		int c = a;
		rep(i,a,n) {
			if(v[0] == v[i]) {
				c = i+1;
			} else {
				break;
			}
		}
		int m = min(c,b)+1;
		ll cnt = 0;
		rep(i,a,m) {
			cnt += COM(c,i);
		}
		cout << fixed << setprecision(6) << (double)v[0] << '\n';
		cout << cnt << '\n';
	} else {
		int c = 0;
		int k = 0;
		rep(i,0,n) {
			if(v[i] == v[a-1]) {
				c++;
				if(i<=a-1) {
					k++;
				}
			}
		}
		ll ret = 0;
		rep(i,0,a) {
			ret += v[i];
		}
		ll cnt = COM(c,k);
		cout << fixed << setprecision(6) << (double)ret/a << '\n';
		cout << cnt << '\n';
	}
	return 0;
}


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

using namespace std;

const int MAX_N = 2e5 + 200, mod = 1e9 + 7;

typedef long long ll;

int n, m, ai[MAX_N], bi[MAX_N], nodes[MAX_N << 2], pts[MAX_N], lft[MAX_N], rig[MAX_N], pcnt;
struct node
{
    int x, y;
    bool operator<(const node &rhs) const { return x < rhs.x || (x == rhs.x && y > rhs.y); }
    bool operator==(const node &rhs) const { return x == rhs.x && y == rhs.y; }
} nds[MAX_N];
vector<int> mp;

int ripe(int x) { return lower_bound(mp.begin(), mp.end(), x) - mp.begin() + 1; }

inline int lowbit(int x) { return x & -x; }

void update(int x, int d)
{
    for (; x <= mp.size(); x += lowbit(x))
        nodes[x] = (0LL + nodes[x] + d) % mod;
}

int query(int x, int ret = 0)
{
    for (; x; x -= lowbit(x))
        ret = (0LL + nodes[x] + ret) % mod;
    return ret;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    for (int i = 1; i <= m; i++)
        scanf("%d", &bi[i]);
    for (int i = 1; i <= n; i++)
        if (ai[i] >= bi[1] && ai[i] <= bi[m])
        {
            pts[++pcnt] = ai[i];
            int pos = lower_bound(bi + 1, bi + 1 + m, ai[i]) - bi;
            nds[pcnt] = node{ai[i] - bi[pos - 1], bi[pos] - ai[i]};
            mp.push_back(bi[pos] - ai[i]);
        }
    sort(mp.begin(), mp.end()), mp.erase(unique(mp.begin(), mp.end()), mp.end());
    for (int i = 1; i <= pcnt; i++)
        nds[i].y = ripe(nds[i].y);
    sort(nds + 1, nds + 1 + pcnt), pcnt = unique(nds + 1, nds + 1 + pcnt) - nds - 1;
    int ans = 1;
    for (int i = 1; i <= pcnt; i++)
    {
        int sum = (query(nds[i].y - 1) + 1) % mod;
        ans = (0LL + sum + ans) % mod, update(nds[i].y, sum);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 7672
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
int main(){
  ll n,k;
  cin >> n >> k;
  ll a[n];
  REP(i,n) cin >> a[i];
  bool dp[k+1];
  REP(i,k+1){
    bool temp = false;
    REP(j,n){
      if(i-a[j]>=0&&dp[i-a[j]]==false) temp=true;
    }
    dp[i]=temp;
  }
  if(dp[k]){
    cout << "First" << endl;
  }else{
    cout << "Second" << endl;
   }
  return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	elems, err := nextInts(n, sc)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		nodeId := i + 1
		key := elems[i]
		parentId := getParentId(nodeId, elems)
		leftKey := getLeftKey(nodeId, elems)
		rightKey := getRightKey(nodeId, elems)
		printNode(nodeId, key, parentId, leftKey, rightKey)
	}
}

func getParentId(nodeId int, elems []int) *int {
	if nodeId == 1 {
		return nil
	}
	return &elems[nodeId/2-1]
}

func getLeftKey(nodeId int, elems []int) *int {
	if nodeId*2-1 < len(elems) {
		return &elems[nodeId*2-1]
	} else {
		return nil
	}
}

func getRightKey(nodeId int, elems []int) *int {
	if nodeId*2 < len(elems) {
		return &elems[nodeId*2]
	} else {
		return nil
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(n int, sc *bufio.Scanner) ([]int, error) {
	rs := make([]int, n)
	for i, _ := range rs {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		rs[i] = x
	}
	return rs, nil
}

func printNode(nodeId int, key int, parentId *int, leftKey *int, rightKey *int) {
	fmt.Printf("node %d: key = %d, ", nodeId, key)
	if parentId != nil {
		fmt.Printf("parent key = %d, ", *parentId)
	}
	if leftKey != nil {
		fmt.Printf("left key = %d, ", *leftKey)
	}
	if rightKey != nil {
		fmt.Printf("right key = %d, ", *rightKey)
	}
	fmt.Print("\n")
}



Measured memory_bytes: 1100