akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UnionFind
{
    int i;
    vector<int> par;
    vector<int> size;
    UnionFind(int n): par(n),size(n,1){
        for(i = 0;i < n;++i){
            par.at(i) = i;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = root(par.at(x));
        }
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return;
        }else{
            if(size.at(rx) < size.at(ry)){
                swap(rx,ry);
            }
            par.at(ry) = rx;
            size.at(rx) += size.at(ry);
            return;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    while(true){
        ll n;
        cin >> n;
        if(n == 0) return 0;
        vector<double> x(n);
        vector<double> y(n);
        vector<double> z(n);
        vector<double> r(n);
        for(i = 0;i < n;++i){
            cin >> x.at(i) >> y.at(i) >> z.at(i) >> r.at(i);
        }

        priority_queue<pair<double,pair<ll,ll>>> pq; //優先度付きキュー
        for(i = 0;i < n-1;++i){
            for(j = i+1;j < n;++j){
                double kyori = sqrt(pow(x.at(i) - x.at(j), 2.0) + pow(y.at(i) - y.at(j), 2.0) + pow(z.at(i) - z.at(j), 2.0));
                kyori = max(0.0, kyori - r.at(i) - r.at(j));
                pq.emplace(-kyori, make_pair(i,j));
                pq.emplace(-kyori, make_pair(j,i));
            }
        }
        
        double ans = 0; //最小全域木の重み
        
        UnionFind uf(n); //連結管理(UnionFind)
        while(!pq.empty()){
            auto x = pq.top();
            pq.pop();
            double w = -x.first;
            ll s = x.second.first;
            ll t = x.second.second;
            if(uf.same(s,t)) continue; //連結は排除
            ans += w;
            uf.unite(s,t);
        }

        cout << fixed << setprecision(3) << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3556
import sys

n = int(sys.stdin.readline().strip())
nums = map(int, sys.stdin.readline().split())
nums = list(nums)
if 1 not in nums:
    print(-1)
    sys.exit(0)
crt = 1

for i in range(n):
    if nums[i] == crt:
        crt += 1
    
print(n - crt + 1)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

void bfs();

vector<int> graph[SIZE];
int res[SIZE];
bool isvisit[SIZE];

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

    int N, M;
    cin >> N >> M;

    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        graph[a].pb(b);
        graph[b].pb(a);

    }

    bfs();
    cout << "Yes" << endl;
    for(int i = 2; i <= N; ++i) {
        cout << res[i] << endl;

    }
    return 0;
}

void bfs() {
    queue<int> q;
    q.push(1);

    isvisit[1] = true;
    while(!q.empty()) {
        int p = q.front();
        q.pop();
        for(int i = 0; i < graph[p].size(); ++i) {
            if(isvisit[graph[p][i]]) continue;
            isvisit[graph[p][i]] = true;
            res[graph[p][i]] = p;
            q.push(graph[p][i]);

        }
    }
}


Measured memory_bytes: 12976
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int q = scanner.nextInt();
			// 全員のポイント
			int[] p = new int[n];
			Arrays.fill(p, k - q);
			IntStream.range(0, q).forEach(i -> p[scanner.nextInt() - 1]++);
			Arrays.stream(p).mapToObj(i -> (i > 0) ? "Yes" : "No").forEach(System.out::println);
		}
	}
}


Measured memory_bytes: 59536
### main

loop do
  n = gets.strip.to_i
  break if n == 0

  sc_a = sc_b = 0

  n.times do
    ai, bi = gets.strip.split(' ').map{|s| s.to_i}

    if ai > bi
      sc_a += ai + bi
    elsif ai < bi
      sc_b += ai + bi
    else
      sc_a += ai
      sc_b += bi
    end
  end

  puts [sc_a, sc_b].join(' ')
end

Measured memory_bytes: 6112
import sys
s=input()
c=0
if s[0]=="A":
    for i in range(2,len(s)-1):
        if s[i]=="C":
            c+=1
            C_nobasyo=i
    #print(c)=1
    if c==1:
        text=s
        #print(text)
        text=text.replace("C","")
        text=text.lstrip("A")
        #print(text)
        if text.islower()==True:
            print("AC")
        else:
            print("WA")
            sys.exit()
    else:
        print("WA")
        sys.exit()
else:
    print("WA")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
