akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
using namespace std;
 
typedef pair<int,int> P;
 
int d[31][31];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
enum{RIGHT,UP,LEFT,DOWN};
 
bool tate[30+1][30];
bool yoko[30][30+1];
int W,H;
 
bool canmove(int x,int y,int mx,int my,int d){
     if(mx<0||my<0||mx>=W||my>=H){
      return false;
     }else{
      switch(d){
      case RIGHT:
           if(tate[x][y])return false;
           break;
      case LEFT:
           if(tate[x-1][y])return false;
           break;
      case DOWN:
           if(yoko[x][y-1])return false;
           break;
      case UP:
           if(yoko[x][y])return false;
      }
      return true;
     }
}
 
int bfs(){
  queue< pair<int,int> > que;
 
  for(int i=0;i<W;i++){
    for(int j=0;j<H;j++){
      d[i][j]=-1;
    }
  }
 
  que.push(P(0,0));
  d[0][0]=0;
 
  while(que.size()){
    P p=que.front();
    que.pop();
    if(p.first==W-1&&p.second==H-1)break;
    for(int i=0;i<4;i++){
      int nx=p.first+dx[i],ny=p.second+dy[i];
      if(canmove(p.first,p.second,nx,ny,i)&&d[nx][ny]==-1){
    que.push(P(nx,ny));
    d[nx][ny]=d[p.first][p.second]+1;
      }
    }
  }
  return d[W-1][H-1];
}
       
int main(){
     for(int i=0;i<30;i++){
      for(int j=0;j<31;j++){
           tate[j][i]=0;
           yoko[i][j]=0;
      }
     }
     while(cin>>W>>H,W||H){
      for(int i=0;i<H;i++){
           for(int j=0;j<W-1;j++){
            cin>>tate[j][i];
           }
           if(i!=H-1){
            for(int j=0;j<W;j++){
             cin>>yoko[j][i];
            }
           }
      }
   
      int a=bfs();
      /*for(int j=0;j<H;j++){
           for(int i=0;i<W;i++){
            cout<<d[i][j];
           }
           cout<<endl;
           }*/
       
      if(a==-1)cout<<0<<endl;
      else cout<<a+1<<endl;
     }
     return 0;
}

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


ans = 2**30-1
X = [i-100 for i in range(201)]
for a in X:
    tmp = 0
    for b in A:
        tmp += (b-a)*(b-a)
    ans = min(ans,tmp)
print(ans)
    

Measured memory_bytes: 38896
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    long long N, K;
    cin >> N >> K;

    vector<long long> A(N);

    for (long long i = 0; i < N; ++i) {
        long long Ai;
        cin >> Ai;
        A.at(i) = Ai;
    }

    vector<long long> route;

    route.push_back(0);

    unordered_map<long long, bool> visited;
    visited[0] = true;

    long long next = A.at(0) - 1;

    while (true) {
        if (visited[next]) {
            break;
        }

        route.push_back(next);

        visited[next] = true;

        next = A.at(next) - 1;
    }

    long long start = next;
    long long startIndex;

    for (long long i = 0; i < route.size(); ++i) {
        if (route.at(i) == next) {
            startIndex = i;
        }
    }

    long long cycleLength = route.size() - startIndex;

    if (K < route.size()) {
        cout << route.at(K) + 1 << endl;
    } else {
        long long index = startIndex + (K - startIndex) % cycleLength;
        cout << route.at(index) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 14388
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

s = input().strip()
n = len(s)
ans = [0]*n
p = 0
v = 0
while p<n:
    while s[p]=='R':
        p += 1
    ans[p-1] += (p-v)//2
    ans[p] += (p-v)//2
    if (p-v)%2 == 1:
        ans[p-1] += 1
    v = p

    while p<n and s[p]=='L':
        p += 1
    ans[v-1] += (p-v)//2
    ans[v] += (p-v)//2
    if (p-v)%2 == 1:
        ans[v] += 1
    v = p

for i in range(n):
    printn(("" if i==0 else " ") + str(ans[i]))
print("")


Measured memory_bytes: 5172
//
//  main.swift
//  TestSpace for AtCoder
//
//  Created by Koichi Okai on 2020/06/25.
//  Copyright © 2020 Koichi Okai. All rights reserved.
//

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let N = Int(readLine()!)!
    let a = readInts()
    
    let n = (1...N).filter { $0 % 2 == 1 && a[$0 - 1] % 2 == 1 }.count
    
    print(n)
}

