akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, t;
vector<int> G[110];
vector<int> d(110), f(110), visited(110, -1); 

void dfs_visit(int u) {
    visited[u] = 0;
    d[u] = ++t;
    for (int v = 0; v < G[u].size(); v++) {
        if (visited[G[u][v]] == -1) {
            dfs_visit(G[u][v]);
        }
    }
    visited[u] = 1;
    f[u] = ++t;
}

void dfs() {
    for (int u = 0; u < n; u++) visited[u] = -1;
    t = 0;
    for (int u = 0; u < n; u++) {
        if (visited[u] == -1) dfs_visit(u);
    }
    for (int u = 0; u < n; u++) {
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            G[u-1].push_back(v-1);
        }
    }
    dfs();
}


Measured memory_bytes: 3160
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

from collections import defaultdict as dl
n  =ii()
s = []
for _ in range(n):
    ss = input()
    a = sorted(ss)
    a = "".join(a)
    s.append(a)
dic = dl(int)
for i in range(n):
    dic[s[i]] += 1

ans = 0
for k,v in dic.items():
    ans += v*(v-1)//2
print(ans)


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

int main() {
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}

	int len = a.at(n - 1) - a.at(0);
	int len2;
	for (int i = 0; i < n - 1; i++) {
		len2 = a.at(i) + k - a.at(i + 1);
		if (len2 < len) len = len2;
	}
	cout << len << endl;
}

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

#define INF 100000000
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define De cout << "Debug" << endl;
const int M = 100000;

int gcd(int X, int Y) {
	if (X < Y) gcd(Y, X);
	int r;
    if(Y == 0) return X;
	while (r = X % Y) {
		X = Y;
		Y = r;
	}
	return Y;
}

int main() {
  int N,l[M],r[M],c[M];
  cin >> N;
  int A[M];
  REP(i,N) cin >> A[i];

  l[0] = 0,r[N+1] = 0;
  REP(i,N) l[i+1] = gcd(l[i],A[i]);

  for(int i = N; i >= 0; i--) r[i] = gcd(r[i+1],A[i]);
  REP(i,N) c[i] = gcd(l[i],r[i+1]);
  sort(c,c+N);
  cout << c[N-1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    string a;
    cin >> a;

    if (a[1] != a[0] or a[1] != a[2])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);
		long l = 1l*k*(long)Math.pow((k-1),(n-1));
		sb.append(l);
		System.out.print(sb);
	}
}

Measured memory_bytes: 8276
n, m = map(int, input().split())
a = [[] for i in range(8)]

for i in range(n):
    x, y, z = map(int, input().split())
    a[0].append(x+y+z)
    a[1].append(x+y-z)
    a[2].append(x-y+z)
    a[3].append(x-y-z)
    a[4].append(-x+y+z)
    a[5].append(-x+y-z)
    a[6].append(-x-y+z)
    a[7].append(-x-y-z)


ans = 0
for x in a:
    tmp = sum(sorted(x, reverse = True)[:m])
    if ans < tmp:
        ans = tmp

print(ans)


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

typedef long long ll;
typedef long double ld;

ld dp[605];
ld dps[605];
vector <int> graf[605];

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

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int a, b;
        cin >> a >> b;
        graf[a].push_back(b);
    }
    for(int i=n-1; i>=1; i--){
        int k = graf[i].size();
        dp[i] = 0;
        for(auto c : graf[i]){
            dp[i] += (1+dp[c])/k;
        }
        dps[i] = dp[i];
    }
    ld mn = dp[1];
    for(int j=1; j<n; j++){
        if(graf[j].size() > 1){
            int x = graf[j].size();
            int blocked = 0;
            for(int r=0; r<x; r++){
                if(dps[graf[j][r]] > dps[graf[j][blocked]]) blocked = r;
            }
            for(int i=n-1; i>=1; i--){
                dp[i] = 0;
                int k = graf[i].size();
                if(i == j){
                    for(int r=0; r<x; r++){
                        if(r == blocked) continue;
                        dp[i] += (1+dp[graf[i][r]])/(k-1);
                    }
                }
                else{
                    for(auto c : graf[i]){
                        dp[i] += (1+dp[c])/k;
                    }
                }
            }
            mn = min(mn, dp[1]);
        }
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0;i<n;i++) cin >> a[i];
    for(ll i=n-1;i>=0;i=i-2){
        cout << a[i] << " ";
    }
    if((n-1)%2!=0){
        for(ll i=0;i<=n-2;i=i+2){
            cout << a[i] << " ";
        }
    }else{
        for(ll i=1;i<=n-2;i=i+2){
            cout << a[i] << " ";
        }
    }

    cout << endl;
    return 0;
}

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

