akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;

int main()
{
    IOS;
    while(1)
    {
        string s;
        cin>>s;
        int k;cin>>k;
        int l=s.length();
        for(int i=0;i<l;i++){
            if(s[i]+k>'z'&&s[i]!='a'){
                int temp=('z'-s[i]+1);
                k-=temp;
//                cout<<i<<" "<<temp<<endl;
                s[i]='a';
            }
        }
//        cout<<"k = "<<k<<endl;
        k%=26;
        for(int i=0;i<k;i++)
        {
            if(s[l-1]=='z')s[l-1]='a';
            else s[l-1]++;
        }
        cout<<s<<endl;
        break;
    }
}
/*
awe
26
*/


Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int x[200000],A[200000];
    for(int i=0;i<n;i++){
        cin>>x[i];
        A[i]=x[i];
    }
    sort(x,x+n);
    for(int i=0;i<n;i++){
        if(A[i]<x[n/2]) cout<<x[n/2]<<endl;
        else cout<<x[n/2-1]<<endl;
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main(){
  ll x; cin >> x;
  ll a = x/500;
  x -= a*500;
  ll b = x/5;
  cout << a*1000+b*5 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}


Measured memory_bytes: 2488
#include <stdio.h>

void solve(int a,int n) {

	for (int i = 0; i < n; ++i) printf("%d", a);
	puts("");
}

int main() {

	int a, b;
	scanf("%d %d", &a, &b);
	a < b ? solve(a, b) : solve(b, a);

	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string S = Console.ReadLine();
        int ans = 1000000000;
        for (int i = 0; i + 2 < S.Length; i++)
        {
            int box = int.Parse((S[i].ToString() + S[i + 1].ToString() + S[i + 2].ToString()).ToString());
            ans = Math.Min(ans,Math.Abs(753-box));
        }
        Console.WriteLine(ans);
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = strReverce(ret);
        return ret;
    }

}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include<cstdio>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <map>
#include <numeric>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define len(str) (int)(str.length())
int main() {
	int L, R;
	cin >> L >> R;
	vector<vector<bool> > visit(2019, vector<bool>(2019, false));
	int min_ = 1e9;
	for (int i = L; i < R; i++)
	{
		for (int j = i + 1; j <= R; j++)
		{
			int modi = i % 2019;
			int modj = j % 2019;
			if (visit[modi][modj]) {
				cout << min_ << endl;
				return 0;
			}
			else {
				visit[modi][modj] = true;
				min_ = min(min_, (modi * modj) % 2019);
			}
		}
	}
	cout << min_ << endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
pair<P,int> p[100000];
P x[100000];
signed main(){
	int a,b;
	cin>>a>>b;
	f(i,b){
		cin>>p[i].F.F>>p[i].F.S;
		p[i].S=i;
		x[i].F=p[i].F.F;
	}
	sort(p,p+b);
	int z=1;
	f(i,b){
		if(i&&p[i].F.F!=p[i-1].F.F){
			z=1;
		}
		x[p[i].S].S=z;
		z++;
	}
	f(i,b){
		int c=6,d=x[i].F;
		while(d){
			d/=10;
			c--;
		}
		f(i,c) cout<<0;
		cout<<x[i].F;
		c=6;
		d=x[i].S;
		while(d){
			d/=10;
			c--;
		}
		f(i,c) cout<<0;
		cout<<x[i].S<<endl;
	}
	return 0;
}


Measured memory_bytes: 5504
# Author: cr4zjh0bp
# Created: Mon Mar 23 19:34:20 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b = na()

if a + b >= 10:
    print("error")
else:
    print(a + b)

Measured memory_bytes: 3064
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int TD = 17, PA = 1 << TD, AN = 100100, MA = AN * 4 * TD;
class IntervalEdgeTech {
public:
	int Eto[PA * 5 + MA], Eco[PA * 5 + MA], Ene[PA * 5 + MA], Ehe[PA * 5 + AN * 2 + 2], EN, Nadd;
	ll D[PA * 5 + AN * 2 + 2];
	void adde(int v, int to, int co) {
		Eto[EN] = to;
		Eco[EN] = co;
		Ene[EN] = Ehe[v];
		Ehe[v] = EN++;
	}
	IntervalEdgeTech() : Ehe() {
		EN = 1;
		for (int i = PA * 2 - 1; i > 1; i--) adde(i << 1, i >> 1 << 1, 0);
		rep1(i, PA - 1) {
			adde(i << 1 | 1, i << 2 | 1, 0);
			adde(i << 1 | 1, i << 2 | 3, 0);
		}
		for (int i = PA * 2; i < PA * 4; i += 2) adde(i + 1, i, 0);
		Nadd = PA * 4;
	}
	void AddE(int L1, int R1, int L2, int R2, int C) {
		for (L1 += PA, R1 += PA; L1 < R1; L1 >>= 1, R1 >>= 1) {
			if (L1 & 1) adde(L1++ << 1, Nadd, 0);
			if (R1 & 1) adde(--R1 << 1, Nadd, 0);
		}
		for (L2 += PA, R2 += PA; L2 < R2; L2 >>= 1, R2 >>= 1) {
			if (L2 & 1) adde(Nadd + 1, L2++ << 1 | 1, 0);
			if (R2 & 1) adde(Nadd + 1, --R2 << 1 | 1, 0);
		}
		adde(Nadd, Nadd + 1, C);
		Nadd += 2;
	}
	void dij(int v) {
		rep(i, PA * 5 + AN * 2 + 2) D[i] = 1e18;
		priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
		que.push(mp(0, (v + PA) << 1));
		D[(v + PA) << 1] = 0;
		while (que.size()) {
			auto p = que.top();
			que.pop();
			int from = p.second;
			if (D[from] != p.first) continue;
			for (int ind = Ehe[from]; ind; ind = Ene[ind]) {
				int to = Eto[ind];
				ll d = D[from] + Eco[ind];
				if (D[to] > d) {
					D[to] = d;
					que.push(mp(d, to));
				}
			}
		}
	}
	ll dist(int v) {
		return D[(v + PA) << 1];
	}
} Noshi;

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



	int N, M;
	cin >> N >> M;

	rep(i, M) {
		int l, r, c;
		cin >> l >> r >> c;
		Noshi.AddE(l, r + 1, l, r + 1, c);
	}

	Noshi.dij(1);
	if (Noshi.dist(N) < 1e17) co(Noshi.dist(N));
	else co(-1);


	Would you please return 0;
}