main()


Measured memory_bytes: 8324
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int INF=1001001001;
//f(x)=xを倒すのに必要な回数
//f(x)=2f(x/2)+1
ll f(ll x){
   if(x==1) return 1;
   ll a=f(x/2);
   return a*2+1;
}
int main(){
   ll h; cin>>h;
   cout<<f(h)<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>

long getBigger(long value, long standard);

int main(void) {
    long a, b, c, d;
    long value, max;
    long sign_max = 0;
    
    std::cin >> a >> b >> c >> d;
    
    max = a * c;
    
    value = a * d;
    max = getBigger(value, max);
    
    value = b * c;
    max = getBigger(value, max);
    
    value = b * d;
    max = getBigger(value, max);
    
    std::cout << max << std::endl;
    
    return 0;
}

long getBigger(long x, long y) {
    if(x > y) {
        return x;
    }
    return y;
}


Measured memory_bytes: 3552
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,int>P;
void dfs(int pos,int pre);
bool used[100]={false};
bool edge[1000]={false};
vector<P>node[105];
int main(){
  int n,m;
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    node[a].push_back(P(b,i));
    node[b].push_back(P(a,i));
  }
  
  for(int i=1;i<=n;i++){
    dfs(i,i);
  }
  int cnt=0;
  for(int i=0;i<m;i++){
    if(edge[i]){
      cnt++;
    }
  }
  cout<<m-cnt<<endl;
  return(0);
}

void dfs(int pos,int pre){
  for(int i=0;i<node[pos].size();i++){
    int next=node[pos][i].first;
    int id=node[pos][i].second;
    if(next!=pre){
      if(!used[next]){
	used[next]=true;
	dfs(next,pos);
	used[next]=false;
      }else{
	edge[id]=true;
      }
    }
  }
  return;
}

