akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T> T GCD(T a, T b)
{
    if(b == 0) return a;
    return GCD(b, a % b);
}
template<typename T> T LCM(T a, T b)
{
    T g = GCD(a, b);
    return a / g * b;
}
signed main(void)
{
    ll a, b; cin >> a >> b;
    cout << LCM(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split(' ').map(function(value) {
  if (!isNaN(parseInt(value))) {
    return parseInt(value);
  } else {
    return value;
  }
});

function push(value, container) {
  container.push(value);
  return container;
}

function add(container) {
  var a = container.pop();
  var b = container.pop();
  container.push(a + b);
  return container;
}

function sub(container) {
  var b = container.pop();
  var a = container.pop();
  container.push(a - b);
  return container;
}

function mul(container) {
  var a = container.pop();
  var b = container.pop();
  container.push(a * b);
  return container;
}

function calc(operation, container) {
  switch (operation) {
    case '+':
      container = add(container);
      break;
    case '-':
      container = sub(container);
      break;
    case '*':
      container = mul(container);
  }
  return container;
}

var container = [];

input.forEach(function (value) {
  if (typeof value === 'number') {
    push(value, container);
  } else {
    calc(value, container);
  }
});

console.log(container[0]);

Measured memory_bytes: 15860
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string s;
   cin >> s;
   cout << (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ? "Bad" : "Good") << endl;
   return 0;
}


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

int main(void) {

	int  N,A[100];
	int i;

	scanf("%d",&N);

	for(i=0;i<N-1;i++) scanf("%d ",&A[i]);
	scanf("%d",&A[i]);

	for(i=0;i<N;i++){
		if(A[i]%2) continue;   //奇数
		if(A[i]%3 && A[i]%5)
  	      {printf("DENIED");return 0;}
	}
	printf("APPROVED");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
using namespace std;
int main() {
	int a;
	cin >> a;
	if (a == 3 || a == 5 || a == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,m,h,k;
  while(cin>>n>>m>>h>>k,n){
    struct edge{
      int to,cost,time;
      edge(int to,int cost,int time):
        to(to),cost(cost),time(time){}
    };
    vector< vector< vector< edge > > > G(k,vector< vector<edge> >(n));
    for(int i=0;i<m;i++){
      int a,b,c,h,r;
      cin>>a>>b>>c>>h>>r;
      a--;b--;r--;
      G[r][a].emplace_back(b,c,h);
      G[r][b].emplace_back(a,c,h);
    }

    int s,t;
    cin>>s>>t;
    s--;t--;

    int ps=1<<k;
    const int INF = 1e9;
    vector<int> dp(ps,INF);
    dp[0]=0;

    int p;
    cin>>p;
    for(int i=0;i<p;i++){
      int l,d;
      cin>>l>>d;
      int bit=0,v=0;
      for(int j=0;j<l;j++){
        cin>>v;
        v--;
        bit|=1<<v;
      }
      chmin(dp[bit],d);
    }

    for(int i=0;i<ps;i++)
      for(int j=0;j<ps;j++)
        chmin(dp[i|j],dp[i]+dp[j]);

    int ans=INF;
    for(int bit=0;bit<ps;bit++){
      using T = tuple<int, int, int>;
      priority_queue<T, vector<T>, greater<T> > pq;
      vector< vector<int> > dist(n,vector<int>(h+1,INF));
      dist[s][0]=0;
      pq.emplace(dist[s][0],s,0);

      while(!pq.empty()){
        int d,v,ch;
        tie(d,v,ch)=pq.top();pq.pop();
        if(dist[v][ch]<d) continue;
        for(int i=0;i<k;i++){
          for(auto e:G[i][v]){
            int u=e.to;
            int nd=d+(((bit>>i)&1)?0:e.cost);
            int nh=ch+e.time;
            if(nh>h) continue;
            if(dist[u][nh]<=nd) continue;
            dist[u][nh]=nd;
            pq.emplace(dist[u][nh],u,nh);
          }
        }
      }
      for(int res:dist[t]) chmin(ans,res+dp[bit]);
    }
    if(ans==INF) ans=-1;
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        String len = in.nextLine();
        String n = in.nextLine();
        String[] numbers = n.split(" ");
        int[] nums = new int[Integer.parseInt(len)];
        
        for (int s = 0; s < numbers.length; s++) {
        	nums[s] = Integer.parseInt(numbers[s]);
        }
        
        for (int c = 0; c < nums.length; c++) {
    		System.out.print(nums[c]);
    		if (c < nums.length - 1) {
    			System.out.print(" ");
    		} else {
    			System.out.println();
    		}
    	}
        
        int j = 0;
        for (int i = 1; i < nums.length; i++) {
        	int key = nums[i];
        	j = i - 1;
        	
        	while (j >= 0 && nums[j] > key){
        		nums[j+1] = nums[j];
        		j--;
        	}
        	nums[j+1] = key;
            
        	for (int b = 0; b < nums.length; b++) {
        		System.out.print(nums[b]);
        		if (b < nums.length - 1) {
        			System.out.print(" ");
        		} else {
        			System.out.println();
        		}
        	}
        }
	}
}


Measured memory_bytes: 34012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        int minv = Integer.MAX_VALUE;
        int maxv = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            int j = Integer.parseInt(reader.readLine());
            maxv = Math.max(maxv, j-minv);
            minv = Math.min(minv, j);
        }
        System.out.println(maxv);
    }
}


