akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unistd.h>
#define inf 1000000007LL
#define INF 1000000000000000007LL
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pair<int,int>>
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define LOG(x) (63-__builtin_clzll(x))
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i, n) for(int i=1; i<=(n); ++i)
#define endr cerr<<'\n'
#define endl '\n'
#ifdef DEBUG
#define pv(...) cerr<<'\n',dbg(#__VA_ARGS__, __VA_ARGS__)
#define ps(x) {cerr<<'\n'<<#x<<":\n:";for(auto _q:(x)){cerr<<_q<<" ";}cerr<<'\n';}
#define pa(x, xs) {cerr<<'\n'<<#x<<":\n:";for(int _q=0; _q<=(xs); ++_q){cerr<<x[_q]<<" ";}cerr<<'\n';}
#define pal(x, xs) {cerr<<'\n'<<#x<<":\n";for(int _q=0; _q<=(xs); ++_q){cerr<<_q<<": "<<setw(_q? 3-(int32_t)log10(_q):3)<<x[_q]<<'\n';}cerr<<'\n';}
#define ppii(x, xs) {cerr<<'\n'<<#x<<":\n";for(int _q=0; _q<=(xs); ++_q){cerr<<_q<<": "<<setw(_q? 6-(int32_t)log10(_q):6)<<x[_q].first<<" "<<setw(5)<<x[_q].second<<'\n';}cerr<<'\n';}
#define pm(x, xn, xm) {cerr<<'\n'<<#x<<":\n";for(int _qa=0; _qa<=(xn); ++_qa){for(int _qb=0; _qb<=(xm); ++_qb){cerr<<setw(6)<<x[_qa][_qb]<<" ";}cerr<<'\n';}cerr<<'\n';}
#else
#define cerr if(0)cout
#define pv(...) if(0)endr
#define ps(x) if(0)endr
#define pa(x, xs) if(0)endr
#define pal(x, xs) if(0)endr
#define ppii(x, xs) if(0)endr
#define pm(x, xn, xm) if(0)endr
#endif
using namespace std;
template<class T> void dbg(const char* xn, T x){cerr<<xn<<": "<<x<<"\n";} template<class T, class... TA> void dbg(const char* xn, T x, TA... t){while(*xn!=',')cerr<<*xn++;cerr<<": "<<x<<",";dbg(xn+1, t...);}
template<class T> inline bool upd_max(T &x, T y){return y>x?x=y,true:false;} template<class T> inline bool upd_min(T &x, T y){return y<x?x=y,true:false;}
const int N = 1000007;
#define int long long

int n, k, rst = 0;


void solve()
{
  cin>>n>>k;

  for (int a=1; a<=n; ++a)
  {
    int res = 0;
    int whole = n/a;
    res += max(0LL, whole*(a-1-k+1));
    int rest = n - whole*a;
    res += max(0LL, rest-k+1);

    rst += res;
  }

  if (k == 0) rst -= n;
  cout<<rst;
}

int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cout<<fixed<<setprecision(10);

  solve();

return 0;
}


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

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

  int targets[n + 1];

  rep(i, n) {
    int a;
    cin >> a;
    targets[i + 1] = a;
  }

  int location = 1;

  vector<ll> visited(n + 1, -1);
  visited[1] = 0;
  ll loop_size = 0;

  for (ll i = 0; k > 0; i++) {
    k--;
    location = targets[location];

    if (visited[location] > -1) {
      loop_size = i + 1 - visited[location];
      break;
    }
    visited[location] = i + 1;
  }

  if (k == 0) {
    cout << location << endl;
    return 0;
  }

  ll remaining = k > loop_size ? k % loop_size : k;

  rep(i, remaining) { location = targets[location]; }

  cout << location << endl;
}


Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

Measured memory_bytes: 4052
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;

