akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



char a, b;
int main() {
  cin >> a >> b;
  if (a == 'H') {
	if (b == 'H') puts("H");
	else puts("D");
  }
  else {
	if (b == 'H') puts("D");
	else puts("H");
  }
}
																				   


Measured memory_bytes: 256
/*input
1 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	if(a*b%2) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1_7_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            int r = int.Parse(str[2]);

            int[,] A = new int[n, m];
            int[,] B = new int[m, r];
            long[,] C = new long[n, r];

            for(int i = 0; i < n; i++)
            {
                string[] str1 = Console.ReadLine().Split(' ');
                for(int j = 0; j < m; j++)
                {
                    A[i, j] = int.Parse(str1[j]);
                }
            }

            for (int i = 0; i < m; i++)
            {
                string[] str1 = Console.ReadLine().Split(' ');
                for (int j = 0; j < r; j++)
                {
                    B[i, j] = int.Parse(str1[j]);
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < r; j++) 
                {
                    for (int k = 0; k < m; k++)
                    {
                        C[i, j] += A[i, k] * B[k, j];
                    }
                }
            }
            
            for(int i = 0; i<n; i++)
            {
                for(int j = 0 ; j < r; j++)
                {
                    Console.Write(C[i, j]);
                    if (j == r - 1)
                        Console.Write("\n");
                    else
                        Console.Write(" ");
                }
            }
        }
    }
}

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

int main() {
	long long A,B;
	cin >> A >>B; 
	if (A%2 != B%2) {
		cout << "IMPOSSIBLE"<< endl;
	}
	else {
		cout << (A+B)/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 3604
using System;

namespace A___Odds_of_Oddness
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = double.Parse(Console.ReadLine());

            if (N==1)
            {
                Console.WriteLine(1);
                return;
            }
            if (N%2 == 0)
            {
                Console.WriteLine(0.5);
                return;
            }
            var a = ((N - 1) / 2)+1;
            Console.WriteLine(a/N);
        }
    }
}


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

int main() {
  int n; string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,0,n-2) {
    if (s.substr(i,3) == "ABC") {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

bool check(string s){
    int N = s.size();
    if(N % 2 == 1) return false;
    return (s.substr(0, N/2) == s.substr(N/2));
}

int main(void){
    string s;
    cin >> s;

    int n = s.size();

    for (int i = n-1; ; i--){
        if(check(s.substr(0, i))){
            cout << i << endl;
            return 0;
        }
    }

    return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;

int main() {
	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	A--; B--; C--; D--;
	string S;
	cin >> S;
	int len = 0;
	for (int i = A; i <= C; i++) {
		if (S[i] == '#') {
			len++;
			if (len == 2) {
				cout << "No" << endl;
				return 0;
			}
		}
		else len = 0;
	}
	len = 0;
	for (int i = B; i <= D; i++) {
		if (S[i] == '#') {
			len++;
			if (len == 2) {
				cout << "No" << endl;
				return 0;
			}
		}
		else len = 0;
	}
	if (C < D) {
		cout << "Yes" << endl;
		return 0;
	}
	len = 0;
	for (int i = B - 1; i <= D + 1; i++) {
		if (S[i] == '.') {
			len++;
			if (len == 3) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else len = 0;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n;
    cin>>n;
    vi v(n);
    rep(i,0,n) cin>>v[i];
    vi dp(n);
    dp[0] = 0;
    dp[1] = abs(v[1]-v[0]);
    rep(i,2,n){
        dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1]<<endl;
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 4752
//shipc_c.cpp
//Sat Jul  7 20:35:34 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
using ll=long long;

int main(){
	double n,m,d;
	cin >> n >> m >> d;

	double ans;
	if (d == 0){
		ans = (m-1)/n;
	}else {
		ans = 2*(n-d)/pow(n,2);
		ans = ans * (m-1);
	}
	printf("%.10lf\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, M;
    cin >> N >> M;
    if (N == 1){
        if (M >= 2){
            cout << -1 << endl;
            return 0;
        }
        else {
            if (M == 0){
                cout << 0 << endl;
                return 0;
            }
            else {
                int a, b;
                cin >> a >> b;
                cout << b << endl;
                return 0;
            }
        }
    }
    vector<int> A(N);
    for (int i = 0; i < M; i++){
        int s, c;
        cin >> s >> c;
        if (s == 1 && c == 0){
            cout << -1 << endl;
            return 0;
        }
        if (A.at(s - 1) != 0 && A.at(s - 1) != c){
            cout << -1 << endl;
            return 0;
        }
        else {
            A.at(s - 1) = c;
        }
    }
    for (int i = 0; i < N; i++){
        if (i == 0 && A.at(i) == 0){
            cout << 1;
            continue;
        }
        cout << A.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    
    if (a > b && b > c)
        printf("%d %d %d\n",c,b,a);
    else if (a < b && b < c)
        printf("%d %d %d\n",a,b,c);
    else if (a < b && b > c && a > c)
        printf("%d %d %d\n",c,a,b);
    else if (a < b && b > c && a < c)
        printf("%d %d %d\n",a,c,b);
    else if (a > b && b < c && a > c)
        printf("%d %d %d\n",b,c,a);
    else if (a > b && b < c && a < c)
        printf("%d %d %d\n",b,a,c);
    else if (a > b && b == c)
        printf("%d %d %d\n",b,c,a);
    else if (a > b && a == c)
        printf("%d %d %d\n",a,c,b);
    else if (a == b && b < c)
        printf("%d %d %d\n",a,b,c);
    else if (a < b && a == c)
        printf("%d %d %d\n",a,c,b);
    return 0;
}

Measured memory_bytes: 596
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String w = sc.next();
        int[] alpc = new int[26];
        boolean b = true;
        for (int i = 0; i < w.length(); i++) {
            alpc[w.charAt(i)-'a']++;
        }
        for (int i = 0; i < 26; i++) {
            if (alpc[i] % 2 != 0) {
                b = false;
                break;
            }
        }
        if (b) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

        sc.close();
    }

}





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

namespace abc104_c
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			Tuple<int, int>[] arr = new Tuple<int, int>[x[0]];
			for (int i = 0; i < x[0]; i++)
			{
				int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
				arr[i] = new Tuple<int, int>(a[0], a[1]);
			}
			int ret = int.MaxValue;
			for (int i = 0; i < 2 << x[0]; i++)
			{
				int now = 0; int sum = 0;
				for (int j = 0; j < x[0]; j++)
				{
					if ((i & (1 << j)) > 0)
					{
						now += arr[j].Item1;
						sum += 100 * (j + 1) * arr[j].Item1 + arr[j].Item2;
					}
				}
				if (sum < x[1])
				{
					int j = x[0] - 1;
					while ((i & (1 << j)) > 0) j--;
					int point = 100 * (j + 1);
					int should = (x[1] - sum + (point - 1)) / point;
					if (should > arr[j].Item1) now += 999999;
					else now += (x[1] - sum + (point - 1)) / point;
				}
				ret = Math.Min(ret, now);
			}
			Console.WriteLine(ret);
		}
	}
}

Measured memory_bytes: 13396
#include<stdio.h>

int main(){
  int x,y,t;
  scanf("%d %d",&x,&y);
  t = x % y;
  while(t != 0){
    x = y;
    y = t;
    t = x % y;
  }
  printf("%d\n",y);

  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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 namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

const int MAX = 210000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理O(n)
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算O(1)
ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {

    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    int odd = 0, even = 0;
    REP(i, n) {
        cin >> a[i];
        if (a[i] % 2) odd++;
        else even++;
    }
    
    COMinit();

    int odd_k = 1, even_k = 0;
    ll sum_odd = 0, sum_even = 0;
    while (true) {
        if (even_k == 50) break;
        sum_odd += COM(odd, odd_k);
        sum_even += COM(odd, even_k);
        odd_k += 2;
        even_k += 2;
    }

    cerr << sum_odd << " " << sum_even << endl;

    if (p == 1) {
        cout << (ll)pow(2, even) * sum_odd << endl;
    } else {
        cout << (ll)pow(2, even) * sum_even << endl;
    }


    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8992
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            System.out.println(A > 8 || B > 8 ? ":(" : "Yay!");
        }
    }
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().Split();
        var n = int.Parse(s[0]);
        var a = int.Parse(s[1]);
        var b = int.Parse(s[2]);

        Console.WriteLine(Math.Min(n * a, b));
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string>
#include <map>

typedef long long ll;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

int main()
{
  std::string S;
  std::cin >> S;

  std::map<char, bool> MM;
  MM['A'] = true;
  MM['T'] = true;
  MM['C'] = true;
  MM['G'] = true;

  ll length = 0LL;
  ll ans = 0LL;
  for (auto c : S) {
    if (MM[c] == true) {
      length++;
    } else {
      ans = std::max(ans, length);
      length = 0LL;
    }
  }
  ans = std::max(ans, length);
  print(ans);

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    switch(s){
      case "A":
        s="T";
        break;
      case "T":
        s="A";
        break;
      case "G":
        s="C";
        break;
      case "C":
        s="G";
        break;
    }
    System.out.println(s);
  }
}

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

int id[1000000+5];
int sz[1000000+5];
void ufinit(int n)
{
    for (int i = 1; i < n + 1; i++)
    {
        id[i] = i;
        sz[i] = 1;
    }
}

int root(int i)
{
    while (i != id[i])
    {
        id[i] = id[id[i]];
        i = id[i];
    }

    return i;
}

bool connected(int p, int q)
{
    return root(p) == root(q);
}

void link(int p, int q)
{
    int i = root(p);
    int j = root(q);
    if (i == j)
        return;
    if (sz[i] < sz[j])
    {
        id[i] = j;
        sz[j] += sz[i];
    }
    else
    {
        id[j] = i;
        sz[i] += sz[j];
    }
}

vector<unordered_set<int>> graph(1000000+5);
int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    ufinit(n);
    rep(i, 0, m)
    {
        int p, q;
        cin >> p >> q;
        link(p, q);
        graph[p].insert(q);
        graph[q].insert(p);
    }
    rep(i, 0, k)
    {
        int p, q;
        cin >> p >> q;
        if (connected(p,q))
        {
            graph[p].insert(q);
            graph[q].insert(p);
        }
    }
    rep(i, 1, n + 1)
    {
        int ans = sz[root(i)] - graph[i].size() - 1;
        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;

int N, K;
vector<int> DpSum;

int solve() {
	int sum;

	sum = -1000000001;
	for (int i = 1; i + K <= N; ++i) {
		sum = max(sum, DpSum[i + K] - DpSum[i]);
	}

	return sum;
}

int main() {
	int a;

	while (cin >> N >> K, N) {
		DpSum.clear();
		DpSum.resize(N + 1);
		DpSum[0] = 0;
		for (int i = 1; i <= N; ++i) {
			cin >> a;
			DpSum[i] += DpSum[i - 1] + a;
		}
		cout << solve() << endl;
	}

	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N)
  {
    cin >> a[i];
  }
  int ans = 0;
  int next = 1;
  rep(i, N)
  {
    if (next != a[i])
    {
      ans++;
    }
    else
    {
      next++;
    }
  }
  if (ans == a.size())
  {
    cout << -1 << endl;
  }
  else
  {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int d;
	int p;
	
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
	
	if (p > c){
		if (a * p > (p - c) * d + b){
			printf("%d\n", (p - c) * d + b);
		}
		else {
			printf("%d\n", a * p);
		}
	}
	
	else {
		if (a * p > b){
			printf("%d\n", b);
		}
		else {
			printf("%d\n", a * p);
		}
	}
	
	return (0);
}
		

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
using namespace std ;

char s[200005] ;

int main() {
	scanf("%s", s + 1) ;
	int top = 0, n = strlen(s + 1), ans = n ;
	rep(i, 1, n) {
		if (s[i] == 'S') {
			++ top ;
		} else {
			if (top) -- top, ans -= 2 ;
		}
	}
	printf("%d\n", ans) ;
	return 0 ; 
}

Measured memory_bytes: 384
class DisjointSet:
    def __init__(self, size):
        self.rank = [0 for i in range(size)]
        self.p = [0 for i in range(size)]
        for i in range(size):
            self.makeSet(i)
    
    def makeSet(self, x):
        self.p[x] = x
        self.rank[x] = 0

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

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
    
    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]

N, M = map(int, input().split())
# A = [0 for i in range(N+1)]
ds = DisjointSet(N)
for i in range(M):
    X, Y, Z = map(int, input().split())
    ds.unite(X-1, Y-1)

print(sum([ds.p[x] == x for x in range(N)]))

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//main code

int main(int argc, char const* argv[])
{
	char a;
	cin >> a;
	char ans;
	switch (a) {
		case 'A':
			ans = 'T';
			break;
		case 'C':
			ans = 'G';
			break;
		case 'G':
			ans = 'C';
			break;
		case 'T':
			ans = 'A';
			break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }


template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	rer(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for(int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}

mint nCr(int n, int r) {
	if(n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}

int main() {
	int N; int A; int B; int C;
	while(~scanf("%d%d%d%d", &N, &A, &B, &C)) {
		nCr_computeFactinv(N);
		mint ans;
		rer(p, 0, N) rer(q, 0, N) {
			int a = A - p, b = B / 2, c = C - p - q * 3;
			if(a < 0 || c < 0 || B % 2 != 0) continue;
			int groups = a + b + p + q;
			mint cnt = 1;
			cnt *= fact[groups];
			cnt *= factinv[a];
			cnt *= factinv[b];
			cnt *= factinv[p];
			cnt *= factinv[q];
			cnt *= b == 0 ? (c == 0 ? 1 : 0) : nCr(c + b - 1, b - 1);
			ans += cnt;
		}
		printf("%d\n", ans.get());
	}
	return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  int totalDist = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int distB = k - x;
    if ( x > distB) {
      totalDist += distB * 2;
    } else {
      totalDist += x * 2;
    }
  }
  cout << totalDist << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(j=a;j>=b;j--)
#define vi vector<int>
using namespace std;

int main(){
	int n,i,j;
	cin>>n;
	vi a(n);
	loop(i,0,n){
		cin>>a[i];
	}
	vector<bool> dp(40001,false);
	dp[0]=true;
	loop(i,0,n){
		rloop(j,40001,0){
			if(dp[j]==true){
				dp[j+a[i]]=true;
			}
		}
	}
	int q;
	cin>>q;
	loop(i,0,q){
		cin>>j;
		if(dp[j]==true){
			cout<<"yes"<<"\n";
		}else{
			cout<<"no"<<"\n";
		}
	}
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int N = 2e5 + 1;
//ll int freq[100001];
ll int bigPower(ll int x, unsigned ll int y, ll int p)
{
    ll int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
    // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
void findAns()
{

   ll  int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;

    if (k <= a)
    {
        cout << k;
        return;
    }
    else if (k <= a + b)
        cout << a;
    else
    {
        k -= (a + b);
        sum = a - k;
        cout << sum;
    }


}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
// #endif

    fastio;

    // ll int t;
    // cin >> t;

    // while (t--)
    findAns();
}

Measured memory_bytes: 3556
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	plus := a + b
	minus := a - b
	multiple := a * b
	if plus >= minus && plus >= multiple {
		fmt.Println(plus)
		return
	}
	if minus >= plus && minus >= multiple {
		fmt.Println(minus)
		return
	}
	fmt.Println(multiple)
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll q; cin>>q;
  vll s(100005);
  for(ll i=1; i<=100000; i++){
    s[i]=s[i-1];
    if(i%2) if(is_prime(i)&&is_prime((i+1)/2)) s[i]++;
  }
  rep(i,q){
    ll l,r; cin>>l>>r;
    cout<<s[r]-s[l-1]<<endl;
  }
}

Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin >> a >> b >> c;
    vi v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(all(v));
    cout << v[2]*10+v[1]+v[0] << endl;
    return 0;
}

Measured memory_bytes: 3488
import numpy as np
from collections import Counter


n = int(input())
A = list(map(int, input().split()))
A.sort()
is_divisible = np.zeros(10**6+1, dtype=np.int64)


def update(num):
    nums = np.arange(num, 10**6+1, num)
    is_divisible[nums] = True

counter = Counter(A)
ans = 0
for a, count in counter.items():
    if count == 1 and not is_divisible[a]:
        ans += 1
        
    update(a)

print(ans)


Measured memory_bytes: 62924
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
template<class Type> class BinaryTree
{
    struct Node
    {
        Type val;
        Node *left, *right;
    };
    public:
        Node *root = NULL;
        Node *insert(Node *p, Type x)
        {
            if(p == NULL)
            {
                Node *q = new Node;
                q->val = x;
                q->left = q->right = NULL;
                if(root == NULL) root = q;
                return q;
            }
            else
            {
                if(x < p->val) p->left = insert(p->left, x);
                else p->right = insert(p->right, x);
                return p;
            }
        }
        void inorder(Node *p)
        {
            if(p->left != NULL) inorder(p->left);
            cout << " " << p->val;
            if(p->right != NULL) inorder(p->right);
        }
        void preorder(Node *p)
        {
            cout << " " << p->val;
            if(p->left != NULL) preorder(p->left);
            if(p->right != NULL) preorder(p->right);
        }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    BinaryTree<int> T;
    for(int i = 0; i < n; i++)
    {
        string s; cin >> s;
        if(s == "insert") 
        {
            int n; cin >> n;
            T.insert(T.root, n);
        }
        if(s == "print")
        {
            T.inorder(T.root);
            cout << endl;
            T.preorder(T.root);
            cout << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 18676
#define DEBUG 1

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 1000000007

LLI dp[5001][2],dp2[5001][2];
int main() {
    int N,A,B;
    scanf("%d %d %d",&N,&A,&B);
    if (A > B) swap(A,B);
    if (A == 1) {
        int i,p = 1;
        for (i = 0; i < N; i++) p *= 2,p %= MOD;
        printf("%d\n",p);
        return 0;
    }

    int i,j;
    dp[1][1] = 1;
    for (i = 2; i <= N; i++) {
        dp[i][1] = dp[i-1][0]+dp[i-1][1];
        for (j = A; j < i; j++) dp[i][0] += dp[i-j][1];
        dp[i][0] %= MOD,dp[i][1] %= MOD;
    }
    dp2[0][0] = dp2[0][1] = 1;
    for (i = 1; i <= N; i++) {
        for (j = 1; j <= i; j++) {
            if (j < A) dp2[i][0] += dp2[i-j][1];
            if (j < B) {
                dp2[i][1] += (dp2[i-j][0]*dp[j][1]) % MOD;
                if (i == N) dp2[i][1] += (dp2[i-j][0]*dp[j][0]) % MOD;
                if (j == i) dp2[i][1] += dp[j][0];
            }
        }
        dp2[i][0] %= MOD,dp2[i][1] %= MOD;
    }
    int p = 1;
    for (i = 0; i < N; i++) p *= 2,p %= MOD;
    printf("%lld\n",(p-(dp2[N][0]+dp2[N][1])+2*MOD) % MOD);

    return 0;
}



Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m;
	cin >> n >> m;
	vector<int> v(m);
	rep(i,0,m)cin >> v[i];
	ll ans = n - accumulate(all(v), 0LL);
	cout << (ans >= 0?ans:-1) << '\n';
}


Measured memory_bytes: 3668
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::bitset<200> graph[200];
int pos01[200];

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

void func(int v, int val)
{
	if (pos01[v] == -1) {
		pos01[v] = val;
	}
	else {
		if (pos01[v] != val) {
			out << -1 << std::endl;
			exit(0);
		}
		return;
	}

	for (size_t i = 0; i < N; i++)
	{
		if (graph[v][i]) {
			func(i, val ^ 1);
		}
	}
}


int dist[200][200] = {};
void war() {
	
	for (size_t i = 0; i < N; i++)
		for (size_t j = 0; j < N; j++)
	{
		if (graph[i][j]) {
			dist[i][j] = 1;
		}
		else {
			dist[i][j] = 200200200;
		}
	}
	for (size_t k = 0; k < N; k++)
		for (size_t i = 0; i < N; i++)
			for (size_t j = 0; j < N; j++)
	{
		dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
	}

}



int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	fill_all(pos01, -1);
	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		std::string s;
		in >> s;
		std::reverse(s.begin(), s.end());
		graph[i] = std::bitset<200>{s};
	}
	func(0, 0);
	war();

	int max = 0;
	for (size_t i = 0; i < N; i++)
		for (size_t j = 0; j < N; j++)
	{
		if (dist[i][j] < 200200200 && i!=j) {
			max = std::max(max, dist[i][j]);
		}
	}
	out << max+1 << endl;

	return 0;
}
#endif


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
#include <cmath>

int f(int N)
{
    std::vector<int> p(N+1, 0);
    int ans = 0;
    for (int k = 1; k <= N; ++k)
    {
        for (int j = k; j <= N; j += k)
        {
            ++ans;
        }
    }
    return ans;
}

int main()
{
    int N;
    io >> N;
    int ans = f(N-1);
    io << ans << BR;
}

Measured memory_bytes: 7128
#include<iostream>
 
int main()
{
	char a, b, c;
  	char x, y, z;
	scanf("%c %c %c", &a, &b, &c);
  	scanf(" %c %c %c", &x, &y, &z);
  	printf("%d\n", ((a == x) + (b == y) + (c == z)));
}

Measured memory_bytes: 256
#include <stdio.h>
    //--------------------------------------------------------------
    // checkMove
    // 受け取った文字列と呪文の文字列と一致するものを探す。
    // あった場合に、呪文の移動の判定を行う。
    // 移動した先が一番端だった場合、
    // 最も左ならば-1を、最も右ならば1を返す関数
    // どちらでもなかった場合には0を返す
    //--------------------------------------------------------------
    int checkMove(char *s, char *t, char *d, int n, int q, int b) {
    	int i;
    	for (i = 0; i < q; ++i) {
    		if (s[b] == t[i]) {                           
    			b += ((d[i] == 'R') ? 1 : -1);
    			if (b < 0) {
    				return -1;
    			}
    			if (b > n - 1) {
    				return 1;
    			}
    		}
    	}
    	return 0;
    }
     
    int main(void) {
    	int n, q, i;
        int dummy;
        
    	scanf("%d %d", &n, &q);
    	char s[n];
    	scanf("%s", s);
    	char t[q], d[q];
    	for (i = 0; i < q; ++i) {
    		scanf("\n %c %c", &t[i], &d[i]);
    	}
    	int a = -1, b_prev = -1, c = n;                                           
    	int b;
    	while(1) { // 左に行けるものの中で最も離れているものを探す => それまでのものはすべて消すことができる
    		b = (a + c ) / 2;	// 二分探索の中央を求める
    		if (b == b_prev) {		// 前回の探索と中央値が同じなら終わり
    			break;              
    		}
    		if (checkMove(s, t, d, n, q, b) < 0) {	// チェックして、行くことができるものがあるならaに、なければcに
                //bの位置にあったものが-1まで行った場合bより左に居たゴーレムはすべて死亡
    			a = b;
    		} else {
    			c = b;
    		}
    		b_prev = b;
    	}
    	int left = a;
    	a = -1;
    	b_prev = -1;
    	c = n;
    	while(1) { // 左の時と同様に最も右に行くことができるかどうかの判定
    		b = (a + c ) / 2;
    		if (b == b_prev) {
    			break;
    		}
    		if (checkMove(s, t, d, n, q, b) > 0) {
    			c = b;
    		} else {
    			a = b;                  
    		}
    		b_prev = b;
    	}
    	int right = c;
        printf( "%d", n - ((left + 1) + ( n -1 - right + 1)) );        
        
    	return 0;
    }








Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int long long
#define Mod 1000000007
using namespace std;
string s;
int Val(int val) {
	return val % Mod;
}
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	int ans = 0;
	int dp[13] = {0};
	dp[0] = 1;
	for(char c : s) {
		if(c=='?') {
			int tem[13]={0};
			for(int i=0;i<13;i++)
				for(int j=0;j<=9;j++)	
					tem[(i*10+j)%13] += dp[i];
			for(int i=0;i<13;i++)
				dp[i] = tem[i];
		}
		else {
			int tem[13];
			for(int i=0;i<13;i++)
				tem[(i*10+c-'0')%13] = dp[i];
			for(int i=0;i<13;i++)
				dp[i] = tem[i];
		}
		for(int i=0;i<13;i++)
			dp[i] = Val(dp[i]);
	}
	cout << dp[5] << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

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

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

template<class T>
bool chmax(T &a, initializer_list<T> l)
{
	return chmax(a, *max_element(l.begin(), l.end()));
}

template<class T>
bool chmin(T &a, initializer_list<T> l)
{
	return chmin(a, *min_element(l.begin(), l.end));
}

ll N;
ll W[310];
ll dp[310][310];

void init()
{
	for (ll i = 0; i < 310; ++i) for (ll j = 0; j < 310; ++j) dp[i][j] = -1;
}

ll solve(ll l, ll r)
{
	if (dp[l][r]!=-1)return dp[l][r];
	if (l == r) return dp[l][r] = 0;

	ll res(0);
	if (abs(W[l]-W[r])<=1 && solve(l+1, r-1) == r-l-1)
		res = r - l + 1;

	for (ll mid = l; mid <= r-1; ++mid)
		chmax(res, solve(l, mid)+solve(mid+1, r));

	return dp[l][r] = res;
}

int main(int argc, char **argv)
{
	while (cin >> N, N)
	{
		init();
		for (ll i = 0; i < N; ++i) cin >> W[i];
		std::cout << solve(0, N-1) << std::endl;
	}
}



Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n,k;
	ll ans=0;
	
	cin>>n>>k;
	ans = k;
	for(int i=0;i<n-1;i++)
	{
		ans*=(ll)(k-1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
# 問題ごとの提出リスト
# 1 : WA AC
# 2 : WA 
# 3 : AC
teisyutu_list = {} 

for i in range(1, M+1) :
    q_num, ac_wa = map(str, input().split())

    # 提出済みの問題か判定 
    if q_num in teisyutu_list.keys() :
        # q_num の 提出結果リストを取得する。
        teisyutu_list[q_num].append(ac_wa)
    else : 
        teisyutu_list[q_num] = [ac_wa]

ac_cnt = 0
wa_cnt = 0

for j in teisyutu_list.keys() :
    # AC できない問題は無視する(WAをカウントしない)
    if 'AC' not in teisyutu_list[j] :
        continue
    else :
        ac_cnt += 1

        for k in teisyutu_list[j] :
            if 'WA' == k :
                wa_cnt += 1
            else :
                break

print('%d %d' % (ac_cnt, wa_cnt))



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

int main(){
  string s, t; cin >> s >> t;
  ll ans = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int a[2];
  for(int i=0;i<3;i++){
    cin >> a[i];
  }
  sort(a,a+3,greater<int>());
  int sum = a[2] + a[1];
  cout << sum;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int R = cin.nextint;
        if (R < 1200)
        {
            WriteLine("ABC");
        }
        else if (R < 2800)
        {
            WriteLine("ARC");
        }
        else
        {
            WriteLine("AGC");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092