akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <list>
using namespace std;

void depthset(int node, list<int>* l, int* depth, int current_depth)
{
    depth[node] = current_depth;
    if (l[node].size() == 0) return;
    current_depth++;
    for (list<int>::iterator it = l[node].begin(); it != l[node].end(); it++)
    {
        depthset(*it, l, depth, current_depth);
    }
}

int main(void)
{
    int n;
    cin >> n;
    int parent[n], depth[n];
    memset(parent, -1, sizeof(parent));
    list<int> l[n];
    for (int i = 0; i < n; i++)
    {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++)
        {
            int t;
            cin >> t;
            l[id].push_back(t);
            parent[t] = id;
        }
    }
    int rootid = 0;
    for (int i = 0; i < n; i++)
    {
        if (parent[i] == -1) rootid = i;
    }
    depthset(rootid, l, depth, 0);
    for (int i = 0; i < n; i++)
    {
        printf("node %d: parent = %d, depth = %d, ", i, parent[i], depth[i]);
        if (parent[i] == -1)
        {
            printf("root, ");
        }
        else if (l[i].size() == 0)
        {
            printf("leaf, ");
        }
        else
        {
            printf("internal node, ");
        }
        printf("[");
        list<int>::iterator endit = l[i].end();
        endit--;
        for (list<int>::iterator it = l[i].begin(); it != l[i].end(); it++)
        {
            if (endit != it)
            {
                printf("%d, ", *it);
            }
            else
            {
                printf("%d", *it);
            }
        }
        printf("]\n");
    }
    return 0;
}


Measured memory_bytes: 8612
use whiteread::parse_line;

fn main() {
    let s: String = parse_line().unwrap();
    let mut s: Vec<u8> = s.into_bytes();
    let t: String = parse_line().unwrap();
    let mut t: Vec<u8> = t.into_bytes();

    s.sort();
    t.sort();
    t.reverse();
    if s.iter().lt(t.iter()) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    string S; cin >> S;
    while (S.size() <= 14) S.push_back('o');
    int c = count(begin(S), end(S), 'o');
    cout << (c >= 8 ? "YES" : "NO") << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    static constexpr ll INF = 1LL << 60;
    struct VertexQ {
        bool operator<(const VertexQ &o) const {
            return c > o.c; // 逆
        }
        int i;
        ll c;
    };
    struct Vertex { int n; ll c; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, INF }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    void dijkstra(int i, int j) {
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.i == j) break;
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                ll c = p.c + o.c;
                if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, n - 2 + m);
    for (int i = 0; i < n - 2; i++) {
        g.add_edge(i + 1, i, 0);
    }
    for (int j = 0; j < m; j++) {
        int l, r, c;
        cin >> l >> r >> c;
        l--; r--;

        g.add_edge(l, r, c);
    }

    g.dijkstra(0, n - 1);

    ll r = g.v[n - 1].c;
    cout << (r == g.INF ? -1 : r) << endl;

    return 0;
}

Measured memory_bytes: 5112
#include <iostream>

using int64 = long long;

int main()
{    
    int64 n, d;
    std::cin >> n >> d; n--;
    
    int64 N = n - d + 1;
    std::cout << (d == 1 ? n * (n + 1) / 2 : d + (N + 3) * N / 2 - 2) << std::endl;
    return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
	Scanner sc = new Scanner(System.in);
// 最初の文字の固まりを整数値と想定して読み込む while (true) {
	int N = sc.nextInt();
	int i;
	int A[];
	int flag = 1;
	int j=0;
	int save;
	A = new int[N];
for(i=0; i<N; i++){
	A[i] = sc.nextInt();
}

while(flag==1){
	flag=0;
	for(i=1; i<N; i++){
		if(A[i-1]>A[i]){
			save = A[i-1];
			A[i-1] = A[i];
			A[i] = save;
			j=j+1;
			flag=1;
		}
	}
}
for(i=0; i<N-1; i++)
System.out.print(A[i]+" ");
System.out.println(A[N-1]);
System.out.println(j);
}
}


Measured memory_bytes: 26504
import os, sys, re, math

N = int(input())
root = []
for _ in range(N):
    x,y = map(int,input().split(' '))
    root.append((x,y))

s = 0
for i in range(N):
    for j in range(N):
        if i != j:
            tmp = (root[i][0] - root[j][0]) ** 2 + (root[i][1] - root[j][1]) ** 2
            s += math.sqrt(tmp)

ret = s / N
print(ret)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    int N;
    cin >> N;

    bool flg = false;
    for (int i = 1; i <= 9; i++) {
        if (N % i == 0 && N / i <= 9) {
            flg = true;
            break;
        }
    }

    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