int main() {
	
	ll a, b, k, i;

	cin >> a >> b >> k;

	if (a - k <= 0) {
		k -= a;
		a = 0;
		if (b - k > 0) b -= k;
		else b = 0;
	}
	else a -= k;

	cout << a << " " << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n;
  cin >> n;

  map<string, int> cnt;

  while(n--) {
    string s;
    cin >> s;
    cnt[s]++;
  }

  cout << "AC x " << cnt["AC"] << '\n';
  cout << "WA x " << cnt["WA"] << '\n';
  cout << "TLE x " << cnt["TLE"] << '\n';
  cout << "RE x " << cnt["RE"] << '\n';
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<bool>> iswhite(H, vector<bool>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char a;
            cin >> a;
            iswhite[i][j] = (a == '1');
        }
    }

    int ans = 1e9;
    for (int i = 0; i < (1 << (H - 1)); ++i) {
        int bitcnt = 0;
        for (int j = 0; j < H - 1; ++j)
            if (i & (1 << j))
                bitcnt++;

        int anstmp = bitcnt;
        bool isover = false;
        vector<int> wcnt(bitcnt + 1);
        for (int j = 0; j < W; ++j) {
            vector<int> wtmp(bitcnt + 1);
            int idx = 0;
            for (int k = 0; k < H; ++k) {
                wtmp[idx] += iswhite[k][j];
                if (i & (1 << k) || k == H - 1) {
                    if (wcnt[idx] + wtmp[idx] > K)
                        isover = true;
                    idx++;
                }
            }
            if (!isover) {
                for (int k = 0; k <= bitcnt; ++k)
                    wcnt[k] += wtmp[k];
            } else {
                for (int k = 0; k <= bitcnt; ++k) {
                    if (wtmp[k] > K)
                        anstmp = 1e9;
                    wcnt[k] = wtmp[k];
                }
                isover = false;
                anstmp++;
            }
        }
        ans = min(ans, anstmp);
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int x, y;
  cin >> x >> y;

  int a[7] = {1, 3, 5, 7, 8, 10, 12}, b[4] = {4, 6, 9, 11};

  int cx[2] = {}, cy[2] = {};
  REP(i, 7){
    if(x == a[i]) cx[0]++;
    if(y == a[i]) cy[0]++;
    if(i < 4){
      if(x == b[i]) cx[1]++;
      if(y == b[i]) cy[1]++;
    }
  }
  REP(i, 2){
    if(cx[i] != cy[i]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  char s[4];
  cin >> s;
  int ans[4] = {0,0,0,0};
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      if(s[i] == s[j]) ans[i]+=1;
    }
  }
  int twonum = 0;
  for(int i=0; i<4; i++){
    if( 2 == ans[i] ) twonum+=1;
  }
  if(twonum == 4){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int count=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]!=s[i+1]) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
n,k,m = map(int,input().split())
#print(k*m,n)
if n>=0:
    if k*m > n:
        #print(min(n%m, n-(n%m)))
        x = n//m;
        left = n - x*m;
        right = abs(left - m);
        k = k - x;
        if k&1:
            print(right)
        else:
            print(left)
        
    else:
        print(n - k*m)
else:
    n = abs(n)
    k = abs(k)
    m = abs(m)
    if k*m > n:
        #print(min(n%m, n-(n%m)))
        x = n//m;
        left = n - x*m;
        right = abs(left - m);
        k = k - x;
        if k&1:
            print(right)
        else:
            print(left)
        
    else:
        print(n - k*m)


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

int main(){
int N, D, X;
cin >> N >> D >> X;

int cnt = 0;
for(int i = 0; i < N; i++){ 
     int A;
     cin >> A;
for(int j = 0; 1 + (A * j) <= D; j++){ 
     cnt++;
}
}

cout << cnt + X << endl; 
}

Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    string::size_type pos = 0;
    while (true) {
        pos = s.find("ABC", pos);
        if (pos == string::npos) {
            break;
        }
        pos++;
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;

namespace AOJ0071
{
    class Program
    {
        byte[,] map;
        readonly int width = 8;
        int setCount;

        public void Proc()
        {
            string input = Console.ReadLine();
            int N = int.Parse(input);

            for (setCount = 1; setCount <= N; setCount++)
            {
                if (!string.IsNullOrEmpty(Console.ReadLine())) Console.WriteLine("Input Error");

                setMap();

                int x = int.Parse(Console.ReadLine());
                int y = int.Parse(Console.ReadLine());

                explosion(y + 2, x + 2);

                Console.WriteLine("Data {0}:", setCount);
                outputMap();
            }
        }

        static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }

        public void setMap()
        {
            string input;
            map = new byte[width + 6, width + 6];
            for (int i = 0; i < width; i++)
            {
                input = Console.ReadLine();
                for (int j = 0; j < width; j++)
                {
                    map[i + 3, j + 3] = byte.Parse(input.Substring(j, 1));
                }
            }
        }

        public void explosion (int y, int x)
        {
            if (map[y,x] == 1)
            {
                map[y, x] = 0;
                explosion(y - 3, x); explosion(y - 2, x); explosion(y - 1, x);
                explosion(y + 3, x); explosion(y + 2, x); explosion(y + 1, x);
                explosion(y, x - 3); explosion(y, x - 2); explosion(y, x - 1);
                explosion(y, x + 3); explosion(y, x + 2); explosion(y, x + 1);
            }
        }

        public void outputMap()
        {
            for (int i = 0; i < width; i++)
            {
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < width; j++)
                {
                    sb.Append(map[i + 3,j + 3]);
                }
                Console.WriteLine(sb.ToString());
            }
        }

        public static string ArrayJoin(byte[] arr)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                sb.Append(arr[i]);
            }
            return sb.ToString();
        }

    }
}

