akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3F3F3F3F;
const int maxn = 1e6 + 555;
const int MOD = 1e9 + 7;
bool vis[maxn];
vector<int> V;
bool gao() {
    for (int i : V) {
        for (int j = 1; j * j <= i; j++) {
            if (i % j == 0) {
                if ((vis[j] && j != 1) || (vis[i / j] && (i / j) != 1))
                    return false;
                vis[j] = 1;
                vis[i / j] = 1;
            }
        }
    }
    return true;
}
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n;
    cin >> n;
    V.resize(n);
    for (auto &i : V)
        cin >> i;
    if (gao()) {
        cout << "pairwise coprime" << endl;
    } else {
        int g = 0;
        for (auto i : V)
            g = __gcd(i, g);
        if (g == 1)
            cout << "setwise coprime" << endl;
        else {
            cout << "not coprime" << endl;
        }
    }
    return 0;
}

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

int NMAX = 100000;
int MAX  =  10000;

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

  int h[NMAX + 1];
  for (int i = 0; i <= NMAX; i++ ) h[i] = 0;

  for (int i = 1; i <= N; i++ ) cin >> h[i];

  int dp[NMAX + 1];
  for (int i = 0; i <= NMAX; i++ ) dp[i] = MAX;

  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);
  for (int i = 3; i <= N; i++ ) {
    dp[i] = min( abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 1024
b = input()

tmp = 0
total = 0
for i in b :
    if i == 'A' or i == 'C' or i == 'G' or i == 'T':
        tmp += 1
        total = max(total,tmp)
    else:
        total = max(total,tmp)
        tmp = 0

print(total)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);cerr<<fixed<<setprecision(5);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
/* VARIABLE DECLARATION START */
int globe[int(1e6)];
/*  FUCNTION TEMPLATE STARTS  HERE */
double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
   string s1,s2,s3;
   cin>>s1>>s2>>s3;
   string s="A"+string(1,s2.front())+"C";
   cout<<s;
   
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  long n;
  cin >> n;
  long p = sqrt(n);
  for(long i = p; i >= 1;i--){
    if(n % i != 0) continue;
    long a = i;
    long b = n/i;
    string sa = to_string(a);
    string sb = to_string(b);
    cout << max(sa.size(),sb.size()) << endl;
    return 0;
  }
}


Measured memory_bytes: 256
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    func enumerated() -> EnumerateSequence<[Element]> {
        return self.enumerate()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}
//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** テストスペース ***************/

//arr.sort{$0.0==$1.0 ? $0.1<$1.1 : $0.0<$1.0}  // 2つの条件に優先順位をつけてソート

/*************** メインプログラム ***************/

var time = readIntSplit(by: " ")
time.sort()
print(time[0] + time[1])


Measured memory_bytes: 7908
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sign cout<<"-----------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

signed main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<a[2]-a[0]<<en;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, v) = readLine()!!.split(' ').map { it.toLong() }
    val (b, w) = readLine()!!.split(' ').map { it.toLong() }
    val t = readLine()!!.toLong()

    val distance = if (b > a) {
        b - a
    } else {
        a - b
    }

    if (w >= v) {
        if(distance <= t){
            println("NO")
        }else{
            println("NO")
        }
        return
    }


    if (distance <= (v - w) * t) {
        println("YES")
    } else {
        println("NO")
    }
}

Measured memory_bytes: 36488
S = input()


def next_sun(S):
    m = {
        'SUN': 7,
        'MON': 6,
        'TUE': 5,
        'WED': 4,
        'THU': 3,
        'FRI': 2,
        'SAT': 1
    };
    return m[S]

print(next_sun(S))

Measured memory_bytes: 2940
#include<stdio.h>
#define N 100
int main(){
  int A[N],n,i,j,count=0;
  int minj=101,x,y,w;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &A[i]);

  for(i = 0; i < n-1; i++){
    minj = i;
    x = A[i];
    for( j = i; j < n; j++){
      if(A[j] < A[minj])
	minj = j;
    }
    A[i] = A[minj];
    A[minj] = x;
    if( i != minj)
      count++;
  }
  

 
  for(i = 0; i < n; i++){
    if( i > 0)
      printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n", count);

  return 0;
}





