akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations


def combinations_full_search(n, zero_set=False):
    if zero_set:
        yield tuple()

    for i in range(1, n + 1):
        for pt in combinations(range(n), i):
            yield pt


N, M = [int(v) for v in input().split()]

S = [[int(v) - 1 for v in input().split()[1:]] for _ in range(M)]
P = [int(v) for v in input().split()]

res = 0
for pat in combinations_full_search(N, True):
    patset = set(pat)
    cnt = 0
    for i in range(M):
        s = S[i]
        cnt += int(len(patset.intersection(set(s))) % 2 == P[i])
    res += int(cnt == M)
print(res)


Measured memory_bytes: 3188
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int main() {
	int n; qr(n);
	int ans=n/500*1000+(n%500)/5*5;
	pr2(ans);
	return 0;
}



Measured memory_bytes: 256
#if 0
#cflags(-std=c++14 -Wall)
#endif
#include<iostream>
template<typename T>
T input(std::istream& os = std::cin){T t;os >> t;return t;}

#include<vector>
#include<string>
#include<queue>
#include<numeric>

struct pos{
  int x, y;
  template<typename T>
  auto&& operator[](T&& t)const{return std::forward<T>(t)[y][x];}
};
template<typename F>
struct itr{
  int r;
  std::pair<pos, int> t;
  F shortest;
  bool flag;
  itr& operator++(){++r;flag = true;return *this;}
  int& operator*(){if(flag)t = shortest(r, t.first.x, t.first.y), flag = false;return t.second;}
  bool operator==(const itr& other)const{return r == other.r;}
  bool operator!=(const itr& other)const{return !(*this == other);}
};
template<typename F>
itr<F> make_itr(const pos& p, F&& f){return ++itr<F>{0, {p, 0}, f};}
template<typename F>
itr<F> make_itr(int r, F&& f){return itr<F>{r, {}, f};}

int main(){
  const auto H = input<int>();
  const auto W = input<int>();
  const auto N = input<int>();
  const std::vector<std::string> data = [H]{
    std::vector<std::string> data;
    data.reserve(H);
    for(int i = 0; i < H; ++i)
      data.emplace_back(input<std::string>());
    return data;
  }();
  const pos po = [&]{
    pos po;
    for(int j = 0; j < H; ++j)
      for(int i = 0; i < W; ++i)
        if(data[j][i] == 'S')
          po = {i, j};
    return po;
  }();
  auto shortest = [&](int rank, int i, int j){
    std::vector<std::vector<char>> flags(H, std::vector<char>(W));
    std::queue<std::pair<pos, int>> q;
    q.push({{i, j}, 0});flags[j][i] = true;
    while(true){
      const auto& d = q.front();
      const auto& p = d.first;
      if(p[data] == rank+'0')
        return q.front();
      p[flags] = true;
      auto add = [&](const pos& po){
        if(!po[flags])
          if(po[data] != 'X')
            q.push({po, d.second+1}), po[flags] = true;
          else
            po[flags] = true;
      };
      for(int a = -1; a <= 1; a += 2)
        if(0 <= p.x + a && p.x + a < W)
          add(pos{p.x+a, p.y});
      for(int b = -1; b <= 1; b += 2)
        if(0 <= p.y + b && p.y + b < H)
          add(pos{p.x, p.y+b});
      q.pop();
    }
    return q.front();
  };
  std::cout << std::accumulate(make_itr(po, shortest), make_itr(N+1, shortest), 0) << std::endl;
}

Measured memory_bytes: 4964
import java.util.Scanner;

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

        String strT = in.nextLine();
        String strP = in.nextLine();

        NativeStringSearch.search(strT, strP);
    }
}

class NativeStringSearch {
    static void search(String strT, String strP) {
        for (int i = 0; i < strT.length() - strP.length()+1; i++) {
            if (strT.substring(i, i + strP.length()).equals(strP)) {
                System.out.println(i);
            }
        }
    }
}