int check(string s, string t){
	for(int i = 0; i < s.length(); i++){
		if(s[i] == t[i] || s[i] == '?') continue;
		return 0;
	}
	return 1;
}

int main(){
	string s, t; cin >> s >> t;
	reverse(begin(s), end(s));
	reverse(begin(t), end(t));
	bool f = 0;
	for(int i = 0; i < s.length() - t.length() + 1; i++){
		if(!check(s.substr(i, t.length()), t)) continue;
		f = 1;
		s.replace(i, t.length(), t);
		for(int j = 0; j < s.length(); j++){
			if(s[j] == '?') s[j] = 'a';
		}
		reverse(begin(s), end(s));
		break;
	}
	if(!f) puts("UNRESTORABLE");
	else cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define    mod      1000000007
#define    speed    ios_base::sync_with_stdio(false);
#define    up       cin.tie(NULL);
#define    pb       push_back
#define    mp       make_pair
#define    T        int t; cin >> t; while(t--)

int main(){
    speed up
    int n , k; cin >> n >> k;
    ll arr[n+5] , dp[n+5];
    dp[0] = dp[1] = 0;
    arr[0] = 100000;
    for(int i = 1; i <= n; ++i){
        cin >> arr[i];
    }
    for(int i = 2; i <= n; i++){
        dp[i] = 10000000000;
        for(int j = i-1; j >= max(1 , i-k); j--){
            dp[i] = min(dp[i] , dp[j] + abs(arr[i]-arr[j]));
        }
    }
    cout << dp[n] << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll n, m, d[N];
V<int> v[N];
bool z;
void dfs(int a, int k){
  d[a] = k;
  for(int b:v[a]){
    if(d[b] < 0){
      dfs(b, k+1);
    }else if((k-d[b])%2==0){
      z = true;
    }
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Fill(d, -1);
  cin >> n >> m;
  FOR(i, 0, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    v[a].pb(b);
    v[b].pb(a);
  }
  ll o = n, c1 = 0, c2 = 0;
  FOR(i, 0, n){
    if(d[i] >= 0) continue;
    if(v[i].empty()){
      o--;
      continue;
    }
    z = false;
    dfs(i, 0);
    if(z){
      c1++;
    }else{
      c2++;
    }
  }
  cout << n*n-o*o + c1*c1+(c1+c2)*c2*2 << endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MD=int(1e9)+7;
int const MAXN=220000;
int f[MAXN];
int fi[MAXN];
int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}
int mpow(int x,int p) {
	int res=1;
	while (p>0) {
		if (p%2) res=mmul(res,x);
		x=mmul(x,x);
		p/=2;
	}
	return res;
}
int mcomb(int n,int k) {
	return mmul(f[n],mmul(fi[k],fi[n-k]));
}


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);
	
	f[0]=fi[0]=1;
	rep(i,1,MAXN) {
		f[i]=mmul(f[i-1],i);
		fi[i]=mpow(f[i],MD-2);
	}

	int N,M,K;
	cin>>N>>M>>K;
	
	int res=0;
	rep(d,1,N) res=madd(res,mmul(mmul(d,N-d),mmul(M,M)));
	rep(d,1,M) res=madd(res,mmul(mmul(d,M-d),mmul(N,N)));
	res=mmul(res,mcomb(N*M-2,K-2));
	
	cout<<res<<"\n";
}


Measured memory_bytes: 1920
c = [0, 3, 5, 7]


N = input()
l = len(N)
N = int(N)


def parse_to_tri(x):
    ret = 0
    d = 1
    for i in range(l):
        ret += c[x % 4]*d
        d *= 10
        x //= 4
    return ret


ans = 0


for i in range(4**l):
    x = parse_to_tri(i)
    s = str(x)
    if '3' not in s or '5' not in s or '7' not in s:
        continue
    if '0' in s:
        continue
    if x <= N:
        ans += 1
print(ans)


Measured memory_bytes: 73960
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int>
#define di             deque<int>
#define vpii           vector<pair<int,int>>
#define pi             pair<int,int>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define all(a)         a.begin(),a.end()
#define rall(a)        a.rbegin(),a.rend()
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x:a) cin>>x
#define endl           '\n'
#define ln             printf("\n");
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int n,k,s=0;cin>>n>>k;
    int a[n];read(a);
    sort(a,a+n,greater<>());
    for(int i=0;i<k;++i) s+=a[i];
    cout<<s;
}


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

