akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;


int x[11][11];
bool digi(int x){
    for(int i = 1;i*i<=x;++i){
        if(x%i==0){
            if(x/i==i) return true;
        }
    }
    return false;
}
int main(){
    int n,d;
    cin >> n >>d;
    rep(i,n){
        rep(j,d){
            cin >> x[i][j];
        }
    }
    int cnt = 0;
    rep(i,n-1){
        for(int k =i+1;k<n;++k){
        int y = 0;
        rep(j,d){
            y+=(x[i][j]-x[k][j])*(x[i][j]-x[k][j]);
        }
        if(digi(y)) cnt++;
        }
        
    }
    cout << cnt <<endl;
}

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

int main() {
  int n;
  cin >> n;
  if(n < 3){
    cout << 0 << endl;
    return(0);
  }
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  ll cnt=0;
  vector<ll> t(3);
  for(ll i=0;i<n;i++){
    t[0] = a[i];
    for(ll j=i+1;j<n;j++){
      t[1] = a[j];
      for(ll k=j+1;k<n;k++){
        t[2] = a[k];
        //cout << t[0] << " " << t[1] << " " << t[2] << endl; 
        if(t[0] != t[1] && t[0] != t[2] && t[1] != t[2] && abs(t[1]-t[2]) < t[0] && t[0] < t[1] + t[2] ){
          cnt++;
          //cout << i << " " << j << " " << k << endl;
        }
      }
    }
  }
  
  cout << cnt << endl;
  
  return(0);
}

Measured memory_bytes: 3628
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
vector<ll> vis(N);
ll p[2][N];
vector<ll> g[N];
ll y;
ll dfs(ll x, ll l = 0)
{
    vis[x] = 1;
    if (g[x].size() == 1)
        p[y][x] = l;
    for (ll e : g[x])
        if (!vis[e])
            dfs(e, l + 1);
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    for (ll i = 0; i < 2; i++)
        for (ll j = 0; j < N; j++)
            p[i][j] = -1;
    ll n, u, v, a, b;
    cin >> n >> u >> v;
    for (ll i = 0; i < n - 1; i++)
        cin >> a >> b, g[a].push_back(b), g[b].push_back(a);
    dfs(u);
    y = 1;
    vis.clear();
    vis.resize(N);
    dfs(v);
    ll ans = 0;
    for (ll i = 1; i < N; i++)
        if (p[0][i] != -1)
            if (p[0][i] < p[1][i])
                ans = max(ans, p[1][i] - 1);
    cout << ans;
    return 0;
}

Measured memory_bytes: 52992
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:24:31 2017

