akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef long int l;

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

    int a[5];
    rep(i, 5){
        cin >> a[i];
    }
    int k;
    cin >> k;
    
    if(a[4] - a[0] > k){
        cout << ":(" << endl;
        return 0;
    }
    
    cout << "Yay!" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=998244353,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll dp[3333];

void Main() {
  ll n,s;
  cin >> n >> s;
  ll a[n];
  rep(i,n) R a[i];
  dp[0]=1;
  ll ans=0;
  rep(i,n) {
    rrep(j,s+1) {
      if(j+a[i]<=s) {
        dp[j+a[i]]+=dp[j];
        dp[j+a[i]]%=MAX;
      }
      dp[j]+=dp[j];
      dp[j]%=MAX;
    }
  }
  pr(dp[s]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

using namespace std;

#pragma GCC optimize("03")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define arctan atan
#define arccos acos
#define arcsin asin
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define vt vector
#define pr pair
#define u_map unordered_map
#define endl "\n"

typedef double db;			typedef long long ll;		typedef long double ld;			typedef string str;
typedef pr<int, int> pii;	typedef pr<ll,ll> pll;		typedef pr<ld,ld> pdd;
typedef vt<int> vi;			typedef vt<ll> vll;			typedef vt<bool> vb;
typedef vt<str> vs;			typedef vt<pii> vpii;		typedef vt<pll> vpll;
typedef map<int, int> mii;	typedef map<int, bool> mib;	typedef map<int, str> mis;		typedef map<int, char> mic;
typedef complex<db> cpx;	typedef vt<cpx> vcpx;
const int MAX_N = 1007;
//const int MAX_K = MAX_N*(MAX_N-1) / 2;
ll a[MAX_N];
int n,k, last = 40;
vll beauty;

void make_beauties()
{
	for(int i = 1; i < n+1; ++i)
	{
		ll sum = 0;
		for(int j = i; j < n+1; ++j)
		{
			sum += a[j];
			beauty.pb(sum);
		}
		
	}
}

ll MAX_AND()
{
	ll ans = 0, i = 39;
	for(vll temp; i > -1; --i)
	{
		ll cunt = 0;
		for(ll& j: beauty)
		{
			if (j & (1LL << i)) ++cunt;
		}
		
		if (cunt >= k)
		{
			ans |= (1LL << i); temp.clear();
			for(ll j : beauty)
			{
				if (j & (1LL << i)) temp.pb(j);
			}
			beauty = temp;
		}
	}
	return ans;
}

void input()
{
	cin >> n >> k;
	for(int i = 1; i < n+1; ++i)
	{
		cin >> a[i];
	}
	make_beauties();
	cout << MAX_AND();
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	input();
	return 0;
}


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

using namespace std;
int main ()
{
    int N;
    int x[110];
    int y[110];
    long h[110];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    long H;
    long prevH;
    bool hozon=false;
    long minH=1000000007;
    long maxH=0;
    for(int i=0;i<N;i++){
        minH=min(minH,h[i]);
        maxH=max(maxH,h[i]);
    }
    int ansX,ansY;
    long ansH;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(H=max(1l,maxH-200);H<=minH+200;H++){
                for(int l=0;l<N;l++){
                    if(max(H-abs(x[l]-i)-abs(y[l]-j),0l)!=h[l]){
                        break;
                    }else if(l==N-1){
                        ansX=i;
                        ansY=j;
                        ansH=H;
                    }
                }
            }
        } 
    }
    cout << ansX << " " << ansY << " " << ansH << endl;
    return 0;
    
}












Measured memory_bytes: 256
# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
m = max(a)
count = [0 for _ in range(m + 1)]
ans = 0

for i in a:
    if count[i] != 0:
        count[i] = 1
        continue
    for j in range(2 * i, m + 1, i):
        count[j] = 1
    count[i] = 2

for i in a:
    if count[i] != 1:
        ans += 1

print(ans)


Measured memory_bytes: 32100
#include <iostream>
using namespace std;
int n,m;
char map[110][110];
void dfs(int x,int y,char ch)
{   
    int dir[4][2]={1,0,-1,0,0,1,0,-1};
    int x1,y1;
    map[x][y]='.';
    for(int i=0;i<4;i++)
    {
        x1=x+dir[i][0];
        y1=y+dir[i][1];
        if(x1>=0&&x1<n&&y1>=0&&y1<m&&map[x1][y1]==ch)
        dfs(x1,y1,ch);
    }
} 

