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

const int N = 55;
int C[N][N];
bool seen[N][N];

int h, w;

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

void dfs(int x, int y){
    seen[x][y] = true;
    for(int i = 0; i < 8; i++){
        int nx = dx[i] + x;
        int ny = dy[i] + y;
        if(nx < 0 || ny < 0 || nx >= h || ny >= w){
            continue;
        }
        if(C[nx][ny] == 0 || seen[nx][ny]){
            continue;
        }
        dfs(nx, ny);
    }
}

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

    while(cin >> w >> h){
        if(h == 0 && w == 0){
            break;
        }

        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> C[i][j];
                seen[i][j] = false;
            }
        }

        int ans = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(C[i][j] == 0 || seen[i][j]) continue;
                ans++;
                dfs(i, j);
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3300
#include <iostream>

using namespace std;
long long a[100010],mod = 1000000007,ans = 1,r = 0,g = 0,b = 0;
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		long long cnt = 0;
		if(r==a[i]) cnt++;
		if(g==a[i]) cnt++;
		if(b==a[i]) cnt++;
		(ans *= cnt) %= mod;
		if(r==a[i]){
			r++;
		}else if(g==a[i]){
			g++;
		}else{
			b++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
 
int main(){
    int N[65535];
    int i = 0;
    while(1){
        scanf("%d", &N[i]);
        if(N[i] == 0) break;
        i++;
    }
 
    for (int j = 0; j < i; j++){
        cout << "Case " << j+1 << ": " << N[j] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1248
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}



int main(){
	int n;
	cin >> n;
	
	ll ans=0;
	
	for(int i=1; i<n; i++){
		
		
		ans += (n-1)/i;
	}
	
	cout << ans << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3592
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define MAXI (1<<32)
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define SIZ 1000005
#define SIZE 200005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*bool comp(const pair<ll,ll>&a,const pair<ll,ll>&b){
	return a.ff<b.ff || (a.ff==b.ff && a.ss<b.ss);
}*/

//ll p[20000005]={0};
//vector<ll>ans;
/*void sieve(){
    ll i,j;
    p[0]=p[1]=1;
    for(i=2;i*i<=20000005;i++){
        if(!p[i]){
            for(j=2*i;j<20000005;j+=i){
                p[j]=1;
            }
        }
    }
    fo(i,2,20000005){
        if(!p[i]){
            ans.pb(i);
        }
    }
}*/

signed main(){ 
    IOS
    //io_set();
    ll n, sum = 0;
    cin >> n;
    ll m = n;
    while(n){
        sum += n%10;
        n/=10;
    }
    if(m%sum == 0){
        cout << "Yes\n";
    }
    else{
        cout<< "No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#if 0
2019.12.17

只放两种值，一种是 k ，一种是 b (k > 0, b < 0) ，要求最大化所有值的和。
考虑在每个满足 x % w = y % h = 0 的 (x, y) 上放 b ，
这样每个 wxh 的子矩阵都会包含恰好一个 b ，且 b 的数量最少，
要每个每个 wxh 的子矩阵和小于 0 ，就是满足 (wh - 1)k + b < 0 ，
为了让 b 尽可能大，令 b = (1 - wh)k - 1 。
那么接下来再最大化 k ，因为要满足 b >= -1e9 ，也就是满足 (1 - wh)k >= 1 - 1e9 ，
令 k = (1e9 - 1) / (1 - wh) 即可，这样如果最大化的和仍小于 0 ，说明不合法。
需要特判的是 wh = 1 的情况。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 505;
int a[maxn][maxn];

int main() {
	int H = read, W = read, h = read, w = read;
	if(w * h == 1) return puts("No"), 0;
	int k = (1000000000 - 1) / (w * h - 1);

	ll sum = 0;
	for(int i = 1; i <= H; i ++)
		for(int j = 1; j <= W; j ++) {
			if(i % h == 0 and j % w == 0)
				a[i][j] = k - w * h * k - 1;
			else
				a[i][j] = k;
			sum += a[i][j];
		}

	if(sum > 0) {
		puts("Yes");
		for(int i = 1; i <= H; i ++) {
			for(int j = 1; j <= W; j ++)
				printf("%d ", a[i][j]);
			puts("");
		}
	} else
		puts("No");
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N;
    cin>>N;
    int cnt[N];
    fill_n(cnt,N,0);
    REP(i,N){
        int a;cin>>a;
        cnt[a]++;
    }
    int point =N-1;
    bool isPossible = true;
    while(point>=0){
        if(point==0){
            if(cnt[point]!=1)isPossible =false;

        }else if(cnt[point]!=2)isPossible=false;
        point-=2;
    }
    LL INF = 1000000007;
    LL ans=0;
    if(isPossible){
        ans=1;
        N--;
        while(N>0){
            ans*=2;
            ans%=INF;
            N-=2;
        }
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 640
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }


    let mut c0 = 0;
    let mut c1 = 0;
    let mut c2 = 0;
    let mut c3 = 0;
    for i in s {
        if &i == "AC" {
            c0 += 1;
        } else if &i == "WA" {
            c1 += 1;
        } else if &i == "TLE" {
            c2 += 1;
        } else if &i == "RE" {
            c3 += 1;
        }
/*
        match s1 {
            "AC" => { c0 += 1; },
            "WA" => { c1 += 1; },
            "TLE" => { c2 += 1; },
            "RE" => { c3 += 1; },
        }
*/
    }
    println!("AC x {}", c0);
    println!("WA x {}", c1);
    println!("TLE x {}", c2);
    println!("RE x {}", c3);
}


Measured memory_bytes: 7840
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n;
	cin>>n;
	if(n<1200)cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
 
#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}
 
 
void execute()
{
    int A, B;
    cin >> A >> B;
 
    cout << A * B << endl; 
}


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

int main(){
    int N,M, i, j, k, n;

    cin >> N;
    vector<string> blue(N);
    for(int i=0; i<N; i++){
        cin >> blue[i];
    }

    cin >> M;
    vector<string> red(M);
    for(int i=0; i<M; i++){
        cin >> red[i];
    }

    int sum=0;
    for(i=0; i<N; i++){
        string a = blue[i];
        int count = 0;

        for(j=i;j<N; j++){
            if(a==blue[j]){
                count++;
            }
        }
        for(k=0; k<M; k++){
            if(a==red[k]){
                count--;
            }
        }

        sum = max(sum, count);
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int[] L = new int[2 * N];
		for (int i = 0; i < 2 * N; i++)
		{
			L[i] = cin.nextInt();
		}
		Array.Sort(L);
		int ans = 0;
		for (int i = 0; i < N; i++)
		{
			ans += L[2 * i];
		}
		Console.WriteLine(ans);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2904
#include <iostream>

using std::cout;
using std::cin;

int main(int argc, const char * argv[]) {
    std::ios::sync_with_stdio(false);
    
    int stone725_is_pro;
    int a,b;
    
    cin>>stone725_is_pro;
    
    for(int i=0;i<stone725_is_pro;++i)
    {
        cin>>a>>b;
        cout<<(a-1)%b+1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<ll> ans(n+1, 0);
    vector<pair<int,pii>> vp;
    int pos = 0;
    while(pos < n){
        int npos = pos;
        while(npos < n && s[npos] == s[pos])    npos++;
        pii p;
        if(s[pos] == '<')   p = {pos, npos};
        else                p = {npos, pos};
        vp.push_back({npos-pos, p});
        pos = npos;
    }
    sort(vp.rbegin(), vp.rend());
    for(auto p : vp){
        int from = p.second.first, to = p.second.second;
        if(from < to){
            for(int i = 0; i+from <= to; i++)   ans[from+i] = max(ans[from+i], (ll)i);
        }else{
            for(int i = 0; from+i >= to; i--)   ans[from+i] = max(ans[from+i], -(ll)i);
        }
    }
    cout << accumulate(ans.begin(),ans.end(),0ll) << endl;
    return 0;
}

Measured memory_bytes: 8956
/*
    Union Findを使う。
    ―友達関係をcandidateという森構造でまとめる。 
    ―既に友達 or ブロック関係 で候補から外れるものをNGでまとめる
*/

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i<(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;


using graph = vector<vector<int>>;

struct UnionFind{
    vector<int> parent;
    UnionFind(int n) : parent(n,-1){};   // : を使っているのはUnionFindを呼び出した際の初期化操作だから
                                    // 全てを根として初期化(parent)
    int root(int x){    // 根はクラスタ―のサイズを負の数として記憶、それ以外は根の位置を記憶
        if(parent.at(x) < 0) return x; //根に到達したら、根のラベルを返す
        return parent.at(x)=root(parent.at(x)); //根を探すついでに木を低層に繋げなおす
    }

    void unite(int x,int y){
        x=root(x);  
        y=root(y);
        if(x==y) return;
        //xにyをつなぎ直す。
        parent.at(x)+=parent.at(y); //xが根になるのでクラスターのサイズの和をとる
        parent.at(y)=x; //yの根がxになる
    }

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

    int size(int x){
        return -parent.at(root(x));
    }
};

int main(void){
    int n,m,k;
    
    cin >> n >> m >> k;
    graph ng(n); // (0,n)の配列を作る
    UnionFind candidates(n);
    
    fr(i,0,m){
        int one, two;
        cin >> one >> two;
        --one;--two;

        ng.at(one).push_back(two);
        ng.at(two).push_back(one);
        candidates.unite(one,two);
    }

    fr(i,0,k){
        int one, two;
        cin >> one >> two;
        --one;--two;

        if(!candidates.same(one,two)) continue; //根が同じでないならスルー
        ng.at(one).push_back(two);  //同じならNGリストに載せる
        ng.at(two).push_back(one);
    }
    
    
    fr(i,0,n){
        cout << candidates.size(i)-1-ng.at(i).size() << " ";
    }
}


Measured memory_bytes: 8056
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
double A[10],B[10];
int main() {
double N;
cin >> N;
for (int i = 0; i < 5; ++i){
    cin >> A[i];
}
sort(A,A+5);
double ans;
  ans = ceil(N/A[0]) + 4;
cout << (int long long)ans <<endl;

return 0;

}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

class Node
{
    public:
    int number;// 部屋の番号。Nodes[2]なら3。Nodes[3]なら4。Nodes[i]ならi+1。
    set<int> next;// 任意のiに対して 部屋iと繋がっている部屋を集めている。
    int milestone = 0;// 道標。道標の指す部屋の番号。
    bool seen = false;// 見てあるかどうか
};

int main()
{
    int N,M;
    cin >> N >> M;// 何も言うことはない

    Node nodes[N];// N個の部屋
    for(int i=0;i<N;i++)
    {
        nodes[i].number = i+1;// 部屋番号を入力。
    }
    for(int i=0;i<M;i++)
    {
        int A,B;
        cin >> A >> B;
        A--;B--;

        nodes[A].next.insert(B);// M個の辺（道）の端点（部屋）に
        nodes[B].next.insert(A);// 隣になる部屋を設定
    }

    // queue: 入れた要素が配列の最後尾に追加されて、先頭の要素にのみアクセスできる。
    queue<Node> BFS;// BFS。
    BFS.push(nodes[0]);// 始点は0番目。

    while(!BFS.empty())// BFSに新たに追加できるNodeが無ければ徐々にqueueの要素は減っていってやがて0になる。
    {
        for(auto x : BFS.front().next)// BFS.front()の隣の部屋
        {
            if(!nodes[x].seen)// もしもこの部屋がまだ見られてなかったら
            {
                // 見られていない部屋が無ければqueueの要素は少なくなっていく。
                
                nodes[x].seen = true;// 見ました。
                
                nodes[x].milestone = BFS.front().number;// 来た道の直前の部屋
                
                BFS.push(nodes[x]);// この部屋をqueueに追加。
            }
        }
        BFS.pop();// 先頭の要素を削除。
    }


    cout << "Yes" << endl;// Noになるシチュエーションなど存在しない。
    for(int i=1;i<N;i++)
    {
        cout << nodes[i].milestone << endl;// それぞれの部屋の道標。0番目には道標がない。
    }

    return 0;
}

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

int main(void){
  char s[12],t[12];
  scanf("%s",s);
  scanf("%s",t);
  for(int i=0;i<strlen(s);i++){
    if(s[i]!=t[i]){
      printf("No\n");
     return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1660
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let S: String = read();
    println!("{}", &S[..].replace(",", " ") );

}


Measured memory_bytes: 4352
import sys, os
import collections

MOD = 10 ** 9 + 7

def solve(input_stream):
  N, K  = read_ints(input_stream)
  numbers = [int(i) - 1 for i in input_stream.readline().strip().split()]
  cumulative_sum = [0 for i in range(N + 1)]
  mods = {}
  ans = 0
  for index, number in enumerate(numbers):
    cumulative_sum[index + 1] = (cumulative_sum[index] + number) % K
  queue = []
  
  for index in range(N+1):
    if cumulative_sum[index] not in mods:
      mods[cumulative_sum[index]] = 0
    ans += mods[cumulative_sum[index]]
    mods[cumulative_sum[index]] += 1
    queue.append(cumulative_sum[index])
    if len(queue) == K:
      target = queue.pop(0)
      mods[target] -= 1
  return [str(ans)]

  


def read_ints(input_stream):
  return [i for i in map(int, input_stream.readline().strip().split())]

def read_int(input_stream):
  return int(input_stream.readline().strip())


if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Measured memory_bytes: 41344
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  N = parseInt(input[0].split(" "));
  var result = 0;
  for(var i=1; i<N; i++) {
    result += Math.floor((N-1)/i);
  }
  //出力
  console.log("%d", result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32596
#include<iostream>
#include<math.h>
using namespace std;
int n;
int x[30], y[30],h1,h2,d1,d2,s1,s2;
  
double dist(int a, int b){
    return sqrt(a*a+b*b+0.0);
}  
int main(){
    while(1){
		bool ok=true;
        cin >> n;
        if(n == 0) break;
        cin >>h1>>h2>>d1>>d2>>s1>>s2;
		if(dist(h1-s1,h2-s2)>= dist(d1-s1,d2-s2))ok=false;
        for(int i=1;i<n;i++){
            cin >> x[i] >> y[i];
			if(dist(h1-s1,h2-s2)+dist(s1-x[i],s2-y[i]) >= dist(d1-x[i],d2-y[i]))ok=false;
        }
  
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 2948
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    long long s = 0;
    for (int i = 1; i < n; ++i)
    {
        if (a[i] - a[i - 1] <= t)
            s += a[i] - a[i - 1];
        if (a[i] - a[i - 1] > t)
            s += t;
    }
    s += t;
    cout << s;
    return 0;
}


Measured memory_bytes: 4004
import java.util.Scanner;
import java.lang.Math;

class Main{
  
  	static int solve(int n, int k, int[] arr){
    	int[] dp = new int[n];
      	dp[0] = 0;
        dp[1] = Math.abs(arr[0] - arr[1]);
      
      	for(int i = 2; i < n; i++){
        	int min = dp[i-1] + Math.abs(arr[i-1] - arr[i]);
          
          	for(int j = 1; j <= k; j++){
            	if(i - j < 0)
                      break;

              	int h = dp[i-j] + Math.abs(arr[i] - arr[i-j]);
              	min = (h <= min) ? h : min;
            }
          	dp[i] = min;
        }
      
      	return dp[n-1];
    }

	public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
      	int n = scanner.nextInt();
      	int k = scanner.nextInt(); scanner.nextLine();
      	int[] arr = new int[n];
      	
      	for(int i = 0; i < n; i++){
        	arr[i] = scanner.nextInt();
        }
      
      	System.out.println(Main.solve(n,k,arr));
      
      	scanner.close();
    }
}

Measured memory_bytes: 59780
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, i, a[100000] = {}, flag = 0;
	cin >> N;
	for (i = 0;i < N;i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	for (i = 0;i < N;i++) {
		flag++;
		if (a[i] == a[i - 1] && a[i] > 0) {
			flag = flag - 2;
			a[i] = 0;
			a[i - 1] = 0;
		}
	}
	cout << flag << endl;
}

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

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

int a;

int main()
{
	int i, j;

	scanf("%d", &a);
	printf("%d\n", a+a*a+a*a*a);
}

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

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

    int min_cost = 100000;

    for (int i = 0; i < N; i++)
    {
        int c, t;
        cin >> c >> t;
        if (T >= t && min_cost > c)
        {
            min_cost = c;
        }
    }

    if (min_cost == 100000)
    {
        cout << "TLE" << endl;
        return 0;
    }

    cout << min_cost << endl;
    return 0;
}

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


int main()
{
    char s[51][51];
    int h,w,i,j,cons,ans,k,l;
    ans=0;

    for(i=0; i<=50; i++)
    {
        for(j=i; j<=50; j++)
        {
            s[i][j]=s[j][i]='.';
        }
    }
    scanf("%d%d",&h,&w);
    getchar();
    ans++;

    if(ans!=1) printf("\n");
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            scanf("%c",&s[i][j]);
        }
        getchar();
    }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            if(s[i][j]!='#')
            {
                cons=0;
                for(k=-1; k<=1; k++)
                {
                    for(l=-1; l<=1; l++)
                    {
                        if(s[i+k][j+l]=='#')
                            cons++;
                    }
                }
                s[i][j]='0'+cons;
            }
        }
    }


    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict as dd
from bisect import bisect_left, bisect

def stc(L, R, mp):
    m = 10**20
    for y, ll in L.items():
        if y not in R:
            continue
        ll.sort()
        for r in R[y]:
            i = bisect(ll, r)
            if i == len(ll):
                continue
            m = min(m, ll[i] - r)
    return m * mp


def main():
    N = int(input())
    UL, UR, DL, DR = dd(list), dd(list), dd(list), dd(list)
    ULa, URa, DLa, DRa = dd(list), dd(list), dd(list), dd(list)
    D, U, L, R = dd(list), dd(list), dd(list), dd(list)
    for _ in range(N):
        _x, _y, u = input().split()
        x, y = int(_x), int(_y)
        if u == 'U':
            UL[x - y].append(x)
            UR[x + y].append(x)
            U[x].append(y)
        elif u == 'D':
            DL[x + y].append(x)
            DR[x - y].append(x)
            D[x].append(y)
        elif u == 'L':
            ULa[x - y].append(x)
            DLa[x + y].append(x)
            L[y].append(x)
        else:
            URa[x + y].append(x)
            DRa[x - y].append(x)
            R[y].append(x)
    m = 10 ** 20
    m = min(m, stc(L, R, 5))
    m = min(m, stc(D, U, 5))
    m = min(m, stc(ULa, UL, 10))
    m = min(m, stc(UR, URa, 10))
    m = min(m, stc(DLa, DL, 10))
    m = min(m, stc(DR, DRa, 10))
    print('SAFE' if m >= 10 ** 20 else m)

main()


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += l.at(n - 1 - i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	vint v(10,-INF);
	v[0] = 0;
	rep(i,n){
		int t;
		cin>>t;
		vint pre = v;
		rep(j,10){
			maxs(v[(j+t)%10], pre[j]+t);
		}
	}
	int ans = 0;
	rep(i,1,10) maxs(ans, v[i]);
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

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

int n,m;

int main(){
    cin>>n>>m;
    out((n-1)*(m-1));
}

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

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

    long long int a,b; cin>>a>>b;
    a=a%b;

    long long int prev=a;
    bool to=true;
    while(to) {
        if(abs(b-prev)>=prev) to=false;
        else prev=abs(b-prev);
    }
    cout<<prev<<endl;


}


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

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

	int n , x , t ;
	cin >> n >> x >> t; 
	int k = n/x ; 
	if(n%x) 
		k++ ; 
	cout << k*t ;
          

}    


















Measured memory_bytes: 3560
from collections import Counter
import math
mod = 10**9+7
N,M = map(int,input().split())
factors = []
f = 2
while M%f==0:
    M//=2
    factors.append(f)
f = 3
while f*f<=M:
    if M%f==0:
        M//=f
        factors.append(f)
    else:
        f+=2
if M!=1:
    factors.append(M)
count = Counter(factors)

def choose(n,k):
    return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
ans = 1
for v in count.values():
    ans *= choose(N+v-1,N-1)
    ans %= mod
print(ans)

Measured memory_bytes: 114396
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 200000 + 10;

int n, arr[maxn];
char s[maxn];

int main() {
	scanf("%d%s", &n, s + 1);
	for(int i = 1;i <= n;i ++) arr[i] = arr[i - 1] + (s[i] == '.');
	arr[n + 1] = arr[n];
	int Ans = n + 1;
	for(int i = 0;i <= n;i ++) {
		int x = (i - arr[i]);
		int y = (arr[n] - arr[i]);
		Ans = min(Ans,x + y);
	}
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2e5+2;

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

      int n;
      cin>>n;
      int o=1;
      for(int i=0;i<n;i++)
      {
        int x;
        cin>>x;
        if(x==o)
        {
          o++;
        }
      }
      o--;
      if(o==0) cout<<"-1";
      else
      cout<<n-o;
} 
// I never lose. I either win or I learn

Measured memory_bytes: 384
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, M, Q = mapint_inp()
abcds = [list(mapint_inp()) for _ in range(Q)]

import itertools
l = []
for v in itertools.combinations_with_replacement(list(range(1,M+1)), N):
    l.append(v)
ans = 0
for x in l:
    t = 0
    for abcd in abcds:
        a, b, c, d = abcd
        if (x[b-1]-x[a-1])==c:
            t += d
    ans = max(ans, t)
print(ans)

Measured memory_bytes: 21612
#include <stdio.h>
using namespace std;

int main(void){
    int A,B,C,X;

    scanf("%d %d %d", &A,&B,&C);

    if(A==B){
        X=C;
    }else if(B==C){
        X=A;
    }else{
        X=B;
    }

    printf("%d \n", X);


    return 0;
}

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

char a [ 200100 ] , b [ 200100 ];
string s;
int cao_zuo;
string cz;
int ret = 1;//是否翻转 
int a_number , b_number;

int main ( void )
{
	cin >> s >> cao_zuo;
	getline ( cin , cz );
	for ( int i = 0 ; i < cao_zuo ; i++ ) {
		getline ( cin , cz );
		if ( cz [ 0 ] == '1' ) {
			ret = -ret;
		} else {
			if ( cz [ 2 ] == '1' ) {
				if ( ret == 1 ) {
					a [ a_number++ ] = cz [ 4 ];
				} else {
					b [ b_number++ ] = cz [ 4 ];
				}
			} else {
				if ( ret == 1 ) {
					b [ b_number++ ] = cz [ 4 ];
				} else {
					a [ a_number++ ] = cz [ 4 ];
				}
			}
		}
	}
	if ( ret == 1 ) {
		for ( int i = a_number - 1 ; i >= 0 ; i-- ) {
			cout << a [ i ];
		}
		for ( int i = 0 ; i < s.size ( ) ; i++ ) {
			cout << s [ i ];
		}
		for ( int i = 0 ; i < b_number ; i++ ) {
			cout << b [ i ];
		}
	} else {
		for ( int i = b_number - 1 ; i >= 0 ; i-- ) {
			cout << b [ i ];
		}
		for ( int i = s.size ( ) - 1 ; i >= 0 ; i-- ) {
			cout << s [ i ];
		}
		for ( int i = 0 ; i < a_number ; i++ ) {
			cout << a [ i ];
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, T;
	cin >> N >> T;
	int ans = 1 << 30;
	for (int i = 0; i < N; i++) {
		int c, t;
		cin >> c >> t;
		if (t <= T) {
			ans = min(ans, c);
		}
	}
	if (ans == 1 << 30) {
		cout << "TLE" << endl;
	}
	else {
		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;
int main()
{
    ll n;
    cin>>n;
    ll x=ceil(sqrt(n));
    ll dis=1ll<<50;
    for(ll i=1;i<=x;i++)
    {
        if(n%i==0)
        {
            dis=min(dis,i+n/i-2);
        }
    }
    cout<<dis;
    return 0;
}


Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
using namespace std; 
 
const int N = 1e3 + 100, T = 1e4 + 100, OO = 1e9 + 100, M = 1e9 + 7, P = 6151, SQ = 50, lg = 21;
typedef pair <int, int> pii;

int dp[N][T];
unordered_map <int, int> mp;

int32_t main() {
	use_fast;
	int h, n;
	cin >> h >> n;
	memset(dp, 43, sizeof(dp));
	int inf = dp[0][0];
	dp[0][0] = 0;
	set <int> s;
	for(int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		if(s.find(x) == s.end()) {
			s.insert(x);
			mp[x] = y;
		}
		else 
			mp[x] = min(mp[x], y);
	}
	int i = 0;
	for(auto u : s) {
		i++;
		int x = u, y = mp[u];
		for(int j = 0; j <= h; j++) {
			dp[i][j] = dp[i - 1][j];
			for(int k = 1; (k - 1) * x <= j; k++) {
				dp[i][j] = min(dp[i][j], dp[i - 1][max((int)0, j - k * x)] + k * y);
			}
			if(dp[i][j] == inf)
				break;
		}
	}
	cout << dp[i][h] << endl;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 87168
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int a = 1;
        
        while(true){
            int x = sc.nextInt();
            if(x == 0){
                break;
            }
            
            System.out.println("Case " + a + ": " + x);
            a++;
        }
        sc.close();
    }
}



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


	int main()
	{
		int h, w;
		cin >> h >> w;
		int** grid = new int*[h];
		for (int i = 0; i < h; i++)
			grid[i] = new int[w];
		int n;
		cin >> n;
		vector<int> colors;
		int num = 0;
		while (n--)
		{
			num++;
			int k;
			cin >> k;
			for (int i = 1; i <= k; i++)
				colors.emplace_back(num);
		}
		int x = 0, y = 0;
		for (int i = 0; i < colors.size(); i++)
		{
			grid[x][y] = colors[i];
			if (y % 2 == 0)
			{
				if (x < h - 1)
				{
					x++;
					continue;
				}
				if (x == h - 1)
				{
					y++;
					continue;
				}
			}
			if (y % 2 == 1)
			{
				if (x > 0)
				{
					x--;
					continue;
				}
				if (x == 0)
				{
					y++;
					continue;
				}
			}
		}
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
				cout << grid[i][j] << " ";
			cout << endl;
		}
		return 0;
}


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

int main() {
int a, b;
cin >> a >> b;
if (a >= b) {
    for (int i = 0; i < a; i++) {
        cout << b;
    }
}
else {
    for (int i = 0; i < b; i++) {
        cout << a;
    } 
    }
cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

//int cost[5001][5001];

int main(void) {
    int n;
    cin >> n;
    int a[n + 2];
    a[0] = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    a[n + 1] = 0;

//    for (int i = -5000; i <= 5000; ++i) {
//        for (int j = -5000; j <= 5000; ++j) {
//            cost[i][j] = abs(i - j);
//        }
//    }

    long long total = 0;
    for (int i = 0; i < n + 1; ++i) {
        total += abs(a[i + 1] - a[i]);
    }

    for (int i = 0; i < n; ++i) {
        long long ans;
        ans = total - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]);
        cout << ans << endl;
    }
    return 0;
}

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

// 插入此處

const int MAXN = 1e5 + 2;
bool vis[MAXN];
vector<int> adj[MAXN];

void dfs(int idx) {
    vis[idx] = true;
    for (auto x : adj[idx]) {
        if (!vis[x])  dfs(x);
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M; cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int x, y, z; cin >> x >> y >> z;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= N; ++i) {
        if (vis[i])  continue;
        dfs(i);
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105;
int a[N];
int main() {
    //freopen("in.txt","r",stdin);
    int n,m,sum=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a,a+n);
    int num=0;
    for(int i=n-1;i>=0;i--) {
        if(a[i]*4*m>=sum) num++;
        else break;
    }
    printf("%s\n",num>=m?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

const ll MOD = 1e9 + 7;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}

void __sol(){
    int n=5;// cin >> n;
    int a[n];
    forr(i,n) cin >> a[i];
    for(int i=0;i<5;i++){
        if(a[i]==0){
            cout << i+1;
            return;
        }
    }
}


int main(){
    fastio
    ll tc=1;// cin >> tc;
    while(tc--) __sol();
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(b + Math.min(b, c) + Math.min(Math.max(c - b, 0), a + 1));
    }
}


Measured memory_bytes: 23252
from itertools import accumulate
from collections import Counter
N, M = map(int, input().split())
As = list(map(int, input().split()))

def f(a, b):
    return (a+b)%M
cumsum = list(accumulate([0]+As, f))

answer = 0
for k, v in Counter(cumsum).items():
    answer += v * (v-1) // 2

print(answer)

Measured memory_bytes: 21612
import sys
input = sys.stdin.readline
from collections import *
from heapq import *

N, K = map(int, input().split())
td = [tuple(map(int, input().split())) for _ in range(N)]
td.sort(key=lambda t: t[1], reverse=True)
d = defaultdict(list)
now = 0

for ti, di in td[:K]:
    d[ti].append(di)
    now += di

remove = []

for k in d.keys():
    d[k].sort(reverse=True)
    
    for i in range(1, len(d[k])):
        heappush(remove, d[k][i])
    
s = set(list(d.keys()))
add = []

for ti, di in td:
    if ti in s:
        continue
    
    s.add(ti)
    heappush(add, -di)

x = len(d)
ans = now+x**2

while len(remove)>0 and len(add)>0:
    now -= heappop(remove)
    now -= heappop(add)
    x += 1
    ans = max(ans, now+x**2)

print(ans)

Measured memory_bytes: 84700
#include<cstdio>
#include<vector>

using namespace std;

int main(){
  int N,M,K,tmpA,res=0;
  vector<int> A;
  scanf("%d %d\n", &N, &M);
  for(int i=0;i<M;i++){
    A.push_back(0);
  }
  
  for(int i=0;i<N;i++){
    scanf("%d", &K);
    for(int j=0;j<K;j++){
      scanf("%d", &tmpA);
      A[tmpA-1]+=1;
    }
  }

  for(auto &num:A){
    if(num==N)
      res++;
  }
  
  printf("%d\n",res);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    int h,w;
	cin >> w >> h;
    vector <string> vec(w);

    for(int i = 0;i < w;i++)
    {
        cin >> vec.at(i);
    }
    for(int i = 0;i < w + 2;i++)
    {
        if(i == 0||i == w + 1)
        {
            for(int j = 0;j < h+2;j++)
            {
                cout << "#";
            }
            cout << endl;
            continue;
        }
        cout << "#" << vec.at(i-1) << "#" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct Node{
    int parent,left,right;
};
#define NIL -1
struct Node T[26];
int n,p,l,r,D[26],H[26];
int max(int a,int b){
    if(a<b) return b;
    else return a;
}
void printdegree(int x){
    int d=0;
    if(T[x].left!=NIL) d++;
    if(T[x].right!=NIL) d++;
    cout<<d;
}
int getheight(int x){
    int a=0,b=0;
    if(T[x].right==NIL && T[x].left==NIL){H[x]=0;}
    else{
        if(T[x].left!=NIL) a=getheight(T[x].left)+1;
        if(T[x].right!=NIL) b=getheight(T[x].right)+1;
        H[x]=max(a,b);
    }
    return H[x];
}
void  getdepth(int x,int u){
    D[x]=u;
    if(T[x].left!=NIL) getdepth(T[x].left,u+1);
    if(T[x].right!=NIL) getdepth(T[x].right,u+1);
}
void printsibling(int x){
    int p=T[x].parent;
    if(T[x].parent==NIL) cout<<NIL;
    else if(T[p].left==x) cout<<T[p].right;
    else cout<<T[p].left;
}
int main(){
    int d,s;
    cin>>n;
    for(int i=0;i<n;i++) T[i].parent=T[i].left=T[i].right=NIL;
    for(int i=0;i<n;i++){
        cin>>p>>l>>r;
        if(l!=NIL){T[p].left=l; T[l].parent=p;}
        if(r!=NIL){T[p].right=r; T[r].parent=p;}
    }
    for(int i=0;i<n;i++){
        if(T[i].parent==NIL) s=i;
    }
    getdepth(s,0);
    getheight(s);
    for(int i=0;i<n;i++){
        cout<<"node "<<i<<": ";
        cout<<"parent = "<<T[i].parent<<", ";
        cout<<"sibling = "; printsibling(i);cout<<", ";
        cout<<"degree = "; printdegree(i); cout<<", ";
        cout<<"depth = "<<D[i]<<", ";
        cout<<"height = "<<H[i]<<", ";
        if(T[i].parent==NIL) cout<<"root";
        else if(T[i].left==NIL &&T[i].right==NIL) cout<<"leaf";
        else cout<<"internal node";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <set>
#include <bitset>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define LAST(i,n) if(i==n-1)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

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

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

    vector<lint> A;
    FOR(_, 0, pow(2,N)) {
      lint a; cin >> a; A.push_back(a);
    }

    lint res = 0;
    vector<P> maxpair;
    maxpair.push_back(P(-1,-1));

    FOR(K, 1, pow(2, N)) {
      P p;
      if(!(K&(K-1))) {
        p=P(0, K);
      }
      else {
        set<lint> s;
        s.insert(K);

        REP(i, N) {
          lint mask = 1 << i;
          if ((K & mask) == mask) {
            lint masked = K & ~mask;

            s.insert(maxpair[masked].first);
            s.insert(maxpair[masked].second);
          }
        }
    
        lint first = -1;
        lint second = -1;
        for(set<lint>::iterator it = s.begin();
            it != s.end();
            ++it){
          if (first == -1 || A[*it] >= A[first]) {
            if(first != -1) {
              second = first;
            }
            first = *it;
          }
          else if(second == -1 || A[*it] >= A[second]) {
            second = *it;
          }
        }
        p = P(first, second);
      }

      //            cout << "K "<< K << " " <<  p.first << " -> " << A[p.first] << " " << p.second << " -> " << A[p.second] << "\n";

      maxpair.push_back(p);
      res = max(res, A[p.first] + A[p.second]);
      PRINT(res);
    }

    return 0;
}


Measured memory_bytes: 9840
#include <iostream>

#define N_MAX 1000

using namespace std;

int c[N_MAX];
int t[N_MAX];

int main(){
    int N, T;
    int cost_min = 1001;
    bool flag = false;
    cin >> N >> T;
    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];
        if(t[i] <= T){
            flag = true;
            if(c[i] < cost_min){
                cost_min = c[i];
            }
        }
    }
    if(flag == false){
        cout << "TLE\n";
    }else{
        cout << cost_min << '\n';
    }
}

Measured memory_bytes: 888
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
S = sorted(S)
T = sorted(T)
reg = 0
count = 0
for i in range(q):
    for j in range(reg, n):
        if T[i] > S[j]:
            reg = j
        elif T[i] == S[j]:
            reg = j
            count += 1
            break
        else:
            break
print(count)


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

n = int(input())
ss = [Counter(input()) for _ in range(n)]

s = ''
for c in sorted(reduce(lambda x, y: x & y, [{c for c, n in s.items()} for s in ss])):
    s += c * min(s[c] for s in ss)

print(s)



Measured memory_bytes: 3692
#include <stdio.h>

int gcd(int x, int y) {
  int r, tmp;
  if(x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }
  return x;
}

int main(void) {
  int x, y;
  scanf("%d %d", &x, &y);
  printf("%d\n",(x+1)+(y+1)-(gcd(x, y)-1)-2);
  return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

struct Card {
  char suit;
  int num;
};

bool operator==(Card lhs, Card rhs) {
  return lhs.suit == rhs.suit && lhs.num == rhs.num;
}

int partition(vector<Card> &A, int p, int r) {
  auto x = A[r].num;
  auto i = p - 1;
  FOR(j, p, r) {
    if (A[j].num <= x) swap(A[++i], A[j]);
  }
  swap(A[i + 1], A[r]);
  return i + 1;
}

void quick_sort(vector<Card> &A, int p, int r) {
  if (p < r) {
    auto q = partition(A, p, r);
    quick_sort(A, p, q - 1);
    quick_sort(A, q + 1, r);
  }
}

int main() {
  int n;
  cin >> n;
  vector<Card> A1(n);
  REP(i, n) cin >> A1[i].suit >> A1[i].num;
  auto A2 = A1;
  quick_sort(A1, 0, n - 1);
  stable_sort(ALL(A2), [](Card a, Card b) {
    return a.num < b.num;
  });
  cout << (equal(ALL(A1), A2.begin()) ? "Stable" : "Not stable") << endl;
  for (auto a : A1) {
    cout << a.suit << " " << a.num << endl;
  }
}


Measured memory_bytes: 4684
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  int n,a;
  cin >> n >> a;
  if(n%500 <= a) cout(__TRUE);
  else cout(__FALSE);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ds := make([]int, n+1)
	ds[0] = 0
	for i := 1; i < len(ds); i++ {
		fmt.Scan(&ds[i])
	}
	sort.Ints(ds)

	ans := max(calc(ds, 0), calc(ds, 1))
	fmt.Println(ans)
}

func calc(ds []int, x int) int {
	n := len(ds)
	ts := make([]int, n)
	copy(ts, ds)

	for i := 0; i < len(ts); i++ {
		if i%2 == x && ts[i] > 0 {
			ts[i] = 24 - ts[i]
		}
	}
	ts = append(ts, 24)
	sort.Ints(ts)

	t := int(1e9)
	for i := 1; i < len(ts); i++ {
		t = min(t, abs(ts[i]-ts[i-1]))
	}

	return t
}

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

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

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


Measured memory_bytes: 512