akhauriyash/Code-Regression huggingface dataset:
import sys
from itertools import permutations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
RC = [list(map(int, readline().split())) for _ in range(N)]

for per in permutations(range(8), 8):
    board = [['.'] * 8 for _ in range(8)]
    flag = True
    for r, c in RC:
        if per[r] != c:
            flag = False
            break
    if flag:
        flag_ = True
        pos = []
        for i, p in enumerate(per):
            if any([abs(i - q[0]) == abs(p - q[1]) for q in pos]):
                flag_ = False
                break
            board[i][p] = 'Q'
            pos.append((i, p))
        if flag_:
            for r in board:
                print(''.join(r))



Measured memory_bytes: 5640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] hm = new int[n][3];
		int[] result = new int[n];
		
		for(int i =0;i<n;i++){
			result[i] = 0;
			for(int k=0;k<3;k++){
				hm[i][k]= sc.nextInt();
			}
		}
		
		for(int k =0;k<3;k++){
			for(int i=0;i<n;i++){
				int sum = hm[i][k];
				for(int j=0;j<n;j++)
					if(hm[i][k]==hm[j][k]&& i!=j)
						sum = 0;
				result[i] += sum;
			}
		}
		
		for(int i=0;i<n;i++){
			System.out.println(result[i]);
		}
	}
}

Measured memory_bytes: 20844
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        string s;
        cin >> s;
        sort(all(s));
        map<char, int> st;
        for (auto e : s) {
            st[e]++;
        }

        if (st.size() != 2) {
            cout << "No" << endl;
            return;
        }

        for (auto e : st) {
            if (e.second != 2) {
                cout << "No" << endl;
            }
        }

        cout << "Yes" << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
import Data.List
import Data.Ord

solve :: Int -> [Int] -> Int
solve n xs = (last xs - head xs) - zs
  where diffList = zipWith (-) (tail xs) xs
        sortDesc = sortOn Down
        zs = sum $ take (n - 1) $ sortDesc diffList

main :: IO ()
main = do
  [n, _] <- map read . words <$> getLine :: IO [Int]
  xs <- sort . map read . words <$> getLine
  print $ solve n xs

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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0);

ll arr[200005] ;

int main()
{
  ll n, k, sum = 0 ;
  cin >> n >> k ;

  for(int i = 0; i < n; i++)  cin >> arr[i] ;
  sort(arr, arr + n, greater<ll>()) ;

  for(int i = k; i < n; i++) {
    sum += arr[i] ;
  }
  cout << sum << endl ;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>

int main(){
	int n,k;
	std::cin >> n >> k;
	int p[n];
	for(int i = 0;i < n;i++){
		std::cin >> p[i];
		p[i]++;
	}
	long long s[n + 1];
	s[0] = 0;
	for(int i = 0;i < n;i++){
		s[i + 1] = s[i] + p[i];
	}
	long long expected[n - k + 1];
	for(int i = 0;i < n - k + 1;i++){
		expected[i] = s[i + k] - s[i];
	}
	std::sort(expected, expected + n - k + 1, std::greater<long long>());
	std::cout << std::fixed << std::setprecision(20) <<(long double)expected[0]/2 << std::endl;
  	return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
char str[20][20];
int dx[]={1,0,-1,0,0};
int dy[]={0,1,0,-1,0};
int num[20][20];
int bfs[130][130][130];
int to[130][5];
int cnt;
struct wolf{
	int a,b,c;
	wolf(int A,int B,int C){
		a=A;b=B;c=C;
	}
	wolf(){
		a=b=c=cnt;
	}
};
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&b,&a,&c),a){
		gets(str[0]);
		for(int i=0;i<a;i++)gets(str[i]);
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)num[i][j]=-1;
		int cnt=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)if(str[i][j]!='#')num[i][j]=cnt++;
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(str[i][j]!='#'){
			for(int k=0;k<5;k++){
				if(0<=i+dx[k]&&i+dx[k]<a&&0<=j+dy[k]&&j+dy[k]<b&&str[i+dx[k]][j+dy[k]]!='#'){
					to[num[i][j]][k]=num[i+dx[k]][j+dy[k]];
				}else to[num[i][j]][k]=-1;
			}
		}
		queue<wolf>Q;
		wolf S;
		wolf T;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			if(str[i][j]=='a'){S.a=num[i][j];str[i][j]='.';}
			if(str[i][j]=='b'){S.b=num[i][j];str[i][j]='.';}
			if(str[i][j]=='c'){S.c=num[i][j];str[i][j]='.';}
			if(str[i][j]=='A'){T.a=num[i][j];str[i][j]='.';}
			if(str[i][j]=='B'){T.b=num[i][j];str[i][j]='.';}
			if(str[i][j]=='C'){T.c=num[i][j];str[i][j]='.';}
		}
		for(int i=0;i<=cnt;i++)for(int j=0;j<=cnt;j++)for(int k=0;k<=cnt;k++)
			bfs[i][j][k]=-1;
		Q.push(S);
		bfs[S.a][S.b][S.c]=0;
		while(Q.size()&&!~bfs[T.a][T.b][T.c]){
			wolf at=Q.front();Q.pop();
			for(int i=0;i<5;i++){
				if(!~to[at.a][i])continue;
				if(c==1){
					if(!~bfs[to[at.a][i]][at.b][at.c]){
						bfs[to[at.a][i]][at.b][at.c]=bfs[at.a][at.b][at.c]+1;
						Q.push(wolf(to[at.a][i],at.b,at.c));
					}
					continue;
				}
				for(int j=0;j<5;j++){
					if(!~to[at.b][j])continue;
					if(c==2){
						int ta=to[at.a][i];
						int tb=to[at.b][j];
						if(!~bfs[ta][tb][at.c]&&ta!=tb&&(ta!=at.b||tb!=at.a)){
							bfs[ta][tb][at.c]=bfs[at.a][at.b][at.c]+1;
							Q.push(wolf(ta,tb,at.c));
						}
						continue;
					}
					for(int k=0;k<5;k++){
						if(!~to[at.c][k])continue;
						int ta=to[at.a][i];
						int tb=to[at.b][j];
						int tc=to[at.c][k];
						if(!~bfs[ta][tb][tc]&&ta!=tb&&ta!=tc&&tb!=tc&&(ta!=at.b||tb!=at.a)&&
						(tb!=at.c||tc!=at.b)&&(tc!=at.a||ta!=at.c)){
							bfs[ta][tb][tc]=bfs[at.a][at.b][at.c]+1;
							Q.push(wolf(ta,tb,tc));
						}
					}
				}
			}
		}
		printf("%d\n",bfs[T.a][T.b][T.c]);
	}
}

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

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


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

