akhauriyash/Code-Regression huggingface dataset:
/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
*/
function Main(input) {
  //write here!
  input = input.split("\n");
  var a = input[0].split(" ").map(Number);
  var xmax = a[2];
  var ymax = a[3];
  var arr = input[1].split(" ").map(Number);
  for(var i=0;i<arr.length;i++){
  if(xmax<arr[i]) xmax = arr[i];
  }
  var arr2 = input[2].split(" ").map(Number);
  for(i=0;i<arr2.length;i++){
  if(ymax>arr2[i]) ymax = arr2[i];
  }
  if(xmax<ymax) console.log("No War");
  else console.log("War");

}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function pf(n) {
    var result = {};
    
    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}

Measured memory_bytes: 7756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,k;
   cin >> n >> k;
   int ans = 1e9;
   for (int i=0;i <= 10;i++){
      for (int j = 0; j <= 10;j++){
         if (i+j != n) continue;
         int tmp = 1;
         rep(h,i) tmp*=2;
         tmp += k*j;
         ans = min(ans,tmp);
      }
   }
   cout << ans << endl;
   return 0;
   
}



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

B = []
for h in range(H):
    if A[h].count('.') != W:
        B.append(A[h])

for c in range(W-1, -1, -1):
    for r in range(len(B)):
        if B[r][c] != '.':
            break
    else:
        for r in range(len(B)):
            del B[r][c]

for r in range(len(B)):
    print(''.join(B[r]))

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

int main()
{
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i = 0; i < N; ++i)
  {
    cin >> A.at(i);
  }
  
  int power = 0;
  while(true)
  {
    for(int i = 0; i < A.size(); ++i)
    {
      if(A.at(i) % 2 != 0)
      {
        cout << power << endl;
        return 0;
      }
      A.at(i) /= 2;
    }
    ++power;
  }
  
  return 0;
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let r = v[0];
	if r < 1200 {
		println!("ABC");
	}else if r < 2800 {
		println!("ARC");
	}else{
		println!("AGC");
	}
}

Measured memory_bytes: 4352
using System;


public class B{
	
	public static void Main(){
	
		int n = Int32.Parse(Console.ReadLine());
		if( n <= 111 ){
			Console.WriteLine(111);
		}else if( n <= 222 ){
			Console.WriteLine(222);
		}else if( n <= 333 ){
			Console.WriteLine(333);
		}else if( n <= 444 ){
			Console.WriteLine(444);
		}else if( n <= 555 ){
			Console.WriteLine(555);
		}else if( n <= 666 ){
			Console.WriteLine(666);
		}else if( n <= 777 ){
			Console.WriteLine(777);
		}else if( n <= 888 ){
			Console.WriteLine(888);
		}else{
			Console.WriteLine(999);
		}
		
	}
}

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

int main(){
    int n;
    cin >> n;
    int p[10], q[10];
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    for(int i=0; i<n; i++){
        cin >> q[i];
    }

    int permutation[10];
    for(int i=0; i<n; i++){
        permutation[i] = i+1;
    }
    sort(permutation, permutation + n);
    int a = 0, b = 0;
    do {
        bool isok = true;
        for(int i=0; i<n; i++){
            if(p[i] != permutation[i]){
                isok = false;
                break;
            }
        }
        if(isok){
            break;
        }else{
            a++;
        }
    } while (next_permutation(permutation, permutation + n));

    sort(permutation, permutation + n);
    do {
        bool isok = true;
        for(int i=0; i<n; i++){
            if(q[i] != permutation[i]){
                isok = false;
                break;
            }
        }
        if(isok){
            break;
        }else{
            b++;
        }
    } while (next_permutation(permutation, permutation + n));

    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// const ll INF = 1e18;
// const ll MOD = 1e9+7;
const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N;

int Main() {
    cin >> N;
    double ans = N* pi* 2;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3804
/*//////////////////////////////////////*/
/*/  NULLCT$ (｀･ω･´) <<"Be accept!!"  /*/
/*//////////////////////////////////////*/
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(counter, limit) for (int counter = 0; counter < limit; counter++)
typedef long long ll; using namespace std;
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<endl<<a<<endl<<b<<endl;

return 0;
}


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

int main(){ 
  int n;
  cin >> n;
  vector<double> a(n);
  double av = 0.0;
  rep(i,n) cin >> a[i], av += a[i];
  av /= (double)n;
  double dif = 1000.0;
  rep(i,n) {
    dif = min(dif, abs(av - a[i]));
  }
  rep(i,n) {
    if (dif == abs(av - a[i])) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
} 

Measured memory_bytes: 256
import fractions

def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    G = [A[0]]
    prev = A[0]
    for i in range(1, n):
        prev = fractions.gcd(prev, A[i])
        G.append(prev)

    ANS = [G[n - 2]]
    prev = A[n - 1]
    for i in range(n - 2, 0, -1):
        ANS.append(fractions.gcd(G[i - 1], prev))
        prev = fractions.gcd(A[i], prev)

    ANS.append(prev)

    print(max(ANS))

if __name__ == "__main__":
    main()


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n-1){
    if(s[i] == 'A' && s[i+1] == 'C'){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


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

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

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

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

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

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

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

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

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

use std::collections::HashSet;

fn main() {
    input!{
        abc: [i32;3],
    }
    let mut s = HashSet::new();
    for i in abc{
        s.insert(i);
    }
    let ans = s.len();
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

int main()
{
    string s;
    cin >> s;

    if (s[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }

    int cnum = 0;
    int index = 0;
    for (int i = 2; i <= s.size() - 2; i++)
    {
        if (s[i] == 'C')
        {
            cnum++;
            index = i;
        }
    }

    if (cnum != 1)
    {
        cout << "WA" << endl;
        return 0;
    }
    else
    {
        s.erase(s.begin() + index);
    }

    /*
    auto itr = find(s.begin() + 2, s.end() - 1, 'C');
    if (itr == s.end() - 1)
    {
        cout << "WA" << endl;
        return 0;
    }
    else
    {
        s.erase(itr);
    }
    cout << s << endl;
    */

    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] < 'a' || s[i] > 'z')
        {
            cout << "WA" << endl;
            return 0;
        }
    }

    cout << "AC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s;
    cin >> s;

    int n = s.size();

    ll r = 0;
    int k = n;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'B') {
            k--;
            r += k - i;
        }
    }

    cout << r << endl;

    return 0;
}

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

