akhauriyash/Code-Regression huggingface dataset:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    d = []
    tmp = 0
    for i in range(10 ** 7):
        tmp += i
        d.append(tmp)
        if tmp > 10 ** 7 + 1000:
            break

    l = bisect.bisect_left(d, n)
    ans = []
    tmp_n = n
    for i in range(l, 0, -1):
        if tmp_n >= i:
            ans.append(i)
            tmp_n -= i

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10804
use std::io;
use std::str::FromStr;

fn input_int_tuple() -> (i32, i32) {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
  (vec[0], vec[1])
}

fn main() {
  let (a, b) = input_int_tuple();
  let mut max = a + b;
  if a - b > max {
    max = a - b;
  }
  if a * b > max {
    max = a * b;
  }
  println!("{}", max);
}


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

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll> 
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define fast            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl; 
#define pll             pair<ll,ll> 
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)

void solve()
{
    ll i;
    cin>>i;
    cout<<1-i;
}

int main()
{
    
    fast
    ll t = 1;

    while(t--)
    solve();
    
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX 1e9+7
#define lim 1e5
using namespace std;

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

	std::vector<double> prob(n);

	for(int i=0;i<n;i++)
		cin>>prob[i];

	double dp[n+1][n+1];

	memset(dp,0.0,sizeof(dp));

	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{

			if(i==0 && j==0)
				dp[i][j]=1.0;


			else
			{
				double temp1=0.0,temp2=0.0;

				if(i-1>=0 && j-1>=0)
				temp1 = dp[i-1][j-1]*prob[i-1];

				if(i-1>=0 && j>=0)
				temp2 = dp[i-1][j]*(1.0-prob[i-1]);

				dp[i][j] = temp2+temp1;
			}
			
		}
	}

	double ans=0.0;

	for(int i = (n+1)/2 ; i<=n ; i++)
	{
		ans+=dp[n][i];
	}

	//cout<<ans<<endl;
	printf("%0.10lf\n",ans );
}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
struct pos{
  int x,y;
};
int d(pos p1,pos p2){
  return abs(p1.x-p2.x)+abs(p1.y-p2.y);
}
int main(){
  int H,W,D;cin>>H>>W>>D;
  vector<vector<int>>A(H,vector<int>(W));
  vector<pos>P(H*W);
  for(int i=0;i<H;i++)for(int j=0;j<W;j++){
    cin>>A[i][j];
    P[A[i][j]-1].x=j;
    P[A[i][j]-1].y=i;
  }
  vector<int>costs(H*W,0);
  //例えば累積和的にcosts(i)-costs(i-D)で一回の移動?
  //ここまでくるのに必要なコスト
  for(int i=D;i<H*W;i++){
    costs[i]=costs[i-D]+d(P[i],P[i-D]);
  }
  
  
  int Q;cin>>Q;
  for(int i=0;i<Q;i++){
    int l,r;cin>>l>>r;
    cout<<costs[r-1]-costs[l-1]<<endl;
  
  }
}



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

using namespace std;

const int N = 50;
char g[N+1][N+1];
int cnt[N+1][N+1];
int n,m;

void cs(int i , int j)
{
    if(i>=0&&i<=n&&j>=0&&j<=m&&g[i][j]=='.')
        cnt[i][j]+=1;
}

void spread(int i,int j)
{
    cs(i-1,j);
    cs(i,j-1);
    cs(i-1,j-1);
    cs(i+1,j);
    cs(i,j+1);
    cs(i+1,j+1);
    cs(i-1,j+1);
    cs(i+1,j-1);
}

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

    for(int i = 0 ;i<n;i++)
        for(int j = 0;j<m;j++)
            cin>>g[i][j];
    
   memset(cnt,0,sizeof(cnt)); 

   for(int i = 0;i<n;i++)
       for(int j = 0;j<m;j++)
        if(g[i][j]=='#')
            spread(i,j);
   for(int i = 0;i<n;i++)
   {
       for(int j = 0;j<m;j++)
           if(g[i][j]=='#')
                cout<<"#";
           else
               cout<<cnt[i][j];
       cout<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
MIS = len(S)
for TS in range(0,len(S)-len(T)+1):
    LS = S[TS:TS+len(T)]
    Count = 0
    for TT in range(0,len(T)):
        if LS[TT]!=T[TT]:
            Count += 1
    MIS = min(MIS,Count)
print(MIS)

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

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;
    for (int i = 0; i < x - 1; i++)
        cout << y - x + 1 + i << " ";
    for (int i = 0; i < x; i++)
        cout << y + i << " ";
}


