akhauriyash/Code-Regression huggingface dataset:
def func(A, n, k): 
    A.sort() 
    product = 1

    if (A[n - 1] == 0 and (k & 1)): 
        return 0

    if (A[n - 1] <= 0 and (k & 1)) : 
        for i in range(n - 1, n - k - 1, -1): 
            product = (product*A[i])%mod
        return product 

    i = 0
    j = n - 1
    if (k & 1): 
        product = (product*A[j])%mod 
        j-= 1
        k-=1

    k >>= 1
  
    for itr in range( k) : 
        left_product = A[i] * A[i + 1] 
 
        right_product = A[j] * A[j - 1] 
  
        if (left_product > right_product) : 
            product = (product*(left_product%mod))%mod
            i += 2
          
        else : 
            product = (product*(right_product%mod))%mod
            j -= 2
  
    return product 


n,k=map(int,input().split())
arr=list(map(int,input().split()))
global mod
mod=1000000007
ans=func(arr,n,k)
print(ans%mod)

Measured memory_bytes: 31632
import java.util.*;
import java.util.ArrayList;

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

		// 値取得
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		int cnt = 0;
		int corres[] = new int[q];
		int apps[] = new int[n];


		Arrays.fill(apps, k-q);
		while(sc.hasNext()){
			corres[cnt] = sc.nextInt();
			cnt++;
		}
		// System.out.println(corres.length);

		for(int cor:corres){
			apps[cor-1] +=1;
		}

		for(int app:apps){

			if(app <= 0){
				System.out.println("No");
			}else{
				System.out.println("Yes");
			}
		}		
	}
}


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

int main(){
    int a,b;
    cin >>a>>b;
    if((b-1)%(a-1)==0) cout << (b-1)/(a-1) << endl;
    else cout << (b-1)/(a-1) + 1 << endl;

}

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

int main() {

  int N, M;
  cin >> N >> M;

  vector<int> count(N+1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    count[a]++;
    count[b]++;
  }

  for (int i = 1; i <= N; i++) {
    cout << count[i] << endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int i, j, a, b;

  while(1){
    scanf("%d%d",&a,&b);
    if(a==0 && b==0)break;
    for ( i = 0; i < a; i++ ){
      for ( j = 0; j < b; j++ ){
	if(i!=0&&i!=a-1&&j!=0&&j!=b-1){
	  printf(".");
	} else {
	  printf("#");
	}
      }
      printf("\n");
    }
 
    printf("\n");
  }
  return 0;
}

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

typedef long long ll;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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; }

vector<vector<pair<int, int>>> g;
vector<int> ans;