Measured memory_bytes: 2128
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
c1=a.select{|x|x.odd?}.size
c2=a.select{|x|x%4!=0&&x.even?}.size
c3=a.select{|x|x%4==0}.size
if c3==0
  if c1>0 or c2==1
    puts 'No'
  else
    puts 'Yes'
  end
else
  if c1==c3
    puts 'Yes'
  else
    if c3>=c1-1
      if c2>=1 && c3==c1-1
        puts 'No'
      else
        puts 'Yes'
      end
    else
      puts 'No'
    end
  end
end


Measured memory_bytes: 9228
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Snake s;
		
		for(int i=0;i<n;i++){
			s = new Snake(scan.next());
			System.out.println(s.getType());
		}
	}
}

class Snake{
	String snake;
	
	Snake(String str){
		snake = str;
	}
	
	public String getType(){
		switch(checkHead()){
		case 1:
			return "A";
		case 2:
			return "B";
		default:
			return "NA";
		}
	}
	
	public int checkHead(){
		if(snake.charAt(0) == 62){
			if(snake.charAt(1) == 39){
				return checkBodyA();
			}else if(snake.charAt(1) == 94){
				return checkBodyB();
			}
		}
		return -1;
	}
	
	public int checkBodyA(){
		int count = 0;
		boolean flag = true;
		
		if(snake.charAt(2) == 61){
			count++;
		}else{
			return -1;
		}
		
		for(int i=3;i<snake.length()-1;i++){
			if(flag){
				if(snake.charAt(i) == 61){
					count++;
				}else if(snake.charAt(i) == 35){
					flag = false;
				}else{
					return -1;
				}
			}else{
				if(snake.charAt(i) == 61){
					count--;
				}else{
					return -1;
				}
			}
		}
		
		if(count == 0){
			if(snake.charAt(snake.length()-1) == 126){
				return 1;
			}
		}
		
		return -1;
	}
	