@author: Kanoh
"""
import numpy as np
N = int(raw_input())#標準入力
A = raw_input()#標準入力
A_split=A.split(" ")
A_int=np.zeros((N))

for i in range(int(N)):
    A_int[i]=int(A_split[i])

counter=0
checker=0
while 1 :
    for i in range(N):
        if((A_int[i]%2)!=1) and((A_int[i])>1):
            A_int[i]=A_int[i]/2
        else:
            checker=1
    if(checker==1):
        break
    else:
        counter=counter+1
    
print counter

Measured memory_bytes: 20332
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n);
	vector<pii> v(n);
	REP(i, n) {
	
		cin >> a[i];
		v[i] = { a[i],i };
	}
	sort(ALL(v));
	vi ans(n);
	REP(i, n) {
		if (i < n / 2) {
			ans[v[i].second] = v[n / 2].first;
		}
		else {
			ans[v[i].second] = v[n / 2 - 1].first;
		}
	}
	REP(i, n)cout << ans[i] << endl;
}


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

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

int main(){
    int n; cin >> n;
    int a[12]; rep(i,n) cin >> a[i];
    int max = 0,idx = 0;;
    rep(i,n) if(max < a[i]) {max = a[i]; idx = i;}
    int sum = 0;
    rep(i,n) if(i != idx) sum += a[i];
    if(max < sum) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

public class Program
{
  public static void Main()
  {
    var s = Console.ReadLine();
    var t = Console.ReadLine();

    var posList = Enumerable.Range(0, 'z' - 'a' + 1)
      						.Select(x => new List<int>())
      						.ToList();
    
    var text = s + s;
    for (var index = 0; index < text.Length; index++)
    {
      posList[text[index] - 'a'].Add(index);
    }

    long result = 0;

    foreach (var c in t)
    {
      var list = posList[c - 'a'];

      if (!list.Any())
      {
        result = -1;
        break;
      }

      var current = (int)(result % s.Length);
      var listIndex = list.BinarySearch(current);
      
      if (listIndex < 0)
      {
        listIndex = ~listIndex;
      }

      var next = list[listIndex];
      result += next - current  + 1;
    }

    Console.WriteLine(result);
  }
}

Measured memory_bytes: 20448
#include <iostream>
#include <iomanip>
#include <math.h>


void add(int n, int len, int *t, int *p) {
  // add 1/n to p;
  t[0] = 1 / n;
  int _t = 1 % n;

  // calculate 1 / n, and store into *t
  for (int i = 1; i < len; i ++) {
    _t *= 10;
    t[i] = _t / n;
    _t %= n;
  }

  // add 1 / n to *p
  for (int i = len - 1; i > 0; i --) {
    p[i] += t[i];
    p[i - 1] += p[i] / 10;
    p[i] %= 10;
  }
  p[0] += t[0];
}


void div(int n, int len, int *t, int *p) {
  t[0] = p[0] / n;
  int _t = p[0] % n;
  for (int i = 1; i < len; i ++) {
    _t = _t * 10 + p[i];
    t[i] = _t / n;
    _t %= n;
  }
  for (int i = 0; i < len; i ++)
    p[i] = t[i];
}


int main() {
  int n, k, m, r;
  std::cout << std::fixed;
  while (1) {
    std::cin >> n >> k >> m >> r;
    if (n == 0 && k == 0 && m == 0 && r == 0) break;
    int len = r + 10;
    int prob[len], temp[len];
    for (int i = 0; i < len; i ++) prob[i] = 0;


    if (m == 1) {
      for (int i = 1; i < n; i ++) add(i, len, temp, prob);
      div(n, len, temp, prob);
    }

    add(n, len, temp, prob);

    std::cout << prob[0] << ".";
    for (int i = 1; i <= r; i ++)
      std::cout << prob[i];
    std::cout << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
const long long INF = 1LL << 60;
const int inf = 1e9;
ll mod = 1e9 + 7;

int main()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.size() <= k)
    {
        cout << s << endl;
    }
    else
    {
        rep(i, k) cout << s[i];
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
n = int(input())
lens = [False for i in range(n + 1)]

for i in range(n):
    p = int(input())
    lens[p] = True
    lens[p - 1] = False

ps = []
for i in range(n + 1):
    if lens[i]:
        ps.append(i)

ps.sort()
x = 0
temp = 0
for i in ps:
    x = max(i - temp, x)
    temp = i
print(n - x)

Measured memory_bytes: 12584
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

const MODULO: usize = 1_000_000_007;

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let s: Vec<usize> = vec(n, |_| scan(tokens));
    let t: Vec<usize> = vec(m, |_| scan(tokens));
    let mut dp: Vec<Vec<usize>> = vec![vec![0; m + 1]; n + 1];
    dp[0][0] = 1;
    for j in 0..m {
        dp[0][j + 1] = 1;
    }
    for i in 0..n {
        dp[i + 1][0] = 1;
        for j in 0..m {
            dp[i + 1][j + 1] = if s[i] == t[j] {
                (dp[i + 1][j] + dp[i][j + 1]) % MODULO
            } else {
                (dp[i + 1][j] + dp[i][j + 1] + MODULO - dp[i][j]) % MODULO
            };
        }
    }
    println!("{}", dp[n][m]);
}


Measured memory_bytes: 45308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, K;
  cin >> N >> K;
  
  int sum = 1;

  for (int i = 0; i < N; i++){
    
    int a = 1;
    a *= 2;
    sum *= a;
    
    if(sum > K){
      
     for (int j = 0; j < (N - i - 1); i++){
    
     sum += K;
     }
    }
    
  }
    cout << sum << endl;
}


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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n-1;i++){
        int x[26]={0};
        int y[26]={0};
        int hukumu=0;
        for(int j=0;j<=i;j++){
            x[s[j]-'a']++;
        }
        for(int j=i+1;j<n;j++){
            y[s[j]-'a']++;
        }

        for(int j=0;j<26;j++){
            if(x[j]>0&&y[j]>0)hukumu++;
        }
        ans=max(ans,hukumu);
    }
    cout<<ans<<endl;


    return 0;
}




Measured memory_bytes: 256
from math import sqrt
n = int(input())

for i in range(n):
    l = input()
    x1,y1,x2,y2,x3,y3=map(float,l.split(' '))
    a_2 = (x1 - x2)**2 + (y1 - y2)**2
    b_2 = (x2 - x3)**2 + (y2 - y3)**2
    c_2 = (x3 - x1)**2 + (y3 - y1)**2
    cos_a_2 = (b_2 + c_2 - a_2)**2/(4* b_2 * c_2)
    sin_a_2 = 1 - cos_a_2
    r = round(sqrt(a_2/sin_a_2)/2,3)
    a = (x1**2 - x3**2 + y1**2 - y3**2)*(x2 - x1)
    b = (x1**2 - x2**2 + y1**2 - y2**2)*(x3 - x1)
    c = (y2 - y1)*(x3 - x1)
    d = (y3 - y1)*(x2 - x1)
    py = round((a-b)/(c-d)/2,3) + 0
    a = (x1**2 - x3**2 + y1**2 - y3**2)*(y2 - y1)
    b = (x1**2 - x2**2 + y1**2 - y2**2)*(y3 - y1)
    c = (x2 - x1)*(y3 - y1)
    d = (x3 - x1)*(y2 - y1)
    px = round((a-b)/(c-d)/2,3) + 0
    print('%.3f %.3f %.3f' %(px, py, r))

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

int main(void) {

	int K, X;

	cin >> K >> X;

	int sign = 0;
	for (int i = max(-1000000, X - K + 1); i <= min(1000000, X + K - 1); i++) {
		if (sign == 0) { sign = 1; }
		else { cout << " ";  }
		cout << i;
	}cout << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

fn main() {
    let inf = 1000001;
    let stdin = io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();
    buf.clear();
    stdin.read_line(&mut buf).unwrap();

    let xs: Vec<i64> = buf.trim().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    let min = xs.iter().fold(inf, |x, &c| cmp::min(x, c));
    let max = xs.iter().fold(-inf, |x, &c| cmp::max(x, c));
    let sum = xs.iter().fold(0i64, |x, &c| x + c);
    println!("{} {} {}", min, max, sum);
}

Measured memory_bytes: 5056
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool simulate(
	char chT, char chA, int dxT, int dyT, 
	int H, int W, int N, int sx, int sy, 
	const string &T, const string &A)
{
	int dxA = -dxT;
	int dyA = -dyT;

	for (int i = 0; i < N; ++i) {
		if (T[i] == chT) {
			sx += dxT;
			sy += dyT;
			if (sx < 1 || W < sx || sy < 1 || H < sy) {
				return true;
			}
		}
		if (A[i] == chA) {
			sx = max(1, min(W, sx + dxA));
			sy = max(1, min(H, sy + dyA));
		}
	}
	return false;
}

string solve(int H, int W, int N, int sr, int sc, const string &S, const string &T)
{
	if (simulate('L', 'R', -1, 0, H, W, N, sc, sr, S, T)) {
		return "NO";
	}
	if (simulate('R', 'L', +1, 0, H, W, N, sc, sr, S, T)) {
		return "NO";
	}
	if (simulate('U', 'D', 0, -1, H, W, N, sc, sr, S, T)) {
		return "NO";
	}
	if (simulate('D', 'U', 0, +1, H, W, N, sc, sr, S, T)) {
		return "NO";
	}
	return "YES";
}

int main()
{
	int H, W, N;
	int sr, sc;
	string S, T;
	cin >> H >> W >> N;
	cin >> sr >> sc;
	cin >> S >> T;
	cout << solve(H, W, N, sr, sc, S, T) << endl;
}


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

int main() {
    int N, l, r, ans = 0;
    cin >> N;
    rep(i, N){
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<setprecision(10)<<fixed;
	int n, m, c, b[30], a;
	cin>>n>>m>>c;
	REP(i, m){
		cin>>b[i];
	}
	int ans=0;
	REP(i, n){
		int tmp=0;
		REP(j, m){
			cin>>a;
			tmp+=a*b[j];
		}
		if(tmp+c>0){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
N = int(input())
#A,B= map(int,input().split())
D =list(map(int,input().split()))
# [list(map(int,input().split())) for i in range(N)]
ans = 0
for i,d in enumerate(D):
    for j in range(i+1,len(D)):
        ans += d*D[j]
print(ans)


Measured memory_bytes: 38896
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()

  a=list(set(s))

  ans=[]
  for x in a:
    c=0
    t=list(s)
    while True:
      if len(set(t))==1:
        break

      for i in range(len(t)-1):
        if t[i]==x or t[i+1]==x:
          t[i]=x
      t=t[:-1]

      c+=1

    ans.append(c)

  return min(ans)

print(main())


Measured memory_bytes: 6700
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    FOR(i, 1, 10) FOR(j, 1, 10){
        if(i * j == N){
            Out("Yes");
            return 0;
        }
    }
    Out("No");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct node {
    int a, b;
} a[2000010];
int n, m, k;
set <int> Set;
char s[1000010];
int main() {
    scanf("%d%d%d", &n, &m, &k);
    scanf("%s", s);
    reverse(s, s + n);
    for (int i = 0; i < n; i++) a[i].a = s[i] - '0';
    scanf("%s", s);
    reverse(s, s + m);
    for (int i = 0; i < m; i++) a[i].b = s[i] - '0';
    for (int i = 0; i < max(n, m); i++) if(a[i].a ^ a[i].b) Set.insert(i);
    Set.insert(1e9);
    for (int i = n; i --> 0; ) {
        if (a[i].a & a[i].b) {
            int rest = k, now = i;
            a[i].a = a[i].b = 0;
            while (rest) {
                int nxt = *Set.upper_bound(now);
                if (rest + now < nxt) {
                    a[now].a = a[now].b = 0;
                    now += rest;
                    rest = 0;
                    a[now].a = a[now].b = 1;
                }
                else {
                    a[now].a = a[now].b = 0;
                    rest -= nxt - now;
                    now = nxt;
                    int A = 1, B = 1;
                    while ((A && a[now].a) || (B && a[now].b)) {
                        // cerr << now << ' ' << A << ' ' << B << endl;
                        if (a[now].a ^ a[now].b) Set.erase(now);
                        if (A && a[now].a) a[now].a = 0, A = 1;
                        else a[now].a |= A, A = 0;
                        if (B && a[now].b) a[now].b = 0, B = 1;
                        else a[now].b |= B, B = 0;
                        if (a[now].a ^ a[now].b) Set.insert(now);
                        now++;
                    }
                    if (a[now].a ^ a[now].b) Set.erase(now);
                    a[now].a |= A, a[now].b |= B;
                    if (a[now].a ^ a[now].b) Set.insert(now);
                    if (!(a[now].a && a[now].b)) rest = 0;
                }
                // int tag = 0;
                // for (int i = 2000000; i --> 0; ) if (tag |= a[i].a) putc('0' + a[i].a, stderr);
                // fputs("", stderr);
                // tag = 0;
                // for (int i = 2000000; i --> 0; ) if (tag |= a[i].b) putc('0' + a[i].b, stderr);
                // fputs("", stderr);
                // cerr << rest << endl;
            }
        }
    }
    int tag = 0;
    for (int i = 2000000; i --> 0; ) if (tag |= a[i].a) putchar('0' + a[i].a);
    puts("");
    tag = 0;
    for (int i = 2000000; i --> 0; ) if (tag |= a[i].b) putchar('0' + a[i].b);
    puts("");
    return 0;
}

Measured memory_bytes: 54144
#include<bits/stdc++.h>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define vi vector<int>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
#define watch(x) cout << (#x) << " is " << (x) << endl
//#define endl "\n"
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    //memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
map<pll,ll> edgeweight;
struct node
{
	vll adj;
    ll colour;
    ll subtree_size;
};
void dfs(node N[], bool vis[], ll i)
{
    vis[i]=true;
    N[i].subtree_size=1;
    for(auto x: N[i].adj)
    {
        if(!vis[x])
        {
            dfs(N,vis,x);
            N[i].subtree_size+=N[x].subtree_size;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    set<string> s;
    REP(i,0,n)
    {
        string a;
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<"\n";
    return 0;
}


Measured memory_bytes: 19288
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int n, m;

const int MAXN = 100100;

map<int, vector<int> > g[MAXN];
bool processed[MAXN];
priority_queue<pair<int, pair<int, int> > > qq;
set<pair<int, int> > expanded;

int main() {
	cin >> n >> m;
	int p, q, c;
	FOR (i, m) {
		cin >> p >> q >> c;
		p--;
		q--;
		g[p][c].pb(q);
		g[q][c].pb(p);
	}
	SET(processed, 0);
	qq.push(make_pair(0, make_pair(0, -1)));
	expanded.clear();
	int ret = -1;
	while (true) {
		int cost, v, company;
		while (!qq.empty()) {
			pair<int, pair<int, int> > pp = qq.top();
			cost = pp.first;
			v = pp.second.first;
			company = pp.second.second;
			if (!expanded.count(make_pair(v, company)))
				break;
			qq.pop();
		}
		if (qq.empty())
			break;
		qq.pop();
		if (v == n - 1) {
			ret = -cost;
			break;
		}
		expanded.insert(make_pair(v, company));
		if (!processed[v]) {
			processed[v] = true;
			for (map<int, vector<int> >::iterator it = g[v].begin(); it != g[v].end(); it++) {
				vector<int> vv = it->second;
				FOR (i, vv.sz)
					qq.push(make_pair(cost - 1, make_pair(vv[i], it->first)));
			}
		}
		vector<int> vv = g[v][company];
		FOR (i, vv.sz)
			qq.push(make_pair(cost, make_pair(vv[i], company)));
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 67584
#include<bits/stdc++.h>
using namespace std;
int main(){
	
  int N,K;
  cin >> N >> K;
  int inp[N];
  for(int i=0;i<N;i++){
    cin >> inp[i];
  }
  int dp[K+1];
  int res[N][K+1];
  for(int j=0;j<=K;j++){
    bool flag = false;
    for(int i=0;i<N;i++){
      
      if(j<inp[i]) res[i][j] = 0;
      else{
        if(dp[j-inp[i]]==0) {
          flag=true;
          break;
        }
        
        
      }
      
    }
    if(flag==false) dp[j] = 0;
    else dp[j] =1;
  }
  if(dp[K]==1) cout<< "First";
  else cout<< "Second";
  return 0;
  
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  vector<bool> f(b, true);
  for(int i = 1;;++i) {
    if(!f[a*i%b]) {
      cout << "NO" << endl;
      return 0;
    }
    if(a*i%b==c) {
      cout << "YES" << endl;
      return 0;
    }
    f[a*i%b] = false;
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::collections::{HashSet, HashMap};
use std::cmp::{min,max};
use std::io;
use std::str;
 
struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: io::BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Scanner { reader : reader, buf_str: vec![], buf_iter: "".split_whitespace() }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

const MD : u32 = 1000000007;

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let ss : String = scan.token();
    let s : Vec<char> = ss.chars().collect();
    let mut dp1 = vec![0 as u32; s.len() + 3];
    let mut dp2 = vec![0 as u32; s.len() + 3];
    dp2[0] = 1;
    for i in 0..s.len() {
        if s[i] == '1' {
            dp1[i + 1] = (dp1[i] * 3 + dp2[i]) % MD;
            dp2[i + 1] = (dp2[i] * 2) % MD;
        } else {
            dp1[i + 1] = (dp1[i] * 3) % MD;
            dp2[i + 1] = dp2[i];
        }
    }
    writeln!(out, "{}", (dp1[s.len()] + dp2[s.len()]) % MD).ok();
}


fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    int f = 0;
    for(int i=0;i<=x;i++){
        int a = i;
        int b = x-i;
        if(a*2 + b*4 == y){ 
            f = 1;
            break;
        }
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3548
#include<stdio.h>
#define MAX 60001
int pri[MAX];
void prime()
{
    int i,j;

    for(i=3;i<MAX;i+=2) pri[i]=1;
    pri[0]=pri[1]=0;
    pri[2]=1;

    for(i=3;i<MAX;i+=2) if(pri[i]) for(j=i+i;j<MAX;j+=i) pri[j]=0;
}

int main(){
    int n,i;
    prime();
    while(scanf("%d",&n)!=EOF){
        for(i=n-1;pri[i]==0;i--);
        printf("%d ",i);
        for(i=n+1;pri[i]==0;i++);
        printf("%d\n",i);
    }
    return 0;
}

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

long long MAX_V = 105;
long long INF = 1e12;

// d[u][v] := 辺 (u, v) のコスト (辺が存在しない場合 INF, d[i][i] := 0 )
vector<vector<long long>> d(MAX_V, vector<long long>(MAX_V));
long long v;


void warshall_floyd() {
    for (long long k = 0; k < v; k++) {
        for (long long i = 0; i < v; i++) {
            for (long long j = 0; j < v; j++) {
                if (d[i][k] == INF || d[k][j] == INF) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
// d[i][i] < 0 なる i があれば負の閉路がある


int main() {
    long long e;
    cin >> v >> e;

    for (long long i = 0; i < v; i++) {
        for (long long j = 0; j < v; j++) {
            d[i][j] = INF;
        }
    }

    for (long long i = 0; i < e; i++) {
        long long s, t, c;
        cin >> s >> t >> c;
        d[s][t] = c;
    }

    for (long long i = 0; i < v; i++) {
        d[i][i] = 0;
    }

    warshall_floyd();

    for (long long i = 0; i < v; i++) {
        if (d[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    for (long long i = 0; i < v; i++) {
        for (long long j = 0; j < v; j++) {
            if (j > 0) cout << ' ';
            if (d[i][j] == INF) cout << "INF";
            else cout << d[i][j];
        }
        cout << endl;
    }
}




Measured memory_bytes: 3244
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.next()),A[]=new int[n];
		for(int i=0;i<n;i++)A[i]=Integer.parseInt(in.next());
		int m=Integer.parseInt(in.next()),B[]=new int[m];
		for(int i=0;i<m;i++)B[i]=Integer.parseInt(in.next());
		
		int size=Math.min(n, m);
		int isbig=0;
		
		for(int i=0;i<size;i++) {
			if(A[i]!=B[i]) {
				if(A[i]>B[i])isbig=-1;
				else if(A[i]<B[i])isbig=1;
				break;
			}
		}
		
		if(isbig==1 ||(isbig == 0 && n<m))System.out.println(1);
		else System.out.println(0);
	}

}



Measured memory_bytes: 31728
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  map<int,int> m;
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  rep(i,n) {
    if(m[a[i]]!=0) {
      cout << "NO" << endl;
      return 0;
    }
    m[a[i]]++;
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 10368
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, K;

int main()
{
  scanf( "%d%d", &N, &K );

  printf( "%d\n", K>1?N-K:0 );

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

 
int vector_finder(std::vector<int> vec, int number) {
  size_t index = std::distance( vec.begin(), std::find(vec.begin(), vec.end(), number) );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
 
int main()
{
	string S;

	cin >> S;

	int N = S.size();

	

	if(N==1){
		cout << 0 << endl;
	}else{
		int countg = 0;
		int countk = 0;
		REP(i, N)
		{
			if(i%2==0){
				if(S[i]!='1'){
					countg += 1;
				}
			}else{
				if(S[i]!='0'){
					countg += 1;
				}
			}
		}
		REP(i,N){
			if(i%2==0){
				if(S[i]!='0'){
					countk += 1;
				}
			}else{
				if(S[i]!='1'){
					countk+= 1;
				}
			}
		}

		cout << min(countg, countk) << endl;


	}

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  std::vector<int> seq(n);
  for (auto& i : seq) std::cin >> i;
  long long min = std::numeric_limits<long long>::max() / 2;
  for (int first = -1; first <= 1; first += 2) {
    long long sign = first;
    long long sum = 0, count = 0;
    for (auto i : seq) {
      sum += i;
      if (sum * sign <= 0) {
        count += std::abs(sum - sign);
        sum = sign;
      }
      sign *= -1;
    }
    min = std::min(min, count);
  }
  std::cout << min << std::endl;
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        Solve(4, 4);
        Solve(0, 0);
        Solve(1000000000, 0);
        Solve(0, 1000000000);
        Console.WriteLine(Solve(0, 0));
    }

    public static string Solve(ulong a, ulong b)
    {
        checked
        {
            List<string> seq = new List<string>();
            var xptr = 0;
            var yptr = 1;
            var resptr = 2;

            var zeroPtr = 99999;
            var onePtr = 3;

            ulong[] arr = new ulong[200000];
            arr[xptr] = (ulong)a;
            arr[yptr] = (ulong)b;

            void CompAssign(int i, int j, int k) { arr[k] = arr[i] < arr[j] ? 1UL : 0UL; seq.Add($"< {i} {j} {k}"); }
            void AddAssign(int i, int j, int k) { arr[k] = arr[i] + arr[j]; seq.Add($"+ {i} {j} {k}"); }

            void DoubleAssign(int numPtr, int destPtr) => AddAssign(numPtr, numPtr, destPtr);

            AddAssign(xptr, yptr, onePtr);
            CompAssign(resptr, onePtr, onePtr);

            //d     d+30   d+60
            //| data | bulk |
            void GenBytes(int numptr, int destptr)
            {
                AddAssign(numptr, onePtr, numptr);
                for (int t = destptr; t < destptr + 30; t++)
                {
                    var p = t + 1;
                    DoubleAssign(p, p + 1);
                    var q = p + 1;
                    AddAssign(q, onePtr, q);
                    for (int j = q; j < destptr + 31; j++)
                        DoubleAssign(j, j + 1);
                    CompAssign(destptr + 31, numptr, t);
                    DoubleAssign(p, p + 1);
                    AddAssign(q, t, q);
                }
            }

            var aBinOffset = 9;
            var bBinOffset = 50;
            GenBytes(0, aBinOffset);
            GenBytes(1, bBinOffset);

            void And(int aptr, int bptr, int destptr)
            {
                var tmpPtr = 5;
                AddAssign(aptr, bptr, tmpPtr);
                CompAssign(onePtr, tmpPtr, destptr);
            }

            for (int t = 0; t < 60; t++)
            {
                DoubleAssign(resptr, resptr);
                for (int s = 0; s < t; s++)
                {
                    if (t - 31 < s && s < 30)
                    {
                        //bitwise-and
                        And(aBinOffset + t - 1 - s, bBinOffset + s, 6);
                        AddAssign(resptr, 6, resptr);
                    }
                }
            }

            if (a * b != arr[resptr]) throw new Exception();

            return $"{seq.Count}\n{string.Join("\n", seq)}";
        }
    }
}


Measured memory_bytes: 27836
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
using namespace std;


int main() {
	int N, M;

	cin >> N >> M;

	int left = 1, right = N;

	vector<int> L(M), R(M);

	for (int i = 0; i < M; i++) {
		cin >> L[i];
		cin >> R[i];

		if (L[i] <= left) {
			if (R[i] < left) {
				right = -1;
				left = 0;
				break;
			}
			else if (R[i] < right) {
				right = R[i];
			}
			else {
				;//更新なし
			}

		}
		else {
			if (L[i] > right) {
				right = -1;
				left = 0;
				break;
			}
			else if (R[i] < right) {
				right = R[i];
				left = L[i];
			}
			else {
				left = L[i];
			}
		}
	}

	cout << right - left + 1 << endl;

}




Measured memory_bytes: 1024
// Last Change: 03/22/2020 21:11:56.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  auto isPalindrome = [](const string text) {
    size_t fullSize = text.size();
    size_t halfSize = fullSize / 2;
    for (size_t i = 0; i < halfSize; ++i) {
      if (text[i] != text[fullSize - 1 - i]) {
        return false;
      }
    }
    return true;
  };

  string ipt;
  cin >> ipt;
  size_t halfSize = ipt.size() / 2;
  if (isPalindrome(ipt) and isPalindrome(ipt.substr(0, halfSize))
      and isPalindrome(ipt.substr(halfSize + 1, halfSize))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int, int > Pi;
 
const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};
void bfs(vector< vector< int > >& sum, int x, int y)
{
  queue< Pi > que;
  que.push({x, y});
  sum[y][x] = 1;
  while(!que.empty()) {
    Pi p = que.front(); que.pop();
    for(int i = 0; i < 4; i++) {
      int ny = p.second + dy[i], nx = p.first + dx[i];
      if(ny >= 0 && nx >= 0 && ny < (int)sum.size() - 1 && nx < (int)sum[0].size() - 1) {
        if(sum[ny][nx] == 0) {
          sum[ny][nx] = 1;
          que.push({nx, ny});
        }
      }
    }
  }
}
 
int main()
{
  int W, H, N, X1[1000], Y1[1000], X2[1000], Y2[1000];
  vector< int > xs, ys;
  
  while(cin >> W >> H, W) {
    cin >> N;
    for(int i = 0; i < N; i++) {
      cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
      for(int j = -1; j < 1; j++) {
        if(0 <= X1[i] + j && X1[i] + j <= W) xs.push_back(X1[i] + j);
        if(0 <= X2[i] + j && X2[i] + j <= W) xs.push_back(X2[i] + j);
        if(0 <= Y1[i] + j && Y1[i] + j <= H) ys.push_back(Y1[i] + j);
        if(0 <= Y2[i] + j && Y2[i] + j <= H) ys.push_back(Y2[i] + j);
      }
    }
    xs.push_back(0);
    xs.push_back(W);
    ys.push_back(0);
    ys.push_back(H);
  
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
  
    W = lower_bound(xs.begin(), xs.end(), W) - xs.begin();
    H = lower_bound(ys.begin(), ys.end(), H) - ys.begin();
    for(int i = 0; i < N; i++) {
      X1[i] = lower_bound(xs.begin(), xs.end(), X1[i]) - xs.begin();
      X2[i] = lower_bound(xs.begin(), xs.end(), X2[i]) - xs.begin();
      Y1[i] = lower_bound(ys.begin(), ys.end(), Y1[i]) - ys.begin();
      Y2[i] = lower_bound(ys.begin(), ys.end(), Y2[i]) - ys.begin();
    }
  
    vector< vector< int > > sum(H + 1, vector< int >(W + 1, 0));
    for(int i = 0; i < N; i++) {
      ++sum[Y1[i]][X1[i]];
      --sum[Y1[i]][X2[i]];
      --sum[Y2[i]][X1[i]];
      ++sum[Y2[i]][X2[i]];
    }
  
    for(int i = 0; i <= H; i++) {
      for(int j = 1; j <= W; j++) {
        sum[i][j] += sum[i][j - 1];
      }
    }
  
    for(int j = 0; j <= W; j++) {
      for(int i = 1; i <= H; i++) {
        sum[i][j] += sum[i - 1][j];
      }
    }
  
    int all = 0;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(sum[i][j] == 0) {
          ++all;
          bfs(sum, j, i);
        }
      }
    }
    cout << all << endl;
    ys.clear(), xs.clear();
  }
}

Measured memory_bytes: 6796
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n, m, R;
int r[9];
int e[201][201];

int main(int argc, char const* argv[])
{
	cin >> n >> m >> R;
	for(int i = 0; i < R; i++){
			cin >> r[i];
	}
	for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++)e[i][j] = inf;
			e[i][i] = 0;
	}
	for(int i = 0; i < m; i++){
			int a, b, c;
			cin >> a >> b >> c;
			a--; b--;
			e[a][b] = c;
			e[b][a] = c;
	}
	for(int k = 0; k < n; k++){
			for(int i = 0; i < n; i++){
					for(int j = 0; j < n; j++){
							e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
					}
			}
	}
	vector<int> vec;
	for(int i = 0; i < R; i++)vec.pb(i);
	int res = inf;
	do{
			int tmp = 0;
			for(auto itr = vec.begin() + 1; itr != vec.end(); ++itr){
					tmp += e[r[(*(itr - 1))]-1][r[(*itr)]-1];
			}
			res = min(res, tmp);
	}while(next_permutation(vec.begin(), vec.end()));
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    r = A[0]
    for i in range(1, N//2):
        r += 2 * A[i]
    if N % 2 == 1:
        r += A[N//2]
    return r
print(main())


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

long N, ans = 1;
vector<long> A;

int main(void) {

    cin >> N; A.resize(N);
    for (auto &e: A) cin >> e;

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

    for (auto e: A) {
        if (e != 0 && ans > 1000000000000000000 / e) {
            ans = -1;
            break;
        }
        ans *= e;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> div(n+1, 0);
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j += i){
            div[j]++;
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        ans += i * div[i];
    }
    cout << ans << endl;
}

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

using namespace std;

#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back

int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);

    int a,b,c;

    cin>>a>>b>>c;
    cout<<max(c-(a-b),0);
}


Measured memory_bytes: 256
n=int(input())
a = [int(input()) for _ in range(n)]
nex=[]
k=1
for i in range(len(a)):
    nex.append(a[k-1])
    k=nex[-1]
    if nex[-1]==2:
        print(len(nex))
        break
    elif len(nex)>=n:print(-1)
    else:pass

Measured memory_bytes: 7852
N, M, K = map(int, input().split())
flag = False

for j in range(M + 1):
    for i in range(N + 1):
        t = i * j + (N - i) * (M - j)
        area = M * N - t
        # area = (M - j) * i + (N - i) * j
        if area == K:
            flag = True

if flag:
    print('Yes')
else:
    print("No")

Measured memory_bytes: 9128
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,i,t;
  string s;
  cin >> n >> s;
  for(i=0;i<s.size();i++){
    t=(int)s[i]+n;
    if(t-(int)'A'>=26)
      t-=26;
    cout << (char)t;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,a,ans=0;
	cin>>n;
	int g=n;
	while(n--)
	{
		cin>>a;
		for(int i=2;i<=sqrt(a);i+=(i==2?1:2))
		{
			if(a%i==0)
			{
				ans++;break;
			}
		}
	}
	cout<<g-ans<<endl;
	return 0;
 } 


Measured memory_bytes: 3088