akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S;
    cin >> S;
    if(S[2]==S[3] && S[4]==S[5])
    	cout << "Yes" << endl;
    else
    	cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
D = int(input().strip())
c = list(map(int, input().strip().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last=[0]*26 # contents(last day): 1 ind

for d in range(1,D+1): # 1 ind
    max_ = -float("inf")
    for contest in range(26): # 0ind
        score=s[d-1][contest]
        for i in range(26):
            if i==contest:
                continue
            score-=c[i]*(d-last[i])
        if score>max_:
            nextContest=contest
            max_=score
    last[nextContest]=d
    print(nextContest+1)

Measured memory_bytes: 9152
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
//typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
//struct edge{int from, to; ll cost;};

int main(){
    int q,a,b,c,d;
    scanf("%d", &q);
    rep(q){
        scanf("%d %d %d %d", &a, &b, &c, &d);
        string s = "";
        int n = a+b, aa, bb, l = max((a+b) / (b+1), (b+a) / (a+1));

        int ok = 0, ng = a+b+1;
        while(ng-ok > 1){
            int mid = (ok+ng)/2;
            aa = a - mid/(l+1)*l - mid%(l+1);
            bb = b - mid/(l+1);
            
            if((ll)bb < (ll)(aa+1)*(ll)l){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        // cout << c << ok << endl;
        if(c <= ok){
            reppp(j, c-1, min(d,ok)){
                putchar((j % (l+1) == l)?'B':'A');
            }
        }
        if(ng <= d){
            reppp(j, max(ok,c-1), min(n,d)){
                putchar(((n-j) % (l+1) == 0)?'A':'B');
            }
        }
        puts("");
    }
}


Measured memory_bytes: 384
module Main (main) where
import Control.Monad.State

strToInt str = (read str :: Integer)

readLineN n = do
  str <- getLine
  if (n > 1)
    then do
      tail <- readLineN (n-1)
      return $ (strToInt str) : tail
    else
      return $ (strToInt str) : []

calcProfit :: (Ord a, Num a) => State ([a], a, a) a
calcProfit = do
  (xs, maxProf, min) <- get
  case xs of
    [] -> return maxProf
    head:tail -> do
      if head < min then put (tail, maxProf, head)
      else if (head - min) > maxProf then put (tail, head - min, min)
      else put (tail, maxProf, min)
      calcProfit

main = do
  str <- getLine
  ls <- readLineN $ strToInt str
  -- putStrLn $ show ls
  let head1:head2:tail = ls
  putStrLn $ show $ evalState calcProfit (tail, head2 - head1, min head1 head2)


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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);

    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    sort(L.begin(), L.end());

    int count = 0;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = N - 1; k > j; k--) {
                int a, b, c;
                a = L[i];
                b = L[j];
                c = L[k];
                if (c < a + b) {
                    //  cout << a << " " << b << " " << c << " " << k - j <<
                    //  endl;
                    count += k - j;
                    break;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int h, w, K;
  cin>>h>>w>>K;
  char s[15][1252];
  REP(i, h){
    REP(j, w){
      cin>>s[i][j];
    }
  }
  int ans=1e9;
  REP(i, 1<<(h-1)){
    int cnt=0;
    vi v;
    v.push_back(0);
    REP(j, h-1){
      if(i>>j&1){
        ++cnt;
        v.push_back(j+1);
      }
    }
    v.push_back(h);
    int m=v.size();
    vi u(m-1);
    bool can=true;
    [&]{REP(k, w){
      bool ok=true;
      vi uu(m-1);
      REP(l, m-1){
        int sx=v[l], tx=v[l+1];
        int tmp=0;
        FOR(xx, sx, tx){
          if(s[xx][k]=='1'){
            ++tmp;
          }
        }
        if(tmp>K){
          can=false;
          return;
        }
        uu[l]=tmp;
        if(u[l]+uu[l]>K){
          ok=false;
        }
      }
      if(!ok){
        ++cnt;
        REP(l, m-1){
          u[l]=uu[l];
        }
      }
      else{
        REP(l, m-1){
          u[l]+=uu[l];
        }
      }
      // if(i==0){
      //   DEBUG_VEC(u);
      // }
    }
    }();
    if(can){
      CHMIN(ans, cnt);
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 256
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  
  int a, b, t;
  cin.scan(a, b, t);

  int res;
  for (int i = a; i <= t; i += a) {
    res += b;
  }
  writeln(res);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define MOD 1000000007

int main(){
  int i,N,K,ans=0;
  scanf("%d%d",&N,&K);
  char S[N];
  scanf("%s",&S);
  if(S[K-1]=='A')S[K-1]='a';
  else if(S[K-1]=='B')S[K-1]='b';
  else S[K-1]='c';

  printf("%s\n",S);
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
char S[1000000+2];
int main(){
  int i;
  int dp1 = 0;
  int dp2 = 1073709056;
  int nx1;
  int nx2;
  N = rd(S);
  for(i=(0);i<(N);i++){
    S[i] -= '0';
  }
  N++;
  for(i=(N)-1;i>=(1);i--){
    S[i] = S[i-1];
  }
  S[0] = 0;
  for(i=(N)-1;i>=(0);i--){
    nx1 = nx2 = 1073709056;
    chmin(nx1, dp1 + S[i]);
    chmin(nx1, dp2 + S[i] + 1);
    chmin(nx2, dp1 + 10 - S[i]);
    chmin(nx2, dp2 + 9 - S[i]);
    dp1 = nx1;
    dp2 = nx2;
  }
  wt_L(dp1);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200214-1

// --- original code ---
// int N;
// char S[1d6+2];
// {
//   int dp1 = 0, dp2 = int_inf;
//   int nx1, nx2;
//   rd(S@N);
//   rep(i,N) S[i] -= '0';
//   N++;
//   rrep(i,1,N) S[i] = S[i-1];
//   S[0] = 0;
// 
//   rrep(i,N){
//     nx1 = nx2 = int_inf;
// 
//     nx1 <?= dp1 + S[i];
//     nx1 <?= dp2 + S[i] + 1;
// 
//     nx2 <?= dp1 + 10 - S[i];
//     nx2 <?= dp2 + 9 - S[i];
// 
//     dp1 = nx1;
//     dp2 = nx2;
// 
//   }
//   wt(dp1);
// }


Measured memory_bytes: 1280
sx, sy, tx, ty = map(int, input().split())
v = [tx - sx, ty - sy]
ans = []
ans.append("".join(["R"] * v[0]))
ans.append("".join(["U"] * v[1]))
ans.append("".join(["L"] * v[0]))
ans.append("".join(["D"] * (v[1] + 1)))
ans.append("".join(["R"] * (v[0] + 1)))
ans.append("".join(["U"] * (v[1] + 1)))
ans.append("LU")
ans.append("".join(["L"] * (v[0] + 1)))
ans.append("".join(["D"] * (v[1] + 1)))
ans.append("R")
print("".join(ans))

Measured memory_bytes: 3064
import collections
s = input()
dic = collections.defaultdict(list)
for i in range(len(s)):
    dic[s[i]].append(i)
ans = 10000
for key in dic.keys():
    ls = [-1] + dic[key] + [len(s)]
    diff = []
    for i in range(len(ls)-1):
        diff.append(ls[i+1] - ls[i]-1)
    #print(diff)
    ans = min(max(diff),ans)
print(ans)


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] x = new int[100001];
		for(int i=2;i<=100000;i++) {
			x[i] = 1;
		}
		for(int i=2;i<=100000;i++) {
			if(x[i]==0) continue;
			int j = i+i;
			while(j<=100000) {
				x[j] = 0;
				j += i;
			}
		}
		
		int[] like2017 = new int[100001];
		like2017[3] = 1;
		like2017[5] = 1;
		for(int i=9;i<=100000;i+=4) {
			if(x[i]==1 && x[(i+1)/2]==1) like2017[i] = 1;
		}
		for(int i=1;i<=100000;i++) {
			like2017[i] += like2017[i-1];
		}
		
		Scanner in = new Scanner(System.in);
		int q = in.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];
		for(int i=0;i<q;i++) {
			l[i] = in.nextInt();
			r[i] = in.nextInt();
		}
		for(int i=0;i<q;i++) {
			System.out.println(like2017[r[i]]-like2017[l[i]-1]);
		}
		in.close();
	}

}


Measured memory_bytes: 73284
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine()) % 500;
        var s = Console.ReadLine().Split(' ');
        var d = new int[n];
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(s[i]);
        }

        Array.Sort(d, (x, y) => y - x);

        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0)
            {
                ans += d[i];
            }
            else
            {
                ans -= d[i];
            }
        }


        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<complex>
