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

#define INF 0x7fffffff

int n;
int m;
int limh;
int as[11451419];
int bs[11451419];
int cs[11451419];
int hs[11451419];
int es[11451419];
int vs[11451419];

class UnionFind {
public:
  int size;
  vector<int> par;
  vector<int> height;

  UnionFind(int n) {
    par.resize(n);
    height.resize(n);
    for (int i=0; i<n; i++) {
      par[i] = i;
      height[i] = 0;
    }
    size = n;
  }
    
  int find(int v) {
    if (par[v] != v) return par[v] = find(par[v]);
    return v;
  }

  bool same(int u, int v) {
    return find(u) == find(v);
  }

  void unite(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return;
  
    size--;
    if (height[u] > height[v]) par[v] = u;
    else if (height[v] > height[u]) par[u] = v;
    else {
      par[v] = u;
      height[v]++;
    }
  }
};

bool CompareVertex(int x, int y) {
  return hs[x] > hs[y];
}

bool CompareEdge1(int x, int y) {
  int at = min(hs[as[x]], hs[bs[x]]);
  int bt = min(hs[as[y]], hs[bs[y]]);
  if (at != bt) return at > bt;
  return cs[x] < cs[y];
}

bool CompareEdge2(int x, int y) {
  int at = min(hs[as[x]], hs[bs[x]]);
  int bt = min(hs[as[y]], hs[bs[y]]);
  if (min(at, bt) >= limh) return cs[x] < cs[y];
  if (at != bt) return at > bt;
  return cs[x] < cs[y];
}

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) return 0;

    int maxv;
    int maxh = -1;
    for (int i=1; i<=n; i++) {
      scanf("%d", &hs[i]);
      if (maxh < hs[i]) {
        maxh = hs[i];
        maxv = i;
      }
      vs[i-1] = i;
    }

    for (int i=0; i<m; i++) {
      scanf("%d%d%d", &as[i], &bs[i], &cs[i]);
      es[i] = i;
    }

    sort(vs, vs+n, CompareVertex);

    limh = maxh;
    UnionFind uf1(n+1);
    for (int i=0; i<n; i++) {
      int v = vs[i];
      for (int j=0; j<m; j++) {
        if (hs[as[j]] >= hs[v] && hs[bs[j]] >= hs[v]) {
          uf1.unite(as[j], bs[j]);
        }
      }

      for (int j=0; j<i; j++) {
        int u = vs[j];
        if (!uf1.same(u, v)) {
          limh = hs[vs[i+1]];
          break;
        }
      }
    }
    //cout << "limh: " << limh << "\n";

    sort(es, es+m, CompareEdge2);

    int ans = 0;
    UnionFind uf2(n+1);
    for (int i=0; i<m; i++) {
      int idx = es[i];
      int u = as[idx];
      int v = bs[idx];
      int c = cs[idx];
      if (uf2.same(u, v)) continue;
      uf2.unite(u, v);
      ans += c;
    }

    for (int i=1; i<=n; i++) {
      if (!uf2.same(1, i)) {
        ans = 0;
        break;
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 3580
#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>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int kakaku(int n){
	int value=1150;

	n-=10;
	if(n>0)value+=125*n;
	n-=10;
	if(n>0)value+=15*n;
	n-=10;
	if(n>0)value+=20*n;
	return value;
}

int main(){
	int sui,sen,kon;
	

	sen=4280;
	
	
	while(cin>>sui){
		if(sui==-1)break;
		kon=kakaku(sui);
		cout<<sen-kon<<endl;

	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	int ans=-1000000000;
	for(int i=2;i<32;i++){
		int b=i*i,c=i;
		for(;;){
			if(b*c<=a){
				b=b*c;
			}
			else{
				break;
			}
		}
		if(b<=a){
			ans=max(ans,b);
		}
	}
	if(ans==-1000000000){
		ans=1;
	}
	cout<<ans;
}

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

int main(void) {
	int N, M, P, X, per_m, champ = 0;
	double sum_money = 0;

	while (cin >> N >> M >> P, N | M | P) {
		per_m = champ = sum_money = 0;

		for (int i = 1; i <= N; i++) {
			cin >> X;
			if (i == M) champ = X;
			sum_money += X;
		}
		sum_money = sum_money * 100 - sum_money * (double)P;
		if (champ != 0) {
			per_m = sum_money / champ;
		} else {
			per_m = 0;
		}
		cout << per_m << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
H = [int(i) for i in input().split()]

min_value = 1
ans = 'Yes'
for i in range(N-1):
    if H[i] > min_value:
        H[i] -= 1
    if H[i] > H[i+1] or H[i] < min_value:
        ans = 'No'
        break
    min_value = H[i]
    
print(ans)

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


int main() {
    int n,s;
    cin >> n >> s;
    vector<ll> dp(s+1),p(s+1);
    ll ans = 0;
    vector<int> a(n);
    ll mod = 998244353;
    rep(i,n){
        cin >>a[i];
        
    }
    dp[0] = 1;
    rep(i,n){
        
        p = dp;
        int ai = a[i];
        
        rep(j,s+1){
            dp[j] = p[j]*2;
            if(j>=ai) dp[j] += p[j-ai]; 
            dp[j] %= mod;
        }
    }
    ans = dp[s]%mod;
    cout << ans << endl;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;cin>>N>>K;
  map<int,int>mp;
  for(int X=0;X<K;X++){
    int D;cin>>D;
    for(int Y=0;Y<D;Y++){
      int A;cin>>A;mp[A]++;
    }
  }
  int U=0;
  for(auto p:mp){
    auto V=p.second;U++;
  }
  cout<<N-U<<endl;
}

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

const int N = 1e5;

int li[N+5];
int n;
int cnt1[N+5], cnt2[N+5];
int main()
{
   memset(cnt1,0,sizeof(cnt1));
   memset(cnt2,0,sizeof(cnt2));
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
      scanf("%d",&li[i]);
      if(i%2==0)
      {
         cnt1[li[i]]++;
      }
      else
      {
         cnt2[li[i]]++;
      }
   }
   int mx1,mx2,id1,id2;
   mx1=mx2=0;
   id1=id2=-1;
   for(int i=1;i<=N;i++)
   {
      if(id1==-1)
      {
         mx1 = cnt1[i];
         id1 = i;
      }
      else if(cnt1[i] > mx1)
      {
         mx2 = mx1;
         id2 = id1;
         id1 = i;
         mx1 = cnt1[i];
      }
      else if(id2==-1)
      {
         mx2 = cnt1[i];
         id2 = i;
      }
      else if(cnt1[i]>mx2)
      {
         mx2 = cnt1[i];
         id2 = i;
      }
   }
   int mx3,mx4,id3,id4;
   mx3=mx4=0;
   id3=id4=-1;
   for(int i=1;i<=N;i++)
   {
      if(id3==-1)
      {
         mx3 = cnt2[i];
         id3 = i;
      }
      else if(cnt2[i] > mx3)
      {
         mx4 = mx3;
         id4 = id3;
         id3 = i;
         mx3 = cnt2[i];
      }
      else if(id4==-1)
      {
         mx4 = cnt2[i];
         id4 = i;
      }
      else if(cnt2[i]>mx4)
      {
         mx4 = cnt2[i];
         id4 = i;
      }
   }
   if(id1!=id3) printf("%d\n",n-mx1-mx3);
   else printf("%d\n",n-max(mx1+mx4,mx3+mx2));
 	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    bool exist=false;
    REP(x, 1, 50001){
        double tmp=1.08*x;
        if((ll)tmp==n){
            cout<<x<<endl;
            exist=true;
            break;
        }

        if(x>n) break;
    }
    if(!exist) cout<<":("<<endl;
    return 0;
}

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

int main() {
    //freopen( "C:\\Users\\ehab\\Desktop\\problems\\in.txt" , "r" , stdin );

    string s;
    cin >> s;

    bool flag = false; int counter = 0;
    for ( int i = 0; i < s.length(); i++ ){
        if ( i >= 2 && i < s.length() - 1 && s[i] == 'C' ){
            flag = true;
        }
        if ( islower( s[i] ) ){
            counter++;
        }
    }

    if ( s[0] == 'A' && flag == true && counter == s.length() - 2 ){
        cout << "AC";
    }
    else{
        cout << "WA";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int L;
  cin >> N >> L;
  int min = L;
  int max = L + N - 1;
  int sum = 0;
  
  for (int i = 1; i <= N; i++){
    sum += L + i - 1;
    //cout << L << endl;
    //cout << sum << endl;
  }
  if (max <= 0){
    cout << sum - max << endl;
  }
  else if (min >= 0){
    cout << sum - min << endl;
  }
  else {
    cout << sum << endl;
  }
}

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


using namespace std;

int main() {
	int s;
	cin >> s;
	
	vector<int> ans(1000000,0);
	ans.at(s)++;
	int a = s;
	int answer = 1;
	bool match = false;
	
	while (match == false){
		if(a % 2 == 1){
			//ai-1が奇数
			a = 3*a + 1;
		} else {
			//ai-1が偶数
			a = a / 2;
		}
		ans.at(a)++;
		if (ans.at(a) > 1) {
			match = true;
		}
		answer++;
	}
	
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>

int main(){
        int d;
        while(1){
                scanf("%d", &d);
                if(d<0) break;

                long ans=0, digit=1;
                while(d){
                        ans += (d%4)*digit;
                        d /= 4;
                        digit *= 10;
                }
                printf("%ld\n", ans);
        }
        return 0;
}


Measured memory_bytes: 2028
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=2000;
const int INF=(int)1e9+5;
int n,k,q,A[MAXN+5],ans=INF;
void SOLVE(int x)
{
	vector<int> pri;
	int i=0;
	while(i<n)
	{
		vector<int> que;
		while(A[i]<x && i<n) i++;
		while(A[i]>=x && i<n) que.push_back(A[i++]);
		if(que.size()>=k)
		{
			sort(que.begin(),que.end());
			for(int j=0;j<(int)que.size()-k+1;j++)
				pri.push_back(que[j]);
		}
	}
	sort(pri.begin(),pri.end());
	if((int)pri.size()>=q)
		ans=min(ans,pri[q-1]-pri[0]);
}
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=0;i<n;i++)
		scanf("%d",&A[i]);
	for(int i=0;i<n;i++)
		SOLVE(A[i]);
	printf("%d\n",ans);
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<ll>x(n),y(n);
  vector<P>pxpy(n),pxmy(n),mxpy(n),mxmy(n);
  rep(i,n){
    cin>>x[i]>>y[i];
    pxpy[i]=P(x[i]+y[i],i);
    pxmy[i]=P(x[i]-y[i],i);
    mxpy[i]=P(-x[i]+y[i],i);
    mxmy[i]=P(-x[i]-y[i],i);
  }
  sort(pxpy.begin(),pxpy.end());
  sort(pxmy.begin(),pxmy.end());
  sort(mxpy.begin(),mxpy.end());
  sort(mxmy.begin(),mxmy.end());
  int p1=pxpy[n-1].second;
  int p2=pxpy[0].second;
  int p3=pxmy[n-1].second;
  int p4=pxmy[0].second;
  int p5=mxpy[n-1].second;
  int p6=mxpy[0].second;
  int p7=mxmy[n-1].second;
  int p8=mxmy[0].second;
  cout<<max({abs((x[p1]+y[p1])-(x[p2]+y[p2])),
            abs((x[p3]-y[p3])-(x[p4]-y[p4])),
            abs((-x[p5]+y[p5])-(-x[p6]+y[p6])),
            abs((-x[p7]-y[p7])-(-x[p8]-y[p8]))})<<endl;
}

Measured memory_bytes: 12752
package main

import "fmt"

func main() {
	var n, q int
	var s string
	fmt.Scan(&n, &q, &s)
	ls := make([]int, q)
	rs := make([]int, q)
	for i := range ls {
		fmt.Scan(&ls[i], &rs[i])
	}

	ns := make([]int, n)
	for i := 1; i < n; i++ {
		if s[i-1:i+1] == "AC" {
			ns[i] = ns[i-1] + 1
		} else {
			ns[i] = ns[i-1]
		}
	}
	ms := make([]int, n)
	for i := 0; i < n-1; i++ {
		if s[i:i+2] == "AC" {
			if i == 0 {
				ms[i] = 1
			} else {
				ms[i] = ms[i-1] + 1
			}
		} else {
			if i == 0 {
				ms[i] = 0
			} else {
				ms[i] = ms[i-1]
			}
		}
	}

	for i, l := range ls {
		r := rs[i]
		if l == 1 {
			fmt.Println(ns[r-1])
		} else {
			fmt.Println(ns[r-1] - ms[l-2])
		}
	}
}


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

int main(void){
    double n;
    cin >> n;
    double ans = 0;
    double num = 0;
    for(int i=1;i<=n;i++){
        if(i%2==1){
            num++;
        }
    }
    ans = num/n;
    cout << ans << endl;
    
    return 0;
}



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

int main()
{
    int n, x, t, div, rem, ans = 0;
    cin >> n >> x >> t;
    if (n > x)
    {
        div = n / x;
        rem = n % x;
        if (rem > 0)
        {
            ++div;
        }
        ans = (div * t);
    }
    else if (n <= x)
    {
        ans = t;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3544
def gaus(n):
    if n//1<n:
        return int(n+1)
    return int(n)
def hante(S):
    n=len(S)
    for i in range(n//2):
        if S[i]!=S[n-i-1]:
            return False
    return True
S=input()
S1=S[:len(S)//2]
S2=S[gaus(len(S)/2):]

if hante(S)==True and hante(S1)==True and hante(S2)==True:
    print("Yes")
else:
    print("No")


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int N;
    cin>>N;
    int t = 6,s = 9;
    vector<int> v(100010,INF);
    v[0]=0;
    vector<int> a;
    a.push_back(1);
    while(t<100010){
        a.push_back(t);
        t*=6;
    }
    while(s<100010){
        a.push_back(s);
        s *= 9;
    }
    int cnt = 0;
    while(v[N]==INF){
        rep(i,100010){
            if(v[i]==cnt){
                for(auto x:a){
                    if(x+i<100010){
                        chmin(v[i+x],cnt+1);
                    }
                }
            }
        }
        cnt++;
    }
    cout<<v[N]<<endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
/* DSU 
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/ 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
 
using namespace std;

int main()
{
	fast;
	ll n,k; cin>>n>>k;
	ll arr[n];
	for(ll i = 0; i < n; i++)
	{
		cin>>arr[i];
	}
	ll sum = 0;
	sort(arr,arr+n);
	for(ll i = 0; i < n && k > 0; i++)
	{
		sum += arr[i];
		k--;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main()
{
    int a,b;
    scanf(" %d%d",&a,&b);
    1<=a&&a<=100;
    1<=b&&b<=100;

    if((a+b)%3==0||a%3==0||b%3==0){printf("Possible");}
    else {printf("Impossible");}

    return 0;
}






Measured memory_bytes: 128
object Main extends App{
  val k_n = io.StdIn.readLine().split(' ').map(_.toInt)
  val k = k_n(0)
  val n = k_n(1)
  val An = io.StdIn.readLine().split(' ').map(_.toInt)
  val candidate = for(i <- 0 until n) yield (k + An((i+n-1)%n) - An(i)) % k
  println(candidate.min)
}


Measured memory_bytes: 58464
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = sum([(p+1)/2 for p in P[:K]])
tmp = ans
for i in range(N-K):
    tmp = tmp - (P[i]+1)/2 + (P[K+i]+1)/2
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 25060
void solve(){
}
void main(){
	int n = inelm();
	int a = inelm();
	(n*n-a).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
alias instr = () => readln().chomp();
T inelm(T= int)(){ return to!(T)( readln().chomp() ); }
T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }



Measured memory_bytes: 2660
fun main(args: Array<String>){
    val a =readLine()!!.split(" ")
    val cat :Int = a[0].toInt()
    val ani :Int = a[1].toInt()
    val sumcat :Int =a[2].toInt()
    val ans = if(cat + ani >= sumcat && cat <= sumcat) "YES" else "NO"
    println(ans)
}



Measured memory_bytes: 35896
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long LL;
const LL inf = 0x3f3f3f3f3f3f3f3f;
const int MaxN = 2e5 + 5;

int n;
LL dp[MaxN],a[MaxN];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n; i++) scanf("%lld",&a[i]);
	dp[0] = 0;
	dp[1] = 0;
	for(int i = 2;i <= n; i++) dp[i] = inf;
	for(int i = 2;i <= n; i++){
		if(i == 2) dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
		else dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]),dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	printf("%lld\n",dp[n]);
}

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

//read_kaisetsu
int main() {
    int n,m;cin>>n>>m;
    pair<int,int>a[m];
    rep(i,m)cin>>a[i].second>>a[i].first;
    sort(a,a+m);

    int ans=1;
    int tmp=a[0].first-1;
    rep(i,m-1){
        if(a[i+1].second<=tmp)continue;
        else {
            tmp=a[i+1].first-1;
            ++ans;
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4392
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,m,d;
    cin >> n >> m >> d;
    int b = d == 0 ? n : (2 * (n - d));
    //cout << 1.0 * b * (m - 1) / n / n << endl;
    printf("%.12lf", 1.0 * b * (m - 1) / n / n);
}

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

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, M; cin >> N >> M;
    vector<ll> dp(1 << N, LONGINF);
    dp[0] = 0;

    vector<ll> A(M), B(M);
    vector<ll> vari(M);

    for(int i=0; i<M; i++) {
        cin >> A[i] >> B[i];

        ll bit = 0;
        for(int j=0; j<B[i]; j++) {
            int c; cin >> c; c--;
            bit |= (1 << c);
        }
        vari[i] = bit;
    }

    for(int bit=0; bit<(1<<N); bit++) {
        for(int i=0; i<M; i++) {
            chmin(dp[bit | vari[i]], dp[bit] + A[i]);
        }
    }

    ll ans = dp[(1 << N) - 1];
    cout << (ans == LONGINF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
int _reverse(int n){
	int tmp = 0;
	while(n>0){
		tmp = tmp*10 + (n%10);
		n/=10;
	}
	return tmp;
}
int main(){
	int A,B;
	cin>>A>>B;
	//string s,r;
	int cnt =0;
	for(int n=A;n<=B; n++){
		//s = to_string(n);
		if(n==_reverse(n)) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    s = input()
    t = input()
    print("Yes" if s == t[:-1] else "No")
resolve()

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    if len(set([A, B, C]))==2:
        print(YES)
    else:
        print(NO)
    # return


# Generated by 1.1.6 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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	while (N) {
		ans = 0;
		for (int i = 3; i <= N; i+=2) {
			if (N%i)continue;
			if (N / i >= (i+1)/2) {
				//cout << i << endl;
				ans++;
			}
		}
		for (int i = 2; i <= N; i += 2) {
			if ((N * 2) % i)continue;
			if (!((N * 2 / i) % 2))continue;
			if (N * 2 / i > i) {
				//cout << i << endl;
				ans++;
			}
		}
		cout << ans << endl;
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_V = 100,MAX_E = 10000;
int V,E;
class Union_Find{
private:
	int par[MAX_V],rank[MAX_V];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};
void Union_Find::init(int n){
	for(int i = 0;i < n;++i){
		par[i] = i;
		rank[i] = 0;
	}
}
int Union_Find::find(int x){
	if(par[x] == x){
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
void Union_Find::unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rank[x] < rank[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
		if(rank[x] == rank[y]) rank[x]++;
	}
}
bool Union_Find::same(int x,int y){
	return find(x) == find(y);
}
struct edge{
	int u,v,cost;
};
edge es[MAX_E];
bool comp(const edge& e1,const edge& e2){
	return e1.cost < e2.cost;
}
int kruskal(){
	sort(es,es + E,comp);
	Union_Find u;
	u.init(V);
	int res = 0;
	for(int i = 0;i < E;++i){
		edge e = es[i];
		if(!u.same(e.u,e.v)){
			u.unite(e.u,e.v);
			res += e.cost;
		}
	}
	return res;
}
int main(){
	edge e;
	int u,v,cost;
	char a;
	while(cin >> V,V){
		cin >> E;
		for(int i = 0;i < E;++i){
			cin >> u >> a >> v >> a >> cost;
			e.u = u;
			e.v = v;
			e.cost = (cost / 100) - 1;
			es[i] = e;
		}
		cout << kruskal() << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from fractions import gcd

def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i*i <= n:
    while n%i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  # 重複なし
  return set(table)

A, B = map(int, input().split())
n_gcd = gcd(A, B)
n_div = prime_decomposition(n_gcd)
print(len(n_div)+1)

Measured memory_bytes: 5048
nn = 200200
P = 998244353

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

C = lambda a, b: fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0
N, M, K = map(int, input().split())
if M == 1:
    print(1 if K == N - 1 else 0)
    exit()
ans = 0
t = pow(M-1, N-1, P)
m = pow(M-1, P-2, P)
for i in range(K+1):
    ans = (ans + t * C(N-1, i)) % P
    t = t * m % P
print(ans * M % P)

Measured memory_bytes: 72404
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVVld = vector<VVld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N; cin >> N;
  Vll a(N);
  rep(i, N) cin >> a[i];
  
  VVll dp(N+1, Vll(N+1));

  rep(d, N) rep(i, N) {
    int j = i+d+1;
    if (j > N) continue;
    dp[i][j] = max(a[i] - dp[i+1][j], a[j-1] - dp[i][j-1]);
  }

  ll ans = dp[0][N];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 72704
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dp[111][5][5][5];
bool check(ll i,ll j,ll k,ll l){
  bool fl=true;
  return !((i==0&&j==1&&k==2) || (i==0&&j==2&&k==1) || (i==1&&j==0&&k==2) || 
    (j==0&&k==1&&l==2)||(j==0&&k==2&&l==1)||(j==1&&k==0&&l==2)||(i==0&&j==1&&l==2)||(i==0&&k==1&&l==2));
}
vi make_vec(ll i,ll j,ll k){
  vi ret;
  for(ll l=0;l<4;l++){
    if(check(i,j,k,l))ret.pb(l);
  }
  return ret;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  n-=3;
  // 0:A,1:G,2:C,3:T
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
	if(i==0&&j==1&&k==2 || i==0&&j==2&&k==1 || i==1&&j==0&&k==2)continue;
	dp[0][i][j][k]=1;
      }
    }
  for(int i=0;i<n;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
	for(int ii=0;ii<4;ii++){
	  if(j==0&k==1&&ii==2 || j==0&&k==2&&ii==1 || j==1&&k==0&&ii==2)continue;
	  vi A=make_vec(j,k,ii);
	  for(auto a:A){
	    dp[i+1][k][ii][a]+=dp[i][j][k][ii];
	    dp[i+1][k][ii][a]%=MOD;
	  }
	}
      }
    }
  }
  ll ans=0;
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
      for(int k=0;k<4;k++){
	ans+=dp[n][i][j][k];
	ans%=MOD;
      }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll f[200011],n,m,w[110],c[110],ans;
int main()
{
	memset(f,0x7f,sizeof(f));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>w[i]>>c[i];
	f[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=200010;j>=c[i];j--)
		{
			f[j]=min(f[j],f[j-c[i]]+w[i]);
		}
	}
	for(int j=0;j<=200010;j++)
	{
		if(f[j]<=m)
			ans=j;
//		cout<<f[j]<<endl;
	}
//	cout<<endl;
	cout<<ans<<endl;
	return 0;
}

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

int main (){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> node(N+1);
    
    int A,B;
    rep(i, M){
        cin >> A >> B;
        node.at(A).push_back(B);
        node.at(B).push_back(A);
    }
    queue<int> que;
    vector<int> ans(N+1,0);

    que.push(1);
    ans.at(1) = 1;
    while(!que.empty()){
        int new_node = que.front();
        que.pop();
        for(auto x:node.at(new_node)){
            if(ans.at(x) == 0){
                que.push(x);
                ans.at(x) = new_node;
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 2; i <= N; i++){
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 10324
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, a, b, c;
  scanf("%d%d%d", &n, &a, &b);
  for(int i = 0; i < n-1; i++) scanf("%d", &a);
  scanf("%d", &c);
  printf("%d\n", (n-1 ? max(abs(a-c), abs(b-c)) : abs(b-c)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int d[10];

bool check(ll num,ll k,const int* d){
	while(num){
		rep(i,k){
			if((num%10)==d[i])
				return false;
		}
		num/=10;
	}
	return true;
}

int main(){
	ll k,n;
	cin >> n >> k;
	rep(i,k){
		cin >> d[i];
	}
	rep(i,1e7){
		if(check(n+i,k,d)){
			cout << n+i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3608
import string

alphabet = {}
n  = 0
for i in string.ascii_lowercase:
    alphabet[i] = n
    n += 1
    
s = list(input().rstrip())
t = list(input().rstrip())



for i in range(len(s)):
    s[i] = alphabet[s[i]]
    
for i in range(len(t)):
    t[i] = alphabet[t[i]]
    

s.sort()
t.sort(reverse=True)

if s < t:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 3768
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(N)]
cnt = 0
for listA in A:
    ans = [x * y for (x, y) in zip(listA, B)]
    if sum(ans) + C > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int counter=0,i,n;
scanf("%d",&n);
for(i=1;i<=n;++i){
    int num;
    scanf("%d",&num);
    if(num&1&&i&1){
        counter++;
    }
}
printf("%d\n",counter);


    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <numeric>
#include <algorithm>

#define MAX_N 1000000000

int N, X;
int *x;

void solve(void) {
    int res = std::abs(x[0] - X);
    int tmp;

    for (int i=1; i<N; i++) {
        tmp = std::abs(x[i] - x[i-1]);
        res = std::__gcd(tmp, res);
    }
    std::cout << res << std::endl;
}

int main(void) {
    std::cin >> N >> X;
    x = (int *) malloc(sizeof(int) * N);
    for (int i=0; i<N; i++) std::cin >> x[i];
    
    solve();

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
typedef long long ll;
using namespace std;
ll dp[100005];
int main() {
	ll n;
	cin >> n;
	ll h[100005];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;

}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();
		int num = scan.nextInt();

		for(int i = 0; i < num; i++) {
			list.add(scan.nextInt());
		}

		int sumAlice = 0;
		int sumBob   = 0;

		// カードを降順に並べ替え
		Collections.sort(list, Comparator.reverseOrder());


		// カードを交互に配る
		for(int i = 0; i < list.size(); i++) {
			if(i % 2 == 0)
				sumAlice += list.get(i);
			else
				sumBob   += list.get(i);
		}

		System.out.println(sumAlice - sumBob);
		scan.close();

	}

}

Measured memory_bytes: 21844
fun main() {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toLong() }

    val map = mutableMapOf<Long, Long>()
    A.forEach { a ->
        map[a] = (map[a] ?: 0) + 1
    }
    var rec = A.sum()

    val Q = readLine()!!.toInt()
    repeat(Q){
        val (B, C) = readLine()!!.split(" ").map { it.toLong() }
        if(map.containsKey(B)) {
            rec += (C - B) * map[B]!!
            map[C] = (map[C] ?: 0) + (map[B] ?: 0)
            map[B] = 0
        }
        println(rec)
    }
}

Measured memory_bytes: 70592
#include<iostream>
using namespace std;
int main ()
{
    int a,b,c,d,e,k;
    int z,x,v,n,m,q,w,p,u,l;
    cin>>a>>b>>c;
    cin>>d>>e>>k;

    if(a>b)
        z=a-b;
    else
        z=b-a;
    if(a>c)
        x=a-c;
    else
        x= c-a;
    if(a>d)
        v=a-d;
    else
        v=d-a;
    if(a>e)
        n=a-e;
    else
        n=e-a;
    if(b>c)
        m=b-c;
    else
        m=c-b;
    if(b>d)
        q=b-d;
    else
        q=d-b;
    if(b>e)
        w=b-e;
    else
        w=e-b;
    if(c>d)
        p=c-d;
    else
        p=d-c;
    if(c>e)
        u=c-e;
    else
        u=e-c;
    if(d>e)
        l=d-e;
    else
        l=e-d;
    if( z<=k && x<=k && v<=k && m<=k && n<=k && q<=k && w<=k && p<=k && u<=k && l<=k )
    {
        cout<<"Yay!"<<endl;
    }
    else
    {
        cout<<":("<<endl;
    }
    return 0;
}


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





int main(){
  int a[12]={};
  for(int i=0;i<12;i++){
    cin>>a[i];
  }
  int ans=0;
  for(int i=0;i<12;i++){
    int count=0;
    if(a[i]!=0){
      int b=a[i];
      for(int t=i;t<12;t++){
	if(a[t]==b){a[t]=0; count++;}
	if(count==4){ans++; break;}
      }
    }

  }
  cout<<(ans==3? "yes":"no")<<endl;
  

  
  return 0;
}



Measured memory_bytes: 3084
import math
a,b,C = map(float,input().split())
S = a * b * math.sin(math.radians(C)) / 2
c = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(C)))
L = a + b + c
h = b * math.sin(math.radians(C))
print(S)
print(L)
print(h)


Measured memory_bytes: 5696
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int x;
	cin >> x;
	
	vector<bool> ex(x + 1, false);
	ex[1] = true;
	
	for(int i = 2; i <= x; ++i) {
		int m = i * i;
		while( m <= x ) {
			ex[m] = true;
			m *= i;
		}
	}
	
	int ans = 0;
	for(int i = x; i >= 1; i--) {
		if( ex[i] ) {
			ans = i;
			break;
		}
	}
	
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main() {

	int A = 7, B = 5, C = 1;

	cin >> A >> B >> C;

	int stop = A%B;

	if (stop == C) {
		cout << "YES\n";
		return 0;
	}

	for (int i = 2;; i++) {
		if ((A*i) % B == C) {
			cout << "YES\n";
			break;
		}

		if (((A*i) % B) % B == stop) {
			cout << "NO\n";
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using vi = vector<int>;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0, num = 1;
    while(num < b) {
        num += a - 1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
#include<iostream>
#include<map>
#include<string>

using namespace std;

map<string, int> m;
string DAYS[8] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main(){
   string s;
   cin >> s;
   for(int i=0;i<7;i++){
       m[DAYS[i]] = i;
   } 
   cout << 7 - m[s] << endl;
}

Measured memory_bytes: 256
main = do
  [h,w]<-map read.words<$>getLine
  getLine
  as<-map read.words<$>getLine
  putStr.unlines.map (unwords.map show) $ solve h w as

solve h w as = formAns $ colorSeq as 1
  where
  formAns [] = []
  formAns xs = line1 : reverse line2 : formAns remainings
    where
    (line1,l2rem) = splitAt w xs
    (line2,remainings) = splitAt w l2rem
  colorSeq [] _ = []
  colorSeq (a:as) c = replicate a c ++ colorSeq as (c+1)


Measured memory_bytes: 2428
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
bool pairComparesecond(const p& firstElof, const p& secondElof)
{
    return firstElof.second > secondElof.second;
}

ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
	ll x[35][35];
int main(){
	ll n,m;
	cin>>n>>m;
	
	rep(i,0,n){
		ll k;
		cin>>k;
		rep(j,0,k){
			ll a;
			cin>>a;
			x[i][a]++;
		}
	}
	ll ans=0;
	rep(i,1,m+1){
		bool s=true;
		rep(j,0,n){
			if(x[j][i]>0)continue;
			else s=false;
		}
		if(s)ans++;
	}
	cout<<ans<<endl;
		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  string s;
  cin >> s;
  // 排他的論理和
  s[1] = 'R'^'B'^s[1];
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
  final static Integer[] CARDS = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

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

    while (true) {
      String tmp = br.readLine();
      if (tmp == null) {
        break;
      }
      List<Integer> list = Arrays.stream(tmp.split(" ")).map(x -> Integer.valueOf(x)).collect(Collectors.toList());
      List<Integer> remain = Arrays.asList(CARDS).stream().filter(x -> !list.contains(x)).collect(Collectors.toList());
      List<Integer> within20 = remain.stream().filter(x -> (x + list.get(0) + list.get(1) <= 20)).collect(Collectors.toList());
      float rate = (float) within20.size() / (float) remain.size();
      if (rate >= 0.5) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
}

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

using namespace std;

#define x first
#define y second
typedef long long ll;

const int MOD = 1000000007;
const int oo = 1e9;
typedef pair<int,int> pii;

const int N = 1e6+10;


int n , a[N],idx;
double avg,mn=oo;

int main(){
  cin >> n;
  for (int i = 0; i < n; ++i)cin >> a[i];
  for (int i = 0; i < n; ++i)avg += a[i];
  avg/= n;
  for(int i = 0 ; i < n ; ++i){
    double diff = abs(a[i]-avg);
    if(diff < mn){
      mn = diff;
      idx = i;
    }
  }
  printf("%d\n", idx);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string.h>
#include <string>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
int a,s,d,f;
cin>>a>>s>>d;
f=d;
d=s;
int x=0;
int c;
while(x<f){

    if(a%d==0&&s%d==0){
        c=d;
        x++;
    }
    d--;

}
cout<<c;
    return 0;
}


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

int main()
{
  int n,m,sum=0,count=0;
  int* t;

  cin>>n>>m;

  t=new int[n];

  for(int i=0;i<n;i++){
    cin>>t[i];
    sum+=t[i];
  }

  double border=(double)sum/4/m;

  for(int i=0;i<n;i++){
    if(t[i]>=border)count++;
  }

  if(count<m){
    cout<<"No\n";
  }else{
    cout<<"Yes\n";
  }

  delete[] t;

  return 0;
}

Measured memory_bytes: 256
from sys import stdin

N = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
A = [0] + a
B = [0]*(N+1)
putBall = []

for i in range(N, 0, -1):
    cnt = 1
    multiple = i
    tmp = 0
    if sum(B[i::i])%2 != A[i]:
        B[i] = 1
        putBall.append("%d" % i)

print(sum(B))
print(*putBall)

Measured memory_bytes: 18600
def matmul(mt1, mt2, n, modp):
    ans = [[0 for _ in range(n)] for _ in range(n)]

    for i in range(n):
        for j in range(n):
            for k in range(n):
                ans[i][j] += mt1[i][k] * mt2[k][j]
                ans[i][j] %= modp
    return ans


def pow_matrix(mt, k, n, modp):
    ans = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        ans[i][i] = 1

    while k:
        if k % 2:
            ans = matmul(ans, mt, n, modp)
        mt = matmul(mt, mt, n, modp)
        k //= 2
    return ans


def submit():
    n, k = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(n)]
    modp = 10 ** 9 + 7
    ak = pow_matrix(a, k, n, modp)
    
    ans = 0
    for ar in ak:
        for ac in ar:
            ans += ac
            ans %= modp
    print(ans)

submit()


Measured memory_bytes: 41964
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b;
	scanf("%d",&a);
	int k=0;
	for(int i=0;i<=a;i++)
	if((int)(1.08*i)==a)
	{
		k=1;
		b=i;
	}
	if(k==1)printf("%d",b);
	else printf(":(");
	return 0;
}

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

using namespace std;

int main()
{
	//yyyy/mm/dd
	char date[11];

	cin >> date;

	int m = (date[5] - '0')*10 + (date[6] - '0');

	if(m <=4)
	{
		cout << "Heisei" << endl;
	}
	else
	{
		cout << "TBD" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n,ans,i,j,x;
  scanf("%d",&n);
  int h[n];
  ans=0;
  for(i=0;i<n;i++)scanf("%d",&h[i]);
  for(i=n-1;i>=0;i--){
    x=0;
    for(j=i-1;j>=0;j--){
      x+=(h[i]>=h[j])?1:0;
     // printf("%d-%d ",h[i],h[j]);
    }
   // printf("%d=%d\n",i,x);
    if(i==x) ans++;
  }
 printf("%d",ans);
}

Measured memory_bytes: 128
s = int(input())
lst = [s]
i = 0
while True:
    a = lst[i]
    if a%2 == 0:
        tmp = a//2
    else:
        tmp = 3*a + 1
    lst.append(tmp)
    if lst.count(tmp) == 2:
        i += 1
        print(i+1)
        break
    i += 1


Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
	// iz
	int a=0;
	int b=0;
	int area=0;
	int peri=0;
	
	scanf("%d" "%d", &a, &b);		// input
	area = a * b;
	peri = (a * 2) + (b * 2);
	printf("%d %d\n",area, peri);
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<long long int> l(n+1);
    l[0]=2;
    l[1]=1;
    for(int i=2;i<=n;i++) l[i]=l[i-1]+l[i-2];
    cout<<l[n]<<endl;
    return 0;
}

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

int main (void)
{
  char s[10] , ans[10] , c;
  int  j = 0;
  scanf("%s",s);
  
  for(int i = 0;i <strlen(s);i ++){
    if(s[i] !='B'){
      c = s[i];
      ans[j] = c;
      j ++;
    }
    else{
      if(j > 0)
      j --;
    }}
  
  ans[j] = '\0';
  printf("%s",ans);
  
  return 0;
}

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

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

n, m = map(int, input().split())
bridges = list(readlines(m))

tree = list(range(n+1))
rank = [1] * (n+1)

def root(v):
    while tree[v] != v:
        tree[v] = tree[tree[v]]
        v = tree[v]
    return v

def main():
    fuben = n*(n-1)//2

    for a, b in bridges[::-1]:
        x = root(a)
        y = root(b)

        if x == y:
            yield str(fuben)
            continue
        
        yield str(fuben)
        fuben -= rank[x]*rank[y]

        if rank[x] < rank[y]:
            tree[x] = y
            rank[y] += rank[x]
        else:
            tree[y] = x
            rank[x] += rank[y]

print("\n".join(reversed(list(main()))))


Measured memory_bytes: 29500
S = input()
N = len(S)
O = ["R", "U", "D"]
E = ["L", "U", "D"]
for i in range(N):
    if i%2 == 0:
        if S[i] not in O:
            print("No")
            exit()
    else:
        if S[i] not in E:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#define ll long long
using namespace std;
int dp[100100];
void solve(){
    for(int i=0;i<100;i++)
        for(int j=0;j<100;j++)
            dp[i*4+j*7]=1;
}
int main() {
    solve();
    int n;
    cin>>n;
    cout<<(dp[n] ? "Yes":"No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void app() {
  int n;
  cin>>n;

  int n1=n+1;
  vector<int> v(n1),w(n1);
  rep_range(i,1,n1){
    cin>>v[i]>>w[i];
  }

  int memd=9;
  // 深さmemdまでは事前に全探索して保持
  // 深さmemdからはその場で全探索

  int maxw=1e5+1;
  vector<vector<int>> dp((1<<memd)+1,vector<int>(maxw));
  dp[0]=vector<int>(maxw,0);
  rep_range(i,1,(1<<memd)+1){
    if(i>=n1) break;
    rep(wn,maxw){
      dp[i][wn]=dp[i/2][wn];
      if(wn-w[i]>=0) chmax(dp[i][wn], dp[i/2][wn-w[i]]+v[i]);
    }
  }

  int q;
  cin>>q;
  rep(t,q){
    int i,l;
    cin>>i>>l;

    int s=0;
    vector<int> vo,wo;
    while(i>(1<<memd)){
      vo.push_back(v[i]);
      wo.push_back(w[i]);
      s++;
      i/=2;
    }

    int ans=0;
    rep(k,1<<s){
      int wn=0,vn=0;
      rep(b,s) if(k&(1<<b)){
        vn+=vo[b];
        wn+=wo[b];
      }
      if(wn>l) continue;
      vn+=dp[i][l-wn];
      chmax(ans,vn);
    }

    cout<<ans<<endl;
  }

}

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


Measured memory_bytes: 206828
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>

using namespace std;

int main() {
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < W; i++) {
			cout << "#";
		}
		cout << endl;
		for (int i = 0; i < H - 2; i++) {
			for (int j = 0; j < W; j++) {
				if (j == 0 || j == W - 1)cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		for (int i = 0; i < W; i++) {
			cout << "#";
		}
		cout << endl;
		cout << endl;

	}
}

Measured memory_bytes: 1152