int main(int argc, char *argv[])
{   
    char ch;
    while(cin>>n>>m)
    {   
        int ans=0;
        if(n==0||m==0) break;

        for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>map[i][j];
        for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(map[i][j]!='.')
                {
                ch=map[i][j];
                ans++;
                dfs(i,j,ch);
                }   
    cout<<ans<<endl;             
    }
    return 0;
}

Measured memory_bytes: 4032
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = 1000000;
char ch[1000][1000];
int dis[1000][1000];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int BFS(int h, int w){
	bool checked[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			checked[i][j] = false;
		}
	}

	int res = 0;

	queue<P> que;

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(ch[i][j]=='#'){
				que.push(make_pair(i, j));
				checked[i][j] = true;
			}
		}
	}

	while(!que.empty()){
		queue<P> quetmp;
		while(!que.empty()){
			P p = que.front();
			que.pop();
			for(int k=0;k<4;k++){
				int ny = p.first + dy[k];
				int nx = p.second + dx[k];
				if(0<=ny && ny<h && 0<=nx && nx<w && checked[ny][nx]==false){
					checked[ny][nx] = true;
					quetmp.push(make_pair(ny, nx));
				}
			}
		}
		res++;
		que = quetmp; 		
	}
	return res-1;
}

int main(){
	int H, W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> ch[i][j];
		}
	}

	cout << BFS(H, W) <<endl;
 
  	return 0;
}


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

#define endl "\n"
#define ll long long int
#define f(i,st,ed) for(ll i=st;i<ed;i++)
#define fr(i,ed,st) for(ll i=ed;i>=st;i--)
#define vv vector<ll>
#define all(v) v.begin(),v.end() 
#define pb push_back
#define pp pair<ll,ll>
#define gv(v,s,e) f(i,s,e){ ll x; cin >> x; v.pb(x);}
#define pv(v,s,e) f(i,s,e){cout << v[i] << " ";}
#define MOD 1000000007
#define debug(x) cout << x << endl;


void yes(){
    cout << "YES" << endl;
}

void no(){
    cout << "NO" << endl;
}

ll powmod(ll x, ll y, ll mod)
{
    ll ans=1;

    while(y)
    {
        if(y%2==1)
        {
            ans = (ans*x)%mod;
        }

        x = (x*x)%mod;
        y/=2;
    }

    return ans;
}

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

    ll n;
    cin >> n;

    vector<pair<ll,pp>> v;

    f(i,0,n)
    {
        ll x,y,z;
        cin >> x >> y >> z;
        v.pb({x,{y,z}});
    }

    ll dp1[n];
    ll dp2[n];
    ll dp3[n];

    dp1[0]=v[0].first;
    dp2[0]=v[0].second.first;
    dp3[0]=v[0].second.second;

    f(i,1,n)
    {   
        dp1[i] = max(dp2[i-1]+v[i].first, dp3[i-1]+v[i].first);
        dp2[i] = max(dp1[i-1]+v[i].second.first, dp3[i-1]+v[i].second.first);
        dp3[i] = max(dp2[i-1]+v[i].second.second, dp1[i-1]+v[i].second.second);
    }

    cout << max(dp1[n-1],max(dp2[n-1],dp3[n-1]));
    return 0;
}



Measured memory_bytes: 7920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.sql.Array;
import java.util.*;

public class Main {

    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
    static long lcm (long a, long b) {return a*b/gcd(a,b);}

    public static void main(String[] args){
	// write your code here
        Scanner sc=new Scanner(System.in);
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        while(true){
            int a = sc.nextInt();
            String s= sc.next();
            int b =sc.nextInt();
            if(s.equals("+")){
                arrayList.add(a+b);
            }else if(s.equals("-")){
                arrayList.add(a-b);
            }else if(s.equals("/")){
                arrayList.add(a/b);
            }
            else if(s.equals("*")){
                arrayList.add(a*b);
            }else{
                break;
            }
        }
        for(int i=0;i<arrayList.size();i++){
            System.out.println(arrayList.get(i));
        }
    }
}