Measured memory_bytes: 56572
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

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

int main() {
    solve();
    
    return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
 int n,sum=0,max=0,l;
 cin>>n;
 r(i,n){
   cin>>l;
   sum+=l;
   max<l? max=l:max=max;
 }

 if(sum-max>max)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;


return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    string S;
    cin >> S;
    int N = S.length();
    vector<int> ans(N, 0);
    int prv = 0;
    for (int i = 0; i < N - 1; i++) {
        if (S.substr(i, 2) == "RL") {
            ans[i] += (i - prv) / 2 + 1;
            ans[i + 1] += (i - prv + 1) / 2 + 1;
            prv = i + 2;
        } else if (S[i] == 'L') {
            prv = i + 1;
        }
    }

    prv = N - 1;
    for (int i = N - 1; i >= 1; i--) {
        if (S.substr(i - 1, 2) == "RL") {
            ans[i] += (prv - i) / 2;
            ans[i - 1] += (prv - i + 1) / 2;
            prv = i - 2;
        } else if (S[i] == 'R') {
            prv = i - 1;
        }
    }

    for (int a : ans) {
        cout << a << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val (n, m) = sc.intList()
        val e = Array(n) { Array(n) { false } }
        for (i in 1..m) {
            val (a, b) = sc.intList().map { it - 1 }
            e[a][b] = true
            e[b][a] = true
        }

        val f = Array(n) { false }
        f[0] = true
        fun go(cur: Int): Int {
            var result = 0
            var flag = true
            for (i in 0 until n) {
                if (f[i]) continue
                flag = false
                if (!e[cur][i]) continue
                f[i] = true
                result += go(i)
                f[i] = false
            }
            return if (flag) 1 else result
        }
        println(go(0))
    }
}


class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 36904
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;
 
typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
 
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || a + c == b || b + c == a)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

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

