akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans = 0;
    int t = n-1;
    rep(i,n) {
        int lim = 2;
        if(i==0) lim = 1;
        rep(j,lim) {
            if(t) {
                ans += a[i];
                t--;
            }
        }
    }
    cout << ans << endl;
}
    




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

typedef long long int ll;

int main()
  
{
	ll n;cin>>n;
  vector<ll> a(n);
  
  for(auto &v:a)
    cin>>v;
  
  	for(int i=0;i<n;i++)
    {
    	if(a[i]%2==0)
        {
        	if(a[i]%3==0||a[i]%5==0)
              	continue;
          	else
            {
            	cout<<"DENIED";return 0;
            }
        }
    }
  cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <iostream>

int main() {

	int a, b;

	std::cin >> a >> b;

	if ( a <= 0 and 0 <= b ) {
		std::cout << "Zero" << std::endl;
		return 0;
	}

	int cnt = ( a > 0 ? 0 : b-a+1 );

	if ( cnt % 2 ) {
		std::cout << "Negative" << std::endl;
	} else {
		std::cout << "Positive" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,k,ans = 1e9;
    cin >> n >> k;
    vector<ll> x(n);
    rep0(i, n)cin >> x[i];
    rep0(i, n - k + 1){
        if(x[i] <= 0 && x[i + k - 1] <= 0)ans = min(ans,abs(x[i]));
        else if(x[i] >= 0 && x[i + k - 1] >= 0)ans = min(ans,abs(x[i + k - 1]));
        else ans = min(ans,min(x[i + k - 1] * 2 + abs(x[i]),x[i + k - 1] + abs(x[i] * 2)));
    }
    pf(ans)
    return 0;
}


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

// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  if (d[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  sort(d.begin(), d.end());
  vector<P> p(1, P(d[0], 0));
  rep(i, n) {
    if (p.back().first == d[i])
      p.back().second++;
    else
      p.emplace_back(d[i], 1);
  }

  // for (auto x : p) cerr << x.first << " " << x.second << endl;

  if (!(p[0].first == 0 && p[0].second == 1)) {
    cout << 0 << endl;
    return 0;
  }

  rep(i, p.size()) {
    if (p[i].first != i) {
      cout << 0 << endl;
      return 0;
    }
  }

  mint ans = 1;
  rep(i, p.size() - 1) rep(j, p[i + 1].second) ans *= p[i].second;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4680
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int a,b,c,h[1111]={},f=0;
	string s,t;
	double d,e;
	cin>>  a ;

	if(1)cout<<48-a  <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//

ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if (a==0) return 0; if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}




int main() {

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

    out(modexp(m,n));

    return 0;
}











Measured memory_bytes: 3092
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int n;
string a[15], b[15], s, g;

int dfs(string t) {
  // cout << t << endl;
  if(t == g) return 0;
  if(t.size() > g.size()) return INF;
  int res = INF;
  REP(i, n) {
    // i???????????§?????????????????¨
    string ret = "";
    REP(j, t.size()) {
      if(j <= t.size() - a[i].size() && t.substr(j, a[i].size()) == a[i]) {
        ret += b[i];
        j += a[i].size()-1;
      } else {
        ret += t[j];
      }
      // cout << "j:" << j << " " << ret << endl;
    }
    // cout << i << " " << ret << endl;
    if(ret != t) chmin(res, dfs(ret)+1);
  }
  return res;
}

signed main(void)
{
  while(true) {
    cin >> n;
    if(!n) break;
    REP(i, n) cin >> a[i] >> b[i];
    cin >> s >> g;

    int ret = dfs(s);
    if(ret >= INF) cout << "-1" << endl;
    else cout << ret << endl;
  }

  return 0;
}

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

int main()
{
  double x1, y1, x2, y2;
  double dx, dy;
  cin >> x1 >> y1 >> x2 >> y2;

  dx = x2 - x1;
  dy = y2 - y1;
  cout << setprecision(10) << sqrt(dx*dx + dy*dy) << endl;

  return 0;
}

  


Measured memory_bytes: 3280
import numpy as np

def main():
  N, M = input().split()
  N = int(N)
  M = int(M)

  # H = []
  H = [int(i) for i in input().split()]
  # arg_list = list(np.argsort(np.array(H))[::-1])
  bad_obs = set()

  for m in range(M):
    A, B = input().split()
    A = int(A)-1
    B = int(B)-1
    if H[A] < H[B]:
      bad_obs.add(A)
    elif H[A] > H[B]:
      bad_obs.add(B)
    else:
      bad_obs.add(A)
      bad_obs.add(B)

  print(len(H) - len(bad_obs))


if __name__ == "__main__":
    main()

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		int x = i;
		int cnt = 0;
		while(x) {
			cnt++;
			x /= 10;
		}
		
		ans += cnt % 2;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<int> C;
vector<int> R[500010];

int seg[1048576], ANS[500010];

void raq(int s, int t, int k = 1, int l = 0, int r = 524287) {
	if (t < l || r < s)return;
	if (s <= l && r <= t) {
		seg[k]++;
		return;
	}
	raq(s, t, k * 2, l, (l + r) / 2);
	raq(s, t, k * 2 + 1, (l + r) / 2 + 1, r);
}

int gets(int x) {
	x += 524288;
	int ans = 0;
	while (x) {
		ans += seg[x];
		x /= 2;
	}
	return ans;
}

int main() {
	for (int i = 0;i < 1048576;i++) {
		seg[i] = 0;
	}
	for (int i = 0;i < 500010;i++) {
		ANS[i] = 0;
	}
	int N, Q;
	cin >> N >> Q;
	C = vector<int>(N);
	for (int i = 0;i < N;i++) {
		cin >> C[i];
		R[C[i]].push_back(i);
	}
	vector<tuple<int, int, int>> LR(Q);
	int l, r;
	for (int i = 0;i < Q;i++) {
		cin >> l >> r;
		l--;r--;
		LR[i] = (make_tuple(l, r, i));
	}
	sort(all(LR));
	int ind = 0;
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> P;
	vector<pair<int, int>> ID;
	for (int i = 0;i < N;i++) {
		while (ind < Q && get<0>(LR[ind]) == i) {
			P.push(make_tuple(get<1>(LR[ind]), ind, get<2>(LR[ind])));

			ID.push_back({ get<0>(LR[ind]),ind });
			ind++;
		}

		auto it = lower_bound(all(R[C[i]]), i);
		if (it == R[C[i]].begin()) {
			raq(0, ind - 1);
		}
		else {
			it--;
			pair<int, int> ser = { *it + 1,-MOD };
			auto it2 = lower_bound(all(ID), ser);
			if (it2 != ID.end()) {
				raq((*it2).second, ind - 1);
			}
		}

		while (!P.empty() && get<0>(P.top()) == i) {
			ANS[get<2>(P.top())] = gets(get<1>(P.top()));
			P.pop();
		}
	}
	for (int i = 0;i < Q;i++) {
		cout << ANS[i] << endl;
	}
}

Measured memory_bytes: 51984
n, m, x, y = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]
y_list = [int(i) for i in input().split()]


