akhauriyash/Code-Regression huggingface dataset:
MOD = 1000000007

S = input()
N = len(S)

dp = [[0, 0, 0, 0] for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        for j in range(4):
            dp[i + 1][j] += dp[i][j] * 3
            dp[i + 1][j] %= MOD
    else:
        for j in range(4):
            dp[i + 1][j] += dp[i][j]
            dp[i + 1][j] %= MOD
            
    if S[i] == 'A' or S[i] == '?':
        dp[i + 1][1] += dp[i][0]
        dp[i + 1][1] %= MOD
        
    if S[i] == 'B' or S[i] == '?':
        dp[i + 1][2] += dp[i][1]
        dp[i + 1][2] %= MOD
        
    if S[i] == 'C' or S[i] == '?':
        dp[i + 1][3] += dp[i][2]
        dp[i + 1][3] %= MOD

print(dp[N][3])

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const ll mod = 1000000007LL;
int n,m;

ll nfact = 1LL,mfact = 1LL;

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

	rep(i,1,n+1) nfact = 1LL * nfact * i  % mod;
	rep(i,1,m+1) mfact = 1LL * mfact * i  % mod;

	ll ans = 0LL;

	if(n == m or n == m + 1){
		ans += 1LL * nfact * mfact % mod;
		ans %= mod;
	}

	if(m == n or m == n + 1){
		ans += 1LL * nfact * mfact % mod;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

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

from collections import deque
h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
s = [list(input()) for _ in range(h)]
INF=10**7

queue = deque()

cost = [[INF]*w for _ in range(h)]
cost[ch-1][cw-1]=0

dxdy = [[1,0],[-1,0],[0,1],[0,-1]]
warp = []
for m in range(-2,3):
    for n in range(-2,3):
        if [m,n] not in [[0,0],[1,0],[-1,0],[0,1],[0,-1]]:
            warp += [[m,n]]

queue.append([ch-1,cw-1,0])

while queue:
    x,y,d = queue.popleft()
    if d>cost[x][y]:
        continue
    for dx,dy in dxdy:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d<cost[nx][ny]:
            cost[nx][ny]=d
            queue.appendleft([nx,ny,d])

    for dx,dy in warp:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d+1<cost[nx][ny]:            
            cost[nx][ny]=d+1
            queue.append([nx,ny,d+1])

if cost[dh-1][dw-1]<INF:
    print(cost[dh-1][dw-1])
else:
    print(-1)


Measured memory_bytes: 154068
#include<stdio.h>
long long int dp[101][4][4];
int main(void)
{
	int i,j,k,l,n,m,a,b[101],c;
	long long int sum,x;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			for(k=0;k<=3;k++) dp[i][j][k]=0;
		}
	}
	for(i=1;i<=n;i++) b[i]=0;
	for(i=1;i<=m;i++){
		scanf("%d",&a);
		scanf("%d",&b[a]);
	}
	if(b[1]>0) dp[1][b[1]][0]=1;
	else{
		for(i=1;i<=3;i++) dp[1][i][0]=1;
	}
	for(i=1;i<n;i++){
		for(j=1;j<=3;j++){
			if(dp[i][j][0]+dp[i][j][1]+dp[i][j][2]+dp[i][j][3]>0){
				for(k=0;k<=3;k++){
					if(b[i+1]>0){
						if(b[i+1]!=k||b[i+1]!=j){
							dp[i+1][b[i+1]][j]+=dp[i][j][k];
							dp[i+1][b[i+1]][j]%=10000;
						}
					}
					else{
						for(l=1;l<=3;l++){
							if(k!=l||j!=l){
								dp[i+1][l][j]+=dp[i][j][k];
								dp[i+1][l][j]%=10000;
							}
						}
					}
				}
			}
		}
	}
	sum=0;
	for(i=1;i<=3;i++){
		for(j=0;j<=3;j++) sum+=dp[n][i][j];
	}
	x=sum%10000;
	printf("%d\n",x);	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ans = 1;
  int res = 1;
  rep(i,n) {
    ans *= 3;
    int a;
    cin >> a;
    if(a % 2 == 0) res *= 2; 
  }
  cout << ans - res << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
char ch[10005];
int vst[10005];
int main()
{
	scanf("%s",ch+1);
	int len=strlen(ch+1);
	for(int i=1;i<=len;i++)
	{
		if(vst[ch[i]]){printf("no\n");return 0;}
		else vst[ch[i]]++;
	}
	printf("yes\n");
	return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = [0]
for a in A:
    B.append(B[-1] + a)

ans = float('inf')
for i in range(1,N):
    tmp = abs(B[-1]-B[i] - B[i])
    ans = min(ans, tmp)
print(ans)

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

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

int main(){
#define int ll
  int n; cin >> n;
  int a; cin >> a;
  int res = 0;
  rep(i,n-1){
    int b; cin >> b;
    if(a == b){
      res++;
      a = -1;
    }else a = b;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,parent[100010];
vector<pair<int,int> > x,y;
vector<pair<int,pair<int,int> > > v;

int findP(int a)
{
	if(parent[a] == a) return a;
	return parent[a] = findP(parent[a]);
}
void unite(int a, int b)
{
	int fa = findP(a);
	int fb = findP(b);
	parent[fa] = fb;
	return;
}
int main()
{
	int i,j;
	int a,b;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		parent[i] = i;
		scanf("%d %d",&a,&b);
		x.push_back({a,i});
		y.push_back({b,i});
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	
	for(i=1;i<x.size();i++)
	{
		v.push_back({x[i].first - x[i-1].first , {x[i].second , x[i-1].second}});
	//	printf("{%d , {%d , %d} } \n",x[i].first - x[i-1].first , x[i].second , x[i-1].second);
	}
	for(i=1;i<y.size();i++)
	{
		v.push_back({y[i].first - y[i-1].first , {y[i].second , y[i-1].second}});
//		printf("{%d , {%d , %d} } \n",y[i].first - y[i-1].first , y[i].second , y[i-1].second);
	}
	sort(v.begin(), v.end());
	
	int edge=0;
	long long totalsum = 0;
	for(i=0;i<v.size();i++)
	{
		a = v[i].second.first;
		b = v[i].second.second;
		
	//	printf("look cost = %d ,  %d===%d \n",v[i].first ,a,b);
		if(findP(a) != findP(b))
		{
	//		printf("yes\n");
			edge++;
			unite(a,b);
			totalsum += v[i].first;
			
		}
		
		
	}
	
	
	printf("%lld\n",totalsum);
	
}

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << 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; }

int main(){
  ll x;
  cin >> x;
  ll ans = 1;
  for (ll i = 2; i * i <= x; i++){
    ll a = i;
    ll b = i;
    while (a * b <= x){
      a *= b;
    }
    chmax(ans, a);
  }
  print(ans);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
            String ringStr = kb.readLine();    // リング状の文字列
            String targetStr = kb.readLine();  // 対象の文字列

            int ringStrLen = ringStr.length();     // リング状の文字列の長さ
            int targetStrLen = targetStr.length(); // 対象の文字列の長さ
            int j = 0;
            for( int i = 0; i < ringStrLen; i++ ) {
                if( targetStr.charAt( 0 ) == ringStr.charAt( i ) ) {
                	// リング状の文字列における対象の文字列のインデックス用
                    int ij = i;
                    for( j = 0; j < targetStrLen; j++ ) {
                    	// リング状の文字列のインデックスを超えないように剰余演算
                        ij = ( i+j ) % ringStrLen;
                        // 文字が一致しない場合、リング状の文字列の次の文字に進めるため処理を抜ける
                        if( targetStr.charAt( j ) != ringStr.charAt( ij ) ) {
                            break;
                        }
                    }
                }
                // 対象の文字列が見つかった場合、処理を抜ける
                if( targetStrLen == j ) { break; }
            }

            // 対象の文字列が見つかった場合、j = 0 にリセットされないので、
            if( targetStrLen == j ) {
                System.out.println( "Yes" );            
            } else {
                System.out.println( "No" );
            }
        } catch( IOException e ) {
            System.err.println( e );
        }

	}

}



Measured memory_bytes: 24448
#include<stdio.h>


int main(){
    int a[128], b, i, x, k,  j, temp;
    
    scanf("%d", &b);
    
    for(i = 0; i < b; i++){
        scanf("%d", &a[i]);
    }
    
    for(k=1; k < b; k++){
            for( i = 0; i < b; i++){
        
               if(i != 0){
                    printf(" ");
                 }
                printf("%d", a[i]);
             }
            putchar('\n');
            
            x = a[k]; 
            
            j = k- 1;
            
           while(j >= 0 && a[j] > x){
                a[j + 1] = a[j];
                j--;
            }             
            a[j + 1] = x;
          
  }
    
     for( i = 0; i < b; i++){
        
         if(i != 0){
            printf(" ");
         }
        
        printf("%d", a[i]);
         }
        putchar('\n');
    return 0;
}



Measured memory_bytes: 1964
Imports System.Collections.Generic
Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim S As String = Console.ReadLine()
        Dim T As String = Console.ReadLine()
        Dim z = S.Zip(T, Function(first, second)  New Char() { first, second })
        Dim ans= 0
        For Each v in z
            If v(0) <> v(1) Then
                ans += 1
            End If
        Next
        Console.WriteLine(ans)
        Return
    End Sub
End Class

Measured memory_bytes: 34024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    string s;
    int suma = 0, sumb = 0, sumc = 0;
    cin >> s;
    rep(i, 3)
    {
        if (s[i] == 'a')
            suma++;
        else if (s[i] == 'b')
        {
            sumb++;
        }
        else
        {
            sumc++;
        }
    }
    if (suma == 1 && sumb == 1 && sumc == 1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
        cout << "No" << endl;

    return 0;
}

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

int main() {
    int Q;
    std::cin >> Q;
    std::vector<int> v;
    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int x;
            std::cin >> x;
            v.push_back(x);
        } else if (t == 1) {
            int i;
            std::cin >> i;
            std::cout << v[i] << std::endl;
        } else {
            v.pop_back();
        }
    }
    return 0;
}



