akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=2000;

ll modpow(ll x,ll y){
  long long ans=1;
  while(y>0){
    if(y&1){
      ans*=x%MOD;
    }
    x*=x%MOD;
    x%=MOD;
    ans%=MOD;
    y>>=1;
  }
  return ans;
}

ll fac[MAX];
ll faci[MAX];

void modCf(){
  fac[0]=1;
  faci[0]=1;
  for(int i=1;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    faci[i]=modpow(fac[i],MOD-2);
  }
  return;
}

ll modC( ll x,ll y){
  ll ans=fac[x];
  ans*=faci[y]%MOD;
  ans%=MOD;
  ans*=faci[x-y]%MOD;
  return ans%MOD;
}

int main() {
  modCf();
  ll N;
  cin>>N;
  ll ans=0;
  ll kou=N/3;
  ll amari=N%3;
  while(kou>0){
    ans+=modC(kou+amari-1,amari);
    ans%=MOD;
    kou--;amari+=3;
  }
  cout<<ans;
}



Measured memory_bytes: 3660
a, b, c, k = map(int, input().split())
#1 0 -1
t = 0
ans = 0

if a >= k:
    print(k)
else:
    # a < k
    t = k - a

    if b >= t:
        print(a)
    else:
        # b < t
        s = t - b

        print(a-s)


Measured memory_bytes: 9168
#include <iostream>
#include<string>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  if(N<3200){
      cout<<"red"<<endl;
  }
  else{
      cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,m,i;
	int wana[10000],detame[10000];
	int susumu=1;
	int cnt;
	scanf("%d %d",&n,&m);
	while(n!=0 && m!=0){
		cnt=0;
		susumu=1;
		for(i=1;i<=n;i++){
			scanf("%d",&wana[i]);
		}
		for(i=0;i<m;i++){
			scanf("%d",&detame[i]);
		}
		for(i=0;i<m;i++){
			cnt++;
			susumu+=detame[i];
			susumu+=wana[susumu];
			if(susumu>=n){
				printf("%d\n",cnt);
				break;
			}
		}
		scanf("%d %d",&n,&m);
	}
	return 0;
}

