akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

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

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max();
constexpr long long int mod = 1000000007;

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

    vector<int> v(n);
    REP(i, n) { cin >> v[i]; }

    vector<bool> dp(n * 100 + 1);
    dp[0] = true;
    REP(i,n){
        DEFOR(j,n*100+1,0){
            if(dp[j]){
                dp[j + v[i]] = true;
            }
        }
    }
    DEFOR(i,n*100+1,0){
        if(dp[i]&&i%10){
            cout << i << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m,s[100010];
	int cnt=0,mn=0x3f3f3f3f;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>m;
		if(m<=mn) 
		{
			mn=m;
			cnt++;
		}
		
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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 (b<a) { a=b; return 1; } return 0; }

lli n;
vector<lli> a, b, v;
vector<vector<lli>> g;
vector<bool> seen;
map<pair<lli, lli>, lli> mp;

void dfs(lli x, lli c){
    if(seen[x]) return;
    seen[x] = true;
    lli cur = 1;
    for(auto i : g[x]){
        if(seen[i]) continue;
        if(cur == c) cur++;
        mp[{x, i}] = cur;
        mp[{i, x}] = cur;
        dfs(i, cur);
        cur++;
    }
    return;
};

int main(void){
    cin >> n;
    a.resize(n-1);
    b.resize(n-1);
    v.resize(n);
    g.resize(n);
    seen.resize(n);
    lli k = 0;
    rep(i, n-1){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
        v[a[i]]++;
        v[b[i]]++;
        k = max({k, v[a[i]], v[b[i]]});
    }
    dfs(0, -1);
    cout << k << endl;
    rep(i, n-1){
        cout << mp[{a[i], b[i]}] << endl;
    }
    return 0;
}


Measured memory_bytes: 24036
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    //std::vector<int> dnaLen;
    int tmp;
    //cout << N << endl;
    int max = 0;
    int ans[2000000] ={};
    for(int i=0; i<N-1 ; i++){
        cin >> tmp;
        //cout << tmp << endl;
        if(tmp > max){
            //cout << max << endl; 
            max = tmp;
            ans[tmp] = 0;
        }
        ans[tmp] = ans[tmp] + 1;
    }
    //cout << "finish" << endl;
    for(int i=1; i<=N; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 11440
package main

import (
  "fmt"
  "strings"
  "bufio"
  "os"
  "strconv"
)

func main(){
  var result float64
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  n,_ := strconv.Atoi(scanner.Text())
  for i := 0;i < n;i++{
    scanner.Scan()
    b := strings.Fields(scanner.Text())
    x := b[0]
    u := b[1]
    xa,_ := strconv.ParseFloat(x,64)
    if strings.Contains(u,"BTC"){
      x := xa * 380000.0
      result += x
    } else {
      result += xa
    }
  }
  fmt.Println(result)
}

Measured memory_bytes: 640
using System;

class Program {
  static void Main() {
    var s = Console.ReadLine();
    while (true) {
      s = s.Substring(0, s.Length - 1);
      if ((s.Length & 1) == 1) continue;
      var a = s.Substring(0, s.Length / 2);
      var b = s.Substring(s.Length / 2);
      if (a == b) {
        Console.WriteLine(s.Length);
        break;
      }
    }
  }
}

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

int main() {
    string s;
    cin >> s;
    ll a, b, n=s.size();
    rep(i,n) {
        if(s.at(i)=='A') {
            a=i; 
            break;
        }
    }
    rep(i,n) {
        if(s.at(n-1-i)=='Z') {
            b=n-1-i;
            break;
        }
    }
    cout << b-a+1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 
vector<int> G[300001];
vector<int> dp(300001,0);


void dfs(int u,int cost){
    dp[u] += cost;
    for (int i = 0; i < G[u].size(); i++) {
        int to = G[u][i];
        dfs(to,dp[u]);
    }
}


int main(){
    int n,q;cin >> n >> q;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb(b);
    }
    for (int i = 0; i < q; i++) {
        int p,x;cin >> p >> x;
        p--;
        dp[p]+=x;
    }
    dfs(0,0);
    for (int i = 0; i < n; i++) {
        cout << dp[i] << (i==n-1?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 26240
#include <iostream>
#include<vector>
#include<climits>
#define ll long long
#include<cmath>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> s(n+5);
    vector<int>dp(n+5);
    dp[0]=dp[1]=0;
    s[0]=INT_MAX;
    for(int i=1; i<=n; i++){
        cin>>s[i];
    }
    for( int i=2; i<=n; i++ ){
        dp[i] = min( abs(s[i] - s[i-1])+dp[i-1] , abs(s[i] - s[i-2])+dp[i-2]);
    }
    cout<<dp[n];
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll s[100010], t[100010];
int main()
{
	int A, B, Q;
	cin >> A >> B >> Q;
	for (int i = 1; i <= A; i++) cin >> s[i];
	for (int i = 1; i <= B; i++) cin >> t[i];
	s[0] = -INF; s[A + 1] = INF;
	t[0] = -INF; t[B + 1] = INF;
	while (Q--) {
		ll x; cin >> x;
		int ok1 = 0;
		int ng1 = A + 2;
		while (abs(ok1 - ng1) > 1) {
			int mid = (ok1 + ng1) / 2;
			if (s[mid] < x) ok1 = mid;
			else ng1 = mid;
		}
		int ok2 = 0;
		int ng2 = B + 2;
		while (abs(ok2 - ng2) > 1) {
			int mid = (ok2 + ng2) / 2;
			if (t[mid] < x) ok2 = mid;
			else ng2 = mid;
		}
		ll ans = INF;
		ans = min(ans, abs(x - s[ok1]) + abs(s[ok1] - t[ok2]));
		ans = min(ans, abs(x - s[ok1]) + abs(s[ok1] - t[ok2 + 1]));
		ans = min(ans, abs(x - s[ok1 + 1]) + abs(s[ok1 + 1] - t[ok2 + 1]));
		ans = min(ans, abs(x - s[ok1 + 1]) + abs(s[ok1 + 1] - t[ok2]));
		ans = min(ans, abs(x - t[ok2]) + abs(t[ok2] - s[ok1]));
		ans = min(ans, abs(x - t[ok2]) + abs(t[ok2] - s[ok1 + 1]));
		ans = min(ans, abs(x - t[ok2 + 1]) + abs(t[ok2 + 1] - s[ok1]));
		ans = min(ans, abs(x - t[ok2 + 1]) + abs(t[ok2 + 1] - s[ok1 + 1]));
		cout << ans << endl;
	}
}


Measured memory_bytes: 5152
a, b, k = map(int, input().split())
small = []
big = []
for i in range(a, a+k):
    if i <= b:
        small.append(i)
for i in range(b-k+1, b+1):
    if i >= a:
        big.append(i)
ans = sorted(list(set(small) | set(big)))
for i in ans:
    print(i)

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

int main(){
    int n, x; cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int sum=0;
    int min=1001;
    rep(i,n) sum += a[i];
    rep(i,n){
        if(min > a[i]) min = a[i];
    }
    int ans = n + (x-sum)/min;
    cout << ans << endl;
}


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

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    ll bit;
    for(int i = 0; i < M; ++i)
        bit |= (1 << i);
    for(int i = 0; i < N; ++i) {
        int K;
        ll tmp = 0;
        cin >> K;
        for(int j = 0; j < K; ++j) {
            int a;
            cin >> a;
            a--;
            tmp |= (1 << a);
        }
        bit &= tmp;
    }
    for(int i = 0; i < M; ++i)
        if(bit & (1 << i))
            ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=100005;
const long long INF=4557430888798830399;
int n,m;
vector<pair<int,int> >pre[N];
struct Node
{
	int l,r;
	long long Min;
}tree[N<<2];
long long f[N];
void push_up(int i)
{
	tree[i].Min=min(tree[i*2].Min,tree[i*2+1].Min);
	return;
}
void build(int i,int l,int r)
{
	tree[i].l=l,tree[i].r=r;
	if(l==r)
	{
		tree[i].Min=f[l];
		return;
	}
	int mid=(l+r)/2;
	build(i*2,l,mid);
	build(i*2+1,mid+1,r);
	push_up(i);
	return;
}
long long query(int i,int l,int r)
{
	if(l>r) return INF;
	if(l<=tree[i].l&&tree[i].r<=r) return tree[i].Min;
	long long res=INF;
	if(l<=tree[i*2].r) res=min(res,query(i*2,l,r));
	if(r>=tree[i*2+1].l) res=min(res,query(i*2+1,l,r));
	return res;
}
void modify(int i,int u,long long val)
{
	if(tree[i].l==tree[i].r)
	{
		tree[i].Min=val;
		return;
	}
	if(u<=tree[i*2].r) modify(i*2,u,val);
	else modify(i*2+1,u,val);
	push_up(i);
	return;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int l,r,c;
		scanf("%d%d%d",&l,&r,&c);
		pre[r].push_back(make_pair(l,c));
	}
	memset(f,63,sizeof(f));
	f[1]=0;
	build(1,1,n);
	for(int r=1;r<=n;r++)
	{
		for(auto [l,c]:pre[r])
			f[r]=min(f[r],query(1,l,r-1)+c);
		modify(1,r,f[r]);
	}
	if(f[n]>=INF) printf("-1");
	else printf("%lld",f[n]);
	return 0;
}

Measured memory_bytes: 13976
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long int gcd(long long int a, long long int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
long long int lcm(long long int a, long long int b){
	return a / gcd(a, b) * b;
}
int main(){
int N; 
cin >> N; 
long long int T[110]; 
for(int i = 0; i < N; i++){
cin >> T[i]; 
}
long long int ans = T[0]; 
for(int i = 0; i < N; i++){
ans = lcm(ans, T[i]); 
}
cout << ans << endl; 
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

int n, k, a, mx, gd;

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

int main(){
	cin >> n >> k >> a;
	gd = mx = a;
	lp(n - 1) {
		cin >> a;
		mx = max(mx, a);
		gd = gcd(gd, a);
	}
	cout << (k > mx || (mx - k) % gd != 0 ? "IMPOSSIBLE" : "POSSIBLE") << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int a,b,c,d;
  
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = N-a*1000-b*100-c*10;
  
  if((a == b && a == c) || (b == c && b == d))
    cout << "Yes" << endl;
  
  else
    cout << "No" << endl;
  
}

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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;

vector <int> adj[100005];
ll int dp[100005][2];

ll int dfs(int node, int pn, int colour)
{
  if(dp[node][colour] != -1)
    return dp[node][colour];

  dp[node][colour] = 1;

  for(int i=0;i<adj[node].size();i++)
    if(adj[node][i] != pn)
    {
      if(colour)
      {
        dp[node][colour] = (dp[node][colour] * dfs(adj[node][i], node, 1-colour)) % mod;
      }
      else
      {
        ll int res = (dfs(adj[node][i], node, colour) + dfs(adj[node][i], node, 1-colour)) % mod;
        dp[node][colour] = (dp[node][colour] * res) % mod;
      }
    }

  return dp[node][colour] % mod;
}


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

  memset(dp, -1, sizeof dp);
  int n, x, y;
  cin>>n;

  for(int i=0;i<n-1;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  cout<<(dfs(1, -1, 0) + dfs(1, -1, 1)) % mod <<endl;

  return 0;
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {

    int arr[3];

    cn arr[0]>>arr[1]>>arr[2]; ct arr[2] spc arr[0] spc arr[1];nl;









    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int H, W;
	while (cin >> H >> W) {
		if (H == 0 && W == 0) {
			break;
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i > 0 && i < H - 1 && j>0 && j < W - 1) {
					cout << ".";
				}
				else {
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

int main(){
  int N,sum;
  cin >> N;
  vector<int> Worth(N);
  vector<int> Cost(N);
  vector<int> total_worth(N);
  for(int i = 0;i < N;i++){
    cin >> Worth.at(i);
  }
  for(int i = 0;i < N;i++){
    cin >> Cost.at(i);
  }
  for(int i = 0;i < N;i++){
    total_worth.at(i)=Worth.at(i)-Cost.at(i);
    if(total_worth.at(i)>0){
      sum +=total_worth.at(i);
    }
  }
  
  cout << sum;
  
    

         
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	ll sum = 0;
	for (auto v : s) {
		sum+=v-'0';
	}
	cout << (sum % 9 == 0 ? "Yes\n" : "No\n");

}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

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

    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
    int H,W; cin>>H>>W;
    vii A(H,vi(W));
    rep(i,0,H){
        rep(j,0,W) cin>>A[i][j];
    }
    rep(i,0,H){
        rep(j,0,W){
            int X; cin>>X;
            A[i][j]-=X;
        }
    }
    bool dp[81][81][25601];
    dp[0][1][12800]=1;
    rep(i,0,H){
        rep(j,0,W){
            REP(k,0,25600){
                if(dp[i][j+1][k]||dp[i+1][j][k]){
                    dp[i+1][j+1][k+A[i][j]]=1;
                    dp[i+1][j+1][k-A[i][j]]=1;
                }
            }
        }
    }
    int ans=INF;
    REP(i,0,25600){
        if(dp[H][W][i]) ans=min(ans,abs(i-12800));
    }
    cout<<ans<<endl;
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 1E5 + 10;

int a[N];

int main(){
	int n, K;
	scanf("%d%d", &n, &K);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);

	int ans = 1e9;
	for (int i = K - 1; i < n; ++i){
		int j = i - (K - 1);
		ans = min(ans, (a[i] - a[j]) + min(abs(a[i]), abs(a[j])));
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUT2TEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
//TEST??????????????????????????¨???outputfile??????????????????????????????
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif



#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl


const int INF = 2e9-1;



int main(){

    int n;
    cin >> n;
    
    string s;
    cin >> s;
    
    int ans = 1;
    char c = s[0];
    rep(i,1,s.size()) {
        if( c == 'x' && s[i] == 'x' ) break;
        ans++;
        c=s[i];
    }
    
    cout << ans << endl;
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <cstring>

using namespace std;

void initiate(int* a)
{
	for (int j=0; j<101; j++) a[j] = 0;
}

int main()
{
	int a[101], b[101];
	char buf[101];
	
	int datasets;
	cin >> datasets;
	
	int len;
	
	for (int i=0; i<datasets; i++) {
		initiate(a); initiate(b);
		cin >> buf;
		len = strlen(buf);
		for (int j=0; j<len; j++) a[j] = static_cast<int>(buf[len-j-1] - 48);
		cin >> buf;
		len = strlen(buf);
		for (int j=0; j<len; j++) b[j] = static_cast<int>(buf[len-j-1] - 48);
		
		//test
		//for (int j=0; j<100; j++) cout << a[j];
		//cout << endl;
		//for (int j=0; j<100; j++) cout << b[j];
		//cout << endl;
		
		int carry = 0;
		for (int j=0; j<101; j++) {
			a[j] += b[j] + carry;
			carry = a[j] / 10;
			a[j] -= carry * 10;
		}
		
		bool nonzeroFlg = false;
		for (int j=100; j>=0; j--) {
			if (j>=80 && a[j]>0) {
				cout << "overflow";
				break;
			}
			if (a[j]>0) nonzeroFlg = true;
			if (nonzeroFlg) cout << a[j];
			if (j==0 && !nonzeroFlg) cout << 0;
		}
		
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;
double a[N];
int main()
{
	int n,ind=1;
	cin>>n;
	double x,p,diff,T,A;
	cin>>T>>A;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		diff=T-x*0.006;
		if(i==1||abs(A-diff)<p)
		{
			p=abs(A-diff);
			ind=i;
		}
	}
	cout<<ind;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <map>
#include <string>

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

void solve()
{
	int n;
	while(cin >> n, n)
	{
		map<P, int> Map;
		for(int i = 0; i < n; ++i)
		{
			int num;
			cin >> num;
			P p;
			p.second = -num;
			string str;
			getline(cin, str);
			str += " ";
			int size = str.size();
			vector<int> Vec;
			int s = 0;
			for(int j = 1; j < size; ++j)
			{
				if(str[j] == ' ')
				{
					Vec.push_back(s);
					s = 0;
				}
				else
				{
					s *= 10;
					s += str[j] - '0';
				}
			}
			int sum = 0;
			size = Vec.size();
			Vec.push_back(0);
			Vec.push_back(0);
			int count = 0;
			int bonus = 0;
			int point = 0;
			int frame = 0;
			for(int i = 0; i < size; ++i)
			{
				if(count % 2 == 0)
				{
					count %= 2;
					point = 0;
					++frame;
				}
				++count;
				if(frame >= 10)
				{
					sum += Vec[i];
					continue;
				}
				point += Vec[i];
				sum += Vec[i];
				if(count == 2 && point == 10)		//spare
				{
					bonus = 1;
				}
				if(count == 1 && point == 10)		//strike
				{
					bonus = 2;
					count = 2;
				}
				if(bonus == 1)
				{
					sum += Vec[i + 1];
					bonus = 0;
				}
				else if(bonus == 2)
				{
					sum += Vec[i + 1] + Vec[i + 2];
					bonus = 0;
				}				
			}
			p.first = sum;
			++Map[p];
		}
		map<P, int>::iterator It = Map.end();
		--It;
		for(int i = 0; i < n; ++i)
		{
			cout << -It->first.second << " " << It->first.first << endl;
			--It;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

int main(){
    int K,A,B;
    cin >> K >> A >> B;
    for(int i=A;i<=B;i++){
        if(i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}

bool cmp(const pair<int , int> &a , const pair<int , int> &b){
    return (a.first < b.first);
}



int main()
{
    weewoo;
    ll n,a,b;
    cin >> n >> a >> b;
    ll cur=n/(a+b);
    cout << a*cur + min(a,n%(a+b)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

lld gcd(lld a, lld b) {
  lld r;
  while (1) {
    if (b == 0) {
      return a;
    }
    r = a % b;
    a = b;
    b = r;
  }
}

int main(void) {
  lld n;
  cin >> n;
  cout << (360 / gcd(360, n)) << "\n";
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n-1) cin >> b[i];
  b[n-1] = 1000001;

  int ans = b[0];
  int right;
  for(int i = 0; i < n-1; ++i)
  {
    if(b[i] < b[i+1])
      ans += b[i];
    else
      ans += b[i+1];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a[1:])
ans = abs(x - y)
for i in range(1, n - 1):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x - y))
print(ans)


Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<char> a(3);
  for(int i=0; i<3; i++){
    cin>>a[i];
  }
  if(a[0]==a[1] && a[1]== a[2]){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}
       

Measured memory_bytes: 256
e=["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"]
h,w=map(int,input().split())
a=[input().split() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=="snuke":
            print(e[j]+str((i+1)))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll mod = 998244353;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	Combination comb(1000000);
	mint ans = 0;
	for(ll i = 0; i <= n; ++i){
		ll r = k - a * i;
		if(r < 0) continue;
		if(r%b != 0) continue;
		ll j = r / b;
		ans += comb(n, i) * comb(n, j);
	}
	cout << ans.x << endl;
	return 0;
}

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

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

  vector<int> s;
  vector<int> ord(n+1, -1);
  int c = 1; int l;

  int v = 1;
  while (ord[v] == -1){
    ord[v] = s.size();
    s.push_back(v);
    v = a[v-1];
  }
  c = s.size() - ord[v];
  l = ord[v];

  if (k < l) cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[l+k] << endl;
  }

  return 0;
}


Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
int main(){
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double nans = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
    double ans = sqrt(nans);
    printf("%.6f", ans);
}


Measured memory_bytes: 3276
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <cmath>

#include <bitset>

const int MAX  = 100010;
int a[MAX][3];
int dp[MAX][3];

template<class T>
bool chmax(T& a,T b){{if(a < b) a = b;return true;}return false;}
int main(){

    int N;
    cin >> N;

    for(int i = 0;i < N;i++) for(int j = 0;j < 3;j++)cin >> a[i][j];

    //初期化
    memset(dp,0,sizeof(dp));
    //初期条件も０でOK

    for(int i = 0;i < N;i++){
        for(int j = 0;j < 3;j++){
            for(int k = 0;k < 3;k++){
                if(j == k) continue;
                chmax(dp[i + 1][k],dp[i][j] + a[i][k]);
            }
        }
    }
  
    int max = 0;
    for(int j = 0;j < 3;j++){
        chmax(max,dp[N][j]);
    }
  
    cout << max << endl;
    return 0;
}

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

#define fi first
#define se second
#define eb emplace_back

typedef long long ll;

using namespace std;

const int nm = 200010;
const ll mod = 998244353;

int n, q;
ll tree[4 * nm], power[nm], same[10][nm];
int add[4 * nm];

void build(int l, int r, int id) {
	if (l == r) {
		tree[id] = 1;
		return;
	}
	int m = (l + r) >> 1, c1 = id << 1, c2 = c1 ^ 1;;
	build(l, m, c1);
	build(m + 1, r, c2);
	tree[id] = (tree[c1] * power[r - m] + tree[c2]) % mod;
}

void update(int u, int v, int d, int l, int r, int id) {
	if (u == l && v == r) {
		tree[id] = same[d][r - l + 1];
		add[id] = d;
		return;
	}
	int m = (l + r) >> 1, c1 = id << 1, c2 = c1 ^ 1;
	if (add[id]) {
		tree[c1] = same[add[id]][m - l + 1];
		add[c1] = add[id];
		tree[c2] = same[add[id]][r - m];
		add[c2] = add[id];
		add[id] = 0;
	}
	if (u <= m) {
		update(u, min(m, v), d, l, m, c1);
	}
	if (v > m) {
		update(max(u, m + 1), v, d, m + 1, r, c2);
	}
	tree[id] = (tree[c1] * power[r - m] + tree[c2]) % mod;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    power[0] = 1;

    for (int i = 1; i <= n; ++i) {
    	power[i] = (power[i - 1] * 10) % mod;
    	for (int j = 1; j <= 9; ++j) {
    		same[j][i] = (same[j][i - 1] * 10 + j) % mod;
    	}
    }
    build(1, n, 1);
    for (int i = 1; i <= q; ++i) {
    	int l, r, d;
    	cin >> l >> r >> d;
    	update(l, r, d, 1, n, 1);
    	cout << tree[1] << "\n";
    }
}


Measured memory_bytes: 25396
#include<stdio.h>
#define MAX 10

int main()
{
        char str[MAX];
        int i;

        scanf("%s", str);

        if(str[0]=='Y'&&str[1]=='A'&&str[2]=='K'&&str[3]=='I')printf("Yes\n");
        else printf("No\n");

        return 0;
}

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

int main(){

	string s, t;
	cin >> s >> t;
	if(s.size()+1 != t.size()){
		cout << "No\n";
		return 0;
	}
	for(int i = 0; i < s.size(); i++){
		if(s[i] != t[i]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";

	return 0;
}

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

int main() {
  int k;
  cin>>k;
  int count=0;
  int judge=0;
  for(int i=0;i<k;i++){
    int a,b;
    cin>>a>>b;
    if(a==b){
      count++;
      if(count==3){
        judge=1;
        
        break;
      }
    }
    else{
      count=0;
    }
  }
  
  if(judge==1){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  
  
}


Measured memory_bytes: 3620
fun main(args: Array<String>) {
  val N = readInt()
  val A = readInts()

  var current = 1
  var cnt = 0
  for (i in 0 until N) {
    val a = A[i]
    if (a == current) {
      current++
    } else {
      cnt++
    }
  }
  println(if (current == 1) -1 else cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 82796
require 'set'

MOD = 10 ** 9 + 9

$fact = [1]
(1..2*10**6).each do |i|
  $fact << $fact[-1] * i % MOD
end

def comb(n, k)
  $fact[n] * inv($fact[k]) * inv($fact[n - k]) % MOD
end

def inv(k)
  exp(k, MOD - 2, MOD)
end

def exp(n, k, mod = nil)
    x = 1
    r = n
    while k > 0
        x *= r if k & 1 == 1
        r *= r
        if mod
            x %= mod
            r %= mod
        end
        k >>= 1
    end
    x
end

n, m = gets.split.map(&:to_i)
points = (1..m).map { gets.split.map(&:to_i) }.map {|x, y| [x - 1, y - 1] }.sort_by {|x, y| x + y }

def bfs(n, m, points, xs, ys)
  s = [xs, ys]
  reached = Set[s]
  reached += points
  queue = [s]
  count = Hash.new(0)
  count[s] = 1
  dist = { s => 0 }
  until queue.empty?
    x, y = queue.shift
    k = count[[x, y]]
    d = dist[[x, y]]
    [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dx, dy|
      u, v = x + dx, y + dy
      count[[u, v]] += k if dist[[u, v]] == nil or dist[[u, v]] == d + 1
      next if reached.include?([u, v]) or
        u < 0 or u >= n or
        v < 0 or v >= n or
        (xs - u).abs + (ys - v).abs > m
      reached << [u, v]
      dist[[u, v]] = d + 1
      queue << [u, v]
    end
  end
  return [dist, count]
end

if n <= 150
  _, count = bfs(n, 2 * n, points, 0, 0)
  puts (count[[n - 1, n - 1]] || 0) % MOD
  exit
end

dist1, count1 = bfs(n, m, points, 0, 0)
dist2, count2 = bfs(n, m, points, n - 1, n - 1)

d = (0..m).map {|i| dist1[[i, m - i]] || -Float::INFINITY }.min
starts = (0..m).map {|i| [i, m - i] }.select {|v| dist1[v] == d }
d = (0..m).map {|i| dist2[[n - 1 - i, n - 1 - m + i]] || -Float::INFINITY }.min
ends = (0..m).map {|i| [n - 1 - i, n - 1 - m + i] }.select {|v| dist2[v] == d }

total = 0
starts.each do |xs, ys|
  xe, ye = n - 1, n - 1
  ends.each do |xe, ye|
    valid_points = points.select {|x, y| (xs..xe) === x && (ys..ye) === y } + [[xe, ye]]
    a = []
    (0..valid_points.size-1).each do |i|
      x1, y1 = valid_points[i]
      c = comb(x1 - xs + y1 - ys, x1 - xs)
      (0..i-1).each do |j|
        x2, y2 = valid_points[j]
        next if x2 > x1 or y2 > y1
        c = (c - a[j] * comb(x1 - x2 + y1 - y2, x1 - x2)) % MOD
      end
      a << c
    end
    total += count1[[xs, ys]] * a[-1] * count2[[xe, ye]] % MOD
  end
end
p total % MOD



Measured memory_bytes: 25088
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    sort(all(in));
    int sum=0;
    rep(i,n)sum+=in[i]*(n-i);
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1216
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        HashSet<String> hs = new HashSet<>();
        for(int i = 0; i < n; i++){
            hs.add(s.substring(i,i+1));
        }
        int[] kinds = new int[n];
        for(String c : hs){
            int f = s.indexOf(c);
            int l = s.lastIndexOf(c);
            if(f == l){
                continue;
            }
            for(int i = f; i < l; i++){
                kinds[i]++;
            }
        }
        int ans = 0;
        for(int k : kinds){
            ans = Math.max(ans,k);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
def main():
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    d=[v[i] - c[i] for i in range(n)]
    print(sum((x for x in d if x > 0)))
    
if __name__ == "__main__":
    main()

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

using namespace std;

void solve()
{
	double n;
	while(cin >> n)
	{
		if(n < 0)
		{
			break;
		}
		string str;
		int k = 128;
		for(int i = 0; i < 8; ++i)
		{
			if(n >= k)
			{
				n -= k;
				str += "1";
			}
			else
			{
				str += "0";
			}
			k /= 2;
		}
		str += ".";
		double f = 0.5;
		for(int i = 0; i < 4; ++i)
		{
			if(n >= f)
			{
				n -= f;
				str += "1";
			}
			else
			{
				str += "0";
			}
			f /= 2;
		}
		if(n < 1e-8)
		{
			cout << str << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1220
#!/usr/bin/perl

my $s = <STDIN>;
$s =~ s/[\x00-\x20]+$//io;

unless( $s =~ /^A/o ){
  print "WA\n" ;
  exit(0);
}
substr($s,0,1) = 'a';

my $cc = 0;
for(my $i=2;$i<length($s)-1;$i++){
  if( substr($s,$i,1) eq 'C'){
    $cc++;
    substr($s,$i,1) = 'c';
  }
}

if( $cc != 1 ){
  print "WA\n" ;
  exit(0);
}

unless( $s =~ /^[a-z]+$/o ){
  print "WA\n" ;
  exit(0);
}

print "AC\n";

exit(0);





Measured memory_bytes: 512
function parseInt(x) parse(Int, x) end

function main()
	n = parseInt(readline())
	d = parseInt.(split(readline()))
	count = 0
	for i in 1:n
		a = parseInt(readline())
		p = (d[1]-1)%a
		q = convert(Int, (d[1]-1-p)/a)
		count += q+1
	end
	count += d[2]
	print(count)
end

main()

Measured memory_bytes: 114072
#f problem
import math
import re
import os
import sys
N = int(input())
X = [0] * N
ans = 0
for i in range(N-1):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    #take +1 if...
    if x > y: x, y = y, x
    ans += (y - x) * (N - y + x + 1)
    X[x] += 1
    X[y] += 1
    #the pivot off
for i, x in enumerate(X):
    ans += (i + 1) * (N - i) * (2 - x)
print(ans // 2)#//2 -1 possible.  # solution master

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

using namespace std;

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    
    string str;
    cin >> str;
    
    bool is_not_2w = true;
    int sp_counter = 0;
    bool is_ch = false;
    for(int n=A; n<str.size(); n++) {
        if(str[n]=='#') {
            if(n<str.size()-1 && (n<C||n<D)) {
                if(str[n+1]=='#') {
                    is_not_2w = false;
                }
            }
            sp_counter = 0;
        } else {
            sp_counter++;
            
            if(n>=B && n<=D) {
                if(sp_counter>=3) {
                    is_ch = true;
                }
            }
        }
    }
    
    if(C<D) {
        if(is_not_2w) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if(is_not_2w && is_ch) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    
    return 0;
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define vi vector<ll>
# define vvi vector<vi>
# define rep(i, N) for (int i = 0; i < N; i++)
# define Rep(i, N) for (int i = 1; i <= N; i++)
# define deb(x) cerr << #x << ": " << x << endl;
# define deb2(x, i) cerr << #x << "[" << i << "]: " << x[i] << endl;
/*
vi v(10, 2); 
rep(i, 10) deb2(v, i); 
*/

/*
int a; cin >> a;
int a, b; cin >> a >> b;
rep(i, n){cin >> v[i];}
cout <<   << endl;
*/

signed		main()
{
	int a, b, c; cin >> a >> b >> c;
	cout << ((a+b + 1 >= c ? c: a + b + 1) + b) << endl;	
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long

int W, H;
vector<vector<int>> field;

void dfs(int h, int w) {
	field[h][w] = 0;

	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			int nh = h + dy;
			int nw = w + dx;

			if (nh < 0 || nw < 0 || nh >= H || nw >= W)continue;
			if (field[nh][nw] == 0)continue;

			dfs(nh, nw);
		}
	}
}

int main() {
	while (1) {
		cin >> W >> H;
		if (W == 0 && H == 0)break;
		field.assign(H, vector<int>(W, 0));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> field[i][j];
			}
		}
		int ans = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (field[i][j] == 0)continue;
				dfs(i, j);
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3356
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#define INF 999999999
const int MX=1e5+10;
using namespace std;
int vis[MX];
vector<int>vc[MX],e1,e2;
void dfs(int x,vector<int>& v){
	v.push_back(x);
	vis[x]=1;
	for(int i=0;i<vc[x].size();i++)
		if(!vis[vc[x][i]])
		{
			dfs(vc[x][i],v);
			return;
		}
}
int main()
{
    int n,m;
	cin>>n>>m;
	int ta,tb;
	while(m--){
		cin>>ta>>tb;
		vc[ta].push_back(tb);
		vc[tb].push_back(ta);
	}
	vis[ta]=1;vis[tb]=1;
	dfs(ta,e1);
	dfs(tb,e2);
	reverse(e1.begin(),e1.end());
	cout<<e1.size()+e2.size()<<endl;
	for(int i=0;i<e1.size();i++)
		cout<<e1[i]<<" ";
	for(int i=0;i<e2.size();i++)
		cout<<e2[i]<<" ";
	cout<<endl;
	//system("pause");
    return 0;
}

Measured memory_bytes: 9720
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    string s, t;
    int count = 0;
    cin >> s >> t;
    for (int i = 0; i < 3; i++) {
        if (s.at(i) == t.at(i)) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
from bisect import bisect

n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())

#r[i][j]: jから(2**i)日で行ける右端
r = [[i for i in range(n)] for _ in range(18)]
for j in range(n):
	r[0][j] = bisect(x, x[j]+l) - 1
for i in range(1, 18):
	for j in range(n):
		r[i][j] = r[i-1][r[i-1][j]]

def search(x, y):
	res = 0
	cur = x
	i = 17
	while True:
		if i == 0 and r[i][cur] >= y:
			return res+1
		if r[i][cur] < y:
			cur = r[i][cur]
			res += 1 << i
			continue
		i -= 1

for _ in range(q):
	a, b = map(int, input().split())
	print(search(min(a, b)-1, max(a, b)-1))

Measured memory_bytes: 118896
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i=a; i<b; i++)
// #define endl "\n"
const int mod = 1000000007;
const ll INF = 1e18L + 5;

ll power(ll x, ll y) 
{ 
    ll res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
        res%=mod;
        // n must be even now 
        y = y>>1; // y = y/2 
        x = x*x;
        x%=mod;  // Change x to x^2 
    } 
    return res%mod; 
}

const int nax = 1e5 + 5;
vector<int> edges[nax];
vector<int> dp(nax, -1);
int dfs(int a){
    if(edges[a].size()==0){
        dp[a]=0;
        return 0;
    }
    
    if(dp[a]!=-1)
        return dp[a];
    
    int max_so_far=-1;
    for(int i=0; i<edges[a].size(); i++){
        max_so_far = max(max_so_far, dfs(edges[a][i]));
    }

    dp[a] = max_so_far+1;

    return dp[a];    

}

int main() {
    ios_base::sync_with_stdio(false);    //Fast I/O
    cin.tie(NULL);
 
    // freopen("input.txt", "r", stdin);    // Read and write from a file
    // freopen("output.txt", "w", stdout);
    int n,m;
    cin >> n >> m;
    int a,b;
    rep(i,0,m){
        cin >> a >> b;
        edges[a].push_back(b);
    }
    for(int i=1; i<=n; i++)
        edges[0].push_back(i);

    cout << dfs(0)-1 << endl;

    return 0;
}

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

typedef long long ll;

// Union-Find
// verified AOJ DSL_1_A
struct UF {
    vector<int> p;  // parent
    vector<int> r;  // rank

    UF(int n) {
        p.resize(n);
        r.resize(n);
        for(int i=0;i<n;i++){
            p[i] = i;
            r[i] = 1;
        }
    }

    int find(int x) {
        if(x == p[x]){
            return x;
        }else{
            return p[x] = find(p[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(r[x] < r[y]){
            p[x] = y;
        }else{
            p[y] = x;
            if(r[x] == r[y]){
                r[x]++;
            }
        }
    }
};


struct V {
    int id;
    ll x, y;
};

struct E {
    ll w;
    int s, t;
};

// 最小全域木 (Minimum spanning tree)
struct MST {
    static vector<E> solve(int n, vector<E> e) {
        UF uf(n);
        vector<E> ret;
        sort(e.begin(), e.end(), [](E e1, E e2){
                return e1.w < e2.w;
                });
        for(auto ee : e){
            if(uf.find(ee.s) != uf.find(ee.t)){
                uf.unite(ee.s, ee.t);
                ret.push_back({ee.w, ee.s, ee.t});
            }
        }
        return ret;
    }
};

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

    UF uf(n);
    vector<V> v(n);
    vector<E> e;

    for(int i=0;i<n;i++){
        ll x, y;
        cin >> x >> y;
        v[i] = {i, x, y};
    }

    // x sort
    sort(v.begin(), v.end(), [](V v1, V v2){
            return v1.x != v2.x ? v1.x < v2.x : v1.y < v2.y;
            });
    for(int i=0;i<n-1;i++){
        ll w = min(abs(v[i].x - v[i+1].x), abs(v[i].y - v[i+1].y));
        e.push_back({w, v[i].id, v[i+1].id});
    }

    // y sort
    sort(v.begin(), v.end(), [](V v1, V v2){
            return v1.y != v2.y ? v1.y < v2.y : v1.x < v2.x;
            });
    for(int i=0;i<n-1;i++){
        ll w = min(abs(v[i].x - v[i+1].x), abs(v[i].y - v[i+1].y));
        e.push_back({w, v[i].id, v[i+1].id});
    }

    // solve
    auto mst = MST::solve(n, e);

    ll ans = 0;
    for(auto v : mst){
        ans += v.w;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14700