akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int K;
    cin >> K;
    int ans = 0;
    for (int a = 1; a < K + 1; a++) {
        for (int b = 1; b < K + 1; b++) {
            for (int c = 1; c < K + 1; c++) {
                ans += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
s = int(input())
a = [s]
for i in range(1000000):
    if a[i] % 2 == 0:
        next = a[i]/2
    else:
        next = 3*a[i]+1
    if next in a:
        ans = i+2
        break
    a.append(next)
print(ans)


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

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < N-1; i++) {
            int a = sc.nextInt(); a--;
            int b = sc.nextInt(); b--;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }

        long ans = K*dfs(K, graph, 0, -1);
        ans %= MOD;

        System.out.println(ans);
    }

    private static long dfs(int K, List<List<Integer>> graph, int now, int from) {

        int colorNum = from == -1 ? K-1 : K-2;

        long ret = 1;
        for (int next : graph.get(now)) {
            if (next == from) continue;
            ret *= colorNum;
            ret %= MOD;
            colorNum--;
        }

        for (int next : graph.get(now)) {
            if (next == from) continue;
            ret *= dfs(K, graph, next, now);
            ret %= MOD;
        }

        return ret;
    }
}


Measured memory_bytes: 111164
#include <iostream>
int main(int argc, const char * argv[]) {
    int n;
    std::cin >> n;
    int * p= new int[n];
    for(int i=0; i<n; i++) std::cin >> p[i];
    int count=0;
    for(int i=1; i<n-1; i++)
    {
        if(p[i-1]<p[i] && p[i]<p[i+1]) count++;
        if(p[i-1]>p[i] && p[i]>p[i+1]) count++;
        
    }
    std::cout << count << std::endl;
    return 0;
}

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

using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int primeFactorize(ll n) {
  int count = 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    int ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    count *= (ex + 1);
  }
  if (n > 1) {
    count *= 2;
  }
  return count;
}