x_list.sort()
y_list.sort()
xmax = x_list[n-1]
ymin = y_list[0]

if ymin - xmax >= 1 and x < ymin and xmax+1 < y and y - x > 1:
    print("No War")
else:
    print("War")




Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable {

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
		//long n = Long.parseLong(sc.next());
    	//int[] ar = new int[3];
    	//ar[0]=Integer.parseInt(sc.next());
    	//ar[1]=Integer.parseInt(sc.next());
    	//ar[2]=Integer.parseInt(sc.next());
    	//Arrays.parallelSort(ar);
		//int n = Integer.parseInt(sc.next());
		//int k = Integer.parseInt(sc.next());
		//int l = Integer.parseInt(sc.next());
		//long a = Long.parseLong(sc.next());
		//String s = sc.next();
		//int k = Integer.parseInt(sc.next());
		//int m = Integer.parseInt(sc.next());
		//int x2000 = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		String str = sc.next();
		char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		//ArrayList<Integer> lists = new ArrayList<Integer>();
		//lists = new ArrayList;
		PrintWriter out = new PrintWriter(System.out);
		int ans = 0;
		if(c[0]==c[1]&&c[2]==c[3]&&c[0]!=c[2])
		{
			ans=1;
		}
		if(c[0]==c[2]&&c[1]==c[3]&&c[0]!=c[1])
		{
			ans=1;
		}
		if(c[0]==c[3]&&c[1]==c[2]&&c[0]!=c[1])
		{
			ans=1;
		}
		if(ans==0)
		{
			out.println("No");
		}
		else
		{
			out.println("Yes");
		}
		

		out.flush();
	}

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

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

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

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

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

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

    }


}