string s;
int main() {
	cin>>s;
	for(int i=0; i<3; i++) {
		if(s[i]==s[i+1]) {
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good";
	return 0;
}

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();
		boolean f = false;
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				if (i * j == n) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repx(i,a,b,x) for(ll i=a;i<b;i+=x)
#define rev(i,a,b) for(ll i=a;i>b;i--)
#define revx(i,a,b,x) for(ll i=a;i>b;i-=x)
#define arep(it,v) for(auto it=v.begin();it!=v.end();it++)
#define wh1(n) rep(xy1,0,n)
#define wh2(n) rep(xy2,0,n)
#define wh3(n) rep(xy3,0,n)
#define sc(i) cin>>i
#define ssc(i,j) sc(i);sc(j)
#define sssc(i,j,k) ssc(i,j);sc(k)
#define pf(i) cout<<i<<" "
#define pfn(i) cout<<i<<endl
#define cvec(v,n) rep(abc,0,n){ll xyz;sc(xyz);v.pb(xyz);}
#define pvec(v,n) rep(abc,0,n){pf(v[abc].F);pf(v[abc].S);}pfn("")
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define spll set<pll>
#define vpll vector<pll>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define pq(a) priority_queue<a>
#define pqc(a,cmp) priority_queue<a,vector<a>,cmp>
#define F first
#define S second
#define B begin
#define E end
#define R return
#define mp make_pair
#define pb push_back
#define ln length()
#define to_s to_string
#define Sort(v) sort(v.begin(),v.end())
#define Scmp(v,cmp) sort(v.begin(),v.end(),cmp)
#define zero_arr(v) memset(v,0,sizeof(v))
#define update_map(m,i) if(m.find(i)!=m.end()){m[i]++;}else{m[i]=1;}
#define update_mapx(m,i,x) if(m.find(i)!=m.end()){m[i]+=x;}else{m[i]=x;}
#define M 1000000007
#define INF 2000000000
#define fast ios::sync_with_stdio(0); cin.tie(0)
int main(){
    fast;
    ll x,y,z;
    sssc(x,y,z);
    x=100*x+10*y+z;
    if(x%4){
        pfn("NO");
    }else{
        pfn("YES");
    }
    R 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  vector<int>p;
  for(int i=0;i<N;i++){
    p.push_back(A[i]-(i+1));
  }
  sort(p.begin(),p.end());
  int a=p[N/2];
  int64_t sum=0;
  for(int i=0;i<N;i++){
    sum+=abs(A[i]-(i+1)-a);
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  int k;
  cin >> k;
  int len[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << len[k-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int i,j,k,n,T,q;
	string s1,s2;
	char s[200003];
	cin>>s;
	int count=0;
	int len=strlen(s);
	int maxi=0,a,b;
	for(i=0;i<len;i++){
        if(s[i]=='A'){
            a=i;
            break;
        }
	}
	for(i=0;i<len;i++){
        if(s[i]=='Z') b=i;
	}
	cout<<b-a+1<<endl;
}



Measured memory_bytes: 512
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2+5;

const int mod = 1e9+7;

//A 1
//C 2
//G 3
//T 4

int n;
int mem[N][5][5][5];

int go(int idx , int lst1 , int lst2 , int lst3){
    if(idx == n)
        return 1;
    if(~mem[idx][lst1][lst2][lst3])
        return mem[idx][lst1][lst2][lst3];
    int cnt = 0;
    for(int i = 1; i <= 4; i++){
        if(i == 3 && lst1 == 2 && lst2 == 1) continue;
        if(i == 3 && lst1 == 1 && lst2 == 2) continue;
        if(i == 3 && lst2 == 2 && lst3 == 1) continue;
        if(i == 3 && lst1 == 2 && lst3 == 1) continue;
        if(i == 2 && lst1 == 3 && lst2 == 1) continue;

        cnt += go(idx + 1 , i , lst1 , lst2);
        cnt %= mod;
    }
    return mem[idx][lst1][lst2][lst3] = cnt;
}

int main(){
    scanf("%d" , &n);
    memset(mem , -1 , sizeof mem);
    printf("%d\n" , go(0 , 0 , 0 , 0));
}

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

#include <atcoder/dsu>

using namespace std;
using namespace atcoder;

using ll = long long;

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}

inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm) {
    while ((ct = getcha()) >= '0') {
      A = A * 10 + ct - '0';
    }
  } else {
    while ((ct = *ci++) >= '0') {
      A = A * 10 + ct - '0';
    }
  }
  return A;
}

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int n = getint(), m = getint();
  dsu ds(n);
  while (m--) {
    int a = getint(), b = getint();
    a--, b--;
    ds.merge(a, b);
  }
  vector<vector<int>> g = ds.groups();
  printf("%d", (int)g.size() - 1);
  return 0;
}


Measured memory_bytes: 8720
object Main extends App{
  val List(s,t) = readLine.split(" ").toList
  val List(a,b) = readLine.split(" ").map(_.toInt).toList
  val u = readLine.split(" ").toList(0)
  
  val x = if(u == s) a-1 else a
  val y = if(u == t) b-1 else b  
  println(x + " " + y)
}

Measured memory_bytes: 27320
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	int i;
	string s;
	map<char, int> win;
	cin >> s;
	while (1) {
		char c;
		cin >> c;
		if (cin.eof()) break;
		int n;
		cin >> n;
		win[c] = n;
	}
	while (s.size() != 1) {
		int k, i;
		k = 0;
		i = 0;
		while (s[k] != ']') k++;
		while (s[k] != '[') k--;
		if (win[s[k + 1]] > win[s[k + 3]]) {
			win[s[k + 1]]--;
			s.replace(k, 5, s.substr(k + 1, 1));
		}
		else {
			win[s[k + 3]]--;
			s.replace(k, 5, s.substr(k + 3, 1));
		}
	}
	i = 0;
	for (auto d : win) {
		if (d.second != 0) break;
		i++;
	}
	if (i == win.size()) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}