Measured memory_bytes: 1044
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    string s,t;
    cin>>s>>t;
    int cnt=10001;

    for(int i=0;i+t.length()<=s.length();i++){
        string u=s.substr(i,t.length());
        int count=0;
        for(int j=0;j<t.length();j++){
            if(t[j]!=u[j]) count++;
        }
        cnt=min(count,cnt);
    }

    cout<<cnt<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  bool flag = 0;
  FOR(i,0,S.size()){
    if(S[i] == 'C'){
      flag = 1;
    }
    if(S[i] == 'F' && flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int cnt;
	static int x, y;
	static int[][] a;
	static int n;
	
	static void pushNumber(){
		// 2. ÌðEÎßºÌ}XÚÉ...
		x++;
		y++;
		
		/* 2-1. EÉÍÝoµ½êÉÍA¯¶sÌ¶ÍµÉA
		 * ¶ÉÍÝoµ½êÉÍA¯¶sÌEÍµÉA
		 * ºÉÍÝoµ½êÉÍA¯¶ñÌêÔãÉ... */
		if(x>=n){
			x=0;
		}
		if(y>=n){
			y=0;
		}
		if(x<0){
			x=n-1;
		}
		if(y<0){
			y=n-1;
		}
		if(a[x][y]==0){
			a[x][y]=cnt++;	// ðüêé
		}
		else{
			/* ð¢êæ¤Æµ½}XÚªÜÁÄ¢éÆ«ÉÍA
			 * »ÌÜÁÄ¢é}XÚÌ¶ÎßºÌ}XÚÉ*/
			y-=2;
		}
	}
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		while(true){
			n = stdIn.nextInt();		// Input
			if(n==0){		// Finish
				return;
			}
			a = new int[n][n];		// Box Make
			
			// 1. Ì}XÚÌ¿å¤ÇêÂºÌ}XÚÉPð¢êéB
			x=(n-1)/2;
			y=x++;
			a[x][y]=1;
			
			cnt = 2;
			while(true){
				if(cnt>n*n){
					break;
				}
				pushNumber();
			}
			
			// Output
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					System.out.printf("%4d",a[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  
  int N, M;   cin >> N >> M;
  vector<int> X(M);
  for(int i = 0 ; i < M ; i++)
    cin >> X[i];

  sort(X.begin(), X.end());
  vector<int> dif(M - 1);
  for(int i = 0 ; i < M - 1 ; i++)
    dif[i] = X[i + 1] - X[i];

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


  if(M == 1){
    cout << 0 << endl;
  }else{
    long long ans = 0;
    for(int i = 0 ; i < M - N ; i++)
      ans += dif[i];

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
n, x, y = map(int, input().split())
ans = [0 for i in range(n - 1)]

for i in range(1, n):
  for j in range(i + 1, n + 1):
    d = min(j - i, abs(x - i) + abs(y - j) + 1)
    ans[d - 1] += 1

for i in range(n - 1):
  print(ans[i])

Measured memory_bytes: 3444
import itertools



class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.command_allpattern = "NNNNENNNNENNNNENNNNNENNNNEENNNNWWWSE"

    def set_number(self, d0, d1, d2, d3, d4, d5):
        self.number[0] = d0
        self.number[1] = d1
        self.number[2] = d2
        self.number[3] = d3
        self.number[4] = d4
        self.number[5] = d5

    def roll(self, command):
        if   command == "E":
            self.set_number(self.number[3],self.number[1],self.number[0],self.number[5],self.number[4],self.number[2])
        elif command == "N":
            self.set_number(self.number[1],self.number[5],self.number[2],self.number[3],self.number[0],self.number[4])
        elif command == "S":
            self.set_number(self.number[4],self.number[0],self.number[2],self.number[3],self.number[5],self.number[1])
        elif command == "W":
            self.set_number(self.number[2],self.number[1],self.number[5],self.number[0],self.number[4],self.number[3])
        else:
            raise

    def get_top(self):
        return self.number[0]

    def get_d2(self, d0, d1):
        flag_correct = False
        
        for command in self.command_allpattern:
            self.roll(command)

            if ((d0 == self.number[0]) and
                (d1 == self.number[1])):
                d2 = self.number[2]
                flag_correct = True

        if flag_correct:
            return d2
        else:
            raise

    def is_equal_dice_number(self, Dice):
        if set(Dice.number) == set(self.number):
            return True
        else:
            return False

    def equal_dice(self, Dice):

        if not self.is_equal_dice_number(Dice):
            return("No")

        flag_correct = False

        for command in self.command_allpattern:
            Dice.roll(command)

            if ((Dice.number[0] == self.number[0]) and
                (Dice.number[1] == self.number[1]) and
                (Dice.number[2] == self.number[2]) and
                (Dice.number[3] == self.number[3]) and
                (Dice.number[4] == self.number[4]) and
                (Dice.number[5] == self.number[5])):
                flag_correct = True

        if flag_correct:
            return("Yes")
        else:
            return("No")



n = int(input())

list_dice_class = []

for _ in range(n):
    list_face = list(map(int, input().split()))

    dice = Dice()
    dice.set_number(list_face[0], list_face[1], list_face[2], list_face[3], list_face[4], list_face[5])

    list_dice_class.append(dice)


flag_equal = False

for dice_a, dice_b in list(itertools.combinations(list_dice_class, 2)):
    if dice_a.equal_dice(dice_b) == "Yes":
        flag_equal = True
        break

if flag_equal:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 6008
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b,c,x;cin>>a>>b>>c>>x;
    int res=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x) res++;
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
a=input()
m=int(a[:2])
u=int(a[2:])
if (m<=12 and m>0) and (u<=12 and u>0):
    print("AMBIGUOUS")
    exit()
elif (m<=12 and m>0) and (u>12 or u==0):
    print("MMYY")
    exit()
elif (m>12 or m==0) and (u<=12 and u>0):
    print("YYMM")
    exit()
    
else:
    print("NA")

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int d,t,s;
	cin>>d>>t>>s;
	int val=t*s;
	if(val>=d)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll tot=0;
  for (ll i = 1;n >= i*i;i++){
    if (n % i == 0){
      ll m = n / i;
      if (m - 1 > i){
	tot += m - 1;
      }
      if (i - 1 > m){
	tot += i - 1;
      }
    }
  }
  cout << tot;
}

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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    char c;
    cin >> c;
    if ('a' <= c && c <= 'z')
        cout << "a" << endl;
    else
        cout << "A" << endl;
}

Measured memory_bytes: 3604
#if 1
#pragma GCC optimize "O3"
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <random>
#include <cassert>
#include <cmath>
#include <cstring>
#include <chrono>
using namespace std;
using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using f32 = float; using f64 = double;
template <class T> inline T sq(T a) { return a * a; }
template <class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; }
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
void _u() { cerr << endl; } template <class H, class... T> void _u(H&& h, T&&... t) { cerr << h << ", "; _u(move(t)...); }
#define _polyfill(v) v
#define _overload3(a, b, c, d, ...) d
#define _rep3(i, a, b) for (i32 i = i32(a); i < i32(b); ++i)
#define _rep2(i, b) _rep3(i, 0, b)
#define _rep1(i) for (i32 i = 0; ; ++i)
#define rep(...) _polyfill(_overload3(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__))
#define A(a) begin(a), end(a)
#define S(a) i32((a).size())
#define U(...) { cerr << #__VA_ARGS__ << ": "; _u(__VA_ARGS__); }
#define lin U(__LINE__)
#define exi exit(0);
#endif

class timer {
    vector<timer> timers;
    int n = 0;
public:
    double limit = 2.95;
    double t = 0;
    timer() {}
    timer(int size) : timers(size) {}
    bool elapses() const {
        return time() - t > limit;
    }
    void measure() {
        t = time() - t;
        ++n;
    }
    void measure(char id) {
        timers[id].measure();
    }
    void print() {
        if (n % 2)
            measure();
        for (int i = 0; i < 128; ++i) {
            if (timers[i].n)
                cerr << (char)i << ' ' << timers[i].t << 's' << endl;
        }
        cerr << "  " << t << 's' << endl;
    }
    static double time() {
#ifdef LOCAL
        return __rdtsc() / 3.3e9;
#else
        using namespace std::chrono;
        return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() / 1000.0;
#endif
    }
} timer(128);

constexpr bool Deterministic = 0;
class rando {
    unsigned y;
public:
    rando(unsigned y) : y(y) {}
    unsigned next() {
        return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
    }
    int next(int b) {
        return next() % b;
    }
    int next(int a, int b) {
        return next(b - a) + a;
    }
    double nextDouble(double b = 1) {
        return b * next() / 4294967296.0;
    }
    double nextDouble(double a, double b) {
        return nextDouble(b - a) + a;
    }
    int operator() (int b) {
        return next(b);
    }
} rando(Deterministic ? 2463534242 : random_device()());

i32 main() {
    i64 r, D, x;
    cin >> r >> D >> x;
    rep (_, 10) {
        x = x * r - D;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define moda 998244353
#define pi 3.14159265358979323846
#define io ios::sync_with_stdio(0); cin.tie(0);
#define debug cout<<"f\n";
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(), x.rend()

int main()
{

int n, k;
cin>>n>>k;
int h[n];

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

int dp[n];

for(int i = 0 ; i < n ; i++)
    dp[i] = 0;

for(int i = 1 ; i <= n ; i++)
{
    for(int j = 1 ; j <= k ; j++)
    {
        if(i - j >= 0)
        {
            if(j == 1)dp[i] = dp[i - j] + abs(h[i] - h[i - j]);
            else
            {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
        else break;
    }
}

cout<<dp[n - 1];

return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define ll long long

int main(){
    ll n;
    cin >> n;
    ll ans = n*(n+1)*(n+2)/6;
    rep(i, n-1) {
        ll u, v;
        cin >> u >> v;
        if (u>v) swap(u, v);
        ans -= (u)*(n-v+1);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#coding: utf-8
import sys
def input():
    return sys.stdin.readline()[:-1]
"""
高橋君はたこ焼きが好きです。
たこ焼き器を使うと、1度に最大でX個のたこ焼きを作ることができます。
これにかかる時間は作る個数によらず T分です。
N個のたこ焼きを作るためには何分必要ですか？
"""
import math
N, X, T = map(int, input().split())
out = int(math.ceil(N/X) * T)
print(out)

Measured memory_bytes: 62064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n;cin>>n;
  P left,right;
  string s;
  cout<<0<<endl;
  cin>>s;
  if(s[0]=='V')exit(0);
  if(s[0]=='M')left=P(0,0);
  else left=P(0,1);
  cout<<n-1<<endl;
  cin>>s;
  if(s[0]=='V')exit(0);
  if(s[0]=='M')right=P(n-1,0);
  else right=P(n-1,1);
  P half;
  while(right.first-left.first>1){
    half.first=(left.first+right.first)/2;
    string s;cout<<half.first<<endl;
    cin>>s;
    if(s[0]=='V')exit(0);
    if(s[0]=='M')half.second=0;
    else half.second=1;
    if(((left.first+half.first)%2)^(left.second^half.second)){
      right=half;
    }
    else left=half;
  }
  cout<<right.first<<endl;
  cin>>s;
  if(s[0]=='V')exit(0);
  cout<<left.first<<endl;
  cin>>s;
  if(s[0]=='V')exit(0);
}




  


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

bool able(int a){
  return a > 12 || a == 0;
}

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

  int a = S / 100;
  int b = S % 100;

  string ans = "";
  if(able(a) && able(b))
    ans = "NA";
  else if(able(a))
    ans = "YYMM";
  else if(able(b))
    ans = "MMYY";
  else
    ans = "AMBIGUOUS";
  
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

ll f(int n){
    ll m=1;
    rep(i,n) m=m*2;
    return m;
}

ll c(int n,int r){
    if(r==n || r==0) return 1;
    else if(r==1) return n;
    else return c(n-1,r-1)+c(n-1,r);
}

int main(){
   int n,p,r0=0,r1=0;
   cin >> n >>p;
   vector<int> a(n);
   rep(i,n){
       cin >> a[i];
       a[i]%=2;
       if(a[i]==0) r0++;
       else r1++;
   }
   ll ans=0;
   if(p==1){
       for(int i=0;2*i+1<=r1;i++) ans+=c(r1,2*i+1);
       ans*=f(r0); 
   }else{
       for(int i=0;2*i<=r1;i++) ans+=c(r1,2*i);
       ans*=f(r0);
   }
   cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>

using namespace std;

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

	int n, m;
	int x[200000];

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}

	sort(x, x + m);

	int sum = 0;
	int t[200000];
	for (int i = m - 1; i > 0; i--) {
		sum += (x[i] - x[i - 1]);
		t[m - 1 - i] = x[i] - x[i - 1];
	}

	sort(t, t + m - 1);
	reverse(t, t + m - 1);
	int max = 0;
	for (int i = 0; i < n - 1; i++)  max += t[i];
	cout << sum - max << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x;
    cin>>n;
    ll ans = LLMAX;
    for(ll i=1;i<1000001;i++){
        if(n%i==0){
            ans = min(ans,i+n/i-2);
        }
    }
    cout<<ans;
    
    

    return 0;
}




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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i < N; i++) {
        A[i] += A[i - 1];
    }

    ll ans = 1e18;
    for (int n = 1; n < N - 2; n++) {
        int pq = lower_bound(A.begin(), A.end(), A[n] / 2) - A.begin();
        ll P = A[pq];
        ll Q = A[n] - A[pq];
        if (pq > 0 && abs(P - Q) > abs(A[pq - 1] - A[n] + A[pq - 1])) {
            P = A[pq - 1];
            Q = A[n] - A[pq - 1];
        }
        if (pq < n && abs(P - Q) > abs(A[pq + 1] - A[n] + A[pq + 1])) {
            P = A[pq + 1];
            Q = A[n] - A[pq + 1];
        }

        ll d = A[N - 1] - A[n];
        int rs = lower_bound(A.begin(), A.end(), A[n] + d / 2) - A.begin();
        ll R = A[rs] - A[n];
        ll S = A[N - 1] - A[rs];
        if (rs > n + 1 && abs(R - S) > abs(A[rs - 1] - A[n] - A[N - 1] + A[rs - 1])) {
            R = A[rs - 1] - A[n];
            S = A[N - 1] - A[rs - 1];
        }
        if (rs < N - 1 && abs(R - S) > abs(A[rs + 1] - A[n] - A[N - 1] + A[rs + 1])) {
            R = A[rs + 1] - A[n];
            S = A[N - 1] - A[rs + 1];
        }

        ans = min(max({P, Q, R, S}) - min({P, Q, R, S}), ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main() {

  double n,t,a,m=INF,ans=0;
  cin>>n>>t>>a;
  vector<double> A(n);
  for(int i=0;i<n; i++){
    double tmp;
    cin>>A[i];
    A[i]=t-0.006*A[i];
    tmp = max(A[i],a)-min(A[i],a); 
    if(m>tmp){m=tmp;ans=i;}
  }
  cout<<ans+1<<endl;

}


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

int main() {

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

  vector<int> AC(N);
  vector<int> WA(N);

  for(int i = 0; i < M; i++) {
    int p;
    cin >> p;
    string s;
    cin >> s;
    if (s == "AC" && AC[p - 1] == 0) {
      AC[p - 1] = 1;
    } else if (AC[p - 1] == 0) {
      WA[p - 1]++;
    }
  }

  int ac = 0;
  int wa = 0;

  for(int i = 0; i < N; i++) {
    ac += AC[i];
    if (AC[i] == 1) {
      wa += WA[i];
    }
  }

  cout << ac << " " << wa << endl;

}

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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }




int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n,k;
	cin >>n >>k;
	
	if(k==0){cout <<n*n <<"\n"; return 0;}
	ll as=0;
	
	rep2(i,k+1,n+1){
		ll w= 1LL * (n /i ) * (i-k) + max(0LL, n%i +1LL -k);
		as += w;
		//dbg(i,i-k,n,w);
	}
	
	cout << as <<"\n";

	return 0;
	
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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 pid_t pid = getpid();
// Problem Specific Parameter:

int dist[9][9];
int cnt[9][9];



int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;

	rep(i, 9) rep(j, 9){
		dist[i][j] = 0;
		dist[i][j] += abs(i / 3 - j / 3);
		dist[i][j] += abs(i % 3 - j % 3);
	}

	rep(i, n - 1){
		const int a = s[i] - '1';
		const int b = s[i + 1] - '1';
		cnt[a][b]++;
	}

	vector<int> ary(9);
	iota(begin(ary), end(ary), 0);

	int cmin = 1 << 28;
	string ans = "";

	do {
		int cur = 0;
		rep(i, 9)rep(j, 9){
			cur += cnt[ary[i]][ary[j]] * dist[i][j];
		}

		if(chmin(cmin, cur)){
			string tmp = "";
			rep(i, 9) tmp += char(ary[i] + '1');
			ans = tmp;
		}

	} while(next_permutation(begin(ary), end(ary)));

	rep(i, 3) cout << ans.substr(3 * i , 3) << endl;

	return 0;
}


Measured memory_bytes: 3312
using System;

namespace CA {
	class Prg {
		static void Main() {
			string[] str = new string[2];
			while(true){
				str = Console.ReadLine().Split(' ');
				if (int.Parse(str[0]) < int.Parse(str[1])) Console.WriteLine("{0} {1}", str[0], str[1]);
				else if (str[0] == "0" && str[1] == "0") break;
				else Console.WriteLine("{1} {0}", str[0], str[1]);
			}
		}
	}
}

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

int main(){
    int n;
    int x=0;
    int tmp=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s.at(i)=='I'){
            x++;
            if(tmp<x){
                tmp=x;
            }
        }
        else{
            x--;
        }
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mx=1234567;
#define ll long long
#define p push_back
#define ff first
#define ss second
ll n ,s[mx],ss[mx],b,sum;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        ss[i]=i+1-s[i];
    }
    sort(ss,ss+n);
    b-=ss[n/2];
    for(int i=0;i<n;i++){
        sum+=abs(b+i+1-s[i]);
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 5888
#include <cstdio>
#include <vector>
using namespace std;
class UnionFind {
private:
	int size_; vector<int> g; vector<vector<int> > v;
public:
	UnionFind() : size_(0), g(vector<int>()), v(vector<vector<int> >()) {};
	UnionFind(int size__) : size_(size__) {
		g.resize(size__); v.resize(size__);
		for (int i = 0; i < size__; i++) g[i] = i, v[i] = { i };
	};
	int size() { return size_; }
	int root(int x) { return g[x]; }
	int size(int x) { return v[x].size(); }
	bool same(int x, int y) { return g[x] == g[y]; }
	void unite(int x, int y) {
		x = g[x], y = g[y];
		if (x == y) return;
		if (v[x].size() < v[y].size()) swap(x, y);
		v[x].insert(v[x].end(), v[y].begin(), v[y].end());
		for(auto &e : v[y]) g[e] = x;
		v[y].clear();
	}
	bool operator==(const UnionFind& u) { return g == u.g; }
	bool operator!=(const UnionFind& u) { return g != u.g; }
	int operator[](int x) { return g[x]; }
};
int n, q, c, x, y;
int main() {
	scanf("%d%d", &n, &q);
	UnionFind u(n);
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &c, &x, &y);
		if(c) printf("%d\n", u.same(x, y) ? 1 : 0);
		else u.unite(x, y);
	}
}

Measured memory_bytes: 3304
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    int num[4][3][10];

    int m=0;

    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                num[i][j][k]=0;
            }
        }
    }

    int b,f,r,v;

    for (int i=0;i<n;i++){
        cin >> b >> f >> r >> v;

        num[b-1][f-1][r-1] = num[b-1][f-1][r-1] + v;

    }

    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                
                cout << " " << num[i][j][k];                
                
            }

            cout << endl;
            
        }

        if(i!=3){
            cout << "####################" << endl;
        }
    }

    

    return 0;

}


