akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n + 1);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<int> parent(n + 1, -1);
    queue<int> q;
    q.push(1);
    parent[1] = 0;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto v : g[u]) {
            if (parent[v] == -1) {
                q.push(v);
                parent[v] = u;
            }
        }
    }

    bool ans = true;
    for (int i = 1; i <= n; ++i) {
        if (parent[i] == -1) {
            ans = false;
            break;
        }
    }
    if (!ans) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";
        for (int i = 2; i <= n; ++i) {
            cout << parent[i] << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 10060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        // https://atcoder.jp/contests/abc159/tasks/abc159_b
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            string result = "No";

            if (s.Length % 2 == 1 && new string(s.Reverse().ToArray()) == s)
            {
                string s1 = s.Substring(0, (s.Length - 1) / 2);
                if (new string(s1.Reverse().ToArray()) == s1)
                {
                    string s2 = s.Substring(((s.Length + 3) / 2) -1);
                    if (new string(s2.Reverse().ToArray()) == s2) result = "Yes";
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  string S;
  cin>>S;
  S[3]='8';
  cout<<S<<endl;
  return 0;
}


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

#define N 100000
#define INF 1000000
#define M 500000
#define O 0
#define I 1

typedef struct{
  int go, back, cost;
}Date;

int n,d[N];
Date a[M];
void root(int);

int main(){
  int i,j,u,k,c=O;
  scanf("%d",&n);
  for(i=O;i<n;i++) {
    scanf("%d%d",&u,&k);
    for(j=O;j<k;j++){
      a[c].back=u;
      scanf("%d%d",&a[c].go,&a[c].cost);
      c++;
    }
  }
  root(c);
  for(i=O;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return O;
}

void root(int b){
  int i,flag=I;

  for(i=O;i<n;i++){
    d[i]=INF;
  }
  d[O]=O;
  while(flag!=O){
    flag=O;
    for(i=O;i<b;i++){
      if(a[i].cost+d[a[i].back] < d[a[i].go]){
        d[a[i].go]=a[i].cost+d[a[i].back];
        flag=I;
      }
    }
  }
}



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

int main() {
  string s;
  cin >> s;
  vector<int> alp(26, 0);
  bool ans = true;
  for (int i = 0; i < s.size(); i++) {
    if (alp.at(s.at(i) - 'a') != 0) {
      ans = false;
    }
    alp.at(s.at(i) - 'a')++;
  }
  if (ans) {
    cout << "yes" << endl;
  }
  else {
    cout << "no" << endl;
  }
  return 0;
}


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

int main(void) 
{
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    ll tmp = 0;
    rep(i,n) cin >> a[i];

    rep(i,n)
    {
        ans += tmp%mod*a[i]%mod;
        tmp += a[i];
    }
    cout << ans%mod << endl;
    return 0;
}

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

int main(){
	int d;
	cin >> d;
	if(d==25) cout << "Christmas" << endl;
	if(d==24) cout << "Christmas Eve" << endl;
	if(d==23) cout << "Christmas Eve Eve" << endl;
	if(d==22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;

const int MAX_N = 100000;

int main() {
	char S[MAX_N + 1];
	cin >> S;

	int first_pattern = 0;
	int second_pattern = 0;
	int i = 0;
	while (S[i] != '\0') {
		if (i % 2 == 0) {
			if (S[i] == '0') first_pattern++;
			else second_pattern++;
		}
		else {
			if (S[i] == '1') first_pattern++;
			else second_pattern++;
		}
		i++;
	}
	int ans = min(first_pattern, second_pattern);
	cout << ans << endl;
}

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

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

    int n;
    cin >> n;
    ll dp[110][4][4][4] = {0}; //A0 C1 G2 T3
    ll mod = 1e9 + 7;
    rep(i, 4) rep(j, 4) rep(k, 4)
    {
        dp[3][i][j][k] = 1;
    }
    dp[3][0][2][1] = dp[3][2][0][1] = dp[3][0][1][2] = 0;

    forx(c, 3, n)
    {
        rep(i, 4) rep(j, 4) rep(k, 4)
        {
            dp[c + 1][j][k][0] += dp[c][i][j][k] % mod;
            dp[c + 1][j][k][3] += dp[c][i][j][k] % mod;
            if (j != 0 || k != 1)
                dp[c + 1][j][k][2] += dp[c][i][j][k] % mod;
            if (j == 2)
            {
                if (i == 0 || k == 0)
                    continue;
            }
            if (k == 2)
            {
                if (i == 0 || j == 0)
                    continue;
            }
            dp[c + 1][j][k][1] += dp[c][i][j][k] % mod;
        }
    }
    ll ans = 0;
    rep(i, 4) rep(j, 4) rep(k, 4)
    {
        ans += dp[n][i][j][k] % mod;
    }
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

vector<int> graph[100005];
vector<int> revgraph[100005];
vector<bool> root(100005);

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

  int n; cin >> n;
  vector<ll> a(n);
  vector<ll> sum(n+1);
  rep(i, n) {
    cin >> a[i];
    sum[i+1] = sum[i] + a[i];
  }

  ll dp[n+1][n+1];

  rep(i, n+1) {
    rep(j, n+1) {
      dp[i][j] = 0;
    }
  }

  for(int i=1; i<=n; i++) {
    dp[i][i] = 0;
  }
  for(int i=1; i<n; i++) {
    dp[i][i+1] = a[i-1] + a[i];
  }

  for(int i=2; i<n; i++) {
    for(int j=1; j<=n; j++) {
      if (j+i > n) continue;
      ll mi = LONG_MAX;
      for(int k=0; k+1<=i; k++) {
        mi = min(mi, dp[j][j+k] + dp[j+k+1][j+i]);
      }
      dp[j][j+i] = mi + sum[j+i] - sum[j-1];
      //cerr << j << ' ' << j+i << ' ' << dp[j][j+i] << endl;
    }
  }

  cout << dp[1][n] << endl;
}

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

#define N 100

int main(void)
{
    char s[N] = "\0";
    char t[N] = "\0";
    char c;

    gets(s);
    gets(t);

    int i;
    int j;
    for (i = 0;i < N && s[i] != '\0';i++) {
        for (j = i + 1;j < N && s[j] != '\0';j++) {
            if (s[i] > s[j]) {
                c = s[i];
                s[i] = s[j];
                s[j] = c;
            }
        }
    }
    for (i = 0;i < N && t[i] != '\0';i++) {
        for (j = i + 1;j < N && t[j] != '\0';j++) {
            if (t[i] < t[j]) {
                c = t[i];
                t[i] = t[j];
                t[j] = c;
            }
        }
    }

    if (strcmp(s, t) < 0) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}

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

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;

  if (a+b==15) {
    cout << "+" << endl;
  } else if (a*b==15) {
    cout << "*" << endl;
  } else {
    cout << "x" << endl;
  }
  
  return 0;
}


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

int main() {
    int n, c[10000], minx = 1000001, maxx = -1000001;
    long long int sum = 0;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < n; i++) minx = min(minx, c[i]);
    for (int i = 0; i < n; i++) maxx = max(maxx, c[i]);
    for (int i = 0; i < n; i++) sum += c[i];
    printf("%d %d %lld\n", minx, maxx, sum);
    return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define Nmax 100005
#include <cmath>
#include <vector>

using namespace std;

const long long INF=1e18l;
ifstream f("1.in");
ofstream g("1.out");
//dp[i]= minimum weight with exactly value i
int main()
{
    int n, W;
    cin >> n >> W;
    vector <int> weight(n), value(n);
    for (int i = 0; i < n; i++)
        cin >> weight[i] >> value[i];

    int sum_value=0;
    for (auto i:value) sum_value+=i;

    vector <long long> dp(sum_value+1, INF);
    dp[0]=0;

    for (int i = 0; i < n; i++)
    {
        for (int value_already=sum_value-value[i]; value_already >= 0; value_already--)
            dp[value_already+value[i]]=min(dp[value_already+value[i]], dp[value_already]+weight[i]);
    }
    long long ans=0;
    for (int i = 0; i <= sum_value; i++)
    {
        if(dp[i]<=W) ans=max(ans, 1ll*i);

    }

    cout << ans;

}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int a;
    cin>>a;
    if(a/10==9 || a%10==9){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
ll gcd(ll a,ll b){
	if(b==0)
	return a;
	return gcd(b,a%b);
}
string toBin(ll a) {
	string res = "";
	while (a) {
		res += char((a & 1) + '0');
		a >>= 1;
	}
	reverse(res.begin(), res.end());
	return res;
}
const int mod = 1e9+7;
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){
            ans = ans*base;
            ans = ans%mod;
        }
        base *= base;
        base%=mod;
        pow/=2;
    }
    return ans;
}
ll inv(ll x){
    return expo(x,mod-2);
}
bool isPal(string ss){
    int len = ss.length();
    for(int i = 0 ; i<len/2 ; i++){
	int comp = len-i-1;
	if(ss[i]!=ss[comp])
		return false;
	}
    return true;
}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
/* -------Template ends here-------- */

const int M = 100001;

int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ll arr[3];
    int o = 0;
    for(int i = 0 ; i<3 ; i++){
        sll(arr[i]);
        if(arr[i]%2 == 0){
            o = 1;
        }
    }

    if(o){
        cout<<"0";
            return 0;
    }
    sort(arr , arr+3);
    ll ans = arr[0]*arr[1];
    cout<<ans;

















}














Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