Measured memory_bytes: 3916
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

/*
 * Dependencies: typedef long long ll
 * Headers: iostream
 * Verified by: ARC099-F
 *              https://beta.atcoder.jp/contests/arc099/submissions/2743855
 */

template<ll mod = (ll)1e9 + 7>
struct ModInt {
  ll x;
  ModInt(void): x(0) {}
  ModInt(ll x): x(x % mod){}
  ModInt(const ModInt &x): x(x.x) {}
  ModInt operator+(ModInt o) const {
    ll y = x + o.x;
    if (y >= mod) y -= mod;
    return ModInt(y);
  }
  ModInt operator-(ModInt o) const {
    ll y = x - o.x + mod;
    if (y >= mod) y -= mod;
    return ModInt(y);
  }
  ModInt operator*(ModInt o) const {
    return ModInt((x * o.x) % mod);
  }
  void operator+=(ModInt o) { *this = *this + o; }
  void operator-=(ModInt o) { *this = *this - o; }
  void operator*=(ModInt o) { *this = *this * o; }
  ModInt operator-(void) const { return ModInt() - *this; }
  ll to_ll() const {
    return x;
  }
  bool operator<(ModInt o) const {
    return x < o.x;
  }
  ModInt pow(ll e) {
    assert (e >= 0);
    ModInt sum = 1;
    ModInt cur = *this;
    while (e > 0) {
      if (e % 2) {
        sum = sum * cur;
      }
      cur = cur * cur;
      e /= 2;
    }
    return sum;
  }
  ModInt inv(void) {
    return pow(mod - 2);
  }
};