using namespace std;
typedef complex<double> qua;
qua solve(qua a,qua b,qua c)
{
    b=b-a,c=c-a;
    return a+b*conj(c/b);
}
int main()
{
    int m;
    double x1,y1,x2,y2,x3,y3;
    scanf("%lf%lf%lf%lf%d",&x1,&y1,&x2,&y2,&m);
    while(m--)
    {
        scanf("%lf%lf",&x3,&y3);
        qua ans=solve(qua(x1,y1),qua(x2,y2),qua(x3,y3));
        printf("%.8f %.8f\n",ans.real(),ans.imag());
        qua b =qua(x2,y2);
    }
}



Measured memory_bytes: 2764
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

typedef pair<int,int>P;

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

int main() {

  int h,w;cin>>h>>w;
  int dotCnt=0;
  char s[h+10][w+10];
  rep(i,0,h){
    rep(j,0,w){
      cin>>s[i][j];
      if(s[i][j]=='.')dotCnt++;
    }
  }

  int d[h+10][w+10];
  rep(i,0,h){
    rep(j,0,w){
      d[i][j]=INF;
    }
  }
  d[0][0]=0;

  queue<P>q;
  q.push(P(0,0));

  while(!q.empty()){
    P p=q.front();
    q.pop();
    int x=p.first,y=p.second;

    if(x==w&&y==h)break;

    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];

      if(nx>=0&&ny>=0&&nx<w&&ny<h&&s[ny][nx]!='#'&&d[ny][nx]==INF){
        q.push(P(nx,ny));
        d[ny][nx]=d[y][x]+1;
      }
    }
  }
  if(d[h-1][w-1]==INF)out(-1)
  else out(dotCnt-d[h-1][w-1]-1)

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <string.h>
#include <limits>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <chrono>

