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

int main() {
  int N, K;
  stack<int> owo;
  cin >> N >> K;
  
  while (N != 0) {
    owo.push(N%K);
    N /= K;
  }
  
  cout << owo.size() << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main(void)
{
    int x;
    cin >> x;
    if (x == 0)
    {
        cout << "1" << endl;
    }
    else
    {
        cout << "0" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
N,Y=map(int,input().split())
for x in range(N+1):
  for y in range(N+1):
    z=N-x-y
    if z<0:
      continue
    else:
      if 10000*x+5000*y+1000*z==Y:
        print(x,y,z)
        exit()
print("-1 -1 -1")


Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
using namespace std;
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int x,n;
     cin>>x>>n;
     int arr[n];
     for(int i=0;i<n;i++)
         cin>>arr[i];
         sort(arr,arr+n);
     int ans1,ans2;
     for(int i=x;i<102;i++){
         if(!(binary_search(arr,arr+n,i))){
             ans1=i;
             break;
         }
     }
     for(int i=x;i>-102;i--){
         if(!(binary_search(arr,arr+n,i))){
             ans2=i;
             break;
         }
     }
    // cout<<ans1<<" "<<ans2<<endl;
     //int ans{0};
      if(x-ans2>ans1-x)
        cout<<ans1<<endl;
     else
         cout<<ans2<<endl;
 return 0;    
}

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

int n, m;
char c[60][60];
int bio[60][60];
int d1[] = {0, 0, -1, 1};
int d2[] = {1, -1, 0, 0};
queue< pair<int, int> > q;

void bfs() {
	
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for (int i = 0; i < 4; i ++) {
			int x1 = x + d1[i];
			int y1 = y + d2[i];
			if (x1 < 0 || y1 < 0 || x1 >= n || y1 >= m || bio[x1][y1] != -1 || c[x1][y1] == '#') continue;
			bio[x1][y1] = bio[x][y] + 1;
			q.push( make_pair(x1, y1) );
		}
	}
	
}

int main () {

	cin >> n >> m;
	int b = 0;
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < m; j ++) {
			cin >> c[i][j];
			bio[i][j] = -1;
			if (c[i][j] == '.') b ++;
		}
	}
	q.push( make_pair(0, 0) );
	bio[0][0] = 0;
	bfs();
	if (bio[n-1][m-1] == -1) cout << -1;
	else {
		cout << b - bio[n-1][m-1] - 1;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int l=s.length();
  int ans=100000;
  for(int i=0;i<l-2;++i) {
    int a=100*(s[i]-'0')+10*(s[i+1]-'0')+(s[i+2]-'0');
    ans=min(ans,abs(753-a));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed  main()
{
    int i, j, x, a, b, sz;
    cin>>x;
    sz=sqrt(x);
    for(i=-sz; i<=sz; i++)
    {
        for(j=-sz; j<=sz; j++)
        {
            a=i*i*i*i*i;
            b=j*j*j*j*j;
            if((a-b)==x)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG
int main(){
    int n;
    cin>>n;
    string S;
    cin>>S;
    int E[n];
    int W[n];
    rep(i,n){
        int a=0;
        if(S[i]=='E') a=1;
        E[i]=a;
    }
    rep(i,n){
        int a=0;
        if(S[i]=='W') a=1;
        W[i]=a;
    }
//累積和作成
    int sumE[n+1];
    int sumW[n+1];
    sumE[0]=0;
    sumW[0]=0;

    rep1(i,n){
        sumE[i]=sumE[i-1]+E[i-1];
        sumW[i]=sumW[i-1]+W[i-1];
    }
    int ans=300000;
    rep(i,n){
        int sum;
        sum=(sumW[i]-sumW[0])+(sumE[n]-sumE[i+1]);
        ans=min(ans,sum);
    }

    cout<<ans<<endl;
}





Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
const int N=2e5+5;
int a[N],n,i;
int ans[N];
vector<int>v;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n-2;i+=2){
        v.pb(a[i]^a[i+1]);
    }
    //for(i=0;i<v.size();i++)
     //   cout<<v[i]<<" ";
    int val=a[n-1];
    for(i=0;i<v.size();i++){
        val^=v[i];
    }
    ans[n]=val;
    for(i=n-1;i>=1;i--){
        int val=a[i]^a[i+1];
        ans[i]=val^ans[i+1];
    }
    for(i=1;i<=n;i++)
        cout<<ans[i]<<" ";
    return 0;
}

Measured memory_bytes: 5288
io = STDIN
hash={}
(1..400).each{|x|hash[x**2]=true}

n,d=io.gets.split.map(&:to_i)
ar=n.times.map{io.gets.split.map(&:to_i)}
def calc1(x,y)
  sum=x.zip(y).inject(0){|s,(a,b)|(a-b)**2+s}
end
p ar.combination(2).map{|x,y|calc1(x,y)}.count{|z|hash[z]}


Measured memory_bytes: 1788
program ABC171_B
  integer::N,K
  integer,allocatable::P(:)
  read(*,*)N,K
  allocate(P(N))
  read(*,*)P
  do i=1,N-1
     do j=i+1,N
        if(P(i)>P(j)) then
           L=P(i)
           P(i)=P(j)
           P(j)=L
        end if
     end do
  end do
  write(*,*)sum(P(1:K))
end program ABC171_B

Measured memory_bytes: 2816
#include<iostream>
using namespace std;
long long int a[100005][2];
int main(){
	long long int n;
	long long int i,j,k;
	long long int s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
	}
	for(i=n-1;i>=0;i--){
		a[i][0]+=s;
		if(a[i][0]==0)continue;
		j=(a[i][0]-1)/a[i][1];
		s+=a[i][1]*(j+1)-a[i][0];
	}
	cout<<s<<endl;
	return 0;
}


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

int main(){
  string S;
  cin>>S;
  int n=S.size();

  stack<char> st;
  for(int i=0;i<n;i++){
      if(st.empty()) st.push(S[i]);
      else{
          if(S[i]=='S') st.push(S[i]);
          else if(st.top()=='S'){
              st.pop();
          }else st.push(S[i]);
      }
  }

  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 644
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <functional>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
int dp[100010]{0};
int main(){
    int N;
    cin>>N;
    vector<int>h(N+1,0);
    rep(i,N) cin>>h[i+1];
    for(int i=2;i<N+1;i++){
        if(i-2<1) dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        else dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
    }
    cout<<dp[N];
}


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

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

	int n;
	long double t;
	priority_queue <long double,vector<long double>,greater<long double>> pque;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		pque.push(t);
	}

	while(pque.size()>1)
	{
		double x = pque.top();
		pque.pop();
		double y = pque.top();
		pque.pop();
		pque.push((x+y)/2);
	}

	cout << pque.top() << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <istream>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main() {
	int a = -1;//万
	int b = -1;//五千
	int c = -1;//千
	int n, y;
	cin >> n >> y;
	rep0(i, n) {
		rep0(j, n - i) {
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
				a = i;
				b = j;
				c = n - i - j;
			}	
		}
	}
	printf("%d %d %d", a, b, c);
	return 0;
}


Measured memory_bytes: 384
from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

per = [0] + list(permutations(list(range(1,n+1))))
pnum = per.index(p)
qnum = per.index(q)
ans = abs(pnum-qnum)

print(ans)

Measured memory_bytes: 14240
import java.util.Scanner;

class Main {

  static intStack stack = new intStack(20000);
  static Scanner scan;

  static public void main(String[] args){
    // get from std in
    scan = new Scanner(System.in);
    String input = scan.nextLine();

    // calc : total area
    int sum = 0;
    Tuple[] lines = new Tuple[10000];
    int n = 0;
    for(int i = 0; i < input.length(); i++) {
      switch(input.charAt(i)) {
        case '\\':
        stack.push(i);
        break;
        case '/':
        if (!stack.isEmpty()){
          int tmp = (Integer)stack.pop();
          sum += i - tmp;
          lines[n] = new Tuple(tmp, i);
          n++;
        }
        break;
        default:
        break;
      }
    }
    // print : total area
    System.out.println(sum);

    // calc : each floods area
    int[] area = new int[n];
    int count = 0;
    for(int i = 0; i < n; i++) {
      int min = lines[i].tail;
      int index = i;
      for(int j = i+1; j < n; j++) {
        if(min > lines[j].tail) {
          min = lines[j].tail;
          index = j;
        }
      }
      for(int j = i; j <= index; j++){
        area[count] += lines[j].head - lines[j].tail;
      }
      count++;
      i = index;
    }

    if(count > 0){
      System.out.printf("%d ", count);
      for(int i = 0; i < count-1; i++){
        System.out.printf("%d ", area[i]);
      }
      System.out.printf("%d\n", area[count-1]);
    } else {
      System.out.printf("%d\n", count);
    }
  }
}

class Tuple {
  public int tail;
  public int head;

  public Tuple(int t, int h){
    this.tail = t;
    this.head = h;
  }
}


class intStack {
  private static int length;
  private static int[] Stack;
  private static int current;

  public intStack(int length) {
    this.length = length;
    this.Stack = new int[length];
    this.current = 0;
  }

  public void push(int data) {
    this.Stack[current] = data;
    current++;
  }

  public int pop() {
    if (current == 0) return 0;
    current--;
    return this.Stack[current];
  }

  public boolean isEmpty(){
    if (current == 0) return true;
    else return false;
  }
}



Measured memory_bytes: 36120
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
if len(a) == 1:
    print(len(a[0]) - 1)
else:
    s = list(set(a[0][1:]) & set(a[1][1:]))
    for i in range(2, n):
        s = list(set(s) & set(a[i][1:]))
    print(len(s))

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }

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

