akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const ll MAX = 1e18;

int main(void){
    std::ios_base::sync_with_stdio(false);

    ll a,c;
    float b;
    cin >> a >> b;

    c = b*100 + 0.5;
    cout << a*c/100;

    return 0;
}


/*

https://atcoder.jp/contests/abc169/tasks/abc169_c


*/


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

using namespace std;

#define ll long long
#define fo(i,b,n) for(int i=(b); i<(n) ; i++)
#define xx first
#define yy second
#define pb push_back
#define sz(n) int(n.size())
#define pii pair
#define MP make_pair

#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define readl(x) scanf("%lld",&x)
#define readl2(x,y) scanf("%lld%lld",&x,&y)
#define readd(x) scanf("%lf",&x)
#define readd2 scanf("%lf%lf",&x,&y)

#define pr(n) printf("%d",n)
#define prn(n) printf("%d\n",n)
#define prl(n) printf("%lld",n)
#define prln(n) printf("%lld\n",n)
#define prd(x) printf("%lf",x)
#define prdn(x) printf("%lf\n",x)



int main()
{
    ll n,k,x,y;
    cin>>n>>k>>x>>y;
    ll ans=0;
    if(k>=n)
    {
        ans=n*x;
    }
    else{
        ans=x*k+(n-k)*y;
    }
    cout<<ans<<endl;
    return 0;
}

















Measured memory_bytes: 256
function main(input) {
  var In = input.split(' ');
  var str = In[0] + In[1];
  var num = parseInt(str, 10);
  var sqrt = Math.sqrt(num);
  
  if(Number.isInteger(sqrt)) {
    console.log('Yes');
  } else {
    console.log('No');
  }
  
}

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

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

int main() {
    
    // 1. input.
    int a, b;
    cin >> a >> b;
    
    // 2. output answer.
    cout << (a * b) << " " << (2 * a + 2 * b) << endl;
    
    return 0;
    
}


Measured memory_bytes: 2988
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define pb push_back
#define eb emplace_back

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll INF = 1e12;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    ll n,w;
    cin >> n >> w;
    vector<pair<ll,ll>> wv(n);
    Rep(i,n) cin >> wv[i].first >> wv[i].second;
    vector<ll> dp(1e5+1,INF);
    dp[0] = 0;
    Rep(i,n){
        RRep(j,1e5+1){
            if(j-wv[i].second>=0 && dp[j-wv[i].second]!=INF){
                chmin(dp[j],dp[j-wv[i].second]+wv[i].first);
            }
        }
    }
    RRep(j,1e5+1){
        if(dp[j]<=w && dp[j]>=0){
            cout << j << '\n';
            return 0;
        }
    }
}

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

public class Main{
	
	static long mod=(long)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			long x=in.nextLong();
			long c=100;
			int i;
			for(i=1;;i++) {
				c=c+c/100;
				if(x<=c) break;
			}
			out.println(i);
		}
		out.close();		
		
	}

	static boolean tri(int a, int b, int c) {
		if(c<a+b && c>abs(a-b)) return true;
		return false;
	}
	
	
/*********************************** UTILITY CODE BELOW **************************************/	
		
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	
	static int max(int a, int b) {
		return a>b ? a : b;
	}
	
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

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