Measured memory_bytes: 26336
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
const string FILENAME = "input";
const int MAXN = 200228;



int n;
string s;
int pref[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++) {
		pref[i] = (s[i] == '#');
		if (i) {
			pref[i] += pref[i - 1];
		}
	}
	int ans = pref[n - 1];
	int res = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '.') {
			res++;
		}
		chkmin(ans, res + (i == 0 ? 0: pref[i - 1]));
	}
	cout << ans << '\n';
	return 0; 	
}

Measured memory_bytes: 1300
using System;
using System.Globalization;

namespace ITP1_8_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            char[] moji = str.ToCharArray();

            for (int i = 0; i < moji.Length; i++)
            {
                if (char.IsUpper(moji[i]))
                    moji[i] = char.ToLower(moji[i]);
                else if (char.IsLower(moji[i]))
                    moji[i] = char.ToUpper(moji[i]);
            }

            string str2 = new string(moji);
            Console.WriteLine(str2);
        }
    }
}



Measured memory_bytes: 7752
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back

const ll LLINF = (1LL<<60);

class UnionFind {
public:
  const static int MAX_N = 100010;
  int par[MAX_N];
  int s[MAX_N];
  UnionFind() { init(); }
  UnionFind(int n) { init(n); }
  void init() { for(int i=0; i<MAX_N; ++i) par[i] = i, s[i] = 1; }
  void init(int n) { for(int i=0; i<n; ++i) par[i] = i, s[i] = 1; }
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
    else par[y] = x, s[x] = s[x] + s[y];
  }
  bool same(int x, int y) { return find(x) == find(y);}
};
UnionFind uf;

vector<PII> g[100010];
int d[100010];
void dfs(int x, int p, int dist) {
  d[x] = dist;
  for(auto e: g[x]) {
    if(e.first != p) dfs(e.first, x, dist + e.second);
  }
}

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

  while(true) {
    int n, m;
    cin >> n >> m;
    if(!n) break;

    REP(i, n) g[i].clear();
    memset(d, 0, sizeof(d));
    uf.init(n);

    vector<PII> query;
    VI ans(m+5);
    int idx = 0;
    REP(i, m) {
      char c;
      int a, b;
      cin >> c >> a >> b; a--, b--;
      if(c == '!') {
        int w; cin >> w;
        if(!uf.same(a, b)) {
          uf.unite(a, b);
          g[a].PB({b, -w});
          g[b].PB({a, w});
        }
      } else {
        query.PB({a, b});
        if(!uf.same(a, b)) ans[idx] = LLINF;
        idx++;
      }
    }

    REP(i, n) if(d[i] == 0) dfs(i, -1, 0);

    REP(i, query.size()){
      if(ans[i]==LLINF) cout << "UNKNOWN" << endl;
      else cout << d[query[i].first] - d[query[i].second] << endl;
    }
  }

  return 0;
}



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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    set <string> a;
    for(int i=0;i<n;++i)
    {
        string s;
        cin>>s;
        a.insert(s);
    }
    cout<<a.size();
    return 0;
}


Measured memory_bytes: 19212
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());

        while (true) {
            C = C - B;
            if (C <= 0) {
                System.out.println("Yes");
                return;
            }
            A = A - D;
            if (A <= 0) {
                System.out.println("No");
                return;
            }
        }

    }
}

Measured memory_bytes: 26968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	int q; cin>>q;
	int ar[n+1] = {};
	bool taken[n+1] = {};
	while(q--){
		int left, i; cin>>left>>i;
		if(taken[left] && ar[left] != i){
			cout<<-1;
			return 0;
		}
		ar[left] = i;
		taken[left] = true;
	}
	if(taken[1] && ar[1] == 0 && n != 1){
		cout<<-1;
		return 0;
	}
	if(!taken[1]) ar[1] = 1;
	if(!taken[1] && n == 1) ar[1] = 0;
	for(int i = 1; i <= n; i++){
		cout<<ar[i];
	}
}

