akhauriyash/Code-Regression huggingface dataset:
/*
 *           AUTHOR: Maria Theresa M. Padayhag
 *             DATE: 20160326
 *  PRE-REQUIREMENT: JDK 1.8
 */
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.time.*;
import java.time.format.TextStyle;
import java.util.Locale;

class DayIndentifier
{
	LocalDate date = null;
	
	public 	DayIndentifier( String inMonth, String inDay )
	{
		// NumberFormatException might be thrown here
		// but it will be handled by the caller.
		int month = Integer.parseInt( inMonth );
		int day   = Integer.parseInt( inDay );
		
		// DateTimeException might be thrown here
		// but it will be handled by the caller.
		date = LocalDate.of( 2004, month, day );
	}
	
	public String getDayOfWeek()
	{
		// NullPointerException might be thrown here
		// but it will handled by the caller.
		return date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH);
	}
}

public class Main
{
	public static boolean toExit( String[] dataset )
	{
		for(String data: dataset)
		{
			if(data.equals("0"))
				return true;
		}
		
		return false;
	}
	
	public static void main( String args[] ) throws IOException
	{
		BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
		String input;
		String dataset[];
		DayIndentifier di;
		
		READ: 
		while( ( input = br.readLine() ) != null ) {
			try {
				dataset = input.split(" ");
			
				if( toExit( dataset ) ) {
					break READ;
				}
				
				if( dataset.length != 2 ) {
					System.out.println("Invalid input.");
					continue READ;
				} 		
				
				di = new DayIndentifier(dataset[0], dataset[1]);
				System.out.println( di.getDayOfWeek() );
			} catch( Exception e ) {
				System.out.println("Invalid input.");
				continue READ;
			}		
		}
	}
}

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

int main(){
    int h,w;
    cin >> h >> w;
    int i,j;
    for(i=0;i<w+2;i++)
        cout << '#';
    cout << endl;
    char a[h][w];
    for(i=0;i<h;i++){
        cout << '#';
        for(j=0;j<w;j++){
            cin >> a[i][j];
            cout << a[i][j];
        }
        cout << '#' << endl;
    }
     for(i=0;i<w+2;i++)
        cout << '#';
    cout << endl;
}

Measured memory_bytes: 3596
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    ll price = 700;
    for(char c : s){
        if(c=='o'){
            price += 100;
        }
    }

    p(price);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<int,int> pii;
map<string,int>M;
bool cmp(lint a,lint b){
    return abs(a)>abs(b);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n,k,ans=1,sign=0;
    cin>>n>>k;
    vector<lint> V(n);
    for(int i=0;i<n;i++) cin>>V[i];
    sort(V.begin(),V.end(),cmp);
    for(int i=0;i<k;i++){
        ans=(ans*V[i])%mod;
        if(V[i]<0)
            sign++;
    }
    sign%=2;
    if(sign){
        int flg1=0,flg2=0,fnd=0;
        int pos1,pos2,pos3,pos4;
        for(pos1=k;pos1<n;pos1++){
            if(V[pos1]>0)
                break;
        }
        for(pos2=k-1;pos2>=0;pos2--){
            if(V[pos2]<0)
                break;
        }
        for(pos3=k;pos3<n;pos3++){
            if(V[pos3]<0)
                break;
        }
        for(pos4=k-1;pos4>=0;pos4--){
            if(V[pos4]>0)
                break;
        }
        if(pos1<n && pos2>=0) flg1=1;
        if(pos3<n && pos4>=0) flg2=1;
        if(flg1 && flg2 && abs(V[pos1])*abs(V[pos4])>abs(V[pos2])*abs(V[pos3]))
            fnd=1;
        else if(flg1 && flg2)
            fnd=2;
        else if(flg1)
            fnd=1;
        else if(flg2)
            fnd=2;

        if(fnd==1){
            ans=1;
            for(int i=0;i<k;i++){
                if(i!=pos2)
                    ans=(ans*V[i])%mod;
            }
            ans=(ans*V[pos1])%mod;
        }
        else if(fnd==2){
            ans=1;
            for(int i=0;i<k;i++){
                if(i!=pos4)
                    ans=(ans*V[i])%mod;
            }
            ans=(ans*V[pos3])%mod;
        }
        else{
            reverse(V.begin(),V.end());
            ans=1;
            for(int i=0;i<k;i++){
                ans=(ans*V[i])%mod;
            }
        }
    }
    cout<<(mod+ans)%mod;
    return 0;
}