const int MAXN = 2010;
char mat[MAXN][MAXN];
bool arr[MAXN][MAXN];
int up[MAXN][MAXN];
int n, m;
int ans;
const int N = 2010;
void calcRPoint(int * A, int * B, int n) {
    static int S[N]; int top = 0;
    for (int i = 1; i <= n; ++i) {
        while (top > 0 && A[S[top]] > A[i])
            B[S[top--]] = i - 1;
        S[++top] = i;
    }
    for (int i = 1; i <= top; ++i) B[S[i]] = n;
}
int calcRow(int * A ,int n) {
    static int L[N], R[N];
    calcRPoint(A, R, n), std::reverse(A + 1, A + 1 + n);
    calcRPoint(A, L, n), std::reverse(A + 1, A + 1 + n);
    int ans = 0; using std::max;
    for (int i = 1, j = n; i <= n; ++i, --j)
        ans = max(ans, (A[i] + 1) * (R[i] - (n - L[j] + 1) + 2));
    return ans;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m; ans = std::max(n, m);
	for (int i = 1; i <= n; ++i) {
		std::cin >> mat[i] + 1;
		for (int j = 1; j <= m; ++j) mat[i][j] = mat[i][j] == '.';
	}
	for (int i = 1; i < n; ++i)
		for (int j = 1; j < m; ++j) {
			arr[i][j] = (mat[i][j] + mat[i][j + 1] + mat[i + 1][j] + mat[i + 1][j + 1]) % 2 == 0;
			up[i][j] = arr[i][j] ? up[i - 1][j] + 1 : 0;
		}
	for (int i = 1; i < n; ++i)
		ans = std::max(ans, calcRow(up[i], m - 1));
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 27168
H, W, D = gets.split.map(&:to_i)

field = H.times.map { gets.split.map(&:to_i) }
id2coord = Hash.new

field.each_with_index do |row, y|
  row.each_with_index do |id, x|
    id2coord[id] = [y, x]
  end
end

cost_table = Hash.new

1.upto(H * W) do |id|
  next if cost_table[id]

  cost = 0
  cost_table[id] = 0

  while id + D <= H * W
    next_id = id + D
    fromY, fromX = id2coord[id]
    toY, toX = id2coord[next_id]

    cost += (toY - fromY).abs + (toX - fromX).abs

    cost_table[next_id] = cost
    id = next_id
  end
end

Q = gets.to_i

query = Q.times.map { gets.split.map(&:to_i) }

query.each do |from, to|
  puts cost_table[to] - cost_table[from]
end


Measured memory_bytes: 28540
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

ll d = 998244353;

ll pow2(ll base, ll pow){
    ll e = pow;
    ll ans = 1;
    ll kake = base;
    if (base == 0){
        return 0;
    }
    while (e > 0){
        if (e%2 == 1){
            ans = (ans * kake) % d;
        }
        kake = (kake * kake) % d;
        e /= 2;
    }
    return ans;
}

int main(void){
    ll n; cin >> n;
    map <ll, ll> m;
    ll max_d = -1;
    REP(i, n){
        ll d; cin >> d;
        if (i==0 && d !=0){
            cout << 0 << endl;
            return 0;
        }
        m[d]++;
        max_d = max(max_d, ll(d));
    }
    ll ans;
    if (m[0] != 1){
        ans = 0;
    } else {
        ans = 1;
    }
    for(ll i=1; i<max_d+1; i++){
        ans = ans * pow2(m[i-1], m[i]);
        ans %= d;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main{

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

    int n = Integer.parseInt(sc.next());

    int[] a = new int[n];
    for (int i=0; i<n; i++){
      a[i] = Integer.parseInt(sc.next());
    }

    for (int i=0; i<n; i++){
      if (a[i] % 2 == 0){
        if (a[i] % 3 != 0 && a[i] % 5 != 0){
          System.out.println("DENIED");
          break;
        }
      }
      if (i == n-1)
        System.out.println("APPROVED");
    }
    
  }
}


Measured memory_bytes: 21844
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		int a = Integer.parseInt(scan.next());
		int b = Integer.parseInt(scan.next());
		String s = scan.next();

		boolean[] ans = new boolean[n];
		int count = 0;
		int rank = 0;
		for(int i = 0;i < n; ++i){
			if(count >= a+b)break;
			if(s.charAt(i) == 'a'){
				ans[i] = true;
				++count;
			}else if(s.charAt(i) == 'b' && rank < b ){
				++rank;
				++count;
				ans[i] = true;
			}
		}		

		for(boolean i: ans){
			System.out.println(i?"Yes":"No");
		}

	}
}



