akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    ll u = 1LL;
    rep(i, n) {
        u *= 2LL;
    }

    int a[n];
    rep(i, n) {
        int A;
        cin >> A;
        a[i] = A%2;
    }

    sort(a, a+n);

    if(a[n-1] == 0) {
        if(p == 1) {
            cout << 0;
        }
        else {
            cout << u;
        }
    }
    else {
        u /= 2LL;
        cout << u;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <tuple>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
namespace loquat {
class disjoint_set {
public:
	using value_type = size_t;
private:
	std::vector<value_type> m_parents;
	std::vector<value_type> m_ranks;
public:
	explicit disjoint_set(size_t n)
		: m_parents(n)
		, m_ranks(n)
	{
		for(size_t i = 0; i < n; ++i){
			m_parents[i] = i;
		}
	}
	value_type find(size_t x){
		if(m_parents[x] == x){ return x; }
		m_parents[x] = find(m_parents[x]);
		return m_parents[x];
	}
	value_type unite(size_t x, size_t y){
		x = find(x);
		y = find(y);
		if(x == y){ return x; }
		if(m_ranks[x] < m_ranks[y]){
			m_parents[x] = y;
			return y;
		}else if(m_ranks[x] > m_ranks[y]){
			m_parents[y] = x;
			return x;
		}else{
			m_parents[y] = x;
			++m_ranks[x];
			return x;
		}
	}
	bool same(size_t x, size_t y){
		return find(x) == find(y);
	}
};
}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using tiii = tuple<int, int, int>;
int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(n);
	for(int i = 0; i < n; ++i){ cin >> a[i] >> b[i]; }
	vector<vector<int>> conn(n);
	for(int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;
		--u; --v;
		conn[u].push_back(v);
		conn[v].push_back(u);
	}
	vector<tiii> vorder(n);
	for(int i = 0; i < n; ++i){
		vorder[i] = tiii(a[i], -b[i], i);
	}
	sort(vorder.begin(), vorder.end());
	loquat::disjoint_set ds(n);
	vector<bool> done(n);
	vector<ll> w(n), c(n);
	for(const auto& vp : vorder){
		const int u = get<2>(vp);
		vector<pll> ws;
		for(const int v : conn[u]){
			if(done[v] && !ds.same(u, v)){
				const int g = ds.find(v);
				ws.emplace_back(w[g], c[g]);
				ds.unite(u, v);
			}
		}
		const int g = ds.find(u);
		ll csum = 0;
		for(const auto& p : ws){ csum += p.second; }
		ll w_best = max(a[u], b[u]) + csum;
		for(const auto& p : ws){
			w_best = min(w_best, max(a[u], p.first + b[u]) + (csum - p.second));
		}
		w[g] = w_best;
		c[g] = csum + b[u];
		done[u] = true;
	}
	cout << *max_element(w.begin(), w.end()) << endl;
	return 0;
}


Measured memory_bytes: 12924
local arr = {}
local arr_temp = io.read()
for token in string.gmatch(arr_temp, "[^%s]+") do
   arr[#arr + 1] = tonumber(token)
end
local a, b = arr[1], arr[2]

if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end


Measured memory_bytes: 2768
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;

int N;

int main(int argc, char const *argv[]) {
	cin >> N;
	int a[3];
	for (int i = 0; i < N; i++) {
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a+3);
		if (a[0]*a[0] + a[1]*a[1] == a[2]*a[2]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
import kotlin.math.hypot

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val city = mutableListOf<Pair<Double, Double>>()
    for (i in 0..(n-1)) {
        val aa = readLine()!!.split(" ").map { it.toDouble() }.let {
            Pair(it[0], it[1])
        }
        city.add(aa)
    }

    var result = 0.0

    for (i in 0..(n-2)) {
        for (j in i..(n-1)) {
            result += hypot(city[i].first - city[j].first, city[i].second - city[j].second)
        }
    }
    println( 2.0 / n.toDouble() * result)
}

Measured memory_bytes: 36688
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAX 1000003

ll mod = (ll)998244353;
ll n,q;
vector<vll> que;
vll mini;

void solve(){
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,1,n) ans += ((n - 1)/i);
    cout << ans << br;
}
	

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}	

