akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    string s,t;
    int n,m;
    cin>>s>>t;
    n=s.length();
    m=t.length();
    vector<vector<int>> dp(n+1,vector<int> (m+1));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            dp[i][j]=max({dp[i-1][j],dp[i][j-1],dp[i][j]});
        }
    }
    string ans="";
    int row=n,col=m;
    while(row !=0 && col!=0){
        debug(row,col);
        if(s[row-1]==t[col-1]){
            if(dp[row][col]==dp[row-1][col-1]+1){
                ans+=s[row-1];
                row=row-1;
                col=col-1;
                continue;
            }
        }
        else if(dp[row][col]==dp[row-1][col]){
            row=row-1;
        }
        else if(dp[row][col]=dp[row][col-1]){
            col=col-1;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 38560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll A, B, K;
  cin >> A >> B >> K;

  ll a = max(0LL, A - K);
  ll b = max(0LL, B - max(0LL, (K - A)));
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "string"

int main()
{
    int n, m;
    int line[100][100], temp;
    int vect[100];
    int result[100];
    std::cin >> n >> m;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            std::cin >> line[i][j];

    for(int i = 0; i < m; i++){
        std::cin >> vect[i];
    }

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++){
            result[i] += vect[j] * line[i][j];
        }

    for(int i = 0; i < n; i++){
        if(1)
            std::cout << result[i] << std::endl;
        else
            std::cout << result[i];
    }

    return 0;
}

Measured memory_bytes: 3088
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int l = s.length();
		int count = 0;
		for(int i=0; i < l /2; i++) {
			if (s.charAt(i) != s.charAt(l - 1 - i))
				count++;
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 23636
N, M, Q = map(int, input().split())
req = [list(map(int, input().split())) for i in range(Q)]
maxi = 0
def dfs(A):
  global maxi
  
  if len(A) == N:  # 終端条件 --- 10 重ループまで回したら処理して打ち切り
    ans = 0
    for i in range(Q):
      if A[req[i][1]-1] - A[req[i][0]-1] == req[i][2]:
        ans += req[i][3]
        
    maxi = max(maxi, ans)
    return
      
  if len(A) == 0:
    for v in range(1, M+1):
      A.append(v)
      dfs(A)
      A.pop()
      
  else:    
    for v in range(A[-1], M+1):
      A.append(v)
      dfs(A)
      A.pop() # これが結構ポイント

dfs([])
print(maxi)

Measured memory_bytes: 9256
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = []
for i in range(n):
  t.append((a[i], 1))

for i in range(m):
  b, c = map(int, input().split())
  t.append((c, b))

t.sort(reverse=True)
ans = 0
for c, b in t:
  for k in range(b):
    if n == 0:
      break
    ans += c
    n -= 1

print(ans)


Measured memory_bytes: 28888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  cout << (a + b) % 24 << endl;
}

Measured memory_bytes: 3564
def main():
    N, M = map(int, input().split())
    A = []
    for i in range(N):
        A.append(input())
    B = []
    for i in range(M):
        B.append(input())
    for i in range(N - M + 1):
        for j in range(N - M + 1):
            if check(i, j, M, A, B):
                print('Yes')
                return
    print('No')


def check(i, j, M, A, B):
    for w in range(M):
        for h in range(M):
            if A[i + w][j + h] != B[w][h]:
                return False
    return True

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

# 繰り返し二乗法
def pow_r_mod(x:int, n:int, mod=10**9+7)->int:
    # 計算量 : log N
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        x %= mod
        n //= 2
    return (K * x) % mod

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        #fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        #factinv.append((factinv[-1] * inv[-1]) % p)

m, a, b = mi()

P = 10**9+7
N = 2*(10**5)
table(N)

mca = 1
for i in range(1, a+1):
    mca *= (m-i+1) * inv[i]
    mca %= P

mcb = mca
for i in range(a+1, b+1):
    mcb *= (m-i+1) * inv[i]
    mcb %= P

print((pow_r_mod(2, m)-1-mca-mcb) % P)
#print((pow(2, m, P)-1-mca-mcb) % P)

Measured memory_bytes: 11052
#include<iostream>

using namespace std;

#define N 100

//grobal
int data[N],num1,num2;

//flag
bool flag=false;

//function solve
bool solve(int i,int m){

  //if i >num1 or m<0 then false
  if(i>num1 ||m<0) return false;

  //if m=0 then  true
  if(m==0){
    flag=true;
    return true;
  }
  //execute
  solve(i+1,m);
  solve(i+1,m-data[i]);  

}


int main(){

  int i,m;

  //load number
  cin >>num1;

  //load data
  for(i=0;i<num1;i++){
    cin >>data[i];
  }
  //load number
  cin >>num2;
  //load  data and execute
  for(i=0;i<num2;i++){
    cin >>m;
    //initial flag
    flag=false;
    //execute solve
    solve(0,m);

    //print yes or no
    if(flag==true){
      cout <<"yes"<<endl;
    }  
    else cout <<"no"<<endl;
  }

  return 0;
}

Measured memory_bytes: 852
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int long long
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define s second
#define f first
#define mp make_pair
typedef std::pair<int,int> pii ;

using namespace std;

const int N=110,K=1e5+1e2,mod=1e9+7;
int n,dp[N][K],ps[N][K],k,a[N];

int32_t main(){
	ibsws(true==false);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=0;i<=k;i++){
        dp[1][i]=(a[1]>=i);
        ps[1][i]=(ps[1][max(0ll,i-1)]+dp[1][i]+mod)%mod;
    }
    for(int i=2;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j<=a[i]){
                dp[i][j]=ps[i-1][j];
            }
            else{
                dp[i][j]=ps[i-1][j]-ps[i-1][j-a[i]-1];
            }
            dp[i][j]+=mod;
            dp[i][j]%=mod;
            ps[i][j]=ps[i][j-1]+dp[i][j];
            ps[i][j]+=mod;
            ps[i][j]%=mod;
        }
    }
    /*/
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            cout<<i<<' '<<j<<':'<<dp[i][j]<<'\n';
        }
    }//*/
    cout<<dp[n][k];
}


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

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    ll n;cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        ll tmp;cin>>tmp;
        mp[tmp]++;
    }
    bool flg = 0;
    ll ans = 0;
    for(auto it = mp.begin();it!=mp.end();it++){
        if(it == mp.begin()){
            if(n % 2 == 1){
                if(it->first != 0 || it->second != 1)flg = 1;
            }else{
                if(it->first != 1 || it->second != 2)flg = 1;
            }
        }else{
            if(it->first != prev(it,1)->first + 2 || it->second != 2)flg = 1;
        }
    }
    if(flg == 1)cout<<'0'<<endl;
    else cout<<modpow(2,n/2)<<endl;
    return 0;
}

