akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

const long long MOD = 1e9+7;

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    sort(h.rbegin(), h.rend());

    for (int i = 0; i < min(n, k); i++) {
        h.at(i) = 0;
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += h.at(i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

ans = [[0 for j in range(w)] for i in range(h)]

x = 0
y = 0
f = True
for i in range(n):
    for j in range(a[i]):
        ans[y][x] = str(i+1)
        if f:
            x += 1
        else:
            x -= 1
        if x == w:
            x = w-1
            y += 1
            f = False
        if x == -1:
            x = 0
            y += 1
            f = True

for i in range(h):
    print(" ".join(ans[i]))




Measured memory_bytes: 74348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int r;
    cin >> r;
    
    cout << r * r << endl;

    return 0;
}

Measured memory_bytes: 892
l=[]
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.append(int(input()))
l.sort()
l.reverse()
print l[0]
print l[1]
print l[2]

Measured memory_bytes: 4224
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

did = "-" * k
ans = 0
for i in t:
    if i == "r":
        if did[-k] == "p":
            did += "-"
        else:
            did += "p"
            ans += p
    elif i == "s":
        if did[-k] == "r":
            did += "-"
        else:
            did += "r"
            ans += r
    else:
        if did[-k] == "s":
            did += "-"
        else:
            did += "s"
            ans += s

print(ans)

Measured memory_bytes: 9360
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    S=input()

    o=list(S)
    r=list(reversed(o))
    cnt=0
    for i in range(len(S)//2):
        if o[i]!=r[i]:
            cnt += 1
    print(cnt)


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

# %%
# from atcoder_test import doTest
# doTest("abc147","b",main)

Measured memory_bytes: 3060
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, y] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const res = _ => {
  for (let i = 0; i <= n; i++) {
    for (let j = 0; j <= n - i; j++) {
      const total = i * 10000 + j * 5000 + (n - i - j) * 1000
      if (total === y) return `${i} ${j} ${n - i - j}`
    }
  }
  return '-1 -1 -1'
}

console.log(res())


Measured memory_bytes: 7372
import java.util.*
import java.math.*
import java.lang.Math.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }
private val MOD = 1e9.toLong()+7


fun greedyBitFS(item: List<Pair<Int, Int>>, bonus: List<Int>, LowLimit: Int): Int {
    val N = item.size
    var res = Int.MAX_VALUE;
    for (p in 0 until (0b01 shl N)) {
        var ptn = p
        var scr = 0
        var cnt = 0
        var lv = -1
        for(i in 0 until N) {
            val vi = item[i].first
            val ci = item[i].second
            if ((ptn and 0b01) == 1) {
                scr += vi * ci + bonus[i]
                cnt += ci;
                if (scr >= LowLimit) {
                    res = min(res, cnt)
                }
            } else {
                lv = max(lv, i)
            }
            ptn = ptn shr 1
        }
        if (scr < LowLimit) {
            if (lv >= 0) {
                val v = item[lv].first
                val c = item[lv].second

                val dc = min((LowLimit - scr + v - 1) / v, c - 1)
                if (scr + v*dc >= LowLimit) {
                    res = min(res, cnt + dc)
                }
            }
        }
    }
    return res
}


fun main(args: Array<String>) {
    val (D,G) = readListInt()
    val item = Array<Pair<Int, Int>>(D){ Pair(0,0) }
    val C = Array<Int>(D){0}

    for(i in 0 until D) {
        val pc = readListInt()
        item[i] = Pair(100*(i+1), pc[0])
        C[i] = pc[1]
    }

    val ans = greedyBitFS(item.toList(), C.toList(), G)

    println(ans)
}


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