class UnionFind {
private:
  vector<int> par;
public:
  UnionFind(int N) {
    par.resize(N);
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) { return (x == par[x])? x: (par[x] = root(par[x])); }
  void unite(int x, int y) { par[root(y)] = root(x); }
  bool same(int x, int y) { return (root(x) == root(y)); }
};

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

  int N, Q;
  cin >> N >> Q;
  UnionFind UF(N);

  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    UF.unite(x, y);
  }

  vector<ll> cnt(N);
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll r = UF.root(i);
    cnt[r]++;
    ans = max(ans, cnt[r]);
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5828
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let S = input[0][0];
    let K = input[1][0];
    K = BigInt(K);
    let ans;
    if (S[0] !== '1') ans = S[0];
    else {
        let flag;
        let tmpLength = 0n;
        ans = 1;
        for (let i = 0; i < S.length; i++){
            flag = false;
            if (S[i] !== '1') {
                ans = S[i];
                break;
            }
            tmpLength = tmpLength + 1n;
            flag = true;
        }

        if (!flag){
            if (K <= tmpLength) ans = 1;
        }
    }

    console.log(ans);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30552
str_list = list(input().split(","))
new_list=[]
for i in range(len(str_list)):
    f=[]
    for j in str_list[i]:
        if j.islower()==True:
            f.append(j.upper())
        elif j.isupper()==True:
            f.append(j.lower())
        else:
            f.append(j)
    new_list.append("".join(f))
for i in range(len(new_list)):
    if i==len(new_list)-1:
        print("{}".format(new_list[i]))
    else:
        print("{},".format(new_list[i]),end="")


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define mod 1000000007
#define abdo(); std::ios_base::sync_with_stdio(0);cin.tie(NULL);
#define lowcase(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define uppcase(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define M 80
#define LENGTH 12
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
typedef vector<int> vi;
const double PI = acos(-1.0);
int dir_r[] = {1       , 0    , -1, 0   , -1     , 1         , -1      , 1        };
int dir_c[] = {0       , 1    , 0 , -1  , -1     , 1         , 1       , -1       };



