akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define pb(c) push_back(c)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int dis[111][111];
int c, n, m, s, d;
int next[111][111];

void dfs(int cur, int sum, int cost){
  if(next[cur][sum] < cost) return;
  next[cur][sum] = cost;
  for(int i = 0; i < n; i++){
    if(dis[cur][i] == (1<<29)) continue;
    if(sum > 0) dfs(i, sum-1, cost+(dis[cur][i]/2));
    dfs(i, sum, cost+dis[cur][i]);
  }
}

int main(){
  ios::sync_with_stdio(false);

  while(cin >> c >> n >> m >> s >> d && (c||n||m||s||d)){

    for(int i = 0; i < 111; i++){
      for(int j = 0; j < 111; j++){
        dis[i][j] = next[i][j] = (1<<29);
      }
    }

    for(int i = 0; i < m; i++){
      int a, b, f;
      cin >> a >> b >> f;
      a--; b--;
      dis[a][b] = f;
      dis[b][a] = f;
    }

    dfs(s-1,c,0);
    int ans = (1<<29);
    for(int i =0; i < c; i++){
      ans = min(ans, next[d-1][i]);
    }
    cout << ans << endl;
  }


}

Measured memory_bytes: 1296
n,m = map(int,input().split())
gate = [[int(i) for i in input().split()] for _ in range(m)]

minv = gate[0][0]
maxv = gate[0][1]

for x in gate:
  minv = max(minv,x[0])
  maxv = min(maxv,x[1])
  
print(maxv-minv+1 if maxv-minv+1 >= 1 else 0)
  

Measured memory_bytes: 25696
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

    #pragma GCC optimize("O3")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    /*#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC target ("avx2")*/

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

ll MAX = 1e15;
double PI = 3.141592653589793238463;
//double PI = acos(-1);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


void solve(){
    string s;
    cin >> s;
    ll x = s[s.size()-1]-'0';
    if(x==3){
        cout << "bon";
    }
    else if(x==0 || x==1 || x==6 || x==8){
        cout << "pon";
    }
    else {
        cout << "hon";
    }

}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif


    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }


    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef pair<int, int> St;
int calc(int P, vector<int> Q, vector<int> R, int x){
  int sum = 0;
  REP(i, P){
    if(Q[i] < x && x <= Q[i + 1]){
      return sum + R[i] * (x - Q[i]);
    }
    sum += R[i] * (Q[i + 1] - Q[i]);
  }
  assert(false);
}