Measured memory_bytes: 256
#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
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
db a[55];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  db ans=0;
  cin>>n;
  rep(i,1,n+1)
    cin>>a[i];
  sort(a+1,a+n+1);
  vector<db> v;
  rep(i,1,n+1) v.pb(a[i]);
  while(sz(v)>1)
    {
      vector<db> tmp=v;
      reverse(all(v));
      v.pop_back(); v.pop_back();
      db x=tmp[0]+tmp[1];
      x/=2.0;
      v.pb(x);
      sort(all(v));
    }
  cout<<fixed<<setprecision(10)<<v[0]<<endl;
  return 0 ;
}


Measured memory_bytes: 256
defmodule Main do
  def main do
    _ = IO.gets("")
    
    IO.gets("")
    |> String.trim()
    |> String.split("", trim: true)
    |> process(0, 0)
    |> IO.puts()
  end
  
  defp process([], _, max), do: max
  
  defp process(["I" | tail], acc, max) do
    case acc + 1 > max do
      true -> process(tail, acc + 1, acc + 1)
      false -> process(tail, acc + 1, max)
    end
  end
  
  defp process(["D" | tail], acc, max) do
    process(tail, acc - 1, max)
  end
end

Measured memory_bytes: 31096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

int n, m;
const int MAX_N = 100000;
vector<int> g[MAX_N];
int color[MAX_N];

// ある点のcolorが0でないからといってcontinueできない
// その先の頂点は別
// v, dのpairでメモ化
int fin[MAX_N][11];

void dfs(int v, int d, int c) {
    if (fin[v][d]) return;
    fin[v][d] = 1;
    if (d == 0) {
        color[v] = c;
        return;
    }
    dfs(v, d - 1, c);
    for (auto nxt : g[v]) {
        dfs(nxt, d - 1, c);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].eb(b);
        g[b].eb(a);
    }
    
    int q;
    cin >> q;
    
    vector<int> v(q), d(q), c(q);
    rep(i, q) {
        cin >> v[q - 1 - i] >> d[q - 1 - i] >> c[q - 1 - i];
        v[q - 1 - i]--;
    }
    
    rep(i, q) {
        dfs(v[i], d[i], c[i]);
    }
    
    rep(i, n) out(color[i]);
}



Measured memory_bytes: 12408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, S = 0;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
 
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
 
	for (int j = 0; j < N; j++) {
		if (j % 2 == 0) {
			S += a[j];
		}
		else {
			S -= a[j];
		}
	}
 
	cout << S << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  
  int minv = 1e9;
  for (int i = 0; i + 2 < s.size(); i++) {
    int num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0';
    minv = min(minv, abs(753 - num));
  }
  cout << minv << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c,d,t;
    scanf("%lld%lld%lld%lld%lld",&a,&c,&b,&d,&t);
    ll h=abs(a-b);
    if(((c-d)*t)>=h)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 3764
from sys import stdin
from math import cos, sin, pi, sqrt, radians, degrees
from collections import deque, Counter, defaultdict
import heapq

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    A, B, H, M = map(int, input().split())
    th1 = pi / 2 - H / 12 * 2 * pi
    if th1 < 0:
        th1 += 2 * pi

    if M != 0:
        th1 -= 2 * pi / 12 * (M / 60)
    Ax = A * cos(th1)
    Ay = A * sin(th1)
    th2 = pi / 2 - M / 60 * 2 * pi
    if th2 < 0:
        th2 += 2 * pi
    Bx = B * cos(th2)
    By = B * sin(th2)
    d = sqrt((Ax - Bx) ** 2 + (Ay - By) ** 2)
    print("{:.10f}".format(d))

if __name__ == '__main__':
    main()

Measured memory_bytes: 65636
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let x = v[0];
	let y = v[1];
	let z = v[2];
	println!("{} {} {}", z, x, y);
}

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

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Div(long a, long b)
        {
            return (a + b - 1) / b;
        }
        static bool CanBeat(int N, long A, long B, int[] H, long bombs)
        {
            long rest = bombs;
            foreach (int h in H)
            {
                long n = Div(h - B * bombs, A - B);
                if (n == 0) { return true; }
                if (n > rest) { return false; }
                rest -= n;
            }
            return true;
        }
        static int Solve(int N, long A, long B, int[] H)
        {
            Array.Sort(H, (a, b) => b - a);
            long min = 0;
            long max = Div(H[0], B);
            while (max - min > 1)
            {
                long med = (min + max) / 2;
                if (CanBeat(N, A, B, H, med))
                {
                    max = med;
                }
                else
                {
                    min = med;
                }
            }
            return (int)max;
        }
        static void Main(string[] args)
        {
            long[] values1 = ReadLongs();
            int N = (int)values1[0];
            int[] H = new int[N];
            for (int i = 0; i < N; ++i) { H[i] = ReadInt(); }
            Console.WriteLine(Solve(N, values1[1], values1[2], H));
        }
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007