using namespace std;

int n, x, y;

int a[110];

int main(){
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n - 1; i++){
		cin >> a[i];
	}
	sum = a[1] + a[n-1];
	for(int i = 1; i <= n - 2; i++){
		sum += min(a[i], a[i + 1]);
	}
	cout << sum;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int n, m, q;
  int a[55], b[55], c[55], d[55];
  void solve() {
    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
      cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    e[0] = 1;
    dfs(1);
    cout << ans;
  }
  int e[22];
  i64 ans = 0, cc = 0;
  void dfs(int p) {
    if (p == n + 1) {
      i64 res = 0;
      for (int i = 0; i < q; ++i) {
        if (e[b[i]] - e[a[i]] == c[i])
          res += d[i];
      }
      ans = max(ans, res);
      return;
    }
    for (int j = e[p - 1]; j <= m; ++j) {
      e[p] = j;
      dfs(p + 1);
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int  size, co = 0, ce = 0;
	char o[100000], e[100000];
	string s;
	cin >> s;
	size = s.size();
	for (int i = 0; i < size; ++i) {
		if (i % 2 == 0)o[i] = '0';
		else o[i] = '1';
	}
	//for (int i = 0; i < size; ++i)cout << "o" << i << "=" << o[i] << endl;
	for (int i = 0; i < size; ++i) {
		if (i % 2 == 0)e[i] = '1';
		else e[i] = '0';
	}
	//for (int i = 0; i < size; ++i)cout << "e" << i << "=" << e[i] << endl;
	for (int i = 0; i < size; ++i) {
		if (o[i] != s[i])co = co + 1;
		if (e[i] != s[i])ce = ce + 1;
	}
	//cout << co << ce << endl;
	cout << min(co, ce) << endl;
	//cin >> s;
}

Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N=Integer.parseInt(sc.next());
        int prevT=0;
        int prevX=0;
        int prevY=0;
        for (int i=0;i<N;i++){
            int nextT=Integer.parseInt(sc.next());
            int nextX=Integer.parseInt(sc.next());
            int nextY=Integer.parseInt(sc.next());
            int dt=nextT-prevT;
            int dist=Math.abs(nextX-prevX)+Math.abs(nextY-prevY);
            if ((dt<dist)||((dist-dt)%2!=0)){
                System.out.println("No");
                return;
            }
            prevT=nextT;
            prevX=nextX;
            prevY=nextY;
        }
        System.out.println("Yes");
    }
}

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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

LL a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	
	LL ma1 = min(a, k);
	
	k -= ma1;
	
	LL ma2 = min(b, k);
	k -= ma2;
	LL ma3 = min(c, k);
	
	cout << ma1 - ma3 << endl;
}

Measured memory_bytes: 3640
H, W = list(map(int, input().split()))
S = []
for i in range(H):
  S.append(input())
  
L = [[0] * W for i in range(H)]
R = [[0] * W for i in range(H)]
U = [[0] * W for i in range(H)]
D = [[0] * W for i in range(H)]

for i in range(H):
  work = 0
  for j in range(W):
    if S[i][j] == '#':
      work = 0
    else:
      work += 1
    R[i][j] = work
    
for i in range(H):
  work = 0
  for j in range(W-1,-1,-1):
    if S[i][j] == '#':
      work = 0
    else:
      work += 1
    L[i][j] = work
    
for i in range(W):
  work = 0
  for j in range(H):
    if S[j][i] == '#':
      work = 0
    else:
      work += 1
    D[j][i] = work
    
