akhauriyash/Code-Regression huggingface dataset:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]

dist = 0
difs = [0]*N
for i, a in enu(A[:-2]):
    c = a
    n = A[i+1]
    nn = A[i+2]
    dist += abs(n-c)

    dif = 0 # 消したときに減る量
    flg_dif = (c<=n)^(n<=nn)
    if flg_dif:
        difs[i] = min(2*abs(n-c), 2*abs(nn-n))
dist += abs(A[-2])

# print('dist', dist)
# print('difs', difs)
for i, a in enu(A[1:-1]):
    print(dist-difs[i])


Measured memory_bytes: 90436
N,K = map(int,input().split())
import sys
if N==1:
    print(input())
    sys.exit()
list = input().split()
MIN = 1001
SUM = 0
for j in range(0,K):
  for i in list:
    if MIN > int(i):
      MIN = int(i)
  list.remove(str(MIN))
  SUM += MIN
  MIN = 1001
print(SUM)


Measured memory_bytes: 9212
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int x[60][20], y[60][20]; // n=0?????¢??????
int m[60];
int dy[20], dx[20];

bool check(int i, int deg) {
  bool ok = true;
  if(deg==0) {
    ok = true;
    FOR(j,0,m[0]-1) {
      if(dy[j] != y[i][j+1] - y[i][j]) ok = false;
      if(dx[j] != x[i][j+1] - x[i][j]) ok = false;
    }
    if(ok) return true;
    ok = true;
    for(int j = m[0] - 1; j > 0; j--) {
      if(dy[m[0] - 1 - j] != y[i][j-1] - y[i][j]) ok = false;
      if(dx[m[0] - 1 - j] != x[i][j-1] - x[i][j]) ok = false;
    }
    if(ok) return true;
  }
  if(deg==90) {
    ok = true;
    FOR(j,0,m[0]-1) {
      if(-dx[j] != y[i][j+1] - y[i][j]) ok = false;
      if(dy[j] != x[i][j+1] - x[i][j]) ok = false;
    }
    if(ok) return true;
    ok = true;
    for(int j = m[0] - 1; j > 0; j--) {
      if(-dx[m[0] - 1 - j] != y[i][j-1] - y[i][j]) ok = false;
      if(dy[m[0] - 1 - j] != x[i][j-1] - x[i][j]) ok = false;
    }
    if(ok) return true;
  }
  if(deg==180) {
    ok = true;
    FOR(j,0,m[0]-1) {
      if(-dy[j] != y[i][j+1] - y[i][j]) ok = false;
      if(-dx[j] != x[i][j+1] - x[i][j]) ok = false;
    }
    if(ok) return true;
    ok = true;
    for(int j = m[0] - 1; j > 0; j--) {
      if(-dy[m[0] - 1 - j] != y[i][j-1] - y[i][j]) ok = false;
      if(-dx[m[0] - 1 - j] != x[i][j-1] - x[i][j]) ok = false;
    }
    if(ok) return true;
  }
  if(deg==270) {
    ok = true;
    FOR(j,0,m[0]-1) {
      if(dx[j] != y[i][j+1] - y[i][j]) ok = false;
      if(-dy[j] != x[i][j+1] - x[i][j]) ok = false;
    }
    if(ok) return true;
    ok = true;
    for(int j = m[0] - 1; j > 0; j--) {
      if(dx[m[0] - 1 - j] != y[i][j-1] - y[i][j]) ok = false;
      if(-dy[m[0] - 1 - j] != x[i][j-1] - x[i][j]) ok = false;
    }
    if(ok) return true;
  }
  return false;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(cin>>n,n) {
    n++;
    FOR(i,0,n) {
      cin >> m[i];
      FOR(j,0,m[i]) cin >> x[i][j] >> y[i][j];
    }
    FOR(i,0,m[0]-1) {
      dy[i] = y[0][i+1] - y[0][i];
      dx[i] = x[0][i+1] - x[0][i];
    }
    FOR(i,1,n) {
      if(m[0] == m[i]) {
        if(check(i,0)||check(i,90)||check(i,180)||check(i,270)) {
          cout << i << endl;
        }
      }
    }
    cout << "+++++" << endl;
  }
  return 0;
}

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

int main() {
	char s[5];
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
	else cout << "Good" << endl;
	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-3)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

int d,bc[(1<<10)];
double answer[10];

typedef vector<double> vd;
typedef vector<vd> mat;