Measured memory_bytes: 26576
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MAX_DIGIT = 50;
long long dp[100][2]; // dp[上から i 桁まで][ smaller ]

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0; // 初期条件
    for (int d = 0; d < MAX_DIGIT; ++d) {
        long long mask = 1LL<<(MAX_DIGIT - d - 1);
        
        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
        
        // X の d 桁目を 0, 1 にしたときのコスト
        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);
        
        // smaller -> smaller
        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }
        
        // exact -> smaller
        if (dp[d][0] != -1) {
            if (K & mask) { // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        }
        
        // exact -> exact (K にぴったり合わせる)
        if (dp[d][0] != -1) {
            if (K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
            else chmax(dp[d+1][0], dp[d][0] + cost0);
        }
    }
    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}

Measured memory_bytes: 1024
# your code goes here
import sys

a=[]
for line in sys.stdin:
  line.rstrip('rn')
  tmp=line.split(" ")
  a.append(int(tmp[-1]))

a.sort(reverse=True)
y=0
for i in a:
  if y==3:
    break
  if i>=0 and i<=10000:
    print(i)
    y=y+1

Measured memory_bytes: 7612
#include <stdio.h>

int main()
{
  int N, i, j, flag=1, work, count=0, minj, A[100];

  scanf("%d", &N);
  for(i=0;i<N;i++){
    scanf("%d", &A[i]);
  }

  for(i=0; i<N; i++){
    minj=i;
    for(j=i; j<N; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(minj != i){
      work=A[i];
      A[i]=A[minj];
      A[minj] =work;
      count++;
    }
  }

  for(i=0;i<N;i++){
    if(i==N-1){
      printf("%d",A[i]);
      break;
    }
    printf("%d ", A[i]);
  }

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

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define llrep(i,a,b) for(ll i=a;i<b;i++)
#define llrepd(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    ll N, K; cin >> N >> K;
    ll sum = 0;
    llrep(i, K, N+2) {
        ll final = i*(2*N-i+1)/2;
        ll first = i*(i-1)/2;
        sum = (sum + (final - first + 1)) % MOD;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


vector<LL> fact;
vector<LL> inver(200001);
 
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 
LL hcombi(int n,int r){
    return combi(n+r-1,r); 
}
vector<LL> divi(LL K){
    vector<LL> v;
    for(int i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

vector<LL> pdivi(LL K){
    vector<LL> v;
    for(int i=2;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        while(K%i==0){
            K/=i;
        }
    }
    if(K!=1) v.pb(K);
    return v;
}



int main(){
    set_combi();
    LL n,a,b;cin >> n >> a >> b;
    LL ans = fpow(2,n);
    LL p = inver[a];
    for (int i = 0; i < a; i++) {
        p = p * (n-i) %mod;
    }
    LL q = inver[b];
    for (int i = 0; i < b; i++) {
        q = q * (n-i) %mod;
    }
    ans = (ans - p + mod - q +mod - 1 + mod)%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3956
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
    	int N = scanner.nextInt();
    	
		//System.out.println(N);
		
		if (N%2 == 0) {
			System.out.println(N);
		} else {
			System.out.println(N*2);
		}
	}
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var r = D * 2 + 1;
		Console.WriteLine((N + r - 1) / r);
		
	}
	int N,D;
	public Sol(){
		var d = ria();
		N = d[0]; D = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n)cin >> s[i];
    vector<P> a, b;
    rep(i, n){
        int l = 0;
        int r = 0;
        rep(j, s[i].size()){
            if(s[i][j] == '('){
                r++;
            }else{
                if(r > 0)r--;
                else l++;
            }
        }
        if(r-l>=0)a.push_back(make_pair(l, r));
        else b.push_back(make_pair(-r, l));
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int cnt = 0;
    for(P p : a){
        cnt -= p.first;
        if(cnt < 0){
            cout << "No" << endl;
            return 0;
        }
        cnt += p.second;
    }
    for(P p : b){
        cnt -= p.second;
        if(cnt < 0){
            cout << "No" << endl;
            return 0;
        }
        cnt -= p.first;
    }
    if(cnt != 0)cout << "No" << endl;
    else cout << "Yes" << endl;
    
}

Measured memory_bytes: 42536
#include <cstdio>
using namespace std;

typedef long long ll;

int cnt[41];

inline void add(ll x) {
    int i = 0;
    while (x) {
        if (x & 1) ++cnt[i];
        x >>= 1, ++i;
    }
}

int n;
ll k;

inline ll get(int i) {
    if (i < 0) return 0;
    return (1ll << i) * ((cnt[i] > n - cnt[i]) ? cnt[i] : n - cnt[i]);
}

int main() {
    ll temp;
    scanf("%d%lld", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &temp);
        add(temp);
    }
    ll ans = 0;
    ll new_k = 0;
    for (int i = 39; i >= 0; --i) {
        if (cnt[i] > n - cnt[i]) {
            ans += (1ll << i) * cnt[i];
        } else {
            new_k |= 1ll << i;
            if (new_k > k) {
                new_k ^= 1ll << i;
                ans += (1ll << i) * cnt[i];
            } else {
                ans += (1ll << i) * (n - cnt[i]);
            }
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 760
k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(k[int(input())-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    string s; cin >> s;
    rep(i,s.size()){
        if(s[i]==',') cout << " ";
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
	int h, w;
	while (cin >> h >> w, h != 0 || w != 0) {

		for (int j = 1; j <= h / 2;j++) {
				for (int i = 1; i <= w / 2; i++) {
					cout << '#' << '.';
				}
				if (w % 2 != 0) {
					cout << '#';
				}
				cout << endl;
				for (int i = 1; i <= w / 2; i++) {
					cout << '.' << '#';
				}
				if (w % 2 != 0) {
					cout << '.';
				}
					cout << endl;
		}
		if (h % 2 != 0) {
			for (int i = 1; i <= w / 2; i++) {
				cout << '#' << '.';
			}
			if (w % 2 != 0) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);   
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes";
    } else
    {
        cout<<"No";
    }
    
}

Measured memory_bytes: 256
use io::*;
use std::*;

fn solve(N: i64, M: i64, A: Vec<i64>) {
    let total: i64 = A.iter().sum();
    println!("{}", if N - total >= 0 { N - total } else { -1 });
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut M: i64;
    M = scanner.next();
    let mut A: Vec<i64> = vec![0i64; (M) as usize];
    for i in 0..(M) as usize {
        A[i] = scanner.next();
    }
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, M, A)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b && b==c) cout << '1' << endl;
    else if(a==b || b==c || c==a) cout << '2' << endl;
    else cout << '3' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,q;
    cin >> n;
    vector<int> s(n);
    map<int, int> m;
    rep(i,n){
        cin >> s[i];
        m[s[i]] = 1;
    }
    cin >> q;
    vector<int> t(q);
    int ct = 0;
    rep(i,q){
        cin >> t[i];
        if(m[t[i]] == 1){
            ct++;
        }
    }
    cout << ct << endl;
}


Measured memory_bytes: 10500
def solve(pos, tot, A):
    if tot == 0: return True
    if pos > len(A) - 1: return False

    return solve(pos+1, tot - A[pos], A) or \
           solve(pos+1, tot, A)

n = raw_input()
b = map(int, raw_input().split())
n = raw_input()
t = map(int, raw_input().split())

max = sum(b) + 1
for tt in t:
    print 'yes' if tt < max and True == solve(0, tt, b) else 'no'

Measured memory_bytes: 6404
#include<stdio.h>
#define A 100;
 
main()
{
 
  int num[100], t = 0;
  int i,j;
  int max, mini, s;
 
  scanf("%d", &max);
 
 for(i = 0; i < max; i++){
 
    scanf("%d", &num[i]);
 
  }
 
 
 for(i = 0; i < max; i++){
    
   mini = i;
    
   for(j = i; j < max; j++){
      
     if(num[j] < num[mini]) mini = j;
      
   }
    
     if(mini != i){
       s = num[i];
       num[i] = num[mini];
       num[mini] = s;
       t++;
     }
 }
 for(i = 0; i < max; i++){
 
   if(i>0) printf(" ");
 
   printf("%d",num[i]);
 
 }
 
 printf("\n%d\n",t);
 
 return 0;
}

Measured memory_bytes: 1032
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [A, B] = nextIntArray()
    let min = Math.min(A, B)
    let ans = min
    while (ans <= A * B) {
        if (ans % A == 0 && ans % B == 0) {
            console.log(ans)
            return
        }
        ans += min
    }
}
Main()



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

const int N = 200010;

int n, t, pos[N], w[N], l, lis[N];
int main() {
	scanf("%d%d%d", &n, &l, &t);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &lis[i], &w[i]);
		pos[i] = lis[i];
		if (w[i] == 2) pos[i] -= t;
		else pos[i] += t;
		if (pos[i] < 0) pos[i] += (abs(pos[i]) + l - 1) / l * l;
		pos[i] %= l;
	}
	
	int cnt = 0;
	for (int i = 2; i <= n; ++i) {
		if (w[i] != w[1]) {
			if (w[1] == 1) {
				int del = lis[i] - lis[1];
				if (2 * t >= del) cnt = cnt + (2 * t - del) / l + 1;
			}
			else {
				int del = l - (lis[i] - lis[1]);
				if (2 * t >= del) cnt = cnt + (2 * t - del) / l + 1;
			}
		}
	}

	int p = pos[1], q;
	if (w[1] == 1) q = 1 + cnt % n;
	else q = (cnt % n == 0 ? 1 : 1 - cnt % n + n);
	
	sort(pos + 1, pos + n + 1);
	for (int i = 1; i <= n; ++i) pos[i + n] = pos[i];
	
	
	cnt = 0;
	for (int i = q; i <= 2 * n; ++i) {
		if (pos[i] == p) {
			int start;
			if (pos[i + 1] == p) start = w[1] == 1 ? i + 1 : i;
			else start = i;
			for (int j = start - q + 1; j - start + q - 1 < n; ++j) {
				printf("%d\n", pos[j]);
			}
			break;
		}
	}
}

Measured memory_bytes: 2816
N = int(input())
S = []
T = []
from operator import itemgetter

for _ in range(N):
    s,t = input().split()
    S.append(s)
    T.append(int(t))

X = input()
def main():
    for i in range(N):
        if X == S[i]:
            print(sum(T[i + 1:]))
            return


if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()
#define allpt_r(v) (v).rbegin(), (v).rend()



const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

template <typename T>
void show1dvec(vector<T> v)
{
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << wsp;
    cout << v[n] << rt;
    return;
}

template <typename T>
void show2dvec(vector<vector<T>> v)
{
    int n = v.size();
    rep(i, n) show1dvec(v[i]);
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    string s, ans;
    int q, t, f, ord = 1;
    char c;
    deque<char> deq;
    cin >> s >> q;

    rep(i, s.length()) deq.push_back(s[i]);

    rep(i, q)
    {
        cin >> t;
        if (t == 1)
        {
            ord *= -1;
        }
        if (t == 2)
        {
            cin >> f >> c;
            if (ord == 1 && f == 1) deq.push_front(c);
            if (ord == -1 && f == 2) deq.push_front(c);
            if (ord == 1 && f == 2) deq.push_back(c);
            if (ord == -1 && f == 1) deq.push_back(c);
        }
    }

    for (auto z : deq) ans += z;
    if (ord == -1) reverse(allpt(ans));
    cout << ans << rt;


    return 0;
}


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

int main() {
  long long N;
  cin >> N;
  vector<vector<long long>> V(N,vector<long long>(3,0));
  for (int i = 0; i < N; i++)
    cin >> V.at(i).at(0) >> V.at(i).at(1) >> V.at(i).at(2);
  
  vector<vector<long long>> W(N + 1,vector<long long>(3,0));
  for (int j = 1; j < N + 1; j++) {
    W.at(j).at(0) = max(W.at(j - 1).at(1),W.at(j - 1).at(2)) + V.at(j - 1).at(0);
    W.at(j).at(1) = max(W.at(j - 1).at(2),W.at(j - 1).at(0)) + V.at(j - 1).at(1);
    W.at(j).at(2) = max(W.at(j - 1).at(0),W.at(j - 1).at(1)) + V.at(j - 1).at(2);
  }
  
  cout << max(W.at(N).at(0),max(W.at(N).at(1),W.at(N).at(2))) << endl;
}


Measured memory_bytes: 14084
def main():
    N = input()
    if len(N) == 1:
        print(N)
        return
    for d in N[1:]:
        if d != "9":
            ans = int(N[0]) - 1 + 9 * (len(N)-1)
            print(ans)
            return
    ans = int(N[0]) + 9 * (len(N)-1)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
n = int(raw_input())

red = []
blue = []
data = []

for a in range(n):
  q = map(int,raw_input().split(" "))
  red.append(q)
  data.append(q)

for a in range(n):
  q = map(int,raw_input().split(" "))
  blue.append(q)
  data.append(q)

red.sort()
blue.sort()
data.sort()

s = []
ans = 0

for a in data:
  if a in red:
    s.append(a)
  else:
    q = None
    y = -1
    for b in s:
      if y < b[1] and b[1] < a[1]:
        q = b
        y = b[1]
    if q != None:
      s.remove(q)
      ans += 1

print ans


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string S; cin >> S;
  int len = S.length();
  string s0, s1;
  for(int i = 0; i < len; ++i) {
    if(i % 2 == 0) {
      s0.push_back('0');
      s1.push_back('1');
    } else {
      s0.push_back('1');
      s1.push_back('0');
    }
  }
  int c0=0, c1=0;
  for(int i = 0; i < len; ++i) {
    if(s0[i] != S[i]) c0++;
    if(s1[i] != S[i]) c1++;
  }
  cout << min(c0, c1) << endl;

  return 0;
}


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

namespace AltCoder
{
    public sealed class Begineer149
    {
        public static void Main()
        {
            int[] NK = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            int n = NK[0], k = NK[1];
            int[] RSP = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            string t = Console.ReadLine();
            char[] win = new char[t.Length];
            Dictionary<char, char> winMoves = new Dictionary<char, char>()
            {
                ['r'] = 'p',
                ['p'] = 's',
                ['s'] = 'r'
            };

            Dictionary<char, int> winScores = new Dictionary<char, int>()
            {
                ['r'] = RSP[0],
                ['s'] = RSP[1],
                ['p'] = RSP[2]                
            };

            for (int i = 0; i < t.Length; i++)
            {
                win[i] = (winMoves[t[i]]);
            }

          
          // Console.WriteLine(new string(win));

            long score = 0;
            for (int i = 0; i < win.Length; i++)
            {
                if (i >= k && win[i] == win[i - k])
                {
                    if ((i + k) < win.Length)
                    {
                        win[i] = winMoves[win[i + k]];
                    }
                }

                else
                {
                    score += winScores[win[i]];
                }              
                
            }

            Console.WriteLine(score);
          //  Console.WriteLine(new string(win));
          
        }
    }
}


Measured memory_bytes: 13920
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;
int main(){
    int node[128]={0};
    int ma = -INF;
    int in,out;
    while(~scanf("%d%d",&in,&out)){
        if(ma < in)ma = in;
        if(ma < out)ma = out;
        if(in == 0 && out == 0){
            int cnt = 0;
            bool f = false;
            if(node[1]%2 == 0 || node[2]%2 == 0)f = true;
            reps(i,3,ma+1){
                if(node[i] % 2 == 1)f = true;
            }
            f ? puts("NG") : puts("OK");
            memset(node,0,sizeof(node));
            ma = -INF;
        }
        node[in]++;
        node[out]++;
    }
    return 0;
}

Measured memory_bytes: 1168
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
int32_t main()
{
 int n; cin >> n; vi v(n); fr(i,n) cin >> v[i],v[i]%=2;;
 int ans = 0;
 fr(i,n)  ans += v[i++];
 cout << ans ;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main() {
    /**
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    **/
	FIO
	int n; cin >> n;
	vector<string> words;
	for (int i = 0; i < n; i++) {
		string str; cin >> str;
		words.push_back(str);
	}
	vector<string> w = words;
	if (true) {
		sort(words.begin(), words.end());
		for (int i = 0; i < n-1; i++) {
			if (words[i] == words[i+1]) {
				cout << "No" << "\n";
				exit(0);
			}
		}
	}
	string lw = w[0];
    bool ans = true;
	for (int i = 1; i < n; i++) {
		string s = w[i];
		if ((lw != s) && (s[0] == lw[lw.size()-1]))
			lw = s;
		else {
			ans = false;
			break;
		}
	}
	(ans) ? cout << "Yes" << "\n" : cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 3648
n = int(input())

g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))

color = [-1] * n
dist = [0] * n

import queue
def dfs(v):
    color[v] = dist[v] % 2
    q = queue.LifoQueue()
    q.put(v)

    while not q.empty():
        vv = q.get()
        for next_v in g[vv]:
            if color[next_v[0]] == -1 and next_v[1] != 0:
                dist[next_v[0]] = dist[vv] + next_v[1]
                color[next_v[0]] = dist[next_v[0]] % 2
                q.put(next_v[0])

# 0を始点として各点までの距離を求める
dfs(0)

for c in color:
    print(c)

Measured memory_bytes: 79004
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define A 0
#define C 1
#define G 2
#define T 3

using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
  	long const div = 1000000007;
  	//A, C, G, T
  	//AGC を部分文字列として含まない
  	//3:AGC, ACG, GACの３パターン
  	//4:AGC*, *AGC, A*GC, AG*C, GAC*, *GAC, ACG*, *ACG の３２パターン
    //  から重複するACGC, AAGC, AGAC, AGCC, GACC, GACGの被り６パターンを除く26パターン
  	//A:0, C:1, G:2, T:3
  	int comb[101][4][4][4] = {};
	for (int i=0;i<4;i++) {
        for (int j=0;j<4;j++) {
            for (int k=0;k<4;k++) {
                if (i == A && j == G && k == C) continue;
                if (i == A && j == C && k == G) continue;
                if (i == G && j == A && k == C) continue;
                comb[3][i][j][k] = 1;
            }
        }
    }
  	//動的計画法：dp
    for (int i = 3; i < N; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          for (int l = 0; l < 4; l++) {
            for (int m = 0; m < 4; m++) {
              if (k == A && l == G && m == C) continue;
              if (k == G && l == A && m == C) continue;
              if (k == A && l == C && m == G) continue;
              if (j == A && l == G && m == C) continue;
              if (j == A && k == G && m == C) continue;
              comb[i+1][k][l][m] += comb[i][j][k][l];
              comb[i+1][k][l][m] %= div;
            }
          }
        }
      }
    }
    long ans;
    ans = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          ans += comb[N][i][j][k];
          cerr << i << j << k << ":" <<comb[N][i][j][k] << endl;
          ans %= div;
        }
      }
    }
    cout<<ans<<endl;
    
  	return 0;
}