	public int checkBodyB(){
		boolean flag = false;
		
		for(int i=3;i<snake.length();i+=2){
			if(snake.charAt(i-1)==81){
				if(snake.charAt(i) == 61){
					flag = true;
				}else{
					return -1;
				}
			}else if(snake.charAt(i-1) == 126){
				if(snake.charAt(i) == 126){
					if(flag){
						return 2;
					}else{
						return -1;
					}
				}else{
					return -1;
				}
			}else{
				return -1;
			}
		}
		
		return -1;
	}
}

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



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

    int ans=0;
    rep2(i,1,(N+1)){
        int cnt=0;
        if(i%2==1){
            rep2(j,1,(i+1)){
                if(i%j==0) cnt++;
            }
            if(cnt==8) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
blue_cards={}
red_cards={}

for i in range(n):
    s=input()
    if s in blue_cards:
        blue_cards[s]+=1
    else:
        blue_cards[s]=1

m=int(input())

for j in range(m):
    s=input()
    if s in red_cards:
        red_cards[s]+=1
    else:
        red_cards[s]=1

ans=0
for word in blue_cards:
    if word not in red_cards:
        ans=max(ans, blue_cards[word])
    else:
        ans=max(ans, blue_cards[word]-red_cards[word])

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int solve(int x){
  if(400 <= x && x<600) return 8;
  if(600 <= x && x<800) return 7;
  if(800 <= x && x<1000) return 6;
   if(1000 <= x && x<1200) return 5;
   if(1200 <= x && x<1400) return 4;
   if(1400 <= x && x<1600) return 3;
   if(1600 <= x && x<1800) return 2;
   if(1800 <= x && x<2000) return 1;
}
int main(){
  int k=0;
  cin>>k;
  cout<<solve(k)<<'\n';
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstring>

#define rep(X, Y) for( int X = 0; X < Y; ++X )

int n, m;
int N[1001], M[1001];
int cnt[1001];

int main(){
	memset( cnt, 0, sizeof(cnt) );

	std::cin >> n >> m;

	rep( i, n ) std::cin >> N[i];

	rep( i, m ) std::cin >> M[i];

	rep( i, m ) rep( l, n ) if( N[l] <= M[i] ){
		cnt[l]++;
		break;
	}

	std::cout << std::max_element( cnt, cnt + n ) - cnt + 1 << std::endl;

	return 0;
}

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

constexpr long long int M = 1000000007;

template<int N>
struct Fact{
  long long int val[N];
  constexpr Fact() : val() {
    val[0] = 1;
    for(int i = 1; i < N; ++i)val[i] = val[i - 1] * i % M;
  }
};

template<int N, long long F>
struct IFact{
  long long int val[N];
  constexpr IFact() : val() {
    val[N - 1] = F;
    for(int i = N - 1; i > 0; --i)val[i - 1] = val[i] * i % M;
  }
};

long long int N, ans;
constexpr auto fact = Fact<1000000>();
constexpr auto ifact = IFact<1000000, 498215386>();

int main(){
    scanf("%lld", &N);
    for(int i = N / 2; i < N - 1; ++i){
        ans += fact.val[i] * fact.val[i - 1] % M * ifact.val[i * 2 - N] % M;
    }
    ans = fact.val[N - 1] * (N - 1) - ans;
    ans %= M;
    cout << (ans > 0 ? ans : M + ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int a, b;
int main()
{
	scanf("%d %d", &a, &b);
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < sz(t); i++) {
        ans += s[i] != t[i];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll ang;
    cin>>ang;
    if(360%ang==0)cout << 360/ang <<"\n";
    else {
        ll x=360;
        ll ans=0;
        while(true){
            x+=360;
            ans++;
            if(x%ang==0){
                cout << x/ang <<"\n";
                return;
            }
        }
    }

}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
import math
import collections
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)

Measured memory_bytes: 29300
l=[]
s=int(input())
num=0
ans=0
l.append(s)
for i in range(10**6):
    if s%2==0:
        s=s//2
    else:
        s=3*s+1
    num=l.count(s)
    l.append(s)
    if num>0:
        ans=i+2
        break
print(ans)

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

bool check(int x, int y);
void jump(bool f[10][10], int x, int y);

int dx[12] = {2,2,2,1,0,-1,-2,-2,-2,-1,0,1};
int dy[12] = {1,0,-1,-2,-2,-2,-1,0,1,2,2,2};

int main() {
	while (true) {
		int px, py, n, x[10], y[10];
		
		cin >> px >> py;
		if (!px && !py) break;		
		cin >> n;
		REP(i, n) scanf("%d %d", &x[i], &y[i]);
		
		bool f[10][10];
		fill(f[0], f[10], false);
		f[py][px] = true;
		
		REP(i, n) jump(f, x[i], y[i]);
		
		bool ans = false;
		REP(i, 10) REP(j, 10) if (f[i][j]) ans = true;
		
		if (ans) puts("OK");
		else puts("NA");
	}
	return 0;
}

bool check(int x, int y) {
	return x >= 0 && x < 10 && y >= 0 && y < 10;
}

void jump(bool f[10][10], int x, int y) {
	bool tmp[10][10];
	fill(tmp[0], tmp[10], false);
	
	REP(i, 10) REP(j, 10) {
		if (!f[i][j]) continue;
		REP(k, 12) {
			int nx = j + dx[k], ny = i + dy[k];
			if (!check(nx, ny)) continue;
			tmp[ny][nx] = true;
		}
	}
	
	fill(f[0], f[10], false);
	REP(i, 10) REP(j, 10) {
		if (y - 1 <= i && i <= y + 1 && x - 1 <= j && j <= x + 1)
			f[i][j] = tmp[i][j];
	}
}

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


int main(void) {
    using namespace std;

    long n;
    cin >> n;
    
    vector<long> a(n);
    for(auto &x: a) cin >> x;

    map<long,long> m;
    for(auto &x: a) {
        m[x] = m[x] + 1;
    }

    long r = 0;
    for(long i=1l<<40; i; i>>=1) {
        for(auto &t: m) {
            if(t.second == 0) continue;
            if(i - t.first == t.first) {
                long k = t.second / 2;
                m[t.first] -= k*2;
                r += k;
            }
            else if(m.count(i - t.first) == 1 && m[i - t.first] > 0) {
                long k = min(t.second, m[i-t.first]);
                m[t.first] -= k;
                m[i - t.first] -= k;
                r += k;
            }
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 14336
#!/usr/bin/env python3

import sys


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8')


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

# ----------------------------------------------------------------


def main():
    h, w = LI()
    if h == 1 or w == 1:
        print(1)
    elif h % 2 == 0 or w % 2 == 0:
        print('{:.0f}'.format(w * h / 2))
    else:
        print('{:.0f}'.format((h * w + 1) / 2))


main()


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

vector<long long> shrines, temples;
long long s, t, x, lshrine, rshrine, ltemple, rtemple, ans1, ans2, ans3, ans4, ans5, ans6, a, b, q;

long long solve(long long c, long long l, long long r) {
    while (l != r) {
        if (c > shrines[(l+r)/2]) {
            l = (l+r)/2+1;
        }
        else {
            r = (l+r)/2;
        }
    }
    if (shrines[l] > c) {
        l--;
    }
    if (l<1) return -10000000001;
    return shrines[l];
}

long long solve2(long long c, long long l, long long r) {
    while (l != r) {
        if (c > shrines[(l+r)/2]) {
            l = (l+r)/2+1;
        }
        else {
            r = (l+r)/2;
        }
    }
    if (shrines[l] < c) {
        l++;
    }
    if (l>a) return 20000000001;
    return shrines[l];
}

long long solve3(long long c, long long l, long long r) {
    while (l != r) {
        if (c > temples[(l+r)/2]) {
            l = (l+r)/2+1;
        }
        else {
            r = (l+r)/2;
        }
    }
    if (temples[l] > c) {
        l--;
    }
    if (l<1) return -10000000001;
    return temples[l];
}

long long solve4(long long c, long long l, long long r) {
    while (l != r) {
        if (c > temples[(l+r)/2]) {
            l = (l+r)/2+1;
        }
        else {
            r = (l+r)/2;
        }
    }
    if (temples[l] < c) {
        l++;
    }
    if (l>b) return 20000000001;
    return temples[l];
}

int main() {
    cin >> a >> b >> q;
    
    shrines.push_back(0);
    temples.push_back(0);
    
    for (long i=0; i<a; i++) {
        cin >> s;
        shrines.push_back(s);
    }
    
    for (long i=0; i<b; i++) {
        cin >> t;
        temples.push_back(t);
    }
    
    sort(shrines.begin(),shrines.end());
    sort(temples.begin(),temples.end());
    
    for (long i=0; i<q; i++) {
        cin >> x;
        lshrine = solve(x, 1, a);
        rshrine = solve2(x, 1, a);
        ltemple = solve3(x, 1, b);
        rtemple = solve4(x, 1, b);
        
        ans1 = x-min(lshrine,ltemple);
        ans2 = max(rshrine,rtemple)-x;
        ans3 = (x-lshrine)*2+rtemple-x;
        ans4 = (x-ltemple)*2+rshrine-x;
        ans5 = (rtemple-x)*2+x-lshrine;
        ans6 = (rshrine-x)*2+x-ltemple;
        
        ans2 = min(ans1, ans2);
        ans3 = min(ans2, ans3);
        ans4 = min(ans3, ans4);
        ans5 = min(ans4, ans5);
        ans6 = min(ans5, ans6);
        cout << ans6 << endl;
        //cout << lshrine << endl;
        //cout << rshrine << endl;
        //cout << ltemple << endl;
        //cout << rtemple << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = sc.nextInt();
		int[] v = new int[n];
		int[] w = new int[n];
		for (int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		int[] t = new int[max + 1];
		for (int i = 0; i < n ; i++) {
			for (int j = w[i]; j <= max; j++) {
				t[j] = Math.max(t[j], t[j - w[i]] + v[i]);
			}
		}
		System.out.println(t[max]);
		sc.close();
    }
}



Measured memory_bytes: 26984
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)



int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];

	sort(h.begin(), h.end(),greater<ll>());
	ll ans = 0;
	for (int i = k; i < n; i++)
	{
		ans += h[i];
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4852
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

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

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

int N;
ll a[300010];
ll f[100010];
ll s[100010];

void init()
{
}

void solve()
{
    priority_queue<ll, vector<ll>, greater<ll> > first;
    priority_queue<ll> second;
    REP(i, N){
        f[0] += a[i];
        first.push(a[i]);
        s[N] += a[3*N-1-i];
        second.push(a[3*N-1-i]);
    }

    FOR(k, 1, N+1){
        f[k] = f[k-1] + a[N-1+k];
        first.push(a[N-1+k]);
        f[k] -= first.top();
        //cout << "first: push " << a[N-1+k] << ", pop " << first.top() << endl;
        first.pop();

        s[N-k] = s[N+1-k] + a[2*N-k];
        second.push(a[2*N-k]);
        s[N-k] -= second.top();
        //cout << "second: push " << a[2*N-k] << ", pop " << second.top() << endl;
        second.pop();

    }
    
    ll ans = -LINF;
    REP(k, N+1){
        //cout << f[k] << " " << s[k] << endl;
        ans = max(ans, f[k]-s[k]);
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, 3*N){
        cin >> a[i];
        //cout << a[i] << " ";
    }
    //cout << endl;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 5996
#include<bits/stdc++.h>
#define PI 2*acos(0)
#define ll long long
#define pii pair<int,int>
#define mx 100005
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll int val,x,n,i,j;
    cin>>n;
    ll int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    val=a[0];
    for(i=1;i<n;i++) val=val^a[i];
    for(i=0;i<n;i++){
        x=val^a[i];
        cout<<x<<" ";
    }
    return 0;
}


Measured memory_bytes: 5160
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

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

  int apa = 0;
  while(apa*apa <= n) {
    apa++;
  }
  apa--;
  int ans = apa*apa;

    cout << ans << endl;
}


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

typedef long long ll;

int main() {
    int n, m, k;
    ll black;
    cin >> n >> m >> k;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            black = m*i;
            black += (n-i)*j-i*j;
            if (black == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
int main(){
    int a, b, c;
    cin >> c >> a >> b;
    cout << max(abs(a - b) - c, 0) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N;

void solve() {
    string ans;
    while (N != 0) {
        if (N % 2 != 0) {
            ans = "1" + ans;
            N--;
        } else {
            ans = "0" + ans;
        }
        N /= -2;
    }
    if (ans == "") ans = "0";
    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

const long long PRIME = 1000000007;

using namespace std;

int main() {
  string s;
  cin >> s;
  long long ans = s.size() * (s.size() + 1) / 2;
  map<char, int> sum;
  for(int i = 0; i < s.size(); i++) {
  sum[s[i]]++;
    ans -= sum[s[i]];
  }
  cout << ans + 1 << endl;
  return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
	int xx,nn;
	int tmp;
	
	cin >> xx >> nn;
	vector<int> pp(nn);
	
	rep(i,nn) cin >> pp[i];
	
	sort(pp.begin(),pp.end());
	
	if(pp.size() == 0) {
		cout << xx << endl;
		return 0;
	}
	
	
	tmp = 100000;
	for(int i=0;i<=101;i++){
		auto itr = find(pp.begin(),pp.end(),i);
		if(itr == pp.end()) if(abs(tmp - xx) > abs(i-xx))tmp=i;
	}
	cout << tmp << endl;
	
}

Measured memory_bytes: 3632
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
ab = [a1, b1, a2, b2, a3, b3]
one = 0
two = 0
for i in range(1, 5, 1):
    if ab.count(i) == 1:
        one += 1
    elif ab.count(i) == 2:
        two += 1
print("YES" if one == 2 and two == 2 else "NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
int ans=mINF;
ans = max(a+b,ans);
ans = max(a-b,ans);
ans = max(a*b,ans);
cout << ans << endl;
return 0;
}


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

template <class T>
using Table = std::vector<std::vector<T> >;

class Edge{
public:
    int from, to;
    long long cost;
    Edge(): from(0), to(0), cost(0){}
    Edge(int u, int v, long long w): from(u), to(v), cost(w){}
    ~Edge(){}
    bool operator<(const Edge &e)const{
        return cost < e.cost;
    }
};

void search(Table<int> &to_list, std::vector<bool> &visited,
        std::deque<int> &path)
{
    int tmp = 0;
    path.push_front(tmp);
    while(1){
        visited[tmp] = true;
        if(to_list[tmp].empty()) break;

        bool is_end = true;
        for(int v: to_list[tmp]){
            if(visited[v] == false){
                path.push_back(v); tmp = v;
                is_end = false; break;
            }
        }
        if(is_end == true) break;
    }

    tmp = 0;
    for(int& v: to_list[0]){
        if(visited[v] == false) tmp = v;
        // printf("v=%d\n", v);
    }
    if(tmp == 0) return;
    path.push_front(tmp);
    // printf("tmp=%d\n", tmp);

    while(1){
        visited[tmp] = true;
        if(to_list[tmp].empty()) break;

        bool is_end = true;
        for(int v: to_list[tmp]){
            if(visited[v] == false){
                path.push_front(v); tmp = v;
                is_end = false; break;
            }
        }
        if(is_end == true) break;
    }
}

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    Table<int> to_list(N);
    for(int i=0; i<M; i++){
        int u, v;
        scanf(" %d %d", &u, &v);
        u--; v--;
        to_list[u].push_back(v);
        to_list[v].push_back(u);
    }

    std::vector<bool> visited(N, false);
    std::deque<int> path;
    search(to_list, visited, path);

    printf("%lu\n", path.size());
    for(int& u: path) printf("%d ", u+1);
    printf("\n");
}

Measured memory_bytes: 6656
//API???????????????
import java.util.Scanner;
import java.io.IOException;
class Main {
  	public static void main(String[] args) throws IOException{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		Nodes nodes = new Nodes();
		Node[] node = new Node[n];
		nodes.nodes = node;
		for(int i = 0;i < n;i++){
			node[i] = new Node(i);
		}
		
		for(int i = 0;i < n; i++){
			int id = scan.nextInt();
			int left = scan.nextInt();
			int right = scan.nextInt();
			if(left != -1) node[left].parent = id;
			if(right != -1) node[right].parent = id;
			node[id].left = left;
			node[id].right = right;
			if(left != -1 && right != -1){
				node[left].sibling = right;
				node[right].sibling = left;
			}
		}
		
		int root = 0;
		
		while(node[root].parent != -1){
			root = node[root].parent;
		}
		
		nodes.setDepth(root, 0);
		node[root].height = nodes.setHeight(root);
		
		for(int i = 0; i < n; i++){
			StringBuilder sb = new StringBuilder();
			int d = 0;
			if(node[i].left != -1) d++;
			if(node[i].right != -1) d++;
			
			sb.append("node " + i + ": parent = " + node[i].parent + ", sibling = " + node[i].sibling + ", degree = " + d + ", depth = " + node[i].depth + ", height = " + node[i].height + ", ");
			//????????????????????°
			if(node[i].parent == -1) sb.append("root\r\n");
			//???????????????????????????????????°
			else if(d == 0) sb.append("leaf\r\n");
			//????????\???
			else sb.append("internal node\r\n");
			System.out.print(sb);
		}
	}
}

class Node{
	int id;
	int parent = -1;
	int left = -1;
	int right = -1;
	int sibling = -1;
	int depth = -1;
	int height = -1;

	public Node(int id) {
		this.id = id;
	}
}

class Nodes{
	/*
	List<Node> nodes;
	/*/
	Node[] nodes;
	/**/
	
	//-1??????????????§??±????????£?????????
	public void setDepth(int id, int d){
		int l = nodes[id].left;
		int r = nodes[id].right;
		if(l != -1) setDepth(l, d + 1);
		if(r != -1) setDepth(r, d + 1);
		nodes[id].depth = d;
	}
	
	public int setHeight(int id){
		if(id == -1) return -1;
		
		int l = nodes[id].left;
		int r = nodes[id].right;
		nodes[id].height = Math.max(setHeight(l), setHeight(r)) + 1; 
		return nodes[id].height;
	}
}

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

typedef long long LL;
const int N = 200005, mod = 1000000007;

void reduce(int &x) { x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}

int n, a[N], b[N], t[N], it[N], pre[N], v[N], inversion, number;
std::vector<int> id[N];

void solve(std::vector<int> &points) {
	static int bit[N];
	std::sort(points.begin(), points.end());
	for (int p : points) {
		int sum = 0;
		for (int j = a[p] - 1; j; j &= j - 1) reduce(sum += bit[j] - mod);
		inversion = (inversion + (LL) sum * t[a[p]]) % mod;
		for (int j = a[p]; j <= n; j += j & -j) reduce(bit[j] += it[a[p]] - mod);
	}
	for (int p : points) for (int j = a[p]; j <= n; j += j & -j) bit[j] = 0;
	for (int p : points) {
		int sum = 0;
		for (int j = a[p] + 1; j <= n; j += j & -j) reduce(sum += bit[j] - mod);
		inversion = (inversion + (LL) (mod - sum) * it[a[p]]) % mod;
		for (int j = a[p]; j; j &= j - 1) reduce(bit[j] += t[a[p]] - mod);
	}
	for (int p : points) for (int j = a[p]; j; j &= j - 1) bit[j] = 0;
	points.clear();
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> a[i], ++b[a[i]], id[a[i]].emplace_back(i);

	{
		static int bit[N];
		for (int i = 1; i <= n; ++i) {
			for (int j = a[i]; j; j &= j - 1) ++bit[j];
			for (int j = a[i] + 1; j <= n; j += j & -j) reduce(inversion += bit[j] - mod);
		}
		inversion = inversion * 2LL % mod;
		for (int i = 1; i <= n; ++i)
			inversion = (inversion + (LL) b[i] * (b[i] - 1) / 2) % mod;
	}

	for (int i = 1; i <= n; ++i) v[i] = a[i]; std::sort(v + 1, v + n + 1);
	number = 1; for (int i = 1; i <= n; ++i) number = (LL) number * (v[i] - i + 1) % mod;
	if (!number) return std::cout << "0\n", 0;
	number = (LL) number * (mod + 1 >> 1) % mod;

	
	for (int i = n - 1; i; --i) b[i] += b[i + 1];
	for (int i = 1; i <= n; ++i) b[i] -= n - i;

	for (int i = 1; i <= n; ++i) assert(b[i] > 0);

	for (int i = 1; i <= n; ++i) t[i] = pow(b[i], mod - 2, b[i] - 1), it[i] = pow(b[i] - 1, mod - 2, b[i]);

	std::vector<int> now;
	for (int i = 0; i <= n + 1; ++i) {
		if (!t[i]) {
			solve(now), now.insert(now.end(), id[i].begin(), id[i].end());
			t[i] = it[i] = 1;
		} else {
			now.insert(now.end(), id[i].begin(), id[i].end());
			t[i] = (LL) t[i] * t[i - 1] % mod;
			it[i] = (LL) it[i] * it[i - 1] % mod;
		}
	}

	std::cout << (LL) inversion * number % mod << '\n';
	return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main(void) {
    string s; cin >> s;
    ll dp[100005][13]={0};
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n) {
        int c;
        if(s[i] == '?') c = -1;
        else c = s[i] - '0';
        
        rep(j,10) {
            if(c!=-1 && c!=j) continue;
            rep(ki,13) {
                dp[i+1][(ki*10+j)%13] += dp[i][ki];
            }
        }
        rep(j,13) dp[i+1][j] %= mod;
    }
    cout << dp[n][5];
}



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

int n, m, si[2020], ti[2020];

int dep[2020], fa[2020], vis[2020];
vector<int>G[2020], pa[2020], pb[2020], cov[2020];
int las[2020], die[2020];

void dfs(int x,int fff){
    dep[x]=dep[fff]+1; fa[x]=fff;
    for (auto y:G[x])
        if (y!=fff) dfs(y,x);
}

int main(){
    cin>>n>>m;
    for (int i=1;i<n;++i){
        int x, y; cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1,0);
    for (int i=1;i<=m;++i){
        cin>>si[i]>>ti[i];
        int x=si[i], y=ti[i];
        while (x!=y){
            if (dep[x]>dep[y]){
                pa[i].push_back(x);
                cov[x].push_back(i);
                x=fa[x];
            }else{
                pb[i].push_back(y);
                cov[y].push_back(-i);
                y=fa[y];
            }
        }
    }
    int ans=0;
    for (int i=1;i<=n;++i){
        las[i]=cov[i].size();
        ans+=min(las[i],2);
    }
    for (int p;;){
        for (p=2;p<=n&&!(las[p]==1&&__builtin_popcount(vis[p])==1);++p);
        if (p>n){
            for (p=2;p<=n&&las[p]==0;++p);
            if (p>n) break;
        }
        while (cov[p].size()&&die[abs(cov[p].back())]) cov[p].pop_back();
        int i=cov[p].back(), rev=i<0;
        die[i=abs(i)]=1;
        if (las[p]<0) exit(0);
        if (vis[p]==1) rev^=1;
        if (rev) swap(si[i],ti[i]);
        for (auto o:pa[i]) vis[o]|=1<<(rev), --las[o];
        for (auto o:pb[i]) vis[o]|=1<<(rev+1)%2, --las[o];
    }
    cout<<ans<<endl;
    for (int i=1;i<=m;++i)
        cout<<si[i]<<' '<<ti[i]<<endl;
}

Measured memory_bytes: 13696
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int rotation(char*,string);
int main(){
	int time;
	string roll;
	while(cin>>time&&time!=0){
		int answer=0;
		char Dice[6]={1,2,3,4,5,6};
		for(int i=0;i<time;++i){
			cin>>roll;
			answer+=rotation(Dice,roll);
		}
		cout<<answer+1<<endl;
	}
	return 0;
}
int rotation(char Dice[6],string roll){
	char dommy;
	if(roll[0]=='N'){
		dommy=Dice[0];
		Dice[0]=Dice[1];
		Dice[1]=Dice[5];
		Dice[5]=Dice[4];
		Dice[4]=dommy;
	}else if(roll[0]=='E'){
		dommy=Dice[0];
		Dice[0]=Dice[3];
		Dice[3]=Dice[5];
		Dice[5]=Dice[2];
		Dice[2]=dommy;
	}else if(roll[0]=='W'){
		dommy=Dice[0];
		Dice[0]=Dice[2];
		Dice[2]=Dice[5];
		Dice[5]=Dice[3];
		Dice[3]=dommy;
	}else if(roll[0]=='S'){
		dommy=Dice[0];
		Dice[0]=Dice[4];
		Dice[4]=Dice[5];
		Dice[5]=Dice[1];
		Dice[1]=dommy;
	
	}else if(roll[0]=='R'){
		dommy=Dice[1];
		Dice[1]=Dice[2];
		Dice[2]=Dice[4];
		Dice[4]=Dice[3];
		Dice[3]=dommy;
	}else{
		dommy=Dice[1];
		Dice[1]=Dice[3];
		Dice[3]=Dice[4];
		Dice[4]=Dice[2];
		Dice[2]=dommy;
	}
	return (int)Dice[0];
}

Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
//水色，もう一回
/*
ボーナスの扱いが難しい→ボーナス点を全探索する
ボーナスをとるか取らないかでbit全探索
・中途半端に解く配点は1種類以下であり，それ以外の配点は完全に解くか全く解かない
・中途半端に解くはいてんがあるならそれは完全に解く配点以外の配点の中で最も高い配点である
*/
int main() {
    int d, g;
    cin >> d >> g;
    int p[11], c[11];
    int bonus[11];
    int solve = 0;
    int ans = 1e9;
    int sum = 0;
    int rest_max;
    for(int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
        bonus[i] = (i+1)*100*p[i] + c[i];
    }
    //ボーナス点を取るか取らないか→bit全探索で調べる
    for(int bit = 0;  bit < (1 << d); bit++){
        solve = 0;
        sum =  0;
        rest_max = -1;
        for(int i = 0; i < d; i++){
            if(bit & (1<<i)){
                solve += p[i];
                sum += bonus[i];  
            }
            else {
                rest_max = i;
            } 
        }
        if(sum < g){
            int s1 = 100*(rest_max + 1);
            int need = (g - sum + s1 - 1) / s1;
            //問題数が足りない場合があることに注意
            if(need >= p[rest_max]) continue;
            solve += need;
        }

        if(solve < ans) ans = solve;
    }     
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 


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

    int N; cin >> N;
    string s; cin >> s;
    int k; cin >> k;
    k--;

    for(int i=0; i<N; i++){
        if(s[i] != s[k]) s[i] = '*';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3608
import sys
s = input()
t = input()
if t in s:
    print(0)
    sys.exit()

lenS = len(s)
lenT = len(t)

ans = lenT

for i in range(lenS-lenT+1):
    ss = s[i:i+lenT]
    num = 0
    for j in range(lenT):
        if ss[j] != t[j]:
            num += 1
    # print(ss, num)
    ans = min(num, ans)

print(ans)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,D;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>D;
	int ret=(N+(2*D))/(2*D+1);
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256