Measured memory_bytes: 256
import itertools

a = []
while True:
    d = list(map(int,input().split()))
    if d == [0,0]:
        break
    a.append(d)

for n,x in a:
    ans = 0
    for c in itertools.combinations(range(1,n+1), 3):
        if sum(c) == x: ans += 1
    print(ans)

Measured memory_bytes: 7660
#include <bits/stdc++.h>
using namespace std;
int a[101],n,f[100010],k; 
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=0;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[j]>i)
				break;
			if(i==a[j])
			{
				f[i]=1;
				break;
			}
			if(!f[i-a[j]])
			{
				f[i]=1;
				break;
			}
		}
	}
	if(!f[k])
		cout<<"Second"<<endl;
	else
		cout<<"First"<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstring>

using namespace std;

int main(){
        int n;
        cin >> n;
        while(n){
                int sq[n][n];
                memset(sq,0,sizeof(sq));
                int x[2] = {n/2,n/2+1};
                int m = 1;
                while(!sq[x[0]][x[1]]){
                        sq[x[0]][x[1]] = m;
                        m++;
                        for(int i = 0; i < 2; i++){
                                x[i]++;
                                x[i] %= n;
                        }   
                        if(sq[x[0]][x[1]]){
                                x[0] += n-1;
                                x[1]++;
                                x[0] %= n;
                                x[1] %= n;
                        }   
                }   
                for(int i = 0; i < n; i++){
                        for(int j = 0; j < n; j++){
                                cout << setw(4) << sq[j][i];
                        }   
                        cout << endl;
                }   
                cin >> n;
        }   
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X,Y;
    cin >> X >> Y;
    
    if(Y%2 != 0){cout << "No" << endl;}
    else{
    if( (Y+2)/4 <= X && X <= Y/2) {cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    }
    
    
 
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{
    int A,B,C,CV;

    cin>>A>>B>>C;
    if(B+C>A){
    CV=C-(A-B);
    cout<<CV<<endl;
    }
    else{
    cout<< "0";
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>

using namespace std;

typedef long long ll;


int main(){
    ll n;
    cin>>n;
    ll max_yz=1;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            max_yz=i;
        }
    }
    cout<<(max_yz+n/max_yz-2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS (1e-5)

bool has_solution(vector< vector<double> > A){
  int n = A.size(), m = A[0].size(), t = 0;
  /*
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      printf("%02.10lf ",A[i][j]);
    }cout << endl;
  }
  cout << "-------------------------------------------" << endl;
  */
  for(int i = 0; i < m; ++i){
    int pivot = t;
    for(int j = t; j < n; ++j){
      if(abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
    }
    swap(A[t], A[pivot]);

    if(abs(A[t][i]) <= EPS){
      A[t][i] = 0;
      continue;
    }
    
    for(int j = i+1; j < m; ++j) A[t][j] /= A[t][i];
    A[t][i] = 1.0;
    
    for(int j = 0; j < n; ++j){
      if(j == t) continue;
      double c = A[j][i];
      for(int k = i; k < m; ++k){
        A[j][k] -= A[t][k]*c;
      }
    }
    ++t;
    /*
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < m; ++j){
        printf("%02.10lf ",A[i][j]);
      }cout << endl;
    }
    cout << "-------------------------------------------" << endl;
    */
  }
  for(int i = n-1; i >= 0; --i){
    for(int j = 0; j < m-1; ++j){
      if(abs(A[i][j]) > EPS) return true;
    }
    if(abs(A[i].back()) > EPS) return false;
  }
  return false;
}

vector< vector<double> > cofactor(vector< vector<double> > A, int x, int y){
  //余因子A_xy
  //x = -1 or y = -1 とすると、一方のみを除く
  //cout << " x = " << x << ", y = " << y << endl;
  vector< vector<double> > ret;
  for(int i = 0; i < A.size(); ++i){
    if(i == x) continue;
    ret.push_back(vector<double>());
    for(int j = 0; j < A[0].size(); ++j){
      if(j == y) continue;
      ret.back().push_back(A[i][j]);
    }
  }
  return ret;
}

int solve(vector<double> V, int d){
  vector< vector<double> > A(d+3, vector<double>(d+2));
  for(int i = 0; i < d+3; ++i){
    A[i][0] = 1.0;
    for(int j = 1; j < d+1; ++j) A[i][j] = A[i][j-1]*(i+1);
    A[i].back() = V[i];
  }
  for(int i = 0; i < d+3; ++i){
    if(has_solution(cofactor(A,i,-1))) return i;
  }
  return -1;
}

int main(){
  int d;
  while(cin >> d, d){
    vector<double> V(d+3);
    for(int i = 0; i < d + 3; ++i){
      cin >> V[i];
    }
    cout << solve(V, d) << endl;
  }
  return 0;
}



Measured memory_bytes: 3220
#!/usr/bin/env python3
import sys
import math

def timesNeed(S0, K):
    return int(math.ceil(math.log2(K)-math.log2(S0)))

def solve(N: int, K: int):
    fact = 1./N
    p = 0.
    for S0 in range(1, min(N, K-1)+1):
        p += math.pow(0.5, timesNeed(S0, K))
    p *= fact
    p += max(0., (N-K+1)/N)
    print(p)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

typedef long long ll;

const int maxn = 2e3+5;

const ll mod = (ll)(1e9+7);

int aa[maxn],rk[maxn],ne[maxn];

ll gcd(ll a,ll b, ll &x,ll &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        ll r = gcd(b,a%b,y,x);
        y -= x * (a / b);
        return r;
    }
}

ll ni(ll a,ll n)
{
    ll x, y;
    ll d = gcd(a, n, x, y);
    ll ans;
    if(d == 1)
    {
        x %= n;
        x += n;
        x %= n;
        ans = (x % n);
        return ans;
    }
    else
    {
        return -1;
    }
}
int main()
{
    int n,k;
    ll b=0LL;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&aa[i]);
        rk[i] = 0;
        ne[i] = 0;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(aa[i]>aa[j])
                rk[i]++;
        }
        for(int j=i;j<n;j++)
        {
            if(aa[i]>aa[j])
            {
                ne[i]++;
                rk[i]++;
            }
        }
        b = (b + (((((((ll)rk[i]*(ll)(k-1))%mod)*(ll)k)%mod)*ni(2,mod))%mod) + (((ll)ne[i] * (ll)k)%mod)) % mod;
    }
    printf("%lld\n",b);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> matrix;

string s;

bool win(int start, int end) {
  for(int i = start; i + 1 <= end; i++) {
    if(s[i] == '#' && s[i+1] == '#') return false;
  }
  return true;
}

void solve() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;
  s += ".";
  s += ".";
  s += ".";
  bool can = false;
  if(c < d) {
    can = win(a, c) && win(b, d);
  }
  else {
    can = win(a, c) && win(b, d);
    bool three = false;
    if(can) {
      for(int i = b; i <= d; i++) {
        if(s[i-1] != '#' && s[i] != '#' && s[i+1] != '#') three = true;
      }
    }
    can &= three;
  }
  if(can) cout << "Yes\n";
  else cout << "No\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 592
import java.util.Scanner;

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

        int cnt=0;
        int i, j ,k;
        int [] h, w;
        h = new int[300];
        w = new int[300];
        
        while(true){
            h[cnt] = sc.nextInt();
            w[cnt] = sc.nextInt();
            if(h[cnt] == 0 || w[cnt] == 0)
                break;
            cnt++;
        }

        for(i=0; i<cnt; i++){
            for(j=0; j<h[i]-1; j++){
                if(j == 0){
                    for(k=0; k<w[i]-1;k++)
                        System.out.print("#");
                }else{
                    for(k=0; k<w[i]-1; k++){
                    if(k==0)
                        System.out.print("#");
                    else    
                        System.out.print(".");
                    }   
                }
                System.out.print("#\n");                           
            }
            for(k=0; k<w[i]; k++)
                System.out.print("#");
            System.out.print("\n");
            System.out.println("");
        }
    sc.close();
    }
}


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