Measured memory_bytes: 256
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=print.f.map(fst.fromJust.B.readInt).B.words=<<B.getContents
f(_:as)=g 0 0.reverse.zip as.scanl' (\i a->min(maxBound`div`2)$(i-a)*2) 1$as
g j k((a,i):ais)=if a+(j+1)`div`2>i then -1 else g m(k+m)ais where m=min i$a+j
g _ k _=k

Measured memory_bytes: 23032
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n;

vector<int> prefix_function(vector<int>& a){
   int n = a.size();
   int j = 0;
   vector<int> pi(n);
   for (int i = 1; i < n; ++i)
   {
      while(j and a[j] != a[i]){
         j = pi[j-1];
      }
      j += a[j] == a[i];
      pi[i] = j;
   }
   return pi;
}
vector<int> a, b;

vector<int> get(int bits, vector<int>& a, int type){
   vector<int> curr;
   for (int i = 0; i < sz(a); ++i)
   {
      if(a[i] & (1LL << bits)){
         curr.push_back(1 ^ type);
      }
      else{
         curr.push_back(0 ^ type);
      }
   }
   vector<int> v;
   for(auto it: b)
      v.push_back((it & (1LL << bits)) > 0);

   v.push_back(-123456);

   for(auto it: curr)
      v.push_back(it);

   //[b1,b2,b3,...bn] + k + [a1,a2,a3,...an,an+1,an+2,...a2n]
   v = prefix_function(v);
   return v;
}