Measured memory_bytes: 4224
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n, N) for(ll i=(n);i<(N);i++)
#define RREP(i, n, N) for(ll i=(N-1);i>=(n);i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll A, B, K;

int main() {
    cin>>A>>B>>K;

    REP(i,0,K){
        if(i % 2 == 0){
            if(A % 2 != 0){
                A--;
            }
            B += A/2;
            A /= 2;
        }else{
            if(B % 2 != 0){
                B--;
            }
            A += B/2;
            B /= 2;
        };
    }

    cout<<A<<" "<<B<<endl;


    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::io::{stdin, stdout, Read, Write};
use std::str::FromStr;

#[derive(Default)]
struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner {
            reader,
        }
    }

    fn scan<T: FromStr>(&mut self) -> Option<T> {
        let s = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok()
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.scan() {
            s
        } else {
            std::process::exit(1);
        }
    }
}

fn partition(a: &mut[i32], p: usize, r: usize) -> usize {
    let x = a[r];
    let mut i = p;
    for j in p..r {
        if a[j] <= x {
            a.swap(i, j);
            i += 1;
        }
    }
    a.swap(i, r);
    i
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let out = stdout();
    let mut out = out.lock();

    let n = sc.next();
    let mut a = vec![0; n];
    for i in 0..n {
        a[i] = sc.next();
    }

    let q = partition(&mut a[..], 0, n-1);
    for i in 0..n {
        if i == q {
            write!(out, "[{}]", a[i]).ok();
        } else {
            write!(out, "{}", a[i]).ok();
        }
        if i != n-1 {
            write!(out, " ").ok();
        } else {
            write!(out, "\n").ok();
        }
    }
}