int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2;

    int a, b;
    a = x2 - x1;
    b = y2 - y1;

    x3 = x2 - b;
    y3 = y2 + a;
    x4 = x1 - b;
    y4 = y1 + a;

    cout << x3 << " " << y3 << " " << x4 << " " << y4;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int t;
	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll k[n],l[n],r[n];
		
		vector<ip> vl,vr;

		ll ans = 0;
		for(int i=0;i<n;i++){
			cin>>k[i]>>l[i]>>r[i];
			--k[i];
			ans += l[i];
			if(k[i] == n-1)
				continue;
			if(l[i]<r[i])
				vr.pb({r[i]-l[i],k[i]});
			else if(l[i]>r[i]){
				vl.pb({l[i]-r[i],k[i]});
				ans += r[i]-l[i];
			}
		}

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

		set<int>::iterator it;

		set<int> s;
		for(int i=0;i<n;i++)
			s.insert(i);
		for(int i=vl.size()-1;i>=0;i--){
			it = s.upper_bound(vl[i].ss);
			if(it == s.begin())
				continue;
			--it;
			s.erase(it);
			ans += vl[i].ff;
		}

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

		s.clear();
		for(int i=0;i<n;i++)
			s.insert(i);
		for(int i=vr.size()-1;i>=0;i--){
			it = s.lower_bound(vr[i].ss+1);
			if(it == s.end())
				continue;
			s.erase(it);
			ans += vr[i].ff;
		}

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

Measured memory_bytes: 20356
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n, k;
	char *str;
	scanf("%d %d", &n, &k);
	str = malloc(sizeof(char) * (n + 1));
	scanf("%s", str);
	str[k - 1] -= 'A' - 'a';
	printf("%s\n", str);
	return 0;
}