int main() {
    int n,m,l;
    cin >> n >> m >>l;
    int arr1[n][m];
    int arr2[m][l];
    for(int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            int num;
            cin >> num;
            arr1[i][j]=num;
        }
    }

    for(int i=0; i<m; i++) {
        for (int j=0; j<l; j++) {
            int num;
            cin >> num;
            arr2[i][j]=num;
        }
    }

    for(int i=0; i<n; i++) {
        for (int j=0; j<l; j++) {
            int k=0;
            long long sum=0;
            while(k<m) {
                sum+=arr1[i][k]*arr2[k][j];
                k++;
            }
            cout << sum;
            if (j+1!=l) cout << " ";
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

ll digit(ll n) {
    ll ret = 0;
    while(n > 0) {
        n /= 10;
        ret++;
    }
    return ret;
}


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

    ll N; cin >> N;
    vvll cnt(10, vll(10, 0));
    for(ll i = 1; i <= N; i++) {
        ll last = i % 10;
        ll first = i;
        rep(j, digit(i)-1) first /= 10;
        cnt[first][last]++;
    }

    ll ans = 0;
    for(ll i = 1; i <= 9; i++) {
        for(ll j = 1; j <= 9; j++) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
}


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

int H, W, dp[1009][1009], mod = 1000000007; char c[1009][1009];

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	dp[1][1] = 1;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' || i + j == 2) continue;
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	}
	cout << dp[H][W] << endl;
	return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N, K;
  cin >> N >> K;
  
  vector<ll> A(N);

  rep(i, N) cin >> A[i];

  vector<ll> Aneg, Apos;
  ll cnt_0;

  rep(i, N){
    if(A[i] > 0){
      Apos.push_back(A[i]);
    }else if(A[i] < 0){
      Aneg.push_back(A[i]);
    }else{
      cnt_0++;
    }
  }

  ll P = Apos.size();
  ll Q = Aneg.size();

  ll cnt_p_neg = P * Q;
  ll cnt_p_pos = P * (P-1)/2 + Q * (Q-1) /2;
  ll cnt_p_0   = N * (N-1) / 2 - cnt_p_neg - cnt_p_pos;

  ll ans = 0;
  if(K <= cnt_p_neg){

    // 解は negのペアの中で K 番目の数
    // 簡単のため、

    rep(i, Aneg.size()){
      Aneg[i] = -Aneg[i];
    }

    sort(Aneg.begin(), Aneg.end());
    sort(Apos.begin(), Apos.end());

    ll L = cnt_p_neg - K + 1;
    // L番目の数

    ll left = 0;
    ll right = 1e18 + 1;

    while(right - left > 1){

      ll mid = left + (right - left) / 2;

      // mid以上の数が L 個以上か？

      ll cnt = 0;
      rep(i, Aneg.size()){
        
        ll num = Aneg[i];

        ll min_val = mid / num;

        ll cnt_;

        cnt_ = lower_bound(Apos.begin(), Apos.end(), min_val+1) - Apos.begin();

        cnt += cnt_;

      }

      if(cnt >= L){
        right = mid;
      }else{
        left = mid;
      }
    }

    ans = -1 * right;


  }else if(K <= cnt_p_0 + cnt_p_neg){
    
    // 解は0

    ans = 0;

  }else{
    
    // 解はposのペアの中で K - cnt_p_neg - cnt_p_0番目の数

    ll L = K - cnt_p_neg - cnt_p_0;
    rep(i, Aneg.size()){
      Aneg[i] = -Aneg[i];
    }

    sort(Aneg.begin(), Aneg.end());
    sort(Apos.begin(), Apos.end());
    

    ll left = 0;
    ll right = 1e18+1;

    while(right - left > 1){

      ll mid = left + (right - left) / 2;

      // mid以上の数がL個以上か？

      ll cnt = 0;

      rep(i, Aneg.size()-1){

        ll num = Aneg[i];

        ll min_val = mid / num;

        ll cnt_;

        cnt_ = lower_bound(Aneg.begin() + i + 1, Aneg.end(), min_val+1) - Aneg.begin() - i - 1;

        cnt += cnt_;

      }
      rep(i, Apos.size()-1){

        ll num = Apos[i];

        ll min_val = mid / num;

        ll cnt_;

        cnt_ = lower_bound(Apos.begin() + i + 1, Apos.end(), min_val+1) - Apos.begin() - i - 1;

        cnt += cnt_; 
      }

      if(cnt >= L){
        right = mid;
      }else{
        left = mid;
      }
    }
    ans = right;
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%N;x=x*x%N;n>>=1;}return res;}
ll modinverse(ll a){return power(a,  998244353-2);}
void solve()
{
   ll n, k;
   ll MOD=1000000007;
   cin>>n>>k;
   vl a(n);
   vl pos;
   vl neg;
   ll xyz=1;
   forr(i, n)
   {
       cin>>a[i];
       xyz=(xyz*a[i])%MOD;
       if(xyz<0)
       xyz+=MOD;
       if(a[i]>=0)
       pos.pb(a[i]);
       else
       neg.pb(-a[i]);
   }
   if(k==n)
   {
       cout<<xyz<<endl;
       return;
   }
   sort(all(pos));
   sort(all(neg));
   reverse(all(pos));
   reverse(all(neg));
   if(neg.size()==0)
   {
       ll prod=1;
       for(ll i=0; i<k; i++)
       {
           prod=(prod*pos[i])%MOD;
           if(prod<0)
           prod+=MOD;
       }
       cout<<prod<<endl;
       return;
   }
   if(pos.size()==0)
   {
       ll prod=1;
       if(k%2==0)
       {
           for(ll i=0; i<k; i++)
           {
               prod=(prod*neg[i])%MOD;
               if(prod<0)
               prod+=MOD;
           }
       }
       else
       {
           reverse(all(neg));
           prod=-1;
           for(ll i=0; i<k; i++)
           {
               prod=(prod*neg[i])%MOD;
               if(prod<0)
               prod+=MOD;
           }
       }
       cout<<prod<<endl;
       return;
   }
   ll prod=1;
   ll ind1=0, ind2=0;
   ll index=1;
   if(k%2==1)
   {
       k--;
       prod=pos[ind1]%MOD;
       if(prod<0)
       prod+=MOD;
       ind1++;
   }
   while(true)
   {
       if(k==0)
       {
           cout<<prod<<endl;
           return;
       }
       if(ind1+1<pos.size()&&ind2+1<neg.size())
       {
           ll check1=pos[ind1]*pos[ind1+1];
           ll check2=neg[ind2]*neg[ind2+1];
           if(check1<=check2)
           {
               check2%=MOD;
               prod=(prod*check2)%MOD;
               if(prod<0)
               prod+=MOD;
               ind2+=2;
           }
           else
           {
               check1%=MOD;
               prod=(prod*check1)%MOD;
               if(prod<0)
               prod+=MOD;
               ind1+=2;
           }
       }
       else if(ind1+1<pos.size())
       {
           ll check1=pos[ind1]*pos[ind1+1];
           check1%=MOD;
           prod=(prod*check1)%MOD;
           if(prod<0)
           prod+=MOD;
           ind1+=2;
       }
       else if(ind2+1<neg.size())
       {
           ll check2=neg[ind2]*neg[ind2+1];
           check2%=MOD;
           prod=(prod*check2)%MOD;
           if(prod<0)
           prod+=MOD;
           ind2+=2;
       }
       k-=2;
   }
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
}

