akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;

ll n,ans;

int main()
{
	ios::sync_with_stdio(0);
	
	cin>>n;
	
	for(int i=1;i*i<=100*n;i++){
		if(i>=(n/i-1))break;
		if(n%i==0)ans+=n/i-1;
	}
	cout<<ans<<endl;
	
return 0;
}








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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;
string S;
bool ans = false;

void dfs(int i)
{
    if ((int)S.length() == i)
    {
        ans = true;
        return;
    }
    if (i + 4 < (int)S.length() and S.substr(i, 5) == "dream")
        dfs(i + 5);
    if (i + 6 < (int)S.length() and S.substr(i, 7) == "dreamer")
        dfs(i + 7);
    if (i + 4 < (int)S.length() and S.substr(i, 5) == "erase")
        dfs(i + 5);
    if (i + 5 < (int)S.length() and S.substr(i, 6) == "eraser")
        dfs(i + 6);

    return;
};

void solve()
{
    cin >> S;
    dfs(0);
    cout << (ans ? "YES" : "NO") << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 2128
#include <cstdio>
#define ll long long
ll T[1<<18],val[1<<18];
bool tag[1<<18];
void setval(int node,int left,int right,ll x){
	tag[node]=1;
	T[node]=x*(right-left+1);
	val[node]=x;
}
void pushdown(int node,int left,int right){
	if(tag[node]){
		int mid=left+right>>1;
		setval(node<<1,left,mid,val[node]);
		setval(node<<1|1,mid+1,right,val[node]);
		tag[node]=0;
	}
}
void modify(int node,int left,int right,int l,int r,ll x){
	if(l==left&&r==right)setval(node,l,r,x);
	else{
		pushdown(node,left,right);
		int mid=left+right>>1;
		if(r<=mid)modify(node<<1,left,mid,l,r,x);
		else if(l>mid)modify(node<<1|1,mid+1,right,l,r,x);
		else{
			modify(node<<1,left,mid,l,mid,x);
			modify(node<<1|1,mid+1,right,mid+1,r,x);
		}
		T[node]=T[node<<1]+T[node<<1|1];
	}
}
ll getsum(int node,int left,int right,int l,int r){
	if(l==left&&r==right)return T[node];
	pushdown(node,left,right);
	int mid=left+right>>1;
	if(r<=mid)return getsum(node<<1,left,mid,l,r);
	if(l>mid)return getsum(node<<1|1,mid+1,right,l,r);
	return getsum(node<<1,left,mid,l,mid)+getsum(node<<1|1,mid+1,right,mid+1,r);
}
int main(){
	int N,Q,a;
	ll b;
	scanf("%d%d",&N,&Q);
	while(Q--){
		scanf("%d%lld",&a,&b);
		int left=0,right=a,mid;
		while(right-left>1){
			mid=left+right>>1;
			if(getsum(1,1,N,mid,mid)*(a-mid+1)-getsum(1,1,N,mid,a)<=b)right=mid;
			else left=mid;
		}
		ll tmp=getsum(1,1,N,right,right),tmp1,tmp2;
		b-=tmp*(a-right+1)-getsum(1,1,N,right,a);
		tmp1=b/(a-right+1);
		tmp2=b%(a-right+1);
		modify(1,1,N,right,a,tmp+tmp1);
		if(tmp2)modify(1,1,N,right,right+tmp2-1,tmp+tmp1+1);
	}
	for(int i=1;i<=N;i++)printf("%lld\n",getsum(1,1,N,i,i));
}

Measured memory_bytes: 5888
s = input()
t = input()

x = len(s)
y = len(t)

a = 0
b = x
c = 0
a0 = 0


for i in range(0,y):
  while True:
    #先頭からの位置
    a=s.find(t[i:i+1],a0)+1
    if a <= 0:
      a=s.find(t[i:i+1])+1
    if a <= 0:
      print("-1")
      exit()
    
    if a<=a0:
      c=c+a+b
    else:
      c=c+a-a0
    b=x-a
    a0=a
    break
    
print(c)


Measured memory_bytes: 3316
/*input
4 3
2
4
8
1
2
9
3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

vector<pii> v;

int main()
{
	//IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n){
		int x; cin>>x;
		v.pb(MP(x,0));
	}
	REP(i,m){
		int x;
		cin>>x;
		v.pb(MP(x,1));
	}
	sort(ALL(v));
	ll ans=0;
	ll a=n+1,b=m+1;
	for(auto i:v){
		if(i.S){
			ans+=i.F*a;
			b--;
		}
		else{
			ans+=i.F*b;
			a--;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll N,K;
const ll MOD=1e9+7,MAX_K=1e5;
ll mpw(ll n,ll m){
	ll r=1;
	while(m){
		if(m&1){
			r*=n;
			r%=MOD;
		}
		m>>=1;
		n*=n;
		n%=MOD;
	}
	return r;
}
ll dp[MAX_K+1];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>K;
	N=3;
	for(ll i=K;i>0;i--){
		dp[i]=mpw(K/i,N);
		for(ll j=2*i;j<=K;j+=i){
			dp[i]+=MOD-dp[j];
			dp[i]%=MOD;
		}
	}
	ll ans=0;
	FOR(i,1,K+1){
		ans+=dp[i]*i;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include <algorithm>
 
using namespace std;
 
int main(){
 int N=0;
 cin >> N;
 vector<int> vec(N);
 vector<int> vec2(N);
 
 for(int i=0; i<N; i++){
 cin>> vec.at(i);
 }  
 for(int i=0; i<N; i++){
 if(vec.at(i)%2==0){
   vec2.at(i)=vec.at(i);
 }  
 }
  
  for(int i=0;i<N;i++){
  if(vec2.at(i)%3!=0 && vec2.at(i)%5!=0){
     cout<<"DENIED"<<endl;
     return 0;
  }
  else{
  1;
  } 
  }
        cout<<"APPROVED"<<endl;
}

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

vector<int> to[100005];
vector<int> distT(100005);
vector<int> distA(100005);
void dfsT(int v, int p=-1) {
  if(p==-1)distT[v]==0;
  for (int u : to[v]) {
    if (u == p) continue;
    distT[u] = distT[v]+1;
    dfsT(u,v);
  }
}
void dfsA(int v, int p=-1) {
  if(p==-1)distA[v]==0;
  for (int u : to[v]) {
    if (u == p) continue;
    distA[u] = distA[v]+1;
    dfsA(u,v);
  }
}

int main() {
  int n,u,v;
  cin >> n >> u >> v;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  u--;
  v--;
  dfsA(v);
  dfsT(u);
  int mx = 0;
  rep(i,n) {
    if (distT[i] < distA[i]) {
      mx = max(mx, distA[i]);
    }
  }
  int ans = mx-1;
  cout << ans << endl;
  // rep(i,n)cout << distT[i];
  // cout << endl;
  // rep(i,n)cout << distA[i];
  // cout << endl;
  return 0;
}


Measured memory_bytes: 10368
N, A, B = map( int, input().split())
H = [0]*N
hmax = 0
for i in range(N):
    h = int( input())
    H[i] = h
hmax = max(H)
L = 0
R = hmax//B + 1
add = A-B
while L != R:
    now = (L+R)//2
    need = 0
    for i in range(N):
        if H[i] > now*B:
            need += (H[i]-1-now*B)//add + 1
    if need <= now:#うまくいくとき
        R = now
    else:#うまくいかないとき
        L = now+1#うまく行かないので+1している．これがないと無限ループが発生する。
print(L)

Measured memory_bytes: 6900
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,x,a;
    cin >>x>>a;
    if(x<a){
        ans=0;
    }else{
        ans=10;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <sstream>
#include <cctype>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cfloat>
#include <cmath>
using namespace std;

int main() {
  string str;
  double a, b;

  while( getline(cin, str) ) {
    stack<double> st;
    stringstream ss(str);
    string s;

    while( ss >> s ) {
      if( s.size() > 1 || isdigit(s[0]) ) {
	a = atof( s.c_str() );
	st.push( a );
      }
      else if( s == "+" ) {
	a = st.top(); st.pop();
	b = st.top(); st.pop();
	st.push( b+a );
      }
      else if( s == "-") {
	a = st.top(); st.pop();
	b = st.top(); st.pop();
	st.push( b-a );
      }
      else if( s == "*" ) {
	a = st.top(); st.pop();
	b = st.top(); st.pop();
	st.push( b*a );
      }
      else if( s == "/" ) {
	a = st.top(); st.pop();
	b = st.top(); st.pop();
	st.push( b/a );
      }
    }
    printf("%.6lf\n", st.top());
  }
  
  return 0;
}

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		scan.close();
		int cnt=0;
		for(int i=0;i<n-2;i++) {
			if(s.charAt(i)=='A' && s.charAt(i+1)=='B'&&s.charAt(i+2)=='C')cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define LARGE 100005
#define SMALL 105

struct Point{

	bool operator<(const struct Point &arg)const{

		return x < arg.x;
	}
	double x,y,z;
};

int N,Q;
int M;
Point point[LARGE],work[SMALL];
double near_dist[SMALL];

double calc_dist(Point a,Point b){

	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

void func(){

	for(int i = 0; i < N; i++){

		scanf("%lf %lf %lf",&point[i].x,&point[i].y,&point[i].z);
	}
	sort(point,point+N);

	for(int loop = 0; loop < Q; loop++){

		scanf("%d",&M);

		int left,right,mid,loc;

		for(int i = 0; i < M; i++){

			scanf("%lf %lf %lf",&work[i].x,&work[i].y,&work[i].z);

			near_dist[i] = HUGE_NUM;

			//自分より右にある点の中で、最も左にあるものを求める
			left = 0,right = N-1,mid = (left+right)/2;
			loc = N;

			while(left <= right){

				if(point[mid].x >= work[i].x){

					loc = mid;
					right = mid-1;
				}else{

					left = mid+1;
				}
				mid = (left+right)/2;
			}

			//右へ
			for(int k = loc; k < N && sqrt((work[i].x-point[k].x)*(work[i].x-point[k].x)) < near_dist[i]; k++){

				near_dist[i] = min(near_dist[i],calc_dist(work[i],point[k]));
			}

			//左へ
			for(int k = loc-1; k >= 0 && sqrt((work[i].x-point[k].x)*(work[i].x-point[k].x)) < near_dist[i]; k--){

				near_dist[i] = min(near_dist[i],calc_dist(work[i],point[k]));
			}
		}

		double ans = 0;

		for(int i = 0; i < M-1; i++){

			ans += min(calc_dist(work[i],work[i+1]),near_dist[i]+near_dist[i+1]);
		}

		printf("%.10lf\n",ans);
	}
}

int main(){

	while(true){
		scanf("%d %d",&N,&Q);
		if(N == 0 && Q == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 5628
#include <stdio.h>

int main(void) {
	int n, i, j, r, x;
	char s[111], t[111];
	
	scanf("%d %s %s", &n, s, t);
	
	r=2*n;
	
	for(i=1;i<=n;i++){
		x=n-i;
		for(j=0;j<i;j++){
			if(s[j+x]!=t[j])
			break;
			if(j==i-1)
			r=2*n-i;
		}
	}
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 128
# 21:01
n,a,b = map(int,input().split())
if abs(b-a) % 2 == 0:
    print((b-a)//2)
else:
    ans = min(max(a-1,b-1),max(n-a,n-b))
    if (a-1) >= (n-b):
        t = (n-((n+1-b)+a))//2 + (n-b+1)
        print(min(ans,t))
    else:
        t = (b-((a-1)+1)-1)//2 + (a-1+1)
        print(min(ans,t))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,X;
	cin>>A>>B>>X;
	if(X>=A)
	{
		if(X<=A+B)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int i,j,a[100],k=0;
  for(i=1;i<10;i++)
    for(j=1;j<10;j++)
      a[k++]=i*j;
  int b,flag=0;
  cin>>b;
  for(i=0;i<k;i++)
    if(b==a[i])
      flag=1;
  if(flag==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] order = new int[n + 1];
		
		for (int i = 0; i < n; i++) {
			order[sc.nextInt()] = i + 1;  
		}
		
		for (int i = 1; i < order.length; i++) {
			if (i == order.length - 1) {
				System.out.print(order[i]);
			} else {
				System.out.print(order[i] + " ");
			}
		}
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 40392
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = in.readLine();
    char[] c = str.toCharArray();
    Arrays.sort(c);
    System.out.println(c[0]==c[1] && c[1] != c[2] && c[2] == c[3] ?"Yes":"No");
  }
}
    

Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n;
string s[N];
int t[N];

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> s[i] >> t[i];
	string x;
	cin >> x;
	int ans = 0;
	for(int i = n; i >= 1; i--)
	{
		if(s[i] == x)
			break;
		ans += t[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	vector<int> arr(s.size()+1,-1);
	int j = s.size(),num;
	for(int i=s.size()-1;i>=0;i--,j--){
		if(s[i]=='>'){
		num=0;
		while(i>=0 && s[i]=='>')
		{
			arr[j]=num;
			num++;
			i--;
			j--;
		}
		arr[j]=num;
		}
	}
	j=0;
	// for(int i=0;i<arr.size();i++)
	// 	cout<<arr[i]<<" ";
	// cout<<endl;
	for(int i=0;i<s.size();i++,j++){
		num=0;
		if(s[i]=='<'){
			while(i<s.size() && s[i]=='<')
		{
			arr[j]= max(num,arr[j]);
			num++;
			i++;
			j++;
		}
		arr[j]=max(num,arr[j]);
		}
		
	}
	long long sum=0;
	for(int i=0;i<arr.size();i++)
		sum+=arr[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2820
import sys
stdin=sys.stdin

ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))

N,K=nm()
A=nl()

D=60
MAX_N=2000005
to=[[0]*MAX_N for i in range(D)]

to[0][1:N+1]=A

for i in range(D-1):
    for j in range(1,N+1):
        to[i+1][j]=to[i][to[i][j]]

v=1
for i in range(D-1,-1,-1):
    l = 1<<i
    if(l<=K):
        v=to[i][v]
        K-=l

print(v)



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

const int mod=1000000007,N=100100,inf=INT_MAX;
inline void upd(int&x,const int&y){x+=y-mod;x+=x>>31&mod;}
int sm[N],n;
void add(int x,int y){for(;x<=n+1;x+=x&-x)upd(sm[x],y);}
int qry(int x){int ans=0;for(;x;x-=x&-x)upd(ans,sm[x]);return ans;}
int m,a[N],b[N];
pair<int,int>c[N];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=m;++i)cin>>b[i];
	for(int i=1;i<=n;++i){
		int u=lower_bound(b+1,b+m+1,a[i])-b;
		if(u==1)c[i].first=inf;else c[i].first=a[i]-b[u-1];
		if(u==m+1)c[i].second=inf;else c[i].second=b[u]-a[i];
	}
	for(int i=1;i<=n;++i)a[i]=c[i].first,b[i]=c[i].second;
	sort(a+1,a+n+1);sort(b+1,b+n+1);
	for(int i=1;i<=n;++i){
		c[i].first=lower_bound(a+1,a+n+1,c[i].first)-a;
		c[i].second=-(lower_bound(b+1,b+n+1,c[i].second)-b);
	}
	sort(c+1,c+n+1);add(1,1);
	for(int i=1;i<=n;++i){
		c[i].second=-c[i].second;if(i>1&&c[i]==c[i-1])continue;
		if(a[c[i].first]==inf||b[c[i].second]==inf)continue;
		add(c[i].second+1,qry(c[i].second));
	}
	cout<<qry(n+1)<<'\n';
	return 0;
}


Measured memory_bytes: 2176
import java.util.*;

import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j,k;
		Scanner sc = new Scanner(System.in);
		int n = parseInt(sc.next());
		int d = parseInt(sc.next());
		int[][] x = new int[n][d];
		for(i=0;i<n;i++) {
			for(j=0;j<d;j++) {
				x[i][j] = parseInt(sc.next());
			}
		}
		sc.close();
		int cnt=0;
		int NNMax = 126;
		int[] nn = new int[NNMax+1];
		for(i=1;i<=NNMax;i++) {
			nn[i] = i*i;
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				int nnsum = 0;
				for(k=0;k<d;k++) {
					nnsum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]); 
				}
//				System.out.println(nnsum);
				for(k=1;k<=NNMax;k++) {
//					System.out.println(nn[k]);
					if(nn[k]==nnsum) {
						cnt++;
						break;
					}
					if(nn[k]>nnsum) {
						break;
					}
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int cnt = 0;

    if(n >= 105){
        cnt++;
        for(int i = 106; i <= n; i++){
            int cnt_y = 0;
            if(i % 2 != 0){
                for(int j = 1; j <= n; j++){
                    if(i%j == 0){
                        cnt_y++;
                    }
                }
                if(cnt_y == 8)cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(){ 
    int n, k, x;
    cin >> n >> k;
    int sum = 0;
    
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x <= k - x) {
            sum += x * 2;
        }
        else {
            sum += (k - x) * 2;
        }
    }
    
    cout << sum;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())

# 脇道あり
def sp_root(i, j, X, Y): #i<j, X+1<Y
    root = abs(X-i) + abs(Y-j) + 1
    return root

# 距離の配列
k_lis = [0]*(n-1)
 
ans = 0
for i in range(1,n):
    for j in range(i+1,n+1):
        k_lis[min(j - i, sp_root(i, j, x, y))-1] += 1
 
for i in k_lis:
    print(i)

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin>>n;
  vector<int> a(n),b(n);

  rep(i,0,n) cin>>a[i]>>b[i];
  sort(all(a)),sort(all(b));

  if(n % 2 == 1){
    cout<<b[n/2]-a[n/2]+1<<'\n';
  }else{
    int t1 = a[n/2] + a[n/2-1];
    int t2 = b[n/2] + b[n/2-1];
    int ans = t2 - t1;
    cout<<ans+1<<'\n';
  }

  return 0;
}

Measured memory_bytes: 6352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	string s,t;
	cin>>s>>t;
	int ans=INT_MAX;
	for(int i=0;i<s.length()-t.length()+1;i++)
	{
		int minchar{};
		for(int j=0;j<t.length();j++)
		{
			if(t[j]!=s[i+j])
			{
			 minchar++;
			}
		}
		ans=min(ans,minchar);
	}
	cout<< ans<<endl;
}


Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <list>
#include <numeric>
using namespace std;
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define pb push_back
 
int INF = INT_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int K, T; cin >> K >> T;
	vector<int> a(T);
	for (int t = 0; t < T; t++)
		cin >> a[t];
	int ma = 0;
	for (int t = 0; t < T; t++)
		ma = max(ma, a[t]);
	if (ma == K) {
		cout << K - 1 << endl;
		return 0;
	}
	int ans = 0;
	for (; ma > (K + 1) / 2; ma--, K--) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
ac = True
c = True
if s[0] != "A":
  ac = False
if not ord("a") <= ord(s[1]) <= ord("z"):
  ac = False
if not ord("a") <= ord(s[-1]) <= ord("z"):
  ac = False
for i in range(2, len(s)-1):
  if s[i] == "C":
    if c:
      c = False
    else:
      ac = False
  else:
    if not ord("a") <= ord(s[i]) <= ord("z"):
      ac = False
if c:
  ac = False
if ac:
  print("AC")
else:
  print("WA")


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
	new Main().run();
    }
    
    final long mo=998244353;

    void run(){
	Scanner sc=new Scanner(System.in);
	String s=sc.next();
	int n=s.length();
	if(n<=3){
	    System.out.println(f(s));
	    return;
	}
	{
	    boolean flag=true;
	    for(int i=0;i+1<s.length();++i){
		flag&=s.charAt(i)==s.charAt(i+1);
	    }
	    if(flag){
		System.out.println(1);
		return;
	    }
	}
	int sum=0;
	for(char c:s.toCharArray()){
	    if(c=='a'){
		sum+=0;
	    }else if(c=='b'){
		sum+=1;
	    }else if(c=='c'){
		sum+=2;
	    }
	    sum%=3;
	}
	long[][][][] dp=new long[n][3][3][2];//[長さ-1][sum][末尾][flag=連続が存在]
	dp[0][0][0][0]=1;
	dp[0][1][1][0]=1;
	dp[0][2][2][0]=1;
	for(int i=1;i<n;++i){
	    for(int j=0;j<3;++j){//sum
		for(int k=0;k<3;++k){//前に選んだ数
		    for(int m=0;m<3;++m){//次に選ぶ数
			for(int l=0;l<2;++l){
			    dp[i][(j+m)%3][m][l|(k==m?1:0)]+=dp[i-1][j][k][l];
			    dp[i][(j+m)%3][m][l|(k==m?1:0)]%=mo;
			}
		    }
		}
	    }
	}
	long ans=0;
	for(int i=0;i<3;++i){
	    ans+=dp[n-1][sum][i][1];
	}
	{
	    boolean flag=true;
	    for(int i=0;i+1<s.length();++i){
		flag&=s.charAt(i)!=s.charAt(i+1);
	    }
	    if(flag)++ans;
	}
	ans%=mo;
	System.out.println(ans);
    }

    long f(String str){
	int[] strn=new int[str.length()];
	for(int i=0;i<str.length();++i){
	    strn[i]=(int)(str.charAt(i)-'a');
	}
	class S{
	    int[] cs;
	    int num=0;
	    
	    S(int[] cs_){
		cs=Arrays.copyOf(cs_,cs_.length);
		long p=1;
		for(int c:cs){
		    num=(int)((num+c*p)%mo);
		    p=p*3%mo;
		}
	    }
	}
	boolean[] a=new boolean[81];
	ArrayDeque<S> dq=new ArrayDeque<S>();
	S src=new S(strn);
	dq.add(src);
	while(!dq.isEmpty()){
	    S s=dq.pollLast();
	    a[s.num]=true;
	    for(int i=0;i+1<s.cs.length;++i){
		if(s.cs[i]!=s.cs[i+1]){
		    int next=(3-(s.cs[i]+s.cs[i+1])%3)%3;
		    int tmp1=s.cs[i];
		    int tmp2=s.cs[i+1];
		    s.cs[i]=next;
		    s.cs[i+1]=next;
		    if(!a[new S(s.cs).num]){
			dq.addFirst(new S(s.cs));
			a[new S(s.cs).num]=true;
		    }
		    s.cs[i]=tmp1;
		    s.cs[i+1]=tmp2;
		}
	    }
	}
	long ans=0;
	for(int i=0;i<a.length;++i){
	    if(a[i])++ans;
	}
	return ans;
    }
    
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

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

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int N, M;
str S;
map<int, int> isParent;
// moves it takes, spot
set<pi> pref;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> N >> M >> S;
	// Find min moves to get to a square then store the preceding node later
	int dp[N + 1], p[N + 1];
	vi firstValidParents;
	
	F0R(i, N + 1) {
		dp[i] = 0;
		p[i] = 0;
	}
	pref.insert({0, 0});
	
	F0R(i, N) {
		if (S[i] == '1') dp[i] = -1;
	}
	
	FOR(i, 1, N + 1) {
		if (i > M && dp[i - M - 1] != -1) {
			pref.erase({dp[i - M - 1], i - M - 1});
		}
		
		if(dp[i] != -1 && sz(pref)) {
			dp[i] = pref.begin()->f + 1;
			p[i] = pref.begin()->s;
		}
		
		if (dp[i] > 0) {
			pref.insert({dp[i], i});
		}
	}
	
	if (!dp[N]) {
		cout << -1;
		return 0;
	}
	
	int curr = N;
	vi dists;
	while(curr != 0) {
		dists.pb(curr - p[curr]);
		curr = p[curr];
	}
	reverse(all(dists));
	trav(i, dists) cout << i << " ";
	// F0R(i, N + 1) cout << dp[i] << " ";
	// cout << "\n";
	
	// firstValidParents.pb(N);
	// FOR(i, 1, sz(firstValidParents)) cout << firstValidParents[i] - firstValidParents[i - 1] << " ";
	
	// int curr = 0;
	// while(curr != N) {
		// FOR(i, 1, M + 1) {
			// if (curr + i <= N && dp[curr + i] == dp[curr] + 1 && (isParent.count(curr + i) || curr + i == N)) {
				// curr = curr + i;
				// cout << i << " ";
				// break;
			// }
		// }
	// }
	
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3712
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{

    boost::multi_array<int64_t, 2> C(boost::extents[3][3]);
    for (auto p = C.data(); p < (C.origin() + C.num_elements()); ++p) {
        std::cin >> *p;
    }

    int64_t a1, a2, a3, b1, b2, b3;

    a1 = 0;
    b1 = C[0][0];
    b2 = C[0][1];
    b3 = C[0][2];
    a2 = C[1][0] - b1;
    a3 = C[2][0] - b1;

    bool ans;
    ans  = a1 + b1 == C[0][0];
    ans &= a1 + b2 == C[0][1];
    ans &= a1 + b3 == C[0][2];

    ans &= a2 + b1 == C[1][0];
    ans &= a2 + b2 == C[1][1];
    ans &= a2 + b3 == C[1][2];

    ans &= a3 + b1 == C[2][0];
    ans &= a3 + b2 == C[2][1];
    ans &= a3 + b3 == C[2][2];

    std::cout << (ans ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll a,b,c; cin>>a>>b>>c;
    if(a%b==c){
        cout<<"YES"<<endl;
        return 0;
    }
    ll i=2;
    while((a*i)%b!=a%b){
        if((a*i)%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
        i++;
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int CountYakusuu(const int n){
	//a*b=nとなるようなa,bの組を探していく
	int count=0;
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			if(i*i!=n){
				//平方根でない場合は約数はa,bの2つ増える
				count+=2;
			} else{
				//平方根の場合は約数はa==bなので1つしか増えない
				count+=1;
			}
		}
	}
	return count;
}

int main(){
	//入力機構
	int N;
	std::cin>>N;

	//処理機構
	//N<=200なので、全探索でよい
	int ans=0;
	for(int i=1;i<=N;i++){
		if(i%2!=0 && CountYakusuu(i)==8){
			//奇数かつ約数が8個
			ans++;
		}
	}

	//出力機構
	std::cout<<ans<<std::endl;
	
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        mut n:i64,
        d:i64,
    }
    let mut ans = 0;
    while n > 0 {
        ans += 1;
        n -= d * 2 + 1;
    }
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
n,k = map(int,input().split())
ab = []
for _ in range(n):
    a=int(input())
    ab.append(a)
ab.sort()
#print(ab)
ans = 1000000000000000000000

for i in range(k-1, n):
    ans = min(ans,ab[i]-ab[i-k+1])
print(ans)

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int n;
  cin>>n;
  vector<int> ans;
  for(int p=2; p<=55555; p++){
    if(IsPrime(p) && p%10==1) ans.push_back(p);
  }
  rep(i,n) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3672
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;



int main() {
	int n, m;
	vector<long long> sx, sy, cx, cy;
	cin >> n >> m;
	sx.resize(n);
	sy.resize(n);
	cx.resize(m);
	cy.resize(m);

	for (int i = 0; i < n; i++) {
		cin >> sx[i] >> sy[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> cx[i] >> cy[i];
	}

	for (int i = 0; i < n; i++) {
		long long ans = 1000000000000;
		int id = -1;
		for (int j = 0; j < m; j++) {
			if (abs(cx[j] - sx[i]) + abs(cy[j] - sy[i]) < ans) {
				ans = abs(cx[j] - sx[i]) + abs(cy[j] - sy[i]);
				id = j + 1;
			}
		}
		cout << id << endl;
	}
	//cin >> n;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for _ in range(M)]

for i in range(0,1000):
  i = str(i)
  l = len(i)
  check = False
  if l == N:
    check = True
    for s, c in SC:
      if int(i[s-1]) != c:
        check = False
  if check:
    ans = int(i)
    break
else:
  ans = -1
    
print(ans)

Measured memory_bytes: 9196
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let w = get!([isize]);
    let total = w.iter().sum::<isize>();
    let mut mn = total;
    let mut sum = 0;
    for e in w {
        sum += e;
        mn = min!(mn, (total-2*sum).abs());
    }
    println!("{}", mn);
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
 
int main(void){

	int a, b, c;
	cin >> a >> b >> c;
	
	if(a == 5 && b == 5 && c == 7){
		cout << "YES";
	} else 	if(a == 7 && b == 5 && c == 5){
		cout << "YES";
	} else 	if(a == 5 && b == 7 && c == 5){
		cout << "YES";
	} else cout << "NO";
	

	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
tree_list,new_tree_list = [],[]
for i in range(N):
    tree_list.append(int(input()))

tree_list.sort(reverse=True)

for i in range(len(tree_list)-K+1):
    new_tree_list.append(tree_list[0+i]-tree_list[K+i-1])
new_tree_list.sort()
print(new_tree_list[0])


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

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end
n, alist = gets_n_and_i_list
puts alist.sum - n


Measured memory_bytes: 14540
//https://atcoder.jp/contests/dp/tasks/dp_c
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
 
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
ll n,dp[100001][3],q[1000001][3];




int main() 
{

    fast();
      
    // #ifndef ONLINE_JUDGE
    //         freopen("input.txt", "r", stdin);
    //         freopen("output.txt","w",stdout);
    // #endif
    
    cin>>n;
    f(i,0,n)
    {
        cin>>q[i][0]>>q[i][1]>>q[i][2];
    }
    dp[0][0]=q[0][0];
    dp[0][1]=q[0][1];
    dp[0][2]=q[0][2];
    f(i,1,n)
    {
        f(j,0,3)
        {
            if(j==0)
            {
                dp[i][j]=max(dp[i-1][j+1],dp[i-1][j+2])+q[i][j];
            }
            if(j==1)
            {
                dp[i][j]=max(dp[i-1][j-1],dp[i-1][j+1])+q[i][j];
            }
            if(j==2)
            {
                dp[i][j]=max(dp[i-1][j-2],dp[i-1][j-1])+q[i][j];
            }
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});

  

    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int x[214514];
double y[214514];
string z[214514];
int sum[214514];
signed main(){
	ic(n)
	rep(0,i,n-1)cin>>x[i];
	int ans=0;
	rep(0,i,n-1){
		ans+=min(x[i],x[i+1]);
	}
	c(ans+x[0]+x[n-2])	
}	

Measured memory_bytes: 4736
use std::io::BufRead;

fn main() {
    loop {
        println! ("{}", 
            match read_three_tests() {
                Ok(tests) => jadge(tests),
                Err(_) => return (),
            }
        );
    }
}

fn read_three_tests() -> Result<(isize, isize, isize), ()> {
    let handle = std::io::stdin();
    let mut line = String::new();
    handle.lock().read_line(&mut line).ok();
    let tests:Vec<isize> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
    match (tests[0], tests[1], tests[2]) {
        (-1, -1, -1) => Err(()),
        all@(_, _, _) => Ok(all), 
    }
}

fn jadge((a, b, c): (isize, isize, isize)) -> char{
    if a == -1 || b == -1 { return 'F'; } 
    else if a + b >= 80 { return 'A'; }
    else if a + b >= 65 { return 'B'; } 
    else if a + b >= 50 { return 'C'; }
    else if a + b >= 30 {
        if c >= 50 { return 'C'; }
        return 'D';
    } else { return 'F'; }
}


Measured memory_bytes: 5032
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
const int MAX=1e9+7;
const int mod=1e9+7;

int main()
{
	long long n,r;
	cin>>n>>r;
	if(n>=10)cout<<r;
	else cout<<r+100*(10-n);
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct edge{
	int to,next,w;
}e[maxn<<1];
int head[maxn<<1],cnt=0,color[maxn];
void add(int u,int v,int w){
	e[++cnt].w=w;
	e[cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void dfs(int u,int fa,int vis){
	color[u]=vis;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa)continue;
		int w=e[i].w;
		if(w&1){
			dfs(v,u,vis^1);
		}
		else{
			dfs(v,u,vis);
		}
	}
} 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);
		add(v,u,w);
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++){
		printf("%d\n",color[i]);
	}
}


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

using namespace std;

#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#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_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int N;
int h, n, w;

signed main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);

	cin>>N;

	for_(i, 1, 3501) {
		for_(j, i, 3501) {
			if(4*i*j>N*(i+j) && N*i*j%(4*i*j-N*(i+j))==0) {
				cout<<i<<' '<<j<<' '<<N*i*j/(4*i*j-N*(i+j))<<endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin>>n;
  string s; cin>>s;
  
  vector<int>b(n+1);
  vector<int>w(n+1);
  
  b[0]=0; w[0]=0;
  for (int i=1; i<=n; i++){
    if(s[i-1] == '.'){
      w[i]=w[i-1]+1;
      b[i]=b[i-1];
    }
    if(s[i-1] == '#'){
      b[i]=b[i-1]+1;
      w[i]=w[i-1];
    }

  }
  
  vector<int>sum(n+1); 
  for(int i=0;i<=n;i++){
    sum[i]=b[i]+w[n]-w[i];
  }
  sort(sum.begin(),sum.end());
  cout<<sum[0]<<endl;

}

Measured memory_bytes: 2948
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    vector<int> a(3, 0);

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

    sort(a.begin(), a.end(), greater<int>());

    cout << a[0]*10 + a[1] + a[2] << endl;    
    
    return 0;
}

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

using namespace std;
int n,k,i,inc,max1,min1,fr[2005],x,y,j,a;
int main()
{

cin>>n>>x>>y;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
    min1=j-i;
    a=abs(x-i)+abs(y-j)+1;
    min1=min(min1,a);
    fr[min1]++;
    //cout<<min1;
    //b=abs(y-i)+abs(x)
}
for(i=1;i<n;i++)
    cout<<fr[i]<<"\n";

       return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, m, t, p;
int o[1000][1000];

void solve() {
    memset(o, 0, sizeof(o));
    rep(i,m) rep(j,n) o[i][j] = 1;
    int h = 0, w = 0;
    rep(i,t) {
        int d, c; cin >> d >> c;
        if (d == 1) {
            rep(j,1000) {
                rep(k,c) {
                    o[j][w+2*c-1-k] += o[j][w+k];
                }
            }
            w += c;
        } else {
            rep(j,1000) {
                rep(k,c) {
                    o[h+2*c-1-k][j] += o[h+k][j];
                }
            }
            h += c;
        }
    }
    rep(i,p) {
        int x, y; cin >> x >> y;
        cout << o[h+y][w+x] << endl;
    }
}

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
    cout.precision(20);
    cerr << fixed;
    cerr.precision(6);
#ifdef LOCAL
    //freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif  
    while (cin >> n >> m >> t >> p) {
        if (n == 0 && m == 0 && t == 0 && p == 0) break;
        solve();
    }
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}



Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int sum = 0, a, ma = -1;
  for(int i = 0; i < N; i++){
    cin >> a;
    ma = max(a, ma);
    sum += a;
  }
  cout << sum - (ma / 2) << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Possible")  # type: str


def no():
    print("Impossible")  # type: str


def solve(A: int, B: int):
    if A % 3 == 0 or B % 3 == 0 or (A+B) % 3 == 0:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);

        int wa = a + b;
        int sa = a - b;
        int seki = a * b;

        int ans = wa;

        if (ans < sa)
            ans = sa;
        if (ans < seki)
            ans = seki;

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140