akhauriyash/Code-Regression huggingface dataset:
// ＡＢＣの過去問を解くだけだよ

// フォント x:小文字 X:大文字

#include <bits/stdc++.h>

using namespace std;

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

    n = n % 500;

    if (a >= n)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}

// できた


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A + B == 60 && A < C){
        cout << -1 << endl;
        return 0;
    }
    int time = 0;
    while(1){
        int l = time % 60;
        int r = (time + A) % 60;
        /*
        int next = time + C;
        if(next >= l && next <= r){
            cout << next << endl;
            return 0;
        }
        */
        
        if  (l < r && C >= l && C <= r || 
             l > r && ( (C >= l && C <= 60) || (C >= 0 && C <= r)) ){
            cout << time + C - time % 60 << endl;
            //cout << time << endl;
            return 0;
        }
        
        time += A + B;
        if(time > 60 * 60 * 60){
            cout << -1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define scl(x) scanf("%lld",x);
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<int>arr;
map<char,int>cp;
map<ll,ll>mp;
deque<char>stp1;
deque<char>stp2;
map<int,int>pos;
map<string,int>check;
map<string,string>server;
vector<string>ans1;
vector<string>ans2;
vector<string>ans3;
string server1[1009];
string ip1[1009];
string server2[1009];
string ip2[1009];
ll cashier[109];
ll fir[10009];
ll sec[100009];
ll dice[109];
vector<ll>element;
map<ll,ll>skysc;
map<string,ll>iteams;
map<ll,ll>equal1;
map<ll,ll>equalcnt;
ll complete[200009][29];
map<ll,ll>vis_pos;
map<char,ll>haiku;
vector<string>original;
vector<string>sorted;
vector<char>stps;
map<string,ll>mps;
map<string,ll>cnteql;
map<string,ll>eql;
deque<char>tem;
map<string,ll>tot;
map<string,ll>vislr;
vector<ll>arry;
vector<ll>colr;
vector<ll>primes;
vector<ll>primesdiv;
map<ll,ll>summand;
map<ll,ll>vps;
map<ll,ll>cnt;
ll solve[200009][4];
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
  
double calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6.00 * m;  
  
    // Find the difference between two angles  
    double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle= min(360 - angle, angle);  
  
    return angle;  
} 
int main()
{
  ll a=4,b=0,c,d,e,f,g,h=2,i,j,k,l,p,q,r=10,s,t,m,n,sum=0,x;
  double fi,se,last,ho,mi,pi,ans1,ans2;
  pi=acos(-1.00);
  cin>>ho>>mi>>fi>>se;
 last=calcAngle(fi,se);
// cout<<last<<'\n';
  last=(last*pi)/180.00;
  
  ans1=ho*ho+mi*mi-2.00*ho*mi*cos(last);
  ans2=sqrt(ans1);
  printf("%.17lf\n",ans2);
  
  
  
  
   
   
  
     
     	
  	
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

  while( true ) {
    long long int n, input;
    cin >> n;

    if ( n == 0 ) break;

    vector< long long int > s;

    for ( long long int i = 0; i < n; i++ ) {

      cin >> input;
      s.push_back( input );

    }

    sort( s.begin(), s.end() );

    long long int ans = 0;

    for ( long long int i = 1; i < n - 1; i++ ) {

      ans += s[i];

    }

    cout << ans / ( n - 2 ) << endl;

  }

  return 0;

}

Measured memory_bytes: 1216
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

constexpr int MOD = int(1e9) + 7;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    i64 H, W;
    read(H, W);

    vector<i64> R(H), C(W);
    rep(i, H) read(R[i]);
    rep(i, W) read(C[i]);

    sort(all(R), greater<>());
    sort(all(C), greater<>());
    R.push_back(-INF);
    C.push_back(-INF);

    i64 boundR = 0;
    i64 boundC = 0;
    i64 ans = 1;
    repr(n, H * W, 1) {
        if (R[boundR] > n || C[boundC] > n) {
            ans = 0;
            break;
        }

        i64 candidateCnt;
        if (R[boundR] == n && C[boundC] == n) {
            ++boundR;
            ++boundC;
            candidateCnt = 1;
        } else if (R[boundR] == n) {
            ++boundR;
            candidateCnt = boundC;
        } else if (C[boundC] == n) {
            ++boundC;
            candidateCnt = boundR;
        } else {
            candidateCnt = (boundR * boundC) - (H * W - n);
        }

        ans *= candidateCnt;
        ans %= MOD;
    }

    print(ans);

    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  
  int c = 0;
  for (int i = 0; i < 3; i++) {
    if(s.at(i) == t.at(i)) c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, m; string s;
multiset<pair<int, int>> opcije;
long long best[100005], from[100005];
vector<int> ans;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m; cin >> s;
opcije.insert(make_pair(0, 0)); 
for (int i=1; i<=n; i++){
	if (opcije.empty()){
		cout << "-1"; 
		return 0;
	}
	if (s[i]=='0'){
		pair<int, int> x = *(opcije.begin());
		best[i]=x.first + 1;
		from[i]=x.second;
		opcije.insert(make_pair(best[i], i));
	}
	if (i >= m){
	//	cout << "am? "  << i << endl;
		if (s[i-m]=='1') continue;
		opcije.erase(opcije.find(make_pair(best[i-m], i-m)));
	}
}
for (int i=n; i!=0; ){
	int x = i; i=from[i];
	ans.push_back(x-i);
}
for (int i=ans.size()-1; i>=0; i--) cout << ans[i] << " ";
return 0;
}

Measured memory_bytes: 4480
def solution(edges):
    num_of_neighbor = {}
    for e in edges:
        if e[0] in num_of_neighbor:
            num_of_neighbor[e[0]] += 1
        else:
            num_of_neighbor[e[0]] = 1
        if e[1] in num_of_neighbor:
            num_of_neighbor[e[1]] += 1
        else:
            num_of_neighbor[e[1]] = 1
    n_2 = 0
    n_1 = 0
    for n in num_of_neighbor:
        if num_of_neighbor[n] == 2:
            n_2 += 1
        elif num_of_neighbor[n] == 1:
            n_1 += 1

    if n_2 == 2 and n_1 == 2:
        return 'YES'
    else:
        return 'NO'

e1 = [int(s) for s in input().split(' ')]
e2 = [int(s) for s in input().split(' ')]
e3 = [int(s) for s in input().split(' ')]
edges = [e1, e2, e3]
print(solution(edges))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int sum[2][200010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    int A[200010];
    int B[200010];
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    int ans = 0;
    rep(i, N) sum[0][i + 1] += sum[0][i] + A[i];
    rep(i, M) sum[1][i + 1] += sum[1][i] + B[i];
    rep(i, N + 1) {
        int remain = K - sum[0][i];
        if(remain < 0) break;
        int ok = 0;
        int ng = M + 1;
        while(abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if(remain >= sum[1][mid]) ok = mid;
            else ng = mid;
        } 
        ans = max(ans, i + ok);
        
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 9912
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int N = scanner.nextInt();
			long ans = 0;
			Map<String, Long> map = new HashMap<String, Long>();
			for (int i = 0; i < N; i++) {
				char[] array = scanner.next().toCharArray();
				Arrays.sort(array);
				String tmp = new String(array);
				if (map.containsKey(tmp)) {
					ans = ans + map.get(tmp);
					map.put(tmp, map.get(tmp) + 1);
				} else {
					map.put(tmp, (long) 1);
				}
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 51092
//ABC100A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(a <= 8 && b <= 8){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner scan = new Scanner(System.in);
	void run() {
		int n = scan.nextInt();
		int[] S = new int[13];
		int[] H = new int[13];
		int[] C = new int[13];
		int[] D = new int[13];

		for(int i = 0; i < n; i++) {
			String t = scan.next();
			if("S".equals(t)) {
				int j = scan.nextInt();
				S[j-1]++;
			} else if("H".equals(t)) {
				int j = scan.nextInt();
				H[j-1]++;
			} else if("C".equals(t)) {
				int j = scan.nextInt();
				C[j-1]++;
			} else if("D".equals(t)) {
				int j = scan.nextInt();
				D[j-1]++;
			}
		}

		for (int i = 0; i < 13; i++) {
			if(S[i] == 0) {
				System.out.println("S " + (i+1));
			}
		}
		for (int i = 0; i < 13; i++) {
			if(H[i] == 0) {
				System.out.println("H " + (i+1));
			}
		}
		for (int i = 0; i < 13; i++) {
			if(C[i] == 0) {
				System.out.println("C " + (i+1));
			}
		}
		for (int i = 0; i < 13; i++) {
			if(D[i] == 0) {
				System.out.println("D " + (i+1));
			}
		}
	}

	public static void main(String[] args){
		//TODO Auto-generated mathod stub
		new Main().run();
	}
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<P> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main() {
    ll N,ans = 0;
    cin >> N;
    ll T;
    cin >> ans; 
    rep(i,N-1){
        cin >> T;
        ans = lcm(ans,T);
    }

    cout << ans;
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    H = i2nn()
    n = 1
    h = H[0]
    for i in range(1, N):
        if H[i] >= h:
            h = H[i]
            n += 1
    print(n)

main()


Measured memory_bytes: 38384
using System;
using System.Linq;
class A
{
    static void Main()
    {
        string N = Console.ReadLine();
        string s = Console.ReadLine();
        int R = 0;
        int B = 0;
        for (int i = 0; i < int.Parse(N); i++)
        {
            if (s.Substring(i, 1) == "R") R++ ;
            else B++;
        }
        if (R > B) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
import math
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]


def enough(T):
    temp = 0
    ch = H[:]
    for h in ch:
        left = h - B*T
        if left > 0:
            temp += (left + A-B-1)//(A-B)
            #temp += math.ceil(left/(A-B))
            #print(temp)

    if temp > T:
        return False
    else:
        return True

#print(enough(2))
ok = 10**15
ng = 0

while ok - ng > 1:
    mid = (ok + ng)//2
    if enough(mid):
        ok = mid
    else:
        ng = mid
    #print(ok,ng)
print(ok)

Measured memory_bytes: 76504
<?php
  fscanf(STDIN, "%d", $n);
  $a = [];
  $max = -1;
  $second_max = -1;
  for ($i=0; $i<$n; $i++) {
    fscanf(STDIN, "%d", $a_);
    $a[] = $a_;
    
    # マックス値と次に大きな値を保存しておく
    if ($a_ > $max) {
      $second_max = $max;
      $max = $a_;
    } else if ($a_ > $second_max) {
      $second_max = $a_;
    }
  }

  # マックス値と同じなら次に大きな値を出力 
  # そうでないならマックス値
  for ($i=0; $i<$n; $i++) {
    if ($a[$i] == $max) echo $second_max . "\n";
    else echo $max . "\n";
  }
?>

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

int main()
{
	int D;
	cin >> D;
	if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	if (D == 25) {
		cout << "Christmas" << endl;
	}
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL BS(LL x , LL y , LL p){
	if(y-x<2) return x;
	LL z = (x+y)/2;
	return (z/2) * ((z+1)/2) < p ? BS(z,y,p) : BS(x,z,p);
}

int main(){
	int Q; cin >> Q;
	repp(rep_t,0,Q){
		LL A,B; cin >> A >> B;
		if(A > B) swap(A,B);
		cout << (A == B ? 2*(A-1) : BS(A+1,A+B+1,A*B)-2) << endl;
	}
	return 0;
}


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

int main(){
	string s;
	int n;
	while (1) {
		s = "";
		cin >> n;
		if (n == -1) break;
		for (int i = 0; n;i++) {
			char c = '0' + (n % 4);
			s = c + s;
			n /= 4;
		}
		if (s.empty()) s = "0";
		cout << s << endl;
	}
	return 0;
}

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

const int INF=1001001001;
const int di[]={0,1,0,-1};
const int dj[]={1,0,-1,0};


int main(){
  int h,w;	cin >> h >> w;
  vector<string>	s(h);
  rep(i,h)	cin >> s[i];
  int ans=0;
  
  rep(si,h)rep(sj,w){
    if(s[si][sj]=='#')	continue;
    vector<vector<int>>	dist(h,vector<int>(w,INF));
    queue<P>	q;
    auto update=[&](int i,int j,int x){
      if(dist[i][j]!=INF)	return;
      dist[i][j]=x;
      q.push(P(i,j));
    };
    update(si,sj,0);
    while(!q.empty()){
      int i=q.front().first;
      int j=q.front().second;	q.pop();
      rep(dir,4){
        int ni=i+di[dir],nj=j+dj[dir];
        if(ni<0||ni>=h||nj<0||nj>=w)	continue;
        if(s[ni][nj]=='#')	continue;
        update(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w){
      if(dist[i][j]==INF)	continue;
      ans=max(ans,dist[i][j]);
    }
  }
  cout << ans;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main(){
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a<=b){
		printf("1\n");
		return 0;
	}
	if(b<=c){
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",(long long)(2*((a-b)/(b-c)+(bool)((a-b)%(b-c)))+1));
	return 0;
	
}

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

#define rep(i, x, y) for(int i = (x), _ = (y); i <= _; ++ i)
#define per(i, x, y) for(int i = (x), _ = (y); i >= _; -- i)
#define dprintf(...) fprintf(stderr, __VA_ARGS__)
#define disp(x) cout << #x << " = " << x << "; "

typedef long long LL;

template <class T> bool chkmin(T& a, T b) { return a > b ? a = b, true : false; }
template <class T> bool chkmax(T& a, T b) { return a < b ? a = b, true : false; }

template <class T> void read(T& a) {
	char c = getchar(); 
	T f = 1; 
	a = 0;
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) a = a * 10 + c - '0';
	a *= f;
}
/*}}}*/

const int maxN = 2e5 + 5;

int outp[maxN];
int a[maxN];
int l, r;
int N;

int main()
{
	read(N);
	read(outp[l = r = 100000]);
	rep(i, 2, N)
	{
		int x;
		read(x);
		if(((N - i) & 1) == 0)
			outp[--l] = x;
		else
			outp[++r] = x;
	}
	rep(i, l, r)
		printf("%d ", outp[i]); puts("");

	return 0;
}


Measured memory_bytes: 2944
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;



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

	cin >> N;
	while (1) {
		M++;
		if (pow(2, M) - 1 > N) {
			M--;
			break;
		}
	}
	vector<int>ans(M * 2);
	for (int i = 0; i < M; i++) {
		ans[i] = i + 1;
		ans[i + M] = i + 1;
	}
	N -= pow(2, M) - 1;
	while (N) {
		K = 0;
		while (1) {
			K++;
			if (pow(2, K)  > N) {
				K--;
				break;
			}
		}
		ans.push_back(M + 1);
		ans.insert(ans.begin() + K, M + 1);
		N -= pow(2, K) ;
		M++;
	}
	cout << ans.size() << endl;
	for (auto i : ans) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}

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


void solve(std::string S, std::string T, long long A, long long B, std::string U){
    if(U==S)A--;else B--;
    cout<<A<<" "<<B<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    std::string U;
    std::cin >> U;
    solve(S, T, A, B, U);
    return 0;
}


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

typedef pair<int,int> P;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define F first
#define S second

const int M = 1024;
const int INF = 114514810;
int h,w,n;
char f[M][M];
int d[M][M];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
vector<P> cheese(12);

void init() {
    rep(y,M) rep(x,M) f[y][x] = '$';
    cheese.clear();
}

bool ng(int x, int y) {
    return (x<0 or w<=x or y<0 or h<=y);
}

int bfs(P s, P g) {
    int gx=g.F, gy=g.S;
    queue<P> Q;
    rep(y,M) rep(x,M) d[y][x] = INF;
    Q.push(s);
    d[s.S][s.F] = 0;

    while(Q.size()) {
        P p = Q.front(); Q.pop();
        if(p.F==gx and p.S==gy) break;

        rep(i,4) {
            int nx = p.F + dx[i], ny = p.S + dy[i];
            if(ng(nx,ny) or f[ny][nx]=='X' or d[ny][nx]<INF) continue;
            d[ny][nx] = d[p.S][p.F] + 1;
            Q.push(P(nx,ny));
        }
    }

    return d[gy][gx];
}

int main() {
    while(cin>>h>>w>>n) {
        init();
        rep(y,h) rep(x,w) {
            cin >> f[y][x];
            char c = f[y][x];
            if(c!='.' and c!='S' and c!='X') cheese[c-'0'] = make_pair(x,y);
            if(c == 'S') cheese[0] = make_pair(x,y);
        }

        int ans = 0;
        rep(i,n) ans += bfs(cheese[i], cheese[i+1]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    int dp[n+1]={};
    for(int i=2;i<=n;i++){
      int x,y;
      x=y=INT_MAX;
      x=dp[i-1]+abs(a[i-1]-a[i]);
      if(i-2>0) y=dp[i-2]+abs(a[i-2]-a[i]);
      dp[i]=min(x,y);
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<map>

int64_t const MOD = 1e9+7;

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};
typedef mod_int<MOD> mint;

int main() {
  int N; std::cin >> N;
  std::map<std::pair<int,int>,mint> s;
  int x = 0, y = 0, z = 0;
  mint ans(1);
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    std::map<std::pair<int,int>,mint> n;
    int c = 0;
    if(A == x) ++c;
    if(A == y) ++c;
    if(A == z) ++c;
    ans *= mint(c);
    if(A == x) ++x;
    else if(A == y) ++y;
    else ++z;
    if(x > y) std::swap(x, y);
    if(x > z) std::swap(x, z);
    if(y > z) std::swap(y, z);
  }
  std::cout << ans.v_ << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

//約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    ll n;
    cin >> n;

    vector<int> a(n+1);
    rep(i, n)cin >> a[i+1];

    vector<bool> inBall(n+1);
    vector<ll> ans;
    for(ll i = n; i > 0; --i){
        if(inBall[i] == a[i])continue;

        ans.push_back(i);
    
       vector<ll> divs = enum_divisors(i);
       rep(j, divs.size()){
           inBall[divs[j]] = !inBall[divs[j]];
       }
    }

    cout << ans.size() << endl;
    rep(j, ans.size())cout << ans[ans.size()-j-1] << " ";
}

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

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

    int output = 0;
    output += M * (M - 1) / 2;
    output += N * (N - 1) / 2;

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    int count = 0;
    rep(i, n) cin >> p[i];

    rep(i, n-1){
        if(i==0) continue;
        if((p[i]<p[i+1] and p[i-1] < p[i]) or (p[i]<p[i-1] and p[i+1]<p[i])){
            count++;
        }
    }
    cout << count << endl;
    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 a,b,tmp;
		for(;;){
		a = scan.nextInt();
		b = scan.nextInt();
		if(a >= b){
			tmp = a;
			a = b;
			b = tmp;
		}
		
		if (a == 0 && b == 0)
			break;
		System.out.println(a+" "+b);
		}
		
		}
	
}

Measured memory_bytes: 36060
X, K, D = map(int, input().split())
T = abs(X) // D
if T > K:
    print(abs(abs(X) - K*D))
else:
    if (K - T) % 2 == 0:
        print(abs(abs(X) - T*D))
    else:
        print(abs(abs(X) - (T+1)*D))

Measured memory_bytes: 61836
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

map<int,vector<int>> edges;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,a,b,k,ans=0,flag;
    cin>>n>>m;
    int h[n+1];
    for (int i=1;i<=n;++i)
        cin>>h[i];
    while (m--)
    {
        cin>>a>>b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    for (int i=1;i<=n;++i)
    {
        k=sz(edges[i]);
        if (k)
        {
            flag=1;
            for (int j=0;j<k;++j)
                if (h[edges[i][j]]>=h[i])
                    flag=0;
            if (flag)
                ++ans;
        }
        else
            ++ans;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 14564
#include<cstdio>
#include<cstring>
char s[100005];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i+2<len;i++)
		if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i])
		{
			printf("%d %d",i+1,i+3);
			return 0;
		}
	printf("%s",len==2&&s[0]==s[1]?"1 2":"-1 -1");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, a_rem, b_rem;
	int ans;

	cin >> a >> b;

	a_rem = a % 2;
	b_rem = b % 2;


	if ((a == 0) && (b_rem == 0)) {
		ans = b / 2;
		cout << ans << endl;
	}
	else if ((a_rem == 0) && (b == 0)) {
		ans = a / 2;
		cout << ans << endl;
	}
	else if ((a == 0) || (b == 0)) {
		cout << "IMPOSSIBLE" << endl;
	}
	else if (a_rem == b_rem) {
		ans = (a + b) / 2;
		cout << abs(ans) << endl;
	}
	else if ((a_rem != 0) || (b_rem != 0)) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		ans = (a - b) / 2;
		cout << abs(ans) << endl;
	}
}

Measured memory_bytes: 256
n,m=map(int,input().split())
left=[]
right=[]
for i in range(m):
    l,r=map(int,input().split())
    left.append(l)
    right.append(r)

if max(left)>min(right):
    print(0)
else:
    print(min(right)-max(left)+1)

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

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<pair<int,int>>

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

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

    int n;
    string cur;
    char prev = '0';
    set<string> s;

    cin >> n;
    while (n--) {
        cin >> cur;
        if ((cur[0] == prev || prev == '0') && s.find(cur) == s.end()) {
            s.insert(cur);
            prev = cur[cur.length()-1];
        } else {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

vector <int> a;
vector <vector <long long>> dp;

long long solve(int l, int r, bool maximize = true) {
    if (l > r)
        return 0;
    if (dp[l][r] != -1)
        return dp[l][r];
    if (maximize)
        return dp[l][r] = max(solve(l + 1, r, !maximize) + a[l], solve(l, r - 1, !maximize) + a[r]);
    else
        return dp[l][r] = min(solve(l + 1, r, !maximize) - a[l], solve(l, r - 1, !maximize) - a[r]);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    a.resize(n);
    cin >> a;
    dp.resize(n, vector <long long> (n, -1));
    cout << solve(0, n - 1);
    return 0;
}

Measured memory_bytes: 70912
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
   
 
   cin >> n;
   int a[n];
  
  
for(int i = 0;i<n;i++){
     
  cin >> a[i];
  
}
  
   sort(a, a + n, greater<int>()); 
  
  int sum = 0;
  
for(int i = 1;i<n;i++){
     
  //cin >> a[n];
  
   // cout << a[i] << endl;
  
  sum = sum + a[i];
}
  
  if(a[0]<sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

static const int MAX = 50;
const int INF = 1e+5;
int mat[MAX][MAX];
int h, w;

void check(int i, int j){
    if(i < 0 || h <= i) return;
    if(j < 0 || w <= j) return;
    mat[i][j]++;
}

int main(){
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char ch;
            cin >> ch;
            if(ch == '#'){
                check(i+1, j);
                check(i, j+1);
                check(i-1, j);
                check(i, j-1);
                check(i+1, j+1);
                check(i+1, j-1);
                check(i-1, j+1);
                check(i-1, j-1);
                mat[i][j] = INF + 8;
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] >= INF){
                cout << '#';
            } else {
                cout << (char)(mat[i][j] + '0');
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int N,An;
cin>>N;
int A[N];
for (int i = 0; i < N; i++) {
  cin>>A[i];
}
sort(A,A+N);

An=A[N-1]-A[0];

if(An<0){An=An*-1;
}else{}


cout<<An<<endl;









}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
/*
int checker(int n,vector<int> l){
    ll cnt=0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                int a=l[i],b=l[j],c=l[k];
                if(a<b+c && b<c+a && c<a+b){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}
*/

int main(){
    int n;cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end());
    //for(auto t : l) cout << t << " ";
    //cout << endl;
    ll ans = 0;
    for(int i=n-1;i>=0;i--){
        for(int j=i-1;j>=0;j--){
            int left_idx = distance(l.begin(),upper_bound(l.begin(),l.end(),l[i]-l[j]));
            //int right_idx = distance(l.begin(),lower_bound(l.begin(),l.end(),l[i]+l[j]));
            int right_idx = j - 1;
            ans += max(right_idx - left_idx + 1,0);
            //cout << "i:" << i << " j:" << j << "  left_idx=" << left_idx << " and right_idx=" << right_idx << " = " << right_idx - left_idx + 1 << "  answer is " << ans << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
  int i, result = 0;
  char s[200005], t[200005];
  
  scanf("%s", s);
  scanf("%s", t);

  for( i = 0; s[i] != '\0'; i++ ){
      if( s[i] != t[i] ){
        result++;
      }
  }
  
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 2116
a[3][1<<18],b[2],x,y,N[2][1<<18],i,j;main(n){scanf("%d",&n);for(;i<3;++i)for(j=0;j<n;++j){scanf("%d",&a[i][j]);--a[i][j];}for(j=0;j<n;++j){if(a[0][j]/3-a[1][j]/3||a[1][j]/3-a[2][j]/3||a[2][j]/3-a[0][j]/3||a[1][j]%3-1||a[1][j]/3-j&1){b[0]=1;break;}x=a[1][j]/3+1;while(x){b[j&1]-=N[j&1][x]%2;x-=x&-x;}b[j&1]+=j/2;y=a[2][j]/3+1;while(y<1<<18){++N[j&1][y];y+=y&-y;}if(a[0][j]%3)++b[1-j%2];}puts(b[0]&1|b[1]&1?"No":"Yes");}

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main (){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int>num(210000);
  for(int i=0; i<N;i++){
    cin >> A[i];
    num[A[i]]++;
  }
  sort(num.begin(),num.end());
  int cou=0;
  for(int i=0; i<num.size()-K;i++){
    cou+=num[i];
  }
  cout << cou << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
/*
6
ooxoox
SSSWWS
*/
int provjeri(string a,string b){
	for(int i=0;i<a.length();i++){
		if((a[i]=='o'&&b[i]=='S')||(a[i]=='x'&&b[i]=='W')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			int y=i+1;
			if(y==a.length()) y=0;
			if(b[x]!=b[y]) return 0;
		}
		else if((a[i]=='o'&&b[i]=='W')||(a[i]=='x'&&b[i]=='S')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			int y=i+1;
			if(y==a.length()) y=0;
			if(b[x]==b[y]) return 0;
		}
	}
	return 1;
}
int main(){
	int n;
	cin>>n;
	string a,b,c,d,e;
	cin>>a;
	for(int i=0;i<a.length();i++) b.push_back('#');
	b[0]='S';
	b[a.length()-1]='S';
	for(int i=0;i<a.length()-1;i++){
		if((a[i]=='o'&&b[i]=='S')||(a[i]=='x'&&b[i]=='W')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			b[i+1]=b[x];
		}
		else if((a[i]=='o'&&b[i]=='W')||(a[i]=='x'&&b[i]=='S')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			if(b[x]=='S') b[i+1]='W';
			else b[i+1]='S';
		}
	}
	for(int i=0;i<a.length();i++) c.push_back('#');
	c[0]='S';
	c[a.length()-1]='W';
	for(int i=0;i<a.length()-1;i++){
		if((a[i]=='o'&&c[i]=='S')||(a[i]=='x'&&c[i]=='W')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			c[i+1]=c[x];
		}
		else if((a[i]=='o'&&c[i]=='W')||(a[i]=='x'&&c[i]=='S')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			if(c[x]=='S') c[i+1]='W';
			else c[i+1]='S';
		}
	}
	
	for(int i=0;i<a.length();i++) d.push_back('#');
	d[0]='W';
	d[a.length()-1]='S';
	for(int i=0;i<a.length()-1;i++){
		if((a[i]=='o'&&d[i]=='S')||(a[i]=='x'&&d[i]=='W')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			d[i+1]=d[x];
		}
		else if((a[i]=='o'&&d[i]=='W')||(a[i]=='x'&&d[i]=='S')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			if(d[x]=='S') d[i+1]='W';
			else d[i+1]='S';
		}
	}
	
	for(int i=0;i<a.length();i++) e.push_back('#');
	e[0]='W';
	e[a.length()-1]='W';
	for(int i=0;i<a.length()-1;i++){
		if((a[i]=='o'&&e[i]=='S')||(a[i]=='x'&&e[i]=='W')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			e[i+1]=e[x];
		}
		else if((a[i]=='o'&&e[i]=='W')||(a[i]=='x'&&e[i]=='S')){
			int x=i-1;
			if(x==-1) x=a.length()-1;
			if(e[x]=='S') e[i+1]='W';
			else e[i+1]='S';
		}
	}
	if(provjeri(a,b)){
		cout<<b;
	}
	else if(provjeri(a,c)){
		cout<<c;
	}
	else if(provjeri(a,d)){
		cout<<d;
	}
	else if(provjeri(a,e)){
		cout<<e;
	}
	else{
		cout<<-1;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
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<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a<b)
	printf("a < b\n");
	else if(a>b)
	printf("a > b\n");
	else
	printf("a == b\n");
	return 0;
}


Measured memory_bytes: 2056
#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>;

int main(){
	int we, he, n;
	cin >> we >> he >> n;
	int w0 = 0;
	int h0 = 0;
	rep(i, n){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){
			if(w0 < x) w0 = x;
		}else if(a == 2){
			if(we > x) we = x;
		}else if(a == 3){
			if(h0 < y) h0 = y;
		}else if(a == 4){
			if(he > y) he = y;
		}
	}
	int a = we-w0;
	int b = he-h0;
	if(a < 0) a = 0;
	if(b < 0) b = 0;
	cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

i = 0

yen = 1000
while i < N:
    while i < N - 1 and A[i] >= A[i + 1]:
        i += 1

    if i == N - 1:
        break

    x = i
    while i < N - 1 and A[i] <= A[i + 1]:
        i += 1

    y = i

    cnt = yen // A[x]
    yen = yen - A[x] * cnt + A[y] * cnt

print(yen)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;//ベルマンとかはllにしよ
//ここ十分にしないとだめ
#define INF 1000000000000

struct Node{
  //ノードの情報
  vector<pair<ll,ll>> edge;//各エッジの接続先のノード番号とコスト
  //ベルマンフォード法用のデータ
  ll mincost=INF;//そのノードへの最小コスト
};

//関係ないループを外す
bool bellmanford(vector<Node>& nodes,ll l1){
  bool f=false;
  for(ll i=0;i<l1;i++){
    f=false;
    for(ll j=0;j<l1;j++){
      Node x=nodes[j];
      if(x.mincost!=INF){
        ll l2=x.edge.size();
        for(ll k=0;k<l2;k++){
          ll a=x.mincost+x.edge[k].second;
          if(nodes[x.edge[k].first].mincost>a){
            nodes[x.edge[k].first].mincost=a;
            if(x.edge[k].first==l1-1)f=true;
          }
        }
      }
    }
  }
  return f;//負の閉路があればtrue
}

int main(){
  ll n,m;cin >> n >> m;
  vector<Node> Nodes(n);
  //mincost0の更新だけしっかりやる
  Nodes[0].mincost=0;//cout << 0;

  for(ll i=0;i<m;i++){
    ll a,b,c;cin >> a >> b >> c;
    Nodes[a-1].edge.push_back(make_pair(b-1,-c));
  }
  //Nodesを更新
  if(bellmanford(Nodes,n)){
    cout << "inf" << endl;
  }else{
    cout << -Nodes[n-1].mincost << endl;
  }

}


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

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

using namespace std;

int main(){
	int n; cin>>n;
	int mn=1000,mx=0;
	rep(i,n){
		int a; cin>>a;
		mn=min(mn,a);
		mx=max(mx,a);
	}
	cout<<mx-mn<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>

using  namespace std;

//拡張ユークリッドの互除法
//ax + by = cとなるようなc=gcd(a,b)をxをペアにして返す
//firstがx,secondがc
template <typename number>
pair<number, number> extended_euclid(number a, number b)
{
    number r0, r1, a0, a1, b0, b1;
    r0 = a; r1 = b;
    a0 = 1; a1 = 0;
    b0 = 0; b1 = 1;
    while (r1>0) {
        number q1 = r0 / r1;
        number r2 = r0 % r1;
        number a2 = a0 - q1 * a1;
        number b2 = b0 - q1 * b1;
        r0 = r1 ; r1 = r2;
        a0 = a1 ; a1 = a2;
        b0 = b1 ; b1 = b2;
    }
    number c = r0;
    a = a0; //x
    b = b0; //y
    return  {a, c};
}

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> city(n);
    for (int i = 0; i < n; ++i) {
        cin >> city[i];
    }
    for (int i = 0; i < n; ++i) {
        city[i] = abs(x - city[i]);
    }
    if(n < 2)
    {
        cout << city[0] << endl;
    }else {
        pair<int, int> temp = extended_euclid(city[0], city[1]);
        for (int i = 3; i < n; ++i) {
            temp = extended_euclid(city[i], temp.second);
        }
        cout << temp.second << endl;
    }
    return 0;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
x = [int(x) for x in input().split()]

x.sort()

dis = []

if n >= m:
    print("0")
    exit(0)

for i in range(m-1):
    dis.append(x[i+1]-x[i])

dis.sort(reverse=True)

print(sum(dis[n-1:]))



Measured memory_bytes: 13832
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n ,m;
    cin >> n >> m;
    int wa[100501];
    bool ac[100400];
    int acnum=0;
    int wanum=0;
    for(int i=0;i<n;i++){
        wa[i]=0;
        ac[i]=false;
    }
    while(m--){
        int p;
        string s;
        cin >> p >> s;
        if(ac[p]==true)continue;
        if(s=="AC"){
            ac[p]=true;
            acnum++;
            wanum+=wa[p];
        }
        else{
            wa[p]++;
        }
    }
    cout << acnum << " " << wanum;
    return 0;

}

Measured memory_bytes: 768
#include <cstdio>
using namespace std;
const int maxn=100005;
struct node{
    int num;
    bool redable;
}box[maxn];
void initialize_box(){
    box[1].num=1;
    box[1].redable=true;
    for(int i=2;i<=maxn;i++){
        box[i].num=1;
        box[i].redable=false;
    }
}
int main()
{
    initialize_box();
    int n,m,x,y;
    scanf("%d %d",&n,&m);
    while(m--){
        scanf("%d %d",&x,&y);
        box[x].num--;
        box[y].num++;
        if(box[x].redable)box[y].redable=true;
        if(box[x].num==0)box[x].redable=false;
    }
    int cnt=0;
    for(int i=1;i<=n;i++)if(box[i].redable)cnt++;
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int num,ans,cou;
	cou=0;
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	num = min(s.length(), t.length());
	for (int i = 0; i < num; i++) {
		if (s[i] < t[i]) {
			ans = 1;
			break;
		}
		else if (s[i] > t[i]) {
			ans = 0;
			break;
		}
		else if (s[i] == t[i]) {
			cou++;
		}
		if (cou == num && s.length() > t.length())ans = 0;
		else if (cou == num && t.length() > s.length())ans = 1;
	}
	if (ans == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
r,c = map(int, input().split())
l=[]
for i in range(r):
    l.append(list(map(int, input().split())))
    l[i].append(sum(l[i]))
l.append(list([0 for _ in range(c+1)]))
for i in range(c+1):
    for j in range(r):
      l[r][i]+=l[j][i]
for i in range(r+1):
  for j in range(c+1):
    if j != c:
      print("{} ".format(l[i][j]), end='')
    else:
      print("{}".format(l[i][j]))


Measured memory_bytes: 6236
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

typedef string::const_iterator State;
class ParseError {};

int expression(State &begin);// 四則演算の式をパースして、その評価結果を返す。
int term(State &begin);// 乗算除算の式をパースして、その評価結果を返す。
int factor(State &begin);// 括弧か数をパースして、その評価結果を返す。
int number(State &begin);//数字の列をパースして、その数を返す



//数字の列をパースして、その数を返す
int number(State &begin){
	int ret =0;
	while(isdigit(*begin)){
		ret *=10;
		ret += *begin-'0';
		begin++;
	}
	return ret;
}


// 乗算除算の式をパースして、その評価結果を返す。
int term(State &begin) {
	int ret =factor(begin);

	for(;;){
		if(*begin=='*'){
			begin++;
			ret *=factor(begin);
		}else if(*begin =='/'){
			begin++;
			ret /=factor(begin);
		}else{
			break;
		}
	}
	return ret;
}
// 四則演算の式をパースして、その評価結果を返す。
int expression(State &begin) {
	int ret =term(begin);

	for(;;){
		if(*begin=='+'){
			begin++;
			ret +=term(begin);
		}else if(*begin=='-'){
			begin++;
			ret -=term(begin);
		}else{
			break;
		}
	}
	return ret;
}
// 括弧か数をパースして、その評価結果を返す。
int factor(State &begin){
	int ret = 0;
	if(*begin=='('){
		begin++;//'('を飛ばす
		ret =expression(begin);
		begin++;//')'を飛ばす
	}else{
		return number(begin);
	}
	return ret;
}


int main(){
	int n;
	cin>>n;
	cin.ignore();
	for(int i =0;i <n;i++){
		string s;
		getline(cin, s);

		State begin= s.begin();
		int ans =expression(begin);
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)  
{  
    
    if (n == 3||n==2)  return true;  
     
    if (n%2 == 0 || n%3 == 0) return false;  
    
    for (int i=5; i*i<=n; i=i+6)  
        if (n%i == 0 || n%(i+2) == 0)  
           return false;  
    
    return true;  
}  
int main()
{
    long long a,b,c,d,e,m,n,t;
    bool sieve[100005]={true};
    vector<int> aa;
    string s1,s2, s3;
    
    
    n=100005;
    cin>>a;
    //n=a*a;bool found = false; 
    bool found=false;
    while (1) 
    {
        if (isPrime(a))
        {
            found = true;
            break;
            
        }
            a++;
    } 
    //sort(aa.begin(),aa.end());
    cout<<a;
    
    return 0;
}

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (a >= 6) cout << b / 2 << endl;
	else cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
# 2019-11-22 16:56:24(JST)
import sys


def main():
    n, c, k, *T = [int(x) for x in sys.stdin.read().split()]
    T.sort()


    count = 0
    bus_count = 1
    t = T[0]
    for i in range(n):
        if T[i] - t > k:
            bus_count += 1
            count = 1
            t = T[i]
            continue
        count += 1
        if count > c:
            bus_count += 1
            count = 1
            t = T[i]
    
    print(bus_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14052