akhauriyash/Code-Regression huggingface dataset:
import java.awt.TexturePaint;
import java.awt.event.ComponentAdapter;
import java.io.BufferedReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int first = Integer.parseInt(sc.next()); 
		int second = Integer.parseInt(sc.next()); 
		int[] dis = new int[first];
		for(int i=0; i<first; i++) {
			dis[i] = Integer.parseInt(sc.next());
		}
		int now = 0;
		int count = 1;
		
		for(int i=0; i<first; i++) {
			now += dis[i];
			if(now > second) {
				break;
			}
			count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    P itv[m];
    rep(i, m)
    {
        int a, b; cin >> a >> b; --a;--b;
        itv[i] = {b, a};
    }
    sort(itv, itv + m);
    int ans = 0, t = 0;
    rep(i, m)
    {
        if (itv[i].second >= t)
        {
            ans++;
            t = itv[i].first;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int A, B, c=1, t=0;
    cin >> A >> B;
    while(c<=3){
        if(A*B*c%2!=0){
            t=1;
            break;
        }
        c++;
    }
    if (t==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	string s;
	int n;
	cin>>n;
	cin>>s;
	int i=0;
	for(i=0;s[i]!=0;i++);
	if(i<=n)cout<<s;
	else{
		for(int t=0;t<n;t++)
			cout<<s[t];
		cout<<"...";
	}
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
ll n,x;
ll calc(ll A,ll B)
{
	if(A<B)std::swap(A,B);
	if(A%B==0)return (A*2-B);
	ll ret=0;
	ret+=(A/B)*B*2;
	return ret+calc(B,A%B);
}
int main()
{
	scanf("%lld%lld",&n,&x);
	printf("%lld\n",n+calc(x,n-x));
	return 0;
}


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

int a,b,c;

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

struct dice
{
	int _1, _2, _3, _4, _5, _6;
	
	dice()
	{
		
	}
	
	dice(int _1, int _2, int _3, int _4, int _5, int _6)
	: _1(_1), _2(_2), _3(_3), _4(_4), _5(_5), _6(_6)
	{
		
	}
	
	void roll(const char& c)
	{
		int _1_ = _1;
		int _2_ = _2;
		int _3_ = _3;
		int _4_ = _4;
		int _5_ = _5;
		int _6_ = _6;
		
		switch (c)
		{
		case 'N':
			_5 = _1_;
			_6 = _5_;
			_2 = _6_;
			_1 = _2_;
			break;
		case 'S':
			_1 = _5_;
			_2 = _1_;
			_6 = _2_;
			_5 = _6_;
			break;
		case 'E':
			_1 = _4_;
			_3 = _1_;
			_6 = _3_;
			_4 = _6_;
			break;
		case 'W':
			_1 = _3_;
			_4 = _1_;
			_6 = _4_;
			_3 = _6_;
			break;
		}
	}
	
	int top()
	{
		return _1;
	}
	
	friend std::istream& operator >> (std::istream& is, dice& d)
	{
		int _1, _2, _3, _4, _5, _6;
		
		is >> _1 >> _2 >> _3 >> _4 >> _5 >> _6;
		
		d = dice(_1, _2, _3, _4, _5, _6);
		
		return is;
	}
};

int main()
{
	dice d;
	std::cin >> d;
	
	std::string dir;
	std::cin >> dir;
	
	for (const char& c : dir)
		d.roll(c);
	
	std::cout << d.top() << std::endl;
	
	return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;


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

	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	REP(i, n) cin >> h[i];
	vector<int> q = h;
	q.emplace_back(0);
	sort(q.begin(), q.end());
	q.resize(unique(q.begin(), q.end()) - q.begin());
	debug(q);
	int dif = size(q);

	vector<vector<vector<LL>>> dp(n + 1, vector<vector<LL>>(k + 1, vector<LL>(dif, 1e15)));
	dp[0][0][0] = 0;

	FOR(i, 1, n) {
		int not_mod = -1;
		REP(d, dif) if(q[d] == h[i - 1]) not_mod = d;
		FOR(j, 0, k) {
			REP(d, dif) {
				// case 1 : nie modyfikuje
				dp[i][j][not_mod] = min(dp[i][j][not_mod], dp[i - 1][j][d] + max(0, h[i - 1] - q[d]));
				// case 2 : modyfikuje
				if(j != 0) dp[i][j][d] = min(dp[i][j][d], dp[i - 1][j - 1][d]);
			}
		}
	}

	LL ans = 1e15;
	FOR(j, 0, k) REP(d, dif) ans = min(ans, dp[n][j][d]);
	cout << ans << "\n";
	
}


Measured memory_bytes: 216832
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int pri=1000000007;
int dy[2]={0,1};
int dx[2]={1,0};

signed main(){
	int H,W; cin>>H>>W;
	vector<string> field(H);
	for(int i=0;i<H;i++)cin>>field[i];
	vector<vector<int>> ans(H,vector<int>(W,-1));
	queue<pair<int,int>> que;
	que.push(make_pair(0,0));
	ans[0][0]=1;
	while(!que.empty()){
		int x=que.front().first;
		int y=que.front().second;
		que.pop();
		for(int i=0;i<2;i++){
			int nx=x+dx[i];
			int ny=y+dy[i];
			if(nx<0 || ny<0 || nx>=H || ny>=W)continue;
			if(field[nx][ny]=='#')continue;
			if(ans[nx][ny]==-1){
				que.push(make_pair(nx,ny));
				ans[nx][ny]=0;
			}
			ans[nx][ny]+= ans[x][y];
			ans[nx][ny]%=pri;
		}
	}
	cout<<max(0LL,ans[H-1][W-1])<<endl;
	return 0;



}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;

    mint ans = 0;
    mint cl = m;
    for(int i=n-1; i>=0; i--)
    {
        mint lans = cl;
        lans *= c(n-1, i);
        if(k >= i) ans += lans;
        cl *= (m-1);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6228
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1e9+7
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define M 110


int main(){
    IOS;
 
 	
 	ll a[5];
 	rep(i,0,5){
 		cin>>a[i];
 		if(!a[i]){
 			cout<<i+1;
 			return 0;
 		}
 	}
    return 0;
}

Measured memory_bytes: 3612
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn shortest(i: i32, j: i32, x: i32, y: i32) -> usize {
    let mut short = min((i-j).abs(), (i-x).abs() + 1 + (y-j).abs());
    
    short = min(short, (i-y).abs()+1+(j-x).abs());
    (short as usize)
}

fn main() {
    let input = read_vec::<i32>();
    let n = input[0];
    let x = input[1] - 1;
    let y = input[2] - 1;

    let mut len = vec![0; (n - 1) as usize];

    for i in 0..n {
        for j in i+1..n {
            let index = shortest(i,j,x,y) - 1;
            len[index] += 1;
        }
    }


    for i in len.iter() {
        println!("{}", i);
    }
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define REP(i,j) for(int i=0; i<j; ++i)

int L, n, m, N = 0, M = 0, c[100][2], t[10000][2], s[10000][2], k, ct, cs, a = 0;

void T(int &t1, int &t2){
    int h1, m1, h2, m2;
    scanf("%d:%d-%d:%d", &h1, &m1, &h2, &m2);
    t1 = h1 * 60 + m1;
    t2 = h2 * 60 + m2;
}

int main(){
    cin >> L;
    REP(i, L) T(c[i][0], c[i][1]);
    cin >> n;
    REP(i, n){
        cin >> k;
        REP(j, k)
            T(t[N][0], t[N][1]), ++N;
    }
    cin >> m;
    REP(i, m){
        cin >> k;
        REP(j, k)
            T(s[M][0], s[M][1]), ++M;
    }
    REP(i, L){
        ct = cs = 0;
        REP(j, N)
            if(t[j][0]<=c[i][0] && c[i][1]<=t[j][1]) ++ct;
        REP(j, M)
            if(s[j][0]<=c[i][0] && c[i][1]<=s[j][1]) ++cs;
        a += min(ct, cs);
    }
    cout << a << endl;
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,tot=0,sum=0,vote;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
	tot+=a[i];
	}	
	vote=tot/(4*m);
	for(int i=0;i<n;i++)
	{
		if(a[i]>=vote)sum++;
		if(vote*4*m<tot&&a[i]==vote)sum--;
		if(sum==m){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
n, t = STDIN.readline.strip().split(' ').map(&:to_i)
as = STDIN.readline.strip().split(' ').map(&:to_i)
m = [10**9+1, -1, 0]
as.each do |a|
  if m[0] > a
    m[0] = a
  end
  if a - m[0] > m[1]
    m[1] = a - m[0]
    m[2] = 1
  elsif a - m[0] == m[1]
    m[2] += 1
  end
end
puts m[2]


Measured memory_bytes: 11524
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
set<ll> st;
ll n;
void make(string s, int cnt)
{
    if(cnt >= 8) return;
    cnt++;
    make(s + '7', cnt);
    make(s + '5', cnt);
    make(s + '3', cnt);
    sort(s.begin(), s.end());
    do
    {
        st.insert(atoll(s.c_str()));
    }
    while(next_permutation(s.begin(), s.end()));
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    make("357", 0);
    ll ans = 0;
    for(auto x : st)
    {
        if(x > n) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
    int n; 
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
         cin >> a.at(i);
    }
    
    long long answer = 0;
    for(int i = 0; i < n; i++){
        answer += a.at(i) / 2;
        a.at(i) %= 2;
        if(i < n - 1){
            if(a.at(i + 1) > 0 && a.at(i) > 0){
                answer++;
                a.at(i + 1)--;
            }
        }
    }
    
    cout << answer << endl;
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())
b = b[::-1]
from collections import Counter
d = Counter(a+b)
if max(d.values()) > n:
    print("No")
    exit()

same = set(i for i in range(n) if a[i]==b[i])
from random import randrange
while same:
    i = same.pop()
    while True:
        j = randrange(0,n)
        if a[j] != b[i] and a[i] != b[j]:
            b[i],b[j] = b[j],b[i]
            same.discard(j)
            break

print("Yes")
print(*b)


Measured memory_bytes: 46804
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int MAX_N = 100001;

bool isPrime(int num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }
  // 素数である
  return true;
}

int main()
{

  vi a(MAX_N, 0);
  srep(i,2,MAX_N)
  {
    if (isPrime(i) && isPrime((i+1)/2))
      a[i] = 1;
  }
  vi s(MAX_N + 1, 0);
  rep(i, MAX_N)
  {
    s[i + 1] = s[i] + a[i];
  }
  int q;
  cin >> q;
  vi ans;
  rep(i, q)
  {
    int l, r;
    cin >> l >> r;
    ans.push_back(s[r+1]-s[l]);
  }
  rep(i,q){
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1912
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main() {
  int x, count[101]={}, max=0; 
  set<int> a; 
  multimap<int, int> b; 
  while(cin >> x) { 
    count[x]++;  
    a.insert(x);
  } 
  for(set<int>::iterator it=a.begin(); it!=a.end(); it++) { 
    b.insert(make_pair(count[*it], *it));   
    if(count[*it]>max) max=count[*it]; 
  } 
  for(multimap<int, int>::iterator it=b.begin(); it!=b.end(); it++) {  
    if(it->first==max) cout << it->second << endl; 
  } 
  return 0;
}


Measured memory_bytes: 1200
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    private static long dist[];

    private static Map<Integer, List<Edge>> map;

    private static class Edge {
        int from;
        int to;
        long cost;

        private Edge(int from, int to, long cost) {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

    public static void dfs(int v, int p, long d) {
        dist[v] = d;
        for (Edge edge : map.get(v)) {
            if (edge.to == p) {
                continue;
            }
            dfs(edge.to, v, d + edge.cost);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n - 1];
        int[] b = new int[n - 1];
        long[] c = new long[n - 1];
        dist = new long[n + 1];
        map = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            map.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextLong();
            List<Edge> l1 = map.get(a[i]);
            l1.add(new Edge(a[i], b[i], c[i]));
            map.put(a[i], l1);
            List<Edge> l2 = map.get(b[i]);
            l2.add(new Edge(b[i], a[i], c[i]));
            map.put(b[i], l2);
        }
        int q = sc.nextInt();
        int k = sc.nextInt();
        int[] x = new int[q];
        int[] y = new int[q];
        for (int i = 0; i < q; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        dfs(k, -1, 0);
        for (int i = 0; i < q; i++) {
            System.out.println(dist[x[i]] + dist[y[i]]);
        }
    }

}


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

int main() {
  int ans = 0;
  int N, M; cin >> N >> M;
  vector<int> suki(M, 0);
  for(int i = 0; i < N; i++){
    int k; cin >> k;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      suki[a - 1]++;
    }
  }
  
  for(int i = 0; i < M; i++){
    if (suki[i] == N) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  vector<int> K(M,0);
  for(int i=0;i<N;i++){
  int a;
    cin>>a;
    for(int j=0;j<a;j++){
    int A;
      cin>>A;
      A--;
      K[A]++;
      
    
    }
    
  
  }
  int count=0;
  for(int i=0;i<M;i++){
  if(K[i]==N){
  count++;
  }
  }
  cout<<count<<endl;
}


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

int main(int argc, char **argv)
{
	ll A, B;
	cin >> A >> B;
	ll res = max(ceil(A/0.08), ceil(B/0.1));
	if (min(ceil((A+1)/0.08), ceil((B+1)/0.1)) <= res) res = -1;
	std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

ll cnt[26];
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'a']++;
	}
	ll sum = s.size();
	ll ans = 1;
	for(int i=0;i<26;i++){
		if(cnt[i]){
			ans += (sum-cnt[i])*cnt[i];
			sum -=cnt[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 720
import java.util.Scanner;
public class Main{
  public static void main(String... args){
    Scanner sc = new Scanner(System.in);
    int m1 = sc.nextInt(), d1 = sc.nextInt();
    int m2 = sc.nextInt(), d2 = sc.nextInt();
    if(m1 != m2)
      System.out.println(1);
    else
      System.out.println(0);
  }
}

Measured memory_bytes: 21588
h, w=map(int, input().split())
s=['.'*(w+2)]+['.'+input()+'.' for _ in range(h)]+['.'*(w+2)]
for i in range(1, h+1):
  for j in range(1, w+1):
    if s[i][j]=='#':
      if '#' not in (s[i-1][j], s[i+1][j], s[i][j-1], s[i][j+1]):
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    // dp[i]:=砂糖水i(g)のとき最大の砂糖の質量
    vector<int> dp(F + 1, -INF);
    dp[0] = 0;
    for(int i = 0; i < F; i++) {
        if(i + 100 * A <= F)
            dp[i + 100 * A] = max(dp[i], dp[i + 100 * A]);
        if(i + 100 * B <= F)
            dp[i + 100 * B] = max(dp[i], dp[i + 100 * B]);
        if(i + C <= F && E * ((i - dp[i]) / 100) >= dp[i] + C) {
            dp[i + C] = max(dp[i] + C, dp[i + C]);
        }
        if(i + D <= F && E * ((i - dp[i]) / 100) >= dp[i] + D) {
            dp[i + D] = max(dp[i] + D, dp[i + D]);
        }
    }
    double conc = -1;
    pair<int, int> res = MP(0, 0);
    for(int i = 1; i < F + 1; i++) {
        if(dp[i] == -INF)
            continue;
        double tmp = (100.0 * dp[i]) / (double)i;
        if(conc < tmp) {
            res = MP(i, dp[i]);
            conc = tmp;
        }
    }
    cout << res.first << " " << res.second << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
ll n, m, k;
ll fac[MN];

pll gcd(ll a, ll b){ //a*first+b*second=gcd
    if(a == 0){
        return mp(0, 1);
    }

    pll prev = gcd(b%a, a);

    return mp(prev.s-(b/a)*prev.f, prev.f);
} //using ll's just to be safe wrt overflow issues

ll modInv(ll x){ //return x^-1 % MOD
    pll res = gcd(x, MOD);

    res.f = (res.f+MOD)%MOD;

    //cout << "modinv of " << x << " is " << res.f << "\n";

    return res.f;
}

ll modDiv(ll x, ll y){
    return (x*modInv(y))%MOD;
}

ll c2(ll x){
    return (x*(x-1)/2)%MOD;
}

void getFacs(){
    fac[0] = 1;
    FOR(i, 1, MN-1){
        fac[i] = (fac[i-1]*i)%MOD;
    }
}

ll choose(ll a, ll b){
    ll c = a-b;
    if(c < 0){
        cout << "ur bad\n";
        exit(0);
    }

    ll num = fac[a];
    ll denom = (fac[b]*fac[c])%MOD;

    //cout << "num " << num << " denom " << denom << "\n";

    return modDiv(num, denom);
}

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

    getFacs();

    cin >> n >> m >> k;
    
    ll smx = 0;
    FOR(i, 1, n-1){
        ll nw = n-i;
        smx = (smx+i*nw)%MOD;
    }

    ll smy = 0;
    FOR(i, 1, m-1){
        ll nw = m-i;
        smy = (smy+i*nw)%MOD;
    }

    ll nw = c2(n*m);
    ll tsx = ((smx*m)%MOD*m)%MOD;
    ll tsy = ((smy*n)%MOD*n)%MOD;

    //cout << smx << " " << smy << "\n";

    ll tot = (tsx+tsy)%MOD;

    ll xpv = modDiv(tot, nw);
    ll ch = choose(n*m, k);
    ll ch2 = choose(k, 2);
    ll res = ((xpv*ch)%MOD*ch2)%MOD;

    //cout << tot << " " << xpv << " " << ch << "\n";

    cout << res << "\n";

    return 0;
}


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

int main(){
  
  int a,b;
  cin >> a >> b;
  
  if( a < 10 && b < 10 ){
    
  cout << a*b << endl;
    
  }
  
  else{
    
  cout << -1 << endl;
    
  }
    
}


Measured memory_bytes: 256
import sys

N = (int)(raw_input())
a = [0,0,0]

for i in range(N):
    a[0],a[1],a[2] = map(int,raw_input().split())
    a.sort()
    if a[0]**2 + a[1]**2 == a[2]**2:
	print("YES")
    else:
	print("NO")

    

Measured memory_bytes: 6224
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> hh(N);
    rep(i, N) cin >> hh.at(i);

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

    int idx = 0;
    int diff = 1000000001;
    while (idx + K != hh.size() + 1)
    {
        diff = min(diff, hh.at(idx + K - 1) - hh.at(idx));
        idx++;
    }
    cout << diff << endl;
}


Measured memory_bytes: 640
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut xu: Vec<(f64, String)> = Vec::new();
    for _ in 0..n {
      let v: Vec<String> = read_vec();
      xu.push((v[0].parse().ok().unwrap(), v[1].clone()));
    }

    let mut ans: f64 = 0.0;

    for i in 0..n {
      ans += match (xu[i].1).as_str() {
        "JPY" => xu[i].0,
        "BTC" => xu[i].0 * 380000.0,
          _   => 0.0,
      };
    }

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


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
    long long n,a;
    cin >> n >> a;
    long long x[n];
    for (int i=0; i<n; i++){
        cin >> x[i];
        x[i]-=a;
    }
    if (n>=17){
        long long dp[n][100*n+1]={{0,0}};
        dp[0][x[0]+50*n]=1;
        dp[0][50*n]+=1;
        for (int i=1; i<n; i++){
            for (int j=0; j<=100*n; j++){
                if (j>=x[i] && j-x[i]<=100*n){
                    dp[i][j]=dp[i-1][j]+dp[i-1][j-x[i]];
                }
                else{
                    dp[i][j]=dp[i-1][j];
                }
                
            }
            
        }
        cout << dp[n-1][50*n]-1<<endl;
    }
    else {
        int ans=0;
        for (int i=1; i< (1<<n); i++){
            int sum=0;
            for (int j=0; j<n; j++){
                if (i>>j & 1){
                    sum+=x[j];
                }
            }
            if (sum==0){
                ans++;
            }
        }
        cout << ans <<endl;
    }
}





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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  vi abc;
  REP(i, 3) { abc.PB(read()); }
  sort(ALL(abc));
  int ans = 0;
  while (abc[0] < abc[1]) {
    abc[0] += 2;
    ans++;
  }
  ans += abc[2] - abc[0];
  if (abc[0] != abc[1]) ans += 2;
  print(ans);
}


Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll a[500005]={},ans=0;
  cin >> s;
  for(int i=0; i<s.size()+1; i++) {
    if(s[i]=='<') {
      a[i+1]=max(a[i+1],a[i]+1);
    }
  }
  for(int i=s.size(); i>=0; i--) {
    if(s[i]=='>') {
      a[i]=max(a[i],a[i+1]+1);
    }
  }
  for(int i=0; i<s.size()+1; i++) {
    ans+=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 5012
num = gets.to_i
list = gets.split
cnt = 0
bool = true
is_break = false
while bool
  list.each_with_index do |elem, i|
    if elem.to_i % 2 != 0
      bool = false
      is_break = true
      break
    else
      list[i] = elem.to_i/2
    end
  end
  break if is_break
  cnt += 1
end
puts cnt

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

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

    string S = " ACGT"; // バグ回避の特効薬

    ll DP[N+1][5][5][5] = {};
    DP[0][0][0][0] = 1;
    for (int i = 0; i < N; ++i) {
        // 1番外側のforループだけ別格
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 5; ++k) {
                for (int l = 0; l < 5; ++l) {
                    // DP[i][j][k][l] に対してDP[i+1][][][]を計算
                    for (int m = 1; m < 5; ++m) {
                        if(S[k] == 'A' && S[l] == 'G' && S[m] == 'C') continue;
                        if(S[j] == 'A' && S[k] == 'G' && S[m] == 'C') continue;
                        if(S[j] == 'A' && S[l] == 'G' && S[m] == 'C') continue;

                        if(S[k] == 'G' && S[l] == 'A' && S[m] == 'C') continue;
                        if(S[k] == 'A' && S[l] == 'C' && S[m] == 'G') continue;

                        DP[i+1][k][l][m] += DP[i][j][k][l];
                        DP[i+1][k][l][m] %= mod;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 5; ++k) {
                ans += DP[N][i][j][k];
                ans %= mod;
            }
        }
    }
    cout << ans;
    return 0;
}

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

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	int h,w;
	cin >> h >> w;
	string s;
	for(int i = 0;i < h; ++i){
		cin >> s;
		cout << s << '\n';
		cout << s << '\n';
	}
}


Measured memory_bytes: 256
from collections import Counter
from functools import reduce


def ncr(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x, y: x * y, range(n, n - r, -1), 1)
    denom = reduce(lambda x, y: x * y, range(1, r + 1), 1)
    return numer // denom


N, P = map(int, input().split())
A = Counter(map(lambda x: int(x) % 2, input().split()))
e = A.get(0, 0)
o = A.get(1, 0)
ans = 2 ** e
if P:
    if o == 0:
        print(0)
    else:
        ans *= sum(ncr(o, i) for i in range(1, o + 1) if i % 2)
        print(ans)
else:
    ans *= sum(ncr(o, i) for i in range(o + 1) if i % 2 == 0)
    print(ans)


Measured memory_bytes: 3564
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  set<int> st;
  int ans = 0;
  while (n--) {
    int p; cin >> p;
    if (st.empty() || st.lower_bound(p) == st.begin()) ++ans;
    st.emplace(p);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int x[1000];
    int sum=0;
    cin >>n;
    for(int i=0;i<n;i++){
      cin >>x[i];
      sum+=x[i];
    }
    lol ans=0,an=0,pa=0;
    sum/=n;
    for(int i=0;i<n;i++){
      int k=abs(x[i],sum);
      int o=abs(x[i],sum-1);
      int p=abs(x[i],sum+1);
      ans+=k*k;
      an+=o*o;
      pa+=p*p;
    }
    cout <<min(an,min(pa,ans))<<'\n';
    return (0);
}


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

int main() {
  long long h;
  cin >> h;
  
  long long d = 2;
  for(int i=0; i<100000; i++) {
    if(d > h)
      break;
    d *= 2;
  }
   cout << d - 1 << endl;
}

Measured memory_bytes: 256
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let k:u32 = match iter.next().unwrap().parse() {
		Ok(m) => m,
		Err(_) => panic!(""),
	};
	let x:u32 = match iter.next().unwrap().parse() {
		Ok(m) => m,
		Err(_) => panic!(""),
	};
	if 500*k >= x {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
string m[7]={"null","one pair","two pair","three card","straight","full house","four card"};
int c[5],ans;
bool s1(){
	bool ok=false;
	for(int i=0;i<4;i++){
		if(c[i]==c[i+1])ok=true;
	}
	return ok;
}
bool s2(){
	bool ok=false;
	if(c[1]==c[2]&&c[3]==c[4])ok=true;
	if(c[0]==c[1]&&c[3]==c[4])ok=true;
	if(c[0]==c[1]&&c[2]==c[3])ok=true;
	return ok;
}
bool s3(){
	bool ok=false;
	for(int i=0;i<3;i++){
		if(c[i]==c[i+1]&&c[i]==c[i+2])ok=true;
	}
	return ok;
}
bool s4(){
	bool ok=true;
	for(int i=0;i<4;i++){
		if(c[i]+1!=c[i+1])ok=false;
	}
	int d[5]={1,10,11,12,13};
	bool A=true;
	for(int i=0;i<5;i++){
		if(c[i]!=d[i])A=false;
	}
	if(A)ok=true;
	return ok;
}
bool s5(){
	bool ok=true;
	if(c[0]!=c[1]||c[3]!=c[4])ok=false;
	if(c[1]!=c[2]&&c[3]!=c[2])ok=false;
	return ok;
}
bool s6(){
	bool ok=false;
	if(c[0]==c[1]&&c[0]==c[2]&&c[0]==c[3])ok=true;
	if(c[4]==c[1]&&c[4]==c[2]&&c[4]==c[3])ok=true;
	return ok;
}
int main(){
	char z;
	while(cin>>c[0]){
		for(int i=1;i<5;i++)cin>>z>>c[i];
		ans=0;
		sort(c,c+5);
		if(s1())ans=1;
		if(s2())ans=2;
		if(s3())ans=3;
		if(s4())ans=4;
		if(s5())ans=5;
		if(s6())ans=6;
		cout<<m[ans]<<endl;
	}
	return 0;
}

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

int main() {
	int n, h[100005];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int tmp = 0;
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (h[i - 1] >= h[i]) tmp++;
		if (h[i - 1] < h[i]) tmp = 0;
		if (ans < tmp) ans = tmp;
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 640
#include<cstdio>

int main(){
	int N;
	scanf("%d", &N);
	int tpresent = 0, xpresent = 0, ypresent = 0;
	int tnext, xnext, ynext;
	int i = 0;
	while(i < N){
		scanf("%d %d %d", &tnext, &xnext, &ynext);
		int tdifference = tnext - tpresent;
		int xdifference = xnext - xpresent;
		int ydifference = ynext - ypresent;
		int judge = tdifference - (xdifference + ydifference);
		if(judge < 0 || judge % 2){
			printf("No\n");
			break;
		}
		tpresent = tnext;
		xpresent = xnext;
		ypresent = ynext;
		i++;
	}
	if(i == N)
		printf("Yes\n");
	return 0;
}

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

int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int l[Q], r[Q];
  rep(i, Q)
    cin >> l[i] >> r[i];
  //ここまで入力

  //i番目までにACが何回出たかを計算
  int cum[N]={0};
  rep(i, N-1){
    cum[i+1] += cum[i];
    //'AC'の'C'が出た段階でカウントする
    if(S[i] == 'A')
      if(S[i+1] == 'C')
	cum[i+1]++;
  }

  //累積和による計算  
  rep(i, Q){
    int s = l[i]-1;
    int g = r[i]-1;
    cout << cum[g]-cum[s] << endl;
  }

  

  return 0;
}


Measured memory_bytes: 2304
using System;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
      int n = int.Parse(Console.ReadLine().Split(' ')[0]);
int[] x = Console.ReadLine().Split(' ').Select<string ,int>((o)=> int.Parse(o)).OrderBy((i) => i).ToArray();
Console.WriteLine(x.Skip(1).Select((v,i)=>v-x[i]).OrderBy((i) => -i).Skip(n-1).Sum());
    }
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, K; cin >> N >> K;
    // N-1回以内にループになるので余りをみる。。。みたいなやつ
    vector<ll> v;
    v.push_back(0);//1-index
    REP(i, N) {
        ll tmp; cin >> tmp;
        v.push_back(tmp);
    }
    ll mod = 0;
    map<ll, ll> cnt_mp;
    map<ll, ll> prev_mp;
    ll cur_pos;
    ll syuki = 0;
    ll yobun = 0;
    // 周期ゲット
    REP(i, N) {
        if (i==0) {
            cur_pos = 1;
        }
        else {
            cur_pos = v[cur_pos];
        }
        if (i == K) { // K < Nの時
            cout << cur_pos << endl;
            return 0;
        }
        cnt_mp[cur_pos]++;
        if (cnt_mp[cur_pos] == 2) {//loop検知
            syuki = i - prev_mp[cur_pos];
            yobun = prev_mp[cur_pos];
            break;
        }
        prev_mp[cur_pos] = i;
    }
    ll rest = K - yobun; // ここは周期には関係ない
    rest %= syuki;
    REP(i, rest) {
        cur_pos = v[cur_pos];
    }
    cout << cur_pos << endl;

    return 0;
}


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

int SumA(vector<int>A, int b){
    int Sum = 0;
    for(int i = 0; i < A.size(); i++){
        Sum += abs(A[i]-b);
    }
    return Sum;
}

int main(){
    int N, tmp;
    vector<int> A;
    cin >> N;
    while(cin >> tmp){
        A.push_back(tmp);
    }
    for(int i = 0; i < N; i++){
        A[i] -= i+1;
    }
    sort(A.begin(), A.end());

    int mid = A[N/2];
    long long ans = 0;
    for(int i = 0; i < N; i++){
        ans += abs(A[i] - mid);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func calcScore(day int, score, c, last []int) (int, []int) {
	loss := make([]int, 26)
	for i := 0; i < 26; i++ {
		loss[i] = c[i] * (day - last[i])
	}

	ret := 0
	new := make([]int, 26)
	for j := 0; j < 26; j++ {
		new[j] = score[j] - loss[j]
		ret += new[j]
	}

	return ret, new
}

func calcAllScore(D int, days []int, c []int, s [][]int) int {
	last := make([]int, 26)
	score := make([]int, 26)

	ans := 0
	for i := 0; i < D; i++ {
		t := days[i]
		score[t] += s[i][t]
		last[t] = i + 1
		ret, nw := calcScore(i+1, score, c, last)
		score = nw
		ans = ret
		// out(score)
	}
	return ans
}

var tab [366][26]int
var sum [366][26]int
var exe [366]int
var D int
var c []int
var s [][]int

func calc(typ int) {
	score := 0
	last := 0
	for i := 1; i <= D; i++ {
		if tab[i][typ] == 1 {
			score += s[i][typ]
			last = i
		}
		score += c[typ] * (last - i)
		sum[i][typ] = score
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	D = getInt()
	c = getInts(26)
	s = make([][]int, D+1)
	for i := 0; i < D; i++ {
		s[i+1] = getInts(26)
	}

	for i := 1; i <= D; i++ {
		maxS := s[i][0]
		idx := 0
		for j := 0; j < 26; j++ {
			if maxS < s[i][j] {
				maxS = s[i][j]
				idx = j
			}
			exe[i] = idx + 1
		}

	}

	// 	t := 0
	// 	tab[i][t] = 1
	// 	exe[i] = t + 1
	// }

	// for i := 0; i < 26; i++ {
	// 	calc(i)
	// }
	// ans := 0
	// for i := 0; i < 26; i++ {
	// 	ans += sum[D][i]
	// }
	// out(ans)

	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()
	for i := 1; i <= D; i++ {
		fmt.Fprintln(wr, exe[i])
	}

	// M := getInt()
	// for i := 0; i < M; i++ {
	// 	d, q := getInt(), getInt()-1
	// 	tab[d][q] = 1
	// 	if exe[d] != 0 {
	// 		tab[d][exe[d]-1] = 0
	// 	}
	// 	for i := 0; i < 26; i++ {
	// 		calc(i)
	// 	}
	// 	exe[d] = q + 1
	// 	tot := 0
	// 	for i := 0; i < 26; i++ {
	// 		tot += sum[D][i]
	// 	}
	// 	fmt.Fprintln(wr, tot)
	// }
}


Measured memory_bytes: 1932
#include<iostream>

int main() {
	int h, w;
	std::cin >> h >> w;
	int cnt[50][50] = { 0 };
	char c[50][50];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			std::cin >> c[i][j];
			if (c[i][j] == '#') {
				for (int k = -1; k <= 1; k++) {
					for (int l = -1; l <= 1; l++) {
						if (k == 0 && l == 0)continue;
						if (i + k < 0 || i + k >= h)continue;
						if (j + l < 0 || j + l >= w)continue;
						cnt[i + k][j + l]++;
						std::cerr << i << ' ' << j << ' ' << i + k << ' ' << j + l << ' ' << cnt[i + k][j + l] << std::endl;
					}
				}
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (c[i][j] == '#') std::cout << c[i][j];
			else std::cout << cnt[i][j];
		}
		std::cout << std::endl;
	}


}


Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;



int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	string s;
	int k;
	string t;

	cin >> k;
	cin >> s;

	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		rep(i, k) {
			cout << s[i];
		}
		cout << "..." << endl;
	}
}

Measured memory_bytes: 3600
a = input().split()
b = input().split()
c = input().split()

road = [a,b,c]
c = [0,0,0,0]

for r in road:
    if "1" in r:
        c[0] += 1

    if "2" in r:
        c[1] += 1

    if "3" in r:
        c[2] += 1

    if "4" in r:
        c[3] += 1

c.sort()

if c == [1,1,2,2]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    
    int n, limit, temp;
    string name;
    
    queue<pair<string, int> > Q;
    
    cin >> n >> limit;
    
    for (int i = 0; i < n; i++) {
        cin >> name >> temp;
        Q.push(make_pair(name, temp));
    }
    
    pair <string, int> u;
    int elaps = 0, a;
    
    while(!Q.empty()) {
        u = Q.front(); Q.pop();
        a = min(u.second, limit);
        u.second -= a;
        elaps += a;
        if (u.second > 0) {
            Q.push(u);
        } else {
            cout << u.first << " " << elaps << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6320