Measured memory_bytes: 3208
n = int(input())
a, b = map(int, input().split())
p = [int(i) for i in input().split()]

p1 = []
p2 = []
p3 = []

for i in p :
	if a >= i:
		p1.append(i)
	elif a+1 <= i <= b:
		p2.append(i)
	elif b+1 <= i:
		p3.append(i)

print(min(len(p1), len(p2), len(p3)))

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


using namespace std;

int MAP[10][5];
int h;
void fall(){
	rep(i,h){
		for(int i=h-1;i>0;i--) rep(j,5){
			if(MAP[i][j]==-1){
				MAP[i][j]=MAP[i-1][j];
				MAP[i-1][j]=-1;
			}
		}
	}
}

int search(int x,int y,int num,int count){

	if(x<0||y<0||x>=5) return count;
	if(MAP[y][x]==-1||MAP[y][x]!=num) return count;


	int ans = 0;
	count++;
	count = search(x+1,y,num,count);

	if(count>=3) MAP[y][x]=-1;

	return count;
}

int main(){

	while(1){
		cin >> h;

		if(h==0) break;

		int ans=0;
		int p_score=-1;
		memset(MAP,-1,sizeof(MAP));
		rep(i,h) rep(j,5) cin >> MAP[i][j];


		while(1){
			rep(i,h) rep(j,5){
				int point = MAP[i][j];  
				int combo = search(j,i,MAP[i][j],0);
				if(combo>=3){
					ans+=combo*point;
				}
			}

			fall();

			if(p_score==ans) break;
			p_score=ans;
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 1160
data = []
while True:
    in_line = raw_input().split()
    m = int(in_line[0])
    f = int(in_line[1])
    r = int(in_line[2])
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        data.append("F")
    elif m + f >= 80:
        data.append("A")
    elif m + f >= 65:
        data.append("B")
    elif m + f >= 50:
        data.append("C")
    elif m + f >= 30:
        if r >= 50:
            data.append("C")
        else:
            data.append("D")
    else:
        data.append("F")
for n in data:
    print n

Measured memory_bytes: 6456
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    ll n, m;
    cin >> n >> m;
    ll res = 0;
    if (m / 2 <= n) {
        cout << m / 2 << endl;
        return;
    }
    cout << (m - 2 * n) / 4 + n << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
using namespace std;
int a[100004];
int main()
{
	int n;
	int h=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			i++;
		}
		else
		{
			h++;
		}
	}
	printf("%d\n",h);
	return 0;

}


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

using namespace std;

int R;

int main() {
    cin>>R;
    if(R<1200){
        cout<<"ABC"<<endl;
        }
    else if (R<2800){
        cout<<"ARC"<<endl;
        }
    else{
        cout<<"AGC"<<endl;
        }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    std::sort(a.begin(), a.end(), std::greater<int>() );
    int ans=0;
    rep(i,k){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var T = sc.ReadInt();
        var ans = int.MaxValue;
        for (int i = 0; i < N; i++)
        {
            var c = sc.ReadInt();
            var t = sc.ReadInt();
            if (t <= T)
            {
                ans = Math.Min(ans, c);
            }
        }
        if (ans == int.MaxValue)
        {
            Console.WriteLine("TLE");
        }
        else
        {
            Console.WriteLine(ans);
        }
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();

    std::vector<int> A(N + 1), B(N);
    in.read(A.begin(), N + 1);
    in.read(B.begin(), N);

    std::uint64_t res = 0;
    for (int i : boost::irange(0, N)) {
        int x = std::min(B[i], A[i]);
        res += x;
        B[i] -= x;
        A[i] -= x;

        x = std::min(B[i], A[i + 1]);
        res += x;
        A[i + 1] -= x;
    }
    out << res;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;//頂点数

void dijkstra(int s)
{
	for (int i = 0; i < MAX_V; i++)
	{
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;

	while (true)
	{
		int v = -1;
		for (int u = 0; u < V; u++)
		{
			if (!used[u] && (v == -1 || d[u]<d[v]))
			{
				v = u;
			}
		}
		if (v == -1)
		{
			break;
		}
		used[v] = true;

		for (int u = 0; u < V; u++)
		{
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
	

}




int main()
{
	for (int i = 0; i < MAX_V; i++)
	{
		for (int j = 0; j < MAX_V; j++)
		{
			cost[i][j] = INF;
		}
	}
	cin >> V;
	for (int i = 0; i < V; i++)
	{
		int u;//頂点番号
		cin >> u;
		int k;//出次数
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int v;
			cin >> v;
			int c;
			cin >> c;
			cost[u][v] = c;
	    }

	}

	dijkstra(0);

	for (int i = 0; i < V; i++)
	{
		cout <<i<<" "<< d[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input!{
        s: Chars
    };

    let mut cnt = s.clone();
    cnt.dedup();

    match cnt.len() {
        1 => {
            if cnt.pop().unwrap() == 'S' {
                println!("0");
            } else {
                println!("3");
            }
        }
        2 => {
            let mut ans = 0;
            for weather in s {
                if weather == 'R' {
                    ans += 1;
                }
            }
            println!("{}", ans);
        }
        3 => {
            println!("1");
        }
        _ => unreachable!(),
    }
}


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> C(N);
	vector<int> V(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	int X, Y;
	X = 0;
	Y = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i]) {
			X += V[i];
			Y += C[i];
		}
	}
	cout << X - Y << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {
		execute13_1();
	}

	private static void execute13_2() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int q = sc.nextInt();
			int[] a = new int[n];
			
			long ans =0L;
			for(int i=1; i<m; i++) {
				for(int j=0; j<n; j++) {
					
				}
			}
			
			
			System.out.println(ans);
		}

	}
	
	private static int rr() {
		
		rr();
		return 0;
	}

	private static void execute13_1() {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			long b = sc.nextLong();
			long n = sc.nextLong();

			long x = 0;
				x = Math.min(n, b - 1);
			long ans = (long) (Math.floor(a * x / b) - a * Math.floor(x / b));

			
			System.out.println(ans);
		}

	}
}

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

long long int gcd(long long int x,long long int y){
	while((x%=y)&&(y%=x));
	return x^y;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--){
		long long int A,B,C,D;
		cin>>A>>B>>C>>D;
		if(A<B||D<B){
			cout<<"No\n";
			continue;
		}
		long long int g = gcd(B,D);
		A = A - (C-B+1);
		long long int d = (A%g+g)%g;
			A = C-B+1+d;
		if(A<0)
			cout<<"No\n";
		else
			cout<<"Yes\n";
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
const int N=1100;

int l;
bool f1,f2;
char ch[N];
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);

	ch[0]=3;
	scanf("%s",ch+1);
	l=strlen(ch)-1;
	
	f1=f2=false;
	for(int i=1; i<=l; i++){
		if(ch[i]!='C' and ch[i]!='F') continue;
		
		if(!f1 and ch[i]=='C'){
			f1=true;
			continue;
		}
		if(f1 and ch[i]=='F'){
			f2=true;
			break;
		}
	}
	
	if(f2){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int maxn = 500 + 5;
int mp[maxn][maxn], vis[maxn];
int match[maxn]; //表示match[1]=2表示女1和男2约上了(不一定最后是在一起的)
int n;
struct node {
	int a, b;
} p[105], q[105];
int Find(int x) //这里x表示男生
		{
	for (int i = 1; i <= n; i++) //这里的i表示女生
		if (!vis[i] && mp[i][x]) //如果这个女生没有询问过而且你和这个男生认识
				{
			vis[i] = 1; //标记询问过了
			if (match[i] == -1 || Find(match[i])) //如果当前男孩纸是来直接找约会对象，或者是要抛弃当前女孩去找下一个女孩的(而且找到了)
					{
				match[i] = x; //当前男生和女生约上了(x男i女)
				return 1; //返回找到了~~~
			}
		}
	return 0;
}

int main(void) {
	scanf("%d", &n);
	memset(mp, 0, sizeof(mp));
	memset(match, -1, sizeof(match));
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &p[i].a, &p[i].b);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &q[i].a, &q[i].b);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (p[i].a < q[j].a && p[i].b < q[j].b)
				mp[i][j] = 1;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		memset(vis, 0, sizeof(vis));
		if (Find(i))
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long C=sc.nextLong();
		long[][] sushi=new long[N][2];
		long[][] migi=new long[N][2];
		long[][] hidari=new long[N][2];

		long max_cal=0;
		for(int i=0; i<N; i++) {
			sushi[i][0]=sc.nextLong();
			sushi[i][1]=sc.nextLong();
		}
		//右回り

		migi[0][0]=sushi[0][0];
		migi[0][1]=sushi[0][1];
		for(int i=1; i<N; i++) {
			migi[i][0]=sushi[i][0];
			migi[i][1]=migi[i-1][1]+sushi[i][1];	//累積和
		}
		//スタート地点よりも左側に行かない時
		for(int i=0; i<N; i++) {
			migi[i][1]-=migi[i][0];		//１回分のキョリを引く
			if(migi[i][1]>=0) {
				max_cal=Math.max(max_cal, migi[i][1]);
			}
		}

		//左のとある地点まで行く場合
		hidari[0][0]=C-sushi[N-1][0];
		hidari[0][1]=sushi[N-1][1];
		for(int i=1; i<N; i++) {
			hidari[i][0]=C-sushi[N-1-i][0];		//逆周りなので一番最初にxN
			hidari[i][1]=hidari[i-1][1]+sushi[N-1-i][1];
		}

		long[][] gyaku=new long[N][2];		//左のどこまで行くのが最善化をもとめる 0得られるカロリー  1得られる地点(ダブリングを防ぐ為)
		if(hidari[0][1]-hidari[0][0]>0) {
			gyaku[0][0]=hidari[0][1]-hidari[0][0];
			gyaku[0][1]=0;
		}
		else {
			gyaku[0][0]=0;
			gyaku[0][1]=-1;	//行くな
		}
		for(int i=1; i<N; i++) {
			if(hidari[i][1]-hidari[i][0]>gyaku[i-1][0]) {		//ここがある意味DPテーブルみたいな感じ
				gyaku[i][0]=hidari[i][1]-hidari[i][0];
				gyaku[i][1]=i;
			}
			else {
				gyaku[i][0]=gyaku[i-1][0];		//今までよりも先に行った結果損したなら行かないほうが得
				gyaku[i][1]=gyaku[i-1][1];
			}
		}

		for(int i=0; i<N-1; i++) {		//右側の行く地点を固定して、左側に最大利益で行けるとこまで行く。		N-1まで（実質N-2）なのは、N-1まで右回りで行ったら左に向かっていない（向かうと無駄）なので
			migi[i][1]-=migi[i][0];		//右にいく　そして　左へ向かう時の2回目の分を引く
			long tmp=migi[i][1]+gyaku[N-2-i][0];
			max_cal=Math.max(tmp,max_cal);
		}
		//右回り終了

		//左回り
		hidari=new long[N][2];
		migi=new long[N][2];
		hidari[0][0]=C-sushi[N-1][0];
		hidari[0][1]=sushi[N-1][1];
		for(int i=1; i<N; i++) {
			hidari[i][0]=C-sushi[N-1-i][0];
			hidari[i][1]=hidari[i-1][1]+sushi[N-1-i][1];	//累積和
		}
		//スタート地点よりも右側に行かない時
		for(int i=0; i<N; i++) {
			hidari[i][1]-=hidari[i][0];		//１回分のキョリを引く
			if(hidari[i][1]>=0) {
				max_cal=Math.max(max_cal, hidari[i][1]);
			}
		}

		//右のとある地点まで行く場合
		migi[0][0]=sushi[0][0];
		migi[0][1]=sushi[0][1];
		for(int i=1; i<N; i++) {
			migi[i][0]=sushi[i][0];		//逆周りなので一番最初にx1が来る
			migi[i][1]=migi[i-1][1]+sushi[i][1];		//累積和
		}

		//long[][] gyaku=new long[N][2];		//右のどこまで行くのが最善化をもとめる 0得られるカロリー  1得られる地点(ダブリングを防ぐ為)
		if(migi[0][1]-migi[0][0]>0) {
			gyaku[0][0]=migi[0][1]-migi[0][0];		//得られるカロリー
			gyaku[0][1]=0;
		}
		else {
			gyaku[0][0]=0;
			gyaku[0][1]=-1;	//行くな
		}
		for(int i=1; i<N; i++) {
			if(migi[i][1]-migi[i][0]>gyaku[i-1][0]) {		//ここがある意味DPテーブルみたいな感じ
				gyaku[i][0]=migi[i][1]-migi[i][0];
				gyaku[i][1]=i;
			}
			else {
				gyaku[i][0]=gyaku[i-1][0];		//今までよりも先に行った結果損したなら行かないほうが得
				gyaku[i][1]=gyaku[i-1][1];
			}
		}

		for(int i=0; i<N-1; i++) {		//左側の行く地点を固定して、左側に最大利益で行けるとこまで行く。		N-1まで（実質N-2）なのは、N-1まで左回りで行ったら右に向かっていない（向かうと無駄）なので
			hidari[i][1]-=hidari[i][0];		//左にいく　そして　右へ向かう時の2回目の分を引く
			long tmp=hidari[i][1]+gyaku[N-2-i][0];
			max_cal=Math.max(tmp,max_cal);
		}
				//左回り終了
		System.out.println(max_cal);

	}
}

