akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 1000000007;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n, m;
vector<P> e[100000];
int dist[100000];
priority_queue<P,vector<P>, greater<P> > que;

int main(){
    cin >> n >> m;
    rep(i,n) dist[i] = INF;
    dist[0] = 0;
    rep(i,m){
        int a, b, c;
        scanf("%d%d%d",&a,&b,&c);
        a--; b--;
        e[a].push_back(P(b,c));
    }
    que.push(P(0,0));
    while(que.size() != 0){
        P p = que.top();
        que.pop();
        if(dist[p.second] < p.first) continue;
        rep(i,e[p.second].size()){
            P to = e[p.second][i];
            if(to.second < dist[p.second]) continue;
            if(dist[to.first] <= to.second) continue;
            dist[to.first] = to.second;
            que.push(P(dist[to.first],to.first));
        }
    }
    int ans = 0;
    if(dist[n-1] == INF){
        cout << -1 << endl;
        return 0;
    }
    rep(i,n-1){
        if(dist[i] == INF) continue;
        rep(j,e[i].size()){
            if(e[i][j].first != n-1) continue;
            if(e[i][j].second < dist[i]) continue;
            ans = max(ans,e[i][j].second);
        }
    }
    cout << ans << endl;
}

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

void solver(){
	//type your code here
	int N , M, C , ans =0 ;
	cin >> N >> M >> C;
	vector<int> B(M);
	for(auto &i:B)cin >> i;
	vector<vector<int>> A(N,vector<int>(M));
	for(auto &i:A){
		for(auto &j:i){
			cin >> j;
		}
	}
	for(int i = 0 ; i < N ; ++i){
		int sum = C;
		for(int j = 0 ; j < M ; ++j){
			sum += B[j]*A[i][j];
		}
		if(sum > 0)ans++;
	}
	cout << ans << endl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int queries = 1;
	//(cin >> queries);
	for(int i = 0 ; i < queries ; ++i){
		solver();
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
d1=[]
d2=[]

for _ in range(n):
    D1,D2 = map(int,input().split())

    d1.append(D1)
    d2.append(D2)

ans='No'

cnt=0
for i in range(n):
    p=d1[i]
    q=d2[i]

    if p==q:
        cnt+=1
    else:
        cnt=0

    if cnt>=3:
        ans='Yes'
        break


print(ans)




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

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

    int largest = (b / k) * k;
    if(a<=largest){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
    return 0;
}

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

int N;

void dfs(string s, char mx) {
    if (s.length() == N) {
        cout << s.c_str() << endl;
    } else {
        for (char c = 'a'; c <= mx; c++) {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
        }
    }
}

int main() {
    cin >> N;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

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

int mod=1000000007;

long long arr[200004];
int rarr[200004];
int main()
{
    int n,x;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        rarr[i]=x;
        arr[i]+=(arr[i-1]+x);
    }
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        long long temp=(((arr[n]-arr[i])%mod)*rarr[i])%mod;
        sum=(sum+temp)%mod;
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 5928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll x, n;
    cin >> x >> n;
    vector<ll> p(n);
    REP(i, n) cin >> p[i];

    ll mi = INF, idx = -1;
    REP(i, 105) {
        bool flag = true;
        REP(j, n) if(i == p[j]) flag = false;
        if(!flag) continue;

        if(mi > abs(x-i)) {
            mi = abs(x-i);
            idx = i;
        }
    }
    cout << idx << endl;

    return 0;
}

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

int main() {
  			double pi1 = 3.14159265358979323846;
  			int r;
  			cin >> r;
  			double cir = 2 * pi1 * r;
  			cout  << cir;
}

Measured memory_bytes: 3796
S = input()
if S[0] == "R":
    if S[1] == "R":
        if S[2] == "R":
            print(3)
        else:
            print(2)
    else:
        print(1)
elif S[1] == "R":
    if S[2] == "R":
        print(2)
    else:
        print(1)
elif S[2]  == "R":
    print(1)
else:
    print(0)

Measured memory_bytes: 9048
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;


int main() {
    int a, b;
    scanf("%d", &a);
    int i;
    for(i = a; i<10000000000; i*=2){
        if(i % a == 0){
            if(i % 2 == 0){
                cout << i << "\n";
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    VI v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    sort(ALL(v));
    int ans = 0;
    rep(i, k)
    {
        ans += v[i];
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<3;i++){
    if(s.at(i)=='1') s.at(i)='9';
    else if(s.at(i)=='9') s.at(i)='1';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
from itertools import accumulate
N, C = map(int, input().split())
R = [0] * (10**5+1)
RC = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    RC[c-1].append((s,t))

for rc in RC:
    rc.sort()
    pt = 0
    for s, t in rc:
        if s == pt:
            R[pt] += 1
        else:
            R[s-1] += 1
        R[t] -= 1
        pt = t
print(max(list(accumulate(R))))

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

typedef vector<long long> vec;
typedef vector<vector<long long>> mat;

const long long INF = LLONG_MAX;
long long L, A, B, M;

long long pow10(long long n, long long M) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = pow10(n/2, M);
        return (t * t) % M;
    }
    return (10 * pow10(n - 1, M)) % M;
}

mat mult(mat A, mat B) {
    mat ret(A.size(), vec(B[0].size(), 0));
    for (int i=0; i<A.size(); ++i) {
        for (int j=0; j<B[0].size(); ++j) {
            for (int k=0; k<A[0].size(); ++k) {
                ret[i][j] += A[i][k] * B[k][j];
                ret[i][j] %= M;
            }
        }
    }
    return ret;
}

mat pow(mat A, long long n) {
    if (n == 0) {
        return { {1,0,0}, {0,1,0}, {0,0,1} };
    }
    if (n % 2 == 0) {
        mat t = pow(A, n/2);
        return mult(t, t);
    }
    return mult(A, pow(A, n-1));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    cin >> L >> A >> B >> M;

    long long ans = 0;

    for (long long d=1; d<=18; ++d) { // d:=桁数
        long long l = pow10(d - 1, INF) - A;
        l = (l % B && l > 0) ? l/B+1 : l/B;
        l = max(l, 0LL);

        long long r = pow10(d, INF)-A;
        r = (r % B && r > 0) ? r/B+1 : r/B;
        r = min(r, L);

        if (l >= r) continue;
        
        // ans = (ans * pow10((r-l)*d, M)) % M;
        for (int i=0; i<d; ++i) {
            ans *= pow10(r-l, M);
            ans %= M;
        }

        long long si, ai;
        si = ((A % M) + (B % M) * (l % M)) % M;
        ai = si;

        mat m = {
            {pow10(d, M), 0, 0},
            {1, 1, 0},
            {B % M, B % M, 1}
        };
        m = pow(m, r-l-1);

        ans += (ai * m[0][0]) % M + (si * m[1][0]) % M + m[2][0];
        ans %= M;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import heapq
K = int(input())
def NewLun(strX):
    if strX[-1] != '0' and strX[-1] != '9':
        intX0 = int(strX[-1])
        heapq.heappush(Lun,int(strX + str(intX0+1)))
        heapq.heappush(Lun,int(strX + str(intX0)))
        heapq.heappush(Lun,int(strX + str(intX0-1)))
    elif strX[-1] == '0':
        heapq.heappush(Lun,int(strX + '0'))
        heapq.heappush(Lun,int(strX+'1'))
    else:
        heapq.heappush(Lun,int(strX +'9'))
        heapq.heappush(Lun,int(strX+'8'))
Lun = [i for i in range(1,10)]
heapq.heapify(Lun)
for _ in range(K):
    Ans = heapq.heappop(Lun)
    NewLun(str(Ans))
print(Ans)

Measured memory_bytes: 16304
#include <iostream>

using namespace std;

int digits(int n) {
    int dig = 1;

    while (n / 10) {
        dig++;
        n /= 10;
    }
    return dig;
}

int main(void)
{
    int a, b;
    
    while (cin >> a >> b) 
        cout << digits(a + b) << '\n';

    return 0;
}

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

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

  set<int> num;
  for(int x:a){
    num.insert(x);
    if(num.size()==4)break;
  }

  if(num.size()>=4)cout<<"No"<<endl;
  else if(num.size()==1){
    if(a[0]==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else if(num.size()==2){
    bool fl1=false, fl2=false;

    vector<int> xx;
    for(int x:num){
      xx.push_back(x);
      if(x==0)fl1=true;
    }

    vector<int> xnum(2,0);
    for(int y:a){
      if(y==xx[0])xnum[0]++;
      if(y==xx[1])xnum[1]++;
    }

    if(xnum[1]%xnum[0]==0 && xnum[1]/xnum[0]==2)fl2=true;

    if(fl1 && fl2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else{
    vector<int> x;
    for(int y:num)x.push_back(y);

    bool fl=true;

    vector<int> xnum(3,0);
    for(int y:a){
      if(y==x[0])xnum[0]++;
      if(y==x[1])xnum[1]++;
      if(y==x[2])xnum[2]++;
    }

    if(!(xnum[0]==xnum[1] && xnum[1]==xnum[2]))fl=false;
    
    while(x[0]!=0 && x[1]!=0 && x[2]!=0){
      int xx=x[0]%2, yy=x[1]%2, zz=x[2]%2;
      if((xx+yy+zz)%2!=0){fl=false; break;}
      x[0]/=2; x[1]/=2; x[2]/=2;
    }

    if(fl)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}


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

int main()
{
	while(true){

		int n , m;
		int mas[1001],dice[1001];
		int a = 1,b = 1;

		cin >> n >> m;
	
		if(n==0 && m==0)
			break;

		for(int i=1 ;i<=n ;i++){
			cin >> mas[i];
		}
		for(int i=1 ;i<=m ;i++){
			cin >> dice[i];
 		}

		for(int j=1 ;j<=m ;j++){
			
			a += dice[j];
			if(a >= n){
				b = j;
				break;
			}
			a += mas[a];

			if(a >= n){
				b = j;
				break;
			}
		}

		cout << b << endl;
		
		}
 return 0;
}					

Measured memory_bytes: 0
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll n, a[3], d;
map<ll, ll> s;

ll calc(ll n)
{
    auto it0 = s.find(n);
    if (it0 != s.end()) {
        return it0->second;
    }
    if (n == 0) {
        return s[0]=0;
    }
    else if (n == 1) {
        return s[1] = d;
    }

    const int prime[3] = { 2,3,5 };
    ll ans = LINF3;
    int k;
    for (k = 0; k < 3; k++) {
        ll m = n / prime[k];

        {
            if ((double)n * d < LINF3) {
                ll ans1 = n * d;
                ans = MIN(ans, ans1);
            }
        }

        {
            ll tmp = calc(m);
            if ((double)tmp + (double)(n % prime[k]) * d + a[k] < LINF3) {
                ll ans1 = tmp + (n % prime[k]) * d + a[k];
                ans = MIN(ans, ans1);
            }
        }

        if (n % prime[k]) {
            ll tmp = calc(m + 1);
            if ((double)tmp + (double)(prime[k] - n % prime[k]) * d + a[k] < LINF3) {
                ll ans1 = tmp + (prime[k] - n % prime[k]) * d + a[k];
                ans = MIN(ans, ans1);
            }
        }
    }

    return s[n] = ans;
}

void solve()
{
    s.clear();
    scanf("%lld%lld%lld%lld%lld", &n, &a[0], &a[1], &a[2], &d);

    ll ans = calc(n);
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 0
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, m, q;
int a[55][4], lis[15];
int ans = 0;
void init(){
    n = read(), m = read(), q = read();
    for (int i = 1; i <= q; ++i)
        a[i][0] = read(), a[i][1] = read(), a[i][2] = read(), a[i][3] = read();
}
void dfs(int cur, int lst){
    if (cur == n + 1){
        int res = 0;
        for (int i = 1; i <= q; ++i)
            if (lis[a[i][1]] - lis[a[i][0]] == a[i][2])
                res += a[i][3];
        ans = max(ans, res);
        return ;
    }
    for (int i = lst; i <= m; ++i)
        lis[cur] = i, dfs(cur + 1, i);
}
void solve(){
    for (int i = 1; i <= m; ++i)
        lis[1] = i, dfs(2, i);
    printf("%d\n", ans);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 3696
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cctype>
#include<cstring>
#include<string>
#include<iomanip>

using namespace std;

int main(){
	string moji,tmpf,tmpb;
	int m;
	while(1){
		cin>>moji;
		if(moji=="-")break;
		cin>>m;
		for(int i=0,h;i<m;i++){
			cin>>h;
			tmpb=moji.substr(0,h);//????????????????????£????????????????????????????????????????????????????????????
			tmpf=moji.substr(h,moji.size()-h);
			moji=tmpf+tmpb;
			tmpb.erase();
			tmpf.erase();
			
		}
		cout<<moji<<endl;
	}
	return 0;

}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> t(N),a(N);
    REP(i,N) cin>>t[i];
    REP(i,N) cin>>a[i];
    if(a[0]!=t[N-1]){
        cout<<0<<endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 1; i < N-1; i++){
		if(t[i] == t[i-1] && a[i] == a[i+1]){
			ans *= min(t[i],a[i]);
			ans %= MOD;
		}else if(t[i] > t[i-1] && a[i] == a[i+1] && a[i] < t[i]){  //h[i] == t[i]
			ans = 0;
		}else if(t[i] == t[i-1] && a[i] > a[i+1] && a[i] > t[i]){  //h[i] == a[i]
			ans = 0;
		}else if(t[i] > t[i-1] && a[i] > a[i+1] && a[i] != t[i]){   //h[i] == t[i] == a[i]
			ans = 0;
		}
	}
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
N = int(input())
a = [int(input()) for i in range(N)]
b = []
for i in range(N):
    b.append([a[i], i])
b.sort(key=lambda x: x[0])

# print(b)
for i in range(N):
    if i != b[-1][1]:
        print(b[-1][0])
    else:
        print(b[-2][0])


Measured memory_bytes: 40872
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	string L, S[100] = {}, A;
	int N;

	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S, S + N);

	for (int i = 0; i < N; i++) {
		A += S[i];
	}
	cout << A << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 #define MAX 100
 int main()
 {
     int a[MAX];
     int n, i, j, flag, count=0, temp;

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

     flag=1;
     for(i=0;flag!=0;i++)
     {
         flag=0;
         for(j=n-1;j>=i+1;j--)
         {
             if(a[j]<a[j-1])
             {
                 temp=a[j];
                 a[j]=a[j-1];
                 a[j-1]=temp;
                 count++;
                 flag=1;
             }
         }
     }

     for(i=0;i<n-1;i++)
        printf("%d ", a[i]);
     printf("%d\n", a[i]);
     printf("%d\n", count);

     return 0;
 }

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

int main() {
    int N; cin >> N;
    int X[N], sortedX[N];
    for (int i = 0; i < N; i++) {
        int x_i; scanf("%d", &x_i);
        X[i] = x_i; sortedX[i] = x_i;
    }
    sort(sortedX, sortedX + N);

    int md_sm = sortedX[(N - 2) / 2];
    int md_la = sortedX[N / 2];
    for (int i = 0; i < N; i++) {
        int target = X[i];
        if (target < md_la) {
            printf("%d\n", md_la);
        } else {
            printf("%d\n", md_sm);
        }
    }
}

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

#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  ll long long
#define sc second
#define fr first
const int nax = 1e6+5;
const int mod = 1e4+7;
using namespace std;
typedef pair<double,double> pi;
typedef tuple<int,int,int> tu;


signed main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
    #endif
	int n;
	cin >> n;
	if(n>=30)
		cout << "Yes"<< "\n";
	else
		cout << "No" << "\n";
	return 0;

}



Measured memory_bytes: 3616
PROGRAM cardGameForTwo
      IMPLICIT NONE
      INTEGER :: N
      INTEGER,ALLOCATABLE :: a(:)
      INTEGER :: buffer(2),ans,i,piyo, alice,bob
      LOGICAL :: flag
      
      READ*,N
      ALLOCATE( a(N) )
      READ*,a(:)
      
      DO while(.TRUE.)
        flag = .TRUE. 
        DO i = 1,N-1
          IF(a(i)<a(i+1))THEN
            buffer(1:2) = a(i:i+1)
            a(i) = buffer(2); a(i+1) = buffer(1)
            flag = .FALSE.
          END IF
        END DO
        
        IF(flag)THEN
        !sort has end
        EXIT
        END IF
      END DO 
      
      ans = 0
      alice = 0
      bob = 0
      
      flag = .TRUE.
      DO i = 1,N
        IF(flag)THEN
          alice = alice + a(i)
          flag = .FALSE.
        ELSE
          bob = bob + a(i)
          flag = .TRUE.
        END IF
      END DO
      
      ans = alice - bob
      
      print'(I0)',ans
      
      
      
      
      
      
      
      
      
      END PROGRAM

Measured memory_bytes: 256
#include<iostream>

#define     MAX_LENGTH     30

using namespace std;

int main(){
	char str[MAX_LENGTH];
	int i,n;

	// 入力
	cin >> str;

	// 文字数計測
	for(n=0;(str[n] != '\n') && (str[n] != '\0');n++){
	}

	// 逆順出力
	for(i = (n - 1);i>=0;i--){
		cout << str[i];
	}
	cout << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int x;
    cin>>x;
    vector<bool> expo(x+1);
    expo[1] = 1;
    for (int i = 2; i <= x; i++) {
        int v = i * i;
        while (v <= x) {
            expo[v]= 1;
            v *= i;
        }
    }
    for (int i = x; i >=  1; i--) {
        if (expo[i]) {
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  __int128 s2 = 0;
  __int128 diag2 = 0;
  __int128 mod = 1e9 + 7;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    __int128 ai = a;
    s2 += ai;
    diag2 += ai * ai;
  }
  s2 *= s2;
  __int128 ret = (s2 - diag2) / 2;
  ret %= mod;
  cout << (int)ret << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
using namespace std;

int main (void) {
  int N,K;
  cin >> N >> K;
  int ans=K;
  if (N==1){
    cout << ans;
    return 0;
  }
  for (int i=1; i<N; i++) {
    ans=ans*(K-1);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;

  if(S.at(K - 1) == 'A') S.at(K - 1) = 'a';
  if(S.at(K - 1) == 'B') S.at(K - 1) = 'b';
  if(S.at(K - 1) == 'C') S.at(K - 1) = 'c';

  cout << S << endl;
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

using namespace std;

int main() {

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (s == u)
        a--;
    if (t == u)
        b--;

    AA(a << ' ' << b);
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
using namespace std;

int main() {
	int n,current,cnt=0;
	cin >> n;
	int* a = new int[n];
	list<int> lst;
	for (int i = 0; i < n; i++)	cin >> a[i];

	current = 1;
	while (current!=2)
	{
		lst.push_back(current);
		cnt++;
		current = a[current - 1];
		if (cnt>n)
			break;
	}
	if (current == 2) {
		cout << cnt << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
s=list(input())
t=list(input())
p=len(s)-len(t)
for i in range(p+1):
    for j in range(len(t)):
        if s[p-i+j]!="?" and s[p-i+j]!=t[j]:
            break
    else:
        print(("".join(s[:p-i]+t+s[len(s)-i:])).replace("?","a"))
        exit()
print("UNRESTORABLE")        
            



Measured memory_bytes: 3060
n = map(int, input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, len(p) - 1):
    if p[i] > p[i - 1] and p[i] < p[i + 1]:
        ans += 1
        continue
    
    if p[i] > p[i + 1] and p[i] < p[i - 1]:
        ans += 1
        continue

print('{}'.format(ans))



Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

    int n, a, b, r, i, j, t, c;
    scanf("%d%d%d", &n, &a, &b);
    r=0;

    for(i=1;i<=n;i++){

        c=0;
        t=i;

        for(j=0;j<5;j++){
            c+=t%10;
            t/=10;
        }

        if(a<=c && c<=b){
            r+=i;
        }

    }

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

    return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(string S, string T) {

    map<char, set<char> > go, back;

    for (int i = 0; i < S.size(); i++) {
        go[S[i]].insert(T[i]);
        back[T[i]].insert(S[i]);
    }

    for (auto s : {go, back}) {
        for (auto i : s) {
            if (i.second.size() > 1) {
                cout << "No" << endl;
                return;
            }
        }
    }
    cout << "Yes" << endl;


}


void main_(istream &cin) {
    string S;
    string T;
    cin >> S;
    cin >> T;
    solve(S, T);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





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

int main(){
	int N,M,max=0;
	cin>>N;
	vector<string> s(N);
	map<string,int> name;
	for(int i=0;i<N;i++){
		cin>>s[i];
		name[s[i]]++;
	}
	cin>>M;
	vector<string>t(M);
	for(int i=0;i<M;i++){
		cin>>t[i];
		name[t[i]]--;
	}
	for(int i=0;i<N;i++){
		if(name[s[i]]>max)max=name[s[i]];
	}
	cout<<endl;
	cout<<max<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string code;
	cin >> code;
	for (int i = 0; i < code.size(); ++i) {
		cout << (char)(code[i] <= 'C' ? code[i] + 23 : code[i] - 3);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n,k;
    double ans=0.0;
    cin>>n>>k;
    ll a[n],pre[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
      pre[i]=0;
    }
    pre[0]=a[0];
    ll index=k-1;
    for(int i=1;i<n;i++)
    {
      pre[i]=pre[i-1]+a[i];
    }
    ll sum=pre[k-1];
    for(int i=k;i<n;i++)
    {
      if(sum<pre[i]-pre[i-k])
      {
        index=i;
        sum=pre[i]-pre[i-k];
      }
    }
    //for(auto t:pre)cerr<<t<<" ";
      //cerr<<endl;

    for(int i=index;i>=index-k+1;i--)
    {
      ll temp=(a[i]*(a[i]+1))/(2);
      double d=(temp/double(a[i]));
      ans+=d;

    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int n,m,a[5001],b[5001],maxn;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<m;i++){
		int G=i;
		for(int j=0;j<n;j++){
			if(G<m && b[G]==a[j])G++;
		}
		maxn=max(maxn,G-i);
	}
	cout<<maxn<<endl;
	return 0;
}

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

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

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


Measured memory_bytes: 256
N = int(input())
D = []
tempD = []

for i in range(N):
    D.append(int(input()))

for i in range(N):
    tempD.append(D[i])

for i in range(len(D)):
    while tempD.count(D[i]) >= 2:
        tempD.remove(D[i])

print(len(tempD))


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
using namespace std;
int p[30][100050];//0文字はカウンタ。1を引くと現在の文字数
int max_p[30];//各文字の末尾の位置。
int main(){
    for(int i=0;i<30;i++){
        p[i][0]=1;
        max_p[i]=(-1);
        for(int j=1;j<100050;j++){
            p[i][j]=999999;
        }
    }
    string s,t;
    cin>>s>>t;
    long long n_s,n_t;
    n_s=(long long)s.length();
    n_t=(long long)t.length();
    long long num;
    for(int i=0;i<n_s;i++){
        num=s[i]-'a';
        p[num][p[num][0]]=i;
        max_p[num]=i;
        p[num][0]++;
    }
    long long count=0;
    int cor=-1;
    int buf;
    long long ans;
    int k=1;
    for(int i=0;i<n_t;i++){
        num=t[i]-'a';
        buf=1;
        if(max_p[num]==-1){
            k=0;
         goto FINE;   
        }
        else if(cor>=max_p[num]){
            count++;
            cor=p[num][buf];
        }
        else{
            while(cor>=p[num][buf])buf++;
            cor=p[num][buf];
        }
    }
    ans=count*n_s+cor+1;
    FINE:
    if(k==0){
        cout<<"-1"<<endl;
    }
    else{
    cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 12288
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int a,b;

int main(){
while(cin>>a>>b){
if(a+b>6250000||a+b<0)cout<<a+b<<endl;
else{
stack<int> S;
rep(i,a+b)S.push(0);
cout<<S.sz<<endl;
}
}
}

Measured memory_bytes: 0
s = gets.chomp.split("").map(&:to_i)

min = s.size
s.each_cons(2).with_index(1) do |(s1, s2), i|
  unless s1 == s2
    min = [i, s.size - i].max if min > [i, s.size - i].max
  end
end
puts min

Measured memory_bytes: 12284
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int fib[44];
  int n;
  cin >> n;
  rep(i, n+1) {
    if(i == 0 || i == 1) {
      fib[i] = 1;
      continue;
    }
    fib[i] = fib[i-1] + fib[i-2];
  }
  cout << fib[n] << endl;
  return 0;
}


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

int A, B, K;

int main() {
	cin >> A >> B >> K;
	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) {
			if (A % 2 == 1) A--;
			B += A / 2; A /= 2;
		}
		else {
			if (B % 2 == 1) B--;
			A += B / 2; B /= 2;
		}
	}
	cout << A << " " << B << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef unsigned long long ull; 

class AOJ0186{
private:
  int q1,b,c1,c2,q2;
public:

  AOJ0186(int a,int b,int c,int d,int f):q1(a),b(b),c1(c),c2(d),q2(f){}
  ~AOJ0186(){}


  void run(){
    int aizu_meet,meet;

    bool ok = false;
    int preb = b;
    
    for(int i=q2;i>=1;i--){
      aizu_meet = meet = 0,b = preb;
      if(i*c1 > b)continue;
      aizu_meet = i;
      b -= (c1*i);
      meet = b/c2;
      //cout << "i =" << i << endl;
      //cout << aizu_meet << ' ' << meet << ", b = " << b << endl;
      if(aizu_meet+meet < q1)continue;
      if(aizu_meet == 0)continue;
      ok = true;
      cout << aizu_meet << ' ' << meet << endl;
      //cout << "i = " << i << endl;

      break;
    }
 if(!ok)cout << "NA" << endl;


   


  }


};

int main(){
  int q;
  while(true){
    cin >> q;
      if(q == 0)break;
    int B,c,cc,qq;
    cin >> B >> c >> cc >> qq;
    AOJ0186 ans = AOJ0186(q,B,c,cc,qq);
    ans.run();


  }
  return 0;
}

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

int main(){
    int n,m;cin >> n >> m;
    int ans = 0;
    for(int i=sqrt(m);i >= 1;i--){
        if(m%i == 0){
            int tans = 0;
            int tmp = m/i;
            if(tmp >= n){
                tans = i;
            }

            if(i >= n){
                tans = max(tmp,tans);
            }

            if(tans > ans){
                ans  =tans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int r;
int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main(){
	r=read();
	printf("%d\n",3*r*r);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

int n;
ll x[100005];
ll fact[100005];
ll fact_inv[100005];
ll sum[100005];

int main(void){
	scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&x[i]);
	}
	fact[0]=1;
	for(ll i=1;i<=n;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	fact_inv[0]=1;
	for(ll i=1;i<=n;i++){
		fact_inv[i]=fact_inv[i-1]*mod_inverse(i,MOD)%MOD;
	}
	sum[1]=fact[n-1]*mod_inverse(2,MOD)%MOD;
	for(int i=2;i<n-1;i++){
		sum[i]+=sum[i-1];
		ll v1=fact[n-1];
		ll v2=fact_inv[i+1];
		ll v3=fact[i-1];
		v1=v1*v2%MOD;
		sum[i]+=v1*v3%MOD;
		sum[i]%=MOD;
	}
	sum[n-1]=0;
	for(int i=0;i<n-1;i++){
		sum[n-1]+=fact[n-1]*mod_inverse(i+1,MOD)%MOD;
		sum[n-1]%=MOD;
	}
	for(int i=0;i<n;i++){
		ans+=sum[i]*x[i]%MOD;
		//printf("%lld %lld\n",sum[i],x[i]);
	}
	//printf("%lld\n",ans);
	for(int i=0;i<n-1;i++){
		ans+=MOD-fact[n-1]*x[i]%MOD;
		ans%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
    string a;
    char low[26] = {
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
    };
    char up[26] = {
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    };

    int i, j;
        getline(cin, a);
        for(i = 0; i < a.size(); i++){
            for(j = 0; j < 26; j++){
                if(a[i] == low[j]){
                    a[i] = up[j];
                }
                else if(a[i] == up[j]){
                    a[i] = low[j];
                }
            }
        }
    cout << a << endl;
}



Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++){
		if (floor(i * 1.08) == N) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
count = 0
for i in range(n):
    a = list(map(int, input().split()))
    ans = c
    for j in range(m):
        ans += b[j] * a[j]
    if ans > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e9;
static const int MOD=1e9+7;
static const int NMAX=100;
static const int VMAX=1e7;
int n;
ll W,w[NMAX+2],v[NMAX+2];

void solve(){
    ll ans=0;
    map<ll,ll> dp;
    dp[0]=0;
    for(int i=1;i<=n;i++){
        auto tmp=dp;
        for(auto p:tmp){
            auto x=p.first+w[i];
            auto y=p.second+v[i];
            if(x<=W){
                dp[x]=max(dp[x],y);
                ans=max(ans,dp[x]);
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    cin>>n>>W;
    for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
using namespace std;
int main() {
	string a, b;
	int w;
	string ans = "No";
	cin >> a >> b;
	w = stoi(a + b);
	rep(i, 100100) {
		if (i * i == w)ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=200005;


void solve()
{
    int a,b,n;
    cin>>a>>b>>n;
    int ans=0;
    int z=a/b;
    z=z-a*(1/b);
    ans=max(ans,z);
    if(n>=(b-1))
    {
        z=a*(b-1);
        z=z/b;
        ans=max(ans,z);
    }
    z=(a*n)/b;
    z=z-a*(n/b);
    ans=max(ans,z);
    cout<<ans<<endl;
    
    
}

int32_t main()
{
    IOS;
   // FILE *fin = freopen("in.txt","r",stdin);
    //FILE *fout = freopen("out.txt","w",stdout);

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


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    string str;
    cin >> str;

    if(str.back()-'0' == 2 || str.back()-'0' == 4 || str.back()-'0' == 5 || str.back()-'0' == 7 || str.back()-'0' ==  9) cout << "hon" << endl;
    else if(str.back()-'0' == 0 || str.back()-'0' == 1 || str.back()-'0' == 6 || str.back()-'0' == 8) cout << "pon" << endl;
    else cout << "bon" << endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,dp[20][20][2];

string Itoa(LL x)
{
	string ret="";
	while(x>0)
	{
		ret.pb(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}

bool check(LL x)
{
	string t=Itoa(x);
	LL ret=0;
	memset(dp,0,sizeof(dp));
	repn(i,9) dp[0][i][0]=1;
	rep(i,t.size()-1)
	{
		rep(j,10)
		{
			if(dp[i][j][0]==0) continue;
			ret+=dp[i][j][0];
			if(j-1>=0) dp[i+1][j-1][0]+=dp[i][j][0];
			dp[i+1][j][0]+=dp[i][j][0];
			if(j+1<=9) dp[i+1][j+1][0]+=dp[i][j][0];
		}
	}
	memset(dp,0,sizeof(dp));
	repn(i,t[0]-'0'-1) dp[0][i][1]=1;
	dp[0][t[0]-'0'][0]=1;
	rep(i,t.size()-1)
	{
		rep(j,10)
		{
			rep(k,2)
			{
				if(dp[i][j][k]==0) continue;
				if(j-1>=0&& !(k==0&&j-1>t[i+1]-'0')) dp[i+1][j-1][k|(j-1<t[i+1]-'0')]+=dp[i][j][k];
				if(!(k==0&&j>t[i+1]-'0')) dp[i+1][j][k|(j<t[i+1]-'0')]+=dp[i][j][k];
				if(j+1>=0&& !(k==0&&j+1>t[i+1]-'0')) dp[i+1][j+1][k|(j+1<t[i+1]-'0')]+=dp[i][j][k];
			}
		}
	}
	rep(i,10) ret+=dp[t.size()-1][i][1];
	return ret<n;
}

int main()
{
	cin>>n;
	LL lb=1,ub=10000000000,mid;
	while(lb<ub)
	{
		mid=(lb+ub+1)/2;
		if(check(mid)) lb=mid;
		else ub=mid-1;
	}
	cout<<lb<<endl;
	return 0;
}

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

int main(){
    int r,c;
    cin>>r>>c;
    int data[r+1][c+1];
    int sum,allsum=0;
    for(int i=0;i<r;i++){
        sum=0;
        for(int j=0;j<c;j++){
            cin>>data[i][j];
            sum+=data[i][j];
        }
        data[i][c]=sum;
    }
    for(int j=0;j<c;j++){
        sum=0;
        for(int i=0;i<r;i++){
            sum+=data[i][j];
        }
        data[r][j]=sum;
        allsum+=sum;
    }
    data[r][c]=allsum;
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(j==c){
                cout<<data[i][j]<<endl;
            }else{
                cout<<data[i][j]<<" ";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include <algorithm> 
 #include <iostream>
 using namespace std;
 int main(){
 int N;
 cin >> N;
 int S = 0, M = 0;
 for(int i = 0; i < N; ++i){ 
 int p;
 cin >> p;
 S += p;
 M = max(M, p); 
 }
 int ans = S - M / 2;
 cout << ans << endl;
 }


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

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();
            var a = s.Count(x => x == '1');
            var b = s.Count(x => x == '0');

            Console.WriteLine(Math.Min(a, b) * 2);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
N,M,C = gets.chomp.split.map(&:to_i)
b  = gets.chomp.split.map(&:to_i)
a =  N.times.map{gets.chomp.split.map(&:to_i)}
ans = 0

N.times do |i|
  temp = C
  M.times do |j|
    temp += a[i][j] * b[j]
  end
  ans += 1 if temp > 0
end

puts ans

Measured memory_bytes: 1788
#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>;
using Graph = vector<vector<int>>;

// header area

bool isKaibun(string S){
    // cout << "at:" << S << endl;
    int length = (int)S.length();
    rep(i, length/2){
        if(S[i]!=S[length-1-i]) return false; 
    }
    // cout << "is Kaibun" << endl;
    return true;
}

int main(){
    string S; cin >> S;

    int length = (int)S.length();

    bool flag_1 = isKaibun(S.substr(0, length));
    bool flag_2 = isKaibun(S.substr(0, (length-1)/2));
    bool flag_3 = isKaibun(S.substr((length+3)/2-1));
    // bool flag_3 = isKaibun(S.substr((length+3)/2-1, length-(length+3)/2)+1);
    
    if(flag_1 && flag_2 && flag_3){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    ll n; std::cin >> n;
    std::vector<ll> a;
    for(int i=0; i<n; i++){
        ll b; std::cin >> b; a.push_back(b);
    }

    ll ans=0;
    while(a.front()>0){
        for(int i=0; i<n; i++){
            if(a[i]%2){
                std::cout << ans << "\n"; return 0;
            }
            a[i] = a[i]/2;
        }
        ans++;
    }
    return 0;
}


Measured memory_bytes: 256
import warnings
import sys




x = 0
while (x == 0):
	args = map(int, raw_input().split())

	h = args[0]
	w = args[1]

	if (h == 0 and w == 0):
		break

	for i in range(h):
			for j in range(w):
				sys.stdout.write("#")
			print ""
	print ""  

Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 1;i <= (n);i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<tuple<string,int,int>> a;
    rep(i,n){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s,p,i));
    }
    sort(a.begin(),a.end());
    for(int i = 0;i < n; i++){
        cout << get<2>(a[i]) << endl;
    }
}


Measured memory_bytes: 256