Measured memory_bytes: 9528
n,ma,mb = map(int,input().split())
med = [tuple(map(int,input().split())) for _ in range(n)]
maa = sum(x[0] for x in med)
mab = sum(x[1] for x in med)
dp = [[10**6]*(mab+1) for _ in range(maa+1)]
dp[0][0] = 0
for a,b,c in med:
  for i in range(maa,a-1,-1):
    for j in range(mab,b-1,-1):
      if dp[i][j] > dp[i-a][j-b] + c:
        dp[i][j] = dp[i-a][j-b] + c
mi = min(dp[ma*i][mb*i] for i in range(1,min(maa//ma,mab//mb)+1))
if mi > 10**5:
  mi = -1
print(mi)

Measured memory_bytes: 3948
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef  long long ll;


int main(){
  
  int N, cnt[5]={0};
  ll ans = 0;
  cin >> N;

  for(int i=0; i < N; i++){
    string s;
    cin >> s;
    if(s[0] == 'M')
      ++cnt[0];
    else if(s[0]=='A')
      ++cnt[1];
    else if(s[0]=='R')
      ++cnt[2];
    else if(s[0]=='C')
      ++cnt[3];
    else if(s[0]=='H')
      ++cnt[4];
  }

  for(int b = 0; b < 32; b++){
    int sum = 0;
    int flag =1;
    ll sum_box =1;
    for(int i = 0; i < 5; i++){
      if((b>>i)&1){
        ++sum;
        sum_box *= cnt[i];
        if(cnt[i]==0)
          flag = 0;
      }
    }
    if((sum ==3) && flag)
      ans += sum_box;
  }

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




Measured memory_bytes: 256
import sys

def solve(a, b):
    return(int(a)+int(b)//2)


def readQuestion():
    ws = sys.stdin.readline().strip().split()
    a = int(ws[0])
    b = int(ws[1])
    return (a, b)

def main():
    print(solve(*readQuestion()))

# Uncomment before submission
main()

Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int k = scanner.nextInt();

        long answer = 0;
        for (int i = 1; i <= k; i++) {
            if (answer <= 10) {
                answer++;
                continue;
            }

            final char[] array = Long.toString(answer).toCharArray();
            boolean flag = false;
            for (int j = array.length - 1; j > 0; j--) {
                final int latter = array[j] - '0';
                final int former = array[j - 1] - '0';
                if (latter == 9) {
                    continue;
                }
                if (latter <= former) {
                    array[j] += 1;
                    int prev = latter + 1;
                    for (int l = j + 1; l < array.length; l++) {
                        array[l] = (char) (Math.max(--prev, 0) + '0');
                    }
                    answer = Long.parseLong(new String(array));
                    flag = true;
                    break;
                }
            }
            if (flag) {
                continue;
            }

            if (array[0] < '9') {
                array[0]++;
                int prev = array[0] - '0';
                for (int l = 1; l < array.length; l++) {
                    array[l] = (char) (Math.max(--prev, 0) + '0');
                }
                answer = Long.parseLong(new String(array));
            } else {
                final char[] next = new char[array.length + 1];
                Arrays.fill(next, '0');
                next[0] = '1';
                answer = Long.parseLong(new String(next));
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 37972
#ttps://atcoder.jp/contests/abc134/submissions/6459172
from bisect import bisect
n = int(input())
A = [int(input()) for _ in range(n)]
dp = [1]
for a in A:
    a *= -1
    i = bisect(dp,a)   #既存に-aを挿入した時のindex

    if i < len(dp):    #挿入位置が長さより小さい時（要はabsが一番小さくない時
        dp[i] = a     #-aにする
    else:
        dp.append(a)    #右端に-aを普通に追加


print(len(dp))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 3;
const int N = 4e7 + 10, M = 1e7 + 10;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi acos(-1)

int main()
{
    int p;
    cin >> p;
    int sum = 0;
    for (int i = 1; i < N; i++)
    {
        sum = (sum * 10 + 7) % p;
        if (sum == 0)
        {
            cout << i << endl;
            return 0;
        }
    }
    puts("-1");
    return 0;
}


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

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

    T.pop_back();
    if(S == T){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if (ch == 'A') return 1;
  else if (ch == 'C') return 2;
  else if (ch == 'G') return 3;
  else if (ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * getChar(str[i]);
    p *= 5;
  }
  return sum;
}

int h1(int key) {
  return key % M;
}

int h2(int key) {
  return 1 + (key % (M - 1));
}

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int n, h;
  char str[L], com[9];
  for (int i = 0; i < M; i++) H[i][0] = '\0';
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }

  }

  return 0;
}


Measured memory_bytes: 17552
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fo(i,n) for(int i=0;i<n;++i)
#define Fo(i,k,n) for(int i=k;i<n;++i)
typedef long long int lli;
int main(){
    FIO
    int t; cin>>t;
    if(t>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    sc.nextLine()
    val num: Array[Int] = sc.nextLine.split(" ").map(_.toInt)

    def go(target: Array[Int], acc: Int): Int = {
      if (target.count(_ % 2 == 0) == target.length) go(target.map(_ / 2), acc + 1)
      else acc
    }

    println(go(num, 0))
  }
}


Measured memory_bytes: 25656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

static const int N = 1000000001;

int n;
vector<pair<int, int> > sec;

main(){
  while(cin >>n && n){
    sec.clear();
    sec.push_back(make_pair(-1, N));
    for(int i=0;i<n;i++){
      /*for(int j=0;j<sec.size();j++){
        cout << "(" << sec[j].first << "," << sec[j].second << "), ";
      }
      cout << endl;*/
      char op;
      cin >> op;
      if(op == 'W'){
        int a, b;
        cin >> a >> b;
        vector<pair<int, int> >::iterator ite;
        for(ite=sec.begin();ite!=sec.end();ite++){
          if(ite->first == -1){
            ite->first = a;
            if(b > ite->second) b -= ite->second;
            else if(b == ite->second) break;
            else{
              int tmp = ite->second - b;
              ite->second = b;
              ite++;
              sec.insert(ite, make_pair(-1, tmp));
              break;
            }
          }
        }
      }else if(op == 'R'){
        int in;
        cin >> in;
        int p = -1;
        for(int j=0;j<sec.size();j++){
          p += sec[j].second;
          if(p >= in){
            cout << sec[j].first << endl;
            break;
          }
        }
      }else if(op == 'D'){
        int in;
        cin >> in;
        for(int j=0;j<sec.size();j++) if(sec[j].first == in) sec[j].first = -1;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1304
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

    if (s[0] == 'S') {
        cout << "Cloudy" << endl;
    } else if (s[0] == 'C') {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    } 
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		while(true) {
			int l = sc.nextInt();
			if(l == 0) break;
			int n = sc.nextInt();
			int m = sc.nextInt();
			int []d = new int[n];
			int []k = new int[m];
			d[0] = 0;
			for(int i = 1; i <= n - 1; i++) {
				d[i] = sc.nextInt();
			}
			for(int i = 0; i < m; i++) {
				k[i] = sc.nextInt();
			}
			Arrays.sort(d);

			int sum = 0;
			for(int i = 0; i < m; i++) {
				int right = n;
				int left = -1;
				while(right - left > 1) {
					int mid = (right + left) / 2;
					if(d[mid] >= k[i]) {
						right = mid;
					}else {
						left = mid;
					}
				}
				//System.out.println(right);
				if(right == 0 || right == n) {
					int t1 = Math.abs(k[i] - d[0]);
					t1 = Math.min(t1, Math.abs(l - t1));
					sum += Math.min(t1, Math.abs(k[i] - d[n - 1]));
				}else {
					sum += Math.min(Math.abs(k[i] - d[right]), Math.abs(k[i] - d[right - 1]));
				}
			}
			sb.append(sum).append("\n");
		}
		sc.close();
		System.out.print(sb.toString());
	}
}


Measured memory_bytes: 67700
def grading_student(scores):
    
    for i, score in enumerate(scores):

        grade = ""
        total = score[0] + score[1]
        
        if score[0] == -1 or score[1] == -1:
            grade = "F"

        elif total >= 80:
            grade = "A"

        elif 65 <= total < 80:
            grade = "B"
            
        elif 50 <= total < 65:
            grade = "C"
        
        elif 30 <= total < 50:
            if score[2] >= 50:
                grade = "C"
            else:
                grade = "D"
        elif total < 30:
            grade = "F"

        print(grade, end="")

        #if i != len(scores) - 1:
        print("\n", end="")


if __name__ == "__main__":
    

    # create score list
    score = list()
    
    while(True):

        param = input().split(" ")

        s = [ int(a) for a in param ]

        if s[0] == -1 and s[1] == -1 and s[2] == -1:
            break
        else:
            score.append(s)
            

    grading_student(score)


Measured memory_bytes: 5628
import fractions

MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
u = sorted(set(a))
if len(u) == 1:
    print(n)
    exit()
else:
    g = 1
    for x in u:
        g = (g * x) // fractions.gcd(g, x)
    b = 0
    for i in range(n):
        b = b + (g // a[i])
print(b%MOD)

Measured memory_bytes: 6584
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
	ll n,k;cin>>n>>k;
	ll a[n];rep(i,0,n)cin>>a[i];
	// dp[i] : 残り石がi個の時に負けるならfalse
	bool dp[k+1];rep(i,0,k+1)dp[i] = false;
	// 残り石がi個の時に、Aの元を選択することでfalseとなるマスに押し付けられるか？
	rep(i,1,k+1){
		for(ll x : a)
			if(i-x >=0)
				dp[i] |= !dp[i-x];
	}
	cout << (dp[k] ? "First" : "Second") << ednl;

}

Measured memory_bytes: 384
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline
def solve():
  inf = float("Inf")
  n,m,l = (int(i) for i in input().split())
  path = [[-1*inf]*n for _ in range(n)]
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
  d = floyd_warshall(path)
  q = int(input())
  minipath = [[-1*inf]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
  d2 = floyd_warshall(minipath)

  for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1)

solve()

Measured memory_bytes: 19320
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n,c,k;
    cin >> n >> c >> k;
    vector<ll> t(n,0);
    rep(i,n)cin >> t[i];
    sort(begin(t),end(t));
    ll res = 0;
    for(ll i = 0;i<n;){
        res++;
        ll s = i;
        while(i<n && t[i] - t[s] <= k && i-s < c)++i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long X,A,B;
    cin>>X;
    for(long long i=-200;i<200;i++){
    for(long long j=-200;j<200;j++){
    A=i*i*i*i*i;
    B=j*j*j*j*j;
    if(A-B==X){
    cout<<i<<" "<<j<<endl;
    goto as;}}}
    as:
    cout<<endl;}


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

int main() {

    int n, k;
    cin >> n >> k;
    vector<int> A(n);

    while(k--)
    {
        int x;
        cin >> x;

        while(x--)
        {
            int y;
            cin >> y;
            A[y-1] = 1;
        }
    }

    int ans = 0;

    for(auto a : A)
        ans += (a == 0);

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		long[] L=new long[N+1];
		int i;
		L[0]=2;
		L[1]=1;
		for(i=2;i<=N;i++) {
			L[i]=L[i-2]+L[i-1];
		}
		System.out.println(L[N]);
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//使う前にCOMinit
//最大に注意！！！！！！！！！！！！！！！

int main() {
    COMinit();
    ll n,k;
    cin>>n>>k;
    vll a;
    rep(i,n){
        ll aa;
        cin>>aa;
        a.push_back(aa);
    }
    map<ll,ll> d;
    sort(all(a));
    rep(i,n){
        if (d.count(a[i])){
            d[a[i]]+=1;
        }
        else d[a[i]]=1;
    }
    map<ll,ll> d1,d2;
    //d1[i]はiより小ささものの個数
    d1[a[0]]=0;
    int num=0;
    for (int i=1;i<n;i++){
        num+=1;
        if (a[i]==a[i-1])continue;
        else{
            d1[a[i]]=num;
            //cout<<a[i]<<" "<<num<<endl;
        }
    }
    d2[a[n-1]]=0;
    num=0;
    for (int i=n-2;i>=0;i--){
        num+=1;
        if (a[i]==a[i+1])continue;
        else {
            d2[a[i]]=num;
            //cout<<a[i]<<" "<<num<<endl;
            }
    }
    ll m1=0,m2=0;
    a.push_back(1e9+1);
    rep(i,n){
        if (a[i]==a[i+1])continue;
        else{
            if (n-d2[a[i]]<k)continue;
            else{
                if (n-d2[a[i]]-d[a[i]]<k)m1+=COM(n-d2[a[i]],k)*a[i];
                else m1+=(COM(n-d2[a[i]],k)-COM(n-d2[a[i]]-d[a[i]],k))*a[i];
                m1%=MOD;
            }
        }
    }
    rep(i,n){
        if (a[i]==a[i+1])continue;
        else if (n-d1[a[i]]<k)continue;
        else {
            if (n-d1[a[i]]-d[a[i]]<k)m2+=COM(n-d1[a[i]],k)*a[i];
            else m2+=(COM(n-d1[a[i]],k)-COM(n-d1[a[i]]-d[a[i]],k))*a[i];
            m2%=MOD;
        }
    }
    cout<<(m1-m2+MOD*10)%MOD<<endl;

    

    return 0;
}

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

long long N, K;
vector<long long> sumV(100001);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int N;
  cin >> N;
  cout << (1 + N) * N / 2 <<endl;
}


Measured memory_bytes: 1024
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  // vector<pll> ps(n);
  // rep(i,n) ps[i]=pll(a[i],i);
  sort(all(a));
  ll sum=accumulate(all(a),0ll)-a.back();
  int re=1;
  rrep(i,n-1){
    if(sum*2<a[i+1]) break;
    sum-=a[i];
    ++re;
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  long long la,lb;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b >>c;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  //if(a > 9 || b > 9) ans = -1;
  //else ans = a*b;
  
  if(a+b+c > 21)anss = "bust";
  else anss = "win";

  cout << anss << endl;

}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<double> x(N);
	vector<string> u(N);

	double Y=0;

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

	for (int i = 0;i < N;i++) {
		if (u[i] == "JPY") {
			Y += x[i];
		}
		else if(u[i] == "BTC") {
			Y += x[i] * 380000.0;
		}
	}
	cout << Y << endl;
}


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

int array[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;

void Solve()
{
  cout << array[K - 1] << endl;
}

void Init()
{
  cin >> K;
}

void Clean(){}

int main(){ Init(); Solve(); Clean(); return 0; }


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF){
        int m = a, n = b;
        int r = m % n;
        while(r != 0){
            m = n;
            n = r;
            r = m % n;
        }
        int gcd = n;
        int icm = a / n *b;
        printf("%d %d\n",gcd,icm);
    }
}



Measured memory_bytes: 2000
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int inf=1000000007;
int max2(int a,int b){
  int ans=a;
  if(ans<b)ans=b;
  return ans;
}
int dp[3050][3050];
int main(){
  int n,t;
  cin>>n>>t;
  vector<int> a(n+1);
  vector<int> b(n+1);
  rep1(i,n){
    cin>>a[i]>>b[i];
  }
  rep(i,n+5){
    rep(j,t+5){
      dp[i][j]=0;
    }
  }
  rep1(i,n){
    rep(j,t+1){
      if(j-a[i]>=0)
      dp[i][j]=max2(dp[i-1][j],dp[i-1][j-a[i]]+b[i]);
      else dp[i][j]=dp[i-1][j];
    }
  }
  int max=0;
  int tmp;
  rep1(i,t-1){
    if(max<dp[n][i]){
      max=dp[n][i];
      tmp=i;
    }
  }
  int tmp_max=tmp;
  vector<int> list(n+1,0);
  for(int i=n;i>0;i--){
    if(dp[i][tmp]!=dp[i-1][tmp]){
      tmp-=a[i];
      list[i]++;
      //      cout<<i<<endl;
    }
  }
  int add=0;
  rep1(i,n){
    if(list[i]==0){
      if(b[i]>add)add=b[i];
    }
  }
  int ans=max2(dp[n][t],max+add);
  cout<<ans<<endl;
  return 0;
}


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

#define ll long long
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long N;
	cin >> N;
	vector<long long> d;
	for(ll i = 1;i*i<=N;i++){
		if(N%i==0)d.push_back(i);
	}
	int ans = 1e9;
	for(auto x:d){
		int temp = 0;
		int temp2= 0;
		long long first = x;
		long long second= N/x;
		while(first){
			temp++;
			first /=10;
		}
		while(second){
			temp2++;
			second /=10;
		}
		ans = min(ans,max(temp,temp2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(auto c:s){
        int num = (int)(c-'A');
        if(num+n>=26){
            num = num + n - 26;
        }else{
            num += n;
        }
        char ans = (char)('A' + num);
        cout << ans;
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main(){
      int a, b, m;
      cin >> a >> b >> m;
      int x[a], y[b], xi[m], yi[m], c[m];
      for(int i = 0; i < a; i++)
        cin >> x[i];
      for(int i = 0; i < b; i++)
        cin >> y[i];
      for(int i = 0; i < m; i++)
        cin >> xi[i] >> yi[i] >> c[i];
      int p = 200000;
      for(int i = 0; i < m; i++)
        if(p > x[xi[i]-1]+y[yi[i]-1]-c[i])
          p = x[xi[i]-1]+y[yi[i]-1]-c[i];
      sort(x, x+a);
      sort(y, y+b);
      int i = 0;
      while(p > x[i]+y[i]){
        p = x[i]+y[i];
        i++;
      }
      cout << p;
      return 0;
    }

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

args = input().split()
n = int(args[0])
m = int(args[1])
ok = [False] * n
ng = [0] * n
for _ in range(m):
    target, score = input().split()
    target = int(target) - 1
    if score == 'AC':
        ok[target] = True
    else:
        if not ok[target]:
            ng[target] += 1

ok_cnt = 0
ng_cnt = 0
for i in range(n):
    if ok[i]:
        ok_cnt += 1
        ng_cnt += ng[i]
print(ok_cnt, ng_cnt)

Measured memory_bytes: 4596
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let arr = scan_array ~sep:' ' Int.of_string

let () =
  let arr = ArrayL.mapi arr ~f:(fun i v -> (v, succ i)) in
  Array.sort (fun a b ->  Tuple2.compare a b |> Int.neg) arr;
  let dp = Array.make_matrix (succ n) (succ n) (-1) in
  dp.(0).(0) <- 0;
  ListL.iter (1++n) ~f:(fun i ->
      ListL.iter (0++i) ~f:(fun j ->
          let (a, k) = arr.(pred i) in
          let left = j in
          let right = n - (i-1-j) in
          dp.(i).(j) <-
            if j = 0 then dp.(i-1).(j) + a * abs (right - k)
            else
              max (dp.(i-1).(j-1) + a * abs (left - k))
                (if dp.(i-1).(j) >= 0 then dp.(i-1).(j) + a * abs (right - k) else -1)));
  (* Array.print  (Tuple2.print Int.print Int.print) stderr arr;
   * Array.print ~sep:"\n" (Array.print Int.print) stderr dp; *)
  Printf.printf "%d\n" @@ Array.max dp.(n)


Measured memory_bytes: 39728
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
#include<queue>
typedef long long LL;

using namespace std;



int main(void) {
	LL n, k;
	cin >> n >> k;
	vector<LL>a(n), b(n);
	map<LL, LL>m;
	for (LL i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		m[a[i]] += b[i];
	}
	sort(a.begin(), a.end());
	for (LL i = 0; i <= 1e5; i++) {
		if (k - m[i] <= 0) {
			cout << i;
			return 0;
		}
		k -= m[i];
	}
	return 0;
}

Measured memory_bytes: 8064
n, k, q = map(int, input().split())
l = [0]*n
ans = 0

for i in range(q):
    a = int(input())
    l[a - 1] += 1

for i in range(n):
    if k - q + l[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4680
n = gets.chomp.to_i
ary = gets.chomp.split.map(&:to_i)

mean = ary.inject(:+)/(ary.length*1.0)

min = Float::INFINITY
index = 0
ary.each_with_index do |item,i|
  item -= mean
  if item.abs < min
    min = item.abs
    index = i
  end
end

puts index


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

int main(){
  string s;
  cin >> s;
  int slen=s.length();
  int go=0, pa=0;
  ll ans=0;
  for(int i=0;i<slen;i++){
    if(s[i]=='g'){
      if(go>pa){
        ans++;
        pa++;
      }else{
        go++;
      }
    }else{
      if(go>pa){
        pa++;
      }else{
        ans--;
        go++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

long long const N = 5e5 + 1, M = 1e9 + 7;
long long fn[N], fd[N], iv[N];

void initnck(){
    iv[1] = fn[1] = fd[1] = fn[0] = fd[0] = 1;
    for (long long i=2; i<N; i++){
        iv[i] = (M - (M/i) * iv[M%i] % M) % M;
        fn[i] = fn[i-1]*i%M;
        fd[i] = fd[i-1]*iv[i]%M;
    }
}

long long nck(long long n, long long k){
    return fn[n] * fd[n-k] % M * fd[k] % M;
}

void solvetask(){
    initnck();
    long long n,m; cin >> n >> m;
    long long ans = fn[m] * fd[m - n] % M;
    for (int i=1; i<=n; i++){
        if (i & 1) ans = (ans - nck(n, i) * fn[m - i] % M * fd[m - n] % M + M)%M;
        else ans = (ans + nck(n, i) * fn[m - i] % M * fd[m - n] % M)%M;
    }
    cout << ans * fn[m] % M * fd[m - n] % M << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solvetask();
}

Measured memory_bytes: 15360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int W,H,x,y,r;
		Scanner scanner = new Scanner(System.in);
		W = scanner.nextInt();
		H = scanner.nextInt();
		x = scanner.nextInt();
		y = scanner.nextInt();
		r = scanner.nextInt();

		if(y >= r && y <= H-r && x >=r && x <= W-r){
			System.out.printf("Yes\n");
		}else{
			System.out.printf("No\n");
		}

	}
}



Measured memory_bytes: 26404
#include <cstdio>
#define MOD 1000000007
typedef long long LL;

int n;
LL a = 1, b = 1, c = 1;

int main() {
    scanf("%d", &n);
    for (int i = 0 ; i < n ; i++) {
        a *= 10, b *= 9, c *= 8;
        a %= MOD, b %= MOD, c %= MOD;
    }
    a -= b;
    if (a < 0) a += MOD;
    a -= b;
    if (a < 0) a += MOD;
    a += c;
    a %= MOD;
    printf("%lld", a);
}


Measured memory_bytes: 1736
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX = 200000 + 10;
int R[MAX];

int main()
{
    int n;
    while (scanf("%d", &n) == 1){
        for (int i = 0; i < n; i++)
        scanf("%d", &R[i]);

        int maxv = -2000000000;
        int minv = R[0];

        for (int i = 1; i < n; i++) {
            maxv = max(maxv, R[i] - minv);
            minv = min(minv, R[i]);
        }
        
        printf("%d\n", maxv);
        }

    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

int main(){
  int n;
  cin >> n;
  REP(i, n){
    string var1, var2;
    cin >> var1 >> var2;
    int v1 = 0;
    int v2 = 0;
    int tmp = 1;
    REP(j, var1.size()){
      if(var1[j] == 'm') { v1 += tmp * 1000; tmp = 1; }
      else if(var1[j] == 'c') { v1 += tmp * 100; tmp = 1; }
      else if(var1[j] == 'x') { v1 += tmp * 10; tmp = 1; }
      else if(var1[j] == 'i') { v1 += tmp; tmp = 1; }
      else tmp = var1[j] - '0';
    }
    REP(j, var2.size()){
      if(var2[j] == 'm') { v2 += tmp * 1000; tmp = 1; }
      else if(var2[j] == 'c') { v2 += tmp * 100; tmp = 1; }
      else if(var2[j] == 'x') { v2 += tmp * 10; tmp = 1; }
      else if(var2[j] == 'i') { v2 += tmp; tmp = 1; }
      else tmp = var2[j] - '0';
    }
    int sum = v1 + v2;
    string res = "0m0c0x0i";
    res[0] = sum / 1000 + '0'; sum %= 1000;
    res[2] = sum / 100 + '0'; sum %= 100;
    res[4] = sum / 10 + '0'; sum %= 10;
    res[6] = sum + '0';
    REP(i, 8){
      if(res[i] == '0') { i++; continue; }
      if(res[i] == '1') { continue; }
      cout << res[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long t= 0, u = 0;
  for (long long a = 1; a < n; a++)
  {
    for (long long b = a; b < n; b++)
    {
      if (a*b <n)
      {
        t++;
        if (a == b)
        {
          u++;
        }
        
      }else
      {
        break;
      }
      
      
    }
    
    
  }
  cout << t*2-u << endl;
  return 0;
}

Measured memory_bytes: 3632
char out[1001000];
char buf[100];
sz,k;
H,W,A,B;
main()
{
	read(0,buf,100);
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		H=H*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		W=W*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		A=A*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		B=B*10+k-'0';
	}
	sz=0;
	for(int i=0;i<H;++i)
	{
		for(int j=0;j<W;++j)
		{
			out[sz++]='0'|i<B^j<A;
		}
		out[sz++]='\n';
	}
	write(1,out,sz);
}

Measured memory_bytes: 2048