akhauriyash/Code-Regression huggingface dataset:
import math

a, b, h, m = map(float, input().split(" "))
arg_a = 2 * math.pi * (h + m / 60) / 12
arg_b = 2 * math.pi * m / 60
arg = min(abs(arg_a - arg_b), 2 * math.pi - abs(arg_a - arg_b))
"""
print(str(arg_a / (math.pi * 2) * 360)
      + " "
      + str(arg_b / (math.pi * 2) * 360))
print(str(arg_a) + " " + str(arg_b))
print(arg / (math.pi * 2) * 360)
"""
length = math.sqrt((a*a + b*b) - (2*a*b * math.cos(arg)))
print(length)


Measured memory_bytes: 9248
// B - Harshad Number
#include <bits/stdc++.h>
using namespace std;

int f(int x){
	int ret = 0;
	while(x>0){ ret += x%10; x /=10; }
	return ret;
}

int main(){
	int n; cin>>n;
	cout<< (n % f(n)? "No":"Yes") <<endl;
}


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

#define int long long

int h[1501];
int w[1501];

int table[1500*1500+1];

auto main() -> signed {
    int n, m;
    while(cin>>n>>m, n) {
        fill(h, h+1501, 0);
        fill(w, w+1501, 0);
        fill(table, table+1500*1500+1, 0);

        for(int i=1; i<=n; ++i) {
            cin >> h[i];
            h[i] += h[i-1];
        }

        for(int i=1; i<=m; ++i) {
            cin >> w[i];
            w[i] += w[i-1];
        }

        for(int i=0; i<=n; ++i) {
            for(int j=i+1; j<=n; ++j) {
                table[h[j]-h[i]]++;
            }
        }

        int ans = 0;
        for(int i=0; i<=m; ++i) {
            for(int j=i+1; j<=m; ++j) ans += table[w[j]-w[i]];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 20692
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: [[i64; 3]; 3],
        n: i64,
        b: [i64; n],
    };

    let mut bs = [[false; 3]; 3];

    for i in b {
        for y in 0..3 {
            for x in 0..3 {
                if a[y][x] == i {
                    bs[y][x] = true;
                }
            }
        }
    }

    let mut bingo = false;
    // yoko
    for y in 0..3 {
        bingo = bs[y][0] && bs[y][1] && bs[y][2];
        if bingo {
            break;
        }
    }

    // tate
    if !bingo {
        for x in 0..3 {
            bingo = bs[0][x] && bs[1][x] && bs[2][x];
            if bingo {
                break;
            }
        }
    }

    //naname
    if !bingo {
        bingo = bs[0][0] && bs[1][1] && bs[2][2] || bs[0][2] && bs[1][1] && bs[2][0];
    }

    println!("{}", if bingo { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
// https://atcoder.jp/contests/tenka1-2017/tasks/tenka1_2017_c

fun main() {
    tenka1_2017c()
}

fun tenka1_2017c() {
    val n = readLine()!!.toLong()
    var cm = 0L
    var i = 1L
    for (i in 1 .. 3500L) {
        for (j in 1..3500L) {
            val t = n * i * j
            val p = 4 * i * j - n * i - n * j
            if (p <= 0L) continue
            if (t % p == 0L) {
                println("$i $j ${t / p}")
                return
            }
        }
    }
}

Measured memory_bytes: 34288
# coding: utf-8
n, d = list(map(int, input().split()))
x = []
for i in range(n):
    _x = list(map(int, input().split()))
    x.append(_x)
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        _r = dist**0.5
        if int(_r) == _r:
            ans += 1
print(ans)


Measured memory_bytes: 3188
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>

using namespace std;

#define MAX_V 1111
struct edge {
  int to,cap,rev;
};
const int inf = 1<<21;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int f,int t,int cap)
{
  G[f].push_back((edge){t,cap,(int)G[t].size()});
  G[t].push_back((edge){f,0,(int)G[f].size()-1});
}

 void bfs(int s)
{
  memset(level,-1,sizeof(level));
  queue<int> q;
  level[s] = 0;
  q.push(s);
  while( !q.empty() ) {
    int v = q.front(); q.pop();
    for( int i = 0; i < int(G[v].size()); i++ ) {
      edge& e = G[v][i];
      if( e.cap > 0 && level[e.to] < 0 ) {
        level[e.to] = level[v]+1;
        q.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f)
{
  if( v == t ) return f;
  for( int &i = iter[v]; i < int(G[v].size()); i++ ) {
    edge& e = G[v][i];
    if( e.cap > 0 && level[v] < level[e.to] ) {
      int d  = dfs(e.to,t,min(f,e.cap));
      if( d > 0 ) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t)
{
  int flow = 0;
  for(;;) {
    bfs(s);
    if( level[t] < 0 ) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while( (f = dfs(s,t,inf)) > 0 ) {
      flow += f;
    }
  }
}

int main(void)
{
  int m,n;
  int a[555],b[555];
  for(;;) {
    scanf("%d%d",&m,&n); if( m+n == 0 ) break;
    for( int i = 0; i < m+n+2; i++ ) G[i].clear();
    for( int i = 0; i < m; i++ ) scanf("%d", a+i);
    for( int i = 0; i < n; i++ ) scanf("%d", b+i);
    for( int i = 0; i < m; i++ ) {
      add_edge(0,i+1,1);
    }
    for( int i = 0; i < m; i++ ) {
      for( int j = 0; j < n; j++ ) {
        if( __gcd(a[i],b[j]) != 1 ) {
          add_edge(i+1,m+1+j,1);
        }
      }
    }
    for( int i = 0; i < n; i++ ) {
      add_edge(m+1+i,n+m+1,1);
    }
    printf("%d\n",max_flow(0,n+m+1));
  }
  return 0;
}

Measured memory_bytes: 7340
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	int n; cin>>n;
  	string str; cin>>str;
  	
  	ll r = 0; ll g = 0; ll b = 0;
  	for (int i=0;i<n;i++) {
    	if (str[i]=='R') {
        	r++;
        } else if (str[i]=='G') {
        	g++;
        } else {
        	b++;
        }
    }
//  	cout << "R: " << r << " G: " << g << " B: " << b << endl;
  	ll totalNumOfCase=r*g*b;
//  	cout << "total num of case: " << totalNumOfCase << endl;
	ll totalNumOfInvalidCase=0;
	for (int i=0; i<n-2;i++) {
      	for (int j = 1; i+2*j < n; j++) {
//	      	cout << "i: " << i << endl;
//          	cout << "i+j: " << (i+j) << endl;
//          	cout << "i+j*2: " << i+j*2 << endl;
//          	if (k > n-1) { break; }
//	    	cout << "i: " << i << endl;
//        	cout << "j: " << j << endl;
//          	cout << "k: " << j+(j-i) << endl;
//          	cout << "***********" << endl;
//          	cout << "j+1: " << j+1 << endl;
          	if (str[i]!=str[i+j]&&str[i]!=str[i+j*2]&&str[i+j]!=str[i+j*2]) {
            	totalNumOfInvalidCase++;
            }
        }
//	    cout << "--------" << endl;
    }  	
    ll ans = totalNumOfCase-totalNumOfInvalidCase;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
//g++  5.4.0

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

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

signed main()
{
    fast;
    int n;
    cin >> n;
    cout << ((n%1000)?(1000-(n%1000)) : 0 );
}





Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
	int a,b,c,z=0;
	scanf("%d %d %d",&a,&b,&c);
	while(1){
	if(a>=b+1)break;
	if(c%a==0){
		z++;
		}
		a++;
	}
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[110];
char t[]="keyence   ";
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	int ctr1=0,ctr2=0;
	rep(i,0,n){
		if(s[i]==t[i])ctr1++;
		else break;
	}
	for(int i=n-1;i>=0;i--){
		if(s[i]==t[6-(n-1-i)])ctr2++;
		else break;
	}
	puts(ctr1+ctr2>=7?"YES":"NO");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>

using namespace std;

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

    int x, y, z;
    int flag = 0;
    for (x = 0; x <= N; x++) {
        for (y = 0; y <= N; y++) {
            int restMoney = Y - 10000 * x - 5000 * y;
            z = restMoney / 1000;
            if (x + y + z == N && z >= 0) flag = 1;
            if (flag) break;
        }
        if (flag) break;
    }
    if (flag) {
        printf("%d %d %d\n", x, y, z);
    } else {
        printf("-1 -1 -1");
    }
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
x, n = gets.chomp.split(" ").map(&:to_i)
p = gets.chomp.split(" ").map(&:to_i)

p = p.sort

ans = 0

if p.empty?
  puts x
else
  0.upto(101) do |i|
    next if p.include?(i)

    if (x - i).abs < (x - ans).abs
      ans = i
    elsif (x - i).abs == (x - ans).abs && i < ans
      ans = i
    end
  end
  puts ans

  #
  # ans = x
  #
  # a = x
  # while a >= 0
  #   if !p.include?(a) && (x - a).abs <= (x - ans).abs && a < ans
  #     ans = a
  #     break
  #   end
  #   a -= 1
  # end
  #
  # if a == -1
  #   ans = x
  #   while p.include?(ans)
  #     ans += 1
  #   end
  # end
  #
  # puts ans
end



Measured memory_bytes: 14276
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll binary_search(
    ll lo, ll hi, function<bool(ll)> is_ok,
    bool maximize
){
    while(lo < hi){
        if(maximize){
            const ll mid = (lo + hi + 1) / 2;
            if(is_ok(mid)){
                lo = mid;
            }else{
                hi = mid - 1;
            }
        }else{
            ll mid = (lo + hi - 1) / 2;
            if(is_ok(mid)){
                hi = mid;
            }else{
                lo = mid + 1;
            }
        }
    }
    return lo;
}

using S = ll;
S e(){ return numeric_limits<ll>::min(); }
S op(S a, S b){ return max(a, b); }

int main(){
    ll n, q;
    cin >> n >> q;
    vector<S> a(n);
    REP(i, n){ cin >> a.at(i); }
    segtree<S, op, e> st(a);
    REP(i, q){
        ll t;
        cin >> t;
        if(t == 1){
            ll xi, vi;
            cin >> xi >> vi;
            xi--;
            st.set(xi, vi);
        }else if(t == 2){
            ll l, r;
            cin >> l >> r;
            l--; r--;
            cout << st.prod(l, r + 1) << endl;
        }else{
            ll xi, vi;
            cin >> xi >> vi;
            xi--;
            if(st.prod(xi, n) < vi){
                cout << n + 1 << endl;
            }else{
                cout << ::binary_search(
                    xi, n - 1,
                    [&](ll x){ return st.prod(xi, x + 1) >= vi; },
                    false
                ) + 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 9108
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		int[] forward = new int[N];
		forward[0] = A[0];
		for (int i = 1; i < N; i++) {
			forward[i] = gcd(forward[i - 1], A[i]);
		}
		int[] backward = new int[N];
		backward[backward.length - 1] = A[A.length - 1];
		for (int i = N - 2; i >= 0; i--) {
			backward[i] = gcd(backward[i + 1], A[i]);
		}

		int max = Math.max(forward[forward.length - 2], backward[1]);
		for (int i = 0; i < N - 2; i++) {
			max = Math.max(max, gcd(forward[i], backward[i + 2]));
		}
		System.out.println(max);
	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				try {
					return (line = line != null && line.hasMoreTokens() ? line : new StringTokenizer(reader.readLine())).nextToken();
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
		});
	}
}

Measured memory_bytes: 43720
#include <bits/stdc++.h>
using namespace std;
static const int MAX_N = 1e5;
int n, h[MAX_N], dp[MAX_N];

int cost(int i, int j) {
	return abs(h[i] - h[j]);
}

void solve() {
	dp[0] = 0; dp[1] = cost(0, 1);
	for(int i = 0; i + 2 < n; i++) {
		dp[i+2] = min(dp[i+1] + cost(i+1, i+2), dp[i] + cost(i, i+2));
	}
	cout << dp[n-1] << endl;
}

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define erep(i, n) for (ll i = 1; i <= (n); i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

struct UnionFind {
  vector<int> par;

  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }

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

int main(void) {
  int n, m;
  cin >> n >> m;
  UnionFind tree(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    tree.unite(a - 1, b - 1);
  }
  
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (!tree.same(0, i)) {
      tree.unite(0, i);
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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


int main() {
	int N;
   cin >> N ;
int A[N];
set<int> st;
for(int i=0;i<N;i++){
cin >> A[i] ;
st.insert(A[i]);
}
if(st.size()==N){
cout << "YES";
}else{
cout << "NO";
}
return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MN=110,MV=1e5+10,INF=0x3f3f3f3f;
int n,w,ans;
ll dp[MV];
typedef pair<int,int> P;
P a[MN];
int main()
{
    scanf("%d%d",&n,&w);
    for(int i=0;i<n;i++)
        scanf("%d%d",&a[i].first,&a[i].second);
    memset(dp,INF,sizeof(dp));
    if(a[0].first<=w)
        dp[a[0].second]=a[0].first,ans=a[0].second;
    dp[0]=0;
    for(int i=1;i<n;i++)
        for(int j=MV;j>=0;j--)
            if(dp[j]+a[i].first<=w)
            {
                dp[j+a[i].second]=min(dp[j+a[i].second],dp[j]+a[i].first);
                ans=max(ans,j+a[i].second);
            }
    //printf("%lld %lld %lld\n",dp[30],dp[50],dp[80]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

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


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

#define int long long
#define ll long long
#define f1(i, a, b) for (int i = a; i < b; i++)
#define f2(i, a, b) for (int i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
#define ld long double

const int mod = 1000000007;
const ld PI = acosl(-1.0);
ll temp;

int ins[1000001];
int primes[1000001]; // careful with limits
void sieve()
{
    // add line for 1 and 0 if required, currently prime
    for (int i = 0; i < 1000001; i++)
        primes[i] = i;
    for (int i = 2; i * i < 1000001; i++)
            if (primes[i] == i)
            for (int j = i * i; j < 1000001; j += i)
                if (primes[j] == j)
                    primes[j] = i;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    f1(i, 0, n)
            cin >> a[i];
    sieve();
    int gcd = a[0];
    f1(i, 1, n)
    {
        gcd = __gcd(gcd, a[i]);
    }

    memset(ins, 0, sizeof ins);

    int pairco = true;
    for (int i = 0; i < n; i++)
    {
        temp = a[i];
        while (temp != 1)
        {
            ins[primes[temp]]++;
            int fact = primes[temp];
            while (temp % fact == 0 && fact != 1)
                temp /= fact;
        }
    }
    f1(i, 2, 1000001)
    {
        if (ins[i] > 1)
        {
            pairco = false;
            break;
        }
    }
    if (pairco)
        cout << "pairwise coprime" << endl;
    else if (gcd == 1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 27060
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
	
const long long INF = 7+(1e+18);
typedef long long Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

	
//引数 Graph:隣接リスト,dist:各頂点から各頂点までの距離が入る,inter:最短路木の親頂点が入る
//戻値 負閉路が存在しない場合:true,そうでないとき:false
bool shortestPath(const Graph &g,vector<vector<Weight> > &dist,vector<vector<int> > &inter) {
  int n = g.size();
  dist.assign(n,vector<Weight>(n,INF));
  for(int i=0;i<n;i++){
    dist[i][i]=0;
  }
  for(int i=0;i<n;i++){
    for(auto f=g[i].begin();f!=g[i].end();f++){
      dist[i][f->dst]=f->weight;
    }
  }
  inter.assign(n, vector<int>(n,-1));
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i][k]+dist[k][j]){
          dist[i][j] = dist[i][k] + dist[k][j];
          inter[i][j] = k;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    if(dist[i][i]<0){
      return false;
    }
  }
  return true;
}
//-----------------
int main()
{ 
    while(true){
        int i, j, V, E;
        int s, t;
        Weight w;
        if(!(cin >> V >> E))break;
        Graph g(V);    //頂点数vの空隣接リストgを生成
        for(i=0; i<E; i++){
            cin >> s >> t >> w;
            g[s].push_back(Edge(s,t,w));    //隣接リストgにsからtに向かう重さwの辺を追加
        }
        vector<vector<Weight> >dist;
        vector<vector<int> > inter;
        bool negative_cycle=shortestPath(g,dist,inter);
        if(negative_cycle==false){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
        for(i=0; i<V; i++){
            for(j=0; j<V-1; j++){
                if(dist[i][j] == INF){cout << "INF" << " ";}
                else{cout << dist[i][j] << " ";}
            }
            j = V-1;
            if(dist[i][j] == INF){cout << "INF";}
            else{cout << dist[i][j];}
            cout << endl;
        }
    }
  
    return 0;
}



Measured memory_bytes: 3332
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

int arr[100010];
int cnt[200010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
        cnt[arr[i]]++;
        if (arr[i] > 0)
            cnt[arr[i] - 1]++;
        cnt[arr[i] + 1]++;
    }

    int mx = 0;

    for (int i = 0; i <= 100010; ++i)
    {
        mx = max(mx, cnt[i]);
    }
    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 1024
#AtCoder Beginner Contest 132 A問題
S=input()
A=[S[0]]
for i in range(4):
    if S[0]!=S[i]:
        A+=S[i]
A=list(set(A))

if len(A)==2:
    cou=S.count(S[0])
    if cou==2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <climits>
#include <set>
#include <deque>

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

using namespace std;

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

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

    return out;

}

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

	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}

		out << "\n";
	}
		
    return out;

}

int main() {

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

	string s;
	cin >> s;

	vector<pair<string, int> > days;
	days.push_back({"SUN", 7});
	days.push_back({"MON", 6});
	days.push_back({"TUE", 5});
	days.push_back({"WED", 4});
	days.push_back({"THU", 3});
	days.push_back({"FRI", 2});
	days.push_back({"SAT", 1});
	for (int i = 0; i < 7; ++i) {
		if (s == days[i].first) {
			cout << days[i].second << "\n";
			break;
		}
	}

	return 0;

}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N,K;
    cin >> N >> K;
    set<int> st;
    REP(_,K) {
        int d;
        cin >> d;
        REP(__,d) {
            int a;
            cin >> a;
            st.insert(a);
        }
    }
    cout << N-st.size() << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n;
    cin >> n;
    
    string ans = "";
    while(n != 0){
        if(n % 2){
            ans = "1" + ans;
            n -= 1;
        }else{
            ans = "0" + ans;
        }
        n /= -2;
    }
    pr((ans=="")?"0":ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
int dp[2][100][2];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string num;
  int d;
  cin>>num>>d;
  int mod=1e9+7;
  int l=num.length();
  dp[0][0][1]=1;
  rep(i,l)
  {
    int ni=num[i]-'0';
    int no=i&1,ne=1-no;
    rep(j,d){dp[ne][j][0]=0,dp[ne][j][1]=0;}
    rep(j,d)
    {
      rep(k,10)
      {
        dp[ne][(j+k)%d][0]+=dp[no][j][0];
        dp[ne][(j+k)%d][0]%=mod;
      }
      rep(k,ni)
      {
        dp[ne][(j+k)%d][0]+=dp[no][j][1];
        dp[ne][(j+k)%d][0]%=mod;
      }
      dp[ne][(j+ni)%d][1]+=dp[no][j][1];
      dp[ne][(j+ni)%d][1]%=mod;
    }
  }
  cout<<((ll)mod+dp[l&1][0][0]+dp[l&1][0][1]-1)%mod<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    if((a%3)*(b%3)*((a+b)%3)==0)Cout("Possible");
    else Cout("Impossible");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();

		if((A+B) % 2 == 0) {
			System.out.print((A+B)/2);
 		} else {
 			System.out.print("IMPOSSIBLE");
 		}
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <limits>
using namespace std;
typedef long long ll;

float inf = std::numeric_limits<float>::infinity();

/* 二次元配列の宣言
  vector<vector<int>> tb;
  tb.resize(H);
  for (size_t i = 0; i < H; i++) {
    tb[i].resize(W);
  }
*/
/*
  A.resize(N);
  for (int i = 0; i < N; i++) {scanf("%d",&A[i]);}
*/

int main(void) {
  ll a,b,x;
  cin >> a >> b >> x;
  if (a==0){
    cout << b/x+1 << endl ;
  }else{
    cout << (b/x)-(a-1)/x << endl ;
  }
  return 0;
}


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

int main(){
    int n; cin >> n;
    int t[n], x[n], y[n];
    for(int i=0;i<n;i++){
        cin >> t[i] >> x[i] >> y[i];
        if(i!=0){
            t[i] -= t[i-1];
            x[i] -= x[i-1];
            y[i] -= y[i-1];
        }
    }
    for(int i=0;i<n;i++){
        if((x[i] + y[i] -t[i])%2 != 0 || (x[i] + y[i]) > t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int H,W,h,w,nh,nw;
vector<pair<int,int>> way={{1,0},{-1,0},{0,1},{0,-1}};

int bfs(int sh,int sw,int gh,int gw,vector<string> &maze){
    vector<vector<int>> visited(H,vector<int>(W,-1));
    visited[sh][sw]=0;
    queue<pair<int,int>> q;
    q.push(make_pair(sh,sw));
    while(!q.empty()){
        auto p=q.front();q.pop();
        h=p.first;w=p.second;
        for(auto wp:way){
            nh=h+wp.first;nw=w+wp.second;
            if(nh==gh&&nw==gw)return visited[h][w]+1;
            if(nh<0||nh>H-1||nw<0||nw>W-1)continue;
            if(maze[nh][nw]=='#')continue;
            if(visited[nh][nw]!=-1)continue;
            visited[nh][nw]=visited[h][w]+1;
            q.push(make_pair(nh,nw));
        }
    }
}

//(*'ω'*)ACcept me...
int main(){
    cin>>H>>W;
    vector<string> maze(H);
    for(int i=0;i<H;i++)cin>>maze[i];
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=i;k<H;k++){
                for(int l=0;l<W;l++){
                    if(i==k&&j==l)continue;
                    if(i<k&&j<l)continue;
                    if(maze[i][j]=='#'||maze[k][l]=='#')continue;
                    ans=max(ans,bfs(i,j,k,l,maze));
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
import Control.Monad
import Data.List
import Data.Ord

solve :: [Int] -> (Int,Int) -> (Int,Int)
solve [] (a,b) = (a,b)
solve [x] (a,b) = (a,b)
solve (x:y:xs) (a,b) 
    | a * b /= 0 = (a,b)
    | x /= y = solve (y:xs) (a,b)
    | x == y && a == 0 = solve xs (x,b)
    | x == y && b == 0 = solve xs (a,x) 
    | otherwise = solve (x:xs) (a,b)

main = do
    getLine 
    xs <- sortBy (comparing Down) . map read . words <$> getLine :: IO [Int]
    let (a,b) = solve xs (0,0)
    print $ if a*b == 0 then 0 else a*b

Measured memory_bytes: 52604
n,m=(int(x) for x in input().split())
k=m+1
s=[0]*k
c=[0]*k
answer=0
for i in range(m):
    s[i+1],c[i+1]=(int(x) for x in input().split())


a=[-1]*10

for i in range(m):
    if a[s[i+1]]==-1:
        a[s[i+1]]=c[i+1]
    elif not a[s[i+1]]==c[i+1]:
        answer=-1
if a[1]==0 and not n==1:
    answer=-1
if a[1]==-1 and not n==1:
    a[1]=1
if a[1]==-1 and n==1:
    a[1]=0
for i in range(10):
    if a[i]==-1:
        a[i]=0

if answer==0:
    for i in range(n):
        d=n-i-1
        answer+=10**d*a[i+1]
print(answer)


Measured memory_bytes: 3188
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long
struct Fast
{
  Fast()
  {
    std::cin.tie(0);
    std::cout.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  for(int i=0;i < n; ++i) cin >> m[i];

  cout << n + (x - accumulate(m.cbegin(), m.cend(), 0)) / *min_element(m.cbegin(), m.cend()) << endl;;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
int cnt[maxn];

ll poww(ll a, ll b) {
  ll ans = 1, base = a;
  while (b) {
    if (b&1) {
      ans *= base;
      ans %= mod;
    }
    b >>= 1;
    base *= base;
    base %= mod;
  }
  return ans;
}

int main (int argc, char **argv) {
  int n;
  std::cin >> n;
  memset(cnt, 0, sizeof(cnt));
  int a;
  for (int i=1; i <= n; i++) {
    std::cin >> a;
    cnt[a]++;
  }
  
  ll ans = 0;
  if (n&1) {
    if (cnt[0] == 1) {
      bool flag = true;
      for (int i=2; i <= n; i+=2) {
         if (cnt[i] != 2) {
           flag = false;
           break;
         }
      }

      if (flag) {
        ans = poww(2, n/2);
      }
    } 
  } else {
    bool flag = true;
    for (int i=1; i <= n; i+=2) {
       if (cnt[i] != 2) {
         flag = false;
         break;
       }
    }

    if (flag) {
      ans = poww(2, n/2);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3544
import sys
from collections import defaultdict
k=int(sys.stdin.readline())
arr=[1,2,3,4,5,6,7,8,9]
n=len(arr)
if k<=n:
    print(arr[k-1])
    sys.exit()
k-=n
next=[]
i=0
while k>=0 and i<n:
    x=arr[i]%10
    a,b,c=x-1,x,x+1
    if a!=-1:
        next.append(arr[i]*10+a)
        k-=1
        if k==0:
            print(next[-1])
    next.append(arr[i]*10+b)
    k-=1
    if k==0:
        print(next[-1])
    if c!=10:
        next.append(arr[i]*10+c)
        k-=1
        if k==0:
            print(next[-1])
    i+=1
    if i==n:
        arr=[j for j in next]
        i=0
        n=len(arr)
        next=[]



Measured memory_bytes: 45040
#include <bits/stdc++.h>
#define int  long long
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

signed main(){
   int n;
   cin >> n;
   vi a(n), b(n);
   rep(i, n) cin >> a[i];
   rep(i, n) cin >> b[i];

   using P = pair<int, int>;
   priority_queue<P> q;

   rep(i, n) q.push({b[i], i});

    int ans = 0;
    while(!q.empty()) {
        auto p = q.top(); q.pop();
        int i = p.se;
        int j = (i + n - 1) % n;
        int k = (i + 1) % n;
        if(a[i] == b[i]) continue;
        // ++ans;
        // b[i] -= b[j] + b[k];
        int dif = b[i] - a[i];
        int cnt = dif / (b[j] + b[k]);
        chmax(cnt, 1LL);
        ans += cnt;
        b[i] -= (b[j] + b[k]) * cnt;
        dumpVL(b);
        if(a[i] > b[i] || b[i] < 0) {
            cout << -1 << endl;
            return 0;
        }
        q.push({b[i], i});
    }
    cout << ans << endl;
   return 0;
}

Measured memory_bytes: 9584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

int main() {
    COMinit();

    int n; cin >> n;
    string s; cin >> s;

    int r = 0, g = 0, b = 0;
    int f[n*3] = {};
    rep(i,n*3){
        if(s[i] == 'R'){
            r++;
            if(r>g&&r>b)f[i] = 1;
            else if(r<=g&&r<=b)f[i] = 3;
            else f[i] = 2;
        }
        if(s[i] == 'G'){
            g++;
            if(g>r&&g>b)f[i] = 1;
            else if(g<=r&&g<=b)f[i] = 3;
            else f[i] = 2;
        }
        if(s[i] == 'B'){
            b++;
            if(b>g&&b>r)f[i] = 1;
            else if(b<=g&&b<=r)f[i] = 3;
            else f[i] = 2;
        }
    }

    ll ans = 1;

    r = 0, g = 0, b = 0;
    rep(i,n*3){
        if(f[i] == 1){
            if(s[i] == 'R')r++;
            if(s[i] == 'G')g++;
            if(s[i] == 'B')b++;
        }
        if(f[i] == 2){
            if(r > 0){
                ans *= r;
                r--;
            }
            if(g > 0){
                ans *= g;
                g--;
            }
            if(b > 0){
                ans *= b;
                b--;
            }
            ans %= MOD;
        }
    }

    r = 0, g = 0, b = 0;
    drep(i,n*3){
        if(f[i] == 3){
            if(s[i] == 'R')r++;
            if(s[i] == 'G')g++;
            if(s[i] == 'B')b++;
        }
        if(f[i] == 2){
            if(r > 0){
                ans *= r;
                r--;
            }
            if(g > 0){
                ans *= g;
                g--;
            }
            if(b > 0){
                ans *= b;
                b--;
            }
            ans %= MOD;
        }
    }

    srep(i,1,n+1){
        ans *= i;
        ans %= MOD;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16780
#include <bits/stdc++.h>
using namespace std;
     
int main() {

    int N;
    cin >> N;

    int N1 = ( N - N % 1000 ) / 1000 ;
    int N2 = ( N - N % 100 ) / 100 - N1 * 10;
    int N3 = ( N - N % 10 ) / 10 - N1 * 100 - N2 * 10; 
    int N4 = N- N1 * 1000 - N2 * 100 - N3 * 10;

    int P = 0;

     if ( N1 == 2) {
        P++;
    }
 
     if ( N2 == 2) {
        P++;
    }
 
     if ( N3 == 2) {
        P++;
    }
 
     if ( N4 == 2) {
        P++;
    }

    cout << P << endl;
}

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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N, K, S, cur, num;

void solve(){
    rep(i, N){
        if(i < K)
            cout << S;
        else{
            if(S + 1  <= INF)
                cout << S+1;
            else
                cout << 1;
        }
 
        if(i == N-1) cout << endl;
        else cout << " ";
    }
}

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

    solve();
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    ll n;cin>>n;
    ll a[n];
    ll x=0;
    f(i,0,n){cin>>a[i];x^=a[i];}
    f(i,0,n){
        ll y=x^a[i];
        cout<<y<<" ";
    }
    return 0;  
} 





Measured memory_bytes: 5132
n,m = map(int, input().split())
s, c = [], []
for i in range(m):
    _s, _c = map(int, input().split())
    s.append(_s-1)
    c.append(_c)
 
for i in range(1000):
    *t, = map(int, list(str(i)))
 
    if len(t) != n:
        continue
 
    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break
 
    if ok:
        print(i)
        quit()
 
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;


ll ans,mx,sum,mn=1e8;
int main(){
	ll n,m;
	cin>>n>>m;
	if(n*2 >= m){
		cout<<m/2;
	}
	else cout<<n+(m-(n*2))/4<<endl;
}


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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

const int N=10010;
int a[N];
int num(int i,int j,int k){return i*i+j*j+k*k+i*j+i*k+j*k;}
int main(){
	cin.tie(0);cin.sync_with_stdio(0);
	int n;cin>>n;
	for(int i=1;i<N;++i)
		for(int j=i;num(i,j,1)<N&&j<N;++j)
			for(int k=j;num(i,j,k)<N&&k<N;++k)
				if(num(i,j,k)<N)
					if(i==j&&j==k)a[num(i,j,k)]+=1;
					else if(i==j||j==k||i==k)a[num(i,j,k)]+=3;
					else a[num(i,j,k)]+=6;
	for(int i=1;i<=n;++i)cout<<a[i]<<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(),x.end()

using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T>
void printVec(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}

int main() {
  string n;
  int K;
  cin >> n >> K;
  int l = n.length();

  int dp[101][4][2];
  rep(i,101) rep(j,K+1) rep(k,2) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  rep(i,l) rep(j,K+1) rep(k,2) {
    int nd = n[i]-'0';
    rep(d,10) {
      int nj=j,nk=k;
      if(d!=0) nj++;
      if(nj > K) continue;
      if(nk==0 and d > nd) continue;
      if(nk==0 and d < nd) nk++;
      dp[i+1][nj][nk] += dp[i][j][k];
    }
  }
  cout << dp[l][K][0] + dp[l][K][1] << endl;

  return 0;
}

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

int main(void) {
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    for (auto &x : a) {
        cin >> x;
    }

    vector<bool> dp(k + 1);
    dp[0] = false;

    for (ll j = 1; j <= k; j++) {
        bool allWinning = true;

        for (auto step : a) {
            if (step <= j) {
                if (!dp[j - step]) {
                    allWinning = false;
                    break;
                }
            }
        }

        dp[j] = !allWinning;
    }

    cout << (dp[k] ? "First" : "Second") << endl;

    return 0;
}

Measured memory_bytes: 256
//package kyoupuro;
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		//int str = String.valueOf(n).length();
		int sum = 0;
		int i;
		for(i=1;i<=n;i++) {
			if(String.valueOf(i).length()%2 == 1) {
				sum++;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 27604
// Problem : B - NarrowRectanglesEasy
// Contest : AtCoder - AtCoder Beginner Contest 056
// URL : https://atcoder.jp/contests/abc056/tasks/abc056_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int w,a,b;cin>>w>>a>>b;
if(b+w<a or b>a+w)
{
	if(b+w<a)
	{
		cout<<a-b-w;
	}
	else
	{
		cout<<b-a-w;
	}
}
else
{
	cout<<0;
}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	char A, B;
	
	cin >> A >> B;

	if (A == B)
	{
		cout << "H" << endl;
	}
	else
	{
		cout << "D" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256