Measured memory_bytes: 128
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    K = I()

    ans = 1
    while ans < K and N > 0:
        ans *= 2
        N -= 1
    ans += N * K

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10116
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 100000;
int n, a[N];
bool cmp(int a, int b) {
	return (a & -a) > (b & -b);
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	sort(a, a + n, cmp);
	int Xor = 0, ans = 0;
	for (int i = 0; i < n; ++i)
		Xor ^= a[i];
	for (int i = 0; i < n; ++i)
		if (Xor & (a[i] & -a[i]))
			Xor ^= 2 * (a[i] & -a[i]) - 1, ++ans;
	printf("%d", Xor == 0 ? ans : -1);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

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

ll tgc(ll a,ll b,ll c){
  return gcd(gcd(a,b),c);
}

int main(){
  int k;
  cin >> k;
  ll ans = 0;
  rep1(a,k){
    rep1(b,k){
      rep1(c,k){
        ans += tgc(a,b,c);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 100010
int a[N],b[N];
int main()
{
    int n,i,j,k,m,s;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(i=0;i<n;i++)
        scanf("%d%d",&a[i],&b[i]);
        sort(a,a+n);
        sort(b,b+n);
        s=0;
        k=0;
        for(i=n-1;i>=0;i--)
        {
            if(b[i]<a[n-1])
                break;
            s=s+b[i];
            k++;
            if(s>=m)
                break;
        }
        if(s>=m)
        {
            printf("%d\n",k);
            continue;
        }
        k=k+(m-s)/a[n-1];
        if((m-s)%a[n-1])
            k++;
        printf("%d\n",k);
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

int main(void){

  typedef struct Ryouri{
    int num;
    int manzoku;
    int tuika;

  }ryouri;

  int n;
  int i,j;
  int ans=0;
  scanf("%d",&n);

  ryouri ry[n];
  int order[n];

  for(i=0;i<n;i++){
    ry[i].num=i;
  }

  for(i=0;i<n;i++){
    scanf("%d",&order[i]);
    order[i]=order[i]-1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&ry[i].manzoku);
  }
  for(i=0;i<n-1;i++){
    scanf("%d",&ry[i].tuika);
  }

  /*for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(ry[i].itu>ry[j].itu){
        tmp=ry[i];
        ry[i]=ry[j];
        ry[j]=tmp;
      }
    }
  }*/
  for(i=0;i<n;i++){
  ans=ans+ry[i].manzoku;
  }
  for(i=0;i<n-1;i++){

    if(ry[order[i]].num==ry[order[i+1]].num-1){
      ans=ans+ry[order[i]].tuika;
    }
  }
  printf("%d",ans);




return 0;

}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=105;
int d[3][N];
int m[3][N];
int n;
int main(){
	scanf("%d",&n);
    for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&m[i][j]);
	for(int i=2;i>=1;i--)
		for(int j=n;j>=1;j--){
            d[i][j]+=m[i][j];
            d[i-1][j]=max(d[i-1][j],d[i][j]);
            d[i][j-1]=max(d[i][j-1],d[i][j]);
		}
	printf("%d\n",d[1][1]);
}


Measured memory_bytes: 128
n=int(input())
d1=[]
d2=[]
f=0
for i in range(n):
    x,y=map(int, input().split())
    d1.append(x)
    d2.append(y)
for i in range(2,n):
    if d1[i]==d2[i] and d1[i-1]==d2[i-1] and d1[i-2]==d2[i-2] :
        f=1
if f==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false)cerr
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;

inline void solve()
{
    char c;
    cin >> c;
    if ((int) c >= (int)'a')
        cout << "a\n";
    else
    {
        cout << "A\n";
    }
    
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
#coding=UTF-8

N=int(input())
mozir=input()

hyo=mozir.split(' ')
a=[int(mono) for mono in hyo]

hindo=[0]*(10**5+1)

#count up
for suu in a:
    hindo[suu]+=1

#search the best
ansidx=None
tokuten=0
for idx in range(1,10**5,1):
    tmp=hindo[idx-1]+hindo[idx]+hindo[idx+1]
    if tmp > tokuten:
        tokuten=tmp
        ansidx=idx

print(tokuten)



Measured memory_bytes: 15320
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ii tuple<int, int>
#define iii tuple<int, int, int>
#define M 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli t, n, x, y;
    cin>>x>>y;
    if(y>=x)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";
    return 0;
}

Measured memory_bytes: 3640
F=->{gets.split.map &:to_i};n,*d=F[];g=(0..n).map{d<<p;[]};n.times{A,B,c=F[];c&&g[A]<<[B,c]&&g[B]<<[A,c]};d[B]=0;s=[B];g[$I].map{|u,c|d[u]||(d[u]=c+d[$I];s<<u)}while$I=s.pop;A.times{a,b=F[];p d[a]+d[b]}

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

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int search(const vector<vector<int> > & tb,int w,int h,int depth)
{
	if(depth == 0)
		return INF;
	else
	{
		int sx,sy,gx,gy;
		REP(i,h)
		REP(j,w)
		{
			if(tb[i+1][j+1] == 2)
			{
				sx = j+1;sy = i+1;
			}
			else if(tb[i+1][j+1] == 3)
			{
				gx = j+1;gy = i+1;
			}
		}
		int dx[4] = {1,0,-1,0};
		int dy[4] = {0,1,0,-1};
		int mind = INF;
		REP(i,4)
		{
			if(tb[sy+dy[i]][sx+dx[i]] == 0)
			{
				vector<vector<int> > cp(tb);
				FOR(j,2,20)
				{
					int nx = sx+dx[i]*j;
					int ny = sy+dy[i]*j;
					bool flg = false;
					switch(tb[ny][nx])
					{
						case 0:
							break;
						case 1:
							cp[ny][nx] = 0;
							cp[sy][sx] = 0;
							cp[ny-dy[i]][nx-dx[i]] = 2;
							mind = min(mind,search(cp,w,h,depth-1) + 1);
							flg = true;
							break;
						case 3:
							mind = min(mind,1);
							flg = true;
							break;
						case 4:
							flg = true;
							break;
					}
					if(flg)
						break;
				}
			}
			else if(tb[sy+dy[i]][sx+dx[i]] == 3)
			{
				mind = min(mind,1);
			}
		}
		return mind;
	}
}

int main(void) {
	while(1)
	{
		int w,h;
		cin>>w>>h;
		if(!(w||h))break;
		vector<vector<int> > table(h+2,vector<int>(w+2,4));
		REP(i,h)REP(j,w)cin>>table[i+1][j+1];
		int ans = search(table,w,h,10);
		if(ans >= INF)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << ans << endl;
		}
	}
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

//#define FILE_INPUT
//#define DEBUG_MODE

long long int dp[100001];

void DebugPrint(int n, long long int *a)
{
#ifdef DEBUG_MODE
	for (int i = 0; i < n; ++i) {
		cout << a[i] << ",";
	}
	cout << endl;
#endif
}

int main()
{
#ifdef FILE_INPUT
	ifstream in("test3.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */  

	int n, ww;
	cin >> n >> ww;

	vector<int> w(100);
	vector<int> v(100);
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> v[i];
	}

	for (int i = 0; i <= ww; ++i) {
		dp[i] = 0;
	}
	for (int i = 0; i < n; ++i) {
		for (int j = ww; j >= 0; --j) {
			int j2 = j + w[i];
			if (j2 <= ww) {
				dp[j2] = max(dp[j2], dp[j] + v[i]);
			}
		}
		DebugPrint(ww + 1, dp);
	}
	cout << dp[ww] << endl;

	return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

int main()
{
	int a, b;
	scanf("%d %d",&a,&b);

	for(int i = 1 ; i <= 100000 ; i++)
	{
		int newA = i*8;
		newA /= 100;

		int newB = i/10;

		if( newA == a && newB == b )
		{
			printf("%d\n",i);
			return 0;
		}
	}

	printf("-1\n");
}

Measured memory_bytes: 256
def coin(larger=False, single=False):
    """
    ナップサックに入れる重さが W 丁度になる時の価値の最小値
    :param larger: False = (重さ = W)の時の最小価値
                   True  = (重さ =< W)の時の最小価値
    :param single: False = 重複あり

    dp[weight <= W+1] = 重さを固定した時の最小価値
    dp[W+1] = 重さがWより大きい時の最小価値
    """
    W2 = W + 1              # dp[W+1] に W より大きい時の全ての場合の情報を持たせる
    dp_max = float("inf")   # 総和価値の最大値
    dp = [dp_max] * (W2 + 1)
    dp[0] = 0               # 重さ 0 の時は価値 0

    for item in range(N):
        if single:
            S = range(W2, weight_list[item] - 1, -1)
        else:
            S = range(W2)
        for weight in S:
            dp[min2(weight + weight_list[item], W2)] = min2(dp[min2(weight + weight_list[item], W2)], dp[weight] + cost_list[item])
    if larger:
        return min(dp[w] for w in range(W, W2+1))
    else:
        return dp[W]

#######################################################################################################
import sys
input = sys.stdin.readline


def max2(x, y):
    return x if x > y else y

def min2(x, y):
    return x if x < y else y

W, N = map(int, input().split())                                # N: 品物の種類 W: 重量制限

cost_list = []
weight_list = []
for _ in range(N):
    """ cost と weight が逆転して入力されている場合有り """
    weight, cost = map(int, input().split())
    cost_list.append(cost)
    weight_list.append(weight)


print(coin(larger=True, single=False))

Measured memory_bytes: 68912
#include <bits/stdc++.h>
#define fort(i,n) for (int i = 1; i <= n; i++)
#define ll long long
#define pi pair<int,int>
#define sz size()
#define er erase
#define fr first
#define sc second
using namespace std;

int n,m;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for (int i = m/n; i >= 1; i--)
    {
        if (m%i==0)
        {
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 256
/* Author : Prasuk Jain */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int              long long int
#define ull              unsigned long long
#define ld               long double
#define fo(i, n)         for(int i=0; i<n; i++)
#define Fo(i, a, b)      for(int i=a; i<b; i++)
#define rfo(i, n)        for(int i=n-1; i>=0; i--)
#define Rfo(i, a, b)     for(int i=b-1; i>=a; i--)
#define tr(it, v)        for(auto it=v.begin(); it!=v.end(); it++)
#define F                first
#define S                second
#define vi               vector<int>
#define vvi              vector<vector<int>>
#define pii              pair<int, int>
#define pqb              priority_queue<int>
#define pqs              priority_queue<int, vi, greater<int>>
#define mii              map<int, int>
#define uset             unordered_set<int>
#define umap             unordered_map<int, int>
#define mp               make_pair
#define pb(x)            push_back(x)
#define hcf(x, y)        __gcd(x, y)
#define lcm(x, y)        boost::math::lcm(x,y)
#define setpre(x, y)     fixed << setprecision(y) << x
#define maax(a, b, c)     max(a, max(b, c))
#define miin(a, b, c)     min(a, min(b, c))
#define setbits(x)       __builtin_popcountll(x)
#define zerolead(x)      __builtin_clzll(x)
#define zerotrail(x)     __builtin_ctzll(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define PI               3.1415926535897932384626
const int mod = 1e9+7;
const int inf = 1e18;
int mpow(int base, int exp);
bool isprime(int num);
void prifact(int num);

//*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!//

void coderprasukj(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    coderprasukj();
    int a,b;
    cin >> a >> b;
    cout << a*b <<"\n";
    return 0;
}

//*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!//

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
        if (exp & 1) result = ((int)result * base) % mod;
        base = ((int)base * base) % mod;
        exp >>= 1;
    }
  return result;
}

bool isprime(int num) {
    if(num <= 1) return false;
    for(int i=2; i*i <= num; i++)
        if(num%i == 0) return false;
    return true;
}

void prifact(int num){
    for(int i=2; i<=num; i++)
    if(num%i == 0){
        int cnt = 0;
        while(num%i == 0)
        cnt++ , num /= i;
        cout << i << "^" << cnt << " ";
    }
    if(num > 1)
    cout << num << "^" << "1" << " ";
}





Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
const int N = 100000 + 5;; 
char str[N];
int len;
void put(int a, int b){
	printf("%d %d\n", a, b);
}
void solve(){
	for(int i = 0; str[i+1]; i ++){
		if(str[i] == str[i+1]){
			put(i+1, i+2);
			return ;
		}	
	}
	for(int i = 0; str[i+2]; i ++){
		if(str[i] == str[i+2]){
			put(i+1, i+3);
			return ;
		}	
	}
	put(-1, -1);
	return ;
}
int main(){
	scanf("%s", str);
	solve();
}

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

int main(){
    string s;
    cin >> s;
    if(s == "SUN") cout << 7;
    else if(s == "MON") cout << 6 ;
    else if(s == "TUE") cout << 5 ;
    else if(s == "WED") cout << 4 ;
    else if(s == "THU") cout << 3 ;
    else if(s == "FRI") cout << 2 ;
    else cout << 1 ;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
char S[101];
long K;
scanf("%s",S);
scanf("%ld",&K);

if(S[0]=='1'){
  int i=1;
  int count_1=1;
  while(S[i++]=='1'){count_1++;}
  if(K>count_1){
    printf("%c",S[i-1]);
  }else{
    puts("1");
  }
}else{
  printf("%c",S[0]);
}

return 0;

}

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

int main(){
  int N,K,a,temp,cnt,kind,num,sum,minn;
  temp = 0;
  cnt = 1;
  num = 0;
  sum = 0;
  cin >> N >> K;
  minn = N;
  vector<int> ball (N);
  vector<int> kindball(N);
  for(int i = 0;i < N;i++){
    cin >> a;
  	ball.at(i) = a;
  //  kindball.at(i) = 0;
  }
  
  sort(ball.begin(),ball.end());
  temp = ball.at(0);
  for(int i = 0;i < N;i++){
  	if(temp != ball.at(i)){
    	temp = ball.at(i);
      	cnt++;
      num ++;
      kindball.at(num) = 1;
    }else{
    	kindball.at(num) += 1;      
    }
  }
  kind = cnt - K;
  temp= 0;
  
  sort(kindball.begin(),kindball.end()); 
  for(int j = N - cnt;j < N - cnt  +kind;j++){
  	sum += kindball.at(j);
  }
  cout << sum << endl;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n  = sc.nextInt();
			if(n==0)break;
			int[] uta = new int[n];
			for(int i=0;i<n;i++) {
				uta[i] = sc.next().length();
			}
			
			int[] k = {5,7,5,7,7};
			boolean fin = false;
			int ans = 0;
			for(int l=0;l<=n-4;l++) {
				if(5-uta[l] < 0)
						continue;
				int[] kk = Arrays.copyOf(k,5);
				boolean doing = true;
				for(int i=l;i<n;i++) {
					for(int j=0;j<5;j++) {
						if(kk[j]==0)
							continue;
						if(kk[j]-uta[i] < 0 ) {
							doing = false;
							break;
						}
						else {
							kk[j] -= uta[i];
							if(kk[4]==0) {
								fin = true;
								ans = l+1;
							}
							break;
						}
					}
					if(!doing || fin)
						break;
				}
				if(fin)
					break;
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 32068
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    ll xorsum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        xorsum ^= a[i];
    }
    for (int i = 0; i < n; ++i) {
        a[i] &= ~xorsum;
    }
    vector<bool> used(n, false);
    for (ll i = 60; i >= 0; --i) {
        int idx = -1;
        for (int j = 0; j < n; ++j) {
            if (!used[j] && ((1LL << i) & a[j])) {
                idx = j;
                break;
            }
        }
        if (idx == -1)
            continue;
        used[idx] = true;
        for (int j = 0; j < n; ++j) {
            if (j == idx)
                continue;
            if (a[j] & (1LL << i))
                a[j] ^= a[idx];
        }
    }
    ll ret = xorsum;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        sum ^= a[i];
    }
    cout << ret + 2LL * sum << "\n";

    return 0;
}

Measured memory_bytes: 1024
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = sum(f(x) for x in a)
    print(s)

def f(n):
    c = 0
    while n & 0x01 == 0:
        c += 1
        n >>= 1
    return c

main()


Measured memory_bytes: 4152
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var d = int.Parse(line[3]);
        Console.WriteLine(a * b > c * d ? a * b : c * d);
    }
}


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

ll q, h, s, d, n;
int main(void){
  cin >> q >> h >> s >> d >> n;
  ll best1 = min(4*q, min(2*q+h, min(2*h, s)));
  ll best2 = min(best1*2, d);
  ll ans = n%2 * best1 + n/2 * best2;
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().ToCharArray();
            var T = Console.ReadLine();

            var answer = new List<string>();
            for(int i=0;i<S.Length;i++)
            {
                var tmpS = S.ToList().ToArray();
                for(int k =0;k<T.Length && i+k<S.Length;k++)
                {
                    if (tmpS[i + k] == '?') tmpS[i + k] = T[k];
                    if (tmpS[i + k] != T[k]) break;
                }
                if(string.Concat(tmpS).Contains(T))
                {
                    answer.Add(string.Concat(tmpS).Replace('?', 'a'));
                }
            }

            if(!answer.Any())
            {
                Console.WriteLine("UNRESTORABLE");
                return;
            }
            answer.Sort();
            Console.WriteLine(answer.First());
        }
    }

