akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
// mp::cpp_int
 
 int hell=0;
const int MOD=1000000007;
const int MOD1=1000000007;
 
int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a%hell;
  int t=power(a,b/2);
  t*=t;
  t%=hell;
   if(b&1)
   {
       t*=a;
       t%=hell;
   }
   return t;
 
}
 
void EE(int a, int b, int& x, int& y)
{
    if(a%b == 0)
    {
        x=0;
        y=1;
        return;
    }
    EE(b,a%b,x,y);
    int temp = x;
    x = y;
    y = temp - y*(a/b);
}
 
 
int inverse(int a)
{
    int x=0,y=0;
    int m=hell;
    EE(a,m,x,y);
    if(x<0) x +=MOD*m;
    x%=m;
    return x;
}
 
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){
    a=a*x;
    }
  return a;
}
 
 
int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}
int dig(int a)
{
  int sum=0;
  while(a!=0)
  {
    sum+=a%10;
    a/=10;
  }
  
} 


 
int solve()
{  

int n;
cin>>n;
vi a(n);
rep(i,0,n)cin>>a[i];
sort(all(a));

int x=n/2;
cout<<a[x]-a[x-1];

  return 0;
}
 
 
signed main()
{  int t=1;
 
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);                                                                    
 
 
  
 
//pri();
 
  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
 
  //cin>>t;
 
    int k=1;
   while(t--)
     {
      // cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
      //cout<<endl;
     }
 
         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
     // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
        var a, b int
        fmt.Scanf("%d %d\n", &a, &b)

        const row, col = 40, 100
        grid := make([][]byte, row)
        for i := range grid {
                grid[i] = make([]byte, col)
        }

        for i := 0; i < row/2; i++ {
                for j := range grid[i] {
                        grid[i][j] = '#'
                }
        }
        for i := row / 2; i < len(grid); i++ {
                for j := range grid[i] {
                        grid[i][j] = '.'
                }
        }
        a--
        b--

        i, j := 0, 0
        for ; a > 0; a-- {
                grid[i][j] = '.'
                j += 2
                if j >= col {
                        i += 2
                        j = 0
                }
        }
        i, j = row-1, 0
        for ; b > 0; b-- {
                grid[i][j] = '#'
                j += 2
                if j >= col {
                        i -= 2
                        j = 0
                }
        }

        fmt.Printf("%d %d\n", row, col)
        for i := range grid {
                fmt.Println(string(grid[i]))
        }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int sum = -1;
  bool B = true;
  while (B) {
    for (int i = 0; i < N; i++) {
      if (vec.at(i) % 2 == 0) {
        vec.at(i) /= 2;
      }
      else {
        B = false;
      }
    }
    sum += 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=MAX,n;
    cin>>n;
    ll x[n];
    ll ok=0;
    ll ng=101;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for( int p=1;p<=100;p++){
        ll tmp=0;
        for(int i=0;i<n;i++){
            ll v=x[i]-p;
            tmp+=v*v;
        }
        ans=min(ans,tmp);
    }


    cout <<ans<<endl;

    return 0;

}

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

int n;
int c;
string p[5];

int rec(int id,int st,int pos){
  if(id == 10){
    return pos + n;
  }
 
  int res = 10000;
  for(int i=1;i<n;i++){
    if(!((st>>i)&1)){
      int nxt = (st >> i) | c;
      res = min(res,rec(id+1,nxt,pos+i));
    }
  }
  return res;
}

int main(){
  while(cin >> n,n){
    for(int i=0;i<5;i++)cin >> p[i];

    c = 0;
    for(int i=1;i<n;i++){
      bool f = true;
      for(int j=0;j<5;j++){
	for(int k=0;k<n;k++){
	  if(k+i>=n)break;
	  if(p[j][k] == p[j][k+i] && p[j][k] == 'X'){
	    f = false;
	    break;
	  }
	}
	if(!f)break;
      }
      if(!f)c |= 1<<i;
    }

    cout << rec(1,c,0) << endl;
  }
}
      

Measured memory_bytes: 1204
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		for(int i = 1; i <= n; i++) {
			// 3の倍数又は3を含む数字の場合は
			if(i % 3 == 0 || Integer.toString(i).contains("3")) {
				System.out.print(" "+i);
			}
		}
		System.out.println();

	}

}