Measured memory_bytes: 42892
/*..........................*\
|         T.R.FORKAN           |
 \*..........................*/


 /**************************************************************************************\
 |                                                                                      |
 |           _______   ______    _______   _    _       ____   ___      _               |
 |          |  _____| / ____ \  |  ___  | | |  / /     / _  | |   \    | |              |
 |          | |      | |    | | | |   | | | | / /     / / | | | |\ \   | |              |
 |          | |____  | |    | | | |___| | | |/ /     / /  | | | | \ \  | |              |
 |          |  ____| | |    | | |  __  _| |   |     / /___| | | |  \ \ | |              |
 |          | |      | |____| | | |  \ \  | |\ \   / _____  | | |   \ \| |              |
 |          |_|       \______/  |_|   \_\ |_| \_\ /_/     |_| |_|    \___|              |
 |                                                                                      |
 |                                                                                      |
 \**************************************************************************************/


#include<bits/stdc++.h>
using namespace std;

#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi    2*acos(0)
#define    eif    else if
#define    ll    long long
#define    llu    unsigned long long
#define    pb    push_back
#define    popb    pop_back
#define    pf    push_front
#define    popf    pop_front
#define    r0    return 0
#define    all(x)    x.begin(),x.end()
#define    memset(x,y)    memset(x,y,(sizeof(x)/sizeof(*x)))
#define    max_e    max_element
#define    min_e    min_element
#define    lowb    lower_bound
#define    upb    upper_bound
#define    F    first
#define    S    second
#define    bs    binary_search
#define    speed    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define    siz    INT_MAX
#define    read    freopen("cin.txt","r",stdin);
#define    write    freopen("cout.txt","w",stdout);
#define    prnt(x)    printf("%d",x)
#define    nl    printf("\n");
#define    siz    1000007


int Int(){int x;scanf("%d",&x);return x;}
ll int LL(){ll int x;scanf("%lld",&x);return x;}
llu int LLU(){llu int x;scanf("%llu",&x);return x;}
double din(){double x;scanf("%lf",&x);;return x;}