main(){
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    for(int i=1; i<=N; i++){
        int sum = 0, n = i;
        for(int j=0; j<5; j++){
            sum += n%10;
            n /= 10;
        }
        if(A<=sum && sum<=B) ans += i;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout <<"Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    int n, k;
    int ans = 1;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            ans *= k;
        }
        else
        {
            ans *= k - 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		String[] s = {"a","b","c","d","e","f","g",
				"h","i","j","k","l","m","n",
				"o","p","q","r","s","t","u",
				"v","w","x","y","z"};
		long n = sc.nextLong()-1;
		ArrayList<Long> list = new ArrayList<>();

		while(n >= 26) {
			list.add(n%26);
			n = n/26 - 1;
		}
		list.add(n);
		for(int i = list.size()-1; i >= 0; i--) {
			long a = list.get(i);
			System.out.print(s[(int)a]);
		}
	}
	//1000000000000001


	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

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

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

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32556
package main

import "fmt"

func main() {
	var s, t string
	var a, b int
	var u string
	fmt.Scan(&s,&t )
	fmt.Scan(&a,&b )
	fmt.Scan(&u )
	if s == u{
		a--
	}else if t == u {
		b--
	}
	fmt.Println(a, b)
}

Measured memory_bytes: 512
// ref: https://qiita.com/drken/items/cce6fc5c579051e64fab
// ref: http://b1u3.hateblo.jp/entry/2019/11/19/192551

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

template<typename T>
class unionFind_rw{ // rank and weight
 private:
    vector<uint> par;  // parent
    vector<uint> rank; // rank
    vector<T> cSum_w;   // cumulative weight sum
    
 public:
    unionFind_rw(uint N): par(N), rank(N,(uint)0), cSum_w(N,(T)0) {
        for(uint i=0; i<N; ++i){ par[i]=i; }
    }
    ~unionFind_rw(){}
    
    uint root(uint rhs){
        if(rhs==par[rhs]){ return rhs;
        }      else      { uint ri=root(par[rhs]); cSum_w[rhs]+=cSum_w[par[rhs]]; return par[rhs]=ri; }
    }
    
    bool unite(uint lhs, uint rhs, T w){
        w += cSum_w[lhs];
        w -= cSum_w[rhs];
        uint rL = root(lhs);
        uint rR = root(rhs);
        if(rL==rR){ return false; }
        if(rank[rL]< rank[rR]){ swap(rL, rR); w*=-1;}
        if(rank[rL]==rank[rR]){ ++rank[rL]; }
        par[rR] = rL;
        cSum_w[rR] = w;
        return true;
    }
    
    bool same(uint lhs, uint rhs){
        return root(lhs)==root(rhs);
    }
    
    T diff(uint lhs, uint rhs){
        return cSum_w[rhs] - cSum_w[lhs];
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M; cin >> N >> M;
    class unionFind_rw<int> uf(N);
    
    for(int i=0; i<M; ++i){
        int L, R, D; cin >> L >> R >> D; --L; --R;
        if(uf.same(L, R)){
            int diff = uf.diff(L, R);
            if(diff!=D){ cout << "No" << endl; return 0; }
        }else{
            uf.unite(L, R, D);
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n);

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  for ( j = 2; j <= n; j++ ){
    int key = A[j];
    int i = j - 1;
    while( i > 0 && A[i] > key ){
      A[i+1] = A[i];
      i--;
    }
    A[i+1] = key;

    trace(A, n);
  }

  return 0;
}

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}


Measured memory_bytes: 2068
import java.util.Scanner;

public class Main {

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

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

		int hour = A + B;

		if(hour >= 24)hour -= 24;

		System.out.println(hour);

		sc.close();
	}

}


Measured memory_bytes: 21972
using System;


class MainClass
{
    public static void Main(string[] args)
    {

        int N = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        int ans = 0;

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

            a[j] = int.Parse(s[j]);

        }

        Array.Sort(a);
        int i = 0;
        int nowCnt = 0;
        int nowNum =0;

        while(true)
        {

            ans += 1;


            if(a[i]==nowNum)
            {
                nowCnt += 1;
            }
            else
            {
                nowNum = a[i];
                nowCnt = 1;
            }


            if(nowCnt==a[i])
            {
                ans -= a[i];
            }

            i = i + 1;

            if (i >= N) break;

        }

        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 23004
n = [int(x) for x in input()]
op_cnt = len(n)-1

for i in range (2**op_cnt):
  op = ['-']*op_cnt
  for j in range(op_cnt):
    if ((i >>j)&1):
      op[op_cnt-1-j] ='+'


  formula =''

  for p_n, p_o in zip(n, op+[""]):
    formula += (str(p_n) + p_o)
  if eval(formula) == 7:
    print(formula + "=7")
    exit()
  

Measured memory_bytes: 3060
import itertools

N,M,Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q

for i in range(Q):
  a[i],b[i],c[i],d[i] = map(int, input().split())

listA = list(itertools.combinations_with_replacement(range(1,M+1), N))

tans = 0
ans = 0

for A in listA:
  flg = 0
  for i in range(1,len(A)):
    if A[i-1] > A[i]:
      flg = 1
      break
  if flg == 0:
    tans = 0
    for i in range(Q):
      if A[b[i]-1]-A[a[i]-1] == c[i]:
        tans += d[i]
    if tans>ans:
      ans = tans
print(ans)



Measured memory_bytes: 84996
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int len[100000];

int main() {
	int n, l;
	scanf("%d %d", &n, &l);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &len[i]);
	}
	int pick = -1;
	for (int i = 0; i + 1 < n; ++i) {
		if (len[i] + len[i + 1] >= l) {
			pick = i;
			break;
		}
	}
	if (pick == -1) {
		printf("Impossible\n");
		return 0;
	}

	printf("Possible\n");
	vector<int> ans;
	ans.push_back(pick);
	for (int i = pick - 1; i >= 0; --i) {
		ans.push_back(i);
	}
	for (int i = pick + 1; i + 1 < n; ++i) {
		ans.push_back(i);
	}

	for (int v : vector<int>(ans.rbegin(), ans.rend())) {
		printf("%d\n", v + 1);
	}
	return 0;
}

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

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;//ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,k;
 cin>>n;
 rep(i,0,n){
  cin>>k;
  if(k%2==1)continue;
  if(k%6!=0&&k%10!=0){
   puts("DENIED");
   return 0;
  }
 }
 puts("APPROVED");
 return 0;}

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

