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

string s[101];
int n;

int main(){
while(1){	
	
	cin >> n;
	if(n == 0) break;
	for(int i=0; i<n; i++) cin >> s[i];
	
	int r_foot = 0;
	int l_foot = 0;
	int past_l = 0;
	int past_r = 0;
	
	int ans = 0;
	for(int i=0; i<n; i++){
		if(s[i] == "lu") l_foot++;
		else if(s[i] == "ru") r_foot++;
		else if(s[i] == "ld") l_foot--;
		else if(s[i] == "rd") r_foot--;
		
		if(l_foot != past_l and r_foot != past_r){
			ans++;
			past_r = r_foot;
			past_l = l_foot;
		}
	}
	
	cout << ans << endl;
	
}//end
	
	return 0;
}


Measured memory_bytes: 2956
import numpy as np
 
def main():
    N, K = map(int, input().split(" "))
    ps = np.array(input().split(" "))
    ps = ps.astype("int64")
 
    ps_means = np.zeros(N)
    maxval = 0
 
    for i in range(N):
        ps_means[i] = ((1 + ps[i]) * ps[i])/ (2 * ps[i])
        if i + 1 >= K:
            if i + 1 == K:
                sumval = np.sum(ps_means[i-K+1:i+1])
            else:
                sumval -= ps_means[i-K]
                sumval += ps_means[i]
            if sumval > maxval:
                maxval = sumval
 
    ans = maxval
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 33744
#include<bits/stdc++.h>
using namespace std;
int l,n,m;
struct node
{
    int x,y,z;
    node(int x=0,int y=0,int z=0):x(x),y(y),z(z){}
};
vector<node>e;
int main()
{
    scanf("%d",&l);
    if(l<=30)
    {
        printf("%d %d\n",2,l);
        for(int i=0;i<l;i++)
            printf("%d %d %d\n",1,2,i);
        return 0;
    }
    int n=log2(l)+1;
    int sum=0;
    for(int i=1,j=log2(l)-1;i<n;i++,j--)
        e.push_back(node(i,i+1,0)),e.push_back(node(i,i+1,1<<j)),sum+=1<<j;
    while(sum<l-1)
    {
        int s=l-1-sum;
        int res=0;
        for(int i=n-1,j=0;i>=2;i--,j++)
        {
            res+=1<<j;
            if(res+1>s)
            {
                res-=1<<j;
                e.push_back(node(1,i+1,sum+1));
                sum+=res+1;
                break;
            }
            else if(res+1==s||i==2)
            {
                e.push_back(node(1,i,sum+1));
                sum+=res+1;
                break;
            }
        }
    }
    printf("%d %d\n",n,e.size());
    for(int i=0;i<e.size();i++)
        printf("%d %d %d\n",e[i].x,e[i].y,e[i].z);
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
   int n, m, x, i, a[100], o=0, y=0;
   scanf("%d%d%d", &n,&m,&x);
   for(i=0; i<m; i++){
      scanf("%d", &a[i]);
      }

   for(i=0;i<m;i++){
      if(a[i]<x) o++;
      else if(a[i]>x) y++;
      }
   if(o>y) printf("%d\n", y);
   else printf("%d\n", o);

   return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace AtCoder
{
    class Pair
    {
        public Pair(long a,long b)
        {
            this.right = b;
            this.left = a;
        }
        public long right;
        public long left;
    }

    class Program
    {
        static void Main(string[] args)
        {
            new BG042().slove();
            //Console.WriteLine("続行するには何かキーを押してください．．．");
            //#if DEBUG
            //    Console.ReadLine();
            //#endif

        }
    }

    class BG042
    {
        public void slove()
        {
            int[] raw = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
            puts(raw[getLineInts()[0] - 1]);
        }

        public static long[] getLineLongs()
        {
            return getLine().Select(p => long.Parse(p)).ToArray();
        }

        public static int[] getLineInts()
        {
            return getLine().Select(p => int.Parse(p)).ToArray();
        }

        public static String[] getLine()
        {
            String line = Console.ReadLine();
            String[] sp = line.Split(' ');
            if (sp.Length == 1)
            {
                //System.out.println(line);
                return new String[] { line };
            }
            else
            {
                return sp;
            }
        }
       

        void puts(Object mes)
        {
            Console.WriteLine(mes);
        }
    }


}


Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 300009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n,m,d[maxn];
int main()
{
    //freopen("d:\\in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        d[a]++;
        d[b]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",d[i]);
    return 0;
}


Measured memory_bytes: 384
function main()
  
  (sx,sy,tx,ty) = map(x -> parse(Int,x), split(readline()))
 
  S = ""
  
  for i in 1:abs(ty - sy)
    
      S *= "U"
    
  end
  
  for i in 1:abs(tx - sx)
    
      S *= "R"
    
  end
  
  for i in 1:abs(ty - sy)
    
      S *= "D"
    
  end
  
  for i in 1:abs(tx - sx)
    
      S *= "L"
    
  end
  
  S *= "D"
  
  for i in 1:abs(tx - sx) + 1
    
      S *= "R"
    
  end
  
  for i in 1:abs(ty - sy) + 1
    
      S *= "U"
    
  end
  
  S *= "L"
  
  S *= "U"
  
  for i in 1:abs(tx - sx) + 1
    
      S *= "L"
    
  end
  
  for i in 1:abs(ty - sy) + 1
    
      S *= "D"
    
  end
  
  S *= "R"
  
  println(S)
  
end

main()

Measured memory_bytes: 154952
N,M=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort

#N,M=10**5,10**5
#a=N.times.map{rand(10**8..10**9)}.sort

t = [a.pop >> 1]
(M-1).times do
  if a.empty? || t[-1] > a[-1]
    x = t.pop >> 1
  else
    x = a.pop >> 1
  end
  index = t.bsearch_index{|num| num > x } || -1
  t.insert(index, x)
end
p (a+t).inject(:+)


Measured memory_bytes: 12908
object Main extends App{
  override def main(args:Array[String])={
    var s = readLine
    var t = readLine
    var len = s.length
    var flag = false
    if(s==t) {
      println("Yes")
      flag=true
    }
    else{
      for(i <- 0 until len if !flag){
      		s = rotation(s)
        	if(s==t) {
              println("Yes")
              flag=true
            }
      }
    }
    if(!flag) println("No")
    
  }
  def rotation(s:String):String={
    var len = s.length
    return s.charAt(len-1)+s.substring(0,len-1)
  }
}


Measured memory_bytes: 27200
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

void eratos(vector<ll>& prime,ll n){
  bool used[n+10];
  fill(used,used+n+2,false);
  for(int i=2;i<=n;i++){
    if(!used[i]){
      prime.push_back(i);
      int j=i;
      while(j<=n){
        used[j]=true;
        j+=i;
      }
    }
  }
}

int main(){
  ll n,sn,m;
  cin>>n;
  vector<ll> prime;
  sn=sqrt(n);
  ll ans=1;
  eratos(prime,sn);


  //√n以上の素因数pを含む場合はm:=pとし、
  //そうでないときはm=1となる。
  m=n;
  REP(i,prime.size()){
    while(m%prime[i]==0){
      m/=prime[i];
    }
  }


  REP(i,prime.size()){
    if(n%prime[i]==0){
      n=n/prime[i];
      ans*=prime[i]-1;
    }
  }
  if(m!=1){
    n=n/m;
    ans*=m-1;
  }
  ans*=n;
  cout<<ans<<endl;
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int GA, SA, BA;
int GB, SB, BB;
int dp1[5][5050];

int DP1() {
    vector<pii> vw;
    if (GB > GA)vw.push_back(pii(GB - GA, GA));
    if (SB > SA)vw.push_back(pii(SB - SA, SA));
    if (BB > BA)vw.push_back(pii(BB - BA, BA));
    if (vw.size() == 0)return N;
    rep(i, vw.size()) {
        int v = vw[i].first;
        int w = vw[i].second;
        for (int j = 0; j <= N; ++j) {
            if (j < w) {
                dp1[i + 1][j] = dp1[i][j];
            } else {
                dp1[i + 1][j] = max(dp1[i][j], dp1[i + 1][j - w] + v);
            }
        }
    }
    return dp1[vw.size()][N] + N;
}

int DP2() {
    if (GB < GA) {
        //assert(false);
        //SB<SA,BB<BA
        //2で何もしていないはず
        vector<pii> vw;
        //dp1は綺麗なので再利用
        vw.push_back(pii(GA - GB, GB));
        vw.push_back(pii(SA - SB, SB));
        vw.push_back(pii(BA - BB, BB));
        rep(i, vw.size()) {
            int v = vw[i].first;
            int w = vw[i].second;
            for (int j = 0; j <= N; ++j) {
                if (j < w) {
                    dp1[i + 1][j] = dp1[i][j];
                } else {
                    dp1[i + 1][j] = max(dp1[i][j], dp1[i + 1][j - w] + v);
                }
            }
        }
        return dp1[3][N] + N;
    } else if (SB < SA) {
        int ans = 0;
        //BB>2
        for (int b = N / BB; b >= 0; --b) {
            int s = (N - b * BB) / SB;
            int tmp = 0;
            tmp -= b * BB + s * SB;
            tmp += b * BA + s * SA;
            ans = max(ans, tmp);
        }
        return N + ans;
    } else if (BB < BA) {
        //GB>GA,SB>SA,BB<BA
        //変えられるだけ銅に変える
        int b = N / BB;
        N -= b * BB;
        N += b * BA;
        return N;
    } else {
        return N;
    }
}

signed main() {
    cin >> N;
    cin >> GA >> SA >> BA;
    cin >> GB >> SB >> BB;
    //
    if (GB - GA < SB - SA) {
        swap(GB, SB);
        swap(GA, SA);
    }
    if (SB - SA < BB - BA) {
        swap(SB, BB);
        swap(SA, BA);
    }
    if (GB - GA < SB - SA) {
        swap(GB, SB);
        swap(GA, SA);
    }
    //GB-GA>=SB-SA>=BB-BA
    N = DP1();
    int N2 = DP2();
    cout << N2 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[100001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    cin >> a[i];
  }

  int ah = a[n - 1];
  for(int i=n - 2; i >= 0; i--) {
    if(ah < a[i]) {
      if(ah < (a[i] - 1)) {
        cout << "No" << endl;
        return 0;
      } else {
        ah = a[i] - 1;
      }
    } else {
      ah = a[i];
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include<stdlib.h>
#define min(a,b) (a<b?a:b)
#define inf 1<<30

int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    int h[n],dp[114514];
    for(int i=0;i<114514;i++)
    {
        dp[i] = inf;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
    }
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        int j=1;
        while(j<=k)
        {
            int k = abs(h[i+j]-h[i])+dp[i];
            dp[i+j] = min(k,dp[i+j]);
            j++;
        }
    }
    printf("%d\n",dp[n-1]);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[3],ans=0;cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==a[1])ans=a[2]-a[0];
	else
	{
		if((a[1]-a[0])%2)ans=(a[2]-a[0]+a[2]-a[1])/2+2;
		else ans=(a[2]-a[0]+a[2]-a[1])/2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
  s.append(str(input()))
march=[0]*5
for i in range(n):
  if s[i][0]=="M":
      march[0]+=1
  elif s[i][0]=="A":
      march[1]+=1
  elif s[i][0]=="R":
      march[2]+=1
  elif s[i][0]=="C":
      march[3]+=1
  elif s[i][0]=="H":
      march[4]+=1
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += march[i]*march[j]*march[k]
print(ans)


Measured memory_bytes: 9776
import java.util.Scanner;

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

        int a =stdIn.nextInt();
        int b =stdIn.nextInt();

        int x=a*b;
        int y =2*(a+b);
        System.out.println(x +" " + y);
    }

}



Measured memory_bytes: 26052
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int k, a, b;
  cin>>k>>a>>b;
  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK" <<endl;
      return 0;
    }
  }
  cout << "NG" <<endl;
  return 0;
}