#define Int Int()
#define din din()
#define LL LL()
#define LLU LLU()
//#define siv siv()
//int ara[26];
//distance(ara,max_e(ara+1,ara+b)
int main()
{
    //read
    //write
    //speed
    int a=Int;
    int cnt=0,e=0;
    while(a--){
        int x=Int;
        if(x%2==0){
            e++;
            if(x%3==0 || x%5==0)cnt++;
        }
    }
    if(cnt==e)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    r0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n;
	cin >> n;
	ll a[n+1];
	a[0]=2;
	a[1]=1;
	if(n<=1){
		cout << a[n] << endl;
	}else{
		for(int i=2;i<n+1;i++){
			a[i]=a[i-2]+a[i-1];
		}
		cout << a[n] << endl;
	}

/////////////////////////////////////////////
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;


double f(double a,double p,double q,double x){
return a*(x-p)*(x-p)+q;
}

double f(double a, double p, double x){
return sqrt(1.0 + 4.0*a*a*x*x - 8.0*a*a*p*x + 4.0*a*a*p*p);
}
double s(double a, double p, double x1, double x2){
double N = 1000.0;
double h, p1=0.0, p2=0.0;
h = (x2 - x1)/ N;
 for(int n = 1; n <= N/2-1; n++){
   p1 += f(a, p, x1+2.0*n*h);
 }
 for(int n = 1; n <= N/2; n++){
   p2 += f(a, p, x1+2.0*n*h-h);
 }
 p = f(a, p, x1) + 2.0*p1 + 4.0*p2 + f(a, p, x2);
 return p*h/3.0;
}
 
int main(){
  int W,H,n; cin >> W >> H >> n;
  double a[50],p[50],q[50];
  for(int i=0; i<n; i++) cin >> a[i] >> p[i] >> q[i];
 
  vector<double> X; //動的配列クラス
  X.push_back(0);//末尾に0を挿入
  X.push_back(W);//末尾にWを挿入
  for(int i=0; i<n; i++){
    // 山 i と窓枠の下辺との交点
    if(0<=p[i]-sqrt(-(q[i]/a[i])) && p[i]-sqrt(-(q[i]/a[i]))<=W) X.push_back(p[i]-sqrt(-(q[i]/a[i]))); //枠内ならx1を末尾に挿入
    if(0<=p[i]+sqrt(-(q[i]/a[i])) && p[i]+sqrt(-(q[i]/a[i]))<=W) X.push_back(p[i]+sqrt(-(q[i]/a[i]))); //枠内ならx2を末尾に挿入
 
    for(int j=0; j<i; j++){ // 山 i と山 j の交点
      double A=a[i]-a[j];
      double B=-2*a[i]*p[i]+2*a[j]*p[j];
      double C=a[i]*p[i]*p[i]+q[i]-a[j]*p[j]*p[j]-q[j];
 
      if(A!=0){ // Ax^2+Bx+C=0
        if(B*B-4*A*C>=0){
          double x;
          x=(-B-sqrt(B*B-4*A*C))/(2*A);
          if(0<=x && x<=W) X.push_back(x);//枠内なら交点を末尾に挿入
          x=(-B+sqrt(B*B-4*A*C))/(2*A);
          if(0<=x && x<=W) X.push_back(x);//枠内なら交点を末尾に挿入
        }
      }
      else if(B!=0){ // Bx+C=0
        double x=-1.0*C/B;
        if(0<=x && x<=W) X.push_back(x);//枠内なら交点を末尾に挿入
      }
    }
  }
 
  sort(X.begin(),X.end()); //昇順でソートする
 
  double ans=0;
  for(int i=0; i<(int)X.size()-1; i++){
    double x1=X[i],x2=X[i+1];
 
    int jmax=-1;
    for(int j=0; j<n; j++){
      if(f(a[j],p[j],q[j],(x1+x2)/2)>0//ｙ＝０より上
      && (jmax==-1 || f(a[jmax],p[jmax],q[jmax],(x1+x2)/2)<f(a[j],p[j],q[j],(x1+x2)/2))){//それまでで一番高い位置にある関数＜ｊ個目の関数のとき交換
        jmax=j;
      }
    }
 
    if(jmax != -1)ans+=s(a[jmax], p[jmax], x1, x2);
    
  }
 
  cout << fixed;
  cout << setprecision(9) << ans << endl;
 
  return 0;
}


Measured memory_bytes: 3304
s1 = input().split()

N = int(s1[0])
K = int(s1[1])

s2 = input().split()

A = []
for i in range(N):
  A.append(int(s2[i]))
  
for i in range(K, N):
  if A[i] > A[i-K]:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 31572
#include<iostream>
using namespace std;
int i, n, pA, pB, tA = 0, tB = 0;
int main(){
while(cin >> n) {
if(n == 0) { break; }
for (i=1; i<=n; i++) {
cin >> pA >> pB;
if (pA > pB) {
tA += pA + pB;
} else {
if (pA < pB) {
tB += pA + pB;
} else {
tA += pA;
tB += pB;
}
}
}
cout << tA << " " << tB << endl;
tA = 0; tB = 0;
}
return 0;
}

Measured memory_bytes: 3012
# Problem https://atcoder.jp/contests/abc068/tasks/abc068_b
# python 3rd Try


import sys


def twoDividedCounter(N):
    answer = 0
    copyNumber = N
    while True:
        if copyNumber % 2 == 0:
            answer = answer + 1
            copyNumber = copyNumber / 2
        else:
            break
    return answer


def solver(N):
    answer = 1
    counter = 0
    for j in range(1, N+1):
        jcount = twoDividedCounter(j)
        if counter < jcount:
            answer = j
            counter = jcount

    return answer


if __name__ == "__main__":
    N = sys.stdin.readline().rsplit()
    print(solver(int(N[0])))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <complex>
#include <iomanip>

using namespace std;

typedef complex<double> Point;

inline double cross(const Point& a, const Point& b){
    return imag(conj(a) * b);
}

typedef vector<Point> Polygon;

Point next(const Polygon& g, int x){
    return g[(x+1) % (int)g.size()];
}

double area(const Polygon& g){
    double res = 0.0;
    for(int i=0; i<(int)g.size(); ++i)res += cross(g[i], next(g, i));
    return abs(res) * 0.5;
}

int main(){
    int n;
    cin >> n;
    Polygon g;
    while(n--){
        int x, y;
        cin >> x >> y;
        g.emplace_back(x, y);
    }
    cout << fixed << setprecision(1) << area(g) << '\n';
    return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h> //inf=0x3f3f3f3f;//printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
const int N=1e5+20;
int h[N],n,anss;
int inf=0x3f3f3f3f;

int solve(int pos,int dis[]){
if(pos==n-1)return 0;
else if(dis[pos]!=-1)return dis[pos];
else{
    int ans=INT_MAX;
    if(pos+1<n)ans=min(ans,abs(h[pos+1]-h[pos])+solve(pos+1,dis));
    if(pos+2<n)ans=min(ans,abs(h[pos+2]-h[pos])+solve(pos+2,dis));
    return dis[pos]=ans;
}
}


int main()
{
    ROCK;
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    int dis[n];
    memset(dis,-1,sizeof dis);
    cout<<solve(0,dis);
    return 0;
}



Measured memory_bytes: 5760
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

S = str(input())

N = len(S)
ans = 1

def check(strs):
    n = len(strs)
    for i in range(n // 2 + 1):
        if strs[i] == strs[-1-i]:
            pass
        else:
            return False
    
    return True

# print(S[:(N - 1) // 2])
# print(S[(N + 3) //2-1 :])

S_b = S[:(N -1) //2]
S_a = S[(N + 3) // 2 - 1:]

if check(S) and check(S_b) and check(S_a):
    print("Yes")
else:
    print("No")


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

long long int dayCount(long long int y, long long int m, long long int d)
{
    long long int sum;
    long long int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    for(int i=1; i<12; i++) days[i] += days[i-1];
    y--;
    sum = 365*y + days[m-1] + d + y/4 - y/100 + y/400;
    y++;
    if((y%4==0 && y%100!=0) || (y%400==0)) if(m>=3) sum++;
    return sum;
}
long long int dayCount(long long int b, long long int ka, long long int t, long long int w, long long int ki)
{
    long long int sum;
    long long int days[5]={1,20,18,20,20};
    for(int i=2; i<5; i++) days[i] *= days[i-1];
    sum = ki + w*days[1] + t*days[2] + ka*days[3] + b*days[4];
    return sum;
}

string ADtoMaya(int y, int m, int d)
{
    stringstream date;
    long long int now = dayCount(y,m,d);
    long long int dif = now - dayCount(2012,12,21);
    dif %= dayCount(13,0,0,0,0);

    int b,ka,t,w,ki;
    int days[5]={1,20,18,20,20};
    for(int i=2; i<5; i++) days[i] *= days[i-1];
    b = dif/days[4];
    dif %= days[4];
    ka = dif/days[3];
    dif %= days[3];
    t = dif/days[2];
    dif %= days[2];
    w = dif/days[1];
    dif %= days[1];
    ki = dif/days[0];
    date<<b<<"."<<ka<<"."<<t<<"."<<w<<"."<<ki;
    return date.str();
}

string MayatoAD(int b, int ka, int t, int w, int ki)
{
    stringstream date;
    long long int now = dayCount(b,ka,t,w,ki);
    now += dayCount(2012,12,21);

    int y,m,d;
    int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    y = 1;
    while(now > 365) {
        bool leap = (y%4==0 && y%100!=0) || (y%400==0);
        if(leap && now==366) break;
        now -= 365 + leap;
        y++;
    }
    bool leap = (y%4==0 && y%100!=0) || (y%400==0);
    for(int i=1; i<=12; i++) {
        m = i;
        if(now <= days[i]) break;
        now -= days[i];
        if(leap && i==2) {
            if(now==1) {
                now = 29;
                break;
            }
            now--;
        }
    }
    d = now;
    date<<y<<"."<<m<<"."<<d;
    return date.str();
}

int main()
{
    string date;
    while(getline(cin, date), date!="#") {
        int y,m,d;
        int b,ka,t,w,ki;
        stringstream ss;
        string ans;

        while(date.find(".")!=string::npos) {
            date.replace(date.find("."), 1, " ");
        }

        ss.str(date);
        if(count(date.begin(), date.end(), ' ') == 4) {
            ss>>b>>ka>>t>>w>>ki;
            ans = MayatoAD(b, ka, t, w, ki);
        } else {
            ss>>y>>m>>d;
            ans = ADtoMaya(y, m, d);
        }

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true){
        c-=b;
        if(c<=0) return puts("Yes"),0;
        a-=d;
        if(a<=0) return puts("No"),0;
    }
}

Measured memory_bytes: 3700
def main():
    N = int(input())
    ans = 0

    for num in range(1, N + 1, 2):
        cnt = 0
        for i in range(1, num + 1, 2):
            if num % i == 0:
                cnt += 1
        if cnt == 8:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

const int INF = 1e9;

using tp = tuple<int, int, int, int>;

const int dx[2][9] = {
	{ -2, -1, 0, 1, 2, -1, 0, 1, 0 },
	{ -2, -1, 0, 1, 2, -1, 0, 1, 0 }
};

const int dy[2][9] = {
	{ 1, 1, 1, 1, 1, 2, 2, 2, 3 },
	{ -1, -1, -1, -1, -1, -2, -2, -2, -3 }
};

int main()
{
	int w, h;
	while (cin >> w >> h, w | h) {
		vector<int> si, sj, ti, tj;
		vector<vector<char>> s(h, vector<char>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> s[i][j];
				if (s[i][j] == 'S') {
					si.push_back(i);
					sj.push_back(j);
					s[i][j] = '0';
				}
				if (s[i][j] == 'T') {
					ti.push_back(i);
					tj.push_back(j);
					s[i][j] = '0';
				}
			}
		}
		vector<vector<vector<int>>> d(h, vector<vector<int>>(w, vector<int>(2, INF)));
		priority_queue<tp, vector<tp>, greater<tp>> pq;
		for (int i = 0; i < (int)si.size(); i++) {
			pq.emplace(0, si[i], sj[i], 0);
			pq.emplace(0, si[i], sj[i], 1);
		}
		while (!pq.empty()) {
			auto p = pq.top(); pq.pop();
			int x = get<1>(p), y = get<2>(p), b = get<3>(p), c = get<0>(p);
			if (d[x][y][b] != INF) continue;
			d[x][y][b] = c;
			for (int i = 0; i < 9; i++) {
				int tx = x + dx[b][i], ty = y + dy[b][i];
				if (0 <= tx && tx < h && 0 <= ty && ty < w && s[tx][ty] != 'X' && d[tx][ty][1 - b] == INF) {
					pq.emplace(c + (s[tx][ty] - '0'), tx, ty, 1 - b);
				}
			}
		}
		int res = INF;
		for (int i = 0; i < (int)ti.size(); i++) {
			res = min(res, d[ti[i]][tj[i]][0]);
			res = min(res, d[ti[i]][tj[i]][1]);
		}
		cout << (res == INF ? -1 : res) << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,cnt=1,type=-1;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    if(type==-1){ 
      type=0;
   }else if(type==0){
      if(a[i]>a[i-1])type=1;
      else if(a[i]<a[i-1])type=2;
    }else if(type==1){
      if(a[i]<a[i-1]){
        type=-1;
        cnt++;
        i--;
      }
    }else if(type==2){
      if(a[i]>a[i-1]){
        type=-1;
        cnt++;
        i--;
      }
    }
  }
  cout << cnt << endl;
}


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

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

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

const int N = 1e5 + 5;
int fr[N], ans[N], vis[N];
vector<int> e[N];
set<int> blk[N];
set<int> found;
int cnt;

void dfs(int u){
    vis[u] = 1;
    found.insert(u);
    for(int v : e[u]) if(!vis[v]) dfs(v);
    cnt++;
}

void dfs2(int u){
    vis[u] = 2;

    int c = 0;
    for(int b : blk[u]) if(found.count(b)) c++;
    ans[u] = cnt - 1 - fr[u] - c;
    for(int v : e[u]) if(vis[v] != 2) dfs2(v);
}

int main(){
    fcin;
    int n, m, k;
    cin >> n >> m >> k;

    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;

        fr[u]++;
        fr[v]++;

        e[u].pb(v);
        e[v].pb(u);
    }

    for(int i = 0; i < k; i++){
        int u, v;
        cin >> u >> v;

        blk[u].insert(v);
        blk[v].insert(u);
    }

    for(int i = 1; i <= n; i++){
        if(vis[i] == 0){
            cnt = 0;
            found.clear();
            dfs(i);
            dfs2(i);
        }
    }
    for(int i = 1; i <= n; i++) cout << max(0, ans[i]) << " ";
    return 0;
}



Measured memory_bytes: 26616
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF = 1e18;

#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) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int k;cin>>k;
    int a,b;cin>>a>>b;
    check_input();

    //solve
    rep(i, a, b+1){
        if (i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0; 
}


Measured memory_bytes: 3652
N = int(input())
S = str(input())
if N % 2 == 0:
  harf_N = N // 2
  S_first = S[0:harf_N]
  S_last = S[harf_N:N]
  if S_first == S_last:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] hl = new int[n];
        for(int i = 0; i < n; i++){
            hl[i] = sc.nextInt();
        }
        Arrays.sort(hl);
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i <= n-k; i++){
            ans = Math.min(ans, hl[i+k-1]-hl[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 50644
from itertools import combinations_with_replacement as cwd

n,m,q = map(int,input().split())
A = list(cwd(range(1,m+1),n))
l = []
ans = 0

for i in range(q):
    a,b,c,d = map(int,input().split())
    a,b = a-1,b-1
    l.append([a,b,c,d])

for j in A:
    tmp = 0
    for k in l:
        if j[k[1]] - j[k[0]] == k[2]:
            tmp += k[3]
    ans = max(ans,tmp)

print(ans)

Measured memory_bytes: 21532
program abc_b
  integer :: count=0, current_count=0
  character(10) input
  read *, input
  do i=1, 10
    select case (input(i:i))
      case ('A', 'T', 'C', 'G')
        current_count = current_count +1
      case default
        call count_up()
    end select
  end do
  call count_up()
  print '(I0)', count

  contains
    subroutine count_up()
      if (current_count > count) then
        count = current_count
        current_count = 0
      end if
    end subroutine count_up
end program


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

int main() {
  int a = 0, b = 0;
  cin >> a >> b;
  int ans = a * b;
  if( ans % 2 == 1){
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <climits>
#include <sstream>
#include <algorithm>
#define fastio() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long 
#define MOD 1000000007
#define inf 9223372036854775807ll
using namespace std;

string getLCS(string& s, string& t, int len, int dp[][3002]){
	int i = s.size(), j = t.size();
	string res(len, '0');

	while(len > 0){
		if(s[i - 1] == t[j - 1]){
			len--;
			res[len] = s[i - 1];
			i--;
			j--;
		}
		else{
			if(dp[i][j - 1] > dp[i - 1][j]) j--;
			else i--;
		}
	}
	return res;
}

int main(){
	string s, t; 
	cin >> s >> t;
	// reverse(s.begin(), s.end());
	// reverse(t.begin(), t.end());
	int n = s.size(), m = t.size();

	int dp[3002][3002];
	memset(dp, 0, sizeof(dp));

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(s[i - 1] == t[j - 1]) dp[i][j] = 1 + dp[i - 1][j - 1];
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	// for(int i = 0; i <= n; i++){
	// 	for(int j = 0; j <= m; j++){
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }

	cout << getLCS(s, t, dp[n][m], dp);

	return 0;
}

Measured memory_bytes: 35456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();
		long unit = n / (a + b);
		long remain = 0;
		if (n % (a + b) > a) {
			remain = a;
		} else {
			remain = n % (a + b);
		}

		long answer = unit * a + remain;

		print(answer);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 21844
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M, K = MAP()

    l = []
    for i in range(N+1):
        for j in range(M+1):
            l.append(M*i + N*j - i*j*2)

    print("Yes" if K in set(l) else "No")


if __name__ == '__main__':
    main()

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    //a[i] + a[j] == j - i;
    //a[i] + i == j - a[j];
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
    }
    map<Int, Int> mp;
    Int res = 0;
    for (Int i = 0; i < (Int)n; i++) {
        res += mp[i - a[i]];
        mp[a[i] + i]++;
    }
    print(res);
    return 0;
}

Measured memory_bytes: 27548
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x[10000];
    for(int i=0;i<10000;i++){
        cin>> x[i];
        if(x[i]==0) break;
    }
    for(int i=0;i<10000;i++){
        if(x[i]==0) break;
        else cout << "Case "<< i+1 <<": "<< x[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long a[]=new long[n];
		long ans=1;
		long x=(long)(Math.pow(10, 18));
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
			if(a[i]==0) {
				ans=0;
			}
			if(a[i]>x) {
				ans=-1;
			}
		}
		if(ans!=0&&ans!=-1) {
				for(int i=0;i<n;i++) {
					if(Math.log10(ans)+Math.log10(a[i])<18.5) {
					ans*=a[i];
					if(ans>x) {
						ans=-1;
						break;
					}
					}
					else {
						if(Math.log(ans)+Math.log10(a[i])>18) {
							ans=-1;
							break;
						}
					}
			}
		}
				System.out.println(ans);
	}
}


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

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

  string s;
  cin >> s;

  int ans = 700;
  for (auto c : s) ans += (c == 'o' ? 100 : 0);

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3424
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int y[100005];
  int n , r , x , d , a , b , c;

  cin>>n>>r;
  y[0]=r;
  for(int i=1;i<=n;i++){
    cin>>x;
    y[i]=x;; 
  }

  sort(y,y+(n+1) );

  d=y[1]-y[0];
  
  for(int i=1;i<=n;i++){
    if(y[i] != y[i-1]){
      a = d , b = y[i]-y[i-1];
      if(b > a){
	swap(a,b);
      }
      c = a%b;
      while(c != 0){
	a = b;
	b = c;
	c = a%b;
      }
      d = b;
    }
  }
  cout<<d<<endl;
  return(0);
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

//		int M = Integer.parseInt(sc.next());
//		String S = sc.next();
		List<Integer> bingoList = new ArrayList();
		for(int i=0; i<3; i++) {
			for(int j=0; j<3; j++) {
				int a = Integer.parseInt(sc.next());
				bingoList.add(a);
			}
		}
		int N = Integer.parseInt(sc.next());
		for(int i=1; i<=N; i++) {
			int aa = Integer.parseInt(sc.next());
			int bb = bingoList.indexOf(aa);
			if(bb != -1) {
				bingoList.set(bb, 0);
			}
		}
		if(bingoList.get(0)+bingoList.get(1)+bingoList.get(2) == 0 ||
		   bingoList.get(3)+bingoList.get(4)+bingoList.get(5) == 0 ||
		   bingoList.get(6)+bingoList.get(7)+bingoList.get(8) == 0 ||
		   bingoList.get(0)+bingoList.get(3)+bingoList.get(6) == 0 ||
		   bingoList.get(1)+bingoList.get(4)+bingoList.get(7) == 0 ||
		   bingoList.get(2)+bingoList.get(5)+bingoList.get(8) == 0 ||
		   bingoList.get(0)+bingoList.get(4)+bingoList.get(8) == 0 ||
		   bingoList.get(2)+bingoList.get(4)+bingoList.get(6) == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23892
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
tmp = 0
sum = 0
for i in range(n):
    sum += a[i]
    sum %= mod
for i in range(n-1):
    sum -= a[i]
    if sum<0:
        sum+=mod
    tmp += a[i]*sum
    tmp %= mod 
print(tmp)

Measured memory_bytes: 31620
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var list = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        var answers = new List<long>();
        var x = list.Sum();
        var y = 0L;
        for(var i = n - 1;i >= 1;i--){
            x -= list[i];
            y += list[i];
            answers.Add(Math.Abs(x - y));
        }
        Console.WriteLine(answers.Min());
        
    }
}


Measured memory_bytes: 38852
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)

  var min int64 = math.MaxInt64
  for i := 0; i < 5; i++ {
    sc.Scan()
    input, _ := strconv.ParseInt(sc.Text(), 10, 64)
    if input < min {
      min = input
    }
  }

  fmt.Println((n + min - 1) / min + 4)
}


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