using namespace std;

#define INF 210000000
#define int long long

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

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

signed main() {
		string A,B;
		cin >> A >> B;
		map<char,int> acnt;
		map<char,int> bcnt;
		vector<int> a;
		vector<int> b;
		for(int i=0;i<A.length();i++){
				acnt[A[i]]++;
		}
		for(auto& A : acnt){
				a.push_back(A.second);
		}
		for(int i=0;i<B.length();i++){
				bcnt[B[i]]++;
		}
		for(auto& B : bcnt){
				b.push_back(B.second);
		}
		sort(a.begin(),a.end());
		sort(b.begin(),b.end());
		string ans = "Yes";
		if(a.size() != b.size()){
				ans = "No";
		}else{
				for(int i=0;i<a.size();i++){
						if(a[i] != b[i]){
								ans = "No";
								break;
						}
				}
		}
		cout << ans;
}


Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin>>n; int a[n+1];
    for (int i = 0; i < n; i++) cin>>a[i];
    int ans=0;
    for (int i = 0; i < n-1; i++){
        if(a[i]==i+1){
            int b1=a[i],b2=a[i+1]; a[i+1]=b1; a[i]=b2;
            i++; ans++;
        }
    }
    if(a[n-1]==n)ans++;
    cout<<ans<<'\n';
    }
    

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main(){
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==5&&a[1]==5&&a[2]==7)
	    cout<<"YES"<<endl;
	else
	    cout<<"NO"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a=0;
	char b[4];
	string ans = "Good";
	while(a!=4){
		cin>>b[a];
		if(a>0&&b[a]==b[a-1]){
			ans = "Bad";
		}
		a++;
	}
	cout<<ans;
	return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string p = Console.ReadLine();
            int ma= 0;

            for(int i=0;i<s.Length;i++)
            {
                if(p[0]==s[i])
                {
                    int t = 1;
                    int k = t + i;
                    while (t<p.Length)
                    {
                        if (k >= s.Length) k -= s.Length;
                        if (p[t] == s[k]) { t++; k++; }
                        else break;
                    }
                    ma = (t > ma) ? t : ma;
                }
            }
            if (ma == p.Length) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8888