int32_t main(){_
   
   cin>>n;
   a.resize(2*n);
   b.resize(n);
   vector<vector<int>> bit_pi[31];

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

   for (int i = 0; i < n; ++i)
   {
      cin >> b[i];
   }

   for (int bits = 30; bits >= 0; --bits)
   {
      vector<int> pref0 = get(bits, a, 0);
      vector<int> pref1 = get(bits, a, 1);
      bit_pi[bits].push_back(pref0);
      bit_pi[bits].push_back(pref1);
   }

   for (int k = 0; k < n; ++k)
   {
      int x = 0;
      for (int bits = 30; bits >= 0; --bits)
      {
         // tr(k, bits, b, a, bit_pi[bits][0], bit_pi[bits][1], x);
         if(bit_pi[bits][0][2*n+k] == n){
         }
         else if (bit_pi[bits][1][2*n+k] == n){
            x |= (1LL << bits);
         }
         else{
            x = -inf;
            break;
         }
      }
      if(x != -inf){
         cout<<k<<" "<<x<<endl;
      }
   }

   

   return 0;
}

Measured memory_bytes: 314508
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 19)
#define M 26

int n, t[M][4*MAXN];
int a[M][4 * MAXN];

void build (int a[], int v, int tl, int tr, int ind) {
	if (tl == tr)
		t[ind][v] = a[tl];
	else {
		int tm = (tl + tr) / 2;
		build (a, v*2, tl, tm, ind);
		build (a, v*2+1, tm+1, tr, ind);
		t[ind][v] = t[ind][v*2] + t[ind][v*2+1];
	}
}

