akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string s;
int flag;
int ____;
int ___;
int main()
{
	cin>>s;
	long long len=s.length();
	for(int i=0;i<len;i++)
	if(s[i]=='C')
	{
		___=i;	
		flag=1;
		continue;
	}
	if(flag==0)
	{
		cout<<"No"<<endl;
		return 0;
	}
	else
	{
		for(int __=___;__<len;__++)
		{
			if(s[__]=='F')
			{
				____=1;
				continue;
			}	
		}
	}
	if(____==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  
  if(A>=10 || B>=10) cout<<-1<<endl;
  else cout<<A*B<<endl;
}

Measured memory_bytes: 764
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let s: String = read();
    let mut tp: u32 = 0;
    for c in s.chars() {
        if c == 'p' {
            tp += 1;
        }
    }
    let ap: u32 = s.len() as u32 / 2;
    println!("{}", ap - tp);
}


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

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

  if (S == "keyence" || S.substr(0,7) == "keyence" || S.substr(S.size()-7,7) == "keyence") {
    cout << "YES" << endl;
    return 0;
  }

  vector<vector<string>> v = {
    {"k", "eyence"},
    {"ke", "yence"},
    {"key", "ence"},
    {"keye", "nce"},
    {"keyen", "ce"},
    {"keyenc", "e"},
  };

  string ans = "NO";
  rep(i,0,v.size()-1) {
    string l = v[i][0];
    string r = v[i][1];
    bool lok = false, rok = false;
    if (S.substr(0,l.size()) == l && S.substr(S.size()-r.size(),r.size()) == r) {
      ans = "YES";
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout << " >> " << #x << " "<<x<<endl;
vector< vector<int> > adj(2*1e5+2);
vector<int> parent(2*1e5+2);
vector<int> visited(2*1e5+2);
vector<int> value(2*1e5+2);
int N;
void dfs(int node,int par)
{
    value[node]  +=  value[par];
    visited[node] = 1;
    for(auto i : adj[node])
    {
        if( ! visited[i])
        {
            dfs(i,node);
        }
    }
}
void Solve_Case()
{
   cin >> N;
   int Q;
   cin >> Q;
   for(int i=1;i<N;i++)
   {
       int x,y;
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
   }

    while(Q--)
    {
        int node,val;
        cin >> node >> val;
        value[node]  +=  val;
    }

              dfs(1,0);

      for(int node = 1;node<=N;node++)
        cout << value[node] << " ";


}
signed main()
{
    int TestCases = 1;

    while(TestCases--)
    {
        Solve_Case();
    }
	return 0;
}


Measured memory_bytes: 24320
S=list(input())

nS=[]
i=0
while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
  i+=1
    
t=[]
nl=[]
for i in nS:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[]
if nl:
  t.append(nl)


ans=0
for i in t:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1

print(ans)


Measured memory_bytes: 62028
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll x,y; cin>>x>>y;
    cout<<x + y/2 <<endl;
    
    return 0;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
A=[]
for i in range(N):
  d=list(map(int, input().split()))
  A.append(d)
S=[1]*M
num=[0]*N
ans=N
for i in range(M):
  cnt=[0]*M
  for j in range(N):
    d=A[j][num[j]]
    while S[d-1]==0:
      num[j]+=1
      d=A[j][num[j]]
    cnt[d-1]+=1
  e=max(cnt)
  ans=min(e,ans)
  f=cnt.index(e)
  S[f]=0
print(ans)


Measured memory_bytes: 10284
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
/* テンプレートここまで */

int main() {
  ll a,b; string s;
  cin >> a >> s >> b;
  if(s=="+") cout << a+b << endl;
  else cout << a-b << endl;
}


Measured memory_bytes: 256
import sys
import bisect


def main():
    n, K, L, R = map(int, sys.stdin.readline().split())
    a = tuple(map(int, sys.stdin.readline().split()))
    m = n//2+1
    ls = [[] for _ in range(m+1)]
    for i in range(1 << m):
        cnt = 0
        val = 0
        for j in range(m):
            if i >> j & 1:
                cnt += 1
                val += a[j]
        ls[cnt].append(val)
    for i in range(m+1):
        ls[i].sort()
    ans = 0
    for i in range(1 << n-m):
        cnt = 0
        val = 0
        for j in range(n-m):
            if i >> j & 1:
                cnt += 1
                val += a[m+j]
        if K-m <= cnt <= K:
            ans += bisect.bisect_right(ls[K-cnt], R-val) - bisect.bisect_right(ls[K-cnt], L-val-1)
    print(ans)


if __name__ == '__main__':
    main()



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

class AOJ
{
    static void Main()
    {
        int w = int.Parse(Console.ReadLine());
        int n = int.Parse(Console.ReadLine());
        int[] line = Enumerable.Range(1, w).ToArray();
        for (int i = 0; i < n; i++)
        {
            int[] input = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
            int a = input[0] - 1;
            int b = input[1] - 1;
            int temp = line[a];
            line[a] = line[b];
            line[b] = temp;
        }
        foreach (var item in line)
        {
            Console.WriteLine(item);
        }
    }
}


Measured memory_bytes: 18332
import sys
readline=sys.stdin.readline

N = int(readline())

DIV = 10 ** 9 + 7

# dp[i][j][k] = i - 1桁目で、すでに0が出た(j), すでに9が出た(k)

dp = [[[0] * 2 for j in range(2)] for i in range(N + 1)]

dp[0][0][0] = 1

for i in range(1, N + 1):
  dp[i][0][0] += dp[i - 1][0][0] * 8 # まだ0も9も出ない
  dp[i][0][0] %= DIV
  
  dp[i][1][0] += dp[i - 1][0][0] # 0が出た
  dp[i][1][0] += dp[i - 1][1][0] * 9 # 9以外何が出てもよい
  dp[i][1][0] %= DIV
  
  dp[i][0][1] += dp[i - 1][0][0] # 9が出た
  dp[i][0][1] += dp[i - 1][0][1] * 9 # 0以外何が出てもよい
  dp[i][0][1] %= DIV
  
  dp[i][1][1] += dp[i - 1][1][0] # 9が出た
  dp[i][1][1] += dp[i - 1][0][1] # 0が出た
  dp[i][1][1] += dp[i - 1][1][1] * 10 # 何が出てもよい
  dp[i][1][1] %= DIV
  
print(dp[-1][1][1])

Measured memory_bytes: 356644
#include <stdio.h>
main(){
  int i,j,n1,n2,S[10000],T[500],count=0,a;
  scanf("%d",&n1);
  for(i = 0; i < n1; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&n2);
  for(i = 0; i < n2; i++){
    scanf("%d",&T[i]);
  }
  for(i = 0; i < n2; i++){
    a=0;
    for(j = 0; j < n1; j++){
      if(a == 0){
        if(T[i] == S[j]){
        count++; 
        a++;
        break;
	}
      }
    }
  }
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 640
a=int(input())
f=a//100
b=a%100
if 1<=f<=12 and 1<=b<=12:
    print("AMBIGUOUS")
elif 1<=f<=12 and 12<b:
    print("MMYY")
elif b==0 and 1<=f<=12:
    print("MMYY")
elif 1<=b<=12 and 12<f:
    print("YYMM")
elif 1<=b<=12 and f==0:
    print("YYMM")
else:print("NA")

Measured memory_bytes: 3060
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int maxn=5e5+5;
char s[maxn],ch;
set<int> pos[26];
int n,t,opt,x,y;
int main(){
    scanf("%d %s %d",&n,s+1,&t);
    for(int i=0;i<=25;i++){
        pos[i].insert(n+1);//防止二分为空
    }
    for(int i=1;i<=n;i++){//放入相应的set
        pos[s[i]-'a'].insert(i);
    }
    while(t--){
        scanf("%d",&opt);
        if(opt==1){
            scanf("%d %c",&x,&ch);
            if(s[x]!=ch){
                pos[s[x]-'a'].erase(x);//删除
                pos[ch-'a'].insert(x);//加入
                s[x]=ch;
            }
        }else{
            scanf("%d %d",&x,&y);
            int ans=0;
            for(int i=0;i<=25;i++){
                if(*pos[i].lower_bound(x)<=y){
                    ans++;
//                    printf("111111111 ");
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 24192
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n;
	cin>>n;
	int *A = new int[n];
	int *B = new int[n];
	int left,right;
	int index1 = n/2 - 1;
	int index2 = n/2;
	for(int i = 0; i < n; i++){
		cin>>A[i];
		B[i] = A[i];
	}
	sort(A,A + n);
	left = A[index1];
	right = A[index2];
	for(int i = 0 ; i < n; i++){
		if(B[i] <= left){
			cout<<right<<endl;
		}else{
			cout<<left<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3712
n=int(input())
a_list = list(map(int,input().split()))

a_tmp = a_list[0]

sum = 0
for i in range(1, len(a_list)):
    if a_tmp > a_list[i]:
        sum += a_tmp - a_list[i]
    else:
        a_tmp = a_list[i]

print(sum)

Measured memory_bytes: 32284
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}


int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n,m,d,t;
	unordered_map<int,int> ds,ts;
	cin >> n;
	for(int i=0;i < n; ++i) {
		cin >> d;
		ds[d]++;
	}
	cin >> m;
	for(int i=0;i<m;++i) {
		cin >> t;
		if(ds[t]) {
			--ds[t];
		} else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 8520
import collections
n=int(input())
a=list(input().split())
c=collections.Counter(a)
ans=0
for v in c.values():
  ans+=v*(v-1)//2
for i in range(n):
  v=c[a[i]]
  print(ans+((v-1)*(v-2)//2)-(v*(v-1)//2))


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

int main(void){
int N,Q;string s;
cin>>N;cin>>Q;cin>>s;
s+=s;
int same_l;
vector<int>v;

for(int i=1;i<=N/2;i++){
	if(N%i==0){v.push_back(i);}
}

for(int i=0;i<Q;i++){
int pi;char c;int iwa=0;
cin>>pi;cin>>c;

if(i>=1 && s[pi-1]==c){
cout<<same_l<<endl;continue;
}else{
	s[pi-1]=c;
	s[N+pi-1]=c;
}

for(int l=0;l<v.size();l++){
		iwa=0;
		for(int m=0;m<=N/2;m++){
			if(s[m]!=s[m+v[l]]||s[N-m-1]!=s[N-m+v[l]-1]){iwa=1;break;}
		}
			if(iwa==0){cout<<v[l]<<endl;;iwa=100;same_l=v[l];break;}
	}
	if(iwa!=100){same_l=N;cout<<N<<endl;}
}

return 0;
}



Measured memory_bytes: 3340
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Integer N = Integer.parseInt(sc.nextLine());
        String[] VN = sc.nextLine().split(" ");

        int[] values = new int[N];
        for (int i = 0; i < N; i++) {
            values[i] = Integer.parseInt(VN[i]);
        }

        Arrays.sort(values);

        // 貪欲法で解いていく
        double ans = mix(values, N);
        System.out.println(ans);
    }

    private static double mix(int[] values, int N) {

        double tmp = values[0];
        for (int i = 1; i < N; i++) {
            double v = values[i];

            tmp = (tmp + v) / 2;
        }
        return tmp;
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
#define mod 1000000007
long long exp(long long taban, long long us) {
    long long carpan = taban;
    long long temp = us;
    long long res = 1;
    while(temp > 0){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (((a*b)%mod)*(exp(ebob(a,b), (ll)mod-2))) % mod;
}
/*int level[100005];
int parent[100005][20];
vector<vector<int>> vec(100005);
void fonk(int cur, int dont){
	level[cur] = level[dont] + 1;
	parent[cur][0] = dont;
	for(int i = 1; i < 20; i++){
		parent[cur][i] = parent[parent[cur][i - 1]][i-1];
	}
	for(int i = 0; i < vec[cur].size(); i++){
		if(vec[cur][i] != dont) fonk(vec[cur][i], cur);
	}
}

int lca(int n1, int n2){
	int ans = -1;
	if(level[n2] > level[n1]){
		swap(n1, n2);
	}
	while(level[n1] > level[n2]){
		for(int i = 0; i < 20; i++){
			if(level[parent[n1][i]] >= level[n2]){
				n1 = parent[n1][i];
			}else break;
		}
	}
	if(n1 == n2) return n1;
	while(parent[n1][0] != parent[n2][0]){
		int tmp1, tmp2;
		for(int i = 0; i < 20; i++){
			if(parent[n1][i] != parent[n2][i]){
				tmp1 = parent[n1][i];
				tmp2 = parent[n2][i];
			}else break;
		}
		n1 = tmp1, n2 = tmp2;
	}
	return parent[n1][0];
}

int dist(int n1, int n2){
	return level[n1] + level[n2] - 2*level[lca(n1, n2)];
}*/
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	map<string, int> mp;
	int nax = 0;
	while(n--){
		string s; cin>>s;
		mp[s]++;
		nax = max(nax, mp[s]);
	}
	for(auto x: mp){
		if(x.second == nax) cout<<x.first<<"\n";
	}
}


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

int min(int a, int b){
    return (a<b)?a:b;
}

int main(void){
    int N;
    scanf("%d", &N);
    int head = 0;
    int tail = 0;
    int head_tail = 0;
    int count = 0;
    for(int i = 0; i < N; i++){
        char s[11];
        scanf("%s", s);
        if(s[0] == 'B') head += 1;
        if(s[strlen(s)-1] == 'A') tail += 1;
        if(s[0] == 'B' && s[strlen(s)-1]== 'A') head_tail += 1;
        for (int j = 0; j < strlen(s)-1; j++){
            
            if (s[j] == 'A' && s[j + 1] == 'B'){
                count += 1;
            }
        }
    }
    if(head_tail != 0 && head == head_tail && tail == head_tail){
        count -= 1;
    }
    count += min(head, tail);
    printf("%d\n", count);
    return 0; 
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;
class Main{
    static int pare[];
    static int root(int v){
        if(pare[v]<0)return v;
        return pare[v]=root(pare[v]);
    }
    static void unite(int u, int v){
        u=root(u);
        v=root(v);
        if(u==v)return;
        if(pare[u]<pare[v]){
            int tmp=u;
            u=v;v=tmp;
        }
        pare[v]+=pare[u];
        pare[u]=v;
    }
    static boolean same(int u, int v){
        return root(u)==root(v);
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M =scan.nextInt();
        int p[] = new int[N+1];

        pare = new int[N+1];
        Arrays.fill(pare, -1);
        for(int i=0;i<N;++i)p[i+1]=scan.nextInt();
        while(M-->0){
            int x = scan.nextInt();
            int y = scan.nextInt();
            unite(x,y);
        }
        int cnt = 0;
        for(int i=N;i>=1;--i){
            if(same(i, p[i]))++cnt;
        }
        System.out.println(cnt);

    }
}

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

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

    int n;
    cin >> n;

    int max_profit = numeric_limits<int>::min();
    int min_value = numeric_limits<int>::max();

    for (int x; cin >> x;) {
        int p = x - min_value;
        if (max_profit < p)
            max_profit = p;
        if (x < min_value)
            min_value = x;
    }

    cout << max_profit << endl;

    return 0;
}


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

int main() {
    int n,k;
    cin >> n>>k;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    sort(p.begin(),p.end());
    int ans=0;
    rep(i,k){
        ans+=p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#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 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(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll 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 sum(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));}
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>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
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;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
vl sieve_of_eratosthenes(int n) {
  vl primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll m,a,b;

	vl p,plist=sieve_of_eratosthenes(100000);
	rep(i,100000){
		if(plist[i])p.push_back(i);
	}


	while(cin>>m>>a>>b, m+a+b){
		ll ans=0, aw=2, ah=99991;
		rep(hind,p.size()){
			ll h=p[hind];
			ll mw = min(m/h,h);
			if(mw<2)break;

			ll wc = upper_bound(all(p),mw) - p.begin();
			ll w=p[wc-1];
			
			if(w*b>=a*h){
				if(chmax(ans, w*h)){
					aw=w, ah=h;
				}
			}
		}
		puta(aw,ah);
	}

	return 0;
}


Measured memory_bytes: 3784
s = input()
acgt = ["A","C","G","T"]
ans = 0
for i in range(len(s)+1):
	for l in range(1,len(s)+1):
		t = s[i:l].replace("A","").replace("C","").replace("G","").replace("T","")
		if len(t) == 0:
 			if len(s[i:l]) > ans:
	  			ans = len(s[i:l])
		
print(ans)

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;



template<typename T>
struct Segtree{
    int n;
    T op;
    vector<T> elm;
    function<T(T, T)> f;

    Segtree(int n, T init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n, init),
        f(f)
    {
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    Segtree(int n, vector<T> init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n),
        f(f)
    {
        for(int i = 0; i < n; ++i)
            elm[i + n] = init[i];
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    void set(int x, T val){
        x += n;
        elm[x] = val;
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    void update(int x, T val){
        x += n;
        elm[x] = f(val, elm[x]);
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    T get(int x, int y) const{
        T l = op, r = op;
        for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){
            if(x & 1)
                l = f(l, elm[x++]);
            if(!(y & 1))
                r = f(elm[y--], r);
        }
        return f(l, r);
    }
};


signed main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<pair<int,int>> init(n + 1);
    for(int i = 0; i <= n; ++i)
        init[i] = make_pair(MOD, i);
    init.back() = make_pair(0, n);
    vector<int> prev(n + 1, -1);
    Segtree<pair<int,int>> seg(n + 1, init, [](auto x, auto y){return min(x, y);}, make_pair(MOD, MOD));
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == '1')
            continue;
        int to = min(n + 1, i + k + 1);
        auto p = seg.get(i + 1, to);
        prev[i] = p.second - i;
        seg.set(i, make_pair(p.first + 1, i));
    }
    int ans = seg.get(0, 1).first;
    if(ans >= 1e9){
        cout << -1 << endl;
        return 0;
    }
    int t = 0;
    while(t != n){
        cout << prev[t];
        int nex = t + prev[t];
        if(nex == n){
            cout << endl;
        }else
            cout << " ";
        t = nex;
    }
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())

cha = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
       "W", "X", "Y", "Z"]

for i in range(len(S)):
    print(cha[(cha.index(S[i]) + N) % 26],end="")



Measured memory_bytes: 43376
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll N,X=0;
  cin>>N;
  for(int i=0;i<N;i++){
    ll a;
    cin>>a;
    X+=a;
  }
  cout<<X-N;
return 0;}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  int a,b;cin>>a>>b;
  if(a<b) cout<<0<<endl;
  else cout<<10<<endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600
#define EPS 1e-8

// ???????°???°???????????????
inline double add(double a, double b){
  if(abs(a+b) < EPS*(abs(a) + abs(b))) return 0;
  return a+b;
}

struct Point{
  double x,y;
  Point() {}
  Point(double nx, double ny) : x(nx), y(ny) {}
  Point operator + (const Point & p){ return Point(add(x, p.x), add(y, p.y)); }
  Point operator - (const Point & p){ return Point(add(x,-p.x), add(y,-p.y)); }
  Point operator * (double d){ return Point(x*d, y*d); }
  double dot(const Point & p){ return add(x * p.x, y*p.y); }  //??????
  double det(const Point & p){ return add(x * p.y, -y*p.x); } //??????
  double dist(const Point & p){ return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  bool operator < (const Point & p) const {
    if(y != p.y) return y < p.y;
    else return x < p.x;
/*
    if(x != p.x) return x < p.x;
    else return y < p.y;
    */
  }
};

// Graham Scan
// ???????????????????¨?????????§return
// ???????????????????????????
vector<Point> convexHull(vector<Point> points){
  int n = points.size();
  sort(all(points));
  int k=0;
  vector<Point> qs(n+1);
  rep(i,n){
    while(k>1 && (qs[k-1] - qs[k-2]).det(points[i] - qs[k-1]) < 0) k--;
    qs[k++] = points[i];
  }
  for(int i=n-2,t=k; i>=0; i--){
    while(k>t && (qs[k-1] -qs[k-2]).det(points[i] - qs[k-1]) < 0) k--;
    qs[k++] = points[i];
  }
  qs.resize(k-1);
  return qs;
}

int main(){
  int n;
  cin>>n;
  vector<Point> vec(n);
  rep(i,n){
    double x, y;
    scanf("%lf %lf", &x, &y);
    vec[i] = Point(x,y);
  }
  vector<Point> conv = convexHull(vec);

  printf("%d\n", conv.size());
  rep(i,conv.size()){
    printf("%.0f %.0f\n", conv[i].x, conv[i].y);
  }

  return 0;
}

Measured memory_bytes: 7640
#include<stdio.h>
#include<string.h>
typedef long long LL;
const int MAX=1e5;
int main()
{
    char a[MAX+5];
    scanf("%s",a);
    LL la=strlen(a);
    LL count1=0,count2=0;
    for(LL i=0;i<la;i++){
        if(a[i]=='0'){
            count1++;
        }
        else{
            count2++;
        }
    }
    if(count1>count2){
        printf("%lld\n",count2*2);
    }
    else{
        printf("%lld\n",count1*2);
    }
    return 0;
}


Measured memory_bytes: 256
# 配列の要素数
num = int(input())

# 配列
array = list(map(int, input().split()))

def print_array():
    for i in range(num):
        if i != num-1:
            print(array[i], end=' ')
        else:
            print(array[i])


# insertion sort
for i in range(num):
    insert = array[i]
    j = 0
    while array[j] < insert:
        j+=1
    for k in range(i, j, -1):
        array[k] = array[k - 1]
    array[j] = insert
    print_array()



Measured memory_bytes: 5984
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;




int main() {
	int r, c, k;
	cin >> r >> c >> k;

	int n = 3;
	vector<vector<int>> g(r, vector<int>(c));
	for (int i = 0; i < k; i++) {
		int ri, ci, v;
		cin >> ri >> ci >> v;
		ri--;
		ci--;

		g[ri][ci] = v;
	}

	vector<vector<vector<ll>>> dp(r + 1, vector<vector<ll>>(c + 1, vector<ll>(n+1)));

	for (int i = 1; i <= r; i++) {


		for (int j = 1; j <= c; j++) {

			dp[i][j][0] = dp[i][j - 1][0];
			for (int l = 0; l <= n; l++) {
				dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][l]);
			}

			for (int l = n; l > 0; l--) {

				dp[i][j][l] = max(dp[i][j - 1][l], max(dp[i][j - 1][l - 1], dp[i][j][l - 1]) + g[i - 1][j - 1]);

			}


		}
	}

	/*
	for (vector<vector<ll>> dpi : dp) {
		
		for (vector<ll> dpij : dpi) {
			ll ans = 0;
			for (ll dpijl : dpij) {
				ans = max(ans, dpijl);
			}

			cout << ans << " ";
		}

		cout << endl;
	}
	*/

	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ans = max(ans,dp[r][c][i]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 671980
# coding : utf-8

N = int(input())

# 素数かどうか判定する関数
def is_prime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1

    return True

ans = []

n = 2
# できた数列のうちどの5つの要素を選んだ場合でも、その合計が素数でないという条件がある
# 5つ選ぶため、全要素が「5で割って1余る数であれば、余り(１*5)%5==0 で合計は５で割り切れる合成数となる
while len(ans) < N:
    if is_prime(n) and n % 5 == 1:
        ans.append(n)

    n += 1

print(' '.join(map(str, ans)))


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
ll powmod(ll x, ll y)
{
  ll res = 1;
  for (ll i = 0; i < y; i++)
  {
    res = res * x % MOD;
  }
  return res;
}
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = -INF, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> ma;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> a >> b >> c >> n;
  ans = max(max(a * c, a * n), max(b * c, b * n));
  out(ans);
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

Measured memory_bytes: 3656
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();        
        int M = stdIn.nextInt();        
        stdIn.close();

        if (N == M) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int n,a,b;
VI construct(int n,int a,int b) {
	if (n==1) {
		return VI{a,b};
	}
	b^=a;
	int sep=-1;
	rep(i,0,n) if (b&(1<<i)) {
		sep=i;
		break;
	}
	VI p=construct(n-1,0,1);
	VI q=construct(n-1,1,(b^(1<<sep))>>1);
	VI r;
	rep(i,0,SZ(p)) {
		int a=p[i]>>sep,b=p[i]&((1<<sep)-1);
		r.pb((a<<(sep+1))+b);
	}
	rep(i,0,SZ(q)) {
		int a=q[i]>>sep,b=q[i]&((1<<sep)-1);
		r.pb((a<<(sep+1))+(1<<sep)+b);
	}
	rep(i,0,SZ(r)) r[i]^=a;
	return r;
}

int main() {
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	if (__builtin_parity(a^b)==0) {
		puts("NO");
		return 0;
	}
	VI r=construct(n,a,b);
	puts("YES");
	rep(i,0,SZ(r)) printf("%d ",r[i]); puts("");
}

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

   if(N<105) System.out.println(0);
   else if(N<135) System.out.println(1);
   else if(N<165) System.out.println(2);
   else if(N<189) System.out.println(3);
   else if(N<195) System.out.println(4);
   else System.out.println(5);
 }
}

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

/* define const */
/* end up defineing const */

int main()
{
  int N;
  string S;
  cin >> N;
  cin >> S;

  int n = N;//S.length();
  int max = 0;
  //  cout << n << S << endl;
  for (int i = 1; i < n; i++) {
    int tmp = 0;
    int a[32] = {}; // 前半
    int b[32] = {}; // 後半
    for (int j = 0; j < i; j++) {
      a[S[j]-'a']++;
      //      cout << S[j];// << endl;
    }
    //    cout << "\n";
    
    for (int j = i; j < n; j++) {
      b[S[j]-'a']++;
      //      cout << S[j];
    }
    //    cout << "\n";
    
    for (int j = 0; j < 26; j++) {
      if (a[j] && b[j]) tmp++;
      //      cout << a[j] << ", " << b[j] << endl;
    }

    if (tmp > max) max = tmp;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    P = [int(i) for i in input().split()]
    changed = False
    ans = 0
    for i, p in enumerate(P, start=1):
        if changed:
            changed = False
        elif i == p:
            changed = True
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53036
N, M = (int(x) for x in input().split())
s = [0]*M
c = [0]*M
for i in range(M):
  s[i], c[i] = [int(p) for p in input().split()]
 
n = [0]*N
 
for j in range(len(s)):
  if N > 1 and s[j] == 1 and c[j] == 0:
    print(-1)
    exit()
for p in range(len(s)):
  for q in range(len(s)):
    if p == q:
      continue
    else:
      if s[p] == s[q] and c[p] != c[q]:
        print(-1)
        exit()		
for k in range(M):
  l = s[k]
  n[l-1] = c[k]
if N > 1 and n[0] == 0:
  n[0] = 1
resstr = [str(x) for x in n]
res = "".join(resstr)
result = int(res)   
print(result)


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

long long gcd(long long a, long long b)
{
    long long l=a,r=b;
    while(a%b!=0)
    {
        l = b;
        r = a%b;
        a = l;
        b = r;
    }
    return b;
}

int main()
{
    long long a,b;
    cin >> a >> b;
    cout << a*b/gcd(a,b) << endl;
}

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

int main(){
    int n;
    char c;
    int ans = 0;
    int max = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> c;
        if(c=='D')ans--;
        else ans++;
        if(ans>max)max=ans;
    }
    cout << max << endl;
    return 0;
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int a,b;
	while(cin>>a>>b){
		cout <<__gcd(a, b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=300005;
int n,Q,a[N];ll s[N],f[N],g[N],v[N];
int q[N],qr=0,r=0;
inline ll Y(ll *p,int i){
	return ((p[i]+s[i])<<1)-i+1ll*i*i;
}
inline ll calc(ll *p,int i,int j){
	return p[j]+(1ll*(i-j)*(i-j+1)>>1)+s[j]-s[i];
}
inline int midit(ll *p,int x){
	int L=1,R=r,mid,ret=L,lm,rm;
	while(L<R){
		mid=(L+R)>>1;
		lm=(L+mid)>>1;rm=(mid+1+R)>>1;
		if(calc(p,x,q[lm])<=calc(p,x,q[rm]))ret=rm,L=lm+1;
		else ret=lm,R=rm-1;
	}
	return ret;
}
inline void XL(ll *p){
	r=0;q[++r]=0;
	for(int i=1,t;i<=n;i++){
		s[i]=s[i-1]+a[i];
		t=q[midit(p,i)];
		p[i]=calc(p,i,t);
		p[i]=max(p[i],p[i-1]);
		while(r>1 && (Y(p,q[r])-Y(p,q[r-1]))*(i-q[r])<=(Y(p,i)-Y(p,q[r]))*(q[r]-q[r-1]))r--;
		q[++r]=i;
	}
}
int H=0;
inline void solve(int l,int r,ll *pre,ll *suf,ll *w){
	if(l==r){w[l]=1-a[l];return ;}
	int mid=(l+r+H)>>1;
	solve(l,mid,pre,suf,w);solve(mid+1,r,pre,suf,w);
	qr=0;q[++qr]=l-1;
	for(int i=l;i<=mid;i++){
		while(qr>1 && (Y(pre,q[qr])-Y(pre,q[qr-1]))*(i-q[qr])<=(Y(pre,i)-Y(pre,q[qr]))*(q[qr]-q[qr-1]))qr--;
		q[++qr]=i;
	}
	for(int i=mid+1;i<=r;i++){
		while(qr>1 && Y(pre,q[qr])-Y(pre,q[qr-1])<=1ll*(i<<1)*(q[qr]-q[qr-1]))qr--;
		v[i]=calc(pre,i,q[qr])+suf[i+1];
	}
	w[r]=max(w[r],v[r]);
	for(int i=r-1;i>mid;i--)v[i]=max(v[i],v[i+1]),w[i]=max(w[i],v[i]);
}
ll suf[N],pre[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	XL(f);
	reverse(a+1,a+n+1);
	XL(g);
	reverse(a+1,a+n+1);reverse(g+1,g+n+1);
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	solve(1,n,f,g,pre);
	reverse(a+1,a+n+1);reverse(f+1,f+n+1);reverse(g+1,g+n+1);
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	H=-1;solve(1,n,g,f,suf);
	reverse(suf+1,suf+n+1);reverse(a+1,a+n+1);
	reverse(f+1,f+n+1);reverse(g+1,g+n+1);
	scanf("%d",&Q);
	int x,y;
	while(Q--){
		scanf("%d%d",&x,&y);
		printf("%lld\n",max(f[x-1]+g[x+1],max(suf[x],pre[x])-y+a[x]));
	}
	return 0;
}


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


int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M, 0);
  
  rep(i, N) {
    int K;
    cin >> K;
    rep(j, K) {
      int k;
      cin >> k;
      a[k-1]++;
    }
  }
  int ans = 0;
  rep(i, M) {
    if(a[i] == N) {
      ans++;
    }
  }
  cout << ans << endl;
  
}

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

int bubble_sort(vector<int> &value, int num_value){
	int i, j, num_switch=0;
	bool flag_sorted=0;
	
	for(i=0; !flag_sorted; i++){
		flag_sorted = 1;
		for(j=num_value-1; j>=i+1; j--){
			// j-1要素がj要素より大きい場合，要素をスワップして
			// ソート完了フラグをfalseにする
			// 交換数も更新する
			if(value.at(j-1)>value.at(j)){
				swap(value.at(j-1), value.at(j));
				flag_sorted = 0;
				num_switch++;
			}
		}
	}
	
	return num_switch;
}

int main(){
	int num_value, i, num_switch;
	vector <int> value(max_num_value);
	
	cin >> num_value;
	for(i=0;i<num_value;i++){
		cin >> value.at(i);
	}
	
	// バブルソート
	num_switch = bubble_sort(value, num_value);
	
	// 出力
	for(i=0;i<num_value-1;i++){
		cout << value.at(i) << " ";
	}
	cout << value.at(num_value-1) << endl << num_switch << endl;
		
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    int h[n];
    vector<int> mx(n,1);
    rep(i,n) cin>>h[i];

    int ans=0;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        if(h[a-1]>=h[b-1]) mx[b-1]=0;
        if(h[a-1]<=h[b-1]) mx[a-1]=0;
    }

    rep(i,n) ans+=mx[i];

    cout<<ans<<endl;
}

Measured memory_bytes: 4024
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;
int H, W;

ll in(const pair<ll, ll> pos) {
  return (pos.first < H && pos.first >= 0) &&
         (pos.second < W && pos.second >= 0);
}

ll bfs(vector<vector<char>> vec, const pair<ll, ll> pos) {
  priority_queue<pair<ll, ll>> Q;
  if (in(pos) == false) {
    return 0;
  }
  vec[pos.first][pos.second] = 'x';

  for (int ni = -1; ni <= 1; ni++) {
    for (int nj = -1; nj <= 1; nj++) {
      if (in({pos.first + ni, pos.second + nj}) == false) {
        continue;
      }
      if (ni == 0 && nj == 0) {
        continue;
      }
      vec[pos.first + ni][pos.second + nj] = 'x';
      Q.push({pos.first + ni, pos.second + nj});
    }
  }

  ll sum = 0;

  while (!Q.empty()) {
    pair<ll, ll> p = Q.top();
    Q.pop();
    for (int ni = -1; ni <= 1; ni++) {
      for (int nj = -1; nj <= 1; nj++) {
        if (in({p.first + ni, p.second + nj}) == false) {
          continue;
        }
        if (vec[p.first + ni][p.second + nj] == 'x') {
          continue;
        }
        // cout << H << "," << W << "," << p.first + ni << "," << p.second + nj
        // << endl; cout << p.first + ni << "," << p.second + nj << endl;
        if (vec[p.first + ni][p.second + nj] == '#') {
          continue;
        }
        sum++;
        vec[p.first + ni][p.second + nj] = 'x';
        Q.push({p.first + ni, p.second + nj});
      }
    }
  }
  return sum;
}
int main() {
  cin >> H >> W;

  vector<vector<char>> mp(H, vector<char>(W, 0));
  for (size_t i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      mp[i][j] = s[j];
    }
  }

  vector<vector<ll>> col(H, vector<ll>(W, 0));
  vector<vector<ll>> row(H, vector<ll>(W, 0));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (mp[i][j] == '#') {
        row[i][j] = 0;
      } else if (j == 0) {
        row[i][j] = (mp[i][j] == '.');
      } else {
        row[i][j] += (row[i][j - 1]) + (mp[i][j] == '.');
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (mp[i][j] == '#') {
        col[i][j] = 0;
      } else if (i == 0) {
        col[i][j] = (mp[i][j] == '.');
      } else {
        col[i][j] += (col[i - 1][j]) + (mp[i][j] == '.');
      }
    }
  }

  for (int i = 0; i < H; i++) {
    ll pre = row[i][W - 1];
    for (int j = W - 1; j >= 0; j--) {
      if (row[i][j] == 0) {
        pre = 0;
      } else {
        pre = max(row[i][j], pre);
        row[i][j] = max(row[i][j], pre);
      }
    }
  }
  for (int i = 0; i < W; i++) {
    ll pre = col[H - 1][i];
    for (int j = H - 1; j >= 0; j--) {
      if (col[j][i] == 0) {
        pre = 0;
      } else {
        pre = max(col[j][i], pre);
        col[j][i] = pre;
      }
    }
  }

  ll sum = 0;
  for (size_t i = 0; i < H; i++) {
    for (size_t j = 0; j < W; j++) {
      sum = max(sum, max(0LL, col[i][j] + row[i][j] - 1));
    }
  }
  cout << sum << endl;
}

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

ll gcd(ll a, ll b){ 
	if (a == 0) 
	    return b;  
	return gcd(b % a, a);  
}	 
   
ll lcm(ll a, ll b)  
{  
	return (a*b)/gcd(a, b);  
}  

int main(){

	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = (b/c) + (b/d) - (b/lcm(c,d)) - ( ((a-1)/c) + ((a-1)/d) - ((a-1)/(lcm(c,d))) );
	cout<<(b+1-a-ans)<<endl;

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n-1),b(n,0);
    for(int i=0;i<n-1;i++){
        cin >> a.at(i);
        b.at(a.at(i)-1)++;
    }
    for(int i=0;i<n;i++){
        cout << b.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SplitPile
{
    class Program
    {
        public Tuple<int, int> a = new Tuple<int, int>(1,3);
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var curdNums = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            var absDiffs = new long[num - 1];
            long xSum = curdNums[0];
            long ySum = curdNums.Sum() - curdNums[0];
            absDiffs[0] = Math.Abs(xSum - ySum);

            for (int i = 1; i < absDiffs.Length; i++)
            {
                xSum += curdNums[i];
                ySum -= curdNums[i];
                absDiffs[i] = Math.Abs(xSum - ySum);
            }

            Console.WriteLine(absDiffs.Min());
        }

    }
}


Measured memory_bytes: 38212