akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var a = IO.RSInt;
            // スタート地点を拠点としてもつ
            var wk = new int[n + 2];
            Array.Copy(a, 0, wk, 1, n);
            var vec = new int[n + 2];

            var ttl = 0;
            for (int i = 0; i <= n; i++)
            {
                ttl += Math.Abs(wk[i + 1] - wk[i]);
                if (wk[i + 1] - wk[i] >= 0)
                {
                    vec[i] = 1;
                }
                else
                {
                    vec[i] = 0;
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (vec[i + 1] != vec[i])
                {
                    if (Abs(wk[i] - wk[i + 1]) >= Abs(wk[i + 1] - wk[i + 2]))
                        WriteLine(ttl - 2 * Abs(wk[i + 1] - wk[i + 2]));
                    else
                        WriteLine(ttl - 2 * Abs(wk[i + 1] - wk[i]));
                }
                else
                {
                    WriteLine(ttl);
                }
            }
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 26844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	ll n;
	cin>>n;
	vector<pair<ll,ll> > arr(n);
	ll u,v;
	bool y=0;
	int j;
	for(int i=0;i<n;i++){
		cin>>u>>v;
		if(i<2){
			arr[i]={u,v};
		}else{
			arr[i]={u,v};
			j=i-2;
			for(;j<=i;j++){
				if(arr[j].first!=arr[j].second){
					break;
				}
			}
			if(j==i+1){
				y=1;
			}
		}
	}
	if(y){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long t=1;
//	cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3652
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   long long k;
   string s;
   cin>>s;
   cin>>k;
   for(int i=0;i<min((long long)s.size(),k);i++)
       {
       if(s[i]>='2'){cout<<s[i];return 0;}

       }
   cout<<'1';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        int n = 0;        
        for(int i=0; i<=20; i++){
        if((A-1)*i+1<B){
         n++;
    }
        }    
            System.out.print(n);
        }
}


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

int main(){

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

	vector< string > a(n);

	for(int i=0;i<n;i++){
		cin >> a[i];
	}

	vector< vector<int> > l( n , vector<int>(m,0) ),r( n , vector<int>(m,0) ),u( n , vector<int>(m,0) ),d( n , vector<int>(m,0) );

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(j==0){
				if( a[i][j]=='.' ){
					l[i][j]=1;
				}
			}else{
				if( a[i][j]=='.' ){
					l[i][j]=l[i][j-1]+1;
				}
			}

			if(j==0){
				if( a[i][m-1-j]=='.' ){
					r[i][m-1-j]=1;
				}
			}else{
				if( a[i][m-1-j]=='.' ){
					r[i][m-1-j]=r[i][m-j]+1;
				}
			}

			if(i==0){
				if( a[i][j]=='.' ){
					u[i][j]=1;
				}
			}else{
				if(a[i][j]=='.'){
					u[i][j]=u[i-1][j]+1;
				}
			}

			if(i==0){
				if( a[n-1-i][j]=='.' ){
					d[n-1-i][j]=1;
				}
			}else{
				if(a[n-1-i][j]=='.'){
					d[n-1-i][j]=d[n-i][j]+1;
				}
			}

		}
	}

	int ans = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans = max( ans , l[i][j]+r[i][j]+u[i][j]+d[i][j] );
		}
	}

	cout << ans-3 << "\n";




	return 0;
}

Measured memory_bytes: 67200
N, K = map(int, input().split())
D = list(map(int, input().split()))

R = min(N, K)
max_sum = 0
for A in range(R + 1):
        for B in range(R - A + 1):
                drop_max = min(K - (A + B), (A + B))
                if B == 0:
                        L = D[:A]
                else:
                        L = D[:A] + D[-B:]
                L.sort()
                drop_num = 0
                for i in range(A + B):
                        if drop_num < drop_max and L[i] < 0:
                                L[i] = 0
                                drop_num += 1
                        else:
                                break

                max_sum = max(max_sum, sum(L))

                

print(max_sum)