int sum (int v, int tl, int tr, int l, int r, int ind) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return t[ind][v];
	int tm = (tl + tr) / 2;
	return sum (v*2, tl, tm, l, min(r,tm), ind) + sum (v*2+1, tm+1, tr, max(l,tm+1), r, ind);
}

void update (int v, int tl, int tr, int pos, int new_val, int ind) {
	if (tl == tr)
		t[ind][v] = new_val;
	else {
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			update (v*2, tl, tm, pos, new_val, ind);
		else
			update (v*2+1, tm+1, tr, pos, new_val, ind);
		t[ind][v] = t[ind][v*2] + t[ind][v*2+1];
	}
}


int main() {
	int n, q;
	string s;
	cin >> n >> s >> q;
	for (int i = 0; i < n; i++) {
		a[s[i] - 'a'][i]++;
	}
	for (int i = 0; i < M; i++) {
		build(a[i], 1, 0, n - 1, i);
	}
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			int pos;
			char c;
			cin >> pos >> c;
			pos--;
			int cc = c - 'a';
			update(1, 0, n - 1, pos, 0, s[pos] - 'a');
			update(1, 0, n - 1, pos, 1, cc);
			s[pos] = c;
		} else {
			int ll, rr;
			cin >> ll >> rr;
			ll--;
			rr--;
			int ret = 0;
			for (int j = 0; j < M; j++) {
				int cur = sum(1, 0, n - 1, ll, rr, j);
				if (cur > 0) {
					ret++;
				}
			}
			cout << ret << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 160852
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <string.h>
using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(i,x) for(int i = 0;i < x;++i)
#define debug(x) cerr << #x << "=" << x << endl

int n;
int diff[123456];

const long long MOD = 1000000007;

template<class T>T my_pow(T a_, unsigned int x_)
{
	if (x_ == 0)return 1;
	T ans = my_pow(a_, x_ / 2);
	return ans * ans * ((x_ % 2) ? a_ : 1) % MOD;
}

int main()
{
	fill(diff, diff + 123456, 0);
	scanf("%d", &n);
	REP(i, n)
	{
		int a;
		scanf("%d", &a);
		diff[a]++;
	}
	bool flag = true;
	if (n % 2)
	{
		if (diff[0] != 1)
		{
			flag = false;
		}
	}
	REP(i, n / 2)
	{
		if (diff[i * 2 + ((n % 2) ? 2 : 1)] != 2)
		{
			flag = false;
		}
	}
	if (!flag)
	{
		printf("0\n");
	}
	else
	{
		long long ans = my_pow<long long>(2, n / 2);
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 768
/*
https://abc106.contest.atcoder.jp/
*/

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;

int main()
{
 	ios::sync_with_stdio(false);
	int A,B;
	int i,j,k;
	while(cin>>A>>B)
	{
		cout<<A*B-A-B+1<<endl;
		
		
		
		
		
	}
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split.map &:to_i

tower = Struct.new(:height, :connect)
h = Array.new(0)

H = gets.chomp.split.map &:to_i
H.each do |i|
  h << tower.new(i,[])
end

m.times do
  a, b = gets.chomp.split.map &:to_i 
  h[a-1].connect << b-1
  h[b-1].connect << a-1
end

#p h

cnt = 0
h.each do |i|
  better_tower_flg = true
  i.connect.each do |j|
    better_tower_flg = false if h[j].height >= i.height
  end
#  p "i,i.connect #{i}, #{i.connect}, better_flg: #{better_tower_flg}"
  cnt += 1 if better_tower_flg
end

p cnt


Measured memory_bytes: 40636
n = int(input())
s = input()

num = 0
for i in range(n-1):
    x = s[:i+1]
    y = s[i+1:]

    setx = {i for i in x}
    sety = {i for i in y}
    common = setx & sety

    num = max(num, len(common))

print(num)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
int n,i,k,j;
int main()
{
	scanf("%d",&n);
	if(n%2==1)
	{
		k=n/2;
		printf("%d\n",2*k*k);
		for(i=1;i<=k;i++)
		{
			for(j=i+1;j<=k;j++)
			{
				printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,j,i,2*k-j+1,2*k-i+1,j,2*k-i+1,2*k-j+1);	
			}	
		} 
		for(i=1;i<=2*k;i++)printf("%d %d\n",i,2*k+1);
	}
	else
	{
		k=n/2;
		printf("%d\n",2*k*k-2*k);
		for(i=1;i<=k;i++)
		{
			for(j=i+1;j<=k;j++)
			{
				printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,j,i,2*k-j+1,2*k-i+1,j,2*k-i+1,2*k-j+1);	
			}	
		} 
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

//HEADER FILES AND NAMESPACES
 
#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;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);  

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r+", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w+", stdout);
#endif  
	
    int N;
    cin >> N;
    vpl A(N);
    for(int i=0;i<N;i++) {
    	int x,y;
    	cin >> x >> y;
    	A[i] = {x,y};
    }
    sort(all(A));
    vl sum1(N), sum2(N);
    sum1[0] = -1*(A[0].f + A[0].s);
    sum2[0] = A[0].s - A[0].f;
    for(int i=1;i<N;i++) {
    	sum1[i] = max(sum1[i-1], -1*(A[i].f + A[i].s));
    	sum2[i] = max(sum2[i-1], A[i].s - A[i].f);
    }
    ll ans = 0;
    for(int i=1;i<N;i++) {
    	ans = max({ans, A[i].f+A[i].s + sum1[i-1], A[i].f-A[i].s+sum2[i-1]});
    }
    cout << ans << '\n';
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 9508
#include <iostream>
#include <cstring>
using namespace std;
int main(){
    char num[6];
    cin >> num;
    int cnt = 1;
    int flag = 0;
    char temp;
    temp = num[0];
    int i;
    for(i = 1; num[i]; i++){
        if(temp == num[i]){
            cnt++;
            if(cnt >= 3){
                flag = 1;
                break;
            }
        }
        else{
            temp = num[i];
            cnt = 1;
        }
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

N = input()
digits = len(N)
if digits <= 2 or int(N[0]) <= 2:
    print(0)
    sys.exit()

ans = 0

queue = deque([("3", 1, 0, 0), ("5", 0, 1, 0),  ("7", 0, 0, 1)])

while queue:

    current, flg3, flg5, flg7 = queue.popleft()

    if len(current) > digits:
        continue    
    if flg3 and flg5 and flg7 and int(current) <= int(N):
        ans += 1

    queue.append((current+"3", 1, flg5, flg7))
    queue.append((current+"5", flg3, 1, flg7))    
    queue.append((current+"7", flg3, flg5, 1))
    
print(ans)

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

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  printf("%s\n",(abs(c-a)<=d||(abs(b-a)<=d&&abs(c-b)<=d))?"Yes":"No");
}


Measured memory_bytes: 256
k = input()
l = input()
a = list(k)
b = list(l)
num1 = len(a)
num2 = len(b)
c = 0
d = 0

for i,j in enumerate(a):
    if j == b[i]:
        c = c + 1
    else:
        d = d + 1
if c == num1 and num1+1 == num2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9136
def fx(x, y, z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x


n = int(input())

ind = {_: 0 for _ in range(1, 10**4 + 1)}
cnt = 0
for i in range(1, 10**4 + 1):
    if fx(i, 1, 1) > 10 ** 4:
        break
    for j in range(1, 10 ** 4 + 1):
        if fx(1, j, 1) > 10 ** 4:
            break
        for k in range(1, 10 ** 4 + 1):
            if fx(i, j, k) <= 10 ** 4:
                ind[fx(i, j, k)] += 1
            else:
                break

for num in range(1, n + 1):
    print(ind[num])

Measured memory_bytes: 9776
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a1 = sc.nextInt();
        int a2 = sc.nextInt();
        int a3 = sc.nextInt();
        int ans = 1000;
        ans = Math.min(ans, Math.abs(a1 - a2) + Math.abs(a1 - a3));
        ans = Math.min(ans, Math.abs(a2 - a1) + Math.abs(a2 - a3));
        ans = Math.min(ans, Math.abs(a3 - a1) + Math.abs(a3 - a2));
        System.out.println(ans);
    }
}

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

int main(){
	int id;
	char c;
	string bt;
	map<string, int> b;
	while(cin >> id >> c >> bt){
		b[bt]++;
	}
	cout << b["A"] << endl;
	cout << b["B"] << endl;
	cout << b["AB"] << endl;
	cout << b["O"] << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pi pair<ll,ll>
#define pii vector<pair<ll,ll> >
#define v vector
#define vi vector<ll>
#define f(a,i,n) for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define MAX 1000001
#define all(x) x.begin(),x.end()
const ll inf=(ll) 1e18;
 
ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
ll spf[MAX+1];
  void sieve()//complexity = approx 3*10^6
    {
        f(1,i,MAX) {spf[i]=i;} 
        for(ll i=2;i<MAX;i+=2){spf[i]=2;}
        for(ll i=3;i<MAX;i+=2)
        {
            if(spf[i]==i) //if i is prime mark its multiples with spf as i
            {
                for(ll j=i*i;j<MAX;j+=i)
                {
                    spf[j]=min(i,(ll)spf[j]);
                }
            }
        }
    }
int main()
{
    ll n;
    cin >> n;
    vi a(n), b(n), c(n);
    f(0, i, n) cin >> a[i] >> b[i] >> c[i];
    ll aa = a[0], bb = b[0], cc = c[0];
    f(1, i, n) {
        ll at = max(bb, cc) + a[i];
        ll bt = max(aa, cc) + b[i];
        ll ct = max(aa, bb) + c[i];
        
        aa = at;
        bb = bt;
        cc = ct;
    }
    
    cout << max(max(aa, bb), cc) << endl;
} 

Measured memory_bytes: 5644
#include<iostream>
using namespace std;
int main(){
  int rv[5]={0};
  int lv[5]={0};
  double rh,lh;
  while(cin>>lh>>rh){
    if(rh>=1.1) rv[1]++;
    else if(rh>=0.6) rv[2]++;
    else if(rh>=0.2) rv[3]++;
    else rv[4]++;
    if(lh>=1.1) lv[1]++;
    else if(lh>=0.6) lv[2]++;
    else if(lh>=0.2) lv[3]++;
    else lv[4]++;
  }
  for(int i=1;i<5;i++) cout << lv[i] << ' ' << rv[i] << endl;
  return 0;
}

Measured memory_bytes: 1224