Measured memory_bytes: 29248
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]
ans = 10**10
for i in range(2 ** N):
    total = 0
    point = [0 for _ in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            total += CA[j][0]
            for k in range(M):
                point[k] += CA[j][k+1]
    f = True
    for j in range(M):
        if point[j] < X:
            f = False
    if f:
        ans = min(ans, total)
if ans != 10 ** 10:
    print(ans)
else:
    print(-1)

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

string s;
int ans, rock, paper;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> s;
    
    for (auto c : s) {
		if (c == 'g') {
			if (paper < rock) {
				ans++;
				paper++;
			} else {
				rock++;
			}
		} else {
			if (paper < rock) {
				paper++;
			} else {
				rock++;
				ans--;
			}
		}
	}
	
	cout << ans;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    string s;
    cin >> s;

    REP(i, s.length()) {
        if ( s[i] == ',' ) {
            cout << " ";
        } else {
            cout << s[i];
        }
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
s = input()
t = input()
present_len = 10000
curr_len = 0
s_len = len(s)
t_len = len(t)
t_chars = list(t)
for i in range(0, (s_len - t_len + 1)):
    j = i
    curr_len = 0
    for k in range(t_len):
        if s[j] != t[k]:
            curr_len += 1
        j += 1
    present_len = min(present_len, curr_len)
print(present_len)

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int D,E;
    while(cin>>D>>E,D||E){
        double mi=1001001001;
        for(int i=0;i<=D;i++){
            int x=i;
            int y=D-i;
            chmin(mi,abs(hypot(x,y)-E));
        }
        printf("%.20f\n",mi);
    }
    return 0;
}

Measured memory_bytes: 3136
#include<iostream> 
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9; 

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

  vector<char>s; 
  char c;
  while(cin.get(c)){ 
    if(c=='\n'){ 
      break; 
    }
    s.push_back(c); 
  }
  int n=s.size();
  n++; 
  vector<int> lsum(n,0); 
  vector<int> rsum(n,0);
  for(int i=0;i<n-1;i++){ 
    if(s.at(i)=='<'){ 
      lsum[i+1]=lsum[i]+1;
    } 
  } 

  for(int i=n-2;i>=0;i--){ 
    if(s.at(i)=='>'){ 
      rsum[i]=rsum[i+1]+1;
    } 
  } 
  long long ct=0; 
  for(int i=0;i<=n;i++){ 
    ct+=max(rsum[i],lsum[i]);
  }
  cout<<ct;






	return 0;
}


Measured memory_bytes: 4856
import sys

def cross(a, b):
    return a.real * b.imag - a.imag * b.real
 
n = sys.stdin.readline()
for line in sys.stdin:
    a, b, c, d = [x + y * 1j for x, y in zip(* [map(float, line.split())] * 2)]
    print('YES' if abs(cross(a - b, c - d)) < 1e-10 else 'NO')

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
/*
given n and three n size array (A, B, C). array[i] means the happiness
find out how can maximize the happiness. p.s. can consecutively same at most 2

A: [10, 20, 30, 50, 50, 500000]
B: [40, 50, 60, 10, 10, 10]
C: [70, 80, 90, 5, 5, 5]

push dp

dp[i] = dp[i-1] + max(A[i], B[i], C[i])

dp[i][ban] => i means the i-th day and ban means A/B/C is banned (A=0, B=1, C=2, no_ban=3)

dp[i+1][x] = max(dp[i+1][x], dp[i][j] + z)

dp[i][ban] = dp[i-1]

ans = max(dp[n-1][0], dp[n-1][1], dp[n-1][2], dp[n-1][3])

*/
int main() {
    int n;
    scanf("%d", &n);
	vector<int> A;
	vector<int> B;
	vector<int> C;
	
	for (int i = 0; i < n; i++) {
	    int a;
	    int b;
	    int c;
	    scanf("%d%d%d", &a, &b, &c);
	    A.push_back(a);
	    B.push_back(b);
	    C.push_back(c);
	}
	
	vector<vector<int>> dp(n+1, vector<int>(3, 0));
	vector<vector<int>> vs = {A, B, C};
	
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j <= 2; j++) {
	        for (int k = 0; k <= 2; k++) {
	            // not banned
	            if (k != j) {
	                if (i+1 <= n) {
	                    // choose to add 1 vs[k], then it is banned
	                    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + vs[k][i]);    
	                }
	                
	            }
	        }
	    }
	}
	
	printf("%d", max({dp[n][0], dp[n][1], dp[n][2]}));
	
	return 0;
}

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c, d, e, f, i, j, k, w, s, W, S, maxs;
  double maxc = 0;
  scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
  for(i = 0; i * a * 100 <= f; i++){
    for(j = 0; (i * a + j * b) * 100 <= f; j++){
      w = (i * a + j * b) * 100;
      maxs = min(f - w, w / 100 * e);
      for(k = 0; k * c <= maxs && k < 30 ; k++){
        s = (maxs - k * c) / d * d + k * c;
        if(maxc <= (double) s * 100 / (w + s)){
          maxc = (double) s * 100 / (w + s);
          W = w; S = s;
        }
      }
    }
  }
  printf("%d %d\n", W+S, S);
}