Measured memory_bytes: 6992
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;

int n, m;
int tag[N << 2], mx[N << 2];
pii a[N];

void Build(int x, int l, int r) {
	tag[x] = 0;
	if (l == r) {
		mx[x] = -l;
		return;
	}
	int mid = (l + r) >> 1;
	Build(x << 1, l, mid);
	Build(x << 1 | 1, mid + 1, r);
	mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}

inline void Pushdown(int x) {
	mx[x << 1] += tag[x];
	mx[x << 1 | 1] += tag[x];
	tag[x << 1] += tag[x];
	tag[x << 1 | 1] += tag[x];
	tag[x] = 0;
}

void Updata(int x, int l, int r, int ql, int qr) {
	if (ql <= l && r <= qr) {
		++mx[x];
		++tag[x];
		return;
	}
	Pushdown(x);
	int mid = (l + r) >> 1;
	if (mid >= ql)
		Updata(x << 1, l, mid, ql, qr);
	if (mid < qr)
		Updata(x << 1 | 1, mid + 1, r, ql, qr);
	mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}

int Query(int x, int l, int r, int ql, int qr) {
	if (ql <= l && r <= qr) return mx[x];
	int mid = (l + r) >> 1, ans = -inf;
	Pushdown(x);
	if (mid >= ql) {
		ans = max(ans, Query(x << 1, l, mid, ql, qr));
	}
	if (mid < qr) {
		ans = max(ans, Query(x << 1 | 1, mid + 1, r, ql, qr));
	}
	return ans;
}

void dfs(int x, int l, int r) {
	cout << x << ' ' << l << ' ' << r << ' ' << mx[x] << endl;
	Pushdown(x);
	int mid = (l + r) >> 1;
	if (l == r) return;
	dfs(x << 1, l, mid);
	dfs(x << 1 | 1, mid + 1, r);
}

bool cmp(pii a, pii b) {
	return a.second > b.second;
}

int main() {
	scanf("%d%d", &n, &m);
	Build(1, 0, m + 1);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i].first, &a[i].second);
	}
	sort(a + 1, a + n + 1, cmp);
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i == 1 || a[i].second == a[i - 1].second) {
			Updata(1, 0, m + 1, a[i].first, m + 1);
		}
		else {
			int t = Query(1, 0, m + 1, 0, a[i - 1].second - 1);
			ans = max(ans, t - m + a[i - 1].second - 1);
			Updata(1, 0, m + 1, a[i].first, m + 1);
		}
	}
	ans = max(ans, Query(1, 0, m + 1, 0, a[n].second - 1) - m + a[n].second - 1);
	ans = max(ans, 0);
	ans = max(ans, n - m);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int n;
ll a[3005];
ll f[3005][3005];

int main(){
	scanf("%d",&n);
	fore(i,0,n)scanf("%lld",a+i);
	fore(l,1,n+1)fore(i,0,n-l+1){
		int j=i+l;
		f[i][j]=max(a[i]-f[i+1][j],a[j-1]-f[i][j-1]);
	}
	printf("%lld\n",f[0][n]);
	return 0;
}

Measured memory_bytes: 70016
N = int(input())
A = list(map(int,input().split()))
ans = 1000

updown = [0] * (N-1)
for i in range(N-1):
  if A[i] > A[i+1]:
    updown[i] = 0
  elif A[i] == A[i+1]:
    updown[i] = 1
  else:
    updown[i] = 2
    
down = 0
up = -1
for i in range(N-1):
  if updown[i]==0:
    if up!=-1:
      ans += (ans // A[down]) * (A[up] - A[down])
      up = -1
    down = i + 1
    
  elif updown[i]==2:
    up = i + 1

if up!=-1:
  ans += (ans // A[down]) * (A[up] - A[down])
print(ans)

Measured memory_bytes: 62052
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define Oans cout << Ans << endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll
#define Endl endl

struct edge{int end;double cost;};
typedef pair<double,int> P;
double d[1040];
vector<edge> G[1040];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    for(int i=0;i<1040;i++){d[i]=(double)INF;}
    d[s]=0.0;
    que.push(P(0.0,s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.end]>d[v]+e.cost){
                d[e.end] = d[v]+e.cost;
                que.push(P(d[e.end],e.end));
            }
        }
    }
}