Measured memory_bytes: 3064
def main():
    n, a, b = map(int, input().split())
    mod = 10 ** 9 + 7 #素数
    
    def modpow(x, n, mod):
        res = 1
        while n:
            if n % 2:
                res *= x % mod
            x *= x % mod
            n >>= 1
        return res
    
    def cmb(n, r):
        # 分子(n*(n-1)*...*(n-r+1))
        nume = 1
        for i in range(n-r+1, n+1):
            nume = nume * i % mod
        # 分母（1*2*...*r）
        deno = 1
        for j in range(1, r+1):
            deno = deno * j % mod
        d = modpow(deno, mod-2, mod)
        return nume * d
    
    all_cmb = pow(2, n, mod) - 1
    bad_a = cmb(n, a)
    bad_b = cmb(n, b)    
    print((all_cmb-bad_a-bad_b) % mod)

if __name__ == '__main__':
    main()

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

using namespace std;
#define int long long
#define endl '\n'


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1; // cin >> t;
    for (; t; t--) {
        int n; cin >> n;
        vector<int> a(n);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (a[i] % 2 == 1 && i % 2 == 0) {
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

#define i64 long long
#define N 100010
i64 n, m;
char s[N], t[N];
map<i64, char> hav;

i64 gcd(i64 a, i64 b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    cin >> n >> m;
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    i64 lcm = m * n / gcd(n, m);
    for (i64 i = 1; i <= n; ++i) hav[(i - 1) * lcm / n+1]=s[i];
    for (i64 i = 1; i <= m; ++i) if (hav[(i-1)*lcm/m+1] && hav[(i-1)*lcm/m+1]!= t[i]) { puts("-1"); return 0;}
    cout << lcm << endl;
    return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int D, G;
vi p, c;

int dfs(vi x, int res, int sum, int i) {

    if (sum + (i + 1) * p[i] * 100 + c[i] < G) {
        sum += (i + 1) * p[i] * 100 + c[i];
        res += p[i];
    } else {
        REP (j, p[i]) {
            sum += (i + 1) * 100;
            res++;
            if (j+1 == p[i]) sum += c[i];
            if (sum >= G) return res;
        }
    }

    int res2 = (1 << 30);
    REP(d, D) {
        if (x[d] > 0) {
            vi x2 = x; x2[d] = 0;
            res2 = min(res2, dfs(x2, res, sum, d));
        }
    }

    return res2;
}

int main() {

    cin >> D >> G;
    REP(i, D) {
        int a, b;
        cin >> a >> b;
        p.push_back(a);
        c.push_back(b);
    }

    vi x(D, 1);

    int ans = (1 << 30);
    REP(i, D) {
        vi x2 = x;
        x2[i] = 0;
        ans = min(ans, dfs(x2, 0, 0, i));
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<utility>
#include<algorithm>

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 200006
#define P pair<ll,ll>

using namespace std;

int n,q,Q[inf];
vi adj[inf],ans(inf);
vector<bool> visited(inf);

void inp(){
    cin>>n>>q;
    pan(i,n-1){
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    pan(i,q){
        int x,y;
        cin>>x>>y;
        Q[x]+=y;
    }
}

void dfs(int v,int p) {
    visited[v] = true;
    ans[v]+=p;
    for (int u : adj[v]) {
        if (!visited[u])
            dfs(u,Q[u]+p);
    }
}

int main(){
    inp();
    for (int i = 1; i <= inf; i++)
    {
        if(!visited[i]){
            dfs(i,Q[i]);
        }
    }
    pans(i,n+1,1) cout << ans[i] << " ";
}   

Measured memory_bytes: 24064
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

const int mod = 1e9 + 7;
const int inf = 9e18;
const int N = 2e5 + 5;

void solve(){
    int i,n;
    cin>>n;
    int a=n%10;
    int b=(n/10)%10;
    int c=(n/100)%10;
    if(a==7||b==7||c==7)
        cout<<"Yes";
    else
        cout<<"No";
}

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

Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
  int N;
  char S[110] = {};
  int i, j, k, l;
  int count = 0;
  int max = -1;
  int flag1;
  int flag2;
  scanf("%d %s", &N, S);
  for(i = 0; i < N - 1; i++){
    count = 0;
    //S[i]とS[i+1]の間で切断
    for(j = 0; j < 26; j++){
      //左側に'a'+jが含まれるか確認
      flag1 = 0;
      for(k = 0; k <= i; k++){
        if(S[k] == ('a' + j)){
          flag1 = 1;
          break;
        }
      }
      //ここでflag1 == 1ならば，左側に'a'+jが含まれる

      //右側に'a'+jが含まれるか確認
      flag2 = 0;
      for(k = i + 1; k < N; k++){
        if(S[k] == ('a' + j)){
          flag2 = 1;
          break;
        }
      }
      //ここでflag２ == 1ならば，右側に'a'+jが含まれる

      if(flag1 == 1 && flag2 == 1){
        count++;
      }
    }
    if(count > max){
      max = count;
    }
  }
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
 
int search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key){
    i++;
  }
  return i!=n;
}
 
int main(){
  int i,n,A[10000],q,key,sum=0;
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)){
      sum++;
    }
  }
  printf("%d\n",sum);
}

Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

string str;
ll dp[MAXN][15], n;

void norm(ll &x) {
    x = x % MOD;
}

/*

x * 10 + d = rm
x = (rm - d)  / 10
 */
void tran(ll id, ll rm, ll di) {
    ll rmmd = rm - di < 0 ? rm - di + 13 : rm - di;
    norm(dp[id][rm] += dp[id-1][rmmd * 4 % 13]);
}
/********** Good Luck :) **********/
int main()
{
    IOS();

    cin >> str;

    n = SZ(str);
    dp[0][0] = 1;
    REP1 (i, n) {
        REP (r, 13) {
            if (str[i-1] == '?') {
                REP (j, 10) {
                    tran(i, r, j);
                }
            } else {
                tran(i, r, str[i-1] - '0');
            }
        }
    }

    cout << dp[n][5] << endl;
    return 0;
}


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

#define rep(i,n)  for(int i=0;i<n;++i)
#define sc1(a)  scanf("%d",&a)

int main(){
    int n,m=0,ans=0;
    int h[25];
    sc1(n);
    rep(i,n) sc1(h[i]);
    rep(i,n) {
        if (h[i]>=m) {
            m=h[i];
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3736
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

typedef pair<int, int> pii;

int n;

int main() {
	INIT
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
	}
	bool flag = true;
	for (int i = 0; i < n; ++i) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 == 0 || A[i] % 5 == 0) {
				continue;
			} else {
				flag = false;
				break;
			}
		}
	}
	if (flag) cout << "APPROVED\n";
	else cout <<"DENIED\n";

	return 0;
}

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