Measured memory_bytes: 3676
#include <stdio.h>
int main(void)
{
	int a,b,c,x;
	scanf("%d %d %d",&a,&b,&c);
	
	 if(a>b){
	 	x=a;
	 	a=b;
	 	b=x;
	}
	if(a>c){
		x=a;
	 	a=c;
	 	c=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#include<chrono>
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define mt make_tuple
#define tc  ll t; cin>>t; while(t--)
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define F first
#define S second
#define vi vector<ll>
#define pii pair<ll,ll>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define vii vector<pair<ll,ll>>
ll gcd(ll n,ll m)
{
    if(n==0)
            return m;
    return gcd(m%n,n);
}
bool ifprime(ll n)
{
if(n==1)
return false;
    ll i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
return false;
 
}
return true;
}
void disp(vi v)
{
    for(auto u:v)
    cout<<u<<" ";
    cout<<"\n";
}
void remleadzero(vector<int> &v)
{
    vector<int> u;
    int i=0;
    while(v[i]==0)
        i++;
    while(i<v.size())
    {
        u.push_back(v[i]);
        i++;
    }
    v=u;
}
#define mod 1000000007LL
/*
void myscanf(long long *n)
{
    register long long c=getchar_unlocked();
    *n=0;
    for(;(c<48 ||c>57);c=getchar_unlocked())
        ;
    for(;(c>47 && c<58);c=getchar_unlocked())
    {
        *n=(*n<<1)+(*n<<3)+(c&15);
    }
 
}
void fastscan(long long &number)
{
    bool negative = false;
    register long long c;
 
    number = 0;
 
    c = getchar_unlocked();
    if (c=='-')
    {
 
        negative = true;
 
        c = getchar_unlocked();
    }
 
 
    for (; (c>47 && c<58); c=getchar_unlocked())
        number = number *10 + c - 48;
 
 
    if (negative)
        number *= -1;
}
*/
ll fast_expo(ll n,ll m, ll md)
{
    ll a=1;
    while(m>0)
    {
        if(m&1) a=(a*n)%md;
        n=(n*n)%md;
        m/=2;
    }
    return a%md;
}
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,0LL);
    while(sq*sq<n){
        sq++;
    } 
    if((sq*sq)==n)
        return sq;
    return -1;
}
int dig(int n){
    int ret=0;
    while(n>0){
        n/=10;
        ret++;
    }
    return ret;
}
long long dist[405][405];
int main()
{
    io;
    int n,m;
    cin>>n>>m;
    string grid[n];
    for(int i=0;i<n;i++){
        cin>>grid[i];
    }
    for(int i=0;i<n*m;i++){
        for(int j=0;j<n*m;j++)
            dist[i][j]=1e12;
    }
    for(int i=0;i<n*m;i++)
        dist[i][i]=0;
    for(int i=0;i<n*m;i++){
        int x = i/m, y = i%m;
        if(grid[x][y]!='#'){
        if(x+1<n and grid[x+1][y]!='#'){
            dist[i][(x+1)*m+y]=1;
            dist[(x+1)*m+y][i]=1;
        }

        if(y+1<m and grid[x][y+1]!='#'){
            dist[i][x*m+(y+1)]=1;
            dist[x*m+(y+1)][i]=1;
        }}
    }

    for(int k=0;k<n*m;k++){
        for(int i=0;i<n*m;i++){
            for(int j=0;j<n*m;j++){
                dist[i][j] = min(dist[i][k]+dist[k][j],dist[i][j]);
            }
        }
    }
    long long ans=0;
    for(int i=0;i<n*m;i++){
        for(int j=0;j<n*m;j++){
            int x = i/m, y=i%m;
            int x1 = j/m, y1=j%m;
            if(grid[x][y]=='.' and grid[x1][y1]=='.')
                ans=max(dist[i][j],ans);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 11:05:00 2020

@author: liang
"""

"""
片側を固定して、それぞれのケースに対して最適解を求める
それぞれのケースについて
index(b_i) =< index(b_i-1)
であるから、bの最大値bestを保存して探索することで重複探索を回避できる
"""
N, M, K = map(int, input().split())

A = [0] + [int(x) for x in input().split()]
B = [0] + [int(x) for x in input().split()]

s_b = 0
for i in range(M+1):
    s_b += B[i]
    if s_b > K:
        s_b -= B[i]
        best = i - 1
        break
else:
    best = M
res = best
#print(res)
s_a = 0
for i in range(N+1):
   # print("i", i)
    s_a += A[i]
    if s_a > K:
        break
    for j in reversed(range(best+1)):
        #print("j",j)
        if s_b <= K - s_a:
            if i + j > res:
                res = i + j
            best = j
            #print(i, j, s_a, s_b)
            break
        else:
            s_b -= B[j]
        
print(res)

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

typedef struct {
  double x;
  double y;
} Point;

void kock(int, Point, Point);

int main()
{
  Point p1 = {0.0, 0.0}, p2 = {100.0, 0.0};
  int n;

  scanf("%d", &n);

  printf("%f\t%f\n", p1.x, p1.y);
  kock(n, p1, p2);
  printf("%f\t%f\n", p2.x, p2.y);

  return 0;
}

void kock(int n, Point p1, Point p2)
{
  Point s, t, u;

  if(n == 0)
    return ;

  s.x = (2.0*p1.x+1.0*p2.x)/3.0;
  s.y = (2.0*p1.y+1.0*p2.y)/3.0;
  t.x = (1.0*p1.x+2.0*p2.x)/3.0;
  t.y = (1.0*p1.y+2.0*p2.y)/3.0;
  u.x = (t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y = (t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;

  kock(n-1, p1, s);
  printf("%f\t%f\n", s.x, s.y);
  kock(n-1, s, u);
  printf("%f\t%f\n", u.x, u.y);
  kock(n-1, u, t);
  printf("%f\t%f\n", t.x, t.y);
  kock(n-1, t, p2);

}

Measured memory_bytes: 636
N,M=map(int,input().split(' '))
A=[sorted(list(map(int,input().split(' ')))) for i in range(M)]
ans=0
stack=[1]
visited=[1]
def dfs():
    global stack
    global ans
    #終了判定
    if stack==[]:
        return None
    else:
        #これ以上訪問できるnodeがないとき
        if len(stack)==N: #全訪問した
            ans+=1
            stack.pop(0)
        else:
            for i in range(1,N+1): #未訪問の子ノードを検討
                if i not in stack and sorted([stack[0], i]) in A:
                    stack = [i] + stack
                    dfs()
            stack.pop(0)
dfs()
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] word =
                Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            int x = a + b;
            int y = b + c;
            int z = a + c;

            int m = x;
            if (y < m) m = y;
            if (z < m) m = z;

            Console.WriteLine(m);


        }
    }
}


Measured memory_bytes: 27412
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0; i<n; ++i)a[i]=0;

  for(int i=1; i<n; ++i){
    int x; cin>>x;
    ++a[x-1];
  }

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

Measured memory_bytes: 4052
#include<cstdio>
#include <cstring>

#include<iostream>

#include<algorithm>

#include<queue>
#define INF 1900000000

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

#define RREP(i,n) for(int i=(n)-1;i>=0;i++)

using namespace::std;

typedef pair<int,int> P;

typedef pair<P,int> PP;

int n,m,c[2000],d[2000],table[2000][2000];//city,day

int dp(int k,int t){//(numofCity,Day)=tiredness
 //printf("called!(%d,%d)\n",k,t);
	if(table[k][t]>0)return table[k][t];

	int val;
	if(k==0)val = 0;
	else if(t==0&&k!=0)val = INF;
	else val = min(dp(k,t-1),dp(k-1,t-1)+c[t-1]*d[k]);

	return table[k][t] = val;
}



int main(){
	memset( table, -1, sizeof( table ) );
	scanf("%d%d",&n,&m);
	REP(i,n)scanf("%d",&d[i+1]);
	REP(i,m)scanf("%d",&c[i]);
	printf("%d\n",dp(n,m));
}

Measured memory_bytes: 18868
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
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> S;
  S[1]=0;
  
  vector<ll> vec(0);
  vec.push_back(1);
  
  ll p=1;
  ll index;
  for(ll i=0;i<N;i++) {
    p=A[p-1];
    if(S.count(p)) {
      index=S[p];
    break;
    }
    else {
      S[p]=i+1;
      vec.push_back(p);
    }
    }

  if(K<vec.size()) {
cout<<vec[K]<<endl;
    return 0;
  }
  
  
  ll m=vec.size()-index;
  K-=index;
  K%=m;
  cout<<vec[index+K]<<endl;
}
  
  

  
  
  
  
  
  

Measured memory_bytes: 18412
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	string s, t;
	cin >> s >> t;
	vector<vector<int> > dp(s.size()+1, vector<int>(t.size()+1, 0));
	for (int i = 0; i <= s.size(); i++){
		for (int j = 0; j <= t.size(); j++) {
			if (i == 0 || j == 0)continue;
			if (s[i - 1] == t[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
		}
	}
	string ans = "";
	for (int i = s.size(), j = t.size(); dp[i][j] != 0;) {
		if (dp[i - 1][j] == dp[i][j]) {
			i--;
			continue;
		}
		if (dp[i][j - 1] == dp[i][j]) {
			j--;
			continue;
		}
		ans += s[i-1];
		j--; i--;
	}
	reverse(ans.begin(), ans.end());

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
void caesar(string &s, int n) {
  int i;
  char c;
  for (i = 0; c = s[i]; i++) {
    if (c >= 'a' && c <= 'z') 
      s[i] = 'a' + (c - 'a' + n) % 26;
  }
}
int main() {
  int n;
  string s;
  while (getline(cin, s)) {
    for (n = 0; n < 26; n++) {
      caesar(s, 1);
      if (s.find("the") != string::npos || s.find("this") != string::npos || s.find("that") != string::npos) {
        cout << s << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1176
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.nextLine();
        char[] sc = S.toCharArray();
        int len = S.length();

        for (int i = 0; i < (1<<len); i++) {
            StringBuilder sb = new StringBuilder().append(sc[0]);
            int sum = Character.getNumericValue(sc[0]);
            for (int k = 1; k  < len; k++) {
                if ((1 & (i >> k)) == 1) {
                    sb.append("+" + sc[k]);
                    sum += Character.getNumericValue(sc[k]);
                } else {
                    sb.append("-" + sc[k]);
                    sum -= Character.getNumericValue(sc[k]);
                }
            }
            if (sum == 7) {
                System.out.println(sb.toString() + "=" + sum);
                break;
            }
        }
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main (){
     int n,x,t;
     cin >> n >> x >> t;
     if(n%x == 0) cout << (n/x)*t << endl;
     else cout << ((n/x)+1)*t<< endl;
     }

Measured memory_bytes: 3540
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

#include <iomanip>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const ll INF = 1e17;
ll dp[100005][13];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  ll ans = 0;
  rep(i, N) {
    cin >> H[i];
  }

  SORT(H);
  for(int i=0; i<N-K; i++) {
    ans += H[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
int n;
char s[100001],r[100001];
bool c(char a,char b)
{
    r[0]=a;
    r[1]=b;
    for (int i=2; i<n; ++i)
        r[i]=r[i-1]=='S'?s[i-1]=='o'?r[i-2]:r[i-2]=='S'?'W':'S':s[i-1]=='x'?r[i-2]:r[i-2]=='S'?'W':'S';
    return !(r[n-1]=='S'&&((s[n-1]=='o'&&r[n-2]!=r[0])||(s[n-1]=='x'&&r[n-2]==r[0])))&&
           !(r[0]=='S'&&((s[0]=='o'&&r[1]!=r[n-1])||(s[0]=='x'&&r[1]==r[n-1])))&&
           !(r[n-1]=='W'&&((s[n-1]=='x'&&r[n-2]!=r[0])||(s[n-1]=='o'&&r[n-2]==r[0])))&&
           !(r[0]=='W'&&((s[0]=='x'&&r[1]!=r[n-1])||(s[0]=='o'&&r[1]==r[n-1])));
}
int main()
{
    scanf("%d%s",&n,s);
    puts(c('S','W')||c('W','S')||c('W','W')||c('S','S')?r:"-1");
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    /*R,G,Bそれぞれの数を数える*/
    vector<int> r(n),g(n),b(n);
    long long rcount = 0,gcount = 0,bcount = 0;
    for(int i = 0;i < n;i++){
        switch(s.at(i)){
            case 'R':
            //r.at(rcount) = i;　//いらない
            rcount++;
            break;
            case 'G':
            //g.at(gcount) = i;　//いらない
            gcount++;
            break;
            case 'B':
            //b.at(bcount) = i;　//いらない
            bcount++;
            break;
        }
    }
    /*配列順の差が等しいとき、異なる文字が入ってるか調べる*/
    int rest = 0;
    for(int i = 1;i <= (n - 3)/2 + 1;i++){
        //cout << "差分" << i << endl;
        for(int j = 0;j + i*2< n;j++){
            //cout << j << " " << j + i << " " << j + i*2 << endl;
            if((s.at(j) != s.at(j + i))&&(s.at(j) != s.at(j + 2*i))&&(s.at(j + i) != s.at(j + i*2))){
                rest++;
            }
        }
    }
    //cout << "rest" << rest << endl;
    /**/
    long long ans = bcount*rcount*gcount - rest;
    cout << ans << endl;
    return 0;
}

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

const int MAXN = 1e5 + 10;
int cnt[MAXN], n, ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a > 1e5)
			ans++;
		else
			cnt[a]++;
	}
	for (int i = 0; i < MAXN; i++)
		if (cnt[i] < i)
			ans += cnt[i];
		else
			ans += cnt[i] - i;
	cout << ans;
}

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

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, r;

signed main() {
	cin >> n;
	rep(i,n) {
		cin >> a;
		r += a-1;
	}
	cout << r << ln;
}

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

public class Main {
    
    
    public static void makeBlackDotMap(int black){
    	int H = 30;
    	int W = 100;
    	boolean[][] blackMap = new boolean[H][W];
    	for(int h=0;h<H;h++) for(int w=0;w<W;w++) blackMap[h][w]=false;
    	
    	for(int b=0;b<black;b++){
    		blackMap[1+(b/50)*2][(b%50)*2]=true;
    	}
    	for(int h=0;h<H;h++){
    		for(int w=0;w<W;w++){
    			System.out.print(blackMap[h][w] ? '#' : '.');
    		}
    		System.out.println();
    	}
    }


    public static void makeWhiteDotMap(int white){
    	int H = 30;
    	int W = 100;
    	boolean[][] blackMap = new boolean[H][W];
    	for(int h=0;h<H;h++) for(int w=0;w<W;w++) blackMap[h][w]=true;
    	
    	for(int w=0;w<white;w++){
    		blackMap[1+(w/50)*2][(w%50)*2]=false;
    	}
    	for(int h=0;h<H;h++){
    		for(int w=0;w<W;w++){
    			System.out.print(blackMap[h][w] ? '#' : '.');
    		}
    		System.out.println();
    	}
    }

    
    public static void solve(int white, int black){
    	int H = 100;
    	int W = 100;
    	boolean[][] blackMap = new boolean[H][W];
    	
    	if(white == 1){
    		System.out.println("30 100");
    		makeBlackDotMap(black);
    	}else if(black==1){
    		System.out.println("30 100");
    		makeWhiteDotMap(white);
    	}else{
    		System.out.println("60 100");
    		makeBlackDotMap(black-1);
    		makeWhiteDotMap(white-1);
    	}
    	
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int white = sc.nextInt();
        int black = sc.nextInt();
        
        solve(white,black);
        
    }
}

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

int main() {
      int count = 0;
      int i;
      string s;
      getline(cin,s);
      size_t n = s.size();

      for (i=0; i < ((int)n)/2; i++) {
            if(s[i] != s[n-i-1]) {
                  count++;
            }
      }
      cout << count <<endl;
      return 0;
}


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

typedef map<long long, int, less<long long> > btree; 

int main() {

  int n;
  cin >> n;
  long long a[n];
  for ( int i=0; i<n; i++ ) {
    cin >> a[i];
  }
  
  btree bt;
  string result = "YES";
  for ( int i=0; i<n; i++ ) {
    decltype(bt)::iterator it = bt.find(a[i]);
    if (it != bt.end()) { // aldeary exists
      result = "NO";
      break;
    }
    bt.insert( btree::value_type( a[i], i ) );
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>

int main(void){
    int i,j,k,n,a,b,dice[7],
        side[5] = {2,3,5,4,2};
    char order[7][3] = {"","","N","W","E","S","NN"};
    
    for(i=1;i<7;i++)
        scanf("%d", &dice[i]);
    
    scanf("%d", &n);
    
  //上面を合わせる
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
    
        for(j=1;dice[j]!=a;j++);
        
       //回転  
    
        for(k=0;order[j][k]!='\0';k++){
        
            dice[0] = dice[1];
        
            switch(order[j][k]){
                
                case 'E':
                    dice[1] = dice[4];
                    dice[4] = dice[6];
                    dice[6] = dice[3];
                    dice[3] = dice[0]; 
                    break;
            
                case 'N':
                    dice[1] = dice[2];
                    dice[2] = dice[6];
                    dice[6] = dice[5];
                    dice[5] = dice[0]; 
                    break;
            
                case 'S':
                    dice[1] = dice[5];
                    dice[5] = dice[6];
                    dice[6] = dice[2];
                    dice[2] = dice[0]; 
                    break;
                
                case 'W':
                    dice[1] = dice[3];
                    dice[3] = dice[6];
                    dice[6] = dice[4];
                    dice[4] = dice[0]; 
                    break;

            }
        }
        
        for(j=0;b!=dice[side[j]];j++);
        
        printf("%d\n",dice[side[j+1]]);
        
    }
    
    return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
int main () {
    string X;
    cin >> X;
    int S = 0;
    int ans = X.size();
    for (int i = 0; i < X.size(); i++) {
        if (X[i] == 'S') {
            S++;
        }
        else {
            if (S) {
                S--;
                ans -= 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int a,b,c,d,i,n;
  scanf("%1d %1d %1d %1d",&a,&b,&c,&d);
  for(i=0;i<8;i++){
    n=a;
    n+=(i&1)?b:-b;
    n+=(i&2)?c:-c;
    n+=(i&4)?d:-d;
    if(n==7){
      printf("%d%c%d%c%d%c%d=7\n",a,i&1?'+':'-',b,i&2?'+':'-',c,i&4?'+':'-',d);
      return 0;
    }
  }
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector< pair<int,int> > V;
  vector<int> P(M);
  for(int i = 0; i < M; ++i){
    int y;
    cin >> P[i] >> y;
    V.emplace_back(y,i);
    --P[i];
  }
  sort(V.begin(), V.end());
  vector<int> C(N,0);
  vector<string> ans(M);
  for(int i = 0; i < M; ++i){
    int p = P[V[i].second];
    string t = string(6-to_string(p+1).size(),'0') + to_string(p+1) + string(6-to_string(C[p]+1).size(),'0') + to_string(C[p]+1);
    ++C[p];
    ans[V[i].second] = t;
  }
  //sort(ans.begin(), ans.end());
  for(int i = 0; i < M; ++i) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 9716
N, M, X, Y = map(int, input().split()) # 横に2個
Xs = list(map(int, input().split()))
Ys = list(map(int, input().split()))

Xs.sort()
Ys.sort()

if max(Xs[-1], X) < min(Ys[0], Y):
    ans = 'No War'
else:
    ans = 'War'

print(ans)

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

#define ll long long
#define ar array

int n, k, c[2000001][26], m, cnt[2000001];
int ans;

void dfs(int u=0, int d=0) {
	for(int v=0; v<26; ++v)
		if(c[u][v])
			dfs(c[u][v], d+1), cnt[u]+=cnt[c[u][v]];
	ans += (cnt[u] / k ) * d;
	cnt[u] %= k;
}
bool fun(string a){
	string s = a;
	for(int x =0; x<a.length(); x++){
		if(s[x] != s[a.length() - 1- x])return 0;
	}
	return 1;
}
void solve() {
	string s; cin >> s;
	int n = s.length();
	if(fun(s.substr(0, n/2)) && fun(s))cout << "Yes";
	else cout << "No";
}

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

	int t= 1, i=1;
	// cin >> t;
	while(t--) {
		// cout << "Case #" << i << ": ";
		solve();
		++i;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<int> adj[200005];
vector<int> B(200005,1),W(200005,1);
void dfs(int x,int pre){
      for(int i=0;i<adj[x].size();i++){
            int y=adj[x][i];
            if(y==pre)continue;
            dfs(y,x);
            B[x]=(B[x]*W[y])%modulo;
            W[x]=(W[x]*(B[y]+W[y]))%modulo;
      }
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n;
      cin>>n;
      for(int i=0;i<n-1;i++){
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
      }
      dfs(1,0);
      cout<<(W[1]+B[1])%modulo;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



//メイン関数
int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N)cin >> A[i];

	int odd = 0, even = 0;
	for(auto num : A)
	{
		if(num % 2 == 0)even++;
		else odd++;
	}

	cout << (odd % 2 == 0 ? "YES":"NO") << endl;
	cin>>N;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

#include <cmath>
using namespace std;
typedef long long ll;

ll llin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int main() {

    ll N = llin();
    
    typedef pair<ll, ll> P;
    
    P rels[N];
    
    for(auto i = 0; i<N; i++){
        cin >> rels[i].first >> rels[i].second;
    }
    
    ll ans = rels[0].first + rels[0].second;
    
    ll preA = rels[0].first;
    ll preT = rels[0].second;
    
    
    P temp;
    ll n;
    
    ll ai;
    ll ti;
    
    for(auto i = 1; i<N; i++){
        temp = rels[i];
        
        n = (preT/temp.second < preA/temp.first)? preA/temp.first: preT/temp.second;
        
        ai = n * temp.first;
        ti =  n * temp.second;
        
        n++;

        while(ai < preA || ti < preT){

            ai = n * temp.first;
            ti = n * temp.second;

            n++;

        }
        
        preA = ai;
        preT = ti;
        ans = ai + ti;
    }
    
    cout << ans << endl;
    return 0;
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int n;
int ave=0;

int sum1=0,sum2=0;

int main(){
	cin>>n;
	REP(i,n){
		int t;
		cin>>t;
		ave+=t;
		sum1+=t;
		sum2+=t*t;
	}
	if(ave>0)
		ave=(ave+n*0.5)/n;
	else
		ave=(ave-n*0.5)/n;
	cout<<n*ave*ave-2*ave*sum1+sum2<<endl;
	return 0;
}
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 200005
#define ll signed long long int
using namespace std;

ll n , k;

int main()
{
    FAST;
    cin >> n >> k;
    ll s = 0;
    ll tum = 0;
    ll x = 0;
    ll y = n;

    for(ll i = 1; i < k; i++){
        s += i;
        x = i;
    }
    for(ll i = n; i > n - k; i--){
        tum += i;
        y = i;
    }
    ll ans = 0;
    for(ll i = k; i < n + 2; i++){
        x++;
        x+=2;
        x-=2;
        y--;
        ans += (tum - s + 1);
        ans %= 1000000007;
        s += x;
        tum += y;

    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
using namespace std;
using lint = long long;

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

    int N, Q;
    static lint A[100005] = {}, SUM[2][100005] = {}, diff[100005];

    cin >> N >> Q;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
        SUM[i % 2][i] = A[i];
    }
    A[N] = 1e16;

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

    for (int i = 0; i < Q; i++) {
        lint X;
        cin >> X;

        lint le = 0, ri = N;
        lint len = 0;
        while (le <= ri) {
            lint mid = (le + ri) / 2;
            if (abs(A[N - mid] - X) > abs(A[N - (mid + 1) / 2] - X)) {
                ri = mid - 1;
                // len = mid;
            } else {
                len = mid;
                le = mid + 1;
            }
        }

        lint ans = SUM[0][N - 1] + SUM[1][N - 1];
        if (N - (len + 1) / 2 > 0) {
            ans -= SUM[0][N - (len + 1) / 2 - 1] + SUM[1][N - (len + 1) / 2 - 1];
        }
        lint take = (N - (len + 1) / 2) - (N - len);
        if (take < (N - (N - (len + 1) / 2))) {
            if (N - len - 2 >= 0) {
                ans += SUM[(N - len) % 2][N - len - 1];
            }
        } else {
            if (N - len - 1 >= 0) {
                ans += SUM[(N - len + 1) % 2][N - len - 1];
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
 
 
int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if(a+b<=k) cout<<0<<" "<<0<<endl; 
    else if(a<=k) cout<<0<<" "<<b-(k-a)<<endl;
    else cout<<a-k<<" "<<b<<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SequenceGrowingEasy | diff SequenceGrowingEasy.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SequenceGrowingEasy.cpp && ./a.out

/*
 
 4/7/2020
 
 9:39-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void nope() {
  cout<<-1<<endl;
  exit(0);
}
void solve() {
  REP(i,N) if(A[i]>i) nope();
  LL res=0;
  int l=0;
  while(l<N) {
    int r=l;
    while(r+1<N&&A[r+1]>A[r]) ++r;
    if(A[r]-A[l]==r-l) {
//      dump(l,r,r-l,A[r]);
      res+=A[r];
    } else {
      nope();
    }
    l=r+1;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int X, N;
    cin >> X >> N;
    map<int, int>d;
    for (int i=0; i < N; i++) {
        int x;
        cin >> x;
        d[x] = 1;
    }

    int ans = X;
    int tikasii = X - 1;
    int tikasii2 = X + 1;
    if (N == 0) {
        cout << ans << endl;
    } else {
        if (d.count(X) == 0) {
            cout << ans << endl;
        } else {
            while (true) {
                if (d.count(tikasii) == 0) {
                    ans = tikasii;
                    break;
                }

                if (d.count(tikasii2) == 0) {
                    ans = tikasii2;
                    break;
                }

                tikasii--;
                tikasii2++;
            }
            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3628
# coding:utf-8

input=raw_input()
list=input.split(" ")
for i in range(len(list)):
    list[i]=int(list[i])

e=list[4]
f=list[5]

# 1 2 10 20 15 200
# 17 19 22 26 55 2802

# xが取り得る値
listx=[]
a=list[0]
b=list[1]

i=0
while True:
   if i*a*100>f:
       break
   j=0
   while True:
      x=i*a*100+j*b*100
      if x>f:
          break;
      if x==0:
          j+=1
          continue;
      if x not in listx:
          listx.append(int(x))
      j+=1 
   i+=1 

# yが取り得る値
listy=[]
c=list[2]
d=list[3]

# yが水に溶け切れる最大値
f2=f*e/(100.0+e)

i=0
while True:
   if i*c>f2:
       break
   j=0
   while True:
      y=i*c+j*d
      if y>f2:
          break;
      if y not in listy:
          listy.append(int(y))
      j+=1 
   i+=1 

# 全てのxとyの組み合わせについてfを超えないか、および溶け切れるかを調べる
lengthx=len(listx)
lengthy=len(listy)

xy_max=0
y_max=0
noudo_max=0

for i in range(lengthx):
    for j in range(lengthy):
        x=listx[i]
        y=listy[j]
        if x+y>f:
            continue
        if float(y)*100/float(x)<=e:
            noudo=float(y)/(x+y)
            if noudo>=noudo_max:
                xy_max=x+y
                y_max=y
                noudo_max=noudo

message=str(xy_max)+" "+str(y_max)
print message


Measured memory_bytes: 2776