using namespace std;

namespace
{

}

#if 1
int main()
{
	int n;
	cin >> n;

	int m;
	cin >> m;

	int x;
	cin >> x;

	int y;
	cin >> y;

	vector<int> xs;
	xs.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> xs[i];
	}

	vector<int> ys;
	ys.resize(m);
	for (int i = 0; i < m; i++)
	{
		cin >> ys[i];
	}

	int xmax = x;

	for (int i = 0; i < n; i++)
	{
		if (xmax < xs[i])
		{
			xmax = xs[i];
		}
	}

	int ymin = y;

	for (int i = 0; i < m; i++)
	{
		if (ymin > ys[i])
		{
			ymin = ys[i];
		}
	}

	if (xmax < ymin)
	{
		cout << "No War" << endl;
	}
	else
	{
		cout << "War" << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
string s;
cin >> s;
int cnt = 0;
int make = 0;
for(int i = 0; i <s.size(); i++){
    if (s.at(i) == 'o')
    {
        cnt++;
    }
    if (s.at(i) == 'x')
    {
        make++;
    }
}
if (cnt >= 7 && make <= 7)
{
    cout << "YES" << endl;
}
else if(make <= 7){
    cout << "YES" << endl;
}
else{
    cout << "NO" << endl;
}
}

Measured memory_bytes: 256
def calc_distance(maze):
    sx,sy,gx,gy = 0,0,w-1,h-1
    #maze = maze.split()
    INF = 10000000000
    field_x_length = w
    field_y_length = h
        
    distance = []
    for i in range(field_y_length):
        distance.append([])
        for j in range(field_x_length):
            distance[i].append(INF)
        
    queue = []
    queue.insert(0, (sy,sx))
    distance[sy][sx] = 0
        
    while queue:
        y, x = queue.pop()
        if(x == gx and y == gy):
            break
                
        for i in range(0,4):
            nx, ny = x +[1,0,-1,0][i], y +[0,1,0,-1][i]
                
            if(0 <= nx and nx < field_x_length and 0 <= ny and ny < field_y_length and maze[ny][nx] != '#' and distance[ny][nx] == INF):
                queue.insert(0,(ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    return distance[gy][gx]
    
h,w = map(int, input().split())
maze = [input() for _ in range(h)]

import collections
count = 0
for i in range(0,h):
    c = collections.Counter(maze[i])
    count += c["#"]

if (calc_distance(maze) < 200):
    print(w*h - count - calc_distance(maze) -1)
else:
    print(-1)

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
    int count [4][3][10];
    for (int i =0 ; i<4; i++) {
        for (int j = 0; j<3; j++) {
            for (int k = 0; k<10; k++) {
                count [i][j][k] = 0;
            }
        }
    }
    int n;
    cin >> n;
    int a,b,c,d;
    for (int l=0; l<n; l++) {
        cin >> a >> b >> c >> d;
        count [a-1][b-1][c-1] += d;
    }
    for (int q=0;q<4;q++) {
        for (int x=0; x<3; x++) {
            for (int y=0; y<10; y++) {
                cout <<" "<< count [q][x][y];
            }
            cout  << endl;
        }
        if (q==3)  break;
        for (int z= 0; z<20; z++){
            cout << "#";
        }
        cout << endl;
    }
}



Measured memory_bytes: 3028
n=int(input())
l=list(map(int,input().split()))
x=[]
i=0
flag=0
for i in range(n-1,0,-1):
    if(l[i]<l[i-1]):
        if(l[i-1]-1<=l[i]):
            l[i-1]-=1
        else:
            flag=1
if(flag==0):
    print("Yes")
else:
    print("No")
        



Measured memory_bytes: 63984
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cfloat>
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 200005;

int n;
int f[N];
si q;
si :: iterator it;

int main() {
    int x, l, r;
    LL ans;
    while (~scanf("%d", &n)) {
        FOR (i, 1, n) {
            scanf("%d", &x);
            f[x] = i;
        }
        q.clear();
        ans = 0;
        FOR (i, 1, n) {
            q.insert(f[i]);
            it = q.lower_bound(f[i]);
            if (it == q.begin()) l = 1;
            else {
                it--;
                l = *it + 1;
            }
            it = q.upper_bound(f[i]);
            if (it == q.end()) r = n;
            else {
                r = *it - 1;
            }
            //sc3(l, r, i);
            ans += (LL) (f[i] - l + 1) * (r - f[i] + 1) * i;
        }
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 10368
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int a[100001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i]--;
	}
	vector<bool> ischecked(n, false);
	int now = 0;
	ischecked[now] = true;
	for(int i = 1; ; i++){
		int next = a[now];
		if(ischecked[next]){
			cout << -1 << endl;
			break;
		} else if(next == 1){
			cout << i << endl;
			break;
		} else {
			ischecked[next] = true;
			now = next;
		}
	}
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x : int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)

mod = 10**9+7
fact = [1] * N
fact_inv = [1] * N
for i in range(1, N):
    fact[i] = i * fact[i-1] % mod
inv = lambda x : pow(x, mod-2, mod)
fact_inv[N-1] = inv(fact[N-1])
for i in range(1, N)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod

stack = [0]
parent = [-1] * N
order = []
while stack:
    v = stack.pop()
    order.append(v)
    for c in G[v]:
        if c != parent[v]:
            stack.append(c)
            parent[c] = v

dp = [1] * N
size = [1] * N
for v in order[::-1]:
    dp[v] = dp[v] * fact[size[v]-1] % mod
    p = parent[v]
    if p == -1:
        break
    size[p] += size[v]
    dp[p] = dp[p] * dp[v] * fact_inv[size[v]] % mod

ans = [0] * N
ans[0] = dp[0]
for v in order[1:]:
    p = parent[v]
    ans[v] = ans[p] * size[v] * inv(N-size[v]) % mod

print(*ans, sep='\n')

Measured memory_bytes: 116784
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	if false {
		test()
	} else {
		solve(bufio.NewReader(os.Stdin), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int // number of participants
	var m int // number of languages
	fmt.Fscanln(r, &n, &m)

	g := make(map[int][]int)

	for i := 0; i < n; i++ {
		var langs int
		fmt.Fscan(r, &langs)
		g[i] = make([]int, 0, langs)
		for j := 0; j < langs; j++ {
			var lang int
			fmt.Fscan(r, &lang)
			langi := n + lang - 1
			g[i] = append(g[i], langi)
			g[langi] = append(g[langi], i)
		}
	}

	seen := make([]bool, n+m)
	q := []int{0}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		if !seen[v] {
			seen[v] = true
			q = append(q, g[v]...)
		}
	}

	for i := 0; i < n; i++ {
		if !seen[i] {
			fmt.Fprintln(w, "NO")
			return
		}
	}
	fmt.Fprintln(w, "YES")
	return
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `4 6
3 1 2 3
2 4 2
2 4 6
1 6`,
			want: `YES
`,
		},
		{
			in: `4 4
2 1 2
2 1 2
1 3
2 4 3`,
			want: `NO
`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(tt.in), buf)
		if got := buf.String(); got != tt.want {
			fmt.Printf("%d: got %v, want %v\n", i, got, tt.want)
		}
	}
}


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