N, M = map(int, input().split())
S = input()
T = input()
from fractions import gcd

g = gcd(N, M)
flag = True
for k in range(g):
  if S[k * N // g] != T[k * M // g]:
    flag = False

if flag:
  print(N // g * M)
else:
  print(-1)

Measured memory_bytes: 64748
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main()
{
    int A[4], B[4];
    int cnt[10]={};
    REP(i,3){
        cin >> A[i] >> B[i];
    }

    REP(i,3){
        FOR(j, 1, 5)
        {
            if (A[i] == j)
            {
                cnt[j]++;
            }
            if (B[i] == j)
            {
                cnt[j]++;
            }
        }
    }
    if(cnt[1]<=2 and cnt[2]<=2 and cnt[3]<=2 and cnt[4]<=2) cout<<"YES"<<endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, s, n) for (int var = (s); var < (n); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  //
  int n;
  cin >> n;
  vector<pii> data;
  int a, b;
  rep(i, n) {
    cin >> a >> b;
    data.push_back(make_pair(b, a));
  }
  sort(ALL(data));
  int start = 0;
  for (auto& d : data) {
    start += d.second;
    if (start > d.first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2420
#include<string>
#include<list>
#include<iostream>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
	if(*it == x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=--data.end();it!=l;++it) cout << *it << " ";
  cout << *it << endl;
}



Measured memory_bytes: 34336
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rp(i,n) for (int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;
double pi=3.14159265359;

//出力するよ
void output_tate(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        //if (i != 0)
        //    cout << " ";
        cout << s[i]<<endl;
    }
    //cout << endl;
}

void output_yoko(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        if (i != 0)
            cout << " ";
        cout << s[i];//<<endl;
    }
    cout << endl;
}

int MOD = pow(10, 9) + 7;

int kaijou(int n){
    if(n==0) return 1;
    else{
        return ((n%MOD)*(kaijou(n-1)%MOD))%MOD;
    }
}

bool ispow(int n){
    int rn=sqrt(n);
    if(rn*rn==n) return true;
    else return false;
}

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

    queue<int> q;
    for(int i=1;i<10;i++) q.push(i);

    int cnt=0;

    while(cnt<k){
        cnt++;
        int top=q.front();
        q.pop();
        //cout<<top<<endl;

        if(cnt==k){
            cout<<top<<endl;
            break;
        }

        if(top%10!=0){
            q.push(top*10+top%10-1);
        }
        q.push(top*10+top%10);
        if(top%10!=9){
            q.push(top*10+top%10+1);
        }
    }
}


Measured memory_bytes: 5164
import sys
sys.setrecursionlimit(1000000)
N,M = list(map(int,input().split()))
XYZ = [list(map(int,input().split())) for _ in range(M)]

G = [[] for _ in range(N)]
 
for i in XYZ:
    G[i[0]-1].append(i[1])
    G[i[1]-1].append(i[0])
 
check = [False for _ in range(N)]
 
def DFS(G,s):
    check[s-1] = True
    for i in G[s-1]:
        if not check[i-1]:         
            DFS(G,i)
ans = 0
for i in range(N):
    if not check[i]:
        DFS(G,i+1)
        ans += 1

print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >> X.at(i);
  }
  
  sort(X.begin(), X.end());
  int ans = 1000000;
  int a = X.at(0);
  int b = X.at(N-1);
  for(int i=a; i<b+1; i++){
    int tmp=0;
    for(int j=0; j<N; j++){
      tmp += (X.at(j)-i)*(X.at(j)-i);
    }
    if(tmp<ans){
      ans = tmp;
    }
  }
  cout << ans << endl;
      
 
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0;i < n;i++){
        cin >> a[i];
    }
    
    ll ans = 0;
    for (ll i = 0; i < n; i++){
        if (a[i] == a[i+1] && i < n-1){
            continue;
        }
        else if (a[i] < a[i+1]){
            while (a[i] <= a[i+1] && i < n-1){
                i++;
            }
        }
        else{
            while (a[i] >= a[i+1] && i < n-1){
                i++;
            }
        }
        //cout << i << endl;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3960
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	int cmax = 0;
	string s;
	cin >> n >> s;
	for(int i = 1; i < n; i++){
		bool abc[26][2] = {0};
		for(int j = 0; j < i; j++){
			int k = int(s[j]) - 97;
			if(abc[k][0] == 0) abc[k][0] = 1;
		}
		for(int j = i; j < n; j++){
			int k = int(s[j]) - 97;
			if(abc[k][1] == 0) abc[k][1] = 1;
		}
		int count = 0;
		for(int j = 0; j < 26; j++){
			if(abc[j][0] == abc[j][1] && abc[j][0] == 1) count += 1;
		}
		if(cmax < count) cmax = count;
	}
	cout << cmax << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    int n=s.size();
    vector<vector<in>> dp(n+1,vector<in>(13,0));
    dp[0][0]=1;
    int ten_cnt=1;
    rep(i,n){
        if(s[n-i-1]=='?'){
            rep(j,10){
                rep(k,13){
                    dp[i+1][(k+j*ten_cnt)%13] += dp[i][k];
                    dp[i+1][(k+j*ten_cnt)%13] %= MOD;
                }
            }
        }

        else{
            int now=s[n-i-1]-'0';
            rep(j,13){
                dp[i+1][(j+now*ten_cnt)%13] = dp[i][j];
            }
        }

        ten_cnt *= 10;
        ten_cnt %= 13;
    }
    cout<<dp[n][5]<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 16672
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

struct Edge {int to, id;};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k = 1;
    rep(i, g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u == p) continue;
        if (k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u, ans[ei], v);
    }
}