typedef long long ll;

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

    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i += 2){
        cout << s[i];
    }
    cout << "\n";

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  
  if (s[0] == 'o') counter++;
  if (s[1] == 'o') counter++;
  if (s[2] == 'o') counter++;
  
  cout << 700 + counter * 100 << endl;
}

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

int main() {
    int n; cin >> n;
    vector<vector<int>> g(n,vector<int>(n,-1));
    for(int i=0; i<n; i++){
        int a; cin >> a;
        for(int j=0; j<a; j++){
            int x,y; cin >> x >> y;
            g[i][x-1] = y;
        }
    }
    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++){
        int cnt = 0;
        bool ok = true;
        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                for(int j=0; j<n; j++){
                    if(g[i][j] == 0 && (bit & (1<<j))) ok = false;
                    if(g[i][j] == 1 && !(bit & (1<<j))) ok = false;
                    if(!ok) break;
                }
                cnt++;                
            }
            if(!ok) break;
        }
        if(ok) ans = max(ans,cnt);
    }
    cout << ans << endl;
}

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

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
 int64_t h, w, z;
 cin >> h >> w;
 z = h*w;
 if(h==1) cout << 1 << endl;
 else if(w==1) cout << 1 << endl;
 else if(z%2==0) cout << z/2 << endl;
 else cout << z/2+1 << endl;


}

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

_n = int(input())
_alist = list(map(int, input().split()))


def chker(n, alist):
    length = sum(alist)
    ls, rs = 0, length

    cost = length
    for index, ai in enumerate(alist):
        ls += ai
        rs -= ai
        precost = cost
        cost = min(abs(rs - ls), cost)

        if cost >= precost:
            print(precost)
            return


chker(_n, _alist)


Measured memory_bytes: 26216
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int n,m,dis[100020],par[100020];
bool ans=true;

int find(int x){
    if (par[x]==x){
        return x;
    } else {
        int r=find(par[x]);
        dis[x]=dis[par[x]]+dis[x];
        par[x]=r;
        return par[x];
    }
}

void unite(int x,int y,int z){
    int fx=find(x);
    int fy=find(y);
    if (fx==fy){
        if (abs(dis[x]-dis[y])!=z){
            ans=false;
        }
    } else {
        par[fy]=fx;
        dis[fy]=dis[x]+z-dis[y];
    }
}