void dfs(int now, int pre, int pre_color) {
    int color = 1;
    for (auto next: g[now]) {
        if (next.first == pre) continue;
        if (color == pre_color) color++;
        ans[next.second] = color;
        dfs(next.first, now, color);
        color++;
    }
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    g.resize(n);
    ans.resize(n-1);

    int a, b;
    for (int i = 0; i < n-1; i++) {
        cin >> a >> b;
        a--; b--;
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    
    int max_color = 0;

    for (int i = 0; i < n; i++) {
        chmax(max_color, int(g[i].size()));
    }
    cout << max_color << endl;

    dfs(0, -1, -1);

    for (int i = 0; i < n-1; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}




Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=2e5 + 5;
const double arc=acos(-1) * 5;
vector<pair<int, int> > v;

void print(double ans){
	cout << fixed << setprecision(12) << ans << endl;
	exit(0);
}

int lis(){
	vector<int> temp;
	for(int i=0,a;i < v.size();i++){
		a=v[i].se;
		if(!i || a > temp.back()){
			temp.pb(a);
			continue;
		}
		int l=lower_bound(temp.begin(),temp.end(),a) - temp.begin();
		temp[l]=a;
	}
	return temp.size();
}

int main(){

//	freopen("in.txt","r",stdin);

	int x1,y1,x2,y2,n;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	bool f=0,c1=0;
	if(x1 > x2) swap(x1,x2), swap(y1,y2);
	if(y1 > y2) f=1;
	scanf("%d",&n);
	for(int i=0,x,y;i < n;i++){
		scanf("%d%d",&x,&y);
		if(y >= min(y1,y2) && y <= max(y1,y2) && x >= min(x1,x2)
			&& x <= max(x1,x2)) ;
		else continue;
		if(x1 == x2 && x1 == x){
			if(y > min(y1,y2) && y < max(y1,y2)) c1=1;
		}
		else if(y1 == y2 && y1 == y){
			if(x > min(x1,x2) && x < max(x1,x2)) c1=1;
		}
		if(f) y=-y;
		v.pb({ x, y });
	}
	if(x1 == x2){
		double ans=abs(y1 - y2) * 100.0;
		if(c1) ans+=-20 + 2 * arc;
		print(ans);
	}
	if(y1 == y2){
		double ans=abs(x1 - x2) * 100.0;
		if(c1) ans+=-20 + 2 * arc;
		print(ans);
	}
	sort(v.begin(),v.end());
	double ans=-min(y1,y2) + max(y1,y2) - min(x1,x2) + max(x1,x2);
	ans*=100;
	int d=lis();
	ans-=(20 - arc) * d;
	if(d == min(-min(y1,y2) + max(y1,y2),-min(x1,x2) + max(x1,x2)) + 1){
		ans+=(20 - arc);
		ans+=-20 + 2 * arc;
	}
	print(ans);
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;

int main()
{
	int i, j;
	ll a;
	scanf("%lld", &a);
	ll sum = 1000LL * (a / 500LL);
	a -= 500LL*(a/500LL);
	sum += 5LL * (a / 5LL);
	printf("%lld", sum);
}

Measured memory_bytes: 256
S = input()
dream = "dream"
dreamer = "dreamer"
erase = "erase"
eraser = "eraser"


while True:
    if S.find(dream, len(S) - len(dream), len(S)) == len(S) - len(dream):
        S = S[:len(S) - len(dream)]
        continue
    elif S.find(dreamer, len(S) - len(dreamer), len(S)) == len(S) - len(dreamer):
        S = S[:len(S) - len(dreamer)]
        continue
    elif S.find(erase, len(S) - len(erase), len(S)) == len(S) - len(erase):
        S = S[:len(S) - len(erase)]
        continue
    elif S.find(eraser, len(S) - len(eraser), len(S)) == len(S) - len(eraser):
        S = S[:len(S) - len(eraser)]
        continue
    elif len(S) == 0:
        print("YES")
        break
    else:
        print("NO")
        break


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long int
#define double long double
#define endl "\n"
#define PI 3.141592653589793238462643383279502884
#define sum_up(x)  (x*(x+1))/2
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define BSv(v,a) binary_search(v.begin(),v.end(), a)
#define BSa(v,n,a) binary_search(v,v+n, a)
#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
unsigned int N=1000000;
bool prime[100001];
void sieve(int n)
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int power(int x, int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x*x;
    }
    return res;
}

int nxt()
{
    int x;
    cin >> x;
    return x;
}

bool comp(const pair<pair<int,int>,pair<int,int>>&a,
          const pair<pair<int,int>,pair<int,int>>&b)
{
    if(a.second.first==b.second.first)
        return a.first.first<b.first.first;
    return a.second.first>b.second.first;
}

int32_t main()
{
    base;
    int n=nxt();
    int arr[n-1];
    gena(arr,n-1,nxt);
    int sum[n+1];
    memset(sum,0,sizeof(sum));
    for(int i=0;i<n-1;i++)sum[arr[i]]++;
    for(int i=1;i<=n;i++) cout<<sum[i]<<endl;
    return 0;
}


Measured memory_bytes: 6740
from time import time

start = time()
D = int(input())
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
    t.append(i.index(max(i))+1)
DC = [0]*26

def calcScore(t):
    score = []
    S = 0
    last = [0]*26
    for d in range(1,D+1):
        S += scores[d-1][t[d-1]-1]
        last[t[d-1]-1] = d
        for i in range(26):
            S -= C[i] * (d - last[i])
            DC[i] += (d - last[i])
        score.append(S)
    return score[-1]

from random import randint
ts = calcScore(t)
i = 0
while time() - start < 1.8:
    d,q = i, randint(1,26)
    temp = [t[i] if d-1 != i else q for i in range(D)]
    if calcScore(temp) > ts:
        t = temp
        i += 1

print("\n".join(map(str, t)))


Measured memory_bytes: 9956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int m=0,i,n,r=0,w=0;
    cin>>n;
    string s;
    cin>>s; 
    for(i=0;i<n;i++)
    {
        if(s[i]=='W') w++;
        else r++;
    }
    for(i=n-w;i<n;i++)
    {
        if(s[i]=='R') m++;
    }
    cout<<m;
}

Measured memory_bytes: 3716
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

int N;
vector<vector<int>> A;
vector<mint> dp;
vector<bool> check;

mint dfs(int n,int k) {
    if (n == N) return 1;
    if (check[k]) return dp[k];
    mint ans = 0;
    rep(i,N) {
        if (((1 << i) & k) && A[n][i]) {
            ans += dfs(n+1,k - (1 << i));
        }
    }
    check[k] = true;
    return dp[k] = ans;
} 

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    A.resize(N, vector<int>(N));
    rep(i,N) rep(j,N) cin >> A[i][j];

    int M = (1 << (N+1));
    dp.resize(M);
    check.assign(M,false);

    cout << dfs(0,M-1).a << endl;
}

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