int main() {
	int n;
    cin >>n;
    g.resize(n);
    ans = vector<int>(n-1);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i, n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i, n-1) {
    	cout << ans[i] << endl;
    }
	return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;

int main(){

    int n;
    cin >> n;
    vector<tuple<double,ll,ll>> v;

    rep(i,n){
        ll tmpx,tmpy;
        cin >> tmpx >> tmpy;

        double angle;

        double tmpd = sqrt((double)(tmpy * tmpy + tmpx * tmpx));

        if(tmpd < 1.0){
            angle = 0.0;
        }else{
            if(tmpy >= 0){
                angle = acos(((double)tmpx) / tmpd);
            }else{
                angle = 2 * PI - acos(((double)tmpx) / tmpd);
            }
        }

        v.pback(make_tuple(angle,tmpx, tmpy));
    }

    sort(ALL(v));

    rep(i,n){
        double tmpa = get<0>(v[i]);
        ll tmpx = get<1>(v[i]);
        ll tmpy = get<2>(v[i]);

        tmpa = tmpa + 2 * PI;

        v.pback(make_tuple(tmpa,tmpx,tmpy));
    }  

    ll bestd = 0;

    for(int l = 0; l < n; l++){
        for(int i = 1; i <= n; i++){
            ll tmpx = 0;
            ll tmpy = 0;

            rep(j,i){
                tmpx += get<1>(v[l + j]);
                tmpy += get<2>(v[l + j]);
            }

            bestd = max(bestd, tmpx * tmpx + tmpy * tmpy);
        }
    }

    double ans = (double)bestd;
    ans = sqrt(ans);

    cout << setprecision(52) << ans << endl;
}

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

