akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define no cout<<"NO"<<endl;
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define mod 1000000007
#define gcd(x,y) __gcd(x, y)
using namespace std;
map<ll,ll>mp;
int main()
{
	ll n;
	cin>>n;
	ll a[n],i;
	ll sum=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		mp[a[i]]++;
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll x,y;
		cin>>x>>y;
		sum+=(y-x)*mp[x];
		mp[y]+=mp[x];
		mp[x]=0;
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 10268
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int n,k;
    cin>>n>>k;
    vector<ld> p(n+1);
    for(int i=0;i<n;i++){
        ld a;
        cin>>a;
        p[i+1]=p[i]+(a+1)/2.0;
    }
    ld ans=0;
    for(int i=k;i<=n;i++){
        ans=max(ans,p[i]-p[i-k]);
    }
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 6408
#include <iostream>
#include <algorithm>
#define INF 1001001001001001
using namespace std;
typedef long long ll;

ll dp[20010];
ll ary[20010];
int main(){
	ll N,M,K;
	cin>>N>>M>>K;
	for(int i=1;i<=N;i++){
		cin>>ary[i];
	}
	/*
	fill(dp[0],dp[0]+N+1,INF);
	fill(dp[1],dp[1]+N+1,INF);
	dp[0][0]=0;
	int in=0,ou=1;
	ll res=INF;
	for(int i=0;i<N;i++){
		fill(dp[ou],dp[ou]+N+1,INF);
		ll cnt,ma,mi;
		for(int j=0;j<N;j++){
			cnt=0;ma=0;mi=INF;
			for(int k=1;k<=M&&j+k<=N;k++){
				ma=max(ma,ary[j+k]);
				mi=min(mi,ary[j+k]);
				dp[ou][j+k]=min(dp[ou][j+k],dp[in][j]+K+k*(ma-mi));
			}
		}
		res=min(res,dp[ou][N]);
		swap(in,ou);
	}
	*/
	fill(dp,dp+N+1,INF);
	dp[0]=0;
	for(int i=0;i<N;i++){
		ll ma=0,mi=INF;
		for(int j=1;j<=M&&i+j<=N;j++){
			ma=max(ma,ary[i+j]);
			mi=min(mi,ary[i+j]);
			dp[i+j]=min(dp[i+j],dp[i]+K+j*(ma-mi));
		}
	}
	cout<<dp[N]<<endl;
	return 0;
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    string s;
    cin >> s;
    int n = s.size()+1;
    vector<int> a(n,0);
    for(int i = 0; i < s.size(); ++i) {
        if(s[i]=='<') a[i+1] = a[i]+1;
    } 
    for(int i = s.size()-1; i>=0; i--){
        if(s[i]=='>') a[i] = max(a[i], a[i+1]+1);
    }
    ll sum = 0;
    rep(i,n) sum += a[i];
    cout << sum << endl;
    return 0;
}

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

using namespace std;
using LL = long long;

const LL MAX = 1e9;

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

    if (n <= MAX) {
        printf("0 0 0 1 %lld 0\n", n);
    } else {
        LL d = (n + MAX - 1) / MAX;
        printf("0 0 %lld 1 %lld %lld\n", MAX, MAX * d - n, d);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION


struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

//SOLVE
void solve(void)
{
  int N,M,K;
  cin>>N>>M>>K;
  UnionFind UF = UnionFind(N);
  vector<pair<int,int> > C(M);
  for (int i = 0; i < M; i++)
  {
    cin>>C[i].first>>C[i].second;
    C[i].first--;C[i].second--;
    UF.unite(C[i].first,C[i].second);
  }
  // DEBUG(UF.data);
  vector<int> ANS (N,0);
  for (int i = 0; i < N; i++)
  {
    ANS[i] = UF.size(i) -1;
  }
  for (int i = 0; i < M; i++)
  {
    int A,B;
    A = C[i].first;
    B = C[i].second;
      ANS[A]--;
      ANS[B]--;
  }

  for (int i = 0; i < K; i++)
  {
    int A,B;
    cin>>A;
    cin>>B;
    A--;
    B--;
    if(UF.find(A) == UF.find(B))
    {
      ANS[A]--;
      ANS[B]--;
    }
  }
  
  for (int i = 0; i < N; i++)
  {
    if(i!= 0)cout<<" ";
    cout<<ANS[i];
  }
  cout<<endl;

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}

//vc alp(26) ={'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'};
//cout<<""<<endl;
int main(){
  int A,B;string S;cin>>A>>B>>S;
  bool ok=true;
  rep(i,S.size()){
    if(i==A){
      if(S[i]!='-')ok=false;
    }
    else{
      if(S[i]=='-'){
        ok=false;
      }
    }
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

bool isprime(ll x){
  for(ll i=2;i*i<=x;i++){
    if(x%i==0) return 0;
  }
  return 1;
}

int main(){
  ll i,j;
  ll n,m;
  cin>>n>>m;

  map<ll,ll> p;
  for(i=2;i*i<=m;i++){
    if(isprime(i)){
      while(m%i==0){
        m=m/i;
        p[i]++;
      }
    }
  }
  if(m>=2) p[m]++;


//y+n-1Cn-1
  VVI y(35,VI(n+1));

  for(j=1;j<=n;j++) y[0][j]=1;
  for(i=0;i<35;i++) y[i][0]=0;
  
  for(j=1;j<=n;j++){
    for(i=1;i<35;i++){
      y[i][j]=y[i][j-1]+y[i-1][j];
      y[i][j]%=Mod;
    }
  }
  ll ans=1;
  for(auto it=p.begin();it!=p.end();++it){
    ans*=y[it->second][n];
    ans%=Mod;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 28416
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int fun(vector<int> &vis,int x,int n)
{
  int count=0;
  for(int i=1;i<=n;i++)
  {
    if(i>=x)
      break;
    if(vis[i]==0)
      count++;
  }

  return count;
}


int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
 // freopen("input.txt","r",stdin);
#endif

  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    cin>>b[i];
  }

  vector<ll> fac(n+1);

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

  vector<int> vis(n+1);

  ll rank1=0;

  for(int i=0;i<n;i++)
  {
    int count=fun(vis,a[i],n);
   
    rank1+=count*fac[n-i-1];

    vis[a[i]]=1;
  }

  rank1++;

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

  ll rank2=0;

  for(int i=0;i<n;i++)
  {
    int count=fun(vis,b[i],n);
    rank2+=count*fac[n-i-1];
    vis[b[i]]=1;
  }


  rank2++;


  cout<<abs(rank1-rank2)<<endl;


  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    int n;cin>>n;vector<string>v(n);rep(i,n)cin>>v.at(i);
    vector<vector<int>>A(26,(vector<int>(n,0)));
    rep(i,n){
        rep(j,v.at(i).size()){
            A.at(v.at(i).at(j)-97).at(i)++;
        }
    }
    int count=0;
    rep(i,26){
        rep(j,n){
            if(j==0)count=A.at(i).at(j);
            else count=min(count,A.at(i).at(j));
        }
        char x=i+97;
        rep(k,count)cout<<x;
    }
}

Measured memory_bytes: 256
n = int(input())
graph = [[] for _ in range(n)]

global time
global visited 
global f_time 
global e_time 

time = 1
visited = [0 for _ in range(n)]
f_time = [0 for _ in range(n)]
e_time = [0 for _ in range(n)]

def input_graph(n):
  for _ in range(n):
    node_id, num, *v = list(map(int, input().split()))
    for i in range(num):
      graph[node_id-1].append(v[i]-1)

def dfs(node_id):
  global time
  f_time[node_id] = time
  time += 1

  for ad_node in graph[node_id]:
    if visited[ad_node] == 1:
      continue
    visited[ad_node] = 1
    dfs(ad_node)

  e_time[node_id] = time
  time += 1



if __name__ == "__main__":
  input_graph(n)
  for i in range(n):
    if visited[i] == 1:
      continue
    visited[i] = 1
    dfs(i)

  for i, (f, e) in enumerate(zip(f_time, e_time)):
    print(i+1, f, e)
  
  


Measured memory_bytes: 5720
use std::io;
use std::collections::HashMap;

fn read() -> i32{
    let mut n = String::new();
     io::stdin().read_line(&mut n).unwrap();
     let n: i32 = n.trim().parse().unwrap();
     n
}
 
 fn main(){
    let n = read();
    let mut d = HashMap::new();

    for _i in 0..n{
        let key = read();
        match d.clone().get(&key){
            Some(_e) => continue,
            None => d.insert(key, 0),
        };
    }
    println!("{}", d.len());
 }

Measured memory_bytes: 4352
#include<stdio.h>

int main(void){

int a,b,c,d;


d=0;


scanf("%d %d %d",&a,&b,&c);


for(a;a<=b;a++){


if(c%a==0){


d=d+1;


}


}


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


return 0;


}

Measured memory_bytes: 596
n = int(input())
p = [int(i) for i in input().split()]
'''
i == x となる点で、i+1とスワップする
境界に注意
'''
ans = 0
for i in range(n):
    if i < n-1 and p[i] == i+1:
        p[i+1] = p[i]
        ans += 1
    elif i == n-1 and p[i] == i+1:
        ans += 1
print(ans)

Measured memory_bytes: 19980
from itertools import product
n, x, m = map(int, raw_input().split())
h = [map(int, raw_input().split()) for i in xrange(m)]
ans = [-1]
for p in product(range(x+1), repeat=n):
    for l, r, s in h:
        if s != sum(p[l-1:r]): break
    else:
        if sum(ans) < sum(p): ans = p
print" ".join(map(str, ans))

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

using namespace std;

#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 all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int,int>;
const ll mod = 1e9+7;

vector<int> primes((int)1e5+1000, 0);
void calc(){
  primes[0]=2,primes[1]=2,primes[2]=2;
  int current_max_prime = 2;
  for(ll i=2; i<(ll)1e5+1000; i++){
    if(primes[i]!=-1){
      for(int j=current_max_prime+1; j<=i; j++) primes[j]=i;
      current_max_prime = i;
      for(ll j=i*i; j<(ll)1e5+1000; j+=i) primes[j]=-1;
    }
  }

}

int main(){
  calc();
  int x;
  cin>>x;

  cout<<primes[x]<<endl;

  return 0;
}

Measured memory_bytes: 3636
//package TaskC;

import java.io.FileInputStream;
import java.util.Scanner;

import static java.lang.Math.*;

public class Main {
    int N;
    String[] Ss;
    int ba, b, a, ab;
    int count(String s){
        int l = s.length();
        int res = 0;
        for(int i=0; i<l -1; i++){
            if(s.charAt(i)=='A' && s.charAt(i+1)=='B'){
                res++;
            }
        }
        return res;
    }

    void solve() throws Exception {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        Ss = new String[N];
        ba = 0; b = 0; a = 0; ab = 0;
        int res = 0;
        for(int i=0; i<N; i++){
            Ss[i] = sc.next();
            res += count(Ss[i]);
            int ls = Ss[i].length();
            if(Ss[i].charAt(0)=='B' && Ss[i].charAt(ls-1)=='A') ba++;
            //else if(Ss[i].charAt(0)=='A' && Ss[i].charAt(ls-1)=='B') ab++;
            else if(Ss[i].charAt(0)=='B') b++;
            else if(Ss[i].charAt(ls-1)=='A') a++;
        }

        if(ba<=abs(b-a)){
            res += min(a,b)+ba;
        }else{
            res += max(a,b) + ba-abs(b-a)-1;
            if(a+b>0) res++;
        }
        System.out.println(res);

    }

    public static void main(String[] args) throws Exception{
        //System.setIn(new FileInputStream("inputs/c.in"));
        Main s = new Main();
        s.solve();
    }
}


Measured memory_bytes: 31464
# coding: utf-8
#解法2 abc<=Kのみのリスト
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ABC=[]

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            else:
                ABC.append(A[i]+B[j]+C[k])
        if (i+1)*(j+1)>K:
            break
    if i+1>K:
        break

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])


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


int main()
{
  int a ,b ,c, k;
  cin >> a >> b >> c >> k;
  int i = 0;
  for(; i < 5; ++i){
    if(a < b) break;
    b*=2;
  }
  int j= 0;
  for(; j< 5;++j){
    if(b < c) break;
    c*=2;
  }
  if(i+j <= k) cout << "Yes" << endl;
  else cout << "No" << endl;

  
}


Measured memory_bytes: 3628
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val S = in.head.toInt
  val table = (0 to 100000).map(_ => false).toArray
  
  var n = S
  var i = 1
  do {
    table(n) = true
    n = if(n % 2 == 0) n/2 else 3*n+1
    i += 1
  } while(!table(n))
  
  println(i)
}


Measured memory_bytes: 27948
# 2019/11/23
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - A

# Input
x, y = map(int,input().split())
ans = 0

if x == 1:
    ans = 300000
elif x == 2:
    ans = 200000
elif x == 3:
    ans = 100000

if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000

if x == 1 and y == 1:
    ans += 400000

# Output
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

#define N 12
#define W 10
#define H 10

#define VRET(C,V) \
  {if (!(C)) {return (V);}}

static int d[H][W];
static int n;

static int r[N][3];

static jmp_buf e1;

static int drop(int x, int y, int t, int v) {
  if (t == 1) {
    VRET(x - 1 >= 0 && y >= 0 && x + 1 < W && y + 2 < H, 0);
    VRET(d[y][x] >= v, 0);
    VRET(d[y + 1][x - 1] >= v && d[y + 1][x] >= v && d[y + 1][x + 1] >= v, 0);
    VRET(d[y + 2][x] >= v, 0);
    d[y][x] -= v;
    d[y + 1][x - 1] -= v; d[y + 1][x] -= v; d[y + 1][x + 1] -= v;
    d[y + 2][x] -= v;
    return 1;
  }
  if (t == 2) {
    VRET(x >= 0 && y >= 0 && x + 2 < W && y + 2 < H, 0);
    VRET(d[y][x] >= v && d[y][x + 1] >= v && d[y][x + 2] >= v, 0);
    VRET(d[y + 1][x] >= v && d[y + 1][x + 1] >= v && d[y + 1][x + 2] >= v, 0);
    VRET(d[y + 2][x] >= v && d[y + 2][x + 1] >= v && d[y + 2][x + 2] >= v, 0);
    d[y][x] -= v; d[y][x + 1] -= v; d[y][x + 2] -= v;
    d[y + 1][x] -= v; d[y + 1][x + 1] -= v; d[y + 1][x + 2] -= v;
    d[y + 2][x] -= v; d[y + 2][x + 1] -= v; d[y + 2][x + 2] -= v;
    return 1;
  }
  if (t == 3) {
    VRET(x - 2 >= 0 && y >= 0 && x + 2 < W && y + 4 < H, 0);
    VRET(d[y][x] >= v, 0);
    VRET(d[y + 1][x - 1] >= v && d[y + 1][x] >= v & d[y + 1][x + 1] >= v, 0);
    VRET(d[y + 2][x - 2] >= v && d[y + 2][x - 1] >= v && d[y + 2][x] >= v && d[y + 2][x + 1] >= v && d[y + 2][x + 2] >= v, 0);
    VRET(d[y + 3][x - 1] >= v && d[y + 3][x] >= v & d[y + 3][x + 1] >= v, 0);
    VRET(d[y + 4][x] >= v, 0);
    d[y][x] -= v;
    d[y + 1][x - 1] -= v; d[y + 1][x] -= v; d[y + 1][x + 1] -= v;
    d[y + 2][x - 2] -= v; d[y + 2][x - 1] -= v; d[y + 2][x] -= v; d[y + 2][x + 1] -= v; d[y + 2][x + 2] -= v;
    d[y + 3][x - 1] -= v; d[y + 3][x] -= v; d[y + 3][x + 1] -= v;
    d[y + 4][x] -= v;
    return 1;
  }
  return 0;
}

static void try(int x, int y, int k) {
  goto ENTRY;
  for (y = 0; y < H; ++y)
  for (x = 0; x < W; ++x) {
ENTRY:
    if (d[y][x] == 0)
      continue ;
    if (k == n)
      return ;
    if (drop(x, y, 1, 1)) {
      r[k][0] = x; r[k][1] = y + 1; r[k][2] = 1;
      try(x, y, k + 1);
      drop(x, y, 1, -1);
    }
    if (drop(x, y, 2, 1)) {
      r[k][0] = x + 1; r[k][1] = y + 1; r[k][2] = 2;
      try(x, y, k + 1);
      drop(x, y, 2, -1);
    }
    if (drop(x, y, 3, 1)) {
      r[k][0] = x; r[k][1] = y + 2; r[k][2] = 3;
      try(x, y, k + 1);
      drop(x, y, 3, -1);
    }
    return ;
  }
  
  if (k == n)
    longjmp(e1, 1);
}

int main(void) {
  int i, j;
  
  scanf("%d", &n);
  for (i = 0; i < H; ++i)
  for (j = 0; j < W; ++j) {
    scanf("%d", &d[i][j]);
  }

  if (setjmp(e1) == 0) {
    try(0, 0, 0);
  } else {
    for (i = 0; i < n; ++i) {
      printf("%d %d %d\n", r[i][0], r[i][1], r[i][2]);
    }
  }

  return EXIT_SUCCESS;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> p(h, vector<char>(w));
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> p.at(i).at(j);
    }
  }
  for(int i=0; i<h+2; i++) {
    for(int j=0; j<w+2; j++) {
      if(i==0 || i==h+1 || j==0 || j==w+1) {
        cout << "#";
      } else {
        cout << p.at(i-1).at(j-1);
      }
    }
    cout << endl;
  }
}

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