int main(){
  int s,result,flag;
  vector<int> data;
  cin >> s;
  data.push_back(s);
  flag=0;
  int i=0;
  while(flag == 0){
    if(data[i]%2==0){
      data.push_back(data[i]/2);
    }
    else{
      data.push_back(data[i]*3+1);
    }
    for(int j=0;j<i;j++){
      if(data[i]==data[j]){
        flag=1;
        result=data[i];
      }
    }
    i++;
  } 
  cout<<i;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n,k;cin>>n>>k;
  vector<ll> a(n),b(k);
  rep(i,n)cin>>a[i];
  rep(i,k)cin>>b[i];
  ll c=0LL,d=0LL;
  ll j=-n+1;
  rep(i,n){
    c+=a[i]*j;
    j+=2;
  }
  j=-k+1;
  rep(i,k){
    d+=b[i]*j;
    j+=2;
  }
  cout<<(c%M)*(d%M)%M;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.141592653589793238

int main() {
	int N;
	cin >> N;
	int var = 0;
	set<int> color;
	rep(i, N) {
		int a;
		cin >> a;
		if (a >= 3200) {
			var++;
		}
		else {
			color.insert(a / 400);
		}
	}
	cout << (color.empty()?1:color.size()) << " " << color.size() + var << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        String ans = "Impossible";
        if(A%3==0||B%3==0||(A+B)%3==0) ans = "Possible";
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static String replace (String s1, int i, String s2) {
		char[] c1 = s1.toCharArray();
		char[] c2 =s2.toCharArray();
		for (int j = 0; j < c2.length; j++)
			c1[i + j] = c2[j];
		return String.valueOf(c1);
	}

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

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		char[] c = br.readLine().toCharArray();
		char[] a = {'a','p','p','l','e'};
		char[] p = {'p','e','a','c','h'};

		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < a.length; j++) {
				if (i + j >= c.length) break;
				if (c[i + j] != a[j]) break;
				if (j == a.length - 1) {
					for (int k = 0; k < p.length; k++)
						c[i + k] = p[k];
					i++;
				}
			}
			for (int j = 0; j < p.length; j++) {
				if (i + j >= c.length) break;
				if (c[i + j] != p[j]) break;
				if (j == p.length - 1) {
					for (int k = 0; k < a.length; k++)
						c[i + k] = a[k];
				}
			}
		}
		System.out.println(String.valueOf(c));

	}

}