struct node {
    int a[26],s;

    node () {memset(a,0,sizeof a);}

    node operator + (const node &x) const {
        node c;
        for(int i=0;i<26;i++) c.a[i]=a[i]+x.a[i];
        c.s=s+x.s;
        return c;
    }

    node operator - (const node &x) const {
        node c;
        for(int i=0;i<26;i++) c.a[i]=a[i]-x.a[i];
        c.s=s-x.s;
        return c;
    }
}f[100];

int tot,n,p,nxt[maxn];
char s[maxn];

void gao() {
    for(int i=2;i<=n;i++) {
        int j=nxt[i-1];
        while(j&&s[j+1]!=s[i]) j=nxt[j];
        if(s[j+1]==s[i]) nxt[i]=j+1;
    }
}

node solve(int r) {
    node ans;
    for(int i=tot;~i;i--) {
        if(r<f[i].s) continue;
        r-=f[i].s,ans=ans+f[i];
    }
    for(int i=1;i<=r;i++) ans.a[s[i]-'a']++;
    return ans;
}

signed main() {
    scanf("%s",s+1),n=strlen(s+1)/2;
    gao();int p=n-nxt[n];
    for(int i=1;i<=n;i++) f[0].a[s[i]-'a']++;f[1]=f[0];
    for(int i=1;i<=p;i++) f[1].a[s[i]-'a']++;
    f[0].s=n,f[1].s=n+p;tot=1;
    for(int i=2;f[i-1].s+f[i-2].s<=1e18;i++) f[++tot]=f[i-1]+f[i-2];
    int l,r;read(l),read(r);
    node ans=solve(r)-solve(l-1);
    for(int i=0;i<26;i++) printf("%lld ",ans.a[i]);puts("");
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
  }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    vi an;
    cin >> A >> B;
    cout << (B%A == 0?A+B:B-A)<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
   int n;
   cin>>n;
   vector<int> a(n,0);
   for(int i=0;i<n;i++) cin>>a[i];
   sort(a.begin(),a.end());
   cout<<a.back()-a.front()<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

bool shop_table[100][10] = {};
int benefit_table[100][11] = {};

int main(void)
{

	int n,benefit = -mod197;
	cin >> n;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < 10; j++)
			cin >> shop_table[i][j];

	for (int i = 0; i < n; i++)
		for (int j = 0; j <= 10; j++)
			cin >> benefit_table[i][j];

	for (int i = 1; i < (1 << (10)); i++) {

		int now_benefit = 0;

		for (int j = 0; j < n; j++) {
			int total = 0;
			for (int k = 0; k < 10; k++) {
				if ( (i & (1 << k)) && shop_table[j][k]) {
					total++;
				}
			}

			cerr << total << endl;
			now_benefit += benefit_table[j][total];
		}

		
		cerr << now_benefit << endl;
		benefit = max(benefit,now_benefit);

	}

	cout << benefit << endl;

	return 0;
}

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

