akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void solve() {
   ll n;
   cin >> n;
   ll a[n];
   for(int i = 0;i < n;i++){
       cin >> a[i];
   }
   ll front[n],back[n];
   front[0] = a[0];
   back[0] = a[n-1];
   for(int i = 1;i < n;i++){
       front[i] = gcd(a[i],front[i-1]);
       back[i] = gcd(a[n-i-1],back[i-1]);
   }

   ll ans = back[n-2];
   for(int i = 1;i < n-1;i++){
       ans = max(ans,gcd(front[i-1],back[n-i-2]));
   }
   ans = max(ans,front[n-2]);
   cout << ans << endl;
}
int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

signed main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    vector<long long> k(n);
    vector<long long> k1(n);
    map<int, int> cnt;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        k[i] = a[i] - i;
        k1[i] = -a[i] - i;
        ans += cnt[k[i]];
        cnt[k1[i]]++;
    }
    cout << ans << endl;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll count = n / i;
    ans += count * (count + 1) / 2 * i;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
ll ans=0;
ll dp[0][0];

int main()
{ 
ll n,m;
cin >> n >>m; 
ll table[n]={};
rep(i,n) {
    cin >> table [i];
}
ll tab[n+1];
tab[0]=0;
rep(i,n){
    tab[i+1]=(tab[i]+table[i])%m;
}
map<ll,ll> mod{};
rep(i,n+1){
    mod[tab[i]]++;
}

for (auto i = mod.begin(); i != mod.end(); ++i) {
    ll lll=i->second;
    ans+=lll*(lll-1)/2;
}
cout << ans << endl;
return 0;
} 

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define N 1000000
int main()
{
   ll n,m;
   cin >> n >> m;
   
   vector<vector<int>> a(n,vector<int>(2));
   for(int i=0; i<n ; i++)    cin >> a[i][0] >> a[i][1];
   
   sort(a.begin(),a.end());
   multiset <ll> mul ; 
   ll ans = 0;
   int i=0;
   for(int j=1 ; j<=m ; j++)
   {
        for( ; i <n && a[i][0] <= j ; i++)
               mul.insert(a[i][1]);
               
          if(!mul.empty())
          {
              auto itr = mul.end();
                itr--;
               ans += *itr;
             
               mul.erase(itr);    
          }
     
   }
   cout << ans;
}     
     
     

Measured memory_bytes: 10368
#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 double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;