template<ll mod>
ostream &operator<<(ostream &os, ModInt<mod> mi) {
  return os << mi.x;
}

const int N = 100200;
// eq: 0, lt: 1
ModInt<> dp[N][2];

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string l;
  cin >> l;
  int n = l.size();
  dp[0][0] = 1;
  REP(i, 0, n) {
    REP(j, 0, 2) {
      int lim = j == 0 ? (l[i] - '0') : 1;
      REP(k, 0, lim + 1) {
        int to = j || (k < lim);
        dp[i + 1][to] += dp[i][j] * (k == 1 ? 2 : 1);
      }
    }
  }
  cout << dp[n][0] + dp[n][1] << endl;
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> b(n - 1);
    for(int i = 0; i < n - 1; i++){
        cin >> b[i];
    }
    ans += b[0];
    for(int i = 1; i < n - 1; i++){
        ans += min(b[i - 1], b[i]);
    }
    ans += b.back();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*                                                  Alpha_The_Coder
                                                  Created on 20/08/2020                                                     */

#include <bits/stdc++.h>
using namespace std;
#define iamalpha ios_base::sync_with_stdio(false);cin.tie(NULL);
#define loop(a,n) for(int i=a;i<n;i++)
#define nloop(a,n) for(int j=a;j<n;j++)
#define lli long long int
void solve();
int main()
{
    iamalpha;
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}
void solve()
{
  int n,x,t;
  cin>>n>>x>>t;
  int current=0;
  int ans=0;
  while(current<n)
  {
    ans++;
    current+=x;
    if(current>=n)
    {
        break;
    }
  }
  cout<<ans*t;
}

// Solely contributed by Subhojeet Sahoo aka Alpha


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

int const MAX = 200005;
int const MAX_A = 1 << 28;
long long a[MAX];
long long b[MAX];
long long c[MAX];

