akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

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

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int& x : A) cin >> x;
    vector<int> sumL(N), sumR(N);
    sumL[0] = A[0];
    for (int i = 1; i < N; i++) sumL[i] = gcd(A[i], sumL[i - 1]);
    sumR[N - 1] = A[N - 1];
    for (int i = N - 2; i >= 0; i--) sumR[i] = gcd(A[i], sumR[i + 1]);
    int res = 0;
    for (int i = 0; i < N; i++) {
      int g = 0;
      if (i > 0) g = gcd(g, sumL[i - 1]);
      if (i < N - 1) g = gcd(g, sumR[i + 1]);
      res = max(res, g);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int a,b;
  cin>>s;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='A'){
      a=i+1;
   	  break;
    }
  }
  for(int i=0;i<s.size();i++){
  	if(s[s.size()-i]=='Z'){
      b=s.size()-i+1;
      break;
    }
  }

  cout<<b-a+1<<endl;
}


Measured memory_bytes: 640
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fact,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		long m = sc.nextLong();
		long[] a = new long[n];
		for(int i=0;i<n;++i) a[i] = sc.nextLong();
		sort(a);
		// finding mth greatest pair value 
		    long low = 0,high = MAX;
		    while(high - low > 1){
		       long mid = (low + high) / 2;
		        if(check(mid, n, a, m)) low = mid;
		        else high = mid;
		    }
		   
		    long ans = 0,sum=0,cnt=0;
		    int j = 0;
		    for(int i =0; i<n; i++){
		        while(j < n && cnt < m && a[i] + a[n-1-j] >= low){
		            sum += a[n-1-j];
		            j++;
		        }
		        cnt += j;
		        ans += sum + a[i]*j;
		    }
		   
		    if(cnt > m) ans -= low*(cnt-m);
		    out.print(ans);
		
		out.close();
	}
	private static boolean check(long mid, int n, long[] a, long m) {
		long sum = 0;
	    int j = 0;
	    for(int i =0; i<n; i++){
	        while(j < n && a[i] + a[n-1-j] >= mid) j++;
	        sum += j;
	    }
		return sum >= m;
	}
	
	 static void sort(long[] A) {
         PriorityQueue<Long> pq = new PriorityQueue<>();
         int i = 0;
         for (i = 0; i < A.length; i++)
             pq.add(A[i]);
         for (i = 0; i < A.length; i++)
             A[i] = pq.poll();
     }
	 
	
}

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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

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

using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int a, b;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> a; cin >> b;
    if(b % a == 0) cout << a+b << "\n";
    else cout << b-a << "\n";
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
#import collections
# c = collections.Counter()
#import itertools as it
#import math
#import numpy as np
#import sys 
#sys.exit()
 
k = input()
s = input()
#k = int(input())
#a, b  = map(int, input().split())
'''
#  = list(map(int, input().split()))
'''
'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
 
#-------------------------------#
#len(t)==len(s)+1
#print(t[0:-1])
if int(k)>=int(len(s)):
	print(s)
else:
    t=[s[0:int(k)]]
    t.append('...')
    u = ''.join(t)
    print(u)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
using namespace std;

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

int main(void) {
  long long int n;
  cin >> n;
  long long int a;
  long long int i, ans;
  cin >> ans;
  for (i = 1; i < n; i++) {
    cin >> a;
    ans = gcd(ans , a);
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,a[100002],dp[100002];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    dp[1]=0;
    dp[2]=fabs(a[2]-a[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+fabs(a[i]-a[i-1]),dp[i-2]+fabs(a[i]-a[i-2]));
    }
    printf("%d",dp[n]);
    return 0;
}


Measured memory_bytes: 1024
S = input()
T = input()
ans = 1001
for i in range(len(S)-len(T)+1):
	cnt = 0
	a = S[i:i+len(T)]
	for j in range(len(T)):
		if a[j]!=T[j]:
			cnt+=1
	ans = min(ans,cnt)
print(ans)







Measured memory_bytes: 73144
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, K;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;

	double ans = 0;
	rep(x, 1, N + 1) {
		int y = x;
		double q = 1.0 / N;
		while (y < K) {
			y *= 2;
			q /= 2;
		}
		ans += q;
	}
	printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    ll d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

int n, a[4];
vector<vector<vector<double>>> dp;

double solve(int x, int y, int z) {
	if (x < 0 || y < 0 || z < 0) {
		return 0;
	}
	if (x == 0 && y == 0 && z == 0) {
		return 0;
	}
	if (dp[x][y][z] != -1.0) {
		return dp[x][y][z];
	}
	int rem = x + y + z;
	double value = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1);
	return dp[x][y][z] = value / rem;
}

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

	cin >> n;
	dp.resize(n + 1);
	for (int i = 0; i <= n; i++) {
		dp[i].resize(n + 1);
		for (int j = 0; j <= n; j++) {
			dp[i][j].resize(n + 1, -1.0);
		}
	}
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[x]++;
	}
	double answer = solve(a[1], a[2], a[3]);
	cout << fixed << setprecision(12) << answer;

	return 0;
}