int main() {
  ll n;
  cin >> n;
  ll r = 0;

  for (int c = 1; c < n; c++) {
    ll v = n - c;
    r += primeFactorize(v);
  }
	cout << r << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main (void){
	int mai,kin,n,m;
	while(1){
		scanf("%d",&kin);
		if(kin==0) break;
		kin=1000-kin;
		mai=0;
		mai+=kin/500;
		kin=kin%500;
		mai+=kin/100;
		kin=kin%100;
		mai+=kin/50;
		kin=kin%50;
		mai+=kin/10;
		kin=kin%10;
		mai+=kin/5;
		kin=kin%5;
		mai+=kin;
		printf("%d\n",mai);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    /*
    if( a + b + c > 21 ){
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    //*/
    
    cout << a * a << endl;

    return 0; 
}


Measured memory_bytes: 3592
#include<stdio.h>
int main(void) {
    int a, b, c, i, count = 0;
    scanf("%d%d%d", &a, &b, &c);
    for(i = a; i <= b; i++) {
        if(c%i == 0) count++;
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdlib>

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

    int n,w;
    cin >> n >> w;
    long long d[n],v[n];
    long long a[w+1];

    for(int i=0;i<w+1;i++)a[i]=0;

    for(int i=0;i<n;i++)
        cin >> d[i] >> v[i];

    for(int i=0;i<n;i++)
        for(int j=w;j>=d[i];j--)
            a[j]=max(a[j],a[j-d[i]]+v[i]);


    cout << a[w] << endl;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> a(N);
    rep (i, N) {
        cin >> a[i];
    }

    vector<ll> m(100010, 0);
    rep (i, N) {
        m[a[i]]++;
    }

    ll ans = 0;
    for (ll i = 1; i < 100009; i++) {
        ll tmp = (m[i-1]+m[i]+m[i+1]);
        ans = max(ans, tmp);
    }

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


Measured memory_bytes: 1792
n=gets.to_i
s=gets.chomp.split(//)
sum=s.count('R')*s.count('G')*s.count('B')

s.size.times do |i|
    i.upto(s.size) do |j|
        a=s[i]
        b=s[j]
        c=s[j+j-i]
        #p a,b,c,""
        sum-=1 if (a!=b and a!=c and b!=c and !a.nil? and !b.nil? and !c.nil?)
    end
end
p sum

Measured memory_bytes: 14376
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main()
{
    int N, K;
    cin >> N >> K;
    vector<bool> A(N+1, false);
    for (int i=0; i<K; i++) {
        int d; cin >> d;
        for (int j=0; j<d; j++) {
            uint a;
            cin >> a;
            A[a] = true;
        }
    }
    int cnt = 0;
    for (size_t i=1; i<A.size(); i++) {
        if (!A[i]) ++cnt;
    }
    cout << cnt << endl;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 111; i <= 999; i++) {
  	if (i % 10 == i / 10 % 10 && i % 10 == i / 100 && i >= n) {
      cout << i << '\n';
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
char s[110],a[110],b,i,t;main(){while(fgets(s,110,stdin)){if(s[1]=='\n'&&s[0]==46)break;for(t=1,b=0,i=0;s[i]&&t;++i){if(s[i]==40||s[i]==91) a[b++]=s[i];else if(s[i]==41||s[i]==93) {if(!b){t=0;break;}if((s[i]==41&&a[b-1]==40)||(s[i]==93&&a[b-1]==91)) --b;else t=0;}}puts(((t&&!b)?1:0)?"yes":"no");}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+7;
LL x[MAXN];
LL v[MAXN];
LL suffix[MAXN];
LL N, C;

LL solve() {
    x[N+1] = C;
    suffix[N+1] = 0;
    for (int i = N; i > 0; i--) {
        suffix[i] = suffix[i+1]+v[i]-2*(x[i+1]-x[i]);
    }
    for (int i = N; i > 0; i--) suffix[i] = max(suffix[i], suffix[i+1]);

    x[0] = 0;
    LL ans = 0;
    LL sum = 0;
    for (int i = 1; i <= N; i++) {
        sum += v[i]-(x[i]-x[i-1]);
//        cout << i << " -> " << sum << " " << suffix[i+1] << endl;
        ans = max(ans, sum+suffix[i+1]);
    }

    return ans;
}

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

    for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];

    LL ans = solve();
    for (int i = 1, j = N; i <= j; i++, j--) {
        if (i==j) {
            x[i] = C-x[i];
        } else {
            swap(v[i], v[j]);
            swap(x[i], x[j]);
            x[i] = C-x[i];
            x[j] = C-x[j];
        }
    }

//    for (int i = 1; i <= N; i++) cout << x[i] << " " << v[i] << endl;

    ans = max(ans, solve());

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 5992
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def judge(x):
  cnt = 0
  for i in range(N):
    tmp = a[i] - x//f[i]
    cnt += max(tmp, 0)
  else:
    if cnt <= K:
      return True
    else:
      return False

# 二分探索 #
def nibutan(): # MAX(A*F) ans
    left = -1
    ans = num
    while left+1 != ans:
        middle = (left+ans)//2
        if judge(middle):
            ans = middle
        else:
            left = middle
    return ans

N, K = IL()
a = IL()
f = IL()
a.sort()
f.sort(reverse=True)
num = 0
for i in range(N):
  num = max(num, a[i]*f[i])

print(nibutan())


Measured memory_bytes: 119500
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	long long n;
	cin >> n;
	long long ans = 100000;
	for (int i = sqrt(n);i >= 1;--i) {
		if (n % i == 0) {
			long long hoge = n / i;
			long long cnt = 0;
			while (hoge != 0) {
				cnt++;
				hoge /= 10;
			}
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

int A,B;
int ans;

signed main(){
    cin>>A>>B;
    B++;
    for(int i=0;i<60;++i){
        int b=1ll<<i;
        // 0からAまで
        int k=A/b;
        int cnt1_a=(k/2)*b;
        if(k%2==1)cnt1_a+=A-k*b;
        // 0からBまで
        k=B/b;
        int cnt1_b=(k/2)*b;
        if(k%2==1)cnt1_b+=B-k*b;
        // AからBまで
        int cnt1=cnt1_b-cnt1_a;
        if(cnt1%2!=0)ans+=b;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


int n, h[21600], cnt;

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

  while(true){
    bool allzero = true;
    for(int i = 0;i < n;i++)
      if(h[i] != 0)
	allzero = false;

    if(allzero)break;

    int l = 0;
    while(h[l] == 0)l++;
    int r = l;
    while(r < n && h[r+1] != 0)r++;
    cnt++;
    for(int i = l;i <= r;i++)h[i]--;
  }

  cout << cnt << endl;
  return 0;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

const ll N = 1e5 + 10;

ll n, m; ll k;
ll x[N], a[N], b[N], c[N];
ll st[N][61];

int main() {
  scanf("%lld", &n);
  for (ll i = 1; i <= n; i++) {
    b[i] = i;
    scanf("%lld", &x[i]);
  }
  scanf("%lld %lld", &m, &k);
  for (ll i = 1; i <= m; i++) {
    scanf("%lld", &a[i]);
    swap(b[a[i] - 1], b[a[i]]);
  }
  for (ll i = 1; i < n; i++) st[b[i]][0] = i;
  for (ll j = 1; j < 61; j++)
    for (ll i = 1; i < n; i++)
      st[i][j] = st[st[i][j - 1]][j - 1];
  for (ll i = 1; i < n; i++) {
    ll cur = i;
    for (ll j = 0; j < 61; j++) {
      if ((k >> j) & 1) {
        cur = st[cur][j];
      }
    }
    c[cur + 1] = x[i + 1] - x[i];
  }
  c[1] = x[1];
  for (ll i = 2; i <= n; i++) c[i] += c[i - 1];
  for (ll i = 1; i <= n; i++) printf("%lld\n", c[i]);
  return 0;
}

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

/* Dictionaryの練習 */

namespace ABC061
{
    class B
    {
        static void Main(string[] args)
        {

            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int N = input[0];
            int M = input[1];

            int[] A = new int[N];
            int a = 0;
            int b = 0;
            for (int i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();

                a = input[0] - 1;
                b = input[1] - 1;

                A[a]++;
                A[b]++;
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(A[i]);
            }
        }
    }
}


Measured memory_bytes: 13268
from collections import deque


def main():
    n, *a = open(0).read().split()
    dq = deque()
    n = int(n) - 1
    for i, ai in enumerate(a):
        if i % 2 == n % 2:
            dq.appendleft(ai)
        else:
            dq.append(ai)
    print(" ".join(dq))
    return


main()


Measured memory_bytes: 26588
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split()))).T

count = 0
for _ in range(N):
    A = np.array(list(map(int, input().split())))
    if (np.dot(A, B) + C > 0):
        count += 1

print(count)


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;
 
template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

string s;

int main()
{
    fastio();

    cin >> s;

    int ans = 0;
    forn(i,s.size()-1) {
        ans += s[i] != s[i+1];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 2017

int n, nn, i, j;
int a[maxN];
vector<int> adj[maxN];

vector<int> ans[maxN], aux;
bool us[maxN];


int cmmdc(int a, int b) {
    if (a < b) swap(a, b);

    while (b != 0) {
        a %= b;
        swap(a, b);
    }

    return a;
}

void dfs(int node) {
    us[node] = true;

    ans[node] = {};
    sort(adj[node].begin(), adj[node].end());

    for (auto to : adj[node]) {
        if (us[to]) continue;

        dfs(to);
        aux = ans[node];
        ans[node].resize(ans[node].size() + ans[to].size());
        merge(aux.begin(), aux.end(),
              ans[to].begin(), ans[to].end(),
              ans[node].begin(), [](int a, int b)->bool const {return a > b;});
    }

    if (node != 0)
        ans[node].insert(ans[node].begin(), a[node]);
}


int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);

    for (i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            if (cmmdc(a[i], a[j]) != 1) {
                adj[i].pb(j);
                adj[j].pb(i);
            }
        }

        adj[0].pb(i);
        adj[i].pb(0);
    }

    dfs(0);

    for (auto e : ans[0]) printf("%d ", e);




    return 0;
}


Measured memory_bytes: 32000
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2)
    {
        cout << "1\n";
    }
    else
    {
        cout << "0\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

const ll MOD=1000000007;

int main(){
  ll n,a,b;
  cin >> n >> a >> b;

  vector<int> inv(b+1);
  inv[0]=1;inv[1]=1;
  
  for(int i=2;i<b+1;i++){
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
  }

  ll ans=1;
  ll cur=n;
  ll pow=2;
  for(int i=0;i<40;i++){
    if(cur%2==1){ans*=pow; ans%=MOD;}
    cur/=2;
    pow*=pow; pow%=MOD;
  }
  ans-=1;

  
  cur=1;
  for(int i=1;i<b+1;i++){
    cur*=n-i+1;
    cur%=MOD;
    cur*=inv[i];
    cur%=MOD;
    if(i==a || i==b){
      ans-=cur;ans%=MOD;
    }
  }

  ans=(ans+MOD)%MOD;

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


Measured memory_bytes: 1024
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
string s;

bool go(int a, int b) {
	while (a < b) {
		if (s[a + 1] == '.')
			++a;
		else if (s[a + 2] == '.')
			a += 2;
		else
			return 0;
	}
	return 1;
}

int a, b, c, d;


int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> a >> b >> c >> d;
	cin >> s;
	--a, --b, --c, --d;
	if (c < d) {
		if (go(b, d) && go(a, c))
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	else {
		while (true) {
			while (true) {
				if (a + 1 < b && s[a + 1] == '.')
					a += 1;
				else if (a + 2 < b && s[a + 2] == '.')
					a += 2;
				else
					break;
			}
			if (a + 1 == b && a + 2 <= c && s[a + 2] == '.') {
				a += 2;
				if (go(a, c) && go(b, d))
					cout << "Yes\n";
				else
					cout << "No\n";
				return 0;
			}
			if (b + 1 <= d && s[b + 1] == '.')
				b += 1;
			else if (b + 2 <= d && s[b + 2] == '.')
				b += 2;
			else {
				cout << "No\n";
				return 0;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 592
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
using namespace std;
bool p[100010];
int num[100010];
int main() {
	int N, M, x, y, ans = 0;
	cin >> N >> M;
	for (int i = 0; i <= N; i++) {
		p[i] = false;
		num[i] = 1;
	}
	p[0] = true;
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &x, &y);
		if (p[x-1] == true)p[y-1] = true;
		num[x - 1]--; num[y - 1]++;
		if (num[x - 1] == 0)p[x - 1] = false;
	}
	for (int i = 0; i < N; i++) {
		if (p[i] == true && num[i] != 0)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
#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>;
#define chmin(x, y) x = min(x, y)

const int INF = 1001001001;
int dp[1000005][2];

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';
  int n = s.size();
  rep(i, n + 1) rep(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i, n) rep(j, 2) {
    int x = s[i] - '0';
    x += j;
    chmin(dp[i + 1][0], dp[i][j] + x);
    chmin(dp[i + 1][1], dp[i][j] + (10 - x));
  }
  int ans = dp[n][0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9220
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1] = (s[k-1]-'A') + 'a';
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  ll mn=inf,mx=-inf;
  int mn_id,mx_id;
  rep(i,N){
    cin >> A[i];
    if(chmin(mn,A[i])){
      mn_id = i;
    }
    if(chmax(mx,A[i])){
      mx_id = i;
    }
  }
  vector<P> ans;
  if(0<mn){
    ans.emplace_back(mx_id+1,N);
    ans.emplace_back(mx_id+1,N);
    A[N-1] += mx*2;
    for(int i=0; i<N-1; i++){
      A[i] += A[N-1];
      ans.emplace_back(N,i+1);
      A[N-1] += A[N-1];
      ans.emplace_back(N,N);
    }
  }else if(mx<0){
    ans.emplace_back(mn_id+1,1);
    ans.emplace_back(mn_id+1,1);
    A[0] += mn*2;
    for(int i=N-1; i>0; i--){
      A[i] += A[0];
      ans.emplace_back(1,i+1);
      A[0] += A[0];
      ans.emplace_back(1,1);
    }
  }else{
    if(abs(mn) <= abs(mx)){
      ans.emplace_back(mx_id+1,N);
      ans.emplace_back(mx_id+1,N);
      A[N-1] += mx*2;
      for(int i=0; i<N-1; i++){
        A[i] += A[N-1];
        ans.emplace_back(N,i+1);
        A[N-1] += A[N-1];
        ans.emplace_back(N,N);
      }
    }else{
      ans.emplace_back(mn_id+1,1);
      ans.emplace_back(mn_id+1,1);
      A[0] += mn*2;
      for(int i=N-1; i>0; i--){
        A[i] += A[0];
        ans.emplace_back(1,i+1);
        A[0] += A[0];
        ans.emplace_back(1,1);
      }
    }
  }
  cout << ans.size() << endl;
  for(int i=0; i<ans.size(); i++){
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
count = sum([int(j) for j in str(1)]) + sum([int(j) for j in str(n-1)])
for i in range(1,-(-n//2)+1):
    a = sum([int(j) for j in str(i)])
    b = sum([int(j) for j in str(n-i)])
    if count > a + b:
        count = a + b
print(count)


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

int main(){
  char s[3];
  for(int i=0; i<3; i++){
    cin >> s[i];
  }
  int count =0;
  for(int i=0; i<3; i++){
    if(s[i]=='1') count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

using P = pair<int, int>;
P farthest(vector<VI>& g, int now, int par) {
    P ret = { 0,now };
    each(to, g[now]) {
        if (to == par)continue;
        auto a = farthest(g, to, now);
        ++a.first;
        chmax(ret, a);
    }
    return ret;
}

int main() {
    init();

    int n; cin >> n;
    auto g = vec<VI>(n);
    FOR(i, 0, n - 1) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int s = farthest(g, 0, -1).second;
    int d = farthest(g, s, -1).first;
    cout << (d % 3 == 1 ? "Second" : "First") << "\n";
}

Measured memory_bytes: 26880
import sys
input=sys.stdin.readline

N = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
        
s = num2alpha(N)
print(str.lower(s))

Measured memory_bytes: 61844
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

mint dp[61][2][2][2];

int main(){
    ll l, r;
    cin >> l >> r;
    dp[60][0][0][0] = 1;
    for(int i = 59; i >= 0; i--){
        int lb = (l >> i) & 1;
        int rb = (r >> i) & 1;
        rep(j, 2)rep(k, 2)rep(s, 2){
            mint pre = dp[i+1][j][k][s];
            rep(x, 2)rep(y, 2){
                if(x && !y) continue;
                int nj = j, nk = k, ns = s;
                if(!s && x != y) continue;
                if(x && y) ns = 1;
                
                if(!j && !x && lb) continue;
                if(x && !lb) nj = 1;

                if(!k && y && !rb) continue;
                if(!y && rb) nk = 1;

                dp[i][nj][nk][ns] += pre;
            }
        }
    }
    mint ans;
    rep(j, 2)rep(k, 2)rep(s, 2) ans += dp[0][j][k][s];
    cout << ans.x << endl;
}

Measured memory_bytes: 3680
#include<stdio.h>

int main(){
  char S[111];
  S[0] = '\0';
  scanf("%s",S);
  int i,N;
  while(S[N] != '\0'){
    N++;
  };
  for(i=0;i<=N-1;i++)
    S[i] -= 'a';
  int count[30] = {0};
  for(i=0;i<=N-1;i++)
    count[S[i]]++;
  for(i=0;i<=26;i++)
    if(count[i]%2 == 1){
    printf("No");
    goto NO;
    };
  printf("Yes");
  NO:;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 111;
const int MAXC = 22;
const int MAXP = 55;
const int MAXD = 111*200;
const int INF = 1e9;

int d[MAXC][MAXN][MAXN];
ll value[MAXC][MAXD];
int p[MAXC], q[MAXC][MAXP], r[MAXC][MAXP];
int N, M, C, s, g;

struct edge {
    int v;
    ll w;
    edge() {}
    edge(int v, ll w) : v(v), w(w) {};
};

vector<ll> dijkstra(int n, vector<vector<edge> >& G, int s) {
    vector<ll> d(n, LLONG_MAX/10); d[s] = 0;
    priority_queue<pair<ll, int> > que;
    que.push(make_pair(0ll, s));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second;
        ll dist = -p.first;
        if (dist > d[u]) continue;
        for (edge e : G[u]) {
            if (d[e.v] > d[u]+e.w) {
                d[e.v] = d[u] + e.w;
                que.push(make_pair(-d[e.v], e.v));
            }
        }
    }
    return d;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> N >> M >> C >> s >> g) {
    	--s; --g;
    	if (N==0) break;
    	for (int c = 0; c < C; c++) {
    		for (int i = 0; i < N; i++) {
    			for (int j = 0; j < N; j++)
    				d[c][i][j] = INF;
    			d[c][i][i] = 0;
    		}
    	}
    	for (int i = 0; i < M; i++) {
    		int x, y, dist, c;
    		cin >> x >> y >> dist >> c;
    		--x; --y; --c;
    		d[c][x][y] = d[c][y][x] = min(dist, d[c][x][y]);
    	}
    	for (int c = 0; c < C; c++) {
    		for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
    			d[c][i][j] = min(d[c][i][j], d[c][i][k] + d[c][k][j]);
    		}
    	}
    	for (int i = 0; i < C; i++)
    		cin >> p[i];
    	for (int i = 0; i < C; i++) {
    		for (int j = 1; j < p[i]; j++)
    			cin >> q[i][j];
    		q[i][p[i]] = MAXD-1;
    		for (int j = 1; j <= p[i]; j++)
    			cin >> r[i][j];
    		for (int k = 1; k <= p[i]; k++) {
    			for (int z = q[i][k-1]+1; z <= q[i][k]; z++) {
    				value[i][z] = value[i][z-1] + r[i][k];
    			}
    		}
    	}
    	vector<vector<edge> > G(N);
    	for (int v = 0; v < N; v++) for (int u = 0; u < N; u++) {
    		ll mini = INF;
    		for (int c = 0; c < C; c++) {
    			if (d[c][v][u] < MAXD)
    				mini = min(mini, value[c][d[c][v][u]]);
    		}
    		if (mini < INF) {
    			G[v].emplace_back(u, mini);
    			G[u].emplace_back(v, mini);
    		}
    	}
    	auto d = dijkstra(N, G, s);
    	ll ans = d[g];
    	if (ans > INF) ans = -1;
    	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 7984
/*
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$
**/

#include <bits/stdc++.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <cmath>

using namespace std;

//typedef
typedef string STR;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef priority_queue<int> PQI;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
typedef vector<STR> VS;
typedef vector<char> VC;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<STR,int> PSI;
typedef pair<int,STR> PIS;
typedef vector<PII> VII;
typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef map<STR,int> MSI;
typedef map<char,int> MCI;
typedef map<int,STR> MIS;
typedef set<STR> SS;
typedef set<int> SI;
typedef set<LL> SLL;

//symbolic const
#define MOD 1000000007
#define MAXN 1e9
#define SIZE 10000

//STL keywords
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
#define all(v) v.begin(), v.end()

//functions
#define dec(n) cout<<fixed<<setprecision(n);
#define f(i, n)   for(LL i=0; i<n; i++)
#define fa(i,a,n) for(LL i=a; i<n; i++)

//IO
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test int t;cin>>t;while(t--){solve();}

LL maxLL(LL a, LL b){return (a>b?a:b);}
LL minLL(LL a, LL b){return (a<b?a:b);}

void solve() {
  int a, b;
  cin>>a>>b;
  int sum;
  if(a>b) sum=a+max(a-1, b);
  else sum=b+max(b-1, a);
  cout<<sum;
}

int main() {
    sync;
    //test;
    solve();
    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 all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

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

    vector<vector<int>> s(m);
    vector<int> P(m);
    rep(i, m){
        int k;
        cin >> k;
        
        rep(j, k){
            int x; cin >> x;
            x--;
            s[i].push_back(x);
        }
    }

    rep(i, m){
        cin >> P[i];
    }

    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        bool ok = true;
        rep(j, m){
            int cnt = 0;
            for (auto& p : s[j]) {
                if((i >> p) & 1){
                    cnt++;
                }
            }
            if(cnt % 2 != P[j]) {
                ok = false;
            }
        }
        if(ok) {
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<math.h>
#include<string.h>
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int n,m,q;
int ans=0;
int a[55],b[55],c[55],d[55],A[30];
void dfs(int index,int k)
{
    if(index==n+1)
    {
        int i,sum=0;
        for(i=1;i<=q;i++)
            if(A[b[i]]-A[a[i]]==c[i])
            sum+=d[i];
        if(sum>ans)ans=sum;
        return ;
    }
   for(int i=k;i<=m;i++)
   {
       A[index]=i;
       dfs(index+1,i);
   }
}
int main()
{
   cin>>n>>m>>q;
   for(int i=1;i<=q;i++)
   {
       cin>>a[i]>>b[i]>>c[i]>>d[i];
   }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	string s[n+1];
	for(int i=0; i<n; i++){
		cin >> s[i];
	}

	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(s[i] == s[j]){
				printf("No");
				return 0;
			}
		}
	}

	for(int i=1; i<n; i++){
		if(s[i].front() != s[i-1].back()){
				printf("No");
				return 0;
			}
	}

	printf("Yes");

    return 0;
}


Measured memory_bytes: 256
class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

# a = [14, 5, 9, 13, 7, 12, 11, 1, 7, 8]

# def segfunc(x, y):
#     return min(x, y)

# ide_ele = float('inf')

# seg = SegTree(a, segfunc, ide_ele)

# [0, 8)の最小値を表示
# print(seg.query(0, 8))
# 1

# 5番目を0に変更
# seg.update(5, 0)

# [0, 8)の最小値を表示
# print(seg.query(0, 8))
# 0

n,q = map(int,input().split())
cxy = [ list(map(int,input().split())) for _ in range(q) ]

INF = float("inf")

#####segfunc#####
def segfunc(x, y):
    return min(x,y)
#################

#####ide_ele#####
ide_ele = INF
#################

a = [2**31-1]*n

seg = SegTree(a,segfunc,ide_ele)

for i in range(q):
    c = cxy[i][0]
    x = cxy[i][1]
    y = cxy[i][2]
    if c==0:
        seg.update(x,y)
    elif c==1:
        print(seg.query(x,y+1))
    else:
        print("Error")


Measured memory_bytes: 27416
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)
#define SP(i)           fixed << setprecision(i) 

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741
ll n,k;
ll arr[105];
ll dp[100005][2];

ll find(ll k, ll chance){
	if (k==0){
		return dp[k][chance]=0;
	}
	if (dp[k][chance]!=-1)return dp[k][chance];
	dp[k][chance]=0;
	rep(i,0,n){
		if ((k-arr[i]>0 && !find(k-arr[i],!chance) || k==arr[i])){
			dp[k][chance]=1;
			break;
		}
	}
	return dp[k][chance];
}

void solve() {
    cin>>n>>k;
    rep(i,0,n)cin>>arr[i];
    memset(dp,-1,sizeof dp);
    if (find(k,0))cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 4992
n, m = map(int, (input().split()))
lst = sorted([list(map(int, input().split())) for i in range(n)])

cnt = ans = 0
for i in range(n):
    ans += min(lst[i][1], m - cnt) * lst[i][0]
    cnt += min(lst[i][1], m - cnt)
    if cnt==m:
        break

print(ans)


Measured memory_bytes: 28652
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353

void solve(){
	string a, b; cin>>a>>b;
	int n = a.length();
	int m = b.length();
	int f = 1;
	f(i,n){
		if(a[i] != b[i]){
			f = 0;
			break;
		}
	}
	if(f && m == n+1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

long long int f(string s) {
    int i = 0;
    int res = 0;
    while (i < s.size()) {
        int ii = i;
        while (i + 1 < s.size() && s[i] == s[i + 1]) {
            i++;
        }
        res += (i - ii + 1) / 2;
        i++;
    }
    return res;
}

int main(int argc, char *argv[]) {
    string s1, s2, s3;
    cin >> s1;
    long long int k;
    cin >> k;
    s2 = s1 + s1;
    s3 = s2 + s1;
    if (k % 2 == 1) {
        cout << f(s1) + (k - 1) / 2 * (f(s3) - f(s1));
    }
    else {
        cout << f(s2) + (k - 2) / 2 * (f(s3) - f(s1));
    }
}




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

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin >> A.at(i);
    }
    int f;
    f = 0;
    sort(A.begin(), A.end());
    for(int i=0;i<k;i++){
        f += A.at(i);
    }
    cout << f << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int r, c;
string s[100];

int main()
{
    sf("%d%d", &r, &c);
    for (c = 0; c < r; c++) cin >> s[c];
    for (c = 0; c < r; c++) cout << s[c] << endl << s[c] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int m;
  cin>>m;
  while(m--){
    int money,year,n,ans=0;
    cin>>money>>year>>n;
    while(n--){
      int mymoney = money;
      int risoku,tesuu,risi=0;
      double ritu;
      cin>>risoku>>ritu>>tesuu;
      REP(i,year){
        if(risoku){
          risi += (mymoney+risi)*ritu;
        }else{
          risi += mymoney*ritu;
        }
        mymoney-=tesuu;
      }
      ans = max(ans, mymoney + risi);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        long[] a = new long[n];
        a[0] = sc.NextInt();
        for (int i = 1; i < n; i++) a[i] = a[i - 1] + sc.NextInt();
        long min = 1L << 37;
        for (int i = 0; i < n - 1; i++)
        {
            long d = Math.Abs(a[a.Length - 1] - 2 * a[i]);
            if (d < min) min = d;
        }
        Console.WriteLine(min);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 29916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll h,w,mi=1000000000;
  cin>>h>>w;
  ll a,b,c;
  a=h/3*w;
  b=(h-h/3)/2*w;
  c=h*w-a-b;
  mi=min(mi,max({a,b,c})-min({a,b,c}));
  a=w/3*h;
  b=(w-w/3)/2*h;
  c=h*w-a-b;
  mi=min(mi,max({a,b,c})-min({a,b,c}));
  ll m=1000000000000;
  for(int i=0;i<=h;i++){
    a=i;
    b=(h-i)*(w/2);
    a*=w;
    c=h*w-a-b;
    m=min(max({a,b,c})-min({a,b,c}),m);
  }
  mi=min(mi,m);
  m=1000000000000;
  for(int i=0;i<=w;i++){
    a=i;
    b=(w-i)*(h/2);
    a*=h;
    c=h*w-a-b;
    m=min(max({a,b,c})-min({a,b,c}),m);
  }
  mi=min(mi,m);
  
  cout<<mi;
}
  

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

int main() {
  int N, A, B, PA, PB;
  cin >> N >> A >> B;
  PA = N * A ;
  PB = B ;
  
  if ( PA == PB ) {
    cout << PA << endl;
  }
  if ( PA < PB ) {
    cout << PA << endl;
  }
  if ( PA > PB ) {
    cout << PB << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}

		for(int i = a.length - 1; i >= 0; i--) {
			if(i != a.length - 1) {
				System.out.printf(" ");
			}
			System.out.printf("%d", a[i]);
		}
		System.out.println("");

		scan.close();
	}
}


Measured memory_bytes: 26392