int main(void)
{
    //freopen("colors.in", "r", stdin) ;
    //freopen("auxiliary.out", "w", stdout);
    int s, sum = 0, ma = 0;
    cin >> s;
    for(int i = 0; i < s; i++)
    {
    	int n; cin >> n;
    	ma = max(ma, n);
    	sum += n;
    }
    cout << sum - ma / 2;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
#define MP make_pair
int main(){
    int n,m,c;
    while(cin >> n >>m >> c&&n!=0){
        vector<vector<int> > dp(n,vector<int>(m+1,2000000000));
        vector<vector<pair<int,int> > >g(n);
        for(int i=0;i<m;i++){
            int a,b,w;
            cin >> a >> b >> w;
            a--,b--;
            g[a].push_back(make_pair(b,w));
        }
        priority_queue<pair<int,pair<int,int> >, vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > pq;
        dp[0][0] = 0;
        pq.push(MP(0,MP(0,0)));
        while(!pq.empty()){
            auto x = pq.top();
            pq.pop();
            for(auto s : g[x.second.second]){
                if(dp[s.first][x.second.first]>s.second + x.first){
                    dp[s.first][x.second.first] = s.second + x.first;
                    pq.push(MP(s.second+x.first,MP(x.second.first,s.first)));
                }
                if(x.second.first+1>m)break;
                if(dp[s.first][x.second.first+1]> x.first){
                    dp[s.first][x.second.first+1] = x.first;
                    pq.push(MP(x.first,MP(x.second.first+1,s.first)));
                }
            }
        }
        for(int i=0;i<=m;i++){
            if(dp[n-1][i]<=c){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <set>
using namespace std;
typedef long long int lli;

int main()
{
    int N;
    cin >> N;
    set<string> S;
    for (int i = 0; i < N; i++)
    {
        string sn;
        cin >> sn;
        S.insert(sn);
    }
    cout << S.size() << endl;
    return 0;
}

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


int main() {
	int n; cin >> n;
	vector<int> a(n); rep(i, 0, n) cin >> a[i];

	vector<pair<int, bool>> vec(n);
	rep(i, 0, n) {
		vec[i].first = a[i];
		vec[i].second = true;
	}

	int ans = 1, i = 1;
	while (vec[i - 1].second) {
		// 光っているボタンが2ならansを出力
		if (vec[i - 1].first == 2) {
			cout << ans << endl;
			return 0;
		}
		vec[i - 1].second = false; //光っているボタンを押す
		ans++;
		i = vec[i - 1].first; // 次に光るボタン
	}
	// 押したことのあるボタンが光ると-1を出力
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n, W;
int w[101], v[101];
ll dp[101][N];
ll f(int i, int cost){
    if(cost < 0)
        return -1e18;
    if(i == n)
        return 0;
    ll &ans = dp[i][cost];
    if(ans == -1){
        ans = max(f(i + 1, cost), f(i + 1, cost - w[i]) + v[i]);
    }return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n >> W;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    for(int i = n; i >= 0; i--){
        for(int cost = W; cost >= 0; cost--){
            ll &ans = dp[i][cost];    
            if(i == n){
                ans = 0;
                continue;
            }
            ans = max(ans, dp[i + 1][cost]);
            if(cost - w[i] >= 0)
                ans = max(ans, dp[i + 1][cost - w[i]] + v[i]);
        }
    }
    cout << dp[0][W] << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 82624
#include <bits/stdc++.h> /*7B*/
using namespace std; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){

int n, x;

while(1){
cin >> n >> x;

if (n == 0 && x == 0) break;

int count = 0;

for(int i = 1; i < n+1; ++i){
    for(int j = 1; j < n+1; ++j ){
        for(int k = 1; k < n+1; ++k){
            if (!( i == j || j == k || i == k)){
                if(i + j + k == x ) count++;
            }
        }
    }
}
cout << count / 6 << endl;
}
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N, Q;
    string S;
    string ac = "AC";
    cin >> N >> Q >> S;
    vector<int> vp(N,0);
    for (int i = 1; i < N;i++){
        vp[i] = vp[i - 1];
        if(S[i-1] == 'A' && S[i] == 'C')
            vp[i]++;
    }

        vector<int> right(0);
    vector<int> left(0);
    for (int i = 0; i < Q;i++){
        int r,l;
        cin >> l >> r;
        l--, r--;
        left.emplace_back(l);
        right.emplace_back(r);
    }
    for (int i = 0; i < Q;i++){
        cout << vp[right[i]] - vp[left[i]] << endl;
    }
        return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int n,k,r,s,p;
	ll ans=0;
	string t;
	cin>>n>>k>>r>>s>>p>>t;
	string play(t.size(),'$');
	for(int i=0;i<t.size();++i){
		if(i<k){
			if(t[i]=='r'){
				ans+=p;
				play[i]='p';
			}
			else if(t[i]=='p'){
				ans+=s;
				play[i]='s';
			}
			else{
				ans+=r;
				play[i]='r';
			}
		}
		else{
			if(t[i]=='r'&&play[i-k]!='p'){
				ans+=p;
				play[i]='p';
			}
			else if(t[i]=='p'&&play[i-k]!='s'){
				ans+=s;
				play[i]='s';
			}
			else if(t[i]=='s'&&play[i-k]!='r'){
				ans+=r;
				play[i]='r';
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int par[100010];
int dep[100010];
vector<int> g[100010];
int n;

void dfs(int curr, int d) {
  dep[curr] = d;
  for (auto ch : g[curr]) dfs(ch, d + 1);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  fill_n((int*)par, 100010, -1);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      g[id].emplace_back(c);
      par[c] = id;
    }
  }
  int root = 0;
  while (par[root] != -1) root = par[root];
  dfs(root, 0);
  for (int i = 0; i < n; i++) {
    printf("node %d: parent = %d, depth = %d, ", i, par[i], dep[i]);
    if (par[i] == -1) printf("root, ");
    else if (g[i].size()) printf("internal node, ");
    else printf("leaf, ");
    printf("[");
    for (int ch : g[i]) {
      if (ch != g[i][0]) printf(", ");
      printf("%d", ch);
    }
    printf("]\n");
  }

  return 0;
}


Measured memory_bytes: 6940
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define do long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b);
  rep(i,b)
    cin>>c[i];
  int dp[100010];
  rep(i,100010)
    dp[i]=1e10;
  dp[0]=1;
  bool d[100010];
	for(int i=0;i<100010;i++)
		d[i]=true;
	for(int i = 0;i < b;i++) {
		d[c.at(i)] = false;
	}
  if(d[1]==false){
    dp[1]=0;
    }
  else
    dp[1]=1;
  for(int i=2;i<=a;i++){
  if(d[i]==false){
    dp[i]=0;
  }
    else
      dp[i]=(dp[i-1]+dp[i-2])%1000000007;
  }
  cout<<dp[a]%1000000007<<endl;
}

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

ll vis[3001][3001];
double dp[3001][3001];
ll n;

double solve(ll i,double *a,ll c)
{
    
    // cout<<i<<" "<<c<<endl;
    
    if(c==0)
        return 1;
        
    if(i >= n)    
        return 0;
    
    
    if(vis[i][c]){
        return dp[i][c];
    }
    
    
    vis[i][c] = 1;
    
    double ans = 0;
    
    ans += solve(i+1,a,c-1)*a[i];
    
    ans += solve(i+1,a,c)*(1.0-a[i]);
    
    dp[i][c] = ans;
    
    return ans;
}

int main() {
    // ll n;
    cin>>n;
    memset(vis,0,sizeof(vis));
    double a[n+1];
    
    for(ll i=0;i<n;i++)
        cin>>a[i];
    
    ll x = (n+1)/2;
    
    // if(n&1)
    //     x++;
    
    
    cout << setprecision(11) << solve(0,a,x)<<endl; 
    
	return 0;
}

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

ll par(ll x){
    return x*(x-1)/2;
}

ll diff(ll x){
    return par(x) - par(x-1);
}
int main(){
    int n;
    cin >> n;
    unordered_map<int,int> m;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        m[a[i]]++;
    }

    ll total = 0;
    for(auto x:m){
        total += par(x.second);
    }
    for(int i=0;i<n;i++){
        cout << (total - diff(m[a[i]])) << endl;
    }

}

Measured memory_bytes: 8392
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
        int n,x,t;cin>>n>>x>>t;
        
        int m1=(n-1)/x+1;
        m1=m1*t;
        cout<<m1<<"\n";
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(l); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    ll sumA = 0, sumB = 0;
    rep(i, n) cin >> a[i], sumA += a[i];
    rep(i, n) cin >> b[i], sumB += b[i];
    if(sumB < sumA) {
        No();
        return 0;
    }
    ll cnt1 = 0, cnt2 = 0;
    rep(i, n) {
        if(a[i] > b[i]) cnt1 += a[i] - b[i];
        else if(b[i] > a[i]) cnt2 += (b[i] - a[i] + 1) / 2;
    }
    ll cnt = max(cnt1, cnt2);
    if(cnt <= sumB - sumA) Yes();
    else No();
}

Measured memory_bytes: 384
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int X, Y; cin >> X >> Y;
    

    cout << X + Y / 2 << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
char c[10];
ll a;
int b = 0, fb = 0;
int main(){
	scanf("%lld %s", &a, c);
	b = c[0] - '0';
	fb = 10 * (c[2] - '0') + c[3] - '0';
	ll y = a * b;
	ll x = (1LL * a * fb) / 100LL;
	printf("%lld", x + y );


}

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}


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

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


Measured memory_bytes: 256
import math

a,b,c=map(float,input().split())

s = ((a*b)*math.sin(math.radians(c)))/2

S = '{:.8f}'.format(s)

d = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(c)))

L = '{:.8f}'.format(a+b+d)

e = 2*s/a

H =  '{:.8f}'.format(e)

print(S)
print(L)
print(H)


Measured memory_bytes: 5696
# Problem D - Caracal vs Monster

# input
H = int(input())

# initialization
attack_dic = {}

# calc
def calc_count(h, attack):

    if h in attack_dic:
        return attack_dic[h]

    h = h // 2
    if h>0:
        attack += calc_count(h, attack) * 2 + 1
        attack_dic[h] = attack
        return attack
    else:
        return 1
ans = calc_count(H, 0)

# output
print(ans)


Measured memory_bytes: 2940
package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	A := make([]int, n)
	for i:=0; i<n; i++{
		fmt.Scan(&A[i])
	}
	for i:=1; i<=n; i++{
		for k:=0; k<n; k++{
			fmt.Print(A[k])
			if k == n-1{
				fmt.Print("\n")
			} else {
				fmt.Print(" ")
			}
		}
		if i==n{
			break
		}
		key := A[i]
		j:=i-1
		for j>=0 && A[j] > key{
			A[j+1] = A[j]
			j--
		}
		A[j+1] = key
	}
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            if(ABC136.BuildStairs())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

    class ABC136
    {
        public static bool BuildStairs()
        {
            int n = Input.getInt();
            long[] h = Input.getLongArray();
            
            if(n==1) return true;

            for(int i=n-1; i>0; i--)
            {
                if(h[i-1]-h[i]==1)
                {
                    h[i-1] = h[i-1]-1;        
                }
                if(h[i-1]-h[i]>0)
                {
                    return false;
                }
            }

            return true;
        }
    }
        
    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x=>int.Parse(x)).ToArray();
            return num;
        }
        public static long[] getLongArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            long[] num = s.Select(x=>long.Parse(x)).ToArray();
            return num;
        }
    }
 }