int main() {
    int n;
    cin >> n;
    set<string> t;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        t.insert(s);
    }
    cout << t.size() << endl;
    return 0;
}


Measured memory_bytes: 19120
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

ll dp[3004][3004];

int main(){
	int i,n,j;
	scanf("%d",&n);
	ll a[3005],sum[3005];
	sum[0]=0;
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}

	for(i=1;i<=n;i++){
		dp[i][i]=a[i];
	}

	for(i=n;i>=1;i--){
		for(j=i+1;j<=n;j++){
			dp[i][j] = max(sum[j]-sum[i-1]-dp[i+1][j],sum[j]-sum[i-1]-dp[i][j-1]);
		}
	}

	printf("%lld\n",2*dp[1][n]-sum[n] );
	return 0;
}


Measured memory_bytes: 70016
n,m = map(int,input().split())


def judge():
    ans="-"*n
    if m==0:
        if n==1:
            return 0
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1]!="-" and int(ans[s-1])!=c:
            return -1
        else:
            a = list(ans)
            a[s-1] = str(c)
            ans = "".join(a)
    if ans[0]=="-":
        a=list(ans)
        a[0]="1"
        ans="".join(a)
    ans=ans.replace("-","0")
    # print(ans[0])
    if ans[0]==str(0):
        if n==1:
            return 0
        else:
            return -1
    return ans