int main(){
  int N, M, C, S, G;
  while(cin >> N >> M >> C >> S >> G && N){
    S--; G--;
    int dist[20][100][100] = {};
    REP(i, C) REP(j, N) REP(k, N) dist[i][j][k] = (j == k) ? 0 : INF;
    REP(i, M){
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      c--;
      x--; y--;
      dist[c][x][y] = min(dist[c][x][y], d);
      dist[c][y][x] = min(dist[c][y][x], d);
    }
    int P[20];
    vector<int> Q[20];
    vector<int> R[20];
    REP(i, C) cin >> P[i];
    REP(i, C){
      Q[i] = vector<int>(P[i], 0);
      R[i] = vector<int>(P[i]);
      REP(j, P[i] - 1) cin >> Q[i][j + 1];
      REP(j, P[i]) cin >> R[i][j];
      Q[i].push_back(INF);
    }
    REP(c, C) {
      REP(k, N) REP(i, N) REP(j, N) dist[c][i][j] = min(dist[c][i][j], dist[c][i][k] + dist[c][k][j]);
    }
    priority_queue<St, vector<St>, greater<St> > que;
    vector<int> ans(N, INF);
    bool used[100] = {};
    que.push(St(0, S));
    ans[S] = 0;
    while(!que.empty()){
      int u = que.top().second;
      int d = que.top().first;
      que.pop();
      if(used[u]) continue;
      used[u] = true;
      REP(v, N) if(!used[v]){
        REP(c, C) if(dist[c][u][v] < INF){
          //printf("dist[%d][%d][%d] = %d\n", c, u, v, dist[c][u][v]);
          int nd = d + calc(P[c], Q[c], R[c], dist[c][u][v]);
          if(nd < ans[v]){
            ans[v] = nd;
            que.push(St(nd, v));
          }
        }
      }
    }
    if(ans[G] < INF) {
      cout << ans[G] << endl;
    }else{
      cout << -1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2124
#include <stdio.h>

int main(void){
    char s[11], t[11];
    int i,j=0;
    scanf("%s",s);
    for(i=0; s[i] != '\0'; i++){
        if(s[i] != 'B'){
            t[j] = s[i];
            j++;
        }else if(j>=1){
            t[j-1] = ' ';
            j--;
        }
    }
    t[j]='\0';
    printf("%s\n",t);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll a, b, k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> k >> a >> b;
  if(k <= a || b-a <= 2){
    cout << k+1 << endl;
    return 0;
  }
  k -= a-1;
  cout << (a + (k&1) + k/2*(b-a)) << endl;
}

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

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

typedef long long ll;
typedef pair<int, int> pi;

int n;
int m;
const int maxn = 1e5 + 5;
vector<int> G[maxn];

int c[maxn];

bool flag;

int dfs(int u, int col){
    c[u] = col;
    int ans = 1;
    for(auto v : G[u]){
        if(c[v] == -1){
            ans += dfs(v, col ^ 1);
        }else{
            if(c[v] == col)
                flag = false;
        }
    } 
    return ans;
}

int cnt[3];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    memset(c, -1, sizeof(c));
    for(int i = 1;i <= n;i++){
        if(c[i] == -1){
            flag = true;
            int sz = dfs(i, 1);
            if(sz == 1)
                cnt[0]++;
            else{
                if(flag){
                    cnt[1]++;
                }else{
                    cnt[2]++;
                }
            }
        } 
    }
    ll ans = 0;
    ans += 2LL * cnt[1] * cnt[1];
    ans += 1LL * cnt[2] * cnt[2];
    ans += 2LL * cnt[1] * cnt[2];
    ans += 1LL * cnt[0] * (2 * n - cnt[0]);
    cout << ans << endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x,y,z;
    std::cin >> x>>y>>z;
    
    std::cout << z<<" "<<x<<" "<<y << std::endl;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#define gc getchar()
using namespace std;
const int N=200009;
int n,m,vis[N],Max,x;
int read()
{
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
int main()
{
	for (n=m=read();n;n--) Max=max(Max,vis[x=read()]=vis[x-1]+1);
	printf("%d\n",m-Max);
	return 0;
}


Measured memory_bytes: 1024
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0
 
solve()

Measured memory_bytes: 2940
n=int(input())
d = {}
for i in range(26):
  d[chr(ord("a")+i)]=10**9
for i in range(n):
  s=input()
  for j in range(26):
    d[chr(ord("a")+j)]=min(d[chr(ord("a")+j)], s.count(chr(ord("a")+j)))

ans = ""
for e in d.items():
  ans+=e[0]*e[1]
print(ans)
  
  


Measured memory_bytes: 74068
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,K;

int main()
{
  cin>>N>>K;
  
  N=N%K;

   cout <<min(N,K-N);

  
}

Measured memory_bytes: 256
n,m=map(int,input().split())
s=input()[::-1]

if "1"*m in s:
  print(-1)
  exit(0)

ans=[]
cur=0
while cur<len(s):
  for j in range(m,0,-1):
    if cur+j>=len(s):
      continue
    if s[cur+j]=="0":
      cur=cur+j
      ans.append(j)
      break
  if cur==len(s)-1:
    break

ans=ans[::-1]
print(*ans)

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

#define N               200005
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define inp(arr,n)      for(ll x=0;x<n;x++) cin>>arr[x];
#define w(x)            ll x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void fio(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    fio();

    ll n;
    cin>>n;

    pii a[n];
    for(ll x=0;x<n;x++) cin>>a[x].ff>>a[x].ss;

    bool p = false;
    for(ll x=0;x<n-2;x++){
        ll y = x+1, z = x+2;
        if(a[x].ff == a[x].ss and a[y].ff == a[y].ss and a[z].ff == a[z].ss){
            p = true;
            break;
        }
    }

    if(p) cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 3640
//E
//by Cydiater
//2017.6.24
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define up(i,j,n)	for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
#define pii		pair<int,int>
#define fi		first
#define se		second

const int MAXN=4e5+5;
const int oo=0x3f3f3f3f;

int R,C,N,top=0,cnt=0;
pii a[MAXN],b[MAXN],sta[MAXN];
map<pii,bool>mark;

namespace solution{
	inline bool cmp(pii x,pii y){
		int xx,yy;
		xx=x.se==-1?a[x.fi].fi:a[x.fi].se;
		yy=y.se==-1?a[y.fi].fi:a[y.fi].se;
		return xx<yy;
	}
	int calc(pii a){
		if(!a.fi){
			if(!a.se)return 0;
			return 2*R+2*C-a.se;
		}
		if(!a.se)return a.fi;
		if(a.fi==R)return R+a.se;
		if(a.se==C)return 2*R+C-a.fi;
	}
	bool ok(pii a){
		if(a.fi==0||a.fi==R)return 1;
		if(a.se==0||a.se==C)return 1;
		return 0;
	}
	void Prepare(){
		scanf("%d%d%d",&R,&C,&N);
		up(i,1,N){
			pii s,t;
			scanf("%d%d%d%d",&s.fi,&s.se,&t.fi,&t.se);
			if(!ok(s)||!ok(t))continue;
			int p=calc(s),q=calc(t);
			if(p>q)swap(p,q);
			a[++top]=make_pair(p,q);
			if(mark[s]||mark[t]){
				puts("NO");
				exit(0);
			}
			mark[s]=1;mark[t]=1;
//			cout<<p<<' '<<q<<endl;
		}	
	}
	void Solve(){
		up(i,1,top){
			b[++cnt]=make_pair(i,-1);
			b[++cnt]=make_pair(i,1);
		}
		sort(b+1,b+cnt+1,cmp);
		top=0;
		up(i,1,cnt){
			pii now=b[i];
			int x=now.fi,p=now.se;
			if(p==1)top--;
			else{
				if(!top)sta[++top]=a[x];
				else{
					if(a[x].se<sta[top].se)sta[++top]=a[x];
					else{
						puts("NO");
						return;
					}
				}
			}
		}
		puts("YES");
	}
}

int main(){
//	freopen("input.in","r",stdin);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}

Measured memory_bytes: 19328
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

 
 
const int INF = 1000000;


char calc(char c, int n){
	char ret;
	
	if(c <= 'Z') ret = c - 'A';
	else ret = c - 'a' + 26;

	ret = (ret - n + 52) % 52;
	ret += ret < 26 ? 'A' : 'a' - 26;

	return ret;
}

int main(){
	string s;
	int n;
	
	while(cin>>n){
		if(n == 0) break;
		vi v(n, 0);
		rep(i, n) cin>>v[i];
		cin>>s;

		for(int i = 0; i < s.size(); i++){
			s[i] = calc(s[i], v[i % v.size()]);
		}

		cout<<s<<endl;
	}
}

Measured memory_bytes: 1208
H,W = map(int,input().split())

# count = 1
# que = [(0,0)]
# check = set()
# check.add((0,0))
# while que:
#     points = que.pop()

#     ru = (points[0]+1,points[1]-1)
#     if ru[0]<W and -1<ru[1] and ru not in check:
#         que.append(ru)
#         check.add(ru)
#         count += 1
    
#     rd = (points[0]+1,points[1]+1)
#     if rd[0]<W and rd[1]<H and rd not in check:
#         que.append(rd)
#         check.add(rd)
#         count += 1
    
#     lu = (points[0]-1,points[1]-1)
#     if -1<lu[0] and -1<lu[1] and lu not in check:
#         que.append(lu)
#         check.add(lu)
#         count += 1
    
#     ld = (points[0]-1,points[1]+1)
#     if -1<ld[0] and ld[1]<H and ld not in check:
#         que.append(ld)
#         check.add(ld)
#         count += 1

block = H//2 * W
tip = W//2 if W%2==0 else W//2+1
tip = tip if H%2!=0 else 0


ans = 1 if H==1 or W==1 else block+tip
print(ans)

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

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

    vector <long long> a, b;
    for (int i = 0; i < n; i ++){
        long long _a, _b; cin >> _a >> _b;
        a.push_back(_a);
        b.push_back(_b);
    }

    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    // for (int i = 0; i < a.size(); i ++) cout << a[i];
    // cout << endl;

    long long ans = 0;
    for (int i = 0; i < n; i ++){
        if ((a[i] + ans) % b[i] == 0) continue;

        ans += b[i] - ((a[i] + ans) % b[i]);
    }

    cout << ans << endl;

}

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

  static const int N = 100;

  int main() {
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
   for ( int i = 1; i <= n; i++ ) {
     cin >> p[i - 1] >> p[i];
   }

   for ( int i = 1; i <= n; i++ ) m[i][i] = 0;
   for ( int l = 2; l <= n; l++ ) {
     for ( int i = 1; i <= n - l + 1; i++ ) {
       int j = i + l - 1;
       m[i][j] = (1 << 21);
       for ( int k = i; k <= j - 1; k++ ) {
         m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
       }
     }
   }

   cout << m[1][n] << endl;

   return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll h,w;
    while(true){
        cin>>h>>w;
        if(h==0&&w==0)return 0;
        REP(i,h){
            REP(j,w){
                if((i+j)%2==0)cout<<"#";
                else cout<<".";
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3088
# abc120_b.py
# https://atcoder.jp/contests/abc120/tasks/abc120_b

# ★ WA:10
# sample_02
# testcase_1
# testcase_10
# testcase_2
# testcase_3
# testcase_5
# testcase_6
# testcase_7
# testcase_8
# testcase_9

# B - K-th Common Divisor /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 正整数 A,Bが与えられます。
# Aも B も割り切る正整数のうち、K番目に大きいものを求めてください。
# なお、与えられる入力では、Aも B も割り切る正整数のうち K番目に大きいものが存在することが保証されます。

# 制約
#     入力は全て整数である。
#     1≤A,B≤100
#     Aも B も割り切る正整数のうち、K番目に大きいものが存在する。
#     K≥1

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B K

# 出力
# Aも B も割り切る正整数のうち、K番目に大きいものを出力せよ。

# 入力例 1
# 8 12 2

# 出力例 1
# 2

# 8と 12 を割り切る正整数は 1,2,4 です。 この中で 2 番目に大きいものは 2です。

# 入力例 2
# 100 50 4

# 出力例 2
# 5

# 入力例 3
# 1 1 1

# 出力例 3
# 1


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    A, B, K = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))

    cnt = 0

    for i in range(1, 101):
        if A % (101-i) == 0 and B % (101-i) == 0:
            cnt += 1
        if cnt == K:
            return [(101-i)]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['8 12 2']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['100 50 4']
        lines_export = [5]
    if pattern == 3:
        lines_input = ['1 1 1']
        lines_export = [1]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    if FLAG_LOG:
        log(f'lines_input=[{lines_input}]')
        log(f'lines_export=[{lines_export}]')
        log(f'lines_result=[{lines_result}]')
        if lines_result == lines_export:
            log('OK')
        else:
            log('NG')
    finished = time.time()
    duration = finished - started
    log(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int main(void){
	long long X,A,B,buff,L;
	int i,flag;
	char str[10000000],buf[10000000];
 
	fgets(str, sizeof(str), stdin);
	X=strtoll(strtok(str ," "),buf,10);

	L=pow((double)X,0.2)+1;
  	if(X!=1){
	      	A=2;B=0;flag=0;
	      	while(1){
			for(B=-L;B<A;B++){
				if( X%(A-B)==0){
					buff=A*A*A*A + A*A*A*B + A*A*B*B + A*B*B*B + B*B*B*B;
					if( X%buff==0){
			                    	flag=1;
			                    	break;
	                 		 }
				}
			}
			if( flag==1){
				buff=A*A*A*A*A-B*B*B*B*B;
				if(X==buff) break;
			} 
			A++;
		}
		printf("%lld %lld\n",A,B);
	}else{
   		printf("1 0\n");   
	}

	return 0;
}

Measured memory_bytes: 2564
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)
    {
        cin >> A.at(i);
    }
    int min=0,max=0,count=0;
    vector<bool> B(8);
    for(int i=0; i<8; i++) B.at(i)=false;
    for(int i=0; i<N; i++)
    {
        if(A.at(i)>=1&&A.at(i)<=399) B.at(0)=true;
        if(A.at(i)>=400&&A.at(i)<=799) B.at(1)=true;
        if(A.at(i)>=800&&A.at(i)<=1199) B.at(2)=true;
        if(A.at(i)>=1200&&A.at(i)<=1599) B.at(3)=true;
        if(A.at(i)>=1600&&A.at(i)<=1999) B.at(4)=true;
        if(A.at(i)>=2000&&A.at(i)<=2399) B.at(5)=true;
        if(A.at(i)>=2400&&A.at(i)<=2799) B.at(6)=true;
        if(A.at(i)>=2800&&A.at(i)<=3199) B.at(7)=true;
        if(A.at(i)>=3200) count++;
    }
    for(int i=0; i<8; i++)
    {
        if(B.at(i))
        {
            min++;
        }
    }
    max=min+count;
    /*if(max>=8) max=8;*/
    if(min==0) min=1;
    cout << min << " " << max <<endl;
}

Measured memory_bytes: 3604
# include <stdio.h>
# include <string.h>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9+7;

# define FO_OPEN 0
# define RG register
# define ST static

int n, q;
ll add[M], st[M], s[M], cur;
int stn=0;

int main() {
	FO_OPEN ? freopen(".in", "r", stdin), freopen(".out", "w", stdout) : 0;
	scanf("%d%d", &n, &q);
	st[++stn] = n;
	for (int i=1; i<=q; ++i) {
		scanf("%lld", &cur);
		while(stn && st[stn] >= cur) --stn;
		st[++stn] = cur; 
	}
	
	add[stn] = 1;
	for (int i=stn; i>1; --i) {
		if(!add[i]) continue;
		ll x = st[i];
		while(x >= st[1]) {
			int pos = upper_bound(st+1, st+i, x) - st - 1;
			add[pos] += add[i] * (x/st[pos]);
			x = x % st[pos];
		}
		s[x] += add[i];
		add[i] = 0;
	}
	
	s[st[1]] += add[1];
	for (int i=n; i; --i) 
		s[i] += s[i+1];
	for (int i=1; i<=n; ++i)
		printf("%lld\n", s[i]);
	return 0;
}





Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	string s,t;cin>>s>>t;
	rep(i,0,N){
		cout<<s[i]<<t[i];
	}cout<<endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long K, std::string S){
    if (S.size() <= K) {
        cout << S << endl;
        return;
    }
    S = S.substr(0, K);
    S += "...";
    cout << S << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3692
# -*- coding: utf-8 -*-

s = list(input())
a = s[0] + s[1]
a = int(a)
b = s[2] + s[3]
b = int(b)

yymm = False
mmyy = False

if 1 <= b <= 12:
    yymm = True

if 1 <= a <= 12:
    mmyy = True

if yymm and mmyy:
    print("AMBIGUOUS")
elif yymm:
    print("YYMM")
elif mmyy:
    print("MMYY")
else:
    print("NA")


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

int main()
{
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }

  int ans = 0;
  int b = 1;
  
  for(int i = 0; i < n; i++){
    if(a.at(i) == b){
      b++;
    }
    else{
      ans++;
    }
  }
  
  if(b == 1){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,score;
  score=0;
  cin>>N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N);
  for(int i=0;i<N;i++){
  cin>>A.at(i);
  }
  for(int i=0;i<N;i++){
  cin>>B.at(i);
  score+=B.at(i);
  }
  for(int i=0;i<N-1;i++){
    cin>>C.at(i);
  }
  for(int i=0;i<N-1;i++){
    if(A.at(i+1)==A.at(i)+1)score+=C.at(A.at(i)-1);
  }
  cout<<score<<endl;
}
  

Measured memory_bytes: 256
def phi(n):
  ret=1
  rem=1
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      ret*=i-1
      n=n//i
      while n%i==0:
        n=n//i
        rem*=i
  if n>1:
    ret*=n-1
  return ret*rem
 
n=int(input())
print(phi(n))


Measured memory_bytes: 5632
#include<stdio.h>
int main()
{
    int a,b,c,d,c1=0,c2=0;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(c>0)
    {
       c=c-b;
       c1++;
    }
    while(a>0)
    {
        a=a-d;
        c2++;
    }
    if(c1>c2)
    {
        printf("No\n");
    }
    else
        {
            printf("Yes\n");
        }

    return 0;
}


Measured memory_bytes: 1644
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <stdio.h>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;

int n;
int a[100010];

int main() {
	
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 1)cnt++;
	}
	cout << ((cnt % 2 == 0) ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int a,b,c,d;
	cin>>s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	if(a+b+c+d==7)
		return printf("%d+%d+%d+%d=7\n",a,b,c,d),0;
	if(a+b+c-d==7)
		return printf("%d+%d+%d-%d=7\n",a,b,c,d),0;
	if(a+b-c+d==7)	
		return printf("%d+%d-%d+%d=7\n",a,b,c,d),0;
	if(a+b-c-d==7)	
		return printf("%d+%d-%d-%d=7\n",a,b,c,d),0;
	if(a-b+c+d==7)
		return printf("%d-%d+%d+%d=7\n",a,b,c,d),0;
	if(a-b+c-d==7)
		return printf("%d-%d+%d-%d=7\n",a,b,c,d),0;
	if(a-b-c+d==7)
		return printf("%d-%d-%d+%d=7\n",a,b,c,d),0;
	if(a-b-c-d==7)
		return printf("%d-%d-%d-%d=7\n",a,b,c,d),0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll A, V, B, W; cin >> A >> V >> B >> W;
    ll T; cin >> T;
    if (A > B) swap(A, B);
    if (A + T * V >= B + T * W) {
        cout << "YES" << nl;
    } else cout << "NO" << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3608
#include <stdio.h>
int main(void){
    int h,w,i,j;
    char s[51][51];
    scanf("%d%d",&h,&w);
    for(i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(s[i][j]=='#'){
                int c=0;
                if(i>0 && s[i-1][j]=='#') c++;
                if(i<h && s[i+1][j]=='#') c++;
                if(j>0 && s[i][j-1]=='#') c++;
                if(j<w && s[i][j+1]=='#') c++;
                if(c==0){
                    printf("No");
                    return 0;
                }
            }
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
        int d,n=1,s=0;
		while(cin>>d){
        for(int i =1;i<(600/d);i++){
                for(int j=1;j<=2;j++){
                        n*=(i*d);
                        }
                s += d * n;
				n=1;
}
        cout<<s<<endl;
		s=0;
		}
}

Measured memory_bytes: 0
N, C = map(int, input().split())
# D[i][j] = 色をiからjに変える時の「違和感」 = 「コスト」
D = [list(map(int, input().split())) for _ in range(C)]
# 最初の色
c = [list(map(int, input().split())) for _ in range(N)]

# cnt[i][j] = 初期状態において、(x+y)%3==iで、色がj(0,1,...,C-1)の数
cnt = [[0 for _ in range(C)]for _ in range(3)]
# グリッド全体(N*N)を調べる
for i in range(1, N + 1):
    for j in range(1, N + 1):
        cnt[(i + j) % 3][c[i - 1][j - 1] - 1] += 1
# print(cnt)

ans = 10**18

# (x+y)%3==0,1,2をc0,c1,c2で塗る
for c0 in range(C):
    for c1 in range(C):
        for c2 in range(C):
            # 同じ色があってはならない
            if c0 == c1 or c1 == c2 or c2 == c0:
                continue

            cost = 0
            # (x+y)%3==0 をc0に塗り替える
            for i, n in enumerate(cnt[0]):
                cost += n * D[i][c0]
            # (x+y)%3==1 をc1に塗り替える
            for i, n in enumerate(cnt[1]):
                cost += n * D[i][c1]
            # (x+y)%3==2 をc2に塗り替える
            for i, n in enumerate(cnt[2]):
                cost += n * D[i][c2]

            ans = min(ans, cost)

print(ans)


Measured memory_bytes: 76804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	ll a[n];
	rep(i, 0, n){
		cin >> a[i];
	}
	sort(a, a+n);
	
	ll ans = 0;
	ll l = a[n-1];
	ll r = a[n-1];
	bool isl;
	for(ll i = 0; i < n-1; i++){
		
		ll m = (i%2 == 0)? a[i/2] : a[n-2-i/2];
		
		if(i%2 == 0 || i == n-2){	
			if(abs(l-m) > abs(r-m)){
				ans += abs(l-m);
				l = m;
				isl = true;
			}
			else{
				ans += abs(r-m);
				r = m;
				isl = false;
			}
		}
		else{
			if(isl){
				ans += abs(l-m);
				l = m;
			}
			else{
				ans += abs(r-m);
				r = m;
			}
		}
	}
	
	print(ans)
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A_list = list(map(int, input().split()))
A_list.sort()
A_max = A_list[-1]
count = 0
cnt_list = [1] * ((10 ** 6) + 1)
for i in range(len(A_list)-1):
    if cnt_list[A_list[i]] == 1:
        for j in range((A_max // A_list[i]) + 1):
            cnt_list[A_list[i] * j] = 0
        if A_list[i] != A_list[i+1]:
            count += 1
if cnt_list[A_list[-1]] == 1:
    count += 1
print(count)

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

const int M = 1003;
const int N = 12;
int dp[1 << N];
vector<int> key[M];
int cost[M];

int main(){
    fcin;

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < m; i++){
        int k;
        cin >> cost[i] >> k;

        for(int j = 0; j < k; j++){
            int x;  cin >> x;
            x--;
            key[i].pb(x);
        }
    }

    memset(dp, -1, sizeof dp);
    dp[0] = 0;
    for(int i = 0; i < (1 << N); i++){
        for(int j = 0; j < m; j++){
            int mask = i;
            for(int k : key[j]) mask |= (1 << k);
            
            if(dp[i] >= 0){
                if(~dp[mask]) dp[mask] = min(dp[mask], dp[i] + cost[j]);
                else dp[mask] = dp[i] + cost[j];
            }
        }
    }

    if(dp[(1 << n) - 1] == -1) cout << -1 << endl;
    else cout << dp[((1 << n) - 1)] << endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

string to_string(string s) { return '\"' + s + '\"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A,B> p)
{ return "(" + to_string(p.F) + ", " + to_string(p.S) + ")"; }
template <typename T> string to_string(T v) {
	int f = 0; string res = "{";
	for (const auto &x: v)
		res += (f++ ? ", " : "") + to_string(x);
	return res + "}";
}
void debug_out() { cerr << "]\n"; }
template <typename T, typename... V>
void debug_out(T a, V... v)
{ cerr << to_string(a); if (sizeof...(v)) cerr << ", "; debug_out(v...); }

#ifdef LOCAL // add -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif // debug(var1, var2, ...);

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a*b << '\n';
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

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

    vector<vector<int>> n(s.size(), vector<int>(27, -1));
    for(int i = 0; i < 2; ++i){
        for(int j = s.size() - 1; j >= 0; --j){
            int j2 = (j + 1) % s.size();
            for(int k = 0; k < 27; ++k){
                if(n.at(j2).at(k) != -1){
                    n.at(j).at(k) = n.at(j2).at(k) + 1;
                }
            }
            n.at(j).at(s.at(j2) - 'a') = 1;
        }
    }

    if(n.at(0).at(t.at(0) - 'a') == -1){
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    if(t.at(0) == s.at(0)){
        ans = 0;
    }else{
        ans = n.at(0).at(t.at(0) - 'a');
    }
    for(int i = 1; i < t.size(); ++i){
        const char c = t.at(i);
        const ll pos = ans % s.size();
        int idx = c - 'a';
        if(n.at(pos).at(idx) == -1){
            cout << -1 << endl;
            return 0;
        }
        ans += n.at(pos).at(idx);
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 15488
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

N, Q = gets_i_list
S = gets_s

ac_totals = Array.new(N, 0)

0.upto(N-2) do |i|
  if S[i] == "A" && S[i+1] == "C"
    ac_totals[i + 1] = ac_totals[i] + 1
  else
    ac_totals[i + 1] = ac_totals[i]
  end
end

Q.times do
  l, r = gets_i_list
  puts ac_totals[r-1] - ac_totals[l-1]
end

Measured memory_bytes: 3836
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;

  for(int i=1;i<=n;i++){
    int res=0;
    for(lint x=1;x<=100;x++){
      for(lint y=1;y<=100;y++){
        if(x*x+y*y+x*y>i) break;

        lint l=1,r=100;
        lint mid=(l+r)/2;
        bool found=false;
        while(r-l>1){
          lint z=mid;
          if(x*x + y*y + z*z + x*y + y*z + z*x <i){
            l=mid;
          }else if(x*x + y*y + z*z + x*y + y*z + z*x ==i){
            found=true;
            break;
          }else{
            r=mid;
          }
          mid=(l+r)/2;
        }


        if(!found){
          if(x*x + y*y + l*l + x*y + y*l + l*x ==i || x*x + y*y + r*r + x*y + y*r + r*x ==i){
            found=true;
          }
        }

        if(found){
          res++;
        }

      }
    }
    cout<<res<<endl;
  }


  return 0;
}



Measured memory_bytes: 3636
import scala.io.StdIn._

object Main extends App {
  val n = readLine.toInt
  val nums = (1 to n).map(_ => readLine.toInt)
  var diff_v = Int.MinValue
  var min_v = nums(0)
  
  nums.drop(1).foreach(x => {
    diff_v = if (x - min_v > diff_v) x - min_v else diff_v
    min_v = if (x < min_v) x else min_v
  })
  println(diff_v)
}


Measured memory_bytes: 70652
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import copy

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr2=copy.copy(arr)
    for i in range(1,n):
        arr2[i]=(arr2[i]+arr2[i-1])%mod
    base=arr2[n-1]+mod
    ans=0
    for i in range(n-1):
        ans=(ans+arr[i]*((base-arr2[i])%mod))%mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 39408
import sys

def main():
    k = input().replace('\n','').split()
    a = input().replace('\n','').split()
    u = input().replace('\n','')
    a[k.index(u)]=int(a[k.index(u)]) - 1
    print(str(a[0]) + ' ' + str(a[1]))
if __name__ == '__main__':
    input = sys.stdin.readline
    main()


Measured memory_bytes: 2940
N=gets.to_i
A=[]
A << gets.split.map(&:to_i)
A << gets.split.map(&:to_i)
sum=A[0][0]+A[1].inject(0){|r,i|r+i}
max=sum
(1 ... N).each{|i|
    sum+=A[0][i]
    sum-=A[1][i-1]
    if max<sum
        max=sum
    end
}
puts max


Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000000000000
int main(){//0の扱いに注意　else if(1<=FRONT && FRONT<=12 && BACK>=13)とするとBACKに0が含まれないので誤判定
	string s;cin>>s;
	int FRONT=10*(s[0]-'0')+(s[1]-'0');
	int BACK=10*(s[2]-'0')+(s[3]-'0');

	if((1<=FRONT && FRONT<=12) && (1<=BACK && BACK<=12)){cout<<"AMBIGUOUS"<<endl;return 0;}
	else if(1<=FRONT && FRONT<=12){cout<<"MMYY"<<endl;return 0;}
	else if(1<=BACK && BACK<=12){cout<<"YYMM"<<endl;return 0;}
	else{cout<<"NA"<<endl;}
	
	return 0;
}

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


int main() {

 
    int n;
    cin>>n;


    bool flg_z=false;
    bool flg_ov=false;
    vector<int64_t> A(n);
    for(int i=0;i<n;i++){
        cin>>A.at(i);
        if(A.at(i)==0)
            flg_z=true;
        else if(A.at(i)>1000000000000000000)
            flg_ov=true;
    }


    int64_t out=1;
    bool flg=true;
    if(flg_z==false){
    for(int i=0;i<n;i++){
        if(out>1000000000000000000/A.at(i)){
            flg=false;
            break;
        }else{
            out*=A.at(i);
        }
    }
    }

    if(flg_z)
        cout<<0<<endl;
    else if(flg_ov)
        cout<<-1<<endl;
    else if(flg)
        cout<<out<<endl;
    else
        cout<<-1<<endl;

    return 0;
}


Measured memory_bytes: 3964
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const K = parseInt(arg[0].split(" ")[0]);
    const N = parseInt(arg[0].split(" ")[1]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let longestDistances = 0;
    
    // 区間を作る
    for(let i=0; i<N; i++) {
        let distance;
        
        if(parseInt(i) === N - 1) {
            distance = (K - A[i]) + A[0];
        } else {
            distance = A[parseInt(i) + 1] - A[i];
        }
        
        if(longestDistances < distance) {
            longestDistances = distance;
        }
    }
    
    let answer = K - longestDistances;
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

struct data {
  long long s, t, x;
};

struct sdata {
  long long t, x;
  bool flag;
};

bool asc(const data &l, const data &r) {
  if(l.x != r.x) return l.x < r.x;
  return l.t < r.t;
}

bool ascs(const sdata &l, const sdata &r) {
  if(l.t != r.t) return l.t < r.t;
  if(l.x != r.x) return l.x < r.x;
  return !l.flag;
}

long long n, q;
vector<long long> d, ans;
vector<data> v;
vector<sdata> vs;
set<long long> s;

void solve();

int main() {
  cin >> n >> q;
  v.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> v[i].s >> v[i].t >> v[i].x;
    v[i].s = max(0LL, v[i].s - v[i].x);
    v[i].t = max(0LL, v[i].t - v[i].x);
    if(v[i].t == 0) continue;
    vs.push_back({v[i].s, v[i].x, 1});
    vs.push_back({v[i].t, v[i].x, 0});
  }
  sort(vs.begin(), vs.end(), ascs);
  d.resize(q);
  ans.assign(q, -1);
  for(int i = 0; i < q; ++i) cin >> d[i];
  solve();
  for(int i = 0; i < q; ++i) cout << ans[i] << endl;
  return 0;
}

void solve() {
  long long vssize = vs.size();
  for(long long i = 0, j = 0; i < q; ++i) {
    long long nd = d[i];
    while(j < vssize && vs[j].t <= nd) {
      if(vs[j].flag)
        s.insert(vs[j].x);
      else
        s.erase(vs[j].x);
      ++j;
    }
    if(s.empty())
      ans[i] = -1;
    else
      ans[i] = (*s.begin());
  }
}


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

int main(void)
{
  int N, index, K_index, K_count;
  int a[200001];
  K_index = 1;
  K_count = 0;
  scanf("%d", &N);
  for (index = 1; index <= N; ++index)
  {
    scanf("%d", &a[index]);
    if (a[index] == K_index)
    {
      ++K_index;
      ++K_count;
    }
  }
  if (K_count != 0)
  {
    printf("%d\n", N - K_count);
  }
  else
  {
    printf("-1\n");
  }
  
return 0;
}

Measured memory_bytes: 896
'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x=> x*1);
  let A = inp[0];
  let B = inp[1];
  let H = inp[2];
  let M = inp[3];
  let Hkaku = H*30 + M*0.5;
  let Mkaku = M*6;
  let kaku = (Mkaku - Hkaku)* Math.PI /180;
  let ans = 0;
  
  // 余弦定理に打ち込む
  ans = Math.sqrt(A*A + B*B - 2 * A * B * Math.cos(kaku));

  
  console.log(ans);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29888
#include <cstdio>
#include <cstring>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,m;
    cin >> n >>m;
    char s[n][n];
    char t[m][m];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)
        cin >> s[i][j];
    }
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++)
        cin >> t[i][j];
    }

    for(int i=0;i<=n-m;i++){
      for(int j=0;j<=n-m;j++){
        bool ans=true;
        for(int k=0;k<m;k++){
          for(int l=0;l<m;l++){
            if(s[i+k][j+l]!=t[k][l]){
              ans = false;
              break;
            }
          }
        if(!ans){
          break;
        }
      }
      if(ans){
        cout << "Yes"<<endl;
        return 0;
      }
    }
  }
    cout << "No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int r;
	cin >> r;
	cout << 3 * pow(r, 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main(){
	string a,b;

	cin >> a >> b;

	bool flag=true;

	rep(i,a.length()){
		flag = false;
		if(a[i]==b[0]||b[0]=='_'){
			flag = true;
			rep(j,b.length()){
				if(i+j>a.length()){
					flag = false;
					break;
				}

				if(b[j]=='_'){
					flag = true;
				}else if(a[i+j]!=b[j]){
					flag = false;
					break;
				}
			
			}
			if(flag) break; 
		}
	}
	
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a;
  int b = 0;
  int c = 1;
  int check = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> a;
    vec.at(i) = a;
  }
   for (int i = 0; i < N; i++){
    c = vec.at(c - 1);
    b ++;
    if(c == 2){
      check = 1;
      break;
    }
   }
   if(check == 1){
     cout << b << endl;
   }else{
     cout << "-1" << endl;
   }
}    

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

typedef long long ll;
const int N = 2000006;

long double a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	long double ans = 0.0;
	long double sm = 0.0;
	for(int i=1;i<k;i++){
		sm += a[i]/2.0+0.5;
	}
	a[0] = -1.0;
	for(int i=k;i<=n;i++){
		sm -= a[i-k]/2.0;
		sm -= 0.5;
		sm += a[i]/2.0 + 0.5;
		ans = max(ans,sm);
	}
	
	cout<<fixed<<setprecision(12)<<ans;
	
	return 0;
}


Measured memory_bytes: 6900