Measured memory_bytes: 3608
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    for (int i = 0; i <= k; i++) {
      int newB = b * ((int) Math.pow(2, i));
      for (int j = 0; j <= k; j++) {
        if (i + j > k) {
          continue;
        }
        int newC = c * ((int) Math.pow(2, j));
        if (a < newB && newB < newC) {
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}


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

bool cmp(const vector<long> &A, const vector<long> &B) {
        return (A.at(1)>B.at(1));
}

int main() {
        int N, M;
        cin >>N >>M;
        vector<long> A(N);
        for (int i=0; i<N; i++) cin >>A.at(i);
        vector<vector<long>> C(M, vector<long>(2));
        for (int i=0; i<M; i++) {
                cin >> C.at(i).at(0) >> C.at(i).at(1);
        }
        sort(C.begin(), C.end(), cmp);
        sort(A.begin(), A.end());
        long ss=0;
        int k=0;
        long CC;
        for (int i=0; i<A.size(); i++) {
                if (k<C.size()) {
                        if (C.at(k).at(0)>0) {
                                CC=C.at(k).at(1);
                                C.at(k).at(0)--;
                        } else {
                                k++;
                                if (k<C.size()) {
                                        CC=C.at(k).at(1);
                                        C.at(k).at(0)--;
                                } else CC=0;
                        }
                } else CC=0;
                ss += max(A.at(i), CC);
        }
        cout << ss << endl;
        return 0;
}

Measured memory_bytes: 6528
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();

    for i in 1..10 {
        for j in 1..10 {
            if n == i*j {
                return "Yes\n".to_string()
            }
        }
    }

    "No\n".to_string()
}
#[test]
fn test_solve() {
   assert_eq!(solve("10\n"), "Yes\n");
   assert_eq!(solve("50\n"), "No\n");
   assert_eq!(solve("81\n"), "Yes\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
#[allow(dead_code)]
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, n, a, b, c, buf;
	scanf("%d", &n);

	for(i=0; i<n; i++){
		scanf("%d%d%d", &a, &b, &c);
		if(a>b){
			buf=a;
			a=b;
			b=buf;
		}
		if(b>c){
			buf=b;
			b=c;
			c=buf;
		}
		if(a>b){
			buf=a;
			a=b;
			b=buf;
		}
		if(pow(a,2) + pow(b,2) == pow(c,2))
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    // ifstream fin("/Users/yonedatatsuya/Atcoder/data/1_07.txt");
    int n; cin >> n;
    map<int,int> mp;
    rep(i,n) {
        int x; cin >> x;
        mp[x]++;
    }
    if (mp.size() > 2) {
        cout << "No" << endl;
        return 0;
    }
    if (mp.size() == 2) {
        int l = inf, r = -1;
        for (P p : mp) {
            chmax(r,p.first);
            chmin(l,p.first);
        }
        if (r - l != 1 || mp[l] >= r) {
            cout << "No" << endl;
        } else {
            if (n + mp[l] >= 2 * r) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    if (mp.size() == 1) {
        int k;
        for (P p : mp) k = p.first;
        if (k + 1 == n || n >= 2 * k) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 8152
n=int(input())

m=n//6+n%6
for i in range(n+1):
  c=0
  t=i
  while t>0:
    c+=t%6
    t//=6
  t=n-i
  while t>0:
    c+=t%9
    t//=9
  m=min(m,c)

print(m)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main(){
    speed;
    ll n,k; cin>>n>>k;
    vector<ll> a(n);    for(auto &i:a)  cin>>i;
    vector<ll> dp(n,0);
    dp[n-1]=0;
    for(ll i=n-2;i>=0;i--){
        ll mn=INT_MAX;
        for(ll j=1;j<=k&&(i+j)<=n-1;j++){
            mn=min(mn,(abs(a[i+j]-a[i])+dp[i+j]));
        }
        dp[i]=mn;
    }
    cout<<dp[0]<<'\n';
    return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
a-=a/500*500;
if(b>=a)
cout<<"Yes";
else
cout<<"No";
system("pause");
return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char a[105][105];
char *b[105];
int n,l;
bool cmp(const char* x,const char* y)
{  return strcmp(x,y)<0;
}


int main()
{int i,j;
    cin>>n>>l;

    for(i=0;i<n;i++)
        {cin>>a[i];
         b[i]=a[i];
              }
   sort(b,b+n,cmp);
  for(i=0;i<n;i++)
     cout<<b[i];
  cout<<endl;

return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t,cac=0,ctle=0,cwa=0,cre=0;
    string ac="AC",tle="TLE",wa="WA",re="RE",str;
    cin>>t;
    while(t--)
    {
        cin>>str;
        if(str==ac)
        {
            cac++;
        }
        if(str==wa)
        {
            cwa++;
        }
        if(str==tle)
        {
            ctle++;
        }
        if(str==re)
        {
            cre++;
        }
    }
    cout<<"AC x "<<cac<<'\n';
    cout<<"WA x "<<cwa<<'\n';
    cout<<"TLE x "<<ctle<<'\n';
    cout<<"RE x "<<cre<<'\n';
    return 0;

    
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		// 入力フェーズ
				int s = int.Parse(Console.ReadLine());
        int m = 0;
        List<int> arr = new List<int>(){s};

        while(m <= 1000000)
        {
            // 次の項を求める
            int next = 0;
            int n = arr[m];
            if(n % 2 == 0)
            {
              // even
              next = n / 2;
            }else
            {
              // odd
              next = n * 3 + 1;
            }
            //Console.WriteLine(" next " + next);
            if(arr.Contains(next))
            {
              // 答え
              break;
            }else
            {
              arr.Add(next);
            }
            m++;
        }
        Console.WriteLine(m + 2);
    }
}


Measured memory_bytes: 13152
from collections import deque
from sys import maxsize
from copy import deepcopy


class Graph:
    def __init__(self, No_of_nodes):
        self.n = No_of_nodes
        self.adj = [[] for i in range(self.n)]

    def addEdge(self, a, b, w):
        self.adj[a].append([b, w])

    def BFS(self, start):
        visited = [False] * self.n
        depth = [0 for i in range(self.n)]
        que = deque()
        q = [start]
        que.append(start)
        visited[start] = True
        ans = ''
        f = 0
        while que:
            s = que.popleft()
            ans += str(s) + ' '
            for i in self.adj[s]:
                if not visited[i[0]]:
                    depth[i[0]] = s
                    que.append(i[0])
                    visited[i[0]] = True
        return depth

    def dijkstra(self, start):
        nxtpoint = [None for i in range(self.n)]
        distance = [maxsize for i in range(self.n)]
        distance[start] = 0
        q = deque()
        q.append(start)
        while len(q) != 0:
            a = q.pop()
            for u in self.adj[a]:
                b, w = u
                if distance[a] + w < distance[b]:
                    distance[b] = distance[a] + w
                    nxtpoint[b] = a
                    q.append(b)
        return nxtpoint


n, m = map(int, input().split())
ls = []
g = Graph(n)
ans = 'Yes\n'
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g.addEdge(a, b, 1)
    g.addEdge(b, a, 1)
point = g.BFS(0)
for i in range(1, n):
    if point[i] is None:
        ans = 'No'
        break
    else:
        ans += str(point[i] + 1) + '\n'
print(ans)


Measured memory_bytes: 67080
N = int(input())
An = list(map(int, input().split()))

m2, m4, rest = [], [], []
for i in range(N):
    if An[i] % 2 == 0 and An[i] % 4 != 0:
        m2.append(An[i])
    elif An[i] % 4 == 0:
        m4.append(An[i])
    else:
        rest.append(An[i])

ans = "No"
if len(m4) == len(rest):
    ans = "Yes"
if len(m4) == len(rest)-1 and len(m2) == 0:
    ans = "Yes"
if not len(rest):
    ans = "Yes"

print(ans)


Measured memory_bytes: 14252
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());

      var allCount = 0;
      for (int i = 1; i <= n; i++) {
        if (i % 2 == 0) continue;

        int count = 0;
        for (int j = 1; j <= i; j++) {
          if (i % j == 0) count++;
        }

        if (count == 8) {
          allCount++;
        }
      }

      System.out.println(allCount);
    }
  }
}


Measured memory_bytes: 32440
#include<stdio.h>//T2
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define Rof(i,a,b) for(register long long i=a;i>=b;i--)
#define int long long
using namespace std;
const int maxn=1e5+10;
int fa[maxn<<1];
inline int findfa(int i){
	return i==fa[i]?i:fa[i]=findfa(fa[i]);
}
inline void uni(int i,int j){
	int a=findfa(i),b=findfa(j);
	if(a!=b) fa[a]=b;
}
inline bool wxp(int i,int j){
	return findfa(i)==findfa(j);
}
int n,m;
signed main(){
	scanf("%lld%lld",&n,&m);
	Rof(i,n<<1,1){
		fa[i]=i;
	}
	For(i,1,m){
		int u,v;
		scanf("%lld%lld",&u,&v);
		uni(u,v+n);
		uni(u+n,v);
	}
	For(i,1,n){
		if(wxp(i,i+n)){
			printf("%lld\n",n*(n-1)/2-m);
			return 0;
		}
	}
	int ls=1,rs=0;
	For(i,2,n){
		if(wxp(i,1)){
			++ls;
		}else{
			++rs;
		}
	}
	printf("%lld\n",ls*rs-m);
}

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

int main(){
  int n; cin >> n; vector<int> l(n);
  for(int i = 0; i<n; i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  int ans = 0;
  for(int a=0; a<n-2; a++){
    for(int b = a+1; b<n-1; b++){
      int ab = l[a]+l[b];
      int i = lower_bound(l.begin(),l.end(),ab)-l.begin();
      int r = b+1;
      ans += i-r;
    }
  }
  cout << ans << endl;
}
      
  

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

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

  string s;
  cin >> s;

  int len = s.size();

  int ans = 0;
  for (int i = 1; i < len; i++) {
    s.erase(s.size() - 1);

    if (s.size() % 2 != 0) continue;

    int halfLen = s.size() / 2;

    string h1 = s.substr(0, halfLen);
    string h2 = s.substr(halfLen, halfLen);

    if (h1 == h2) ans = max(ans, halfLen * 2);
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector<int> G[100000+5];
int dp[100000+5];
int ans(int i)
{
    if(dp[i]!=0)    return dp[i];
    int lp = 0;
    for(auto c : G[i])
        lp = max(ans(c), lp);
    dp[i] = lp+1;
    // cout << i;
    return dp[i];
}

int main()
{
    IOS
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    // cout << "s";
    int gans = 0;
    REP(i,n)
        gans = max(gans, ans(i));
    
    cout << gans-1;
}

Measured memory_bytes: 8192
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	var cnt int
	for i := 0; i < 1000; i++ {
		pin := fmt.Sprintf("%03d", i)
		p1 := pin[0:1]
		p2 := pin[1:2]
		p3 := pin[2:3]

		i1 := strings.Index(s, p1)
		if i1 < 0 {
			continue
		}
		i2 := strings.Index(s[i1+1:], p2)
		if i2 < 0 {
			continue
		}
		i3 := strings.Index(s[i1+1+i2+1:], p3)
		if i3 < 0 {
			continue
		}
		cnt++
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, K;
    cin >> N >> K;
    vll A(N);
    map<ll, ll> to;
    set<int> seen;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
        A[i]--;
    }
    vll tikan = A,tmp = A,x(N);
    for (size_t i = 0; i < N; i++)
    {
        tikan[i]=i;
    }
    
    while (K > 0)
    {
        if (K % 2)
        {
            for (size_t i = 0; i < N; i++)
            {
                tikan[i] = tmp[tikan[i]];
            }
            
            
        }
        for (size_t i = 0; i < N; i++)
            {
                x[i]=tmp[tmp[i]];
            }
        tmp = x;
        K /= 2;
    }
    cout<<tikan[0]+1;
    return 0;
}

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int K, S;
    cin >> K >> S;
    ll ans = 0;
    rep2(x, 0, K+1) {
        rep2(y, x, K+1) {
            rep2(z, y, K+1) {
                if (x+y+z == S) {
                    if (x == y && y == z) {
                        ans += 1;
                    }
                    else if ((x == y && y != z) || (x != y && y == z)) {
                        ans += 3;
                    }
                    else {
                        ans += 6;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r=0;
  string s,t;
  cin >> s >> t;
  for(int i=0;i<3;i++){
    if (s.at(i)==t.at(i)){
      r++;
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 3572
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	int A, B, C;
	cin >> A >> B >> C;

	int answer = B / A;

	if (answer > C) {
		cout << C << endl;
	}
	else {
		cout << answer << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	for(int n,q;cin>>n>>q,n|q;){
		int a[100]={};
		for(int i=0;i<n;i++){
			int m; cin>>m;
			for(int j=0;j<m;j++){
				int d; cin>>d;
				a[d]++;
			}
		}
		int res=0;
		for(int i=0;i<100;i++)
			if(a[res]<a[i])
				res=i;
		cout<<(a[res]>=q?res:0)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 864
A,B=map(int,input().split())
swapA=A

if A<B:
    A=B
    B=swapA

Anext=A
Bnext=B
amari=1

while amari!=0:
    amari=Anext%Bnext
    if amari==0:
        Bnext=Bnext
    else:
        Anext=Bnext
        Bnext=amari

A=A
B=B/Bnext

print(int(A*B))
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-9;
const int    MOD = 1000000007;
using namespace std;
typedef pair<int,int> P;
typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A, const vec& b){
	int n = A.size();
	mat B(n,vec(n+1));
	rep(i,n) rep(j,n) B[i][j] = A[i][j];
	rep(i,n) B[i][n] = b[i];
	rep(i,n){
		int pivot = i;
		for(int j = i; j < n; j++){
			if(abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
		}
		swap(B[i],B[pivot]);
		if(abs(B[i][i]) < EPS) return vec();
		for(int j = i+1; j <= n; j++) B[i][j] /= B[i][i];
		rep(j,n){
			if(i != j){
				for(int k = i+1; k <= n; k++) B[j][k] -= B[j][i]*B[i][k];
			}
		}
	}
	vec x(n);
	rep(i,n) x[i] = B[i][n];
	return x;
}

int rnk;
vec tbl[10][10];

void solve(){
	vec v;
	rep(i,10) rep(j,10) tbl[i][j].clear();
	rep(i,rnk+3){
		double tmp; cin >> tmp;
		v.push_back(tmp);
	}
	rep(i,rnk+3){
		for(int j = i+1; j < rnk+3; j++){
			mat A;
			vec b;
			rep(k,rnk+3){
				if(i == k || j == k) continue;
				vec a;
				rep(l,rnk+1){
					a.push_back(pow(k,rnk-l));
				}
				b.push_back(v[k]);
				A.push_back(a);
			}
			tbl[i][j] = gauss_jordan(A,b);
			tbl[j][i] = tbl[i][j];
		}
	}
	/*
	rep(i,rnk+3){
		rep(j,rnk+3){
			if(i == j) continue;
			rep(k,rnk+1){
				cout << tbl[i][j][k] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}
	*/
	int ans = 0;
	int counter = 100000;
	rep(i,rnk+3){
		int cnt = 0;
		rep(j,rnk+3) for(int k = j+1; k < rnk+3; k++){
			if(i == j || i == k) continue;
			rep(l,rnk+1){
				if(abs(tbl[i][j][l]-tbl[i][k][l]) > 0.0001){
					cnt++;
					break;
				}
			}
		}
		if(cnt < counter){
			ans = i;
			counter = cnt;
		}
	}
	cout << ans << endl;
}

int main(){
	while(cin >> rnk){
		if(rnk == 0) break;
		solve();
	}
}

Measured memory_bytes: 1320
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
        int c = b % a;
        if(c == 0) System.out.println(a+b);
        else System.out.println(b-a);
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
const int mod = 1e9+7;

vector<int> graph[100001];
vector<ll> dp_b,dp_w;
vector<bool> visited;

void dfs(int p){
    visited[p] = true;
    for(auto e : graph[p]){
        if(!visited[e])
        dfs(e);
    }
    visited[p] = false;

    if(graph[p].size() == 1 && p != 0){
        dp_b[p] = 1;
        dp_w[p] = 1;
    }else{
        dp_b[p] = 1;
        dp_w[p] = 1;
        for(auto e : graph[p]){
            if(!visited[e]){
                dp_b[p] = (( dp_b[p] % mod) * (dp_w[e] % mod)) % mod;
                //dp_b[p] *= dp_w[e];
                dp_w[p] = (((dp_w[e] + dp_b[e]) % mod) * (dp_w[p] % mod)) % mod;
                //dp_w[p] *= (dp_w[e] + dp_b[e]);
            }
        }
    }

}

int main(){
    int N,num;
    cin >> N;
    dp_b.resize(N,0);
    dp_w.resize(N,0);
    visited.resize(N);

    int x,y;
    rep(i,N-1){
        cin >> x >> y;
        x--; y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    dfs(0);
    cout <<(dp_b[0] + dp_w[0])%mod << endl;
    return 0;
}


Measured memory_bytes: 15616
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class c{
    public static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        long x = Math.Abs(long.Parse(str[0]));
        long k = long.Parse(str[1]);
        long d = long.Parse(str[2]);
        long ans;
        long count = (x/d);
        if(k < count){
            ans = x - (k*d);
        }
        else{
            k -= count;
            x -= (count*d);
            ans = x;
            k %= 2;
            if(k == 1){
                ans -= d;
            }
        }
        Console.WriteLine(Math.Abs(ans));
    }
}


Measured memory_bytes: 17884
def solve(string):
    n, *a = map(int, string.split())
    ans = [sum(a) - 2 * sum(a[1::2])]
    for i in range(n - 1):
        ans.append(2 * a[i] - ans[-1])
    return " ".join(map(str, ans))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 20168
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9 + 7

    used = set()
    first = 0
    second = 0
    for i in range(N+1):
        if A[i] in used:
            second = i
            first = A.index(A[i])
        else:
            used.add(A[i])

    factrial = [1] * (N+2)
    for k in range(1, N+2):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (N+2)
    fact_inv[N+1] = pow(factrial[N+1], MOD - 2, MOD)
    for k in range(N, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    def comb(n, r, MOD):
        if n < 0 or r < 0 or n < r:
            return 0
        else:
            return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD

    m = first + (N - second)
    for i in range(1, N+2):
        ans = comb(N+1, i, MOD) - comb(m, i-1, MOD)
        print(int(ans) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20512
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int pay = int.Parse(Console.ReadLine());

			decimal rate = decimal.Parse("1.08");

			for (decimal i = 0; i <= pay; i++)
			{
				decimal price = (int)(i * rate);

				//int price = (int)Math.Floor(i * 1.08);

				if (Math.Abs(price - pay) < 1)
				{
					Console.WriteLine(i);
					return;
				}
			}

			Console.WriteLine(":(");


		}
	}


}


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

int main(int argc, char const *argv[])
{
	int a,b,k;
	cin>>a>>b>>k;
	set<int> ans;
	for (int i = 0; i < k; ++i)
	{
		if (a+i<=b)
		{
			ans.insert(a+i);
		}
		if (a<=b-i)
		{
			ans.insert(b-i);
		}
	}
	for (auto v:ans)
	{
		cout<<v<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.1415926535
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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


main(){
  int m;
  while(cin>>m,m){
    int v=0;
    long double s1=0;
    rep(i,m-1){
      int tv;
      cin>>tv;
      v+=tv;
      s1+=sin(M_PI/180*tv);
    }
    s1+=sin(M_PI/180*(360-v));
    v=0;
    cin>>m;
    rep(i,m-1){
      int tv;
      cin>>tv;
      v+=tv;
      s1-=sin(M_PI/180*tv);
    }
    s1-=sin(M_PI/180*(360-v));
    if(abs(s1)<EPS)cout<<0<<endl;
    else if(s1<0)cout<<2<<endl;
    else cout<<1<<endl;
  }
}

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

abcds = []
for i in range(q):
  abcds.append(list(map(int, input().split())))

# 数列の作成
import itertools
combs = list(itertools.combinations_with_replacement(list(range(1, m+1)), n))

ans = 0
for comb in combs:
  point = 0
 
  for abcd in abcds:
    if (int(comb[abcd[1]-1])-int(comb[abcd[0]-1]) == abcd[2]):
      point += abcd[3]
  ans = max(ans, point)
 
print(ans)

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

using namespace std;

int main()
{
	string a,b,c;
	cin>>a>>b>>c;
	if (a[a.size()-1] == int (b[0]))
	{
		if (b[b.size()-1]==c[0])
		{
			cout<<"YES";
		}
		else 
		{
			cout<<"NO";
		}
	}
	else 
	{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,c,q,k,x,y;
  vector<int> G[100005]={};
  map<P,int> edge;
  cin >> n;
  for(int i=0; i<n-1; i++) {
    cin >> a >> b >> c;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
    edge[P(a,b)]=edge[P(b,a)]=c;
  }
  cin >> q >> k;
  k--;
  ll dist[100005]={};
  for(int i=0; i<100005; i++) {
    dist[i]=INF;
  }
  //kから各頂点への距離をBFSで調べる
  queue<int> que;
  dist[k]=0;
  que.push(k);
  while(!que.empty()) {
    int p=que.front();
    que.pop();
    for(auto next:G[p]) {
      if(dist[next]==INF) {
        dist[next]=dist[p]+edge[P(p,next)];
        que.push(next);
      }
    }
  }
  while(q--) {
    cin >> x >> y;
    x--,y--;
    cout << dist[x]+dist[y] << "\n";
  }
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
 int a,b,k; cin>>k>>a>>b;
 for(int now = a; now<=b;now++){
   if(now%k==0){
     cout<<"OK"<<endl;
     return 0;
   }
 }
 cout<<"NG"<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N, L;
    cin >> N >> L;
    string s[200];
    for(int i=0; i<N; i++) {
        cin >> s[i];
    }
    sort(s, s+N);
    string catStr = "";
    for(int i = 0; i<N; i++) {
        catStr += s[i];
    }
    cout << catStr <<endl;
}

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

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    ll s = a[0];
    for(int i=1;i<n;i++) s ^= a[i];

    for(int i=0;i<n;i++){
        ll t = s^a[i];
        cout << t << " ";
    }
    printf("\n");
    return 0;
}

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

int main()
{
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  C *= 2;

  ll ans = 0;
  if (A+B >= C) {
    int min_num = min(X, Y);
    ans += C * min_num;
    X -= min_num;
    Y -= min_num;
  }
  if (A >= C) {
    ans += C * X;
    X = 0;
    Y -= X;
  }
  if (B >= C) {
    ans += C * Y;
    Y = 0;
    X -= Y;
  }
  if (X < 0) {
    X = 0;
  }
  if (Y < 0) {
    Y = 0;
  }
  ans += A * X;
  ans += B * Y;
  cout << ans << endl;
}


Measured memory_bytes: 256
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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! {
        n: usize,
        m: usize,
        a: [u64;n],
        bc: [(usize,u64);m],
    }
    let mut bc = bc;

    let mut v: Vec<_> = a.iter().map(|&x| (1usize, x)).collect();
    v.append(&mut bc);

    v.sort_by_key(|&x| !x.1);

    let mut ans = 0;
    let mut cnt = 0;

    for (num, val) in v {
        if cnt + num >= n {
            ans += val * (n - cnt) as u64;
            break;
        }
        ans += val * num as u64;
        cnt += num;
    }

    println!("{}", ans);
}


Measured memory_bytes: 14588
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int main()
{
	int N,M;
	char U[256][11];
	char T[11];
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> U[i];
	}
	cin >> M;
	int cnt = 0;
	for (int i = 0; i < M; i++)
	{
		bool find = false;
		cin >> T;

		for (int j = 0; j < N; j++)
		{
			int c = strcmp(U[j], T);
			if (c == 0)
			{
				find = true;
				cnt++;
				break;
			}
		}

		if (find)
		{
			if (cnt % 2== 1)
			{
				cout << "Opened by "<< T << endl;
			}
			else
			{
				cout << "Closed by " << T << endl;
			}
		}
		else
		{
			cout << "Unknown " << T << endl;
		}
	}
	return 0;
}

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

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

constexpr int dx[] = {1, -1, 0, 0};
constexpr int dy[] = {0, 0, 1, -1};
constexpr int MAX_H = 60;
constexpr int MAX_W = 10;

int w, h;
int num;
vector<vector<int>> cnt;
vector<int> on, xl, xr;
bool visited[MAX_H][MAX_W];
int label[MAX_H][MAX_W];

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

void calc_unique_label(vector<string> &field) {
	const int h = field.size();
	const int w = field[0].size();

	num = 0;
	memset(label, -1, sizeof(label));
	for(int i = h - 1; i >= 0; --i) {
		for(int j = 0; j < w; ++j) {
			const char &c = field[i][j];
			if(label[i][j] == -1 && c != '.') {
				queue<pair<int, int>> que;
				que.push({j, i});
				label[i][j] = num;

				while(!que.empty()) {
					const int x = que.front().first;
					const int y = que.front().second;
					que.pop();

					for(int d = 0; d < 4; ++d) {
						const int nx = x + dx[d];
						const int ny = y + dy[d];
						if(out(nx, ny)) continue;
						if(label[ny][nx] == -1 && field[ny][nx] == c) {
							label[ny][nx] = num;
							que.push({nx, ny});
						}
					}
				}

				++num;
			}
		}
	}
}

void calc(int x, int y) {
	const int &l = label[y][x];
	visited[y][x] = true;
	++cnt[l][x];

	for(int d = 0; d < 4; ++d) {
		const int nx = x + dx[d], ny = y + dy[d];
		if(out(nx, ny)) {
			if(d == 2) {
				chmin(xl[l], x);
				chmax(xr[l], x);
			}
			continue;
		}

		if(out(nx, ny)) continue;
		if(label[ny][nx] != -1 && !visited[ny][nx]) {
			calc(nx, ny);
		}

		if(label[ny][nx] != l && label[ny][nx] != -1 && d == 2) {
			chmin(xl[l], x);
			chmax(xr[l], x);
			on[l] = label[ny][nx];
		}
	}
}

bool dfs(int idx) {
	for(int i = 0; i < num; ++i) {
		if(on[i] == idx) {
			if(!dfs(i)) return false;
			for(int x = 0; x < w; ++x) {
				cnt[idx][x] += cnt[i][x];
			}
		}
	}

	int sum = 0;
	int weight_sum = 0;

	for(int x = 0; x < w; ++x) {
		sum += cnt[idx][x];
		weight_sum += cnt[idx][x] * x;
	}

	const double g = (double)weight_sum / sum;
	return xl[idx] - 0.5 < g && g < xr[idx] + 0.5;
}

int main() {
	while(cin >> w >> h && w) {
		vector<string> field(h);
		for(auto &e : field) cin >> e;
		calc_unique_label(field);
		cnt.assign(num, vector<int>(w, 0));
		on.assign(num, -1);
		xl.assign(num, w + 1);
		xr.assign(num, 0);
		memset(visited, false, sizeof(visited));

		for(int x = 0; x < w; ++x) {
			if(label[h - 1][x] == 0) {
				calc(x, h - 1);
				break;
			}
		}

		cout << (dfs(0) ? "STABLE" : "UNSTABLE") << endl;
	}

	return 0;
}

Measured memory_bytes: 1252
n = int(input())
A = list(map(int,input().split()))
B = [0]*3
for i in A:
    if i%4==0: B[0]+=1
    elif i%2==0: B[1]+=1
    else: B[2]+=1
print('Yes' if B[0]==0 and B[2]==0 or B[0]>=B[2] or B[1]==0 and B[2]-B[0]==1 else 'No')


Measured memory_bytes: 14252
N,M = map(int,input().split())
array2 = [0 for i in range(M+1)]
for i in range(N):
  array = list(map(int,input().split()))
  array.pop(0)
  for j in array:
    array2[j] += 1
c = 0
for k in array2:
  if k == N:
    c += 1
print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ll long long
using namespace std;
int32_t main(){
    string s;
    cin >> s;

    cout << ((s.at(2) == s.at(3) && s.at(4) == s.at(5))?"Yes":"No");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

int main()
{
    int n;
    cin >> n;
    for (int i = 9; i > 0; i--)
    {
        if (n%i==0)
        {
            n=n/i;
            break;
        }
        
    }
    if (n<10)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

int n;
ll a[200001];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a, a+n, greater<ll>());
    ll ans=a[0];
    int cnt = n-2, ptr=1;
    while(cnt>0){
        if(cnt>=2){
            ans += 2*a[ptr];
            ptr++;
            cnt-=2;
        }else{
            ans += a[ptr];
            ptr++;
            cnt--;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;

//dp[i][j][k] :=???(?????????????????????i(mod2)??§A???????????????j????????§?¬???????k??????????????????????????????
//?????????????????????????§???°???????°??????????) (k==0:A k==1:B)
int dp[2][5010][2];
int main(void){
	int n; cin >> n;
	vector<int> v(n);
	rep(i, n - 1) cin >> v[i];
	rep(i, 2)rep(j, 5010)rep(k, 2)dp[i][j][k] = INF;

	dp[0][0][0] = 0;
	dp[0][0][1] = 0;
	//??????dp
	for (int i = 0; i < n; ++i){
		rep(j, 5010)rep(k, 2)dp[(i + 1) % 2][j][k] = INF;//dp???????????¨????????????
		for (int j = 0; j <= n / 2; ++j){
			for (int k = 0; k < 2; ++k){
				if(dp[i % 2][j][k] == INF) continue;
				//???????????????????????????
				if(k == 0){
					dp[(i + 1) % 2][j + 1][k] = min(dp[(i + 1) % 2][j + 1][k], dp[i % 2][j][k]);
				}else{
					dp[(i + 1) % 2][j][k] = min(dp[(i + 1) % 2][j][k], dp[i % 2][j][k]);
				}
				//?????????????????????
				if(k == 0){
					dp[(i + 1) % 2][j + 1][1] = min(dp[(i + 1) % 2][j + 1][1], dp[i % 2][j][k] + v[i]);
				}else{
					dp[(i + 1) % 2][j][0] = min(dp[(i + 1) % 2][j][0], dp[i % 2][j][k] + v[i]);
				}
			}
		}
	}

	int ans = INF;
	rep(k, 2){
		ans = min(ans, dp[n % 2][n / 2][k]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1308
#include<stdio.h>

int main(void)
{
    int H, W, i, j;
    for (;;) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W ==0) break;
        for (i=0; i<H; i++) {
            for (j=0; j<W; j++) printf("#");
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2028
#include<stdio.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(i=0; i<n; i++)

int main(void)
{
	int i;
	char a[4];
	char b[7][4]={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	scanf("%s", a);
	rep(i,7){
		if(strcmp(a,b[i]) == 0){
			printf("%d", 7-i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main {
	int x,y;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		y = sc.nextInt();
		while(x != 0 || y != 0){
			if(x > y){
				System.out.println(y + " " + x);
			}else{
				System.out.println(x + " " + y);
			}
			x = sc.nextInt();
			y = sc.nextInt();
		}
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

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

MOD = 1000000007

f = [1]
for i in range(1, 200000):
    f.append(f[-1] * i % MOD)

def inv(x):
    res = 1
    k = MOD - 2
    y = x
    while (k >= 1):
        if(k % 2 == 1):
            res = (res * y) % MOD
        y = (y ** 2) % MOD
        k = k // 2
    return res

def comb(n, k):
    if n < k:
        return 0
    a = f[n]
    b = f[n-k]
    c = f[k]
    bc = (b * c) % MOD
    return (a * inv(bc)) % MOD

def solve(N: int, K: int):
    for i in range(1, K+1):
        print(comb(K-1, i-1) * comb(N-K+1, i) % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11308
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var max = vals.Max();
            var remain = vals.Sum() - max;
            if (remain > max)
            {
                Console.WriteLine("Yes");
            }else
            {
                Console.WriteLine("No");
            }
        }

    }
}
//A

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    if (b[0] != 1) {
        cout << -1 << endl;
        return 0;
    }
    int num = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == num + 1) num++;
    }
    cout << n - num << endl;
    return 0;
}


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

int balls[10];

bool dfs(int i=0,int b_top=0,int c_top=0){
  //10個のボールを落とせたらtrue
  if(i == 10) return true;
  
  //Bのほうに入れる
  if(balls[i] > b_top && dfs(i+1,balls[i],c_top))
    return true;

  //Cの方に入れる
  if(balls[i] > c_top && dfs(i+1,b_top,balls[i]))
    return true;

  return false;
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++) cin >> balls[j];
    cout << (dfs() ? "YES":"NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 1152