Measured memory_bytes: 16868
/*---------------------------------
 *File name: res.cpp
 *Team: 这题太简单啦
 *Author: Snpilola
 *Creation date: 2019-11-10 13:03
 *-------------------------------*/
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define LL long long
#define mkp make_pair
#define PLL pair<LL, LL>
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define Pque priority_queue 
using namespace std;
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int EPS = 1e-6;

char a[maxn][maxn];
LL dp[maxn][maxn];
bool vis[maxn][maxn];

LL dfs(int x, int y){
	if(vis[x][y]) return dp[x][y] % mod;
	if(x == 1 && y == 1) return 1LL;
	vis[x][y] = 1;
	LL up = 0, lef = 0;
	if(a[x - 1][y] == '.') up = dfs(x - 1, y) % mod;
	if(a[x][y - 1] == '.') lef = dfs(x, y - 1) % mod;
	return dp[x][y] = (up + lef) % mod;
}

int main(){
	int h, w;
	scanf("%d %d", &h, &w);
	for(int i = 1; i <= h; ++i)	scanf(" %s", a[i] + 1);
	LL ans = dfs(h, w);
	ans %= mod;
	printf("%lld\n", ans);
}

Measured memory_bytes: 10112
#![allow(unused)]
use std::io::{self, Read};

fn get_stdin() -> String {
    let mut buf = String::new();
    let mut stdin = io::stdin();
    stdin.read_to_string(&mut buf);
    return buf
}

fn to_nums(ss: &str) -> Vec<i32> {
    ss.split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect()
}

fn main() {
    let input = get_stdin();
    let v = to_nums(&input);
    for (i, n) in v.iter().enumerate() {
        if n != &0 {
            println!("Case {}: {}", i + 1, n)
        } else {
            break;
        }
    }
}



Measured memory_bytes: 5032
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    P=LI()
    Q=LI()

    a = 0
    b = 0
    for c,it in enumerate(permutations([i+1 for i in range(N)])):
        if P==list(it):
            a = c
        if Q==list(it):
            b = c
    print(abs(a-b))

if __name__ == '__main__':
    main()