int main() {
    int N;
    cin>>N;
    long A[N];
    for(int i=0;i<N;++i){
        cin>>A[i];
    }
    long ans = 0;
    for(int i=0;i<N-1;++i){
        ans += A[i] / 2;
        A[i] %= 2;
        if(A[i]==1 & A[i+1]>0){
            A[i]--;
            A[i+1]--;
            ans++;
        }
    }
    ans += A[N-1]/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int d[n]={};
	for(int i=0; i<n; i++){
		cin>>d[i];
	}
	int ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			ans+=d[i]*d[j];
		}
	}
	cout<<ans<<endl;
}

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

int main(){
	int W[100],N,i,left=0, right=0,Z,A;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&W[i]);
		if(i!=0)right+=W[i];
		else left+=W[i];
	}
	for(i=1;i<N;i++){
		if(left>right){
			Z=left-right;
			if(left-right+2*W[i]<=0){
				A=right-left-2*W[i];
				break;
			}
			else{
				left=left+W[i];
				right=right-W[i];
			}
		}
		else{
			Z=right-left;
			if(left-right+2*W[i]>=0){
				A=left-right+2*W[i];
				break;
			}
			else{
				left=left+W[i];
				right=right-W[i];
			}
		}
	}
	if(Z>A)printf("%d\n",A);
	else printf("%d\n",Z);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int m = sc.nextInt();
      int f = sc.nextInt();
      int r = sc.nextInt();
      if (m == -1 && f == -1 && r == -1) break;
      if (m == -1 || f == -1) System.out.println("F");
      else if (m + f >= 80) System.out.println("A");
      else if (m + f >= 65) System.out.println("B");
      else if (m + f >= 50 || r >= 50) System.out.println("C");
      else if (m + f >= 30) System.out.println("D");
      else  System.out.println("F");
    }
  }
}




Measured memory_bytes: 26320
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b && a > c) {
        cout << b * c / 2 << endl;
    } else if (b > a && b > c) {
        cout << a * c / 2 << endl;
    } else {
        cout << a * b / 2 << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;
// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int A,B;
    std:cin >> A >> B;
    if((A+B)%2==1){
        std::cout << "IMPOSSIBLE" <<std::endl;
    }
    else{
        std::cout << (A+B)/2 << std::endl;
    }
    return 0;
}
 */

/*
int main(){
    int N;
    std::cin >> N;
    int a[N];
    int flg=0;
    for(int i=0; i<N; i++){
        std::cin >> a[i];
    }
    for(int i=0; i<N; i++){
        if(a[i]!=i+1){
            flg++;
        }

        if(flg==3){
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
    return 0;
}
 */