Measured memory_bytes: 21332
//tokenakatta

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> a(N+1, -1);
    rep(i, N) cin >> a.at(i+1);

    vector<int> dp(N+1, 0);

    for(int i=N; i>=1; i--){
        int tmp = 0;
        for(int j=2*i; j<=N; j+=i) tmp^=dp.at(j);
        dp.at(i)=tmp^a.at(i);
    }

    vector<int> ans;
    rep(i, N){
        if(dp.at(i+1)) ans.push_back(i+1);
    }

    cout << ans.size() << endl;
    rep(i, ans.size()){
        cout << ans.at(i) << " ";
        if(i+1==ans.size()) cout << endl;
    }
}

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long int li;


int main(void){
    ll ans=0;
    int k1=0,k7=0,k4=0,k9=0;
    int a;
    for(int i=0;i<4;i++){
        cin >> a;
        if(a==1)k1++;
        if(a==4)k4++;
        if(a==7)k7++;
        if(a==9)k9++;
            }
    if(k1==1&&k4==1&&k7==1&&k9==1)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        for i in range(2, n, 2):
            if not i == a[i-1] == a[i]:
                print(0)
                break
        else: print((2**(n//2))%1000000007)
else:
    for i in range(1, n, 2):
        if not i == a[i-1] == a[i]:
            print(0)
            break
    else: print((2**(n//2))%1000000007)

Measured memory_bytes: 14008
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AStationAndBus {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            if (S.equals("AAA") || S.equals("BBB")) {
                out.println("No");
            } else {
                out.println("Yes");
            }
        }

    }
}



Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	string o, e;
	cin >> o >> e;
	for(int i = 0; i < o.size(); i++){
		cout << o[i];
		if(i < e.size()) cout << e[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  override def main(args: Array[String]): Unit = {
    val input = io.StdIn.readLine.split(' ')

    val a = input(0).toInt
    val b = input(1).toInt
    val C = input(2).toInt

    val res = calc(a)(b)(C)
    println(res._1)
    println(res._2)
    println(res._3)
  }

  def calc: Int => Int => Int => (Double,Double,Double) = {
    a =>
      b =>
        C =>
          (a * b * Math.sin(rad(C)) / 2 , 
           a + b + len(a,b,Math.cos(rad(C))), 
           b * Math.sin(rad(C)))
  }
 
  def rad:Double => Double = _ * Math.PI/180
  def len:(Double,Double,Double) => Double 
        = (a,b,cosC) => Math.sqrt(a*a + b*b - 2*a*b*cosC)
  
}

Measured memory_bytes: 43892
import math

N = int(input())

def bunkai(n):
    factor={}
    tmp = int(math.sqrt(n)) + 1
    
    for num in range(2, tmp):
        while n%num == 0:
            n /= num
            try:
                factor[num] += 1
            except:
                factor[num] = 1
    if int(n) != 1:
        factor[int(n)] = 1
    
    return factor

bunchan = bunkai(N)
ans = 0

for k in bunchan.keys():
    cnt = 1
    while bunchan[k] - cnt >= 0 :
        bunchan[k] -= cnt
        cnt += 1
        ans += 1

print(ans)

Measured memory_bytes: 63432
n=int(input())
a=[0]*n
def int1(x):
  return int(x)-1
a[:]=map(int1,input().split())

r=0
#j0=0
#import numpy as np
ii=0
for jj in range(n):
  if a[jj]==ii:
    r+=1
    ii+=1
if r==0:
  print(-1)
  exit()

print(n-r)

Measured memory_bytes: 27804
def readinput():
    n=int(input())
    h=list(map(int,input().split()))
    return n,h

def main(n,h):
    count=0
    hmax=max(h)
    for i in range(hmax):
        j=0
        mizuyari=False
        for j in range(n):
            if h[j]>0:
                if mizuyari==False:
                    mizuyari=True
                    count+=1
                h[j]-=1
            else:
                mizuyari=False
    return count

if __name__=='__main__':
    n,h=readinput()
    ans=main(n,h)
    print(ans)


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

int main()
{
    vector<int> answer;

    while (1)
    {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0)
        {
            break;
        }
        vector<int> prices;

        for (int i = 0; i < n; i++)
        {
            int price;
            cin >> price;

            prices.push_back(price);
        }

        int max = 0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (i != j)
                {
                    int sum = prices.at(i) + prices.at(j);

                    if (sum <= m && sum > max)
                    {
                        max = sum;
                    }
                }
            }
        }

        answer.push_back(max);
    }

    for (int i = 0; i < answer.size(); i++)
    {
        if (answer.at(i) == 0)
        {
            cout << "NONE" << endl;
        }
        else
        {
            cout << answer.at(i) << endl;
        }
    }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
const  int maxn = 1e6 + 5;
typedef long long ll;
int a[maxn],b[maxn], c[maxn];
ll dp[maxn][3];
int main() {
//freopen("in.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (int i = 1; i <= n; i++) {
        dp[i][0] = max(dp[i - 1][2], dp[i - 1][1]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
    return 0;
}

Measured memory_bytes: 10496
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i);

    int q; cin >> q;
    vector<int> b(q),c(q);
    for(int i = 0;i < q;i ++) cin >> b.at(i) >> c.at(i);

    vector<int> count(100001);
    for(int i = 0;i < n;i ++) count.at(a.at(i)) ++;
    int sum = 0;
    for(int i = 0;i < n;i ++) sum += a.at(i);

    for(int i = 0;i < q;i ++){
        sum -= count.at(b.at(i)) * b.at(i);
        sum += count.at(b.at(i)) * c.at(i);

        count.at(c.at(i)) += count.at(b.at(i));
        count.at(b.at(i)) = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 6348
#include<cstdio>
#include<cstring>
#define rep(i,a) for(int i=0;i<(a);++i)
#define clr(a,v) memset((a),(v),sizeof(a))

const int mod = 10000;

int N, K, P[100];
int dp[101][3][2];

int main()
{
	clr( P, -1 );

	scanf( "%d%d", &N, &K );
	rep( i, K )
	{
		int A, B;
		scanf( "%d%d", &A, &B );
		P[A-1] = B-1;
	}

	if( ~P[0] )
		dp[0][P[0]][0] = 1;
	else rep( j, 3 )
		dp[0][j][0] = 1;
	
	rep( i, N-1 )
	{
		if( !~P[i+1] ) rep( j, 3 )
		{
			rep( k, 3 ) if( j != k )
				dp[i+1][j][0] = (dp[i+1][j][0]+dp[i][k][0]+dp[i][k][1]) % mod;

			dp[i+1][j][1] = (dp[i+1][j][1]+dp[i][j][0]) % mod;
		}
		else
		{
			rep( j, 3 ) if( j != P[i+1] )
				dp[i+1][P[i+1]][0] = (dp[i+1][P[i+1]][0]+dp[i][j][0]+dp[i][j][1]) % mod;

			dp[i+1][P[i+1]][1] = (dp[i+1][P[i+1]][1]+dp[i][P[i+1]][0]) % mod; 
		}
	}

	int ans = 0;
	rep( j, 3 ) rep( k, 2 )
		ans = (ans+dp[N-1][j][k]) % mod;

	printf( "%d\n", ans );

	return 0;
}

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

int main()
{
    int n, h;
    cin >> n;
    set<int> s;

    for (int i = 0; i < n; i++) {
        cin >> h;
        s.insert(h);
    }
    if (s.size() != n) puts("NO");
    else puts("YES");
}


Measured memory_bytes: 9728
N = int(input())
h = list(map(int, input().split()))
water = 0
ite = 0
while (ite < N):
    if h[ite] == 0:
        ite += 1
        continue
    kari_ite = ite
    water += 1
    while (kari_ite < N):
        if h[kari_ite] == 0:
            break
        else:
            h[kari_ite] -= 1
            kari_ite += 1
print(water)


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

int T, n, a, b, k, c, d;

bool check(int p) {
	int t = p / (k + 1);
	int x = a - (p - t), y = b - t;
	return y <= 1ll * x * k;
}

int main() {
	scanf("%d", &T);
	while (T --> 0) {
		scanf("%d %d %d %d", &a, &b, &c, &d);
		n = a + b, k = n / (min(a, b) + 1);
		int l = 0, r = n, mid;
		while (l < r) {
			mid = (l + r) >> 1;
			if (check(mid)) {
				l = mid + 1;
			} else {
				r = mid;
			}
		}
		for (int i = c; i <= d; i++) {
			if (i <= l) {
				putchar("AB"[i % (k + 1) == 0]);
			} else {
				putchar("AB"[(n - i + 1) % (k + 1) != 0]);
			}
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
N, M = gets.split.map(&:to_i)
a_list = gets.split.map(&:to_i)
m_table = {
  1 => 2,
  2 => 5,
  3 => 5,
  4 => 4,
  5 => 5,
  6 => 6,
  7 => 3,
  8 => 7,
  9 => 6
}
dp = Array.new(N + 10) { -1 }
dp[0] = 0
(0...N).each do |i|
  n = dp[i]
  next if n == -1
  a_list.each do |a|
    max = n * 10 + a
    m = m_table[a]
    dp[i + m] = max if dp[i + m] < max
  end
end
puts dp[N]


Measured memory_bytes: 38396
#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,m,i,j,p,a[100],s[100][21];
int main(void)
{
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<21;j++){
			s[i][j]=0;
		}
	}
	s[0][a[0]]=1;
	for(i=1;i<n-1;i++){
		for(j=0;j<21;j++){
			if(s[i-1][j]>0&&j+a[i]<=20){
				s[i][j+a[i]]+=s[i-1][j];
			}
			if(s[i-1][j]>0&&j-a[i]>=0){
				s[i][j-a[i]]+=s[i-1][j];
			}
		}
	}
	printf("%lld\n",s[n-2][a[n-1]]);
	return 0;
}

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

int main(){
  ll mod =1e9+7;
  ll n;
  string s;
  cin>>n;
  cin>>s;
  ll cnt=0;
  ll redi=0;
  ll cc=1;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='B'){
      if(redi%2==0){
        redi++;
      }else{
        cc*=redi;
        cc%=mod;
        redi--;
      }
    }else{
      if(redi%2==0){
        cc*=redi;
        cc%=mod;
        redi--;
      }else{
        redi++;
      }
    }
  }
  if(redi!=0){
    cout<<0<<endl;
    return 0;
  }
  for(ll i=1;i<=n;i++){
    cc*=i;
    cc%=mod;
  }
  cout<<cc<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/

using namespace std;

const int N=1e5+5;

ll n,k,q,a[N];

int main()
{
    cin >> n >> k >> q;
    for (int i=1;i<=n;i++)a[i]=k;
    ll points=0;
    while(q--)
    {
        ll x;
        cin >> x;
        a[x]++;
        points++;
    }
    for(int i=1;i<=n;i++)
    {
        a[i]-=points;
        if (a[i]<=0)cout << "No\n";
        else cout << "Yes\n";
    }
    return 0;
}


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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

const int INF=1e9+5;

void solve()
{
    int n,k;
    cin>>n>>k;

    vi v(n);
    forn(i,n){
        cin>>v[i];
    }

    vi dp(n,INF);
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j]=min(dp[j],abs(v[i]-v[j])+dp[i]);
            }
        }
    }

    cout<<dp[n-1]<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int ans = a.at(n-1) - a.at(0);
  
  cout << ans << endl;

}  

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

using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long> da(n);
    for(int i=0;i<n;i++){
        cin >> da[i];
    }
    vector<vector<long long>> dp(n,vector<long long> (n,0)),si(n,vector<long long> (n,0));
   /* for(int i=0;i<n;i++){
        dp[i][i]=da[i];
    }*/
    for(int i=0;i<n;i++){
        long long me=0;
        for(int j=0;j<n-i;j++){
            me+=da[j+i];
            si[i][i+j]=me;
        }
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<n-i;j++){
            long long ans=10e12;
            for(int k=0;k<i;k++){
                ans=min(ans,dp[j][j+k]+dp[j+k+1][j+i]);
            }
            dp[j][j+i]=ans+si[j][i+j];
        }
    }
    cout << dp[0][n-1] << endl;
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }*/
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

