akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N,K;
LL a[200002];
LL s[200002];

LL num[200002];
LL used[200002];

#define BITTYPE int

#define BITCNT  2

#define BITSIZE 512345

namespace _BIT{

    int i=0;

    BITTYPE t[2][BITSIZE];

    inline BITTYPE* get(){

        return t[i++];

    }

}



struct BIT{

    using T=BITTYPE;

    T *t;

    int n;

    BIT(int N):t(_BIT::get()),n(N+1){

        REP(i,n+1)t[i]=0;

    }

    void add(int r,T v){//add v for [1,r]

        for(;r;r-=r&-r)t[r]+=v;

    }

    void add(int l,int r,T v){//add v for [l,r]

        add(r,v);

        add(l-1,-v);

    }

    T get(int i){//get sum[i]

        T res=0;

        for(;i<=n;i+=i&-i)res+=t[i];

        return res;

    }

};


int main(){
    cin>>N>>K;
    s[0]=0;
    a[0]=0;
    REP(i,N+1){
        if(i==0)continue;
        cin>>a[i];
        a[i]-=K;
        s[i]=a[i]+s[i-1];
    }
    map<LL,int>m;
    REP(i,N+1){
       m[s[i]]=0;
    }
    LL count=0;
    for(auto it=m.begin();it!=m.end();it++){
        m[it->first]=count;
        count++;
    }
    REP(i,N+1){
        num[i]=m[s[i]]+1;
    }
    REP(i,N+1){
        used[i]=0;
    }
    
    LL ans=0;
    BIT btk=BIT(N+10);

    REP(i,N+1){
        if(i==0){
           btk.add(N+5-num[0],1);
           continue;
        }
        ans+=btk.get(N+5-num[i]);
        btk.add(N+5-num[i],1);
        //cout<<ans<<endl;
        /*
        for(int j=i+1;j<N+1;j++){
            if(s[j]-s[i]>=0)ans++;
        }*/
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 21760
#include<iostream>
#include<cstdlib> 
#include<sstream>
#include<cstdio>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 1000000007
double P = 3.1415926535897932384626;
int main()
{
	//std::ios::sync_with_stdio(false);
	int r;
	cin>>r;
	printf("%.20f\n",2*P*r);
	//system("pause");
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int a,b,c;cin>>a>>b>>c;
  int ans=a*b/2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  string s;
  cin >> s;
  ll num = stoi(s);
  ll a = num%100;
  ll b = num/100;
  if(a == 0 || a > 12){
    if(b == 0 || b > 12){
      cout << "NA";
    } else {
      cout << "MMYY";
    } 
  } else {
      if(b == 0 || b > 12){
        cout << "YYMM";
      } else {
        cout << "AMBIGUOUS";
      }
    }
 return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
N, M = map(int, input().split())

import heapq

ABs = [[] for _ in range(M + 1)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M:
        ABs[A].append(-B)
heapq.heapify(ABs[0])

As = 0
for i in range(M + 1):
    if i > 0:
        for b in ABs[i]:
            heapq.heappush(ABs[0], b)
    if len(ABs[0]) > 0:
        As += heapq.heappop(ABs[0])
print(-As)

Measured memory_bytes: 63024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int cnt[100010];

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

	vector<int> a;
	inputVector(a, N);

	rep(i, N) {
		if (a[i] > 0) cnt[a[i] - 1]++;
		cnt[a[i]]++;
		cnt[a[i] + 1]++;
	}

	int val = 0;
	rep(i, 100005) {
		if (cnt[i] > val) {
			val = cnt[i];
		}
	}

	cout << val << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int S;
	cin >> S;
	int a,b;
	a = S/100;
	b= S%100;
	int flag= 0;
	if(a <13 and a > 0){
		++flag;
	}
	
	if(b<13 and b > 0){
		++flag;
		++flag;
	}
	
	if(flag == 0){
		cout << "NA"<<endl;
	}else if(flag == 1){
		cout << "MMYY"<<endl;
	}else if(flag == 2){
		cout << "YYMM"<<endl;
	}else{
		cout << "AMBIGUOUS"<<endl;
	}
	
	return 0;
}

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

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

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

int n;
string s;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> s;
    if (s.length() <= n)
        cout << s << '\n';
    else
        cout << s.substr(0,n) << "...\n";
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //long long型じゃないと無理
    const ll div = 1000000007;
    cin >> n;
    ll power = 1;
    for(int i = 1; i <= n; i++){
        power = (power * i) % div;
    }
    cout << power << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 999999999999999999
using namespace std;
int h,n;
struct spell
{
    long long cost;
    long long val;
};
spell v[10001];
long long dp[100001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>h>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i].val>>v[i].cost;
    for(int i=1;i<=h;i++)
        dp[i]=inf;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=7*h;j++)
        {
            if(j<=h)
            {
                if(j-v[i].val>=0)
                    if(dp[j-v[i].val]!=inf)
                        dp[j]=min(dp[j],dp[j-v[i].val]+v[i].cost);
            }
            else if(j>h)
            {
                if(j-v[i].val>=0&&j-v[i].val<=h)
                    if(dp[j-v[i].val]!=inf)
                        dp[h]=min(dp[h],dp[j-v[i].val]+v[i].cost);
            }
        }
    }
    cout<<dp[h];
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int H = sc.nextInt();
    int W = sc.nextInt();
    String[] str = new String[H];
    for(int i = 0; i < H; i++){
      str[i] = sc.next();
    }
  
    char[][] wb = new char[H][W];
   
    for(int i = 0; i < H; i++){
      String s = str[i];
      for(int j = 0; j < W; j++){
        wb[i][j] = s.charAt(j);
      }
    }
  
  int count1 = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
        if(wb[i][j] == '.'){
          count1++;
        }
     }
    if(count1 == W){
      for(int k = 0; k < W; k++){
        wb[i][k] = '&';
      }
    }
    count1 = 0;
  }
     
  int count2 = 0;
  for(int j = 0; j < W; j++){
    for(int g= 0; g < H; g++){
        if(wb[g][j] == '.' || wb[g][j] == '&'){
          count2++;
        }
      }
    if(count2 == H){
      for(int k = 0; k < H; k++){
        wb[k][j] = '&';
      }
    }
    count2 = 0;
  } 
    
    for(int h = 0; h < H; h++){
        for(int j = 0;j < W; j++){
          if(wb[h][j] != '&'){
            System.out.print(wb[h][j]);
          }
        }
           System.out.println();
    }
  }  
}

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vl h(n);
    rep(i, n) {
        cin >> h[i];
    }
    sort(all(h));

    ll ans = INF;
    rep(i, n-k+1) {
        chmin(ans, h[i+k-1] - h[i]);
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    ll m=a[0];
    ll s=0;
    for(ll i=0;i<n;i++){
        if(a[i]>=m) m=a[i];
        s+=(m-a[i]);
    }
    cout<<s<<endl;  
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

long long GCD(long long a, long long b){
    if(a>b){long long n=a; a=b; b=n;}
    if(a==0) return b;
    else return GCD(b%a,a);
}

int main(){
    long long A,B,C,D; cin >> A >> B >> C >> D;
    long long cdiv, ddiv, cddiv;
    long long E = GCD(C,D);
    E = C*D/E;
    cdiv = B/C - (A-1)/C;
    ddiv = B/D - (A-1)/D;
    cddiv = B/E - (A-1)/E;
    cout << (B-A+1) - cdiv - ddiv + cddiv << endl;
}


Measured memory_bytes: 256
from collections import deque



H,W = map(int, input().split())
S = [input() for _ in range(H)]

ans = 0
dyx = [(1,0), (0,1),(-1,0), (0,-1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#": continue
        dist = [[0 for _ in range(W)] for _ in range(H)] 
        visited = [[False for _ in range(W)] for _ in range(H)]
        visited[i][j] = True
        q = deque()
        q.append((i,j))
        while q:
            y,x = q.popleft()
            for dy,dx in dyx:
                ny, nx = y+dy, x+dx
                if not 0 <= ny <= H-1 or not 0 <= nx <= W-1 or visited[ny][nx] == True or S[ny][nx] == "#":
                    continue
                q.append((ny, nx))
                dist[ny][nx] = dist[y][x] + 1
                visited[ny][nx] = True



        ans = max(ans, max(max(row) for row in dist))

            

print(ans)

Measured memory_bytes: 48220
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int n = s.length();
        for(int i = 0;i < n;i++){
            char x = s.charAt(n-1);
            s = x + s.substring(0,n-1);
            if(s.equals(t)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


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

int main() {
  
  int k,n;
  cin >> k >> n;
  
  vector<int> a(n);
  
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  int max,p;
    
  max=k-a[n-1]+a[0];
  
  for(int j=0;j<n-1;j++){
    p=a[j+1]-a[j];
      
    if(p>max)max=p;
  }
  
  cout << k-max << endl;
  
  
}






Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int m,k; 
int main(){
	cin>>m>>k;
	int tmp=(1<<m)-1;
	if(m==0&&k==0){
		puts("0 0");
		return 0;
	}
	if(k<=tmp){
		if(m==1&&k==1){
			puts("-1");
			return 0;
		}
		if(!k){
			for(int i=0;i<=tmp;i++){
				printf("%d %d%c",i,i,(i==tmp)?'\n':' ');
			}
		}
		else{
			printf("0 %d 0 ",k);
			for(int i=1;i<=tmp;i++){
				if(i==k) continue;
				printf("%d ",i);
			}
			printf("%d ",k);
			for(int i=tmp;i>=1;i--){
				if(i==k) continue;
				printf("%d ",i);
			}putchar('\n');
		}
	}
	else{
		puts("-1");
	}
	return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
a = gets.split(" ").map{ |i| i.to_i }
a.sort!{ |a, b| b <=> a }
#p a

aPoint = 0
bPoint = 0

for i in 0...a.length do
  if i % 2 == 0
    aPoint += a[i]
  else
    bPoint += a[i]
  end
end

puts aPoint - bPoint


Measured memory_bytes: 1788
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N int
	var S string

	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)

	si := strings.Split(S, "")

	sum := 1

	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			if si[i] == si[j] {
				break
			} else {
				sum++
              	break
			}
		}
	}

	fmt.Printf("%d\n", sum)
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int h, w; cin>>h>>w;
    int sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy;
    sx--; sy--; gx--; gy--;
    string s[1010];
    for(int i=0; i<h; i++) cin>>s[i];
    int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
    int d[1010][1010];
    const int INF=1e9+7;
    for(int i=0; i<h; i++) for(int j=0; j<w; j++) d[i][j]=INF;
    d[sx][sy]=0;
    deque<P> que;
    que.push_back({sx, sy});
    auto check=[&](int x1, int y1){
        if(x1<0 || x1>=h || y1<0 || y1>=w || s[x1][y1]=='#') return false;
        else return true;
    };
    while(!que.empty()){
        P p=que.front(); que.pop_front();
        int x=p.first, y=p.second;
        for(int k=0; k<4; k++){
            int x1=x+dx[k], y1=y+dy[k];
            if(!check(x1, y1)) continue;
            if(d[x1][y1]>d[x][y]){
                d[x1][y1]=d[x][y];
                que.push_front({x1, y1});
            }
        }
        for(int i=-2; i<=2; i++){
            for(int j=-2; j<=2; j++){
                int x1=x+i, y1=y+j;
                if(!check(x1, y1)) continue;
                if(d[x1][y1]>d[x][y]+1){
                    d[x1][y1]=d[x][y]+1;
                    que.push_back({x1, y1});
                }
            }
        }
    }
    if(d[gx][gy]==INF) cout<<-1<<endl;
    else cout<<d[gx][gy]<<endl;
    return 0;
}



Measured memory_bytes: 9540
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  double a,b,c,d,u,v,w,x,y,z;
  while(cin>>a>>b>>c>>d&&a!=-1&&b!=-1&&c!=-1&&d!=-1){
    u=cos(M_PI*b/180)*cos(M_PI*a/180);
    v=sin(M_PI*b/180)*cos(M_PI*a/180);
    w=sin(M_PI*a/180);
    x=cos(M_PI*d/180)*cos(M_PI*c/180);
    y=sin(M_PI*d/180)*cos(M_PI*c/180);
    z=sin(M_PI*c/180);
    cout<<(int)(6378.1*acos(1-((u-x)*(u-x)+(v-y)*(v-y)+(w-z)*(w-z))/2)+0.5)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    if(s[0]==s[s.length()-1]){
        if(s.length()%2==0){
            cout<<"First"<<endl;
            return 0;
        }
        else{
            cout<<"Second"<<endl;
            return 0;
        }
    }
    else{
        if(s.length()%2==0){
            cout<<"Second"<<endl;
            return 0;
        }
        else{
            cout<<"First"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll N,cnt=0;string S;
    cin >> N >> S;
    for(int i = 0; i < N-2; i++){
        if(S[i]=='A'){
            if(S[i+1]=='B'){
                if(S[i+2]=='C'){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int max=300000;
    int R[max],n;
    cin >> n;
    for (int j=0; j<n; j++) cin>>R[j];

    int diff_max=-2000000000;
    int val_min=R[0];
    for (int j=1; j<n; j++){
        if(R[j]-val_min>diff_max) diff_max=(R[j]-val_min);
        if (R[j]-val_min<0) val_min=R[j];
    }
    cout<<diff_max<<endl;
    return 0;
}

Measured memory_bytes: 3880
#include<iostream>
using namespace std;
int main()
{
    int n,y;
    cin>>n>>y;
    for(int a=0;a<=n;a++)
    {
        for(int b=0;b<=n-a;b++)
        {
            int c=n-a-b;
            if(a*10000+b*5000+c*1000==y)
            {
                cout<<a<<" "<<b<<" "<<c<<" ";
                return 0;
            }
        }
    }
    cout<<"-1"<<" "<<"-1"<<" "<<"-1";
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

vector<int> sieve(int n) {
	vector<int> res;
	vector<bool> is_prime(n + 1, true);
	
	is_prime[0] = is_prime[1] = false;
	
	for (int i = 2; i * i <= n; i++) if (is_prime[i]) {
		res.push_back(i);
		is_prime[i] = false;
		for (int j = 2; i * j <= n; j++) if (is_prime[i * j]) {
			is_prime[i * j] = false;
		}
	}
	
	REP(i, n + 1) if (is_prime[i]) res.push_back(i);
	sort(res.begin(), res.end());
	return res;
}

int n, x, v[30];
bool dp[1123456];

int main() {
	vector<int> prime = sieve(1000000);
	
	while (cin >> n >> x, n || x) {
		REP(i, n) scanf("%d", v + i);
		
		memset(dp, 0, sizeof(dp));
		dp[0] = true;
		REP(i, x + 1) if (dp[i]) {
			REP(j, n) if (i + v[j] <= x) dp[i + v[j]] = 1;
		}
		
		int ans = -1;
		REP(i, prime.size()) {
			if (x < prime[i]) break;
			if (dp[prime[i]]) chmax(ans, prime[i]);
		}
		
		if (ans == -1) puts("NA");
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4536
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<s.size()-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
	}
	cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
int main(){
    ll k;
    vector <int> v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>k;
    cout<<v[k-1];
}

Measured memory_bytes: 256
import itertools
n,m,q = map(int,input().split())

a =[]
for _ in range(q):
    a.append(list(map(int,input().split())))

b = [i for i in range(1,m+1)]
c = list(itertools.combinations_with_replacement(b,n))

ans = 0
for i in range(len(c)):
    check = 0
    for j in range(q):
        if c[i][a[j][1]-1] - c[i][a[j][0]-1] == a[j][2]:
            check = check + a[j][3]
    ans = max(ans,check)

print(ans)

Measured memory_bytes: 21628
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    vvi m(3,vi(3));
    set<lli> s;
    rep(i,3){
        rep(j,3){
            cin>>m[i][j];
            s.insert(m[i][j]);
        }
    }
    lli n;
    cin>>n;
    rep(i,n){
        lli b;
        cin>>b;
        if(s.count(b)){
            rep(j,3)rep(k,3){
                if(m[j][k]==b){
                    m[j][k]=-1;
                }
            }
        }
    }
    rep(i,3){
        bool d=true;
        rep(j,2){
            if(m[i][j]!=m[i][j+1]){
                d=false;
            }
        }
        if(d==true){
            out("Yes");
            return 0;
        }
    }
    rep(i,3){
        bool d=true;
        rep(j,2){
            if(m[j][i]!=m[j+1][i]){
                d=false;
            }
        }
        if(d==true){
            out("Yes");
            return 0;
        }
    }
    if(m[0][0]==m[1][1]&&m[1][1]==m[2][2]){
        out("Yes");
        return 0;
    }
    if(m[0][2]==m[1][1]&&m[1][1]==m[2][0]){
        out("Yes");
        return 0;
    }
    out("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int n, a[30], b[30], c[30], point = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n - 1; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i)
  {
    point += b[a[i] - 1];
    if (i >= 1 && a[i - 1] + 1 == a[i])
    {
      point += c[a[i - 1] - 1];
    }
  }
  cout << point;
}


Measured memory_bytes: 3628
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
int n;
int bit[100010];
void add(int v, int x) {

	while (v <= n)
	{
		bit[v] += x;
		v += v & -v;
	}
}

ll sum(int v) {
	ll r = 0;
	while (v > 0)
	{
		r += bit[v];
		v -= v & -v;
	}
	return r;
}
void put(string v) {
	cout << "a" << v<< "b" << endl;
}
void solv() {

	double r;
	cin >> r;
	
	cout << fixed << (M_PI * r * r) << " " << (2 * r * M_PI) << endl;
}


int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <climits>
#include <vector>
using namespace std;
typedef unsigned short ushort;

class blanch{
	public:
		bool visited;
		int distance;
		ushort from;
		ushort to;
};
typedef vector <blanch> vb;
typedef vector <vb> vvb;

int make_graph(vvb &graph, vb &nodes){

	int n=nodes.size();
	for (int i=0; i<n; i++){
		nodes[i].visited = false;
		nodes[i].distance = INT_MAX;
	}

	blanch tmp;
	tmp.visited = false;
	for (int i=0; i<n; i++){
		int n2;
		cin>>tmp.from;
		cin>>n2;

		for (int j=0; j<n2; j++){
			cin>>tmp.to;
			cin>>tmp.distance;
			graph[tmp.from].push_back(tmp);
		}
	}
	return 0;
}

int Shortest_Path(vvb &graph, vb &nodes){

	int p1=0;
	nodes[p1].distance = 0;

	while (p1 != -1){
		nodes[p1].visited=true;
		for (int i = 0; i<(int)graph[p1].size(); i++){
			blanch tmp = graph[p1][i];
			if (!nodes[tmp.to].visited){
				int tmp2 = tmp.distance + nodes[p1].distance;
				if (tmp2 < nodes[tmp.to].distance){
					tmp.distance = tmp2;
					nodes[tmp.to] = tmp;
				}
			}
		}

		p1 = -1;
		int tmp = INT_MAX;
		for (int i=0; i<(int)graph.size(); i++){
			if (!nodes[i].visited && nodes[i].distance<tmp){
				p1 = i;
				tmp = nodes[i].distance;
			}
		}
	}
	return 0;
}

int resultout(vb &nodes){
	for (int i=0; i<(int)nodes.size(); i++){
		cout<<i<<" "<<nodes[i].distance<<endl;
	}
	return 0;
}

int main(void){

	int n;
	cin>>n;
	vvb G(n, vb());
	vb nodes(n);

	make_graph(G, nodes);

	Shortest_Path(G, nodes);

	resultout(nodes);
	G.clear();
	nodes.clear();

	return 0;
} 

Measured memory_bytes: 7868
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        long d = sc.nextLong();
        d *= d;
        int ans = 0;
        for(int i = 0; i < n; i++){
            long x = sc.nextLong();
            long y = sc.nextLong();
            long dist = x*x+y*y;
            if(d >= dist){
                ans++;
            }
        }
        pw.println(ans);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 46352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c));
typedef long long ll;

int main()
{
  int d, g;
  cin >> d >> g;
  vector<ll> p(d), c(d);
  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 = 0;
    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 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <iostream>

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)
using namespace std;

const int maxn = 100 + 5;

int n;
int a[maxn], ans[maxn];

int getint() {
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

bool check(int x, int l, int r) {
	int cur = x;
	fo (i, l, r - 1)
		if (ans[i] <= cur) cur++;
	//if (l == 1 && r == 3) printf("%d\n", cur);
	return cur == r;
}

void ins(int x, int l, int r) {
	fd (i, r, l + 1) ans[i] = ans[i - 1];
	ans[l] = x;
}

int main() {
	n = getint();
	fo (i, 1, n)
		if ((a[i] = getint()) > i) {
			printf("-1\n");
			return 0;
		}
	//printf("---\n");
	fo (i, 1, n) {//printf("%d: ", i);
		//fo (k, 1, n) printf("%d, ", ans[k]);
		if (a[i] == i) {ans[i] = i; continue;}
		fd (j, i - 1, 1) 
		{
			//printf("---\n");
			if (check(a[i], j, i)) {
				ins(a[i], j, i);
				//printf("%d\n", j);
				//fo (k, 1, n) printf("ans[%d] = %d ", k, ans[k]);
				break;
			}
		}
		
		if (!ans[i]) {printf("-1\n"); return 0;}
	}
	
	fo (i, 1, n) printf("%d\n", ans[i]);
	return 0;
}


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

int N;
int x[100000],y[100000],t[100000],d[100000],tt[100000];

int main(){
  cin >> N;
  cin >> t[0] >> x[0] >> y[0];
  d[0] = abs(x[0])+abs(y[0]);
  tt[0] = t[0];

  for(int i=1; i<N; i++){
    cin >> t[i] >> x[i] >> y[i];
    d[i] = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    tt[i] = t[i]-t[i-1];
  }
  bool flag=true;
  for(int i=0; i<N; i++){
    if(tt[i]<d[i] || abs(tt[i]-d[i])%2==1){
      flag=false;
      break;
    }
  }
  if(flag)  cout << "Yes" << endl;
  else  cout << "No" << endl;
}

Measured memory_bytes: 2176
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
	int a, b;
	
	cin >> a >> b;
	
	int d = a / b;
	int r = a % b;
	double f = (double)a / (double)b;
	
	cout << setprecision(5);
	cout << d << " " << r << " " << fixed << f << endl;
	
	
	return 0;
}

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

#define int long long
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; }

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

	vector<int> a(n);
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	cout << a.back() - a.front() << endl;

	return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
void read(long long& x){ scanf("%lld",&x); }
template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); }

const int max_n = 500010;

vector<pp> edge[max_n];
vector<pp> raw_edge[100010];
vector<int> comps[100010];
vector<int> order[100001];
int trans[100001];
int N;

int n, m;

void uni(vector<int>& v){
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}

int ind(vector<int>& v, int x){
    return lower_bound(all(v), x) - v.begin();
}

int get(int vert,int comp){
    return order[vert][ind(comps[vert], comp)];
}

typedef long long ll;

ll dijk[max_n];
typedef pair<ll,int> pli;
priority_queue<pli> pq;
ll inf=(1LL<<60);

int main()
{
    read(n, m);
    for(int i=0; i<m; ++i){
        int a, b, c;
        read(a, b, c);
        raw_edge[a].pb(pp(b, c));
        raw_edge[b].pb(pp(a, c));
        comps[a].pb(c);
        comps[b].pb(c);
    }
    for(int i=1; i<=n; ++i){
        uni(comps[i]);
        trans[i] = ++N;
        for(int j=0; j<comps[i].size(); ++j){
            order[i].pb(++N);
            edge[trans[i]].pb(pp(N, 1));
            edge[N].pb(pp(trans[i], 1));
        }
    }
    for(int i=1; i<=n; ++i){
        for(pp& re : raw_edge[i]){
            int nxt = re.first;
            int com = re.second;
            int me = get(i, com);
            int you = get(nxt, com);
            edge[me].pb(pp(you, 0));
        }
    }
    for(int i=1; i<=N; ++i) dijk[i]=inf;
    dijk[trans[1]] = 0;
    pq.push({0, trans[1]});
    while(pq.size()){
        ll dst; int pt;
        tie(dst, pt) = pq.top(); pq.pop(); dst=-dst;
        if(dijk[pt] != dst) continue;
        for(pp& e : edge[pt]){
            int nxt, dst; tie(nxt, dst) = e;
            if(dijk[nxt] > dijk[pt] + dst){
                dijk[nxt] = dijk[pt]+dst;
                pq.push({-dijk[nxt], nxt});
            }
        }
    }
    if(dijk[trans[n]] == inf) puts("-1");
    else printf("%lld\n", dijk[trans[n]]/2);
    return 0;
}


Measured memory_bytes: 57200
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int x,y,z,sum,flag;
	while(~scanf("%d%d%d",&x,&y,&z)){
		sum=0;
		flag=0;
		for(int i=1; ;i++){
			sum = sum+z;
			if(sum>=x) break;
			sum = sum+y;
			if(sum>x-z) break;
			flag++;
		}
		printf("%d\n",flag);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long comb[51][51] = {};

void combination() {
    comb[0][0] = 1;
    for(int j=1; j<=50; ++j) comb[0][j] = 0;
    for(int i=1; i<=50; ++i) {
        for(int j=0; j<=50; ++j) {
            if(j==0) comb[i][j] = comb[i-1][j];
            else comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
        }
    }
}

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    vector<long long> v(N);
    for(int i=0; i<N; ++i) cin >> v[i];
    sort(v.begin(), v.end(), greater<long long>());
    long long ans = 0;
    for(int i=0; i<A; ++i) ans += v[i];
    printf("%.6f\n", (double)ans / (double)A);
    
    combination();
    if(v[0] == v[A-1]) {
        int cnt = count(v.begin(), v.end(), v[0]);
        long long ans = 0;
        for(int i=A; i<=cnt && i<=B; ++i) ans += comb[cnt][i];
        cout << ans << endl;
    } else {
        int cnt = count(v.begin(), v.end(), v[A-1]);
        int cnt2 = count(v.begin(), v.begin()+A, v[A-1]);
        long long ans = comb[cnt][cnt2];
        cout << ans << endl;
    }
    return 0;
}

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


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

    int n,m,k;
    cin>>n>>m>>k;
    bool ok=false;
    if(k%n==0 || k%m==0) ok=true;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(i*n+j*m-2*i*j == k)ok=true;
        }
    }
    if(ok){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, k = LI()
    a = LI()
    dp = [0] * (k + 1)
    acc = [1] * (k + 1)
    dp[0] = 1
    for i in range(n):
        for l in range(1, k + 1):
            dp[l] = acc[l]
            dp[l] -= acc[l - a[i] - 1] if l - a[i] > 0 else 0
            dp[l] %= mod
        for l in range(1, k + 1):
            acc[l] = acc[l - 1] + dp[l]
            acc[l] %= mod
    print(dp[-1])


    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 43092
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL n, a[200000 + 5], d[200000 + 5];
int main() {
	cin >> n;
	for (LL i = 1; i <= n; ++i) scanf("%lld", &a[i]), a[i] *= 2ll;
	for (LL i = 1; i <= n; ++i) d[1] += a[i] * (i % 2 ? 1 : -1);
	d[1] /= 2;
	for (LL i = 2; i <= n; ++i) d[i] = a[i - 1] - d[i - 1];
	for (LL i = 1; i <= n; ++i) printf("%lld ", d[i]);
	return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

string s;
unsigned long n;

string sa[4] = {"dream", "dreamer", "erase", "eraser"};

void f(unsigned long len) {
  //cout << len << ": " << ts << endl;
  if (len == s.length()) {
      cout << "YES\n";
      exit(0);
      return ;
  }
  if (len > s.length())
    return;
  
  for (int i = 0; i < 4; i++) {
    if (len+sa[i].length() <= s.length() && s.substr(len, sa[i].length()) == sa[i]) {
      f(len+sa[i].length());
    }
  }
}


int main()
{
  cin >> s;
  n = s.length();
  f(0);
  
  cout << "NO\n";
  
  return 0;
}


Measured memory_bytes: 2048
/*ex5-4
ryo_1129*/

#include <stdio.h>

int main(void){
    //入力の文字列は10文字以下なので\0を含めて11で定義する
    char str[11],*p;
    //ACGT配列の長さと、最長の長さをいれる変数
    int length_counter=0,max_length=0;
    scanf("%s",str);
    p = str;
    while(*p){
        //ACTGが続く間はlength_counterに部分文字列の長さを記録する
        if(*p=='A' || *p =='G' || *p=='C' || *p=='T'){
            length_counter++;
        //ACGT以外の文字が出てきたら、部分文字列が最長か比較しlength_counterをリセットする
        }else{
            if(max_length<length_counter){
                max_length = length_counter;
            }
            length_counter=0;
        }
        p++;
    }
//AGCTのみで文字列が構成されていた場合
if(max_length<length_counter){
    max_length = length_counter;
}

    printf("%d\n",max_length);
    return 0;
}

Measured memory_bytes: 1692
#include <stdio.h>

int main(void){
    int K,N;
    int A[2*10*10*10*10*10];
    
    int maxlength=0,length=0,i,min;
    
    scanf("%d",&K);
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    
    for(i=0;i<N;i++){
        if(i!=N-1){
            length=A[i+1]-A[i];
        }else{
            length=(K-A[N-1])+A[0];
        }
        
        if(maxlength<length){
                maxlength=length;
        }
    }
    
    min=K-maxlength;
    
    printf("%d\n",min);
    
    return 0;
}

Measured memory_bytes: 896
import collections

while 1:
    n = int(input())
    if n == 0:
        break

    data = list(input().split())
    vote = [0] * 26
    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    alpha = list(alpha)

    for i, v in enumerate(data):
        num = alpha.index(v)
        vote[num] += 1
        tmp = zip(vote, alpha)
        tmp = sorted(tmp, key=lambda x: -x[0])
        vote, alpha = zip(*tmp)
        vote = list(vote)
        alpha = list(alpha)

        if vote[0] > (n-i-1) + vote[1]:
            print(alpha[0], i+1)
            break
    else:
        print("TIE")



Measured memory_bytes: 5992
/*
 * atcoder/abc163/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

ll N, M;
void solve() {
  cin >> N >> M;
  ll a;
  loop(m,0,M) {
    cin >> a;
    N -= a;
  }

  chmax(N, -1LL);
  cout << N << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


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

int main(){
  int teamn = 0;
  cin >> teamn;
  vector<int> point(teamn,0);
  vector<int> run(teamn,0);
  vector<int> rank(teamn,1);
  int fteam1,fteam2;
  int point1,point2;
  for(int n = 0;n<(teamn*(teamn-1))/2;n++){
    cin >> fteam1 >> fteam2;
    cin >> point1 >> point2;
    fteam1 -= 1;
    fteam2 -= 1;
    if(point1 > point2){
      point[fteam1] += 3;
    }else
    if(point1 == point2){
      point[fteam1] += 1;
      point[fteam2] += 1;
    }else
    if(point1 < point2){
      point[fteam2] += 3;
    }
  }
  for(int g = 0;g<point.size();g++){
    run[g] = point[g];
  }
  sort(run.begin(),run.end(),greater<int>());
  for(int n = 0;n<run.size();n++){
    for(int g = 0;g<point.size();g++){
      if(n == 0 && run[n] == point[g]){
        rank[g] = n;
      }
      if(run[n] == point[g] && n != 0){
        if(run[n] != run[n-1]){
          rank[g] = n;
        }
      }
    }
  }
  for(int n = 0;n<rank.size();n++){
    cout << rank[n]+1 << endl;
  }
  return 0;
}

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

int main() {
  int n, b = -1, S = 0;
  cin >> n;
  set<int> s;
  for(int i = 0;i < n;i++) {
    int a;
    cin >> a;
    if(a == b + 1) s.insert(b);
    b = a;
  }
  for(int i = 0;i < n;i++) {
    int B;
    cin >> B;
    S += B;
  }
  for(int i = 1;i < n;i++) {
    int c;
    cin >> c;
    if(s.count(i)) S += c;
  }
  cout << S << endl;
}

Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
print(sum(range(n+1)))

Measured memory_bytes: 63852
#include <bits/stdc++.h>
using namespace std;
vector <string> ans;
string Str,str;

bool check(int n){
  bool alph[300]={};
  alph['a']=1;
  for(int i=0;i<n;i++){
    int flg=0;
    if(!alph[str[i]])flg=alph[str[i]]=1;
    if(str[i]-flg!=Str[i])return 0;
  }
  return 1;
}

bool used['z'];
void saiki(int idx){
  while(used[str[idx]]||str[idx]=='z')idx++;
  if(!check(idx))return;

  if(idx==str.size()){
    ans.push_back(str);
    return;
  }
  
  saiki(idx+1);
  str[idx]++;
  used[str[idx]-1]=1,saiki(idx+1),used[str[idx]-1]=0;
  str[idx]--;
}

int main(){
  while(1){
    cin>>Str;
    str=Str;
    if(Str=="#")break;
    ans.clear();
    saiki(0);
    sort(ans.begin(),ans.end());

    cout <<ans.size()<<endl;
    if(ans.size()<=10)
      for(int i=0;i<ans.size();i++)cout <<ans[i]<<endl;
    else {
      for(int i=0;i<5;i++)cout<<ans[i]<<endl;
      for(int i=0;i<5;i++)cout<<ans[ans.size()-5+i]<<endl;
    }
  } 
  return 0;
}

Measured memory_bytes: 2352
#include<stdio.h>
int main(){
  int n=0,t,i,c;
  char s[1001];
  while(1){
    fgets(s,1000,stdin);
    if(s[0]=='0')break;
    t=0;
    c=0;
    for(i=0;s[i]!=0;i++){
      if(s[i]==' '||s[i]=='\n'){
	if(n>10)n=10;
	t+=n;//printf("%d,",n);
	if(n==1){
	  t+=10;
	  c++;
	}
	n=0;
      }
      else{
	n*=10;
	n+=s[i]-'0';
      }
    }
    while(c!=0){
      if(t>21){
	c--;
	t-=10;
      }
      else  break;
    }
    if(t>21)t=0;
    printf("%d\n",t);
  }
  return 0;
}

Measured memory_bytes: 524