akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
long long ans;

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int book=a[1];
	for(int i=2;i<=n;i++) {
		if(a[i]>book) book=a[i];
		else ans+=book-a[i];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4604
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <string.h>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

class Cake
{
public:
	Cake(int w, int d) : w(w), d(d) {}
	bool operator<(const Cake& dst) const
	{
		return this->Area() < dst.Area();
	}
	const int Area() const { return w * d; }
	Cake Cut(int p) {
		int l = w;
		bool side = true;
		while(p > l)
		{
			p -= l;
			side = !side;
			l = side ? w : d;
		}
		if (side)
		{
			int temp = (w - p) < p ? w-p : p;
			Cake c(w-temp, d);
			w = temp;
			return c;
		}
		else
		{
			int temp = (d - p) < p ? d-p : p;
			Cake c(w, d-temp);
			d = temp;
			return c;
		}
		return Cake(-1, -1);
	}
	int d, w, t;
};

int main(int argc, char const *argv[])
{
	int n,w,d;
	while(scanf("%d %d %d", &n, &w, &d) != EOF)
	{
		if (n == 0 && w == 0 && d == 0) break;
		std::list<Cake> cakes;
		cakes.push_back(Cake(w, d));
		REP(i, n)
		{
			int p, s;
			scanf("%d %d", &p, &s);
			std::list<Cake>::iterator itr = cakes.begin();
			for (int i = 0; i < (p-1) && itr != cakes.end(); itr++,i++);
			
			Cake& c1 = *itr;
			cakes.erase(itr);
			Cake c2 = c1.Cut(s);
			cakes.push_back(c1);
			cakes.push_back(c2);
		}
		cakes.sort();
		for (std::list<Cake>::iterator itr = cakes.begin(); itr != cakes.end();)
		{
			int area = itr->Area();
			itr++;
			if (itr == cakes.end())
			{
				printf("%d\n", area);
				break;
			}
			else
			{
				printf("%d ", area);
			}
		}
	}
	return 0;
}

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

int main() {
    long n,tmp1,ans;cin>>n;
    long long k,tmp2,s=0,t=0;cin>>k;

    pair<long,long>a[100002];
    for(long i=1;i<100002;++i){
        a[i-1].first=i;
        a[i-1].second=0;
    }
    
    for(long i=0;i<n;++i){
        cin>>tmp1>>tmp2;
        a[tmp1-1].second+=tmp2;
        }
    for(long j=0;j<100002;++j){
        t+=a[j].second;
            if(t>=k){
                ans=a[j].first;
                break;
            }
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[20], B[20], C[19];
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N - 1) cin >> C[i];

    int before = -2, ans = 0;
    REP(i, N) {
        ans += B[A[i] - 1];
        if (before + 1 == A[i] - 1) {
            ans += C[A[i] - 2];
        }
        before = A[i] - 1;
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	string s;
	cin >> s;
	string t = s;
	reverse(t.begin(), t.end());

	int len = s.size();
	int half = s.size() / 2;

	bool ans = true;
	if ( (s != t) || (s.substr(0, half) != t.substr(half+1, len-1)) ){
		ans = false;
	}

	if (ans){
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}

	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 = (a); i < (b); i++)
#define rer(i, a, b) for(int i = (a) - 1; i >= (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 pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vi;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest) { 
	cout << 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 = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
multiset<ll> L, R;
int A[MAX_N], B[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i] >> B[i];
	ll a = A[0], b = A[0];
	L.insert(A[0]); R.insert(A[0]);
	ll ans = 0;
	rep(i, 1, N) {
		a -= B[i] - A[i];
		b += B[i - 1] - A[i - 1];
		//debug(a, b);
		ll l = *L.rbegin(), r = *R.begin();
		if(a <= A[i] && A[i] <= b) {
			L.insert(A[i] - (a - l));
			R.insert(A[i] - (b - r));
			a = A[i]; b = A[i];
		}
		else if(A[i] < a) {
			ans += abs(A[i] - a);
			L.insert(A[i] - (a - l));
			L.insert(A[i] - (a - l));
			ll le = *L.rbegin() + (a - l);
			L.erase(--L.end());
			R.insert(le - (b - r));
			a = *L.rbegin() + (a - l);
			b = le;
		}
		else {
			ans += abs(A[i] - b);
			R.insert(A[i] - (b - r));
			R.insert(A[i] - (b - r));
			ll rb = *R.begin() + (b - r);
			R.erase(R.begin());
			L.insert(rb - (a - l));
			a = rb;
			b = *R.begin() + (b - r);
		}
		//debug(a, vi(all(L)));
		//debug(b, vi(all(R)));
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(5);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}






Measured memory_bytes: 10368
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)
            var line = ReadLine();
            int n = line[0];
            var words = new List<string>();

            for(int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                words.Add(s);
            }

            string ans = String.Join("", words.OrderBy(x => x));
            Console.WriteLine(ans);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

ll ruijo(ll n, ll k, ll m) {
  if(!k) return 1;
  if(k % 2 == 0){
    ll t = ruijo(n, k/2, m);
    return t * t % m;
  }
  return n * ruijo(n, k - 1, m) % m;
}
// n^k mod mを求めるやつ。繰り返し二乗法っていうらしい。
// 便利なので覚えておきたい。

int main() {
  int n, a, b;
  ll x = 1, y = 1, ca = 1, cb = 1, ans = 0;
  cin >> n >> a >> b;
  rep(i, a){
    x *= (n - i);
    x %= MOD;
    y *= (i + 1);
    y %= MOD;
  }
  ca = x * ruijo(y, MOD-2, MOD) % MOD;
/* 
   nCa = n!/a!(n-a)!
   xとyは毎回MODをとって、x / y % MODをすればnCaが出るはず(出ない)。
   MODつき割り算では、割る側は｢逆元｣を取ってそれを掛ければいいらしい。
   逆元はユークリッドの互除法か、フェルマーの小定理(今回はこれを使う)で求められる。
   y * y^(MOD-2) = 1 (mod 1000000007) らしい。なのでy^(MOD-2)する。
   クソ難しくて草
*/
  x = 1;
  y = 1;
  rep(i, b){
    x *= (n - i);
    x %= MOD;
    y *= (i + 1);
    y %= MOD;
  }
  cb = x * ruijo(y, MOD-2, MOD) % MOD;
  ans = ruijo(2, n, MOD) - ca - cb - 1;
  rep(i, 10) if(ans <= 0) ans += MOD; // ansがマイナスにならないように
  cout << ans % MOD << endl;
}

Measured memory_bytes: 256
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N;
  sc.scan(N);

  foreach (i; 0 .. 100) {
    foreach (j; 0 .. 100) {
      if ((i * 4) + (j * 7) == N) {
        writeln("Yes");
        return;
      } else if ((j * 4) + (i * 7) == N) {
        writeln("Yes");
        return;
      }
    }
  }

  writeln("No");
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long ll;
int power( ll x, int n, ll MOD){
  int res = 1;
  while( n > 0 ){
    if( n & 1 ) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
bool suspect(ll a,int s,ll d,ll n){
  ll x = power( a, d, n);
  if(x == 1) return true;
  for(int i = 0 ; i < s ; i++ ){
    if(x == n - 1) return true;
    x = x * x % n;
  }
  return false;
}
bool isPrime(ll n){
  if(n == 1 || ( n > 2 && n % 2 == 0)) return false;
  ll d = n - 1, s = 0, tmp[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23};
  while(d % 2 == 0) ++s, d /= 2;
  for(int i = 0 ; tmp[i] < n && i < 9 ; i++ ){
    if(!suspect( tmp[i], s, d, n)) return false;
  }
  return true;
}
int main(){
  int q, n,ret = 0;
  scanf("%d", &q);
  while(q--){
    scanf("%d", &n);
    ret += isPrime(n);
  }
  printf("%d\n", ret);
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,pri[N],tot,zhi[N],m;
long long ans[505][505];
long long lcm(long long x,long long y){
	if(!x)x=1;if(!y)y=1;
	return x/__gcd(x,y)*y;
}
int main(){
	scanf("%d",&n);
	if(n==2)return puts("7 3\n2 13"),0;
	for(int i=2;i<N;++i)
		if(!zhi[i]){
			pri[++tot]=i;
			for(int j=i+i;j<N;j+=i)zhi[j]=1;
		}
	for(int s=3;s<=n+n;s+=2){
		int p=pri[++m];
		for(int i=1;i<=n;++i){
			int j=s-i;
			if(1<=j&&j<=n)ans[i][j]=p;
		}
	}
	for(int s=n&1?2-n:1-n;s<n;s+=2){
		int p=pri[++m];
		for(int i=1;i<=n;++i){
			int j=i+s;
			if(1<=j&&j<=n)ans[i][j]*=p;
		}
	}
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=n;++j){
			if(!ans[i][j])
				ans[i][j]=lcm(lcm(ans[i-1][j],ans[i+1][j]),lcm(ans[i][j-1],ans[i][j+1]))+1;
			printf("%lld ",ans[i][j]);
		}
	return 0;
}


Measured memory_bytes: 5504
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
  
  # 使わない場合
  ret0 = dfs(cur + 1, a, b, c)
  # A に使う場合
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  # B に使う場合
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  # C に使う場合
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  
  return min(ret0, ret1, ret2, ret3)
  
print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
def main():
    K = int(input())
    from collections import deque
    A = deque([1,2,3,4,5,6,7,8,9])
    a = 0
    while True:
        x = A.popleft()
        xmod10 = x % 10
        if xmod10 != 0:
            A.append(10*x + xmod10 - 1)
        A.append(10*x + xmod10)
        if xmod10 != 9:
            A.append(10*x + xmod10 + 1)
        a += 1
        if a == K:
            print(x)
            break

if __name__ == "__main__":
    main()

Measured memory_bytes: 11980
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,k,n,up,dwn;
    string s;
    cin>>n;
    /*
        4/N- 1/i - 1/j = 1/k
    -> 4ij-Nj-Ni/Nij = 1/k
    -> k = Nij / 4ij-Nj-Ni
    let k=up/dwn
    */
    for(i=1; i<=3500; i++)
    for(j=1; j<=3500; j++)
    {
        up=n*i*j;
        dwn=4*i*j-n*j-n*i;
        if(dwn>0&&up%dwn==0)
        {
            return cout<<i<<" "<<j<<" "<<up/dwn<<endl,0;

        }
    }

   // cout<<"No solution"<<endl;




    return 0;
}





Measured memory_bytes: 3604
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = ReadLine().Split();
            long n = long.Parse(nk[0]);
            long k = long.Parse(nk[1]);
            long ans = 0;

            for(long i = k; i < n + 2; i++)
            {
                ans = (ans + ((n + 1 - i) * i + 1)) % (long)(1e9 + 7);
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27356
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;




int main() {
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	x = x % b;
	cout << x << endl;

	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if len(a)==1 and len(b)==1:
      return n//2
    return min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
  return n-a[0][1]-b[0][1]

print(main())


Measured memory_bytes: 21532
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;   
  	int a,b,n;
  	cin>>a>>b>>n;
  	int x=min(b-1,n);
  	cout<<a*x/b;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout)
#define pll pair <lli,lli>
#define vll vector <lli>
#define vpll vector <pll>
#define f first
#define s second
#define pb push_back
#define priq priority_queue
#define unm unordered_map
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld double
#define eb emplace_back
const long double pi = 3.1415926535898;
const lli mod=1e9+7;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
bool prime (lli k)
{
    if (k==1||k==0) return 0;
    bool flag=1;
    lli a=sqrt(k);
    for (int i=2;i<=a;i++)
    {
        if (k%i==0)
        {flag=0;break;}
    }
    return flag;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i*i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=2*i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
int main()
{
    fio;
    string s;
    cin>>s;
    if (s[s.length()-1]=='s')
    {
        s+='e';
        s+='s';
    }
    else
    {
        s+='s';
    }
    cout<<s;
    return 0;
}

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

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define veci vector<int>
#define pii pair<int,int>
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define repi(i,a,b) for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define fi first 
#define se second
#define all(v) v.begin(),v.end()

int mod=1e9+7;

int powerm(int x,int y, int M){ int res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
int  power(int x,int y){ int res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
bool isprime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;
while(T--){
    int n;
    cin>>n;
    unordered_map<int,int> m;
    int sum=0;
    rep(i,n){
        int x;
        cin>>x;
        sum+=x;
        m[x]++;
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        sum=sum-b*m[b]+c*m[b];
        cout<<sum<<endl;
        m[c]+=m[b];
        m[b]=0;
    }
}
    
    return 0;
}

Measured memory_bytes: 7124
def solve(n,k,a):
    mod = 10**9 + 7
    ans = 1
    l = 0
    r = n-1
    a.sort()
    
    if k%2 == 1:
        ans *= a[r]
        r-=1
    
    if ans < 0:
        ans = 1
        for i in range(k):
            ans*= a[n-i-1]
            ans%= mod
        return ans
    
    for i in range(k//2):
        tmp_min=a[l]*a[l+1]
        tmp_max=a[r]*a[r-1]
        if tmp_max> tmp_min:
            ans*=tmp_max
            ans%=mod
            r-=2
        else:
            ans*= tmp_min
            ans%=mod
            l+=2
    return ans


n, k = map(int, input().split())
A = list(map(int,input().split()))
ans = solve(n,k,A)
print(ans)

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

using namespace std;

typedef pair <int, int> pii;

int main(){
        int N, M;
        cin>>N>>M;
        vector <int> a, b, c, d;
        for(int i=0;i<N;i++){
                int aa, bb;
                cin>>aa>>bb;
                a.push_back(aa);
                b.push_back(bb);
        }
        for(int i=0;i<M;i++){
                int cc, dd;
                cin>>cc>>dd;
                c.push_back(cc);
                d.push_back(dd);
        }
        for(int i=0;i<N;i++){
                int ans;
                for(int j=0;j<M;j++){
                        if(j==0){
                                ans=j;
                        }
                        if((abs(a[i]-c[ans])+abs(b[i]-d[ans]))>(abs(a[i]-c[j])+abs(b[i]-d[j]))){
                                ans=j;
                        }
                }
                cout<<ans+1<<endl;
        }
        return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main()
{
	int n;
	cin >> n;
	vll a(n);
	map<ll, ll> cnt;
	rep(i,n) {
      	cin >> a[i];
      	cnt[a[i]]++;
    }
  	
  	ll ans = 0;
  	for(auto m : cnt){	
  		ans += m.se * (m.se - 1) / 2;
    }
    
  	rep(i,n){
      	ll temp = ans;
        temp -= cnt[a[i]] * (cnt[a[i]]-1) / 2;
        temp += (cnt[a[i]]-2) * (cnt[a[i]]-1) / 2;
      	cout << temp << endl;      	
    }
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  string s;
  cin>>h>>w;
  for(int i=0;i<h;++i)for(int j=0;j<w;++j){
    cin>>s;
    if(s=="snuke"){
      char c='A'+j;
      cout<<c<<i+1<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
int n,m;
int f[maxn],mp[maxn];
int find(int x){
	int y=x;
	while(x!=f[x]) x=f[x];
	while(y!=x) f[y]=x,y=f[y];
	return x;
}

int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;
		if(x>y) swap(x,y);
		int root1=find(x),root2=find(y);
		if(root1!=root2) f[root2]=root1;
	}
	int ans=0;
	for(int i=1;i<=n;i++) mp[find(i)]++,ans=max(ans,mp[find(i)]);
	cout<<ans; 
	return 0;	
} 

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

int main(){
int N,M,f;
  cin>>N>>M;
  vector<int>a(N+1);
 for(int i=0;i<2*M;i++){
   cin>>f;
   a[f]++;
}
   for(int i=1;i<N+1;i++){
cout<<a[i]<<endl;
}
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int n = 0;
    std::cin >> n;

    int counter = 0;
    int max_cnt = 0;
    int pre = 0;
    for(int i =0; i < n; ++i){
        int h = 0;
        std::cin >> h;

        if(pre >= h ){
            ++counter;
            max_cnt = std::max(max_cnt, counter);
        }
        else{
            counter = 0; // reset
        }

        pre = h;

    }

    std::cout << max_cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long H, N, A;
    int total = 0;
    cin >> H >> N;

    while (N>0) {
        cin >> A;
        total = total + A;
        N--;
    }

    if (total>=H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)(N); i++)

const int N = 1e+5 + 10;

vector<bool> isp(N+1, true);

void sieve() {
    isp[0] = false;
    isp[1] = false;
    for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
    }
}

int main() {
    // N以下の整数に対して素数判定をしてくれます。
    // nが素数ならば isp(n)=true、そうでなければ isp(n)=false
    sieve();
    // ex. 51から80までの素数を出力
    //for (int i=51; i<=80; i++) if (isp[i]) cout << i << endl;

    vector<int> f(N,0);
    
    int count = 0;
    for ( int i = 2; i < N; ++i){
        if ( i % 2 == 0 ) {
            f[i] = count;
            continue;
        }
        
        if ( isp[i] and isp[(i+1)/2] ){
            //cout << i << endl;
            ++ count;
        }
        f[i] = count;
    }
    /*for ( int i = 7; i <= 11; ++i ){
        cout << i << " " << f[i] << endl;
    }*/
    
    int Q;
    cin >> Q;
    REP(i,Q){
        int l,r;
        cin >> l >> r;
        cout << f[r] - f[l-1] << endl;
    }

    return 0;
}


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

#define int long long int
#define vi vector<int>

const int N = 1e7;

int sp[N + 1];

signed main() {
    int t = 1;
    //cin >> t;
    while(t--) {
        int n, ans = 0;
        cin >> n;
        for(int i = 2; i <= n; i++) {
            if(!sp[i]) {
                for(int j = i; j <= n; j += i) {
                    sp[j] = i;
                }
            }
        }
        sp[1] = 1;
        for(int i = 1; i <= n; i++) {
            int temp = i, curr = 1;
            while(temp != 1) {
                int cnt = 0;
                int p = sp[temp];
                while(temp > 1 && temp % p == 0) {
                    temp /= p; cnt++;
                }
                // cout << p << " " << cnt << endl;
                curr *= (cnt + 1);
            }
            // cout << curr << endl;
            ans += (i * (curr));
        }
        cout << ans;
    }
}

Measured memory_bytes: 81688
n,m = map(int,input().split())
l = [0 for _ in range(m)]
r = [0 for _ in range(m)]
for i in range(m):
    l[i],r[i] = map(int,input().split())
s = [0 for _ in range(n+1)]
for i in range(m):
    s[l[i]-1] += 1
    s[r[i]] -= 1
h = [0]
for i in range(n):
    h.append(s[i]+h[i])
ans = 0
for i in range(n+1):
    if(h[i] == m):
        ans += 1
print(ans)

Measured memory_bytes: 15896
#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
long long dp[101][100001]={},a[100],sum[100002]={};
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k+1;j++){
            sum[j]=sum[j-1]+dp[i-1][j-1];
        }
        for(int j=0;j<=k;j++){
            dp[i][j]=sum[j+1]-sum[max(0LL,(long long)j-a[i-1])];
            dp[i][j]%=mod;
        }
    }
    printf("%lld\n",dp[n][k]);
}

Measured memory_bytes: 79232
n = int(input())
dp = list(range(n+1))
dp[0] = 0
for i in range(1, n+1):
    p = 6
    while p <= i:
        dp[i] = min(dp[i], dp[i-p]+1)
        p *= 6
    p = 9
    while p <= i:
        dp[i] = min(dp[i], dp[i-p]+1)
        p *= 9
print(dp[n])


Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    int X = N * 100 / 108;
    if (X * 108 / 100 == N) {
        cout << X << endl;
    } else  {
        if ((X + 1) * 108 / 100 == N) {
            cout << X + 1 << endl;
        } else {
            cout << ":(" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
char a[10010];bool c,f;
int main(){
    scanf("%s",a);for(int i=0;i<strlen(a);i++){
        if(a[i]=='C') c=true;
        if(a[i]=='F'&&c==true) f=true;
    }
    if(f==true) printf("Yes\n");else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
use v5.18;
use warnings;
use utf8;
use Data::Dumper;
use List::Util qw( sum );
use Test::More;

sub line { chomp(my $str = <>); $str; }
sub split_line { (split / /, line) }

main();

sub main {
  my ($town_num, $road_num) = split_line;
  my @roads = map { [split_line] } 0 .. $road_num - 1;
  my $ret = solve($town_num, \@roads);
  say $_ for @$ret;
}

sub solve {
  my ($town_num, $roads) = @_;
  my $sets = {};
  for my $road_index (0 .. $#{ $roads }) {
    my $road_id = $road_index + 1;
    for my $town_id (@{ $roads->[$road_index] }) {
      $sets->{$town_id}{$road_id} = 1;
    }
  }
  [ map { scalar keys %{ $sets->{$_} } } 1 .. $town_num ];
}



Measured memory_bytes: 3452
#include<iostream>
#include<string>

using namespace std;

int main(void){
    int a,b;

    cin >> a;
    cin >> b;

    if(a==1){
        if(b==2){
            cout << 3;
        }else{
            cout << 2;
        }
    }

    if(a==2){
        if(b==1){
            cout << 3;
        }else{
            cout << 1;
        }
    }

    if(a==3){
        if(b==1){
            cout << 2;
        }else{
            cout << 1;
        }
    }


    return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ll K, S;
    cin >> K >> S;
    ll sum = 0;
    for (int x = 0; x <= K; x++)
    {
        for (int y = 0; y <= K; y++)
        {
            if (S - x - y <= K && S - x - y >= 0)
            {
                sum++;
            }
        }
    }
    cout << sum << endl;
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}
const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

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

	if(n ==m){
		for(int i=0; i<n; i++){
			cout<<n;
		}
		cout<<endl;
	}else if(n>m){
		for(int i=0; i<n; i++){
			cout<<m;
		}
		cout<<endl;
	}else {
		for(int i=0; i<m; i++){
			cout<<n;
		}
		cout<<endl;
	}
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

const int N=365, M=26;
int c[26], s[365][26];
int res[365];

set<int> st[26];

int calc(){
    int ret=0;
    vector<int> last(26,-1);
    rep(i,N){
        ret+=s[i][res[i]];
        last[res[i]]=i;
        rep(j,26)ret-=c[j]*(i-last[j]);
    }
    return ret;
}
inline int f(int n){
    return n*(n-1)/2;
}

int erase(int i, int j){
    auto itr=st[i].lower_bound(j);
    int nxt = *(next(itr)), prv=*(prev(itr));
    return -s[j][i] + c[i] * (f(j-prv)+f(nxt-j)-f(nxt-prv));
}
int insert(int i,int j){
    auto itr=st[i].lower_bound(j);
    int nxt = *itr, prv=*(prev(itr));
    return s[j][i] + c[i]*(-f(j-prv)-f(nxt-j)+f(nxt-prv));
}
struct Xor128{
    unsigned x,y,z,w;
 
    Xor128(unsigned w_=88675123):x(123456789),y(362436069),z(521288629),w(w_){};
 
    inline unsigned xor128(){
        unsigned t;
        t = x^(x<<11);
        x = y;
        y = z;
        z = w;
        return w = (w^(w>>19))^(t^(t>>8));
    }
 
    int nextInt(int x,int y){
		if(x>y)swap(x,y);
        return xor128()%(y-x)+x;
    }
 
    double nextDouble(double a,double b){
        return (double)(xor128()&0xffff)/0xffff*(b-a)+a;
    }
 
};

const int T = 18000000;
const double startT = 0, endT = 1500;
int main(){
    int _;cin>>_;
    rep(i,M)cin>>c[i];
    rep(i,N)rep(j,M)cin>>s[i][j];
    rep(i,M)st[i].insert(-1);
    rep(i,M)st[i].insert(N);
    auto rnd=Xor128();
    int sum=0;
    rep(j,M)sum+=c[j];
    rep(i,N){
        int t = rnd.nextInt(0,sum);
        int j=0, cs=0;
        while(cs+c[j]<t){
            cs+=c[j++];
        }
        res[i]=j;
        st[res[i]].insert(i);
    }
    int cur = calc();
    rep(loop,T){
        int day=rnd.nextInt(0, N), con=rnd.nextInt(0,M);
        if(res[day]==con)continue;
        int diff = insert(con,day) + erase(res[day],day);
        double temp=startT+(endT-startT)*loop/T;
        double prob=exp((double)diff/temp);
        if(prob>rnd.nextDouble(0, 1)||diff>0) {
            cur += diff;
            st[res[day]].erase(day);
            st[con].insert(day);
            res[day]=con;
        }
    }
    rep(i,N)cout<<res[i]+1<<endl;
    cerr << cur << endl;
    return 0;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M,a,b,H,good=0,goodness,adjnode;
    cin >>  N   >> M;
    set<int> adj[N+1]; //si da error es aqui +1
    vector<int> Hs;
    Hs.push_back(0);
    for (int i = 0; i<N; ++i){
        cin >> H;
        Hs.push_back(H);
    }
    for (int i = 0; i<M; ++i){
        cin >> a >> b;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    for (int i = 1; i<=N; ++i) {
        if (adj[i].size()==0) ++good;
        else {
            goodness = 0;
            for (auto it : adj[i]){
                adjnode = it;
                if (Hs[i]<=Hs[adjnode]) { /// caso que no agarra es el cuatro
                    ++goodness;
                    break;
                }
            }
            if (goodness==0) ++good;
        }
    }
    cout << good << '\n' ;
}


Measured memory_bytes: 17696
use std::io::BufRead;
use std::str::FromStr;
use std::fmt::Debug;

struct Scanner<R: BufRead> {
    buf_reader: R,
}

impl<R: BufRead> Scanner<R> {
    fn new(buf_reader: R) -> Self {
        Scanner {buf_reader: buf_reader}
    }
    fn read_line<T>(&mut self) -> Vec<T> where T: FromStr, <T as FromStr>::Err: Debug {
        let mut line = String::new();
        self.buf_reader.read_line(&mut line).unwrap();
        line.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
    }
    fn read_single_value<T>(&mut self) -> T where T: FromStr, <T as FromStr>::Err: Debug {
        let mut line = String::new();
        self.buf_reader.read_line(&mut line).unwrap();
        let sv: Vec<&str> = line.trim().split_whitespace().collect();
        sv[0].parse::<T>().unwrap()
    }
    fn read_line0(&mut self) -> Vec<String> {
        let mut line: String = String::new();
        self.buf_reader.read_line(&mut line).unwrap();
        line.trim().split_whitespace().map(|c| c.to_string()).collect()
    }
}

fn insertion_sort(a: &mut Vec<u32>, n: u32, g: u32) -> u32 {
    let mut cnt = 0;
    for i in g..n {
        let mut v = a[i as usize];
        let mut j: i32 = i as i32 - g as i32;
        while j >= 0 && a[j as usize] > v {
            a[(j + g as i32) as usize] = a[j as usize];
            j = j - g as i32;
            cnt += 1;
        }
        a[(j + g as i32) as usize] = v;
    }
    cnt
}

fn shell_sort(a: &mut Vec<u32>, n: u32) {
    let mut cnt = 0;

    let mut d = 2;
    let mut g: Vec<u32> = vec![];
    while d <= n {
        g.push(n / d);
        d *= 2;
    }
    if g.len() == 0 {
        g.push(1);
    }

    for i in 0..g.len() {
        cnt = cnt + insertion_sort(a, n, g[i]);
    }

    println!("{}", g.len());

    let mut s: Vec<String> = vec![];
    for v in g {
        s.push(v.to_string());
    }
    println!("{}", s.join(" "));
    println!("{}", cnt);

    for v in a {
        println!("{}",v);
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut scanner = Scanner::new(stdin.lock());

    let n = scanner.read_single_value::<u32>();
    let mut a: Vec<u32> = vec![];
    for i in 0..n {
        a.push(scanner.read_single_value());
    }

    shell_sort(&mut a, n);
}



Measured memory_bytes: 9968
from bisect import bisect_right
n , m , k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acc_a = [0 for i in range(n+1)]
acc_b = [0 for i in range(m + 1)]
acc_a[0] = 0
acc_b[0] = 0
for i in range(1,n+1):
    acc_a[i] = acc_a[i-1] + a[i-1]
for i in range(1,m+1):
    acc_b[i] = acc_b[i-1] + b[i-1]
ans = 0
for i in range(n + 1):
    if k >= acc_a[i]:
        index = bisect_right(acc_b, k - acc_a[i])
        ans = max(ans, i + index - 1)
    else:
        break
print(ans)




Measured memory_bytes: 48628
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  string S;
  cin>>S;
  ll ans=0;
  ll ma=0;
  for(ll i=0;i<N;i++) {
if(S[i]=='I') {
ans++;
}
if(S[i]=='D') {
ans--;
}
    ma=max(ans,ma);
  }
  
  cout<<ma<<endl;
}


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

#define pi          (3.141592653589)
#define mod         1e9+7
#define int         long long
#define pb          push_back
#define mp          make_pair
#define ff          first
#define ss          second
#define all(c)      cc.begin(), c.end()
#define clear       memset(a,0,sizeof(a));
#define rrep(i, n)  for(int i=n-1;i>=0;i--)
#define rep(i,n)    for(int i=0;i<n;i++)

void fast()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int32_t main()
{
    fast();
    int t = 1;
    //cin>>t;
    while (t--)
    {
        int n, m, k;
        cin >> n >> m >> k;

        vector<int> a(n);
        vector<int> b(m);

        rep(i, n) cin >> a[i];
        rep(i, m) cin >> b[i];

        vector<int> sumA(n + 1);
        vector<int> sumB(m + 1);

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

        for (int i = 0; i < m; ++i) {
            sumB[i + 1] = b[i] + sumB[i];
        }

        int total = 0;

        for (int i = 0; i <= n; ++i) {
            int other = k - sumA[i];

            if (other < 0)
                continue;

            int l = lower_bound(sumB.begin(), sumB.end(), other) - sumB.begin();

            if (l > m || sumB[l] > other)
                --l;

            total = max(total, i + l);
        }

        cout << total << '\n';

    }
    return 0;
}

Measured memory_bytes: 9464
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    for i in range(1000):
        if (X-i) not in P:
            print(X-i)
            break
        elif (X+i) not in P:
            print(X+i)
            break


Measured memory_bytes: 9176
def combination(n, r):
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


N, A, B = map(int, input().split())
v_list = list(map(int, input().split()))
v_list.sort(reverse=True)

mean_max = sum(v_list[:A]) / A
comb = 0
if v_list[0] != v_list[A-1]:
    x = v_list.count(v_list[A-1])
    y = v_list[:A].count(v_list[A-1])
    comb = combination(x, y)
else:
    x = v_list.count(v_list[A-1])
    for i in range(A, B+1):
        if v_list[i-1] == v_list[0]:
            comb += combination(x, i)

print("{:.10f}".format(mean_max))
print(comb)


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N);
    for(int i = 0; i < N + 1; i++) cin >> A.at(i);
    for(int i = 0; i < N; i++) cin >> B.at(i);
    int64_t sum = 0;

    for(int i = 0 ; i < N ; i++){
        //勇者を逆順に一人ずつチェック。N - i 番目の勇者。B.at(N- 1 - i)。
        if(B.at(N-1-i) > A.at(N - i)) {
            sum += A.at(N-i);
            int restpower = B.at(N-1-i) - A.at(N-i);
            sum += min(restpower,A.at(N - 1 -i));
            A.at(N - 1 - i) = max(A.at(N - 1 -i) - restpower, 0);
        }
        else{
            sum += B.at(N - 1 - i);
        }    
    }

    cout << sum << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
long long int ans1, ans2, sum1, sum2;
int n, i;
long long int a[100005];
int main()
{
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    if (a[1] >0)
    {
        sum1 = a[1];
        ans2= a[1] + 1;
        sum2 = -1;
    }
    else if (a[1] == 0)
    {
        sum1 = 1;
        ans1 = ans2 = 1;
        sum2 = -1;
    }
    else
    {
        sum1 = 1;
        ans1 = abs(a[1]) + 1;
        sum2 = a[1];
    }
    for (i = 2; i <= n; i++)
    {
        if (sum1 > 0)
        {
            if (a[i] + sum1 >= 0)
            {
                ans1 += a[i] + sum1 + 1;
                sum1 = -1;
            }
            else
            {
                sum1 += a[i];
            }
        }
        else
        {
            if (a[i] + sum1 <= 0)
            {
                ans1 += abs(sum1 + a[i]) + 1;
                sum1 = 1;
            }
            else
            {
                sum1 += a[i];
            }
        }
    }
    if (sum1 == 0)
    {
        ans1++;
    }
    for (i = 2; i <= n; i++)
    {
        if (sum2 > 0)
        {
            if (a[i] + sum2 >= 0)
            {
                ans2 += a[i] + sum2 + 1;
                sum2 = -1;
            }
            else
            {
                sum2 += a[i];
            }
        }
        else
        {
            if (a[i] + sum2 <= 0)
            {
                ans2 += abs(sum2 + a[i]) + 1;
                sum2 = 1;
            }
            else
                sum2 += a[i];
        }
    }
    if (sum2 == 0)
    {
        ans2++;
    }
    cout << min(ans1, ans2)<< endl;
//    cin>>ans1;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,A,B; cin >> N >> A >> B;
    if(N*A>B) cout << B << endl;
    else cout << A*N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int j=0;
    int count=0;
    int l=s.size();
    for(int i=0;i<(l+1)/2;i++)
    {
        if(s[i]==s[l-i-1])
            count++;
    }
    if(count==(l+1)/2)
    j++;
    count=0;
    int p=(l-1)/2;
    for(int i=0;i<(l-1)/2;i++)
    {
        if(s[i]==s[p-i-1])
            count++;
    }
    if(count==p)
        j++;

    count=0;
    int q=(l+3)/2;
    int x=0;
    for(int i=q-1;i<((q+l)/2)-1;i++)
    {
        if(s[i]==s[l-x-1])
            {
                count++;
                x++;
            }
    }

    if(count==(l-q)/2)
     j++;

     if(j==3)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
using namespace std;

#define x first
#define y second
const int N = 1 << 19;
int a[N], b[N];
int limits = 6;
const int C = 12;
vector<pair<int, int> > v[(1 << C) + 10];
int c[C + 10];
int aa[N], bb[N];

void init(int n) {
    int cnt = 0;
	int m = n;
    while (n >= 1) {
	    c[cnt++] = n;
	    n >>= 1;
	}

	v[m].push_back(make_pair(0, 0));
    for (int i = 1; i < (1 << cnt); i++) {
		int x = 0, y = 0;
		for (int j = 0; j < cnt; j++)
			if (i & (1 << j)) {
				x += a[c[j]];
				y += b[c[j]];
			}

		v[m].push_back(make_pair(y, x));
	}	
	sort(v[m].begin(), v[m].end());
	for (int i = 1; i <= v[m].size(); i++)
		v[m][i].y = max(v[m][i - 1].y, v[m][i].y);
}

void solve() {
	int n, m;
	scanf("%d%d", &n, &m);
	int cnt = 0;
	while (n > (1 << C)) {
		c[cnt++] = n;
		n >>= 1;
	}

	int ans = 0;
	for (int i = 0; i < (1 << cnt); i++) {
		int x = 0, y = 0;
		for (int j = 0; j < cnt; j++)
			if (i & (1 << j)) {
				x += a[c[j]];
				y += b[c[j]];
			}
		int lt = 0, rt = v[n].size() - 1, mid;
		while (lt <= rt) {
			mid = (lt + rt) >> 1;
			if (y + v[n][mid].x <= m) {
				ans = max(ans, x + v[n][mid].y);
		        lt = mid + 1;
			} else rt = mid - 1;
		}
	}
	printf("%d\n", ans);
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &a[i], &b[i]);
	for (int i = 1; i <= (1 << C); i++)
		init(i);

	int m;
	scanf("%d", &m);
	while (m--) solve();
	return 0;
}


Measured memory_bytes: 92796
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	while (true) {
		LL a, b, c;
		cin >> a >> b >> c;
		if (a == 0) {
			break;

		}
		LL max = 0;
		FOR(i,1, 1001) {

			FOR(j, 1, 1001) {
				if (i*(100 + a) / 100 + j*(100 + a) / 100 == c) {
					if (max < i*(100 + b) / 100 + j*(100 + b) / 100) {
						max = i*(100 + b) / 100 + j*(100 + b) / 100;
					}
				}
			}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 3092
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  ll n,x;cin>>n>>x;
  vl v(n);
  rep(i,n)cin>>v[i];
  ll ans=0;
  ll k=x;
  rep(i,n){
    ll d=abs(k-v[i]);
    k=v[i];
    ans=__gcd(d,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val m = sc.nextInt()
    val aHash = hashMapOf<Int, Int>()
        (1..a).forEach {
            aHash[it] = sc.next().toInt()
        }
    val bHash = hashMapOf<Int, Int>()
    (1..b).forEach {
        bHash[it] = sc.next().toInt()
    }
    val xyc = (0 until m).map { Triple(sc.nextInt(), sc.nextInt(), sc.nextInt()) }
    println(problemHitachib(a, b, m, aHash, bHash, xyc))
}

fun problemHitachib(
    a: Int,
    b: Int,
    m: Int,
    aHash: HashMap<Int, Int>,
    bHash: HashMap<Int, Int>,
    xyc: List<Triple<Int, Int, Int>>
): Int {
    var min = Integer.MAX_VALUE
    for (i in 0 until m) {
        val (x, y, c)  = xyc[i]
        val value = aHash[x]!! + bHash[y]!! - c
        min = Math.min(min, value)
    }
    min = Math.min(min, aHash.minBy { it.value }!!.value + bHash.minBy { it.value }!!.value)
    return min
}

Measured memory_bytes: 135596
#include <iostream>
#include <string>

int main(){
    std::string S, T;
    std::cin>>S>>T;

    bool flag = false;
    for(int i = 0;i < S.size();i++){
        if(S == T){
            flag = true;
            break;
        }
        S = S.back() + S.substr(0, S.size()-1);
    }
    std::cout<<(flag ? "Yes" : "No")<<std::endl;

    return 0;
}

Measured memory_bytes: 256