Measured memory_bytes: 27356
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 5000000
using namespace std;

struct node
{
  int l, r, id;
} q[N + 5];

int n, a[N + 5], m, c[N + 5], f[N + 5], ans[N + 5];

int lowbit(int x) {return x & (-x);}
int cmp(node x, node y) {return x.r < y.r;}
void add(int x, int k){
  for (; x <= n; x += lowbit(x))
    c[x] += k;
}
int query(int x)
{
  int ans = 0;
  for (; x; x -= lowbit(x))
    ans += c[x];
  return ans;
}

int main()
{
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1; i <= m; i++)
  {
    for (int j = q[i - 1].r + 1; j <= q[i].r; j++)
    {
      if (f[a[j]])
        add(f[a[j]], -1);
      f[a[j]] = j;
      add(j, 1);
    }
    ans[q[i].id] = query(q[i].r) - query(q[i].l - 1);
  }
  for (int i = 1; i <= m; i++)
    printf("%d\n", ans[i]);
  return 0;
}

Measured memory_bytes: 17424
def main():
    from string import ascii_lowercase
    N = int(input())

    ans = []
    while N > 0:
        N -= 1
        N, i = divmod(N, 26)
        ans.append(ascii_lowercase[i])

    ans = ''.join(reversed(ans))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9920
