akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define vvi vector<vi>
#define Q queue<ll>
#define DQ deque<ll> 
#define pb push_back
#define pf push_front
#define popf pop_front
#define popb pop_back
#define mp make_pair
#define mt make_tuple
#define f first
#define s second
#define ub upper_bound
#define lb lower_bound
#define loop(x,y,z) for(ll i=x; i<=y; i+=z)
#define rloop(x,y,z) for(ll i=x; i>=y; i-=z)
#define all(x) x.begin(), x.end()
#define sum(x) accumulate(all(x),0LL)
#define minE(x) *min_element(all(x))
#define maxE(x) *max_element(all(x))
#define mem(a,b) memset(a,b,sizeof(a))
#define watch(x) cout<<(#x)<<" is "<<x
#define endl "\n"

ll gcd(ll a, ll b){
	return (!b)?a:gcd(b,a%b);
}

void display(vi &v,string c){
	for(auto x:v) cout<<x<<c;
}

int main(){
	IOS
	ll n;
	cin>>n;
	string str;
	map<string,ll> myMap;
	loop(0,n-1,1){
		cin>>str;
		sort(all(str));
		myMap[str]++;
	}
	ll temp,ans=0;
	for(auto x:myMap){
		temp=x.second;
		ans+=((temp*(temp-1))/2);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 11264
# coding: utf-8
import re
import math
#import numpy as np

mod=int(10**9+7)

#main
N,K,S=map(int,input().split())
A=[]
for a in range(N):
    if a<K:
        A.append(S)
    else:
        if(S<10**9):A.append(S+1)
        else: A.append(1)
print(" ".join(map(str,A)))

Measured memory_bytes: 15212
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  long long N, K, cv, minv = 0;
  cin >> N >> K;

  if (N == K) {
    cout << N-K << endl;
    return 0;
  }

  if (N < K) {
    minv = min(N, abs(N-K));
  } else {
    cv = N % K;
    minv = min(cv, abs(cv - K));
  }

  cout << minv << endl;
}

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

int gcd(int a,int b);
int left(int i,int c,vector<int> &a);
int right(int i,int c,vector<int> &a);

int main(){
  int N;

  cin>>N;

  vector<int> a(N);
  int i;

  for(i=0;i<N;i++)
  cin>>a.at(i);


  int l=0;
  int max,d;

  vector<int> r(N);
  vector<int> lef(N);

  lef.at(0)=0;
  lef.at(1)=a.at(0);
  for(i=2;i<N;i++){
    lef.at(i)=gcd(lef.at(i-1),a.at(i-1));
  }
  r.at(N-1)=0;
  r.at(N-2)=a.at(N-1);
  for(i=N-3;i>=0;i--){
    r.at(i)=gcd(r.at(i+1),a.at(i+1));
  }

  max=r.at(0);

  for(i=0;i<N;i++){
    d=gcd(r.at(i),lef.at(i));
    if(max<d)
    max=d;
  }


  cout<<max<<endl;
}

int gcd(int a,int b){
  if(a<b)
  swap(a,b);

  if(b==0)
  b=a;
  else{
    int c=a%b;

    while(c!=0){
      a=b;
      b=c;
      c=a%b;
    }
  }
  return b;

}

// int left(int i,int c,vector<int> &a){
//   int ll,d;
//
//   if(i==0)
//   return c;
//   else{
//     ll=gcd(c,a.at(i-1));
//     d=left(i-1,ll,a);
//   }
//
//   return d;
// }
//
// int right(int i,int c,vector<int> &a){
//   int ll,d,N;
//
//   N=a.size();
//
//   if(i==N-1)
//   return c;
//   else{
//     ll=gcd(c,a.at(i+1));
//     d=right(i+1,ll,a);
//   }
//
//   return d;
// }


Measured memory_bytes: 1408
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let s: Vec<char> = it.next().unwrap().chars().collect();
    let mut ret = 0;
    for i in 1..n {
        let mut m = 0;
        for j in 0..(n - i) {
            if s[j] == s[i + j] {
                m += 1;
                ret = std::cmp::max(ret, m);
            } else {
                m = 0
            }
            if m == i {
                break;
            }
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
int main(void)
{
  int n, i, j, l, f=0;
  char s[100][11]={""};
  scanf("%d", &n);
  scanf("%s", &s[0]);
  for(i= 1; i<n;  i++){
    scanf("%s", &s[i]);
    if(s[i][0] != s[i-1][strlen(&s[i-1])-1]){
      f = 1;
      break;
    }
    for(j = 0; j < i; j++){
      if(strcmp(&s[i], &s[j])==0){
        f = 2;
        break;
      }
    }
  }
  printf("%s\n", f ? "No" : "Yes");
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  int ans=0;
  bool serial=false;
  rep(i,n){
    int p;
    cin>>p;
    if(i+1==p){
       //二つ連続で入れ替える必要があればそれらを一回スワップ
      if(serial) serial=false;
      else{
        ans++;
        serial=true;
      }
    }
    else serial=false;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        exit(0)
    if K % 5 == 0:
        print(-1)
        exit(0)
    i = 1
    term = 10
    L = 9 * K
    if K % 7 == 0:
        L = 9 * (K // 7)
    while True:
        amari = term % L
        if amari == 1:
            print(i)
            exit(0)
        term = amari * 10
        i += 1

if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
object Main {

	def main(arg:Array[String]) = {
		val Array(a, b, k) = scala.io.StdIn.readLine().trim.split(" ").map(_.toInt);
		val st = scala.collection.mutable.TreeSet.empty[Int];
		for (i <- 0 until k) {
			if (a + i <= b) st += (a + i);
			if (b - i >= a) st += (b - i);
		}
		st.foreach(println);
	}
}


Measured memory_bytes: 25616
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int main()
{
	char a[10],b[10];
	while(cin>>a>>b,strcmp(a,"0")){
		int h=0,bo=0;
		rep(i,4)rep(j,4)if(a[i]==b[j]){
			if(i==j)h++;
			else bo++;
		}
		cout<<h<<" "<<bo<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
int h,w,dx[]={0,1,0,-1},dy[]={-1,0,1,0};
string mp[55];
struct po{
  int x,y,dir;
  po(int y,int x,int dir): x(x),y(y),dir(dir){}
};

int check(int y,int x,int dir){
  return mp[y+dy[dir%4]][x+dx[dir%4]]=='#';
}

int bfs(int sy,int sx,int sdir){
  int used[55][55][4]={},D[55][55]={};
  queue <po> Q;
  Q.push(po(sy,sx,sdir));
  D[sy][sx]=1;

  while(!Q.empty()){
    po t=Q.front();Q.pop();
    int x=t.x,y=t.y,dir=t.dir;
    if(mp[y][x]=='G') return D[y][x];
    if(used[y][x][dir]++)continue;
    
    int nx=x+dx[dir],ny=y+dy[dir],ndir=(dir+3)%4;
    if(check(y,x,dir)&&check(y,x,dir+1))Q.push(po(y,x,ndir));
    
    if(mp[ny][nx]!='#'){
      ndir=check(ny,nx,dir+1)? dir:(dir+1)%4;
      Q.push(po(ny,nx,ndir));
      D[ny][nx]=D[y][x]+!D[ny][nx];
    }
  }
  return -1;
}

int main(){
  cin>>h>>w;
  for(int i=0;i<=w+1;i++) mp[0]+='#',mp[h+1]+='#';
  for(int i=1;i<=h;i++) cin>>mp[i],mp[i]='#'+mp[i]+'#';

  int sx,sy,dir;
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++) {
      if(mp[i][j]=='^')dir=0,sy=i,sx=j;
      if(mp[i][j]=='>')dir=1,sy=i,sx=j;
      if(mp[i][j]=='v')dir=2,sy=i,sx=j;
      if(mp[i][j]=='<')dir=3,sy=i,sx=j;
    }
  cout <<bfs(sy,sx,dir)<<endl; 
  return 0;
}

Measured memory_bytes: 1308
import sys
input = sys.stdin.readline

def judge(x):
    now = x
    
    for ti, di in td:
        if s[now]==ti:
            if di=='R':
                now += 1
            else:
                now -= 1
        
        if now==-1:
            return True
    
    return False

def judge2(x):
    now = x
    
    for ti, di in td:
        if s[now]==ti:
            if di=='R':
                now += 1
            else:
                now -= 1
        
        if now==N:
            return True
    
    return False
    
N, Q = map(int, input().split())
s = input()
td = [tuple(input().split()) for _ in range(Q)]

l, r = 0, N-1
while l<=r:
    mid = (l+r)//2
    if judge(mid):
        l = mid+1
    else:
        r = mid-1
L = r

l, r = 0, N-1
while l<=r:
    mid = (l+r)//2
    if judge2(mid):
        r = mid-1
    else:
        l = mid+1
R = l

print(R-L-1)

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

int main()
{
    ll n, sr, i, a, b, t, f = 1;

    cin >> n;

    sr = sqrt(n);
    t = n;

    for(i = 2; i <= sr; i++){
        if(n % i == 0) f = 0, t = min(t, (i + (n / i)));
    }

    if(f == 0) cout << t - 2 << endl;
    else cout << t - 1 << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll N, A;

    cin >> N >> A;

    cout << (N % 500 <= A ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
 
struct Node{
  int key;
  Node *right, *left, *parent;
};
 
Node *root, *NIL;
 
Node * treeMinimum(Node *x){
  while(x->left != NIL) x = x->left;
  return x;
}
 
Node * find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}
 
Node * treeSuccessor(Node *x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while( y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
 
void treeDelete(Node *z){
  Node *y;
  Node *x;
 
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  if(y->left != NIL){
    x = y->left;
  } else {
    x = y->right;
  }
 
  if(x != NIL){
    x->parent = y->parent;
  }
 
  if(y->parent == NIL){
    root = x;
  } else {
    if(y == y->parent->left){
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }
 
  if(y != x){
    z->key = y->key;
  }
 
  free(y);
}
 
void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
 
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < y->key){
      x = y->left;
    } else {
      x = y->right;
    }
  }
 
  z->parent = y;
  if(y == NIL){
    root = z;
  } else {
    if(z->key < y->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}
 
void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
 
void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}
 
int main(){
  int n, i, x;
  string com;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){
    cin >> com;
    if(com[0] == 'f'){
      scanf("%d", &x);
      Node *t = find(root, x);
      if( t != NIL) printf("yes\n");
      else printf("no\n");
    }else if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    }else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com == "delete"){
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }
 
  return 0;
}


Measured memory_bytes: 22076
#![allow(non_snake_case)]

use proconio::input;
use proconio::fastout;

#[derive(Clone, Debug)]
struct Heap2 {
    x0: i32,
    x1: i32,
}

impl Heap2 {
    fn new() -> Heap2 {
        Heap2 {
            x0: 1,
            x1: -1,
        }
    }

    fn merge(&mut self, h: &Heap2) {
        let mut a = [self.x0, self.x1, h.x0, h.x1];
        a.sort_by(|x, y| y.cmp(x));
        self.x0 = a[0];
        self.x1 = a[1];
    }
}

#[fastout]
fn main() {
    input! {
        N: usize,
        A: [i32; 1 << N],
    }
    let M = 1 << N;
    let mut dp = vec![Heap2::new(); M];
    for i in 0..M {
        dp[i].x0 = A[i];
    }
    for i in 0..N {
        let mask = 1 << i;
        for j in 0..M {
            if j & mask > 0 {
                let tmp = dp[j ^ mask].clone();
                //let tmp = Heap2 { x0: A[j ^ mask], x1: -1 };
                //let tmp = Heap2 { x0: A[j], x1: -1 };
                dp[j].merge(&tmp);
            }
        }
    }
    let mut result = 0;
    for i in 1..M {
        result = std::cmp::max(result, dp[i].x0 + dp[i].x1);
        println!("{}", result);
    }
}


Measured memory_bytes: 8964
import java.util.Scanner;

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

        //endが入力されたらbreak
        while (true) {

            String line = scan.next();	//入力
            int leng = line.length();

            if(line.equals("-")) {
            	break;
            }

            int shuffle = scan.nextInt();

            for(int i=0; i<shuffle; i++) {

            	int num = scan.nextInt();

//            		line = line.charAt(0 + j) + line.charAt(j + leng);
            		line = line.substring(num, leng) + line.substring(0, num);
            }

        	System.out.println(line);
        }
    }
}


Measured memory_bytes: 26464
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n,m; cin>>n>>m;
	cout<<(n==m?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<int, int> acnt;
    for (int i = 0; i < n; i++) {
        int tmpa; cin >> tmpa;
        acnt[tmpa]++;
    }

    int ans = 0;
    for (P<int, int> aaa: acnt) {
        if (aaa.second < aaa.first) ans += aaa.second;
        else ans += aaa.second - aaa.first;
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
	string a, b;
	cin >> a;
	for (int i = 0; i < a.size(); i++) {
		if (i % 2 == 0) {
			b += a[i];
		}
	}
	cout << b << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0,val,num;cin>>n;
  lvector A(n,0),v;
  map<ll,lvector> mp;
  rep(i,n) {
    cin>>A[i];
    mp[i-A[i]].emplace_back(i);
  }
  for(ll i=0;i<n;i++) {
    val=A[i]+i;
    if(mp[val].size()) {
      num=mp[val].size()-(lower_bound(ALL(mp[val]),i+1)-mp[val].begin());
      ans+=num;
    } 
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 38960
#include <iostream>
using namespace std;
int main(void){
    
    int i=1;
    int j=1;
    
    for (i = 1;i <= 9;i++){
        for (j = 1;j <= 9;j++){
        
    cout<<i<<"x"<<j<<"="<<i*j<<endl;
}
}



    
}



Measured memory_bytes: 3084
def draw(a, b):
    for i in range(a):
        s = ""
        for j in range(b):
            s += ("#" if (i+j)%2 == 0 else ".")
        print(s)
    print("")
 
while 1:
    h, w = map(int, raw_input().split())
    if h == 0 and w == 0:
        break
    draw(h, w)

Measured memory_bytes: 6328
from itertools import accumulate
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()
ai = []
bi = []
for i in range(n):
    ai.append(n - bisect.bisect_right(b, a[i]))
    bi.append(n - bisect.bisect_right(c, b[i]))
ans = 0
c = [0]+list(accumulate(bi[::-1]))
for j in ai:
    ans += c[j]
print(ans)

Measured memory_bytes: 30164
#include <iostream>
#include <cstdio>

using namespace std;

struct Node
{
    int key;
    Node *parent, *right, *left;
};

Node *NIL;

void initialize()
{
    NIL->parent = NIL->left = NIL->right = NIL;
}

Node *make_node(Node *node, int key)
{
    Node *new_node = new Node;
    new_node->left = new_node->right = NIL;
    new_node->parent = node;
    new_node->key = key;
    return new_node;
}

class BinarySearchTree
{
    Node* tree;
public:
    BinarySearchTree() : tree(NIL) {}

    void insert(int key)
    {
        Node *node;
        if (tree == NIL)
        {
            node = new Node;
            node->left = node->right = node->parent = NIL;
            node->key = key;
            tree = node;
            return;
        }

        node = tree;
        while (true)
        {
            if (node->key > key)
            {
                if (node->left == NIL)
                {
                    Node *new_node = make_node(node, key);
                    node->left = new_node;
                    break;
                }
                else
                {
                    node = node->left;
                }
            }
            else
            {
                if (node->right == NIL)
                {
                    Node *new_node = make_node(node, key);
                    node->right = new_node;
                    break;
                }
                else
                {
                    node = node->right;
                }
            }
        }
    }

    void inorder(Node *node)
    {
        if (node != NIL)
        {
            inorder(node->left);
            cout << " " << node->key;
            inorder(node->right);
        }
    }

    void preorder(Node *node){
        if(node != NIL){
            cout << " " << node->key;
            preorder(node->left);
            preorder(node->right);
        }
    }

    void print()
    {
        inorder(tree);
        cout << endl;
        preorder(tree);
        cout << endl;
    }
};

int main()
{
    BinarySearchTree BST;
    char command[10];
    int N, key;
    scanf("%d", &N);
    for(int i=0;i<N;i++){
        scanf("%s", command);
        if(command[0] == 'i'){
            scanf("%d", &key);
            BST.insert(key);
        }
        else{
            BST.print();
        }
    }
}


Measured memory_bytes: 26596
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//????????????????????°?????\???
		int set = sc.nextInt();
		int[] num = new int[9];
		int[] color = new int[9];
		for (int setCount = 0; setCount < set; setCount++) {
			int RCount = 0;
			int GCount = 0;
			int[] used = new int[9];
			int trueSet = 0;
			//??\???
			for (int count = 0; count < 9; count++ ) {
				num[count] = sc.nextInt();
			}
			for (int count = 0; count < 9; count++) {
				String cl = sc.next();
				if (cl.equals("R") ) {
					color[count] = 0;
					RCount++;
				} else if (cl.equals("G") ) {
					color[count] = 1;
					GCount++;
				} else {
					color[count] = 2;
				}
			}
			//??????1
			if ((RCount == 0 && GCount == 0) || (RCount == 0 && GCount == 3) ||
				(RCount == 0 && GCount == 6) || (RCount == 3 && GCount == 0) ||
				(RCount == 3 && GCount == 3) || (RCount == 3 && GCount == 6) ||
				(RCount == 6 && GCount == 0) || (RCount == 6 && GCount == 3) ||
				(RCount == 9) || (GCount == 9)) {
				//?????????????????????????????????
				for (int i = 0; i < 8; i++) {
					for (int j = i+1; j < 9; j++) {
						if (num[i] > num[j]) {
							int numTaihi = num[i];
							num[i] = num[j];
							num[j] = numTaihi;
							int colorTaihi = color[i];
							color[i] = color[j];
							color[j] = colorTaihi;
						}
					}
				}
				//????????????????????????????????????
				for (int xMaime = 0; xMaime < 7; xMaime++) {
					if (used[xMaime] == 0) {
						for (int yMaime = xMaime + 1; yMaime < 8; yMaime++) {
							if (used[xMaime] == 1) {
								break;
							}
							if(used[yMaime] == 0) {
								for (int zMaime = yMaime + 1; zMaime < 9; zMaime++) {
									if (used[xMaime] == 1) {
										break;
									}
									if (used[zMaime] == 0) {
										if (color[xMaime] == color[yMaime] && color[xMaime] == color[zMaime]) {
											if (num[xMaime] == num[yMaime] && num[xMaime] == num[zMaime]) {
												trueSet++;
												used[xMaime]++;
												used[yMaime]++;
												used[zMaime]++;
												break;
											} else if (num[xMaime]+1 == num[yMaime] && num[yMaime]+1 == num[zMaime]) {
												trueSet++;
												used[xMaime]++;
												used[yMaime]++;
												used[zMaime]++;
												break;
											}
										}
									}
								}
							}
						}
					}
				}
				//??????
				if (trueSet == 3) {
					System.out.println(1);
				} else {
					System.out.println(0);
				}
			} else {
				System.out.println(0);
			}
		}
	}
}

Measured memory_bytes: 29184
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=500;
//ここまでテンプレ
int main(){
	int C[5][5]={};
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>C[i][j];
		}
	}
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
			for(int k=0;k<=100;k++){
				if(C[0][0]-i==C[0][1]-j && C[0][0]-i==C[0][2]-k && C[1][0]-i==C[1][1]-j && C[1][0]-i==C[1][2]-k && C[2][0]-i==C[2][1]-j && C[2][0]-i==C[2][2]-k){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <map>

using namespace std;

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

	int N;
	cin >> N;

	map<pair<int, int>, int> count;

	int result = 0;

	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;

		int b = i + 1;

		if (a > b) swap(a, b);

		if (count[make_pair(a, b)] != 0)
		{
			result++;
		}
		else
		{
			count[make_pair(a, b)]++;
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<stdio.h>

using namespace std;

string s;
int main(){
    cin >> s;
    int l = s.size();
    for(int i=0; i<l; i++) {
        for(int j=i; j<l; j++) {
            for(int k=i; k<l; k++) {
                if( s.substr(i,j) + s.substr(k) == "keyence" ) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

map<ll,int>mp;

int main(){
  int n,q;
  cin>>n;
  ll sum=0;
  rep(i,n){
    int a;
    cin>>a;
    mp[a]++;
    sum+=a;
  }
  cin>>q;
  rep(i,q){
    ll b,c;
    cin>>b>>c;
    mp[c]+=mp[b];
    sum-=b*mp[b];
    sum+=c*mp[b];
    mp[b]=0;
    cout<<sum<<endl;
  }
  return(0);
}

Measured memory_bytes: 9380
package main
import (
  "fmt"
)
func main() {
  var n, k, q int
  fmt.Scan(&n, &k, &q)
  as := make([]int, q)
  for i := 0; i < q; i++ {
    fmt.Scan(&as[i])
  }
  ps := make([]int, n)
  for _, a := range as {
    ps[a-1]++
  }
  for _, p := range ps {
    if 0 < p+k-q {
      fmt.Println("Yes")
    } else {
      fmt.Println("No")
    }
  }
}

Measured memory_bytes: 7812
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  string s; cin >> s;
  int n = (int)s.length();

  vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(2, vector<int>(32, 0)));

  function<int(int, int, int)> rec = [&](int k, int tight, int f){
    if(f >> 4) return 0;
    if(k == n) return (f == 0b01111)? 1: 0;
    if(dp[k][tight][f]) return dp[k][tight][f];

    int x = s[k] - '0';
    int r = tight? x: 9;

    int ret = 0;
    REP(i, r+1){
      int nf = f;
      switch (i){
        case 0: if(f >> 3) nf |= bit(4);
                break;
        case 3: nf |= bit(2);
                nf |= bit(3);
                break;
        case 5: nf |= bit(1);
                nf |= bit(3);
                break;
        case 7: nf |= bit(0);
                nf |= bit(3);
                break;
        default:  nf |= bit(3);
                  nf |= bit(4);
      }

      ret += rec(k+1, tight && i == x, nf);
    }

    return dp[k][tight][f] = ret;
  };
  
  cout << rec(0, 1, 0) << endl;
   
  return 0;
}


Measured memory_bytes: 256
#define SORT(v) sort(v.begin(), v.end())
#include "iostream"
#include "map"
#include "vector"
#include <stack>
#include "cstdlib"
#include <algorithm>
#include <cstdarg>
// #include "ane.cpp"

#define INF (int)1e9
#define NMAX 200
#define MMAX 200
#define MOD 100000
using namespace std;

// コメントアウトするとdb_printf()を実行しない
#define DEBUG
// デバッグ用printf
void db_printf(const char* format, ...){
    #ifndef DEBUG
    return;
    #endif
    va_list arg;
    va_start(arg, format);
    vprintf(format, arg);  // コンソールに出力
    va_end(arg);
}
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
typedef pair<int, int> P;

int N,M,dp[NMAX][MMAX] = {};
int sx,sy,gx,gy;
std::vector<char> xmove = {'R', 'L'}, ymove = {'U', 'D'};

static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

string ans = "";

void solve(){
    // 解答アルゴリズム
    // 往路
    for (int i = 0; i < gy-sy; ++i)
    {
        ans += ymove[0];
    }
    for (int i = 0; i < gx-sx; ++i)
    {
        ans += xmove[0];
    }
    // 復路
    for (int i = 0; i < gy-sy; ++i)
    {
        ans += ymove[1];
    }
    for (int i = 0; i < gx-sx; ++i)
    {
        ans += xmove[1];
    }
    // 往路2
    ans += xmove[1];
    for (int i = 0; i < gy-sy+1; ++i)
    {
        ans += ymove[0];
    }
    for (int i = 0; i < gx-sx+1; ++i)
    {
        ans += xmove[0];
    }
    ans += ymove[1];
    // 復路2
    ans += xmove[0];
    for (int i = 0; i < gy-sy+1; ++i)
    {
        ans += ymove[1];
    }
    for (int i = 0; i < gx-sx+1; ++i)
    {
        ans += xmove[1];
    }
    ans += ymove[0];
}
void debug(){
    // デバッグ用出力
}
void answer(){
    // 解答出力
    cout << ans << endl;
}
int main(int argc, char const *argv[])
{
    // 入力の読み込み，番兵法
    ios::sync_with_stdio(false);

    Fill(dp, -1);

    cin >> sx >> sy >> gx >> gy;

    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();

    return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    scanf("%d",&n);
    ll a[n+1];
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%lld",&a[i]);
        a[i] += a[i-1];
    }
    ll ans = a[n];
    for (int i = 1; i <= n; i++){
        ans = min(ans,abs(a[n]-a[i]-a[i]));
    }
    printf("%lld",ans);
}


Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int p;
long long ans;
int a[2];
long long pp[110];
long long C(int x,int y)
{
	long long res=1LL;
	for(int i=1;i<=y;i++)
	{
		res=res*(long long)(x-y+i)/i;
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&p);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x&1]++;
	}
	if(!p)
	{
		for(int i=0;i<=a[0];i++)
		{
			for(int j=0;j<=a[1];j+=2)
			{
				ans+=C(a[0],i)*C(a[1],j);
			}
		}
	}
	else
	{
		for(int i=0;i<=a[0];i++)
		{
			for(int j=0;j<=a[1]-1;j+=2)
			{
				ans+=C(a[0],i)*C(a[1],j+1);
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
ai = [int(i) for i in input().split()]

tmp = format(max(k,max(ai)), 'b')

lng = len(tmp)
tmp = format(k, '0'+str(lng)+'b')

li = [0]*(lng)
ai_li = [0]*(n)

for i in range(n):
    #print(i)
    #print(ai[i])
    #print(format(ai[i], '0'+str(lng)+'b'))
    ai_li[i] = format(ai[i], '0'+str(lng)+'b')

add_enb_flag = False

for i in range(lng):
    cnt = 0
    for j in range(n):
        if ai_li[j][i] == '1':
            cnt += 1
    #print(cnt,i)
    if cnt >= (n+1) // 2:
        if tmp[i] == "1":
            add_enb_flag = True
        li[i] = 0
    elif tmp[i] == '1' or add_enb_flag == True:
        li[i] = 1
    else:
        li[i] = 0
k_m = 0
bai = 1

for i in range(lng):
    k_m += li[lng-i-1] *bai
    bai *= 2

#print(k_m,ai_li,tmp,li)
        
ans = 0
for i in range(n):
    ans += k_m^ai[i]
    
print(ans)

Measured memory_bytes: 91992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int N; cin >> N;
	ll ma = 0;
	ll mi = INF;
    rep(i, N) {
		ll a, b; cin >> a >> b;
		mi = min(mi, b);
		ma = max(ma, a);
    }
	COUT(ma + mi);
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        x: usize,
    }

    let mut ax = vec![];
    let mut cost = vec![];
    for _ in 0..n {
        input! {
            c: usize,
            a: [usize; m],
        }
        cost.push(c);
        ax.push(a);
    }

    let b = 1 << n;

    let mut ans = 1_000_000_000;
    let mut ok = false;
    for i in 0..b {
        let mut i = i;
        let mut index = 0;
        let mut c = 0;
        let mut u = vec![0; m];
        while i > 0 {
            if i & 1 == 1 {
                for (i, &a) in ax[index].iter().enumerate() {
                    u[i] += a;
                }
                c += cost[index];
            }
            index += 1;
            i >>= 1;
        }
        if u.iter().all(|&i| i >= x) {
            ok = true;
            ans = std::cmp::min(ans, c);
        }
    }
    if ok {
        println!("{}", ans);
    } else {
        println!("-1");
    }

}

Measured memory_bytes: 2216
inline = list(map(int,input().split()))

A = inline[0]
B = inline[1]
C = inline[2]
X = inline[3]
Y = inline[4]

kouho1 = A*X+B*Y
less = min(X,Y)
many = max(X,Y)
if A+B>2*C:
    kouho1-=less*(A+B-2*C)
kouho2 = many*2*C

print(min(kouho1,kouho2))

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main() {
	double r;
	cin >> r;
	cout << fixed;
	cout << setprecision(6);
	cout << r * r * M_PI << " " << 2 * r * M_PI << endl;
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int i, check;
  int amax = 0;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i) >> b.at(i);
    if(a.at(i) > amax)
    {
	  amax = a.at(i);
      check = i;
    }
  }
  cout << amax + b.at(check) << endl;
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, W = map(int, input().split())
    a = []
    for _ in range(H):
        w = input()
        if w.count('#') > 0:
            a.append(w)
    ans = [''] * len(a)
    for i in range(W):
        isOK = False
        for s in a:
            if s[i] == '#':
                isOK = True
                break
        if isOK:
            for j, s in enumerate(a):
                ans[j] += s[i]
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pii;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


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


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



int main(int argv, char* argc[])
{
    FASTIO

    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;

    return 0;
}



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

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

  vector<double> cum(n+1,0);

  rep(i,n){
    double p;
    cin >> p;

    double e=0;
    rep(i,p+1){
      if(i==0) continue;
      e += i/p;
    }
    cum[i+1] = cum[i]+e;
  }

  double ans = 0;

  rep(i,n-k+1) ans = max(ans, cum[i+k]-cum[i]);
  printf("%.7f", ans);
  
}


Measured memory_bytes: 4844
import javax.swing.*;
import java.util.*;



/**
 * Created by santa on 2016/10/16.
 */

public class Main {

    static final long MOD = 1000000007;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);


        int a = scanner.nextInt();
        int b = scanner.nextInt();

        long[][] map = new long[a + b + 1][2];

        int N = a + b;
        int tempa = a;
        int tempb = b;
        map[0][0] = 0l;
        map[0][1] = a;


        int flag = 0;
        long to = a;
        a--;
        for (int i = 1; i < N; i++) {
            if(map[i - 1][0] == 0){
                map[i][0] = 1;
                to = to * b % MOD;
                b--;
            }else{
                map[i][0] = 0;
                to = to * a % MOD;
                a--;
            }
        }

        a = tempa;
        b = tempb;
        map[0][0] = 1l;
        map[0][1] = b;

        flag = 0;
        long to2 = b;
        b--;
        for (int i = 1; i < N; i++) {
            if(map[i - 1][0] == 0){
                map[i][0] = 1;
                to2 = to2 * b % MOD;
                b--;
            }else{
                map[i][0] = 0;
                to2 = to2 * a % MOD;
                a--;
            }
        }
        System.out.println((to + to2) % MOD);


    }




} // MainClass


Measured memory_bytes: 28500
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

set <int> s;
int main(void){
    //cin.tie(0); ios::sync_with_stdio(false);
    int n, x; cin >> n >> x;
    if(x == 1 || x == 2*n-1){cout << "No" << endl; return 0;}
    cout << "Yes" << endl;
    if(x == 2*n-2){
        for(int i = 1;i <= n-1;i++)cout << i << endl;
        cout << x << endl; cout << x+1 << endl;
        for(int i = n;i <= x-1;i++)cout << i << endl;
    }else{
        int c = 0; int d = 0;
        while(true){
            c++;
            if(c == x-1)c += 4;
            d++; cout << c << endl; if(d == n-2)break;
        }
        cout << x+1 << endl; cout << x << endl; cout << x-1 << endl; cout << x+2 << endl;
        if(n == 3)return 0;
        c = 2*n;
        while(true){
            c--;
            if(c == x+2)c -= 4;
            d++; cout << c << endl; if(d == 2*n-5)break;
        }
    }
 	return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    int n,d;
    while(scanf("%d %d",&d,&n)!=EOF)
    {
        if(d==0)
        {
            if(n==100)
                printf("101\n");
            else
                printf("%d\n",n);
        }
        else if(d==1)
        {
            if(n==100)
                printf("10100\n");
            else
                printf("%d\n",n*100);
        }
        else if(d==2)
        {
            if(n==100)
                printf("1010000\n");
            else
                printf("%d\n",n*10000);
        }
    }
    return 0;
}



Measured memory_bytes: 128
#include <iostream>


int main() {
    long A, B;

    std::cin >> A >>  B;
    long val = 0;
    long factor = 1;

    auto calc_one_num = [&factor] (long N) {
        long div_n = N / (factor * 2);
        long res_n = N % (factor * 2);
        long num = div_n * factor;
        if (res_n < factor) return num;
        return num + res_n - factor;
    };

    while (B >= factor) {
        long a = calc_one_num(A);
        long b = calc_one_num(B + 1);
        
        if (std::abs(b - a) % 2) {
            val += factor;
        }
        factor *= 2;
    }
    std::cout << val << std::endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#define MN 100
const double pi=acos(-1);
using namespace std;
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;
}
pair<double,int> q[MN*4+5];
int x[MN+5],y[MN+5],n,top=0;
int main()
{
	n=read();
	for(int i=1;i<=n;++i) x[i]=read(),y[i]=read();
	for(int i=1;i<=n;++i)
	{
		top=0;
		for(int j=1;j<=n;++j) if(i!=j)
		{
			double s=atan2(y[j]-y[i],x[j]-x[i]);
			double l=s+pi/2,r=s-pi/2;
			if(l<0) l+=2*pi;if(r<0) r+=2*pi;
			if(l<=r) q[++top]=make_pair(l,1),q[++top]=make_pair(r+1e-10,-1);
			else q[++top]=make_pair(l,1),q[++top]=make_pair(2*pi,-1),
				 q[++top]=make_pair(0,1),q[++top]=make_pair(r+1e-10,-1);
		}
		sort(q+1,q+top+1);double ans=0;int now=0;
		q[top+1].first=2*pi;
		for(int j=1;j<=top;++j) 
			if((now+=q[j].second)==n-1) ans+=q[j+1].first-q[j].first;
		printf("%.10lf\n",ans/pi/2);
	}
	return 0;
}



Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let info = (0..n).map(|_|{
		let a: usize = s.next().unwrap().parse().unwrap();
		let mut r = vec![-1; n];
		for _ in 0..a {
			let x: usize = s.next().unwrap().parse().unwrap();
			let y: i8 = s.next().unwrap().parse().unwrap();
			r[x - 1] = y;
		}
		r
	}).collect::<Vec<_>>();
	let mut ans = 0;
	for i in 1..1 << n {
		if (0..n).filter(|&j| i & (1 << j) != 0).all(|j|{
			(0..n).filter(|&k| info[j][k] >= 0).all(|k| info[j][k] as usize == (i >> k) & 1)
		}) {
			if (i as u32).count_ones() > ans { ans = (i as u32).count_ones(); }
		}
	}
	println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>

using namespace std;
int main(){
    int n;
    cin >> n;
    
    double ans(0);
    if (n%2 == 0) ans = 0.5;
    else ans = (double(n/2)+1)/n;
    
    printf("%.10lf\n",ans);
    return 0;
}


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

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) break;

    vector<int> key(n);
    for(int i=0; i<n; i++){
      cin >> key[i];
    }
    string str;
    cin >> str;

    for(int i=0; i<str.size(); i++){
      for(int j=0; j < key[i%n]; j++){        
        if(str[i]=='a') str[i]='Z';
        else if(str[i]=='A') str[i]='z';
        else str[i]--;
      }
    }

    cout << str << endl;
  }

  return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	string s;
	cin >> s;
	int sum = 0;
	for (int i = 0; i < s.length(); i++){
		sum += s[i] - '0';
	}
	if (stoi(s) % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3560
import sys
input = sys.stdin.readline

def main():
    S = input().strip()

    n = len(S)

    while n > 0:
        if S[n - 5:n] == "dream":
            n -= 5
        elif S[n - 5:n] == "erase":
            n -= 5
        elif S[n - 7:n] == "dreamer":
            n -= 7
        elif S[n - 6:n] == "eraser":
            n -= 6
        else:
            print("NO")
            return
    else:
        print("YES")


if __name__ == '__main__':
    main()




Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<int> p(n), c(n);
	for(auto i = 0; i < n; ++ i){
		cin >> p[i], -- p[i];
	}
	for(auto i = 0; i < n; ++ i){
		cin >> c[i];
	}
	long long res = numeric_limits<long long>::min();
	for(auto s = 0; s < n; ++ s){
		vector<int> cur;
		vector<long long> pref(1);
		for(auto u = s; u != s || cur.empty(); u = p[u]){
			cur.push_back(u);
			pref.push_back(pref.back() + c[p[u]]);
		}
		for(auto rem = 1; rem <= int(cur.size()); ++ rem){
			if(rem <= k){
				ctmax(res, max(pref[rem], pref[rem] + pref.back() * ((k - rem) / int(cur.size()))));
			}
		}
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3800
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<string.h>

using namespace std;

int main(int argc, char* argv[]){
  int n;
  scanf("%d",&n);
  if(n<=999)printf("ABC\n");
  else printf("ABD\n");
  return 0;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]

for i in range(2):
  if c[0][i+1]-c[0][i] != c[1][i+1]-c[1][i]:
    print('No')
    exit()
  if c[0][i+1]-c[0][i] != c[2][i+1]-c[2][i]:
    print('No')
    exit()
  if c[i+1][0]-c[i][0] != c[i+1][1]-c[i][1]:
    print('No')
    exit()
  if c[i+1][0]-c[i][0] != c[i+1][2]-c[i][2]:
    print('No')
    exit()
    
print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

lint N,K;
lint h[100010];
lint dp[100010];

lint ans(lint n)
{
	if(dp[n]!=-1)return dp[n];
	
	if(n==0)dp[n]=0;
	else if(n==1)dp[n]=abs(h[1]-h[0]);
	else
	{
		dp[n]=1e18;
		for(lint i=1;i<=K;i++)
		{
			if(n-i<0)break;
			dp[n]=min(dp[n],ans(n-i)+abs(h[n]-h[n-i]));
		}
	}
	return dp[n];
}

int main()
{
	cin >> N >> K;
	for(lint i=0;i<N;i++)
		dp[i]=-1;
	for(lint i=0;i<N;i++)
		cin >> h[i];
	
	cout << ans(N-1) << endl;
	return 0;
}



Measured memory_bytes: 4864
N = int(input())
D = list(map(int, input().split()))

N_MOD = 998244353

Dmax = max(D)
levels = [0] * (Dmax + 1)
#
for Di in D:
    levels[Di] += 1
#
if levels[0] != 1:
    print(0)
elif D[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1, Dmax + 1):
        p = levels[i - 1]
        i_p = levels[i]
        # print("#", p, i_p)
        for i in range(i_p):
            ans = (ans * (p % N_MOD)) % N_MOD
    #
    print(ans)

Measured memory_bytes: 14396