akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
const int INF = 1e9;
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main() {
    int N,X; cin >> N >> X;
    cout << 3*(N-gcd(N,X)) << endl;
}

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

const int N = 1e6 + 10;
int n, ans, res;
char s[N];

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    s[0] = '0';
    for (int i = n; i >= 1; i--)
        if (s[i] > '5' || (s[i] == '5' && s[i - 1] >= '5'))
            res += 10 - (s[i] - '0'), s[i] = '0', s[i - 1]++;
    rep(i, 0, n) ans += s[i] - '0';
    printf("%d\n", ans + res);
    return 0;
}


Measured memory_bytes: 1280
using System;
class Program
{
	static void Main(string[] args)
	{
		string N =Console.ReadLine();
            int count = 0;
            
            foreach (char item in N)
            {
                if (item == '2')
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
mint modFact(mint n) { 
  mint result(1);
  for (int i = 2; i <= n.x; i++) {
    result *= i;
  }
  return result; 
}
int main() {
  mint N,M;
  cin>>N.x>>M.x;
  if (N.x < M.x) {
    swap(N,M);
  }
  if (N.x-M.x == 1) {
    mint n = modFact(N)*modFact(M);
    cout<<n.x;
  } else if (N.x == M.x) {
    mint n = modFact(N);
    n *= mint(2)*n;
    cout<<n.x;
  } else {
    cout<<0;
  }
}

Measured memory_bytes: 3620
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
    std::cin >> N;
    std::unordered_map<std::string, int64_t> color;
    int64_t over3200 = 0;
    for (int64_t i = 0; i < N; i++)
    {
        int64_t rate;
        std::cin >> rate;
        if (1 <= rate && rate <= 399) color["gray"]++;
        if (400 <= rate && rate <= 799) color["brown"]++;
        if (800 <= rate && rate <= 1199) color["green"]++;
        if (1200 <= rate && rate <= 1599) color["skyblue"]++;
        if (1600 <= rate && rate <= 1999) color["blue"]++;
        if (2000 <= rate && rate <= 2399) color["yellow"]++;
        if (2400 <= rate && rate <= 2799) color["orange"]++;
        if (2800 <= rate && rate <= 3199) color["red"]++;
        if (3200 <= rate) over3200++;
    }

    int64_t color_num = color.size();
    int64_t color_min = color_num == 0 ? 1 : color_num;
    int64_t color_max = color_num + over3200;
    std::cout << color_min << " " << color_max << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


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

int main(){
int N, L;   cin >> N >> L;
vector<string> S(N);
for (int i = 0; i < N; i++) {
    cin >> S[i];
}
sort(S.begin(), S.end());
for (int i = 0; i < N; i++) {
    cout << S[i];
}
cout << endl;
}


Measured memory_bytes: 256
n,a,b,c,d = [int(i) for i in input().split()]
s = input()
flag1 = False
block = 0
for i in range(b, len(s)):
    if block == 2:
        flag1 = False
        break
    elif i == d-1:
        flag1 = True
        break
    elif s[i] == ".":
        block = 0
    elif s[i] == "#":
        block += 1
if flag1:
    s2 = s[:d-1]+'#'+s[d:]
    flag1 = False
    block = 0
    for i in range(a, len(s)):
        if block == 2:
            flag1 = False
            break
        elif i == c-1:
            flag1 = True
            break
        elif s2[i] == ".":
            block = 0
        elif s2[i] == "#":
            block += 1
flag2 = False
flag3 = False
temp = 0
block = 0
for i in range(b-2,c-2):
    if temp == 3:
        flag2 = True
        temp = i-1
        break
    elif s[i] == "#":
        temp = 0
    elif s[i] == ".":
        temp += 1
if flag2:
    flag3 = False
    block = 0
    s1 = s[:temp-1]+'#'+s[temp:]
    for i in range(a, len(s)):
        if block == 2:
            flag3 = False
            break
        elif i == c-1:
            flag3 = True
            break
        elif s1[i] == ".":
            block = 0
        elif s1[i] == "#":
            block += 1
    if flag3:
        s3 = s1[:c - 1] + '#' + s1[c:]
        flag3 = False
        block = 0
        for i in range(temp, len(s)):
            if block == 2:
                flag3 = False
                break
            elif i == d-1:
                flag3 = True
                break
            elif s3[i] == ".":
                block = 0
            elif s3[i] == "#":
                block += 1
if flag1 or flag3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3836
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
    long N;
    cin >> N;
    long M = sqrt(N);
    long ans = N+1;
    for(long i=1;i<=M;i++){
      if(N%i==0){
        ans = min(ans, i + N/i-2);
      }
    }
    cout << ans <<endl;
    
  	return 0;
}


Measured memory_bytes: 256
A,V = map(int, input().split())
B,W = map(int, input().split())
T = int(input())
X = abs(A-B)
Y = V-W
if (V<=W):
  print('NO')
#elif ((X%Y) == 0) and ((X/Y)<=T):
elif ((X/Y)<=T):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9204
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N;
    cin >> N;

    cout << (1000 - (N % 1000)) % 1000 << endl;

    return 0;
}


Measured memory_bytes: 3556
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>

#define N 610
#define RG register
#define ll long long
#define MOD 1000000007

using namespace std;

inline int read(){
    RG int x=0,t=1;RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}

int n,a[N],vis[N],f[N][N][N],nop[N];
inline int Plu(const int &x,const int &y) { return x+y>=MOD?x+y-MOD:x+y; }

int main(){
	n=read(); int A=0,B=0;
	for(RG int i=1;i<=n<<1;++i) a[i]=read(),vis[max(0,a[i])]=1;
	for(RG int i=1;i<=n<<1;i+=2){
		int tmp=(a[i]==-1)+(a[i+1]==-1);
		if(tmp==1) ++A; if(tmp==2) ++B;
		if(!tmp) nop[a[i]]=nop[a[i+1]]=1;
	}   f[(n<<1)|1][0][0]=1; int tA=0,tB=0;
	for(RG int i=n<<1;i;--i){
		if(vis[i]) ++tA; else ++tB;
		if(nop[i]) { memcpy(f[i],f[i+1],sizeof(f[i])); continue ; }
		for(RG int j=0;j<=tA;++j)
			for(RG int k=0;k<=tB;++k)
				if(vis[i]){
					if(j) f[i][j][k]=Plu(f[i][j][k],f[i+1][j-1][k]);
					f[i][j][k]=Plu(f[i][j][k],f[i+1][j][k+1]);
				}	else{
					if(k) f[i][j][k]=Plu(f[i][j][k],f[i+1][j][k-1]);
					f[i][j][k]=Plu(f[i][j][k],f[i+1][j][k+1]);
					f[i][j][k]=(1LL*f[i+1][j+1][k]*(j+1)+f[i][j][k])%MOD;
				}
	}   int ans=f[1][0][0];
	for(RG int i=1;i<=B;++i) ans=1LL*i*ans%MOD; printf("%d\n",ans);
}


Measured memory_bytes: 873344
/*input
3
-1 0
0 3
2 -1
*/ 
#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
const int MX = 1010;
int X[MX], Y[MX];
main () {
    set<int> s;
    int n; cin >> n;
    for(int i = 1; i <= n; i ++) {
        cin >> X[i] >> Y[i];
        s.insert(abs(X[i] + Y[i]) % 2);
    }
    if(s.size() > 1) return cout << -1, 0;
    vector<int> v;
    if(*s.begin() == 0) v.push_back(1);
    v.push_back(1);
    for(int i = 1; i <= 30; i ++) v.push_back(1 << i);
    reverse(v.begin(), v.end());
    cout << v.size() << endl;
    for(auto it: v) cout << it << ' '; cout << endl;
    for(int i = 1; i <= n; i ++) {
        int x = 0, y = 0;
        for(auto it: v) {
            int a = abs(x + it - X[i]) + abs(y - Y[i]);
            int b = abs(x - it - X[i]) + abs(y - Y[i]);
            int c = abs(x - X[i]) + abs(y + it - Y[i]);
            int d = abs(x - X[i]) + abs(y - it - Y[i]);
            int m = min({a, b, c, d});
            if(m == a) {
                cout << 'R';
                x += it;
            }
            else if(m == b) {
                cout << 'L';
                x -= it;
            }
            else if(m == c) {
                cout << 'U';
                y += it;
            }
            else if(m == d) {
                cout << 'D';
                y -= it;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    int x; cin >> x;
    cout << x * x * x << '\n';

}



Measured memory_bytes: 3120
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    if(n>=195) cout << 5 << endl;
    else if(n>=189) cout << 4 << endl;
    else if(n>=165) cout << 3 << endl;
    else if(n>=135) cout << 2 << endl;
    else if(n>=105) cout << 1 << endl;
    else  cout << 0 << endl;
}

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

using namespace std;

int main() {

	string s;
	cin >> s;

	long counter = 0;
	for (long i = 0; i < s.size()/2; i++) {
	
		if (s[i] != s[s.size() - 1 - i]) {
			counter++;
		}
	
	}



	cout << counter << endl;
}

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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  string ans("abcdefghijklmnopqrstuvwxyz");
  for(int i=0; i<L; i++){
    for(int j=0; j<26; j++){
      if(ans.at(j)==S.at(i)) ans.at(j)='.';
    }
  }
  int num=0;
  for(int i=0; i<26; i++){
    if(ans.at(i)!='.'){
      cout << ans.at(i) << endl;
      break;
    }
    else num++;
  }
  if(num==26) cout << "None" << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  static long a, b;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    a = sc.nextInt(); b = sc.nextInt();

    if(a <= 0 && 0 <= b){
      System.out.println("Zero");
      return;
    }

    if(a < 0 && b < 0){
      if((b - a) % 2L == 0L){
        System.out.println("Negative");
      }
      else{
        System.out.println("Positive");
      }
    }
    else{
      System.out.println("Positive");
    }
  }
}

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

//---------------------------

int main(){
    ll k,n;
    cin >> k >> n;
    VL a(n);
    rep(i,n) cin >> a[i];

    VL diff(n);
    rep(i,n-1){
        diff[i] = a[i+1] - a[i];
    }
    diff[n-1] = k + a[0] - a[n-1];

    sort(diff.begin(), diff.end(), greater<ll>());
    cout << k - diff[0] << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct __scanner__{ bool e; operator bool(){ return e; } } IN = { false };
inline __scanner__& operator>>(__scanner__& in,int &n)
{ in.e = scanf("%d",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,ll &n)
{ in.e = scanf("%lld",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,double &n)
{ in.e = scanf("%lf",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,char &n)
{ in.e = scanf(" %c",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,string &n) // BUFFER SIZE!
{ static char buf[1000000]; in.e = scanf(" %s",buf)==1; n = buf; return in; } 

int main() {
  int h, w, d;
  while (cin >> h >> w >> d) {
    const string C[2] = { "RG", "BY" };
    REP(i,h) {
      REP(j,w) {
	int x = i + j, y = i - j + w;
	putchar(C[(y / d) % 2][(x / d) % 2]);
	// printf(" %c %d %d\n", C[(y / d) % 2][(x / d) % 2], (y / d) % 2, (x / d) % 2);
      }
      puts("");
    }
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define res register int
#define N 2005
using namespace std;

inline int read()
{
	char ch=getchar();
	int x=0,f=0;
	while(ch<'0'||ch>'9')
	{
		f|=ch=='-';
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f?-x:x;
}
struct eric
{
	int to,next;
}edge[2*N];
int head[N],size=1;
int n,m,deep[2005],sum,ans=1000000007;
inline void add(int x,int y)
{
	edge[++size].to=y;
	edge[size].next=head[x];
	head[x]=size;
}
inline void dfs(int pos,int fa)
{
	deep[pos]=deep[fa]+1;
	if(deep[pos]>(m)/2)
	sum++;
	for(int i=head[pos];i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==fa)
		continue;
		dfs(v,pos);
	}
}
int main()
{
	n=read(),m=read();
	deep[0]=-1;
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	if(m&1)
	{
		for(int i=2;i<=2*(n-1);i+=2)
		{
			sum=0;
			deep[edge[i^1].to]=-1;
			dfs(edge[i].to,edge[i^1].to);
			deep[edge[i].to]=-1;
			dfs(edge[i^1].to,edge[i].to);
			ans=min(ans,sum);
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			sum=0;
			dfs(i,0);
			ans=min(ans,sum);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a,b;
	cin>>a>>b;
	if(a<b){
	  bool h=false;
	  loop(i,a,b+1){
	    if(h)cout<<" ";
		h=true;
		cout<<i;
      }
	}else if(a<=5){
	  bool h=false;
	  for(int i=a;i>b-1;i--){
	    if(h)cout<<" ";
		h=true;
		cout<<i;
	  }
	}else if(b<=5){
	  bool h=false;
	  loop(i,a,10){
	    if(h)cout<<" ";
		h=true;
		cout<<i;
      }
	  for(int i=5;i>b-1;i--)cout<<" "<<i;
	}else{
	  bool h=false;
	  loop(i,a,10){
	    if(h)cout<<" ";
		h=true;
		cout<<i;
      }
	  for(int i=5;i>0;i--)cout<<" "<<i;
	  rep(i,b+1)cout<<" "<<i;
	}
	cout<<endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
using namespace std;
#define INF (1 << 20)
int main()
{
    int n;
    cin >> n;
    int p[101];

    // i番目の行列は p[i]*p[i+1]
    for (int i = 0; i < n; i++)
    {
        cin >> p[i] >> p[i + 1];
    }

    // m[i][j] : i番目からj番目までの部分積でのスカラー乗算の最小回数
    //      i = 0,1, ... , n-1
    // m[i][i] := 0
    // m[i][j] = min_{i <= k < j} m[i][k] + m[k+1][j] + p[i]*p[k+1]*p[j+1]
    //      l = 2,3, ... , n
    //      i = 0,1, ... , n-l
    //          j = i+l-1
    //      k = i, i+1, ... , j-1
    // l = j-i
    int m[101][101];
    for (int i = 0; i < n; i++)
    {
        m[i][i] = 0;
    }

    for (int l = 2; l <= n; l++)
    {
        for (int i = 0; i <= n-l; i++)
        {
            int j = i + l - 1;
            int minv=INF;
            for (int k = i; k < j; k++)
            {
                minv = min(minv, m[i][k] + m[k + 1][j] + p[i] * p[k + 1] * p[j + 1]);
            }
            m[i][j] = minv;
            
            // cout << "m[ " << i<<" ][ "<<j<< " ] = " << minv << endl;
        }
    }
    cout << m[0][n-1] << endl;
    return 0;
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  for (int n, m; cin >> n >> m, n || m;) {
    vector<pair<int, pair<int, int>>> ps;
    rep (i, m) {
      int t, s, d; cin >> t >> s >> d;
      --s; --d;
      ps.push_back(cons( t, cons(s, d)));
    }
    sort(all(ps));

    vector<bool> is(n, false);
    is[0] = true;
    for (auto&p : ps) {
      if (is[cadr(p)]) is[cddr(p)] = true;
    }
    int cx = 0;
    rep (i, n) { if (is[i]) ++cx; }
    cout << cx << endl;
  }

  return 0;
}

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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)

int mod=1e9+7;

int main(){
    faster;

    ll n,m;
    cin>>n>>m;

    ll wa=0,ac=0;
    map<ll,ll> mp;
    map<ll,ll> pm;

    for(int i=0;i<m;i++){
        ll x;string s;
        cin>>x>>s;

        if(mp.find(x)==mp.end()){
            mp[x]=0;
            pm[x]=0;
        }

        if(s[0]=='A'){
            if(mp[x]!=2) {ac++; wa+=pm[x];}
            mp[x]=2;
        }
        else{
            if(mp[x]!=2) pm[x]++;
            else continue;
        }
    }

    cout<<ac<<" "<<wa<<endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int mod = 10007;
typedef pair<int,int> PII;
LL N,K;
LL V[11][2020];
LL Q[11][2020],T[11][2020];
LL mem[2020][11];
LL temp;

LL cal(int n,int kind){
    LL res=0;
    if(mem[n][kind]!=INF){
        return mem[n][kind];
    }
    if(n==K||kind>temp) return 0;
    REP(i,K-n){
        if(n+i<=K){
            res=max(cal(n+i+1,kind+1)+Q[kind][i],max(cal(n,kind+1),res));
        }
    }
    return mem[n][kind]=res;
}

signed main(){
    REP(i,2001)REP(j,11)mem[i][j]=INF;
    cin>>N>>K;
    REP(i,N){
        LL C,G;
        cin>>C>>G;
        V[G][i]=C;
        temp=max(temp,G);
    }
    FOR(i,1,temp){
        sort(V[i],V[i]+N,greater<LL>());
        REP(j,K){
            if(!V[i][j])break;
            T[i][j]=j*(j+1);
            Q[i][j]=Q[i][j-1]+V[i][j]+T[i][j]-T[i][j-1];
        }
    }
    cout<<cal(0,1)<<endl;
}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

ull N, i, m, a, r, c, h;

int main(){
    char si[11];
    scanf("%d", &N);
    for (i=0; i<N; i++) {
        scanf("%s", si);
        if (si[0] == 'M') m++;
        else if (si[0] == 'A') a++;
        else if (si[0] == 'R') r++;
        else if (si[0] == 'C') c++;
        else if (si[0] == 'H') h++;
    }

    cout << m * (a * (r + c + h) + r * (c + h) + c * h) 
        + a * (r * (c + h) + c * h)
        + r * c * h << endl;

    return 0;
}


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

ll dp[103][2][4];

int main(){
	string n;
	cin >> n;
	int k;
	cin >> k;
	
	int l = n.size();
	
	dp[0][0][0] = 1;
	
	for (int i = 0; i < l; ++i) {
		int D = n[i] - '0';
		for (int smaller = 0; smaller < 2 ; ++smaller) {
			for (int j = 0; j <= k ; ++j) {
				for (int x = 0; x <= (smaller ? 9 : D) ; ++x) {
					int nj = j;
					if(x != 0) nj++;
					if(nj > k) continue;
					dp[i+1][smaller || (x < D)][nj] += dp[i][smaller][j];
				}
			}
		}
	}
	
	cout << dp[l][1][k] + dp[l][0][k] << endl;
	
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));

    for (ll len = 1; len <= N; len++) {
        for (ll i = 0; i + len <= N; i++) {
            ll j = i + len;
            if ((N - len) % 2 == 0) {
                dp[i][j] = max(dp[i + 1][j] + A[i], dp[i][j - 1] + A[j - 1]);
            } else {
                dp[i][j] = min(dp[i + 1][j] - A[i], dp[i][j - 1] - A[j - 1]);
            }
        }
    }
    cout << dp[0][N] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 73668
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
#define TIME ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
    const ll N = 1e5 + 7;///
int n , m , k;
int a[N] , b[N];
int x , y , c;
int mn = 2e9;
int main(){
    TIME
    cin >> n >> m >> k;
    for(int i = 1; i <= n ; i ++)
        cin >> a[i];
    for(int i = 1; i <= m ;i  ++)
        cin >> b[i];
    for(int i =1 ; i <= k ;i ++){
        cin >> x >> y >> c;
        mn = min(mn , a[x] + b[y] - c);
    }
    cout << min(mn , *min_element(a + 1, a + n + 1) + *min_element(b + 1, b + m + 1));
}
///...


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

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>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    string S;
    cin >> S;
    bool flag = true;

    for(int i = 0; i < S.length(); i += 2){
        if(S[i] == 'R' || S[i] == 'U' || S[i] == 'D'){
        } else {
            flag = false;
        }
    }
    for(int i = 1; i < S.length(); i += 2){
        if(S[i] == 'L' || S[i] == 'U' || S[i] == 'D'){
        } else {
            flag = false;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

template <typename T>
void say(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}


/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2.f << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>H(N);
    for(int i = 0; i < N ; i++ ){
      cin >> H.at(i);
    }
    vector<int>c(N);
  int i=0;
  while( i < N-1 ){
    for(int j = 0; j < N-i-1 ; j++ ){
      if(H.at(i+j)>=H.at(i+j+1)){
        c.at(i)++;
      }
      else{
        break;}
    }
    i=i+c.at(i)+1;
  }
  sort(c.begin(),c.end());
  cout << c.at(N-1);
}  

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>


using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 100

int main(){
    int a[3],ans1=0,ans2=0,ans3=0;
    
    while(1){
        scanf("%d%d%d",&a[0],&a[1],&a[2]);
        
        sort(a,a+3);
        
        if(a[0]+a[1] <= a[2]){
            printf("%d %d %d %d\n",ans1+ans2+ans3,ans1,ans2,ans3);
            return 0;
        }
        
        if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
            ans1++;
        
        }else if(a[0]*a[0]+a[1]*a[1] > a[2]*a[2]){
            ans2++;
        
        }else if(a[0]*a[0]+a[1]*a[1] < a[2]*a[2]){
            ans3++;
        }
        
        
    }
    
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string A,B,C; cin>>A>>B>>C;
  string ans="A";
  ans+=B[0];
  ans+='C';
  cout<<ans<<endl;
  }


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

int main() {
	int a, b, c, k; cin >> a >> b >> c >> k;
	int sum = a + b + c - max({ a,b,c });

	sum = sum + max({ a,b,c }) * pow(2, k);

	cout << sum << endl;

	return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N); cin >> A;
        auto B = A;
        sort(all(B));

        int m = N / 2;
        debug(B);
        rep(i, N) {
            cout << (A[i] <= B[m - 1] ? B[m] : B[m - 1]) << endl;
        }

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 3840
#include <cstdio>
#include <algorithm>

using namespace std;

int m[50];
int f[50];
int r[50];

int main(){
	
	int i=0;
	while(1){
		scanf("%d%d%d", &m[i], &f[i], &r[i]);
		if(m[i] == -1 && f[i] == -1 && r[i] == -1){
			break;
		}
		i++;
	}
	
	for(int j=0; j<i; ++j){
		if(m[j]== -1 || f[j]== -1){
			printf("F\n");
		}else if(m[j]+f[j] >= 80){
			printf("A\n");
		}else if(m[j]+f[j]>= 65 ){
			printf("B\n");
		}else if(m[j]+f[j]>=50){
			printf("C\n");
		}else if(m[j]+f[j]>=30 && r[j]>=50){
			printf("C\n");
		}else if(m[j]+f[j]>=30){
			printf("D\n");
		}
		else{
			printf("F\n");
		}		
	}	

}




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

int main() {
 
  string S;
  cin >> S;
  
  int n = S.size();
  
  if(S.at(n-1) == 's'){
    cout << S << "es" << endl;
  }
  
  else{
    cout << S << 's' << endl;
  }
  
  
}


Measured memory_bytes: 3564
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a=0,b=0,ab=0,o=0;
  int x;
  char z;
  string y;
  while(cin>>x>>z>>y){
    if(y=="A")a++;
    else if(y=="B")b++;
    else if(y=="AB")ab++;
    else o++;
  }
  cout<<a<<endl;
  cout<<b<<endl;
  cout<<ab<<endl;
  cout<<o<<endl;
 return 0;
}

Measured memory_bytes: 2992
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 5100;
const int MOD = 1000000007;

int d[MAX][MAX];
int V;

void warshall_floyd() {
    for(int k = 0; k < V; k++) {
        for(int i = 0; i < V; i++) {
            for(int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}


int main(){
  cin>>V;
  int M; cin>>M;
  int R; cin>>R;
  vector<int> r(R);
  rep(i,R){
    cin>>r[i]; r[i]--;
  }

  rep(i,V){
    rep(j,V){
      if(i==j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }
  rep(i,M){
    int from, to, cost;
    cin>>from>>to>>cost;
    from--;to--;
    d[from][to] = cost;
    d[to][from] = cost;
   }
  warshall_floyd();

  vector<int> v(R);
  rep(i,R) v[i] = i;

  int ans = INF;
  while(next_permutation(v.begin(),v.end())){
    int tmp = 0;
    rep(i,R-1){
      tmp += d[r[v[i]]][r[v[i+1]]];
    }
    ans = min(ans,tmp);
  }
  cout<<ans<<endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[b].push_back(a);
    G[a].push_back(b);
  }
  int A=0;
  queue<int> q;
  q.push(A);
  vector<int> seen(N);
  seen[A]=1;
  while(!q.empty()){
    A=q.front();
    q.pop();
    for(int x:G[A]){
      if(!(seen[x])){
        q.push(x);
        seen[x]=1;
      }
    }
  }
  q.push(A);
  vector<int> sen(N);
  sen[A]=2;
  while(!q.empty()){
    A=q.front();
    q.pop();
    for(int x:G[A]){
      if(!(sen[x])){
        q.push(x);
        sen[x]=sen[A]+1;
      }
    }
  }
  int Z=sen[A];
  if(Z%3){
    cout<<"First"<<endl;
  }
  else{
    cout<<"Second"<<endl;
  }
}

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

int dp[101][4][4][4];
int mod = 1000000007;

int main() {
    int N; cin >> N;
    dp[0][3][3][3] = 1;
    for (int len = 0; len < N; len++){
        for (int c3 = 0; c3 < 4; c3++){
            for (int c2 = 0; c2 < 4; c2++){
                for (int c1 = 0; c1 < 4; c1++){
                    if(dp[len][c3][c2][c1] == 0)continue;
                    for (int c0 = 0; c0 < 4; c0++){
                        if(c2 == 0 && c1 == 1 && c0 == 2)continue;
                        if(c3 == 0 && c1 == 1 && c0 == 2)continue;
                        if(c2 == 1 && c1 == 0 && c0 == 2)continue;
                        if(c2 == 0 && c1 == 2 && c0 == 1)continue;
                        if(c3 == 0 && c2 == 1 && c0 == 2)continue;

                        dp[len+1][c2][c1][c0] += dp[len][c3][c2][c1];
                        dp[len+1][c2][c1][c0] %= mod;
                    }
                }    
            }
        }        
    }

    int ans = 0;
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++){
            for (int k = 0; k < 4; k++){
                ans += dp[N][i][j][k];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    ll ans=0;
    string s,t;
    cin>>s>>t;
    rep(i,3){
        if(s[i]==t[i])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define iso ios::sync_with_stdio(false); cin.tie(0);3
int main()
{  iso;
 string s;
 cin>>s; 
   long long  int count=0,w=0;
   for(int i=0;i<s.length();i++)
   {    
      if(s[i]=='W') w++;   
    }
			long long int in=0;    
	for(int i=0;i<s.length();i++)
			 {
		 	  if(s[i]=='W')
		   count+=i-in,in++,w--;
			 if(w==0)
		     break;
//					 cout<<count<<"  ";  
			 	
				 }    
   cout<<count;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define EPS 1e-10
using namespace std;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point
{
  public:
  double x,y;
  Point(double x = -1,double y = -1): x(x),y(y){}

  Point operator + (Point p ){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}//※イケメンに限る

  bool operator < (const Point& p) const
  {
    return x != p.x?x<p.x:y<p.y;
  }

  bool operator == (const Point& p)const
  {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

struct Segment
{
  Point p1,p2;
  Segment(Point p1 = Point(-1,-1),Point p2 = Point(-1,-1)):p1(p1),p2(p2){}
};
typedef Segment Line;
typedef vector<Point> Polygon;

double dot(Point a,Point b)
{
  return a.x*b.x + a.y*b.y;
}
double cross(Point a,Point b)
{
  return a.x*b.y - a.y*b.x;
}

double norm(Point a)
{
  return a.x*a.x+a.y*a.y;
}



int ccw(Point p0,Point p1,Point p2)
{
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > 0)return COUNTER_CLOCKWISE;
  if(cross(a,b) < 0)return CLOCKWISE;
  if(dot(a,b) < 0)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}


bool isIntersect(Point p1,Point p2,Point p3,Point p4)
{
  return (ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 &&
          ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0 );
}

bool isIntersect(Segment s1,Segment s2)
{
return isIntersect(s1.p1,s1.p2,s2.p1,s2.p2);
}


int main()
{
  int N;
  cin >> N;
  while(N-- > 0)
    {
      vector<Point> T(3);
      for(int i=0;i<3;i++)
	  cin >> T[i].x >> T[i].y;
      Segment s;
      cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
      int cnt = 0;
      if(isIntersect(Segment(T[0],T[1]),s))cnt++;
      if(isIntersect(Segment(T[1],T[2]),s))cnt++;
      if(isIntersect(Segment(T[2],T[0]),s))cnt++;
      if(cnt == 1)
	cout << "OK" << endl;
      else
	cout << "NG" << endl;

    }

  return 0;
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x) cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x) cout << ((x) ? "YES" : "NO") << endl

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;

	ll ret = 0x7FFFFFFFFFFFFFFF;
	rep(i, n) {
		ll a;
		cin >> a;

		ll tmp = 0;
		while(a % 2 == 0) {
			++tmp;
			a /= 2;
		}
		if(tmp < ret) ret = tmp;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
class Lazysegtree:
    #RAQ
    def __init__(self, A, intv, initialize = True, segf = min):
        #区間は 1-indexed で管理
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        self.segf = segf
        self.lazy = [0]*(2*self.N0)
        if initialize:
            self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
            for i in range(self.N0-1, 0, -1):
                self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
        else:
            self.data = [intv]*(2*self.N0)

    def _ascend(self, k):
        k = k >> 1
        c = k.bit_length()
        for j in range(c):
            idx = k >> j
            self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
            + self.lazy[idx]
            
    def _descend(self, k):
        k = k >> 1
        idx = 1
        c = k.bit_length()
        for j in range(1, c+1):
            idx = k >> (c - j)
            ax = self.lazy[idx]
            if not ax:
                continue
            self.lazy[idx] = 0
            self.data[2*idx] += ax
            self.data[2*idx+1] += ax
            self.lazy[2*idx] += ax
            self.lazy[2*idx+1] += ax
    
    def query(self, l, r):
        L = l+self.N0
        R = r+self.N0
        Li = L//(L & -L)
        Ri = R//(R & -R)
        self._descend(Li)
        self._descend(Ri - 1)
        
        s = self.intv                                                              
        while L < R:
            if R & 1:
                R -= 1
                s = self.segf(s, self.data[R])
            if L & 1:
                s = self.segf(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s
    
    def update(self, l, r, x):
        L = l+self.N0
        R = r+self.N0

        Li = L//(L & -L)
        Ri = R//(R & -R)
        
        while L < R :
            if R & 1:
                R -= 1
                self.data[R] += x
                self.lazy[R] += x
            if L & 1:
                self.data[L] += x
                self.lazy[L] += x
                L += 1
            L >>= 1
            R >>= 1
        
        self._ascend(Li)
        self._ascend(Ri-1)

N, Q = map(int, input().split())
T = Lazysegtree([0]*N, 2<<31) 
Ans = []
for jq in range(Q):
    t, *q = map(int, sys.stdin.readline().split())
    q[1] += 1
    if t:
        Ans.append(T.query(*q))
    else:
        T.update(*q)
print('\n'.join(map(str, Ans)))



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

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;



void solve() {
    int n, k; cin >> n >> k;
    ar<int,2> arr[n];
    for (int i = 0; i < k; i++) cin >> arr[i][0] >> arr[i][1];
    vector<int> dp(n);
    dp[0] = 1, dp[1] = -1;
    for (int i = 0; i < n; i++) {
        if (i > 0) dp[i] = (dp[i] + dp[i - 1]) % MOD;
        for (int j = 0; j < k; j++) {
            auto [l, r] = arr[j];
            if (i + l < n) dp[i + l] = (dp[i + l] + dp[i]) % MOD;
            if (i + r  + 1 < n) dp[i + r + 1] = (dp[i + r + 1] - dp[i] + MOD) % MOD;
        }
    }
    cout << dp[n - 1] << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; tc = 1;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

Measured memory_bytes: 3988
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int n, M[N][N];
int color[N], d[N], f[N], tt;
 
void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for (v = 0; v < n; v++) {
        if (M[u][v] == 0)continue;
        if (color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}
 
void dfs() {
    int u;
    for (u = 0; u < n; u++)color[u] = WHITE;
    tt = 0;
 
    for (u = 0; u < n; u++) {
        if (color[u] == WHITE)dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
}
 
int main() {
    int u, v, k, i, j;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++)M[i][j] = 0;
    }
 
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
 
    dfs();
 
    return 0;
}


Measured memory_bytes: 2060
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int,int);

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  q=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");
  return 0;
}

int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

Measured memory_bytes: 988
N = int(input())
A = list(map(int,input().split()))
cur = 0
cnt = 0
while cur<N:
    cnt += 1
    c = 0
    cur1 = cur+1
    for i in range(cur+1,N):
        if A[i]>=A[i-1]:
            cur1 = i+1
        else:
            cur1 = i
            break
    cur2 = cur+1
    for i in range(cur+1,N):
        if A[i]<=A[i-1]:
            cur2 = i+1
        else:
            cur2 = i
            break
    cur = max(cur1,cur2)
print(cnt)

Measured memory_bytes: 62704
def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in [0]*n]

    # 中心(x1,y1)・半径r1の円と中心(x2,y2)・半径r2の円の交点を出力する関数
    def circle_cross(x1, y1, r1, x2, y2, r2):
        dist_2 = (x1-x2)**2+(y1-y2)**2
        if dist_2 > (r1+r2)**2:
            return None, None, None, None
        a = (dist_2+r1**2-r2**2)/2
        r = (dist_2*(r1**2)-a**2)**0.5
        ans_x1 = ((a*(x1-x2))+(y1-y2)*r)/dist_2
        ans_x2 = ((a*(x1-x2))-(y1-y2)*r)/dist_2
        ans_y1 = ((a*(y1-y2))-(x1-x2)*r)/dist_2
        ans_y2 = ((a*(y1-y2))+(x1-x2)*r)/dist_2
        return ans_x1+x2, ans_y1+y2, ans_x2+x2, ans_y2+y2

    def check(r):
        flag = 0
        point_list = []
        for i in range(n):
            x1, y1 = xy[i]
            for j in range(i+1, n):
                x2, y2 = xy[j]
                if (x1-x2)**2+(y1-y2)**2 <= 4*(r**2)-10**-9:
                    temp = circle_cross(x1, y1, r, x2, y2, r)
                    point_list.append((temp[0], temp[1]))
                    point_list.append((temp[2], temp[3]))
        for i, j in point_list:
            for x, y in xy:
                if (i-x)**2+(j-y)**2 > r**2+10**-9:
                    break
            else:
                return True
        return False

    def b_search(a, b, value, delta):
        while True:
            med = (a+b)/2
            if abs(b-a) < delta:
                if value(a):
                    return a
                else:
                    return b
            elif value(med):
                b = med
            else:
                a = med

    print(b_search(0, 3000, check, 10**-7))


main()


Measured memory_bytes: 3316