int main() {
	int N;
  	string S;
  	string result = "Three";
  	cin >> N;
  
  	for(int i = 1; i <= N; i++) {
    	cin >> S;
      	if(S == "Y") {
        	result = "Four";
        }
    }
  
  	cout << result << endl;  	
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int sum=0;
    for(int i=l;i<=r;i++)
    {
        if(!(i%d))
            sum++;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3632
#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()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a[252525];
	cin>>n;
	REP(i, n){
		cin>>a[i];
	}
	ll ans=0;
	for(int l=0, r=0, bit=0; l<n; ++l){
		while(r<n && (bit&a[r])==0) bit|=a[r++];
		ans+=r-l;
		bit^=a[l];
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

void is_a_right_triangle(int*, int*, int*);

int main(void) {
    int n, i, a, b, c;

    scanf("%d", &n);
    
    for(i=0; i<n; i++) {
        scanf("%d%d%d", &a, &b, &c);
        if(a >= b && a >= c) {
            is_a_right_triangle(&a, &b, &c);
        } else if(b >= a && b >= c) {
            is_a_right_triangle(&b, &a, &c);
        } else if(c >= a && c >= a) {
            is_a_right_triangle(&c, &a, &b);
        } else {
            is_a_right_triangle(&a, &b, &c);
        }
    }
return 0;
}

void is_a_right_triangle(int *maxSide, int *side1, int *side2 ) {
    if(((*maxSide)*(*maxSide)) == (((*side1)*(*side1)) + ((*side2)*(*side2)))) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

Measured memory_bytes: 580
import itertools
N = int(input())

# 3~9桁まで(3^9は十分探索可能)
num = 0
for m in range(3,10):
    for v in itertools.product(['3','5','7'], repeat=m):
        if '3' in v and '5' in v and '7' in v and int(''.join(v)) <= N:
            num += 1

print(num)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int a = fs.nextInt();
		int b = fs.nextInt();
		int c = fs.nextInt();
		
		if(a == b) {
			System.out.println(c);
		}else if(a == c) {
			System.out.println(b);
		}else {
			System.out.println(a);
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 21076
//#include <bits/stdc++.h>
 
#include <iostream>
#include <algorithm>
 
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>
 
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
 
 
using namespace std;
#define int long long
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
 
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll INFLL = 1LL<<62;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
 
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n, q;

struct UnionFind {
    int trees;
    vector<int> par, rank, tree_size;

    UnionFind() {}

    UnionFind(int n) : par(n), rank(n, 0), tree_size(n, 1), trees(n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
	}

    int find_root(int now) {
        if (now == par[now]) return now;
        return par[now] = find_root(par[now]);
    }

    void unite(int u, int v) {
        int x = find_root(u);
        int y = find_root(v);
        if (x == y) return ;
        if (rank[x] < rank[y]) swap(x, y);
        par[y] = x;
        tree_size[x] += tree_size[y];
        trees--;
        if (rank[x] == rank[y]) rank[x]++;
    }

    bool same(int u, int v) {
        return find_root(u) == find_root(v);
    }

    int tree_num() {
        return trees;
    }

    int tree_w(int x) {
        return tree_size[find_root(x)];
    }
};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> q;
    UnionFind uf(n);
    rep(i, q) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            uf.unite(x, y);
        }
        else {
            cout << uf.same(x, y) << endl;
        }
    }
}

Measured memory_bytes: 3320
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    vl a,b;
    rep(i,n)
    {
        ll l,r;
        cin>>l>>r;
        a.pb(l);
        b.pb(r);
    }
    sort(all(b));
    sort(all(a));
    reverse(all(a));
    ll ans=0,pos=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>pos)
        {
            ans+=(a[i]-pos);
            pos=a[i];
        }
        if(pos>b[i])
        {
            ans+=(pos-b[i]);
            pos=b[i];
        }
    }
    ans+=abs(pos);
    ll out=ans;
    {
        ll ans=0,pos=0;
        for(int i=0;i<n;i++)
        {
            if(pos>b[i])
            {
                ans+=(pos-b[i]);
                pos=b[i];
            }
            if(a[i]>pos)
            {
                ans+=(a[i]-pos);
                pos=a[i];
            }
        }
        ans+=abs(pos);
        out=max(out,ans);
    }
    cout<<out<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