int main(void){
    scanf("%d%d",&n,&m);
    for (int i=0; i<=n; i++){
        par[i]=i;
    }
    for (int i=0; i<m; i++){
        int l,m,d;
        scanf("%d%d%d",&l,&m,&d);
        unite(l,m,d);
    }
    if (ans==true){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
	return 0 ;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long 
#define vi vector<int>
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
using namespace std;

int main()
{
	int n,i,j,mx=1;
	
	cin>>n;
	int a[n],b[n+1],c[n+1];

	f(i,0,n)cin>>a[i];
	
	b[0]=a[0],c[0]=a[n-1];
	
	f(i,0,n)
	{
		b[i+1]=__gcd(a[i],b[i]);
	}
	f(i,0,n)c[i+1]=__gcd(c[i],a[n-1-i]);
	
	mx=max(b[n-1],c[n-1]);
	
	for(i=1;i<n-1;i++)
	{
		mx=max(mx,__gcd(b[i],c[n-i-1]));
	}
	cout<<mx;
}

Measured memory_bytes: 4760
S=input()
flag=[]
if 'N' in S:
    if 'S' in S:
        flag.append(True)
    else:
        flag.append(False)

if 'S' in S:
    if 'N' in S:
        flag.append(True)
    else:
        flag.append(False)

if 'W' in S:
    if 'E' in S:
        flag.append(True)
    else:
        flag.append(False)

if 'E' in S:
    if 'W' in S:
        flag.append(True)
    else:
        flag.append(False)

if False in flag:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  int N = 20;
  while(true){
    int n, l; cin >> n >> l;
    if(n+l == 0)  break;
    vector<int> dif(N+1);
    dif[0] = n;
    REPS(i, N){
      int max_n, min_n;
      string s = to_string(dif[i-1]);
      if(s.length()<l)  {
        string adds(l-s.length(), '0');
        s = adds+s;
      }
      sort(ALL(s));
      min_n = stoi(s);
      sort(RALL(s));
      max_n = stoi(s);
      dif[i]=max_n-min_n;
    }
    int ansi, ansj;
    rep(j, 0, N+1) {
      bool find = false;
      rep(i, j+1, N+1){
        if(dif[i]==dif[j]){
          ansj = j;
          ansi = i;
          find = true;
          break;
        }
      }
      if(find)  break;
    }
    cout << ansj << " " << dif[ansi] << " " << ansi - ansj << endl;
  }
  return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s;
    int ans = 0;
    cin >> s;
    if(s[0] == s[1]) ans++;
    if(s[1] == s[2]) ans++;
    if(s[2] == s[3]) ans++;
    if(ans != 0) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = []

for i in range(n):
    a.append(ni())

a.sort()
t = n//2

if n%2 == 0:
    ans = (sum(a[t+1:])-sum(a[:t-1]))*2+a[t]-a[t-1]
    print(ans)
else:
    x = 2*(sum(a[t+1:])-sum(a[:t-1])) - a[t-1] - a[t]
    y = 2*(sum(a[t+2:])-sum(a[:t])) + a[t+1] + a[t]
    print(max(x,y))

Measured memory_bytes: 7516
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
const int MX = 500005;

struct segtree {
    int size;
    vector<int> sums;
 
    void init(int n) {
        size = 1;
        while (size < n) size *= 2;
        sums.assign(2 * size, 0);
    }

    void set(int i, int v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            sums[x] = v;
            return;
        }
        int m = (lx + rx) / 2;
        if (i < m) {
            set(i, v, 2 * x + 1, lx, m);
        } else {
            set(i, v, 2 * x + 2, m, rx);
        } 
        
        sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
    }

    void set(int i, int v) {
        set(i, v, 0, 0, size);
    }

    int query(int l, int r, int x, int lx, int rx) {
        if (lx >= r || l >= rx) return 0;
        if (lx >= l && rx <= r) return sums[x];

        int m = (lx + rx) / 2;
        int q1 = query(l, r, 2 * x + 1, lx, m);
        int q2 = query(l, r, 2 * x + 2, m, rx);
        return q1 + q2;
    }

    int query(int l, int r) {
        return query(l, r, 0, 0, size);
    }
};
 
int a[MX], loc[MX], ans[MX];
pair<pair<int, int>, int> qv[MX];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    segtree st;
    cin >> n >> q;
    st.init(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        loc[a[i]] = -1;
    }

    // Endpoints are inclusive so +1 to right side query
    for (int i = 0; i < q; ++i) {
        cin >> qv[i].first.second >> qv[i].first.first;
        --qv[i].first.first, --qv[i].first.second;
        qv[i].second = i;
    }
    sort(qv, qv + q);

    for (int i = 0, pt = 0; i < q; ++i) {
        while (pt <= qv[i].first.first) {
            if (loc[a[pt]] != -1) {
                st.set(loc[a[pt]], 0);
                // cout << "RESETTING " << loc[a[pt]] << '\n';
            }
            loc[a[pt]] = pt;
            st.set(pt, 1);
            // cout << "SETTING " << pt << '\n';
            ++pt;
        }

        // cout << "QUERYING: " << qv[i].first.second << ' ' << qv[i].first.first + 1 << '\n';
        ans[qv[i].second] = st.query(qv[i].first.second, qv[i].first.first + 1);
    }

    for (int i = 0; i < q; ++i) {
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 19536
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 100007
#define MAX 100001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    int water = a, sugar = 0, water_tmp, sugar_tmp;
    repp(ai, f/100+1){
        repp(bi, f/100+1){
            water_tmp = a*ai+b*bi;
            if(water_tmp * 100 > f || water_tmp == 0) break;
            repp(ci, e*water_tmp/c+1){
                repp(di, e*water_tmp/d+1){
                    sugar_tmp = c*ci+d*di;
                    if(sugar_tmp + water_tmp*100 > f || sugar_tmp > e*water_tmp) break;
                    if(sugar * water_tmp < sugar_tmp * water){
                        sugar = sugar_tmp;
                        water = water_tmp;
                    }
                }
            }
        }
    }
    
    printf("%d %d\n", water*100+sugar, sugar);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcountll
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i=0; n>i; i++){
        int a, b;
        cin >> a >> b;
        if(a*a + b*b <= d*d){
            ans++;
        }
    }
    cout << ans << endl;
}