Measured memory_bytes: 40820
def generate_substrings(s):
    N = len(s)

    if N == 0:
        return {''}

    if N == 1:
        return {'', s}

    substrings = set()

    for i in range(N):
        for j in range(1, N + 1):
            substrings.add(s[i:j])

    return substrings


def actual(s):
    sub_strings = generate_substrings(s)
    is_agct = lambda string: set(string).issubset({'A', 'G', 'C', 'T'})

    agct_length_list = [len(s) for s in sub_strings if is_agct(s)]

    return max(agct_length_list)

s = input()
print(actual(s))

Measured memory_bytes: 3064
use std::cmp::min;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    a: usize,
    b: usize,
    c: usize,
    x: usize,
    y: usize,
    }
    let mut ans = 0;
    if x > y {
        ans += min(2 * c * y, (a + b) * y);
        ans += min(2 * c * (x - y), a * (x - y));
    } else {
        ans += min(2 * c * x, (a + b) * x);
        ans += min(2 * c * (y - x), b * (y - x));
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0; i<N; i++){
        cin >> x[i];
        y[i] = x[i];
    }
    sort(x.begin(), x.end());
    int med1 = x[N/2-1];
    int med2 = x[N/2];

    for(int i=0; i<N; i++){
        if(y[i] <= med1) cout << med2 << endl;
        else cout << med1 << endl;
    }
    
}

Measured memory_bytes: 3712
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<string>w(n);
    for(int i=0;i<n;i++)cin>>w[i];
    bool abc=true;
    map<string,int>mp;
    for(int i=0;i<n;i++){
        if(mp[w[i]])
            abc=false;
        mp[w[i]]++;
    }
    for(int i=0;i<n-1;i++){
        if(*(w[i].end()-1)!=*(w[i+1].begin()))
            abc=false;
    }
    if(abc==true)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
x = input()

split_x = x.split(sep=" ")

a = split_x[0]
b = split_x[1]

if int(a) < int(b):
    print("a < b")

if int(a) == int(b):
    print("a == b")

if int(a) > int(b):
    print("a > b")

Measured memory_bytes: 7664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll X; cin >> X;
    ll P = 100;
    while(P < X){
        P = P + P/100;
        res++;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;

int N,M;
vector<int> s[11];
int p[11];
int st=0;
int main(){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int a;
            cin>>a;
            s[i].push_back(a);
        }
    }
    for(int i=0;i<M;i++){
        cin>>p[i];
    }
    int ans=0;
    for(st=0;st<(1<<N);st++){
        bool f=false;
        for(int i=0;i<M;i++){
            int c=0;
            for(auto v:s[i]){
                if(((1<<(v-1))&st)!=0){
                    c++;
                }
            }
            if(c%2!=p[i]){
                f=true;
            }
        }
        if(!f){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int A,B,C,X,count=0;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&X);
    for(int i=0;i<=A;i++)
    {
        int Z = X;
        Z = Z - (500*i);
        for(int j=0;j<=B;j++)
        {
            int Y = Z;
            Y = Y - (100*j);
            for(int k=0;k<=C;k++)
            {
                if(Y==50*k)
                {
                    count++;
                    //printf("%d %d %d %d\n",Z,i,j,k);
                }
            }
        }
    }
    printf("%d",count);
}

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