Measured memory_bytes: 13536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;
int main()
{
   int N,K;
   scanf("%d%d",&N,&K);
   int i,j;
   j=0;
   int a;
   for(i=0;i<N;i++)
   {
        scanf("%d",&a);
        if(a>=K)
            j++;
   }
   printf("%d",j);


    return 0;

}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int[] nums = new int[3];

		nums[0] = scan.nextInt();
		nums[1] = scan.nextInt();
		nums[2] = scan.nextInt();

		Arrays.sort(nums);

		System.out.println(nums[0]+" "+nums[1]+" "+nums[2]);


	}

}

Measured memory_bytes: 26144
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
    pair < pair <string,int> ,int> x[110];

    int n,cnt;  char space=' ';
    cin >> n;
    int arr[10010];
    string s;   int pts;
    string s_new;

    for(int i=1;i<=n;i++){
        cin >> s;   cin >> pts;
        x[i] = make_pair (make_pair(s,-pts) ,i);

    }

    sort (x+1,x+1+n);

    for(int i=1;i<=n;i++){
        cout << x[i].second << endl;
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long result =0;
		int N = sc.nextInt();
		long A[] = new long[N];
		long sum =0;
		for (int i=0;i<N;i++) {
			A[i]= sc.nextLong();
			sum +=A[i];
		}
		for (int i=0;i<N;i++) {
			sum -=A[i];
			result = (result +(sum%1000000007)*A[i])%1000000007;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 62916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll a, b, c, k, d = 0;
	cin >> a >> b >> c >> k;
	while (b <= a) b *= 2, d++;
	while (c <= b) c *= 2, d++;
	if (d <= k) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b;
};

//小さい順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main(){
    int X,Y;
    scanf("%d%d",&X,&Y);
    for(int i=0;i<=X;i++){
        int sum=0;
        sum=2*i+4*(X-i);
        if(sum==Y){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}


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

typedef long long ll;
typedef pair<ll,ll> pll;


map<pll,ll> M;
vector<pll> W;

ll count(ll a){
  pll &w=W[a];
  ll mx=0;
  ll C=0;
  for(int i=-1;i<1;i++){
    for(int t=-1;t<1;t++){
      C=0;
      for(int x=0;x<=1;x++){
	for(int y=0;y<=1;y++){
	  C+=M[{w.first+i+x,w.second+t+y}];
	}
      }
      mx=max(mx,C);
    }
  }
  return mx;
}


int main(){
  ll n;
  cin>>n;
  for(int i=0;i<n;i++){
    ll x,y,w;
    cin>>x>>y>>w;
    W.push_back({x,y});
    M[{x,y}]+=w;
  }
  ll ans=0;
  for(int i=0;i<n;i++){ans=max(ans,count(i));}
  cout<<ans<<" / 1"<<endl;


  return 0;
}


Measured memory_bytes: 60536
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    for b in [int(input()) for _ in range(n)]:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    A[i][j] = 0
    for i in range(3):
        if sum(A[i]) == 0:
            return "Yes"
    A = list(zip(*A[::-1]))
    for i in range(3):
        if sum(A[i]) == 0:
            return "Yes"
    if A[0][0] + A[1][1] + A[2][2] == 0 or A[2][0] + A[1][1] + A[0][2] == 0:
        return "Yes"
    return "No"
print(solve())


Measured memory_bytes: 3064
s = input()
counter = 0
n = s.find('BC')
while n != -1:
    k = 1
    while k <= n and s[n-k] == 'A':
        k += 1
    a_num = k-1
    counter += a_num
    s = s[n+2:]
    while True:
        n = s.find('BC')
        if n == -1:
            break
        else:
            if s[:n].count('A') == n:
                a_num += n
                counter += a_num
                s = s[n+2:]
            else:
                break
print(counter)

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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  int ans;
  int cnt = 0;
  for (int n = 100; n > 0; n--) {
    if (a % n == 0 && b % n == 0) {
      cnt++;
      if (cnt == k) ans = n;
    }
  }
  cout << ans << endl;
}


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

constexpr int MAX_N = 8;

bool r[MAX_N + 1][MAX_N + 1];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i{}; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    r[a][b] = r[b][a] = true;
  }
  int index[MAX_N];
  for (int i{}; i < N; ++i) {
    index[i] = i + 1;
  }

