akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = [-1 for i in range(n)]

for i in range(m):
    s, c = map(int, input().split())
    if a[s - 1] == -1:
        a[s - 1] = c
    elif a[s - 1] == c:
        pass
    else:
        print('-1')
        exit()

if n == 1 and a[0] == 0:
    print('0')
    exit()
if n == 1 and a[0] == -1:
    print('0')
    exit()
if n != 1 and a[0] == 0:
    print('-1')
    exit()

for i in range(n):
    if a[i] == -1:
        a[i] = 0

if a[0] == 0:
    a[0] = 1
ans = ''
for i in range(n):
    ans += str(a[i])
print(ans)

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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
  #define DFUNC(fname, ...) fname(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFUNC(fname, ...)
#endif

ll N, K;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N >> K;
  cout << N - K + 1 << endl;

  return 0;
}



Measured memory_bytes: 256
#define g(x)(p[P[x-1]]-p[P[x]])*1./(h[P[x]]-h[P[x-1]])-h[P[x-1]]-h[P[x]]
long C,h[2<<17],p[2<<17],a;P[2<<17];s,t,x,y;
main(i){
	for(scanf("%*d%ld%d",&C,h);~scanf("%d",&a);){
		for(h[i]=a;s<t&&g(s+1)>-2*a;s++);
		p[i]=p[P[s]]+(h[P[s]]-a)*(h[P[s]]-a)+C;
		P[++t]=i;
		for(;s+1<t&&g(t)>g(t-1);P[--t]=i);
		i++;
	}
	printf("%ld",p[i-1]);
}

Measured memory_bytes: 4608
N, T = map(int, input().split())
c = [0] * N
t = [0] * N
cost = []
for i in range(N):
    c[i], t[i] = map(int, input().split())
    if t[i] <= T:
        cost.append(c[i])
if cost:
    print(min(cost))
else:
    print('TLE')

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