#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, D;
    cin >> N >> D;
    ll ans = 0;
    rep(i, N) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= D * D) {
            ans++;
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 3648
N = int(input())
s = []
for _ in range(N):
    inp = int(input())
    s.append(inp)
s = sorted(s)
sm = sum(s)
if sm%10!=0:
    ans = sm
else:
    for i in s:
        if i%10!=0:
            sm-=i
            break
    ans = sm
    if sm==sum(s):
        ans = 0
print(ans)

Measured memory_bytes: 38384
import sys
input = sys.stdin.readline

def unite(node_a, node_b):
    root_a, depth_a = node_a.root()
    root_b, depth_b = node_b.root()
    if root_a == root_b:# すでに連結成分
        return
    elif depth_a >= depth_b:# aの方が深い
        root_b.is_root = False
        root_b.parent = root_a
        root_a.white += root_b.white
        root_a.black += root_b.black
    else:# bの方が深い
        root_a.is_root = False
        root_a.parent = root_b
        root_b.white += root_a.white
        root_b.black += root_a.black

class Node:
    def __init__(self, color):# color: 0:white, 1:black
        self.parent = None
        self.is_root = True
        self.white = 1 if color == 0 else 0
        self.black = 1 if color == 1 else 0
    
    def root(self):
        node = self
        depth = 0
        while not node.is_root:
            node = node.parent
            depth += 1
        return node, depth

def main():
    H, W = map(int, input().split())
    s = [input().strip() for i in range(H)]
    
    nodes = [[Node(0 if s[j][i] == "." else 1) for i in range(W)] for j in range(H)]

    for y in range(H):
        for x in range(W):
            now = s[y][x]
            for nx, ny in [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if s[ny][nx] != now:
                        unite(nodes[y][x], nodes[ny][nx])
    
    ans = 0
    # count_roots = 0
    for y in range(H):
        for x in range(W):
            if nodes[y][x].is_root:
                # count_roots += 1
                node = nodes[y][x]
                ans += node.white * node.black
    print(ans)
    # print(count_roots)


if __name__ == "__main__":
    main()

Measured memory_bytes: 58716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

int main() {
    ll N, M;
    cin >> N >> M;

    vector<ll> IDs(M, 0);
    vector<vector<pair<ll, ll>>> P_years(N + 1);
    REP(i, M) {
        ll P, Y;
        cin >> P >> Y;
        P_years.at(P).emplace_back(make_pair(Y, i));
    }

    REP(pi, P_years.size()) {
        sort(P_years.at(pi).begin(), P_years.at(pi).end());

        REP(yi, P_years.at(pi).size()) {
            ll i = P_years.at(pi).at(yi).second;
            IDs[i] += pi * 10e5;
            IDs[i] += yi + 1;
        }
    }

    REP(i, IDs.size()) {
        printf("%012lld\n", IDs[i]);
    }

    return 0;
}

Measured memory_bytes: 9504
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> a(N);
  long long sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long ave = sum / N;
  long long ave2;
  if(ave >= 0) ave2 = ave +1;
  else ave2 = ave - 1;
  long long res = 0, res2 = 0;
  for(int i = 0; i < N; i++){
    res += (a[i] - ave) * (a[i] - ave);
    res2 += (a[i] - ave2) *(a[i] - ave2);
  }
  cout << min(res, res2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); 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;}
typedef long long ll;

ll n,h;
string s,t;

int main() {
  cin >> h >> n;
  ll a[n],b[n],dp[n+1][h+1];
  rep(i,n) cin >> a[i] >> b[i];
  rep(i,n+1)rep(j,h+1) dp[i][j]=1e18;
  dp[0][0]=0;
  rep(i,n)rep(j,h+1){
    chmin(dp[i+1][j],dp[i][j]);
    chmin(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
  }
  cout << dp[n][h] << endl;
}

Measured memory_bytes: 78464
/*
 * @Author: Kaizyn
 * @Date: 2020-08-27 13:09:59
 * @LastEditTime: 2020-08-27 13:14:15
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 2e5+7;

int n;
long long res;

inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) res += i*(n-i+1ll);
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    if (u > v) swap(u, v);
    res -= u*(n-v+1ll);
  }
  cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

#define nmax 7
#define pmax 343


//玉を設置する関数
/*
	黒が1,白が10
*/


bool chka(int x, int y, int z, int n, int f[nmax][nmax][nmax], int col) {
	if( x < 0 || x >= n ) return false;
	if( y < 0 || y >= n ) return false;
	if( z < 0 || z >= n ) return false;
	if( f[x][y][z] != col) return false;
	return true;
}

//勝敗判定関数
bool check(int f[nmax][nmax][nmax], int g[nmax][nmax], int n, int m, int zz, int p, int t, int r[pmax][2]) {
	bool flg = false;
	int d[13][3] = 
		{ {1,0,0}, {0,1,0}, {0,0,1},
			{1,1,0}  , {1,0,1}  , {0,1,1},
			{1,-1,0} , {1,0,-1} , {0,1,-1},
			{1,1,1}  , {1,1,-1} ,
			{1,-1,1} , {1,-1,-1} };

	for(int i = 0; i < 13; i++) {
		int x = r[t][0], y = r[t][1], z = zz;
		int nx = x, ny = y, nz = z;
		int cnt = 0;
		while( chka( nx, ny, nz, n, f, f[x][y][z]) ) {
			cnt += f[nx][ny][nz];
			nx += d[i][0];
			ny += d[i][1];
			nz += d[i][2];
		}
		nx = x , ny = y, nz = z;
		while( chka( nx, ny, nz, n, f, f[x][y][z]) ) {
			cnt += f[nx][ny][nz];
			nx -= d[i][0];
			ny -= d[i][1];
			nz -= d[i][2];
		}
		cnt -= f[x][y][z];
		
		if( cnt % 10 >= m || cnt / 10 >= m ) {
			flg = true;
			break;
		}
	}
		
	return flg;
}

int set(int f[nmax][nmax][nmax], int n, int m, int p, int g[nmax][nmax], int r[pmax][2]){

	for(int i = 0; i < p; i++) {
		int col;
		int x = r[i][0], y = r[i][1], z = g[x][y];
		if( i % 2 == 0 ) col = 1;
		else col = 10;
		f[x][y][z] = col;
		g[x][y] ++;
		if( check(f, g, n, m, z, p, i, r)  ) return (i);
	}

	return -1;
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while( 1 ) {
		int n, m, p;
		int f[nmax][nmax][nmax];
		int g[nmax][nmax];			//(i,j)のペグに何個のボールが刺さっているか？
		int r[pmax][2];				//レコード

		cin >> n >> m >> p;
		if( n == 0 && m == 0 && p == 0 ) break;
		/*
			一列が成立するのは
			x,y,zの各軸に平行な場合 2 * 3
			二次元の対角線に平行な場合 2 * 3
			三次元の対角線に平行な場合 4
			→　3 + ( 3 * 2 ) + 4 = 13
		*/

		//初期化
		for(int i = 0; i < nmax; i++) {
			for(int j = 0; j < nmax; j++) {
				for(int k = 0; k < nmax; k++) {
					f[i][j][k] = 0;
					g[i][j] = 0;
				}
			}
		}
		
		//データを取得する
		for(int i = 0; i < p; i++) {
			cin >> r[i][0] >> r[i][1];
			r[i][0] --;
			r[i][1] --;
		}

		int ans = set( f, n, m, p, g, r);
		if( ans == -1 ) {
			cout << "Draw" << endl;
		} else if( ans % 2 == 0 ) {
			cout << "Black " << (ans + 1) << endl;
		} else if( ans % 2 == 1 ) {
			cout << "White " << (ans + 1) << endl;
		}

	}
	//while(1){}

    return 0;
}

Measured memory_bytes: 1168
def eveCheck(a):
    k = 0
    while a%2==0:
        a = a//2
        k += 1
    return k
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,M = map(int,input().split())
A = list(map(int,input().split()))
k = eveCheck(A[0])
flag = 0
for i in range(1,N):
    if k!=eveCheck(A[i]):
        flag = 1
        break
if flag==1:
    print(0)
else:
    m = A[0]
    for i in range(1,N):
        m = m*(A[i]//gcd(m,A[i]))
    a = m//2
    print((M-a)//m+1)

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

int main(){
        while(1){
            int n,x;
                scanf("%d %d",&n,&x);
                if(n==0 && x==0) break;
                int ans=0;
                for(int i=1;i<=n-2;i++){
                        for(int j=i+1;j<=n-1;j++){
                                for(int k=j+1;k<=n;k++){
                                        if(i+j+k==x) ans+=1;
                                }
                        }
                }
                printf("%d\n",ans);
        }
        return 0;
}

Measured memory_bytes: 1172
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in= new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			int ob=in.nextInt();
			int c=0;
			int l=0;
			int h=n-1;
			while(true)
			{
				c++;
				int ex=(l+h)/2;
				if(a[ex]==ob)
					break;
				else if(a[ex]<ob)
					l=ex+1;
				else if(a[ex]>ob)
					h=ex-1;
				if(h<l)
					break;
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 12000
a = input()
b = [False] * 4
for i in range(len(a)):
    if a[i] == "N":
        b[0] = True
    elif a[i] == "E":
        b[1] = True
    elif a[i] == "S":
        b[2] = True
    elif a[i] == "W":
        b[3] = True
if b[0] == b[2] and b[1] == b[3]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	s = input()
	r_num = sum([1 for c in s if c == 'R'])
	w_num = n-r_num
	ret = 0
	for c in s[:r_num]:
		if c == 'W':
			ret += 1
			
			
	print(ret)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 11052
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
using namespace std;

typedef struct point{
    int t, x, y;
} point_t;

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

    point_t data[N+1];

    bool flag = true;

    data[0].t = data[0].x = data[0].y = 0;

    for(int i = 1; i < N + 1; i++)
    {
        scanf("%d %d %d", &data[i].t, &data[i].x, &data[i].y);
    }

    for(int i = 0; i < N; i++)
    {
        int dt = data[i+1].t - data[i].t;
        int dist = abs(data[i+1].x - data[i].x) +abs(data[i+1].y - data[i].y);
        if(dt >= dist and (dist % 2) == (dt % 2))
        {
            continue;
        }

        flag = false;
        break;
    }

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

Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
   
int main()
{
	int n=0;
	char w[11],t[1001];
	cin >> w >> t;
	for (int i = 0; i < 10; i++) {
		if (((int)w[i] >= 0x41)&&((int)w[i] <= 0x5a))
		w[i] = (char)((int)w[i]+32);
	}
	while (!(strstr(t,"END_OF_TEXT"))) {
		for (int i = 0; i < 1000; i++) {
			if (((int)t[i] >= 0x41)&&((int)t[i] <= 0x5a))
			t[i] = (char)((int)t[i]+32);
		}
		if(strcmp(w,t)==0)
			n++;
		cin >> t;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);
        int a = sn.nextInt();
        int b = sn.nextInt();
        int c = sn.nextInt();
        int r = 0;
        if(a > b){
            if(a > c) {
                if (b > c) {
                    r = a;
                    a = c;
                    c = r;

                }else{
                    r = a;
                    a = b;
                    b = c;
                    c = r;
                }
            }else {
                r = a;
                a = b;
                b = r;
            }
        }else{
            if (a > c){
                r = a;
                a = c;
                c = b;
                b = r;
            }else{
                if(b > c){
                    r = b;
                    b = c;
                    c = r;
                }
            }
        }
        System.out.printf("%d %d %d\n",a,b,c);
    }
}



Measured memory_bytes: 26420
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){
    
    const long MOD = 1000000007; 

    var input = Console.ReadLine().Split();
    int n = int.Parse(input[0]);
    int m = int.Parse(input[1]);
    
    if(n-m > 1 || m - n > 1){
      Console.WriteLine(0);
      return;
    }
    
    long N = 1;
    for(int i=1; i<=n; i++){
      N = (N * i) % MOD;
    }
    long M = 1;
    for(int i=1;i<=m;i++){
      M = (M * i) % MOD;
    }
    
    long ans;
    if(n == m){
      ans = 2 * N * M % MOD;
    }
    else{
      ans = N * M % MOD;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 11092