signed main(){
    int xs,ys,xt,yt;
    int N;
    int x[1040],y[1040],r[1040];
    cin >> xs >> ys >> xt >> yt >> N;
    REP(i,N){
        cin >> x[i] >> y[i] >> r[i];
    }
    edge h;
    REP(i,N){
        REP(j,i){
            h.end=j;
            h.cost=max((double)0.0,hypot(x[i]-x[j],y[i]-y[j])-r[i]-r[j]);
            G[i].push_back(h);
            h.end=i;
            G[j].push_back(h);
        }
    }
    //スタートは1000、ゴールは1001
    REP(i,N){
        h.end=i;
        h.cost=max((double)0.0,hypot(x[i]-xs,y[i]-ys)-r[i]);
        G[1000].push_back(h);
        h.end=1000;
        G[i].push_back(h);
    }
    REP(i,N){
        h.end=i;
        h.cost=max((double)0.0,hypot(x[i]-xt,y[i]-yt)-r[i]);
        G[1001].push_back(h);
        h.end=1001;
        G[i].push_back(h);
    }
    h.end=1001;
    h.cost=hypot(xs-xt,ys-yt);
    G[1000].push_back(h);
    h.end=1000;
    G[1001].push_back(h);
    
    dijkstra(1000);
    printf("%.12f\n",d[1001]);
    
    return 0;
}   


Measured memory_bytes: 22640
// Anve$hi $hukla
#include <bits/stdc++.h>
using namespace std;
struct ${$(){ios_base::sync_with_stdio(false);cin.tie(NULL);}}$;

typedef long long LL;
const int Maxn = 200005;