#define ll long long  
#define endl "\n"

const ll int MOD=1e9+7;

void solve()
{
	ll n,ans=1,i,x;
	cin >> n;
	vector<ll> arr(n);
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
		if(arr[i]==0)
			ans =0;
	}
	x = (ll)1e18;
	for(i=0;i<n and ans!=0;i++)
	{
		if( ans > x/arr[i])
		{
			ans = -1;
			break;
		}
		ans = ans*arr[i];
	}
	cout << ans << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
int x[50], y[50], xx[50], yy[50];

int main() {
    cin >> n >> m;
    forn(i, n) cin >> x[i] >> y[i];
    forn(i, m) cin >> xx[i] >> yy[i];
    forn(i, n) {
        int best = -1;
        int bestVal = int(2e9);
        forn(j, m) {
            int cur = abs(x[i] - xx[j]) + abs(y[i] - yy[j]);
            if (cur < bestVal) {
                bestVal = cur;
                best = j;
            }
        }
        printf("%d\n", best + 1);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>

using namespace std;

struct Node{
	int key;
	Node *prev;
	Node *next;
};

Node *nil;
char command[10];

void init();
void insert(int key);
Node *listSearch(int key);
void deleteNode(Node *t);
void deleteFirst();
void deleteLast();
void deleteKey(int key);


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

	int key;
	string command;
	
	init();
	for(int i=0;i<n;i++){
		cin>>command;
		if(command=="insert"){
			cin>>key;
			insert(key);
		}else if(command=="deleteFirst"){
			deleteFirst();
		}else if(command=="deleteLast"){
			deleteLast();
		}else if(command=="delete"){
			cin>>key;
			deleteKey(key);
		}
	}

	struct Node *print;
	print = nil->next;
	while(print!=nil){
		if(print->next!=nil){
			cout<<print->key<<" ";
		}else{
			cout<<print->key<<endl;
		}
		print = print->next;
	}

	cin.get();
	cin.get();

}


void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->prev = nil;
	nil->next = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node *listSearch(int key){
	Node *cur = nil->next;
	while(cur!=nil && cur->key!=key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if(t==nil) return ;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

const double PI = 3.141592653589793;


pair<double,double> get(double len, double deg) {
    //watch(deg);
    

    if (deg <= 90) {
	deg = 90-deg;
	double rad = deg*PI/180;
	return {len*cos(rad), len*sin(rad)};
    } else if (deg <= 180) {
	deg = 180-deg;
	double rad = deg*PI/180;
	return {len*sin(rad),-len*cos(rad)};
    } else if (deg <= 270) {
	deg = 270-deg;
	double rad = deg*PI/180;
	return {-len*cos(rad),-len*sin(rad)};
    } else if (deg < 360) {
	deg = 360-deg;
	double rad = deg*PI/180;
	return {-len*sin(rad),len*cos(rad)};
    }
    assert(false);
    return {0,0};
}


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

    int A, B, H, M;
    cin>>A>>B>>H>>M;

    pair<double,double> hpt = get(A, (1.0*H/12 + (1.0*M/60)*(1./12))*360);
    pair<double,double> mpt = get(B, (1.0*M/60)*360);


    double res = sqrt((hpt.first-mpt.first)*(hpt.first-mpt.first) +
		      (hpt.second-mpt.second)*(hpt.second-mpt.second));


    cout<<fixed<<setprecision(15)<<res<<endl;    
    return 0;
}


Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int f(){
	
}

int32_t main(){
    fast_io;
    int a[5];
    for (int i = 0; i < 5; ++i)
    {
        cin>>a[i];
    }
    for (int i = 0; i < 5; ++i)
    {
        if(a[i] == 0){
            show(i+1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
from collections import deque

def main():
    n, m = map(int, input().split())
    to = [[] for _ in range(n+1)]
    ans = [None]*(n+1)
    for _ in range(m):
        a, b = map(int, input().split())
        to[a].append(b)
        to[b].append(a)
    q = deque([1])
    while q:
        p = q.pop()
        for child in to[p]:
            if ans[child] is None:
                ans[child] = p
                q.appendleft(child)
    print("Yes")
    for a in ans[2:]:
        print(a)
    

if __name__ == "__main__":
    main()

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

int main()
{
    ll n; cin >> n;
    
    vector<ll> a(n);
    ll minusCnt = 0;
    ll ans = 0;

    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) minusCnt++;
        a[i] = abs(a[i]);
        ans += a[i];
    }
    
    sort(a.begin(), a.end());

    if (minusCnt % 2 != 0) ans -= 2 * abs(a[0]);    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
//template<class Key, class Compare = less<Key>>
//using Tree = tree<Key, null_type, Compare, rb_tree_tag, tree_order_statistics_node_update>;




int N = 4;
vector<int> G[4];
bool done;

void dfs(int u, int p, int d) {
    if (d == 3) {
        done = true;
        return;
    }
    for (int v : G[u]) {
        if (v != p) {
            dfs(v, u, d+1);
        }
    }
}

void Main() {
    for (int i = 0; i < 3; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < 4; ++i) {
        done = false;
        dfs(i, -1, 0);
        if (done) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef _DEBUG
//        freopen("in.txt", "r", stdin);
//        freopen("out.txt", "w", stdout);
    #endif
    Main();
    return 0;
}


Measured memory_bytes: 256
N,A,B=[int(item)for item in input().split()]
S=input()
for c in S:
    if c == 'c':
        print("No")
    elif c == 'a':
        if A == 0:
            if B>0:
                B -= 1
                print("Yes")
            else:
                print("No")
        else :
            A-=1
            print("Yes")
    else:
        #b
        if B == 0:
            print("No")
        else:
            B-=1
            print("Yes")

Measured memory_bytes: 4016
import sys

while True:
    slist = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
    for c in 'ABCDE':
        s1, s2 = map(int, input().split())
        if s1 == 0 and s2 == 0:
            sys.exit()
        slist[c] = s1+s2
    print(*sorted(slist.items(), key=lambda x: x[1])[-1])



Measured memory_bytes: 5604
'use strict'

class Main {
  solve() {
    const size = input.nextIntArr();
    const nums = input.nextIntArr();
    console.log((size[0] - nums[0]) * (size[1] - nums[1]));
  }
}

class Input {
  constructor() {
	this.cursor = 0;
	this.inputAll();
  }

  inputAll() {
	this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
	return this.data;
  }

  nextLine(n) {
	if (n) {
	  const ret = this.data.slice(this.cursor, this.cursor + n);
	  this.cursor += n;
	  return ret;
	}
	return this.data[this.cursor++];
  }

  nextStrArr() {
	return this.nextLine().split(' ');
  }

  nextIntArr() {
	return this.nextStrArr().map((e) => parseInt(e));
  }

  nextFloatArr() {
	return this.nextStrArr().map((e) => parseFloat(e));
  }

  nextIntLine(n) {
	return this.nextLine(n).map((e) => parseInt(e))
  }

  nextFloatLine(n) {
	return this.nextLine(n).map((e) => parseFloat(e))
  }

  nextStrRange(n) {
	return this.nextLine(n).map((line) => line.split(' '));
  }

  nextIntRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }

  nextFloatRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseFloat(e)));
  }
}

const input = new Input();
(new Main()).solve();


Measured memory_bytes: 21064
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {

	int N,M,X;
	cin >> N >> M >> X;
	int a, sum[2] = {0,0};
	for (int i = 0; i < M;i++) {
		cin >> a;
		if (a < X){
			sum[0]++;
		}
		else {
			sum[1]++;
		}
	}
	cout << min(sum[0],sum[1]);
	/*
	if (x-a >= 0 && x-a < b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, x;
	cin >> n;
	int data[100];
	for (int i = 0; i < n; i++) {
		cin >> data[n - i - 1];
	}
	for (int i = 0; i < n; i++) {
		cout << data[i];
		if (i != n - 1) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3084
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = list()

    for i in map(int, input().split()):
        a.append(i)

    tmp = 0
    for i in a:
        tmp += 1 / i

    print(1 / tmp)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int x[110000];
int gcd(int a,int b){
	while(a){b%=a;swap(a,b);}return b;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",x+i);
	int ret=ABS(b-x[0]);
	for(int i=0;i<a;i++)ret=gcd(ret,ABS(b-x[i]));printf("%d\n",ret);
}

Measured memory_bytes: 512
#include <stdio.h>

int main(int argc, char const *argv[]) {

  char str[8];
  scanf("%s", str);

  if (str[2] == str[3] && str[4] == str[5]) {
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
/*
 /+==================================================+\
//+--------------------------------------------------+\\
|.|\\...>>>>>>> Hollwo_Pelw(ass) 's code <<<<<<<...//|.|
\\+--------------------------------------------------+//
 \+==================================================+/
*/
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r)        for (int i = l; i < r; i++)
//#define ForE(i, l, r)       for (int i = l; i <= r; i++)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O
#define open(file, in, out) if (fopen(file in, "r")) {        \
                                freopen(file in, "r", stdin);  \
                                freopen(file out, "w", stdout); \
                            }
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
// geometry calculate
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 2e5 + 10, MAXM = 1e5 + 5, VV = 5e8 + 4;
// code
#define int long long
int ans[MAXM], cnt[MAXM];
priority_queue<pii> pq;

void Solve(){
    int n; cin >> n;
    for (int i = 0, a; i < n; i++){
        cin >> a; cnt[i] ++;
        pq.push({a, i});
    }
    while(pq.size() > 1){
        pii mx1, mx2;
        mx1 = pq.top(); pq.pop();
        mx2 = pq.top(); pq.pop();
        ans[mx1.S] += cnt[mx1.S] * (mx1.F - mx2.F);
        
		cnt[min(mx1.S, mx2.S)] += cnt[max(mx1.S, mx2.S)];
		pq.push({mx2.F, min(mx1.S, mx2.S)});
    }
	ans[0] += n * pq.top().first;
	for (int i = 0; i < n; i++){
	    cout << ans[i] << endl;
	}
}


signed main(){
    open("", ".inp", ".out");
    FAST_IO;
    int TC = 1;
    //cin >> TC;
    while(TC--) Solve();
    return 0;
}
/*
./-=====>>><<<-------- DEBUG -------->>><<<=====-\.
/.................................................\

+====================== INP ======================+


+====================== OUT ======================+


\................................................./
.\-=====>>><<<--------= END =-------->>><<<=====-/.
*/


Measured memory_bytes: 6584
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B = vector<int>(M, 0);
	for(int mIndex = 0; mIndex < M; ++mIndex){
		int b;
		cin >> b;
		B[mIndex] = b;
	}
	int result = 0;
	for(int nIndex = 0; nIndex < N; ++nIndex){
		int sum = 0;
		for(int mIndex = 0; mIndex < M; ++mIndex){
			int a;
			cin >> a;
			sum += a * B[mIndex];
		} 
		if (sum + C > 0){
			++result;
		}
	}
	cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
int c[N], cnt[N], siz[N];
ll ans[N];
vector<int>G[N];
ll cal(int x) {
	return 1ll * x*(x - 1) / 2 + x;
}
void dfs(int u, int _fa) {
	siz[u] = 1;
	int tmp = cnt[c[u]];
	for (int v : G[u]) {
		if (v == _fa)continue;
		cnt[c[u]] = 0;
		dfs(v, u);
		siz[u] += siz[v];
		ans[c[u]] += cal(siz[v] - cnt[c[u]]);
	}
	cnt[c[u]] = tmp + siz[u];
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &c[i]);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}