int main(int argc, char const *argv[])
{
    int A, B, C, ans = 0;
    cin >> A >> B >> C;

    if (C <= (A + B + 1))
    {
        ans = B + C;
    }
    else
    {
        ans = A + 2 * B + 1;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef pair<int, int> P;


class DSU {
private:
  std::vector<int> rank, p, size;
public:
  DSU(int n): rank(n, 0), p(n), size(n, 1) {
    std::iota(p.begin(), p.end(), 0);
  }

  int findRep(int x) {
    if (p[x] != x) {
      p[x] = findRep(p[x]);
    }
    return p[x];
  }

  void unite(int x, int y) {
    int p1 = findRep(x), p2 = findRep(y);
    if (p1 == p2) return;
    if (rank[p1] < rank[p2]) std::swap(p1, p2);
    
    if (rank[p1] == rank[p2]) rank[p1]++;
    p[p2] = p1;
    size[p1] += size[p2];
  }

  int getSize(int x) {
    int xRep = findRep(x);
    return p[xRep];
  }

  bool isSame(int x, int y) {
    return findRep(x) == findRep(y);
  }
};


int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ab(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ab[i] = P(a, b);
  }

  int ans = 0;
  for (int i = 0; i < m; ++i) {
    DSU dsu = DSU(n);
    for (int j = 0; j < m; ++j) {
      if (j != i) {
	dsu.unite(ab[j].first, ab[j].second);
      }
    }
    int tmp = dsu.findRep(0);
    bool con = true;
    for (int i = 1; i < n; ++i) {
      if (tmp != dsu.findRep(i)) con = false;
    }
    if (!con) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(void) {
  string S;
  cin >> S;
  int n = S.size();

  vector<int> A(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    if (S[i] == '<') A[i + 1] = A[i] + 1;
  }
  for (int i = n; i >= 0; --i) {
    if (S[i] == '>' && A[i] <= A[i + 1]) A[i] = A[i + 1] + 1;
  }

  int64_t answer = 0;
  for (auto n : A) answer += n;
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 2820
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))

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

int main(){
    int N;
    int L[110];
    cin>>N;
    for(int i=0;i<N;++i)cin>>L[i];
    int total=0;
    for(int i=0;i<N;++i)total+=L[i];
    bool can=true;
    for(int i=0;i<N;++i){
        if(L[i]<total-L[i]){
            
        }
        else{
            can=false;
            break;
        }
        
    }
    if(can){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
int main(){
    fastread;
    ll r;
    cin>>r;
    double d=2.0000000*PI*r;
    cout<<d;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define ll long long
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define rep(j,n,jj) for(int i=j;i<n;i+=jj)
#define modd 1000000007
using namespace std;
void solve();
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    time_t start,end;
    time(&start);
    solve();
    time(&end);
    double t= double(end - start); 
/*    cout << fixed */
/*         << t<< setprecision(5)<<endl;*/
    return 0; 
}

void solve(){
	int n;
	cin>>n;
	int arr[n+1]={};
	rep(0,n-1,1){
		int x;
		cin>>x;
		arr[x]+=1;
	}
	rep(1,n+1,1){
		cout<<arr[i]<<"\n";
	}
}

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


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

    int K,N;
    cin >> N >> K;
    double p[N];
    rep(i,N) cin >> p[i];

    rep(i,N) p[i]=(p[i]+1)/2.0;
    double ans=0.0;
    double sum=0;
    rep(i,K) ans+=p[i];
    sum=ans;
    for(int i=K;i<N;i++){
        sum+=p[i];
        sum-=p[i-K];
        ans=max(ans,sum);
        
    }
    cout << fixed << setprecision(14);
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int H, W;
int ans = 0;


int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
string A[1123];
int dp[1123][1123];
vector< cp2 >S[2123];
int idx = 0;

int main(){
	
	fill( dp[0], dp[1123], -1 );
	
	cin>>H>>W;
	REP( i, H ) cin>>A[i];
	

	REP( i, H ){
		REP( j, W ){
			if( A[i][j] == '#' ){
				dp[i][j] = idx;
				S[idx].push_back( cp2( i, j ) );
			}
		}
	}
	
	
	
	while( idx < H+W ){
		if( S[idx].size() == 0 ) break;
		REP( i, S[idx].size() ){
			int y = S[idx][i].fi;
			int x = S[idx][i].se;
			REP( j, 4 ){
				int nx = x+dx[j];
				int ny = y+dy[j];
				if( nx < W && nx >= 0 && ny < H && ny >= 0 ){
					if( dp[ny][nx] < 0 ){
						dp[ny][nx] = idx+1;
						S[idx+1].push_back( cp2( ny, nx ) );
					}
				}
			}
		}
		idx++;
	}
	
	
	REP( i, H ) REP( j, W ) ans = max( ans, dp[i][j] );
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 29540
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct UnionFind {
  vector<int> par; // 親を指すvector,-par[親]は木のサイズ
  UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
  int root(int x) { // 親をたどる&データの整理
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  bool unite(int x, int y) { // データの結合
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) {return root(x) == root(y);} // 所属判定
  int size(int x) {return -par[root(x)];} // 木のサイズ
};

#define N 100100

//head

int n;
P ab[N];
int pl[N];
vi z;
UnionFind uft(N);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, n) cin >> ab[i].first;
  rep(i, n) cin >> ab[i].second;
  sort(ab, ab+n);
  z.reserve(n);
  rep(i, n) z.push_back(ab[i].second);
  sort(all(z));
  rep(i, n) {
    auto itr = lower_bound(all(z), ab[i].second);
    pl[itr-z.begin()] = i;
    *itr--;
  }
  int j = 0;
  bool over = false;
  rep(i, n) {
    while(j < n and ab[j].first <= ab[pl[i]].second) j++;
    uft.unite(i, pl[i]);
    if(j-1 != i) {
      if(j-1 > i) over = true;
      else {
        cout << "No\n";
        return 0;
      }
    }
  }
  if(over) {
    cout << "Yes\n";
    return 0;
  }
  if(uft.size(0) == n) {
    cout << "No\n";
  }
  else {
    cout << "Yes\n";
  }
}

Measured memory_bytes: 5244
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	char s[10];
	vector<int> v1;
	while(gets(s) && *s != '\0') {
		v1.push_back(atoi(s));
	}
	vector<int> v2;
	while(cin >> s) {
		if(find(v1.begin(), v1.end(), atoi(s)) != v1.end()) {
			v2.push_back(atoi(s));
		}
	}
	map<int, int> m;
	rep(i,v2.size()) {
		auto it = m.find(v2[i]);
		if(it == m.end()) {
			m.insert(make_pair(v2[i], 1));
		} else {
			it->second++;
		}
	}
	rep(i,v1.size()) {
		auto it = m.find(v1[i]);
		if(it != m.end()) {
			it->second++;
		}
	}
	for(auto it = m.begin(); it != m.end(); ++it) {
		cout << (*it).first << " " << (*it).second << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
#define OUT(a) {a=false;break;}
typedef long long ll;

int main(void){
  string S;cin >> S;
  bool check_AC = true;
  int i,count=0;
  REP(i,S.length()){
    if(S[i]>='a'&&S[i]<='z'){
      if(i==0) OUT(check_AC);
      continue;
    }else{
      if(i==0&&S[i]=='A')continue;
      else if(S[i]=='C'&&i>=2&&i<=S.length()-2)count++;
      else OUT(check_AC);
    }
  }
  if(count != 1)check_AC=false;
  if(check_AC) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, d, i;
	int b[10000];
	scanf("%d", &a);
	for (i = 0; i < a; i++)
	{
		scanf("%d", &b[i]);
	}
	d = a - 1;
	for (i = d; i >= 0; i--)
	{
		if (i > 0)
		{
			printf("%d ", b[i]);
		}
		else
		{
			printf("%d", b[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
using namespace std;
int main()
{
	char a[10001], b[10001];
	int n,t;
	cin >> n;
	cin >> a;
	while (n >= 26)
		n =n-26;
	for (int i = 0; a[i] != '\0'; ++i)
	{
		b[i] = a[i] + n;
		while(b[i] > 90)
		b[i] = b[i] - 26;
		
		t = i;
		
	}b[t + 1] = '\0';
	cout << b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  int A, B; cin >> A >> B;
  
  rep(i, 10100){
    int a, b;
    a = i*0.08; b = i*0.1;
    if(a == A && b == B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i < n; i++) cin >> v[i];
  sort(v.rbegin(), v.rend());
  int a=0, b=0;
  for(int i=0; i < n; i++) {
    if(i%2 ==0) a+=v[i];
    else b+=v[i];
  }
  cout << a-b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a==0) return b;
    if(b==0) return a;
    if(b>a) swap(a,b);
     return gcd(a%b,b);
}
int main()
{

    ll a,b,lc;
    cin>>a>>b;
    lc=(a*b)/gcd(a,b);
    cout<<lc<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100000

int partition(int *,int,int);

int main(){
  int n,i,a[N],p;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  p=partition(a,0,n-1);
  for(i=0; i<n-1; i++){
    if(i==p){
      printf("[%d] ",a[i]);
    }else{
      printf("%d ",a[i]);
    }
  }
  printf("%d\n",a[i]);
  return 0;
}

int partition(int *a,int p,int r){
  int x,i,j,t;
  x=a[r];
  i=p-1;
  //printf("x=%d,i=%d,p=%d,r=%d\n",x,i,p,r);
  for(j=p; j<r; j++){
    if(a[j]<=x){
      i++;
      t=a[i];a[i]=a[j];a[j]=t;
    }
  }
  t=a[i+1];a[i+1]=a[r];a[r]=t;
  return i+1;
}



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

typedef long long ll;

int main()
{
	ll x;
  	cin >> x;
  	ll ansa = 0, ansb = 0;
 	for(ll i = 0; i < 1000; i++)
    {
    	for(ll j = 0; j < 1000; j++)
        {
        	if(pow(i, 5) - pow(j, 5) == x)
            {
            	ansa = i;
              	ansb = j;
              	break;
            }
          	else if(pow(i, 5) + pow(j, 5) == x)
            {
            	ansa = i;
              	ansb = 0 - j;
              	break;
            }
        }
    }
  	cout << ansa << ' ' << ansb << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 50;
vector<int> G[N];

int n,m,a,b,c;

const int D = 105;
bool dp[D][N][D];
bool vis[D][N][D];

bool dfs(int d, int p, int rem){
    if(rem==0){
        if(p == n-1) return true;
        if(d == 0) return false;
    }
    if(vis[d][p][rem]) return dp[d][p][rem];

    bool ret;
    if(rem==0){
        ret = true;
        ret &= dfs(d-1,p,a);
        ret &= dfs(d-1,p,b);
        ret &= dfs(d-1,p,c);
    }
    else{
        ret = false;
        for(int i:G[p]) ret |= dfs(d,i,rem-1);
    }

    vis[d][p][rem] = true;
    return dp[d][p][rem] = ret;
}

int main(){
    cin >>n >>m >>a >>b >>c;

    rep(i,m){
        int u,v;
        cin >>u >>v;
        --u;
        --v;
        G[u].pb(v);
    }

    const int LIM=100;
    for(int i=1; i<=LIM; ++i){
        if(dfs(i,0,0)){
            cout << i << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}



Measured memory_bytes: 4164
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
     
        char ch[200000],c;
        int N,i,ans=0;
        unordered_map<string, int> hash;
        cin>>N;
     
        unordered_map<string, int>:: iterator p;
        for(i=0;i<N;i++)
        {
            cin>>ch;
            hash[ch]++;
        }
        for (p = hash.begin(); p != hash.end(); p++)
        {
            //if(p->second != 0)
                ans++;
        } 
        cout<<ans;
      
       
        return 0;   
    }   

Measured memory_bytes: 17632
#include <iostream>

using namespace std;
typedef long long ll;
ll a[200010],fro[200010],bac[200010],dpfro[200010][2],dpbac[200010][2];
int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    if(n%2==0){
        ll ans1 = 0;
        dpfro[0][0] = 0; dpfro[0][1] = 0;
        dpfro[2][0] = a[0]; dpfro[2][1] = a[1];
        for(i=4;i<=n;i+=2){
            dpfro[i][0] = dpfro[i - 2][0] + a[i - 2];
            dpfro[i][1] = max(dpfro[i - 2][0],dpfro[i - 2][1]) + a[i - 1];
        }
        cout << max(dpfro[n][0],dpfro[n][1]) << endl;
    }else{
        dpfro[0][0] = 0; dpfro[0][1] = 0;
        dpfro[2][0] = a[0]; dpfro[2][1] = a[1];
        for(i=4;i<=n;i+=2){
            dpfro[i][0] = dpfro[i - 2][0] + a[i - 2];
            dpfro[i][1] = max(dpfro[i - 2][0],dpfro[i - 2][1]) + a[i - 1];
        }
        dpbac[n - 1][0] = 0; dpbac[n - 1][1] = 0;
        dpbac[n - 3][0] = a[n - 1]; dpbac[n - 3][1] = a[n - 2];
        for(i=n - 5;i>=0;i--){
            dpbac[i][0] = dpbac[i + 2][0] + a[i + 2];
            dpbac[i][1] = max(dpbac[i + 2][0],dpbac[i + 2][1]) + a[i + 1];
        }
        ll ans = -10000000000000000;
        for(i=0;i<n;i+=2){
            ans = max(ans,max(dpfro[i][0],dpfro[i][1]) + max(dpbac[i][0],dpbac[i][1]));
        }
        /*for(i=0;i<n;i++){
          cout << i << " " << dpfro[i][0] << " " << dpfro[i][1] << " " << dpbac[i][0] << " " << dpbac[i][1] << endl;
        }*/
        cout << ans << endl;
    }
}


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

#define rep(i,m) for(int i = 0; i < m; i++)
using ll =  long long;

int main(){
  int a,b,c;
  cin >>a >>b >>c;
  //aとbの最大公約数を求める
  int gcd = min(a,b);
  for(int i = gcd; i >= 0; i--){
    if(a%i==0&&b%i==0){
      gcd=i;
      break;
    }
  }
  if(c%gcd==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

int n;
std::vector<std::vector<std::vector<double>>> dp;

double rec(int i, int j, int k){
	if(dp[i][j][k] >= 0) return dp[i][j][k];
	if(i==0 && j==0 && k==0) return 0.0;

	double res = 0.0;
	if(i>0) res += rec(i-1, j, k) * i;
	if(j>0) res += rec(i+1, j-1, k) * j;
	if(k>0) res += rec(i, j+1, k-1) * k;
	res += n;
	res *= 1.0 / (i + j + k);

	return dp[i][j][k] = res;
}

int main(){
	std::cin >> n;
	int one = 0, two = 0, three = 0;
	for(int i=0; i<n; i++){
		int a;
		std::cin >> a;
		if(a == 1){
			one++;
		}else if(a == 2){
			two++;
		}else{
			three++;
		}
	}

	dp = std::vector<std::vector<std::vector<double>>>\
	(n+1, std::vector<std::vector<double>>(n+1, std::vector<double>(n+1, -1)));

	printf("%.10f \n", rec(one, two, three));
	return 0;
}

Measured memory_bytes: 216960
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
#define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	string s, t;
	cin >> s;
	cin >> t;

	ll ans = 0;
	int prev = -1;
	rep(i, t.length()) {
		int findPos = s.find(t[i], prev+1);
		if (findPos >= 0) {
			prev = findPos;
		} else {
			findPos = s.find(t[i]);
			if (findPos >= 0){
				prev = findPos;
				ans += s.length();
			} else {
				cout << -1 << endl;
				return 0;
			}
		}
		if (i == t.length()-1) {
			ans += findPos+1;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  switch (N % 10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    std::cout << "hon" << std::endl;
    break;

  case 0:
  case 1:
  case 6:
  case 8:
    std::cout << "pon" << std::endl;
    break;

  default:
    std::cout << "bon" << std::endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 3592
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

//main.cpp----------------------------


void solve();

ll n;
ll a[100100];

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];

  solve();

  return 0;
}

void solve() {
  ll cnt = 0;
  bool flag = true;
  bool p_flag = false;
  bool m_flag = false;
  ll now;

  for(int i=0; i<n-1; ++i) {
    now = a[i];
    if(flag) {
      if(now<a[i+1]) {
        p_flag = true;
        flag = false;
      }else if(now>a[i+1]) {
        m_flag = true;
        flag = false;
      }
    }else {
      if(p_flag) {
        if(now>a[i+1]) {
          p_flag = false;
          flag = true;
          cnt += 1;
        }
      }else if(m_flag) {
        if(now<a[i+1]) {
          m_flag = false;
          flag = true;
          cnt += 1;
        }
      }
    }
  }

  cout << cnt + 1 << endl;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys

N,M=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()

L=[]    #答えの配列の逆順
for _ in range(N):
    for m in range(M,0,-1):
        if 0<=N-m and S[N-m]=="0":
            L.append(m)
            N-=m
            break
    else:
        break
        
if N!=0:
    print -1
else:
    print " ".join(map(str,L[::-1]))


Measured memory_bytes: 41244
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<double> X(N);
	vector<string> U(N);
	double ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> U[i];
		if (U[i] == "BTC") {
			ans += X[i] * 380000.0;
		} else {
			ans += X[i];
		}
	}

	cout << ans << endl;
}

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

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


int main() {
    ll N,M; cin >> N >> M;

    if(N>M) swap(N,M);

    if(N>1) cout << (N-2) * (M-2) << endl;
    else if(M!=1) cout << M-2 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 3564
//
// Created by 永徳泰明 on 2019-01-12.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

char m[401][401] = {};
int r[401][401] = {};
int H, W;

ll wi = 0, bl = 0;

void dfs(int i1, int j1, int filln) {
    if (r[i1][j1] > 0) {
        return;
    }

    r[i1][j1] = filln;
    if (m[i1][j1] == '#') {
        bl++;
    } else {
        wi++;
    }
    rep(i, 4) {
        int ni = i1 + dy[i];
        int nj = j1 + dx[i];
        if (ni >= H || ni < 0 || nj >= W || nj < 0) {
            continue;
        }
        if (m[ni][nj] == m[i1][j1]) {
            continue;
        }

        dfs(ni, nj, filln);
    }
}

int main() {
    readFromInputFile();
    cin >> H >> W;
    rep(i, H) {
        string s;
        cin >> s;
        rep(j, W) {
            m[i][j] = s[j];
        }
    }

    fill(r, -1);
    int c = 1;
    ll sum = 0;

    rep(i, H) {
        rep(j, W) {
            wi = 0, bl = 0;
            dfs(i, j, ++c);
            sum += wi * bl;
        }
    }
//    rep(i, H) {
//        rep(j, W) {
//            if(r[i][j]==-1){
//                cout<<"#";
//            } else {
//                cout << r[i][j];
//            }
//        }
//        cout<<endl;
//    }


//    c=0;
//    rep(i, H) {
//        rep(j, W) {
//            sum += count(++c);
//        }
//    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 8576
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadLong;
            var M = cin.ReadLong;
            long[] A = new long[N];
            long[] B = new long[N];
            for(long i = 0; i < N; i ++)
            {
                A[i] = cin.ReadLong;
                B[i] = cin.ReadLong;
            }

            var drinkList = new List<Tuple<long, long>>();
            for (long i = 0; i < N; i++)
            {
                drinkList.Add(new Tuple<long, long>(A[i], B[i]));
            }
            drinkList.Sort((a, b) => a.Item1.CompareTo(b.Item1));

            long sumPrice = 0;
            long count = 0;
            long num = 0;

            while(count < M)
            {
                sumPrice += drinkList[(int)num].Item1 * drinkList[(int)num].Item2;
                count += drinkList[(int)num].Item2;
                num++;
            }

            var amari = count - M;
            sumPrice -= amari * drinkList[(int)num - 1].Item1;

            Console.WriteLine(sumPrice);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 20300
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mod 1000000007
#define mx 100001
using namespace std;
int main() {
	FIO;
	int H,W;
	cin>>H>>W;
	vector<vector<char>> vec(H,vector<char>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++) cin>>vec[i][j];
	}
	vector<vector<int>> dp(H,vector<int>(W));
	dp[0][0]=1;
	for(int i=1;i<H;i++){
		if(vec[i][0]=='#') dp[i][0]=0;
		else dp[i][0]=dp[i-1][0];
	}
	for(int j=1;j<W;j++){
		if(vec[0][j]=='#') dp[0][j]=0;
		else dp[0][j]=dp[0][j-1];
	}
	for(int i=1;i<H;i++){
		for(int j=1;j<W;j++){
			if(vec[i][j]=='#') dp[i][j]=0;
			else dp[i][j]=dp[i-1][j]+dp[i][j-1];
			if(dp[i][j]>=int(mod)) dp[i][j]-=mod;
		}
	}
	cout<<dp[H-1][W-1]<<endl;
	return 0;
}

Measured memory_bytes: 5248
from collections import deque
 
# BFSで通す
N, Q = map(int, input().split())  # N頂点, Q個の命令
 
G = [[] for _ in range(N)]
count = [0]*N
for i in range(N-1):  # 辺はN-1本
    a, b = map(lambda x: int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)
 
for i in range(Q):  # Q個の操作について
    p, x = map(int, input().split())
    count[p-1] += x
 
q = deque([0])
flag = [False]*N
 
while len(q):
    v = q.pop()
    flag[v] = True
    for e in G[v]:  # vを親にもつノードについてループを回す
        if flag[e]:  # 頂点eに到達済みであれば
            continue
        count[e] += count[v]  # それぞれの子たちに親の値を伝播させる
        q.append(e)
 
print(*count)

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

int main()
{
  int n;
  int min=1000000001;
  int max=0;
  cin>>n;
  int a;
  for(int i=0; i<n; i++)
  {
    cin>>a;
    if(a<min) min = a;
    if(a>max) max = a;
  }
  cout<<max-min<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#define int long long
using namespace std;
const int N=2e5+2;
const int inf=1e18+2;
int sum[N],revsum[N],ar[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,i,j,k,l,len,ans=-inf;
	cin>>len>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(i=1;i<=n;i++){
		sum[i]=sum[i-1]+ar[i];
		revsum[i]=revsum[i-1]+len-ar[i];
	}
	for(i=0;i<n;i++){
		if((i&1)){
			int j=n-(i+1)/2;
			k=j-(i-(i+1)/2);
			ans=max(ans,(sum[j]-sum[k-1])*2+2*(revsum[n]-revsum[j])-(len-ar[j+1]));
		}
		else{
			int j=n-i/2;
			k=j-i/2;
			ans=max(ans,2*(revsum[n]-revsum[j])+2*(sum[j]-sum[k-1])-ar[j]);
		}
	}
	//cout<<ans<<endl;
	for(i=1;i<=n;i++){
		ar[i]=len-ar[i];
	}
	for(i=1;i<=n/2;i++){
		swap(ar[i],ar[n-i+1]);
	}
	for(i=1;i<=n;i++){
		sum[i]=sum[i-1]+ar[i];
		revsum[i]=revsum[i-1]+len-ar[i];
	}
	for(i=0;i<n;i++){
		if((i&1)){
			int j=n-(i+1)/2;
			k=j-(i-(i+1)/2);
			ans=max(ans,(sum[j]-sum[k-1])*2+2*(revsum[n]-revsum[j])-(len-ar[j+1]));
		}
		else{
			int j=n-i/2;
			k=j-i/2;
			ans=max(ans,2*(revsum[n]-revsum[j])+2*(sum[j]-sum[k-1])-ar[j]);
		}
	}
	cout<<ans;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    
    for (int i = 0; i < H; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < W+2; i++) {
        cout << '#';
    }
    cout << endl;
    for (int i = 0; i < H; i++) {
        cout << '#' + a.at(i) + '#' << endl;
    }
     for (int i = 0; i < W+2; i++) {
        cout << '#';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/*
ID: Bipin Singh [bipinsingh061]
LANG: C++
TASK: gift1
*/
#include<bits/stdc++.h> 
using namespace std; 
#define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n"
#define int long long int

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



void dfs(int src , bool *vis , vector<int> v[] , int& ans)
{
	vis[src]=true;
	// cout<<src<<" ";
	++ans;
 
	for(auto it : v[src])
	{
		if(!vis[it])
			dfs(it,vis,v,ans);
	}
}

int mod=1e9+7 ;


void update(vector<int>& D, int l, int r, int x) 
{ 
    D[l] += x; 
    D[r + 1] -= x; 
}



int32_t main()
{
	inputoutput();


	int n,m;
	cin>>n;
	cin>>m;

	vector<int> v[200500];
	bool vis[200500];

	memset(vis,false,sizeof(vis));

	for(int i=1 ; i<=m ; ++i)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	// for(int i=1 ; i<=n ; ++i)
	// {
	// 	cout<<i<<"->";
	// 	for(auto it : v[i])
	// 		cout<<it<<" ";
	// 	cout<<"\n";
	// }
	int comp=0;

	// unordered_set<int> result;

	int sol=INT_MIN;

	for(int i=1 ; i<=n ; ++i)
	{
		if(!vis[i])
		{
			int ans = 0; 
			dfs(i,vis,v,ans);
			sol=max(sol,ans);
			++comp;
		}
	}


	cout<<sol;

	
	

    



	return 0;
}




Measured memory_bytes: 24076
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  string T = "CODEFESTIVAL2016";

  int ret = 0;
  rep(i,S.size()){
    if(S[i] != T[i]) ret++;
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const int INF = (1 << 28);
int n, k;
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k >> s;
    if (n == 1)
    {
        cout << 1 << "\n";
        return 0;
    }
    s = s.c_str();
    int count = 0;
    int count1 = 0;
    vector<p> c;
    while (true)
    {
        if (s[count1] == '0')
        {
            while (s[count1] == '0' && count1 < n)
            {
                count++;
                count1++;
            }
            c.push_back(make_pair(0, count));
        }
        else if (s[count1] == '1')
        {
            while (s[count1] == '1' && count1 < n)
            {
                count++;
                count1++;
            }
            c.push_back(make_pair(1, count));
        }
        if (count1 == n) break;
        count = 0;
    }
    int n1 = c.size();
    int ans = 0;
    int count0=0;
        int i = 0;
        int j=0;
        int sum=0;
        while (i<n1)
        {
            if(count0<k&&c[i].first==0){
                count0++;
                sum+=c[i].second;
                i++;
            }
            else if(count0==k&&c[i].first==0){
                if(c[j].first==0)count0--;
                sum-=c[j].second;
                j++;
            }
            else{
                sum+=c[i].second;
                i++;
            }
            ans=max(ans,sum);
        }
    cout << ans << "\n";
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b>=c){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;

  }    

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static StringBuilder text;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		text = new StringBuilder();
		scan.close();
		for(int i = 1;i <= n;i++){
			if(i % 3 == 0){
				text.append(" ").append(i);
			}else {
				if(process(i))
					text.append(" ").append(i);
			}
		}
		System.out.println(text.toString());
	}
	static boolean process(int i){
		if(i % 10 == 3){
			return true;
		}else{
			if(i / 10 == 0)
				return false;
			return process(i / 10);
		}
	}
}

Measured memory_bytes: 20300
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;

    return 0;
}

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

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

    long long n, mc = 0, t = 0;
    bool z = false;
    cin >> n;
    vector<long long> A(n);
    for(long long i = 0; i < n; i++){
        cin >> A[i];
        if(A[i] == 0) z = true;
        if(A[i] < 0) mc++;
        t += abs(A[i]);
    }
    if(mc % 2 == 0 or z){
        cout << t << endl;
    }else{
        long long mini = 1e9;
        for(int i = 0; i < n; i++){
            mini = min(mini, abs(A[i]));
        }
        cout << t - mini * 2 << endl;
    }

    return 0;
}

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

int main() {
    int a,b,x;
    cin >> a >> b >> x;
    if(a>x){
        cout << "NO" << endl;
    }
    else if(x-a<=b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N), AR(N);
  REP(i,N) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse_copy(A.begin(), A.end(), AR.begin());

  ll l = (1LL << 62) * -1;
  ll r = 1LL << 62;
  while ( l+1 < r ) {
    ll mid = (l + r) / 2;
    ll lnum = 0;
//    cout << "l: " << l << " , r: " << r << " , mid: " << mid << endl;
    REP(i,N-1) {
      int min_n, max_n;
      bool neg;
      if (A[i] < 0) {
        min_n = N-1; max_n = i+1; neg = true;
      } else {
        min_n = i+1; max_n = N-1; neg = false;
      }
      if ( A[i] * A[min_n] > mid ) {
        // A[i]との積の最小値よりも小さい場合は、0 個
      } else if ( A[i] * A[max_n] <= mid ) {
        // A[i]との積の最大値よりも大きい場合は、N-i-1 個
        lnum += N-i-1;
//        cout << "  + " << mid << " " << i << " " << max_n << " : " << lnum << endl;
      } else {
        int l1 = min_n;
        int r1 = max_n;
//        cout << "  * " << l1 << " " << r1 << endl;
        while( neg ? (l1 > r1+1) : (l1+1 < r1) ) {
          int mid1 = (l1+r1)/2;
//          cout << "  l1: " << l1 << " , r1: " << r1 << " , mid1: " << mid1 << endl;
          if (A[mid1] * A[i] <= mid ) {
            l1 = mid1;
          } else {
            r1 = mid1;
          }
        }
        lnum += (neg ? N-l1 : l1-i);
      }
//      cout << " - lnum " << lnum << endl;
    }
    if (lnum < K) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << r << endl;
}

  




Measured memory_bytes: 3328
#include<stdio.h>

int main(){
  int dog_or_cat;
  int cat;
  int result;
  int i;
  
  scanf("%d %d %d",&cat,&dog_or_cat,&result);
  
  for(i=0;i<=dog_or_cat;i++){
    if(cat + dog_or_cat < result){printf("NO\n");break;}
    if(cat > result){printf("NO\n");break;}
    
    if(cat + i == result){
      printf("YES\n");
      break;
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	a,b = map(int, io().split())
	if a==b:
		ret=2*a
	else:
		c=max(a,b)
		ret=2*c-1

	return ret

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var n, k, r, s, p int
	var t string
	fmt.Scan(&n)
	fmt.Scan(&k)
	fmt.Scan(&r)
	fmt.Scan(&s)
	fmt.Scan(&p)
	fmt.Scan(&t)

	score := map[byte]int{'r': p, 's': r, 'p': s}
	ans := 0

	for start := 0; start < k; start++ {
		i := start
		for i < n {
			l := 1
			for i+k < n && t[i+k] == t[i] {
				i += k
				l++
			}

			ans += (l+1)/2 * score[t[i]]
			i += k
		}
	}

	fmt.Println(ans)
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << floor(double((c+0.5))/a)*b <<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

H,W=map(int,input().split())

board=[]
check=[[None]*W for i in range(H)]
answer=0

for i in range(H):
  S=list(input())
  board.append(S)
  
def dfs(i,j,color):
  if not (0<=i<H and 0<=j<W):
    return 0,0
  if board[i][j]==color:
    return 0,0
  if check[i][j]:
    return 0,0
  
  check[i][j]=True
  black,white=0,0
  
  if board[i][j]=='#':
  	black+=1
  else:
    white+=1
 
  tempblack,tempwhite=dfs(i+1,j,board[i][j])
  black+=tempblack
  white+=tempwhite
  
  tempblack,tempwhite=dfs(i-1,j,board[i][j])
  black+=tempblack
  white+=tempwhite
  
  tempblack,tempwhite=dfs(i,j+1,board[i][j])
  black+=tempblack
  white+=tempwhite

  tempblack,tempwhite=dfs(i,j-1,board[i][j])
  black+=tempblack
  white+=tempwhite
  return black,white

for i in range(H):
  for j in range(W):
    black,white=dfs(i,j,"!")
    answer+=black*white
print(answer)

Measured memory_bytes: 140012
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int V, E;
struct edge { LL to, cost; };

typedef pair<LL, LL> PP;

LL d[100100]; //?????¢
vector<edge> vec[100100];

LL dijkstra() {
	for (int i = 0; i < 100100; i++)d[i] = LINF;
	priority_queue<PP, std::vector<PP>, std::greater<PP>> pq;
	d[100001] = 0;
	pq.push(make_pair(d[100001], 100001));//cost,to
	while (!pq.empty()) {
		PP p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
	return d[V - 1];
}

int k;
int tyolisa[101010], tyolisb[101010], tyolisc[101010];
int main() {
	cin >> V >> E >> k;
	int a, b, c;
	for (int i = 0; i < E; i++) {
		cin >> a >> b >> c;
		a--, b--;
		tyolisa[i] = a, tyolisb[i] = b, tyolisc[i] = c;
		vec[a].push_back(edge{ b,c });
		vec[b].push_back(edge{ a,c });
	}
	for (int i = 0; i < k; i++) {
		int t;
		cin >> t;
		t--;
		vec[100001].emplace_back(edge{ t,0 });
	}
	dijkstra();
	LL ans = 0;
	for (int i = 0; i < E; i++) {
		ans = max((d[tyolisa[i]] + d[tyolisb[i]] + tyolisc[i]) / 2 + ((d[tyolisa[i]] + d[tyolisb[i]] + tyolisc[i]) % 2 == 1 ? 1 : 0), ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 13040
n=int(input())
a=list(map(int,input().split()))

def search_common_divisor(x,y):
    if x<y:
        x,y=y,x
    while y!=0:
        x,y=y,x%y
    return x

def search_list_common_divisor(*numbers):
    b=[search_common_divisor(numbers[0],numbers[1])]
    for i in numbers:
        b.append(search_common_divisor(b[-1],i))
    return b[-1]

print(search_list_common_divisor(*a))

Measured memory_bytes: 14224
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	ll H, N;
	cin>>H>>N;
	ll sum=0;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		sum+=a;
	}
	if(H<=sum)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256