Measured memory_bytes: 3056
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[])
{
	LL N, L[200], ans = 0;
	cin >> N;
	for (int i = 0; i < N * 2; ++i) {
		cin >> L[i];
	}
	sort(L, L + N * 2);
	for (int i = 0; i < N; ++i) {
		ans += L[i * 2];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  vector<ll>b(n+1);
  rep(i,n-1) cin >> b[i+1];
  b[0]=INF;
  b[n]=INF;
  ll ans = 0;
  rep(i,n){
    ans += min(b[i],b[i+1]);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    deque<ll> dq;
    rep(i,n){
        int p=lower_bound(all(dq),a[i])-dq.begin();
        if(p==0) dq.push_front(a[i]);
        else dq[p-1]=a[i];
    }

    cout<<dq.size()<<endl;
}

Measured memory_bytes: 1920
from collections import deque
w,h = list(map(int,input().split(" ")))
path = [input() for _ in range(w)]

def bfs(sw,sh):
    res = 0
    dw = [-1,1,0,0]
    dh = [0,0,1,-1]
    dist = [[-1 for _ in range(h)] for _ in range(w)]
    dist[sw][sh] = 0
    queue = deque()
    queue.append((sw,sh))
    while len(queue) != 0:
        cw,ch = queue.popleft()
        for i in range(4):
            nw,nh = cw + dw[i], ch + dh[i]
            if not (0<= nw < w and 0 <= nh < h): continue
            if path[nw][nh] == "#": continue
            if dist[nw][nh] != -1: continue
            dist[nw][nh] = dist[cw][ch] + 1
            queue.append((nw,nh))
            res = max(res, dist[nw][nh])
    return res

ans = 0
for i in range(w):
    for j in range(h):
        if path[i][j] == "#":
            continue
        ans = max(ans, bfs(i,j))
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll IMF = 1LL << 60;
int main() {
  int N;
  cin >> N;
  vector<int> h(N);

  for(int i = 0; i < N; i++) cin >> h[i];


  ll dp[N];
  for(int i = 0; i < N; i++) {
    dp[i] = IMF;
  }
  dp[0] = 0;

  for(int i = 1; i < N; i++) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if(i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }

  cout << dp[N - 1];
  return 0;
}

Measured memory_bytes: 1408
#include <cctype>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define pk putchar(' ')
#define ph puts("")
typedef long long ll;
using namespace std;
template <class T>
void rd(T &x)
{
    x = 0;
    int f = 1;
    char c = getchar();
    while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    x *= f;
}
template <class T>
void pt(T x)
{
    if (x < 0)
        putchar('-'), x = (~x) + 1;
    if (x > 9)
        pt(x / 10);
    putchar(x % 10 ^ 48);
}
const int N = 2e5 + 5;
int n, a[N];
ll ans;
map<int, ll> M;
int main() 
{
	rd(n);
	for (int i = 1; i <= n; i++)
		rd(a[i]), M[a[i] + i]++;
	for (int i = 1; i <= n; i++)
		ans += M[i - a[i]];
	pt(ans);
    return 0;
}

Measured memory_bytes: 26488
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890
#define ll long long
#define MOD 998244353

int N, K;
int L[11], R[11];
ll dp[200201];
ll sum[11];

int main()
{
	scanf("%d %d", &N, &K);
	for(int i=1; i<=K; i++)
		scanf("%d %d", &L[i], &R[i]);
	
	dp[1] = 1;
	for(int i=2; i<=N; i++)
	{
		for(int k=1; k<=K; k++)
		{
			if (i > L[k]) sum[k] += dp[i-L[k]];
			if (i > R[k]+1) sum[k] -= dp[i-R[k]-1];
			sum[k] %= MOD;
			dp[i] += sum[k];
		}
		dp[i] %= MOD;
	}
	dp[N] += MOD; dp[N] %= MOD;
	printf("%lld", dp[N]);
	return 0;
}

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

using namespace std;

#define ll long long

const int mxN = 3003;

int n;
double dp[mxN][mxN];
double p[mxN];

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

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

    dp[0][0]=1;

    for (int i=1; i<=n; i++) {
        for (int j=0; j<=i; j++) {
            if (j==i) {
                dp[i][j]=dp[i-1][j-1]*p[i];
            } else if (j==0) {
                dp[i][j]=dp[i-1][j]*(1-p[i]);
            } else {
                dp[i][j]=dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
            }
        }
    }

    double ans=0;
    for (int i=(n/2)+1; i<=n; i++) {
        ans+=dp[n][i];
    }
    cout.precision(10);
    cout << ans << "\n";

}


Measured memory_bytes: 68992
#include <stdio.h>
#include <math.h>
int main() {
	long long n;
	long long result = 100000000190000;
	scanf("%lld", &n);
	for (long long a = 1; a <= sqrt(n); a++){
		if (n % a == 0) {
			long long c = a + (n / a) - 2;
			if (c < result) result = c;
		}
	}
	printf("%lld", result);
	return 0;
}


Measured memory_bytes: 128
N = int(input())
T, A = (int(i) for i in input().split())
H = list(int(i) for i in input().split())

a = 0
c = 999
d = 0
for i in range(N):
    a = T - H[i]*0.006
    if c > abs(A-a):
        c = abs(A-a)
        d = i

print(d+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i,j;
    int n,m;
    cin>>n>>m;
    if(n%2==1){
        for(i=1;i<=m;i++){
            cout<<i<<" "<<n+1-i<<endl;
        }
        return 0;
    }
    else {
        int k = n/4;
        for(i=1;i<=min(m,k);i++){
            cout<<i<<" "<<n+1-i<<endl;
        }
        for(i=min(m,k)+1;i<=m;i++){
            cout<<i<<" "<<n-i<<endl;
        }
        return 0;
    }

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int one=9,three=900,five=90000;
 long long int N,num,temp=0;
  cin>>N;
  num=N;
  while(num!=0)
  {
  temp++;
    num/=10;
  }
  switch(temp)
  {
    case 1: cout<<N; break;
    case 2: cout<<one;break;
    case 3: cout<<one+N-99;break;
    case 4: cout<<one+three;break;
    case 5: cout<<one+three+N-9999;break;
    case 6: cout<<one+three+five;break;
  } 
  
  return 0; 
  
}

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

int H,W;

char check(int i,int j,char** field){
  if(i < 0 || j < 0){
    return 0;
  }
  if(i >= H || j >= W)
    return 0;

  if(field[i][j] == '#')
    return 1;

  return 0;
}

int main(void)

{

  scanf("%d %d",&H,&W);

  char** field;
  field = (char**)malloc(sizeof(char*) * H);
  int i,j;
  for(i = 0; i < H;i++){
    field[i] = (char*)malloc(sizeof(char) * W);
  }
  
  for(i = 0; i < H; i++){
    for(j = 0; j < W;j++)
      scanf(" %c",&field[i][j]);
  }
//printf("debug : loadcmp\n");
//for(i = 0;i < H;i++)
//  for(j=0; j < W;j++)
//    printf(" | %c | ",field[i][j]);

  for(i = 0; i < H; i++){
    for(j = 0; j < W;j++){
      if(field[i][j] == '.'){
        field[i][j] = check(i + 1,j + 1,field) + check(i + 1, j ,field) + check(i,j+1,field) 
                     +check(i - 1,j - 1,field) + check(i - 1, j, field) + check(i,j-1,field)
                     +check(i + 1,j - 1,field) + check(i - 1, j + 1,field) + '0';
      }
    }
  }
//printf("debug : calccmp\n");
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
      printf("%c",field[i][j]);
    }
    printf("\n");
  }

  for(i = 0; i <H ;i++){
    free(field[i]);
  }
  free(field);
  return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