int main() {
   string s, t;
   cin >> s;
   t = s;
   int n = s.length();

   for(int i = 0; i < n; i++) {
      if(i % 2 == 0)
         t[i] = 'g';
      else
         t[i] = 'p';
   }
   int ans = 0;
   for(int i = 0; i < n; i++) {
      if(t[i] > s[i])
         ans++;
      else if(t[i] < s[i])
         ans--;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
  ll x,y; cin>>x>>y;
  if(abs(x-y)>1)
    cout<<"Alice\n";
  else
    cout<<"Brown\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> S;
bool visited[100][100][2];
int memo[100][100][2];
int f(int i, int j, int k) {
	if (i == 0 && j == 0) {
		int kk = S[i][j] == '#' ? 1 : 0;
		int r = 0;
		if (k == 0 && kk == 1) ++ r;
		return r;
	}
	if (visited[i][j][k]) return memo[i][j][k];
	visited[i][j][k] = true;
	int kk = S[i][j] == '#' ? 1 : 0;
	int r = 1<<30;
	if (i > 0) r = min(r, f(i-1, j, kk));
	if (j > 0) r = min(r, f(i, j-1, kk));
	if (k == 0 && kk == 1) ++ r;
	return memo[i][j][k] = r;
}
int main() {
	cin >> H >> W;
	S.resize(H);
	for (auto& x : S) cin >> x;
	cout << f(H-1, W-1, 0) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int gcd(int x, int y){
	int a, b, r;
	a = max(x, y);
	b = min(x, y);
	while (true) {
		r = a % b;
		if (r == 0){
			return b;
			break;
		}
		else {
			a = b;
			b = r;
		}
	}
}

int main() {
	int k, ans;
	cin >> k;
  ans = 0;
	for (int a = 1; a <= k; ++a)
	{
		for (int b = 1; b <= k; ++b)
		{
			for (int c = 1; c <= k; ++c)
			{
				int g;
				g = gcd (gcd (a, b), gcd (b, c));
				ans += g;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#119-B
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
ans=0
for i in range(n):
    x,u=input().split()
    if u=="JPY":
        ans+=int(x)
    else:
        ans+=float(x)*380000
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,k,a[N];
ll func(ll bit,ll flg){
    if(bit==-1)return 0;
    if(flg){
        ll cnt = 0 ;
        for(ll i=1;i<=n;i++)cnt+=(a[i]>>bit)%2;
        ll ans = (1ll<<bit) * max(cnt , n - cnt);
        return ans + func(bit-1,flg);
    }
    else{
        ll cnt = 0;
        for(ll i=0;i<=n;i++)cnt+=(a[i]>>bit)%2;
        if((k>>bit)&1){
            if(cnt>=n-cnt){
                ll ans = (1ll<<bit)*cnt;
                return ans + func(bit-1,1);
            }
            else{
                ll ans = (1ll<<bit)*(n-cnt);
                return ans + func(bit-1,0);
            }
        }
        else{
            ll ans = (1ll<<bit)*cnt;
            return ans + func(bit-1,flg);
        }
    }
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>k;
    for(ll i=1;i<=n;i++)cin>>a[i];
    cout<<func(61,0);
}

Measured memory_bytes: 1024
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M;
	cin >> N >> M;
	VVI A;
	A.resize(N, VI(N,0));
	for (int y = 0; y < N; y++) {
		string S;
		cin >> S;
		for (int x = 0; x < N; x++) {
			if (S[x] == '.')A[y][x] = 0;
			else A[y][x] = 1;
		}
	}
	VVI B;
	B.resize(M, VI(M, 0));
	for (int y = 0; y < M; y++) {
		string S;
		cin >> S;
		for (int x = 0; x < M; x++) {
			if (S[x] == '.')B[y][x] = 0;
			else B[y][x] = 1;
		}
	}
	for (int dy = 0; M - 1 + dy < N; dy++) {
		for (int dx = 0; M - 1 + dx < N; dx++) {
			bool flag = true;
			for (int x = 0; x < M; x++) {
				for (int y = 0; y < M; y++) {
					if (B[y][x] != A[y + dy][x + dx]) {
						flag = false;
						break;
					}
				}
				if (!flag)break;
			}
			if (flag) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}

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

typedef long long ll;
const int maxn=100010;
multiset<int> S[maxn];
set<pair<int,int> > S2;
struct Edge
{
	int v,next;
}	e[maxn<<1];
int g[maxn],tot;
void addedge(int x,int y)
{
	tot++;
	e[tot].v=y;
	e[tot].next=g[x];
	g[x]=tot;
}
int n,m;
bool vis[maxn];
int a[maxn];

void dfs(int t,int ha)
{
	S[ha].insert(a[t]);
	vis[t]=true;
	for (int i=g[t];i;i=e[i].next)
	if (!vis[e[i].v])
		dfs(e[i].v,ha);
}
int Union(pair<int,int> x,pair<int,int> y)
{
	multiset<int>::iterator it=S[x.second].lower_bound(x.first);
	S[x.second].erase(it);
	it=S[y.second].lower_bound(y.first);
	S[y.second].erase(it);
	int l=x.second,r=y.second;
	if (S[l].size()>S[r].size())	swap(l,r);
	for (auto i:S[l])
		S[r].insert(i);
	S[l].clear();
	return r;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)	scanf("%d",&a[i]);
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x++;y++;
		addedge(x,y);
		addedge(y,x);
	}
	for (int i=1;i<=n;i++)
	if (!vis[i])
		dfs(i,i);
	for (int i=1;i<=n;i++)
		if (!S[i].empty())
			S2.insert(make_pair(S[i].size(),i));
	ll ans=0;
	for (int i=1;i<=n-1-m;i++)
	{
		if (S2.empty())
		{
			printf("Impossible\n");
			return 0;
		}
		pair<int,int> tmp1=*--S2.end();
		S2.erase(--S2.end());
		if (S2.empty())
		{
			printf("Impossible\n");
			return 0;
		}
		pair<int,int> tmp2=*--S2.end();
		S2.erase(--S2.end());
		tmp1.first=*S[tmp1.second].begin();
		tmp2.first=*S[tmp2.second].begin();
		ans+=tmp1.first+tmp2.first;
		int q=Union(tmp1,tmp2);
		if (!S[q].empty())	S2.insert(make_pair(S[q].size(),q));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15616
while True:
    n, x = map(int,input().split())
    if n == 0 and x == 0:
        break
    counts = 0
    for a in range(1, n-1):
        for b in range(a+1, n):
            for c in range(b+1, n+1):
                if a + b + c == x:
                    counts += 1
    print(counts)


Measured memory_bytes: 5596
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key = lambda x: -x[1])

for B, C in BC:
  A.extend([C]*B)
  if len(A) > N*2:
    break
A.sort(reverse = True)
print(sum(A[:N]))

Measured memory_bytes: 36088
N = int(input())

def cnt753(s):
  if int(s) > N:
    return 0
  if all(s.count(c) > 0 for c in ["7","5","3"]):
    ret = 1
  else:
    ret = 0
  for c in ["7","5","3"]:
    ret += cnt753(s+c)
  return ret
print(cnt753("0"))

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

using namespace std;

int h, w;
char field[100][101];

void solve(int x, int y){

    switch(field[y][x]){

        case '>':
            field[y][x] = 'x';
            solve(x + 1, y);
            return;

        case '<':
            field[y][x] = 'x';
            solve(x - 1, y);
            return;

        case '^':
            field[y][x] = 'x';
            solve(x, y - 1);
            return;

        case 'v':
            field[y][x] = 'x';
            solve(x, y + 1);
            return;

        case '.':
            cout << x << ' ' << y << endl;
            return;

        case 'x':
            cout << "LOOP" << endl;
            return;

    }

}

int main(){

    while(cin >> h >> w, h | w){

        for(int i = 0; i < h; ++i){
            for(int j = 0; j < w; ++j){
                cin >> field[i][j];
            }
        }

        solve(0, 0);

    }

}

Measured memory_bytes: 1168
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    S = kwargs["S"]
    cnt = collections.Counter(S)
    res = "AC x {}\nWA x {}\nTLE x {}\nRE x {}".format(cnt["AC"], cnt["WA"], cnt["TLE"], cnt["RE"])
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    kwargs["S"] = []
    for i in range(kwargs["n"]):
        cin = input().split()
        s = cin[0]
        kwargs["S"].append(s)

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 38388
#include<stdio.h>
#include<math.h>
int ab(double);
int main(){
	int n, i;
	double D[4] = {0};
	double E[4] = {0};
	double pow2, pow3;
	scanf("%d", &n);
	double	x[100] = { 0 }, y[100] = { 0 };

	for (i = 0; i < n; i++){
		scanf("%lf", &x[i]);
	}
	for (i = 0; i < n; i++){
		scanf("%lf", &y[i]);
	}

	//p=1;
	for (i = 0; i < n; i++){
		pow2 = ab(x[i] - y[i]);
		D[0] += pow2;
		D[1] += pow(pow2, 2);
		D[2] += pow(pow2, 3);
	}
	E[0] = D[0];
	E[1] = sqrt(D[1]);
	E[2] = cbrt(D[2]);

	//p=00;
	for (i = 0; i < n; i++){
		if (D[3] < ab(x[i] - y[i])){
				D[3] = ab(x[i] - y[i]);
		}
	}
	E[3] = D[3];
	for (i = 0; i < 4; i++){
		printf("%lf\n",E[i]);
	}
	fscanf(stdin, "%d", &n);
	return 0;


}

int ab(double k){
	return (k > 0) ? k : -k;
}

Measured memory_bytes: 1160
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = 1e9;
const ll LINF = ll(1e18) + 1;
const ll MOD = 1000000007;
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
vector<ll> a;
ll dight(ll l){
    ll count=0;
    while(l){
        l/=2;
        count++;
    }
    return count;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    ll keta=dight(k);
    vector<ll> count(60,0);
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
        for(ll j=0;j<59;j++){
            if((1LL<<j)&temp){
                count[j]++;
            }
        }
    }
    /*
    cout<<keta<<"\n";
    debug(count);
    */
    ll ans=0;
    vector<ll> ansd(keta,0);
    for(ll i=59;i>=0;i--){
        if(i>=keta){
            ans+=(1LL<<i)*count[i];
        }
        else{
        if(((1LL<<i)&k)){
            ansd[i]=(1LL<<i)*(count[i])+ans;//あとは自由
            ans+=(1LL<<i)*(n-count[i]);
            
        }
        else{
            ans+=(1LL<<i)*(count[i]);
        }
        for(int j=keta-1;j>i;j--){
            if(ansd[j]!=0)
            ansd[j]+=(1LL<<i)*max((n-count[i]),count[i]);
        }
        }
    }
    /*
    cout<<ans<<"\n";
    debug(ansd);
    */
    rep(i,keta){
        chmax(ans,ansd[i]);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 1528
object Main extends App {

  val Array(a, b) = scala.io.StdIn.readLine().split(" ").map(_.toInt)


  def solve() = a match {
    case x if (x >= 13) => b
    case x if (6 <= x && x <= 12) => b / 2
    case _ => 0
  }

  println(solve)

}

Measured memory_bytes: 27064
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int N;
  rd(N);
  wt_L(N/3);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int N;
//   rd(N);
//   wt(N/3);
// }


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

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

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;        if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

bool ok(const string& s) {
    int len = (int)s.size();
    for (int i = 0; i < len / 2; i++) {
        if (s[i] != s[len - i - 1]) return false;
    }
    return true;
}

void solve() {
    int n;
    cin >> n;
    int dp[n+1];
    for (int i = 0; i <= n; i++) dp[i] = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (n == 2) {
        cout << abs(a[1] - a[0]);
        return;
    }
    dp[1] = abs(a[1] - a[0]);
    dp[2] = abs(a[2] - a[0]);
    for (int i = 3; i < n; i++) {
        dp[i] = min( abs(a[i] - a[i-1]) + dp[i-1], abs(a[i] - a[i-2]) + dp[i-2] );
    }

    cout << dp[n-1] << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    return 0;
}



Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
using namespace std;
int A[50];
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
  	cin >> A[i];
  }
  sort(A, A+n);
  long double ans = A[0];
  for(int i=1;i<n;i++){
  	ans = (ans + A[i]) / 2;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import sys, re
import math
import numpy as np
from decimal import Decimal
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.maxsize = 10 ** 15
sys.setrecursionlimit(10 ** 9 + 7)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

n = INT()
count = 0
for x in range(0, n):
    a,b = MAP()
    if a == b:
        count += 1
        if count == 3:
            break
    else:
        count = 0
if count == 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27284
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N==1:
        print(1)
    else:
        X, Y = [0] * N, [0] * N
        for i in range(N):
            X[i], Y[i] = map(int, input().split())
        ans = 10 ** 10
        for i in range(N):
            for j in range(N):
                if i != j:
                    p = X[j] - X[i]
                    q = Y[j] - Y[i]
                else:
                    continue
                sub = 0
                for k in range(N):
                    for l in range(N):
                        if X[l] - X[k] == p and Y[l] - Y[k] == q:
                            sub += 1
                ans = min(ans, N - sub)
    
        print(ans)


resolve()

Measured memory_bytes: 40432
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  
  for(scanf("%d",&x);x<1000;x++){
    char s[4];
    sprintf(s,"%d",x);
    if(s[0]==s[1]&&s[1]==s[2]) return puts(s),0;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> S;

signed main()
{
    cin >> N;
    S.resize(N);
    REP(i, N) { cin >> S[i]; }

    ll ans = 0;

    // C = A - B とすると、
    // B 移動では C * 0 .. C * k の場所を取得でき、
    // A 移動では A + C * 0 .. A + C * k の場所を取得する
    // C, k を全探索する
    for(ll C = 1; C < N; ++C) {
        ll prev_val_a = 0;      // A 移動によって取得した数の和
        ll prev_ind_a = N-1;    // 1 つ前のループで遷移した S のインデックス
        ll prev_val_b = 0;      // B 移動によって取得した数の和
        ll prev_ind_b = 0;      // 1 つ前のループで遷移した S のインデックス

        // A + C * k = N - 1 より、 k = ((N - 1) - A) / C なので k は N / C くらいまでのループを
        // 見ればよい
        for(ll k = 1; k < N / C; ++k) {
            // C を固定した場合、1 つ前のループの値が使いまわせる
            ll A = N - 1 - C * k;
            ll B = A - C;
            if(A <= 0 || B <= 0 || A <= B) { continue; }
            prev_ind_b += C;
            prev_val_b += S[prev_ind_b];

            // A 移動でとる位置と B 移動でとる位置がかぶったらだめ
            // -> C が N - 1 の約数の場合
            if((N - 1)  % C == 0 && prev_ind_a == prev_ind_b) { break; }
            prev_ind_a -= C;
            prev_val_a += S[prev_ind_a];

            if((N - 1) % C == 0 && prev_ind_a == prev_ind_b) { break; } // 念のため・・。
            if(prev_ind_a <= 0 || prev_ind_b >= N - 1) { break; }

            ans = max(ans, prev_val_a + prev_val_b);
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++) A[i] = sc.nextInt();
        sc.close();
        int[] dp = new int[K+1];
        for(int i = 1; i <= K; i++){
            for(int j = 0; j < N; j++){
                if(A[j] <= i && dp[i - A[j]] == 0){
                    dp[i] = 1;
                    break;
                }
            }
        }
        System.out.println(dp[K] == 1 ? "First" : "Second");

    }

}


Measured memory_bytes: 23252
/*
  si = ai ai+1 ... aN-1 (テ・ツ渉ウティツセツコテ」ツ?ッ10テゥツ?イテヲツ閉ーテ」ツ?ィテ」ツ?療」ツ?ヲテ」ツ?ソテ」ツつ?
  テ」ツ?ィテ」ツ?凖」ツつ凝」ツ?Ｊ < j テ」ツ?ョテ」ツ?ィテ」ツ?催」ツ??
  si - sj = ai ai+1 .. aj-2 aj-1 * 10^k

  (i)Q != 2, 5テ」ツ?ョテ」ツ?ィテ」ツ??
  10^kテ」ツ?ィQテ」ツ?ッテ、ツコツ津」ツ??」ツ?ォテァツエツ?」ツ?ェテ」ツ?ョテ」ツ?ァ,
  si - sj テ」ツ?ッQテ」ツ?ョテ・ツ?催ヲツ閉ー
  テ「ツ??ai ai+1 .. aj-2 aj-1 * 10^k テ」ツ?ッQテ」ツ?ョテ・ツ?催ヲツ閉ー
  テ「ツ??ai ai+1 .. aj-2 aj-1 テ」ツ?ッQテ」ツ?ョテ・ツ?催ヲツ閉ー
  テ」ツ?セテ」ツ?淌」ツ??
  si - sj テ」ツ?ッQテ」ツ?ョテ・ツ?催ヲツ閉ー
  テ「ツ??si - sj テ「ツ可。 0 (mod Q)
  テ「ツ??si テ「ツ可。 sj (mod Q)
  テ」ツつ暗」ツ?」テ」ツ?ヲテ」ツ??
  si テ「ツ可。 sj (mod Q)
  テ「ツ??ai ai+1 .. aj-2 aj-1 テ」ツ?ッQテ」ツ?ョテ・ツ?催ヲツ閉ー

  テ」ツ?ェテ」ツ?ョテ」ツ?ァテ」ツ?《i テ「ツ可。 sj (mod Q)テ」ツ?ィテ」ツ?ェテ」ツつ凝」ツつ暗」ツ??」ツ?ェsi,sjテ」ツつ津ヲツ閉ーテ」ツ?暗」ツつ凝」ツ??

  (ii)Q = 2 or 5テ」ツ?ョテ」ツ?ィテ」ツ??
  テ」ツ?禿」ツ?ョテ・ツ?エテ・ツ青?i)テ」ツ?ョテヲツ鳴ケテヲツウツ陛」ツ??」ツ?ィ10^kテ」ツ?ィQテ」ツ?古、ツコツ津」ツ??」ツ?ォテァツエツ?」ツ?ァテ」ツ?ッテ」ツ?ェテ」ツ??」ツ?ョテ」ツ?ァテ」ツ??」ツ?セテ」ツ?湘ヲツ閉ーテ」ツ?暗」ツつ嘉」ツつ古」ツ?ェテ」ツ??」ツ??
  テ」ツ?ェテ」ツ?ョテ」ツ?ァテ、ツクツ?」ツ?ョテ、ツスツ催」ツ?ョテヲツ閉ーテ・ツュツ療」ツつ津」ツ?ソテ」ツ?ヲテヲツ閉ーテ」ツ?暗」ツつ凝」ツ??
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long lli;

const int MAXN = 100005;

lli N, S, W, Q;
lli a[MAXN];

void generate() {
  int g = S;
  for(int i=0; i<N; i++) {
    a[i] = (g/7) % 10;
    if( g%2 == 0 ) { g = (g/2); }
    else           { g = (g/2) ^ W; }
  }
}

lli solve25() {
  lli res = 0;
  for(lli i = 0, c = 0; i < N; ++i) {
    c += (a[i] != 0);
    if(a[i]%Q == 0) {
      res += c;
    }
  }
  return res;
}

lli solve() {
  lli res = 0;
  map<lli,lli> m;
  ++m[0];
  for(lli i = N-1, s = 0, t = 1; i >= 0; --i, t = t*10%Q) {
    s = (s + t*a[i]) % Q;
    if(a[i]) res += m[s];
    ++m[s];
  }
  return res;  
}

int main() {
  while(cin >> N >> S >> W >> Q && (N|S|W|Q)) {
    generate();
    if(Q == 2 || Q == 5) {
      cout << solve25() << endl;
    } else {
      cout << solve() << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 7596
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#define SIZE 100005
#define BT 1024*128*2
#define INF 100000000000000000LL

using namespace std;
typedef long long int ll;

struct segtree
{
	int seg[BT];
	int mum;
	
	void init(int n)
	{
		mum=1;
		while(mum<n) mum<<=1;
		for(int i=0;i<mum*2;i++) seg[i]=BT;
	}
	void update(int a,int b,int k,int l,int r,int v)
	{
		if(b<=l||r<=a) return;
		if(a<=l&&r<=b) seg[k]=min(seg[k],v);
		else
		{
			update(a,b,k*2+1,l,(l+r)/2,v);
			update(a,b,k*2+2,(l+r)/2,r,v);
		}
	}
	void update(int a,int b,int v)
	{
		update(a,b,0,0,mum,v);
	}
	int get(int k)
	{
		k+=mum-1;
		int ret=seg[k];
		while(k>0)
		{
			k=(k-1)/2;
			ret=min(ret,seg[k]);
		}
		return ret;
	}
};
segtree seg;
int A[SIZE],B[SIZE];
ll sum[SIZE];
ll dp[SIZE];

int main()
{
	int n,K;
	scanf("%d %d",&n,&K);
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&A[i],&B[i]);
		if(B[i]==1&&A[i]*2>K)
		{
			puts("-1");
			return 0;
		}
	}
	for(int i=0;i<n;i++)
	{
		sum[i]=A[i];
		if(i>0) sum[i]+=sum[i-1];
	}
	vector <ll> vx;
	vx.push_back(0);
	for(int i=0;i<n;i++) vx.push_back((sum[i]*2LL)%K);
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	seg.init(vx.size()+2);
	seg.update(0,vx.size(),n);
	dp[n]=0;
	for(int i=n-1;i>=0;i--)
	{
		if(B[i]==2) continue;
		ll f=i==0?0:sum[i-1];
		int pos=lower_bound(vx.begin(),vx.end(),(f*2LL)%K)-vx.begin();
		int to=seg.get(pos);
		//printf("* %d %d\n",i,to);
		if(to==n) dp[i]=0;
		else
		{
			ll diff=2LL*(sum[to-1]-f);
			dp[i]=dp[to]+(K-diff%K)%K;
		}
		//if(B[i]==1)
		{
			int nxt=lower_bound(vx.begin(),vx.end(),(sum[i]*2LL)%K)-vx.begin();
			if(pos<nxt) seg.update(pos,nxt,i);
			else
			{
				if(pos<vx.size()) seg.update(pos,vx.size(),i);
				if(nxt>0) seg.update(0,nxt,i);
			}
		}
	}
	ll ret=INF;
	for(int i=0;i<vx.size();i++)
	{
		ll a=vx[i],b=i+1==vx.size()?K-1:vx[i+1]-1;
		int v=seg.get(i);
		ll f=v==0?0LL:sum[v-1];
		ll da=(a-(f*2LL)%K+(ll) K)%K;//[a,b]
		ll db=(b-(f*2LL)%K+(ll) K)%K;
		if(da>db) da=0;
		ret=min(ret,dp[v]+da+sum[n-1]*2LL);
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 4468
import math

n = int(input())
arr = [0] * n

for x in range(1,750):
    for y in range(1,750):
        for z in range(1,750):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= n:
                arr[ans - 1] += 1

for i in range(n):
    print(arr[i])

Measured memory_bytes: 74112
#include<bits/stdc++.h>
#define int long long
#define N 300004
#define LL long long
#define ULL unsigned long long
#define pp pair<int,int>
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define REP(i,n) for(int i=0;i<(n);++i)
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define SIZE(c) ((int)((c).size()))
#define ALL(u) (u).begin(),(u).end()
#define K 41
LL fpw(LL a, ULL b, LL p){
    LL r = 1; while(b){if(b&1) r=r*a%p; a=a*a%p; b/=2;} return (LL)r;
}

using namespace std;
int n, m,a,b,k;


bool present[5][5];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin >> k >> a >> b;
    if (b-a < 2) {
        cout << k+1 << endl; exit(0);
    }

    int  x = 1; int y = 0;

    for(int i = 1; i <= k; ++i) {
       // cout << x << " " << y << " start "  << i << endl;
        if (y > 0) {
            x += b; y--; continue;
        }
        if (i == k or x < a) {
            x++;
        } else {
            y += 1;
            x -= a;
        }
        //cout << x << " " << y << " end " << i << endl;
    }
    cout << x << endl;
}


Measured memory_bytes: 256