int main() {
        int H[10000], W[10000], i, b, j = 0;

        for (i = 0; i < 10000; i++) {
                cin >> H[i] >> W[i];
                if (H[i] == 0 && W[i] == 0) break;
        }

        for (j; j < i; j++) {
                for (int k = 0; k < H[j]; k++) {
                        for (int l = 0; l < W[j]; l++) {
                                if (k % 2 == 0) {
                                        if (l % 2 == 0) cout << "#";
                                        else cout << ".";
                                }
                                else {
                                        if (l % 2 == 0) cout << ".";
                                        else cout << "#";
                                }
                        }
                        cout << endl;
                }
                cout << endl;
        }
}

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

int n;
vector<int> pos[100010],vct;
int cnt[100010],first;

inline void dfs(int v,int pr)
{
	cnt[v]=1;
	vct.push_back(v);
	
	if(v==n-1) first=vct[(vct.size()+1)/2];
	
	for(auto to:pos[v])
	{
		if(to==pr) continue;
		dfs(to,v);
		cnt[v]+=cnt[to];
	}
	vct.pop_back();
}

int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		pos[a].push_back(b);
		pos[b].push_back(a);
	}
	
	first=-1;
	dfs(0,0);
	cout<<(cnt[first]*2<n?"Fennec":"Snuke");
	
	return 0;
}