Measured memory_bytes: 216192
s=input()

cnt = 0
for i in range(len(s)):
    if (i % 2 == 1 and s[i] == 'R') or (i % 2 == 0 and s[i] == 'L'):
        cnt = 1
        break
    
if cnt:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int n,x;
    cin >> n >> x;
    int m[n];
    int minm = 1001;
    int summ = 0;
    for(int i = 0;i<n;i++){
        cin >> m[i];
        summ+=m[i];
        minm = min(minm,m[i]);
    }
    cout << n+(x-summ)/minm << endl;
}

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

bool topological_sort(const vector< vector<int> >& g, vector<int>& res){
    const int v = (int)g.size();
    res.clear();

    vector<int> deg(v, 0);
    for(int i = 0 ; i < v ; ++i){
        for(auto to : g[i]){
            ++deg[to];
        }
    }

    vector<int> st;
    for(int i = 0 ; i < v ; ++i){
        if(deg[i] == 0){
            st.emplace_back(i);
        }
    }

    while(!st.empty()){
        int k = st.back();
        st.pop_back();
        res.emplace_back(k);
        for(auto to : g[k]){
            --deg[to];
            if(deg[to] == 0){
                st.emplace_back(to);
            }
        }
    }

    return (int)res.size() == v;
}

#include<iostream>
#include<cassert>

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;

    vector< vector<int> > g(n);
    for(int i = 0 ; i < n - 1 + m ; ++i){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
    }

    vector<int> v;
    assert(topological_sort(g, v));

    vector<int> dp(n, -1);
    vector<int> prev(n, -1);
    dp[v[0]] = 0;

    for(int i = 0 ; i < n - 1 ; ++i){
        for(auto to : g[v[i]]){
            if(chmax(dp[to], dp[v[i]] + 1)){
                prev[to] = v[i];
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 7536
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  int num,m,t;
  cin >> num >> m >> t;
  int f;
  cin >> f;
  int res=f-m;
  int then=f;
  for(int i=1;i<num;i++)
  {
    int a;
    cin >> a;
    if(a-then>2*m)
      res+=a-then-2*m;
    then=a;
  }
  cout << res+max(0,t-then-m) << endl;
}

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



Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<ctime>
#include<cstdlib>
#include<numeric>
#include <typeinfo>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
const int inf=1e8;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009

int main(){
	int n;
	cin>>n;
	int a[n];
	loop(i,0,n){
		cin>>a[i];
	}
	loop(i,1,n){
		cout<<a[0];
		loop(i,1,n){
			cout<<" "<<a[i];
		}
		cout<<"\n";
		int v=a[i];
		int j=i-1;
		while(j>=0&&a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
	}
	cout<<a[0];
	loop(i,1,n){
		cout<<" "<<a[i];
	}
	cout<<"\n";
}

Measured memory_bytes: 3084
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		String s = sc.next();
		int n = s.length() - 1;
		
		long ans = 0L;
		for (int i=0; i<Math.pow(2,n); i++) {
			
			//ビット全探索で文字列Sに"+"を挿入していく
			StringBuilder sb = new StringBuilder(s);
			for (int j=n-1; j>=0; j--) {
				if ((1&i>>j) == 1) {
					sb.insert(j+1,"+");
				}
			}
			
			//"+"入りの文字列をsplitして足し合わせる
			String[] ar = sb.toString().split("\\+",0);
			for (int j=0; j<ar.length; j++) {
				ans += Long.parseLong(ar[j]);
			}

		}
		
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 24788
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;

  int count = 0;

  if(N > K){
    count += K * X;
    count += (N-K) * Y;
  }else{
    count += N * X;
  }
  cout << count << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d = 0, e = 0, count = 0;
	cin >> a >> b >> c;
	if (a > c) {
		cout << "NO" << endl;
	}
	else if (a + b < c) {
		cout << "NO"<<endl;
	}
	else { cout << "YES" << endl; }
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int i, m, tail = INT_INF, cnt = 1;
	cin >> m >> m;
	vector<pair<int, int>> r(m);
	for (i = 0; i < m; i++) cin >> r[i].first >> r[i].second;
	sort(full(r));
	for (i = 0; i < m; i++) {
		tail = min(tail, r[i].second);
		if (r[i].first >= tail) {
			cnt++;
			tail = r[i].second;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
int main()
 
{
  int a,b,c,d,n;
  
  cin >> n;
  
  a = n / 1000;
  b = (n % 1000) / 100;
  c = (n % 100) / 10;
  d = n % 10;
  
  if (a == b && b == c && c == d){
	cout << "Yes" << endl;
  }else if ((a == b && b == c) || (b == c && b == d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
    return 0;
  }

Measured memory_bytes: 256
n,m=map(int, input().split())
cnt = [0]*m
for i in range(n):
    like = list(map(int, input().split()))
    k = like.pop(0)
    for j in like:
        cnt[j-1] += 1

all_like=0
for _ in cnt:
    if _ == n:
        all_like += 1
print(all_like)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define pii pair<ll,ll>
#define ff first
#define ss second
#define mxx 100005
#define endl "\n"
const ll mod=1e9+7;

ll a=1e18;

int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    if(k<=a)
    {
        cout<<k<<endl;
    }
    else
    {
        ll ans=a;
        k-=a;
        if(k<=b)
            cout<<ans<<endl;
        else
        {
            k-=b;
            ll p=min(k,c);
            cout<<ans-p<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

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

void chmax(int &l, int r){if(l<r)l=r;}

int main(){

  int n, d, x; cin>> n>> d>> x;
  int p[d][n];
  rep(i, d)rep(j, n) cin>> p[i][j];

  const int M=100005;
  rep(i, d-1){
    // dp[j][k]:=i日目、種類jまで見て、k円持ってるときの、翌日の所持金の最大
    int dp[n+1][M];
    rep(i, n+1)rep(j, M) dp[i][j]=0;    
    for(int k=0; k<=x; k++) dp[0][k]=k; // ?
    rep(j, n){
      for(int k=0; k<=x; k++){
        chmax(dp[j+1][k], dp[j][k]);
        if(k-p[i][j]>=0){
          chmax(dp[j+1][k], dp[j+1][k-p[i][j]]+p[i+1][j]);
        }
      }
    }
    int y=0;
    for(int k=0; k<=x; k++) chmax(y, dp[n][k]);
    x=y;
  }

  cout<< x<< endl;

  return 0;
}


Measured memory_bytes: 7392
using System;

class Swapping_Two_Numbers
{
    public static void Main()
    {
        while (true)
        {
            string number_str = Console.ReadLine();
            string[] tmp_number = number_str.Split(' ');
            int a = int.Parse(tmp_number[0]);
            int b = int.Parse(tmp_number[1]);

            if (a == 0 && b == 0) break;


            if (a > b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            Console.WriteLine("{0} {1}", a, b);
        }
    }
}

Measured memory_bytes: 9312
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
int N, M;
double diffSum[20][20];
double ans = 0.0;
double calc(double a,double b)
{
	return (a - b) * (a - b);
}
void dfs(int ite,vector<int> &v)
{
	if (ite >= N && v.size() == M)
	{
		double sum = 0.0;
		for (int i = 0; i < v.size() - 1;i++)
		{
			for (int j = i + 1; j < v.size();j++)
			{
				sum += diffSum[v[i]][v[j]];
			}
		}
		ans = max(ans,sum);
		return;
	}

	if (ite >= N)return;

	dfs(ite + 1,v);
	v.push_back(ite);
	dfs(ite + 1,v);
	v.pop_back();
}
int main()
{
	cin >> N >> M;
	double L[20];
	double a[20];
	double b[20];
	for (int i = 0; i < N; i++)
	{
		cin >> L[i] >> a[i] >> b[i];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (i == j)continue;
			diffSum[i][j] = calc(L[i], L[j]) + calc(a[i], a[j]) + calc(b[i], b[j]);
			diffSum[j][i] = diffSum[i][j];
		}
	}
	vector<int> v;
	if(M != 0)dfs(0, v);
	printf("%.6f\n", ans);
	return 0;
}

Measured memory_bytes: 1272
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end


n = gi

ans = 0
while n!=0
  l=0
  k=0
  if n>=0
    l+=1 while (4**l-1)/3<n
    ans += 2**((l-1)*2)
    n -= 2**((l-1)*2) if l!=0
  else
    l+=1 while (4**l-1)*2/3<n.abs #lは1の個数
    ans += 2**(l*2-1)
    n += 2**(l*2-1) if l!=0
  end
end

puts ans.to_s 2


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

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

  int ptr = 0;
  int ans = 0;
  while (ptr < N) {
    int cc = A.at(ptr);
    int f = 0;

    // 自分自身を1枚目と計算する
    while (ptr < N && A.at(ptr) == cc) {
      f++;
      ptr++;
    }

    // 奇数回連続している場合は加算する
    int remainder = f % 2;
    ans += remainder;
  }

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


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 4e5+9;
ll n,k,q,tdfn,tot;
ll dp[50][N],vis[N];
ll B[N],LOG[N],used[N],F[N],pos[N];
vector<pair<ll,ll> > edge[N];
void rmq_init(ll n,ll num[])
{
    ll i,j;
    for(j=1;j<=n;j++) 
        dp[0][j]=num[j];
    for(j=1;j<=LOG[n];j++)
    {
        ll limit=n+1-(1<<j);
        for(i=1;i<=limit;i++)
        {
            ll x=i+(1<<j>>1);
            dp[j][i]=min(dp[j-1][x],dp[j-1][i]);
        }
    }
}
ll rmq(ll l,ll r,ll num[])
{
    ll m=LOG[r-l+1];
    return min(dp[m][l],dp[m][r-(1<<m)+1]);
}
ll sum[N];
void dfs(ll s)
{
    ll i,t;
    used[s]=1;
    ll tmp=++tdfn;
    B[++tot]=tmp;F[tmp]=s;
    pos[s]=tot;
    for(i=0;i<edge[s].size();i++)
    {
        t=edge[s][i].first;
        if(used[t]) continue;
        sum[t]=sum[s]+edge[s][i].second;
        dfs(t);
        B[++tot]=tmp;
    }
}
ll lca(ll a,ll b)
{
    if(pos[a]>pos[b]) swap(a,b);
    ll ans=rmq(pos[a],pos[b],B);
    return F[ans];
}
int main()
{
    ll i,a,b,w;
    LOG[0]=-1;
    for(i=1;i<N;i++)  LOG[i]=LOG[i>>1]+1;
    cin >> n;
    for(i=0;i<=n;i++) edge[i].clear();
    for(i=1;i<n;i++)
    {
        cin >> a >> b >> w;
        edge[a].push_back(make_pair(b,w));
        edge[b].push_back(make_pair(a,w));
    }
    sum[1]=0;
    tdfn=0;
    tot=0;
    memset(used,0,sizeof(used));
    dfs(1);
    rmq_init(tot,B);
    cin >> q >> k;
    while(q--)
    {
        cin >> a >> b;
        cout << sum[a]+sum[k]-2*sum[lca(a,k)] + sum[b]+sum[k]-2*sum[lca(b,k)] << endl;
    }
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (((A == B) && (B == C)) || ((A != B) && (A != C) && (B != C))){
    cout << "No";
  }
  else {
    cout << "Yes";
  }
}

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

int main(){
    char s[5];
    scanf("%s",s);
    if (strcmp(s,"SUN") == 0){
        printf("7\n");
    } else if (strcmp(s,"MON") == 0){
        printf("6\n");
    } else if (strcmp(s,"TUE") == 0){
        printf("5\n");
    } else if (strcmp(s,"WED") == 0){
        printf("4\n");
    } else if (strcmp(s,"THU") == 0){
        printf("3\n");
    } else if (strcmp(s,"FRI") == 0){
        printf("2\n");
    } else if (strcmp(s,"SAT") == 0){
        printf("1\n");
    }
    //printf("%s\n",s);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n,y;
  cin>>n>>y;
  y/=1000;
  rep(i,0,n+1){
    rep(j,0,n+1){
      int z=y-i*10-j*5;
      if((i+j+z)==n && z>=0){
        cout<<i<<" "<<j<<" "<<z<<endl;
        return;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

vll  enumeration;
// 全列挙用の関数
void func(ll n) {
    if (n < 1e9) {
        enumeration.push_back(n);
        func(n * 10 + 3);
        func(n * 10 + 5);
        func(n * 10 + 7);
    }
}

int main() {
	// 上限数
    ll N;
    cin >> N;
	// 再帰関数をつかって3,5,7を使った数字の全列挙。
    func(0);

	// 全列挙した数
    int n   = enumeration.size();
    ll  ans = 0;
    rep(i, n) {
		// 全列挙したなかから上限までを調べる
        if (enumeration[i] <= N) {
			// 文字列化
            string S = to_string(enumeration[i]);
			// すべての文字列の中に3,5,7がそれぞれ1回以上現れている条件
            if (find(all(S), '3') != S.end() &&
			    find(all(S), '5') != S.end() &&
                find(all(S), '7') != S.end()) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
while 1:
    h, w = map(int, raw_input().split())
    if h == w == 0: break
    ts = [list(raw_input()) for i in range(h)]
    x = y = 0
    while 1:
        t = ts[y][x]
        ts[y][x] = None
        if t == '>':
            x += 1
        elif t == '<':
            x -= 1
        elif t == 'v':
            y += 1
        elif t == '^':
            y -= 1
        elif t == '.':
            print x, y
            break
        else:
            print 'LOOP'
            break

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
        int n,w;
        cin>>n>>w;
        int aw[n], av[n];
        for(int i=0; i<n; i++)
        {
                cin>>aw[i]>>av[i];
        }
        int dp[100001]={0};
        memset(dp,-1,sizeof(dp));
        dp[0] = 0;
        int ans=0;
        for(int i=0; i<n; i++)
        {
                for(int j=100000; j>=0; j--)
                {
                        if(dp[j]==-1) continue;
                        if(dp[j] + aw[i] <=w)
                        {
                                //cout<<j<<endl;
                                //cout<<j<<endl;
                                if(dp[j+av[i]]!=-1)
                                        dp[j+av[i]] = min(dp[j+av[i]], dp[j]+aw[i]);
                                else
                                        dp[j+av[i]] = dp[j] + aw[i];
                        } 
                }
        }
        for(int i=100000; i>=0; i--)
        {
                //cout<<i<<" "<<dp[i]<<endl;
                if(dp[i]!=-1)
                {
                        cout<<i<<endl;
                        return 0;
                }
        }
        //cout<<ans<<endl;
        return 0;
}

Measured memory_bytes: 1024
n = gets.chomp.to_i#.split(" ").map(&:to_i)
ary = gets.chomp.split(" ").map(&:to_i)
res = 3**n
r = 1
ary.each do |x|
  if x%2 == 0
    r = r*2
  end
end
puts res-r

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AthleteProgramming2
{
    class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int replacementCount = 0;
            replacementCount = SelectionSort(N, array);
            for(int i = 0; i < N - 1; i++)
            {
                Console.Write("{0} ",array[i]);
            }
            Console.WriteLine(array[N-1]);
            Console.WriteLine(replacementCount);
        }

        static int SelectionSort(int N, int[] array)
        {
            int replacementCount = 0;
            for (int i = 0; i < N - 1; i++)
            {
                int minj = i;
                for (int j = i; j < N; j++)
                {
                    if (array[j] < array[minj])
                    {
                        minj = j;
                    }
                }
                if (minj != i)
                {
                    replacementCount++;
                    Swap(ref array[minj], ref array[i]);
                }
            }
            return replacementCount;
        }

        static void Swap(ref int a,ref int b)
        {
            int tmp = a;
            a = b;
            b = tmp;
        }

    }
}

Measured memory_bytes: 9680
import scala.collection.mutable.Queue

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  var h = sc.nextInt()
  val (a, b) = List.fill(n)((sc.nextInt(), sc.nextInt())).unzip
  val aMax = a.max
  var q = Queue.from(b.filter(_ > aMax).sorted.reverse)

  var ans = 0
  while (h > 0) {
    if (q.nonEmpty) {
      h -= q.dequeue()
      ans += 1
    } else {
      ans += (h + aMax - 1) / aMax
      h = 0
    }
  }
  println(ans)
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct dice{ int a[6]; };
void rot(int &a,int &b,int &c,int &d){ int tmp=a; a=b; b=c; c=d; d=tmp; }
void roll_f(dice &d){ rot(d.a[0],d.a[3],d.a[2],d.a[1]); }
void roll_b(dice &d){ rot(d.a[0],d.a[1],d.a[2],d.a[3]); }
void roll_l(dice &d){ rot(d.a[3],d.a[5],d.a[1],d.a[4]); }
void roll_r(dice &d){ rot(d.a[3],d.a[4],d.a[1],d.a[5]); }

bool vis[101][101][7][7][7]; // 0,3,5

struct state{
	int i,j;
	dice d;
};

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

  int h,w;
  cin>>h>>w;

  vector<string> b(h);
  rep(i,h)cin>>b[i];

  dice ini;
  ini.a[0]=2; ini.a[1]=6; ini.a[2]=5; ini.a[3]=1; ini.a[4]=4; ini.a[5]=3;
  queue<state> que;
  que.push((state){0,0,ini});
  vis[0][0][ini.a[0]][ini.a[3]][ini.a[5]]=true;
  while(que.size()){
  	state s=que.front(); que.pop();
  	dice crt=s.d;
  	int i=s.i,j=s.j;
  	if(i+1<h&&b[i+1][j]!='#'){
  		roll_f(crt);
  		if(crt.a[1]==b[i+1][j]-'0'&&!vis[i+1][j][crt.a[0]][crt.a[3]][crt.a[5]]){
  			vis[i+1][j][crt.a[0]][crt.a[3]][crt.a[5]]=true;
  			que.push((state){i+1,j,crt});
  		}
  		roll_b(crt);
  	}
  	if(i-1>=0&&b[i-1][j]!='#'){
  		roll_b(crt);
  		if(crt.a[1]==b[i-1][j]-'0'&&!vis[i-1][j][crt.a[0]][crt.a[3]][crt.a[5]]){
  			vis[i-1][j][crt.a[0]][crt.a[3]][crt.a[5]]=true;
  			que.push((state){i-1,j,crt});
  		}
  		roll_f(crt);
  	}
  	if(j+1<w&&b[i][j+1]!='#'){
  		roll_r(crt);
  		if(crt.a[1]==b[i][j+1]-'0'&&!vis[i][j+1][crt.a[0]][crt.a[3]][crt.a[5]]){
  			vis[i][j+1][crt.a[0]][crt.a[3]][crt.a[5]]=true;
  			que.push((state){i,j+1,crt});
  		}
  		roll_l(crt);
  	}
  	if(j-1>=0&&b[i][j-1]!='#'){
  		roll_l(crt);
  		if(crt.a[1]==b[i][j-1]-'0'&&!vis[i][j-1][crt.a[0]][crt.a[3]][crt.a[5]]){
  			vis[i][j-1][crt.a[0]][crt.a[3]][crt.a[5]]=true;
  			que.push((state){i,j-1,crt});
  		}
  		roll_r(crt);
  	}
  }

  bool res=false;
  rep(x,7)rep(y,7)rep(z,7){
  	res|=vis[h-1][w-1][x][y][z];
  }
  if(res)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}



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

void Main()
{
    int n, r;
    cin >> n >> r;
    if(n > 10)
        cout << r << endl;
    else
        cout << r + 100*(10-n) << endl;

    // R = Q - 100*(10-N)
    // Q = R + (100*(10-N))
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n, m) for(int i = n; i >= m; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin >> N;

  int p[N];

  int ct=0;

  rep(i,N){
    cin>>p[i];
    if(i+1!=p[i]) ct++;
  }

  cout << (ct>=3 ? "NO" : "YES") <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <vector>
#include <algorithm>
#define inf INT_MAX/2
using namespace std;
int ok[100][100];
int main() {
    int n; scanf("%d",&n);
    for (int i=0; i<n; i++) for (int j=0; j<n; j++) ok[i][j]=inf;
    for (int i=0; i<n; i++) {
        int r,k; scanf("%d%d",&r,&k);
        for (int j=0; j<k; j++) {
            int t; scanf("%d",&t);
            ok[r-1][t-1]=1;
        }
    }
    for (int k=0; k<n; k++) {
        for (int i=0; i<n; i++) {
            for (int j=0; j<n; j++) {
                ok[i][j]=min(ok[i][j],ok[i][k]+ok[k][j]);
            }
        }
    }
    int p; scanf("%d",&p);
    for (int i=0; i<p; i++) {
        int s,d,v; scanf("%d%d%d",&s,&d,&v);
        if (v<=ok[s-1][d-1]) puts("NA");
        else printf("%d\n",ok[s-1][d-1]+1);
    }
}

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

const int N = 1e5+10;
struct edge{ int to,cost; };
vector<edge> G[N];
int d[N];

void dfs(int s,int prev,int dis){
  d[s] += dis;
  for(int i = 0; i < G[s].size(); i++){
    if(G[s][i].to != prev) dfs(G[s][i].to,s,dis + G[s][i].cost);
  }
}

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int a,b,c; cin >> a >> b >> c;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }

  int q,k; cin >> q >> k;
  dfs(k,-1,0);
  for(int i = 0; i < q; i++){
    int x,y; cin >> x >> y;
    cout << d[x] + d[y] << endl;
  }

  return 0;
}


Measured memory_bytes: 15872
#include <stdio.h>

int main(int argc, char *argv[]){
  int prime_table[60002];
  int i,j,n;
  int under = 0,upper = 0;
  
  for(i = 0;i < 60001; ++i){
    prime_table[i] = 1;
  }

  prime_table[0] = prime_table[1] = 0;
  
  for(i = 2;i < 245; ++i){

    if(prime_table[i] == 0){continue;}
    
    for(j = i;j < 60001; ++j){
      if(i != j && (j%i == 0)){
	prime_table[j] = 0;
      }
    }
  }

  while(scanf("%d",&n) != EOF){
    for(i = 2;i < 60001; ++i){
      if(prime_table[i] == 1){
	if(i < n){
	  under = i;
	}else if(i > n){
	  upper = i;
	  break;
	}
      }
    }

    printf("%d %d\n",under,upper);
    
  }
  
  return 0;    
}

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

int main(){

    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h, vector<char>(w));
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            cin >> c.at(i).at(j);
        }
    }

    vector<vector<char>> cc(2*h, vector<char>(w));
    int idx = 0;
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            cc.at(idx).at(j) = c.at(i).at(j);
            cc.at(idx+1).at(j) = c.at(i).at(j);
        }
        idx += 2;
    }

    for (int i=0; i<2*h; i++){
        for (int j=0; j<w; j++){
            cout << cc.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int a, b, k;
    cin>>a>>b>>k;

    int r = -1;
    rep(i, k) {
        r = a + i;
        if (r > b) {
            break;
        }
        cout<<r<<endl;
    }
    rep(i, k) {
        int l = b - k + i + 1;
        if (l <= r) continue;
        cout<<l<<endl;
    }
}

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

const int MAX_N = (int)100 + 5;

int n, a[2][MAX_N];

int tilln0, tilln1;
int whole1;
vector<int> costs;

int main(void){
  // Here your code !
  scanf("%d", &n);
  for (int i = 0; i < 2; ++i) for (int j = 0; j < n; ++j) {
    scanf("%d", &a[i][j]);
  }

  for (int i = 0; i < n; ++i) {
    whole1 += a[1][i];
  }

  tilln0 = 0;
  tilln1 = 0;
  // tilln1 = a[1][0];

  for (int i = 0; i < n; ++i) {
    tilln0 += a[0][i];
    int under = whole1 - tilln1 + tilln0;
    costs.push_back(under);
    tilln1 += a[1][i];
  }
  sort(costs.begin(), costs.end(), greater<>());

  printf("%d\n", costs[0]);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int absy(int x){return x>0?x:-x;}

int main(void){
    string po;
    cin >> po;
    int ans=114514;
    for(int i=0;i<po.size()-2;i++){
        if(ans>absy((po[i]-'0')*100+(po[i+1]-'0')*10+(po[i+2]-'0')-753))ans=absy((po[i]-'0')*100+(po[i+1]-'0')*10+(po[i+2]-'0')-753);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    veci dir(4);
    REP(i,N) {
        if(S[i] == 'N') dir[0] = 1;
        else if(S[i] == 'S') dir[1] = 1;
        else if(S[i] == 'E') dir[2] = 1;
        else if(S[i] == 'W') dir[3] = 1;
    }
    if(dir[0] == dir[1] && dir[2] == dir[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

long long N;
long long res;

void solve(long long now,long long &res,long long cnt){
    if(now<=N){
        if(cnt == 0b111)res++;
    }
    else return;

    solve(now*10+3, res, cnt | 0b001);
    solve(now*10+5, res, cnt | 0b010);
    solve(now*10+7, res, cnt | 0b100);
}

int main(){
    cin>>N;
    res = 0;
    solve(0,res,0);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
  int  N;
  cin >> N;
  
  
  vector<long long int> V(N);
  map<int,int> m;
  for(int i = 0; i < N; i++){
    long long int a;
    cin >> a;
    V[i] = a;
    m[a]++;
  }
  
  sort(V.begin(), V.end(), greater<long long int>());
  
  long long int l = 0LL, s = 0LL;
  for(int i = 0; i < N; i++){
    if(m[V[i]] < 2) continue;
    else{
      l = V[i];
      m[V[i]] -= 2;
      break;
    }
  }
  
  for(int i = 0; i < N; i++){
    if(m[V[i]] < 2) continue;
    else{
      s = V[i];
      m[V[i]] -= 2;
      break;
    }
  }
  cout << l * s;
}


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

int dp[450][450];

int main() {
	int n, m1, m2; scanf("%d%d%d", &n, &m1, &m2);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	rep(i, n) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		for (int j = 400; j >= 0; j--)for (int k = 400; k >= 0; k--) {
			dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
		}
	}
	int Min = INF;
	for (int i = 1; i*m1 <= 400 && i*m2 <= 400; i++)
		Min = min(Min, dp[m1*i][m2*i]);
	if (Min == INF)puts("-1");
	else printf("%d\n", Min);
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(void)
{
    int n,x;
    int S[10000];
    int cprime=0;
    int num=0;
    int flag=1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    while(num<n){
        if(flag==1){
            if(S[num]==1){
                flag=0;
            }
            if((S[num]>2)&&(S[num]%2==0)){
                flag=0;
            }
            if((S[num]>3)&&(S[num]%3==0)){
                flag=0;
            }
            x=3;
            while(x<=(int)sqrt(S[num])){
                if(S[num]%x==0){
                    flag=0;
                }
                x=x+2;
            }
            if(flag==1){
                cprime++;
            }
            num++;
        }
        if(flag==0){
            flag=1;
        }
    }
    printf("%d\n",cprime);
    return 0;
}


Measured memory_bytes: 2036
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n := readInt()
	a := make([]int, n)
	mx := 0
	for i := range a {
		a[i] = readInt()
		if a[i] > mx {
			mx = a[i]
		}
	}

	var (
		dhf = mx
		hf  int
	)
	for _, v := range a {
		if v == mx {
			continue
		}

		if d := abs(v - mx/2); d < dhf {
			dhf = d
			hf = v
		}
	}
	fmt.Println(mx, hf)
}


Measured memory_bytes: 3072
#from https://atcoder.jp/contests/agc037/submissions/6954777
s=input()
p=""
k=i=0
while i<len(s):
    c=s[i]
    if p==c:
        i+=1
        if i==len(s):
            break
        c+=s[i]
    p=c
    k+=1
    i+=1

print(k)

Measured memory_bytes: 41388
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n, vector<int>(n, 0));
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj[a][b] = adj[b][a] = 1;
    }
    vector<int> v(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        v[i] = i + 1;
    }
    int ans = 0;
    do {
        int ok = 1;
        int pre = 0;
        for (int j : v) {
            if (!adj[pre][j]) {
                ok = 0;
                break;
            }
            pre = j;
        }
        ans += ok;
    } while(next_permutation(v.begin(), v.end()));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

const int MAXN = 1e5 + 5;

int n, cnt, sum;
int arr[MAXN], ans[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
        sum += arr[i];
        if (i & 1) 
            cnt += (arr[i] << 1);
    }
    ans[1] = cnt - sum;
    for (int i = 1; i < n; ++i) {
        ans[i + 1] = (arr[i] << 1) - ans[i];
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d ", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

/////////////         modの計算

int mod = 1000000007;
int mod_adjust(int a) {
	if (a > mod) {
		a %= mod;
		return a;
	}
	if (a < 0) {
		a *= -1;
		a %= mod;
		a = mod - a;
	}
	return a;
}
long long mod_adjust(long long a) {
	if (a > mod) {
		return a % mod;
	}
	if (a < 0) {
		a *= -1;
		a %= mod;
		return mod - a;
	}
	return a;
}
int mod_add(int a, int b) {
	a = mod_adjust(a), b = mod_adjust(b);
	long long k = a % mod; k += b % mod; k %= mod;
	return (int)k;
}
int mod_sub(int a, int b) {
	long long k = mod_adjust((long long)a); k += mod_adjust((long long)b); k %= mod;
	return (int)k;
}
int mod_multi(int a, int b) {
	long long k = mod_adjust((long long)a); k *= mod_adjust((long long)b); k %= mod;
	return (int)k;
}
int mod_div(int a, int b) {
	a = mod_adjust(a), b = mod_adjust(b);

	int X = mod, Y = b, X1 = 1, X2 = 0, Y1 = 0, Y2 = 1;
	while (1) {
		int q = X / Y;
		int r = X - Y * q;
		X1 = mod_sub(X1, mod_multi(q, Y1));
		X2 = mod_sub(X2, mod_multi(q, Y2));

		if (a%r == 0) {
			int k = a / r;
			return mod_multi(X2, k);
		}

		int z;
		z = X1; X1 = Y1; Y1 = z;
		z = X2; X2 = Y2; Y2 = z;
		X = Y; Y = r;
	}
}
int mod_pow(int x, int n) {
	if (n < 0) {
		return mod_pow(mod_div(1, x), -n);
	}
	if (n == 0) {
		return 1;
	}
	if (n == 1) {
		return x;
	}
	if (n % 2 == 0) {
		int k = mod_pow(x, n / 2);
		return mod_multi(k, k);
	}
	else {
		int k = mod_pow(x, n / 2);
		return mod_multi(mod_multi(k, k), x);
	}
}
int mod_combination(int n, int r) {
	int a = 1, b = 1;
	for (int i = 0; i < r; i++) {
		a = mod_multi(a, n - i);
		b = mod_multi(b, i + 1);
	}
	return mod_div(a, b);
}


int main() {
	long long N; cin >> N;
	long long *C = new long long[N];

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

	long long *S2 = new long long[N];// 自分が区間の右側だったとしたときの左側の石
	for (long long i = 0; i < N; i++) {
		S2[i] = -1;
	}

	long long prev[200001];

	for (long long i = 0; i < 200001; i++) { prev[i] = -1; }
	for (long long i = 0; i < N; i++) {
		long long c = C[i];
		if (prev[c] == -1 || prev[c] == i - 1) {
			prev[c] = i;
		}
		else {
			S2[i] = prev[c];
			prev[c] = i;
		}
	}

	long long *dp = new long long[N];
	for (long long i = 0; i < N; i++) {
		dp[i] = 0;
	}
	dp[0] = 1;
	for (long long i = 1; i < N; i++) {
		if (S2[i] != -1) {
			dp[i] = mod_adjust(dp[i - 1]) + mod_adjust(dp[S2[i]]);
			dp[i] = mod_adjust(dp[i]);
		}
		else {
			dp[i] = mod_adjust(dp[i - 1]);
		}
	}

	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 7040