int N;
vector <int> a;

int main()
{
	cin >> N;
	for (int i=0; i<N; i++){
		int input;
		cin >> input;
		a.push_back(input);
	}
	int counter=0;
	for (int i=0; i<N; i++){
		if (i+1==a[a[i]-1]) counter++;
	}
	cout << counter/2 << endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

 
int main()
{
	int n, m, d;
	cin >> n >> m >> d;
	string s[n];

	REP(i, n) cin >> s[i];

	int count = 0;

	REP(i, n){
		REP(j, m){
			if (j + d > m) break;
			if (s[i].substr(j, d) == string(d, '.')){
				count++;
			}
		}
	}
	string exs[m];

	REP(i, m){
		REP(j, n){
			exs[i] += s[j][i];
		}
	}

	REP(i, m){
		REP(j, n){
			if (j + d > n) break;
			if (exs[i].substr(j, d) == string(d, '.')){
				count++;
			}
		}
	}

	cout << count << endl;

}



Measured memory_bytes: 3232
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {

    string s;
    cin >> s;
    int ans = 114514;
    REP(i,0,26){
        char c = (char)('a' + i);
        string S = c + s + c;
        vector<int> a;
        REP(j,0,S.size()){
            if(S[j] == c){
                a.push_back(j);
            }
        }
        int cnt = 0;
        REP(j,1,a.size()){
            cnt = max(cnt,a[j]-a[j-1]-1);
        }
        ans = min(cnt,ans);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}



int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
	ll a;cin>>a;
	a %= 500;
	ll b;cin>>b;
	if(b >= a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  char s[101];
  scanf("%s",&s);
  int i;
  int f;
  i = 0;
  f = 0;
  while (s[i])
  {
    if (s[i] == 'C' && f == 0)
    {
      f++;
    }
    else if (s[i] == 'F' && f == 1)
    {
      printf("Yes\n");
      return (0);
    }
    i++;
  }
  printf("No\n");
}

Measured memory_bytes: 128
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.range;
import std.algorithm;

int partition(ref int[] a, int p, int r) {
  int x = a[r];
  int i = p;

  for (int j = p; j < r; j++) {
    if (a[j] <= x) {
      swap(a[i], a[j]);
      i++;
    }
  }

  swap(a[i], a[r]);

  return i;
}

void main() {
  int n = readln.chomp.to!int;
  int[] a = readln.chomp.split.map!(to!int).array;

  int pivot = partition(a, 0, (a.length - 1).to!int);

  foreach (int i, int e; a) {
    if (i != 0) { " ".write; }
    if (i == pivot) { writef("[%d]", e); }
    else { e.write; }
  }

  writeln;
}

Measured memory_bytes: 4056
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {
	int n, k[105];
	cin >> n;

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

	vector<int>ans;
	ans.push_back(k[0]);
	for (int i = 1; i < n - 1; ++i) {
		ans.push_back(min(k[i - 1], k[i]));
	}
	ans.push_back(k[n - 2]);

	cout << accumulate(all(ans), 0) << endl;
}

Measured memory_bytes: 256
N, L, T = gets.split.map(&:to_i)
xs, ys = [], []
N.times do |i|
    xs[i], ys[i] = gets.split.map(&:to_i)
end

tracking = 0
(1...N).each do |i|
    next if ys[0] == ys[i]
    if ys[0] == 1
        dist = xs[i] - xs[0]
        times = (2 * T - dist - 1) / L + 1
        tracking = (tracking + times) % N
    else
        dist = xs[0] - xs[i] + L
        times = (2 * T - dist - 1) / L + 1
        tracking = (tracking - times) % N
    end
end

pos = []
N.times do |i|
    if ys[i] == 1
        pos[i] = (xs[i] + T) % L
    else
        pos[i] = (xs[i] - T) % L
    end
end
tracking_pos = pos[0]
pos.sort!
if ys[0] == 1
    target = pos.index(tracking_pos)
else
    target = pos.rindex(tracking_pos)
end

N.times do |i|
    puts pos[(i-tracking+target)%N]
end

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<ll, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int d, n;
  n = 26;
  cin >> d;
  vi c(n);
  rep(i, n) cin >> c[i];
  vvi s(d, vi(n));
  rep(i, d) rep(j, n) cin >> s[i][j];
  vi l(n, -1);
  vector<vector<P>> g(d, vector<P>(n));
  vi ans(d);
  rep(i, d) {
    rep(j, n) {
      g[i][j].first = s[i][j];
      g[i][j].second = j;
      rep(k, n) {
        if (j != k) g[i][j].first -= (ll)c[k] * (i - l[k]);
      }
    }
    sort(g[i].rbegin(), g[i].rend());
    // dump(g[i]);
    int mi = g[i][0].second;
    l[mi] = i;
    ans[i] = mi;
  }
  auto score = [&] (vi& sel) {
    ll sc = 0;
    l.assign(n, -1);
    rep(i, d) {
      sc += s[i][sel[i]];
      l[sel[i]] = i;
      rep(k, n) sc -= (ll)c[k] * (i - l[k]);
    }
    return sc;
  };
  ll msc = score(ans);
  dump(msc);
  rep(k, 5) {
    rep(i, d) {
      int ix = i;
      for (int j = 1; j < n; j++) {
        vi sel = ans;
        sel[ix] = g[ix][j].second;
        ll ss = score(sel);
        // dump(i, ss, sel);
        if (msc < ss) {
          ans = sel;
          msc = ss;
        }
      }
    }
    dump(k, msc);
  }
  rep(i, d) {
    int j = ans[i];
    g[i][j].first = s[i][j];
    g[i][j].second = j;
    rep(k, n) {
      if (j != k) g[i][j].first -= (ll)c[k] * (i - l[k]);
    }
    sort(g[i].rbegin(), g[i].rend());
  }
  rep(k, 3) {
    rep(i, d) {
      int ix = i;
      for (int j = 1; j < 5; j++) {
        vi sel = ans;
        sel[ix] = g[ix][j].second;
        ll ss = score(sel);
        // dump(i, ss, sel);
        if (msc < ss) {
          ans = sel;
          msc = ss;
        }
      }
    }
    dump(k, msc);
  }
  rep(i, d) cout << ans[i] + 1 << endl;
  dump(msc);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3832
import sys
cin = sys.stdin
while True:
    n = int(cin.readline())
    if n == 0:break
    c = {}
    for _ in range(n):
        a,b = cin.readline().strip().split()
        c[a] = b
    m = int(cin.readline())
    ans = ''
    for _ in range(m):
        a = cin.readline().strip()
        ans+=c[a] if a in c else a
    print(ans)

Measured memory_bytes: 7900
#include<iostream>

using namespace std;

#define MAX 1010
typedef unsigned long long ull;

int H,W,R,C;
char field[MAX][MAX],pattern[MAX][MAX];
ull hash1[MAX][MAX],tmp[MAX][MAX];

void compute_hash(char a[MAX][MAX],int w,int h){
    const ull B1 = 9999973;
    const ull B2 = 950527;
    
    ull t1 = 1;
    // ハッシュ作成列
    for(int j = 0 ; j < C ; ++j) t1 *= B1;
    
    for(int i = 0 ; i < w ; ++i){
        ull e = 0;
        for(int j = 0 ; j < C ; ++j){
          e = e * B1 + a[i][j];
        }
        for(int j = 0 ; j + C <= h ; ++j){
            tmp[i][j] = e;
            if(j + C < h) e = e * B1 - t1 * a[i][j] + a[i][j + C];
        }
    }
    
    // ハッシュ作成行
    ull t2 = 1;
    for(int i = 0 ; i < R ; ++i) t2 *= B2;
    
    for(int j = 0 ; j + C <= h ; ++j){
        ull e = 0;
        for(int i = 0 ; i < R ; ++i) e = e * B2 + tmp[i][j];
        
        for(int i = 0 ; i + R <= w; ++i){
            hash1[i][j] = e;
            if(i + R < w) e = e * B2 - t2 * tmp[i][j] + tmp[i + R][j];
        }
    }
}

void solve(){
    compute_hash(pattern, R, C);
    ull res = hash1[0][0];
    compute_hash(field, W, H);
    for(int i = 0 ; i <= W ; ++i){
        for(int j = 0 ; j <= H ; ++j){
            if(res == hash1[i][j]){
                cout << i << " " << j << endl;
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> W >> H;
    for(int i = 0 ; i < W ; ++i){
        for(int j = 0 ; j < H ; j++){
            cin >> field[i][j];
        }
    }
    cin >> R >> C;
    for(int i = 0 ; i < R ;++i){
        for(int j = 0 ; j < C ;++j){
            cin >> pattern[i][j];
        }
    }
    if(W < R && H < C) return 0;
    solve();
}



Measured memory_bytes: 19896
a, b, k = map(int, input().split()) 

divisorA = [ i for i in range(1,a+1 ) if a % i == 0 ]
divisorB = [ i for i in range(1,b+1 ) if b % i == 0 ]

divisor = []

for elemA in divisorA:
	divisor += filter(lambda elem: elem == elemA, divisorB)	

divisor = sorted(divisor)
divisor = divisor[::-1]
# print(divisor)

print( divisor[k-1] )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge{ int from, to, cost; };

char eki[52];

int main()
{
	eki[0] = 'a';
	FOR(i, 1, 26) eki[i] = eki[i - 1] + 1;
	eki[26] = 'A';
	FOR(i, 27, 53)
	{
		eki[i] = eki[i - 1] + 1;
	}
	int n;
	while (cin >> n, n)
	{
		vector<int> v;
		string ans = "";
		int a[105];
		REP(i, n) cin >> a[i];
		while (v.size() < 105)
		{
			REP(i, n) v.push_back(a[i]);
		}


		string s; cin >> s;
		REP(i, s.size())
		{
			char *p = find(eki, eki + 52, s[i]);
			int m = p - eki;
			m -= v[i];
			if (m < 0) m += 52;
			ans += eki[m];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define int long long
using namespace std;
int pw(int a, int b, int c){
	if (b==0) return 1;
	if (b==1) return a;
	if (b%2){
		int rs = pw(a, b-1, c);
		return (rs*a)%c;
	}
	int rs = pw(a, b/2, c);
	return (rs*rs)%c;
}
vector<int> fact;
int gc(int a, int b, int c){
	int X = fact[a];
	int Y = (fact[b] * fact[a-b]) % c;
	return (X * pw(Y, c-2, c)) % c;
}
int dp[3005][3005];
signed main(){
	//freopen("1.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
	int w = pw(2, n, m-1);
	int res = pw(2, w, m);
    int v = 0;
    fact.push_back(1);
    for (int i=1; i < 5000; i++){
		fact.push_back(fact.back() * i);
		fact.back() %= m;
    }
    for (int i=0; i < 3005; i++) for (int j=0; j < 3005; j++) dp[i][j] = 0;
    dp[0][0] = 1;
	for (int i=1; i < 3005; i++){
		for (int j=3004; j >= 0; j--){
			dp[i][j] = 0;
			if (j+1 <= 3004){
				dp[i][j+1] += dp[i-1][j];
				dp[i][j+1] %= m;
			}
			dp[i][j] = dp[i-1][j] * (j+1);
			dp[i][j] %= m;
		}
	}
    for (int bits = 1; bits <= n; bits++){
        int rest = n - bits;
        int dop = pw(2, rest, m-1);
        int var = pw(2, dop, m);
		int th = 0;
       // cout << dp[2] << endl;
        for (int j=1; j <= bits; j++){
			int C = pw(2, rest, m);
			C = pw(C, j, m);
            C *= dp[bits][j];
            C %= m;
			th += C;
			th %= m;
        }
        th++;
        th *= var;
        th %= m;
        th *= gc(n, bits, m);
        //cout << th << endl;
        if (bits % 2) v += th;
        else v -= th;
        v %= m;
    }
    res -= v;
    res %= m;
    if (res < 0) res += m;
    cout << res;
}


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

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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                sum += gcd(i, gcd(j, k));
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>

using namespace std;


int main() {

	int r;

	cin >> r;

	if (r < 1200) {
		cout << "ABC" << endl;
	}
	else if (r < 2800) {
		cout << "ARC" << endl;
		
	}
	else {
		cout << "AGC" << endl;
	}


	return 0;

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    map<int, int> R, B; //R's key is b, B's key is c
    rep(i, N){
        int a, b;
        cin >> a >> b;
        R[b] = a;
    }
    rep(i, N){
        int c, d;
        cin >> c >> d;
        B[c] = d;
    }

    int ans = 0;
    while(B.size() != 0){
        int c_min = INF;
        int b_max = -1;
        for(auto i : B){
            c_min = min(c_min, i.first);
        }
        
        int d = B[c_min];
        B.erase(c_min);

        for(auto i : R){
            if(i.first < d && i.second < c_min && i.first > b_max){
                b_max = i.first;
            }
        }

        if(b_max != -1){
            ans++;
            R.erase(b_max);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
        int n, l;
        cin >> n >> l;
        vector<string> v(n);
        for (int i = 0; i < n; ++i)
                cin >> v[i];

        sort(v.begin(), v.end());
        for (int i = 0; i < n; ++i)
                cout << v[i];
        cout << endl;
        return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll n,m;
ll p[1001];
vector<ll> v;
int main()
{while(1){
	v.clear();
	cin>>n>>m;
	if(!n) break;
	p[0]=0;
	rep1(i,n) cin>>p[i];
	rep(i,n+1) rep(j,n+1){
		v.pb(p[i]+p[j]);
	}
	sort(v.begin(),v.end());
	ll ans;
	ans=0;
	//ans=v[upper_bound(v.begin(),v.end(),m)-v.begin()-1];
	rep(i,n+1) rep(j,n+1){
		if(p[i]+p[j]<=m) ans=max(ans,v[upper_bound(v.begin(),v.end(),m-p[i]-p[j])-v.begin()-1]+p[i]+p[j]);
	}
	//for(ll i=n/2;i<n;i++) if(p[i]<=m) ans=max(ans,v[upper_bound(v.begin(),v.end(),m-p[i])-v.begin()-1]+p[i]);
	//for(ll i=n/2;i<n;i++) for(ll j=i+1;j<n;j++) if(p[i]+p[j]<=m) ans=max(ans,v[upper_bound(v.begin(),v.end(),m-p[i]-p[j])-v.begin()-1]+p[i]+p[j]);
	//vector<ll>(v).swap(v);
	cout<<ans<<endl;
}}

Measured memory_bytes: 11152
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String strAry[] = br.readLine().split(" ");
    
        int x = Integer.parseInt(strAry[0]);
        int y = Integer.parseInt(strAry[1]);
        
        String op;
    
        op = x > y ? ">": x == y  ? "==" : "<";
        
        System.out.println("a " + op + " b");
    }
}

Measured memory_bytes: 24068
n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
  a.append(a[i]*2+3)
  p.append(p[i]*2+1)

def f(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<= 1 + a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])


print(f(n,x))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef long long ll;
typedef long double ld;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define rrep1(i,x) for(int i = x ; i > 0 ; i --)
#define fr first
#define sc second
#define pb push_back

const int INF = 1000000000;

struct A{
	int a[12];
	A operator*(A y){
		for(int i = 0 ; i < 12 ; i ++){
			this->a[i] = y.a[this->a[i]];
		}
		return *this;
	}
	void show(){
		for(int i = 0 ; i < 12 ; i ++){
			printf("%d ",a[i]);
		}
		cout << endl;
	}
};

int n,k;
char c[30];
A a[30];

struct Syn{
	string s;
	int dfs1(int loc,A* memory){
		/*printf("dfs1:");
		cout << s.substr(loc) << endl;*/
		A ret;
		for(int i = 0 ; i < 12 ; i ++){
			ret.a[i] = i;
		}
		while(1){
			A a_;
			loc = dfs2(loc,&a_);
			ret = ret*a_;
			//cout << s[loc] << endl;
			if(loc >= s.size() || s[loc] != '+'){
				//ret.show();//////////////////////////////////////////////////
				*memory = ret;
				return loc;
			}
			else loc ++;
		}
	}
	int dfs2(int loc,A* memory){
		/*printf("dfs2:");
		cout << s.substr(loc) << endl;*/
		A ret;
		for(int i = 0 ; i < 12 ; i ++){
			ret.a[i] = i;
		}
		for(int i = 0 ; i < k ; i ++){
			if(s[loc] == c[i]){
				*memory = a[i];
				//a[i].show();//////////////////////////////////////////////////////
				return loc+1;
			}
		}
		int t;
		loc = dfs3(loc,&t);
		A a_;
		if(s[loc] != '('){
			for(int i = 0 ; i < k ; i ++){
				if(s[loc] == c[i]){
					a_ = a[i];
					loc += 1;
				}
			}
		}
		else {
			loc = dfs1(loc+1,&a_);
			loc += 1;
		}
		vector<int> G[12];
		for(int i = 0 ; i < 12 ; i ++){
			G[i].pb(i);
			while(1){
				int nex = a_.a[G[i][G[i].size()-1]];
				if(nex == G[i][0])break;
				G[i].pb(nex);
			}
			memory->a[i] = G[i][t%G[i].size()];
		}
		//memory->show();/////////////////////////////////////
		return loc;
	}
	int dfs3(int loc,int* memory){
		/*printf("dfs3:");
		cout << s.substr(loc) << endl;*/
		int ret = 0;
		while('0' <= s[loc] && s[loc] <= '9'){
			ret *= 10;
			ret += s[loc]-48;
			loc ++;
		}
		//cout << ret << endl;
		*memory = ret;
		return loc;
	}
}Syn;

int main(){
	scanf("%d%d",&n,&k);
	for(int i = 0 ; i < k ; i ++){
		int h;
		scanf("\n%c",&c[i]);
		scanf("%d",&h);
		for(int j = 0 ; j < 12 ; j ++){
			a[i].a[j] = j;
		}
		for(int j = 0 ; j < h-1 ; j ++){
			for(int t = 0 ; t < n-1 ; t ++){
				int in;
				scanf("%d",&in);
				if(in)swap(a[i].a[t],a[i].a[t+1]);
			}
		}
		A b;
		for(int j = 0 ; j < 12 ; j ++){
			b.a[a[i].a[j]] = j;
		}
		swap(a[i],b);
		/*printf("%c:",c[i]);
		for(int j = 0 ; j < n ; j ++){
			printf("%d ",a[i].a[j]+1);
		}*/
	}
	int e;
	scanf("%d",&e);
	rep(ppp,e){
		A ans;
		cin >> Syn.s;
		Syn.dfs1(0,&ans);
		A ret;
		for(int i = 0 ; i < n ; i ++){
			ret.a[ans.a[i]] = i;
		}
		for(int i = 0 ; i < n ; i ++){
			printf("%d%c",ret.a[i]+1,(i==n-1)?'\n':' ');
		}
	}
}

Measured memory_bytes: 1296
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;

long long gcd(int x, int y){
    if(y==0)return x;
    else return gcd(y,x%y);
}

int main(int argc, char const *argv[]) {
    int n,m;cin>>n>>m;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> s(n,0);
    for(int i=0;i<n;++i){
        for(int k=0;k<m;++k){
            cin>>a[i][k];
            a[i][k]--;
        }
    }
    vector<bool> b(m,false);
    int res = 1<<30;
    for(int i=0;i<m;++i){
        vector<int> num(m,0);
        for(int k=0;k<n;++k)num[a[k][s[k]]]++;
        int ma=-1,argma;
        for(int k=0;k<m;++k){
            if(num[k]>ma){
                ma=num[k];
                argma=k;
            }
        }
        res = min(res,ma);
        b[argma]=true;
        if(i==m-1)break;
        for(int k=0;k<n;++k){
            while(b[a[k][s[k]]])s[k]++;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<queue>
using namespace std;
int main() {
	int w, h, sx, sy, gx, gy, n;
	while (cin >> w >> h, w) {
		cin >> sx >> sy >> gx >> gy >> n;
		int map[110][110] = {};
		for (int i = 0; i < n; i++) {
			int c, d, x, y; cin >> c >> d >> x >> y;
			map[x][y] = c;
			map[x][y + 1] = c;
			map[x + 1][y] = c;
			map[x + 1][y + 1] = c;
			if (d == 0) {
				map[x + 2][y] = c;
				map[x + 2][y + 1] = c;
				map[x + 3][y] = c;
				map[x + 3][y + 1] = c;
			}
			else {
				map[x][y + 2] = c;
				map[x + 1][y + 2] = c;
				map[x][y + 3] = c;
				map[x + 1][y + 3] = c;
			}
		}
		queue<pair<int, int> >q;
		int p = map[sx][sy];
		if (p == 0)goto museum;
		q.push(make_pair(sx, sy));
		while (q.size()) {
			int x = q.front().first, y = q.front().second;
			q.pop();
			map[x][y] = 0;
			if (x == gx&&y == gy)goto heaven;
			if (map[x][y - 1] == p)q.push(make_pair(x, y - 1));
			if (map[x][y + 1] == p)q.push(make_pair(x, y + 1));
			if (map[x - 1][y] == p)q.push(make_pair(x - 1, y));
			if (map[x + 1][y] == p)q.push(make_pair(x + 1, y));
		}
		museum:cout << "NG\n"; goto park;
	heaven:cout << "OK\n";
	park:;
	}
}

Measured memory_bytes: 3080
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	string s = rstring;
	int k = rint;

	long[] ds = s.map!(c => (c - '0').to!long).array;

	long ans = calc(ds, k);
	ans.writeln;
}

long calc(long[] ds, int k){
	int n = ds.length.to!int;
	if(k > n) return 0;
	if(ds[0] == 0) return calc(ds[1 .. $], k);
	if(k == 1) return ds[0] + (n - 1) * 9;
	else{
		long ans;
		if(k - 1 <= n) ans += calc(ds[1 .. $].map!(d => 9L).array, k); // 最上位0
		foreach(i; 1 .. ds[0]) ans += calc(ds[1 .. $].map!(d => 9L).array, k - 1);
		ans += calc(ds[1 .. $], k - 1);
		return ans;
	}

}


Measured memory_bytes: 1276
a = []
tmp_1 = 1
tmp_2 = 1
while(True):
  tmp_1,tmp_2  = map(int,input().split())
  if tmp_1 == 0 and tmp_2 == 0:
    break
  else:
    x  = [tmp_1,tmp_2]
    x.sort()
    a.append(x)
    
for i in range(len(a)):
  print(f'{a[i][0]} {a[i][1]}')


Measured memory_bytes: 6032
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0

A,B,C,D = map(int, readline().split())



x = A+B -(C+D)
if x > 0:
	result="Left"
elif x == 0:
	result ="Balanced"
else:
	result="Right"


print(result)


Measured memory_bytes: 3060