ll MOD(ll x, ll m) {
    ll r = x % m;
    if (r < 0) {
        r += m;
    }
    return r;
}

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    ll res = n + n*n + n*n*n;



    // cout << fixed << setprecision(6);
    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll n, x,i;
    cin >> n >> x;
    ll sum = 0;
ll a[n];
    for(i = 1; i <= n; i++)
        cin >> a[i];
 ll c=0,d=0;
    for( i = 2; i <= n; i++)
    {
        c = a[i] + a[i - 1];
        if(c <= x)
            continue;
        c -= x;
        sum += c;
        d = min(a[i], c);
        a[i] -= d;
    }
    cout << sum ;
}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
    cin>>t;
    int counter=0;bool ans=false;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a==b)counter++;
        else counter=0;
        if(counter>2){ans=true;cout<<"Yes"<<'\n';break;}
    }
    if(!ans)cout<< "No"<<'\n';
}


Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const LL INF = 1e9;
const LL MAXN = 10007;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	LL aI, aO, aT, aJ, aL, aS, aZ, k, d;
	cin >> aI >> aO >> aT >> aJ >> aL >> aS >> aZ;
	k = aO;
	d = min(min(aI, aJ), aL);
	k += 3 * d;
	aI -= d;
	aJ -= d;
	aL -= d;
	k += aI / 2 * 2;
	aI &= 1;
	k += aJ / 2 * 2;
	aJ &= 1;
	k += aL / 2 * 2;
	aL &= 1;
	if (aI + aJ + aL == 2 && d) ++k;
	cout << k;
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 256
from collections import Counter as ct