ll gcd(ll x, ll y)
{
    while (y > 0)
    {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

int main(int argc, char const *argv[])
{
    ll k;
    cin >> k;
    ll ans = 0;
    for (ll a = 1; a <= k; a++)
    {
        for (ll b = 1; b <= k; b++)
        {
            for (ll c = 1; c <= k; c++)
            {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3620
s = input()
t = input()
n = len(s)
now = -1
count = 0
if set(t) <= set(s):
  for i in t:
    now = s.find(i,now+1)
    if now == -1:
      count += 1
      now = s.find(i)
  print(now + 1 + count*n)
else:
  print(-1)

Measured memory_bytes: 3444
import std.stdio, std.algorithm, std.array, std.string, std.conv, std.container;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

void main() {
    int x, y; readf("%d %d\n",&x,&y);
    writeln(x + y / 2);
}


Measured memory_bytes: 256
K,N=map(int,input().split())
a=list(map(int,input().split()))
j=N-1
d=K+a[0]-a[N-1]
for i in range(N-1):
	td=a[i+1]-a[i]
	if td>d:
		d=td
		j=i
print(K-d)

Measured memory_bytes: 26420
let input = '';

process.stdin.on('data', (chunk: any) => {
  input += chunk;
});

process.stdin.on('end', () => {
  const args = normalize(input);
  main(args[0], args[1]);
});

function main(n: number, ps: number[]): void {
  const median = (array: number[]) => {
    if (array.length % 2 !== 0) throw new Error('Array should be even');
    const halfIndex = Math.floor(array.length / 2);
    const temp = array.sort((a, b) => a - b);
    return (temp[halfIndex - 1] + temp[halfIndex]) / 2;
  };
  const m = median(ps);
  if (ps.indexOf(m) !== -1) {
    console.log(0);
    return;
  }
  const sorted = [...ps, m].sort((a, b) => a - b);
  const medianIndex = sorted.findIndex(val => val === m);
  if (medianIndex === 0 || medianIndex === n) {
    console.log(0);
    return;
  }

  const diff = sorted[medianIndex + 1] - sorted[medianIndex - 1];
  const linear = Array.from(new Array(diff - 1), (_, k) => k).map(n => n + m).length;
  const extention = [-1, 1].filter(k => {
    return ps.filter(p => p >= sorted[medianIndex + k]).length === n / 2;
  }).length;
  console.log(linear + extention);
}

function normalize(input: any): [number, number[]] {
  const inputs = input.toString().split('\n');
  const n = Number(inputs[0]);
  const ps = inputs[1].split(' ').map((p: string) => Number(p));
  return [n, ps];
}



Measured memory_bytes: 30500
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
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 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n), b(n);
	vector<int>c(m), d(m);
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	rep(i, m) {
		cin >> c[i] >> d[i];
	}
	rep(i, n) {
		int ans = INF;
		rep(j, m) {
			int res = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			ans = min(ans, res);
		}
		rep(j, m) {
			int res = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (res == ans) {
				cout << j + 1 << endl;
				break;
			}
		}
	}
	return 0;
}


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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> st(h);

  for(int i=0;i<h;i++) {
    cin >> st[i];
  }

  bool flag=true;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      int count=0;
      if(st[i][j]=='#') {
        if(i+1<=h-1 && st[i+1][j]=='#') count++;
        if(j+1<=w-1 && st[i][j+1]=='#') count++;
        if(i-1>=0 && st[i-1][j]=='#') count++;
        if(j-1>=0 && st[i][j-1]=='#') count++;
        
        if(count==0) {
          flag=false;
          break;
        }
      }
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int group(int x){
	if(x==2) return 0;
	else if(x==4||x==6||x==9||x==11) return 1;
	else return 2;
}

int main(){
	ll x, y;
	cin >> x >> y;
	cout << (group(x)==group(y)?"Yes":"No") << endl;
    return 0;
}

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

int main(){
	int i,j,max,gcd,lcm;
	int a,b;

	while(scanf("%d %d", &a,&b)!=EOF){
		if(a<b) max=b;
		else max=a;
		gcd=lcm=1;
		for(i=2;i<a+b/2;i++){
			while(a%i==0 && b%i==0){
				gcd*=i;
				lcm*=i;
				a=a/i;
				b=b/i;
			};
		}
		lcm=lcm*a*b;
		printf("%d %d\n",gcd,lcm);
	}
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int main(){
    int A,N,sum=0,max=0;
    cin >> N;
    REP(i,N){
        cin >> A;
        sum += A;
        max = std::max(A,max);
    }
    cout << ( (max * 2 >= sum) ? "No" : "Yes" )<< endl;
    return 0;
}

Measured memory_bytes: 256
local n=io.read("*n")
local works={}
for i=1,n do
    works[i]={io.read("*n","*n")}
end
table.sort(works,function(a,b)
    return a[2]<b[2]
end)

local total=0
for i=1,n do
    total=total+works[i][1]
    if total>works[i][2] then
        print("No")
        return
    end
end
print("Yes")

Measured memory_bytes: 14844
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long
#define INF 1000000000

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

	if(d==22)cout << "Christmas Eve Eve Eve" << endl;
	if(d==23)cout << "Christmas Eve Eve" << endl;
	if(d==24)cout << "Christmas Eve" << endl;
	if(d==25)cout << "Christmas" << endl;

	return 0;

}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
   	int n;
   	cin>>n;
   	double sum=0;
   	while(n--)
   	{
   		double x; cin>>x;
   		sum+=(1/x);
   	}
   	sum=1/sum;
   	cout<<fixed<<setprecision(8)<<sum<<"\n";

}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	int ans=0;
	range(i,1,n-1){
		if((v[i-1]<v[i]&&v[i]<v[i+1])|(v[i-1]>v[i]&&v[i]>v[i+1]))ans++;
	}
	puta(ans);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <iomanip>
#include <math.h>
const int MOD = 1000000007;
 
 
ll POWER(ll x,ll y)
{
	ll ret=1;
	ll p=x;
	for (ll i=y;i>0;i/=2)
	{
		if (i%2) ret=(ret*p)%MOD;
		p=(p*p)%MOD;
	}
	return ret;
}
ll gcm(ll a, ll b)
{
	if (b>a) {ll c=a; a=b; b=c;}
	while (b>0)
	{
		ll r=a%b;
		a=b;
		b=r;
	}
	return a;
}
const double PI =3.14159265358979323846264338327950288;
 
 
int main(int argc, char *argv[])
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;

	double d=(2*PI*(h+m/60)/12-2*PI*m/60);
	cerr<<d*180/PI<<endl;
	double ret=sqrt(a*a+b*b-2*a*b*cos(d));

	cout<<setprecision(20)<<ret<<endl;
 
	return 0;
}


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

using namespace std;

using ll = long long;
const ll INF = 1e18L + 5;

void max_self(ll &a, ll b)
{
    a = max(a, b);
}

void min_self(ll &a, ll b)
{
    a = min(a, b);
}

int main(void)
{
    int n, w;
    scanf("%d%d", &n, &w);
    vector<int> weight(n), value(n);

    for(int i=0; i < n; ++i)
        scanf("%d%d", &weight[i], &value[i]);
    
    int sum_value = 0;
    for(int x: value) {
        sum_value += x;
    }

    vector<ll> dp(sum_value + 1, INF);
    dp[0] = 0;
    for(int i=0; i < n; ++i) {
        for(int value_already = sum_value - value[i]; value_already >= 0; --value_already) {
            min_self(dp[value_already + value[i]], weight[i] + dp[value_already]);
        }
    }

    ll ans = 0;
    for(int i=0; i <= sum_value; ++i) {
        if (dp[i] <= w)
            ans = max(ans, (ll) i);
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 1024
def main():
  n = int(input())
  a = [0]
  b = [0]
  c = [0]

  for i in range(n):
      aa,bb,cc = map(int,input().split())
      a.append(max(b[i] + aa, c[i] + aa))
      b.append(max(a[i] + bb, c[i] + bb))
      c.append(max(a[i] + cc, b[i] + cc))

  print(max(a[-1], b[-1], c[-1]))

main()

Measured memory_bytes: 14996
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>

using namespace std;

typedef pair<int, int> P;
#define FOR(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define _1 first
#define _2 second
#define pb push_back
#define bigmod 1000000007
#define INF 1050000000

const int maxn = 1e5 + 10;
vi G[maxn];
int n, m, u, v;
int a,b;

int main() {

	cin >> n >>a>>b;

	if (abs(n - a) < abs(n - b)) cout << "A" << endl;
	else cout << "B" << endl;
	
	return 0;
}

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

using namespace std;

int main(){
    int n, x = 0, max = 0;
    string s;

    cin >> n >> s;

    for(int i = 0; i < n; i++){
        if(s[i] == 'I'){
            x++;
        }else{
            x--;
        }
        if(max < x) max = x;
    } 
    
    cout << max << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	for(int i = 0; i < s.length(); i++){
		s[i] = char((int(s[i] - 'A') + n) % 26 + 'A');
	}
	cout << s << endl;
}	

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int d = sc.nextInt();

		int[] c = new int[27];
		for ( int i=1; i<27; i++ ) {
			c[i] = sc.nextInt();
		}

		int[][] s = new int[d][27];
		for ( int i=0; i<d; i++ ) {
		for ( int j=1; j<27; j++ ) {
			s[i][j] = sc.nextInt();
		}
		}

		int[] last = new int[27];
		for ( int i=0; i<d; i++ ) {
			int t = 0;
			int man = -999999999;

			for ( int j=1; j<27; j++ ) {
				int manj = 0;
				for ( int k=1; k<27; k++ ) {
					if ( j==k ) {
						man += s[i][j];
					} else {
						man -= (c[j]*((i+1)-last[j]));
					}
				}

				if ( manj>man ) {
					man = manj;
					t = j;
				}
			}

			last[t] = i+1;
			System.out.println(t);
		}

	}
}

Measured memory_bytes: 46260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; //10^9

int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(),greater<int>());
    int Alice_point = 0;
    int Bob_point = 0;
    for (int i = 0; i < N; i++){
        if(i%2 == 0){
            Alice_point += a.at(i);
        }else{
            Bob_point += a.at(i);
        }
    }

    cout << Alice_point - Bob_point << endl;
}