int main(){
    ll h,w,k;
    cin >> h >> w >> k;
    char s[h][w] = {};
    rep(i,0,h) rep(j,0,w) cin >> s[i][j];

    ll ans = LINF;
    rep(i,0,pow(2,h-1)){
        ll index = 0;
        vector<ll> vec;
        rep(j,0,h-1) if((i >> j) & 1) vec.push_back(j);
        vec.push_back(LINF);
        ll temp = 0;
        ll cnt[sz(vec)][w] = {};
        bool flag = false;
        rep(j,0,w){
            index = 0;
            rep(l,0,h){
                if(s[l][j] == '1') cnt[index][j]++;
                if(cnt[index][j] > k) flag = true;
                if(vec[index] <= l) index++;
            }
        }
        if(flag) continue;
        
        rep(j,1,w){
            flag = false;
            rep(l,0,sz(vec)){
                if(cnt[l][j] + cnt[l][j-1] > k){
                    temp++;
                    flag = true;
                    break;
                }
            }

            if(!flag){
                rep(l,0,sz(vec)){
                    cnt[l][j] += cnt[l][j-1];
                }
            }
        }
        ans = min(ans,temp + sz(vec)-1);
    } 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, b;
    cin >> a >> b;
    if (a % 2 == 1 && b % 2 == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3624
import sys

N,X = map(int,input().split())
ans = 0
oldx = 0

if N > 2 * X:

    ans = N
    N = N - X

elif N == 2 * X:
    ans = 3 * X
    print (ans)
    sys.exit()

else:

    ans = N
    oldx = X
    X = N - X
    N = oldx

while True:

    #print (N,X,ans)

    if N % X == 0:
        ans += ((N // X) * 2 - 1) * X
        break

    else:
        ans += ((N // X) * 2 * X)

        oldx = X
        X = N % X
        N = oldx

    

print (ans)


Measured memory_bytes: 3064
MOD = 10**9 + 7


def main():
    N, K = (int(i) for i in input().split())
    ans = 0
    for i in range(K, N+2):
        ans += (N*(N+1)//2 - (N-i)*(N-i+1)//2) - ((i-1)*i//2) + 1
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63520
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, N;
  
  cin >> N >> A;
  
  if (A != 0) {
    if (N % 500 < A) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (N % 500 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}  

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
double a[200005];
int sum[10005],f[100][100],t1[200005],t2[200005];
typedef long long ll;
ll b[200005];
int get2(ll x)
{
    int res=0;
    while(!(x&1))x>>=1,res++;
    return res;
}
int get5(ll x)
{
    int res=0;
    while(!(x%5))x/=5,res++;
    return res;
}
int main()
{
    int n;
    long long ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lf",&a[i]);
        a[i]*=1e9;
        b[i]=(ll)(a[i]+0.5);
        t1[i]=get2(b[i]),t2[i]=get5(b[i]);
        ans+=f[max(18-t1[i],0)][max(18-t2[i],0)];
        for(int j=0;j<=t1[i];j++)
            for(int k=0;k<=t2[i];k++)
                f[j][k]++;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 8456
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

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

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");

		int N = Integer.parseInt(Ws[0]);
		int A = Integer.parseInt(Ws[1]);
		int B = Integer.parseInt(Ws[2]);
		int C = Integer.parseInt(Ws[3]);
		int D = Integer.parseInt(Ws[4]);

		W = in.readLine();
		W = "#"+W+"#";
		char[] S = new char[W.length()];
		for(int i=0;i<S.length;i++){
			S[i]=W.charAt(i);
		}

		boolean ans =true;
		String ansS="Yes";
		for(int i=A;i<C-1;i++){
			if(S[i]=='#' && S[i] == S[i+1]){
				ans=false;
				break;
			}
		}
		for(int i=B;i<D-1;i++){
			if(S[i]=='#' && S[i] == S[i+1]){
				ans=false;
				break;
			}
		}

		if(!ans){
			ansS="No";
		}else{

			if(C < D ){
				ansS="Yes";
			}else{
				ansS="No";
				for(int i=B;i<=D;i++){
					if(S[i]=='.' && S[i]==S[i-1]&&S[i-1] == S[i+1]){
						ansS="Yes";
						break;
					}
				}
			}
		}
		System.out.println(ansS);
	}
}


Measured memory_bytes: 27060
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x; cin >> x;
  cout << !x << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define chmax(x,y) x = max(x,y)
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, x, y, ans[4] = {}, fans = 0;

int main() {
	cin >> n;
	vector<vector<ll>> sum(4);
	rep(i, n) {
		cin >> x >> y;
		sum[0].pub(x + y);
		sum[1].pub(x - y);
		sum[2].pub(-x + y);
		sum[3].pub(-x - y);
	}
	rep(i, 4) {
		stable_sort(sum[i].begin(), sum[i].end());
		rep(j, n)chmax(ans[i], sum[i][n - 1] - sum[i][0]);
		chmax(fans, ans[i]);
	}
	cout << fans << endl;
	return 0;
}

Measured memory_bytes: 10556
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
int n,k;
int main(){
	cin>>n>>k;
	if (k<=(n+1)/2)puts("YES");else puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
const ll INF = 1001001001;

int main(){
  int a ,b;
  cin >> a >> b;
  int cnt = 0;
  int plug = 1;
  while(true){
    if (plug >= b) break;
    plug += a-1;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3528
#include<stdio.h>
#define INF 1000000
#define MIN(A,B) ((A) <= (B) ? (A) : (B))

int Ma,Mb,N,maxasum,maxbsum;
int a[41],b[41],c[41];
int DP[41][401][401];

int main(void){
    int i,j,k;


    scanf("%d %d %d",&N,&Ma,&Mb);

    for(i = 1;i <= N;i++)
        scanf("%d %d %d",&a[i],&b[i],&c[i]);

    j = 0;k = 0;
    for(i = 1;i <= N;i++){
        if(j < a[i])
            j = a[i];
        if(k < b[i])
            k = b[i];
    }
    maxasum = j * N;
    maxbsum = k * N;

    for(i = 0;i <= N;i++)
        for(j = 0;j <= 400;j++)
            for(k = 0;k <= 400;k++)
                DP[i][j][k] = INF;

    DP[0][0][0] = 0;
    for(i = 1;i <= N;i++){
        for(j = 0;j <= maxasum;j++ ){
            for(k = 0;k <= maxbsum;k++){
                if(a[i] <= j && b[i] <= k)
                    DP[i][j][k] = MIN(DP[i - 1][j - a[i]][k - b[i]] + c[i],DP[i - 1][j][k]);
                else
                    DP[i][j][k] = DP[i - 1][j][k];
            }
        }
    }

    i = Ma;j = Mb;k = INF;
    while(i <= maxasum && j <= maxbsum){
        if(k > DP[N][i][j])
            k = DP[N][i][j];
        i += Ma;j += Mb;
    }
    printf("%d\n",k < INF ? k : -1);
    return 0;

}

Measured memory_bytes: 25984
MOD = 10**9+7
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
    @a = gets.split.map(&:to_i)
  end

  def solve
    ans = 0
    cs = a[0]
    1.upto(n-1) do |i|
      ans += cs * a[i]
      cs += a[i]
      ans %= MOD
      cs %= MOD
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 28092
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main() {
	long long n,m;
	cin >> n >> m;
	if(n>1)n-=2;
	if(m>1)m-=2;
	cout << n*m << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

class Program
{
    static void Main(string[] args)
    {
        var s = int.Parse(Console.ReadLine());
        var sl = new List<int>();
        sl.Add(s);
        var i = 0;
        int m;
        while (true)
        {
            var q = ((sl[i] % 2 == 0) ? sl[i] / 2 : 3 * sl[i] + 1);
            if (sl.Contains(q))
            {
                m = i + 1;
                break;
            }
            sl.Add(q);
            i++;
        }
        Console.WriteLine(m + 1);
    }
}

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


#define gc getchar
#define pc putchar

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
*/

/*
        two functions for policy based data structure. it is

                find_by_order() and order_of_key().

        The first returns an iterator to the k-th largest element (counting from zero),
        the second returns the number of items in a set that are strictly smaller than our item

*/

#define vi vector<int>
#define si set<int>
#define vs vector<string>
#define pii pair<int,int>
#define vpi vector<pii>
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define mpi map<int,int>
#define i64 long long int
#define endl '\n'
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Rep(i,x,y) for(int i=x;i<=y;i++)
#define eps 1e-8
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt","w", stdout)
#define sz size()
#define dbg(x) cerr << "yo is " << x << endl;
#define dbg2(x,y) printf("yo is %d! and %d!\n",x,y)
#define foreach(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define sqr(a) (a) * (a)
#define clr clear()
#define CASE(a) printf("Case %d: ",a)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)

//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
//int dx[] = { -1, -1,  0, 1, 1, 1,  0, -1 };
//int dy[] = {  0, -1, -1, -1,  0, 1, 1, 1 };
//int dxK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
//int dyK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

//functions

//i64 gcd(i64 a,i64 b){if(!b)return a;return gcd(b,a%b);}

//inline void fastRead(i64 *a){register char c=0;while(c<33)c=gc();*a=0;while(c>33){*a=*a*10+c-'0';c=gc();}}

//inline void fastWrite(int a){char snum[20];int i=0;do{snum[i++]=a%10+48;a=a/10;}while(a!=0);i=i-1;while(i>=0)pc(snum[i--]);pc('\n');}

//i64 bigmod(i64 num,i64 n){if(!n)return 1;i64 x=(bigmod(num,n/2)*bigmod(num,n/2))%mod;if(n%2)x=(x*num)%mod;return x;}

//i64 modinverse(i64 num){return bigmod(num,mod-2);}

//void combination(int pos,int last){if(pos==k+1){for(int i=1;i<=k;i++)cout << tem[i];cout << endl;return;}
//for(int i=last+1;i<=n-k+pos;i++){tem[pos] = num[i-1];combination(pos+1,i);}}
//i64 power(i64 value, i64 base){i64 result = 1;For(i,base)result *= value;return result;}
//int Set(int N,int pos){return N = (1<<pos);}
//int reset(int N,int pos){return N &= (~(1<<pos));}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}

//typedef tree< int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > Set;

int main()
{
    int n,k;
    sff(n,k);
    int a;
    For(i,n)
        sf(a);

    n--,k--;

    cout << (n/k) + (n%k!=0) << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        for(int i = 1; i <= 50; i++){
            if(n < Math.pow(k, i)){
                System.out.println(i);
                return;
            }
        }
        scan.close();
    }
}

Measured memory_bytes: 23124
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


int n, m;
string s[2005];
bool dp[2005][10005], st[10005];
string s1;
int len[2005];

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
        len[i] = (int)s[i].size();
    }
    dp[n][m] = true;
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j <= m; ++j) {
            dp[i][j] = dp[i + 1][j];
            if (j + len[i + 1] <= m && dp[i + 1][j + len[i + 1]]) dp[i][j] = true;
        }
    }
    st[0] = true;
    s1 = "";
    for (int i = 1; i <= n; ++i) {
        string s2 = s[i] + "#" + s1;
        int nn = (int)s2.size();
        vector<int> z(nn, 0);
        for (int j = 1, l = 0, r = 0; j < nn; ++j) {
            if (j <= r) z[j] = min(r - j + 1, z[j - l]);
            while (j + z[j] < nn && s2[z[j]] == s2[j + z[j]]) ++z[j];
            if (j + z[j] - 1 > r) l = j, r = j + z[j] - 1;
        }
        for (int j = len[i]; j <= m; ++j) if (dp[i][j]) {
            int l1 = j - len[i];
            if (!st[l1]) continue;
            int l = len[i] + l1 + 1;
            bool c = false;
            if (l >= nn) c = true;
            else {
                int r = l + z[l];
                if (z[l] < len[i] && (r >= nn || s2[r] > s2[z[l]])) {
                    c = true;
                }
            }
            if (c) {
                string s2 = "";
                for (int k = 1; k <= l1; ++k)
                    s2 += s1[k - 1];
                s2 += s[i];
                s1 = s2;
                for (int k = l1 + 1 + (l >= nn ? 10005: z[l]); k <= m; ++k)
                    st[k] = false;
                st[j] = true;
                break;
            }
        }
        for (int j = 0; j <= m; ++j)
            if (!dp[i][j]) st[j] = false;
        int pos = 0;
        s2 = "";
        for (int j = 0; j <= m; ++j)
            if (st[j]) pos = j;
        for (int j = 1; j <= pos; ++j)
            s2 += s1[j - 1];
        s1 = s2;
    }
    cout << s1 << '\n';
    return 0;
}



Measured memory_bytes: 21120
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, T; cin >> N >> T;
	vector<int>v(T + 1, 0);
	rep(i, 0, N) {
		int l, r; cin >> l >> r;
		v[l]++; v[r]--;
	}
	rep(i, 1, T+1)v[i] += v[i - 1];
	cout << *max_element(all(v)) << endl;
	return 0;
}

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

int main(void){
    int A,B,C;
    cin>>A>>B>>C;
    if(max(A,B)>=C&&C>=min(A,B)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int g = 0;
		int p = 0;
		int res = 0;
		String str = sc.next();
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'g') {
				if (g > p) {
					p++;
					res++;
				} else {
					g++;
				}
			} else {
				if (g > p) {
					p++;
				} else {
					g++;
					res--;
				}
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 13268
D, G = map(int, input().split())

p = []
c = []

for i in range(D):
    x, y = map(int, input().split())
    p.append(x)
    c.append(y)

ans = sum(p)
#5, 3 だったら8
for i in range(2 ** D):
    score = 0
    tmp = 0
    notuse = [0] * D
    for j in range(D):
        if ((i >> j) & 1):
            score += (100 * (j + 1) * p[j] + c[j])
            tmp += p[j]
            notuse[j] += 1
    if score < G:
        k = D - 1
        while notuse[k] == 1:
            k -= 1
        for l in range(p[k] - 1):
            score += 100 * (k + 1)
            tmp += 1
            if score >= G:
                break
        if tmp < ans and score >= G:
            ans = tmp
    else:
        if tmp < ans:
            ans = tmp

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  rep(i,s.size()-1) {
    if(s[i]=='A'&&s[i+1]=='C') {
      pr("Yes");
      return;
    }
  }
  pr("No");
}

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


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define int long long int
signed main() 
{
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    std::vector<int> v(n);
    fr(i,n) cin>>v[i];
    std::vector<std::vector<int> > dp;
    std::vector<int> row(n,0);
    fr(i,n) dp.pb(row);

    fr(i,n) dp[i][i]=v[i];

    for(int j=1;j<n;j++)
    {
        fr(i,n)
        {
            if(i+j>=n) break;

            dp[i][i+j]=max(v[i]-dp[i+1][i+j],v[i+j]-dp[i][i+j-1]);

        }
    }

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

    return 0;
}   

Measured memory_bytes: 70784
n=int(input())

length=list(map(int,input().split()))

sum=0

for i in range(0,len(length)-1):
  if length[i]>length[i+1]:
    dai=length[i]-length[i+1]
    length[i+1]+=dai
    sum+=dai
  else:
    continue

print(sum)


Measured memory_bytes: 32180
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;
typedef long long i64;

i64 getBestV(vector<pair<i64, i64>> &items, int capacity) {
  vector<i64> memo(capacity + 1);
  for (auto item : items) {
    i64 w, v;
    tie(w, v) = item;
    for (int i = capacity; i >= w; i--) {
      memo[i] = max(memo[i], memo[i - w] + v);
    }
  }
  return memo[capacity];
}

int main() {
  int n, cap;
  cin >> n >> cap;
  vector<pair<i64, i64>> items(n);
  for (int i = 0; i < n; i++) {
    i64 w, v;
    cin >> w >> v;
    items[i] = {w, v};
  }
  cout << getBestV(items, cap) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 505050 , P = 1e9 + 7;
int n , ne[N] , ne2[N];
char s[N];

void kmp(int *ne){
    for(int i=2,j=0;i<=n;++i){
        while(j && s[j + 1] != s[i]) j=ne[j];
        ne[i] = s[j + 1] == s[i] ? ++j : j;
    }
}
bool loop(int x,int *ne){
    return ne[x] && x % (x - ne[x]) == 0;
}

int main(){
    scanf("%s",s + 1);
    n = strlen(s + 1);
    kmp(ne);
    if(!loop(n,ne)) printf("1\n1\n");
    else if(ne[n] == n-1) printf("%d\n1\n",n);
    else{
        reverse(s+1,s+1+n);
        kmp(ne2);
        int ans = 0;
        for(int i=1;i<n;++i) if(!loop(i,ne) && !loop(n-i,ne2)) ++ans;
        printf("2\n%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 4608
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<ctime>
#include<iostream>
using namespace std;

const long long MaxN = 1e6;
char a[MaxN],b[MaxN];
long long la,lb;

int main()
{
	cin>>a>>b;
	la = strlen(a);
	lb = strlen(b);
	if(la > lb) printf("GREATER\n");
	else if(la < lb) printf("LESS");
	else{
		if(strcmp(a,b) == 0) printf("EQUAL");
		if(strcmp(a,b) < 0) printf("LESS");
		if(strcmp(a,b) > 0) printf("GREATER\n");
	}
	return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
let arr = input.split("\n");
for (let i = 0; i < arr.length; i++) {
    let Arr = arr[i].split(" ").map(Number);
    let H = Arr[0];
    let W = Arr[1];
    if (H === 0 && W === 0) break;
    let str = '';
    for (let hCount = 1; hCount <= H; hCount ++) {
      for (let wCount  = 1; wCount <= W; wCount ++) {
        if (hCount % 2 !== 0) {
          if (wCount % 2 !== 0) {
            str += '#';
          } else {
            str += '.';
          }
        } else {
          if (wCount % 2 !== 0) {
            str += '.';
          } else {
            str += '#';
          }
        }
        
      }
      str += '\n';
    }
    console.log(str);
}


Measured memory_bytes: 18876
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,h[100005],f[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	memset(f,0x3f,sizeof(f));
	f[1]=0;
	for(int i=2;i<=n;i++)
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 896
#-*-coding:utf-8-*-

import sys

def main():
    k = int(input())
    sevens=0
    for i in range(1,k+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9072
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

const int N = 510;

int n;
ll a[N][N], dp[N][N]; 

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j)
        scanf("%lld", &a[i][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      a[i][j] += a[i][j - 1];
  for (int j = 1; j <= n; ++j)
    for (int i = j + 1; i <= n; ++i)
      a[i][j] += a[i - 1][j];
  for (int i = 1; i <= n; ++i) {
    ll as = 0;
    for (int j = i; j; --j) {
      dp[i][j] = 1LL << 60;
      as += a[j][i];
      ll bs = 0;
      for (int k = j != 1; k < j; ++k) {
        dp[i][j] = min(dp[i][j], dp[j - 1][k] + bs);
        bs += a[i][k] - a[j - 1][k];
      }
      dp[i][j] += as;
    }
  }
  ll ans = *min_element(dp[n] + 1, dp[n] + n + 1);
  printf("%lld\n", ans);

  return 0;
}


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

int main(void){
    string s; cin >> s;
    int n = s.size() - 1;

    char opp[3];
    for(int mask = 0; mask < (1 << n); mask++){
        int ans = s.at(0) - '0';
        for(int flag = 0; flag < n; flag++){
            if((mask >> flag) & 1 == 1){
                ans += s.at(flag + 1) - '0';
                opp[flag] = '+';
            } else {
                ans -= s.at(flag + 1) - '0';
                opp[flag] = '-';
            }
        }
        if(ans == 7) break;
    }
    
    for(int i=0; i<4; i++){
        cout << s[i];
        if(i == 3){
            cout << "=7" << endl;
            break;
        }
        cout << opp[i];
    }
    
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
s_c = []
for _ in range(M):
    s_c.append(list(map(int, input().split())))

def check(num, s_c):
    num = str(num)
    flag = True
    for s,c in s_c:
        if s>len(num):
            flag = False
        elif not num[s-1] == str(c):
            flag = False
    return flag

a = False
b = True
for i in range(1000):
    if check(i, s_c) and len(str(i)) == N:
        falg = False
        print(i)
        b = False
        break
if b:
    print(-1)

Measured memory_bytes: 3188
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int a,b,c,k,ans;

int main() {
	qr(a); qr(b); qr(c); qr(k);
	if(k<=a) ans=k;
	else {
		ans=a;
		k-=a;
		if(k>b) ans-=k-b;
	}
	pr2(ans);
	return 0;
}



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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll K, A, B;
  cin >> K >> A >> B;
  K++;
  ll ans = 0;
  if(A+2>=B){
    ans = K;
  }else{

    if(K>=A+2){
      ans += B;
      K -= (A+2);

      ans += (B-A) * (K/2);
      K = K % 2;
      ans += K;
    }else{
      ans = K;
    }

  }

  cout << ans << endl;

  return 0;
}


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


int main() {
	// your code goes here
int A =0;
int B =0;
int K =0;
	cin >>K;
	cin>> A ;
cin>>B;	
	  bool ans=false;
	for (int i=0; i<B-A+1;i++){
	   
	

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

}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

template<typename T>
class SegTree {
public:
  int n;
  T e;
  T (*op)(T, T);
  vector<T> data;
  SegTree(int m, T _e, T (*_op)(T, T)) : e(_e), op(_op){
    n=1;
    while(n<m) n*=2;
    data.resize(2*n, e);
  }
  T query(int l, int r){
    T vl = e, vr = e;
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1) vl = op(vl, data[l++]);
      if(r&1) vr = op(data[--r], vr);
    }
    return op(vl,vr);
  }
  void update(int k, T a){
    k+=n;
    data[k]=a;
    while(k>0){
      k = k/2;
      data[k] = op(data[k*2], data[k*2+1]);
    }
  }
  inline T operator[](int idx){ return data[idx+n]; }
};

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

  SegTree<long> st(n, 0, [](const long l, const long r){return l+r;});
  rep(i,q){
    int t,x,y;
    cin>>t>>x>>y;
    if(t==0) st.update(x,st.query(x,x+1) + y);
    else cout << st.query(x,y+1) << "\n";
  }

  return 0;
}

Measured memory_bytes: 4944
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[11][10001],b[11],h,ans,w;
void check(){
	int sum=0,t[w]={};
	r(i,h){
		int x=0;
		r(j,w){
			if(b[i])t[j]+=!a[i][j];
			else t[j]+=a[i][j];
		}
	}
	r(i,w)sum+=max(t[i],h-t[i]);
	ans=max(ans,sum);
}
void dfs(int d){
	if(d==h)check();
	else{
		b[d]=0;
		dfs(d+1);
		b[d]=1;
		dfs(d+1);
	}
}
main(){
	while(cin>>h>>w,h){
		r(i,h)r(j,w)cin>>a[i][j];
		ans=0;
		dfs(0);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string S;cin>>S;
  int K;cin>>K;
   vector<int> arr(S.size());
   REP(i,0,S.size()){
     arr[i]=(int)S.at(i)-'a';
   }

   REP(i,0,S.size()-1){
     if(arr[i]!=0&&K-26+arr[i]>=0){
       K=K-26+arr[i];
       arr[i]=0;
     }
   }
   arr[S.size()-1]=(arr[S.size()-1]+K)%26;
   each(v,arr){
     char a=(char)v+'a';
     cout<<a;
   }
   cout<<endl;

}


Measured memory_bytes: 1360
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=300009;
vector<pair<ll ,ll > > v;
ll  dp[101][100001];
ll  call(ll  ind, ll  w)
{
    if(ind==v.size()) return 0;
    ll  &ret=dp[ind][w];
    if(ret!=-1) return ret;
    ll  a=0,b=0;
    if(v[ind].first<=w) a=v[ind].second+call(ind+1,w-v[ind].first);
    b=call(ind+1,w);
    return ret=max(a,b);
}
int main()
{
    ll  n,w;
    cin>>n>>w;
    for(ll  i=0;i<n;i++)
    {
        ll  a,b;
        cin>>a>>b;
        v.pb(mp(a,b));
    }
    memset(dp,-1,sizeof dp);
    cout<<call(0,w)<<endl;
}


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

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

	ll sum = 0;
	for (ll i=0; i<s.size(); i++)
		sum += s[i] - '0';
	
	cout<<(sum % 9 == 0 ? "Yes\n" : "No\n");

	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
int a[N];

int main()

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

    int n;

    vector <ll> v (100);

    v[0] = 2;
    v[1] = 1;

    for (int i = 2; i <= 86; i++) {

        v[i] = v[i-1]+v[i-2];
    }

    cin >> n;

    cout << v[n];

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double ans;

        if (N%2 == 0)
            ans = N/2.0;
        else
            ans = N/2.0 + 0.5;

        System.out.println((int)ans);
    }
}


Measured memory_bytes: 35604
#include <iostream>
#include <algorithm>
#include <assert.h>
using namespace std;
#define int long long
int tempmarge[1000100];
int N, A[10000000];

int MargeSort(int x[], int left, int right) {
	int mid, i, j, k, cl, cr, c;
	if (left >= right)
		return 0;
	mid = (left + right) / 2;
	cl = MargeSort(x, left, mid);
	cr = MargeSort(x, mid + 1, right);

	for (i = left; i <= mid; i++)
		tempmarge[i] = x[i];
	for (i = mid + 1, j = right; i <= right; i++, j--)
		tempmarge[i] = x[j];
	i = left;
	j = right;
	c = 0;
	for (k = left; k <= right; k++)
		if (tempmarge[i] <= tempmarge[j])
			x[k] = tempmarge[i++];
		else {
			c += mid + 1 - i;
			x[k] = tempmarge[j--];
		}
		return c + cl + cr;
}

signed main() {

	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << MargeSort(A, 0, N - 1) << endl;
	return 0;
}

Measured memory_bytes: 6208