akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long int N,ans;
    ans = __LONG_LONG_MAX__;
    cin >> N;
    for(long int i=1;i<=sqrt((double)N);i++){
        if(N%i == 0 && (i + N/i) < ans){
            ans = (i + N/i);
        }
    }
    cout << ans - 2 << "\n";

}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] ar=new int[n][n];
		for(int i = 0; i<n; i++){
			Arrays.fill(ar[i],Integer.MAX_VALUE/2);
		}
		int[] a=new int[m];
		int[] b=new int[m];
		int[] c = new int[m];
		for(int i = 0; i<m; i++){
			a[i]= sc.nextInt()-1;
			b[i]= sc.nextInt()-1;
			c[i]= sc.nextInt();
			ar[a[i]][b[i]]=c[i];
			ar[b[i]][a[i]]=c[i];
		}
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				for(int k = 0; k<n; k++){
					if(i!=j && j!=k && i!=k){
						ar[j][k]=Math.min(ar[j][k],ar[j][i]+ar[i][k]);
					}
				}
			}
		}
		int ans=0;
		for(int i = 0; i<m; i++){
			if(ar[a[i]][b[i]]<c[i]){
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27864
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
	char w[11],s[1000],last;
	char* pos;
	int i,found=0;
	scanf("%s",w);
	getchar();
	while(1){
		scanf("%[^\n]",s);
		if(!strcmp(s,"END_OF_TEXT"))break;
		getchar();
		for(i=0;i<strlen(s);i++){
			s[i] = tolower(s[i]);
		}
		pos = s;
		while(1){
			pos = strstr(pos,w);
			if(pos==NULL)break;
			last=*(pos+strlen(w));
			if(last==' '||last=='\0'){
				if(pos==s||*(pos-1)==' ')found++;
			}
			pos += strlen(w);
		}
	}
	printf("%d\n",found);
	return 0;
}

Measured memory_bytes: 552
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //Compute c1 = new Compute();//calc

        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();

        //input
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        if (s.equals("Sunny")) System.out.println("Cloudy");
        else if (s.equals("Rainy")) System.out.println("Sunny");
        else if (s.equals("Cloudy")) System.out.println("Rainy");
    }
}

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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
}

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int N = 1e3+5;
int dp[505][505];
int arr[N];
int n, k;
int pre[N];
int f(int i, int j){
		
	if(i==j) return 0;

	if(dp[i][j]!=-1) return dp[i][j];

	int ans = 1e15;
	for(int k=i; k<=j-1; k++){
		ans = min(ans, f(i, k) + f(k+1, j) + pre[j]-pre[i-1]);
	}	

	return dp[i][j] = ans;
}

void solve()
{
	cin >> n;
	memset(dp, -1, sizeof(dp));
	rep(i, 1, n+1){
		cin >> arr[i];
		pre[i] = pre[i-1]+arr[i];
	}

	cout << f(1, n) << endl;
}			 	

int32_t main(){
	fast();
    int t = 1;
    // cin>> t;
    while(t--){
    	solve();
    }
	starboy1299();
}