int main(){
    int N;
    long int defeat=0;
    std::cin >> N;
    long int mons[N+1];
    long int brave[N];
    for(int i=0; i<N+1; i++){
        std::cin >> mons[i];
    }
    for(int i=0; i<N; i++){
        std::cin >> brave[i];
    }
    for(int i=0; i<N; i++){
        if(brave[i]>mons[i]){
            defeat+=mons[i];
            defeat+=min(brave[i]-mons[i], mons[i+1]);
            mons[i+1]-=min(brave[i]-mons[i], mons[i+1]);
        }
        else{
            defeat+=brave[i];
        }
    }
    std::cout << defeat << std::endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define vpll vector <pll>
#define pb push_back


int main()
{
    int r;
    double pi = 3.1415926535897;
    cin>>r;
    cout<<2*pi*r;
    return 0;
}



Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,k,c,ans=0;
    cin>>n>>k;
    map <long long,long long> b;
    vector <long long> a;
    f(i,0,n){
        cin>>c;
        b[c]++;
    }
    for(auto x: b){
        a.push_back(x.second);
    }
    sort(a.begin(),a.end());
    if(a.size()<=k){
        cout<<0<<endl;
    }
    else{
        f(i,0,a.size()-k){
            ans+=a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 17664
use std::io::*;
use std::collections::{ HashMap, HashSet };

fn read(s: &mut StdinLock) -> u64 {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as u64 + a * 10)
}
fn read_line_split(s: &mut StdinLock, n: u64) -> Vec<u64> {
    (0..n).map(|_| read(s)).collect()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let n: u64 = read(&mut s);
    let a: Vec<u64> = read_line_split(&mut s, n);
    let mut cnt_map: HashMap<u64, u64> = 
        a.clone().into_iter()
            .collect::<HashSet<u64>>()
            .iter()
            .map(|&x| (x, 0))
            .collect::<HashMap<u64, u64>>();
    for i in &a {
        *cnt_map.get_mut(i).unwrap() += 1;
    }
    let total: u64 = cnt_map.iter().fold(0, |acc, x| acc+(x.1*(x.1-1))/2);
    for i in &a {
        let ans: u64 = total + 1 - cnt_map[i];
        println!("{}", ans);
    }
}

Measured memory_bytes: 18684
#include <iostream>
 
using namespace std;
 
int main(){
    int X;
    int t;
    cin >> X >> t;
    if(t >= X){
        cout << 0 << endl; //tがX以上の場合0と出力
    } else {
        cout << X - t << endl; //それ以外はXからtを引いて結果を出力
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int d[101]={0},a,m=0;
    while(cin>>a){
        d[a]++;
        m=max(m,d[a]);
    }
    for(int i=1;i<=100;i++){
        if(m==d[i])cout<<i<<endl;
    }
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef struct {
    char suit;
    int value;
} card;

void bubbleSort(card A[], const int N)
{
    int flag = 1;

    for( int i = 0; flag; ++i ){
        flag = 0;

        for( int j = N-1; i < j; --j )
            if( A[j].value < A[j-1].value ){
                swap(A[j], A[j-1]);
                flag = 1;
            }
    }
}

void selectionSort(card A[], const int N)
{
    for( int i = 0; i < N; ++i ){
        int min = i;
      
        //iより後でA[i]より最も小さい値の添字を求める
        for( int j = i; j < N; ++j )
            if( A[j].value < A[min].value )
                min = j;
       
        //iとminが異なれば交換
        if( i != min ) swap(A[i], A[min]);
    }
}

int main()
{
    //入力
    int N;
    scanf("%d%*c", &N);
    card A[N], B[N]; //A:bubbleSort, B:selectionSort
    for( int i = 0; i < N; ++i ){
        scanf("%c%d%*c", &A[i].suit, &A[i].value);
        B[i] = A[i];
    }


    bubbleSort(A, N);
    selectionSort(B, N);


    //バブルソートの結果を出力
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", A[i].suit, A[i].value);
    }
    printf("\n");
    printf("Stable\n");

    //選択ソートの結果を出力
    int flag = 1;
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", B[i].suit, B[i].value);
        if( !(B[i].suit == A[i].suit && B[i].value == A[i].value) ) flag = 0;
    }
    printf("\n");
    if( flag ) printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}

Measured memory_bytes: 1200
// https://atcoder.jp/contests/agc029/tasks/agc029_b

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    vector<int> v(n);
    // 値に対して個数を持つ。ペアとして使用する際に個数を数える。
    multiset<int> m;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m.insert(a);
    }

    // 大きい値から順に処理する
    while (!m.empty()) {
        int x = *(m.rbegin());
        // m.erase(x)にしてしまうと値xがすべて消えてしまう
        m.erase(m.find(x));
        // xより大きい２のべき乗を作成
        ll p = 1;
        while (p <= x)
            p *= 2;
        int y = p - x; // ペアとなるyは1通り
        auto itr = m.find(y);
        if (itr != m.end()) {
            m.erase(itr);
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;

const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//これを使うときにはCOMinit();を忘れずに

int main(void){
    COMinit();
    ll N, M, K; cin >> N >> M >> K;
    ll table[N];
    table[0] = 1;
    rep(i, N-1) table[i+1] = table[i]*(M-1) % MOD;
    ll ans = 0;
    for(int i = 0; i <= K; i++){
        ans = (ans + M*(table[N-i-1]*COM(N-1, i) % MOD)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int maxn = 200010;

int a[maxn];
int n;

bool play() {
	int cnt = 0, x = 0;
	for(int i = 0; i < n; ++i) if(a[i] & 1) cnt++, x=i;
	if ((n - cnt) & 1) return true;
	if (cnt > 1) return false;
	if(a[x] == 1) return false;
	a[x] -= 1;
	int g = a[0];
	for(int i = 1; i < n; ++i) g = __gcd(g, a[i]);
	for(int i = 0; i < n; ++i) a[i] /= g;
	return not play();
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	int s = 0;
	for(int i = 0; i < n; ++i) s ^= a[i] - 1;
	if(n == 1) {
		puts(s & 1 ? "First" : "Second");
	} else {
		puts(play() ? "First" : "Second");
	}
	return 0;
}


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

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

    for (int i = k; i < n; ++i) {
        if (a[i] > a[i-k]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3964
until (n = $<.gets.to_i).zero?
  a = n.times.map {$<.gets.to_i}
  k = $<.gets.to_i
  co = 0
  
  f = ->(from, to) {
    return co if from > to
    mid = (from + to) / 2
    co += 1
    return co if a[mid] == k
    (a[mid] < k) ? f.(mid + 1, to) : f.(from, mid - 1)
  }
  puts f.(0, n - 1)
end


Measured memory_bytes: 6876
#include <iostream>
#include <algorithm>
#include <limits.h>
#include <string>
using namespace std;

int main(void){
    string s;
    cin >> s;
    
    if (s.size() == 3) {
        cout << s[2] << s[1] << s[0];
    }
    else cout << s[0] << s[1];
    
    return 0;
}


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

int N, A, B;
long long h[100010];
long long l = 1, r = ~0u >> 1;

int main() {
    scanf("%d%d%d", &N, &A, &B);
    for (int i = 1; i <= N; ++i) scanf("%lld", &h[i]);
    while (l < r) {
        long long m = l + r >> 1;
        long long chk = 0;
        for (int i = 1; i <= N; ++i)
            if (h[i] > m * B) chk += (h[i] - m * B + A - B - 1) / (A - B);
        if (chk <= m) r = m; else l = m + 1;
    }
    printf("%lld\n", l);
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	int m;
	string s;
	while(cin>>n,n!=0){
		cin>>m>>s;
	int p[1000001]={0};
	int f=1;
	for(int i=0;i<m;i++){
		if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I'){
			for(int j=1;j<=f;j++)
				p[j]++;
			f++;
			i++;
		}
		else{
			f=1;
		}
	}
	
	cout<<p[n]<<endl;
	}
}

Measured memory_bytes: 6016
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (auto &&i : v) {
        scanf("%d", &i);
        i--;
    }
    ll X = 0;
    vector<ll> ans1(2*m+1), ans2(2*m+1);
    for (int i = 0; i < n-1; ++i) {
        int a = v[i], b = v[i+1];
        if(b < a) b += m;
        ans1[a+2] += 1;  ans1[b+1] -= 1; ans2[b+1] -= b-a-1;
        X += b-a;
    }
    for (int i = 0; i < 2*m; ++i) {
        ans1[i+1] += ans1[i];
    }
    for (int i = 0; i < 2*m; ++i) {
        ans1[i+1] += ans1[i] + ans2[i+1];
    }
    for (int i = 0; i < m; ++i) {
        ans1[i] += ans1[i+m];
    }
    cout << X - *max_element(ans1.begin(), ans1.end()) << "\n";
    return 0;
}


Measured memory_bytes: 3712
n, *a = map(int, open(0).read().split())

cnt4 = 0
cnt2 = 0
cnt_not = 0
for num in a:
    if num % 4 == 0:
        cnt4 += 1
    elif num % 2 != 0:
        cnt_not += 1
    else:
        cnt2 += 1
        
if 0 < cnt2:
    r = 1
else:
    r = 0

#print(cnt_not, r, cnt4)
if cnt_not + r  < cnt4 + 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14052
# 解説を参考に作成

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
def inverse(a, p):
    """逆元"""
    a_, p_ = a, p
    x, y = 1, 0
    while p_:
        t = a_ // p_
        a_ -= t * p_
        a_, p_ = p_, a_
        x -= t * y
        x, y = y, x
    x %= p
    return x


def dev_mod(a, b, mod):
    """a(= A % mod) / b を mod で割った余り"""
    return (a * inverse(b, mod)) % mod


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, As):
    mod = 10 ** 9 + 7
    As.sort()
    ans = 1
    if N == K:
        for a in As:
            ans = (ans * a) % mod
    elif As[-1] < 0 and K % 2 == 1:
        for k in range(1, K + 1):
            ans = (ans * As[- k]) % mod
    else:
        As.sort(key=abs)
        last_p = -1
        last_m = -1
        cnt_m = 0
        for k in range(1, K + 1):
            ans = (ans *  As[- k]) % mod
            if As[- k] < 0:
                last_m = As[- k]
                cnt_m += 1
            else:
                last_p = As[- k]
        if cnt_m % 2 == 1:
            mlt_p = max(As[:N - K])
            mlt_m = min(As[:N - K])
            if last_p < 0:
                ans = dev_mod(ans, last_m, mod) * mlt_p % mod
            elif mlt_m >= 0:
                ans = dev_mod(ans, last_m, mod) * mlt_p % mod
            elif mlt_p < 0:
                ans = dev_mod(ans, last_p, mod) * mlt_m % mod
            else:
                if abs(last_p * mlt_p) <= abs(last_m * mlt_m):
                    ans = dev_mod(ans, last_p, mod) * mlt_m % mod
                else:
                    ans = dev_mod(ans, last_m, mod) * mlt_p % mod
    print(ans % mod)


# def solve2(N, K, As):
#     mod = 10 ** 9 + 7
#     As.sort()
#     ans = 1
#     if N == K:
#         for a in As:
#             ans *= a
#     elif As[-1] < 0 and K % 2 == 1:
#         for k in range(1, K + 1):
#             ans *= As[- k]
#     else:
#         As.sort(key=abs)
#         last_p = None
#         last_m = None
#         cnt_m = 0
#         for k in range(1, K + 1):
#             ans *= As[- k]
#             if As[- k] < 0:
#                 last_m = As[- k]
#                 cnt_m += 1
#             else:
#                 last_p = As[- k]
#         if cnt_m % 2 == 1:
#             ans1 = ans // last_m * max(As[:N - K])
#             ans2 = ans // last_p * min(As[:N - K]) if last_p is not None else -1
#             ans = max(ans1, ans2)
#     print(ans % mod)


if __name__ == '__main__':
    N, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    # import random
    # N, K = 2 * 10 ** 5, 10 ** 5
    # As = [random.randint(- 10 ** 9, 10 ** 9) for _ in range(N)]
    solve(N, K, As)
    # solve2(N, K, As)


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// 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 );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string S, T;
    cin >> S >> T;

    ll ans = 0;
    REP(i, S.length()){
        if(S[i] != T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3900
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>

using namespace std;

int main(void){
	int n; cin >> n;
	vector < pair<int,int> > v(n);
	int res=0;
	for(int i=0; i<n;i++){
		int t; cin >> t;
		pair<int,int> p;
		p.first=i;
		p.second=t-1;
		v[i]=p;
		
		if(v[t-1].second==v[i].first && v[t-1].first==v[i].second){
			// cout << "i:" << i << " t-1:" << t-1 << endl;
			// cout << v[i].first << " " << v[i].second  << endl;
			// cout << v[t-1].first << " " << v[t-1].second  << endl;
			res++;
			v[t-1].second=-1;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = 998244353;
const ll INF = (ll)1e9+1;
const ll N = 1e5;

ll n, K;
string str;
string a[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> K >> str;
    int j=0;
    a[0] = str[0];
    for(int i=1; i<n; i++){
        if(str[i]==str[i-1]){
            a[j] += str[i];
        }
        else{
            j++;
            a[j] = str[i];
        }
    }
    char c;
    if(a[1][0]=='L'){
        c = 'R';
    }
    else c = 'L';
    for(int i=1; i<=j; i+=2){
        if(!K) break;
        a[i][0] = c;
        K--;
    }
    int cur, ans = 0;
    char pre = ']';
    for(int i=0; i<=j; i++){
        if(a[i][0]!=pre){
            ans--;
            pre = a[i][0];
        }
        ans += sz(a[i]);
    }
    cout << ans;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli k,x;
	cin>>k>>x;

	for(lli i=x-k+1;i<x+k;i++){
		cout<<i<<" ";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int n,T;
    cin>>n>>T;
    vi t(n);
    int cur=0;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
        if(t[i]>=cur)
            ans+=T;
        else{
            ans+=t[i]+T-cur;
        }
        cur=t[i]+T;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>

int main(int, char**) {
  std::array<int, 5> arr;
  int k;

  for(int i{}; i < 5; ++i) {
    std::cin >> arr[i];
  }
  std::cin >> k;

  // a b
  // a c
  // a d
  // a e
  // b c
  if(arr[1] - arr[0] > k
  || arr[2] - arr[0] > k
  || arr[3] - arr[0] > k
  || arr[4] - arr[0] > k
  || arr[2] - arr[1] > k) {
    std::cout << ":(" << std::endl;
  } else {
    std::cout << "Yay!" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
int n;
ll ans;
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  ans+=quick_pow(quick_pow(3,i)*n%MOD*(n-i+1)%MOD,MOD-2);
	printf("%lld\n",ans%MOD);
	return 0;
}

Measured memory_bytes: 128
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

const ll mod = 1000000007LL ;

int n , m ;
char s[ 3005 ] ;
ii q[ 3005 ] ;
vector< ii > v ;
int pre[ 3005 ] ;
ll C[ 3005 ][ 3005 ] ;

void init() {
  scanf( "%d%d%s" , &n , &m , s + 1 ) ;
  pre[ 0 ] = 0 ;
  for ( int i = 1 ; i <= m ; i ++ ) {
    scanf( "%d%d" , &q[ i ].first , &q[ i ].second ) ;
    if ( v.size() == 0 ) v.push_back( q[ i ] ) ;
    else {
      q[ i ].second = max( v.back().second , q[ i ].second ) ;
      if ( v.back().first < q[ i ].first ) v.push_back( q[ i ] ) ;
      else v.back().second = max( v.back().second , q[ i ].second ) ;
    }
  }
  for ( int i = 1 ; i <= n ; i ++ ) {
    if ( s[ i ] == '1' ) pre[ i ] = pre[ i - 1 ] + 1 ;
    else pre[ i ] = pre[ i - 1 ] ;
  }
}

ll dp[ 3005 ][ 3005 ] ;

void process() {
  dp[ v[ 0 ].first ][ pre[ v[ 0 ].first - 1 ] ] = 1 ;
  for ( int i = 0 ; i + 1 < (int)v.size() ; i ++ ) {
    ii nw = v[ i ] ;
    ii nxt = v[ i + 1 ] ;
    int lb = nw.first , rb = nw.second ;
    int nlb = nxt.first ;
    int emp = min( nlb - 1 , rb ) - ( lb - 1 ) ;
    for ( int j = 0 ; j < lb ; j ++ ) if ( dp[ lb ][ j ] ) {
      int ones = pre[ rb ] - j ;
      int zeros = ( rb - lb + 1 ) - ones ;
      int lbnd = max( j , emp - zeros + j ) ;
      int bnd = min( pre[ rb ] , j + emp ) ;
      int offs = 0 ;
      if ( rb < nlb ) offs = pre[ nlb - 1 ] - pre[ rb ] ;
      for ( int one = lbnd ; one <= bnd ; one ++ ) {
        dp[ nlb ][ one + offs ] = ( dp[ nlb ][ one + offs ] + dp[ lb ][ j ] * C[ emp ][ one - j ] ) % mod ;
      }
    }
  }
  ll ans = 0 ;
  ii nw = v.back() ;
  for ( int j = 0 ; j < nw.first ; j ++ ) if ( dp[ nw.first ][ j ] ) {
    int one = pre[ nw.second ] - j ;
    if ( one <= nw.second - nw.first + 1 ) {
      ans = ( ans + dp[ nw.first ][ j ] * C[ nw.second - nw.first + 1 ][ one ] ) % mod ;
    }
  }
  printf( "%lld\n" , ans ) ;
}

int main() {
  for ( int i = 0 ; i <= 3000 ; i ++ )
    C[ i ][ 0 ] = C[ i ][ i ] = 1 ;
  for ( int i = 1 ; i <= 3000 ; i ++ ) {
    for ( int j = 1 ; j < i ; j ++ ) {
      C[ i ][ j ] = ( C[ i - 1 ][ j ] + C[ i - 1 ][ j - 1 ] ) % mod ;
    }
  }
/*
#ifdef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf( "%d" , &Cases ) ;
  for ( int cases = 1 ; cases <= Cases ; cases ++ ) {
*/
    init() ;
    process() ;
/*
  }
*/
  return 0 ;
}


Measured memory_bytes: 54528
def main():
    N = int(input())
    judges = [input() for _ in range(N)]
    
    res_dic = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
    for judge in judges:
        if judge in res_dic:
            res_dic[judge] += 1
        else:
            res_dic[judge] = 0
            
    for k, v in res_dic.items():
        print("{} x {}".format(k, v))

if __name__ == '__main__':
    main()

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

#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PER(j,n,a) for (int j=n-1;j>=a;j--)
#define REP(i,a,n) for (int i=a;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define show(x) cout<<(x)<<endl
#define UM unordered_map
#define PB push_back
#define V vector
#define EPS 1e-8
typedef unsigned long ul;
typedef long long ll;
typedef string str;
/*FIN*/
const ll NINF = 1e-5;
int n,m;
str s,t;

ll cost(int i, int j) {
	if(s[i] == t[j])
		return 1LL;
	return NINF;
}

int main() {
	FAST;
	cin>>s;
	cin>>t;
	n=SZ(s), m = SZ(t);

	ll dp[n+1][m+1];
	dp[0][0] = 0;
	REP(i,0,n+1) {
		REP(j,0,m+1) {
			if(i==0 or j==0)
				dp[i][j]=0;
			else {
				dp[i][j] = cost(i-1,j-1)+dp[i-1][j-1];
				dp[i][j]=max({dp[i][j],dp[i-1][j],dp[i][j-1]});
			}
		}
	}

	str ans = "";
	int si = n, ti = m;
	while(min(si,ti) != 0) {
		if(s[si-1] == t[ti-1]) {
			si--;
			ti--;
			ans += s[si];
		} else {
			if(dp[si-1][ti] > dp[si][ti-1])
				si--;
			else
				ti--;
		}
	}
	reverse(ALL(ans));
	show(ans);
	return 0;
}



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

using namespace std;

int main(){
  int n;
  int a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  
  string s;
  cin >> s;
  
  bool result = true;
  
  if((long long)(b - a) * (long long)(d - c) > 0){
    for(int i = a; i < c; i++){
      if(s[i - 1] == '#' && s[i] == '#'){
        result = false;
        break;
      }
    }
    
    for(int i = b; i < d && result; i++){
      if(s[i - 1] == '#' && s[i] == '#'){
        result = false;
        break;
      }
    }
  }else{
    if(a > b){
      swap(a, b);
      swap(c, d);
    }
    
    result = false;
    for(int i = b - 1; i < d; i++){
      if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
        result = true;
        break;
      }
    }
    
    for(int i = a; i < c && result; i++){
      if(s[i - 1] == '#' && s[i] == '#'){
        result = false;
        break;
      }
    }
  }
  
  cout << (result ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int k;string s;

void solve(){
    cin >> k;
    cin >> s;
    int n=s.length();
    if(n<=k){
        cout << s << endl;
    }
    else{
        string v="...";
        cout << s.substr(0,k)+v << endl;
    }
}

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

Measured memory_bytes: 3660
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next(), t = sc.next();
        int n = s.length();
        System.out.println(s.equals(t.substring(0, n)) ? "Yes" : "No");
    }
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COUT(x) cout << x << endl
#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}

signed main()
{
	string S;
	cin >> S;

	int N = S.size();
	VVI dp(N+1, VI(13, 0));

	dp[0][0] = 1;
	rep(i, N) {
		int num;
		if (S[i] == '?') num = -1;
		else num = ctoi(S[i]);

		rep(j, 10) {
			if (num != -1 && num != j) continue;
			rep(k, 13) {
				dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
			}
		}

		rep(k, 13) dp[i+1][k] %= MOD;
	}

	COUT(dp[N][5]);

	return 0;
}


Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;

using namespace std;

int main(void)
{
	string S;

	cin >> S;

	/*
	int count = 0;
	bool flag = false;
	while(1){
		flag = false;
		for (int i = 0; i < S.size() - 1; i++) {
			if (S[i] != S[i + 1]) {
				S.erase(i, i + 1);
				i--;
				count += 2;
				flag = true;
				continue;
			}
		}
		if (flag == false) {
			break;
		}
	}

	cout << count << endl;
	*/

	int count = 0;
	FOR(i, 0, S.size()) {
		if (S[i] == '0') {
			count++;
		}
	}
	int ans = min(count, (int)(S.size() - count));

	cout << ans * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
ll n, A[MAXN], ans, num[MAXN], p2[MAXN];
int main(){
	FAST
	cin>>n;
	FOR(i,0,n)cin>>A[i];
	auto no=[&](){
		cout<<"-1\n";
		exit(0);
	};
	FOR(i,0,min(40ll,n-1))if(A[i]>=(1ll<<i))no();
	if(n<=40 && (1ll<<n) < A[n]) no();
	p2[0]=1; FOR(i,1,n-1) p2[i]=min(ll(2e18), p2[i-1]*2);
	DEC(i,n-1,0){
		num[i]=min(num[i+1]+A[i+1], p2[i]-A[i]);
	}
	if(n) assert(num[0]==1);
	FOR(i,1,n-1){
		num[i]=min(num[i-1]*2-A[i], num[i]);
		if(num[i]<0)no();
	}
	if(n && num[n-1]*2<A[n])no();
	FOR(i,0,n) ans += num[i]+A[i];
	cout<<ans<<'\n';
}


Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n), a(n), nt(n), na(n);
  rep(i, n) cin >> t[i];
  rep(i, n) cin >> a[i];
  nt[0] = 1;
  na[n - 1] = 1;
  repi(i, 1, n) {
    if (t[i] > t[i - 1])
      nt[i] = 1;
    else if (t[i] == t[i - 1])
      nt[i] = t[i];
    else {
      cout << 0 << endl;
      return 0;
    }
    if (a[n - 1 - i] > a[n - i])
      na[n - 1 - i] = 1;
    else if (a[n - 1 - i] == a[n - i])
      na[n - 1 - i] = a[n - 1 - i];
    else {
      cout << 0 << endl;
      return 0;
    }
  }
  vector<ll> c(n);
  rep(i, n) {
    if (nt[i] == 1 || na[i] == 1) {
      if (nt[i] == 1 && na[i] == 1) {
        if (t[i] == a[i])
          c[i] = 1;
        else {
          cout << 0 << endl;
          return 0;
        }
      } else if (nt[i] == 1 && na[i] != 1) {
        if (t[i] <= a[i])
          c[i] = 1;
        else {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (a[i] <= t[i])
          c[i] = 1;
        else {
          cout << 0 << endl;
          return 0;
        }
      }
    } else {
      c[i] = min(nt[i], na[i]);
    }
  }
  ll ans = 1;
  rep(i, n) ans = ans * c[i] % mod;
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int one, zero, minus, cards;
  cin >> one >> zero >> minus >> cards;
  int64_t ans = 0;
  ans += (cards < one ? cards : one);
  cards -= one;
  if (cards > 0)
  {
    cards -= zero;
  }
  if (cards > 0)
  {
    ans -= cards;
  }
  cout << ans << endl;
}


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

int main(){
    vector<int> d(5);
    int k;
    cin >> d[0] >> d[1] >> d[2] >> d[3] >> d[4] >> k;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            if(abs(d[j]-d[i]) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}

Measured memory_bytes: 256
# AOJ 1208
import sys
import math

def rational(p, n):
    rt = math.sqrt(p)
    k = math.floor(rt)
    mi = n
    mx = n
    mikk = 0
    mibb = 0
    mxkk = 0
    mxbb = 0
    for i in range(1, n+1):
        a = (rt - k) * i
        b = math.floor(a)
        if mi > a - b and k * i + b <= n:
            mi = a - b
            mikk = i
            mibb = b
        if mx > b + 1 - a and k * i + (b + 1) <= n:
            mx = b + 1 - a
            mxkk = i
            mxbb = b
    print("{}/{} {}/{}".format(k * mxkk + (mxbb + 1), mxkk, k * mikk + mibb, mikk))
    
while True:
    line = input().split()
    p, n = map(int, list(line))
    if p == 0 and n == 0:
        break
    rational(p, n)


Measured memory_bytes: 5680