signed main(){
  int A,B;
  cin>>A>>B;
  if( A==1||B==1){
    cout<<1;
  }
  else if( A%2==1 && B%2==1 ){
    cout<<A*B/2+1;
  }
  else{
    cout<<A*B/2;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll x; cin >> x;
    if(x <= 6) {
        cout << 1 << endl;
    }else {
        ll ans = x / 11LL;
        ll tmp = x - 11LL * ans;
        if(tmp > 6) cout << 2 * ans + 2LL << endl;
        else if(tmp == 0) cout << 2 * ans << endl;
        else cout << 2 * ans + 1LL << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
x, y, h = [], [], []
for i in range(n):
    xyh = list(map(int, input().split()))
    x.append(xyh[0])
    y.append(xyh[1])
    h.append(xyh[2])
for i in range(101):
    for j in range(101):
        flag = True
        m = float('inf')
        ch = -1
        for k in range(n):
            if h[k] != 0:
                if ch == -1:
                    ch = h[k] + abs(x[k] - i) + abs(y[k] - j)
                else:
                    if ch != h[k] + abs(x[k] - i) + abs(y[k] - j) and flag:
                        flag = False
            else:
                m = min(m, abs(x[k] - i) + abs(y[k] - j))
        if flag and ch <= m:
            ans = list(map(str, [i, j, ch]))
print(ans[0] + " " + ans[1] + " " + ans[2])


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << (a - c) * (b-d);
}
  /*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll ans = 0;
  vll a(n);re(i, n) std::cin >> a[i];
  for(int i=0;i<n-2;i++) if(a[i]==i+1) swap(a[i], a[i+1]), ans++;
  if(a[n-2]==n-1 || a[n-1]==n) ans++;
  std::cout << ans << '\n';
  return 0;
}


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

int find_match(const std::string & prefix, const std::string & suffix)
{
	auto prefix_iterator = prefix.cbegin();
	auto suffix_iterator = suffix.cbegin();

	while (prefix_iterator != prefix.cend())
	{
		if (*prefix_iterator == *suffix_iterator)
		{
			int match_length = 0;
			auto tmp_prefix_iterator = prefix_iterator;
			auto tmp_suffix_iterator = suffix_iterator;
			
			while (*tmp_prefix_iterator == *tmp_suffix_iterator)
			{
				++match_length;
				++tmp_prefix_iterator;
				++tmp_suffix_iterator;
			
				if (tmp_prefix_iterator == prefix.cend()) {
					return match_length;
				}
			}
			
		}
		++prefix_iterator;
	}
	
	return 0;
}

int main()
{
	int min_length;
	std::string prefix;
	std::string suffix;

	std::cin >> min_length;
	std::cin >> prefix;
	std::cin >> suffix;

	int length = prefix.length() + suffix.length();

	std::cout
		<< std::max(min_length, length - find_match(prefix, suffix))
		<< std::endl;
	return 0;
}



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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7
#define MAX_V

int main(){
    int n, z, w;
    cin >> n >> z >> w;

    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    /* dp[i][j]: 山札からi枚取られた状態で、j(先手 or 後手)からスタートしたときの最適値 */
    vector<vector<ll> > dp(n+1, vector<ll>(2));

    for(int i=n-1; i>=0; i--){
        /* 先手 */
        dp[i][0] = -INF_LL;
        ll pre_y;
        if(i==0){
            pre_y = w;
        } else {
            pre_y = a[i-1];
        }

        dp[i][0] = max(dp[i][0], abs(pre_y - a[n-1]));
        for(int j=i+1; j<n; j++) dp[i][0] = max(dp[i][0], dp[j][1]);

        /* 後手 */
        dp[i][1] = INF_LL;
        ll pre_x;
        if(i==0){
            pre_x = z;
        } else {
            pre_x = a[i-1];
        }
        dp[i][1] = min(dp[i][1], abs(pre_x - a[n-1]));
        for(int j=i+1; j<n; j++) dp[i][1] = min(dp[i][1], dp[j][0]);
    }
    
    cout << dp[0][0] << endl;



    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            char find = char.MinValue;
            for (char i = 'a'; i <= 'z'; i++)
            {
                if (!line.Contains(i.ToString()))
                {
                    find = i;
                    break;
                }
            }
            if (find == char.MinValue)
                Console.WriteLine("None");
            else
                Console.WriteLine(find);

        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

void solve() {
   ll n,k;
   cin >> n >> k;
   vector<ll> h(n);
   for(int i = 0;i < n;i++){
       cin >> h[i];
   }
    sort(h.begin(),h.end());
    ll m = MOD;
    for(int i = 0;i < n-k+1;i++){
        ll dis;
        dis = h[i+k-1]-h[i];
        m = min(m,dis);
    }
   cout << m << endl;
}

int main() {

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//余ったらどなたか一人泣かせることにする。

int main(){
    int N, x;
    cin >> N >>x;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a,a + N);
    int res = 0; //喜ぶ子供たち
    for(int i =0; i < N; i++){
        x -= a[i];
        if(x < 0) break;
        res++;
    }
    if(x<=0)  cout << res << endl;
    else cout << res - 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a,p;
  cin>>a>>p;
  cout<<floor((double)(3*a+p)/2);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
double eps = 1e-5;
int main() {
    long long a;
    double b;
    string s;
    cin >> a;
    cin >> b;
    cout <<  (long long)(a * (long long)(b*100 + eps*100)) / 100;
   // system("pause");
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s=to_string(n);
  for(int i=0;i<3;i++){
    if(s.at(i)=='1'){
      s.at(i)='9';
      continue;
    }
    if(s.at(i)=='9')
      s.at(i)='1';
  }
  int m=stoi(s);
  cout << m<< endl;
}
    

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


int main() { 
    string s, t;
    cin >> s >> t;
    int start = -1;
    for (int i = s.size() - t.size(); i >= 0; --i) {
        bool flag = 1;
        for (int j = 0; j < t.size(); ++j) {
            if (!(s[i+j] == t[j] || s[i+j] == '?')) flag = 0;
        }
        if (flag) {
            start = i;
            break;
        }
    }
    if (start >= 0) {
        for (int i = 0; i < t.size(); ++i) s[start+i] = t[i];
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == '?') s[i] = 'a';
        }
        cout << s << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }  
}

Measured memory_bytes: 256
test = []
while True:
    tmp = map(int,raw_input().split())
    if tmp[0]==tmp[1]==tmp[2]==-1:
        break
    else:
        test.append(tmp)
for a in test:
    if a[0] == -1 or a[1] == -1:
        print "F"
    elif a[0]+a[1] >= 80:
        print "A"
    elif 80 > a[0]+a[1] >= 65:
        print "B"
    elif 65 > a[0]+a[1] >= 50:
        print "C"
    elif 50 > a[0]+a[1] >= 30:
        if a[2] >= 50 and 50 > a[0]+a[1] >= 30:
            print "C"
        else:
            print "D"
    elif a[0] + a[1] < 30:
        print "F"

Measured memory_bytes: 4248
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
while True:
    ma = min(a)
    a = [x % ma for x in a]
    a = [ma if x == 0 else x for x in a]
    if max(a) == min(a):
        print(min(a))
        exit()


Measured memory_bytes: 14252
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for _ in range(N)]

    # dp[i][j]: 0〜(i-1)まで使ったときの重さjのときの価値の最大値
    dp = [[0]*(W+1) for i in range(N+1)]

    for i in range(1, N+1):
        for w in range(0, W+1):
            # i番目を入れられる場合
            if w - wv[i-1][0] >= 0:
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-wv[i-1][0]] + wv[i-1][1])
            else:
                dp[i][w] = dp[i-1][w]

    print(max(dp[N]))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 118512
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vector<ll> getNums(ll N) {
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
    }
    return num;
}
int main() {
    ll X, K, D;
    cin >> X >> K >> D;

    ll ans = INF;

    ll begin = max(min(K / 2, abs(X) / D) - 1000000000, (ll)0);
    if (K % 2 == 0) {
        if (X >= 0) {
            for (ll i = begin; i <= K / 2; ++i) {
                ll tmp = X - D * 2 * i;
                chmin(ans, abs(tmp));
                if (tmp < 0) break;
            }
        }

        if (X <= 0) {
            for (ll i = begin; i <= K / 2; ++i) {
                ll tmp = X + D * 2 * i;
                chmin(ans, abs(tmp));
                if (tmp > 0) break;
            }
        }
    } else {
        if (X >= 0) {
            for (ll i = begin; i <= (K) / 2; ++i) {
                ll tmp = X - D * (i * 2 + 1);
                chmin(ans, abs(tmp));
                if (tmp < 0) break;
            }
        }

        if (X <= 0) {
            for (ll i = begin; i <= (K) / 2; ++i) {
                ll tmp = X + D * (i * 2 + 1);
                chmin(ans, abs(tmp));
                if (tmp > 0) break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
typedef struct qs{
  char c;
  int n;
  int h;
}Q;

int main(void){
  int n,i,count=0;
  Q q[100000];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    q[i].h=i;
  for(i=0;i<n;i++)
    scanf(" %c %d",&q[i].c,&q[i].n);

  Quicksort(&q[0],0,n-1);

  for(i=1;i<n;i++)
    if(q[i-1].n==q[i].n && q[i-1].h>q[i].h)
      count++;

  if(count>0)
    printf("Not stable\n");

  else
    printf("Stable\n");

  for(i=0;i<n;i++)
    printf("%c %d\n",q[i].c,q[i].n);

  return 0;
}
int Partition(Q *A,int p,int r){
  int i,x,j,tmp1;
  char tmp2;
  x = A[r].n;
   
  i = p-1;
  for(j = p;j <= r-1;j++){
    if(A[j].n <= x){
      i = i + 1;
      tmp1=A[i].n;
      A[i].n=A[j].n;
      A[j].n=tmp1;
      tmp2=A[i].c;
      A[i].c=A[j].c;
      A[j].c=tmp2;
      tmp1=A[i].h;
      A[i].h=A[j].h;
      A[j].h=tmp1;
    }
  }
  tmp1=A[i+1].n;
  A[i+1].n=A[r].n;
  A[r].n=tmp1;
  tmp2=A[i+1].c;
  A[i+1].c=A[r].c;
  A[r].c=tmp2;
  tmp1=A[i+1].h;
  A[i+1].h=A[r].h;
  A[r].h=tmp1;
  return i+1;
}
void Quicksort(Q *A,int p,int r){
  int q;
  if(p < r){
    q = Partition(A, p, r);
    Quicksort(A, p, q-1);
    Quicksort(A, q+1, r);
  }
}

Measured memory_bytes: 1780
def main():
  N = int(input())
  Data = []
  for i in range(N):
    Data.append(list(map(int, input().split())))
  Data = tuple(Data)
  
  DP = [[0, 0, 0] for i in range(N)]
  DP[0] = Data[0]
  for i in range(1, N):
    DP[i][0] = Data[i][0] + max(DP[i - 1][1], DP[i - 1][2])
    DP[i][1] = Data[i][1] + max(DP[i - 1][2], DP[i - 1][0])
    DP[i][2] = Data[i][2] + max(DP[i - 1][0], DP[i - 1][1])
    
  print(max(DP[N-1]))
  
main()


Measured memory_bytes: 79704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <climits>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}


int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, t;
	cin >> n >> t;

	vector<pair<int, int>> routes;
	int ci, ti;
	for (int i = 0; i < n; ++i) {
		cin >> ci >> ti;
		routes.emplace_back(ci, ti);
	}

	int smallest_cost = 2000;
	bool found = false;
	for (int i = 0; i < n; ++i) {
		if (routes[i].second <= t) {
			found = true;
			smallest_cost = min(smallest_cost, routes[i].first);
		}
	}

	if (!found) {
		cout << "TLE\n";
	} else {
		cout << smallest_cost << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
ll b[210000];
set<int> s;
ll ans;

int main(){
  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    b[a]=i+1;
  }

  s.insert(0);
  s.insert(n+1);
  FOR(i,1,n+1){
    auto it = s.upper_bound(b[i]);
    ans+= i*(*it-b[i])*(b[i]-*--it);
    s.insert(b[i]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>

int main(void){
	int change[] = {500, 100, 50, 10, 5, 1};
	int mon, ch, cnt;
	while(1){
		scanf("%d", &mon);
		if(mon == 0)	break;
		ch = 1000 - mon;
		cnt = 0;
		if(ch/change[0] != 0)	cnt += ch / change[0]; ch = ch % change[0];
		if(ch/change[1] != 0)	cnt += ch / change[1]; ch = ch % change[1];
		if(ch/change[2] != 0)	cnt += ch / change[2]; ch = ch % change[2];
		if(ch/change[3] != 0)	cnt += ch / change[3]; ch = ch % change[3];
		if(ch/change[4] != 0)	cnt += ch / change[4]; ch = ch % change[4];
		if(ch/change[5] != 0)	cnt += ch / change[5]; ch = ch % change[5];
		printf("%d\n", cnt);
	}

	return 0;
}

Measured memory_bytes: 596
<>;for(glob<>){
	$x+=$_;
	$y+=$_;
	if(--$|){
		$X+=$-=1-$x;
		$-&&($x=1);
		$Y+=$-=1+$y;
		$-&&($y=-1);
	}else{
		$X+=$-=1+$x;
		$-&&($x=-1);
		$Y+=$-=1-$y;
		$-&&($y=1);
	}
}
print$X<$Y?$X+0:$Y+0

Measured memory_bytes: 21504
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1 << 25;

int dp[50][410][410];

int main() {
  int N, Ma, Mb;
  while (cin >> N >> Ma >> Mb) {
    vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 410; j++) {
        for (int k = 0; k < 410; k++) {
          dp[i][j][k] = INF;
        }
      }
    }
    dp[0][0][0] = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j <= 400; j++) {
        for (int k = 0; k <= 400; k++) {
          dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
          dp[i + 1][j + a[i]][k + b[i]] =
              min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
        }
      }
    }
    int res = INF;
    for (int j = 1; j <= 400; j++) {
      for (int k = 1; k <= 400; k++) {
        if (j * Mb == Ma * k) {
          res = min(res, dp[N][j][k]);
        }
      }
    }
    cout << (res < INF ? res : -1) << endl;
  }
  return 0;
}


Measured memory_bytes: 33024
package main

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

var si = bufio.NewScanner(os.Stdin)

func readInt() int {
        si.Scan()
        r, _ := strconv.Atoi(si.Text())
        return r
}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}
func min(x, y int) int {
        if x > y {
                return y
        }
        return x
}

type Node struct {
        I, X, Y int
}

type byX []Node

func (n byX) Len() int {
        return len(n)
}
func (n byX) Swap(i, j int) {
        n[i], n[j] = n[j], n[i]
}

func (n byX) Less(i, j int) bool {
        return n[i].X < n[j].X
}

type byY []Node

func (n byY) Len() int {
        return len(n)
}
func (n byY) Swap(i, j int) {
        n[i], n[j] = n[j], n[i]
}
func (n byY) Less(i, j int) bool {
        return n[i].Y < n[j].Y
}

type Edge struct {
        A, B, P int
}
type Edges []Edge

func (e Edges) Len() int {
        return len(e)
}
func (e Edges) Less(i, j int) bool {
        return e[i].P < e[j].P
}
func (e Edges) Swap(i, j int) {
        e[i], e[j] = e[j], e[i]
}

type UnionTree struct {
        e int
        p *UnionTree
}

func (u *UnionTree) Root() *UnionTree {
        if u.p == nil {
                return u
        }
        root := u.p.Root()
        if root != u.p {
                u.p = root
        }
        return root
}
func (u *UnionTree) same(v *UnionTree) bool {
        return u.Root() == v.Root()
}
func (u *UnionTree) unite(v *UnionTree) {
        uRoot := u.Root()
        vRoot := v.Root()
        if uRoot == vRoot {
                return
        }
        if uRoot.e < vRoot.e {
                vRoot.p = uRoot
        } else {
                uRoot.p = vRoot
        }
}

func main() {
        si.Split(bufio.ScanWords)
        si.Buffer(make([]byte, 0), 10000000)
        N := readInt()
        V := make([]Node, N)
        for i := 0; i < N; i++ {
                V[i] = Node{i, readInt(), readInt()}
        }
        e := make(Edges, 0, N*2)
        sort.Sort(byX(V))
        for i := 1; i < N; i++ {
                e = append(e, Edge{V[i-1].I, V[i].I, V[i].X - V[i-1].X})
        }
        sort.Sort(byY(V))
        for i := 1; i < N; i++ {
                e = append(e, Edge{V[i-1].I, V[i].I, V[i].Y - V[i-1].Y})
        }
        sort.Sort(e)
        u := make([]UnionTree, N, N)
        for i := range u {
                u[i] = UnionTree{i, nil}
        }

        ret := 0
        for _, v := range e {
                if u[v.A].same(&(u[v.B])) {
                        continue
                }
                ret += v.P
                u[v.A].unite(&(u[v.B]))
        }
        fmt.Println(ret)

}

Measured memory_bytes: 11648
#include <iostream>
using namespace std;
int main() {
  int test,WA,TLE,RE = 0;
  int AC = 0;
  cin>> test;
  for(int i=0; i<test;i++){
    string input;
    cin>> input;
    
    if(input=="AC"){
      AC++;
    }
    else if(input=="WA"){
       WA++;
    }
    else if(input=="TLE"){
      TLE++;
    }
    else if(input=="RE"){
      RE++;
    }
  }
  cout<< "AC x " << AC << endl;
    cout<< "WA x " << WA << endl;
      cout<< "TLE x " << TLE << endl;
        cout<< "RE x " << RE << endl;
}

Measured memory_bytes: 3236
#include <stdio.h>

int main(){
  long long int A, B, K;
  scanf("%lld %lld %lld", &A, &B, &K);
  A-=K;
  K=(A>=0LL)?0LL:-A;
  if(K>0LL) A=0LL;
  B-=K;
  K=(B>=0LL)?0LL:-B;
  if(K>0LL) B=0LL;
  printf("%lld %lld\n", A, B);
  return 0; 
}

Measured memory_bytes: 1736
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%d", $Q);
$direction = false;
$array = array_pad(array(), 400000, "");
$array[200000] = $S;
$cursor_l = 199999;
$cursor_r = 200001;
for ($i = 0; $i < $Q; $i++) {
    $cols = explode(' ', trim(fgets(STDIN)));
    if (count($cols) === 1) {
        $direction = ! $direction;
    } else {
        $num = ($direction === false) + $cols[1];
        if ($num % 2 === 0) {
            $array[$cursor_l] = $cols[2];
            $cursor_l--;
        } else {
            $array[$cursor_r] = $cols[2];
            $cursor_r++;
        }
    }
}
$T = implode('', $array);
if ($direction === true) {
    $T = implode("", array_reverse(str_split($T)));
}
echo $T;


Measured memory_bytes: 53752
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int way = 0;
	string s;
	cin >> s;
	if (s[0] == 'A')
	{
		++way;
	}
	int daiC = 0;
	for (int i = 2; i < s.size()-1; ++i)
	{
		daiC += (s[i] == 'C');
	}
	way += (daiC == 1);
	int ko = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		ko += (s[i] >= 'a' && s[i] <= 'z');
	}
	way += (ko == s.size() - 2);
	cout << ((way == 3)?"AC":"WA") << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
