akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		int a[] = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[a.length - 1] - a[0]);
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int num[310][310],sum[310],n,m;
bool bo[310];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) num[i][j]=rd();
	for (int i=1;i<=m;i++) bo[i]=true;
	for (int i=1;i<=n;i++) sum[num[i][1]]++;
	int ans=0;
	for (int i=1;i<=m;i++) ans=max(ans,sum[i]);
	for (int hhhh=1;hhhh<m;hhhh++)
	{
		int id=0;
		for (int i=1;i<=m;i++) if (bo[i]&&sum[i]>sum[id]) id=i;
		bo[id]=false;
		for (int i=1;i<=m;i++) sum[i]=0;
		for (int i=1;i<=n;i++)
		{
			int id=0;
			for (int j=1;j<=m;j++) if (bo[num[i][j]]) { id=num[i][j];break; }
			sum[id]++;
		}
		int res=0;
		for (int i=1;i<=m;i++) res=max(res,sum[i]);
		ans=min(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
S = input()
A = ''.join([str(i % 2) for i in range(len(S))])
B = ''.join([str((i + 1) % 2)  for i in range(len(S))])

ans1 = ans2 = 0

for a, b in zip(S, A):
    if a != b:
        ans1 += 1

for a, b in zip(S, B):
    if a != b:
        ans2 += 1

print(min(ans1, ans2))

Measured memory_bytes: 9588
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
	char s[105];
	while (~scanf("%s", s))
	{
		int len = strlen(s);
		printf("%c%d%c\n", s[0], len-2, s[len-1]);
	}
	return 0;
}

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

int main() {
  int A,B;
  cin>> A >>B;
  
  if((A+B)%2 == 0){
    cout << (A+B)/2 << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

signed main(){ 
   string s,t;
   cin>>s>>t;

   int n=s.size();
   int result=0;

   for(int i=0;i<n;i++){
       if(s[i]!=t[i]) result++;
   }

   cout<<result<<endl;
}  

Measured memory_bytes: 3820
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k;
char s[5005],t[5005],ss[10005],res[5005];
void check()
{
	int len=0;
	for(int i=2;i<k;i++)
	{
		while(s[n-len]==s[n])len++;
		for(int j=len+1;j<=n+len;j++)
		{
			if(j<=n)t[j-len]=s[j];
			else t[j-len]=s[2*n-j+1];
		}
		for(int j=1;j<=n;j++)s[j]=t[j];
	}
	while(s[n-len]==s[n])len++;
	for(int i=n-len+1;i<=2*n-len+1;i++)
	{
		if(i<=n)t[i-(n-len)]=s[i];
		else t[i-(n-len)]=s[2*n-i+1];
	}
	for(int j=1;j<=n;j++)s[j]=t[j];
	for(int i=1;i<=n;i++)
	{
		if(res[i]==s[i])continue;
		if(res[i]>s[i])
		{
			for(int j=i;j<=n;j++)
			  res[j]=s[j];
		}
		break;
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	char minn='z';
	for(int i=1;i<=n;i++)minn=min(minn,s[i]);
	int l=1;
	for(int i=3;i<=k;i++)
	{
		l<<=1;
		if(l>n)
		{
			for(int i=1;i<=n;i++)putchar(minn);
			putchar('\n');
			return 0;
		}
	}
	for(int i=1;i<=n;i++)res[i]='z';
	for(int i=1;i<=n;i++)ss[i]=s[i];
	for(int i=n+1;i<=2*n;i++)ss[i]=s[2*n-i+1];
	for(int en=n;en<=2*n;en++)
	{
		int st=en-n+1;
		for(int i=st;i<=en;i++)s[i-st+1]=ss[i];
		if(k==1)
		{
			for(int i=1;i<=n;i++)
			{
				if(res[i]==s[i])continue;
				if(res[i]>s[i])
				{
					for(int j=i;j<=n;j++)
					  res[j]=s[j];
				}
				break;
			}
		}
		else if(ss[en]==minn)check();
	}
	res[n+1]='\0';
	printf("%s\n",res+1);
	return 0;
}

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

typedef long long LL;

const int N = 50;
const int M = 250;

bool mat[N][N];

int n, m, s;
LL mod;

LL pow_mod(LL x, int p){
    LL s = 1;
    while(p){
        if(p & 1)   s = s * x % mod;
        x = x * x % mod;
        p >>= 1;
    }
    return s;
}

int query(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c, d);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}

void solve(int x1, int x2, int y1, int y2, int div, int s){
    if(s == 0 || x1 > x2 || y1 > y2)  return;
    int area = (x2 - x1 + 1) * (y2 - y1 + 1);
    if(area == s){
        for(int i=x1; i<=x2; i++){
            for(int j=y1; j<=y2; j++){
                mat[i][j] = 1;
            }
        }
        return;
    }
    if(x1 == x2 && div){
        div ^= 1;
    } else if(y1 == y2 && !div){
        div ^= 1;
    }
    if(div){
        int mid = x1 + x2 >> 1;
        int ans = query(x1, y1, mid, y2);
        solve(x1, mid, y1, y2, 1^div, ans);
        solve(mid+1, x2, y1, y2, 1^div, s - ans);
    } else {
        int mid = y1 + y2 >> 1;
        int ans = query(x1, y1, x2, mid);
        solve(x1, x2, y1, mid, 1^div, ans);
        solve(x1, x2, mid+1, y2, 1^div, s - ans);
    }
}

int main(){
    while(~scanf("%d %d %d %lld", &n, &m, &s, &mod)){
        memset(mat, 0, sizeof(mat));
        for(int i=0; i<n-1; i++){
            int g = query(i, 0, i, m-1);
            if(g){
                solve(i, i, 0, m-1, 1, g);
                s -= g;
            }
        }
        solve(n-1, n-1, 0, m-1, 1, s);

        LL ans = 0;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(mat[i][j]){
                    ans = (ans + pow_mod(2, i*m+j)) % mod;
                }
            }
        }
        printf("! %lld\n", ans);
        fflush(stdout);
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<string> v1(n);
  vector<string> v3(n);
  for(int i = 0; i < n; i++){
    cin >> v1[i];
    v3[i] = v1[i];
  }

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

  for(int i = 0; i < m; i++){
    v3.push_back(v2[i]);
  }

  vector<string> v(0);
  sort(v3.begin(), v3.end());
  for(int i = 0; i < m + n; i++){
    if(i == 0){
      v.push_back(v3[0]);      
    }
    else if(v3[i] != v3[i - 1]){
      v.push_back(v3[i]);
    }
  }

  vector<int> w(v.size(), 0);
  for(int i = 0; i < v.size(); i++){
    for(int j = 0; j < n; j++){
      if(v[i] == v1[j]){
        w[i]++;
      }
    }
    for(int j = 0; j < m; j++){
      if(v[i] == v2[j]){
        w[i]--;
      }
    }
  }

  sort(w.begin(), w.end());
  if(w[v.size() - 1] > 0){
    cout << w[v.size() - 1] << endl;
  }
  else{
    cout << 0 << endl;
  }
}

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

int main() {
	long long l, r;
	cin >> l >> r;
	if(l % 2019 == 0)
		return cout << l, 0;
	vector<int> v;
	for(int i = l; i <= r; ++i) {
		if(i % 2019 < l % 2019)
			return cout << i % 2019, 0;
		v.push_back(i % 2019);
	}
	int mini = 1e9;
	for(int x : v) {
		for(int y : v) {
			if(x == y)
				continue;
			mini = min(mini, x * y % 2019);
		}
	}
	cout << mini;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

int main() {
    int x;
    cin >> x;
    ll ans = x;
    while(!prime(ans)){
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;
vector<pair<ll,ll>>prime_factorize(ll n){
  vector<pair<ll,ll>>res;
  for(ll p=2;p*p<=n;p++){
    if(n%p!=0)continue;
    ll num=0;
    while(n%p==0){
      num++;
      n/=p;
    }
    res.push_back(make_pair(p,num));
  }
  if(n!=1)res.push_back(make_pair(n,1));
  return res;
}
int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  map<ll,ll>mp;
  rep(i,n){
    cin >> a[i];
    auto pf=prime_factorize(a[i]);
    for(auto p:pf){
      mp[p.first]=max(mp[p.first],p.second);
    }
  }
  mint lcm=1;
  for(auto p:mp){
    lcm*=modpow(mint(p.first),p.second);
  }
  mint ans=0;
  rep(i,n){
    ans+=lcm/a[i];
  }
  cout << ans << endl;
}

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

const int mod = 1e9+7;

int main() {
    int S;
    cin >> S;
    vector<ll> A(S+1, 0);
    A[0] = 1;
    for (int i=3; i<=S; i++) {
        for (int j=i-3; j>=0; j--) {
            A[i] = (A[i]+A[j])%mod;
        }
    }
    cout << A[S] << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

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

		int doubleTimes = 0;
		while (a >= b) {
			b = b * 2;
			doubleTimes++;
		}
		while (b >= c) {
			c = c * 2;
			doubleTimes++;
		}
		boolean answer = k >= doubleTimes;

		printBool(answer);
	}

	public static void printBool(boolean bool) {
		print(bool ? "Yes" : "No");
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 35644
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int x,y;
};

int N,POW[21];
Info start,enemy,info[21];
double dist_table[21][21],poison_TIME[20];
bool FLG;

double calc_Time(Info from,Info to){
	return sqrt((from.x-to.x)*(from.x-to.x)+(from.y-to.y)*(from.y-to.y));
}

void dfs(int node_id,int count,double total_time,int state){

	if(count == N){
		FLG = true;
	}
	if(FLG)return;

	for(int i = 0; i < N; i++){
		if(state & (1 << i)){
			//Do nothing
		}else{
			double next_time = total_time+dist_table[node_id][i];
			if(next_time >= poison_TIME[i])return;
		}
	}

	for(int i = 0; i < N; i++){
		if(state & (1 << i)){
			//Do nothing
		}else{
			double next_time = total_time+dist_table[node_id][i];
			int next_state = state + POW[i];
			dfs(i,count+1,next_time,next_state);
		}
	}
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%d %d",&info[i].x,&info[i].y);
		poison_TIME[i] = calc_Time(info[i],enemy);
	}
	info[N].x = start.x;
	info[N].y = start.y;

	double tmp;
	for(int i = 0; i < N; i++){
		for(int k = i+1; k <= N; k++){
			tmp = calc_Time(info[i],info[k]);
			dist_table[i][k] = tmp;
			dist_table[k][i] = tmp;
		}
	}

	FLG = false;

	dfs(N,0,0,0);

	if(FLG){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
}

int main(void){

	for(int i = 0; i <= 20; i++)POW[i] = pow(2,i);

    while(true){
    	scanf("%d %d %d %d %d",&N,&start.x,&start.y,&enemy.x,&enemy.y);

    	if(N == 0)break;

    	func();
    }
    return 0;
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll nodenum;
vector<ll> node;

ll init_num=0;
ll func(ll x,ll y){
    return x|y;
}

//セグ木
void init(vector<ll> v){
    nodenum=1;
    while(v.size()>nodenum)nodenum*=2;
    node.resize(2*nodenum-1,init_num);
    rep(i,nodenum-1,nodenum*2-2){
        if(i-(nodenum-1)<v.size()){
            node[i]=v[i-(nodenum-1)];
        }else{
            node[i]=init_num;
        }
    }
    for(ll i=nodenum-2;i>=0;i--){
        node[i]=func(node[2*i+1],node[2*i+2]);
    }
}

void update(ll x,ll y){ //v[x]をyに変更する
    node[x+nodenum-1]=y;
    ll next=x+nodenum-1;
    while(next>0){
        next=(next-1)/2;
        node[next]=func(node[2*next+1],node[2*next+2]);
    }
}

ll find(ll i,ll j,ll x,ll y,ll z){     //v[[i,j)]でのfuncの結果を出力する //node[x]に着目しているnode[x]が担当する範囲は[y,z); //最初はx=-1で
    if(x==-1) return find(i,j,0,0,nodenum);
    if(j<=y || z<=i)return init_num;
    if(i<=y && z<=j)return node[x];
    return func(find(i,j,2*x+1,y,(y+z)/2),find(i,j,2*x+2,(y+z)/2,z));
}

int main(){
    ll n,q;string s;cin>>n>>s>>q;
    ll que;
    vector<ll> ans;
    vector<ll> v;
    ll kk;
    rep(i,0,s.size()-1){
        rep(j,0,alp.size()-1){
            if(s[i]==alp[j]){
                kk=pow(2,j);
                v.pb(kk);
            }
        }
    }
    init(v);
    /*
     rep(j,0,nodenum*2-2){
        cout<<node[j];
    }
    cout<<endl;*/
    rep(i,0,q-1){
        cin>>que;
        if(que==1){
            ll I;
            char c;
            cin>>I>>c;
            ll k;
            rep(j,0,25){
                if(c==alp[j]){
                    k=pow(2,j);
                }
            }
            update(I-1,k);
            
        }else{
            ll l,r;cin>>l>>r;
            ll total=find(l-1,r,-1,0,0);
            ll sum=0;
            rep(j,0,25){
                if((total>>j)%2==1){
                    sum++;
                }
            }
            ans.pb(sum);
        }
        /*
        rep(j,nodenum-1,nodenum*2-2){
            cout<<node[j];
        }
        cout<<endl;*/
    }
    rep(i,0,ans.size()-1){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 17012
#include <cmath>
#include <iostream>
 
using namespace std;
 
int main()
{
    int n, t;
 
    bool check;
 
    cin >> n;
 
    for (int i = 1; i <= n; i++)
    {
        check = false;
 
        if (i % 3 == 0)
        {
            check = true;
        }
        else
        {
            t = i;
 
            for (int j = 0; j <= 5; j++)
            {
                if (t % 10 == 3)
                {
                    check = true;
                }
 
                t /= 10;
            }
        }
 
        if (check == true)
        {
            cout << ' ' << i;
        }
    }
 
    cout << endl;
 
    return 0;
}


Measured memory_bytes: 3068
#ABC095C
A, B, C, X, Y=map(int, input().split())
ans1=X*A+Y*B
if X>Y:
    ans2=Y*2*C+(X-Y)*A
else:
    ans2=X*2*C+(Y-X)*B
ans3=max(X, Y)*2*C
print(min(ans1, ans2, ans3))


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

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

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

        if x == y:
            return

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

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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

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

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

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    uf.union(x-1, y-1)

print(uf.group_count())


Measured memory_bytes: 7856
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n + 1],
        b: [i64; n],
    }

    let mut ans = 0;
    for i in 0..n {
        let front = b[i].min(a[i]);
        a[i] -= front;
        ans += front;

        let back = (b[i] - front).min(a[i + 1]);
        a[i + 1] -= back;
        ans += back;
    }
    println!("{}", ans);
}


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

int n;
long long L;
long long a[101010];
vector<int> ans;

int main() {
	cin >> n >> L;
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	vector<long long> sum(n + 1);
	for (int i = 0; i < n; i++) {
		sum[i + 1] = sum[i] + a[i];
	}

	int l = 0, r = n - 1;
	while (l < r) {
		if (sum[r + 1] - sum[l] < L) {
			cout << "Impossible" << endl;
			return 0;
		}
		if (a[l] + a[l + 1] < L) {
			ans.push_back(l + 1);
			l++;
		} else {
			ans.push_back(r);
			r--;
		}
	}

	cout << "Possible" << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 2936
n = int(input())
inputs = [list(map(int, input().split())) for _ in range(n)]
values = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for i in inputs:
    values[i[0]-1][i[1]-1][i[2]-1] += i[3]
for b in range(4):
    for f in range(3):
        print(' ', end='')
        print(*values[b][f])
    if b != 3:
        print('#'*20)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a, b;
	cin >> a >> b;
	if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}                                     
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;
int n,k;
int t[500000];
pair<int,int> p[300000];
int main(){
	
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>t[i];
	for(int i=0;i<=n;i++){
		p[i]=make_pair(0,i);
	}
	for(int i=0;i<n;i++){
		p[t[i]].first++;
	}

	int cnt=0;
	vector<pair<int ,int > >x;
	for(int i=0;i<=n;i++){
	if(p[i].first!=0){cnt++;x.push_back(p[i]);}
	}
	
	sort(x.begin(),x.end());
	
	int ans=0;
	//for(int i=0;i<cnt;i++)cout<<x[i].first<<" "<<x[i].second<<endl;

	if(cnt<=k)ans=0;

	else{
	for(int i=0;i<cnt-k;i++)ans+=x[i].first;
	}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 6004
import itertools
N = int(input())
P = tuple(list(map(int, input().split())))
Q = tuple(list(map(int, input().split())))

l = [int(i) for i in range(1, N+1)]

r = sorted(list(p for p in itertools.permutations(l)))
# print(r)

print(abs(r.index(P) - r.index(Q)))


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-12;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll xs, ys, xt, yt, n;
	cin >> xs >> ys >> xt >> yt >> n;

	n += 2;
	vl x(n), y(n), r(n);
	x[0] = xs, y[0] = ys, r[0] = 0;
	x[1] = xt, y[1] = yt, r[1] = 0;

	FOR(i,2,n) cin >> x[i] >> y[i] >> r[i];

	vector<long double> dist(n,1e100);
	vector<bool> done(n);

	dist[0] = 0;
	
	while (true) {
		ll i = -1;
		FOR(j,0,n) if (!done[j] && (i == -1 || dist[j] < dist[i])) i = j;
		done[i] = true;
		if (i == 1) break;
		FOR(j,0,n) if (j != i) {
			ll dx = x[i]-x[j], dy = y[i]-y[j];
			long double len = 0;
			if (dx*dx + dy*dy > (r[i]+r[j])*(r[i]+r[j]))
				len = sqrt((long double)(dx*dx + dy*dy)) - r[i] - r[j];
			
			if (dist[j] < dist[i] + len) continue;
			dist[j] = dist[i] + len;
		}
	}
	cout << fixed << setprecision(40) << dist[1] << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int a;
    cin >> a;
    cout << (a + a*a + a*a*a) << endl;
    return 0;
}


Measured memory_bytes: 3604
let words str =
  let len = String.length str in
  let buf = Buffer.create 10 in
  let rec loop cont = function
      i when i = len -> cont [Buffer.contents buf |> int_of_string]
    | i ->
      loop
        (match str.[i] with
         | ' ' ->
           let v = Buffer.contents buf |> int_of_string in
           Buffer.clear buf; (fun x -> cont (v::x))
         | c ->
           Buffer.add_char buf c; cont)
        (i+1)
  in loop (fun x -> x) 0

let setTable table seq =
  let rec loop acc = function
      [] -> ()
    | h::t -> let v = h+acc in
              table.(v) <- true;
              loop acc t;
              loop v t
  in loop 0 seq
       
let () =
  let _ = read_int () in
  let an = read_line () |> words in
  let _ = read_int () in
  let mi = read_line () |> words in
  let table = Array.make 20001 false in
  setTable table an;
  List.iter (fun x -> Printf.printf "%s\n" (if table.(x) then "yes" else "no"))
            mi

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

using namespace std;

int main()
{
    char a, b;
    while (cin >> a >> b) {
        if (a > b)
            cout << ">" << endl;
        else if (a == b)
            cout << "=" << endl;
        else
            cout << "<" << endl;
    }
    return 0;
}


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

#ifdef LOCAL 
string to_string(char a) { return string(1,a); }
string to_string(bool a) { return a ? "1" : "0"; }
string to_string(const char* a) { return (string)a; }
string to_string(string a) { return a; }
string to_string(vector<bool> v) {
	string s = "["; for(unsigned i=0;i<v.size();i++){ s += ((i>0)?" ":"");
    s += char('0'+v[i]); } 	s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) {
	bool b = 1; string s = "["; for (const auto& x: v) {
		if (!b) {s += ", ";} b = 0; s += to_string(x); } s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void dbgf() { cerr << endl; }
template<class H, class... T> void dbgf(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	dbgf(t...); }
#define dbg(...) cerr << #__VA_ARGS__ << " = ", dbgf(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#define boolout(x) cout<<(x?"YES":"NO")<<endl;
typedef long long ll;

const int MOD = 1000000007;

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

    vector<vector<ll>> dp(n, vector<ll>(n, -1));

    for (int l = n-1; l >= 0; --l) {
        for (int r = l; r < n; ++r) {
                
            if (l==r) {
                dp[l][r]=a[l];
                continue;
            }
            ll temp1 = a[l] - dp[l+1][r];
            ll temp2 = a[r] - dp[l][r-1];
            dp[l][r] = max(temp1, temp2);
        }
    }

    cout << dp[0][n-1] << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t; // read t. cin knows that t is an int, so it reads it as such.
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 70784
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<int> B(N-1);
    for(int i=0; i<N-1; i++) cin >> B[i];

    int ans = B[0];
    for(int i=1; i<N-1; i++) {
        ans += min(B[i-1], B[i]);
    }
    ans += B[N-2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int hp,n;
int atk[1001];
int cost[1001];
int mem[10001];
//int temp[10000];
int templen=0;
int f(int hp){
  if (hp<=0&&hp!=-99999) return 0;
  if (mem[hp]>0) return mem[hp];
  
  int minn=99999999+99999999;
  for (int i=0;i<n;i++){
    if (hp>0){
      int x=f(hp-atk[i])+cost[i];
      //temp[templen]=i;
      //templen++;
      if (x<minn) minn=x;
      //if (hp-atk[i]<=0) cout<<minn<<endl;
    }//else cout<<minn<<endl;
  }

  mem[hp]=minn;
  return minn;
}
int main() {
  
  cin>>hp>>n;
  for (int i=0;i<n;i++){
    cin>>atk[i]>>cost[i];
  }
  mem[0]=0;
  for (int i=1;i<10001;i++){  
    mem[i]=-99999;  
  }  
  /*
  int maxn=0,ind;
  for(int i=0;i<n;i++){
    if(atk[i]/cost[i]>maxn) {
      maxn=atk[i]/cost[i];
      ind=i;
    }
  }
  */

  /*
  if (hp>=100){
    int y=hp*0.1;
    while(hp>=y){
      hp-=atk[ind];
      mp+=cost[ind];
      //cout<<"#";
    }
  }
  */
  //cout<<"ind "<<ind<<endl;
  //for (int i=0;i<=hp;i++){  
    //cout<<i<<"  "<<mem[i]<<endl;
  //}  
  cout<<f(hp)<<endl;
}

Measured memory_bytes: 3636
program aaa

integer :: n, i
integer,allocatable,dimension(:) :: h, dp

read*, n
allocate(h(n))
allocate(dp(n))
read*, h

dp=0
dp(1)=0
dp(2)=abs(h(2)-h(1))

if(n==2) then
write(*,'(i0)') dp(2)
return
end if

do i=3, n
dp(i)=min(dp(i-2)+abs(h(i-2)-h(i)),dp(i-1)+abs(h(i-1)-h(i)))
end do

write(*,'(i0)') dp(n)

end program


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ;
  cin >> N ;
  if(N%111 == N%10 || N-111*(N%10) == N/1000*1000){
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin >> N;
  int M = N % 10;
  
  if ( M == 2 || M == 4  || M == 5 || M == 7  || M ==  9){
    cout << "hon" << endl;
  }
  
    else if ( M ==  0|| M == 1  || M == 6 || M == 8 ){
    cout << "pon" << endl;
  }
  
  else {
    cout << "bon" << endl;
  }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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 YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.size();
    
    VVi dp(n+1,Vi(13,0));
    dp[0][0]=1;
    REP(i,0,n){
        if(s[i]!='?'){
            int d=stoi(s.substr(i,1));
            REP(j,0,13){
                int next=(j*10+d)%13;
                dp[i+1][next]+=dp[i][j];
            }
        }else{
            REP(d,0,10){
            REP(j,0,13){
                int next=(j*10+d)%13;
                dp[i+1][next]=(dp[i+1][next]+dp[i][j])%MOD;
            }
            }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
}


Measured memory_bytes: 13648
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Main().run();
		// System.err.println(System.currentTimeMillis() - t);
	}

	void run() {
		Scanner sc = new Scanner();
		String s = sc.next();
		System.out.println(f(s, 0, s.length()));
	}

	int f(String s, int a, int b) {
		if (b - a <= 1) {
			return 0;
		}
		if (s.charAt(a) == s.charAt(b - 1)) {
			return f(s, a + 1, b - 1);
		}
		if (s.charAt(a) == 'x') {
			return 1 + f(s, a + 1, b);
		} else if (s.charAt(b - 1) == 'x') {
			return 1 + f(s, a, b - 1);
		} else {
			System.out.println(-1);
			System.exit(0);
		}
		throw new AssertionError();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


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

int main() {
  int N , a[110];
  std::cin >> N;
  for (size_t i = 0; i < N; i++) {
  std::cin >> a[i];/* code */
  }
  sort(a,a+N);
  reverse(a,a+N);
  int A=0,B=0;
  for (size_t i = 0; i < N; i++) {
    if (i%2==0) {
      A+=a[i];/* code */
    }/* code
    */else{B+=a[i];}
  }
  std::cout << A-B << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;
const int MAX = 510000;
const int MOD = 1000000007;
 const int NINE=1000000000;
 
 
int main(){
ll N;
  cin>>N;
  vector<ll>op(N);
  rep(i,N){
  ll k;
    cin>>k;
    op[i]=k;
  }
vector<ll>sum(N);
  sum[0]=op[0];
  rep(i,N-1) sum[i+1]=sum[i]+op[i+1];
  map<ll,ll>ki;
  ll ans=0;
  rep(i,N){
  if(ki.count(sum[i]) ){
  ll p=ki.at(sum[i]);
  ans=ans+p;
    p++;
    ki[sum[i]]=p;
  }
 else if(sum[i]==0){
 ans++;
 ki[0]=2;
 }
    else ki[sum[i]]=1;
    
  }
  
  cout<<ans<<endl;

}

Measured memory_bytes: 15872
N = int(input())
H = tuple(reversed(tuple(map(int, input().split()))))
assert len(H) == N

result = True
prev = None
for i,h in enumerate(H):
  if prev is not None:
    if h > prev + 1:
      result = False
      break
    if h < prev + 1:
      prev = h
  else:
    prev = h
print('Yes' if result else 'No')

Measured memory_bytes: 84652
#include <iostream>

using namespace std;

int main() {
  long n, a;
  cin >> n >> a;

  long mini = a;
  long dif = -(1 << 30);
  for (int i = 1; i < n; i++) {
    cin >> a;
    
    dif = max(dif, a - mini);
    mini = min(mini, a);
  }

  cout << dif << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
    long N;
    long i, j;
    long res = 0;

    scanf("%ld", &N);
    res = N;

    for (i = 1; i * i < N + 1; i++)
    {
        if (N % i == 0)
        {
            j = N / i;
            if (res > ((i - 1) + (j - 1)))
            {
                res = (i - 1) + (j - 1);
            }
        }
    }

    printf("%ld\n", res);

    return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split())
dp = [0 for i in range(n+1)]
for i in range(m):
    j = int(input())
    dp[j] = -1
dp[0] = 1
dp[1] = 1 if dp[1] != -1 else 0
for i in range(2,n+1):
    if dp[i] == -1:
        dp[i] = 0
        continue
    dp[i] = (dp[i-1] + dp[i-2])%1000000007
print(dp[n])

Measured memory_bytes: 7064
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int n,m;
	cin>>n>>m;
	VB vb(n,true);
	VI vwa(n,0);
	int ac=0,wa=0;
	rep(i,m){
		int p;
		string s;
		cin>>p>>s;
		p--;
		if(vb.at(p)){
			if(s=="WA"){
				vwa.at(p)++;
			}
			if(s=="AC"){
				ac++;
				vb.at(p)=false;
				wa+=vwa.at(p);
			}
		}
	}
	cout<<ac<<" "<<wa<<endl;
	return 0;
}


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

int main(){
    //入力
    int N;
    string S;
    cin >> N;
    cin >> S;

    //出力
    int x_max=0;
    int x=0;
    for(int i=0;i<N;i++){
        if(S.at(i)=='I'){
            x++;
        }else if(S.at(i)=='D'){
            x--;
        }
        if(x>x_max){
            x_max=x;
        }

    }   
    cout << x_max << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> v(n, vector<int>(d));
    REP(i, n){
        REP(j, d){
            cin >> v[i][j];
        }
    }

    int ans = 0;
    REP(i, n){
        FOR(j, i+1, n){
            int dist = 0;
            REP(k, d){
                dist += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
            }
            for(int k=1; k*k<=dist; k++){
                if(k*k == dist){
                    ans++;
                    break;
                }
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
int f(int n){
    if(n%2==0) return n/2;
    else return 3*n+1;
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int s;
    cin  >> s;
   /* vector<int>a(1000000);
    a[0] = s;
    int ans;
    REP1(i,1000000){
        a[i]= f(a[i-1]);
        bool flag = true;
        REP(j,i){
            REP(k,j){
            if(a[k]==a[j] ){ 
                flag = false;
                ans = j;
                cout << ans +1 << endl;
                return 0;
                 
            }
            
        }
        
    }
    }*/
    set<int> st;
    int ans = 1;
    st.insert(s);
    while(st.size() == ans){
        if(s%2==0) s/=2;
        else s=3*s+1;
        st.insert(s);
        ans++;
    }
    cout << ans << endl;
    return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int N, K;
	cin >> N >> K;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    vector<ll> v(N+1, 0);   // 累積和
    rep(i, N) v[i+1] = v[i] + a[i];
    vector<ll> w(N+1, 0);   // 正の値のみの累積和
    rep(i, N) w[i+1] = w[i] + max(a[i], 0ll);

    ll ans = -LINF;
    rep(i, N-K+1) {
        ll tmp = w[N];
        // Kマスを白or黒に塗る
        tmp += max(v[i+K]-v[i], 0ll);
        tmp -= w[i+K]-w[i];
        ans = max(ans, tmp);
    }
    
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =    sc.nextInt();
		String b = sc.next();
		
		if(a < 3200) {
			b = "red";
		}
       System.out.println(b);
	}
}

Measured memory_bytes: 22868
#include<stdio.h>
int main(){
  int n,m,b[55],i,j,r,c,h[55]={0};
  scanf("%d %d",&m,&n);
  for(i=0;i<n;i++){
    scanf("%d",&c);
    while(c--){
      scanf("%d",&r);
      b[r]=i;
    }
  }
  c=0;
  scanf("%d",&n);
  while(n--){
    scanf("%d %d",&i,&j);
    if(b[i]==b[j])h[i]=h[j]=1;
  }
  for(i=0;i<=m;i++)c+=h[i];
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 600
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        long T[] = new long[N];

        for(int i = 0; i < N; i++) {
            T[i] = scan.nextLong();
        }

        scan.close();

        long lcm = T[0];
        for(int i = 1; i < N; i++) {
            lcm = lcm(lcm, T[i]);
        }

        os.println(lcm);
    }

    static public long lcm(long a, long b) {
        if(a == b)
            return a;

        if(a > b) {
            long tmp = a;
            a = b;
            b = tmp;
        }

        long answer =  a*(b/(gcd(a, b)));
        return answer;
    }

    static public long gcd(long a, long b) {
        while(a > 0) {
            long tmpa = a;
            a = b % a;
            b = tmpa;
        }
        return b;
    }
}

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

using namespace std;
using ll = long long;
using ld = long double;

ll mod = 1e9 + 7;

ll dp[100500][2];

vector<int> g[100500];

void dfs(int x, int p = -1) {
    dp[x][0] = 1;
    dp[x][1] = 1;
    for (int i : g[x]) {
        if (i == p) {
            continue;
        }
        dfs(i, x);
        dp[x][0] = (dp[x][0] * (dp[i][0] + dp[i][1])) % mod;
        dp[x][1] = dp[x][1] * dp[i][0] % mod;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    cout.precision(20); cout << fixed;
    int n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % mod;
}


Measured memory_bytes: 13696
n=int(input())
num=list(map(int,input().split()))

flag=True
for i in range(n):
  if num[i]%2==0:
    if num[i]%3!=0 and num[i]%5!=0:
      flag=False
      break
if flag:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060