N = int(input())
res = []
x = N
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

res = ct(res)
cnt = 0
for i in res.values():
    tmp = 1
    for j in range(1, i + 1):
        i -= j
        if i >= 0:
            cnt += 1
        else:
            break
print(cnt)

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

int main() {
    int x, y; cin >> x >> y;
    bool ok=false;
    for (int i = 0; i <= x; i++) {
        if (y == (i * 2) + (x-i)*4) {
            ok = true;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3672
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using INT = long long;

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

    vector<INT> As(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> As[i];
    }

    map<pair<int, int>, INT> dp;
    dp[{ -1, 0 }] = 0;
    dp[{ -1, 1 }] = -LLONG_MAX / 2;

    for (int i = 0; i < N - 1; ++i)
    {
        dp[{i, 0}] = max(dp[{i - 1, 0}] + As[i], dp[{i - 1, 1}] - As[i]);
        dp[{i, 1}] = max(dp[{i - 1, 0}] - As[i], dp[{i - 1, 1}] + As[i]);
    }
    const auto ans = max(dp[{N - 2, 0}] + As.back(), dp[{N - 2, 1}] - As.back());
    cout << ans;

    return 0;
}

Measured memory_bytes: 13568
a = int(input())
num = [int(x) for x in input().split()]
ans = 0
biggest = 0

for n in range(len(num)):
    if n == 0:
        ans += 1
        biggest = num[n]
    elif num[n] <= biggest:
        ans += 1
        biggest = num[n]

print(ans)


Measured memory_bytes: 75984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main{
	public static void main(String[] args){
		Pattern pattern = Pattern.compile("this|that|the");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try{
			while ((buffer = br.readLine()) != null) {
				//暗号解読部
				char[] cipher = buffer.toCharArray();

				//暗号解読に正解していれば、解読文を表示
				//全ての文字を、ひとつ後ろの文字にずらす(例：a→b,z→a)
				for(int i=0;!pattern.matcher(String.valueOf(cipher)).find() & i < 25;i++){
					for(int j=0;j < cipher.length;j++){
						if(97 <= cipher[j] && cipher[j] <= 121){
							cipher[j]++;
						}else if(cipher[j] == 122){
							cipher[j] = 97;
						}
					}
				}
				System.out.println(cipher);
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 9156
#include<cstdio>
#include<iostream>
#include<functional>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long int>a;
	vector<long long int>x;
	

	long long int total = 0;
	for (int i = 0; i < n; i++) {
		long int ai;
		cin >> ai;
		a.push_back(ai);
		total += ai;
		x.push_back(total);
	}

	long long int min = 100000000000001;

	for (int i = 0; i < n-1; i++) {
		if (abs(total - 2*x[i]) < min) {
			min = abs(total - 2*x[i]);
		}
	}
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 3564
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(30).
01 A          PIC 9(10).
01 B          PIC 9(10).
01 num        PIC 9(10).
01 qt         PIC 9(10).
01 rm         PIC 9(10).
01 ans        PIC X(30).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO A B.
  COMPUTE num = A + B
  DIVIDE num BY 2 GIVING qt REMAINDER rm.
  IF ZERO = rm
    MOVE qt TO zs
    DISPLAY FUNCTION TRIM(zs)
  ELSE
    DISPLAY "IMPOSSIBLE"
  END-IF.
  STOP RUN.


Measured memory_bytes: 3956
#include"bits/stdc++.h"

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

using namespace std;
int main() {
	map<string, int>mp;
	int n, m,ans=0;
	cin >> n;
	string s;
	rep(i, n) {
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> s;
		mp[s]--;
	}
	for (auto p : mp) {
		ans = max(ans, p.second);
	}
	cout << ans << endl;
	return 0;
}


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

const int mod = 2019;

int main() {
  string s;
  cin >> s;
  vector<ll> d(s.size() + 1);
  int ten = 1;
  for (int i = s.size()-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % mod;
    d[i] = (d[i+1]+a) % mod;
    ten *= 10; ten %= mod;
  }
  vector<ll> cnt(s.size() + 1);
  ll ans = 0;
  for (int i = s.size(); i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


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

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

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

using namespace std;

#define int long long

signed main() {
	int h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
	}
	else cout << (((h * w) + 1) / 2) << endl;
	// cout << ((h - ((h + 1) / 2)) * (w / 2)) + ((h + 1) / 2) * (w - (w / 2)) << endl;
	return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer n = nil->next;
  while(n != nil && n->key != key)n=n->next;
  return n;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
  return ;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
  return ;
}

void deleteLast(){
  /* your code */
  NodePointer n = nil->prev;
  if ( n == nil ) return;
  deleteNode(n);
  return ;
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
  return;
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  //ここ
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

int main(){
	string x,y;
	cin>>x>>y;
	int xx=0;
	int yy=0;
	for(int i = 0; i<x.size();i++){
		if(x[i]== 'A') xx+=10;
		if(x[i]== 'B') xx+=11;
		if(x[i]== 'C') xx+=12;
		if(x[i]== 'D') xx+=13;
		if(x[i]== 'E') xx+=14;
		if(x[i]== 'F') xx+=15;
	}
	for(int i = 0; i<y.size();i++){
		if(y[i]== 'A') yy+=10;
		if(y[i]== 'B') yy+=11;
		if(y[i]== 'C') yy+=12;
		if(y[i]== 'D') yy+=13;
		if(y[i]== 'E') yy+=14;
		if(y[i]== 'F') yy+=15;
	}
	if(xx>yy){
		cout<<">";
	}
	else if(xx<yy){
		cout<<"<";
	}
	else{
		cout<<"=";
	}
	return 0;
}

Measured memory_bytes: 256
n, l = map(int, input().split())
ans = 10 ** 6
k = 0
for i in range(1, n + 1):
    t = l + i - 1
    if ans > abs(t):
        ans, k = abs(t), t
print(n * l + n * (n - 1) // 2 - k)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+7;

using namespace std;


int main(){
    auto calc = [](LL A,LL B,LL C){
        LL ans = C;
        while(C > A){
          //  cout<<C<<endl;
            LL ins = (C-A)/(A-B)+1;
            if(ins == 0)break;
            ans += (B%MOD)*(ins%MOD);
            C = C + B*ins - ins*A;
            ans %= MOD;
        }
        if(C == A)ans += B%MOD;
        return ans%MOD;
    };/*
    for(int a = 0;a < 1000;a++){
        for(int b = 1;b < a;b++){
            for(int c = 0;c < 1000;c++){
                LL ans = c;
                LL w = c;
                while(w >= a){
                    LL q = w/a;
                    ans += q*b;
                    w+=q*b-q*a;
                }

                if(max(ans,0LL) != calc(a,b,c)){
                    cout<<a<<" "<<b<<" "<<c<<" "<<max(ans,0LL)<<" "<<calc(a,b,c)<<endl;
                }

              //  cout<<a<<" "<<b<<" "<<c<<" "<<ans<<endl;
            }
        }
    }
    */

    LL A,B,C;cin >>A >> B >> C;
    cout<<calc(A,B,C)<<endl;
}



Measured memory_bytes: 3076
fun main(args: Array<String>) {
    val num = readLine()!!.split(" ").map { it.toInt() }
    val dice = DiceB(num[0], num[1], num[2], num[3], num[4], num[5])
    val count = readLine()!!.toInt()
    for (i in (0 until count)) {
        val tempList = readLine()!!.split(" ").map { it.toInt() }
        println(dice.getRight(top = tempList[0], front = tempList[1]))
    }
}

class DiceB(
    private val one: Int,
    private val two: Int,
    private val three: Int,
    private val four: Int,
    private val five: Int,
    private val six: Int
) {

    fun getRight(top: Int, front: Int): Int {
        return when (top) {
            one -> when (front) {
                two -> three
                three -> five
                four -> two
                else -> four
            }
            two -> when (front) {
                one -> four
                three -> one
                four -> six
                else -> three
            }
            three -> when (front) {
                one -> two
                two -> six
                five -> one
                else -> five
            }
            four -> when (front) {
                one -> five
                two -> one
                five -> six
                else -> two
            }
            five -> when (front) {
                one -> three
                three -> six
                four -> one
                else -> four
            }
            else -> when (front) {
                two -> four
                three -> two
                four -> five
                else -> three
            }
        }
    }
}


Measured memory_bytes: 32012
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const long double eps=1e-7;
const ll mod=1e6+3;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n;

int main(){
	cin>>n;
	ll t=1;
	while(t*t<=n) t++;
	cout<<(t-1)*(t-1)<<endl;
}

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

string remove0(string str){
  while(str.size() > 1 && str[0] == '0') str = str.substr(1);
  return str;
}

bool isnum(char c){
  return ('0' <= c && c <= '9');
}

string smax(string s1,string s2){
  if(s1.size() > s2.size()) return s1;
  if(s1.size() < s2.size()) return s2;
  if(s1 > s2) return s1;
  else return s2;
}

int main(){
  int w,h;
  while(cin>>w>>h,w+h){
    string max = "";
    vector<vector<char> > map(h,vector<char>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>map[i][j];
      }
    }
    vector<vector<string> > dp(h,vector<string>(w,""));
    for(int i=h-1;i>=0;i--){
      for(int j=w-1;j>=0;j--){
	if(isnum(map[i][j])){
	  if(dp[i][j] == "") dp[i][j] = string(1,map[i][j]);
	  if(i!=0 && isnum(map[i-1][j])){
	    dp[i-1][j] = smax(string(1,map[i-1][j]) + dp[i][j],dp[i-1][j]);
	  }
	  if(j!=0 && isnum(map[i][j-1])){
	    dp[i][j-1] = smax(string(1,map[i][j-1]) + dp[i][j],dp[i][j-1]);
	  }
	}
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	max = smax(max,remove0(dp[i][j]));
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

Measured memory_bytes: 1352
N = int(input())
s = str(input())
l = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ans = ""
for i in range(len(s)):
    ans+= l[(l.index(s[i])+N)%26]
print(ans)

Measured memory_bytes: 3064