print(judge())

Measured memory_bytes: 3064
#include<queue>
#include<cstdio>

#define	mp	make_pair

using namespace std;

struct Info{
	int now,bef,sp;
	Info(int _now,int _bef,int _sp){
		now=_now;
		bef=_bef;
		sp=_sp;
	}
};

bool operator<(const Info &i1,const Info &i2){
	return true;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		static int adj[30][30],lim[30][30];
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	adj[i][j]=-1;

		int s,g;	scanf("%d%d",&s,&g);
		s--,g--;
		for(int i=0;i<m;i++){
			int x,y,d,l;	scanf("%d%d%d%d",&x,&y,&d,&l);
			x--,y--;
			adj[x][y]=adj[y][x]=d;
			lim[x][y]=lim[y][x]=l;
		}

		static bool visited[30][30][31];
		static double tmin[30][30][31];
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<=30;k++){
			visited[i][j][k]=false;
			tmin[i][j][k]=1<<30;
		}

		tmin[s][s][0]=0;
		double ans=-1;
		priority_queue< pair<double,Info> > pq;	pq.push(mp(0,Info(s,s,0)));
		while(!pq.empty()){
			pair<double,Info> a=pq.top();	pq.pop();
			int u=a.second.now,bef=a.second.bef,sp=a.second.sp;
			if(visited[u][bef][sp])	continue;
//printf("t=%.3f, u=%d, speed=%d\n",-a.first,u,sp);
			visited[u][bef][sp]=true;
			if(u==g && sp==1){
				ans=tmin[u][bef][sp];
				break;
			}

			for(int v=0;v<n;v++){
				if(adj[u][v]==-1 || v==bef)	continue;
//printf("  v candi %d\n",v);
				for(int dv=-1;dv<=1;dv++){
					int nextsp=sp+dv;
//printf("    nextspeed=%d, lim=%d\n",nextsp,lim[u][v]);
					if(1<=nextsp && nextsp<=lim[u][v]){
//					if(!visited[v][nextsp] && 1<=nextsp && nextsp<=lim[u][v]){
						double nextt=tmin[u][bef][sp]+(double)adj[u][v]/nextsp;
//printf("      passed. nextt=%.3f, tmin=%.3f\n",nextt,tmin[v][nextsp]);
						if(nextt<tmin[v][u][nextsp]){
							pq.push(mp(-nextt,Info(v,u,nextsp)));
							tmin[v][u][nextsp]=nextt;
						}
					}
				}
			}
		}

		if(ans<0)	puts("unreachable");
		else		printf("%f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1600
using System;

class Program
{
    static void Main(string[] args)
    {
        var nx = Console.ReadLine().Split();
        var n = long.Parse(nx[0]);
        var x = long.Parse(nx[1]);
        var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);

        var ans = Math.Max(0, a[0] + a[1] - x);
        a[0] = Math.Min(x, a[0]);
        a[1] = Math.Min(x - a[0], a[1]);

        for (int i = 2; i < n; i++)
        {
            var p = Math.Max(0, a[i - 1] + a[i] - x);
            ans += p;
            a[i] -= p;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 27228
X,Y = [int(zz) for zz in input().split()]

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

a = (2*Y-X)/3
b = (2*X-Y)/3

if a != int(a):
    print(0)
    exit()

a = int(a)
b = int(b)
N = a+b

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = cmb(N,a,mod)%(10**9+7)
print(int(ans))


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

using namespace std;

typedef pair<int, int> pii;

const int N = 3e3 + 10;
const int INF = 0x3f3f3f3f;

string s, t;
int dp[N][N];
char recon[N][N];

void load() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s >> t;
}

void solve() {
    dp[0][0] = s[0] == t[0];

    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j < t.size(); ++j) {
            if(!i && !j)
                continue;

            if(s[i] == t[j]) {
                if(!i || !j)
                    dp[i][j] = 1;
                else
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                recon[i][j] = s[i];
            }
            else {
                // dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                if(i)
                    dp[i][j] = dp[i - 1][j], recon[i][j] = '{';
                if(j && dp[i][j - 1] > dp[i][j])
                    dp[i][j] = dp[i][j - 1], recon[i][j] = '}';
            }
        }
    }

    string sol;
    int x = s.size() - 1, y = t.size() - 1;
    while(x || y) {

        if(recon[x][y] == '{')
            x--;
        else if(recon[x][y] == '}')
            y--;
        else
            sol.push_back(recon[x][y]), x--, y--;

        //printf("x %d y %d\n", x, y);
        if(x < 0 || y < 0)
            break;
    }
    if(!x && !y && s[0] == t[0])
        sol.push_back(s[0]);
    reverse(sol.begin(), sol.end());

    cout << sol << endl;
    //cout << dp[s.size() - 1][t.size() - 1] << endl;
    //cout << dp[4][3];
}