long long n,a[200005],b[200005],rez;

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

    cin>>n;
    for(long long i=0;i<n;i++)
        cin>>a[i];
    for(long long i=0;i<n;i++)
        cin>>b[i];

    for(long long i=0;i<30;i++)
    {
        long long a1[n],b1[n],t=(1<<i),cnt=0;
        for(long long j=0;j<n;j++)
        {
            a1[j]=a[j]%(2*t);
            b1[j]=b[j]%(2*t);
        }
        sort(a1,a1+n);
        sort(b1,b1+n);
        for(long long j=0;j<n;j++)
        {
            long long p1=lower_bound(a1,a1+n,t-b1[j])-a1;
            long long p2=lower_bound(a1,a1+n,2*t-b1[j])-a1;
            long long p3=lower_bound(a1,a1+n,3*t-b1[j])-a1;
            long long p4=lower_bound(a1,a1+n,4*t-b1[j])-a1;
            cnt+=max((long long)0,p2-p1)+max((long long)0,p4-p3);
        }
        if(cnt%2==1)
            rez+=t;
    }

    cout<<rez<<endl;

    return 0;
}


Measured memory_bytes: 9880
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int) (n);i++)
int main() {
	int n;
	cin >> n;
	vector<char>s(n);
	rep(i, n)cin >> s[i];

	int count = 0;
	rep(i, n) {
		char a, b;
		a = s[i];
		b = s[i - 1];
		if (a!=b)count++;
	}

	cout << count;
}

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

#define PI 3.14159265359
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
typedef long long int ll;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

bool prime[10000010];
inline void sieve(){
	prime[0]=prime[1]=0;
	for(int i=2;i<10000010;i++)
		prime[i]=1;
	for(int i=2;i<sqrt(10000010);i++){
		if(prime[i]==1){
			for(int j=i*i;j<10000010;j+=i)
				prime[j]=0;
		}
	}
}

inline bool isPrime(ll n){
    if (n <= 1)
        return false; 
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}

inline int toInt(string s){
	//return atoi(s.c_str());
	int x=(int)s[0]-48;
	return x;
}

inline int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

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

inline bool isLeap(int yy){
	return ((yy%4 == 0 && yy%100 != 0) || yy%400 == 0);
}

int n,k,l;
vector<int> E1[200005],E2[200005];
int C1[200005],C2[200005];
bool check[200005];
map<pair<int,int>,int> M;

void dfs1(int v,int c){
    C1[v]=c;
    check[v]=true;
    for(auto u: E1[v]){
        if(!check[u])
            dfs1(u,c);
    }
}

void dfs2(int v,int c){
    C2[v]=c;
    check[v]=true;
    for(auto u: E2[v]){
        if(!check[u])
            dfs2(u,c);
    }
}   

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);	
	
    cin >> n >> k >> l;
    FOR(i,0,k){
        int a,b;
        cin >> a >> b;
        a--,b--;
        E1[a].pb(b);
        E1[b].pb(a);
    }
    
    memset(check,false,sizeof(check));
    int cc=0;
    
    FOR(i,0,n){
        if(!check[i])
            dfs1(i,cc++);
    }

    FOR(i,0,l){
        int a,b;
        cin >> a >> b;
        a--,b--;
        E2[a].pb(b);
        E2[b].pb(a);
    }

    memset(check,false,sizeof(check));
    cc=0;

    FOR(i,0,n){
        if(!check[i])
            dfs2(i,cc++);
    }

    FOR(i,0,n)
        M[mp(C1[i],C2[i])]++;
    FOR(i,0,n)
        cout << M[mp(C1[i],C2[i])] << " ";
    cout << endl;

    //cerr << tick();

	return 0;
}



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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	vi vec(105);
	for (int i = a; i < b; i++) {
		vec[i]++;
	}

	for (int i = c; i < d; i++) {
		vec[i]++;
	}

	int res = 0;
	int cnt = 0;
	for (int i = 0; i < vec.size(); i++) {
		
		if (vec[i] == 2) {
			cnt++;
		} else {
			res = max(res, cnt);
			cnt = 0;
		}
	}

	cout << res << endl;
	return 0;
}

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



int main(){
  ios_base::sync_with_stdio(false);

  int n;
  int a[111];
  int alice, bob;

  alice = bob = 0;

  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a, a+n, greater<int>());
  for(int i=0;i<n;i++){
    if(i%2 == 0){
      alice += a[i];
    } else {
      bob += a[i];
    }
  }

  cout << (alice - bob) << endl;

  return 0;
}

Measured memory_bytes: 256
x=[1,3,5,7,8,10,12]
y=[4,6,9,11]
z=[2]
l,r=map(int,input().split())
if(l in x and r in x):
    print("Yes")
elif(l in y and r in y):
    print("Yes")
elif(l in z and r in z):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61888