Measured memory_bytes: 3632
import collections

if __name__ == '__main__':
    n, m = map(int, input().split())

    counter = collections.defaultdict(int)
    for _ in range(m):
        a, b = map(int, input().split())
        counter[a] += 1
        counter[b] += 1

    for i in range(1, n + 1):
        print(counter[i])


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

int main(){
    int n;
    cin>>n;
    cin.ignore();
    while(n--){
        string s;
        getline(cin,s);
        for(int i=6;i<s.length();i++)
            if(s[i]=='o'&&s[i-1]=='n'&&s[i-2]=='i'&&s[i-3]=='h'&&s[i-4]=='s'&&s[i-5]=='o'&&s[i-6]=='H')
                s[i]='a',s[i-1]='n',s[i-2]='i',s[i-3]='h',s[i-4]='s',s[i-5]='o',s[i-6]='H';
        cout<<s<<endl;
    }
}

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

#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << #x " = " << (x) << '\n'
#define DBG         cerr << "Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i, j, cs, t, x, y, z, s, k;
    sff(k,s);
    int cnt = 0;
    for(int x = 0; x<=k; x++)
    {
        for(int y = 0; y<=k; y++)
        {
            int z = (s-x-y);
            if(0<=z && z <= k)
                cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}




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

using namespace std;


const int kMod = 1e9+7;
const int kMaxN = 1e5+10;

struct Point {
	int x, y, i;

	Point(int x, int y, int i) : x(x), y(y), i(i) {}

	Point() {}
};

struct FenTree {
	int n;
	vector<int> aib;
	FenTree(int n) : n(n) {
		aib.resize(n+1);
	}

	static inline int LSB(int i) {
		return i&-i;
	}

	void update(int i, int val) {
		for (; i <= n; i += LSB(i)) {
			aib[i] += val;
		}
	}

	int query(int i) {
		int res = 0;
		for (; i > 0; i -= LSB(i)) {
			res += aib[i];
		}
		return res;
	}

	int query(int i, int j) {
		if (j > i) {
			return query(j) - query(i-1);
		} else {
			return query(j) + query(n) - query(i-1);
		}
	}
};

bool on_border(int a, int b, int r, int c) {
	return (a == r || a == 0 || b == c || b == 0);
}

void Solve() {
	int r, c, n;

	cin >> r >> c >> n;

	vector<Point> points;
	vector<int> first(n+1), second(n+1);

	for (int i = 1; i <= n; ++i) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;

		if (on_border(x1, y1, r, c) && on_border(x2, y2, r, c)) {
			points.emplace_back(x1, y1, i);
			points.emplace_back(x2, y2, i);
		}
	}

	auto cmp = [&](Point a, Point b) {
		a.x -= 1;
		a.y -= 1;
		b.x -= 1;
		b.y -= 1;

		return atan2(a.y, a.x) < atan2(b.y, b.x);
	};

	sort(points.begin(), points.end(), cmp);

	FenTree fen(points.size());

	for (int i = 0; i < points.size(); ++i) {
		if (first[points[i].i]) {
			second[points[i].i] = i + 1;
			fen.update(i+1, -1);
		} else {
			first[points[i].i] = i + 1;
			fen.update(i+1, 1);
		}
	}

	for (int i = 0; i < points.size(); ++i) {
		if (i+1 == first[points[i].i]) {
			if(fen.query(first[points[i].i], second[points[i].i]) != 0) {
				cout << "NO\n";
				return;
			}
			fen.update(i+1, -2);
			fen.update(second[points[i].i], 2);
		}
	}

	cout << "YES\n";
}