Measured memory_bytes: 256
import sys
s = input()
k = int(input())
ans = 0
#print(s[0] == s[2])
if len(s) == 1:
  print(k//2)
  sys.exit()

for i in range(len(s)):
  if s[i] != s[i-1]:
    break
  if i == len(s)-1:
    print(len(s) * k // 2)
    #print('f')
    sys.exit()
tmp = []
tmpnum = 0
for i in range(len(s)):
  if s[i] == s[i-1]:
    tmpnum += 1
  else:
    tmp.append(tmpnum+1)
    tmpnum = 0
tmp.append(tmpnum+1)

if s[0] == s[-1]:
  tmp[0] -= 1

for i in tmp:
  ans += i//2

ans *= k
if s[0] == s[-1] and tmp[0]%2 and tmp[-1]%2 :
  ans += k-1
print(ans)

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

int main()
{
	long long n,k,sum;
	cin>>n>>k;
	if(n==k)
		sum=0;
	else if(n<k)
		sum=min(n,k-n);
	else
	{
		n=n%k;
		sum=min(n,k-n);
	}
	cout<<sum;

	return 0;
}

Measured memory_bytes: 256
// TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); (i) < (b); (i)++)
#define FORS(i, a, b) for (int i = (a); (i) <= (b); (i)++)
#define REP(i, n) for (int i = 0; (i) < (n); (i)++)
#define REPS(i, n) for (int i = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (int i = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (int i = n; (i) > 0; (i)--)
#define len(x) ((int)(x).size())
#define print(x) (cout << (x) << "\n")
#define MOD 1000000007

// LIBRARY

// SOLVE
void solve()
{
    int N, M; cin>>N>>M;
    vi A(N); REP(i, N) cin>>A[i];
    vi B(M); REP(i, M) cin>>B[i];
    set<int> setA(A.begin(), A.end());
    set<int> setB(B.begin(), B.end());
    if (A.size() != setA.size() || B.size() != setB.size()) {
        print(0);
        return;
    }
    vi inA(N*M+1);
    vi inB(N*M+1);
    vi lA(N*M+1);
    vi lB(N*M+1);
    REP(i, A.size()) {
        inA[A[i]]= 1;
        REP(j, A[i]) {
            lA[j] += 1;
        }
    }
    REP(i, B.size()){
        inB[B[i]] = 1;
        REP(j, B[i]) {
            lB[j] += 1;
        }
    }
    ll ans = 1;
    RREPS(x, N*M) {
        int checked = N*M-x;
        if (inA[x] && inB[x]) continue;
        else if (inA[x]) ans = ans * lB[x] % MOD;
        else if (inB[x]) ans = ans * lA[x] % MOD;
        else ans = ans * (lA[x] * lB[x] - checked) % MOD;
        // print(x);
        // print(ans);
    }
    print(ans);
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


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

const int maxn=1e5+7;
const ll mod=998244353;

ll ksm(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}

ll fac[maxn+3],inv[maxn+3];

void init(){
    fac[0]=1ll;fac[1]=1ll;
    for(int i=2;i<=maxn;i++) fac[i]=fac[i-1]*i%mod;
    inv[maxn]=ksm(fac[maxn],mod-2);
    for(int i=maxn-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}

int a[maxn];

int main(){
    int n,k;scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i==n) {
            if(k==a[i]) ans++;
        }
        else if(k-a[i]>=0) k-=a[i],ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):
    l = bisect.bisect_left(A, B[i])
    r = N - bisect.bisect_right(C, B[i])
    ans += l * r

print(ans)

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

// 各桁の和を求める
int sumBit(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n,a,b;
  long long total = 0;
  
  cin >> n >> a >> b;
  
  int tmpSum = 0;
  for(int i = 1; i <= n; i++){
    // 各桁の和を求める
    tmpSum = sumBit(i);
    
    // a以上 かつ b以下の場合、集計
    if(a <= tmpSum && tmpSum <= b){
      total += i;
    }
  }
  
  cout << total;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

char c[] = {'N' , 'E' , 'S' , 'W'} ;
bool mark[4] ;
string s ;

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

	cin >> s ;

	for (int i = 0 ; i < _sz(s) ; i ++)
		for (int j = 0 ; j < 4 ; j ++)
			if (s[i] == c[j]) mark[j] = 1 ;

	cout << ((mark[0] ^ mark[2]) || (mark[1] ^ mark[3]) ? "No" : "Yes") << '\n' ;
}


Measured memory_bytes: 256
/////////////==========================
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;

}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
//int n,m,c;
//string s;
int n;
int d[105][2];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>d[i][0]>>d[i][1];
	int vis=0;
	for(int i=1;i<=n;i++)
	{
		if(d[i][0]==d[i][1]) vis++;
		else vis=0;
		if(vis==3){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
//	scanf("%s%d%d",&n,&m,&c);
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a[3];

  cin >> a[0] >> a[1] >> a[2];

  int f=0, s=0;
  rep(i,3){
    if(a[i] == 5){
      f++;
    }
    if(a[i] == 7){
      s++;
    }
  }

  if(f==2 && s == 1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
d=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(d):
    s_i=list(map(int,input().split()))
    s.append(s_i)

dp=[0]*26

from random import randint

def score_ans(s,c,now):
    tmp=0
    for i in range(26):
        tmp+=c[i]*(now - dp[i])
    
    return s-tmp

for i in range(d):

    score=0
    ans=randint(1,26)

    for j in range(26):

        s_i=s[i][j]

        if score<score_ans(s_i,c,i):

            ans=j+1

            score+=score_ans(s_i,c,i)

    dp[ans-1]=i    
    

    print(ans)

Measured memory_bytes: 9592
n,k = map(int,input().split())
lis = list(map(int,input().split()))
if n == 1:
  print(lis[0])
  exit()
ans = []
for i in range(n-k+1):
  if lis[i+k-1] <=0 or 0 <= lis[i]:
    ans.append(max(abs(lis[i+k-1]),abs(lis[i])))
  else:
    ans.append(min(abs(lis[i+k-1]),abs(lis[i]))+abs(lis[i+k-1])+abs(lis[i]))
print(min(ans))

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

int main(void)
{
    int X,A,B;
    cin >> X >> A >> B;

    if( A - B >= 0){
        cout << "delicious";
    }else if(B - A <= X){
        cout << "safe";
    }else{
        cout << "dangerous";
    }
    return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b, c;
    cin >> a >> b >> c;

    outYES(b - a == c - b);
}

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

const int INF = 0x7fffffff;

int main(){
    int n, m;
    int d[20];
    int dp[50001];
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++){
        scanf("%d", d + i);
    }
    fill(dp, dp + n + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j + d[i] <= n; j++){
            dp[j + d[i]] = min(dp[j + d[i]], dp[j] + 1);
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}

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

int main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	
  	vector<int> v;
	bool jud=(s[0]=='0')?true:false;
	bool jud2=(s[n-1]=='0')?true:false;
	if(jud) v.push_back(0);
	int re=s[0];
	int cntt=1;
	for(int i=1;i<n;++i){
		if(s[i]==s[i-1]) cntt++;
		else{
			v.push_back(cntt);
			cntt=1;
		}
	}
	v.push_back(cntt);
	if(jud2) v.push_back(0);
	
	int sum=0;
	int ans=0;
	int l=0,r=0;
	while(r<v.size()){
		sum+=v[r];
		if(r-l+1>2*k+1){
			sum-=v[l]+v[l+1];
			l+=2;
		}
		r++;
		ans=max(ans,sum);
	}
	
	cout<<ans<<endl;
}//abc124_d.復習.

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

int main() {
  vector<int> a(10);
  for (int i = 0; i < 10; i ++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < 3; i ++) {
    cout << a.at(i) << endl;
  }
}



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


int main() {
    int H, W;
    cin >> H >> W;
    vector<string>S(H);
    for (int i = 0; i < H; ++i) {
      cin >> S[i];
    }

    int dpR[H][W]; // row(行, 横方向に照らすマスの個数)
    int dpC[H][W]; // column(列. 縦方向に照らすマスの個数)

    for (int i = 0; i < H; ++i) {
        dpR[i][0] = 0;
        for (int j = 0; j < W; ++j) {
            if(S[i][j] == '.') {
                dpR[i][0]++;
            }else {
                break;
            }
        }
        for (int j = 1; j < W; ++j) {
            if(S[i][j] == '#') {
                dpR[i][j] = 0;
            } else if(S[i][j-1] == '#'){
                dpR[i][j] = 0;
                for (int k = j; k < W; ++k) {
                    if(S[i][k] == '.') {
                        dpR[i][j]++;
                    }else {
                        break;
                    }
                }
            } else{
                dpR[i][j] = dpR[i][j-1];
            }
        }
    }

    for (int i = 0; i < W; ++i) {
        dpC[0][i] = 0;
        for (int j = 0; j < H; ++j) {
            if(S[j][i] == '.') {
                dpC[0][i]++;
            }else {
                break;
            }
        }
        for (int j = 1; j < H; ++j) {
            if(S[j][i] == '#') {
                dpC[j][i] = 0;
            } else if(S[j-1][i] == '#'){
                dpC[j][i] = 0;
                for (int k = j; k < H; ++k) {
                    if(S[k][i] == '.') {
                        dpC[j][i]++;
                    }else {
                        break;
                    }
                }
            } else{
                dpC[j][i] = dpC[j-1][i];
            }
        }
    }


    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if(ans < dpR[i][j] + dpC[i][j]){
                ans = dpR[i][j] + dpC[i][j];
            }
        }
    }
    ans--;
    cout << ans;
    return 0;
}

Measured memory_bytes: 35584
#include "bits/stdc++.h"
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  string ans;
  vector<int> vec = {a,b,c};
  sort(vec.begin(),vec.end());
  if (vec[0]==5 && vec[1]==5 && vec[2]==7)
    ans = "YES";
  else
    ans = "NO";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
//typedef __int128_t Int;
#define DBG 1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define loop(n) rep(loop,(0),(n))
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

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

  int N; cin >> N;
  cout<<(N<1000?"ABC":"ABD")<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using ull = unsigned long long;
const static ull MAX = 1e18;

int main(){
	int N;
	scanf("%d", &N);
	ull A[N];
	for (int i = 0; i < N; ++i){
		scanf("%llu", A + i);
		if(!A[i]){
			printf("0\n");
			return 0;
		}
	}
	ull answer = 1ULL;
	for (int i = 0; i < N; ++i){
		if(A[i] > MAX/answer){
			printf("-1\n");
			return 0;
		}
		answer *= A[i];
	}
	printf("%llu\n", answer);
	return 0;
}

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

int main() {
	while(1){
		int n, m;
		cin >> n;
		if(n == 0)break;
		cin >> m;
		int p = 2 * n + 1;
		string pn;
		for(int i = 0; i < p; i++){
			if(i % 2)
				pn += 'O';
			else
				pn += 'I';
		}
		string str;
		cin >> str;
	
		string ans;
		int count = 0;
		for(int i = 0; i < m - p + 1; i++){
			ans = str.substr(i, p);
			if(ans == pn)
				count++;
		}
	
		cout << count << endl;
	}
	return 0;
}

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

dic = {}

for i, a in enumerate(A, 1):
    dic[i] = a

times = {1: [0]}
count = 0
dest = 1
flg = 0
for k in range(K):
    dest = dic[dest]
    count += 1
    if dest not in times:
        times[dest] = [count]
    else:
        times[dest].append(count)
        flg = dest
        break

if count == K:
    trans = K
    dest = 1
else:
    trans = (K - count) % (times[flg][1] - times[flg][0])
    dest = flg

for t in range(trans):
    dest = dic[dest]

print(dest)

Measured memory_bytes: 61604
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	ll mny = 1000 ;
	ll cnt = 0 ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	a.push_back(0) ;
	for(int i=0;i<n;i++){
		mny += cnt*a.at(i) ;
		cnt = 0 ;
		if(a.at(i)<=a.at(i+1)){
			cnt += mny/a.at(i) ;
			mny %= a.at(i) ;
		}
	}
	cout << mny << endl ;
}


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX


int n,k,a,b[100001],c[100001],sum,ans;


signed main() {
    cin >> n >> k;
    rep1(i,n) {
        cin >> a;
        if (a > 0) sum += a, b[i] = a;
        else c[i] = -a;
        b[i] += b[i-1], c[i] += c[i-1];
    }
    repo(i,k,n+1) ans = max(ans, sum-min(b[i]-b[i-k],c[i]-c[i-k]));
    cout << ans << endl;
}




Measured memory_bytes: 1792
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,d;
   cin >> n >> d;
   int ans = 0;
   f(i,0,n){
      int x,y;
      cin >> x >> y;
      ans += (x*x+y*y <= d*d);
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 3648
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


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

    if (N == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int A, B;
        cin >> A >> B;

        cout << A + B
            << endl;
    }
}

Measured memory_bytes: 3552
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int n;
long long ans[90];

int main()
{
	scanf("%d", &n);
	ans[0] = 2;
	ans[1] = 1;
	for(int i = 2; i <= 86; i++)	ans[i] = ans[i - 1] + ans[i - 2];
	printf("%lld\n", ans[n]);
}

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

ll mod(ll a, ll b) {return (a % b + b) % b;}

ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

using namespace std;

int main() 
{	
	fast;
	long long x;
    cin >> x;
    map<long long, long long> mp;
 
    for (long long i = -5404; i <= 5404; i++)
        mp[i * i * i * i * i] = i;
 
    for (long long i = 0; i <= 5404; i++)
        if (mp[i * i * i * i * i - x]) {
            cout << i << ' ' << mp[i * i * i * i * i - x] << "\n";
            break;
        }
 	return 0;
}

Measured memory_bytes: 4336
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.25 20:44:00
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> a(n);
    vector<P> p(m);
    int at, bt, ct;
    rep(i, n) {
        scanf("%d", &at);
        a[i] = at;
    }
    rep(i, m) {
        scanf("%d%d", &bt, &ct);
        p[i] = P(bt, ct);
    }

    sor(a);
    sort(p.begin(), p.end(), [](const P b, const P c) {
        if (b.sc != c.sc)
            return b.sc > c.sc;
        else
            return b.fr > c.fr;
    });
    int id = 0;
    int pl = p.size();
    bool bre = false;
    rep(i, pl) {
        P pc = p[i];
        int bb = pc.fr;
        int cc = pc.sc;
        rep(j, bb) {
            if (a[id] < cc) {
                a[id] = cc;
                id++;
                if (id >= n) {
                    bre = true;
                    break;
                }
            } else {
                bre = true;
                break;
            }
        }
    }
    ll ret = 0;
    rep(i, n) {
        ret += a[i];
    }
    printf("%lld\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<map>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 2e5+5;
string str[maxn];
map<string,int> mm;
vector<string> vv;
int main()
{
	int n;
	scanf("%d",&n);
	int maxx =0 ;
	for (int  i= 1; i <= n; i ++ )
	{
		cin>>str[i];
		mm[str[i]] ++ ;
		maxx = max(maxx, mm[str[i]]);
	}
	for (int  i= 1; i <= n; i ++ )
	{
		if(mm[str[i]] == maxx)
		{
			vv.push_back(str[i]);
			mm[str[i]] = 0;
		}
	}
	sort(vv.begin(),vv.end());
	for (int  i= 0; i < vv.size(); i ++ )
	{
		cout<<vv[i]<<endl;
	}
	
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    if(n < 1200){
        cout << "ABC" << endl;
        return 0;
    } else if(n < 2800){
        cout << "ARC" << endl;
        return 0;
    }
    cout << "AGC" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int X;
  cin >> X;
  for (int i = -200; i < 200; i++) {
    for (int j = -200; j < 200; j++) {
      if (X == pow(i, 5) - pow(j, 5)) {
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

int main()
{
  string w;
  cin >> w;
  sort( w.begin(), w.end() );
  int s = 0;
  for( int i = 0; i <= w.size(); i += 2 ) {
    s += w[ i + 1 ] - w[ i ];
  }

  cout << ( s ? "No" : "Yes" ) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using lint = long long;
using namespace std;
const int MAXN = 200005;
const int mod = 1e9 + 7;

lint ipow(lint x, lint p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret = ret * piv % mod;
		piv = piv * piv % mod;
		p >>= 1;
	}
	return ret;
}

lint fact[MAXN], invf[MAXN];

lint bino(int x, int y){
	return fact[x] * (invf[y] * invf[x - y] % mod) % mod;
}

int main(){
	fact[0] = invf[0] = 1;
	for(int i=1; i<MAXN; i++){
		fact[i] = fact[i-1] * i % mod;
		invf[i] = ipow(fact[i], mod - 2);
	}
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	int p = a * ipow(a + b, mod - 2) % mod;
	int q = b * ipow(a + b, mod - 2) % mod; 
	lint ans = 0;
	for(int i=0; i<n; i++){
		int pan = n + i;
		ans += (pan * bino(n - 1 + i, i) % mod) * (ipow(p, n) * ipow(q, i) % mod) % mod;
		ans += (pan * bino(n - 1 + i, i) % mod) * (ipow(q, n) * ipow(p, i) % mod) % mod;
		ans %= mod;
	}
	ans *= ipow(a + b, mod - 2) % mod;
	ans %= mod;
	ans *= 100;
	ans %= mod;
	cout << ans % mod << endl;
}


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

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

    int D, G, p[11], c[11];
    cin >> D >> G;
    
    for(int i = 0; i < D; i++){
        cin >> p[i] >> c[i];
    }
    
    int ans = 1e9;
    
    for(int mask = 0; mask < (1 << D); mask++){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; i++){
            if(mask >> i & 1){
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            } else {
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans,num);
    }
    cout << ans << '\n';
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
    int a,b,c; cin>>a>>b>>c;
    //入力
    for(int i = 1; i <= a*b; i++){
        if(a*i % b == c){
            cout<<"YES"<<endl;
            return 0;
        }
    }//1からa*bまで全探索
cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int c=0;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]!=s[i+1])c++;
	}
	cout<<c<<endl;
	return 0;
}


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


int main(void)
{
  int a[5],i,j,max,tmp,k; 
  for(i=0;i<5;i++)
    scanf("%d",&a[i]);

  for(i=0;i<4;i++){
    max=a[i];
    k=i;
    for(j=i+1;j<5;j++)
      if(max<a[j]){
	max=a[j];
	k=j;
      }
    tmp=a[i];a[i]=max;a[k]=tmp;
  }

  for(i=0;i<5;i++){
    printf("%d",a[i]);
    if(i<4)
      printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
 
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
 
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
 
const int MOD = 1000000007;
 
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;
 
VI deps;
VVI edge;
 
int fn(int t){
    if(edge[t].size()==0){
        return 0;
    }else{
        VI tdeps(edge[t].size());
        REP(i,edge[t].size()){
            tdeps[i] = fn(edge[t][i]);
        }
        SORT(tdeps);
        for (int i = 1; i <= edge[t].size(); ++i) {
            tdeps[edge[t].size()-i] += i;
        }
        SORT(tdeps);
        return tdeps[edge[t].size()-1];
    }
}
 
signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);
 
    int n;
    cin >> n ;
    VI a(n);
    FOR(i,1,n){
        cin >> a[i];
        a[i]--;
    }
 
    deps.resize(n,-1);
    edge.resize(n,VI());
    FOR(i,1,n){
        edge[a[i]].push_back(i);
    }
 
    cout << fn(0) << endl;
 
    return 0;
}

Measured memory_bytes: 19840
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();

        long res=0;
        int x=S/3;

        if(S%3==0){
            for(int i=0; i<x; i++){
                res = (res + fermatComb(3*i+x-i-1,x-i-1))%((long)Math.pow(10,9) + 7);
            }
        }else if(S%3==1){
            for(int i=0; i<x; i++){
                res = (res + fermatComb(3*i+x-i,x-i-1))%((long)Math.pow(10,9) + 7);
            }
        }else{
            for(int i=0; i<x; i++){
                res = (res + fermatComb(3*i+x-i+1,x-i-1))%((long)Math.pow(10,9) + 7);
            }
        }

        
        
        System.out.println(res);
        
        }

    
    static long mod = (long)Math.pow(10,9) + 7;
    static long fermatComb(long a, long b) {
        if (b > a - b)
            return fermatComb(a, a - b);
        long mul = 1; //分子
        long div = 1; //分母
        for (int i = 0; i < b; i++) {
            mul *= (a - i);
            mul %= mod;
            div *= (i + 1);
            div %= mod;
        }
        long ans = mul * modpow(div, mod - 2) % mod; //フェルマーの小定理を利用して掛け算で計算
        return ans;
    }

    //mod条件下の高速pow
    static long modpow(long a, long p) {
        if (p == 0)
            return 1;
        if (p % 2 == 0) {
            long root = modpow(a, p / 2);
            return root * root % mod;
        } else
            return a * modpow(a, p - 1) % mod;
    }
    }