Measured memory_bytes: 256
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 {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=  new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int num=0;
        if (n > 0) {
            num += n * (n-1)/2;
        } if (m > 0) {
            num +=m * (m-1)/2;
        }
        System.out.println(num);
    }
}


Measured memory_bytes: 22740
<?php
$N = int();
$A = ints();

for($i = 0; $i < $N; $i++){
  $dp[$i] = array_fill(0, $N-$i, 0);
}


for($i = $N-1; $i >= 0; $i--){//左から削る
  $dpi = &$dp[$i];
  $dpip = $dp[$i+1] ?? [];
  for($j = $N-$i-1; $j >= 0; $j--){//右から削る
    $isFirst = (($i+$j)&1) == 0;
    if($j == $N-$i-1){
      $dpi[$j] = $isFirst ? $A[$i] : -$A[$i];
    }else{
      if($isFirst){
        $dpi[$j] = max(
          $dpi[$j+1]+$A[$N-$j-1],
          $dpip[$j]+$A[$i]
        );
      }else{
        $dpi[$j] = min(
          $dpi[$j+1]-$A[$N-$j-1],
          $dpip[$j]-$A[$i]
        );
      }
    }
  }
}

echo $dp[0][0];

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 225912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
char s[N];
int main(){
	scanf("%s",s+1);
	int n  =strlen(s+1);
	s[0] = '0';
	int ans = n;
	for(int i =1;i<=n;i++){
		if(s[i]!=s[i-1])
			ans = min(ans,max(n+1-i,i-1));		
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <cmath>

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")

using namespace std;

int factorical(int x) {
	return x ? x * factorical(x - 1) : 1;
}

//ABC046B - AtCoDeerくんとボール色塗り
//give up
int Main() {
	int N, K;
	int ans = 0;

	cin >> N >> K;

	ans = K * pow((K - 1), N - 1);

	cout << ans;

	return 0;
}


int main()
{
	Main();
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--) 
 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}   
 
signed main(){
    fast;   
    int n, k;
    cin >> n >> k;
    int a[n], d[n+1]={}, b[n]={};
    rep(i,0,n){
        cin >> a[i];
    }
    d[0]=1;
    // b[0]=1;
    int r=0, c=0;
    rep(i,1,n+2){
        if(b[d[i-1]-1]==0){
            d[i]=a[d[i-1]-1];
            b[d[i-1]-1]=1;
        }
        else{
            c=i-1;
            r=d[i-1];
            break;
        }
        // cout << a[d[i-1]--] <<  " " << d[i-1] << " " << endl;
        // cout << d[i] << " ";
    }
    // cout << r <<" ";
    int l=0;
    rep(i,0,n){
        if(r==d[i]){
            l=i;
            break;
        }
    }
    // cout <<endl;
    // cout << c << " "<< l << " ";
    if(k<=c){
        cout << d[k];
    }
    else{
        cout << d[l+1+ (k-l-1)%(c-l)];
    }
}

Measured memory_bytes: 8344
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#define LL long long
#define N 2222
#define int long long
#define reg register
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
int vis[N],ok[N][N],ind[N],a[N];
vector <int> g[N];
int n;
void dfs(int x){
	vis[x]=1;
	for (int i=1;i<=n;++i){
		if (!vis[i] && ok[x][i]){
			ind[i]++;
			g[x].push_back(i);
			dfs(i);
		}
	}
}
void solve(){
	priority_queue <int> q;
	for (int i=1;i<=n;++i){
		if (!ind[i]) q.push(i);
	}
	while (!q.empty()){
		int x=q.top();
		q.pop();
		printf("%lld ",a[x]);
		for (int i=0;i<g[x].size();++i) q.push(g[x][i]);
	}
}
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+1+n);
	for (int i=1;i<=n;++i){
		for (int j=i+1;j<=n;++j){
			if (__gcd(a[i],a[j])!=1){
				ok[i][j]=ok[j][i]=1;
			}
		}
	}
	for (int i=1;i<=n;++i){
		if (!vis[i]) dfs(i);
	}
	solve();
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 37376
// https://atcoder.jp/contests/abc165/tasks/abc165_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int t = 100, cnt = 0;
    while (t < N) {
        t *= 1.01;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3652
fun main(args: Array<String>) {
    readLine()
    val xs = readLine()!!.split(" ").map(String::toInt).sortedDescending()
    // names _, __, ___, ..., are reserved in Kotlin v1.0.0
    val alice = xs.filterIndexed { index, v -> index % 2 == 0 }.sum()
    val bob = xs.filterIndexed { index, v -> index % 2 != 0 }.sum()
    println(alice - bob)
}

Measured memory_bytes: 37652
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<int>>;
using P = pair<int,int>;
//int dy[4] = {-1,0,1,0};
//int dx[4] = {0,-1,0,1};


int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i=0;i<N;i++)
    {
        cin >> h[i];
    }
    
    vector<P> y(N);
    for(int i=0;i<N;i++)
    {
        y[i].first = (i+1) - h[i];
        y[i].second = i+1;
    }
    
    sort(y.begin(),y.end());
    
    long long ans = 0;
    for(int i=0;i<N;i++)
    {
        int a = lower_bound(y.begin(),y.end(),make_pair(h[i] + i+1,i+1)) - y.begin();
        int b = upper_bound(y.begin(),y.end(),make_pair(h[i] + i+1 +1,-1)) - y.begin();
        
        if(b-a != 0)
        {
        ans += b-a;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


/*
int main()
{
    int N;
    cin >> N;
    
    
    return 0;
}
*/

Measured memory_bytes: 5612
#include<stdio.h>
#include<iostream>
#include<vector>

int main(){

  int n, m;
  
  int ans=0;
  
  std::cin>>n>>m;
  
  std::vector<int> okashi;
  //std::vector<int> buff(n);
  std::vector<std::vector<int>> map(n);
  std::vector<int> good(n, 1);
  
  
  //std::cout<<n<<k<<std::endl;
  
  for(int i=0; i<n; i++){
  	
  	int h;
    std::cin>>h;
    
    okashi.push_back(h);
  }
  
  
    
    for(int i0=0; i0<m; i0++){
    	int a1, a2;
      	std::cin>>a1>>a2;
      
      	map[a1-1].push_back(a2-1);
      	map[a2-1].push_back(a1-1);
    }
  
  
  for(int i0=0; i0<n; i0++){
    for(int i1=0; i1<(int)map[i0].size(); i1++){
  		//std::cout<<map[i0][i1];
      	if(okashi[i0] <= okashi[map[i0][i1]]){
        	good[i0]= 0;
        }
      	
    }
    
    //std::cout<<std::endl;
  }
  
  for(int i0=0; i0<n; i0++){
  ans = ans + good[i0];
  }
  
  std::cout<<ans;
  
}

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

int main() {
 string S;
 cin >> S;
 vector<int> ans(S.size()-2);
 for(int i=0;i<S.size()-2;i++){
   string s = "AAA";
   s.at(0)=S.at(i);
   s.at(1)=S.at(i+1);
   s.at(2)=S.at(i+2);
   int x=stoi(s);
  // cout <<x << endl;
   ans.at(i)= max(753,x)- min(753,x);
 }
  sort(ans.begin(),ans.end());
  cout << ans.at(0);
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int result = a + b;
        if (result >= 24) {
            result -= 24;
        }
        System.out.println(result);
    }

}


Measured memory_bytes: 23252
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
res = 0
for i in range(n):
    a = s[:i]
    b = s[i:]
    ss = set(b)
    ans = 0
    sss = set()
    for x in a:
        if x in ss and not x in sss:
            ans += 1
        sss.add(x)
    res = max(res, ans)
print(res)

Measured memory_bytes: 72744
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	s := getNextString(scanner)
	t := getNextString(scanner)
	ans := n << 1
	for i := 0; i < n; i++ {
		if t[0:n-i] == s[i:n] {
			ans -= n - i
			break
		}
	}
	fmt.Println(ans)
	writer.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <math.h>
#include <set>
#include <string>
using namespace std;

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

	vector<vector<int> > h;
	vector<vector<int> > dp;

	dp.resize(N);
	h.resize(N);
	for(int i=0; i<N; i++)
	{
		dp[i].resize(3);
		h[i].resize(3);
		cin>>h[i][0]>>h[i][1]>>h[i][2];
	}
	
	dp[0][0] = h[0][0];
	dp[0][1] = h[0][1];
	dp[0][2] = h[0][2];

	for(int i=1; i<N; i++)
	{
		for(int j=0; j<3; j++)
		{
			vector<int> list;
			for(int k=0; k<3; k++)
			{
				if(j==k)
				{
					continue;
				}
				list.push_back(dp[i-1][k]+h[i][j]);

			}
			dp[i][j] = *max_element(list.begin(),list.end());

		}
	}
	int result = *max_element(dp[N-1].begin(),dp[N-1].end());

	cout<<result<<endl;

	return 0;
}