neighborof1 = set()
neighborofN = set()
for j in range(M):
    a, b = map(int, input().split())
    if a == 1:
        neighborof1.add(b)
    elif b == N:
        neighborofN.add(a)
flag = 0
if len(neighborof1) > len(neighborofN):
    for i in neighborofN:
        if i in neighborof1:
            flag = 1
            break
else:
    for k in neighborof1:
        if k in neighborofN:
            flag = 1
            break
if flag == 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


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

double error = 0.000001;

double distance(pair<double, double>xy1, pair<double, double>xy2) {
    return hypot(xy1.first - xy2.first, xy1.second - xy2.second);
}

bool in_circle(double r, pair<double, double> coordinate, vector<pair<double, double>> xy) {
    bool judge = true;
    for (int i = 0; i < xy.size(); i++) {
        if (distance(xy[i], coordinate) > r+error) {
            judge = false;
            break;
        }
    }
    return judge;
}

bool check_line(pair<double, double>xy1, pair<double, double>xy2, pair<double, double>xy3) {
    return (abs((xy2.second-xy1.second)/(xy2.first-xy1.first) - (xy3.second-xy2.second)/(xy3.first-xy2.first)) < error);
}

pair<double, double> calc_circumcenter(pair<double, double>xy1, pair<double, double>xy2, pair<double, double>xy3) {
    double a = xy1.first;
    double b = xy1.second;
    double c = xy2.first;
    double d = xy2.second;
    double e = xy3.first;
    double f = xy3.second;
    
    double x;
    double y = (((e-a)*(a*a+b*b-c*c-d*d)-(c-a)*(a*a+b*b-e*e-f*f)) / (2*(e-a)*(b-d) -2*(c-a)*(b-f)));
    if (c-a != 0)
        x = (2*(b-d)*y-a*a-b*b+c*c+d*d) / (2*(c-a));
    else
        x = (2*(b-f)*y-a*a-b*b+e*e+f*f) / (2*(e-a));
    return make_pair(x, y);
}

