akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#define N 200002
using namespace std;
int n,i,p[N],a[N],q[N],s[N],t[2][N*4];
int read()
{
	char c=getchar();
	int w=0;
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w;
}
void build(int p,int l,int r)
{
	t[1][p]=-1<<30;
	if(l==r) return;
	int mid=(l+r)/2;
	build(p*2,l,mid);build(p*2+1,mid+1,r);
}
void change(int op,int p,int l,int r,int x,int v)
{
	if(l==r){
		t[op][p]=v;
		return;
	}
	int mid=(l+r)/2;
	if(x<=mid) change(op,p*2,l,mid,x,v);
	else change(op,p*2+1,mid+1,r,x,v);
	t[op][p]=max(t[op][p*2],t[op][p*2+1]);
}
int ask(int op,int p,int l,int r,int ql,int qr)
{
	if(ql<=l&&r<=qr) return t[op][p];
	int mid=(l+r)/2,ans=-1<<30;
	if(ql<=mid) ans=max(ans,ask(op,p*2,l,mid,ql,qr));
	if(qr>mid) ans=max(ans,ask(op,p*2+1,mid+1,r,ql,qr));
	return ans;
}
bool check(int x,int y)
{
	if(y<0) return 0;
	if(y%2==0) return (ask(0,1,1,n,x,n)>=y);
	else return (ask(1,1,1,n,x,n)>=y);
}
int main()
{
	n=read();
	for(i=1;i<=n;i++) p[i]=read();
	int maxp=0;
	for(i=1;i<=n;i++){
		maxp=max(maxp,p[i]);
		if(p[i]==maxp) a[i]=2;
		else a[i]=1;
	}
	for(i=n;i>=1;i--) q[i]=q[i+1]+a[i]-1;
	build(1,1,n);
	for(i=n;i>=1;i--){
		int tmp0=ask(0,1,1,n,p[i],n)+a[i],tmp1=ask(1,1,1,n,p[i],n)+a[i];
		if(a[i]%2==0) change(0,1,1,n,p[i],tmp0),change(1,1,1,n,p[i],tmp1);
		else change(0,1,1,n,p[i],tmp1),change(1,1,1,n,p[i],tmp0);
	}
	int cntx=0,cnty=0,maxx=0,maxy=0;
	for(i=1;i<=n;i++){
		change(0,1,1,n,p[i],0);
		change(1,1,1,n,p[i],-1<<30);
		if(check(maxy,cntx+(p[i]>maxx)+q[i+1]-cnty)||check(max(maxx,p[i]),cnty+q[i+1]-cntx-(p[i]>maxx))){
			cntx+=(p[i]>maxx);
			maxx=max(maxx,p[i]);
		}
		else{
			s[i]=1;
			cnty+=(p[i]>maxy);
			maxy=max(maxy,p[i]);
		}
	}
	if(cntx!=cnty) puts("-1");
	else{
		for(i=1;i<=n;i++) printf("%d",s[i]);
		puts("");
	}
	return 0;
}


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

int main() {
    string s,t;
    cin >> s >> t;
    int count=0;
    
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) count++;
    }
    
    cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3912
# https://atcoder.jp/contests/abc174/tasks/abc174_c

K = gets.to_i

K /= 7 if (K % 7).zero?

if K.even? || (K % 5).zero?
  puts(-1)
  exit 0
end

ws = 10.times.map { |i| K * i }
n = m = 1
v = 1

K.times do
  # p [n, m, v]
  w = ws.find { |a| a % 10 == v % 10 }
  while v < w
    v += 10**m
    n += 1
    m += 1
    # p [' ', n, m, v]
  end
  v = (v - w) / 10
  if v.zero?
    puts n
    exit 0
  end
  m -= 1
end

puts(-1)


Measured memory_bytes: 14248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define MAX_E 2000
#define MAX_V 1000

ll INF = 1000000000000;
//ベルマンフォード法
//計算量O(VE) 頂点数＊辺数
struct edge{ll from, to, cost;};
edge es[MAX_E];
ll d[MAX_V];
ll V, E;

bool shortest_path(ll s){
    for(ll i = 0; i < V; i++) d[i] = INF;
    d[s] = 0;
    for(ll i = 0; i < 2 * V; i++){
        for(ll j = 0; j < E; j++){
            edge e = es[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i >= V - 1 && e.to == V - 1) return true;
            }
        }
    }
    return false;
}