for i in range(W):
  work = 0
  for j in range(H-1,-1,-1):
    if S[j][i] == '#':
      work = 0
    else:
      work += 1
    U[j][i] = work
    
ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
    
print(ans)

Measured memory_bytes: 180868
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  if(N%2 == 0){
    cout << N << endl;
  }
  else{
    cout << 2 * N << endl;
  }

  return 0;
}


Measured memory_bytes: 256
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a)+min(b)
for i in range(M):
    x,y,c = map(int,input().split())
    ans = min(ans,a[x-1]+b[y-1]-c)

print(ans)


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

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

string str;

string print(int a, int b)
{
    string result = "";
    rep(i, b - a + 1)
    {
        result += str[i + a];
    }
    result += "\n";
    return result;
}

void reverse(int a, int b)
{
    rep(i, (b - a + 1) / 2)
    {
        char t = str[i + a];
        str[i + a] = str[-i + b];
        str[-i + b] = t;
    }
}

void replace(int a, int b, string p)
{
    rep(i, b - a + 1)
    {
        str[i + a] = p[i];
    }
}

int main()
{
    int q;
    cin >> str >> q;

    string ans = "";
    rep(i, q)
    {
        string command;
        cin >> command;
        int a, b;
        cin >> a >> b;
        if (command == "print")
        {
            ans += print(a, b);
        }
        if (command == "reverse")
        {
            reverse(a, b);
        }
        if (command == "replace")
        {
            string p;
            cin >> p;
            replace(a, b, p);
        }
    }
    cout << ans;
}



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

int main() {
  int H, W;
  string s[50];
  int i,j,k;
  int dH[8]={0,1,1,1,0,-1,-1,-1};
  int dW[8]={1,1,0,-1,-1,-1,0,1};
  int ph, pw;
  int b;
  
  cin >> H >> W;

  for (i=0;i<H;i++){
    cin >> s[i];
  }

  for (i=0;i<H;i++){
    for (j=0;j<W;j++){
      if (s[i][j]=='#'){
        cout << "#";
        continue;
      }

      b = 0;
      for (k=0;k<8;k++){
        ph = i + dH[k];
        pw = j + dW[k];
        if (ph < 0 || ph >= H) {
          continue;
        }
        if (pw < 0 || pw >= W) {
          continue;
        }
        if (s[ph][pw] == '#') {
          b++;
        }
      }

      cout << b;
    }
    cout << endl;
  }  
}

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

typedef long long ll;
using namespace std;

struct union_find {
    vector<int> parent; // parent. if the element itself is the parent, return -(the size of the group)

    union_find(int N) : parent(N) {
        parent = vector<int>(N, -1);
    }

    int root(int n) {
        return (parent[n] < 0) ? n : parent[n] = root(parent[n]);
    }