int main()
{
    int h, n, c = 0, d;
    char dummy;
    scanf("%d %d", &h, &n);
    scanf("%c", &dummy);

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

    if (h <= c)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
  int a, b;
	cin >> a >> b;
            if (a <= 9 and b <= 9)
              cout << a * b << "\n";
            else
              cout << "-1\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//std::cout << std::setfill('0') << std::right << std::setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int N,K; cin>>N>>K;
  ll h[N]; CINA(h,N);
  sort(h,h+N);
  ll r = pow(10,9)+1;
  REP(i,N-K+1){
    ll temp = h[i+K-1]-h[i];
    if(temp<r) r = temp;
  }
  cout << r << "\n";
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char S;
  int N = 1;
  
  // ここにプログラムを追記
  cin >> S;
  
  if (S == 'a' || S == 'e' || S == 'i' || S == 'o' || S == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll n, k;
	cin >> n >> k;
	vector<ll> p(n), c(n);
	for (ll i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (ll i = 0; i < n; i++) cin >> c[i];

	vector<vector<ll>> cycle(n);
	for (ll i = 0; i < n; i++) {
		vector<bool> v(n, false);
		cycle[i].push_back(i);
		v[i] = true;
		ll prev = i;
		while (!v[p[prev]]) {
			cycle[i].push_back(p[prev]);
			v[p[prev]] = true;
			prev = p[prev];
		}
	}

	ll ans = -1e10;
	for (ll i = 0; i < n; i++) {
		ll m = cycle[i].size();
		vector<ll> sum(m + 1, 0);
		for (ll j = 0; j < m - 1; j++) sum[j + 1] = sum[j] + c[cycle[i][j + 1]];
		sum[m] = sum[m - 1] + c[cycle[i][0]];
		ll subans = sum[m] * (k / m), maxsum = -1e10;
		if (k < m) {
			for (ll j = 1; j < k % m + 1; j++) maxsum = max(maxsum, sum[j]);
			subans += maxsum;
		} else {
			for (ll j = 0; j < k % m + 1; j++) maxsum = max(maxsum, sum[j]);
			subans += maxsum;
		}
		maxsum = -1e10;
		for (ll j = 1; j <= min(m, k); j++) maxsum = max(maxsum, sum[j]);
		ans = max({ans, subans, maxsum});
		maxsum = -1e10;
		for (ll j = 1; j <= m; j++) maxsum = max(maxsum, sum[j]);
		if (k >= m && sum[m] > 0) ans = max(ans, sum[m] * (k / m - 1) + maxsum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 218580
//iコスト = i列目を消すときにi - i + 1列間で生じるコスト(1 <= i <= N - 1)とおく。このとき,
//合計コスト = 1コスト + … + N-1コストとなる。
//1コストは3列目以降を消す順序には影響しない。つまり, 12321と消しても12213と消しても, 1コストは変化しない(2コストは変化するが…)
//{1}_Nに2を挿入 -> {1,2}_NNに3を挿入 ->{1,2,3}_NNNに4を挿入 -> という風に操作列を作ってみよう。すると…
//1コスト, 2コスト, …, はそれぞれ独立に最小化できることが分かる. 
//よって、それぞれの最小値を求め、その和を出力すればよい。
//・1回消すときのコストは前処理で計算 -> 前処理も, 使いまわしetcで工夫しないとO(H^3W)になってTLEする。工夫すればO(H^2W)になって楽勝.

//注意：
//1列目を完全に消してから3列目以降を消す～とすると最適にならないことがある。それは…1列目を小さなコストで消すために適切な順序で2列目を消す必要があるが…
//2列目を小さなコストで消すために, 3列目をあらかじめ消す方がよい場合があるからだ。 -> 
//操作順の候補を(左から～みたいに）限定するのではなく, あくまでも操作順は全部考慮する（1->2->3->4->3->4->3->2->1みたいなのも考慮する）ということに注意。
//感想：
//挿入系になれていないせいで、考察が混乱した。
//操作列を末尾に追加する感じで作ってしまうと, 状態を上手くまとめられず, O(H^W)とかになる。 
//-> 貪欲もなさそうだし, 操作順を左から～っぽくできないし, スコアは隣接する横ブロックだけで計算するし, 挿入っぽいでしょ！

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cassert>
using namespace std;

int h, w;
char c[300][301];
int cost[301][301][301];
int dp[301][301][301];

//i列目はx個消した, i+1列目はy個消した
//ここからの「コストiの増分」の最小値はいくらか？
int dfs(int i, int x, int y) {
	if (x == h && y == h) { return 0; }
	if (dp[i][x][y] != -1) { return dp[i][x][y]; }
	
	int ret = 1145141919;
	if (x < h) {
		ret = min(ret, dfs(i, x + 1, y) + cost[i][x][y]);
	}
	if (y < h) {
		ret = min(ret, dfs(i, x, y + 1) + cost[i][x][y]);
	}
	return (dp[i][x][y] = ret);
}

signed main() {
	int i, j, k;
	
	cin >> h >> w;
	for (i = 0; i < h; i++) { cin >> c[i]; }
	
	for (i = 0; i < w - 1; i++) for (j = 0; j <= h; j++) for (k = 0; k <= h; k++) dp[i][j][k] = -1;
	
	//コストの前計算
	for (i = 0; i < w - 1; i++) {
		for (j = h; j >= 0; j--) {
			for (k = h; k >= 0; k--) {
				if (j == h || k == h) {
					cost[i][j][k] = 0;
				}
				else {
					int p = h - 1 - j;
					int q = h - 1 - k;
					int plus = (p >= 0 && q >= 0 && c[p][i] == c[q][i + 1]);
					cost[i][j][k] = cost[i][j + 1][k + 1] + plus;
				}
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i < w - 1; i++) {
		ans += dfs(i, 0, 0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 212096
n, k = map(int, input().split())
klist = [0 for _ in range(k)]
w = [int(input()) for _ in range(n)]
def check(h, wl, knum):
    cnt = 1
    tmpw = 0
    for w in wl:
        tmpw += w
        if tmpw > h:
            cnt += 1
            tmpw = w
            if cnt > knum:
                return False
    return True
left = max(w)
right = sum(w)
while left  < right:
    mid = (right + left)//2
    if check(mid, w, k):
        right = mid
    else:
        mid += 1
        left = mid
print(mid)
        

Measured memory_bytes: 11680
//                             .
//                            .:.
//                            :|:
//                           .:|:.
//                           ::|::
//            :.             ::|::             .:
//            :|:.          .::|::.          .:|:
//            ::|:.         :::|:::         .:|:;
//            `::|:.        :::|:::        .:|::'
//             ::|::.       :::|:::       .::|:;
//             `::|::.      :::|:::      .::|::'
//              :::|::.     :::|:::     .::|::;
//              `:::|::.    :::|:::    .::|::;'
//     `::.      `:::|::.   :::|:::   .::|::;'     .:;'
//      `:::..    `;::|::.  :::|:::  .::|:::    ::::;
//        `:::::.    ':|::. :::|::: .::|:'   ,::::;'
//          `:::::.    ':|:::::|:::::|:'   :::::;'
//            `:::::.:::::|::::|::::|::::.,:::;'
//               ':::::::::|:::|:::|:::::::;:'
//                  ':::::::|::|::|:::::::''
//                       `::::::::::;'
//                      .:;'' ::: ``::.
//                           :':':
//                             ;                             

//             ,d                                                  
//             88                                                  
// ,adPPYba, MM88MMM ,adPPYba,  8b,dPPYba,   ,adPPYba, 8b,dPPYba,  
// I8[    ""   88   a8"     "8a 88P'   `"8a a8P_____88 88P'   "Y8  
//  `"Y8ba,    88   8b       d8 88       88 8PP""""""" 88          
// aa    ]8I   88,  "8a,   ,a8" 88       88 "8b,   ,aa 88          
// `"YbbdP"'   "Y888 `"YbbdP"'  88       88  `"Ybbd8"' 88  

// ++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++ 
// ++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++ 

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define deb(x) cerr << ">> " << #x << " : " << x << "\n" // never forget to comment out
#define endl '\n'
#define RAGE ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

const ll inf = 1e18 + 42;

const ll MAX = 1e9;

void solve()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	for(ll i = 0; i < m; i++)
		cin >> a[i];
	ll sum = accumulate(all(a), 0);
	ll ans = (n - sum) >= 0 ? (n - sum) : -1;
	cout << ans << endl;
}	

int main()
{
	RAGE
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	ll t;
	//cin >> t;
	//while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 11116
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    int n;
    double tmp;
    string tmp2;
    double ans = 0;
    cin >> n;
    for(int i = 0 ;i < n ; i++){
        cin >> tmp >> tmp2;
        if (tmp2 == "JPY"){
            ans += tmp;
        }
        else{
            ans += tmp*380000.0;
        }
    }
    cout <<  ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll w, a, b;
        cin >> w >> a >> b;

        if (a > b) swap(a, b);
        cout << max(0LL, b - (a + w)) << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int X, N;
int used[MAX_N];

void solve() {
	cin >> X >> N;
	rep(i, 0, N) {
		int a; cin >> a; used[a] = 1;
	}
	int res = -1;
	rep(i, 0, 100 + 2) {
		if(used[i]) continue;
		if(res == -1 || abs(i - X) < abs(res - X)) {
			res = i;
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}




Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
using namespace std;

int n;
string s;
int cntE[300001];
int cntW[300001];

signed main() {
	int i;
	
	cin >> n >> s;
	for (i = 0; i < n; i++) {
		if (s[i] == 'E') cntE[i + 1] = 1;
		else cntW[i + 1] = 1;
	}
	for (i = 1; i <= n; i++) { cntE[i] += cntE[i - 1]; cntW[i] += cntW[i - 1]; }
	
	int ans = n + 1;
	for (i = 0; i < n; i++) {
		int left = cntW[i];
		int right = cntE[n] - cntE[i + 1];
		ans = min(ans, left + right);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3076
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] base = new int[26];
		char[] org = "AIDUNYAN".toCharArray();
		for (char c : org) {
		    base[c - 'A']++;
		}
		char[] next = "AIZUNYAN".toCharArray();
		char[] arr = sc.next().toCharArray();
		int length = arr.length;
		int left = 0;
		int right = -1;
		int[] count = new int[26];
		while (right < length) {
		    while (right < length && right - left < org.length - 1) {
		        right++;
		        if (right < length) {
		            count[arr[right] - 'A']++;
		        }
		    }
		    if (right >= length) {
		        break;
		    }
	        if (equals(count, base)) {
	            for (int i = left; i <= right; i++) {
	                arr[i] = next[i - left];
	            }
	            left = right + 1;
	            Arrays.fill(count, 0);
	        } else {
	            count[arr[left] - 'A']--;
	            left++;
	        }
		}
	    System.out.println(arr);
	}
	
	static boolean equals(int[] arr, int[] another) {
	    for (int i = 0; i < arr.length; i++) {
	        if (arr[i] != another[i]) {
	            return false;
	        }
	    }
	    return true;
	}
}



Measured memory_bytes: 26380
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,m; cin>>n>>m;
    vp a(n);
    rep(i,n) cin>>a[i].F>>a[i].S;

    sort(all(a));
    int res=0,num=0;
    rep(i,n){
        res+=min(a[i].S,m-num)*a[i].F;
        num+=min(a[i].S,m-num);

        if(num==m){
            cout<<res<<endl;
            return 0;
        }
    }
}

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

	public static void main(String[] args) {
		int MOD = 998244353;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] L = new int[K];
		int[] R = new int[K];
		for(int i = 0; i < K; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		long[] dp = new long[N+1];
		long[] dpsum = new long[N+1];
		dp[1] = dpsum[1] = 1;
		for(int i = 2; i <= N; i++) {
			for(int j = 0; j < K; j++) {
				int li = i - R[j];
				int ri = i - L[j];
				if(ri < 0)
					continue;
				li = Math.max(li, 1);
				dp[i] += dpsum[ri] - dpsum[li-1] + MOD;
				dp[i] %= MOD;
			}
			dpsum[i] = (dpsum[i-1] + dp[i]) % MOD;
		}
		System.out.println(dp[N]);
	}

}

Measured memory_bytes: 39684
n= int(input())
a = list(map(int,input().split()))
now = a[0] 
a.sort()
d = {}
for x in a:
    if x not in d:d[x] = 1
    else:d[x] += 1
res = len(d)
if res%2:print(res )
else:print(res-1)

Measured memory_bytes: 17396
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, t;
    cin >> n >> t;
    auto dp = make_v(n+1, t+1, -INF<int>);
    dp[0][0] = 0;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= t; ++j) {
            chmax(dp[i+1][j], dp[i][j]);
            if(j != t)chmax(dp[i+1][min(t, j+v[i].first)], dp[i][j]+v[i].second);
        }
    }
    cout << *max_element(dp.back().begin(),dp.back().end()) << "\n";
    return 0;
}

Measured memory_bytes: 35584
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());

        long sum = 0;
        int i = 0;

        while (sum < n)
        {
            sum += (++i);
        }

        long d = sum - n;

        for (int j = 1; j <= i; j++)
        {
            if (j != d) WriteLine(j);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>

int main(void) {
	int n;
	int d[105];
	scanf("%d", &n);
	int i;
	int count = 0;
	


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

	}
	int k;
	for (i = 0; i < n; i++) {
		for (k = i+1 ; k < n; k++) {
			count += d[k] * d[i];

		}
	}
	
	printf("%d", count);

	return 0;
}



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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> P(N); for (ll i = 0; i < N; i++) { cin >> P[i]; P[i]--; }
  vector<ll> C(N); for (ll i = 0; i < N; i++) cin >> C[i];

  ll ans = -1e18;
  for (ll i = 0; i < N; i++) {
    vector<ll> SUM(N + 1, 0);
    vector<ll> MAX(N + 1, -1e18);
    ll pos = i;
    ll cnt = 0;
    for (ll j = 0; j < N; j++) {
      pos = P[pos];
      SUM[j + 1] = SUM[j] + C[pos];
      MAX[j + 1] = max(MAX[j], SUM[j + 1]);
      cnt++;
      if (pos == i) break;
    }
    ll temp = 0;
    if (K < cnt) {
      temp = MAX[K];
    } else if (SUM[cnt] < 0) {
      temp = MAX[cnt];
    } else {
      ll q = K / cnt;
      ll r = K % cnt;
      ll temp1 = q * SUM[cnt] + MAX[r];
      ll temp2 = (q - 1) * SUM[cnt] + MAX[cnt];
      temp = max(temp1, temp2);
    }
    ans = max(ans, temp);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3784
#include <iostream>

void eat_and_exchange(int &player_cookies, int &enemy_cookies) {
  if (player_cookies % 2 == 1)
    --player_cookies;
  int move_cookies = player_cookies / 2;
  player_cookies -= move_cookies;
  enemy_cookies += move_cookies;
}

int main() {
  int a, b, k;
  std::cin >> a;
  std::cin >> b;
  std::cin >> k;

  for (int i = 0; i < k; i++) {
    if (i % 2 == 0) {
      eat_and_exchange(a, b);
    } else {
      eat_and_exchange(b, a);
    }
  }

  std::cout << a << " " << b << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
   int h,w;
   cin>>h>>w;
   vector<string> a(h);
   rep(i,0,h) cin>>a[i];

   vector<int> x(w),y(h);
   rep(i,0,w) x[i]=false;
   rep(i,0,h) y[i]=false;

   rep(i,0,h){
      rep(j,0,w){
         if(a[i][j]=='#'){
            y[i]=true;
            x[j]=true;
         }
      }
   }

   rep(i,0,h){
      if(y[i]==true){
         rep(j,0,w){
            if(x[j]==true){
               cout<<a[i][j];
            }
         }
         cout<<endl;
      }
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
int main()
{
    vector<ll> a;
    a.pb(2);
    a.pb(1);
    int n;
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        a.pb(a[i-1]+a[i-2]);
    }
    cout<<a[n];
    return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        a: [i32; n],
    }
    let mut j = 0;
    for i in k..n {
        if a[i] > a[j] {println!("Yes");}
        else {println!("No");}
        j += 1;
    }
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
signed main(){
    gearup
    ll n,k; cin >> n >> k;
    ll sum = n*(n+1)/2;
    ll res = 0;
    for(ll i=k;i<=n+1;i++){
        ll mi = i*(i-1)/2;
        //mi %= MOD;
        ll ma = sum - (n+1-i)*(n-i)/2;
        //ma %= MOD;
        res = (res + ma - mi + 1) % MOD;
    }
    out(res);
}


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

int main(){

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

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 52;
ll i,p,n;
string s;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>s;
    n = s.length();
    s = "$" + s;
    p = 1;
    rep(i,1,n + 1){
        if(i & 1){
            if(s[i] == 'L') p = 0;
        }
        else{
            if(s[i] == 'R') p = 0;
        }
    }
    cout<<(p ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>



#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;

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


    ll cnt = 0;
    vector <ll> A(N);
    REP(i,N)
    {
        cin >> A[i];
    }

    bool owa = false;
    while(1)
    {
        REP(i,N)
        {
            if(A[i] % 2 == 0)
            {
                A[i] = A[i]/2;
            }
            else
            {
                owa = true;
                break;
            }
        }
        if(owa == true)break;
        cnt++;
    }

    cout << cnt << endl;
}




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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,q,a,b,p,x,cnt[200000],memo[200000];
vector<int> v[200000];
queue<int> que;
bool visited[200000];

void kr(int a, int now) {
    if (memo[a]) return;
    memo[a] = now;
    for (auto i : v[a]) kr(i,now+1);
}

signed main() {
    cin >> n >> q;
    rep(i,n-1) {
        cin >> a >> b;
        --a, --b;
        v[a].pb(b);
        v[b].pb(a);
    }
    kr(0,1);
    rep(i,q) {
        cin >> p >> x;
        --p;
        cnt[p] += x;
    }
    que.push(0);
    while(que.size()) {
        int qf = que.front();que.pop();
        if (visited[qf]) continue;
        visited[qf] = true;
        for(auto i : v[qf]) {
            if (memo[qf] < memo[i]) cnt[i] += cnt[qf];
            que.push(i);
        }
    }
    rep(i,n) cout << cnt[i] << " ";cout << endl;
}




Measured memory_bytes: 22912
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------
int MAX_N=306;
bool dp[100005][2];
 int n,k;vector<int>a(100005);
int dfs(int k,int t){
    if(dp[k][t]>0)
        return dp[k][t];
    int ans=0;
    for(int i=0;i<n;i++)
        if(k>=a[i])
            ans |= !dfs(k-a[i],!t);
    return dp[k][t]=ans;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
   cin>>n>>k;
    
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(dfs(k,0)==0)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main() {
	int K, A, B;
	unsigned long biscuit = 1;

	cin >> K >> A >> B;

	if ((B - A) < 2) {
		biscuit += K;
	}

	else if(K < A){
		biscuit += K;
	}

	else {
		K = K - (A - 1);
		unsigned long diff = B - A;
		unsigned long count = K / 2;
		biscuit = A;
		biscuit += diff * count;
		biscuit += K % 2;

	}
	cout << biscuit;



	return 0;
}


Measured memory_bytes: 256