Measured memory_bytes: 41712
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> cnt(n,0);
    vector<vector<int>> vect(n);
    for(int i=0 ; i<m ; i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        vect[x].pb(y);
        cnt[y]++;
    }
    queue<int> q;
    for(int i=0 ; i<n ; i++){
        if(cnt[i]==0){
            q.push(i);
        }
    }
    vector<int> dp(n,0);
    int ans=0;
   
    
    while(!q.empty()){
        int curr=q.front();
        q.pop();
        for(int node:vect[curr]){
            cnt[node]--;
            dp[node]=max(dp[node],1+dp[curr]);
            if(cnt[node]==0)
                q.push(node);
            ans=max(ans,dp[node]);    
        }    
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(int argc, char **argv) {
	int n, m;
	cin >> n >> m;
	char s[m+1];
	while(n--) {
		scanf("%s", s);
		puts(s);
		puts(s);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main()
{
    ll X,K,D;
    cin>>X>>K>>D;
    ll a;
    if(X) a = abs(X)/D;
    else a=0;
    if(K<=a)
    {
        cout<<abs(X)-K*D<<endl;
        return 0;
    }else
    {
        X = abs(X)-a*D;
        K-=a;
    } 
    if(K%2)cout<<abs(X-D)<<endl;
    else cout<<X<<endl;
    return 0;
}


Measured memory_bytes: 3564
x = gets.chomp.to_i

if x <= 599
	puts 8
elsif x <= 799
	puts 7
elsif x <= 999
	puts 6
elsif x<= 1199
	puts 5
elsif x <= 1399
	puts 4
elsif x <= 1599 
	puts 3
elsif x<= 1799
	puts 2
else
	puts 1
end


Measured memory_bytes: 14312
#include<bits/stdc++.h>
using namespace std;
const int N=1<<20;
int pv[N],p1[N],st[N],a[N],t[N],tot;

void side(int u,int v)
{
	pv[tot]=v;
	p1[tot]=st[u];
	st[u]=tot++;
	//printf("u=%d v=%d\n",u,v);
}

void dfs(int u,int mytime)
{
	//printf("u=%d t[u]=%d mytime=%d\n",u,t[u],mytime);
	if(~t[u])return;
	t[u]=mytime;
	for(int i=st[u];~i;i=p1[i])
	{
		dfs(pv[i],mytime);
	}
}

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
	}
	tot=0;
	memset(st,-1,sizeof(st));
	for(int i=0;i<m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		u--,v--;
		side(u,v);
		side(v,u);
	}
	memset(t,-1,sizeof(t));
	for(int i=0;i<n;i++)
	{
		dfs(i,i);
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		//printf("i%d a[i]=%d\n",t[i],t[a[i]]);
		ans+=t[i]==t[a[i]-1];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,m,x,y,dp[5][10010],cnt[200],h;
string a;

int main()
{
	int i;
	cin>>n>>m>>x;
	if(n<m) swap(n,m);
	if(n<x) swap(n,x);
	n==m+x?puts("Yes"):puts("No");
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

//構造体&変数宣言
typedef struct{
  int parent;
  int left;
  int right;
}Tree;

Tree t[MAX];
int num;


//関数宣言
void preParse(int);
void inParse(int);
void postParse(int);
void print(void);

//main
int main(){

  int i,v,l,r;

  scanf("%d",&num);
  for(i = 0; i < num; i++){
    t[i].parent =NIL;
  }

  for(i = 0;i < num; i++){
    scanf("%d %d %d",&v,&l,&r);
    t[v].left = l;
    t[v].right = r;
    if(l != NIL)t[l].parent = v;
    if(r != NIL)t[r].parent = v;
  }

  print();

  return 0;
}


//関数

/*先行順巡回*/
void preParse(int u){

  if(u == NIL)return;
  printf(" %d",u);
  preParse(t[u].left);
  preParse(t[u].right);
}

/*中間順巡回*/
void inParse(int u){

  if(u == NIL)return;
  inParse(t[u].left);
  printf( " %d",u);
  inParse(t[u].right);
}

/*後行順巡回*/
void postParse(int u){

  if(u == NIL)return;
  postParse(t[u].left);
  postParse(t[u].right);
  printf(" %d",u);
}

/*出力*/
void print(){
  int i,root;
  for(i = 0; i < num; i++){
    if(t[i].parent == NIL)root = i;
  }

  printf("Preorder\n");
  preParse(root);
  printf("\n");
 
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  
  printf("Postorder\n");
  postParse(root);
  printf("\n");

}

Measured memory_bytes: 616
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int ans = A - B*2;
    if (ans < 0){
      System.out.println(0);
    }else{
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 23124
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007
#define int long long

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

signed main()
{
    int n;
    cin >> n;
    int a[n], b[n];
    REP(i, n)
    {
        cin >> a[i];
    }
    REP(i, n)
    {
        cin >> b[i];
    }
    int ans = 0;

    int tmpb[30][n];
    for (int i = 0; i < 30; i++)
    {
        int bpow = (1 << i);
        for (int j = 0; j < n; j++)
        {
            tmpb[i][j] = b[j] % (bpow * 2);
        }
        sort(tmpb[i], tmpb[i] + n);
    }

    for (int i = 0; i < 30; i++)
    {
        int bitsum = 0;
        for (int j = 0; j < n; j++)
        {
            int bpow = (1 << i);
            int tmpa = a[j] % (2 * bpow);
            //両方ともlower_boundでいい（以上、未満）
            //distanceを用いる方法もある。
            bitsum += lower_bound(tmpb[i], tmpb[i] + n, 2 * bpow - tmpa) -
                      lower_bound(tmpb[i], tmpb[i] + n, bpow - tmpa);
            bitsum += lower_bound(tmpb[i], tmpb[i] + n, 4 * bpow - tmpa) -
                      lower_bound(tmpb[i], tmpb[i] + n, 3 * bpow - tmpa);
            bitsum %= 2;
        }
        ans |= (bitsum << i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 50176
package main
import "fmt"
func main() {
  var n,s,min,sum int
  fmt.Scan(&n)
  sum = 0
  min = 101
  for i:=0;i<n;i++ {
    fmt.Scan(&s)
    sum += s
    if s%10 != 0 && s < min { min = s }
  }
  if sum%10 != 0 {
    fmt.Println(sum)
  } else if min != 101 {
    fmt.Println(sum-min)
  } else {
    fmt.Println(0)
  }
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, A, B) = Read3Longs();
            var X = ReadLongs();

            var cost = 0L;
            for (int i = 1; i < N; i++)
            {
                cost += Math.Min(A * (X[i] - X[i - 1]), B);
            }

            return cost;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 38600
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){char ss[len];scanf("%s",ss);(st)=ss;}
//#define T_ long long
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
int n,m,i,j,col[100005][15],x,y,d,s[100005];
vector<int> bi[100005];
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,m)
	{
		scanf("%d%d",&x,&y);
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	int q;
	scanf("%d",&q);
	fz1(i,q)
	{
		scanf("%d%d%d",&x,&d,&s[i]);
		col[x][d]=i;
	}
	fd(i,9,0)
	{
		fz1(j,n)
		{
			col[j][i]=max(col[j][i],col[j][i+1]);
			ff(bi[j],it)
			{
				col[j][i]=max(col[j][i],col[*it][i+1]);
			}
		}
	}
	fz1(i,n) printf("%d\n",s[col[i][0]]);
	return 0;
}

Measured memory_bytes: 12792
A, B, C, X, Y = map(int, input().split())
p1 = A * X
p2 = B * Y
ans = p1 + p2
mn = 2*max(X, Y)
for i in range(0, mn+1, 2):
    p1 = A*max(0, (X-(i//2)))
    p2 = B*max(0, (Y-(i//2)))
    ans = min(ans, p1+p2+i*C)

print(ans)


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

int main() {
  int K,A,B,x,y;
  cin >> K >> A >> B;
  
  x=A/K;
  y=B/K;

  if (x < y) {
    cout << "OK" << endl;
  }

  else {
    if (A%K==0){
      cout << "OK" <<endl;
    }
    else{
      cout << "NG" << endl;
    }
  }

}


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

int main()
{
    int H, W;
    cin >> H >> W;
    while (H != 0 || W != 0)
    {
        for (int i = 0; i < H; i++)
        {
            if(i%2==0)
            {
                for(int j = 0; j < W; j++)
                {
                    if(j%2==0)
                        cout << "#";
                    else
                    {
                        cout << ".";
                    }
                }
            }
            else
            {
                for (int j = 0; j < W; j++)
                {
                    if (j % 2 == 0)
                        cout << ".";
                    else
                    {
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}


Measured memory_bytes: 3088
n,m=map(int,input().split())
red=[1]+[0]*(n-1)
pink=[1]*n
for _ in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if red[x] and pink[x]==1:
        red[x]=0
        red[y]=1
    elif red[x] and pink[x]>1:
        red[y]=1
    pink[x]-=1
    pink[y]+=1
print(red.count(1))

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int left = 0;
  int right = w;
  int up = h;
  int down = 0;

  for(int i=0;i<n;i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1 && x > left) left = x;
    if(a == 2 && x < right) right = x;
    if(a == 3 && y > down) down = y;
    if(a == 4 && y < up) up = y;
  }
  if(right<left) cout << 0 << endl;
  else if(up<down) cout << 0 << endl;
  else {
    int area = (right - left) * (up - down);
    cout << area << endl;
  }
}

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

using namespace std;

int main(){
    int H, N;
    cin >> H >> N;
    int T=0, a[N], l;
    while(cin >> l){

        T += l;
    }
    if (T >= H){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastRead in = new FastRead();
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, FastRead s, PrintWriter w) {
            int n = s.nextInt();
            w.println(3 * n * n);
        }
    }
   static class FastRead {
            BufferedReader b;
            StringTokenizer st;

            FastRead() {
                b = new BufferedReader(new InputStreamReader(System.in));
            }

            String next() {
                while (st == null || !st.hasMoreTokens()) {
                    try {
                        st = new StringTokenizer(b.readLine());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt() {
                return Integer.parseInt(next());
            }

        }
}

Measured memory_bytes: 22996
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            int len = S.length();

            int[] p = new int[len + 1];
            p[0] = 1;
            for (int i = 1; i <= len; i++) {
                p[i] = (p[i - 1] * 10) % 2019;
            }

            int ans = 0;
            int[] cnt = new int[2019];
            cnt[0] = 1;
            int t = 0;
            for (int i = len - 1; i >= 0; i--) {
                t = (t + (S.charAt(i) - '0') * p[len - 1 - i]) % 2019;
                ans += cnt[t]++;
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 36720
a, b, c, d, e, f = map(int,input().split())

dp = [[-1]*3 for _ in range(f + 1)]
dp[0] = [0, 0, 0]
for i in range(1, f+1):
    lst = []
    if i >= 100*a and dp[i-100*a][1] != -1:
        h = dp[i-100*a][2] / i
        lst.append([h, dp[i-100*a][1] + 100*a, dp[i-100*a][2]])
    if i >= 100*b and dp[i-100*b][1] != -1:
        h = dp[i-100*b][2] / i
        lst.append([h, dp[i-100*b][1] + 100*b, dp[i-100*b][2]])
    if i >= c and dp[i-c][1] > 0:
        h = (dp[i-c][2] + c) / i
        if h <= e/(100 + e):
            lst.append([h, dp[i-c][1], dp[i-c][2] + c])
    if i >= d and dp[i-d][1] > 0:
        h = (dp[i-d][2] + d) / i
        if h <= e/(100 + e):
            lst.append([h, dp[i-d][1], dp[i-d][2] + d])
    if lst:
        dp[i] = max(lst)
ans = max(dp)
print(ans[1] + ans[2], ans[2]) 

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

int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	map<string, int> votes;
	int n, maxV = 0;
	string temp;
	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>temp;
		votes[temp]++;
		maxV = max(maxV, votes[temp]);
	}
	for (auto it: votes) {
		if (it.second == maxV) {
			cout<<it.first<<'\n';
		}
	}
	return 0;
}

Measured memory_bytes: 23808
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();

        if (c <= a + b) {
            out.println(b + c);
        } else {
            out.println(b + (a + b) + 1);
        }

    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int n,k,ans,a,ji;
map<int,int>mp;
vector<int>v;
int main()
{
	cin>>n>>k;
	while(n--)
	{
		cin>>a;
		mp[a]++;
	}
	ji=mp.size()-k;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)v.push_back(it->second);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		if(ji<=0)break;
		ans+=v[i];
		ji--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
#define MAXPROFIT 100001
int main() {
	long n,w;
	cin>>n>>w;
	vector<long> val(n);
	vector<long> wgt(n);
	for(int i=0;i<n;i++)
	{
	    cin>>wgt[i];
	    cin>>val[i];
	}
	long INF = w+1;
	
	// n * profit 
	//DP[i][j] store WEIGHT required to get profit[j] with n[i] items available. 
	//DP[i][j] = INF ==> means profit[j] is not possible to obtained with given iterms[i].
	vector<vector<long>> dp(n+1,vector<long>(MAXPROFIT+1,INF));
	
	for(int i=0;i<=n;i++)
	{
	    dp[i][0]=0;
	}
	for(int j=1;j<=MAXPROFIT;j++)
	{
	    dp[0][j]=INF;
	}
	for(int i=1;i<=n;i++)
	{
	    for(int j=1;j<=MAXPROFIT;j++)
	    {
	        if(val[i-1]<=j)
	        {
	            dp[i][j] = min(dp[i-1][j], wgt[i-1]+dp[i-1][j-val[i-1]]);
	        }
	        else
	            dp[i][j] = dp[i-1][j];
	    }
	}
// 	for(int i=0;i<=n;i++)
// 	{
// 	    for(int j=0;j<=MAXPROFIT;j++)
// 	    {
// 	       cout<<dp[i][j]<<"\t";
// 	    }
// 	    cout<<endl;
// 	}
    
    //find MAX profit(right to left) such that its weight required is <= wgtCapacity.
	int ans;
	for(int j=MAXPROFIT;j>=0;j--)
	{
	   if(dp[n][j]<=w)
	   {
	       ans = j;
	       break;
	   }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 80256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=200005;
const int mod=998244353;
char ch[3*MAXN];
int n,cal[15],bin[5];
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	bin[0]=1;bin[1]=2;bin[2]=4;
	n=read();
	scanf("%s",ch+1);
	int ans=1,lst=n;
	for(int i=1;i<=3*n;i++)
	{
		int u;
		if(ch[i]=='R')u=0;
		else if(ch[i]=='G')u=1;
		else u=2;
		if(cal[7^bin[u]])ans=1LL*ans*cal[7^bin[u]]%mod,--cal[7^bin[u]];
		else
		{
			bool tf=false;
			for(int j=0;j<=2;j++)if(j!=u&&cal[bin[j]])
			{
				ad(cal[bin[j]|bin[u]],1);ans=1LL*ans*cal[bin[j]]%mod;
				--cal[bin[j]];tf=true;break;
			}
			if(!tf)++cal[bin[u]];
		}
	}
	for(int i=1;i<=n;i++)ans=1LL*ans*i%mod;
	pr2(ans);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>

#define rep(i,x) for(ll i=0;i<(int)(x);i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b;
}

int main()
{
    ll n;
    cin >> n;
    ll lc;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        if(i == 0) lc = tmp;
        else lc = lcm(tmp, lc);
    }

    cout << lc;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  ll N,K; cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];

  vector<ll> B(40);
  rep(i,N) {
    bitset<40> s(A[i]);
    rep(j,40) {
      if (s.test(j)) B[j]++;
    }
  }
  ll X = 0;
  rep(i,40) {
    if (N - B[39 - i] > N / 2) {
      if (X + pow(2,39-i) <= K) X += pow(2,39-i);
    } 
  }

  ll ans = 0;
  rep(i,N) ans += (X ^ A[i]);

  cout << ans << endl;
}

Measured memory_bytes: 1024