int main(void){
    cin >> V >> E;
    rep(i, 0, E){
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].from--;
        es[i].to--;
        es[i].cost = -es[i].cost;
    }

    if(shortest_path(0)){
        cout << "inf" << endl;
    }else{
        cout << -d[V - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for (ll i=b-1;i>=a;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define pi 3.141592653589793238462
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
typedef long double ld;
ll ESP=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 ll a,b,c,k;
 cin>>a>>b>>c>>k;
 ll ans=0;
 if(a>=k)
    ans+=k;
 else if(k>0)
    ans+=a;
 k-=a;
 if(k>0 && b>=k)
    ans+=0;
 else if(k>0)
    ans+=0;
 k-=b;
 if(k>0 && c>=k)
    ans+=-k;
 else if(k>0)
    ans+=-c;
 cout<<ans<<"\n";
 return 0;




}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n;
std::list<int> l;

int main(){
	scanf("%d", &n);
	rep(i, n){
		int x;
		char c[20];
		scanf("%s", &c);

		if (c[0] == 'i'){
			std::cin >> x;
			l.push_front(x);
		}
		else if (c[6] != 'F' && c[6] != 'L'){
			std::cin >> x;
			auto it = l.begin();
			while (it != l.end()){
				if (*it == x){
					it = l.erase(it);
					break;
				}
				++it;
			}
		}
		else if (c[6] == 'F')l.pop_front();
		else if (c[6] == 'L')l.pop_back();
	}

	auto it = l.begin();
	if (it != l.end())printf("%d", *it), ++it;
	while (it != l.end()){
		printf(" %d", *it);
		++it;
	}
	printf("\n");

	return 0;
}

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

ll a, b, n;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> a >> b >> n;
    cout << b * (n/a);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,C,K;
  cin>>N>>C>>K;
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin>>T[i];
  }
  sort(T.begin(),T.end());
  int bus=T[0],cnt=1,ans=1;
  for(int i=1;i<N;i++){
    cnt++;
    if(cnt>C || T[i]>K+bus){
      ans++;
      bus=T[i];
      cnt=1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace practice_csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var l = s.Length;
            var h = l / 2;
            var front = s.Substring(0,h);
            var back = s.Substring(h+l%2);
            var invFront = front.Reverse().ToArray();
            var count = 0;
            for(int i=0;i<h;i++){
                if(back[i]!=invFront[i]){
                    count++;
                }
            }
            System.Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 1 << 20 | 5, M = 22;
int n, K, Ans, Alen=-1; char str[N];
int *dp[M][M];
struct dat{
	int S, len; dat(int _S=0, int l=0){ S=_S; len=l; }
	int fnd(int z){ 
		for(int i=len-1;~i;i--)
		if((S>>i&1)==z) return i+1; return -1;
	} void trans(int k){ --k; len=k; S=S&((1<<k)-1); }
};
void Add(dat a, dat b, int coe){
	int x = a.len + b.len, y = a.len;
	int z = (a.S << b.len) + b.S; 
	dp[x][y][z] += coe;
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d%d",&n,&K);
	for(int i=0; i<=n; i++)
	for(int j=0; j<=i; j++){
		dp[i][j] = new int[1<<i];
		memset(dp[i][j],0,sizeof(int)*(1<<i));
	}
	for(int i=0; i<=n; i++){
		scanf("%s",str); int m=1<<i;
		for(int j=0; j<m; j++) 
		if(str[j]=='1') Add(dat(0,0),dat(j,i),1);
	} 
	for(int i=0; i<=n; i++)
	for(int j=i+1,coe; j<=n; j++)
	for(int k=0,m=1<<j; k<m; k++)
	if(coe=dp[j][i][k]){
		dat A(k>>(j-i),i), na = A;
		dat B(k&((1<<(j-i))-1),j-i), nb = B;
		int a = B.fnd(0), b = B.fnd(1);
		if(~a){
			na.S = na.S << 1, ++na.len;
			nb.trans(a); Add(na,nb,coe); 
		} na = A; nb = B;
		if(~b){
			na.S = na.S << 1 | 1; ++na.len;
			nb.trans(b); Add(na,nb,coe);
		} 
	} 
	static int ct[M][N];
	for(int i=0; i<=n; i++)
	for(int j=i; j<=n; j++)
	for(int k=0; k<(1<<j); k++){
		int S=k>>(j-i); ct[i][S]+=dp[j][i][k];
	}
	for(int i=n; i>=0; i--)
	for(int j=0; j<(1<<i); j++) 
	if(ct[i][j]>=K){ for(int t=i-1;~t;t--) cout<<(j>>t&1); return 0; }
}

Measured memory_bytes: 214784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
int p[N], d[N]={};
int grp(int a){
	if(p[a]==a) return a;
	else return grp(p[a]);
}
void mrg(int a, int b){
	a = grp(a), b = grp(b);
	if(a==b) return;
	if(d[a]>d[b]) swap(a, b);
	p[a] = b;
	LAR(d[b], d[a]+1);
}
set<int> s;

int main(){
	REP(i, N) p[i]=i;
	int n, m; scanf("%d%d", &n, &m);
	REP(i, m){
		int x, y, z; scanf("%d%d%d", &x, &y, &z); x--; y--;
		mrg(x, y);
	}
	REP(i, n) s.insert(grp(i));
	printf("%d\n", (int)s.size());
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long int
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int32_t main(){
	FIO
	
	int n;
	cin>>n;
	map<string,int> m;
	string s;
	forn(i,n)
	{
		cin>>s;
		m[s]++;
	}
			cout<<m.size();

	return 0;
}

Measured memory_bytes: 19216
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<cstdio>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,m;
 cin>>n>>m;
 ll s[m+10][100],t[m+10];
 rep(i,0,m){
  sc(t[i]);
  rep(j,0,t[i]){
   sc(s[i][j]);
  }
 }
 ll p[m+10];
 rep(i,0,m)sc(p[i]);

 ll bit,cnt,tmp;
 for(bit=0;bit<(1<<n);bit++){//どれを点灯させるのか
  cnt=0;//点灯している数
  rep(i,0,m){//一つ一つの電灯について見ていく
   tmp=0;//onになっている数
   rep(j,0,t[i]){
    if(bit&(1<<(s[i][j]-1)))tmp++;
   }
   if((tmp%2)==p[i])cnt++;
   //cout<<bit<<" "<<i<<" "<<j<<" "<<p[i]<<" "<<tmp<<" "<<cnt<<endl;
  }
  if(cnt==m)ans++;
 }
 
 pr(ans);
return 0;}


Measured memory_bytes: 3664
n, a = map(int, input().strip().split())

if n <= a:
  print(0)
else:
  aaa = list(map(int, input().strip().split()))

  aaa = sorted(aaa, reverse=True)
  h = 0
  for i in range(a, n):
    h += aaa[i]

  print(h)

Measured memory_bytes: 25768
//package april2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {
	static long[] dp;
	static int n,k, a[];
	static long MOD = (long)1e9+7;
	public static void main(String[] args) throws IOException {
		FastReader scn = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );
		n = scn.nextInt();
		boolean[][] can = new boolean[n][n];
		
		for(int i =0;i<n;i++) {
			for(int j = 0;j<n;j++) {
				can[i][j] = scn.nextInt()==1;
			}
		}
		
		long[] dp = new long[1<<n];
		
		dp[0] = 1;
		
//		for(int i=0;i<n;i++) {
			for(int mask = 0;mask<(1<<n)-1;mask++) {
				int i = num_set_bits(mask);
//				out.write((i+" ").getBytes());
//				out.flush();
				for(int j=0;j<n;j++) {
					if(can[i][j]&&(mask&(1<<j))==0) {
						int m2 = mask^(1<<j);
						dp[m2] = (dp[m2]+dp[mask])%MOD;
					}
				}
			}
//		}
		out.write((dp[(1<<n)-1]+"\n").getBytes());
		out.close();
	}
	static int num_set_bits(int mask) {
		int ans =0;
		while(mask>0) {
			if((mask&1)==1) {
				ans++;
			}
			mask=mask>>1;
		}
		return ans;
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 40148
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto&
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int cnt[500];

bool solve(vector<int> a) {
    int n = size(a);
    int maxv = *max_element(all(a));
    int minv = *min_element(all(a));

    for (int i = minv; i <= maxv; i++) {
        if (i == minv) {
            if (cnt[i] > 2) return false;
        } else {
            if(cnt[i] < 2) return false;
            n -= cnt[i] - 2;
        }
    }
    return n / 2 == minv;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    for (int x : a) cnt[x]++;
    cout << (solve(a) ? "Possible" : "Impossible") << endl;
}


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long N) {
  int ans = 0;
  for(int i = 1 ; i <= N ; i++){
    int d = 0;
    int j = i;
    while(j){
      d++;
      j /= 10;
    }
    if( d % 2 == 1 ){
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

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

    int A, B;cin>>A>>B;
    string U; cin>>U;

    if(U==S){
        cout<<A-1<<" "<<B<<endl;
    }else{
        cout<<A<<" "<<B-1<<endl;

    }


    return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().ToCharArray();
            var N = S.Length;
            var ret = S.Zip(S.Reverse(), (x, y) => x == y).All(x => x);
            if (!ret)
            {
                Console.WriteLine("No");
                return;
            }
            var cond2 = S.Take((N - 1) / 2).ToArray();
            ret = cond2.Zip(cond2.Reverse(), (x, y) => x == y).All(x => x);
            if (!ret)
            {
                Console.WriteLine("No");
                return;
            }
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int s,d,m,k;
vector<int> A[100];
vector<int> B[100];
int dp[5001];

int main(){
  while( scanf("%d %d %d",&s,&d,&m) != EOF){
    for(int i=0;i<s;i++){
      scanf("%d",&k);
      A[i].resize(k);
      B[i].resize(k);
      for(int j=0;j<k;j++)
        scanf("%d %d",&A[i][j],&B[i][j]);
    }
    for(int i=0;i<=5000;i++)dp[i]=1e9;
    dp[0]=0;
    
    for(int i=0;i<d;i++){
      scanf("%d",&k);
      for(int j=0;j<(int)A[k].size();j++){
        int a=A[k][j],b=B[k][j];
        for(int l=5000;l>=a;l--){
          dp[l]=min(dp[l],dp[l-a]+b);
        }
      }
    }

    int ans;
    for(int i=0;i<=5000;i++)
      if(dp[i]<=m)ans=i;
    cout<<ans<<' '<<dp[ans]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long ll;
typedef long int lint;

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

    int x;
    cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3608
let () =
  let rec read pos =
    try let l = read_line ()
                |> Str.split (Str.regexp_string ",")
        in
        if (List.nth l 0) = pos then
          read (List.nth l 1)
        else if (List.nth l 1) = pos then
          read (List.nth l 0)
        else
          read pos
    with End_of_file -> pos
  in print_endline (read "A")
;;

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

int main()
{
    char S[100005];
    cin >> S;
    int N=strlen(S);
    vector<int> vt;
    for(int i=0; i<N; i++){
        if(S[i]=='0'){
            vt.push_back(0);
        }else if(S[i]=='1'){
            vt.push_back(1);
        }
    }
    int flag=0;
    int ans=0;
    int tmp=vt[0];
    while(ans+flag<N){
        if(flag==0){
            tmp=vt[0];
        }else{
            if(tmp!=vt[flag]){
                vt.erase(vt.begin() + flag);
                vt.erase(vt.begin() + flag -1);
                flag-=2;
                ans+=2;
            }
        }
        flag++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1020
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define mod 1000000007
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
bigint fact[2000001] ;
bigint inv[2000001] ;
bigint fact_inv[2000001] ;
void factorial(){
    fact[0] = fact[1] = 1 ;
    for( bigint i = 2 ; i <= 2000000 ; i++ ){
        fact[i] = i * fact[i-1] ;
        fact[i] %= mod ;
    }
}
void inverse(){
     inv[1] = 1 ;
    for( bigint i = 2 ; i <= 2000000 ; i++ ){
       inv[i] = (mod - ((mod/i) * inv[mod%i]) % mod) % mod;
    }
    fact_inv[0] = fact_inv[1] = 1 ;
    for (int i = 2; i <= 2000000; i++)
        fact_inv[i] = (inv[i] * fact_inv[i - 1]) % mod;
    
}
bigint nCr( bigint N , bigint R ){
    if( N < 0 || R < 0 || N < R )
        return 0 ;
    bigint ans =  (( fact_inv[R] * fact_inv[N-R] ) % mod * fact[N] ) % mod ;
    return ans ;
}
bigint power( bigint A , bigint B , bigint md = mod ){
   bigint ans = 1 ;
   while( B > 0 ){
       if( B & 1 )
           ( ans *= A ) %= md ;
       ( A *= A ) %= md ;
        B >>= 1 ;
   }
    return ans ;
}

int main(){
    factorial() ; inverse() ;
    bigint K ; cin >> K ;
    string str ; cin >> str ;
    bigint N = str.length() ;
    bigint ans = 0 ;
    for( bigint i = 0 ; i <= K ; i++ ){
        bigint temp = ( power(26, i) * power(25, K - i ) ) % mod ;
        temp = ( temp * nCr(N + K - i - 1 , N - 1 )) % mod ;
        ans = ( ans + temp ) % mod ;
       }
       cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 52076
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pri = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())

if N <= K:
    print(N)
else:
    print(N-1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j == n){
                cout << "Yes" << endl;
                return 0;
            } 
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
/*
author : seryu
title : contest
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 2019;//1000000007;
int INF = 1001001001;


void solve()
{
	ll l, r;
	cin >> l >> r;
	ll ans;
	if(l / MOD != r / MOD)ans = 0;
	else
	{
		l %= MOD;
		r %= MOD;
		ans = MOD;
		mrep(i, l, r)mreps(j, i+1,r)chmin(ans,(i*j) % MOD);
	}
	cout << ans << endl;
	return;
}

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


Measured memory_bytes: 256
/*@shutoshsuman99*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define rem1 998244353
#define inf 1e18+1e17
#define F first
#define S second
#define pii pair<long long,long long>
#define p_q priority_queue <ll, vector<ll>, greater<ll> >
#define m_sp multiset <pair <ll,ll> > 
#define el "\n"
#define sp " "
typedef long long ll;
ll Pow(ll x,ll y,ll m) 
{ if (y == 0) return 1; ll p = Pow(x, y/2, m) % m; 
p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m; } 
main()
{ 
	// fast io
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);ll i; 
	ll r,d,x;
	cin>>r>>d>>x;
	for(i=1;i<=10;i++)
	{
		cout<<r*x-d<<el;
		x=r*x-d;
	}
}

Measured memory_bytes: 256
import collections
s = input()
d = collections.Counter(s)
if len(d.keys()) == 4:
    print("Yes")
elif len(d.keys()) == 2 and "N" in d.keys() and "S" in d.keys():
    print("Yes")
elif len(d.keys()) == 2 and "E" in d.keys() and "W" in d.keys():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

template<typename T>
struct Segment_Tree {
	typedef function<T(T, T)> F;

	ll n;
	F f;//モノイドとしての演算(最小値、和　など)
	T unit;//単位元

	ll size;
	vector<T> seg;

	Segment_Tree(ll n0, F f0, T unit0) {
		n = n0;
		f = f0;
		unit = unit0;

		size = 1;
		while (size < n) {
			size *= 2;
		}
		seg.assign(2 * size, unit);
	}


	void update(ll k, T x) {//k番目の要素をxに更新
		k += size - 1;
		seg[k] = x;
		while (k > 1) {
			k /= 2;
			seg[k] = f(seg[2 * k], seg[2 * k + 1]);
		}
	}



	T query_prep(ll a, ll b, ll k, ll l, ll r) {//[a,b)とkに対応する区間[l,r)の共通部分でクエリ
		if (b <= l || a >= r) { return unit; }
		if (a <= l && r <= b) { return seg[k]; }

		T v1 = query_prep(a, b, 2 * k, l, (l + r) / 2);
		T v2 = query_prep(a, b, 2 * k + 1, (l + r) / 2, r);
		return f(v1, v2);

	}

	T query(ll a, ll b) {
		return query_prep(a, b, 1, 1, size + 1);
	}

};



int main() {
	ll A, B, M;
	cin >> A >> B >> M;

	vector<ll> a(A + 1), b(B + 1), x(M + 1), y(M + 1), c(M + 1);

	repn(i, A) cin >> a[i];
	repn(i, B) cin >> b[i];
	repn(i, M) cin >> x[i] >> y[i] >> c[i];

	ll ans = INF;

	repn(i, M)ans = min(ans, a[x[i]] + b[y[i]] - c[i]);

	sort(++a.begin(), a.end());
	sort(++b.begin(), b.end());

	ans = min(ans, a[1] + b[1]);

	cout << ans;
	

	system("PAUSE");

}





Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	if(a==b && b==c && a%2==0){
		cout<<"-1"<<endl;
		return(0);
	}
	while(a%2==0 && b%2==0 && c%2==0){
		int A=a,B=b,C=c;
		a=(B+C)/2;
		b=(A+C)/2;
		c=(A+B)/2;
		ans++;
	}
	cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>

int gcf( int a , int b );

int main() {
    int N,X,x[200000],z,hoge;

    scanf("%d %d",&N,&X);
    for( z = 0 ; z < N ; z++ ) {
        scanf("%d",&x[z]);
        if( x[z] > X ) x[z] -= X;
        else x[z] = X - x[z];
    }
    if( N == 1 ) {
        printf("%d\n",x[0]);
        return 0;
    }


    hoge = gcf( x[0] , x[1] );
    for( z = 2; z < N ; z++ ) hoge = gcf( hoge , x[z] );


    printf("%d\n",hoge);


    return 0;
}

int gcf( int a , int b ){
    while (1) {
        if (a%b == 0) return b;
        else if ( b%a == 0) return a;
        else if (a > b) a = a%b;
        else b = b%a;
    }
}

Measured memory_bytes: 512
h, w = gets.split.map(&:to_i)
maze = []
h.times do
  maze << gets.chomp.chars
end

dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
ans = 0
queue = []
(0..h-1).each do |j|
  (0..w-1).each do |i|
    next if maze[j][i] == "#"

    queue << [j, i]
    d = Array.new(h) { Array.new(w, 0) }
    visited = Array.new(h) { Array.new(w, false) }
    d[j][i] = 0
    visited[j][i] = true
    while !queue.empty? do
      y, x = queue.shift
      (0..3).each do |k|
        ny = y + dy[k]
        nx = x + dx[k]
        next if ny < 0 || nx < 0 || ny >= h || nx >= w || maze[ny][nx] == "#" || visited[ny][nx]

        d[ny][nx] = d[y][x] + 1
        visited[ny][nx] = true
        queue << [ny, nx]
      end
    end
    # puts d.inspect
    ans = [ans, d.flatten.max].max
  end
end
puts ans

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

int main(){
	long long s;
	cin>>s;
	
	const int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


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

int n;
int a[2000000];
int m;
int b[2000000];
map<int,int> mpa,mpb;

int main() {
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mpa[a[i]]++;
    }
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> b[i];
        mpb[b[i]]++;
    }
    for(int i=0;i<m;i++){
        int x=b[i];
        if(mpb[x]>mpa[x]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 23808
N = int(input())
H = list(map(int, input().split()))

# 前から順に走査し、移動回数を最大値で更新する
ans, tmp = 0, 0
for i in range(N-1):
  if H[i] >= H[i+1]: tmp += 1
  else:
    ans = max(ans, tmp)
    tmp = 0
    
ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 20316
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
    int a,b ;
    cin >> a >> b;

    int ans;
    if(a == b){
        ans = a+a;
    }else{
        ans = max(a,b)*2-1;
    }
    
    cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++){
        if(n % i == 0 && n / i < 10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0,w=0,t=0,r=0;
  cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s=="AC"){
      a++;
    }
    else if(s=="WA"){
      w++;
    }
    else if(s=="TLE"){
      t++;
    }
    else{
      r++;
    }
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << w << endl;
  cout << "TLE x " << t << endl;
  cout << "RE x " << r << endl;
}

Measured memory_bytes: 3620
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            ab = l[i] + l[j]
            x = bisect_left(l, ab)
            res += x - (j + 1)
    print(res)

if __name__ == '__main__':
    main()

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

enum {
    Up,
    UpLeft,
    Left,
    DownLeft,
    Down,
    DownRight,
    Right,
    UpRight,
    DirectionMax
};

int Direction[][2] = {
    {0, -1},  // Up
    {-1, -1}, // UpLeft
    {-1, 0},  // Left
    {-1, 1},  // DownLeft
    {0, 1},   // Down
    {1, 1},   // DownRight
    {1, 0},   // Right
    {1, -1}   // UpRight
};

void DropInk(int paper[10][10], int x, int y, int s);
void Show(const int paper[10][10]);

int main(void) {
    int paper[10][10] = {{}};
    int x, y, s;
    
    while(scanf("%d,%d,%d", &x, &y, &s) != EOF) {
        DropInk(paper, x, y, s);
    }
    
    Show(paper);
}

void DropInk(int paper[10][10], int x, int y, int s) {
// s = 1(small), 2(medium), 3(large)
    int X, Y;
    ++paper[x][y];
    switch(s) {
        case 1 : { // UP, Left, Down, Right
            for(int i = 0; i < DirectionMax; i+=2) {
                X = x + Direction[i][0];
                Y = y + Direction[i][1];
                if(0 <= X && X < 10 && 0 <= Y && Y < 10) {
                    ++paper[X][Y];
                }
            }
            break;
        }
        case 2 : { // All Direction
            for(int i = 0; i < DirectionMax ; ++i) {
                X = x + Direction[i][0];
                Y = y + Direction[i][1];
                if(0 <= X && X < 10 && 0 <= Y && Y < 10) {
                    ++paper[X][Y];
                }
            }
            break;
        }
        case 3 : { // All Direction + a
            for(int i = 0; i < DirectionMax; ++i) {
                X = x + Direction[i][0];
                Y = y + Direction[i][1];
                if(0 <= X && X < 10 && 0 <= Y && Y < 10) {
                    ++paper[X][Y];
                }
                if(i == Up || i == Left || i == Down || i == Right) {
                    X += Direction[i][0];
                    Y += Direction[i][1];
                    if(0 <= X && X < 10 && 0 <= Y && Y < 10) {
                        ++paper[X][Y];
                    }
                }
            }
            break;
        }
    }
}

void Show(const int paper[10][10]) {
    int count0 = 0;
    int dark = 0;
    for(int x = 0; x < 10; ++x) {
        for(int y = 0; y < 10; ++y) {
            if(paper[x][y] == 0) {
                ++count0;
            }
            if(paper[x][y] > dark) {
                dark = paper[x][y];
            }
        }
    }
    cout << count0 << endl;
    cout << dark << endl;
}


Measured memory_bytes: 3224
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll N;
ll a[16][16];
ll dp[1 << 17];
bool used[1 << 17];
ll num[1 << 17];

ll solve(ll mask) {
    if (used[mask]) {
        return dp[mask];
    }
    used[mask] = true;
    ll ans = num[mask];
    for (ll i = (mask - 1) & mask; i > 0; i = (i - 1) & mask) {
        ans = max(ans, solve(i) + solve(i ^ mask));
    }
    return dp[mask] = ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, 0, N) {
        REP(j, 0, N) {
            cin >> a[i][j];
        }
    }
    REP(i, 0, (1 << N)) {
        ll tmp = 0;
        REP(j, 0, N) {
            REP(k, j + 1, N) {
                if (((i >> j) & 1) && ((i >> k) & 1)) {
                    tmp += a[j][k];
                }
            }
        }
        num[i] = tmp;
    }
    // REP(i, 0, 8) {
    //     cout << num[i] << " ";
    // }
    // cout << endl;
    fill(used, used + (1 << N), false);
    ll ans = solve((1 << N) - 1);
    cout << ans << endl;
}
    


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 18, inf = 1e9;
const int MAX = 1 << MAXN;

int n, a[MAXN], b[MAXN];

int dp[MAX][MAXN];

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

  REP(i, MAX) REP(j, MAXN) dp[i][j] = inf;
  cin >> n;
  REP(i, n)
    cin >> a[i];
  REP(i, n)
    cin >> b[i];

  dp[0][0] = 0;
  REP(i, n)
    dp[(1 << i)][i] = i;

  REP(mask, (1 << n))
    REP(i, n){
      if( (mask & (1 << i)) == 0 ) continue;
      int last_pos = __builtin_popcount(mask) - 1;
      int last_val;
      if( abs(i - last_pos) % 2 )
        last_val = b[i];
      else
        last_val = a[i];

      REP(j, n){
        if( mask & (1 << j) ) continue;
        int nxt_val;
        int new_pos = last_pos + 1;
        if( abs(new_pos - j) % 2 )
          nxt_val = b[j];
        else
          nxt_val = a[j];
        if(nxt_val < last_val) continue;
        int desno = 0;
        FOR(k, j + 1, n)
          if( (mask & (1 << k)) == 0 )
            desno ++;
        int cost = (n - desno - 1) - new_pos;

        dp[ mask | (1 << j) ][j] = min(dp[ mask | (1 << j) ][j], dp[mask][i] + cost);
      }
    }
  int sol = inf;
  REP(i, n)
    sol = min(sol, dp[(1 << n) - 1][i]);
  if(sol == inf)
    cout << -1;
  else
    cout << sol;
}



Measured memory_bytes: 18816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
    return 0;
}


Measured memory_bytes: 256
import re

sdash = input().replace('?', '.')
t = input()
len_t = len(t)
isNotUsed = True

for i in range(len(sdash) - len_t, -1, -1):
    if re.match(sdash[i:i+len_t], t):
        s = sdash[:i] + t + sdash[i+len_t:]
        isNotUsed = False
        break
if isNotUsed:
    print('UNRESTORABLE')
else:
    print(s.replace('.', 'a'))

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

#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

int solve(int i, int j) {
    int result = 1;
    for (int k = 2; k <= min(i, j); k++) {
        if (i % k == 0 && j % k == 0) {
            result = k;
        }
    }
    return result;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    ll sum = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int m = 1; m <= k; m++) {
                sum += solve(solve(i, j), m);
            }
        }
    }
    cout << sum << "\n";



}


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

typedef long long int ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

ll dp[3005][3005][4];
ll grid[3005][3005];
ll r, c, k;

bool ok(ll x, ll y) {
	if (x <= r and y <= c) {
		return true;
	}
	return false;
}

ll go(ll x, ll y, ll left) {
	if (x == r and y == c) {
		if (left > 0) {
			return grid[r][c];
		} else {
			return 0;
		}
	}
	if(dp[x][y][left]!=-1){
		return dp[x][y][left];
	}

	ll ans;
	ll op1 = 0, op2 = 0, op3 = 0, op4 = 0;
	if (ok(x, y + 1)) {
		if (left > 0) {
			op1 = go(x, y + 1, left);
			op2 = go(x, y + 1, left - 1) + grid[x][y];
		}
	}
	if (ok(x + 1, y)) {
		op3 = go(x + 1, y, 3);
		if (left > 0) {
			op4 = go(x + 1, y, 3) + grid[x][y];
		}
	}
	ans = max({op1,op2,op3,op4});
	return dp[x][y][left] = ans;
}

void solve() {

	cin >> r >> c >> k;
	memset(dp,-1,sizeof(dp));
	for (int i = 0; i < k; i++) {
		ll x, y, v;
		cin >> x >> y >> v;
		grid[x][y] = v;
	}

	ll sol = go(1, 1, 3);
	cout << sol << endl;


}

int32_t main()
{
	IOS
	// int T; cin >> T; while (T--)
	solve();
	return 0;
}


Measured memory_bytes: 356956
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int alice=0, bob=0;
  for(int i=0;i<n;i++){
    if(i%2==0)alice+=a[i];
    else bob+=a[i];
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int n;
    std::string s, ans = "Yes";
    std::cin >> n >> s;

    if(1 == n %2){
        ans = "No";
    }else if(s.substr(0, n/2) != s.substr(n/2, n/2)){
        ans = "No";
    }

    std::cout << ans << std::endl;

    return 0;
}

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

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

    bool modd = false, zero = false;
    ll sum = 0;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) {modd = !modd; a[i] *= -1;}
        if (a[i] == 0) zero = true;
        sum += a[i];
    }

    ll ans = sum;
    if (modd && !zero) ans -= *min_element(a.begin(), a.end()) * 2;

    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i], P[i]--;
    rep(i, N) Q[P[i]] = i;

    int k = 0;
    int now = 1;
    rep(i, N - 1) {
        if (Q[i + 1] > Q[i]) {
            now++;
        } else {
            chmax(k, now);
            now = 1;
        }
    }
    chmax(k, now);

    int ans = N - k;
    cout << ans << endl;
}


Measured memory_bytes: 1920