int main() {
    memset(dp, -INF, sizeof dp);

    load();
    solve();

    return 0;
}


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

    int n;
    cin >> n;
    int p[8], q[8];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }
    int a[8] = { 1,2,3,4,5,6,7,8 };
    int cp = -1, cq = -1;
    int count = 0;
    do {
        count++;
        bool p1 = true, q1 = true;
        for (int i = 0; i < n; i++) {
            if (p[i] != a[i]) p1 = false;
            if (q[i] != a[i]) q1 = false;
        }
        if (p1) cp = count;
        if (q1) cq = count;
    } while (next_permutation(a,a+n));
    cout << std::abs(cp - cq) << endl;
    return 0;

}

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

int main(){
    int N;  cin >> N;
    vector<int> H(N+1,0);
    for(int i=1; i<=N; i++) cin >> H[i];

    for(int i=1; i<=N; i++){
        if(H[i] - H[i-1] > 0) H[i]--;
    }

    for(int i=1; i<=N; i++){
        if(H[i] - H[i-1] < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

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

        if(i&1)
            od.push_back(a[i]);
        else
            ev.push_back(a[i]);
    }


    if(n&1){
        reverse(all(ev));
        for(auto x:ev)
            cout << x << " ";
        for(auto x:od)
            cout << x << " ";
    }
    else{
        reverse(all(od));
        for(auto x:od)
            cout << x << " ";
        for(auto x:ev)
            cout << x << " ";
    }
}

Measured memory_bytes: 5020
#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<cmath>
#include<unordered_map>
#include<vector>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
const int inf = (1e18)+7;
const int neginf = -1*((int)1e17 ) + 7 ; 

int32_t main() {
    fastio
    int n,k;
    cin>>n>>k;
    
    int arr[n];
    
    fo(i,n)
        cin>>arr[i];
    int ct = 0;
    fo(i,n)
    {
        if(arr[i]>=k)
            ct++;
    }
    
    cout<<ct;
    

    
    
        
    
    
     
    
    
    

        
        
        
    
            
        
       
        
        
        
    
     
    
    
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
unsigned char code[256];
string S;
int N;

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

	for(int i=0; i <S.length(); i++) {
		S[i] = S[i] + N;
		if(S[i] > 'Z') S[i]-=26;
	}
	cout << S << endl;;
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC096B solver = new ABC096B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC096B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int K = in.nextInt();
            int m = Math.max(A, Math.max(B, C));
            int n = A + B + C - m;
            for (int i = 0; i < K; i++) {
                m = m * 2;
            }
            out.println(m + n);
        }

    }
}



Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define pii pair <int,int>

using namespace std;

const int N = 100100;