    void unite(int x, int y) {
        // unite small one to big one
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (size_of(rx) < size_of(ry))
            swap(ry, rx);
        parent[rx] += parent[ry];
        parent[ry] = rx;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size_of(int n) {
        return -parent[root(n)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    union_find tree(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        tree.unite(x, y);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (tree.parent[i] < 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
  int a,b,c,k;
  scanf("%d%d%d",&a,&b,&c);
  scanf("%d",&k);
  while(b<=a && k)
  {
    b*=2;
    k--;
  }
  while(c<=b && k)
  {
    c*=2;
    k--;
  }
  if(a<b && b<c)printf("Yes");else printf("No");
  
}

Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define MN 100009

int N;
int a[MN];
int b[MN];

int main(){
  std::cin >> N;
  for( int i = 1; i <= N; i++ ){
	std::cin >> a[i];
	b[i] = -1;
  }
  int i = 1;
  b[i] = 0;
  do{
	b[a[i]] = b[i] + 1;
	i = a[i];
  }while( b[a[i]] < 0 );
  std::cout << b[2] << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int k;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>k;
    
    ll res=0;
    
    for (int i=1; i<=k; i++){
        for (int j=1; j<=k; j++){
            for (int p=1; p<=k; p++){
                res+=__gcd(__gcd(i,j),p);
            }
        }
    }
    cout<<res;
    
    return 0;
}

Measured memory_bytes: 3652
import copy
a, b, c = map(int,input().split())

x = copy.deepcopy(a)
visited = [False] * (b+1)
flg = True
while True:
    x %= b
    if x == c:
        break
    elif visited[x]:
        flg = False
        break
    else:
        visited[x] = True
        x += a
print('YES') if flg else print('NO')

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;

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

void solve(){
	
}

int main(){
	load;
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if (k<=a){
    	cout << k << "\n";
    	return 0;
    }else if (k<=a+b){
    	cout << a << "\n";
    	return 0;
    }else{
    	cout << a+(k-a-b)*-1 << "\n";
    }
	return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


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

int arr[n+1];
vector<int> deja(n+1,0);
for(int index = 1 ;index <= n;index++)
    cin>>arr[index];

int next = 1;
int ans = 0;

while(!deja[next]&&next!=2)
{
    deja[next ] =true;
    next = arr[next];
    ans++;
}

if(next == 2)
    cout<<ans<<endl;
else
    cout<<-1<<endl;
 return 0;
}


Measured memory_bytes: 4028
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int main() {
    string S;cin >> S;
    set<char> NS;
    for(int i = 0;i<S.size();i++){
        if(S.at(i) == 'N') NS.insert(S.at(i));
        else if(S.at(i) == 'S') NS.insert(S.at(i));
    }
    set<char> WE;
    for(int i = 0;i<S.size();i++){
        if(S.at(i) == 'W') WE.insert(S.at(i));
        else if(S.at(i) == 'E') WE.insert(S.at(i));
    }
    if(NS.count('N') && NS.count('S') || (!NS.count('N') && !NS.count('S'))){
        if(WE.count('W') && WE.count('E') || (!WE.count('W') && !WE.count('E'))){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    
    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;

    int mod = 1000000007;
    vector<int> a;
    char pre = ' ';

    for (int i=0; i<n; i++) {
        if (pre != s1[i]) {
            pre = s1[i];
            a.push_back(1);
            continue;
        }
        a.back()++;
    }

    int64 ans = a[0]==1?3:6;
    for (int i=1; i<a.size(); i++) {
        if (a[i-1] == 1)
            ans *= 2;
        else if (a[i] == 2)
            ans *= 3;
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 1000007
long long int mod =1e9+7;
int vis[max1];

bool solve(int a){

		if(vis[a]>1){
			return false;
		}
		int n=sqrt(a);
	for(int i=2;i<=n;i++){
		if(a%i==0){
			if(vis[i]>=1){
				return false;
			}
			if(vis[a/i]>=1){
				return false;
			}
		}
	}
	return true;
}

int main(){	
//ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	memset(vis,0,sizeof(vis));
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		vis[a[i]]+=1;
	}
	if(vis[1]==1){
		cout<<1<<endl;
	}
	else if(vis[1]>1){
		cout<<0<<endl;
	}
	else{
	int ans=0;
	for(int i=0;i<n;i++){
		if(solve(a[i])){
			ans++;
		}
	}
	cout<<ans<<endl;
	}



		
}

Measured memory_bytes: 8072
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 109;
ll n,i,k,s,f;
ll a[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n) cin>>a[i];
    sort(a,a + n);
    revrep(i,n - 1,0){
        if(k == 0)
            f += a[i];
        else
            s += a[i];
        k = 1 - k;
    }
    cout<<abs(f - s);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
	int n;
	cin >> n;
	string s;
	map<string, int> m1;
	m1["AC"] = 0;
	m1["TLE"] = 0;
	m1["WA"] = 0;
	m1["RE"] = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> s;
		m1[s]++;
	}
	cout << "AC x " << m1["AC"] << "\n";
	cout << "WA x " << m1["WA"] << "\n";
	cout << "TLE x " << m1["TLE"] << "\n";
	cout << "RE x " << m1["RE"] << "\n";
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 3668
#include<cstdio>
#include<iostream>

using namespace std;

int a,b,c;

int main()
{
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b)) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

int main(){
  int n,r;
  while(cin>>n>>r&&n+r!=0){
    list<int> fuda;
    rep(i,n){
      fuda.pb(n-i);
    }
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rep(j,c){
        auto tmp = fuda.begin();
        rep(l,p+c-2){
          tmp++;
        }
        rep(l,c){
          fuda.push_front(*tmp);
          fuda.erase(tmp);
        }
      }
    }
    cout << fuda.front() << endl;
  }
}

Measured memory_bytes: 1188
import math

while True:
    n = int(input())
    if not n:
        break

    stars = [list(map(float, input().split())) for i in range(n)]
    is_watch_star = [False for i in range(n)]
    scope = [list(map(float, input().split())) for j in range(int(input()))]

    for i in scope:
        a = (i[0] ** 2 + i[1] ** 2 + i[2] ** 2) ** 0.5
        for j in range(len(stars)):
            star = stars[j]
            b = (star[0] ** 2 + star[1] ** 2 + star[2] ** 2) ** 0.5
            if math.cos(i[3]) * a * b < i[0] * star[0] + i[1] * star[1] + i[2] * star[2]:
                is_watch_star[j] = True

    print(len(list(filter(lambda x:x, is_watch_star))))



Measured memory_bytes: 5820
N, x = (int(x) for x in input().split())
a = [int(x) for x in input().split()]

original_amount = sum(a)

for i in range(N - 1):
    pair_amount = a[i] + a[i + 1]
    if x >= pair_amount:
        continue
    diff = pair_amount-x
    a[i] = min(a[i], a[i]-(diff-a[i + 1]))
    a[i + 1] = max(a[i + 1] - diff, 0)

result_amount = sum(a)

print(original_amount-result_amount)


Measured memory_bytes: 14276
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	if m == 0 || n == 0 {
		return maxInt64(m, n)
	}
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var n int
var a, r, l []int64

func rgcd(i int) int64 {
	if r[i] != -1 {
		return r[i]
	}
	r[i] = gcdInt64(a[i-1], rgcd(i-1))
	return r[i]
}

func lgcd(i int) int64 {
	if l[i] != -1 {
		return l[i]
	}
	l[i] = gcdInt64(a[i+1], lgcd(i+1))
	return l[i]
}

func main() {
	n = readInt()
	a = make([]int64, n)
	r = make([]int64, n)
	l = make([]int64, n)
	for i := range a {
		a[i] = readInt64()
		r[i], l[i] = -1, -1
	}
	r[0] = 0
	l[n-1] = 0

	ans := make([]int64, n)
	for i := range a {
		ans[i] = gcdInt64(rgcd(i), lgcd(i))
	}
	sort.Sort(int64Array(ans))

	fmt.Println(ans[n-1])
}


Measured memory_bytes: 12672
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#define pi acos(-1)
using namespace std;
int main()
{
    char s[107];
    char p[107];
    int flag=0;
    scanf("%s",s);
    scanf("%s",p);
    for(int i=0;i<strlen(s);i++)
    {
        for(int j=0;j<strlen(p);j++)
        {
            int q=i+j;
            if(q>=strlen(s))q-=strlen(s);
            if(s[q]!=p[j])break;
            else if(j==strlen(p)-1&&s[q]==p[j])
            {
                flag=1;
                break;
            }
         }
        if(flag)break;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3236
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
ll fac[200111],inv[200111];
ll kissme(ll x,ll k){return k==0?1:kissme(x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,X,Y;
int c[200111],w[200111];
int mn[200111];
vector<int>con[200111];
void adde(int x,int y){con[x].PB(y);con[y].PB(x);}
bool vis[200111];
int cnt[200111];
vector<int>v;
ll coef;
int dfs(int x)
{
	vis[x]=1;
	v.PB(c[x]);
	coef=coef*inv[++cnt[c[x]]]%mod;
	int ret=1;
	for(int i=0;i<con[x].size();i++)
	{
		if(vis[con[x][i]])continue;
		ret+=dfs(con[x][i]);
	}
	return ret;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<=200000;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=1;i<=200000;i++)inv[i]=kissme(i,mod-2);
	getiii(n,X,Y);
	for(int i=1;i<=n;i++)
	{
		getii(c[i],w[i]);
		if(mn[c[i]]==0||w[i]<w[mn[c[i]]])mn[c[i]]=i;
	}
	int tmn=0,tmn2=0;
	for(int i=1;i<=200000;i++)
	{
		if(mn[i]>0)
		{
			if(tmn==0||w[mn[i]]<w[tmn])tmn2=tmn,tmn=mn[i];
			else if(tmn2==0||w[mn[i]]<w[tmn2])tmn2=mn[i];
		}
	}
	assert(tmn==0||tmn2==0||c[tmn]!=c[tmn2]);
	for(int i=1;i<=n;i++)
	{
		if(w[i]+w[mn[c[i]]]<=X)adde(i,mn[c[i]]);
		if(tmn&&c[tmn]!=c[i]&&w[i]+w[tmn]<=Y)adde(i,tmn);
		if(tmn2&&c[tmn2]!=c[i]&&w[i]+w[tmn2]<=Y)adde(i,tmn2);
	}
	ll ans=1;
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
		v.clear();
		coef=1;
		int sz=dfs(i); 
		ans=ans*fac[sz]%mod;
		ans=ans*coef%mod;
		for(int j=0;j<v.size();j++)cnt[v[j]]=0;
	}
	putsi(ans);
	return 0;
}

Measured memory_bytes: 20456
#include <iostream>

int main(void){
    int N,Pmin,ans;
    int *P;

	std::cin >> N;
    ans = 1;

    P = new int[N];

    std::cin >> P[0];
    Pmin = P[0];
    for(int i = 1 ;i < N; i++){
        std::cin >> P[i];
        if(P[i] < Pmin){
            ans++;
            Pmin = P[i];
        }
    }

    std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1024
Input = input().split()
W = int(Input[0])
H = int(Input[1])
x = int(Input[2])
y = int(Input[3])
r = int(Input[4])

if (x+r <= W) and (y+r <= H) and (0 <= x-r) and (0 <= y-r):
    print('Yes')
else:
    print('No')


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

int main() {
	string t; //P, D, ? 
	cin >> t;
	for(int i=0;i<t.size();i++)
	{
		if(t.at(i) == '?')
		{
			t.at(i) = 'D';
		}
	}
	cout << t << endl;
	return 0;
}


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

int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  if (s.front() != 'L') {
    for (int i = 0; i < (int)s.size(); i++) {
      if (s.at(i) == 'R') {
        s.at(i) = 'L';
      } else {
        s.at(i) = 'R';
      }
    }
  }
  int idx = 0;
  while (0 < k && idx < (int)s.size()) {
    if (s.at(idx) == 'L') {
      idx++;
      continue;
    }
    k--;
    while (idx < (int)s.size() && s.at(idx) == 'R') {
      s.at(idx) = 'L';
      idx++;
    }
  }
  int res = 0;
  char pre = ' ';
  for (char c : s) {
    if (pre == c) {
      res++;
    } else {
      pre = c;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 512
use std::io;
use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;

////////////////////////////////////////////////

fn get_first(s:&String) -> char{
    s.chars().nth(0).unwrap()
}
fn get_last(s:&String) -> char{
    let n = s.len()-1;
    s.chars().nth(n).unwrap()
}

fn main(){
    let n = read_int();
    let words = (0..n).map(|_|read_line()).collect::<Vec<String>>();
    let mut hm = HashMap::new();
    let mut c = get_last(&words[0]);
    
    for i in 0..n as usize{
        if hm.get(&words[i]).is_some(){
            println!("No");
            return;
        }else{
            hm.insert(words[i].clone(),true);
        }
    }
    
    for i in 1..n as usize{
        if get_first(&words[i]) != c{
            println!("No");
            //println!("{},{}",c,get_first(&words[i]));
            
            return;
        }
        
        c = get_last(&words[i]);
        
    }
    println!("Yes");
}



Measured memory_bytes: 4352
[N,M] = list(map(int,input().split()))
SC = []
for i in range(M):
    SC.append(list(map(int,input().split())))

X = [0]*N
X[0] = 1
Y = [0]*N
flag = 0

if (N==1)and(M==0):
    print(0)
elif N==1:
    Y = SC[0][1]
    for j in range(1,M):
        if Y!=SC[j][1]:
            flag = 1
    if flag == 1:
        print(-1)
    else:
        print(Y)
else:
    for i in range(M):
        S = SC[i][0]
        C = SC[i][1]
        if (S-1==0)and(C==0):
            flag = 2
            break
        if (Y[S-1]==0)or((Y[S-1]==1)and(X[S-1]==C)):
            X[S-1] = C
            Y[S-1] = 1
        else:
            flag = 2
            break
    if flag ==2:
        print(-1)
    else:
        output = ""
        for i in range(N):
            output += str(X[i])
        print(output)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
      	long K = sc.nextLong();
      
      	long i, j;
      
      	if (A >= K) {
          	i = A - K;
        	System.out.print(i + " " + B);
        }
      
      	if (A < K) {
        	i = A - K;
          	j = B - (K - A);
          	
            if (j > 0){
            	System.out.print(0 + " " + j);
            } else {
            	System.out.print(0 + " " + 0);
            }
        }

	return;

	}
}

Measured memory_bytes: 23760
#include <iostream>
using namespace std;
int main() {
  	auto N = 0;
  	cin >> N;
  	int cnt = 0;
  	while (N) {
     	if (N % 10 == 2) {
          cnt++;
        }
        N /= 10;
    }
  	cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
A,B,C,X = tuple(int(input()) for i in range(4))
n = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            T = 500*a + 100*b + 50*c
            if T == X:
                n += 1
print(n)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <ctime>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 200;
int n;
int num[maxn];
int A, B;

bool cmp(const int &a, const int &b) {
    return a > b;
}

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    #endif // LOCAL
    ios::sync_with_stdio(false);

    while(scanf("%d", &n) != EOF) {
        A = B = 0;
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &num[i]);
        }
        sort(num + 1, num + 1 + n, cmp);
        for(int i = 1; i <= n; ++i) {
            if(i % 2 == 1) {
                A += num[i];
            } else {
                B += num[i];
            }
        }
        printf("%d\n", A - B);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  ll N = S.size();
  ll K; cin >> K;
  vector<vector<vector<ll> > > dp(N+1, vector<vector<ll> >(K+1, vector<ll>(2, 0)));
  dp[0][0][0] = 1;
  REP(i, N) REP(j, K+1) REP(k, 2){
    ll cd = S[i] - '0';
    REP(d, 10){
      ll ni = i + 1, nj = j, nk = k;
      if(d != 0) nj++;
      if(nj > K) continue;
      if(k == 0){
        if(d > cd) continue;
        if(d < cd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  cout << dp[N][K][0] + dp[N][K][1] << endl;
}


Measured memory_bytes: 256
using System;

class Complete_Binary_Tree {
	public static void Main() {

		int n = int.Parse(Console.ReadLine());
		string[] num_c = Console.ReadLine().Split(' ');
		int[] num = new int[n + 1];
		for(int i = 1; i <= n; i++) {
			num[i] = int.Parse(num_c[i - 1]);
		}

		for(int i = 1; i <= n; i++) {

			Console.Write("node {0}: key = {1}, ", i, num[i]);

			if(Math.Floor(i / 2.0) != 0.0)
			Console.Write("parent key = {0}, ", num[i / 2]);
			

			if(i * 2 <= n)
			Console.Write("left key = {0}, ", num[i * 2]);

			if(i * 2 + 1 <= n)
			Console.Write("right key = {0}, ", num[i * 2 + 1]);

			Console.WriteLine();

		}

	}
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> v{111, 222, 333, 444, 555, 666, 777, 888, 999};
    if(N > 111 && N <= 222){
        cout << v[1] << endl;
    }else if(N > 222 && N <= 333){
        cout << v[2] << endl;
    }else if(N > 333 && N <= 444){
        cout << v[3] << endl;
    }else if(N > 444 && N <= 555){
        cout << v[4] << endl;
    }else if(N > 555 && N <= 666){
        cout << v[5] << endl;
    }else if(N > 666 && N <= 777){
        cout << v[6] << endl;
    }else if(N > 777 && N <= 888){
        cout << v[7] << endl;
    }else if(N > 888 && N <= 999){
        cout << v[8] << endl;
    }else{
        cout << v[0] << endl;
    }

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLineInt();
            var a = ReadLineIntSpilit();

            Console.WriteLine((Distinct(a) <= 0) ? "YES" : "NO");
            ReadLine();
        }

        //メモ

        //配列
        //降順
        //var sort = array.OrderBy(x => -x).ToArray();

        //合計値
        //array.Sum();

        //kのn乗
        //(int) Math.Pow(k, n);

        //for文の逆
        //for(int i = array.Length - 1; i >= 0; i--) { }


        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static int Distinct(int[] array)
        {
            var q = array.Distinct().Count();
            return array.Count() - q;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAlphaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAlphaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 38728
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int n,i,j;cin>>n;
	int bas;
	string str;
	string mae="None";
	cout<<'?';
	for(j=0;j<n;j++){cout<<' '<<1+j;}
	cout<<endl;
	cin>>mae;
	if(str[0]=='-'){return 1;}
	int bmin=1,bmax=n+1;
	while(bmax-bmin>1){
		int bgen=(bmin+bmax)/2;
		cout<<'?';
		for(j=0;j<n;j++){cout<<' '<<bgen+j;}
		cout<<endl;
		string str;cin>>str;
		if(str[0]=='-'){return 1;}
		if(mae!=str){bmax=bgen;}
		else{bmin=bgen;}
		
	}
	bas=bmax;
	
	string ans(n+n+1,' ');
	ans[bas-1]=mae[0];
	ans[bas+n-1]='R'+'B'-mae[0];
	for(i=0;i<n-1;i++){
		cout<<'?';
		for(j=1;j<bas-1;j++){cout<<' '<<j;}
		cout<<' '<<bas+i;
		for(j=bas+n;j<=n+n;j++){cout<<' '<<j;}
		cout<<endl;
		cin>>str;
		if(str[0]=='-'){return 1;}
		ans[bas+i]=str[0];
	}
	for(i=1;i<bas-1;i++){
		cout<<'?'<<' '<<i;
		for(j=bas;j<bas+n-1;j++){cout<<' '<<j;}
		cout<<endl;
		cin>>str;
		if(str[0]=='-'){return 1;}
		ans[i]=str[0];
	}
	for(i=bas+n;i<=n+n;i++){
		cout<<'?'<<' '<<i;
		for(j=bas;j<bas+n-1;j++){cout<<' '<<j;}
		cout<<endl;
		cin>>str;
		if(str[0]=='-'){return 1;}
		ans[i]=str[0];
	}
	cout<<'!'<<ans<<endl;
	return 0;
}


Measured memory_bytes: 724
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end();
#define pp pair<int,int>
int N, M;
bitset<51> p = {};
bitset<51> p2;
pp e[110];
pp e2[110];
void find(int pos) {
	p[pos] = 0;
	TFOR(i, M * 2) {
		if (e[i].first == pos&&p[e[i].second])find(e[i].second);
	}
}
int main() {
	cin >> N >> M;
	TFOR(i, N)p[i] = 1;
	p2 = p;
	TFOR(i, M) {
		int fr, to;
		cin >> fr >> to;
		fr -= 1; to -= 1;
		e[i*2] = pp{ fr,to };
		e[i * 2 + 1] = pp{ to,fr };
		e2[i * 2] = e[i * 2];
		e2[i * 2 + 1] = e[i * 2 + 1];
	}
	int ans = 0;
	TFOR(i, M) {
		e[i*2] = {};
		e[i * 2 + 1] = {};
		find(0);
		if (p.count()!=0) { ++ans; }
		p = p2;
		e[i * 2] = e2[i * 2];
		e[i * 2 + 1] = e2[i * 2 + 1];
	}
	std::cout << ans << std::endl;
	return 0;
	}

Measured memory_bytes: 256
N = int(input())
A = input()
B = input()
C = input()

same = [2]*N
for i in range(N):
    if A[i] == B[i] == C[i]:
        same[i] = 0
    elif A[i] == B[i] or A[i] == C[i] or B[i] == C[i]:
        same[i] = 1

ans = sum(same)
print(ans)


Measured memory_bytes: 3060