Measured memory_bytes: 11136
import  java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        String s = sc.next();
        String t = sc.next();
        
        //char[] ans = new char[n*2];
        String ans = new String();
        
        for(int i = 0;i<n;i++)
        {
            ans += s.substring(i,i+1);
            ans += t.substring(i,i+1);
            //System.out.println(s.substring(i,i+1));
            //System.out.println(t.substring(i,i+1));
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
struct node{
	int x,y;
};
char s[110][110];
int dp[110][110];//到第i，j最少变几次，i，j是否变化 
int main()
{
  	int n,m;
  	scanf("%d%d",&n,&m);
  	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
  	memset(dp,0x3f,sizeof(dp));
  	dp[1][1]=(s[1][1]=='#');
  	for(int i=1;i<=n;i++)
  	for(int j=1;j<=m;j++)
  	{
  		if(s[i][j+1]=='.')dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
  		else dp[i][j+1]=min(dp[i][j+1],dp[i][j]+(s[i][j]=='.'));
  		
  		if(s[i+1][j]=='.')dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
  		else dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(s[i][j]=='.'));
  	//	cout<<dp[i][j]<<"  "<<i<<"  "<<j<<" "<<dp[i][j]+(s[i][j]=='.')<<endl;
	}
	cout<<dp[n][m]<<endl;
	return 0;
}
/*
3 3
.##
#.#
### 
*/

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