Measured memory_bytes: 102668
#include <bits/stdc++.h>
#define MAX 10000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define inf 1e9
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mod 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define ios ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll x[100004];
int main()
{
    ios;
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    for(int i=2;i<=n;i++)
    {
        ll t=x[i]-x[i-1];
        t=t*a;
        if(t>=b)ans+=b;
        else ans+=t;
    }
    cout<<ans<<endl;



}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

const int mxn = 1e5;
ll arr[100], cost[100], dp[mxn+1][101];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int w, n;cin>>n>>w;
	for(int i = 0; i < n; ++i) cin>>cost[i]>>arr[i];
	memset(dp, INT_MIN, sizeof(dp));
	for(int i = 0; i <=w; ++i) dp[i][0] = 0;
	for(int i = 0; i <=n; ++i) dp[0][i] = 0;
	for(int i = 0; i <=w; ++i){
		for(int j = 0; j < n; ++j){
			// if we are on the ith state then if adding ith wie
			if(i + cost[j] <=w){
				//if(!i) cout<<j<<endl;
				dp[i + cost[j]][j+1] = max(dp[i + cost[j]][j+1], dp[i][j] + arr[j]);
				//cout<<i+cost[j]<<" "<<j+1<<" "<<dp[i+cost[j]][j+1]<<endl;
			}
			dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	// for(int i = 0; i <=w; ++i){
	// 	for(int j = 0; j <=n; ++j){
	// 		cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
	// 	}
	// }
	cout<<dp[w][n];
	return 0;
}



Measured memory_bytes: 79232
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,3){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << min(A[0]*A[1],A[2]) << endl;
}