Measured memory_bytes: 256
h, w=map(int, input().split())
t=[]
start=end="0"*(w+2)
t.append(start)
ans=[[0]*(w+2) for i in range(h+2)]

for i in range(h):
    s=input()
    new_string="0"+s+"0"
    t.append(new_string)

t.append(end)

for i in range(1, h+1):
    for j in range(1, w+1):
        if t[i][j]=="#":
            ans[i][j]="#"


for i in range(1,h+1):
    for j in range(1,w+1):
        if ans[i][j]=="#":
            if ans[i-1][j-1]!="#": ans[i-1][j-1]+=1
            if ans[i-1][j]!="#": ans[i-1][j]+=1
            if ans[i-1][j+1]!="#": ans[i-1][j+1]+=1
            if ans[i][j-1]!="#": ans[i][j-1]+=1
            if ans[i][j+1]!="#": ans[i][j+1]+=1
            if ans[i+1][j-1]!="#": ans[i+1][j-1]+=1
            if ans[i+1][j]!="#": ans[i+1][j]+=1
            if ans[i+1][j+1]!="#": ans[i+1][j+1]+=1

for i in range(1, h+1):
    for j in range(1, w+1):
        print(ans[i][j], end='')
    print()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() 
#define higher(v,x) high2way(v,x)-v.begin()-1 
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除

ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
string RLE(string s){
  ll n=s.size();
  char now='.';
  ll count=1;
  string press;
  loop(i,n){
    if(s[i]!=now){
      if(i){
        press+=now;
        press+=to_string(count);
      }
      now=s[i];
      count=1;
      continue;
    }
    else count++;
  }
  press+=now;
  press+=to_string(count);
  return press;
}
// index が条件を満たすかどうか
bool isOK(vec a,ll index,ll key) {
    if(a[index]>=key)return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(vec a,ll key) {
    ll ng=-1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ok=(ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(isOK(a,mid,key))ok=mid;
        else ng=mid;
    }
    return ok;
}

int main() {
  cout << fixed << setprecision(30);
  ll n,m;
  cin>>n>>m;
  vec a(n);
  vec b(m);
  vec c(m);
  loop(i,n)cin>>a[i];
  loop(i,m)cin>>b[i]>>c[i];
  vector<pair<ll,ll>> pairs(m);
  loop(i,m)pairs[i]=make_pair(c[i],b[i]);
  sort(all(pairs));
  reverse(all(pairs));
  loop(i,m){
    b[i]=pairs[i].second;
    c[i]=pairs[i].first;
  }
  ll now=0;
  sort(all(a));
  loop(i,m){
    loop(j,b[i]){
      if(a[now]>=c[i])goto skip;
      a[now]=c[i]; 
      now++;
    }
  }
  skip:
  putout(sum(a));
}

Measured memory_bytes: 4224
def kai(s):
    n = len(s)
    for i in range(n):
        if s[i]!=s[n-1-i]:
            return False
    return True

def main():
    S = input()
    N=len(S)
    if kai(S) and kai(S[:(N-1)//2]) and kai(S[(N+1)//2]):
        return "Yes"
    return "No"

print(main())

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

void chmin(int& a, int b) {
    a = min(a, b);
}

int main(void) {
    int L;cin>>L;
    int A[L];
    for (int i=0;i<L;i++) cin>>A[i];
    int dp[L+1][5];
    for(int i=0;i<=L;i++) for(int j=0;j<5;j++) dp[i][j]=1e9;
    dp[0][0] = 0;
    for(int i=0;i<L;i++) {
        int pre=dp[i][0];
        int diff;
        for(int j=0;j<5;j++){
            // 遷移元の最小を探す。この書き方だと、preのjは求めるj以下に必ずなる
            chmin(pre, dp[i][j]);
            if(j==0 || j==4) {
                diff = A[i];
            } else if(j==1 || j==3) {
                diff = (A[i]==0 ? 2 : A[i]%2);
            } else {
                diff = (A[i]+1)%2;
            }
            chmin(dp[i+1][j], pre+diff);
        }
    }
    int ans = dp[L][0];
    for(int j=1;j<5;j++) chmin(ans, dp[L][j]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

char a[10];
char b[10];
int count;

int main(void)
{
	scanf("%s", a);
	scanf("%s", b);
	
	for(int i = 0 ; i < 3 ; i++)
	{
		if(a[i] == b[i])
			count++;
	}
	
	printf("%d", count);
	return 0;
}

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

bool is[10];

bool iss(int n)
{
	while(n)
	{
		if(is[n%10])
		{
			return false;
		}
		n/= 10;
	}
	return true;
}

int main()
{
	int n,k;
	cin >> n >> k;
	for(int i = 0;i<k;i++)
	{
		int x;
		cin >> x;
		is[x] = true;
	}
	for(int i = n;;i++)
	{
		if(iss(i))
		{
			cout<<i<<endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

def main():
    r1,c1,r2,c2=map(int,input().split())

    # MOD combination
    def cmb(n, r, mod=10**9+7):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    N = 10**6*2+2
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    def g(r,c):
        tmp=cmb(r+1+c+1,r+1)-1
        return tmp%mod

    ans=0
    ans+=g(r2,c2)
    ans-=g(r2,c1-1)
    ans-=g(r1-1,c2)
    ans+=g(r1-1,c1-1)
    ans%=mod
    print(ans)
main()

Measured memory_bytes: 224852
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[20];
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	if(n==1){
		printf("%s\n",s);
		return 0;
	}
	ll flag=1;
	rep(i,1,n)flag&=(s[i]=='9');
	printf("%lld\n",(n-1)*9+(s[0]-48)-1+flag);
}

Measured memory_bytes: 128
h, w = map(int, input().split())

ds = []

for i in range(1, h):
  s1 = w*i
  s2 = (h-i)*(w//2)
  s3 = (h-i)*(w-w//2)
  d1 = max(s1, s2, s3) - min(s1, s2, s3)
  
  s1 = w*i
  s2 = w*((h-i)//2)
  s3 = w*(h-(h-i)//2-i)
  d2 = max(s1, s2, s3) - min(s1, s2, s3)
  
  if i == h-1:
    d = d1
  else:
    d = min(d1, d2)
  ds.append(d)

for i in range(1, w):
  s1 = h*i
  s2 = (w-i)*(h//2)
  s3 = (w-i)*(h-h//2)
  d1 = max(s1, s2, s3) - min(s1, s2, s3)
  
  s1 = h*i
  s2 = h*((w-i)//2)
  s3 = h*(w-(w-i)//2-i)
  d2 = max(s1, s2, s3) - min(s1, s2, s3)
  
  if i == w-1:
    d = d1
  else:
    d = min(d1, d2)
  ds.append(d)
  
print(min(ds))



Measured memory_bytes: 11032
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
     
import qualified Data.ByteString.Char8 as C
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
 
main = putStrLn . solve . C.lines =<< C.getContents
 
solve [_,ds,_,ts] = if ans then "YES" else "NO"
    where
        ds' = map (fst . fromJust . C.readInt) $ C.words ds
        ts' = map (fst . fromJust . C.readInt) $ C.words ts
        mp = foldl (\m x -> M.insertWith (+) x 1 m) M.empty ds'
        mp' = foldl (\m x -> M.insertWith (+) x (-1) m) mp ts'
        ans = (minimum $ M.elems mp') >= 0

Measured memory_bytes: 68988
n = int(input())
test_list = [[[int(i) for i in input().split()] for j in range(int(input()))] for k in range(n)]

man_list = [[int(j) for j in bin(i)[2:].zfill(n)] for i in range(2**n)]

ans = 0
bad = 0

for man in man_list:
  for j in range(n):
    if man[j] == 1:
      for k in test_list[j]:
        x = k[0] - 1
        y = k[1]
        if man[x] != y:
          bad = 1
          break
    if bad == 1:
      bad = 0
      break
  else:
    ans = max(ans, sum(man))

print(ans)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
	string s;
	int64 cnt = 0;
	int64 res = 0;
	cin >> s;
	REP(i, s.size()) {
		if (s[i] == '(') cnt++;
		else if (s[i] == ')') cnt--;
		else res += cnt;
	}
	cout << res << endl;
}



Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int main(){
    int num;
    int s[3];
    int balls = 0;
    cin >> num;
    s[2]=num%10;
    s[1]=((num%100) - s[2])/10;
    s[0]=(num -s[2]-10*s[1])/100;
    for(int i=0;i<3;i++){
        if(s[i]==1) balls = balls+1; 
    }
    cout << balls << endl;

}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;
    vector<f64> p(n);
    for (auto& e : p) cin >> e;

    vector<f64> dp(n + 1);
    dp[0] = 1;
    for (i64 i = 0; i < n; i++) {
        for (i64 j = n; j > 0; j--) {
            dp[j] += dp[j - 1] * p[i];
            dp[j - 1] *= 1 - p[i];
        }
    }

    cout << accumulate(begin(dp) + (n + 1) / 2, end(dp), 0.0) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;
int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> cnt(N, 1);
    vector<int> check(N, 0);
    check[0] = 1;

    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;

        if (check[x]) check[y] = 1;
        if (cnt[x] == 1) check[x] = 0;
        cnt[x]--, cnt[y]++;
    }

    int ans = 0;
    rep(i, N) {
        if (check[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int q = Integer.parseInt(sc.nextLine());
            int MIN_LENGTH = 1;
            int MAX_LENGTH = 1000;
            while (sc.hasNext()) {
                String x = sc.nextLine();
                String y = sc.nextLine();
                if (x.length() < MIN_LENGTH || x.length() > MAX_LENGTH
                    || y.length() < MIN_LENGTH || y.length() > MAX_LENGTH) {
                    System.out.println("Conditions is invalid.");
                    return;
                }
                System.out.println(getLCS(x, y));
            }
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static int getLCS(String x, String y) {
        if (x.isEmpty() || y.isEmpty()) {
            return 0;
        }
        if (x.equals(y)) {
            return x.length();
        }
        if (x.contains(y)) {
            return y.length();
        }
        char[] xs = x.toCharArray();
        char[] ys = y.toCharArray();
        int m = x.length();
        int n = y.length();
        int[][] c = new int[m + 1][n + 1];
        for (int i = 1; i <= m; i++) {
            c[i][0] = 0;
        }
        for (int i = 1; i <= n; i++) {
            c[0][i] = 0;
        }

        int maxl = 0;
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if (xs[i - 1] == ys[j - 1]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = Integer.max(c[i - 1][j], c[i][j - 1]);
                }
                maxl = Integer.max(maxl, c[i][j]);
            }
        }
        return maxl;
    }
}



Measured memory_bytes: 63964
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
      cout.precision(10);
      cout << fixed;
   }
} iofix;

void solve(){
   int64_t A, B, C, K; cin >> A >> B >> C >> K;
   while(K--){
      if(B <= A)
         B *= 2;
      else if(C <= B)
         C *= 2;
      else  break;
   }
   if(B > A && C > B)
      cout << "Yes";
   else 
      cout << "No";
}

int main(){

   	solve();

#ifndef Time
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}

Measured memory_bytes: 3796
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[200011];
int dp[200011];
char ans[200011];

void MAIN() {
    scanf("%s", S);
    N = strlen(S);

    dp[0] = 0;
    REP (i, N) {
	amax(dp[i+1], dp[i]);
	if (S[i] != 'P') amax(dp[i+1], dp[i]+1);
	if (S[i] != 'D' && S[i+1] != 'P') amax(dp[i+2], dp[i]+2);
    }

    for (int i=N; i>0; ) {
	if (dp[i] == dp[i-1]) {
	    ans[i-1] = (S[i-1] == '?'? 'D': S[i-1]);
	    i--;
	} else if (S[i-1] != 'P' && dp[i] == dp[i-1]+1) {
	    ans[i-1] = 'D';
	    i--;
	} else if (dp[i] == dp[i-2]+2) {
	    ans[i-1] = 'D';
	    ans[i-2] = 'P';
	    i -= 2;
	}
    }
//    eprintf("%d\n", dp[N]);
//    eprintf("%s\n", S);
    puts(ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 4936
#include<iostream>
#define MAXN 400+15
using namespace std;
int a[MAXN][MAXN]={0},n,m,rst = 0x3f3f3f;
bool used[MAXN];
void dfs(int step);
int main(){
  long long  n,m,k;
  cin>>n>>m>>k;
  int  flag = 1;
  for(int i = 0 ;i < k;i++){
    if(flag){
      if(n % 2 != 0){
        n -= 1;
      }
      m += n /2;
      n /= 2;
      flag = 0 ;
    }else{
      if(m % 2 != 0 ){
        m -= 1;
      }
      n += m/2;
      m /= 2 ;
      flag = 1;
    }
  }
  cout<<n<<" "<<m<<endl;
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 1000;
const int MAX_W = 10000;
int dp[MAX_N+1][MAX_W+1];
int v[MAX_N];
int w[MAX_N];
int W, N;
int c;
int cnt;

int main()
{
  while((cin >> W) && W){
    cin >> N;
    rep(i, N) scanf("%d,%d", &v[i], &w[i]);

    rep(i, N) erep(j, 0, W) dp[i][j] = 0;
    rev(i, N) erep(j, 0, W){
      if(j < w[i]) dp[i][j] = dp[i+1][j];
      else dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
    }

    cout << "Case " << ++cnt << ":" << endl;
    cout << dp[0][W] << endl;
    rev(i, W) if(dp[0][i+1] > dp[0][i]){
      cout << i + 1 << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 38564