pii a[N];
set <int> st;

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

    for(int i = 0; i < n; i++)  scanf("%d%d", &a[i].second, &a[i].first);

    sort( a, a + n, greater <pii> ());

    for(int i = 0; i <= m; i++) st.insert(i);

    int Ans = 0;

    for(int i = 0; i < n; i++)
    {
        set <int> :: iterator it = st.lower_bound(a[i].second);

        if(it != st.end())
        {
            Ans += a[i].first;
            st.erase(it);
        }
    }

    cout << Ans;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0;
  string s;
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]==s[i+1]){
      cout<<"Bad"<<endl;
      exit(0);
    }
}
  cout<<"Good"<<endl;
}

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

string p="CODEFESTIVAL2016",a;
int i,ans;
bool f;
int main()
{
	cin>>a;
	for(i=0;i<=15;i++)
	{
		if(a[i]!=p[i])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define REP(i,n) for(i=0;i<=n;i++)
int main(void)
{
	int i,j;
	int N,Y;

	scanf("%d""%d",&N,&Y);

	REP(i,N){
		REP(j,N){
			if((Y-i*10000-j*5000)>=0&&(i+j+((Y-i*10000-j*5000)/1000))==N){
				printf("%d %d %d\n",i,j,(Y-i*10000-j*5000)/1000);
				return 0;
			}
		}
	}

	printf("-1 -1 -1\n");
	return 0;
}


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

int main(void){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int t = 0;
	t += a + (a%10?10-(a%10):0);
	t += b + (b%10?10-(b%10):0);
	t += c + (c%10?10-(c%10):0);
	t += d + (d%10?10-(d%10):0);
	t += e + (e%10?10-(e%10):0);
	int save = 0;
	save = max(save, a%10?10-a%10:0);
	save = max(save, b%10?10-b%10:0);
	save = max(save, c%10?10-c%10:0);
	save = max(save, d%10?10-d%10:0);
	save = max(save, e%10?10-e%10:0);
	t -= save;
	cout<<t<<'\n';
	return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
#define ll long long int 
int main(){
    ll a,b,k,x,y;
    scanf("%lld%lld%lld",&a,&b,&k);
    ll i;
    x=a-k;
    y=b;
    if(x>=0){
        k=0;
    }
    else{
        k=-1*x;
        x=0;
    }
    y-=k;
    if(y<0){
        y=0;
    }
    printf("%lld %lld\n",x,y);
    return 0;
}

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

ll a,b,c,k,d,e,f;

int main() {
  cin >> a  >> b >> c >> k;
  if(k%2==0)
  cout << a-b << endl;
  else 
  cout << b-a << endl;
}

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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int t, x;
    
    scanf("%d%d", &t, &x);
    
    if (x%t==0) {
        printf("%d", x+t);
    } else {
        printf("%d", x-t);
    }
    
    return 0;
}



Measured memory_bytes: 1720
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+')cout << a + b << "\n";
    else if(op == '-')cout << a - b << "\n";

    return 0;
}


Measured memory_bytes: 256
q = int(input())
l, r = [0] * q, [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())

mini = min(min(l), min(r))
maxi = max(max(l), max(r))
ans = [0] * (maxi + 1)
prime = [0] * (maxi + 1)
def judge_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    
    return True if n != 1 else False

for i in range((mini + 1) // 2, maxi + 1):
    prime[i] = judge_prime(i)

for i in range(mini, maxi + 1, 2):
    ans[i] = ans[i - 2] + 1 if prime[i] and prime[(i + 1) // 2] else ans[i - 2]
for i in range(q):
    print(ans[r[i]] - ans[max(0, l[i] - 2)])


Measured memory_bytes: 19136
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    cout << N*N*N << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n, k;
    cin >> n >> k;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    map<LL,LL> cnt;
    LL ans = 0;
    LL total = 0, total2 = 0;
    for(LL i = 0; i < n; ++i){
        ++cnt[total];
        total = (total + a[i] + k-1) % k;
        if(i >= k-1){
            --cnt[total2];
            total2 = (total2 + a[i-k+1] +k-1) % k;
        }
        ans += cnt[total];
        //cerr << ans << ", " << cnt << ", total=" << total  << endl;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14336
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int main()
{
	int n, d, a;
	cin >> n >> d >> a;
	vector<int> x(n), h(n);
	vector<pair<int, int>> t(n);
	rep(i, 0, n)cin >> x[i] >> h[i], t[i] = { x[i], i };
	sort(all(t));
	vector<int> t_pos(n);
	rep(i, 0, n)t_pos[i] = t[i].first;
	vector<int> p(n);
	rep(i, 0, n)p[i] = h[t[i].second];
	ll ans = 0;
	int k;
	vector<int> kai(n);
	int damage = 0, left = 0;
	rep(c, 0, n) {
		while (t_pos[left] < t_pos[c] - 2 * d)damage -= kai[left] * a, left++;
		//printf("l:%d c:%d d:%d p:%d\n", left, c, damage, p[c]);
		if (p[c] - damage <= 0)k = 0;
		else k = (p[c] - 1 - damage) / a + 1;
		ans += k;
		kai[c] = k;
		damage += k * a;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8708
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

int main (){
    double r;
    cin >> r;

    double ans = 2*M_PI*r;
    cout << ans;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,W;
    cin >> N >> W;  
    vector<ll> w(N), v(N);
    rep(i,N){
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>> vt(4),S(4,vector<ll>(101));
    rep(i,N){
        vt[w[i]-w[0]].push_back(v[i]);
    }
    rep(i,4){
        sort(vt[i].rbegin(), vt[i].rend());
    }
    rep(i,4){
        rep(j,ll(vt[i].size())){
            S[i][j+1] = S[i][j] + vt[i][j];
        }
    }
    ll ans = 0;
    rep(i,ll(vt[0].size()+1)){
        rep(j,ll(vt[1].size()+1)){
            rep(k,ll(vt[2].size()+1)){
                ll wt = w[0]*i + (w[0]+1)*j + (w[0]+2)*k;
                wt = W - wt;
                if(wt < 0) continue;
                ll q = min(wt/(w[0]+3),ll(vt[3].size()));
                ll tmp = S[0][i] + S[1][j] + S[2][k] + S[3][q];
                cmax(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}

int a[maxn],p[maxn];
vector<set<int>> res[maxn];
map<int,int> cnt;

void eratothenes(){
    for(int i=2;i<maxn;i++){
        if(!p[i]){
            for(int j=i;j<maxn;j+=i){
                p[j]=i;
            }
        }
    }
}
  
int main(){
    int n;
    read(n);
    eratothenes();
    int ans;
    for(int i=1;i<=n;i++){
        read(a[i]);
        if(i==1){
            ans=a[i];
        }else{
            ans=__gcd(ans,a[i]);
        }
    }
    vector<set<int>> res(n+5);
    for(int i=1;i<=n;i++){
        for(int j=a[i];p[j]!=0;j/=p[j]){
            res[i].insert(p[j]);
        }
    }
    map<int,int> mps;
    bool pairwise=true;
    for(int i=1;i<=n;i++){
        for(auto &it : res[i]){
            cnt[it]++;
            if(cnt[it]>=2){
                pairwise=false;
                break;
            }
        }
    }
    if(pairwise){
        puts("pairwise coprime");
    }else{
        if(ans==1){
            puts("setwise coprime");
        }else{
            puts("not coprime");
        }
    }
    return 0;
}

Measured memory_bytes: 318132
n, k = gets.chomp.split.map(&:to_i)
hs = gets.chomp.split.map(&:to_i)
dp = [0]

1.upto(n - 1) do |i|
  min = Float::INFINITY
  [0, i - k].max.upto(i - 1) do |j|
    cost = dp[j] + (hs[i] - hs[j]).abs
    min = cost if cost < min
  end
  dp[i] = min
end

puts dp[n - 1]

Measured memory_bytes: 12164
#include<stdio.h>
int main(){
	int h;
	int a;
	int x;
	scanf("%d %d", &h, &a);
	if(a>h){
		printf("1");
	}
	else if(h>=a){
		x = (h-1)/a+1;
		printf("%d", x);
	}

	return 0; 
}

Measured memory_bytes: 3168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		float max = Float.MIN_VALUE;
		float min = Float.MAX_VALUE;

		while ((line = br.readLine()) != null) {
			float altitude = Float.parseFloat(line);

			if (altitude > max)
				max = altitude;
			if (altitude < min)
				min = altitude;
		}
		System.out.println(max - min);
	}
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

template<typename T>
bool chmin(T &_a, T _b){
    if(_a > _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

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

    int n;
    cin >> n;

    int mini = IINF, maxi = -1;
    rep(i, n){
        int a;
        cin >> a;
        chmax(maxi, a);
        chmin(mini, a);
    }

    cout << maxi - mini << endl;

    return 0;
}

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

int arr[10],N,total=0;

int main(){
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> arr[i];
  }
  sort(arr,arr+N);
  //strictly less than sum of n-1 ..
  total = accumulate(arr,arr+N-1,total);
  if ( total > arr[N-1]){
    cout << "Yes";
  }
  else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 256