Measured memory_bytes: 36616
#!/usr/bin/env python3
#ABC124 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
ans1,ans2 = 0,0
for i in range(len(s)):
    if i % 2:
        if s[i] == '0':
            ans1 += 1
        else:
            ans2 += 1
    else:
        if s[i] == '1':
            ans1 += 1
        else:
            ans2 += 1
ans = min(ans1,ans2)
print(ans)


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

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

constexpr auto inf = 1e9;

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

using ll = long long;

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

	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());

	if (s < t)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

int main()
{
    int m, f, r;
    
    while(1)
    {
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        if(m == -1 || f == -1) {
            cout << 'F' << endl;
        } else if(m + f >= 80) {
            cout << 'A' << endl;
        } else if(m + f >= 65) {
            cout << 'B' << endl;
        } else if(m + f >= 50) {
            cout << 'C' << endl;
        } else if(m + f >= 30) {
            (r >= 50)? cout << 'C' << endl : cout << 'D' << endl;
        } else {
            cout << 'F' << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };

int n;
string str;
VS input(9);

string now;
PII many_push;

int gcd( int m, int n ) {
	if ( n == 0 ) return m;
	return gcd( n, m % n );
}

int main() {
	input[ 0 ] = ".,!? ";
	input[ 1 ] = "abc";
	input[ 2 ] = "def";
	input[ 3 ] = "ghi";
	input[ 4 ] = "jkl";
	input[ 5 ] = "mno";
	input[ 6 ] = "pqrs";
	input[ 7 ] = "tuv";
	input[ 8 ] = "wxyz";
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		cin >> str;
		now = "(";
		for ( int j = 0; j < str.size(); j++ ) {	
			if ( str[ j ] == '0' ) {
				if ( now[ 0 ] != '(' ) {
					cout << now;
					now[ 0 ] = '(';
					many_push = PII( 10, 10 );
				}
				continue;
			}
			if ( many_push.first != str[ j ] - '1' ) {
				many_push = PII( str[ j ] - '1', 0 );
				now[ 0 ] = input[ many_push.first ][ many_push.second ];
				continue;
			}
			many_push.second++;
			many_push.second %= input[ many_push.first ].size();
			now[ 0 ] = input[ many_push.first ][ many_push.second ];
		}
		printf( "\n" );
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi pair<int, int>
const int mod = 1e9 + 7;
vector<pi> lim[333];
int N, M;
int dp[333][333][333];
inline bool check(int r, int g, int b){
	int k = max(r, max(g, b));
	for(int i = 0;i < lim[k].size(); i++){
		int l = lim[k][i].first, x = lim[k][i].second, cnt = 0;
		if(r >= l)cnt++;
		if(g >= l)cnt++;
		if(b >= l)cnt++;
		if(cnt != x)return false;
	}
	return true;
}
int main(){
	cin>>N>>M;
	int x, l, r;
	for(int i = 1;i <= M; i++){
		scanf("%d%d%d", &l, &r, &x);
		lim[r].push_back(make_pair(l, x));
	}
	int ans = 0;
	dp[0][0][0] = 1;
	for(int r = 0;r <= N; r++){
		for(int g = 0;g <= N; g++){
			for(int b = 0;b <= N; b++){
				if(dp[r][g][b] == 0){
					continue;
				}
				if(check(r, g, b) == false){
					dp[r][g][b] = 0;
					continue;
				}
				int k = max(r, max(g, b)) + 1;
				if(k == N + 1){
					ans = (1LL * ans + 1LL * dp[r][g][b]) % mod;
				}
				dp[k][g][b] = (1LL * dp[k][g][b] + 1LL * dp[r][g][b]) % mod;
				dp[r][k][b] = (1LL * dp[r][k][b] + 1LL * dp[r][g][b]) % mod;
				dp[r][g][k] = (1LL * dp[r][g][k] + 1LL * dp[r][g][b]) % mod;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}
/*
此题要我自己想要一年 故听进哥讲加看题解总结几个要点
1 想到dp 并且可以枚举每一个最后出现的颜色的位置
2 想到每一位上满足限制来推得最终状态满足限制 枚举位 + 最右点条件
3 由于只有三种颜色 且每一种颜色数量没有限制 故l前面的颜色情况对满足当前位没有影响 且当前状态由之前的合法位推来
故之前的限制均满足 所以可以枚举最后出现的位置
*/ 

Measured memory_bytes: 131200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        M_Candies solver = new M_Candies();
        solver.solve(1, in, out);
        out.close();
    }

    static class M_Candies {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni(), k = in.ni();
            int[] a = in.na(n);
            long[][] dp = new long[n + 1][k + 1];
            long mod = (int) 1e9 + 7;
            dp[0][0] = 1;
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i];
                if (sum > k) sum = k;
                long total = 0;
                for (int j = 0; j <= a[i]; j++) {
                    total += dp[i][j];
                    dp[i + 1][j] = total % mod;
                }
                for (int j = a[i] + 1; j <= sum; j++) {
                    total += dp[i][j];
                    total -= dp[i][j - a[i] - 1];
                    dp[i + 1][j] = total % mod;
                }
            }
            out.println(dp[n][k]);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public int[] na(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

    }
}



Measured memory_bytes: 128468
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s,t;
    vector<string> vs;
    cin>>s>>t;
    rep(i,s.size()-t.size()+1){
        string copy = s;
        bool ok = 1;
        if(s[i]=='?' || t[0]){
            //cout<<"Yes"<<i<<endl;
            rep(j,t.size()){
                //cout<<s[i+j]<<" "<<t[j]<<" "<<j<<endl;
                if(s[i+j]==t[j] || s[i+j]=='?'){
                    s[i+j]=t[j];
                }else{
                    ok = 0;
                }
            }
        }
        if(ok) vs.push_back(s);
        s = copy;
    }
    sort(vs.begin(),vs.end());
    if(vs.size()==0) cout<<"UNRESTORABLE"<<endl;
    else{
        for(auto u : vs[0]){
            if(u=='?') cout<<'a';
            else cout<<u;
        }
        cout<<endl;
    }
    return 0;
}

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

int main(void) {
    int N, K;
    cin >> N >> K;

    if(K>(N-1)*(N-2)/2) { 
        cout << -1 << endl;
        return 0;
    }

    cout << N-1+(N-1)*(N-2)/2-K << endl;
    for(int i=2;i<=N;i++) {
        cout << 1 << " " << i << endl;
    }

    int cnt=0;
    for(int i=2;i<=N;i++) {
        for(int j=i+1;j<=N;j++) {
            if(cnt==(N-1)*(N-2)/2-K) return 0;
            cout << i << " " << j << endl;
            cnt++; 
        }
    }

    return 0;
}


Measured memory_bytes: 256