int main() {
	int tests = 1;

	for (;tests; --tests) {
		Solve();
	}
}

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

int main(){
    int n;
    map<string, int> mp;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }

    ll ans = 0;
    for(auto m : mp){
        ll v = m.second;
        ans += v * (v - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long N;
  cin >> N;
  if (N & 1) return cout << 0 << "\n", 0;
  N >>= 1;
  long cnt = 0;
  while (N) N /= 5, cnt += N;
  cout << cnt << "\n";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(int i = 1; i <= 9; i++) {
			for(int j = 1; j <= 9; j++) {
				if(i * j == N) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    long long i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;
    long long ans = o * 2 + (i / 2) * 4 + (j / 2) * 4 + (l / 2) * 4;
    long long ans2 = 0;
    if((i > 0) && (j > 0) && (l > 0)){
        ans2 = o * 2 + ((i - 1) / 2) * 4 + ((j - 1) / 2) * 4 + ((l - 1) / 2) * 4 + 6;
    }
    cout << max(ans, ans2) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[40000],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<Pll>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	cnt = 0;
	rep(i, n) {
		if ((a[i] - cnt) % 2 == 1) {
			ans ^= (n - i);
		}
		cnt = a[i];
	}
	cout << (ans == 0 ? "second" : "first") << endl;
	return 0;
}

Measured memory_bytes: 1024
S = input()
AA = int(S[:2])
BB = int(S[2:])

def check(num):
    if 1<=num<=12:
        return True
    else:
        return False
    
if check(AA) and check(BB):
    print("AMBIGUOUS")
elif check(AA):
    print("MMYY")
elif check(BB):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        int k=sc.nextInt();
        
        
            if(k*2-1<=n){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        
    }
}


Measured memory_bytes: 24148
class Dice
  def dice_s(arr, i)
    arr[i][0],arr[i][1],arr[i][4],arr[i][5] = arr[i][4],arr[i][0],arr[i][5],arr[i][1]
    return arr[i]
  end
 
  def dice_e(arr, i)
    arr[i][0],arr[i][2],arr[i][3],arr[i][5] = arr[i][3],arr[i][0],arr[i][5],arr[i][2]
    return arr[i]
  end
 
  def dice_w(arr, i)
    arr[i][0],arr[i][2],arr[i][3],arr[i][5] = arr[i][2],arr[i][5],arr[i][0],arr[i][3]
    return arr[i]
  end
 
  def dice_n(arr, i)
    arr[i][0],arr[i][1],arr[i][4],arr[i][5] = arr[i][1],arr[i][5],arr[i][0],arr[i][4]
    return arr[i]
  end
 
  def dice_b(arr, i)
    arr[i][0],arr[i][1],arr[i][4],arr[i][5]  = arr[i][5],arr[i][4],arr[i][1],arr[i][0]
    return arr[i]
  end
 
  def dice_sp(arr, i)
    arr[i][1],arr[i][2],arr[i][4],arr[i][3] = arr[i][2],arr[i][4],arr[i][3],arr[i][1]
    return arr[i]
  end
end

n = gets.chomp.to_i
arr = Array.new(n){Array.new(6)}
arr[0] = gets.chomp.split.map(&:to_i)
count = false
dice = Dice.new()


for i in 1..n-1
  arr[i] = gets.chomp.split.map(&:to_i)
    
  case arr[0][0]
  when arr[i][4]; dice.dice_s(arr, i)
  when arr[i][3]; dice.dice_e(arr, i)
  when arr[i][2]; dice.dice_w(arr, i)
  when arr[i][1]; dice.dice_n(arr, i)
  when arr[i][5]; dice.dice_b(arr, i)
  end

  4.times{
    if arr[0][1] != arr[i][1]
      dice.dice_sp(arr, i)
    else
      break
    end
  }

  break if arr[0] == arr[i]

  next if i < n-1

  catch(:break) do
    for j in 1..n-1
      for k in j+1..n-1
        throw :break if arr[j] == arr[k]
      end
    end
    count = true
  end
end

puts count == true ? "Yes" : "No"

Measured memory_bytes: 8820