Measured memory_bytes: 2304
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LF()
    r = [1]
    for i in range(n):
        t = [0] * (i+2)
        ai = a[i]
        a1 = 1 - a[i]
        for j in range(i+1):
            t[j] += r[j] * a1
            t[j+1] += r[j] * ai
        r = t

    return "{:0.10f}".format(sum(r[n//2+1:]))


print(main())


Measured memory_bytes: 6476
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string n;
    cin >> n;
    ll a=0;
    rep(i,n.size()){
        a+=n[i]-'0';
        a%=9;
    }
    if(a%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3768
N=int(input())
S=input()

l,r=0,1
res=0
def check(l,r):
    #半閉区間[l,r)
    if not l<r:
        return False
    t=S[l:r]
    s=S[r:]
    n=(r-l)
    for i in range(len(s)-n+1):
        if s[i:i+n]==t:
            return True
    return False
        


while l<N and r<N:
    if r==l:
        r+=1
    if check(l,r):
        res=max(r-l,res)
        r+=1
    else:
        l+=1
    
print(res)

Measured memory_bytes: 74232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<long long int> ans(n);
  if(n%2==0){
    for(int i=1;i<=n/2;i++) cin >> ans.at(n/2+i-1) >> ans.at(n/2-i);
  }
  if(n%2==1){
     cin >> ans.at((n+1)/2-1);
     for(int i=1;i<=(n-1)/2;i++) cin >> ans.at((n+1)/2+i-1) >> ans.at((n+1)/2-1-i) ;
  }
  for(int i=0; i<n;i++) cout << ans.at(i) << " ";
  cout << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    char s[20][20];
    int used[20][20];
    int maxi=0;
    rep(i,h)rep(j,w)cin>>s[i][j];
    rep(i,h)rep(j,w){
        if(s[i][j]=='#')continue;
        rep(k,h)rep(l,w)used[k][l]=-1;
        queue<P> pq;
        pq.push({i,j});
        used[i][j]=0;
        int tmp=0;
        while(!pq.empty()){
            P p=pq.front();pq.pop();
            int k=p.first,l=p.second;
            if(s[k][l]=='#'){
              used[k][l]=-2;
              continue;
            }
            tmp=max(tmp,used[k][l]);
            if(l+1<w && used[k][l+1]==-1){
                pq.push({k,l+1});
                used[k][l+1]=used[k][l]+1;
            }
            if(l-1>=0 &&used[k][l-1]==-1){
                pq.push({k,l-1});
                used[k][l-1]=used[k][l]+1;}
            if(k+1<h && used[k+1][l]==-1){
                pq.push({k+1,l});used[k+1][l]=used[k][l]+1;
            }
            if(k-1>=0 && used[k-1][l]==-1){
                pq.push({k-1,l});
                used[k-1][l]=used[k][l]+1;
            }
        }
        if(maxi<tmp)maxi=tmp;
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;if(n==1) return 0*puts("0");
    vector<int> v;
    for(int i=1;i<=n;i++){int tmp;cin>>tmp;v.push_back(tmp);}
    int ans=0;int tmp=0;
    for(int i=0;i<v.size()-1;i++){
        if(v[i]<v[i+1]){
            ans=max(ans,tmp);tmp=0;
        }else{
            tmp++;
        }
    }
    ans=max(ans,tmp);
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n, p;
    cin >> n >> p;
    int a[n];
    rep(i, n) cin >> a[i];

    ll dp[2][n + 1];

    dp[0][0] = 1;
    dp[1][0] = 0;

    rep(i, n) {
        if (a[i] % 2 == 0) {
            dp[0][i + 1] = dp[0][i]*2;
            dp[1][i + 1] = dp[1][i]*2;
        } else {
            dp[0][i + 1] = dp[0][i] + dp[1][i];
            dp[1][i + 1] = dp[1][i] + dp[0][i];
        }
    }

    cout << dp[p][n] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int now;
char st[1024];

void add_str(char d){
  int len=strlen(st);
  for(int i=len;i>now;i--){
    st[i]=st[i-1];
  }
  st[now]=d;
  return;
}

void af(char d){
  if(st[now+1]==d){
    now++;
    return;
  }else{
    st[now+1]=d;
    now++;
    return;
  }
}

void bf(char d){
  if(now-1>=0&&st[now-1]==d){
    now--;
    return;
  }else{
    add_str(d);
    return;
  }
}
int main(void){
  int n;
  char d,way[3];
  cin>>n;
  getchar();
  for(int i=0;i<n;i++){
    now=0;
    memset(st,'\0',sizeof(st));
    st[0]=getchar();
    while(true){
      way[0]=getchar();
      if(way[0]=='\n')break;
      way[1]=getchar();
      way[2]='\0';
      d=getchar();
      if(!strcmp(way,"->")){
        af(d);
      }else{
	bf(d);
      }
    }
    printf("%s\n",st);
  }
  return 0;
}

Measured memory_bytes: 1120
n=int(input())
k=int(input())

op=[[0],[1]]

for i in range(n-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp
ans=1e10

for i in op:
    a=1
    for j in range(n):
        if i[j]==0:
            a+=k
        else:
            a*=2
    ans=min(ans,a)
print(ans)

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

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << ' ' << X << ' ' << Y << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  vector<int> x(5);
  int k;
  rep(i, 5) cin >> x[i];
  cin >> k;

  rep(i, 5)
  {
    for (int j = i + 1; j < 5; j++)
    {
      if (std::abs(x[i] - x[j]) > k)
      {
        cout << ":(" << endl;
        return 0;
      }
    }
  }

  cout << "Yay!" << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
ac,wa,tle,re=0,0,0,0

for i in range(n):
  s=input()
  if s=="AC":
    ac+=1
  elif s=="WA":
    wa+=1
  elif s=="TLE":
    tle+=1
  elif s=="RE":
    re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))


Measured memory_bytes: 69984
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >>s;
    
    if(s[0]=='1'){
        cout <<9;
    }else if(s[0]=='9'){
        cout <<1;
    }else{
        cout <<s[0];
    }
    
    if(s[1]=='1'){
        cout <<9;
    }else if(s[1]=='9'){
        cout <<1;
    }else{
        cout <<s[1];
    }
    
    if(s[2]=='1'){
        cout <<9;
    }else if(s[2]=='9'){
        cout <<1;
    }else{
        cout <<s[2];
    }
    
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int a, b;
void solve() {
    cin >> a >> b;

    reps(i, 3)
        if (i != a && i != b) cout << i << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void check(char data[][101], int h,int w,char kind)
{
	if(data[h][w]==kind)
	{
		data[h][w]=0;
		if(h<100)
			check(data,h+1,w,kind);
		if(h>0)
			check(data,h-1,w,kind);
		if(w<100)
			check(data,h,w+1,kind);
		if(w>0)
			check(data,h,w-1,kind);
	}
}

int main()
{
	char DATA[100][101];
	int h,w,i,j;
	while(1)
	{
		int ans=0;
		scanf("%d%d",&h,&w);
		if(h==0 && w==0)
			break;
		else
		{
			
			for(i=0;i<h;i++)
					scanf("%s",DATA[i]);
					

			for(i=0;i<h;i++)
				for(j=0;j<w;j++)
					if(DATA[i][j]!=0)
					{
						ans++;
						check(DATA,i,j,DATA[i][j]);
					}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h, w;
    cin >> h >> w;
    char a[h][w];
    ll b[h][w];
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            cin >> a[i][j];
            b[i][j]=0;
        }
    }
    b[h-1][w-1]=1;
    for (int i = h-1; i >=0; --i)
    {
        for (int j = w-1; j >=0; --j)
        {
            if (a[i][j]=='.')
            {
                if(a[i+1][j]=='.'&&i+1<h)
                b[i][j]+=b[i+1][j];
                if(a[i][j+1]=='.'&&j+1<w)
                b[i][j]+=b[i][j+1];
                b[i][j]%=mod;
            }
        }
    }
    cout << b[0][0];
    return 0;
}

Measured memory_bytes: 9088
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], sum[N];
map < int, int > f; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	long long ans = 0, cur = 0; 
	cin >> n >> k;
	f[0] = 1; 
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum[i] = (sum[i - 1] + a[i] - 1) % k;
	}
	for(int i = 1; i <= n; i++){
		if(i >= k)f[sum[i - k]]--;
		ans += f[sum[i]];
		f[sum[i]]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L


int main() {
  int k,ans=-1,a;
  
  cin>>k;
  for(int i=1;i<=k;i++){
  	a=a*10+7;
    if(a%k==0){
    	ans=i;
      	break;
    
    }
  	a%=k;
  }
  
  cout<<ans<<endl;
}



Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
struct P {
	long long size, cost;
};
long long dp[600][10500];
long long a[10500],m,n;
long long d[10500];
P b[600];
long long solve(int i, int j) {
	if (i == n) return 0;
	long long sum = 0;
	if (j + b[i].size < m) {
		if (dp[i + 1][j + b[i].size] != -1) {
			sum = (d[j + b[i].size] - d[j] - b[i].cost) +
				dp[i + 1][j + b[i].size];
		}
		else {
			sum = (d[j + b[i].size] - d[j] - b[i].cost) +
				(dp[i + 1][j + b[i].size] =
				solve(i + 1, (j + b[i].size)));
		}
	}
	else {
		if (dp[i + 1][m] != -1) {
			sum = d[m] - d[j] - b[i].cost + dp[i + 1][m];
		}
		else {
			sum = d[m] - d[j] - b[i].cost + (dp[i + 1][m] =
				solve(i + 1, m));
		}
	}
	if (dp[i + 1][j] != -1) {
		sum = max(sum, dp[i + 1][j]);
	}
	else {
		sum = max(sum, dp[i+1][j]=solve(i + 1, j));
	}
	return sum;
}
int main() {
	while (cin >> m >> n) {
		for (int i = 0; i < m; i++) {
			cin >> a[i];
			d[i] = 0;
		}
		d[m] = 0;
		sort(a, a + m);
		reverse(a, a + m);
		for (int i = 0; i < n; i++)
			cin >> b[i].size >> b[i].cost;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j < m; j++)
				dp[i][j] = -1;
		}
		for (int i = 1; i <= m; i++) {
			d[i] = d[i - 1] + a[i - 1];
		}
		long long sum = solve(0, 0);
		if (sum < 0) sum = 0;
		cout << sum << endl;
	}
}

Measured memory_bytes: 44424
n, l = gets.split.map(&:to_i)

sum = 0
for i in 1..n
	sum += l + i - 1
end

list = []
for i in 1..n
	x = sum - (l + i - 1)
	list << x
end
puts list.min_by{|x| (x-sum).abs}


Measured memory_bytes: 1788
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        String f = String.format("%.5f", ((double)a/(double)b));

        System.out.println((a/b)+" "+(a%b)+" "+f);

    }
}