vector<double> gauss_jordan(const mat& A,const vd& b){
  int n = A.size();
  mat B(n,vd(n+1));
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) B[i][j] = A[i][j];

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

  for(int i=0;i<n;i++) {
    int pivot = i;
    for(int j=i;j<n;j++) if( abs(B[j][i]) > abs(B[pivot][i]) ) pivot = j;
    swap(B[i],B[pivot]);
    if( abs(B[i][i]) < EPS ) return vd();
    
    for(int j=i+1;j<=n;j++) B[i][j] /= B[i][i];
    for(int j=0;j<n;j++) {
      if( i != j )  {
        for(int k=i+1;k<=n;k++) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }
  vd x(n);
  for(int i=0;i<n;i++) x[i] = B[i][n];
  return x;
}

inline double f(const vector<double> &coef,double x){
  double ret = coef.back();
  double multi = x;
  for(int i=(int)coef.size()-2;i>=0;i--) { ret += coef[i] * x; x = x * multi; }
  return ret;
}

bool isValid(const vector<double> &x,const vector<double> &v,int sp,int bitmask,const int wrong){
  if( bc[bitmask] >= d+1 ) {
    vector<vector<double> > A;
    vector<double> b;
    rep(i,d+3) {
      if( (bitmask>>i) & 1 ) {
        b.push_back(v[i]);
        vector<double> tmp;
        tmp.push_back(1);
        rep(j,d) tmp.push_back(tmp.back()*x[i]);
        reverse(tmp.begin(),tmp.end());
        A.push_back(tmp);
      }
    }
    vector<double> coef = gauss_jordan(A,b);

    if( coef.empty() ) return false; // 
    rep(i,d+3) if( i != wrong && !equals(answer[i],f(coef,i)) ) return false;
    return true;
  }
  REP(i,sp,(int)x.size()) if( !isValid(x,v,i+1,bitmask|(1<<i),wrong) ) return false;
  return true;
}

int main(){
  rep(i,(1<<10)) bc[i] = __builtin_popcount(i);
  while( cin >> d, d ){
    rep(i,d+3) cin >> answer[i];
    rep(wrong,d+3){
      vector<double> x,v;
      rep(i,d+3) if( i != wrong ) x.push_back(i), v.push_back(answer[i]);
      if( isValid(x,v,0,0,wrong) ) {
        printf("%d\n",wrong);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1248
N = gets.to_i
as = [nil] + gets.split.map(&:to_i)
bs = Array.new(N/2+1) { nil } + as[N/2+1..-1]

(N/2).step(1, -1) do |i|
  sum = 0
  ratio = 2
  until i * ratio > N
    sum += bs[i * ratio]
    ratio += 1
  end

  if as[i] == sum % 2
    bs[i] = 0
  else
    bs[i] = 1
  end

end

# p bs

puts bs.count(1)
answer_array = bs.map.with_index { |b, i| b == 1 ? i : nil }.compact
puts answer_array.join(" ") unless answer_array.empty?


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

unordered_map<string, int> judge{
    {"RE", 0},
    {"TLE", 0},
    {"WA", 0},
    {"AC", 0}
};

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    
    string input;
    REPinit(i,0,N) {
        cin >> input;
        judge[input]++;
    }

    for(auto j : judge) {
        cout << j.first << " x " << j.second << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if(a >= b && a >= c)
    cout << b + c;
  if(b > a && b >= c)
    cout << a + c;
  if(c > a && c > b)
    cout << a + b;
  return 0;
}

Measured memory_bytes: 3612
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] t = new long[N];
		long T = sc.nextLong();
		for (int i = 0; i < N; ++i) {
			t[i] = sc.nextLong();
		}
		long ans = 0;
		ans = 0;
		ans += T;
		for (int i = N - 2; i >= 0; --i) {
			if (t[i + 1] - t[i] < T) {
				ans += t[i + 1] - t[i];
			} else {
				ans += T;
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 67072
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) {
    t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin>>N;
    long double a;
    vector<int> d2(N), d5(N);
    auto plane = make_v<ll>(19, 19);
    for (size_t i = 0; i < N; i++)
    {
        cin>>a;
        ll tmp = llround(a*1e9);
        ll tmp2 = tmp;
        while (tmp%2==0)
        {
            d2[i]++;
            tmp /=2;
        }
        tmp=tmp2;
        while (tmp%5==0)
        {
            d5[i]++;
            tmp/=5;
        }
        plane[min(18, d2[i])][min(18, d5[i])]++;
    }
    ll ans=0;
    for (size_t i = 0; i < 19; i++)
    {
        for (size_t j = 0; j < 19; j++)
        {
            for (size_t i2 = 0; i2 < 19; i2++)
            {
                for (size_t j2 = 0; j2 < 19; j2++)
                {
                    if (i+i2 >= 18 and j + j2 >= 18)
                    {
                        ans+= plane[i][j]*plane[i2][j2];
                        if (i==i2 and j == j2)
                            ans -= plane[i][j];
                    }

                }

            }

        }

    }

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

Measured memory_bytes: 4828
#include <iostream>
#include <stdlib.h>

using namespace std;

int binarySearch(int *arr, int size, int target) {
    int left = 0;
    int right = size;
    while (left < right) {
        int mid = (left + right) / 2;
        if (*(arr + mid) == target) {
            return 1;
        } else if (target < *(arr + mid)) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}

int main() {

    int numS;
    cin >> numS;

    int *arrS = (int*) malloc(numS * sizeof(int));
    for (int i = 0; i < numS; i++) {
        cin >> arrS[i];
    }

    int numT;
    cin >> numT;
    int count = 0;
    for (int i = 0; i < numT; i++) {
        int current;
        cin >> current;
        count += binarySearch(arrS, numS, current);
    }

    free(arrS);

    cout << count;
    cout << endl;

    return 0;
}



Measured memory_bytes: 3124
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []

    D = []
    for i in range(M):
        b, c = map(int, input().split())
        BC.append((b, c))
    BC.sort(key=lambda x: x[1], reverse=True)
    ld = 0
    for b, c in BC:
        D += [c] * b
        ld += b
        if ld > N:
            break
    
    res = 0
    A.sort()
    for i in range(N):
        if i < ld:
            res += max(A[i], D[i])
        else:
            res += A[i]
    

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 24044
from fractions import gcd
from collections import Counter
slope=Counter()
slope_zero=0
slope_inf=0
both_zero=0
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        both_zero+=1
    else:
        if a==0:
            slope_zero+=1
        elif b==0:
            slope_inf+=1
        else:
            sign=(a//abs(a))*(b//abs(b))
            a=abs(a)
            b=abs(b)
            gc=gcd(a,b)
            a//=gc
            b//=gc
            if sign==1:
                slope[(a,b)]+=1
            else:
                slope[(-a,b)]+=1
ans=1
mod=10**9+7
for a,b in slope.keys():
    if slope[(a,b)]>0:
        aa=-b
        bb=a
        if bb<0:
            bb*=-1
            aa*=-1
        if slope[(aa,bb)]>0:
            ans*=(pow(2,slope[(a,b)],mod)+pow(2,slope[(aa,bb)],mod)-1+mod)%mod
            ans%=mod
            slope[(aa,bb)]=0
        else:
            ans*=(pow(2,slope[(a,b)],mod))%mod
            ans%=mod
ans*=(pow(2,slope_zero,mod)+pow(2,slope_inf,mod)-1+mod)%mod
ans%=mod
ans+=both_zero
if ans>=mod:
    ans%=mod
print((ans-1+mod)%mod)




Measured memory_bytes: 47924
N,M=map(int,input().split())
original_paths={}
paths={}
for n in range(1,N+1):
    original_paths[n]=[]
    paths[n]=[]
for m in range(1,M+1):
    s,e=map(int,input().split())
    original_paths[s].append(e)
    original_paths[e].append(s)
    paths[s].append(e)
    paths[e].append(s)#以上地図作り
    
visited=[1]
current_point=1
answer=0

while len(paths[1])!=0:#すべてのルートを探索済み==点1から動けない
    
    if len(paths[current_point])!=0:
        next_point=paths[current_point][0]
    
        if next_point in visited:#next_pointに行ったことがある

            if len(paths[current_point])!=1:#next_point以外に選択肢がある
                paths[current_point].remove(next_point)#next_pointを選択肢から消す

            else:#next_point以外に選択肢がない(current_pointは行き止まり)
                if len(visited)==N:#すべての点を訪れたかチェック
                    answer+=1
                prior_point=visited[-2]#ひとつ前にいた点をprior_pointとし、
                paths[current_point]=original_paths[current_point].copy()#current_pointからの選択肢を初期化
                paths[prior_point].remove(current_point)#prior_pointの選択肢からcurrent_pointを除く
                visited.remove(current_point)#current_pointをvisitedから除き、
                current_point=prior_point#prior_pointに戻る

        else:#next_pointに行ったことがない
            visited.append(next_point)#next_pointをvisitedに加え、
            current_point=next_point#next_pointに進む

    else:
        prior_point=visited[-2]#ひとつ前にいた点をprior_pointとし、
        paths[current_point]=original_paths[current_point].copy()#current_pointからの選択肢を初期化
        paths[prior_point].remove(current_point)#prior_pointの選択肢からcurrent_pointを除く
        visited.remove(current_point)#current_pointをvisitedから除き、
        current_point=prior_point#prior_pointに戻る
        
print(answer)


Measured memory_bytes: 3064
a, b = map(int,input().split())
s = input()
for c in range(len(s)):
  if c < a:
    if s[c] != '-':
      continue
    else:
      break
  elif c == a:
    if s[c] == '-':
      continue
    else: break
  elif c < a+b+1:
    if s[c] != '-':
      continue
    else: break
  else:break
else:
  print('Yes')
  exit(0)
print('No')
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	rep(i, ty-sy) cout << "U";
	rep(i, tx-sx) cout << "R";
	rep(i, ty-sy) cout << "D";
	rep(i, tx-sx+1) cout << "L";
	rep(i, ty-sy+1) cout << "U";
	rep(i, tx-sx+1) cout << "R";
	cout << "DR";
	rep(i, ty-sy+1) cout << "D";
	rep(i, tx-sx+1) cout << "L";
	cout << "U";
	
	return 0;
}

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

using namespace std;

int main(){
    long long N,A,B;
    cin >> N >> A >> B;
    vector<long long> X(N);
    for(int i=0; i<N; i++){
        cin >> X[i];
    }

    long long ans=0;
    for(int i=1; i<N; i++){
        if((X[i]-X[i-1])*A>B){
            ans+=B;
        }else{
            ans+=(X[i]-X[i-1])*A;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
const int N=2e5 + 5;
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a;double b;
    cin>>a>>b;
    int c=100*b+0.5;
    ll ans=a*c;
    //cout<<b<<" "<<ans<<endl;
    ans=ans/100;
    ll ans1=(ll)ans;
    cout<<ans1;


    return 0;
}


Measured memory_bytes: 3736
#include <cstdio>
#include <inttypes.h>
#include <cstdlib>
#include <queue>
#include <vector>
#include <set>
#include <cctype>

uint64_t read_uint64(void) {
	uint64_t result = 0;
	int c;
	while (!isdigit(c = getchar()) && c != EOF);
	if (c == EOF) exit(1);
	do {
		result = result * 10 + (c - '0');
		c = getchar();
	} while (isdigit(c));
	return result;
}

void print_uint64(uint64_t c) {
	if (c > 9) print_uint64(c / 10);
	putchar(c % 10 + '0');
}

/* desc */
int cmp(const void* asumisu, const void* mizuhasu) {
	uint64_t nakazimamegumi = *(const uint64_t*)asumisu;
	uint64_t tiharaminori = *(const uint64_t*)mizuhasu;
	if (nakazimamegumi > tiharaminori) return -1;
	return nakazimamegumi < tiharaminori;
}

#define MAX 1024

int X, Y, Z, K;
uint64_t A[MAX], B[MAX], C[MAX];

struct kitaeri {
	int xidx, yidx, zidx;

	kitaeri() : xidx(0), yidx(0), zidx(0) {}
	kitaeri(int xi, int yi, int zi) : xidx(xi), yidx(yi), zidx(zi) {}

	std::vector<kitaeri> getNext() const {
		std::vector<kitaeri> result;
		if (xidx + 1 < X) result.push_back(kitaeri(xidx + 1, yidx, zidx));
		if (yidx + 1 < Y) result.push_back(kitaeri(xidx, yidx + 1, zidx));
		if (zidx + 1 < Z) result.push_back(kitaeri(xidx, yidx, zidx + 1));
		return result;
	}

	uint64_t value() const {
		return A[xidx] + B[yidx] + C[zidx];
	}

	bool operator<(const kitaeri& k) const {
		return value() < k.value();
	}
};

struct kugyu {
	kitaeri k;
	kugyu() {}
	kugyu(const kitaeri& kk) : k(kk) {}

	bool operator<(const kugyu& o) const {
		if (k.xidx != o.k.xidx) return k.xidx < o.k.xidx;
		if (k.yidx != o.k.yidx) return k.yidx < o.k.yidx;
		return k.zidx < o.k.zidx;
	}
};

int main(void) {
	int i;
	if (scanf("%d%d%d%d", &X, &Y, &Z, &K) != 4) return 1;
	for (i = 0; i < X; i++) {
		//if (scanf("%" SCNu64, &A[i]) != 1) return 1;
		A[i] = read_uint64();
	}
	for (i = 0; i < Y; i++) {
		//if (scanf("%" SCNu64, &B[i]) != 1) return 1;
		B[i] = read_uint64();
	}
	for (i = 0; i < Z; i++) {
		//if (scanf("%" SCNu64, &C[i]) != 1) return 1;
		C[i] = read_uint64();
	}
	qsort(A, X, sizeof(*A), cmp);
	qsort(B, Y, sizeof(*B), cmp);
	qsort(C, Z, sizeof(*C), cmp);

	std::priority_queue<kitaeri> Q;
	std::set<kugyu> visited;
	Q.push(kitaeri(0, 0, 0));
	visited.insert(kugyu(Q.top()));
	for (int i = 0; i < K && !Q.empty(); i++) {
		//printf("%" PRIu64 "\n", Q.top().value());
		print_uint64(Q.top().value()); putchar('\n');
		std::vector<kitaeri> next = Q.top().getNext();
		Q.pop();
		for (std::vector<kitaeri>::iterator itr = next.begin(); itr != next.end(); itr++) {
			if (visited.find(kugyu(*itr)) == visited.end()) {
				Q.push(*itr);
				visited.insert(kugyu(*itr));
			}
		}
	}

	return 0;
}

/*
1000 100 5
101 2 1

0
(1000, 100)
1
(1000, 2) (101, 100)
2
(1000, 1) (100, 2) (5, 101)

(0, 0)
(0, 1)        (1, 0)
(1, 1) (0, 2) (2, 0) (1, 1)
*/


Measured memory_bytes: 764
#include <iostream>
#include <math.h>
using namespace std;
 
int main(){
  double a,b,n;
  cin>>a>>b>>n;
  if (n<b){
    double answer = floor(a*n/b) - a*floor(n/b);
    int answer2 = (int)answer;
    cout << answer2<<endl;
  } else{
    double answer = floor(a*(b-1)/b) - a*floor((b-1)/b);
    int answer2 = (int)answer;
    cout << answer2 << endl;
  }
  return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define f(i,q,a) for(long long i=q; i<a; i++)
#define ll long long
#define pb push_back
#define mod 1000000007
using namespace std;
int main()
{
    string s;
    cin>>s;
    ll m=0, q=0;
    f(i,0,s.size())
    {
        if(s[i]=='R')q++;
        else m=max(m,q), q=0;
    }
    m=max(m,q);
    cout<<m<<endl;
}


Measured memory_bytes: 3624
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

h, w = rm()
print('#' * (w+2))
for _ in range(h):
    print('#' + rr() + '#')
print('#' * (w+2))











Measured memory_bytes: 27156
n = int(input())
a = [int(i) // 400 for i in input().split()]
from collections import Counter
rate=Counter(a)
b,cnt = 0, 0
for k,v in rate.items():
    if k < 8:
        cnt += 1
    else:
        b += v
print(max(cnt,1), cnt+b)

Measured memory_bytes: 3316
fn main() {
    let (n, k): (usize, i64) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let a: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut left = 0;
    let mut right = 1_000_000_000;
    while right - left > 1 {
        let mid = (left + right) / 2;
        let mut sum = 0;
        for i in 0..n {
            sum += (a[i] + mid - 1) / mid - 1;
        }
        if sum <= k {
            right = mid;
        } else {
            left = mid;
        }
    }
    println!("{}", right);
}

Measured memory_bytes: 5716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = 0;
		double b = 0;
		for(int i=0; i<N; i++) {
			a = sc.nextInt();
			b += 1.0/a;
		}
		sc.close();
		double c = 1/b;
		System.out.println(c);

	}

}

Measured memory_bytes: 23764
#include <iostream>

int main()
{
  int x = 0, max = 0;
  int n;
  char s[101];
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++)
  {
    if (s[i] == 'I')
    {
      x++;
      max = max < x ? x : max;
    }
    else
    {
      x--;
    }
  }
  std::cout << max << std::endl;
}

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

typedef struct binaryHeap{
  void *h;
  size_t heapSize;
  size_t maxSize;
  size_t size;
  int (*cmp)(const void *,const void *);
} heap;

heap* newHeap(const size_t size,int (*cmpF)(const void *,const void *)){
  const size_t maxSize=1;
  heap *res=(heap *)malloc(sizeof(heap));
  res->h=malloc(size*(maxSize+1));
  res->heapSize=0;
  res->maxSize=maxSize;
  res->size=size;
  res->cmp=cmpF;
  return res;
}

int getSize(const heap *h){
  return h->heapSize;
}

int isEmpty(const heap *h){
  return h->heapSize==0;
}

void freeHeap(heap *h){
  free(h->h);
  free(h);
  return;
}

void initHeap(heap *h){
  h->heapSize=0;
  return;
}

static inline void heapFunc_swap(void * restrict a,void * restrict b,void * restrict tmp,size_t size){
  memcpy(tmp,a,size);
  memcpy(a,b,size);
  memcpy(b,tmp,size);
  return;
}

void push(heap *q,const void *p){
  if(q->heapSize==q->maxSize){
    q->maxSize*=2;
    q->h=realloc(q->h,q->size*(q->maxSize+1));
  }
  q->heapSize+=1;
  char *h=(char *)(q->h);
  int k=q->heapSize;
  const size_t size=q->size;
  int (*cmp)(const void *,const void *)=q->cmp;
  memcpy(h+k*size,p,size);
  while(k>1){
    size_t parent=k/2;
    if(cmp(h+parent*size,h+k*size)<=0) return;
    heapFunc_swap(h+parent*size,h+k*size,h,size);
    k=parent;
  }
  return;
}

void pop(heap *q,void *res){
  char *h=(char *)(q->h);
  const size_t size=q->size;
  if(res!=NULL) memcpy(res,h+size,size);
  memcpy(h+size,h+size*q->heapSize,size);
  q->heapSize-=1;
  int (*cmp)(const void *,const void *)=q->cmp;
  const size_t n=q->heapSize;
  size_t k=1;
  while(2*k+1<=n){
    size_t next=cmp(h+2*k*size,h+(2*k+1)*size)<=0?2*k:2*k+1;
    if(cmp(h+k*size,h+next*size)<=0) return;
    heapFunc_swap(h+k*size,h+next*size,h,size);
    k=next;
  }
  if(2*k<=n && cmp(h+k*size,h+2*k*size)>0) heapFunc_swap(h+k*size,h+2*k*size,h,size);
  return;
}

void top(const heap *q,void *res){
  memcpy(res,(char *)q->h+q->size,q->size);
  return;
}

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

void run(void){
  int n,k,q;
  scanf("%d%d%d",&n,&k,&q);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  heap *h=newHeap(sizeof(int),cmp);
  int *b=(int *)calloc(n,sizeof(int));
  int ans=1000000000;
  for(i=0;i<n;i++){
    int len=0;
    int j=0;
    while(j<n){
      initHeap(h);
      while(j<n && a[j]>0) push(h,a+j++);
      while(getSize(h)>=k){
	int v;
	pop(h,&v);
	b[len++]=v;
      }
      j++;
    }
    if(len<q) break;
    qsort(b,len,sizeof(int),cmp);
    int t=b[q-1]-b[0];
    if(ans>t) ans=t;
    for(j=0;a[j]==0;j++);
    int min=j;
    for(j++;j<n;j++) if(a[j]>0 && a[j]<a[min]) min=j;
    a[min]=0;
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


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

using ll =long long;

int main() {
int N;
  cin>>N;
  string S;
  cin>>S;
  int counter=0;
  for(int i=0;i<N-2;i++){
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
      counter++;
    }
  }
  cout<<counter<<endl;
}

Measured memory_bytes: 256
using System;

class p0003
{

    static void Main(string[] args)
    {
        string[] s;
        int[] a = new int[3];


        int n = int.Parse(Console.ReadLine());

        while (0 < n--)
        {
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < 3; ++i)
            {
                a[i] = int.Parse(s[i]);
                a[i] = a[i] * a[i];
            }

            Array.Sort(a);
            Console.WriteLine((a[0] + a[1] == a[2]) ? "YES" : "NO");
        }

    }
    
}

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


int main() {
  string s,t;
  cin >> s >> t;
  int count = 0;
  rep(i,3)
    if(s[i]==t[i]) count ++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;

void solve()
{
   cin>>n;
   vector<pair<ll,ll>>v(n);
  ll f=0;
   for(ll i=0;i<n;i++)cin>>v[i].first>>v[i].second;
   for(ll i=0;i<=n-3;i++)
   {
       if(v[i].first==v[i].second and v[i+1].first==v[i+1].second and v[i+2].first==v[i+2].second)
       {f=1;break;}
   }
   cout<<((f==1)?"Yes":"No");
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    
   //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}


Measured memory_bytes: 3652
n,k=map(int,input().split())
data=[] 
for i in range(n): 
    data.append(i+1)

for i in range(k): 
    d=int(input()) 
    a=list(map(int,input().split())) 
    for j in range(d): 
        if a[j] in data: 
            data.remove(a[j]) 
        else: 
            pass 
print(len(data))

Measured memory_bytes: 67932
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long a[200000];
int main()
{
	int N;
	long long sum1 = 0, sum2 = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
		sum2 += a[i];
	}
	sum1 = a[0]; sum2 -= a[0];
	long long an = abs(sum1 - sum2);
	//printf("%lld %lld\n", sum1, sum2);
	for (int i = 1; i < N - 1; i++) {
		sum1 += a[i];
		sum2 -= a[i];
		//printf("%lld %lld\n", sum1, sum2);
		if (abs(sum1 - sum2) < an) {
			an = abs(sum1 - sum2);
		}
	}
	printf("%lld", an);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int N, T, t[210000];
    cin >> N >> T;

    ll X = 0;
    int fst = 0;
    REP(i, N)
    {
        cin >> t[i];

        if (i == 0)
        {
            fst = t[i];
        }
        else
        {
            if (t[i] - t[i - 1] > T)
            {
                X += t[i - 1] + T - fst;

                fst = t[i];
            }
        }
    }

    X += t[N - 1] + T - fst;

    cout << X << endl;

    return 0;
}

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

bool judge(int x) {
  if (x % 5 != 1) return false;
  for (int d = 3; d * d < x + 3; d += 2) {
    if (x % d == 0) return false;
  }
  return true;
}

int main() {
  int n, k = 3;
  cin >> n;
  while (true) {
    if (judge(k)) {
      cout << k;
      n--;
      if (n == 0) break;
      cout << " ";
    }
    k += 2;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int n, m, q;
int p[100010][5];
vector<int> G[100010];
int color[100010];
bool dp[100010][20];

void DP(int v, int d, int c)
{
    if(d < 0)
    return ;
	if(!dp[v][d])
	{
		for(int i=0;i<=d;i++)
		dp[v][i] = 1;
		if(!color[v])color[v] = c;
		
		for(int i=0;i<G[v].size();i++)
		DP(G[v][i], d-1, c);
      //  printf("dad");
	}
	
}

int main()
{
	while(~scanf("%d%d", &n, &m))
	{
		for(int i=1;i<=n;i++)
		G[i].clear();
		memset(color, 0, sizeof color);
		memset(dp, 0, sizeof dp);
		for(int i=1;i<=m;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			G[a].push_back(b);
			G[b].push_back(a);
		}
		
		scanf("%d", &q);
		for(int i=1;i<=q;i++)
		scanf("%d%d%d",&p[i][1], &p[i][2], &p[i][3]);
		
		for(int i=q;i>=1;i--)
		{
			DP(p[i][1], p[i][2], p[i][3]);
		}
		
		for(int i=1;i<=n;i++)
		printf("%d\n",color[i]);
	}
	return 0;
	
}

Measured memory_bytes: 10744
#include <stdio.h>
#include <string.h>

int min(int a, int b){
    return (a < b) ? a : b;
}
int main(void){
    char s[1000000];
    scanf("%s", s);
    int n = strlen(s);
    int count = 0;
    for(int i = 0; i < n; i++){
        int tmp = s[i] - '0';
        count += (tmp == i%2);
    }
    printf("%d\n", min(count, n - count));
    return 0; 
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
using namespace std;
typedef long long ll;
const ll MOD = pow(10, 9) + 7;

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}


int main() {
	int N,r=0,g=0,b=0,t=0;
	ll sum = 0;
	cin >> N;
	char S[N] = { 0 };
	int P[N] = { 0 };
	FOR(N) {
		cin >> S[i];
		if (S[i] == 'R') {
			r++;
			P[i] = 1;
		}
		if (S[i] == 'G') {
			g++;
			P[i] = 2;
		}
		if (S[i] == 'B') {
			b++;
			P[i] = 4;
		}
	}
	sum = r * g;
	sum *= b;
	for (int i = 0; i < N - 2; i++) {
		for (int j = (N - i - 1) / 2; j >0; j--) {
			t = P[i] + P[i + j] + P[i + j * 2];
			if (t == 7)
				sum--;
			t = 0;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
set<string> a;
int main(){
	int n;
	cin>>n;
	string s[n],t;
	r(i,n)cin>>s[i];
	r(i,5)r(j,n)r(k,s[j].size())
		if(k+i<=s[j].size())a.insert(s[j].substr(k,i));
	r(i,27)r(j,27)r(k,27)r(l,26){
		t="";
		if(i)t+='a'-1+i;
		if(j)t+='a'-1+j;
		if(k)t+='a'-1+k;
		t+='a'+l;
		if(!a.count(t))cout<<t<<endl,exit(0);
	}
}

Measured memory_bytes: 42696
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define debug(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define TAU PI * 2
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;

map<string, int> mp;

int main(){
    int n, m;
    cin >> n;
    string t{};
    rep(i, n){
        cin >> t;
        mp[t]++;
    }

    cin >> m;
    string s{};
    rep(i, m){
        cin >> s;
        mp[s]--;
    }

    int ans = 0;
    foreach(e, mp){
        if(e.second >= ans){
            ans = e.second;
        }
    }

    println(ans);
}

Measured memory_bytes: 256
while True:
    [a,b,c]=map(int,input().split())
    if a==-1:
        if b==-1:
            if c==-1:
                break
        grade="F"
    elif b==-1:
        grade='F'
    else:
        if a+b>=80:
            grade='A'
        elif a+b>=65 and a+b<80:
            grade='B'
        elif a+b>=50 and a+b<65:
            grade='C'
        elif a+b>=30 and a+b<50:
            if c>=50:
                grade='C'
            else:
                grade='D'
        elif a+b<30:
            grade='F'
    print(grade)


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

bool is_prime(int n)
{
    if (n == 1)
    {
        return false;
    }
    if (n == 2)
    {
        return true;
    }
    bool is_p = true;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            is_p = false;
        }
    }
    return is_p;
}

int main()
{
    int Q;
    cin >> Q;
    int l[Q], r[Q];
    for (int i = 0; i < Q; i++)
    {
        cin >> l[i] >> r[i];
    }
    vector<int> count(100001, 0);
    for (int i = 1; i <= 100000; i++)
    {
        if (is_prime(i) && is_prime((i + 1) / 2))
        {
            count[i] += count[i - 1] + 1;
        }
        else
        {
            count[i] = count[i - 1];
        }
    }

    for (int i = 0; i < Q; i++)
    {
        cout << count[r[i]] - count[l[i] - 1] << endl;
    }
}


Measured memory_bytes: 1792
def B_ss(x):
    length = 0
    for i in range(len(x) // 2):
        a = x[0:i + 1]
        b = x[i + 1: (i + 1) * 2]
        if a == b and len(a) != len(x) // 2:
            length = len(a) * 2
    return length

s = input()
print(B_ss(s))

Measured memory_bytes: 3060
N,K=map(int, input().split())
d=[0]*K
A=[0]*K
B=[0]*N
for i in range(K):
  d[i]=int(input())
  A[i]=list(map(int, input().split()))
  for j in range (d[i]):
    B[A[i][j]-1]+=1
print(B.count(0))

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

using ll = long long;

int gcd(int a, int b) {
    if(a < b)
        gcd(b, a);
    int r;
    while((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) { cin >> a[i]; }
    rep(i, n - 1) { a[i + 1] = gcd(a[i], a[i + 1]); }
    cout << a[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	ll n;
	vector<ll> d;
	
	cin>>n;
	//cout<<n<<endl;
	d.resize(n);
	for(ll i=0;i<n;i++){
		cin>>d[i];
		
	}
	ll ans=0;
	//cout<<n<<endl;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			ans+=d[i]*d[j];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int[][] d = new int[n][2];
		
		int count = 0;
		for(int i = 0; i < n; i++) {
			d[i][0] = sc.nextInt();
			d[i][1] = sc.nextInt();
			
			if(d[i][0] == d[i][1]) {
				count++;
			}else {
				count = 0;
			}
			
			if(count == 3) {
				System.out.println("Yes");
				break;
			}
			
		}
		
		if(count != 3) System.out.println("No");
		
		
		
		
	}

}


Measured memory_bytes: 36044
import sys
sys.setrecursionlimit(10**8)

def dfs(v,c):
  now = 1
  for u,i in edge[v]:
    if color[i]==0:
      if now==c:
        now += 1
      color[i] = now 
      dfs(u,now)
      now += 1
  return 0

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  edge[a-1].append([b-1,i])
  edge[b-1].append([a-1,i])
color = [0]*(N-1)
dfs(0,1<<30)
print(max(color))
print(*color, sep='\n')

Measured memory_bytes: 81888
import numpy as np
n,m =map(int, input().split())  #複数数値入力
x=list(map(int, input().split()))  #リスト入力

x.sort()
x_d = list()

if n > m:
    print(0)
else:
    if m == 1:
        print(0)
    else:
#         for i in range(m-1):
#             x_d.append(x[i+1] - x[i])   
        x_d = list(np.diff(x))

#         for i in range(n-1):
            
#             x_d.remove(max(x_d))
            
        x_d.sort(reverse=True)
#         sumd = sum(x_d)  
        sumd = sum(x_d[n-1:])
        print(sumd)


Measured memory_bytes: 23024
#include<bits/stdc++.h>
using namespace std;
const int maxn=300000+10;
long long n,a[maxn],ans=0;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=3*n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+1+3*n);
    for(int i=(3*n)-1;i>=n+1;i-=2){
        ans+=a[i];
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 2560
#include<stdio.h>
struct gra_m {
    int m,f,r;
};
struct kakoi {
    struct gra_m root[100];
};

int main() {
    int i=0,a,total,nm,nf,nr;
    char rank;
    struct kakoi m;
    struct kakoi f;
    struct kakoi r;
    while(1) {
        scanf("%d %d %d",&nm,&nf,&nr);
        m.root[i].m = nm;
        m.root[i].f = nf;
        m.root[i].r = nr;
        if(nm==-1 && nf==-1 && nr==-1) break;
        i++;
    }
    for(a=0;a<i;a++) {
        total = m.root[a].m + m.root[a].f;
        if(m.root[a].m ==-1 || m.root[a].f == -1) rank = 'F';
        else if(total >= 80) rank = 'A';
        else if(total >= 65) rank = 'B';
        else if(total >= 50) rank = 'C';
        else if(total >= 30) {
            if(m.root[a].r<50) {
                rank = 'D';
            }
            else if(m.root[a].r>=50) {
                rank = 'C';
            }
        }
        else rank = 'F';
        printf("%c\n",rank);
    }
    return 0;
}


Measured memory_bytes: 2684
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static int mindis = 1000000000;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		N = sc.nextInt();
		long sum = 0;

		map = new ArrayList<ArrayList<Integer>>();
		for(int i = 0;i <= N;i++){								//初期値入力
			ArrayList<Integer> x = new ArrayList<Integer>();
			x.add(0);
			map.add(x);
		}

		for(int i = 0;i < N-1;i++){							//mapの作成
			int a = sc.nextInt();
			int b = sc.nextInt();
			map.get(a).add(b);
			map.get(b).add(a);
		}


		int[] dataf = new int[N+1];
		dataf	= dfs(1,-1,dataf);


		int[] datas = new int[N+1];
		datas	= dfs(N,-1,datas);

		int a = 0;
		int b= 0;
		for(int i= 1;i < N+1;i++){
			if(dataf[i] <= datas[i]){
				a++;

			}else{
				b++;
			}

		}
		if(a > b){
			System.out.println("Fennec");
		}else{
			System.out.println("Snuke");
		}

	}

	static int[] dfs(int p,int back, int[] data){				//始点からそれぞれの辺までの距離を求める
		//pは現在地、dataは距離

		ArrayList<Integer> edge = map.get(p);				//辺のリスト
		for(int v : edge){
			if(v != back){
				data[v] = data[p] + 1;
				dfs(v, p, data);
			}

		}
		return data;

	}





}




Measured memory_bytes: 111340
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://beta.atcoder.jp/contests/arc090/tasks/arc090_a>
問題文============================================================
 2×N のマス目があります。上からi 行目、左からj 列目 (1≤i≤2,1≤j≤N) のマスをマス (i,j) と表すことにします。
 
 あなたははじめ、左上のマス (1,1) にいます。
 あなたは、右方向または下方向への移動を繰り返し、右下のマス (2,N) に移動しようとしています。
 
 マス (i,j) には Ai,j 個のアメが置かれています。
 あなたは移動中に通ったマスに置いてあるアメをすべて回収します。
 左上および右下のマスにもアメが置かれており、あなたはこれらのマスに置かれているアメも回収します。
 
 移動方法をうまく選んだとき、最大で何個のアメを回収できるでしょうか。
 
=================================================================

解説=============================================================
dp
 
 dp[i][j] := マス(i,j)に到達した時の最大回収アメ個数
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<vector<int>> A(3,vector<int>(N+1));
    vector<vector<int>> dp(3,vector<int>(N+1));
    for(int i = 0; i < 2;i++){
        for(int j = 0; j < N;j++){
            cin >> A[i][j];
        }
    }
    dp[0][0] = 0;
    
    for(int i = 0; i < 2;i++){
        for(int j = 0; j < N;j++){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j] + A[i][j]);
            dp[i][j+1] = max(dp[i][j+1],dp[i][j] + A[i][j]);
        }
    }
    
    cout << max(dp[2][N-1],dp[1][N]) << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



















int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    vector<ll> c(n + 1);
    ll ans = 0;
    REP(i, n){
        c[min(i + a[i], n)]++;
        if(i - a[i] < 0) continue;
        ans += c[i - a[i]];
    }
    cout << ans << endl;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long a){

    cout<<a+a*a+a*a*a<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long a;
    scanf("%lld",&a);
    func(a);
    return 0;
}


Measured memory_bytes: 3760
#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)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

struct UnionFind{
    vector<int> Parent;
    vector<int> sizes;
    UnionFind(int n):Parent(n),sizes(n,1){ rep(i,n)Parent[i]=i; }
    //find the root of x
    int root(int x){
        if(x!=Parent[x]){
        Parent[x] = root(Parent[x]);
        }
        return Parent[x];
    }
    //merge x and y
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        Parent[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return root(x) == root(y); }
    int size(int x){ return sizes[root(x)]; }
};
/*~使い方講座~
まず、main関数内で 
    UnionFind uni(N);
と呼び出します（これでUnionFind木のuniちゃんが呼び出されます）。
uniちゃんの中には、NodeがN個あり、
それぞれの親とそれが属する集合の数（size）が定義されています。
    ①二つのNode xとy が同じ集合に属するか確認するとき
    uni.same(x, y)
    などとすることで、それらが同じかどうかをtrue/falseで返す
    ②あるNode x が含まれる集合の大きさを知りたいとき
    uni.size(x)
    ③二つのNode xとyを同じ集合に属させたいとき
    uni.unite(x, y)
*/
/*~UnionFind木が出題された問題~
①
https://beta.atcoder.jp/contests/abc120
/Users/knaga/procon/Atcoder/abc120
*/


int main() {
	ll N,M;
	cin>>N>>M;
	vector<int> p(N);
	rep(i,N){
		cin>>p[i];
		p[i]--;
	}
    UnionFind uni(N);
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--;y--;
        uni.unite(x,y);
	}
    ll ans = 0;
    rep(i,N){
        if(uni.same(i, p[i])){
            ans++;
        }
    }	
	cout<<ans<<endl;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    ll ans = 0;
    string last = "";
    string now = "";

    rep(i,s.size())
    {
        now += s[i];

        if( now != last )
        {
            last = now;
            now = "";
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640