Measured memory_bytes: 5048
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, nn):
        self.par = [i for i in range(nn+1)]
        self.rank = [0] * (nn+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

u = UnionFind(n)
for i in range(m):
    x = a[i][0]
    y = a[i][1]
    z = a[i][2]
    u.union(x, y)

counter = []
for i in range(n+1):
    counter.append(u.find(i))

print(len(list(set(counter[1:]))))


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

int main(){
	int x;
	double p;
	cin >> x >> p;
	p /= 100.0;
	if(x % 2) {
		x /= 2;
		printf("%.9lf\n",x + (x + 1) / p * (1 - p) + 1);
	}
	else printf("%.9lf\n",x / 2 / p);
	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int n;
  vector<string> s;
  cin>>n;
  for(i=0;i<n;i++){
    string str;
    cin>>str;
    s.push_back(str);
  }
  for(i=0;i<n;i++){
    if(s[i].find(">'")==0){
      if(s[i].find("~")==s[i].length()-1){
	if(s[i].find("#")!=-1){
	  if(s[i].find("#")-2==s[i].length()-s[i].find("#")-2){
	    int len;
	    string str;
	    str=s[i].substr(2,s[i].find("#")-2);  
	    len=str.length();
	    if(len>0){
	      for(j=0;j<len;j++){
		if(str[j]!='=')
		  break;
	      }
	      if(j==len){
		str=s[i].substr(s[i].find("#")+1,s[i].find("#")-2);
		len=str.length();
		for(j=0;j<len;j++){
		  if(str[j]!='=')
		    break;
		}
		if(j==len){
		  cout<<"A"<<endl;
		  continue;
		}
	      }
	    }
	  }
	}
      }
    }else if(s[i].find(">^")==0){
      if(s[i].find("~~")==s[i].length()-2){
	int len;
	string str;
	str=s[i].substr(2,s[i].length()-4);
	len=str.length();
	if(len>1&&len%2==0){
	  for(j=0;j<len;j+=2){
	    if(str[j]!='Q')
	      break;
	  }
	  if(j==len){
	    for(j=1;j<len;j+=2){
	      if(str[j]!='=')
		break;
	    }
	    if(j==len+1){
	      cout<<"B"<<endl;
	      continue;
	    }
	  }
	}
      }
    }
    cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a.sort()
    a = tuple(a)

    ans = 0
    mx = max(a) + 1
    dp = [0] * mx
    for i in a:
        if dp[i] == 2:
            continue
        else:
            for j in range(i, mx, i):
                dp[j] += 1
    for i in a:
        if dp[i] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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

//apple i taste=L+i-1 could be <0
//therere N apples but ate 1 so N-1 apples
// apple pi N vs apple pi N-1 min abs(NvsN-1)
//N=>2
// so eat abs|L|=0 
//input Number Ludiclulors
//taste=L+i-1 -> mins(abs(taste))->sum(taste)=?

int main(){
    int N,L;
    cin>>N>>L;
    
    int taste[N]={0};
    int abs_taste[N]={0};
    int i=0;
    int sum=0;
    //i=0 1 2 N
    for(i=1;i<=N;i++){
        taste[i]=L+i-1;
        sum+=taste[i];
    }
        int inf=9999999;
        int zero=0;
        int tmp=0;
        tmp=abs(taste[1]);
        //taste = -2 -1 0 1 2 3 4 5
    int tmp2=0;
    for(int j=1;j<=N;j++){
        
        if(abs(taste[j])<=tmp){
            tmp=abs(taste[j]);
            tmp2=taste[j];
        }
    }
    sum=sum-tmp2;


    //M=min(abs(taste[i]))
    //sum=sum-M;
    cout<<sum;
    

}

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

int main(void)
{
  string s;
  cin >> s;
  
  int count = 0;
  int g=0;
  for(auto i : s){
    if(g>0){
       g--; //パーを出す
       if(i=='g')
        count++;
    }
    else{
      g++; //グーを出す
      if(i=='p')
        count--;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 512
//header{{{
    #include<bits/stdc++.h>
      
    using namespace std;
     
    #define rep(i,n) for(int i=0;i<(n);++i)
    #define reps(i,n) for(int i=1;i<=(n);++i)
    #define all(x) (x).begin(),(x).end()
    #define setout(n,x) setw(n+1) << setfill(x)
    #define Fixed fixed << setprecision(10)
    #define int int64_t
    using pii = pair<int,int>;
    constexpr int INF  = 0x3f3f3f3f;
    constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
    constexpr int mod = 1e9+7; 
     
    template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
    template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
     
    template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
    template <class T> using max_heap = priority_queue<T>;
      
    int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
    int lcm(int a,int b){ return a / gcd(a,b) * b;}
    //}}}
     
    signed main(){
    	cin.tie(0);
    	ios::sync_with_stdio(false);
    	int n,m,r;
    	cin >> n >> m >> r;
    	vector<int> vec(r);
    	vector<vector<pii> > g(n+1);
    	rep(i,r){
    		cin >> vec[i];
    	}
    	rep(i,m){
    		int a,b,c;
    		cin >> a >> b >> c;
    		g[a].emplace_back(b,c);
    		g[b].emplace_back(a,c);
    	}
    	int minv = LINF;
    	vector<vector<int> > mem(n+1,vector<int>(n+1));
    	for(int i = 0;i < r;++i){
    		vector<int> dist(n+1,LINF);
    		queue<int> que;
    		que.emplace(vec[i]);
    		dist[vec[i]] = 0;
    		while(!que.empty()){
    			int now = que.front();
    			que.pop();
    			rep(k,g[now].size()){
    				int next = g[now][k].first;
    				int cost = g[now][k].second;
    				if(dist[now] + cost < dist[next]){
    					dist[next] = dist[now] + cost;
    					que.emplace(next);
    				}
    			}
    		}
    		rep(j,r){
    			mem[vec[i]][vec[j]] = dist[vec[j]];
    			mem[vec[j]][vec[i]] = dist[vec[j]];
    		}
    	}
        sort(all(vec));
     	do{
    		int sum = 0;
    		rep(i,r-1){
    			sum += mem[vec[i]][vec[i+1]];
    		}
    		chmin(minv,sum);
    	}while(next_permutation(all(vec)));
     
    	cout << minv << '\n';
     
    	return 0;
    }

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

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

    long long x;
    cin >> x;

    if (x < 7)
    {
        cout << 1 << endl;
        return 0;
    }

    long long count = 0;
    count = x % 11;

    if (count == 0)
    {
        cout << x / 11 * 2 << endl;
    }
    else
    {
        if (count < 7)
        {
            cout << x / 11 * 2 + 1 << endl;
        }
        else
        {
            cout << x / 11 * 2 + 2 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 632
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int n, m;
  readf("%d %d\n", &n, &m);
  auto cnt = new int[](n);
  foreach (i; 0..m) {
    auto a = readln.chomp.split.to!(int[]);
    cnt[a[0]-1]++;
    cnt[a[1]-1]++;
  }
  foreach (i; 0..n) {
    cnt[i].writeln;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;

  int count = 0, sum = 0;
  while (count < 2)
  {
    if (A > B)
    {
      sum += A;
      --A;
    }
    else
    {
      sum += B;
      --B;
    }
    ++count;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}		
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String str = in.nextLine();
        int n = str.length();
        int c=0;
        for(int i=0;i<n/2;i++){
            if(str.charAt(i)!=str.charAt(n-i-1)) c++;
        }
        out.write(c+"\n");
        
    }
    
    /************* SOLUTION ENDS HERE **********/
}

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

int main(){
    int N;
    scanf("%d", &N);
    double sum=0;
    double x;
    char u[3];
    char *shu = "JPY";
    
    for (int i=0; i<N; i++) {
        scanf("%lf%s", &x, u);
        if ((strncmp(u, shu, 3)) == 0) {
            sum += x;
        }else{
            sum += x * 380000;
        }
    }
    printf("%lf\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n,m,p;
  long t,x,rem;
  vector<long> arr;
  cin >> n;
  while (n--)
  {
    cin >> t;
    arr.push_back(t);
  }
  cin >> m;
  while (m--)
  {
    cin >> p >> x;
    rem = arr[p-1];
    arr[p-1] = x;
    cout << accumulate(arr.begin(),arr.end(),0) << endl;
    arr[p-1] = rem;
  }
  return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a[4],b[2]={1,-1};
  char c[2]={'+','-'};
  for(int i=0; i<4; i++) {
    a[i]=s[i]-'0';
  }
  for(int i=0; i<2; i++) {
    for(int j=0; j<2; j++) {
      for(int k=0; k<2; k++) {
        if(a[0]+a[1]*b[i]+a[2]*b[j]+a[3]*b[k]==7) {
          cout <<s[0]<<c[i]<<s[1]<<c[j]<<s[2]<<c[k]<<s[3]<<"=7"<<endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
	double n,k;
	cin>>n>>k;
	double t;
	double kk;
	int s;
	double kkk;
	double ans=0;
	for(int i=1;i<=n;i++){
		t=1/n;
		kk=k/i;
		s=max(double(0),ceil(log2(kk)));
		kkk=pow(0.5,s);
		ans+=t*kkk;
//		cout<<s<<endl;
	}
	printf("%.12f",ans);
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
	const col = input.split(" ");
	const D = parseInt(col[0], 10);
	const T = parseInt(col[1], 10);
	const S = parseInt(col[2], 10);
	const ans = D > T * S ? 'No' : 'Yes';
	console.log(ans);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29316
#鈴木に教わった

import heapq

N,M=map(int,input().split())
A=[]
B=[]
for h in range(N):
    A.append(0)
    B.append(0)
for i in range(N):
    A[i],B[i]=map(int,input().split())

L=[[] for _ in range(M+1)]

for j in range(N):
    if A[j]<=M:
        L[A[j]].append(B[j])   #O(N)

ans=0
rest=[]
for k in range(1,M+1):  #O(M*logN)
    for x in L[k]:
        heapq.heappush(rest,-x)
    if rest:     #restが空だとエラーが起きる
        ans+=-heapq.heappop(rest)

print(ans)





Measured memory_bytes: 23000
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

class UniteFind {
  long long par[100000],sizes[100000];
public:
  long long init (int n) { // init
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sizes[i] = 1;
    }
  }

  long long root(int x) { //find
    if (par[x] == x) {
      return x;                      //根
    } else {
      return par[x] = root(par[x]);  //経路圧縮
    }
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite (int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    sizes[x] += sizes[y];
    sizes[y] = -1;
    par[y] = x;
  }

  long long size(int x) {
    return sizes[root(x)];
  }
};

int main () {
  long long n,m,a,b;
  cin >> n >> m;
  std::vector<pair<long , long> > vec(m);
  unsigned long long ans[m+1];
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    vec[i].first = a;
    vec[i].second = b;
    ans[i] = 0;
  }
  ans[m] = n * (n-1) / 2;
  UniteFind uf;
  uf.init(n);
  for(int i = m-1; i >= 0; i--) {
    if(uf.same(vec[i].first -1, vec[i].second -1)){
      ans[i] = ans[i+1];
    } else {
      // cout << "統合っ " << vec[i].first << " : " << vec[i].second << " "
      // << i << " => "
      // << uf.size(vec[i].first-1) << " : " << uf.size(vec[i].second-1) << endl;
      ans[i] = ans[i+1] - uf.size(vec[i].first-1) * uf.size(vec[i].second-1);
      uf.unite(vec[i].first-1, vec[i].second-1);
    }
  }
  for (int i = 1; i < m+1; i++) {
    cout << ans[i] << endl;
  }
}


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

int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  int s = a1 + a2 + a3;
  if (s >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  }

Measured memory_bytes: 256
N, M, C = (int(i) for i in input().split())

B = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])


counter =0
for i in range(N):
    ans = C
    for j in range(M):
        ans += A[i][j]*B[j]

    if(ans>0):
        counter+=1

print(counter)

Measured memory_bytes: 3064
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()
    pre = [''] * N
    ans = 0
    for i in range(N):
        if i - K < 0:
            if T[i] == 'r':
                ans += P
                pre[i] = 'p'
            if T[i] == 's':
                ans += R
                pre[i] = 'r'
            if T[i] == 'p':
                ans += S
                pre[i] = 's'
        else:
            if T[i] == 'r':
                if pre[i-K] == 'p':
                    continue
                ans += P
                pre[i] = 'p'
            if T[i] == 's':
                if pre[i-K] == 'r':
                    continue
                ans += R
                pre[i] = 'r'
            if T[i] == 'p':
                if pre[i-K] == 's':
                    continue
                ans += S
                pre[i] = 's'
    
    print(ans)

if __name__ == "__main__":
    main()

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k <= a){
        cout << k << endl;
    }else if(k <= a+b){
        cout << a << endl;
    }else{
        cout << a - (k-a-b) << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
N = int(input())
ans = [0,0,0,0]

for _ in range(N):
    a = input()
    if a == "AC":
        ans[0] += 1
    elif a == "WA":
        ans[1] += 1
    elif a == "TLE":
        ans[2] += 1
    else:
        ans[3] += 1

print("AC x "+ str(ans[0]))
print("WA x "+ str(ans[1]))
print("TLE x "+ str(ans[2]))
print("RE x "+ str(ans[3]))


Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <iomanip>
#include <sstream>
using namespace std;
int main(void){
    int n, k;
    cin>>n>>k;
    int ans =log(n)/log(k) +1;
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
deque<char> d;
deque<char> ::iterator id;
char c;
string s,ans;
int q,t,f;
bool k;
int main()
{
	cin>>s>>q;
	for(int i=0;i<s.size();++i)
	 d.push_back(s[i]);
	for(int i=1;i<=q;++i)
	{
		cin>>t;
		if(t==1) k^=1;
		else
		{
			cin>>f>>c;
			if(k^(f==1)) d.push_front(c);
			else d.push_back(c);
		}
	}
	for(id=d.begin();id!=d.end();++id)
	 ans+=*id;
	if(k) reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1412
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();

		int Ai[] = new int[M];

		int i;
		for (i = 0; i < M; i++) {
			Ai[i] = sc.nextInt();

		}

		if (X == 1 || N - X == 1) {
			// 最短だったらおしまい
			System.out.println("0");

		} else {

			int cost_l = 0;
			// 左側チェック
			for (i = 0; i < X; i++) {

				for (int n = 0; n < M; n++) {
					// 料金所は小さい順ではいっているけれど・・・全部比べちゃう。
					if (i == Ai[n]) {
						cost_l++;
						break;
					}
				}
			}

			int cost_r = 0;
			// 右側チェック
			for (i = X + 1; i < N; i++) {

				for (int n = 0; n < M; n++) {
					// 料金所は小さい順ではいっているけれど・・・全部比べちゃう。
					if (i == Ai[n]) {
						cost_r++;
						break;
					}
				}
			}

			if (cost_r < cost_l) {

				System.out.println(cost_r);
			} else {
				System.out.println(cost_l);
			}
		}

	}
}


Measured memory_bytes: 22612
#include <iostream>
using namespace std;
int main(){
  int N,M,l,r,L=0,R=100000;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> l >> r;
    if(l>L)L=l;
    if(r<R)R=r;
  }
  cout << max(R-L+1,0) << endl;
  return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }.sorted()
    val set = mutableSetOf<Int>()
    var ans = 0
    for ((idx, v) in a.withIndex()) {
        var divisible = true

        if (idx + 1 < n && v == a[idx + 1]) {
            divisible = false
        }

        var i = 1
        while (divisible && i * i <= v) {
            if (v % i == 0) {
                if (set.contains(i) || set.contains(v / i)) {
                    divisible = false
                }
            }
            i++
        }

        if (divisible) ans++
        set.add(v)
    }
    println(ans)
}

Measured memory_bytes: 80516
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b)
{
	return a%b==0?b:gcd(b,a%b);
}
long long a,b,c,d;
int main()
{
	long long T;
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
		long long ww=gcd(gcd(a,b),gcd(c,d));
		a/=ww,b/=ww,c/=ww,d/=ww;
		if(a<b||b>d)
		{
			printf("No\n");
			continue;
		}
		if(a<=c)
		{
			if(b==d||c>=b)
			{
				printf("Yes\n");
				continue;
			}
			a=a%b;
			if(c>=a)
				a=((c-a)/b+1)*b+a;
			if(a<b)
			{
				printf("No\n");
				continue;
			}
			long long e=d-b;
			long long cc=gcd(b,e);
			a=a%cc;
			if(c>=a)
				a=((c-a)/cc+1)*cc+a;
			if(b==d||a>=b)
				printf("Yes\n");
			else
				printf("No\n");
			continue;
		}
		if(a>c)
		{
			a=a%b;
			if(c>=a)
				a=((c-a)/b+1)*b+a;
			if(a<b)
			{
				printf("No\n");
				continue;
			}
			long long e=d-b;
			if(b==d||c>=b)
			{
				printf("Yes\n");
				continue;
			}
			long long cc=gcd(b,e);
			a=a%cc;
			if(c>=a)
				a=((c-a)/cc+1)*cc+a;
			if(b==d||a>=b)
				printf("Yes\n");
			else
				printf("No\n");
			continue;
		}
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<int> graph[100010];
map<P, int> mp;
void dfs(int prev, int now, int color){
    int nextc = 1;
    for(auto next:graph[now]){
        if(next == prev)continue;
        if(nextc == color)nextc++;
        int a = now, b = next;
        if(a > b)swap(a,b);
        mp[P(a,b)] = nextc;
        dfs(now, next, nextc);
        nextc++;
    }
}
main(){
    int N;
    cin >> N;
    vector<P> E(N-1);
    rep(i,0,N-1)cin >> E[i].first >> E[i].second;
    rep(i,0,N-1){
        
        E[i].first--;
        E[i].second--;
        graph[E[i].first].push_back(E[i].second);
        graph[E[i].second].push_back(E[i].first);
    }
    
    dfs(-1, 0, -1);
    int maxi = 0;
    vector<int> ans(N-1);
    rep(i, 0, N - 1){
        ans[i] = mp[P(E[i].first, E[i].second)];
        maxi = max(maxi, ans[i]);
    }
    cout << maxi << endl;
    rep(i, 0, N - 1){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//無限大
const ll INF = 1LL << 60;


//------------------------------------------------
int main() {

    //DPテーブル初期化
    ll dp[100010][3];
    rep(i,100010) rep(j,3) dp[i][j] = 0;

    //main
    int N;
    cin >> N ;

    ll abc[3];
    rep(i,3) cin >> dp[1][i];

    for(int day=2; day<N+1; ++day){
        rep(i,3) cin >> abc[i];
        rep(i,3) rep(j,3) if (i != j) chmax(dp[day][j],dp[day-1][i] + abc[j]);
    }
    
    //answer
    ll ans = 0;
    rep(i,3) chmax(ans, dp[N][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


n = int(input())
testimony = [[] for _ in range(n)]  # 各iの証言
for i in range(n):
    for _ in range(int(input())):
        x, y = spline()
        x -= 1
        testimony[i].append((x, y))
best = 0  # 正直者の最大人数
for honest in range(1 << n):  # 正直者をあらかじめ仮定して破綻を確認する
    for i in range(n):  # 証言者i
        if not (honest >> i) & 1:  # iが不親切な人なら証言を聞かない
            continue
        for j, t in testimony[i]:  # iによるjに対する証言t
            if (honest >> j) & 1 ^ t:  # jに対する仮定とtが食い違えば破綻
                break
        else:
            continue
        break
    else:  # 全ての正直者に話を聞いて破綻が無ければ更新
        best = max(best, bin(honest).count('1'))
print(best)


Measured memory_bytes: 3064
n, w = map(int, input().split())

dp = [0] * (w + 1)
# (v, w)
weight = []
value = []
for _ in range(n):
    v, we = map(int, input().split())
    weight.append(we)
    value.append(v)

# dp[i+1][w] i番目までの品物の中から重さがWを超えないように選んだ時の価値の総和の最大値
#              weight[i]を引いた時の最大値
# dp[i+1][w] = dp[i][w-weight[i]]+value[i]
# 入れない時
# dp[i+1][w] = dp[i][w]

for i in range(n):
    for j in range(w+1):
        if j >= weight[i]:
            dp[j] = max(dp[j - weight[i]] + value[i], dp[j])

# print(dp)

print(dp[w])



Measured memory_bytes: 5724
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 118：A - B +- A


def main():
    A, B = [int(i) for i in raw_input().strip().split(' ')]

    if B % A == 0:
        print A+B
    else:
        print B-A


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt_4 = 0;
    int cnt_2 = 0;
    REP(i,n){
        int in;
        cin >> in;
        if( in%4 == 0) cnt_4++;
        if(in%4 != 0 && in % 2 == 0) cnt_2++;
    }

    if(cnt_4 >= n/2) cout << "Yes" << endl;
    else if(cnt_2/2 + cnt_4 >=n/2) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int counter=0;
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;
  if((b>a && c>b) || (c<b && b<a)) counter++;
  for(int i=3; i<n; i++){
    a = b;
    b = c;
    cin >> c;
  	if((b>a && c>b) || (c<b && b<a)){
      counter++;
    }
  }
  cout << counter << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int cnt=0;
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int k = 0; k < 10; k++) {
                int dig[3]={i,j,k};
                int m=0;
                for(int l = 0; l < n; l++) {
                    if(s[l] == '0'+dig[m]) m++;
                    if(m==3){
                        cnt++;
                        break;
                    }
                }
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    map<string, ll> m;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans = 0;
    for (auto &&j : m) {
        ans += j.second*(j.second-1)/2;
    }
    cout << ans << "\n";
    return 0;
}

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

bool checkEvenSentence(string str)
{
    int l = str.size();
    if (l % 2 != 0) return false;

    if (str.substr(0, l/2) == str.substr(l/2, l/2)) return true;
    return false;
}

int main()
{
    string str;
    cin >> str;
    str.pop_back();
    
    for (;;) {
        if (checkEvenSentence(str)) {
            cout << str.size() << endl;
            break;
        } else if (str.size() == 0) {
            exit(1);
        } else {
            str.pop_back();
        }
    }
    return 0;
}

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

int const N=1e2+5, M=1e5+5, OO = 0x3f3f3f3f;


int n,k;
int arr[N];
int mem[M][2];
int solve(int rem, bool last)
{
    if(rem<0)
        return !last;
    if(mem[rem][last]!=-1)
        return mem[rem][last];
    int ret;
    bool f;
    if(last)
    {
        ret=0;
        f=0;
        for(int i=0; i<n; i++)
        {
            if(rem-arr[i]>=0)
            {
                ret=max(ret,solve(rem-arr[i],0));
                f=1;
            }
            else
                break;
        }
        if(!f)
            ret=0;
    }
    else
    {
        f=0;
        ret=1;
        for(int i=0; i<n; i++)
        {
            if(rem-arr[i]>=0)
            {
                ret=min(ret,solve(rem-arr[i],1));
                f=1;
            }
            else
                break;
        }
        if(!f)
            ret=1;
    }
    return mem[rem][last]=ret;
}


int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
    scanf("%d %d",&n, &k);
    for(int i=0; i<n; i++)
        scanf("%d",arr+i);
    memset(mem, -1, sizeof mem);
    if(solve(k,1))
        puts("First");
    else
        puts("Second");

}


Measured memory_bytes: 7296
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
ll two[70],a,b,ans,x,y,u,v;
int i,j,k,l,t,n,m,d;
int main(){
    scanf("%lld%lld",&a,&b);
    swap(a,b);
    two[0]=1;
    fo(i,1,62)  two[i]=(ll)two[i-1]*2;
    fd(i,62,0){
        if ((a&two[i])!=(b&two[i])) break;
        if ((a&two[i])>0){
            a^=two[i];
            b^=two[i];
        }
    }
    if (a==b){
        printf("1\n");
        return 0;
    }
    d=i;
    fd(k,i-1,-1)
        if (k==-1||(a&two[k])>0) break;
    x=b;y=two[d]+two[k+1]-1;
    u=two[d]+b;v=two[d+1]-1;
    ans=y-x+1;
    if (u>y) ans+=v-u+1;
    else if (u<=y&&v>y) ans+=v-y;
    printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,K; cin >> N >> K;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    sort(a.begin(),a.end());
    int ng = -1,ok = N;
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        vector<int> v;
        rep(i,N){
            if(i != mid) v.push_back(a[i]);
        }
        bool dp[5000][5000];
        rep(i,5000)rep(j,5000) dp[i][j] = false;
        dp[0][0] = true;
        rep(i,N-1)rep(j,K){
            if(j-v[i] >= 0 && dp[i][j-v[i]]) dp[i+1][j] = true; 
            if(dp[i][j]) dp[i+1][j] = true;
        }
        bool flag = false;
        repr(i,max(K-a[mid],0),K){
            if(dp[N-1][i]) flag = true;
        }
        if(flag) ok = mid;
        else ng = mid; 
    }
    cout << ok << endl;
}



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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	string s;
	cin >> n >> s;
	if(SIZE(s)%2==1){
		cout << "No\n";
		return 0;
	}
	string t="";
	rep(i,n/2) t+=s[i];
	t+=t;
	Yes(t==s);
	return 0;
}


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

using namespace std;

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

    vector<pair<long long ,long long >> ab(n);
    for(long long i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
    }

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


    long long cnt = 0;
    long long sum = 0;
    bool flag = false;
    for(long long i = 0; i < n; i++){
        cnt += ab[i].second;
        sum += ab[i].first * ab[i].second;
        if(cnt >= m){
            sum -= (cnt - m) * ab[i].first;
            break;
        }
    }


    cout << sum << endl;
}


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

int main(){
  string S,A;
  cin >> S;
  vector<int> s(4);
  for(int i=0;i<4;i++){
    s.at(i) = S.at(i) - '0';
  }
  
  for(int tmp=0;tmp < (1 << 3);tmp++){
    bitset<3> p(tmp);
    int sum=s.at(0);
    
    for(int i=0;i<3;i++){
      if(p.test(i)){
        sum += s.at(i+1);
      }else{
        sum -= s.at(i+1);
      }
    }
    
    if(sum == 7){
      A += to_string(s.at(0));
      for(int i=0;i<3;i++){
        if(p.test(i)){
          A += '+';
        }else{
          A += '-';
        }
        A += to_string(s.at(i+1));
      }
      A += "=7";
      break;
    }
  }
  cout << A << endl;
}
    

Measured memory_bytes: 3696
N, Q = map(int, input().split())
S = input()

count = [0] * N

for i in range(N-1):
	
	if S[i] == 'A' and S[i+1] == 'C':
		count[i] = 1

accum = count.copy()
for i in range(1, N):
	accum[i] += accum[i-1]

for i in range(Q):
	l, r = map(int, input().split())
	l -= 1; r -= 1;
	if l == 0:
		res = accum[r]
	else:
		res = accum[r] - accum[l-1]
	if count[r] == 1:
		res -= 1
	print(res)

Measured memory_bytes: 72688
#include<stdio.h>
int main(void){
  
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
   
  if(abs((b-a)) <= d && abs((c-b)) <= d){
    printf("Yes");
  }else if(abs((c-a)) <= d){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 256
from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
a=1e9
for Y in A:
	C=s(sum((v[:len(v)-K+1]for v in(s(v)for k,v in groupby(A,lambda a:a>=Y)if k)if l(v)>=K),[]))
	if l(C)>=Q:a=min(a,C[Q-1]-Y)
print(a)

Measured memory_bytes: 69084