int main(void){
    int n;
    cin >> n;
    vector<pair<double, double>> xy(n);
    rep(i, n) {
        double x, y;
        cin >> x >> y;
        xy[i] = make_pair(x, y);
    }
    
    double min_r = 1000;
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            double r = distance(xy[i], xy[j]) / 2;
            pair<double, double> center = make_pair((xy[i].first + xy[j].first)/2, (xy[i].second + xy[j].second)/2);
            if (in_circle(r, center, xy))
                min_r = min(min_r, r);
        }
    }
    
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            for (int k = j+1; k < n; k++) {
                if (!check_line(xy[i], xy[j], xy[k])) {
                    pair<double, double> center = calc_circumcenter(xy[i], xy[j], xy[k]);
                    double r = distance(center, xy[i]);
                    if (in_circle(r, center, xy))
                        min_r = min(min_r, r);
                }
            }
        }
    }
    
    cout << fixed << setprecision(10) << min_r << endl;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();

        // 主処理
        int sum = 0;
        int result = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'I') {
                sum++;
            } else {
                sum--;
            }
            result = Math.max(result, sum);
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int a,b,c;cin>>a>>b>>c;
    int e=a;
    for(int i=0;i<b;i++){
        if(e%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
        e+=a;
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int  maxn = 1e5 + 5;
int a, b, c;
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> a >> b >> c;
    int ret = 0;
    for(int i = 0; i < c; i ++){
        if(b >= a){
            b -= a;
            ret ++;
        }
        else{
            break;
        }
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <algorithm>

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int N;
  long long int a[MAX_N];
  cin >> N;
  for (long long int i = 0; i < N; i++) cin >> a[i];
  sort(a, a+N, greater<long long int>());

  long long int mid_a = a[0]/2;
  long long int deff = abs(a[0] - mid_a);
  long long int mid_idx = 1;
  for (long long int i = 1; i < N; i++) {
    if (abs(a[i]-mid_a) < deff) {
      deff = abs(a[i]-mid_a);
      mid_idx = i;
    }
  }

  cout << a[0] << ' ' << a[mid_idx] << endl;

  return 0;
}


Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto D = aryread();
    auto cnt = new long[](13);
    cnt[0] = 1;
    foreach (d; D)
    {
        cnt[d]++;

        if (cnt[d] == 3 || ((d == 0 || d == 12) && cnt[d] == 2))
        {
            writeln(0);
            return;
        }
    }
    auto t = new bool[](24);
    t[0] = true;
    t[12] = (cnt[12] != 0);
    bool b;
    foreach (i; 1 .. 12)
    {
        if (cnt[i] == 1)
            t[(b ? 24 - i : i)] = true;
        if (cnt[i] == 2)
            t[24 - i] = t[i] = true;
        if (cnt[i] != 0)
            b = (b == false);
    }

    // writeln(t.map!(to!long));
    long ans = long.max;
    foreach (i; 0 .. 24)
        foreach (j; i + 1 .. 24)
            if (t[i] && t[j])
            {
                long diff = j - i;
                ans = min(ans, diff, 24 - diff);
            }
    writeln(ans);
}


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

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

	int B[n];

	for (int i = 0; i < n - 1; i++)
		cin >> B[i];

	vector<int> myVec;

	if (n == 2)
	{
		myVec.push_back(B[0]);
		myVec.push_back(B[0]);
	}
	else
	{
		myVec.push_back(B[0]);
		myVec.push_back(min(B[0], B[1]));
	}

	for (int i = 1; i < n - 2; i++)
		myVec.push_back(min(B[i], B[i + 1]));

	if (n != 2)
		myVec.push_back(B[n - 2]);

	vector<int>::iterator it;
	int sum = 0;
	for (it = myVec.begin(); it != myVec.end(); it++)
	{
		// cout << *it << " ";
		sum = sum + *it;
	}

	cout << sum;
	return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)