long long find(long long y, int p, int n) {
	long long t;
	t = 1 << p;
	long long x = y % (1 << (p + 1));
	return (lower_bound(c + 1, c + n + 1, 4 * t-x) - lower_bound(c + 1, c + n + 1, 3 * t-x) 
		+ lower_bound(c + 1, c + n + 1, 2 * t-x) 
		- lower_bound(c + 1, c + n + 1, t-x));
}


long long f(int p, int n) {
	for (int i = 1; i <= n; i++) {
		c[i] = a[i] % (1 << (p + 1));
	}
	sort(c + 1, c + n + 1);
	int cnt=0;
	for (int i = 1; i <= n; i++) {
		cnt += find(b[i], p, n);
	}
	return cnt;
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	long long ans = 0;
	for (int i = 0; i <= 29; i++) {
		long long t = f(i, n) & 1;
		ans += t*(1 << i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	ll k; cin >> k;
	vector<ll> p(n);
	for(int i=0;i<n;i++){
		cin >> p[i];
		p[i]--;
	}
	vector<ll> c(n);
	ll res=-3e18;
	for(int i=0;i<n;i++){
		cin >> c[i];
		res=max(res,c[i]);
	}
	for(int i=0;i<n;i++){
		vector<ll> v;
		v.push_back(0LL);
		ll cnt=0;
		ll sum=0;
		ll mx=0;
		ll now=p[i];
		while(1){
			cnt++;
			sum+=c[now];
			mx=max(mx,sum);
			if(cnt<=k){
				res=max(res,sum);
			}
			v.push_back(mx);
			if(now==i)break;
			now=p[now];
		}
		if(cnt<=k)res=max(res,k/cnt*sum+v[k%cnt]);
		if(cnt*2<=k)res=max(res,(k/cnt-1)*sum+v.back());
	}
	cout << res << endl;
	
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define N 200010
using namespace std;

int n, q[N], l, r, deg[N];
bool vis[N], inqueue[N];
vector<int> edge[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		edge[x].push_back(y);
		edge[y].push_back(x);
		++deg[x]; ++deg[y];
	}
	
	l = r = 0;
	for (int i = 1; i <= n; ++i) {
		if (deg[i] == 1) {
			q[++r] = i;
			inqueue[i] = 1;
		}
	}

	while (l < r) {
		int nq = -1;
		int u = q[l++];
		for (int j = 0; j < edge[u].size(); ++j) {
			int v = edge[u][j];
			if (!vis[v]) {
				nq = v;
				vis[v] = 1;
				vis[u] = 1;
				break;
			}
		}
		
		if (nq == -1) continue;
		for (int i = 0; i < edge[nq].size(); ++i) {
			int v = edge[nq][i];
			if (!inqueue[v] && --deg[v] == 1) {
				q[++r] = v;
				inqueue[v] = 1;
			}
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		if (!vis[i]) {
			puts("First");
			return 0;
		}
	}
	puts("Second");
}

Measured memory_bytes: 9600
# -*- coding: utf-8 -*-
"""


"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    ranks = [0] * 6
    n = int(input())
    for _ in range(n):
        h = float(input())
        if h < 160.0:
            h = 160.0
        if h >= 190.0:
            h = 189.9
        pos = int((h - 160.0) / 5)
        ranks[pos] += 1

    for i, f in enumerate(ranks):
        print('{}:{}'.format(i+1, '*'*f))


if __name__ == '__main__':
    main(sys.argv[1:])

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



int main() {
   int n;
   cin >> n;
   vector<int> a(n);
   for (int i=0; i<n; i++) {
      cin >> a[i];
   }
   string ans = "APPROVED";
   for (int i=0; i<n; i++) {
      if (a[i] % 2 == 0) {
         if ((a[i] % 3 != 0) && (a[i] % 5 != 0)) {
            ans = "DENIED";
         }
      }
   }
   cout << ans << endl;
   return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<int> v;
  rep(i, n) {
    int t;
    cin >> t;
    bool found = find(v.begin(), v.end(), t) != v.end();
    if (!found) {
      v.push_back(t);
    }
  }

  cout << v.size();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める

//x かけるy　で　x とｙが違う値の時にNoになるかも？naranai
int main(){
    string S;cin>>S;
    int n = S.size();
    //最後の文字列まで到達したらbreak;
    //１つ前の文字列だけ見ればいい！！
    int i = 0;
    int ans =0 ;
    string bef;
    string now;
    while(1){
        if(i==S.size()){
            break;
        }
        if(0==i){ bef = S[i];
        i++;
        ans ++;
        }
        else{
           now +=S[i] ;
           i++;
           if(bef!=now){
               ans++;
               bef = now;
               now ="";
           }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 640
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	ss := strings.Split(s,"")

	count := 0
	for _,v := range ss {
		if v == "+" {
			count++
		} else {
			count--
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2147483647;
using namespace std;

const int sqrtN = 512;

class sqdiv{
    public:
        int N, K;
        vector<int> data;
        vector<bool> lazy_flag;
        vector<int> lazy_update;
        vector<int> bkt_min;
        sqdiv(int n){ //?????±???????????????????????´
            N = n;
            K = (N + sqrtN - 1) / sqrtN;
            data.assign(K * sqrtN, INF);
            lazy_flag.assign(K, false);
            lazy_update.assign(K, 0);
            bkt_min.assign(K, INF);
        }
        void eval(int k){
            if(lazy_flag[k]){
                lazy_flag[k] = false;
                for(int i = k * sqrtN; i < (k + 1) * sqrtN; i++){
                    data[i] = lazy_update[k];
                }
            }
        }
        void update(int x, int y, int a){
            rep(k,K){
                int l = k * sqrtN, r = (k + 1) * sqrtN;
                if(r <= x || y <= l) continue;
                if(x <= l && r <= y){
                    lazy_flag[k] = true;
                    lazy_update[k] = a;
                    bkt_min[k] = a;
                }else{
                    eval(k);
                    for(int i = max(x, l); i < min(y, r); i++){
                        data[i] = a;
                    }
                    int &mini = bkt_min[k] = INF;
                    for(int i = l; i < r; i++){
                        mini = min(mini, data[i]);
                    }
                }
            }
        }
        int find(int x, int y){
            int mini = INF;
            rep(k,K){
                int l = k * sqrtN, r = (k + 1) * sqrtN;
                if(r <= x || y <= l) continue;
                if(x <= l && r <= y){
                    mini = min(mini, bkt_min[k]);
                }else{
                    eval(k);
                    for(int i = max(x, l); i < min(y, r); i++){
                        mini = min(mini, data[i]);
                    }
                }
            }
            return mini;
        }
};

int main(){
    int n,q;
    cin >> n >> q;
    sqdiv ob(n);
    rep(i,q){
        bool com;
        int a, b, c;
        cin >> com;
        if(com){
            cin >> a >> b;
            cout << ob.find(a, b + 1) << endl;
        }else{
            cin >> a >> b >> c;
            ob.update(a,b + 1,c);
        }
    }
}

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


int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> a(m);
  rep(i,m){
    cin >> a[i];
    sum += a[i];
  }
  if (sum <= n) cout << n-sum << endl;
  else cout << -1 << endl;
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/

// n : num of nodes
ll n;
// m : num of queries
ll m;
// dat[i] : if({i is root}) -1 * {num of nodes under i} else {i's root}
vl dat;

// return x's root
ll root(ll x){
  return dat[x] < 0 ? x : dat[x]=root(dat[x]);
}

// make node a and node b belong to same group
void unite(ll a, ll b){
  a = root(a);
  b = root(b);
  if(a==b) return;
  // thanks to following line, {num of nodes under a}>={num of nodes under a} is true
  // tree height becomes smallest 
  if(-dat[a] < -dat[b]) swap(a,b);
  // {num of nodes under a} += {num of nodes under b}
  dat[a] += dat[b];
  // node b is no longer root, and b's root is a
  dat[b] = a;
}

int main() {
  cin >> n >> m;
  dat = vl(n,-1);
  REP(i,m) {
    ll ai,bi,d;
    cin >> ai >> bi >> d;
    ai--;
    bi--;
    unite(ai,bi);
  }
  ll ans = 0;
  REP(i,n) if(root(i)==i) ans++;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  int ans;
  if(A==B){
    if(A==C) ans=1;
    else ans=2;
  }
  else if (A==C) ans=2;
  else if (B==C) ans=2;
  else ans=3;
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		vector<int> gs(n),ss(n);
		for(int i=0;i<n;i++){
			int m; cin>>m>>ss[i];
			for(int j=0;j<m;j++){
				int s,e; cin>>s>>e;
				gs[i]|=(1<<e)-(1<<s)>>6;
			}
		}
		vector<int> dp(1<<16);
		for(int i=0;i<(1<<16);i++)
			for(int j=0;j<n;j++)
				if(!(i&gs[j]))
					dp[i|gs[j]]=max(dp[i|gs[j]],dp[i]+ss[j]);
		cout<<*max_element(begin(dp),end(dp))<<endl;
	}
}

Measured memory_bytes: 1452
#include<bits/stdc++.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;
	int b[101];
	cin>>n;

	rep(i,n-1){
		cin>>b[i];
	}
	ll t=0;
	t+=b[0]+b[n-2];
	for(int i=1; i<n-1; i++){
		t+=min(b[i],b[i-1]);
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
vector<int> compress(vector<ll> a) {
  int n = a.size();
  vector<ll> vals;
  rep(i,n) vals.push_back(a[i]);

  sort(vals.begin(), vals.end());
  vals.erase(unique(vals.begin(), vals.end()), vals.end());

  vector<int> res;
  rep(i,n) {
    int id = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin() + 1; // 1-indexed
    res.push_back(id);
  }

  return res;
}

ll dp[310][310][310];
int main()
{
  int n,k;cin >> n >> k;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];

  vector<int> comp = compress(h);
  vector<ll> mp(n+1);
  mp[0] = 0;
  rep(i,comp.size()) mp[comp[i]] = h[i];
  
  rep(i,n+1) rep(j,k+1) rep(l,n+1) dp[i][j][l] = 1e+15;
  dp[0][0][0] = 0;
  
  rep(i,n) {
    rep(j,k+1) {
      rep(l,n+1) {
	int nl = comp[i];
	// not change
	chmin(dp[i+1][j][nl], dp[i][j][l] + max(mp[nl] - mp[l], 0LL) );
	// change
	if(j + 1 <= k) chmin(dp[i+1][j+1][l], dp[i][j][l]);
      }
    }
  }
  
  ll res = 1e+15;
  rep(j,k+1) rep(l,n+1) {
    chmin(res, dp[n][j][l]);
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 227584
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, m, q;
ll A[N];
ll ans;
struct Query{
	ll a, b, c, d;
}Q[N];


void bt(ll x) {
	if (x == n) {
		ll res = 0;
		for (int i = 1; i <= q; i ++) {
			ll aa = Q[i].a, bb = Q[i].b, cc = Q[i].c, dd = Q[i].d;
			aa --;
			bb --;
			if (A[bb] - A[aa] == cc) {
				res += dd;
			}
		}
		ans = max(ans, res);
		return;
	}
	if (!x) {
		for (int i = 1; i <= m; i ++) {
			A[x] = i;
			bt(x + 1); 
			A[x] = 1;
		}
	}
	else {
		for (int i = A[x - 1]; i <= m; i ++) {
			A[x] = i;
			bt(x + 1);
			A[x] = 1;
		}
	}
}
int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i ++) {
    	ll a, b, c, d;
    	cin >> a >> b >> c >> d;
    	Q[i] = {a, b, c, d};
    }
    bt(0);
    cout << ans;
    return (0);
}

Measured memory_bytes: 3680
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll A, B; cin >> A >> B;
    char C; cin >> C;
    int D; cin >> D;
    B *= 100; B += D;
    ll X = A*B; X /= 100;
    cout << X << nl;
	
	return 0;
}
 


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n,b;
    int ans =0;
    scanf("%d%d",&n,&b);
    if(n>=13)printf("%d",b);
    else if(n>=6&&n<=12)printf("%d",b/2);
    else printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int M, D;
    cin >> M >> D;
    int ans = 0;
    FOR(mo, 1, M + 1) {
        FOR(day, 1, D + 1) {
            int d1 = day % 10;
            int d2 = day / 10;
            if (2 <= d1 && 2 <= d2 && d1 * d2 == mo)
                ans++;
        }
    }
    print(ans);

    return 0;
}

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

#define MAX 2000001
#define VMAX 10000

int
main(void)
{
        unsigned short *A, *B;

        int C[VMAX + 1];
        int A_len;
        int i, j;

        scanf("%d", &A_len);

        A = malloc(sizeof(short) * A_len + 1);
        B = malloc(sizeof(short) * A_len + 1);

        for (i = 0; i <= VMAX; i++)
                C[i] = 0;

        for (i = 0; i < A_len; i++) {
                scanf("%hu", &A[i + 1]);
                C[A[i + 1]]++;
        }

        for (i = 1; i <= VMAX; i++)
                C[i] = C[i] + C[i - 1];

        for (j = 1; j <= A_len; j++) {
                B[C[A[j]]] = A[j];
                C[A[j]]--;
        }

        for (i = 1; i <= A_len; i++) {
                if (i > 1)
                        printf(" ");
                printf("%d", B[i]);
        }
        printf("\n");

        return 0;
}



Measured memory_bytes: 9604
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int a[14];
int k;
int SUM=0;
int main(){
    for (int i=1;i<=3;i++){
        cin>>a[i];
        SUM+=a[i];
    }
    cin>>k;
    sort(a,a+4);
    for (int i=1;i<=k;i++){
         SUM+=a[3];
         a[3]*=2;
    }
    cout<<SUM<<endl;    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N;
bool path[100050];
vector<int> to[100050];

bool dfsp(int u, int p = -1) {
  int ch = 0;
  bool all = true;
  for (int v : to[u]) {
    if (v != p) {
      ++ch;
      all &= dfsp(v, u);
    }
  }
  return path[u] = (ch <= 1 && all);
}

int dfs(int u, int p = -1) {
  if (path[u]) {
    return 1;
  }
  bool ign = false;
  int res = 0;
  for (int v : to[u]) {
    if (v != p) {
      if (path[v] && !ign) {
        ign = true;
      } else {
        res += dfs(v, u);
      }
    }
  }
  return res;
}

int main() {
  N = in();
  int maxdeg = 0;
  for (int i = 0; i < N - 1; ++i) {
    int a = in();
    int b = in();
    to[a].push_back(b);
    to[b].push_back(a);
    if (to[a].size() > to[maxdeg].size()) {
      maxdeg = a;
    }
    if (to[b].size() > to[maxdeg].size()) {
      maxdeg = b;
    }
  }
  if (to[maxdeg].size() <= 2) {
    puts("1");
    return 0;
  }

  dfsp(maxdeg);
  printf("%d\n", dfs(maxdeg));

  return 0;
}


Measured memory_bytes: 11776
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, Q = [int(x) for x in input().split()]

    uf = UnionFind(N)

    for _ in range(Q):
        t, u, v = [int(x) for x in input().split()]
        if t == 1:
            print(int(uf.same(u, v)))
        else:
            uf.union(u, v)




if __name__ == '__main__':
    main()



Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string s;
	int len = 0;
	cin >> s;
	
	s.pop_back();
	
	for (int j = 0; j < (int)s.size(); j++) {
		string tmp = s;
		tmp.erase(tmp.find(s.substr(0, j)), (int)s.substr(0, j).size());
		if ((int)tmp.find(s.substr(0, j)) == 0) {
			if (len < (int)s.substr(0, j).size() * 2) {
				len = (int)s.substr(0, j).size() * 2;
			}
		}
	}

	cout << len << endl;
	
	return (0);
}

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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 2*1e5 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 78
// mbeginer
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];
//vector<ll>adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

ll n, m, k;
ll h[e];

int main()
{
    cin >> n;
    for(ll i=-1000; i<=1000; i++)
    {
        for(ll j=-1000; j<=1000; j++)
        {
            ll cur = i*i*i*i*i;
            ll curr = j*j*j*j*j;
            if(cur - curr == n)
            {
                cout <<i <<" "<<j;
                return 0;
            }
        }
    }
}
/*

*/


Measured memory_bytes: 3600
/** @Date    : 2017-07-09 11:12:52
  * @FileName: B 逻辑 思维.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

int a[N];
int main()
{
	int n;
	while(cin >> n)
	{
		int ma = 0, mi = INF;
		map<int, int>q;
		int cnt = 0;
		for(int i = 0; i < n; i++)
		{
			scanf("%d", a + i);
			ma = max(ma, a[i]);
			mi = min(mi, a[i]);
			if(!q[a[i]])
				cnt++;
		}
		int flag = 0;
		if(ma == mi)
		{
			if(a[0] == cnt - 1 || a[0] * 2 <= n)
				flag = 1;
			else flag = 0;
		}
		else if(ma - mi == 1)
		{
			int x, y;
			x = y = 0;
			for(int i = 0; i < n; i++)
			{
				if(a[i] == ma)
					y++;
				if(a[i] == mi)
					x++;
			}
			if(ma >= x + 1 && ma <= x + y / 2)
				flag = 1;
			else flag = 0;
		}
		printf("%s\n", flag?"Yes":"No");
	}
    return 0;
}

Measured memory_bytes: 5376
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	String x = sc.next();
        if (x.length() == 6 && (x.charAt(2) == x.charAt(3)) && (x.charAt(4) == x.charAt(5))) {
 			System.out.println("Yes");
        } else System.out.println("No");
    }
 }

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

int N, M;

std::priority_queue<int> q;

int main() {
    cin >> N >> M;
    vector<vector<int>> jobs(M);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        if (M < a) {
            continue;
        }
        jobs[M-a].push_back(b);
    }

    long long int ans = 0;
    for (int i = M-1; i >= 0; i--) {
        for (int b: jobs[i]) {
            q.push(b);
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;

/** Problem1153 : Equal Total Score **/
int main()
{
	int n, m;
	while (cin>>n>>m, n||m) {
		int taro[n], hanako[m], sumT=0, sumH=0;
		rep(i, n) {
			cin >> taro[i];
			sumT+=taro[i];
		}
		rep(i, m) {
			cin >> hanako[i];
			sumH+=hanako[i];
		}
		int tmpT=INF, tmpH=INF;
		rep(i, n) {
			rep(j, m) {
				if (sumT+hanako[j]-taro[i] == sumH-hanako[j]+taro[i]) {
					if (tmpT + tmpH>taro[i]+hanako[j]) {
						tmpT = taro[i]; tmpH = hanako[j];
					}
				}
			}
		}
		if (tmpT==INF)
			cout << -1 << endl;
		else
			cout << tmpT << " " << tmpH << endl;
	}
}

Measured memory_bytes: 1156
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a1, a2, a3; cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22) cout << "bust\n";
    else cout << "win\n";
    return 0;
}


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

const int maxn = 1e5+5;
int N, M, A[maxn], B[maxn];
vector<int> times[maxn];

int main()
{
	cin >> N >> M;
	multiset<int> curr;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
        if (A[i] <= M) times[A[i]].push_back(B[i]);
	}
    ll ans = 0;
    for (int i = 1; i <= M; i++) {
        for (int j: times[i]) {
            curr.insert(j);
        }
        if (!curr.empty()) {
            ans += *curr.rbegin();
            curr.erase(prev(curr.end()));
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 8576
a = int(input())
b = round(a**0.5) + 1

x = []
for i in range(1,b):
    for j in range(1,b):
        for k in range(1,b):
            l = i**2 + j**2 + k**2 + i*j + j*k + k*i
            x.append(l)

t = [0] * a
for i in range(0,len(x)):
    if x[i] <= a:
        t[x[i]-1] = t[x[i]-1] + 1

for i in t:
    print(i)

Measured memory_bytes: 49048
N, M = map(int, input().split())
t = [0] * (N+1)
for i in range(M):
    l, r = map(int, input().split())
    t[l-1] += 1
    t[r] -= 1

for i in range(N):
    if (0 < i):
        t[i] += t[i-1]

t = t[:-1]
m = max(t)
if m == M:
    print(t.count(m))
else:
    print(0)


Measured memory_bytes: 7668
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1, 0, 1, 1, -1, -1};
vector<int> dx = {1,-1,0,0, 0, 1, -1, 1, -1};


int main(void){
    ll N,M;
    cin >> N >> M;
    if(N == 2 || M == 2) cout << 0 << endl;
    else if(N == 1 && M == 1) cout << 1 << endl;
    else if(N == 1 || M == 1) cout << N + M - 3 << endl;
    else cout << (N-2) * (M-2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef pair<int, bool> ib;

#define FOR(a, b, c) for(int a = b; a < c; ++a)
#define RFOR(a, b, c) for(int a = b; a >= c; --a)
#define mp(a, b) make_pair(a, b)
#define all(v) v.begin(), v.end()

#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vb vector<bool>
#define fst first
#define snd second
#define MAXN 310
#define MAXM 44100
#define LOGMAXN 20
#define INF 1000000007
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007LL


int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	string s;
	while(cin >> s)
	{
		bool can = true;
		FOR(i, 0, (int) s.size())
		{
			if((i&1) == 0)
			{
				if(s[i] == 'L')
				{
					can = false;
					break;
				}
			}
			else
			{
				if(s[i] == 'R')
				{
					can = false;
					break;
				}
			}
		}
		printf("%s\n", can ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL a, b, c, k;
int main(){
    scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
    if(k & 1){
        LL ta, tb, tc;
        ta = b + c;
        tb = c + a;
        tc = a + b;
        a = ta;
        b = tb;
        c = tc;
    }
    printf("%lld", a - b);

}

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


def solve(parity):
    wa = 0
    ans = 0
    for i in range(n):
        wa += a[i]
        if i % 2 == parity:
            if wa >= 0:
                ans += wa + 1
                wa -= wa + 1
        else:
            if wa <= 0:
                ans += -wa + 1
                wa += -wa + 1
    return ans


print(min(solve(0), solve(1)))


Measured memory_bytes: 20132