// int main(){
//     char A[19];
//     cin >> A;
//     A[3]='8';
//     cout <<  A << endl;
// }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define ft first
#define sd second
#define pb(a) push_back(a)
#define PII std::pair<int,int>
#define PLL std::pair<ll,ll>
#define mp(a,b) std::make_pair(a,b)
#define ITR(a,b) for(auto a:b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=2000+10,MAXM=5000000+10,Mod=1e9+7;
int n,k;
ll f[MAXN][MAXN],fac[MAXM],inv[MAXM];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}
template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline ll qexp(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=res*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return res;
}
inline void init(int LM)
{
	fac[0]=1;
	REP(i,1,LM)fac[i]=1ll*fac[i-1]*i%Mod;
	inv[LM]=qexp(fac[LM],Mod-2);
	DEP(i,LM-1,0)inv[i]=1ll*inv[i+1]*(i+1)%Mod;
}
inline ll C(int n,int m)
{
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main()
{
	read(n);read(k);init((n+1)*k);
	if(k==1)
	{
		puts("1");
		return 0;
	}
	f[0][0]=1;
	REP(i,0,n)REP(j,0,i)if(i||j)
		f[i][j]=((j?f[i][j-1]:0)+(i?1ll*C((i-1)*(k-1)+j+k-2,k-2)*f[i-1][j]%Mod:0))%Mod;
	write(1ll*f[n][n]*fac[n]%Mod,'\n');
	return 0;
}


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

char trump[4][13][2];
int tuyosa[4][13];
int pt[4];

//rankを求める
int srank(const char *x,char head)
{
	int a=0;
	switch(x[0])
	{
		case 'T':
		a=10;
		break;
		case 'J':
		a=20;
		break;
		case 'Q':
		a=21;
		break;
		case 'K':
		a=22;
		break;
		case 'A':
		a=23;
		break;
		default:
		a=x[0]-'0';
		break;
	}
	return a;
}

int main()
{
	char head;
	string debug[4]={"north","east","south","west"};
	while(1)
	{
		cin>>head;
		if(head=='#')
			break;
		for(int i=0;i<4;i++)
		{
			for(int j=0;j<13;j++)
			{
				cin>>trump[i][j];
				tuyosa[i][j]=srank(trump[i][j],head);
			}
		}
		fill(pt,pt+4,0);
		int prewinner=0;
		int winner=0;
		//13のトリック
		for(int i=0;i<13;i++)
		{
			int kiri=0;
			int tmp=0;
			for(int j=0;j<4;j++)
			{
				if(trump[j][i][1]==trump[prewinner][i][1])
					tmp|=(1<<j);
				if(trump[j][i][1]==head)
					kiri|=(1<<j);
			}
			int m=0;
			if(kiri>0)
			{
				for(int j=0;j<4;j++)
				{
					if((kiri&(1<<j))==0)
						continue;
					m=max(m,tuyosa[j][i]);
				}
				for(int j=0;j<4;j++)
				{
					if((kiri&(1<<j) && tuyosa[j][i]==m))
						winner=j;
				}
			}else if(tmp>0){
				for(int j=0;j<4;j++)
				{
					if((tmp&(1<<j))==0)
						continue;
					m=max(m,tuyosa[j][i]);
				}
				for(int j=0;j<4;j++)
				{
					if((tmp&(1<<j) && tuyosa[j][i]==m))
						winner=j;
				}
			}else{
				for(int j=0;j<4;j++)
				{
					m=max(m,tuyosa[j][i]);
				}
				for(int j=0;j<4;j++)
				{
					if((tuyosa[j][i]==m))
						winner=j;
				}
			}
			//cerr<<debug[winner]<<endl;
			pt[winner]++;
			prewinner=winner;
		}
		int ns=pt[0]+pt[2];
		int ew=pt[1]+pt[3];
		if(ns>ew)
			cout<<"NS "<<max(0,ns-6)<<endl;
		else
			cout<<"EW "<<max(0,ew-6)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3040