/*
ある整数 N に対し，その数自身を除く約数の和を S とする． N = S のとき N は完全数 (perfect number)， N > S のとき N は不足数 (deficient number)， N < S のとき N は過剰数 (abundant number) と呼ばれる． 与えられた整数が，完全数・不足数・過剰数のどれであるかを 判定するプログラムを作成せよ．
各データセットに対し， 整数 N が完全数ならば “perfect number”， 不足数ならば “deficient number”， 過剰数ならば “abundant number” という文字列を 1行に出力せよ．
*/
ll calc (int n )
{
	set<ll> sum; sum.clear();
	for (int i = 1; i*i <= n; i++ ){
		if (n % i == 0 ){
			sum.insert ((ll)i);
			if (i != 1 )
				sum.insert ((ll)n/i );
		} // end if
	} // end for
	ll res = accumulate (ALL (sum), 0LL );

	return (ll)n - res; 
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Perfect_Number", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		ll m = 1LL;
		if (n != 1 )
			m = calc (n );
		if (m > 0LL ){
			printf ("deficient number\n" );
		}else
		if (m == 0LL ){
			printf ("perfect number\n" );
		}else{ // if (m < 0LL )
			printf ("abundant number\n" );
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1172
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func exhaustiveSearch(A []int, n, i, m int) bool {
	// i-1を選んだときにもとのmが作れている
	if m == 0 {
		return true
	}

	if i >= n {
		return false
	}

	// i を選ばなかったときに残りの数で m　を作れるか: exhaustiveSearch(A, n, i+1, m)
	// i を選んだときに残りの数で m-i　を作れるか: exhaustiveSearch(A, n, i+1, m-A[i]
	return exhaustiveSearch(A, n, i+1, m) || exhaustiveSearch(A, n, i+1, m-A[i])
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	A := make([]int, n)
	for i := 0; i < n; i++ {
		A[i] = nextInt()
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		v := nextInt()
		if exhaustiveSearch(A, n, 0, v) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}



Measured memory_bytes: 1124
#include <stdio.h>
#include <string.h>

#define LEN 100005


typedef struct {
  char name[100];
  int time;
}DATA;

void enqueue(DATA );
DATA dequeue();

int head=0,tail=0; 
DATA data[LEN+1];

int main(){

  int elaps=0,t,i,n,q,flag=0;
  DATA tmp;
  scanf("%d%d",&n,&q);

  for(i=0;i<n;i++){
    scanf("%s %d",tmp.name,&tmp.time);
    enqueue(tmp);
    }

  while(1){
    // printf("経過時間:%d\n",elaps);
    
   
     
      tmp =dequeue();
      if(q< tmp.time) t =q;
      else t =tmp.time;
      tmp.time-=t;
      elaps +=t;

      if(tmp.time > 0) enqueue(tmp);
	else printf("%s %d\n", tmp.name, elaps);
    
 
   if(head == tail)break;
  }
 

  return 0;
}

void enqueue(DATA x){
  if(tail == LEN ) tail = 0;
  strcpy(data[tail].name,x.name);
  data[tail].time=x.time;
  tail++;
}

DATA dequeue(){
  if(head == LEN) head = 0;
  head++;
  return data[head-1];
}



Measured memory_bytes: 11888
class BinarySearchTree
	attr_accessor :key, :parent, :left, :right
	@@root = nil
	def initialize(key, parent, left, right)
		self.key = key
		self.parent = parent
		self.left = left
		self.right = right
	end
	
	def self.insert(key)
		if @@root == nil
			@@root = BinarySearchTree.new(key, -1, nil, nil)
		else
			val = @@root
			while true
				if key < val.key
					if val.left
						val = val.left
					else
						val.left = BinarySearchTree.new(key, val.key, nil, nil)
						break
					end
				else
					if val.right
						val = val.right
					else
						val.right = BinarySearchTree.new(key, val.key, nil, nil)
						break
					end
				end
			end
		end
	end
	
	def self.posto(val=@@root)
		Kernel.print " #{val.key}"
		self.posto(val.left) if val.left != nil
		self.posto(val.right) if val.right != nil
	end
	
	def self.ino(val=@@root)
		self.ino(val.left) if val.left != nil
		Kernel.print " #{val.key}"
		self.ino(val.right) if val.right != nil
	end
	
	def self.print
		ino
		Kernel.print "\n"
		posto
		Kernel.print "\n"
	end
	
end


m = gets.chomp.to_i
commands = []
m.times do
	commands.push(gets.chomp)
end
commands.each do |cmd|
	opn, opnd = cmd.split(" ")
	if opnd
		BinarySearchTree.send(opn, opnd.to_i)
	else
		BinarySearchTree.send(opn)
	end
end



Measured memory_bytes: 97836
#include <iostream>
#include <cmath>

using namespace std;

constexpr double EPS = 0.0000000001;

int main()
{
    double xA, yA, xB, yB, xC, yC, xD, yD;

    while (cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD) {
        double dot = (yA-yB) * (yC-yD) + (xC-xD) * (xA-xB);

        cout << ((abs(dot) < EPS)? "YES": "NO") << endl;
    }

    return 0;
}

Measured memory_bytes: 1224
from collections import Counter

def solve():
    N = int(input())
    D = list(map(int, input().split()))

    mod = 998244353

    if D[0] != 0:
        print(0)
        return

    cnt = Counter(D)

    if cnt[0] > 1:
        print(0)
        return

    res = 1

    for i in range(1, max(D)+1):
        if cnt[i-1] == 1:
            continue
        res *= cnt[i-1]**cnt[i] %mod
        res %= mod
    
    print(res)

solve()

Measured memory_bytes: 24452
#include <iostream>
#include <algorithm>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
int a[1000+10];
int main()
{
    int n,k,ans=0;
    cin>>n>>k;
    For(i,1,n)cin>>a[i];
    sort(a+1,a+1+n);
    For(i,1,k)ans+=a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::pair<ll, ll> pll;

using namespace std;

int main() 
{
    ll x;
    ll ans = 0;
    cin >> x;

    irep(i, INF) {
        ans += i;
        if(ans >= x) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int N, M;
int cnt = 0;
vector<int> ord(MAX, NIL), lowLink(MAX);
vector<vector<int> > G(MAX, vector<int>());
/* function */
void dfs(int from, int parent) {
    ord[from] = lowLink[from] = cnt++;
    for (int to : G[from]) {
        // DFS木の親を訪れようとしたら何もしない
        if (to == parent) continue;
        if (ord[to] == NIL) {
            // nodeが使われていないならdfs
            dfs(to, from);
            // dfsが戻ってきたらlowlinkの更新
            lowLink[from] = min(lowLink[from], lowLink[to]);
        }
        // 使われている頂点まだ使ってない辺でを訪れようとした場合
        else {
            // これが後退辺となるのでusedEは0のままにしておく
            // lowlinkの更新
            lowLink[from] = min(lowLink[from], ord[to]);
        }
    }
    return ;
}
void bridge(vector<pii> edges) {
    int from, to;
    int ans = 0;
    for (pii edge : edges) {
        from = edge.first, to = edge.second;
        if (ord[from] < lowLink[to] || ord[to] < lowLink[from])
            ans++;
    }

    cout << ans << '\n';
}
/* main */
int main(){
    cin >> N >> M;
    int u, v;
    vector<pii> edges;
    for (int i = 0; i < M; i++) {
        cin >> u >> v;
        if (u > v) swap(u, v);
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
        edges.push_back(pii(u, v));
    }
    dfs(0, -1);
    sort(edges.begin(), edges.end());
    bridge(edges);
}

Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>

int main()
{
  	int N, Q;
  	std::cin >> N >> Q;
  
  	std::string line;
  	std::getline(std::cin, line);
  	std::getline(std::cin, line);
  
  	std::vector<int> sub;
  	int m = 0;
    for (auto i = 0u; i < line.size(); ++i)
    {
      switch (line[i])
      {
        case 'A': m = 1; break;
        case 'C': if (m == 1) sub.push_back(i);
        default: m = 0; break;
      }
    }
  
  	for (int i = 0; i < Q; ++i)
    {
      	int l, r;
      	std::cin >> l >> r;
      
      	auto L = std::lower_bound(sub.begin(), sub.end(), l);
      	auto R = std::lower_bound(L, sub.end(), r);
      
      	std::cout << std::distance(L, R) << std::endl;
    }
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e9;
string s;
ll ans =0;;
map<string,int> m;
set<char> cc;	
ll dfs(string str=""){
	if(s.size()*2-1<str.size()) return 0;
	if(str!=""&&str.front()!=s.front()) return 0;
	stringstream ss(str);
	string cell,check;
  	ll num=0;
	while(getline(ss,cell,'+')){
      	check+=cell;
		num+=stoll(cell);
	}
  	if(s.substr(0,check.size())!=check) return 0;

  	if(check==s){
      if(str.back()=='+') return 0;
      if(m[str]!=0) return 0;
      else m[str]=1;
    	//cout << str << endl;
		ans+=num;
      	//cout << ans << endl;
    }
	//ll res=0;
	for(auto c:cc){
		if(str.back()=='+'&&c=='+') continue;
		dfs(str+c);
	}
	return 0;
}
int main(){
	cin >> s;
	for(auto i:s){
		cc.insert(i);
	}
	cc.insert('+');
	dfs();
  	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]", M: int, t: "List[str]"):
    dic = {}
    for a in s:
        if a in dic:
            dic[a] += 1
        else:
            dic[a] = 1
    for a in t:
        if a in dic:
            dic[a] -= 1
        else:
            dic[a] = -1
    ret = 0
    for val in dic.values():
        ret = max(ret, val)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    M = int(next(tokens))  # type: int
    t = [ next(tokens) for _ in range(M) ]  # type: "List[str]"
    solve(N, s, M, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	string s;
	cin >> s;
	REP(i, s.length())
	{
		if (i == 3)
		{
			cout << 8;
		}
		else
		{
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>

using namespace std;

void vec_cout(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

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

    vector<long long> dp(100001,W+1);
    dp[0]=0;
    for(int i=0; i<N; i++){
        int w,v;
        cin >> w >> v;
        for(int j=100000-v; j>=0; j--){
            dp[j+v]=min(dp[j]+w,dp[j+v]);
        }
    }
    int ans = 0;
    for(int i=0; i<dp.size(); i++){
        if(dp[i]<=W)ans=i;
    }
    //vec_cout(dp);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
        int n, b, f, r, v, i, j, k;
        int a[4][3][10] = {};
        scanf("%d", &n);

        for(i=0;i<n;i++) {
                scanf("%d %d %d %d", &b, &f, &r, &v);
                a[b-1][f-1][r-1]+=v;
        }

        for(k=0;k<4;k++) {
                for(j=0;j<3;j++) {
                        for(i=0;i<10;i++) {
                                printf(" %d", a[k][j][i]);
                        }
                        printf("\n");
                }
                if(k!=3)        printf("####################\n");
        }
        return 0;
}

Measured memory_bytes: 612
fn main() {
    let (a, b) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        let v: Vec<i32> = line.split_whitespace().map(|a|a.parse().unwrap()).collect();
        (v[0], v[1])
    };
    println!("{}", std::cmp::max(a + b, std::cmp::max(a - b, a * b)))
}


Measured memory_bytes: 4352
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,a[200010],sum=0,ans=1e18;

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
		sum+=a[i];
	}
	LL res=0;
	rep(i,n-1)
	{
		res+=a[i];
		ans=min(ans,abs(res-(sum-res)));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<cstring>
using namespace std;
int main()
{int n,m;
 cin>>n>>m;
 cout<<n*n-m<<endl; 
 system("pause");
 return 0;
}

Measured memory_bytes: 504
#include <stdio.h>
int main()
{
    int x[4], y[4];
    scanf("%d %d %d %d",&x[0], &y[0], &x[1], &y[1]);
    x[2]=x[1]+y[0]-y[1];
    y[2]=y[1]+x[1]-x[0];
    x[3]=x[0]+y[0]-y[1];
    y[3]=y[0]+x[1]-x[0];
    printf("%d %d %d %d\n",x[2], y[2], x[3], y[3]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	string S;
	cin>>S;
	
	auto s1=atoi(S.substr(0,2).c_str());
	auto s2=atoi(S.substr(2,2).c_str());
	
	if(s1>12||s1==0){
		if(s2>0&&s2<13){
			ce("YYMM")
		}else{
			ce("NA")
		}
	}else{
		if(s2>12||s2==0){
			ce("MMYY")
		}else{
			ce("AMBIGUOUS")
		}
	}
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2e5+1e2;
const ll inf=1e15;
int n;
ll Ans=inf;
ll val[maxn];

inline void file() {
	freopen("ARC100D.in","r",stdin);
	freopen("ARC100D.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n) val[i]=read();
	For (i,1,n) val[i]+=val[i-1];
	int p1=1,p2=2,p3=3; ll minx=inf,maxx;
	for (;p2<n;++p2) {
		minx=inf;
		for (int i=p1;i<p2;++i)
			if (chkmin(minx,abs((val[p2]-val[i])-val[i]))) p1=i;
			else break;
		minx=inf;
		if (p3<=p2) p3=p2+1;
		for (int i=p3;i<n;++i)
			if (chkmin(minx,abs((val[n]-val[i])-(val[i]-val[p2])))) p3=i;
			else break;
		minx=inf; maxx=0;
		minx=min(val[p1],min(val[p2]-val[p1],min(val[p3]-val[p2],val[n]-val[p3])));
		maxx=max(val[p1],max(val[p2]-val[p1],max(val[p3]-val[p2],val[n]-val[p3])));
		chkmin(Ans,maxx-minx);
	}
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 1792
/* Author: Mrigank
Science is what we understand well enough to explain to a computer, 
    Art is everything else we do - Donald E. Knuth */

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <string> 
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair < ll , ll > PLL;
typedef pair<int, int> PII;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < pair < int , int > > vpi;
typedef vector < pair < ll , ll > > vpl;
typedef vector < pair < ll , bool > > vpb;
typedef vector < vector < int > > vvi;
typedef vector < vector < ll > > vvl;


#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x , val) memset(x , val , sizeof(x))
#define deb(x) cout<<#x<<" :: "<<x<<"\n"
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define all(x) x.begin() , x.end()
#define alls(x , y) x.begin() , x.end() , y
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"

const ll mxsize = 1e5 + 10;
const ll linf = 1e9;
const ld inf = 10000000000.0;
const ll mod = 1e9 + 7;
 
/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
    int n;
    cin >> n;
    vl arr(n);
    ll i , j , k;
    ll ans = 0;
    fo(i , n) cin >> arr[i];
    fo(i , n)
    {
        Fo(j , i + 1 , n)
        {
            Fo(k , j + 1 , n)
            {
                if(arr[i] == arr[j] || arr[i] == arr[k] || arr[j] == arr[k]) continue;
                else
                {
                    if(arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[j] + arr[k] > arr[i])
                    {
                        ans++;
                    }
                }
                
            }
        }
    }
    cout << ans << endl;
}

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

const int maxn = 1e3 + 5;

int num[maxn];
double sum;
bool ok = 1;

int cmp(int x,int y) { return x > y; }

int main(){
	int n,m; cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> num[i];
		sum += num[i];
	}

	double sign = sum / (4.0 * (double)m);
	if(sign != (int)sign) sign = (int)sign + 1;


	sort(num + 1, num + 1 + n, cmp);

	for(int i = 1; i <= m; i++){
		if(num[i] < sign){
			ok = 0;
			break;
		}
	}

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







Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(){
     
    string str;
    int a = 0, i = 0;
     
    while(1){
     
        cin >> str;
         
        if(str == "0")break;
         
        for(i = 0; i < str.size(); ++i){
         
            a += str[i] - '0';
        }
         
        cout << a << endl;
        a = 0;
    }
     
    return 0;
}


Measured memory_bytes: 3224
n,m = map(int,input().split())
a = list()
for i in range(n):
    b,c = map(int,input().split())
    a.append([b,c])
a.sort(key=lambda x:x[0])
ans = 0
for x in a:
    if x[1] <= m:
        ans += x[1] * x[0]
        m-=x[1]
    else:
        ans += m * x[0]
        m = 0
    if m == 0:
        break
print(ans)

Measured memory_bytes: 21204
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 200000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
string a[100];
int b[100];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)cin >> a[i] >> b[i];
	string s;
	cin >> s;
	int r = 0;
	bool f = false;
	for (int i = 0; i < num; i++)
	{
		if (f)r += b[i];
		if (s == a[i])f = true;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll a,b,c,x,y;cin>>a>>b>>c>>x>>y;
  ll ans=a*x+b*y;
  while(x>0||y>0){
    ll tmp;
    if(x>0&&y>0)tmp=ans-(a+b)+c*2;
    else{
      if(x>0)tmp=ans-a+c*2;
      if(y>0)tmp=ans-b+c*2;
    }
    x--;y--;
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
while 1:
    datas = list(map(int, input().split()))
    if datas[0] == 0:
        break

    n, m = datas[0], datas[1]
    cnt = 0
    for i in range(n, m+1):
        b = i
        while b % 5 == 0:
            b //= 5
        while b % 3 == 0:
            b //= 3
        while b % 2 == 0:
            b //= 2
        if b == 1:
            cnt += 1
    print(cnt)



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

int a, b, c;
int main() {
	scanf("%d/%d/%d", &a, &b, &c);
	a = a*10000 + b*100 + c;
	cout << (a<=20190430 ? "Heisei" : "TBD");
	return 0;
}


Measured memory_bytes: 3664
N = int(input())
LP = list(map(int, input().split()))

cnt = 0
for i in range(N-2):
    LA = []
    LB = []
    LA = [LP[i],LP[i+1],LP[i+2]]
    LB = sorted(LA)
    if LA[1] == LB[1]:
        cnt += 1
print(cnt)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#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++)
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; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    REP(i,N){
        int l;
        cin >> l;
        L[i] = l;
    }

    sort(L.begin(), L.end());

    ll ans = 0;
    REP(a, N){
        REPi(b, a+1, N){
            //cout << a << " " << b << endl;
            int A = L[a];
            int B = L[b];
            int low = max(A-B, B-A);
            int high = A+B;

            int tmp = 0;
            tmp = lower_bound(L.begin(), L.end(), high) - lower_bound(L.begin(), L.end(), low+1);
            //cout << tmp << endl;
            if(low < A && A < high) tmp--;
            if(low < B && B < high) tmp--;
            ans += tmp;
        }
    }

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


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

int main() {
  int n, a, b, c;
  cin >> n;
  a = n / 100;
  b = (n - a * 100) / 10;
  c = (n - a * 100) - (b * 10);
  cout << a + b + c << endl;
}


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

int main(void){
    int n = 0; 
    char s[101];
    char t[101];

    scanf("%d", &n);

    scanf("%s%s", s, t);

    for(int i = 0; i < n; i++){
        printf("%c%c", s[i], t[i]);
    }
    printf("\n");

    return 0;

} 


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define fr(i,n) for(i=0;i++<n;)

int main(){
  int i,n,m,a;
  bool c[100010]={};
  cin>>n>>m;
  for(;cin>>a;) c[a]=!c[a];
  fr(i,n){
    if(c[i]&1){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

N,M = map(int,input().split())
condition = [list(map(int,input().split())) for _ in range(M)]

uf = UnionFind(N)

for c in condition:
    uf.union(c[0]-1,c[1]-1)

print(uf.group_count())

Measured memory_bytes: 80472
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];

  double s = 0;
  for(int i = 0; i < n; i++){
    s += 1.0 / a[i];
  }
  s = 1.0 / s;

  printf("%.5lf\n", s);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

vector<bool> used, used_init;
vector<int> mt;
vector<vector<int>> g;
vector<pair<int, int>> matching;

bool try_kuhn(int v)
{
    if(used[v])
    {
        return false;
    }
    used[v] = true;
    
    for(int i = 0; i < (int) g[v].size(); i++)
    {
        int to = g[v][i];
        if(mt[to] == -1 || try_kuhn(mt[to]))
        {
            mt[to] = v;
            return true;
        }
    }
    
    return false;
}

void build_matching(int n, int k)
{
    mt.assign(k, -1);
    used_init.assign(n, false);
    for(int i = 0; i < n; i++)
    {
        for(int k = 0; k < (int) g[i].size(); k++)
        {
            if(mt[g[i][k]] == -1)
            {
                mt[g[i][k]] = i;
                used_init[i] = true;
                break;
            }
        }
    }
    
    
    for(int i = 0; i < n; i++)
    {
        if(used_init[i])
        {
            continue;
        }
        used.assign(n, false);
        try_kuhn(i);
    }
    
    for(int i = 0; i < k; i++)
    {
        if(mt[i] != -1)
        {
            matching.pb(mp(mt[i] + 1, i + 1));
        }
    }
}

vector<pair<int, int>> v;

void solve()
{
    int n;
    cin >> n;
    v.resize(2 * n);
    for(int i = 0; i < 2 * n; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    
    g.resize(n);
    for(int i = 0; i < n; i++)
    {
        for(int k = n; k < 2 * n; k++)
        {
            if(v[i].first < v[k].first && v[i].second < v[k].second)
            {
                g[i].pb(k - n);
            }
        }
    }
    
    build_matching(n, n);
    cout << matching.size() << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())

a = [0 for k in range(n)]
b = [0 for k in range(n)]

for i in range(n):
    tempA, tempB = map(int, input().split())
    a[i] = tempA
    b[i] = tempB

t = sorted(range(len(a)), key=lambda k: a[k])

cost = 0
nokori = m
for i in t:
    if(b[i]<=nokori):
        cost += a[i]*b[i]
        nokori = nokori - b[i]
    else:
        cost += a[i]*nokori
        nokori = 0
    if(nokori==0):
        break

print(cost)

Measured memory_bytes: 16448
(function() {
    'use strict';

    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;

    // ToDo start
      //var line2token = lines[1].split(" ")
      console.log( Math.pow(parseInt(lines[0]),2) - parseInt(lines[1])  )
    // ToDo end

    });


})();



Measured memory_bytes: 8264
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int p; string s;
	cin >> p;
	for (int i = 0; i < 32; i++) {
		s = (p % 2 ? '1' : '0') + s;
		p /= 2;
	}
	cout << s << endl;
	for (int i = 0; i < 32; i++)cout << (s[i] == '0'); cout << endl;
	cout << s.substr(1, 31) + '0' << endl;
	cout << '0' + s.substr(0, 31) << endl;
}


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

int main(){
	
	int n;
	cin >> n;
	int a[n+1];
	int ans[n+1];
	for(int i =1;i<=n;i++) {
		cin >> a[i];
	  ans[a[i]] = i;	
	}
     
    for(int i=1;i<=n;i++) cout << ans[i]<<" ";
    
    cout << endl;
   
	
	
	
}


Measured memory_bytes: 1536
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a;
        a.push_back(0);
        for (int i = 0; i < n; i ++) {
                int tmp;
                scanf("%d", &tmp);
                a.push_back(tmp);
        }
        a.push_back(0);
        int res = 0;
        for (int i = 1; i < n + 2; i ++) {
                res += abs(a[i] - a[i - 1]);
        }
        for (int i = 1; i <= n; i ++) {
                int l = a[i - 1], m = a[i], r = a[i + 1];
                if (abs(l - m) + abs(m - r) == abs(l - r)) {
                        printf("%d\n", res);
                } else {
                        printf("%d\n", res - (abs(l - m) + abs(m - r)) + abs(l - r));
                }
        }
        return 0;
}



Measured memory_bytes: 1784
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main( ){
  int n;
  string a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    int sum=0;
    for(int j=0;j<a.size();j++){
      sum+=a[j]-'0';
    }
    int kai=a.size()-1+sum/9;
    if(sum%9==0)kai--;
    if(kai%2!=0)printf("Fabre wins.\n");
    else printf("Audrey wins.\n");
  }
  return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,a;
  long long s=0; 
  scanf("%d %d",&n,&m);
  m=n-m;
  while(n--){
    scanf("%d",&a);
    hin(a);
  }
  if(m>0){
    while(m--)s+=N[hout()];
  }
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 4992
n, m = map(int, input().split(' '))
k = [0] * m
s = [[]] * m
for i in range(m):
  _input = [num for num in map(int, input().split(' '))]
  k[i] = _input[0]
  s[i] = _input[1:]
p = [num for num in map(int, input().split(' '))]

# print(n, m)
# print(k)
# print(s)
# print(p)

# スイッチのパターンデータ作成
s_pattern = [''] * (2**n)
str_format = '{:0' + str(n) + 'b}'
for i in range(2**n):
  s_pattern[i] = str_format.format(i)
# print(s_pattern)

ans = 0

for i in range(2**n):
  pattern = s_pattern[i]
  for j in range(m):
    need_switches = s[j]
    on_count = 0
    for switch in need_switches:
      if pattern[switch-1] == '1':
        on_count += 1
    # print(on_count, p[j])
    # 電球が点灯するか
    if on_count % 2 == p[j]:
      continue
    else:
      break
  else:
    # break で抜けていなければ場合はすべての電球が点灯する
    ans += 1

print(ans)

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



int main(void){
    int R;
    cin>>R;
    if(0<=R&&R<1200) cout<<"ABC"<<endl;
    else if(R<2800) cout<<"ARC"<<endl;
    else if(R<=4208) cout<<"AGC"<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	private ArrayList<Building> building;

	final int BUILDING = 4;
	final int FLOOR = 3;
	final int ROOM = 10;

	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    Main main = new Main();
	    main.init();

	    int n = Integer.parseInt(br.readLine());

	    for (int i = 0; i < n; i++) {
		    String[] line = br.readLine().split(" ");
		    // ?£?
		    int b = Integer.parseInt(line[0]);
		    // ???
		    int f = Integer.parseInt(line[1]);
		    // ??¨?±???????
		    int r = Integer.parseInt(line[2]);
		    // ?¢?????????°
		    int v = Integer.parseInt(line[3]);

		    main.movePeople(b, f, r, v);
	    }
	    main.disp();
	}

	private void init() {
		this.building = new ArrayList<Building>();

		for (int i = 1; i <= BUILDING; i++) {
			building.add(new Building(i));
		}
	}

	private void disp() {
		for (int b = 0; b < this.building.size(); b++) {

			Building building = this.building.get(b);
			for (int f = 0; f < building.getFloorCount(); f++) {

				Floor floor = building.getFloor(f);
				for (int r = 0; r < floor.getRoomCount(); r++) {
					Room room = floor.getRoom(r);
					System.out.print(" " + room.getNinzu());
				}
				System.out.println("");
			}

			if (b != this.building.size() - 1) {
				System.out.println("####################");
			}
		}
	}

	private void movePeople(int b, int f, int r, int v) {
		Building building = this.building.get(b - 1);
		Floor floor = building.getFloor(f - 1);
		Room room = floor.getRoom(r - 1);

		room.setNinzu(v);
	}

	class Building {
		private int num;

		private ArrayList<Floor> floor;

		Building(int buildingNo) {
			this.num = buildingNo;

			floor = new ArrayList<Floor>();
			for (int i = 1; i <= FLOOR; i++) {
				floor.add(new Floor(i));
			}
		}

		public int getFloorCount() {
			return this.floor.size();
		}

		public Floor getFloor(int floorNo) {
			return floor.get(floorNo);
		}
	}

	class Floor {
		private int num;

		private ArrayList<Room> room;

		Floor(int floorNo) {
			this.num = floorNo;

			room = new ArrayList<Room>();
			for (int i = 1; i <= ROOM; i++) {
				room.add(new Room(i));
			}
		}

		public Room getRoom(int roomNo) {
			return room.get(roomNo);
		}

		public int getRoomCount() {
			return this.room.size();
		}
	}

	class Room {
		private int num;

		private int ninzu;

		Room(int roomNo) {
			this.num = roomNo;
		}

		public int getNinzu() {
			return ninzu;
		}

		public void setNinzu(int ninzu) {
			this.ninzu += ninzu;

			if (this.ninzu < 0) this.ninzu = 0;
		}
	}
}

Measured memory_bytes: 24664
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == '1')
            s[i] = '9';
        else if (s[i] == '9')
            s[i] = '1';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  int flag=(n==1 || m==1 || k==0);
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      int cnt=i*j+(n-i)*(m-j);
      if(cnt==k) flag=1;
    }
  }
  printf("%s\n",flag?"Yes":"No");
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){

	int i,n;
	int top,north,south,east,west,bottom,temp;
	char direction[8];

	while(1){
		top=1;
		north=2;
		west=3;
		east=4;
		south=5;
		bottom=6;

		scanf("%d",&n);
		if(n==0){
			break;
		}

		for(i=0;i<n;i++){
			scanf("%s",direction);

		    if(direction[0]=='n'){
		    	temp=top;
		    	top=south;
		    	south=bottom;
		    	bottom=north;
		    	north=temp;
		    }
		    else if(direction[0]=='s'){
		    	temp=top;
		    	top=north;
		    	north=bottom;
		    	bottom=south;
		    	south=temp;
		    }
		    else if(direction[0]=='w'){
		    	temp=top;
		    	top=east;
		    	east=bottom;
		    	bottom=west;
		    	west=temp;
		    }
		    else if(direction[0]=='e'){
		    	temp=top;
		    	top=west;
		    	west=bottom;
		    	bottom=east;
		    	east=temp;
		    }
		}
		printf("%d\n",top);
	}

	return(0);
}

Measured memory_bytes: 604
loop do
    w, h = gets.split.map(&:to_i)
    break if w == 0
    a = (1..h).map { gets.split.map(&:to_i) }
    a << Array.new(w, 0)
    t = (1..h+1).map { Array.new(w, 0) }
    (0..w-1).each do |j|
        t[0][j] = (a[0][j] == 0 ? 1 : 0)
    end
    (0..h-1).each do |i|
        (0..w-1).each do |j|
            # next if t[i][j] == 0
            if i == h - 1
                t[i+1][j] += t[i][j]
            elsif a[i][j] == 2
                t[i+2][j] += t[i][j] if a[i+2][j] != 1
            else
                t[i+1][j-1] += t[i][j] if j > 0 && a[i+1][j-1] == 0
                t[i+1][j+1] += t[i][j] if j < w-1 && a[i+1][j+1] == 0
                t[i+1][j] += t[i][j] if a[i+1][j] != 1
            end
        end
    end
    puts t[-1].inject(:+)
end



Measured memory_bytes: 6916
#include <bits/stdc++.h>
using namespace std;
inline int calc(int n, int k) {
    while (n % k) {
        int d = n / k + 1;
        n -= (n % k + d - 1) / d * d;
    }
    return n / k;
}
int main() {
    int t;
    cin >> t;
    int ans = 0;
    while (t--) {
        int n, k;
        cin >> n >> k;
        ans ^= calc(n, k);
    }
    return puts(ans ? "Takahashi" : "Aoki"), 0;
}

Measured memory_bytes: 256
//header files
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,count=0,t1,t2,t3;
	long long L[100];
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>L[i];
	}
	sort(L,L+n);
	/*for (int i = 0; i < n; ++i)
	{
		cout<<L[i]<<endl;
	}
	return 0;
	for (int i = 2; i < n; ++i)
	{
		temp=i/2;
		if(L[i-2]!=L[i-1] && L[i-1]!=L[i])
			if(L[i-2]+L[i-1]>L[i])
				count+=((i-2)*(i-1))/2;
	}*/
	for (int i = 0; i < n-2; ++i)
	{
		for (int j = i+1; j < n-1; ++j)
		{
			for(int k=j+1;k<n;k++)
				if(L[i]!=L[j] && L[k]!=L[j])
					if(L[i]+L[j]>L[k])
						count++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 3572