15
1 2 1 1 3 2 2 2 3 3 3 1 1 2 2

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define MAX 100001

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
    
  int n;
  cin >> n;
  ll v;
  vector <ll> vec;
  ll ans = 0;
  int neg = 0;
  ll mn = 1e18;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    cin >> v;
    neg += (v < 0);
    vec.pb(v);
    ans += abs(v);
    mn = min(mn, abs(v));
    ok |= (v == 0);
  }
  if (neg % 2 == 0 || ok)
    cout << ans << endl;
  else
    cout << ans - 2 * mn << endl;
  

  return 0;
}


Measured memory_bytes: 1400
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .expect("read line");
    let mut iter = line.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut ans = 0;
    for i in 1..n+1 {
        if i % 2 == 0 {
            continue;
        }
        let mut cnt = 0;
        for j in 1..i+1 {
            if i % j == 0 {
                cnt += 1;
            }
        }
        if cnt == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int H, W, dist[50][50];
char s[50][50];

void bfs() {
	int c[50][50] = { 0 };
	REP(i, H) {
		REP(j, W) {
			dist[i][j] = 200;
		}
	}
	dist[0][0] = 0;
	c[0][0] = 1;
	queue<pair<int, int>>qu;
	vector<int>dx = { 1,-1,0,0 }, dy = { 0,0,1,-1 };
	qu.push(make_pair(0, 0));
	while (!qu.empty()) {
		int x = qu.front().first, y = qu.front().second;
		qu.pop();
		REP(i, 4) {
			if (x + dx[i] >= 0 && x + dx[i] < H&&y + dy[i] >= 0 && y + dy[i] < W&&s[x + dx[i]][y + dy[i]] != '#'&&c[x + dx[i]][y + dy[i]] == 0) {
				dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
				c[x + dx[i]][y + dy[i]] = 1;
				qu.push(make_pair(x + dx[i], y + dy[i]));
			}
		}
	}
}

int main() {
	cin >> H >> W;
	int cnt = 0;
	REP(i, H) {
		REP(j, W) {
			cin >> s[i][j];
			if (s[i][j] == '#') {
				cnt++;
			}
		}
	}
	bfs();
	if (dist[H - 1][W - 1] == 200) {
		cout << -1 << endl;
	}
	else {
		cout << H * W - dist[H - 1][W - 1] - cnt - 1 << endl;
	}

	return 0;
}

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

int main()
{

    int n;
    scanf("%d",&n);

    vector<ll> a(n+1);
    for (int i = 0; i < n+1; i++)
    {
        scanf("%lld",&a[i]);
    }
    ll sum = 0;
    for (int i = 0; i <= n; i++)
    {
        sum += a[i];
    }
    ll ans = 0, space = 1;
    for (ll i = 0; i <= n; i++, space *= 2, space = min(space, sum))
    {
        ans += min(sum, space);
        sum -= a[i];
        space -= a[i];
        if (space < 0)
        {
            printf("-1");
            return 0;
        }
    }

    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 4040
#include <cstdio>
#include <algorithm>
#include <set>
#define MAX(a,b) ((a)>(b))?(a):(b)
using namespace std;


int main() {
	int n,p,q,r,max=-1,w;
	int i,j;
	int c;
	int *sum;
	set<int> under;
	set<int> over;
	bool flag=false;
	scanf("%d%d",&n,&q);
	sum=(int *)malloc(sizeof(int)*n);
	scanf("%d",&w);
	max=sum[0]=w;
	for(i=1; i<n; ++i) {
		scanf("%d",&w);
		max=MAX(w,max);
		sum[i]=sum[i-1]+w;
	}
	if(q==1) {
		printf("%d\n",sum[n-1]);
		return 0;
	}
	p=max;
	while(1) {
		i=0;
		for(c=0; c<q-1; ++c) {
			for(j=0; i+j<n; ++j) {
				if(i==0) {
					if(sum[j]>p) {
						i=j;
						j=0;
						break;
					}
				} else {
					if(sum[i+j]-sum[i-1]>p) {
						i+=j;
						j=0;
						break;
					}
				}
			}
			if(i+j==n-1 && c<q-2) {
				if(p==max || flag) {
					printf("%d\n",p);
					return 0;
				}
				over.insert(p);
				if(flag) {
					++p;
				} else if(!under.empty()) {
					p=((*over.begin())+(*(--under.end())))/2;
				} else {
					p=(max+p)/2;
				}
			}
		}
		r=sum[n-1]-sum[i-1];
		if(r==p) {
			printf("%d\n",p);
			return 0;
		} else if (!flag) {
			if(r<p) {
				over.insert(p);
				if(!under.empty()) {
					p=((*(over.begin()))+(*(--under.end())))/2;
				} else {
					p=r+(p-r)/2;
				}
			} else if(r>p) {
				if((!over.empty() && !under.empty() && (*(over.begin()))-(*(--under.end()))<=10) || r-p<=10 ) {
					flag=true;
					under.insert(p);
					++p;
				} else {
					under.insert(p);
					if(!over.empty()) {
						p=((*(over.begin()))+(*(--under.end())))/2;
					} else {
						p=p+(r-p)/2;
					}
				}
			}
		} else {
			if(r>p) {
				++p;
			} else {
				printf("%d\n",p);
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3168
#!/usr/bin/env python3
def solve(k, a, b):
    if 1 + k < a or b - a <= 2:
        return 1 + k
    cnt = a
    k -= a - 1
    if k % 2 == 1:
        cnt += 1
        k -= 1
    cnt -= a * (k // 2)
    cnt += b * (k // 2)
    k -= k
    return cnt

k, a, b = map(int, input().split())
print(solve(k, a, b))


Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
  long N,i,j,ans;
  
  scanf("%ld", &N);
  ans = 0;
  
  for(i = 1; i <= 1000000 && i*i <= N; i++){
    if(N % i == 0){
      ans = i;
    }
  }
  i = ans;
  j = N / ans;
  
  printf("%ld\n",i-2+j);

  return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
 
public class Test
{
	public static void Main()
	{
		int n=int.Parse(Console.ReadLine());
		long [] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long ret=long.MaxValue;
		long flont = 0;
		long back  = x.Sum();
		for(int i=0;i<n-1;i++){
			flont+=x[i];
			back-=x[i];
			ret=Math.Min(ret,Math.Abs(flont-back));
		}
		Console.WriteLine(ret);
	}
}

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

int sosu(int x) {
    int order = sqrt(x);
    for (int j = 2; j <= order; j++) {
        if (x%j == 0) {
            return 0;
        }
    }
    return 1;
}

int main() {
    int x, i = 0;
    cin >> x;
    while (true) {
        if (sosu(x+i)) {
            break;
        }
        i++;
    }
    cout << x+i << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
X, Y, P = [], [], []
for i in range(n):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * n for s in range(1 << n)]
DY = [[0] * n for s in range(1 << n)]
for s in range(1 << n):
    for i in range(n):
        DX[s][i] = abs(X[i]) * P[i]
        DY[s][i] = abs(Y[i]) * P[i]
        for j in range(n):
            if s & (1 << j):
                DX[s][i] = min(DX[s][i], abs(X[i] - X[j]) * P[i])
                DY[s][i] = min(DY[s][i], abs(Y[i] - Y[j]) * P[i])

BC = [bin(s).count("1") for s in range(1 << n)]
A = [10**20] * (n + 1)
for sx in range(1 << n):
    rx = ((1 << n) - 1) ^ sx
    sy = rx
    for _ in range(1 << (n - BC[sx])):
        sy = (sy - 1) & rx
        d = 0
        for i in range(n):
            d += min(DX[sx][i], DY[sy][i])
        c = BC[sx] + BC[sy]
        A[c] = min(A[c], d)
print(*A, sep="\n")


Measured memory_bytes: 89656
import sys,string
A="abcdefghijklmnopqrstuvwxyza"
tbl=string.maketrans(A[:-1],A[1:])
for s in sys.stdin:
    while not("the" in s or "that" in s or "this" in s):
        s=s.translate(tbl)
    print s[:-1]

Measured memory_bytes: 4376
#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(){
  vector<int> a(9);
  rep(i,9) cin >> a[i];
  int n;
  cin >> n;
  rep(i,n){
    int x;
    cin >> x;
    rep(j,9){
      if(a[j]==x){
        a[j]=0;
      }
    }
  }
  string ans = "No";
  for(int i=0;i<9;i++){
    for(int j=i+1;j<9;j++){
      for(int k=j+1;k<9;k++){
        if(a[i]==0 and a[j]== 0 and a[k]==0){
          if((i==0 and j==1 and k==2) or (i==3 and j==4 and k==5) or (i==6 and j==7 and k==8) or (i==0 and j== 3 and k==6) or (i==1 and j==4 and k==7) or (i==2 and j==5 and k==8) or (i==0 and j==4 and k==8) or (i==2 and j==4 and k==6)){
            ans ="Yes";
          }
        }        
      }
    }
  }
  cout << ans << "\n";
  
  return 0;
}

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

#define MOD 998244353

long long power( long long x, int n )
{
	long long res = 1;
	long long p = x;
	while( n > 0 ) {
		if( n % 2 ) res = res * p % MOD;
		p = p * p % MOD;
		n /= 2;
	}
	return res;
}

int main()
{
	int N;
	cin >> N;
	vector<int> D( N );
	for( int i = 0; i < N; i++ ) {
		cin >> D[i];
	}

	map<int, int> mp;
	for( int i = 1; i < N; i++ ) {
		mp[D[i]]++;
	}
	int j = 1;
	int flag = 0;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		if( it->first != j ) {
			flag = 1;
			break;
		}
		j++;
	}
	long long ans = 0;
	if( D[0] > 0 || flag ) {
	}
	else {
		ans = 1;
		int last = -1;
		for( auto it = mp.begin(); it != mp.end(); it++ ) {
			int n = it->second;
			if( last > 0 ) {
				ans *= power( last, n );
				ans %= MOD;
			}
			last = n;
		}
	}
 
	cout << ans << endl;
}


Measured memory_bytes: 5376
fn input_pair<T: std::str::FromStr + Copy> () -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1])
}

fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn main() {
    let (n, m) = input_pair::<usize>();
    let mut r = vec![(0, 0); n];
    for _ in 0..m {
        let ps: String = input_one().unwrap();
        let ps: Vec<_> = ps.split_whitespace().collect();
        let p = ps[0].parse::<usize>().unwrap() - 1;
        let s = ps[1];
        if s == "AC" {
            r[p].0 = 1;
        } else {
            if r[p].0 == 0 {
                r[p].1 += 1;
            }
        };
    }
    let mut result = (0, 0);
    for (ac, ng) in r.into_iter() {
        result.0 += ac;
        if ac == 1 {
            result.1 += ng;
        }
    }
    println!("{} {}", result.0, result.1);
}


Measured memory_bytes: 2784
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n, m;
    cin >> n >> m;
    if (n == m) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
n = int(input())
m = int(input())
cards = [ i for i in range(1,2*n+1) ]

def riffle(c):
    length = len(c)//2
    c1 = c[:length]
    c2 = c[length:]
    c3 = []
    for i in range(length):
        c3.append(c1[i])
        c3.append(c2[i])
    return c3

for i in range(m):
    s = int(input())
    if s == 0:
        cards = riffle(cards)
    else:
        cards = cards[s:] + cards[:s]

print(*cards, sep='\n')


Measured memory_bytes: 5632
#include<algorithm>
#include<cstring>
#include<cstdio> 
#include<cmath> 

using namespace std;

int n,m;
char  s[20];

int main(){
    scanf("%d%d",&n,&m);
    scanf("%s",s);
    for(int  i=0;i<=n+m;i++)
    {
        if((s[i]<'0'||s[i]>'9')&&i!=n)
        {
            puts("No");
            return 0;
        }
        if(s[i]!='-'&&i==n)
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define M 505
#define base 200
inline int read(){
	int x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0'; ch = getchar();}
	return x*f;
}

int n,h;
int f[M],size[M],in[M],out[M];
bool vis[M];

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

inline void Union(int x,int y){
	int fx = find(x),fy = find(y);
	if(fx == fy){
		size[fx]++;
		return;
	}
	f[fx] = fy; size[fy] += size[fx]+1;
}

int main(){
	n = read(); h = read();
	for(int i = 1;i <= h;i++){
		f[i+base] = i+base;
		size[i+base] = 1;
	}
	for(int i = -h;i <= -1;i++){
		f[i+base] = i+base;
		size[i+base] = 1;
	}
	for(int i = 1;i <= n;i++){
		int a = read(),b = read(),c = read(),d = read();
		int x,y;
		if(c == 0) x = a;
		else x = -c;
		if(d == 0) y = -b;
		else y = d;
		out[x+base]++; in[y+base]++;
		Union(x+base,y+base);
	}
	for(int i = 1;i <= h;i++)
		if(out[i+base] < in[i+base]){
			puts("NO");
			return 0;
		}
	for(int i = -h;i <= -1;i++)
		if(in[i+base] < out[i+base]){
			puts("NO");
			return 0;
		}
	for(int i = 1;i <= h;i++)
		vis[find(i+base)] |= (in[i+base] != out[i+base]);
	for(int i = -h;i <= -1;i++)
		vis[find(i+base)] |= (in[i+base] != out[i+base]);
	for(int i = 1;i <= h;i++)
		if(size[find(i+base)] > 1)
			if(find(i+base) == i+base)
				if(vis[i+base] == false){
					puts("NO");
					return 0;
				}
	for(int i = -h;i <= -1;i++)
		if(size[find(i+base)] > 1)
			if(find(i+base) == i+base)
				if(vis[i+base] == false){
					puts("NO");
					return 0;
				}
	puts("YES");
	return 0;
}

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

int main(){
  int n,m,a[110000],b[110000];
  bool flag[110000]={};
  long int h[110000];
  cin>>n>>m;
  for(int i=1;i<=n;i++) cin>>h[i];
  for(int i=0;i<m;i++){
     cin>>a[i]>>b[i];
  }
  for(int i=0;i<m;i++){
    if(h[a[i]]==h[b[i]]) { flag[a[i]]=true; flag[b[i]]=true; }
    else if(h[a[i]]<h[b[i]]) flag[a[i]]=true;
    else flag[b[i]]=true;
  }
  int cnt=0;
  for(int i=1;i<=n;i++) if(flag[i]) cnt++;

  cout<<n-cnt;

}


Measured memory_bytes: 5224
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main (){
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<"Draw"<<endl;
	}else{
		if(a==1){
			cout<<"Alice";
		}else if(b==1){
			cout<<"Bob";
		}else{
			cout<<(a>b ? "Alice" : "Bob")<<endl;
		}
	}
}


Measured memory_bytes: 256
// Problem Code: abc158_e

#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

long long divisible_substring(int N, int P, string& S) {
	int res, p;
	long long cnt;
	cnt = res = 0;
	unordered_map<int, long long> m;
	
	if (P == 2 || P == 5) {
		for (int i = 0; i < N; i++)
			if ((S[i] - '0') % P == 0)
				cnt += i + 1;
		return cnt;
	}
	
	m[0] = p = 1;
	for (int i = N - 1; i >= 0; i--) {
		res = (res + (S[i] - '0') * p) % P;
		m[res]++;
		p = (10 * p) % P;
	}
	for (auto it: m)
		cnt += it.second * (it.second - 1) / 2;
	
	return cnt;
}

int main() {
	int N, P;
	string S;
	cin >> N >> P >> S;
	cout << divisible_substring(N, P, S);
	return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

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

  int magic_count = 0;
  for (int i = 1; i < N; i++) {
    if (a[i - 1] == a[i]) {
      magic_count++;
      i++;
    }
  }

  cout << magic_count << endl;

  return 0;
}


Measured memory_bytes: 256
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;

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

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

void stndrtn() {
#ifdef hitorie
    freopen(".in", "r", stdin);
#endif        
}

const bool flag = 0;

void maincode() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    ll sum = 0;
    for (int& x : a)
        cin >> x, sum += x;
    if (sum > n)
        cout << -1, exit(0);
    cout << n-sum;           
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) 
        cin >> ts;
    while (ts--)
        maincode(); 
    return 0;
}

Measured memory_bytes: 3720