//  sort(index, index + N); // 昇順にソートしておく必要あり
  int count{};
  do {
    bool ok{true};
    for (int i{}; i < N - 1; ++i) {
      if (!r[index[i]][index[i + 1]]) {
        ok = false;
        break;
      }
    }
    if (ok)
      ++count;
  } while (next_permutation(index + 1, index + N));

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
s = 0
b = 0
count = int(input())
list_A = list(map(int, input().split()))
for a in list_A:
  s = s + a
s = s/count
s = Decimal(s).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for a in list_A:
  b = b + (a - s) * (a - s)
print(b)

Measured memory_bytes: 5076
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	int D_Set;
	
	cin >> D_Set;
	cin.ignore();
	for(int i = 0; i < D_Set; i++) {
		string text;
		getline(cin, text);
		
		while(1) {
			string::size_type pos = text.find("Hoshino");
			if(pos == string::npos)	{ break; }
			else {
				text[pos + 6] = 'a';
			}
		}
		cout << text << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
char nn[2][55];
int main()
{
	int n;
	scanf("%d",&n);
	memset(nn,0,sizeof(nn));
	scanf("%s",nn[0]);
	scanf("%s",nn[1]);
	int t;
	ll s;
	vector<int> bj;
	for(t=0;t<n;t++)
	{
		if(nn[0][t] == nn[1][t])
			bj.push_back(0);
		else
		{
			bj.push_back(1);
			t++;
		}
	}
	if(bj[0] == 1)
		s = 6;
	else
		s = 3;
	for(t=1;t<bj.size();t++)
	{
		if(bj[t-1]==0 && bj[t]==0)
			s *= 2;
		else if(bj[t-1]==0 && bj[t]==1)
			s *= 2;
		else if(bj[t-1]==1 && bj[t]==0)
			s *= 1;
		else if(bj[t-1]==1 && bj[t]==1)
			s *= 3;
		s %= MOD;
	}
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
template<typename I>
using DifferenceType = typename std::iterator_traits<I>::difference_type;
template<typename I>
using IteratorCategory = typename std::iterator_traits<I>::iterator_category;
template<typename I>
using ValueType = typename std::iterator_traits<I>::value_type;
// distance
template<typename I>
DifferenceType<I> distance(I f, I l, std::input_iterator_tag) {
    // 事前条件: valid_range(f, l)
    DifferenceType<I> n(0);
    while (f != l) {
        ++f;
        ++n;
    }
    return n;
}
template<typename I>
DifferenceType<I> distance(I f, I l, std::random_access_iterator_tag) {
    // 事前条件: valid_range(f, l)
    return l - f;
}
template<typename I>
DifferenceType<I> mydistance(I f, I l) {
    return distance(f, l, IteratorCategory<I>());
}
// advance
template<typename I>
void advance(I& x, DifferenceType<I> n, std::input_iterator_tag) {
    while (n) {
        --n;
        ++x;
    }
}
template<typename I>
void advance(I& x, DifferenceType<I> n, std::random_access_iterator_tag) {
    x += n;
}
template<typename I>
void myadvance(I& x, DifferenceType<I> n) {
    advance(x, n, IteratorCategory<I>());
}
// // linear find
// template<InputIterator I, Predicate P>
// I find_if(I f, I l, P p) {
//     std::cout << "find_if(InputIterator) is called" << std::endl;
//     while (f != l && !p(*f)) {
//         ++f;
//     }
//     return f;
// }
//
// template<InputIterator I, Predicate P>
// std::pair<I, DifferenceType<I>> find_if_n(
//         I f, DifferenceType<I> n, P p) {
//     while (n && !p(*f)) { ++f; --n; }
//     return {f, n};
// }
// binary search
template<typename I, typename P>
I partition_point_n(I f, DifferenceType<I> n, P p) {
    while (n) {
        I middle(f);
        DifferenceType<I> half(n >> 1);
        advance(middle, half);
        if (!p(*middle)) {
            n = half;
        } else {
            f = ++middle;
            n = n - (half + 1);
        }
    }
    return f;
}
template<typename I, typename P>
I mypartition_point(I f, I l, P p) {
    return partition_point_n(f, distance(f, l), p);
}
// lower_bound
template<typename I>
I mylower_bound(I f, I l, ValueType<I> a) {
    return mypartition_point(f, l,
            [=](ValueType<I> x) { return x < a; });
}
// upper_bound
template<typename I>
I myupper_bound(I f, I l, ValueType<I> a) {
    return mypartition_point(f, l,
            [=](ValueType<I> x) { return x <= a; });
}
int main() {
    int n; std::cin >> n;
    std::vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) std::cin >> a[i];
    for (int i = 0; i < n; ++i) std::cin >> b[i];
    for (int i = 0; i < n; ++i) std::cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        auto lb = mylower_bound(a.begin(), a.end(), b[i]);
        auto ub = myupper_bound(c.begin(), c.end(), b[i]);
        ans += (long long)mydistance(a.begin(), lb) * mydistance(ub, c.end());
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://agc002.contest.atcoder.jp/tasks/agc002_c>
問題文============================================================
 N 本のロープがあります。 ロープは 1 から N まで番号が振られています。 ロープ i の長さは ai です。
 
 最初、1≤i≤N−1 について、ロープ i の右端とロープ i+1 の左端が結ばれています。
 高橋君は次の操作を N−1 回行い、すべての結び目をほどこうとしています。
 
 ひと繋がりのロープのうち、長さの総和が L 以上のものをひとつ選ぶ。
 選んだひと繋がりのロープに結び目があれば、結び目のうちどれかひとつをほどく。
 
 高橋君は結び目をほどく順番を工夫し、すべての結び目をほどくことができるでしょうか？
 可能か判定し、可能ならば結び目をほどく順番をひとつ求めてください。

=================================================================

解説=============================================================

 結び目を解く順番によらず、いずれ紐は二本が繋がった ai + a_i+1 := len の長さを扱わなくては行けなくなる
 逆にこの len が len >= L であれば、この二本が入ったグループが残されるように両端から紐を解いて行けば良いので
 
 possible か impossibleかどうかの判定は ai + a_i+1 >= L の判定でできる
 
================================================================
*/

struct sec{
    ll l,r,len;
    sec(){}
    sec(ll l,ll r,ll len):l(l),r(r),len(len){}
};
void solve(){
    int N,L; cin >> N >> L;
    vector<int> a(N);
    for(auto &in:a) cin >> in;
    for(int i = 0; i < N-1;i++){
        if(a[i] + a[i+1] >= L){
            cout << "Possible" << endl;
            for(int j = 1; j <= i;j++) cout << j << endl;
            for(int j = N - 1; j > i; j--) cout << j << endl;
            return;
        }
    }
    cout << "Impossible" << endl;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;																																																																																																																																							auto Nextint=[]()->int{int x;scanf("%d",&x);return x;};

int n,a[1000001];

bool check(int x)
{
	vector<int> pos;
	auto func=[x](int p)->bool{return a[p]>=x;};auto proc=[](bool a,bool b,bool c)->bool{return a==b||b==c;};
	for(int i=2;i<=2*(n-1);++i)if(proc(func(i-1),func(i),func(i+1)))pos.push_back(i);
	if(pos.empty())return func(1);
	auto res=0,maxn=INT_MAX;
	for(auto i : pos)if(abs(i-n)<maxn)res=i,maxn=abs(i-n);
	return func(res);
}

int main()
{
	n=Nextint();
	for(int i=1;i<=2*n-1;++i)[](int i)->void{a[i]=Nextint();}(i);
	auto l=1,r=2*n,ans=0;
	while(l<=r)
	{
		auto mid=(l+r)>>1;
		if(check(mid))l=mid+1,ans=mid;else r=mid-1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 2896
#!/usr/bin/env python3
import sys


def solve(S: str):
    for i in range(len(S)-1):
        if S[i+1] == S[i]:
            print('Bad')
            return
    print('Good')
    return 


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for ( int i = 0; i < 3; i++){
    if ( s[i] == t[i]){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N;
    cin>>N;
    long long b[N];
    long long mb=0;
    long long ma=0;
    for(long long i=0;i<N;i++){
    cin>>b[i];}
    for(long long i=0;i<N;i++){
    if(b[i]>=b[i+1]){
    ma++;}
    else{
    mb=max(ma,mb);
    ma=0;}}
    cout<<mb<<endl;}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>

typedef long long ll;

using namespace std;

bool isPrime(int n){
	if(n == 2)
		return true;
	if(n<2 || n%2==0)
		return false;
	for(int i = 3 ; i*i<=n ; i+=2){
		if(n%i == 0)
			return false;
	}
	return true;
}

int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	printf("%d:",n);
	if(isPrime(n)){
		printf(" %d\n",n);
		return 0;
	}
	int a[100010];
	int t = 0;
	while (n%2==0){
		a[t++] = 2;
		n >>= 1;
		if(n&1)
			break;
	}
	
	for(int i = 3 ; i<=n ; i++){
		if(isPrime(i) == false)
			continue;
		while (n%i==0){
			a[t++] = i;
			n /= i; 
		}
		if(n == 1)
			break;
	}
	
	for(int i = 0 ; i<t ; i++){
			printf(" %d",a[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 3244
#include <stdio.h>

int main()
{
    char * a;
    char b[1200];
    int i, length;
    fgets(b, sizeof(b), stdin);
    a = &b[0];
    length = sizeof(b)/sizeof(char);
    //printf("%d", length);
    //puts(b);
    i = 0;
    while(i < length){
        if(a[i] > 64 && a[i] < 91){
            a[i] += 32;
        }
        else if(a[i] == '\0') break;
        else if(a[i] > 66 && a[i] < 123){
            a[i] -= 32;
        }
        //putchar(b[i]);
        i++;
        //printf("%c", a[i]);
    }
    printf("%s", b);
    //putchar('\n');
    return 0;
}


Measured memory_bytes: 2052