#define for_(i,a,b) for(int i=a;i<b;++i)

int main() {
	string s; cin >> s;
	int len = s.size();
	
	for_(i,0,len) {
		int id = s[i] - 'A';
		id = (id + 23) % 26;
		char put = 'A' + id;
		cout << put;
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1176
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] n = new int[5];
		for(int i=0; i<N; i++) {
			String s = sc.next();
			if(s.charAt(0) == 'M') {
				n[0]++;
			} else if(s.charAt(0) == 'A') {
				n[1]++;
			} else if(s.charAt(0) == 'R') {
				n[2]++;
			} else if(s.charAt(0) == 'C') {
				n[3]++;
			} else if(s.charAt(0) == 'H') {
				n[4]++;
			}
		}
		
		long count = 0;
		for(int i=0; i<5; i++) {
			int a = n[i];
			for(int j = i+1; j<5; j++) {
				int b = n[j];
				for(int k = j+1; k<5; k++) {
					int c = n[k];
					count += 1L * a*b*c;
				}
			}
		}
		
		
		System.out.println(count);
		
		
		
	}

}


Measured memory_bytes: 59160
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <limits.h>
#include <string.h>
const int N = 2e3+10;
int q[N], cnt=INT_MAX;
struct edge {
	int next, to;
}e[N*2];
int head[N], sum;
inline void add(int x, int y) {
	e[++sum].next = head[x];
	head[x] = sum;
	e[sum].to = y;
}
int h[N];
bool vis[N];
int fa[N];
inline void BFS(int S) {
	std::queue<int> q;
	h[S] = 1;
	fa[S] = 0;
	q.push(S);
	memset(vis, 0, sizeof(vis));
	vis[S] = 1;
	while (!q.empty()) {
		int now = q.front();
//		printf("%d\n", now);
		q.pop();
		for (int i=head[now]; i; i=e[i].next) {
			int to = e[i].to;
			if (to == S) {
				if (h[now]-h[S]+1 < cnt) {
					cnt = 0;
					for (int i=now; i; i=fa[i]) {
						::q[++cnt] = i;
					}
				}
				continue;
			}
			if (!vis[to]) {
				fa[to] = now;
				h[to] = h[now]+1;
				vis[to] = 1;
				q.push(to);
			}
		}
	}
}
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	for (int i=1; i<=m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y);
	}
	for (int i=1; i<=n; i++) {
		BFS(i);
	}
	if (cnt == INT_MAX) {
		printf("-1\n");
		return 0;
	}
	printf("%d\n", cnt);
	for (int i=1; i<=cnt; i++) {
		printf("%d\n", q[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  for(ll i=0;i<n;i++)cin>>b[i];
  ll ans[30];
  for(ll i=0;i<=29;i++){
    ll now=pow(2,i+1);
    vector<ll> va(n),vb(n);
    for(ll j=0;j<n;j++){
      va[j]=a[j]%now;
      vb[j]=b[j]%now;
    }
    sort(va.begin(),va.end());
    sort(vb.begin(),vb.end());
    ll cnt=0;
    for(ll j=0;j<n;j++){
      ll g=va[j];
      if(g<=now/2){
        ll s=lower_bound(vb.begin(),vb.end(),now/2-g)-vb.begin();
        ll t=lower_bound(vb.begin(),vb.end(),now-g)-vb.begin();
        cnt+=t-s;
      }
      else{
        ll s=lower_bound(vb.begin(),vb.end(),now-g)-vb.begin();
        ll t=lower_bound(vb.begin(),vb.end(),now-(g-now/2))-vb.begin();
        cnt+=s+vb.size()-t;
      }
    }
    ans[i]=cnt%2;
  }
  ll sum=0;
  for(ll i=0;i<30;i++)sum+=pow(2,i)*ans[i];
  cout<<sum<<endl;
}

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

constexpr double pi = 3.14159265358979;

int main() {
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double dh = 30.0 * h;
    dh += m * 0.5;
    double dm = 6.0 * m;
    double diff = abs(dh - dm);
    if(diff > 180) {
        diff = 360.0 - diff;
    }
    double x = b * b + a * a - 2 * a * b * cos(diff * pi / 180);
    cout << fixed << setprecision(10);
    cout << sqrt(x) << endl;
    return 0;
}

Measured memory_bytes: 4228
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int maxv = 0;
  for (int i = 1; i < n; i++) {
    map<int, int> first;
    for (int j = 0; j < i; j++) {
      first[s[j] - 'a']++;
    }
    map<int, int> second;
    for (int k = i; k < n; k++) {
      second[s[k] - 'a']++;
    }
    int cnt = 0;
    for (int l = 0; l < 26; l++) {
      if (first[l] && second[l]) {
        cnt++;
      }
    }
    maxv = max(maxv, cnt);
  }
  cout << maxv << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,k,mod=1e9+7;
    cin>>n>>k;
    ll A[200011],B[200011],ans=0;
    A[0]=0;
    B[0]=0;
    rep(i,n+1) (A[i+1]=A[i]+i)%=mod,(B[i+1]=B[i]+n-i+mod)%=mod;
    for(int i=k;i<=n+1;i++) (ans+=B[i]-A[i]+1+mod)%=mod;
    cout<<ans;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> bool chmax(T &a,T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int h,w,ans=0;
    cin>>h>>w;
    Vs s(h);
    VVi yoko(h,Vi(w)),tate(h,Vi(w));
    REP(i,0,h) cin>>s[i];
    
    REP(i,0,h){
        REP(j,0,w){
            if(j>0){
                if(s[i][j]=='.' && yoko[i][j-1]>0){
                    yoko[i][j]=yoko[i][j-1];
                    continue;
                }
            }
            int tj=j,t=0;
            while(s[i][tj]=='.' && tj<w){t++;tj++;}
            yoko[i][j]=t;
        }
    }
    REP(i,0,w){
        REP(j,0,h){
            if(j>0){
                if(s[j][i]=='.' && tate[j-1][i]>0){
                    tate[j][i]=tate[j-1][i];
                    continue;
                }
            }
            int tj=j,t=0;
            while(s[tj][i]=='.'){t++;tj++;if(tj==h)break;}
            tate[j][i]=t;
        }
    }

    
    REP(i,0,h){
        REP(j,0,w){
            if(ans<yoko[i][j]+tate[i][j]-1) ans=yoko[i][j]+tate[i][j]-1;
        }
    }
    cout<<ans<<endl;
}


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

typedef long long int ll;

int main()
{
    ll n ,m;
    cin >> n >> m;
    ll ans = 0;
    if(n * 2 <= m){
        ans = n;
        m -= 2 * n;
    }
    else{
        ans += m / 2;
        m = m % 2;
    }

    ans += m / 4;

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



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


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  long x = 0, sig = 1;
  for (int i = 0; i < n; i++) {
    x += sig * a.at(i);
    sig = -sig;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << x << " ";
    x = -x + 2 * a.at(i);
  }
  cout << x << endl;
}


Measured memory_bytes: 1664
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    
    if((a*b)%2 == 0){
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 21716
def solve():
    ans = 0
    S = input()
    lis = [0]*26
    for s in S:
        lis[ord(s)-ord('a')] += 1
    for i,l in enumerate(lis):
        if l==0:
            ans = chr(ord('a')+i)
            return ans
    return 'None'
print(solve())

Measured memory_bytes: 3188
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

/*
操作 1: ビーカーに水を 100A [g] 入れる。
操作 2: ビーカーに水を 100B [g] 入れる。
操作 3: ビーカーに砂糖を C [g] 入れる。
操作 4: ビーカーに砂糖を D [g] 入れる。
すぬけ君の実験環境下では、水 100 [g] あたり砂糖は E [g] 溶けます。

すぬけ君はできるだけ濃度の高い砂糖水を作りたいと考えています。

ビーカーに入れられる物質の質量 (水の質量と砂糖の質量の合計) が F [g] 以下であり、
*/

int water[3009], sugar[3009];

int main() {
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    A *= 100;
    B *= 100;
    
    for(int i=0; i<=F; i+=A) water[i] = 1;
    for(int i=F; i>=0; i-=100){
        if(water[i]){
            for(int j=i; j<=F; j+=B) water[j] = 1;
        }
    }
    
    for(int i=0; i<=F; i+=C) sugar[i] = 1;
    for(int i=F; i>=0; i--){
        if(sugar[i]){
            for(int j=i; j<=F; j+=D) sugar[j] = 1;
        }
    }
    
    pair<int,int> ans = {A,0};
    double maxv=0;
    for(int s=F; s>0; s--){
        if(sugar[s]){
            for(int w=0; s+w <= F; w+=100){
                if( water[w] && (1.0*E*w)/100 >= s && 1.0*100*s/(s+w) > maxv){
                    maxv = 1.0*100*s/(s+w);
                    ans.first = s+w;
                    ans.second = s;
                }
            }
        }
    }
    
    cout2(ans.first, ans.second);
}

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

using namespace std;

#define INF 0x7fffffff

long N;
long ans = 0;

bool judge(long n) {
  int flag = 0;
  int dig = 0;
  
  while (n != 0) {
    dig = n % 10;
    
    if (dig == 3) {
      flag = flag | 1;
    }
    
    if (dig == 5) {
      flag = flag | 2;
    }
    
    if (dig == 7) {
      flag = flag | 4;
    }
    
    n /= 10;
  }
  
  return flag == 7;
}

void search(long n) {
  if (n > N) {
    return;
  }
  
  if (judge(n)) {
    ans++;
  }
  
  n *= 10;
  search(n + 3);
  search(n + 5);
  search(n + 7);
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pdd              pair<double,double>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.second < b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
    fast;
    ll i,j,n,c=0,d=0,e=0,f=0,g=0,h=0,sum=0,k;
     cin>>k>>n;
     ll a[n];
     vector<ll> b(n);
     vector<ll> p;
     for(i=0;i<n;i++)
     {
         cin>>a[i];
         b[i]=a[i]+k;
         if(i>0)
         {
         sum+=(a[i]-a[i-1]);
         }
     }
     b.insert(b.begin(),a[n-1]);
     p.push_back(sum);
     for(i=0;i<n-1;i++)
     {
         sum-=(a[i+1]-a[i]);
         sum+=abs(b[i]-b[i+1]);
         p.push_back(sum);
     }
     cout<<*min_element(p.begin(),p.end());

}


Measured memory_bytes: 8548
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

multiset<int> nums;
int n;

int opposite(int x){
  int k = 1;
  while(k <= x)k *= 2;
  return k-x;
}
int a;
int main(){
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a;
    nums.insert(-a);
  }
  int res = 0;
  while(nums.size() >= 2){
    int a = -*nums.begin();
    nums.erase(nums.begin());
    if(nums.find(-opposite(a)) == nums.end())continue;
    res++;
    nums.erase(nums.find(-opposite(a)));
  }
  cout << res << endl;
}

Measured memory_bytes: 9600
h,w=map(int,input().split())
s=[]
for _ in range(h):
  s.append(input())
ans=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      ans[i][j]='#'
      continue
    i0=max(0,i-1)
    i1=min(i+1,h-1)
    j0=max(0,j-1)
    j1=min(j+1,w-1)
    p=0
    for _ in range(i0,i1+1):
      p += s[_][j0:j1+1].count('#')
    ans[i][j]=p
#print(s)
for ansi in ans:
  print(''.join(map(str,ansi)))


Measured memory_bytes: 3064
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,W = LI()
    B = [[0,0]]+[LI() for _ in range(N)]

    k_min = max(1,W // (B[1][0] + 3))
    k_max = min(W // B[1][0],N)

    if B[1][0] <= 300: base = 0
    else: base = B[1][0] - 300
    for i in range(1,N+1): B[i][0] -= base

    ans = 0
    for k in range(k_min,k_max+1):
        w_sub = min(303 * k,W - k*base)
        dp = [[0] * (w_sub+1) for _ in range(N+1)]
        for i in range(1,N+1):
            for j in range(1,w_sub+1):
                if j - B[i][0] >= 0:
                    dp[i][j] = max(dp[i-1][j],dp[i-1][j-B[i][0]] + B[i][1])
                else:
                    dp[i][j] = dp[i-1][j]
        ans = max(ans,dp[-1][-1])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 87916
def check(a,x):
    if x == 3 :
        print a,
    elif x % 10 == 3:
        print a,
    elif x :
        check(a,x/10)
        
        
n = input()
print"",

for i in range(3,n+1) :
    if i % 3 == 0 :
        print i ,
    elif i%10 == 3 :
        print i,
    else :
        check(i,i/10)
        

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        map<string,int> mp[26];
        string a;
        getline(cin,a);
        REP(i,n){
            string s, tmp;
            getline(cin,s);
            s += ' ';
            for(auto t : s){
                if(t==' '){
                    mp[tmp[0]-'a'][tmp]++;
                    tmp.clear();
                }
                else tmp.push_back(t);
            }
        }
        char c;
        cin >> c;
        if(mp[c-'a'].size()>0){
            int i=0, m=mp[c-'a'].size();
            vector<pair<int,string> > ls;
            for(auto k:mp[c-'a']){
                ls.push_back({-k.second,k.first});
            }
            SORT(ls);
            REP(i,min(m,5)){
                if(i>0)cout << " ";
                cout << ls[i].second;
            }
            cout << endl;
        }
        else cout << "NA" << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

int main()
{
  ll X; cin >> X;
  ll sum = 0;
  for (int i = 1;; ++i) {
    sum += i;
    if (sum >= X) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
H, W, D = map(int, input().split())
p = {}
for i in range(H):
    for j, value in enumerate(map(int, input().split())):
        p[value] = (i, j)

cost = {}
for i in range(1, W * H + 1):
    cost[i] = cost[i - D] + abs(p[i][0] - p[i - D][0]) + abs(p[i][1] - p[i - D][1]) if i > D else 0

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(cost[R] - cost[L])


Measured memory_bytes: 35980
package main

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

type Item struct {
	v int
	w int
	t string
	d int
	s string
}

func NextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func NextInt(sc *bufio.Scanner) int {
	n, err := strconv.Atoi(NextString(sc))
	if err != nil {
		panic(err)
	}
	return n
}

func ReadTuple(sc *bufio.Scanner) Item {
	return Item{
		NextInt(sc),
		NextInt(sc),
		NextString(sc),
		NextInt(sc),
		NextString(sc),
	}
}

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

	n := NextInt(sc)
	items := make([]Item, n)
	for i := 0; i < n; i++ {
		items[i] = ReadTuple(sc)
	}

	sort.Slice(items, func(i, j int) bool {
		ii, ij := items[i], items[j]
		switch {
		case ii.v != ij.v:
			return ii.v < ij.v
		case ii.w != ij.w:
			return ii.w < ij.w
		case ii.t != ij.t:
			return ii.t < ij.t
		case ii.d != ij.d:
			return ii.d < ij.d
		case ii.s != ij.s:
			return ii.s < ij.s
		default:
			return true
		}
	})

	w := bufio.NewWriterSize(os.Stdout, 1e6)
	for _, v := range items {
		fmt.Fprintln(w, strings.Trim(fmt.Sprint(v), "{}"))
	}
	w.Flush()
}



Measured memory_bytes: 22656
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<int> a(n,inf);
    rep(i,n-1){
        int f;
        cin >> f;
        a.at(i)=min(a.at(i),f);
        a.at(i+1)=min(a.at(i+1),f);
    }
    int ans=0;
    rep(i,n) ans+=a.at(i);
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main(){
  string str; cin >> str;
  vector<char> tes;
  bool pos=true;
  for(int i=0;i<str.size();i++){
    if(str[i] != 'x') tes.push_back(str[i]);
  }
  for(int i=0;i<tes.size()/2;i++){
    if(tes[i] != tes[tes.size()-1-i]){
      pos=false;
      break;
    }
  }
  if(pos == true){
    int sum=0;
    int ix=0, jx=0;
    int idx=0, jdx=str.size()-1;
    while(idx <= jdx){
      if(str[idx] != 'x' && str[jdx] != 'x'){
        sum = sum + max(ix, jx)-min(ix, jx);
        ix=0; jx=0;
        idx++; jdx--;
      }else if(str[idx] != 'x'){
        jx++; jdx--;
      }else if(str[jdx] != 'x'){
        ix++; idx++;
      }else{
        ix++; jx++;
        idx++; jdx--;
      }
    }
    cout << sum << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
import sys,os,math
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import Queue



# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())


def main():
    n, m = map(int, raw_input().split())
    G = [[] for i in range(n+1)]
    ss = set()
    for i in range(m):
        a, b = map(int, raw_input().split())
        G[a].append(b)
    s, t = map(int, raw_input().split())
    t = t<<2
    q = deque()
    q.append((s<<2, 0))
    ss.add(s<<2)
    while q:
        st, step = q.popleft()
        point, mod = st>>2, st&3
        # print point, step, mod
        if st == t:
            print step/3
            return

        for adj in G[point]:
            new_st = (adj<<2) + (mod+1)%3
            if new_st not in ss:
                ss.add(new_st)
                q.append((new_st, step+1))
    print -1

main()


Measured memory_bytes: 34380