Measured memory_bytes: 4756
// This code wrote by chtholly_micromaker(MicroMaker)
#pragma GCC optimize("Ofast,O3,inline")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln puts("")
#define lsp putchar(32)
#define pb push_back
#define MP make_pair
#define dbg(x) cerr<<">"<<__func__<<"\tLine: "<<__LINE__<<' '<<#x<<": "<<x<<endl
using namespace std;
const int MaxN=55;
struct Node
{
	int x,y;
}a[MaxN];
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
int n;
int outdeg[MaxN];
inline int calc(int p,int q)
{
	mem(outdeg,0);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(a[i].x-a[j].x==p&&a[i].y-a[j].y==q)
				++outdeg[i];
	reg int cnt=0;
	for(int i=1;i<=n;++i)
		if(!outdeg[i])
			++cnt;
	return cnt;
}
signed main(void)
{
	read(n);
	reg int ans=n;
	for(int i=1;i<=n;++i)
		read(a[i].x,a[i].y);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i!=j)
				checkmin(ans,calc(a[i].x-a[j].x,a[i].y-a[j].y));
	write(ans),ln;
	return 0;
}

/*
 * Check List:
 * 1. Input / Output File (USACO and OI and UVa)
 * 2. long long 
 * 3. Special Test such as n=1
 * 4. Array Size
 * 5. Memory Limit (OI) int is 4 and longlong is 8
 * 6. Mod (a*b%p*c%p not a*b*c%p  ,  (a-b+p)%p not a-b )
 * 7. Name ( int k; for(int k...))
 * 8. more tests , (T=2 .. more)
 * 9. blank \n after a case
*/






Measured memory_bytes: 3604
#include <bits/stdc++.h>
#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__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

ll n,m,q;
vl a(50),b(50),c(50),d(50);
ll ans;
vl s(10);

void dfs(ll i,ll v){
    if(v>m) return;
    s[i] = v;
    if(i==n-1){
        ll tmp = 0;
        rep(j,q){
            if(s[b[j]]-s[a[j]]==c[j]) tmp+=d[j];
        }
        chmax(ans,tmp);
        return;
    }
    rep(j,m) dfs(i+1,v+j);
    return;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    rep(i,1,m+1) dfs(0,i);
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a,b;
int main(){
	scanf("%lld%lld",&a,&b);
	if(b==1)puts("0");
	else printf("%lld",a-b);
}

Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

struct point{
    double x,y;
    point(double _x , double _y){
        x = _x , y = _y;
    }
};

bool insidePoly( point p,vector<point>P  ) {
	bool inside = false;
	int n = P.size();
	for( int i = 0, j = n - 1; i < n; j = i++ )
		if( (( P[i].x < p.x ) ^ ( P[j].x < p.x )) &&
        (P[i].y - P[j].y) * fabs(p.x - P[j].x) < (p.y - P[j].y) * abs(P[i].x - P[j].x) )
			inside = !inside;
	return inside;
}

int main()
{

     double x,y;
    while(cin>>x>>y)
    {
        vector<point>P;
        P.push_back(point(x,y));

        for( int i = 0 ; i < 2 ; i++ ){
                scanf("%lf %lf",&x,&y);
                P.push_back(point(x,y));
        }
        scanf("%lf %lf",&x,&y);

        bool f = insidePoly(point(x,y),P);

        if(f)puts("YES"); else puts("NO");

    }
}

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

#define min(x,y) ((x)>(y))?(y):(x)

int main() {
	int C, K, N, X, Y;
	scanf("%d%d%d%d", &N, &K, &X, &Y);
	C  = X * (min(K,N));
	if (N>K) C += Y * (N-K);
	printf("%d\n", C);
	return 0;
}


Measured memory_bytes: 128
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
        ll n, m;
        scanf("%ld %ld", &n, &m);
        V links[n];
        REP(i, 0, m){
                ll a, b;
                scanf("%ld %ld", &a, &b);
                links[a-1].push_back(b-1);
                links[b-1].push_back(a-1);
        }

        V ans(n, -1);
        bool used[n];
        memset(used, 0, n);
        std::queue<P> que;
        que.emplace(0, 0);
        while(!que.empty()){
                auto [from, dist] = que.front();
                que.pop();
                if(used[from]) continue;
                used[from] = true;
                for(ll to: links[from]){
                        if(used[to]) continue;
                        if(ans[to]<0) ans[to] = from+1;
                        que.emplace(to, dist+1);

                }
        }
        puts("Yes");
        REP(i, 1, n) printf("%ld\n", ans[i]);
        return 0;
}

Measured memory_bytes: 14148
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int r=(a>b?a:b)>c?(a>b?a:b):c;
    System.out.println(r*10+a+b+c-r);
  }
}