Measured memory_bytes: 26512
#include <stdio.h>
int main (void){
int D;
scanf("%d",&D);
if(D==25){
    printf("Christmas");
}else if(D==24){
    printf("Christmas Eve");
}else if(D==23){
    printf("Christmas Eve Eve");
}else if(D==22){
    printf("Christmas Eve Eve Eve");
}
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var ans int

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	x, _ := strconv.Atoi(stringLineScan())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(stringLineScan())
	}
	ans := 0
	for i := 0; i < n-1; i++ {
		if a[i]+a[i+1] > x {
			if x-a[i] >= 0 {
				ans += a[i] + a[i+1] - x
				a[i+1] = x - a[i]
			} else {
				ans += a[i] + a[i+1] - x
				a[i], a[i+1] = a[i]-(x-a[i+1]), 0
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Mon Dec 23 15:06:08 JST 2019
 **/

signed main() {
    Int n = in();
    vector<Int> a = in(n);
    Int cur = 0;
    for (Int x : a) {
        if (x == cur + 1) cur++;
    }
    Int ans = cur == 0 ? -1 : n - cur;
    cout << ans << endl;
}


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


def main():
    from math import sqrt

    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    count = 0

    for i in range(n):
        for j in range(i + 1, n):
            total = 0

            for k in range(d):
                total += (x[i][k] - x[j][k]) ** 2

            if total == int(sqrt(total)) ** 2:
                count += 1

    print(count)


if __name__ == '__main__':
    main()


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

const int INF = 1e10;

int N;
int h[111111];
int dp[111111];

signed main() {
  cin >> N;
  rep (i, N) {
    cin >> h[i];
  }

  fill(dp, dp+111111, INF);
  
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    if (i + 1 < N) {
      chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    }
    if (i + 2 < N) {
      chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
  }

  cout << dp[N-1] << endl;

  return 0;
}

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

template<class Numeric> struct Dinic {
  struct edge {
    int to; Numeric cap; int rev;
    edge(int t, Numeric c, int r){
      to = t; cap = c; rev = r;
    }
    void print() {
      cout << to << "\t" << cap << "\t" << rev << endl;
    }
  };
  vector< vector<edge> > g; vector<int> iter, level;
  int N; Numeric INF;
  Dinic(int n) {
    N = n; g.resize(N); iter.resize(N); level.resize(N);
    INF = numeric_limits<Numeric>::max();
  }
  void add(int from, int to, Numeric cap) {
    g[from].push_back(edge(to, cap, (int) g[to].size()));
    g[to].push_back(edge(from, 0, (int) g[from].size()-1));
  }
  void bfs(int s){
    level.assign(N,-1);
    queue<int> q;
    level[s] = 0; q.push(s);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for(int i = 0; i < (int) g[v].size(); i++){
        edge &e = g[v][i];
        if (e.cap > 0 and level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }
  Numeric dfs(int v, int t, Numeric f) {
    if (v == t) return f;
    for (int i = iter[v]; i < (int) g[v].size(); i++) {
      edge &e = g[v][i];
      if (e.cap > 0 && level[v] < level[e.to]){
        Numeric d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          g[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  Numeric solve(int s, int t) {
    Numeric flow = 0;
    while(true){
      bfs(s);
      if (level[t] < 0) return flow;
      iter.assign(N, 0);
      Numeric f;
      while ((f = dfs(s, t, INF)) > 0){
        flow += f;
      }
    }
  }
};


int main(){
  int n; cin >> n;
  Dinic<int> f((n+1)*2);
  vector<int> a(n), b(n), c(n), d(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    f.add(0, i+1, 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> d[i];
    f.add(n+i+1, n*2+1, 1);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i] < c[j] && b[i] < d[j]) f.add(i+1, n+j+1, 1);
    }
  }
  cout << f.solve(0, n*2+1) << endl;
  return 0;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    double a, b, x;
    cin >> a >> b >> x;

    if (a * a * b / 2.0 <= x) {
        double y = x - a * a * b / 2.0;
        double tb = (y * 2) / (a * a);
        double rad = atan2(a, b-tb);
        printf("%.10f\n", 90 - rad / M_PI * 180);
    } else {
        double ta = (x * 2) / (a * b);
        double rad = atan2(ta, b);
        printf("%.10f\n", 90 - rad / M_PI * 180);
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,n;
	cin>>x>>n;
	
	vector<int> arr(n);
	
	for(int i=0;i<n;i++)
	 cin>>arr[i];
    
    sort(arr.begin(),arr.end());
    int found =1,min=x,max=x;
    while(found){
    	
		int i;
    	for(i=0;i<n;i++)
    	 if(min==arr[i])
    	  break;
        if(i==n)
			found=0;
		else
		 min--;
	}
	found=1;
	while(found){
    	
		int i;
    	for(i=0;i<n;i++)
    	 if(max==arr[i])
    	  break;
        if(i==n)
			found=0;
		else
		 max++;
	}
	if(abs(max-x)>=abs(min-x))
	 cout<<min;
	else 
	 cout<<max; 
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int a[3];
int main() {
    cin >> s;
    for (int i = 0; i < 3; ++i) {
        ++a[s[i] - 'a'];
    }
    if (a[0] == 1 && a[1] == 1 && a[2] == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
N, W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1, N+1):
    for sum_w in range(1, W + 1):
        if sum_w-wv[i-1][0] >= 0:
            dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[-1][-1])


Measured memory_bytes: 171784
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
 int n,k;
 cin>>n>>k;
 vector<int>l(n);
 rep(i,n){
   cin>>l.at(i);
 }
 sort(all(l));
 reverse(all(l));
 int ans=0;
 rep(i,k){
   ans+=l.at(i);
 }
 cout<<ans<<endl;
}



Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

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

    while(--m >= 0){
        int ope;
        cin >> ope;
        if(ope == 0){
            int r, c, size, angle;
            cin >> r >> c >> size >> angle;
            -- r;
            -- c;

            while(angle > 0){
                vector<vector<int> > b = a;
                for(int i=0; i<size; ++i){
                    for(int j=0; j<size; ++j){
                        a[r+i][c+j] = b[r+size-1-j][c+i];
                    }
                }
                angle -= 90;
            }
        }
        else if(ope == 1){
            int r, c, size;
            cin >> r >> c >> size;
            -- r;
            -- c;
            for(int i=0; i<size; ++i){
                for(int j=0; j<size; ++j){
                    a[r+i][c+j] ^= 1;
                }
            }
        }
        else if(ope == 2){
            int r;
            cin >> r;
            -- r;
            rotate(a[r].begin(), a[r].begin()+1, a[r].end());
        }
        else if(ope == 3){
            int r;
            cin >> r;
            -- r;
            rotate(a[r].begin(), a[r].end()-1, a[r].end());
        }
        else{
            int r, c;
            cin >> r >> c;
            -- r;
            -- c;
            int num = a[r][c];
            a[r][c] = num ^ 1;

            queue<pair<int, int> > q;
            q.push(make_pair(r, c));
            while(!q.empty()){
                int y = q.front().first;
                int x = q.front().second;
                q.pop();
                for(int i=0; i<4; ++i){
                    int y2 = y + dy[i];
                    int x2 = x + dx[i];
                    if(y2 < 0 || y2 >= n || x2 < 0 || x2 >= n)
                        continue;
                    if(a[y2][x2] == num){
                        a[y2][x2] = num ^ 1;
                        q.push(make_pair(y2, x2));
                    }
                }
            }
        }
    }

    for(int i=0; i<n; ++i){
        cout << a[i][0];
        for(int j=1; j<n; ++j)
            cout << ' ' << a[i][j];
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <math.h>

int main() {

  double x1,y1,x,y;
  int w,h,n;
  int i,j,ki,l;
  double xs,ys;
  int s=0;
  scanf("%d %d %d",&w,&h,&n);


  scanf("%lf %lf",&x1,&y1);


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

    scanf("%lf %lf" ,&x,&y);
    //     printf("x = %lf x1 = %lf \n",x , x1);

    xs = x1-x;
    ys = y1-y;
  
    //     printf("xs = %lf\n",xs);

    if(xs*ys > 0) {
      xs = xs * xs;
      ys = ys * ys;
      //    printf("xs = %lf\n",xs);
      xs = sqrt(xs);
      ys = pow(ys, 1.0/2);
      //   printf("xs = %lf\n ys = %lf\n",xs,ys);

      if(xs > ys) {
	s = s + xs;
	//	printf("s = %d\n",s);
      } else {
	s = s + ys;
      }
    } else {

      xs = xs * xs;
      ys = ys * ys;
      xs = pow(xs, 1.0/2);
      ys = pow(ys, 1.0/2);
      s = s + xs + ys;
    }

    x1 = x;
    y1 = y;

  }

  printf("%d\n",s);

  return 0;

}

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

int main() {
    
    int X,N;
    int answer=0;
    bool match=false;
    cin>>X>>N;
    
    vector<int> d(102);//forbidden list
    rep(i,N){
      int p;
      cin>>p;
      d[p]=1;
    }
    P ans(99999,-1);
    for(int i=0; i<=101;++i)
    {
      if(d[i]==1)continue;
      int dif=abs(X-i);
      ans = min(ans,P(dif,i));
    }
    cout<<ans.second<<endl;
    return 0;
}

Measured memory_bytes: 3640
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		String S = nextString();
		System.out.println("ABC".equals(S)?"ARC":"ABC");
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main()
{
    int n, w;
    
    cin >>n >> w;
    vector<long long> dp(w+1, 0);
    for(int i = 0; i < n; i++){
        int val, weight;
        cin >> weight >> val;
        
        for(int j = w - weight; j >= 0; j--){
            dp[j + weight] = max(dp[j+weight], dp[j] + val);
            // cout << dp[j+weight] << " ";
        }
        
    }
    
    long long answer = 0;
    for(int i = 0; i<=w; i++)
        answer = max(answer, dp[i]);
    
    cout << answer;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}

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

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	ll t,n,m,k,i,j,z;
	str s;
	cin >> s;
	cout << s[0] << s[1] << s[2] << "\n";
	return 0;
}

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


Measured memory_bytes: 256
// 
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 1000000005


int main() {
	string a;
	string b;
	cin >> a >> b;
	if(b.substr(0,a.size())==a){
		outl("Yes");
	}else{
		outl("No");
	}
    return 0;
}



Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
n = int(input())
t,x,y = 0,0,0
for i in range(n):
  pt,px,py = t,x,y
  t,x,y = map(int,input().split())
  if t-pt < abs(x-px)+abs(y-py) or ((t-pt) - abs(x-px) - abs(y-py)) % 2:
    print('No')
    break
  if i == n-1:
    print('Yes')

Measured memory_bytes: 3064
S = input()
ans = False
if S[0] == S[1]:
    ans = (S[0] != S[2] and S[2] == S[3])
elif S[0] == S[2]:
    ans = (S[0] != S[1] and S[1] == S[3])
elif S[0] == S[3]:
    ans = (S[0] != S[1] and S[1] == S[2])
print("Yes" if ans else "No")

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    readLine()!!
    val list= readLine()!!.split(" ").map(String::toInt).toMutableList()
    list.sortDescending()
    var alice = 0
    var bob   = 0
    for(i in 0..list.count() -1) {
        if(i %2 == 0) {
            alice += list[i]
        } else if(i %2 != 0) {
            bob += list[i]
        }
    }
    print(alice - bob)
}

Measured memory_bytes: 36624
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(), W = sc.nextInt(), h= sc.nextInt(), w= sc.nextInt();
		System.out.println(W*H-W*h-H*w+h*w);
		sc.close();
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,y=0,x=0,z=0,p=0,ans=0;
    while(cin>>a)
    {
        x=a;
        y=x/500;
        x=x%500;
        p=x/5;
        //x=x%5;
        ans=y*1000+p*5;
        cout<<ans<<endl;


    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	vector<ll> a(n), s(n + 1);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	ll ans = 1e18;
	for (int t = 0; t < n; t++) {
		ll l = s[t], r = s[n] - s[t];
		ll d = abs(r - l);
		ans = min(ans, d);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, m;

int main() {
	cin >> n;
	ll a[n]; 
	for(ll i = 0; i < n; i++){
		ll buf;
		cin >> buf; 	
		a[i] = buf-(i+1);
	}
	sort(a, a+n);
	//for(ll i = 0; i < n; i++){
	//	cout << a[i] << endl;
	//}
	ll mid = (n%2==0)? (a[n/2-1]+a[n/2])/2 : a[n/2];
	ll r = 0;
	for(ll i = 0; i < n; i++){
		r += abs(a[i]-mid);
	}
	cout << r;
	return 0;
}

Measured memory_bytes: 1792
require 'set'

def main
    n,m = gets.chomp.split(" ").map(&:to_i)
    hs = gets.chomp.split(" ").map(&:to_i)
    hs = [0] + hs
    to = Array.new(n+1).map{Array.new()}
    (1..n).each do |i|
        to[i].push [i, hs[i]]
    end
    m.times do
        a,b = gets.chomp.split(" ").map(&:to_i)
        to[a].push [b, hs[b]]
        to[b].push [a, hs[a]]
    end
    (1..n).each do |i|
        to[i].sort_by!{ |x| x[1] }
    end

    ans = 0
    (1..n).each do |i|
        if to[i][-1][0] == i
            ans += 1
        end
    end
    puts ans
end

main

## イディオムなど
# until s.empty? do
#
## 配列のインデックス
# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
#
## 全探索
# [0, 1].repeated_permutation(n) do |combination| # bit全探索
# array.combination(i) do |selected| # array から要素が i 個である部分列を全部抽出
#
## 無向グラフの幅優先探索(BFS)
# to = Array.new(n).map{Array.new()} # ある頂点と繋がる頂点のリスト
# m.times do
#     a,b = gets.chomp.split(" ").map(&:to_i)
#     to[a].push b
#     to[b].push a
# end
# q = Queue.new # BFS は queue
# ds = Array.new(n, -1)
# pre = Array.new(n, -1)
#
## その他
# a1 = Marshal.load(Marshal.dump(a2)) # 深いコピー
# matrix = Array.new(n).map{Array.new()} # 二次元配列の初期化
# 

Measured memory_bytes: 65956
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = Integer.parseInt(sc.nextLine());
			if(n == 0) break;
			
			int[] array = new int[n];
			for(int i = 0; i < n; i++){
				array[i] = (sc.nextLine()).length();
			}
			
			for(int i = 0; i < n; i++){
				int sum = 0, flag = 0, pos = i;
				while(true){
					sum += array[pos];
					if(sum == 5 && (flag == 0 || flag == 2)){
						sum = 0;
						flag++;
					}else if(sum == 7 && (flag == 1 || flag == 3 || flag == 4)){
						sum = 0;
						flag++;
						if(flag == 5){
							break;
						}
					}else if(sum > 7){
						break;
					}
					pos++;
				}
				if(flag == 5){
					System.out.println(i+1);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 34108
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int a,b,c;
	std::cin >> a >> b >> c;
	std::swap(a,b);
	std::swap(a,c);
	std::cout << a << ' ' << b << ' ' << c << EL;
	return 0;
}


Measured memory_bytes: 256
def inpl():
    return tuple(map(int, input().split()))


def getHash():
    def value(i):
        ret = 0
        for j in range(N):
            if (i >> j) % 2:
                ret += A[j]
        return ret
    return set(value(i) for i in range(2**N))


def solve(m):
    return "yes" if m in hash else "no"


N = int(input())
A = inpl()

Q = int(input())
M = inpl()

hash = getHash()

for m in M:
    print(solve(m))



Measured memory_bytes: 5660
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=3005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int val[N], dp[N][N];
int fun(int l, int r)
{
    if(l>r)
    return 0;
    if(dp[l][r]!=-1)
    return dp[l][r];
    return dp[l][r]=max(val[l]-fun(l+1, r), val[r]-fun(l, r-1));
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>val[i];
    fill(dp, -1);
    cout<<fun(1, n);
}

Measured memory_bytes: 74364
# include <cstdio>

int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i+=2) {
        int a = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) a++;
        }
        if (a == 8) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   int r;
   cin >> r;
   double ans;
   double pi=acos(-1);
   ans=2*pi*r;
   cout<<fixed<<setprecision(5)<<ans;
}


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

int main(void) {
	long long n, L[86], i;
	cin >> n;
	for (L[0]=2,L[1]=1,i=2; i < n+1; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	cout << L[n] << endl;
	return 0;
}

Measured memory_bytes: 256