Measured memory_bytes: 10104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll cnt;
int l;
int A[1000000];
int n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g){
    for(int i=g; i<n; i++){
        int v = A[i]; //A[i]の値を一時的に保持しておくための変数
        int j = i-g; //ソート済み部分列からvを挿入するための位置を探すループ変数
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v; //挿入操作
    }
}

void shellSort(int A[], int n){
    //数列G = {1,4,13,40,121,364,1093,...}を生成
    for(int h = 1;;){
        if(h>n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    //逆順にG[i]=gを指定
    for(int i = G.size()-1; i>=0; i--){
        insertionSort(A, n, G[i]);
    }
}

int main() {
    cin >> n;
    //より速い入力scanf関数を使用
    for(int i=0; i<n; i++) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for(int i=G.size()-1; i>=0; i--){
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%lld\n", cnt);
    for(int i=0; i<n; i++) printf("%d\n", A[i]);

    return 0;
}


Measured memory_bytes: 7184
#include<stdio.h>

int main(int argc, char const *argv[]) {
  int n,i;
  int a[128];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = n-1; i >= 0; i--) {
    printf("%d", a[i]);
    if (i>0) {
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}


const ll N=2e5+5;

 
int main()
{ 

IOS;

ll n;cin>>n;

set<ll>s;

ll val=0;

FOR(i,n){
  ll x;cin>>x;
  s.insert(x^(x-1));
  val=val^x;
}

ll cnt=0;


for(int i=30;i>=0;i--){
  ll temp=0;
  ll x=1ll<<i;
  if((1ll<<i)&val)temp=1;
  //d2(cnt,temp);
  temp=(temp+cnt)%2;
  if(temp){
    if(s.count(2*x-1))cnt++;
    else {
      cout<<-1;
      return 0;
    }
  }
}

d1(cnt);

//end_routine();

return 0;
 
 }


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	int n;
	cin>>n;
	cout<<n*n*n;
 
	return 0;	
}

Measured memory_bytes: 256
/*					                                
										   *                             *
		                                    *             * * * * * * * *
		                                    *             *
		                                    *             *
		                                    *             *
		                                    *             *
		                                    *             *
		                                    *             *
		                                    * * * * * * * * * * * * * * *
		                                                  *             *
		                                                  *             *
		                                                  *             *
		                                                  *             *
		                                                  *             *
		                                                  *             *
		                                    * * * * * * * *             *
		                                   *                             *                             
*/
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static int dp[][]=new int[100002][3];
	public static int happiness(int arr[][],int n,int m) {
		/*if(n==0) {
			if(m==0) 
				return Main.dp[0][0];
			else if(m==1)
				return Main.dp[0][1];
			else
				return Main.dp[0][2];
		}*/
		if(dp[n][m]!=-1) {
			return Main.dp[n][m];
		}
		else if(m==0) {
			Main.dp[n][m]=arr[n][0]+Math.max(Main.happiness(arr, n-1, 1),Main.happiness(arr, n-1, 2));
			return dp[n][m];
		}
		else if(m==1) {
			Main.dp[n][m]=arr[n][1]+Math.max(Main.happiness(arr, n-1, 0),Main.happiness(arr, n-1, 2));
			return dp[n][m];
		}
		else {
			dp[n][m]=arr[n][2]+Math.max(Main.happiness(arr, n-1, 0),Main.happiness(arr, n-1, 1));
			return dp[n][m];
		}
	}
	public static void main(String []args) {
		for(int i=0;i<100002;i++) {
			for(int j=0;j<3;j++) {
				Main.dp[i][j]=-1;
			}
		}
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int arr[][]=new int[N][3];
		for(int i=0;i<N;i++) {
			arr[i][0]=sc.nextInt();
			arr[i][1]=sc.nextInt();
			arr[i][2]=sc.nextInt();
		}
		Main.dp[0][0]=arr[0][0];
		Main.dp[0][1]=arr[0][1];
		Main.dp[0][2]=arr[0][2];
	    int x=Main.happiness(arr,N-1,0);
	    int y=Main.happiness(arr,N-1,1);
	    int z=Main.happiness(arr,N-1,2);
		System.out.println(Math.max(x,Math.max(y, z)));
		sc.close();
	}
}

Measured memory_bytes: 72376
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
  int month[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
  for(int i=0;i<12;i++)month[i+1]+=month[i];
  vector<string> day(7);
  day[0] = "Sunday";
  day[1] = "Monday";
  day[2] = "Tuesday";
  day[3] = "Wednesday";
  day[4] = "Thursday";
  day[5] = "Friday";
  day[6] = "Saturday";

  int a,b;
  while(true){
    cin>>a>>b;
    if(!a&&!b)break;
    cout<<day[(month[a-1]+b+3)%7]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
int n,x,m;
vector<iii> vec;
int ori[11];
int mxc[11];
int asx[11];
int mex;
bool ok;
 
void rec(int p)
{
  if(p >= n)
    {
      rep(i,m)
	{
	  int sum = 0;
	  REP(j,vec[i].F.F,vec[i].F.S+1)
	    {
	      sum += ori[j];
	    }
	  if(sum != vec[i].S)return;
	}
      ok = false;
      int cost = 0;
      rep(i,n)cost += ori[i];
      if(cost > mex)
	{
	  mex = cost;
	  rep(i,n)asx[i] = ori[i];
	}
      return;
    }
 
  REP(i,0,x+1)
    {
      if(mxc[p] < i)break;
      ori[p] = i;
      rec(p+1);
    }
}
 
int main()
{
  mex = 0;
  ok = true;
  cin >> n >> x >> m;
  rep(i,n)mxc[i] = x;
  vec.resize(m);
  rep(i,m){
    cin >> vec[i].F.F >> vec[i].F.S >> vec[i].S;
    vec[i].F.F--;
    vec[i].F.S--;
    REP(j,vec[i].F.F,vec[i].F.S+1)mxc[j] = min(mxc[j],vec[i].S);
  }
 
  rec(0);
  if(ok)
    {
      cout << -1 << endl;
      return 0;
    }
  rep(i,n)
    if(i)cout << ' ' << asx[i];
    else cout << asx[i];
  cout << endl;
 
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
const int INF = 1e9;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dist[100][100];
int ans;
int main(){
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	REP(i,H){
		cin >> s[i];
		REP(j,W){
			if(s[i][j] == '#') ans++;
		}
	}
	queue<pair<int, int> > que;
	que.push({0, 0});
	dist[0][0] = 1;
	while(not que.empty()){
		int y, x;
		tie(y, x) = que.front();
		que.pop();
		REP(d,4){
			int nx = x + dx[d];
			int ny = y + dy[d];
			if(nx < 0 or nx >= W or ny < 0 or ny >= H) continue;
			if(dist[ny][nx] or s[ny][nx] == '#') continue;
			dist[ny][nx] = dist[y][x] + 1;
			que.push({ny, nx});
		}
	}
	if(dist[H-1][W-1] == 0) cout << -1 << endl;
	else cout << H*W - ans - dist[H-1][W-1] << endl;
	return 0;
}


Measured memory_bytes: 256