long long dp[3010][6010] = {};
long long powing(long long a, long long b) {
	long long ans = 1;
	while (b != 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long inv(long long now) {
	return powing(now, MOD - 2);
}
long long omote[20000];
long long gyaku[20000];
long long combination(long long a, long long b) {
	long long ans = omote[a];
	ans *= gyaku[b];
	ans %= MOD;
	ans *= gyaku[a - b];
	ans %= MOD;
	return ans;
}
long long hype(long long a, long long b) {
	return combination(a + b - 1, b);
}
int main(){
	int n, x;
	cin >> n >> x;
	omote[0] = 1;
	gyaku[0] = 1;
	for (long long i = 1; i < 20000; ++i) {
		omote[i] = omote[i - 1] * i;
		omote[i] %= MOD;
		gyaku[i] = inv(omote[i]);
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int q = 0; q < x; ++q) {
			if (dp[i][q] == 0) continue;
			dp[i + 1][q + 1] += dp[i][q];
			dp[i + 1][q + 2] += dp[i][q];
			dp[i + 1][q + 1] %= MOD;
			dp[i + 1][q + 2] %= MOD;
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		for (int q = 0; q < x; ++q) {
			if (dp[i][q] == 0) continue;
			ans += dp[i][q] * hype(i+1, n - i);
			ans %= MOD;
		}
	}
	if (x % 2 == 1) {
		for (int i = (x + 1) / 2; i <= n; ++i) {
			ans += hype(i + 1, n - i);
			ans %= MOD;
		}
	}
	for (int i = 1;; ++i) {
		long long target = x - 1 - 2 * i;
		if (target <= 0) break;
		for (int two = 0;; ++two) {
			long long remaining = target - 2 * two;
			if (remaining <= 0) break;
			long long cnt = i * 2 + two + remaining;
			if (cnt > n) continue;
			long long hoge = hype(cnt + 1, n - cnt) * combination(two + remaining, two);
			ans += hoge;
			ans %= MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 140032
#include<iostream>
#include<string>
using namespace std;
int main(){
   string line,str1,str2;
   int m;

   while(cin >> line , line != "-"){
	cin >> m;
	int h[m];

	for(int i=0; i<m; i++){
		cin >> h[i];
		str1 = line.substr(0,h[i]);
		str2 = line.substr(h[i],line.size());
		line = str2 + str1;
	}

	cout << line << endl;
   }

   return 0;

}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;

    int a = P + Q;
    int b = Q + R;
    int c = R + P;

    int min = (a < b) ? a : b;
    min = (min < c) ? min : c;

    cout << min;

    return 0;
}



Measured memory_bytes: 256