Measured memory_bytes: 23764
#include<stdio.h>
int main(void)
{
	int a = 0, b = 0, c = 0;
	scanf("%d%d", &a, &b);
	if (a>=10||b>=10)
	{
		printf("-1");
	}
	else
	{
		c = a * b;
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int i,n,d;
	int debt=100000;
	cin >> n;
	for(i=0; i<n; i++){
		debt = debt * 1.05;
		d = debt % 1000;
		if(d>0){
			debt = debt - d + 1000;
		}
	}
	cout << debt << endl;
}

Measured memory_bytes: 1160
n=int(input())
res = []
for i in range(n):
    s,p=map(str, input().split())
    res += [(s,int(p))]
res1=res
res = sorted(res, key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(res1.index(res[i])+1)

Measured memory_bytes: 9056
import java.util.*;

public class Main {
    long MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        // from min
        int minIdx = 1;
        int maxIdx = n - 1;
        int left = a[0];
        int right = a[0];
        long ans = 0;
        while (minIdx <= maxIdx) {
            int tmpLmin = Math.abs(left - a[minIdx]);
            int tmpRmin = Math.abs(right - a[minIdx]);
            int tmpLmax = Math.abs(left - a[maxIdx]);
            int tmpRmax = Math.abs(right - a[maxIdx]);

            if (tmpLmin >= tmpRmin && tmpLmin >= tmpLmax && tmpLmin >= tmpRmax) {
                ans += Math.abs(left - a[minIdx]);
                left = a[minIdx++];
            } else if (tmpRmin >= tmpLmin && tmpRmin >= tmpLmax && tmpRmin >= tmpRmax) {
                ans += Math.abs(right - a[minIdx]);
                right = a[minIdx++];
            } else if (tmpLmax >= tmpLmin && tmpLmax >= tmpRmin && tmpLmax >= tmpRmax) {
                ans += Math.abs(left - a[maxIdx]);
                left = a[maxIdx--];
            } else if (tmpRmax >= tmpLmin && tmpRmax >= tmpRmin && tmpRmax >= tmpLmax) {
                ans += Math.abs(right - a[maxIdx]);
                right = a[maxIdx--];
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 51712
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, z = 0;
    string s[102] = {}, t[102] = {};
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];
    cin >> m;
    for (int i = 0; i < m; i++) cin >> t[i];
    for (int i = 0; i < n; i++) {
        int c = 0;
        for (int j = 0; j < n; j++) if (s[i] == s[j]) c++;
        for (int j = 0; j < m; j++) if (s[i] == t[j]) c--;
        //cout << c << ' ';
        z = max(z, c);
    }
    cout << z;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  int n=S.size(),count=0,check=0;
  for(int i=2;i<n-1;i++)
    if(S.at(i)=='C')count++;
  for(int i=0;i<n;i++)
    if('A'<=S.at(i) && S.at(i)<='Z')check++;
  
  if(S.at(0)!='A')count=0;
  else if(check!=2)count=0;
  
  if(count==1)cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}

Measured memory_bytes: 256
function calc(input) {
  var array = input.split(' ');
  var A = parseInt(array[0]);
  var B = parseInt(array[1]);
  var C = parseInt(array[2]);

  if (A === B === C) {
    return 0;
  }

  var max = Math.max(A, B, C);
  var min = Math.min(A, B, C);

  if (A === B === max || B === C === max || C === A === max) {
    return Math.floor((max - min) / 2) + ((max - mod) % 2 === 0 ? 0 : 2);
  }

  if (A === B === min || B === C === min || C === A === min) {
    return max - min;
  }

  var mid;
  if (A === max) {
    mid = B === min ? C : B;
  } else if (B === max) {
    mid = A === min ? C : A;
  } else {
    mid = A === min ? B : A;
  }

  var diffFromMidToMax = max - mid;
  var diffFromMinToMid = mid - min;
  var isMod0 = diffFromMinToMid % 2 === 0;

  return diffFromMidToMax + Math.floor(diffFromMinToMid / 2) + (isMod0 ? 0 : 2);
}

function main(input) {
  console.log(calc(input));
}

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

Measured memory_bytes: 11468
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<cstdio>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
LL read(){
	LL f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return f*x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
#define Mod int(1e9+7)
int d[MAXN+5];
LL cal[MAXN+5];
vector<int> G[MAXN+5];
void DFS(int u,int fa){
	int cnt=0;
	for(int i=0;i<int(G[u].size());i++){
		int v=G[u][i];
		if(v==fa) continue;
		d[v]+=cnt+1;
		cnt++;
		for(int j=0;j<int(G[v].size());j++){
			int w=G[v][j];
			if(w==u) continue;
			d[w]++;
		}
		DFS(v,u);
	}
	return ;
}
int main(){
	int n=read(),k=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		d[u]++,d[v]++;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(d[i]>=k){
			printf("0\n");
			return 0;
		}
	memset(d,0,sizeof(d));
	DFS(1,0);
	LL ans=1;
	for(int i=1;i<=n;i++)
		ans=ans*(k-d[i])%Mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12032
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
using namespace std;

int c[100][100];
int f[100];
signed main() {
	int a, b; cin >> a >> b;
	for (int d = 0; d < a; d++) {
		for (int e = 0; e < b; e++) {
			cin >> c[d][e];
		}
	}
	for (int g = 0; g < b; g++)cin >> f[g];
	for (int i = 0; i < a; i++) {
		int sum = 0;
		for (int j = 0; j < b; j++) {
			sum += c[i][j] * f[j];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3136
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n, m;
	string str, sub;
	while (cin >> n >> m >> str) {
		string ioi;
		int ans = 0;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; ++i) {
			ioi += "IO";
		}
		ioi += "I";
		for (int i = 0; i < str.size(); ++i) {
			sub = str.substr(i, n * 2 + 1);
			if (sub == ioi) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3960
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	int odd, bai2, bai4;
	odd = bai2 = bai4 = 0;
	for (int i = 0; i < N; i++) {
		ll temp;
		cin >> temp;
		if (temp % 4 == 0) bai4++;
		else if (temp % 2 == 0) bai2++;
		else odd++;
	}
	if (odd == 0) cout << "Yes" << endl;
	else {
		if (bai2 == 0) {
			if (bai4 >= odd - 1) cout << "Yes" << endl;
			else cout << "No" << endl;
		} else {
			if (bai4 >= odd) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
	}
	return 0;
}


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

using namespace std;

int main(){
  int n;
  int alice=0,bob=0;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<a.size(); i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<a.size();i++){
    i%2==0 ? alice+=a.at(i) : bob+=a.at(i);
  }
  cout << alice-bob << endl;
  return 0;
}


Measured memory_bytes: 256
N = tuple(input())
N = tuple(map(int, N))

ans = 0
flag = False
flag5 = False
i = len(N)-1


for x in reversed(N):
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:

        ans += x
    if x == 5:
        flag5 = True
    i -= 1

print(ans)

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

int par[200200];
int get_par(int now){
	return par[now] = (par[now] == now ? now : get_par(par[now]));
}
void unite(int a, int b){
	if(get_par(a) != get_par(b)) par[get_par(a)] = get_par(b);
}
int sz[200200];

int main(){
	int n, m;
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i, n) par[i] = i;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		unite(a, b);
	}
	rep(i, n) sz[get_par(i)]++;
	int ans = 0;
	rep(i, n) ans = max(ans, sz[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10648
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		int max = Integer.MIN_VALUE, maxId = 0, min = Integer.MAX_VALUE, minId = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] < min) {
				min = arr[i];
				minId = i;
			}
			if (arr[i] > max) {
				max = arr[i];
				maxId = i;
			}
		}
		boolean f = false, m = false;
		if (minId == 0 && maxId == n - 1) {
			for (int i = 0; i < n - 1; i++) {
				for (int j = 1; j < n; j++) {
					m = false;
					if (arr[i] > arr[j]) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
						m = true;
					}
					// check
					f = check(arr);
					if (f)
						break;
					if (m) {
						int t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
				if (f)
					break;
			}
		} else if (min != 0 && maxId == n - 1) {
			int t = arr[minId];
			arr[minId] = arr[0];
			arr[0] = t;
			f = check(arr);
		} else if (minId == 0 && maxId != n - 1) {
			int t = arr[maxId];
			arr[maxId] = arr[n - 1];
			arr[n - 1] = t;
			f = check(arr);
		} else {
			int t = arr[maxId];
			arr[maxId] = arr[minId];
			arr[minId] = t;
			f = check(arr);
		}

		if (f)
			System.out.println("YES");
		else
			System.out.println("NO");
		in.close();
	}

	public static boolean check(int arr[]) {
		int n = arr.length;
		int order[] = new int[n];
		for (int i = 0; i < n; i++)
			order[i] = arr[i];
		Arrays.sort(order);
		for (int i = 0; i < n; i++) {
			if (arr[i] != order[i])
				return false;
		}
		return true;
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll h,w,k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for(ll i=0;i<h;i++) {
    cin >> s[i];
  }
  mat white(h+1,vec(w+1));
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      white[i+1][j+1]=(ll)(s[i][j]-'0');
    }
  }
  for(ll i=1;i<=h;i++) {
    for(ll j=0;j<w;j++) {
      white[i][j+1]+=white[i][j];
    }
  }
  for(ll i=1;i<=w;i++) {
    for(ll j=0;j<h;j++) {
      white[j+1][i]+=white[j][i];
    }
  }
  ll ans=inf;
  for(ll i=0;i<(1<<(h-1));i++) {
    bitset<12> bit(i);
    ll count=bit.count();
    bool flag=true;
    set<ll> ver;
    for(ll i=0;i<h-1;i++) {
      if(bit.test(i)) {
        ver.insert(i);
      }
    }
    ver.insert(h-1);
    ll xlast=0;
    for(ll x=0;x<w;x++) {
      ll ylast=0;
      for(ll y:ver) {
        ll block=white[y+1][x+1]-white[ylast][x+1]-white[y+1][xlast]+white[ylast][xlast];
        if(block>k) {
          if(xlast==x) {
            flag=false;
            break;
          }
          xlast=x;
          count++;
        }
        if(!flag) break;
        ylast=y+1;
      }
    }
    if(flag) {
      ans=min(ans,count);
    }
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;           \
    cin >> name;
#define VL(name, num) \
    vl name(num);           \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

int main() { cin.sync_with_stdio(0);
    LL(N);
    VL(A, N);

    vl help(N);
    ll ans = 0;
    FOR(i, 0, N) {
        ll idx = A[i] + i - 1;
        if (idx < N){
            help[idx]++;
        }

        idx = i - A[i] - 1;
        if (idx >= 0) {
            ans += help[idx];
        }
    }
    cout << ans << endl;
}  // cin.tie(0) bei schnellem Wechseln


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

using namespace std;

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < 11; i++)
    {
        if((1000*i-N)>=0){
            cout << 1000 * i - N << endl;
            break;
        }
    }

}

Measured memory_bytes: 3620
n = int(input())
h = list(map(int,input().split()))

dp = [float("inf")]*(n)
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,n):
  temp_1 = abs(h[i] - h[i-1]) + dp[i-1]
  temp_2 = abs(h[i] - h[i-2]) + dp[i-2]
  if temp_1 < temp_2:
    dp[i] = temp_1
  elif temp_2 <= temp_1:
    dp[i] = temp_2
  
print(dp[n-1])

Measured memory_bytes: 13980
#include<iostream>

using namespace std;

int main(void)
{
	
	int K, A, B;
	cin >> K >> A >> B;
	cout << (!(A%K)||
		(K * (A/K + 1) <= B)?
		"OK":"NG"
		) << std::endl;
	
	return 0;
	
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


   
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans;
    if(a<=c){
      if(b<=c)ans=0;
      else if(b<=d)ans=b-c;
      else if(b>d)ans=d-c;
    }
    else if(a>c){
      if(d<=a)ans=0;
      else if(d<=b)ans=d-a;
      else if(d>b)ans=b-a;
    }
    cout << ans << endl;
  }


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

using namespace std;

const int N = 1e6;
int a[N], f[N];
int main()
{
	cin.sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];	
	int tmp = 0;
	for (int i = 1; i <= n; ++i) if (a[i] == i) f[i] = 1;
	for (int i = 1; i <= n; ++i)
	{
		if (f[i])
		{
			tmp++;
			if (f[i + 1]) ++i;
		}
	}
	cout << tmp << endl;
}


Measured memory_bytes: 4736
// Problem : B - Distance 
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
#define 	ll		    long long
#define 	rep(i,a,n)  for(int i=a;i<n;i++)
#define 	MOD 		1000000007
#define 	vp 			vector<pair<int,int> >
#define 	ff 			first
#define 	ss 			second
#define 	pb 			push_back
#define 	all(x) 		(x.begin(),x.end())
#define 	dg(x)		cerr<<"--- x = "<<x<<"\n"
#define 	endl		"\n"


using namespace std;
const int N = 1e5;
ll ar[N];

void solve(){
	double d,x,y; 
	int n;
	cin >> n >> d;
	int ans = 0;
	rep(i , 1, n+1){
		cin >> x >> y;
		if(sqrt(x  * x + y * y) <= d)
			ans++;	
	}
	cout << ans;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 3820
n,x,a[123];main(i){while(scanf("%d ",&n),n){for(i=0;i<123;++i)a[i]=i;for(;n--;a[x]=*a)scanf("%c %c ",&x,a);for(scanf("%d ",&n);n--;putchar(a[x]))scanf("%c ",&x);puts("");}}

Measured memory_bytes: 388
using System;

namespace AOJ.Volume0
{
    public class MaximumSumSequence
    {
        public static void Main()
        {
            while (true)
            {
                int length = int.Parse(Console.ReadLine());
                if (length == 0) { break; }

                int[] dp = new int[length + 1];
                dp[0] = 0;
                for (int i = 1; i <= length; i++) { dp[i] = dp[i - 1] + int.Parse(Console.ReadLine()); }

                int ans = int.MinValue;
                for (int i = length; i > 0; i--)
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        ans = Math.Max(ans, dp[i] - dp[j]);
                    }
                }
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 5716
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
int main(){
  int n;
  cin>>n;
  int ans=1;
  while(1){
    if(ans*2<=n){
      ans *= 2;
    }else{
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {

  long long N, M;
  cin >> N >> M;

  long long a;
  long long sum = 0;

  for(int i = 0; i < M; i++){
    cin >> a;
    sum += a;
  }
  if(sum <= N){
    cout << N - sum << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3636
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var H = input[1].split(" ").map(i => parseInt(i));
  var H1=0;
  var ans="Yes";
  var max=0;
  for(var i=1;i<N;i++){
    if(H[i-1]-H[i]>=2){
      ans="No";
      break;
    }else if(H[i-1]-H[i]==1){
      if(H[i-1]-1>=max){
        max=H[i-1]-1;
      }else{
        ans="No";
        break;
      }
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22212
n=int(input())
s=input()
t=input()
ans=1
if s[0]==t[0]:ans=3;i,b=1,1
else:ans=6;i,b=2,0
while i<n:
    if s[i]==t[i]:
        ans*=b+1
        i+=1
        b=1
    else:
        ans*=3-b
        i+=2
        b=0
print(ans%(10**9+7))

Measured memory_bytes: 3064
N = int(input())
W = list(map(int, input().split()))

MIN = 0
for t in range(N-1):
    S1 = 0
    S2 = 0
    norm = 0

    LW = W[0:t+1]
    RW = W[t+1:]

    for j in range(len(LW)):
        S1 += LW[j]
    for k in range(len(RW)):
        S2 += RW[k]

    if S1 > S2:
        norm = S1-S2
    else:
        norm = S2-S1

    # print("norm:{}".format(norm))
    if t == 0:
        MIN = norm

    elif MIN > norm:
        MIN = norm

    # for j in range(t+1):
    #     S1 += W[j]
    #
    # for k in range(N-(t+1)):

print(MIN)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = 0;
    while(N > 1) {
        N /= 2;
        ans++;
    }
    int t = 1;
    while(ans--) t *= 2;
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <deque>
#include <assert.h>
using namespace std;

#define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++)
#define rep(i, a) ran ((i), 0, (a))
#define rep1(i, a) ran ((i), 1, (a)+1)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define _0 first
#define _1 second
#define _pb(x) push_back(x)
#define _mp(x, y) make_pair(x, y)
#if defined(SHIROKO1_LOCAL) && !defined(NDEBUG)
#define DEBUG(...) fprintf(stderr, "[DEBUG] " __VA_ARGS__)
#else
#define DEBUG(...) ((void)0)
#endif

int main()
{
	deque<int> a;
	int n;
	cin >> n;
	int rev = 0;
	while (n--) {
		int x;
		cin >> x;
		if (rev)
			a.push_front(x);
		else
			a.push_back(x);
		rev ^= 1;
	}
	if (rev) {
		for (auto it = a.rbegin(); it != a.rend(); it++)
			printf("%i ", *it);
	} else {
		for (auto it = a.begin(); it != a.end(); it++)
			printf("%i ", *it);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
std::vector<long long int> v;
int main() {
     long long int n;
	cin >> n;
	long long int x;
	cin >> x;
	v.emplace_back(x);
	for(long long int i=0;i<n;i+=1){
	    // long long int x;
	     cin >> x;
	     v.emplace_back(x);
	}
	{
     	sort(v.begin(),v.end());
     	auto x = v[0];
     	long long int g = 0;
          for(long long int i=0;i<=n;i++){
               // cout << g << endl;
               g = __gcd(v[i]-x,g);
          }
     	cout << g;
	}
	return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	long double w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << (w * h) / 2 << ' ' << (x == w / 2 && y == h / 2) ? 1 : 0 << '\n';
	return 0;
}

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

class ABC
{
    public static void Main()
    {
        string str = Console.ReadLine();

        string[] arr = str.Split(' ');
        List<int> num = new List<int>();
        foreach (string item in arr)
        {
            num.Add(int.Parse(item));
        }
        if((num[0] + num[1]) % 2 == 0)
        {
            Console.WriteLine((num[0] + num[1]) / 2);
        }
        else
        {
            Console.WriteLine("IMPOSSIBLE");
        }
    }
}

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

#define int long long

using namespace std;

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

    priority_queue<int> q;
    for (int i = 0; i < 2 * N; i++) {
	int L;
	cin >> L;
	q.push(L);
    }

    int ret = 0;
    for (int i = 0; i < N; i++) {
	q.pop();
	ret += q.top();
	q.pop();
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; cin >> N; 
	int D[100010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> D[i]; 
	}
	sort(D, D+N); 
	cout << D[N/2] - D[N/2-1] << endl; 
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++)
    cin >> L[i];
  int max = 0;
  int sum = 0;
  for (int i = 0; i < N; i++)
  {
    if (max < L[i])
      max = L[i];
    sum += L[i];
  }
  sum -= max;
  if (sum <= max)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double PI=3.14159265358979323846;

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

int lcm(int a,int b){
  return a * b / gcd(a,b);
}

int main(){
  int n; cin >> n;
  string s;
  map<string,int> mp;
  for(int i = 0; i < n; i++){
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for(auto p: mp){
    int i = p.second;
    ans += (ll)i*(i-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,s,sum=0;
	cin >> n;
	set <int> notas;
	
	for (int i=0;i<n;i++){
		cin >> s;
		notas.insert(s);
		sum += s;
	}
	
	if (sum %10 == 0){
		int menor=101;
		for (auto &it:notas){
			if (it <= menor && it % 10 != 0) menor = it;
		}
		if (menor == 101) cout << 0;
		else cout << sum-menor;
		return 0;
	}
	
	cout << sum;
	
	return 0;
}

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

int main(void){
  int a,b,x;
  double deg;

  scanf("%d %d %d",&a,&b,&x);
  if (x<=(a*a*b/2.0))
    deg = atan((double)(a*b*b)/(x*2));
  else{
    deg = atan((2.0*(a*a*b-x))/(a*a*a));
  }
  deg = (180.0/M_PI)*deg;

  printf("%.10lf\n",deg);
  return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func Foo(a, b int) int {
	x := a * b
	if a < b {
		tmp := a
		a = b
		b = tmp
	}
	r := a % b
	for r != 0 {
		a = b
		b = r
		r = a % b
	}
	return x / b
}

func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)

	cd := Foo(c, d)

	cleft := a
	dleft := a
	cdleft := a

	ans := b - a + 1

	if cleft%c != 0 {
		cleft = int(a/c)*c + c
	}
	if dleft%d != 0 {
		dleft = int(a/d)*d + d
	} else {
	}
	if cdleft%cd != 0 {
		cdleft = int(a/cd)*cd + cd
	}

	var ccnt, dcnt, cdcnt int

	if cleft <= b {
		ccnt = ((b - cleft) / c) + 1
	}
	if dleft <= b {
		dcnt = ((b - dleft) / d) + 1
	}
	if cdleft <= b {
		cdcnt = ((b - cdleft) / cd) + 1
	}

	ans = ans - (ccnt + dcnt - cdcnt)

	fmt.Println(ans)
}


Measured memory_bytes: 1832
import sys
 
N=int(input())
S=[int(input()) for _ in range(N)]
S.sort()
 
ans=sum(S)
 
if ans%10!=0:
  print(ans)
  sys.exit()
else:
  for i in range(N):
    if S[i]%10!=0:
      print(ans-S[i])
      sys.exit()
  else:
    print(0)

Measured memory_bytes: 8992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 A[202020], B[202020];

i64 &at(int i)
{
	if (i == -1) return B[N - 1];
	else if (i == N) return B[0];
	return B[i];
}

bool ext(int i)
{
	return at(i - 1) < at(i) && at(i) > at(i + 1);
}

void fail()
{
	puts("-1");
	exit(0);
}

bool qd[202020];
queue<int> Q;

void app_test(int i)
{
	if (i < 0) i += N;
	if (i >= N) i -= N;

	if (ext(i) && B[i] > A[i]) {
		if (!qd[i]) {
			qd[i] = true;
			Q.push(i);
		}
	} else if (B[i] < A[i]) {
		fail();
	}
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lld", A + i);
	for (int i = 0; i < N; ++i) scanf("%lld", B + i);

	i64 ret = 0;
	for (int i = 0; i < N; ++i) app_test(i);

	while (!Q.empty()) {
		int p = Q.front(); Q.pop();
		qd[p] = false;

		i64 cnt = (B[p] - A[p]) / (at(p - 1) + at(p + 1));
		if (cnt == 0) {
			if (B[p] != A[p]) {
				fail();
			} else break;
		}
		ret += cnt;
		//printf("%d %lld\n", p, (at(p - 1) + at(p + 1)) * cnt);
		B[p] -= (at(p - 1) + at(p + 1)) * cnt;
		app_test(p - 1);
		app_test(p);
		app_test(p + 1);

		//for (int i = 0; i < N; ++i) printf("%lld ", B[i]); puts("");
	}

	for (int i = 0; i < N; ++i) if (A[i] != B[i]) fail();
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	string line;
	cin>>line;
	int cnt[100];
	for(int i=0;i<100;i++) cnt[i]=0;
	for(int i=0;i<line.size();i++){
		cnt[line[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		if(cnt[i]%2) {
          cout<<"No"<<endl;
		return 0;
        }
	}
	cout<<"Yes"<<endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define tr(a, x) for (auto &a : x)
#define all(c) c.begin(), c.end()

#define lld long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(a) int((a).size())
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())

#define vi vector<lld>
#define si set<lld>
#define endl "\n"
#define int long long
#define pii pair<int, int>
#define minq priority_queue<int, vector<int>, greater<int>>
#define mem(a, val) memset(a, val, sizeof(a))
#define scani(x) scanf("%lld", &x)
#define scani2(x, y) scanf("%lld %lld", &x, &y)
#define scani3(x, y, z) scanf("%lld %lld %lld", &x, &y, &z);
#define print(x) printf("%lld ", x)
#define println(x) printf("%lld\n", x)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define MOD 1000000009

using namespace std;

const int N = 3e5 + 11;
int dp[N], n, height[N];
int jump(int i)
{
     if (dp[i] != -1)
          return dp[i];
     
     dp[i] = min((abs(height[i]-height[i+1])+jump(i+1)),abs(height[i]-height[i+2])+jump(i+2));
     return dp[i];
}

int32_t main()
{
     // #ifndef ONLINE_JUDGE
     //      freopen("input.txt", "r", stdin);
     //      freopen("output.txt", "w", stdout);
     // #endif

     SpeedForce;
     int n;
     cin >> n;
     
     rep(i,n){
          cin >> height[i];
     }

     rep(i,n){
          dp[i] = -1;
     }

     dp[n] = dp[n-1] = 0;
     dp[n-2] = abs(height[n-1]-height[n-2]);
     cout << jump(0) << endl;
}

Measured memory_bytes: 7516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int, ll, int> edges;

int main()
{
    int N, M;
    cin >> N >> M;
    set<edges> edgeSet;
    for(int i = 0 ; i < M; i ++){
        int L, R;
        ll C;
        cin >> L >> R >> C;
        edgeSet.insert(edges(L, C, R));
    }
    auto ite = edgeSet.begin();
    ll INF = LLONG_MAX;
    vector<ll> dp(N + 1, INF);
    dp.at(1) = 0;
    while (ite != edgeSet.end()) {  
        edges edge = *ite;
        int left =  get<0>(edge);
        ll cost =  get<1>(edge);
        int right = get<2>(edge);
        if(dp.at(left) == INF){
            ite++;
            continue;
        }
        ll currentDistance = cost + dp.at(left);
        for(int i = right; i >= left; i--){
            if(dp.at(i) <= currentDistance){
                break;
            }
            dp.at(i) = currentDistance;
        }
        ite++;
    }
    if(dp.at(N) == INF){
        cout << -1 << endl;
    }else{
        cout << dp.at(N) << endl;
    }
    return 0;
}

Measured memory_bytes: 7168
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

int main()
{
	ll n; lscn(n);

	int ans=0;

	for(ll fac=2;fac*fac<=n;fac++)
	if(n%fac==0)
	{
		int cnt=0;

		while(n%fac==0)
		cnt++,n/=fac;

		int here=0,cur=1;

		//cout<<cnt<<endl;

		while(here+cur<=cnt)
		ans++,here=here+cur,cur++;
	}

	if(n>1)
	ans++;

	pri(ans);

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=in.nextInt(),m=in.nextInt(),l=in.nextInt();
		long A[][]=new long[n][m],B[][]=new long[m][l],C[][]=new long[n][l];
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				A[i][j]=Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<m;i++) {
			for(int j=0;j<l;j++) {
				B[i][j]=Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<l;j++) {
				for(int k=0;k<m;k++) {
					C[i][j]+=A[i][k]*B[k][j];
				}
			}
		}
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<l-1;j++) {
				out.print(C[i][j]+" ");
			}
			out.println(C[i][l-1]);
		}
		out.flush();
	}

}



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

int main(){
	int H,W;
	cin >> H >> W;
	vector<vector<int>> c(10,vector<int>(10,0));
	rep(i,10)rep(j,10)cin >> c[i][j];

	vector<vector<int>> A(H,vector<int>(W,-1));
	rep(i,H)rep(j,W) cin >> A[i][j];

	vector<int> ME(10,-1); 

	for(int k=0; k<10; k++){
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++) c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
		}
	}
	rep(i,10) ME[i] = c[i][1];

	int ans = 0;
	rep(i,H){
		rep(j,W){
			int num = A[i][j];
			if(num==-1)continue;
			ans += ME[num];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>

using namespace std;

const int MAXN = 100500;
vector<int> g[MAXN];
int n, m, k;
int ans = 0;
int ans_1 = 0;
int dist[MAXN];
int used[MAXN];

typedef pair <int, int> pii;
#define mp make_pair


void bfs(int init) {
	dist[init] = 0;
	used[init] = 1;
	queue<int> q;
	q.push(init);
	while(!q.empty()) {
		int cur = q.front();
		q.pop();
		for (int i = 0; i < g[cur].size(); ++i) {
			int to = g[cur][i];
			if (!used[to]) {
				used[to] = 1;
				q.push(to);
				dist[to] = dist[cur] + 1;
			}
		}
	}
}

void bfs_exclude(int init) {
	queue<int> q;
	q.push(init);
	used[init] = 1;
	while(!q.empty()) {
		int cur = q.front();
		q.pop();
		for (int i = 0; i < g[cur].size(); ++i) {
			int to = g[cur][i];
			if (!used[to] && dist[to] > dist[cur]) {
				used[to] = 1;
				q.push(to);
			}
		}
	}
}


int go_up(int v, int t) {
	if (t == 0) {
		return v;
	}
	for (int i = 0; i < g[v].size(); ++i) {
		if (dist[g[v][i]] == dist[v] - 1) {
			return go_up(g[v][i], t-1);
		}
	}
}

void calc_ans() {
	priority_queue<pii> q;
	for (int i = 2; i <= n; ++i) {
		q.push(mp(dist[i], i));
	}
	for (int i = 1; i <= n; ++i) {
		used[i] = 0;
	}
	while (!q.empty()) {
		int v = q.top().second;
		int cur_dist = q.top().first;
		q.pop();
		if (used[v] == 1) {
			continue;
		}
		if (cur_dist <= k)
			return;
		int u = go_up(v, k - 1);
		++ans;
		bfs_exclude(u);
	}
}



int main(){
	cin >> n >> k;
	m = n - 1;
	int tmp;
	cin >> tmp;
	if (tmp != 1)
		++ans;
	for (int i = 2; i <= n; ++i) {
		scanf("%d", &tmp);
		g[i].push_back(tmp);
		g[tmp].push_back(i);
	}
	bfs(1);
	calc_ans();
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 8324