Measured memory_bytes: 34184
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
int dp[114514],m[114514];

int main() {
	int n, s[114514] = {};
	REPO(i, 114513) dp[i] = INF;
	cin >> n;
	REP(i, n) cin >> s[i];
	REP(i, n) {
		dp[i + 1] = min(dp[i + 1], dp[i] + max(s[i], s[i + 1]) - min(s[i], s[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + max(s[i], s[i + 2]) - min(s[i], s[i + 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    int N; string S; cin >> N >> S;
    int ans = 0;
    set<char> ST;
    for(int i = 0; i < N; i++){
        int tmp;
        string S_ = S.substr(i+1);
        if( find(S_.begin(), S_.end(), S[i]) != S_.end()){//mitukattara
            ST.insert(S[i]);
        }
        else{
            if(find(ST.begin(), ST.end(), S[i]) != ST.end()) ST.erase(S[i]);
        }
        ans = max(ans, (int)ST.size());
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;

public class Main {

	public static void main(String args[]) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// String str[] = br.readLine().split(" ");
		int x = Integer.parseInt(br.readLine());
		int a = Integer.parseInt(br.readLine());
		int b = Integer.parseInt(br.readLine());

		x -= a;
		while (x >= b) {
			x -= b;
		}
		System.out.println(x);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <cstring>
#include <bitset>

#define M 4000000

using namespace std;

int main(){
    int N;
    int A[2000];
    int sum = 0;
    bitset<M+1> dp;
    bitset<M+1> dp_;
    
    dp[0] = 1;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    for(int i = 0; i < N; i++){
        dp_ = dp << A[i];
        dp |= dp_;
    }
    int m = (sum+1)/2;
    for(int i = m; i <= sum; i++){
        if(dp[i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1664
import sys
input = sys.stdin.readline


def read():
    S = list(input().strip())
    return S,

def solve(S):
    N = len(S)
    count = 0
    l = 0
    r = N-1
    while r >= 0 and S[r] != 'W':
        r-=1
    s = list()
    c = 0
    for i in range(r, -1, -1):
        d = r - i
        if S[i] == 'B':
            s.append(d - c)
            c += 1
    return sum(s)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 8868
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

int main(){
	int N,K;cin>>N>>K;
  	if(N%K==0){
      cout<<0<<endl;
      return 0;
    }
  cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())
if A + 2 >= B:  # 交換は無駄
    print(K + 1)
elif K < A + 1:  # 全部たたいても交換ができない
    print(K + 1)
else:
    print(A + ((K-A+1)//2)*(B-A) + (K-A+1) % 2)


Measured memory_bytes: 2940
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

string fill_in(int n)
{
    string S = to_string(n);
    string ans;
    REP(i, 6-S.size())
    {
        ans+="0";
    }
    ans += S;
    return ans;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N,M;cin >> N >> M;
    VI Y(M), P(M);
    VVI A(N);
    REP(i,M)
    {
        int p, y;cin>>P[i]>>Y[i];
        A[P[i]-1].pb(Y[i]);
    }
    REP(i,N)
    {
        SORT(A[i]);
    }
    REP(i,M)
    {
        int y = Y[i];
        int p = P[i];
        cout << fill_in(p);
        int rank=upper_bound(ALL(A[p-1]), y) - A[p-1].begin();
        cout << fill_in(rank) << endl;
        
    }
  
    return 0;
}



Measured memory_bytes: 7808
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
a=[0]*m
b=[0]*m
ans=[1]*n
for i in range (m):
    a[i],b[i]=list(map(int,input().split()))
    if h[a[i]-1]<h[b[i]-1]:
        ans[a[i]-1]=0
    elif h[a[i]-1]>h[b[i]-1]:
        ans[b[i]-1]=0
    else:
        ans[a[i]-1]=0
        ans[b[i]-1]=0
print(sum(ans))

Measured memory_bytes: 87496
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		int n = Integer.parseInt(in.nextLine());
		String s = in.nextLine();
		String t = s;
		String tmp = s;
		do{
			s = tmp;
			tmp = s.replace("()", "");
		}while(s.length() != tmp.length());

		String f = "", b = "";
		for(int i = 0; i < tmp.length(); i++){
			if(tmp.charAt(i) == '('){
				b += ")";
			}else{
				f += "(";
			}
		}
		System.out.println(f + t + b);
	}

}

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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

void DP_82(){
    string s;
    cin>>s;
    if(s[0]!=s[1] || s[0]!=s[2] || s[1]!=s[2])cout<<"Yes";
    else cout<<"No";
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    DP_82();
    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;
const ll C=1000;




int main(){
    ll sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    ll r=tx-sx;
    ll u=ty-sy;
    for(int i=0;i<r;i++){
        cout<<"R";
    }
    for(int i=0;i<u;i++){
        cout<<"U";
    }
    for(int i=0;i<r;i++){
        cout<<"L";
    }
    for(int i=0;i<u;i++){
        cout<<"D";
    }
    cout<<"D";
    for(int i=0;i<r+1;i++){
        cout<<"R";
    }
    for(int i=0;i<u+1;i++){
        cout<<"U";
    }
    cout<<"L";
    cout<<"U";
    for(int i=0;i<r+1;i++){
        cout<<"L";
    }
    for(int i=0;i<u+1;i++){
        cout<<"D";
    }
    cout<<"R"<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
  int A,B;
    cin >> A >> B;
  cout << max({A-B,A+B,A*B});
    


}

/*



 */



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, s, t;
  cin >> d >> s >> t;
  int res = (d + t - 1) / t;
  if (res <= s)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

Measured memory_bytes: 3604