akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    ll n, m;
    string s;
    cin >> n >> m >> s;
    ll p = n;
    vector<ll> ans;
    while(p > 0){
        for(ll k = min(m, p); k >= 1; k--){
            if(s[p - k] == '0'){
                p -= k;
                ans.push_back(k);
                break;
            }
            if(k == 1){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    REP(i, ans.size()){
        cout << ans[i] << " \n"[i == ans.size() - 1];
    }
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
#define INF (1ll<<60)
typedef pair<li, li> PI;


li dp[1010][1010];
string board[1010];

int main(void)
{
	li h, w;
	cin >> h >> w;
	rep(i, h) {
		cin >> board[i];
	}
	dp[0][0] = 1;
	rep(i, h) {
		rep(j, w) {
			if (max(i, j) == 0)continue;
			if (board[i][j] == '#')continue;
			dp[i][j] = 0;
			if (i > 0 && board[i - 1][j] == '.') {
				dp[i][j] += dp[i - 1][j];
			}
			if (j > 0 && board[i][j - 1] == '.') {
				dp[i][j] += dp[i][j - 1];
			}
			dp[i][j] = dp[i][j] % MOD;
		}
	}
	cout << dp[h - 1][w - 1] << endl;

	return 0;
}

Measured memory_bytes: 9216
import math
N=int(input())
ans=[0]*(N+1)

for x in range(1,int(math.sqrt(N))+1):
    for y in range(1,int(math.sqrt(N))+1):
        for z in range(1,int(math.sqrt(N)+1)):
            c=x**2+y**2+z**2+x*y+y*z+z*x
            if c<=N:
                ans[c]+=1

for i in range(1,N+1):
    print(ans[i])


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

int main(){
  int N,Q,count=0,l,r;
  string S;
  cin>>N>>Q>>S;
  vector<int> vec(N,0);
 
  for(int i=0;i<N-1;i++){
    if(S.at(i)=='A'&&S.at(i+1)=='C')
      vec.at(i+1)=vec.at(i)+1;
    else
      vec.at(i+1)=vec.at(i);
  }

  for(int i=0;i<Q;i++){
    cin>>l>>r;
    cout<<vec.at(r-1)-vec.at(l-1)<<endl;
  }
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  int mi = INF;
  int argmi = -1;
  for(int i=0;i<n;++i) {
    int a; cin >> a;
    if(mi > a) {
      mi = a;
      argmi = i;
    }
  }
  cout << argmi + 1 << endl;

}



Measured memory_bytes: 3216
#include <iostream>
#define NMAX 1000
#define MOD 1000000007

using namespace std;

int n, m, a[NMAX+10][NMAX+10], dp[NMAX+10][NMAX+10];

int main()
{
    cin >> n >> m;
    for(int i=1; i<=n; i++)
        {   string s;
            cin >> s;
            for(int j=0; j<m; j++)
                if(s[j] == '#') a[i][j+1] = 1;
        }
    dp[0][1] = 1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            {   if(a[i][j]) continue;
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }
    cout << dp[n][m] << '\n';
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <bits/stdc++.h>
#include<math.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define debug(a) cout<<a<<'\n'
typedef pair<int,int> pii;
typedef long long ll;
#define PB push_back
#define II second
#define I first
#define MP make_pair
int main() {
	//code
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++)
        cin>>a[i];
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
    {
        int mini=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i-j>-1)
                mini=min(dp[i-j]+abs(a[i]-a[i-j]),mini);
        }
        dp[i]=mini;
    }
    cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[4],b,c,i,l,m;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    l=a[1]-a[0];
    m=a[2]-a[1];
    if(l==m){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include "stdio.h"
#include "math.h"
using namespace std;
int main(){
    
    double r;
    cin >> r;
    
    double a,b;
    a = 2* M_PI *r;
    b = r*r *M_PI;
   printf("%.5lf %.5lf",b,a);
}


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

#define REP(i,num) for(int i=0;i<(num);++i)

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

  int N=in();
  vector<ll> A(N);
  REP(i,N) A[i]=in();
  
  vector<array<ll,2>> dp(N+1);
  dp[0][0]=0;
  dp[0][1]=-1e12;
  for(int i=0;i<N;i++){
    dp[i+1][0] = max(dp[i][0]+A[i],dp[i][1]-A[i]);
    dp[i+1][1] = max(dp[i][0]-A[i],dp[i][1]+A[i]);
  }
  cout << dp[N][0] << endl;
  
  return 0;
}

Measured memory_bytes: 2560
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
string s;
int main(){
	cin>>s;
	cout<<s[0];
	cin>>s;
	cout<<s[0];
	cin>>s;
	cout<<s[0];
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <map>
typedef long long ll;
int p[5005], tot;
bool np[5005];
std::map<ll, int> app;
std::map<ll, ll> ano;
int main()
{
	// freopen("AGC003-D.in", "r", stdin);
	for (int i = 2; i <= 5000; i++)
	{
		if (!np[i])
			p[tot++] = i;
		for (int j = 0; j < tot && p[j] * i <= 5000; j++)
		{
			np[i * p[j]] = true;
			if (!(i % p[j]))
				break;
		}
	}
	int n;
	scanf("%d", &n);
	while (n--)
	{
		ll x, a = 1, b = 1;
		scanf("%lld", &x);
		for (int j = 0; j < tot; j++)
		{
			int cnt = 0;
			while (!(x % p[j]))
			{
				x /= p[j];
				cnt = (cnt + 1) % 3;
			}
			switch (cnt)
			{
			case 1:
				a *= p[j];
				b *= p[j] * p[j];
				break;
			case 2:
				a *= p[j] * p[j];
				b *= p[j];
			}
		}
		ll res = sqrt(x);
		if (res * res == x)
		{
			a *= x;
			b *= res;
		}
		else
		{
			a *= x;
			b *= x * x;
		}
		app[a]++;
		ano[std::min(a, b)] = std::max(a, b);
	}
	int ans = app[1] != 0;
	for (auto &it : ano)
	{
		if (it.first != 1)
			ans += std::max(app[it.first], app[it.second]);
	}
	printf("%d\n", ans);
	return 0;
}


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

class UF{
  public:
    vector<int> rank, p;

    UF(){}
    UF(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }

    int findSet(int x){
        if(x != p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    UF uf(n);
    int x, y, z;
    for(int i = 0; i < m; i++){
        cin >> x >> y >> z;
        x--, y--;
        uf.unite(x,y);
    }
    set<int> res;
    for(int i = 0; i < n; i++)  res.insert(uf.findSet(i));
    cout << res.size() << endl;
    return 0;
}

Measured memory_bytes: 5760
from collections import Counter

n = int(input())
v = [int(v) for v in input().split()]

even = Counter(v[::2])
odd = Counter(v[1::2])
even_most_common = even.most_common(2)
odd_most_common = odd.most_common(2)


ans = 0
if even_most_common[0][0] == odd_most_common[0][0]:
    if len(even_most_common) == 1 and len(odd_most_common) == 1:
        ans += n // 2
    elif len(even_most_common) == 1:
        ans += n // 2 - odd_most_common[1][1]
    elif len(odd_most_common) == 1:
        ans += n // 2 - even_most_common[1][1]
    elif even_most_common[0][1] == odd_most_common[0][1]:
        if even_most_common[1][1] < odd_most_common[1][1]:
            ans += n // 2 - even_most_common[0][1]
            ans += n // 2 - odd_most_common[1][1]
        else:
            ans += n // 2 - even_most_common[1][1]
            ans += n // 2 - odd_most_common[0][1]
    elif even_most_common[0][1] > odd_most_common[0][1]:
        ans += n // 2 - even_most_common[0][1]
        ans += n // 2 - odd_most_common[1][1]
    else:
        ans += n // 2 - even_most_common[1][1]
        ans += n // 2 - odd_most_common[0][1]
else:
    ans += n // 2 - even_most_common[0][1]
    ans += n // 2 - odd_most_common[0][1]

print(ans)

Measured memory_bytes: 18656
import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

dx=[-1,1,0,0]
dy=[0,0,1,-1]


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")


def soe(limit):
    l=[1]*(limit+1)
    l[0]=0
    l[1]=0
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0
    
    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r
    
def solve():
    n=inp()
    s=1
    A=li()
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
 
    array_sum_square = array_sum * array_sum 
  
    
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 

    c=((array_sum_square - individual_square_sum)>>1)%mod
    pr(c)
    
for _ in range(1):
    solve()



Measured memory_bytes: 32392
#include <iomanip>
#include <iostream>
using namespace std;
int main(){
int N;
double ans = 0, A;
cin >> N;
for(int i = 1; i <= N; ++i){
       cin >> A;
       ans += 1.0 / A;
    }
 ans = 1.0 / ans;
cout <<  ans << endl;
}

Measured memory_bytes: 256
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
N,M = map(int,input().split())
S = input()
T = input()

L = lcm(N,M)
H = (L/N)*(L/M)
n = int(L/H)
for i in range(n):
  if S[i*int(L/M)] != T[i*int(L/N)]:
    print(-1)
    exit()
print(L)


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

int main(void)
{
	char str[1000];
	int i;
	int n;
	
	scanf("%s", str);
	
	n = strlen(str);
	
	for (i = 0; i < n; i++){
		switch (str[i]){
		  case 'A':
		    printf("X");
			break;
			
		  case 'B':
		    printf("Y");
			break;
			
		  case 'C':
		    printf("Z");
			break;
			
		  default:
		    printf("%c", str[i] - ('D' - 'A'));
			break;
		}
	}
	
	printf("\n");
	
	return (0);
}

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

int main() {
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<int> v;
	v.push_back(-a[0]);
	for(int i=1;i<n;i++){
		int idx=lower_bound(v.begin(),v.end(),-a[i]+1)-v.begin();
		if(idx==v.size()){
			v.push_back(-a[i]);
		}else{
			v[idx]=-a[i];
		}
	}
	cout<<v.size()<<endl;
	return 0;
}


Measured memory_bytes: 1276
N = int(input())
now_t, now_x, now_y = 0, 0, 0
for i in range(N):
    next_t, next_x, next_y = map(int, input().split())
    distance = abs(next_x - now_x) + abs(next_y - now_y)
    spent_time = next_t - now_t
    if spent_time < distance or distance % 2 != spent_time % 2:
        print('No')
        exit()
    now_t, now_x, now_y = next_t, next_x, next_y
print('Yes')

Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  ll a;
  string b;
  cin >> a >> b;
  ll x = b[0] - '0';
  ll y = b[2] - '0';
  ll z = b[3] - '0';
  ll nb = x * 100 + y * 10 + z;
  cout << a * nb / 100 << endl;
  return 0;
}


Measured memory_bytes: 3624
m;f(r,n,i,t){if(n==1)return r>i&r<10;for(;i++<9;)t+=f(r-i,n-1,i,0);return t;}main(s){for(;scanf("%d%d",&m,&s),m;printf("%d\n",f(s,m,-1,0)));}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
  int n;
  cin>>n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
      cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  cout<<d.at(n/2)-d.at(n/2-1)<<endl;
}

Measured memory_bytes: 640
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    if(a == b) count++;
    if(a == c) count++;
    if(count == 1){
        cout << "Yes" << endl;
        return 0;
    }
    count = 0;
    if(b == a) count++;
    if(b == c) count++;
    if(count == 1){
        cout << "Yes" << endl;
        return 0;
    }
    count = 0;
    if(c == a) count++;
    if(c == b) count++;
    if(count == 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int n,k;
  cin >> n >> k;
  cout << (n%k==0 ? 0 : 1) << endl;
}



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

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++) {
		cin >> B.at(i);
	}
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j < M; j++) {
			sum += A[i][j] * B[j];
			}
        if (sum > -C) {
				ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	bool s = 0;
	ll ans = 0, n, a, b, c, d, e, m;
	cin >> n;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;

	if (n > a) {
		s = 1;
		ans++;
		m = a;
		if (n%a == 0)ans = n / a;
		else ans = n / a + 1;
	}
	else m = n;

	if (m > b) {
		s = 1;
		m = b;
		if (n%b == 0)ans = n / b;
		else ans = n / b + 1;
	}

	if (m > c) {
		s = 1;
		m = c;
		if (n%c == 0)ans = n / c;
		else ans = n / c + 1;
	}

	if (m > d) {
		s = 1;
		m = d;
		if (n%d == 0)ans = n / d;
		else ans = n / d + 1;
	}

	if (m > e) {
		s = 1;
		m = e;
		if (n%e == 0)ans = n / e;
		else ans = n / e + 1;
	}

	if (s)ans += 4;
	else ans += 5;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
//#define random_shuffle(r...) random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 100000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}
ll prime[1000000];bool visprime[10000000];
void sieve(){ll k=0;for(ll i=2;i*i<=1000000;i++){for(ll j=i*i;j<=1000000;j+=i){visprime[j]=true;}}for(ll i=2;i<=1000000;i++){if(visprime[i]==false) prime[k++]=i;}}
int myrandom (int i) { return std::rand()%i;}

bool checkbit(int mask,int bit) {return (mask & (1<<bit));}

ll fact(ll n)
{
    if(n==0) return 1;
    if(n==1) return 1;
    ll ret=((n%mod)*(fact(n-1)%mod))%mod;
    return ret;

}

int main()
{

   ll n;
   cin>>n;
   bool flag=false;
   for(int i=1;i<=9;i++)
   {
      if(n%i==0){
       ll temp=n/i;
       if(temp<=9)
       {flag=true; break;}
   }
   }

   if(flag==false) cout<<"No"<<endl;
   else cout<<"Yes"<<endl;


   }

















Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
typedef pair<int, int> pii;

int H, W, N;
pii P[10];
string T[1000];
int D[1000][1000];

int MinDist(pii S, pii G)
{
    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {
            D[h][w] = -1;
        }
    }

    queue<pii> Q;
    Q.push(S);
    D[S.first][S.second] = 0;
    while (!Q.empty()) {
        pii Tmp = Q.front(); Q.pop();
        int dif[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

        for (int i = 0; i < 4; ++i) {
            int h = Tmp.first + dif[i][0];
            int w = Tmp.second + dif[i][1];
            if (h < 0 || h >= H) continue;
            if (w < 0 || w >= W) continue;
            if (T[h][w] == 'X') continue;
            if (D[h][w] >= 0) continue;
            D[h][w] = D[Tmp.first][Tmp.second] + 1;
            Q.push(make_pair(h, w));
        }
    }

    return D[G.first][G.second];
}

int main()
{
    cin >> H >> W >> N;
    for (int h = 0; h < H; ++h) {
        cin >> T[h];
    }
    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {
            if (T[h][w] == 'S') P[0] = make_pair(h, w);
            if (T[h][w] >= '1' && T[h][w] <= '9') P[T[h][w]-'0'] = make_pair(h, w);
        }
    }
    int Res = 0;
    for (int n = 0; n < N; ++n) {
        Res += MinDist(P[n], P[n+1]);
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 7952
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long i; long long j;
};


ll const MAX = 200005;
ll parent[MAX];
ll rk[MAX];

void init(ll n) {
	for (ll i = 1; i <= n; i++) {
		parent[i] = i;
		rk[i] = 1;
	}
}

ll find(ll x) {
	if (parent[x] == x) {
		return x;
	}
	parent[x] = find(parent[x]);
	return parent[x];
}

bool same(ll x, ll y) {
	return find(x) == find(y);
}

void unite(ll x, ll y) {
	if (!same(x, y)) {
		x = parent[x];
		y = parent[y];
		if (rk[x] < rk[y]) {
			parent[x] = y;
		}
		else {
			parent[y] = x;
			if (rk[x] == rk[y]) {
				rk[x]++;
			}
		}
	}
}

vll p[MAX];

int main() {
	ll n, m;
	cin >> n >> m;
	init(n);
	REP(i, 1, n) {
		ll k;
		cin >> k;
		REP(j, 1, k) {
			ll t;
			cin >> t;
			p[t].push_back(i);
		}
	}
	REP(i, 1, m) {
		if (SIZE(p[i]) == 0) {
			continue;
		}
		ll person = p[i][0];
		for (auto cur : p[i]) {
			unite(person, cur);
		}
	}
	REP(i, 2, n) {
		if (!same(1, i)) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

int main()
{
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  
  sort(a, a + 3);
  
  int ans = a[2] * 10 + a[1];
  ans += a[0];
    
  cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 924844033;

ll dp[2005][2005][2], dp2[2005][2005], fac[1000010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> cnt(2 * K, 0);
	int hoge = min(N, 2 * K);
	for (int i = 0; i < hoge; i++) {
		dp[i][0][0] = 1;
		if (i - K >= 0) dp[i][1][0] = 1;
		if (i + K < N) dp[i][1][1] = 1;
		cnt[i]++;
	}

	for (int i = 2 * K; i < N; i++) {
		cnt[i % (2 * K)]++;
		for (int j = 0; j <= N; j++) {
			(dp[i][j][0] += dp[i - 2 * K][j][0] + dp[i - 2 * K][j][1]) %= MOD;

			(dp[i][j + 1][0] += dp[i - 2 * K][j][0]) %= MOD;

			if (i + K < N) (dp[i][j + 1][1] += dp[i - 2 * K][j][0] + dp[i - 2 * K][j][1]) %= MOD;
		}
	}

	int sum = 0;
	dp2[0][0] = 1;
	for (int i = 0; i < hoge; i++) {
		int ii = N - i - 1;
		for (int j = 0; j <= sum; j++) {
			for (int k = 0; k <= cnt[i]; k++) {
				(dp2[i + 1][j + k] += dp2[i][j] * (dp[ii][k][0] + dp[ii][k][1])) %= MOD;
			}
		}
		sum += cnt[i];
	}

	fac[0] = 1;
	for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % MOD;

	ll ans = 0;
	for (int i = 0; i <= N; i++) {
		if (i % 2 == 0) (ans += dp2[hoge][i] * fac[N - i]) %= MOD;
		else (ans += MOD - (dp2[hoge][i] * fac[N - i]) % MOD) %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 94720
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 1; i < n; i++){
        ll s = a[i]+a[i-1];
        if (s > x){
            ll t = min(s-x, a[i]);
            ans += t;
            s -= t;
            a[i] -= t;
            if (s > x){
                t = min(s-x, a[i-1]);
                a[i-1] -= t;
                ans += t;
            }
        }
    }
    cout << ans << '\n';
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int k; cin>>k;
    vector <int> a(50,49); 
    vector <int> cnt(50); 
    int lest = k%50;
    int main = k/50;
    int n = 50;
    for(int i=0;i<n;i++){
        if(lest-1 >= i) cnt[i]++;
        cnt[i] += main;
    }
    //rep(i,n) cout<<cnt[i]<<endl;
    rep(i,n){
        a[i] -= (k-cnt[i]);
        a[i] += n*cnt[i];
    }
    cout<<50<<endl;
    rep(i,n) cout<<a[i]<<' ';
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> num(5);
  for(int i=0; i<5; i++) cin >>num[i];
  sort(num.begin(),num.end());
  for(int i=0; i<5; i++){
    cout <<num[4-i];
    if(i == 4) cout <<endl;
    else cout <<" ";
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
#define ll long long
#define trace(x) cerr << #x << " = " << x << endl
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main()
{
   /*
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("ouput.txt","w",stdout);
    #endif 
   */

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while(t--){
       double d, t, s;
       cin>>d>>t>>s;
       double ans = d/s;
       if(ans > t)
	       cout<<"No"<<endl;
       else
	       cout<<"Yes"<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3736
N = int(input())
b_list = [int(i) for i in input().split(' ')]

a_sum = 0
last_b = 10 ** 5 + 1
for b in b_list:
    i = b if b <= last_b else last_b 
    a_sum += i
    last_b = b
a_sum += b

print(a_sum)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  //配列にa_iを代入
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  //判定
  int x = 0;
  int counter = 1;
  for(int i = 0; i < N; i++){
    
    //不可能判定
    if(vec.at(x) == 1){
      cout << -1 << endl;
      break;
    }
    
    //成功判定
    else if(vec.at(x) == 2){
      cout << counter << endl;
      break;
    }
    
    //ループ時判定
    else if(counter >= N){
      cout << -1 << endl;
    }
    
    //継続判定
    else{
      counter += 1;
      x = vec.at(x) - 1;
    }
  }
}


Measured memory_bytes: 768
N=int(input())
D = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N-2):
    if D[i][0] == D[i][1]:
        if D[i+1][0] == D[i+1][1]:
            if D[i+2][0] == D[i+2][1]:
                ans = 1
                break
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 62420
fun main(args:Array<String>){
    val line = readLine()!!.split(" ").map{it.toInt()}
    val n = line[0]
    val l = line[1]
    val sum = (2*l + n - 1)*n/2
    val result = if(l>=0){
        sum-l
    }else{
        if(l+n-1>=0){
            sum - 0
        }else{
            sum - (l+n-1)
        }
    }
    println(result)
}

Measured memory_bytes: 37720
#include <stdio.h>

int main(void)
{
  int a;
  int five = 2, seven = 1;
  int i;
  for (i = 0; i < 3; ++i)
  {
    scanf("%d", &a);
    if (a == 5) five--;
    else if(a == 7) seven--;
  }
  if (!five && !seven) printf("YES\n");
  else printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] h = new int[n];
      int min = 1000000000;
      for(int i = 0;i < n;i++)h[i] = sc.nextInt();
      Arrays.sort(h);
      for(int i = 0;i <= n-k;i++){
      	min = Math.min(min,h[i+k-1]-h[i]);
      }
      System.out.println(min);
    }
}


Measured memory_bytes: 50016
s = input()
s1 = ord(s[0])
s2 = ord(s[1])
s3 = ord(s[2])
s4 = ord(s[3])

if s1 == s2:
    if s3 == s4 and s1 != s3:
        print("Yes")
        exit()
elif s1 == s3:
    if s2 == s4 and s1 != s2:
        print("Yes")
        exit()
elif s1 == s4:
    if s2 == s3 and s1 != s2:
        print("Yes")
        exit()

print("No")

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

int main()
{
    int N;
    std::cin >> N;

    std::vector<int> X(N);

    int maxX = 0;
    for (int i=0; i<N; ++i)
    {
        int x;
        std::cin >> x;
        X[i] = x;

        if (maxX < x)
            maxX = x;
    }

    int minScore = 1000000;
    for (int i=1; i<=maxX; ++i)
    {
        int score = 0;
        for (int j=0; j<N; ++j)
            score += (X[j] - i) * (X[j] - i);

        if (score < minScore)
            minScore = score;
    }

    std::cout << minScore;
}

Measured memory_bytes: 384
/**
       ????????????    ????????????
		Author : Avi J Patel
		University : DA-IICT
       ????????????    ????????????
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main()
 {
	int n,x;
	cin>>n>>x;
	vector<int> a(n);
	int ans=1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(a[0]<=x)
	ans++;
	for(int i=1;i<n;i++)
	{
		a[i]=a[i-1]+a[i];
		if(a[i]<=x)
		ans++;
	}
	cout<<ans;
	return 0;
}








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

int main() {
    int A, B;
    cin >> A >> B;

    if (A == B) {
        cout << "Draw" << endl;
    }
    else if (A == 1) {
        cout << "Alice" << endl;
    }
    else if (B == 1) {
        cout << "Bob" << endl;
    }
    else if (A > B && B != 1) {
        cout << "Alice" << endl;
    }
    else if (A < B && A != 1) {
        cout << "Bob" << endl;
    }
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, flag = 0;
  while (cin >> n, n) {
    if (flag++) cout << endl;
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    string name[10];
    int w[10], l[10], d[10];
    for (int i = 0; i < n; i++) {
      cin >> name[i] >> w[i] >> l[i] >> d[i];
    }
    stable_sort(ord.begin(), ord.end(), [&](int a, int b) {
      return w[a] * 3 + d[a] > w[b] * 3 + d[b];
    });
    for (int i = 0; i < n; i++) {
      cout << name[ord[i]] << "," << w[ord[i]] * 3 + d[ord[i]] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3016
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long n, h, w;
	cin >> n >> h >> w;
	long long ans = 0;
	REP(i, n) {
		long long a, b;
		cin >> a >> b;

		if (h <= a && w <= b) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<string> a(n);
  for(int i=0;i<n; i++) cin >> a[i];
  
  map<string,int> data;
  int ans=0;
  for(int i=0;i<n; i++){
    if(data.count(a[i])) data[a[i]]+=1;
    else{
      data[a[i]]=0;
      ans+=1;
    }
  }
  
  cout << ans <<endl;

}

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

typedef long long int ll;

int main()
{
	ll n;
	scanf("%lld",&n);
	ll a=n%10;
	ll b=n/100;
	n=n/10;
	ll c=n%10;
	if(a==7 || b==7 || c==7)
		printf("Yes\n");
	else
		printf("No\n");
}


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

int main() {
    int n, ts = 0, hs = 0;
    string t, h;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> t >> h;
        if (t > h) {
            ts += 3;
        } else if (t < h) {
            hs += 3;
        } else {
            ts++;
            hs++;
        }
    }
    cout << ts << " " << hs << endl;
    return 0;
}

Measured memory_bytes: 3144
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vs = vector<string>;
using vcc = vector<vector<char>>;
using vll = vector<vector<long long>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
int main() {
    ll n;
    cin >> n;
    vl a(n);
    bool app = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] % 2 == 1) {
            app = true;
        }
    }
    if (app) cout << "first" << endl;
    else cout << "second" << endl;
}

Measured memory_bytes: 3940
from heapq import heappop, heappush
N, M = map(int, input().split())
A = list(map(int, input().split()))
h = []
for a in A:
    heappush(h, a*-1)

for i in range(M):
    val = heappop(h)*-1
    heappush(h, (val//2)*-1)

print(sum(h)*-1)

Measured memory_bytes: 14180
#include<stdio.h>
#include<math.h>

int func(int* a,int* b){
	return ((*a)-(*b));
}
int main (){
	int v[3];
	int s;
	int n;
	int i;
	while('A'){
		scanf("%d %d %d",&v[0],&v[1],&v[2]);
		if(v[0]==0){
			break;
		}
		qsort(v,3,sizeof(int),func);
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&s);
			if((v[0]*v[0]+v[1]*v[1])<(4*s*s)){
				puts("OK");
			}
			else {
				puts("NA");
			}
		}
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int N,C[202020];
ll dp[202020];
int last[202020];

int main(){
	scanf("%d",&N);
	for(int i = 0;i < N;++i){
		scanf("%d", C+i);
		--C[i];
	}
	for (int i = 0; i < 202020; ++i) last[i] = -1;
	dp[0] = 1;
	for(int i = 0; i < N; ++i){
		dp[i+1] = dp[i];
		if(last[C[i]] != -1 && last[C[i]] != i-1){
			dp[i+1] = (dp[i+1]+dp[last[C[i]]+1])%MOD;
		}
		last[C[i]] = i;
	}
	printf("%lld\n",dp[N]);
	return 0;
}

Measured memory_bytes: 3328
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private void solve(Scanner sc, PrintWriter out) {
    String s = sc.nextLine();

    int score = 0;
    for (int i = 0; i < s.length(); ++i) {
      char ch = s.charAt(i);
      char hand = (i % 2 == 0 ? 'g' : 'p');
      if (ch == 'g' && hand == 'p') {
        ++score;
      } else if (ch == 'p' && hand == 'g') {
        --score;
      }
    }
    out.println(score);
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 14004
using System;
using System.Linq;

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var t = new int[n].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).OrderBy(p => p[0]).Select(p => p[1]).ToArray();
		var yx = Enumerable.Range(0, n).ToArray();
		var xy = (int[])yx.Clone();
		Array.Sort(t, yx);
		yx.CopyTo(t, 0);
		Array.Sort(t, xy);

		int ss = 64, sc = n / ss + 1;
		var s = new int[sc, sc];
		for (int i = 0; i < n; i++)
			s[i / ss, xy[i] / ss]++;
		for (int i = 0; i < sc; i++)
			for (int j = 1; j < sc; j++)
				s[i, j] += s[i, j - 1];
		for (int j = 0; j < sc; j++)
			for (int i = 1; i < sc; i++)
				s[i, j] += s[i - 1, j];

		var c = MInt(n * MPow(2, n) - n);
		for (int i = 0; i < n; i++)
		{
			var v = xy[i];

			var li = i >= ss && v >= ss ? s[i / ss - 1, v / ss - 1] : 0;
			var ix = i - i % ss;
			for (int i2 = ix; i2 < i; i2++)
				if (xy[i2] < v) li++;
			for (int j2 = v - v % ss; j2 < v; j2++)
				if (yx[j2] < ix) li++;

			c -= MPow(2, i) + MPow(2, n - 1 - i) + MPow(2, v) + MPow(2, n - 1 - v);
			c += MPow(2, li) + MPow(2, i - li) + MPow(2, v - li) + MPow(2, n - 1 + li - i - v);
			c = MInt(c);
		}
		Console.WriteLine(c);
	}

	const int M = 998244353;
	static long MPow(long b, long i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
	static long MInt(long x) => (x %= M) < 0 ? x + M : x;
}


Measured memory_bytes: 71364
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int64_t X, Y;
  cin >> X >> Y;
  
  int result = 1;
  for (;;) {
    X *= 2;
    if (X <= Y) {
      ++result;
    } else {
      break;
    }
  }
  
  cout << result << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define f first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010


int main(){
	IOS;
	ll n,m;cin>>n>>m;
	ll a[n+1],b[n+1];
	rep(i,0,n+1)a[i]=0,b[i]=0;
	rep(i,0,m){
		ll x;string s;cin>>x>>s;
		if(s=="AC")a[x]=1;
		else {
			if(!a[x])b[x]++;
		}
	}
	ll sum=0,ans=0;
	rep(i,0,n+1)if(a[i])sum++,ans+=b[i];
	cout<<sum<<" "<<ans;
	return 0;
}



Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define sz(v) (v.empty() ? 0 : v.size())
#define all(v) v.begin(), v.end()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define fi first
#define se second
#define pb push_back
#define int long long
#define mod 1000000007
#define rem 998244353
#define maxn 500005
const int INF = 1e18;
typedef pair<int, int> pii;

signed main() {
    boostIO;
    int n;
    cin >> n;
    int L[n], ans = 0;
    for(int i = 0; i < n; i++){
        cin >> L[i];
    }
    set<int> s;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            for(int k = j + 1; k < n; k++){
                s.clear();
                s.insert(L[i]);
                s.insert(L[j]);
                s.insert(L[k]);
                if(sz(s) != 3) continue;
                int sum = 0;
                for(auto x : s) sum += x;
                if(sum - *s.rbegin() > *s.rbegin()) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
// XD

Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int c=0;
  rep(i,a-1){
  if(b[i]==b[i+1]){
  c++;
    b[i+1]=-1;
  }
    
  }
    out(c);
}


Measured memory_bytes: 256
import sys

s = input()

if s.find('N') != -1:
    if s.find('S') == -1:
        print('No')
        sys.exit()

if s.find('S') != -1:
    if s.find('N') == -1:
        print('No')
        sys.exit()

if s.find('W') != -1:
    if s.find('E') == -1:
        print('No')
        sys.exit()

if s.find('E') != -1:
    if s.find('W') == -1:
        print('No')
        sys.exit()
        
print('Yes')


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 ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}

int main() {
  ll n, ans = 0;
  cin >> n;

  ans = modpow(10, n) - modpow(9, n) * 2 + modpow(8, n);
  ans %= mod;
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632