akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<ll,ll> P;
//#include <boost/multiprecision/cpp_int.hpp>
//using bint = boost::multiprecision::cpp_int;



int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    
    vector<int> dp(n+k,1e9);
    dp[0] = 0;
    rep(i,n){
        rep(j,k){
            dp[i+j+1] = min(dp[i+j+1],dp[i] + abs(h[i+j+1] - h[i]));
        }
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n;
    cin>>n;
    ll a=0;
    bool f=1;
    rep(i,n){
        cin>>a;
        if(a%2==0){
            if(a%3!=0&&a%5!=0){
                f=0;
                break;
            }
        }
    }   
    if(f==0) cout<<"DENIED"<<endl;
    else cout<<"APPROVED"<<endl;
}


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

int main(){

  long A,B,i,ans;
  cin >> A;
  for(i=1; i<=pow(A,0.5); i++){
    if(A%i==0) B=i;
  }

  B = A/B;

  for(int j=1; j<12; j++){
    if(B/10==0){
      ans = j;
      break;
    }
    B /= 10;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
a,b,c,d = [int(i) for i in input().split()]
dab =abs(b-a)
dbc = abs(b-c)
ans = "No"
dac = abs(a-c)
if (dab <=d and dbc <= d) or dac<=d :
    ans = "Yes"
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long 
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define SIZE 100005
 
int func(int n)
{
	for(int i = 2; i<= sqrt(n); i++)
	{
		if(n%i == 0) return 0;
	}
	return 1;
} 
 
int main()
{
	int x;
	
	cin >> x;
	if(x==1) x++; 
	for(int i= x;; i++)
	{
		if(func(i) == 1)
		{
			cout << i << endl;
			return 0;
		}
		
	}
	return 0;
}

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

int main(){
  string s,t;
  int sum = 0;
  cin >> s >> t;
  for(int i=0; i < s.size(); i++){
  	if(s.at(i) != t.at(i)){
    	sum += 1;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3924
import scala.io.StdIn

object Main extends App {
  val input = StdIn.readLine().split(" ").map(_.toInt)
  val ret = if(isSame(input(0), input(1), input(2))) "Yes" else "No"
  println(ret)

  def isSame(a: Int, b: Int, c: Int): Boolean =
    if (a == b && b == c) true else false
}

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

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  for(int i=0;i<=b;i++){
    if(i*a%b==c){
      cout <<"YES"<<endl;
      return 0;
    }
  }
  cout <<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long[] count = new long[100000];
        long sum = 0;
        for(int i = 0;i<n;i++) {
            int a = sc.nextInt();
            sum+=a;
            count[a-1]++;
        }
        int q = sc.nextInt();
        int[] b = new int[q];
        int[] c = new int[q];
        for(int i = 0;i<q;i++){
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        for(int i = 0;i<q;i++){
            sum-=count[b[i]-1]*b[i];
            sum+=count[b[i]-1]*c[i];
            if(count[b[i]-1]!=0){
                count[c[i]-1]+=count[b[i]-1];
                count[b[i]-1]=0;
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 61684
n,m,k = map(int,input().split())
ans = 0
MOD = 998244353
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = MOD
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(k+1):
    ans += pow(m-1,n-i-1,MOD)*m*cmb(n-1,i,mod)
    ans%=MOD
print(ans%MOD)



Measured memory_bytes: 33276
def gcd(a, b):
    if b > a:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


N, X = map(int, input().split())
dif = list(map(lambda x: abs(int(x) - X), input().split()))

ans = dif[0]
for i in range(1, N):
    ans = gcd(ans, dif[i])

print(ans)


Measured memory_bytes: 15016
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int 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.0)
#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;

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    REP(i, n)ans += i * (n-i+1);
    rep(i, n-1){
        ll v, w;
        cin >> v >> w;
        if(v > w)swap(v, w);
        ans -= v * (n-w+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    if(P == 2 || P == 5) {
        ll ans = 0;
        rep(i, N) {
            ll d = S[i] - '0';
            if(d % P == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    
    vll cnt(P, 0);
    ll now = 0;
    ll beki = 1;
    for(ll i = N-1; i >= 0; i--) {
        ll d = S[i] - '0';
        now += d * beki;
        now %= P;
        cnt[now]++;
        beki = beki * 10 % P;
    }

    ll ans = cnt[0];
    for(auto x : cnt) if(x >= 2) ans += x * (x-1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vvi g;
vvi lca;
vi v;
vi rui;
void dfs2(int i,int p){
    v.pb(i);
    for(ll x:g[i])if(x!=p)dfs2(x,i);
}
void dfs(int i,int p){
    v=vi(0);
    dfs2(i,p);
    ll n=v.size();
    rep(k,n)rep(j,n)lca[v[k]][v[j]]=i;
    for(ll x:g[i])if(x!=p)dfs(x,i);
}
ll d(int i,int p){
    for(ll x:g[i])if(x!=p)rui[i]+=d(x,i);
    return rui[i];
}
int main(){
    ll n;cin>>n;
    g=vvi(n);
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    ll m;cin>>m;
    vector<P> query(m);
    rep(i,m)cin>>query[i].fi>>query[i].se;
    rep(i,m)query[i].fi--;
    rep(i,m)query[i].se--;
    lca=vvi(n,vi(n));
    dfs(0,-1);
    ll ans=0;
    rep(i,(1<<m)){
        ll num=1;
        rui=vi(n);
        rep(j,m)if(i>>j&1){
            num*=-1;
            ll a=query[j].fi,b=query[j].se,c=lca[a][b];
            rui[a]++;rui[b]++;rui[c]-=2;
        }
        ll s=0;
        d(0,-1);
        REP(k,1,n)if(rui[k]>0)s++;
        ans+=pow(2,n-1-s)*num;
    }
    out(ans);
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 400020
vector<int>e[N];
int num[N];

int dfs(int k) {
	if (e[k].size() == 0)num[k] = 1;
	else {
		num[k] = 0;
		f(i, e[k].size())num[k] += (dfs(e[k][i]));
	}
	return num[k];
}


int main() {
	vector<char>aa;
	vector<pair<vector<char>, int> >b;
	vector < pair<pair<int, int>, pair<char, char> > >v;
	vector<char>cc[N];
	int d[N];

	set<int>s;
	map<int, int>m;
	vector<int>adds;
	bool vk, vi, bvk;
	int bz;
	char a[N];
	int chan[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	int ans;
	ans = 0;
	scanf("%d", &n);
	f(i, n) {
		scanf("%s", a);
		k = strlen(a);
		a[k] = 'A';
		aa.clear();
		f(i, k + 1) {
			aa.push_back(a[i]);
			a[i] = 0;
		}
		b.push_back(make_pair(aa, i));
	}
	sort(b.begin(), b.end());
	f(i, n)chan[b[i].second] = i;
	f(i, n - 1) {
		k = 0;
		while (true) {
			if ((b[i].first)[k] == (b[i + 1].first)[k])k++;
			else break;
		}
		v.push_back(make_pair(make_pair(k, i + 1), make_pair((b[i].first)[k], (b[i + 1].first)[k])));
	}
	sort(v.begin(), v.end());

	s.insert(0);
	m[0] = 0;
	k = 1;
	bz = 0;
	vk = true;
	vi = false;
	int yy, zz;
	int cut[N];
	cut[0] = 0;
  auto itr=s.begin();
	f(i, n - 1) {
		bvk = vk;
		vk = false;
		if (i == (n - 2))vk = true;
		else if (v[i].first.first != v[i + 1].first.first)vk = true;
		x = v[i].first.first;
		y = v[i].first.second;
      itr=s.lower_bound(y);
      itr--;
                		z = m[*(itr)];
		vi = false;
		if (i == 0)vi = true;
		else if (bz != z)vi = true;
		else if (bvk)vi = true;
		if (vi) {
			if (i != 0) {
				m[yy] = zz;
				cut[zz] = yy;
			}  
          itr=s.lower_bound(y);
      itr--;
          		z = m[*(itr)];
			e[z].push_back(k);
			d[z] = x;
			cc[z].push_back(v[i].second.first);
			itr=s.lower_bound(y);
            itr--;
          yy=*(itr);
			zz = k;
			k++;
		}
		e[z].push_back(k);
		cc[z].push_back(v[i].second.second);
		m[y] = k;
		cut[k] = y;
		adds.push_back(y);
		k++;
		bz = z;
		if (vk) {
			f(j, adds.size())s.insert(adds[j]);
			adds.clear();
		}
	}
	dfs(0);
	int q;
	int leq[200];
	int kk;
	char qk[30];
	scanf("%d", &q);
	f(qq, q) {
		scanf("%d", &kk);
		kk = chan[kk - 1];
		f(i, 30)qk[i] = 0;
		scanf("%s", qk);
		f(i, 26)leq[qk[i]] = i;
      leq['A']=-1;
		k = 0;
		ans = 1;
		while (num[k] > 1) {
			f(i, e[k].size()) {
				if (leq[cc[k][i]] < leq[(b[kk].first)[d[k]]])ans += num[e[k][i]];
			}
			f(i, e[k].size()) {
				if (leq[cc[k][i]] == leq[(b[kk].first)[d[k]]]) {
					k = e[k][i];
					break;
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

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

int debug = 0;

int main()
{
    int n,m;
    vector<pair<int, int>> sc;
    cin >> n >> m;
    rep(i,m){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        sc.push_back(make_pair(tmp1, tmp2));
    }

    auto condok = [&](int i) {
        string st;
        st = to_string(i);
        int len = st.size();
        bool res = true;
        for(auto x:sc){
            int keta = x.first;
            int val = x.second;
            string st2 = to_string(val);
            if(debug){
                cout << "check:"<<i <<":"<<st<<":";
                cout << "k,y=" << keta << "," << val << ":";
                cout << st[keta - 1] << endl;
            }
            if(st[keta-1]== st2[0])
                continue;
            else
                return false;
        }
        return res;
    };

    //
    int ans =-1;
    if(n==1){
        for (int i = 0; i < 10;++i){
            if(condok(i)) {
                ans = i;
                break;
            }
        }
    }else if(n==2){
        for (int i = 10; i < 100;++i){
            if(condok(i)){
                ans = i;
                break;
            }
        }
    }else{
        for (int i = 100; i < 1000;++i){
            if(condok(i)){
                ans =i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int i;
	char O[51], E[51];

	scanf("%s", O);
	scanf("%s", E);

	i = 0;

	do
	{
		printf("%c%c", O[i],E[i]);
		i++;
	} while (E[i] != '\0');

	if (O[i] != '\0')
		printf("%c", O[i]);

	printf("\n");

	return 0;
}

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

const int N = 4e2 + 8;
int n, m, ans;
bool dead[N];
bool tar[N][N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;

		if (dead[a] || dead[b] || tar[a][b]) {
			dead[a] = dead[b] = true;
			continue;
		}
		
		tar[a][b] = tar[b][a] = true;
		for (int c = 0; c < n; c++)
			if (c != a && tar[c][b])
				tar[a][c] = tar[c][a] = true;
		for (int c = 0; c < n; c++)
			if (c != b && tar[c][a])
				tar[b][c] = tar[c][b] = true;
	}

	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			ans += !dead[i] && !dead[j] && !tar[i][j];

	cout << ans << "\n";
	return 0;
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

#define int long long
signed main() {
	stack<int> s1;
	stack<pair<int,int>>s2;
	string s;
	cin>>s;
	int sum=0;
	lp(i,s.size()) {
		if(s[i]=='\\'){
			s1.push(i);
		}
		else if (s[i]=='/'&&s1.size()!=0) {
			int j=s1.top();
			s1.pop();
			sum+=(i-j);
			int a=(i-j);
			while (s2.size()&&s2.top().first>j) {
				a+=s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(j,a));
		}
	}
	vector<int> ans;
	while (s2.size()) {
		ans.emplace_back(s2.top().second);
		s2.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size();
	lp(i, ans.size()) {
		cout<<" ";
		cout<<ans[i];
	}
	cout << endl;
}



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

using namespace std;

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

    int a = s / 100, b = s % 100;
    bool fa = a >= 1 && a <= 12;
    bool fb = b >= 1 && b <= 12;

    if (fa && fb) {
        cout << "AMBIGUOUS" << endl;
    } else if (fa) {
        cout << "MMYY" << endl;
    } else if (fb) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> ret = new ArrayList<Integer>();
		int i;
		for (i = 0; i < 10; i++) {
			ret.add(sc.nextInt());
		}
		Collections.sort(ret);
		Collections.reverse(ret);
		for (i = 0; i < 3; i++) {
			System.out.println(ret.get(i));
		}
	}
}

Measured memory_bytes: 17172
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;

inline char gc() {
//	static char buf[100000],*p1,*p2;
//	return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	return getchar();
}

template<class T>
int read(T &ans) {
	ans=0;char ch=gc();T f=1;
	while(!isdigit(ch)) {
		if(ch==EOF) return -1;
		if(ch=='-') f=-1;
		ch=gc();
	}
	while(isdigit(ch))
		ans=ans*10+ch-'0',ch=gc();
	ans*=f;return 1;
}

template<class T1,class T2>
int read(T1 &a,T2 &b) {
	return read(a)!=EOF&&read(b)!=EOF?2:EOF;
}

template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
	return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
}

typedef long long ll;
const int Maxn=310000;
const int inf=0x3f3f3f3f;
const ll mod=1000000007;

int n;
ll C,h[Maxn],f[Maxn];

struct node {
	ll x,y;
}a[Maxn];

signed main() {
//	freopen("test.in","r",stdin);
	read(n,C);
	for(int i=1;i<=n;i++) read(h[i]);
	int zhy=1,nh=0;
	a[++nh]=(node){-2*h[1],h[1]*h[1]};
	for(int i=2;i<=n;i++) {
		while(zhy!=nh&&h[i]*a[zhy+1].x+a[zhy+1].y<h[i]*a[zhy].x+a[zhy].y) zhy++;
		f[i]=a[zhy].x*h[i]+a[zhy].y+C+h[i]*h[i];
		ll x=-2*h[i],y=f[i]+h[i]*h[i];
		while(zhy!=nh&&1.0*(y-a[nh].y)*(a[nh].x-a[nh-1].x)>1.0*(a[nh].y-a[nh-1].y)*(x-a[nh].x)) nh--;
		a[++nh]=(node){-2*h[i],f[i]+h[i]*h[i]};
	}
	printf("%lld",f[n]);
	return 0;
}



Measured memory_bytes: 8960
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

string t[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main() {
  string s;
  while (cin >> s) {
    for (int i = 0; i < 7; i++) {
      if (s == t[i]) {
        cout << 7 - i << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int a[207];
int main()
{
	int n,i,x,minv=1000000000;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		while(x%2==0)
		{
			a[i]++;
			x=x/2;	
		}	
		minv=min(minv,a[i]);
	}	
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    int N;
    pair<int, int> A[100];
    pair<int, int> B[100];
    cin >> N;
    int a,b;
    for(int i=0;i<N;i++){
        cin >> a >> b;
        A[i] = make_pair(a,b);
    }
    for(int i=0;i<N;i++){
        cin >> a >> b;
        B[i] = make_pair(a,b);
    }
    sort(B, B+N);
    int temp=-1,ans=0,ind;
    for(int i=0;i<N;i++){
        temp = -1;
        for(int j=0;j<N;j++){
            if(B[i].first > A[j].first && B[i].second > A[j].second && temp < A[j].second){
                temp = A[j].second;
                ind = j;
            }
        }
        if(temp != -1){
            ans++;
            A[ind].first=999;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    if 1<=n<105:
        print(0)
    elif n<135:
        print(1)
    elif n<165:
        print(2)
    elif n<189:
        print(3)
    elif n<195:
        print(4)
    else:
        print(5)
resolve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << 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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int mod = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vector<int> f = {1},fi = {1};
int fact(int x){
    while(f.size() <=x)f.push_back((f.back()*f.size())%mod);
    return f[x];
}
int ifact(int x){
    return modpow(fact(x),mod-2,mod);
}
int C(int x,int y){
    if(x < y)return 0;
    return fact(x)*ifact(y)%mod*ifact(x-y)%mod;
}
signed main(){
    int k;cin >> k;
    string s;cin >> s;
    int ret = 0;
    int n = s.size();
    rep(x,k+1){
        int tmp = C(n+k-x-1,n-1)*modpow(25,k-x,mod)%mod;
        tmp =(tmp*modpow(26,x,mod))%mod;
        ret = (ret + tmp)%mod;
    }
    cout << ret  << endl;

    return 0;
}

Measured memory_bytes: 21584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = (1 << 30) - 1;

int N, C, D[50][50], grid[555][555], color[3][50], ans = inf;

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

    for (int i = 0; i < C; i++)
    {
        for (int j = 0; j < C; j++)
        {
            cin >> D[i][j];
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            cin >> grid[i][j];
            grid[i][j]--;
            color[(i + j) % 3][grid[i][j]]++;
        }
    }

    for (int i = 0; i < C; i++)
    {
        for (int j = 0; j < C; j++)
        {
            for (int k = 0; k < C; k++)
            {
                if (i == j || j == k || k == i)
                    continue;
                int sum = 0;
                for (int l = 0; l < C; l++)
                {
                    if (l == i)
                        continue;
                    sum += D[l][i] * color[0][l];
                }

                for (int l = 0; l < C; l++)
                {
                    if (l == j)
                        continue;
                    sum += D[l][j] * color[1][l];
                }
                for (int l = 0; l < C; l++)
                {
                    if (l == k)
                        continue;
                    sum += D[l][k] * color[2][l];
                }
                ans = min(ans, sum);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

//二つの最大公約数を求める
//(x>y) ll -> ll -> ll
ll gcd(ll x,ll y){
    if (y==0){ 
        return x;
    }else {
      return gcd(y,x%y);
    }
}

//素因数を求める
int soinnsuu(ll x){
    ll tmp=x;
    int cnt=1;
    for (ll a=2;a*a<=x;a++){
        if (tmp%a==0){
            cnt++;
            while(tmp%a==0){
                tmp/=a;
            }
            
        }
    } if (tmp>1) cnt++; 
    return cnt;
}


int main(){
    ll A,B,z;
    cin>>A>>B;
    if (A>B) {
        z=gcd(A,B);
    }else {
        z=gcd(B,A);
    }
    
    //cout<<z;
    
    cout<<soinnsuu(z)<<endl;
    
    return 0;
    

}


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

n, a, b = [int(x) for x in input().split()]
h = [int(input()) for _ in range(n)]

left = 0
right = 10**10

def solve(x):
    remain = []
    for i in h:
        i -= b*x
        if i > 0:
            remain.append(i)
    cnt = 0
    for i in remain:
        cnt += i // (a - b) + int(i % (a - b) != 0)
    if cnt <= x:
        return True
    else:
        return False

while right - left > 1:
    mid = (right + left) // 2
    if solve(mid):
        right = mid
    else:
        left = mid

print(right)






Measured memory_bytes: 118236
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int M;
    cin >> M;
    int d;
    long long c;
    long long sum=0;
    long long digit=0;
    rep(i,M){
        cin >> d >> c;
        digit += c;
        sum += d * c;
    }
    cout << digit-1 + (sum - 1) / 9;
 
    return 0;
}

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

int compara(const void * a, const void * b){
    int x = *(int *)a, y = *(int *)b;
    return x>y?1:x<y?-1:0;
}


void b(){
    int n;
    scanf("%d",&n);
    int v[n];
    for (int i = 0; i < n; i++) {
        scanf("%d",&v[i]);
    }
    qsort(&v,n,sizeof(v[0]),compara);
    printf("%d\n",v[n-1]-v[0] );
}

int main(int argc, char const *argv[]) {
    b();
    return 0;
}


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

const int maxn = 2e5 + 1;
int a[maxn];

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

    for(int i=0; i<n; i++) cout << (a[i]^xr) << " ";
    cout << "\n";

    return 0;
}

Measured memory_bytes: 4352
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    """ main """
    N = int(input())
    AS = list(map(int, input().split()))
    L = [0]*(N+2)
    R = [0]*(N+2)
    for i in range(0,N):
        L[i+1] = gcd(L[i],AS[i])
    for i in range(N-1,-1,-1):
        R[i] = gcd(R[i+1],AS[i])
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(L[i],R[i+1]))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 15476
#include <stdio.h>
#include <stdlib.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
void dfs();
void dfs_visit( int );
int M[N][N],color[N];
int n,d[N],f[N],timelap;
 
int main(){
  int i,j,u,v,k;
 
  scanf("%d",&n);
 
  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      M[i][j] = 0;
    }
  }
 
 
  for( i = 0 ; i < n ; i++ ){
    scanf("%d %d",&u,&k);
    u--;
 
    for( j = 0 ; j < k ; j++ ){
      scanf("%d",&v);
      v--;
 
      M[u][v] = 1;
    }
  }
 
  dfs();
  
  return 0;
}
 
 
void dfs(){
  int u;
 
  for( u = 0 ; u < n ; u++ ){
    color[u] = WHITE;
  }
 
  for( u = 0 ; u < n ; u++ ){
    if( color[u] == WHITE ) dfs_visit(u);
  }
 
  for( u = 0 ; u < n ; u++ ){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
 
 
void dfs_visit( int u ){
  int v;
 
  color[u] = GRAY;
  d[u] = ++timelap;
 
  for( v = 0 ; v < n ; v++ ){
 
    if( M[u][v] == 0 ) continue;
 
    if( color[v] == WHITE ) dfs_visit(v);
  }
 
  color[u] = BLACK;
  f[u] = ++timelap;
}

Measured memory_bytes: 636
#include <stdio.h>

int n;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0)
		{
			printf(" %d", i);
		}
		else if (i % 10 == 3)
		{
			printf(" %d", i);
		}
		else if (i % 100 / 10 == 3)
		{
			printf(" %d", i);
		}
		else if (i % 1000 / 100 == 3)
		{
			printf(" %d", i);
		}
		else if (i / 1000 == 3)
		{
			printf(" %d", i);
		}
	}
	printf("\n");
}


Measured memory_bytes: 2144
from fractions import gcd

n,x = map(int,input().split())
x_list = list(map(int,input().split()))
hoge = set()
for y in x_list:
  hoge.add(abs(x-y))
ans = abs(x_list[0]-x)
for num in hoge:
  ans = gcd(num,ans)
print(ans)

Measured memory_bytes: 18840
import sys

def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())
    ans = 0
    for i in range(B-A+1):
        x = str(A+i)
        if x == x[::-1]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    string S; cin >> S;
    char c1 = S[0];char c2 = S[1];char c3 = S[2];char c4 = S[3];
    if(c1 == c2 || c2 == c3 || c3 == c4) cout << "Bad" << endl;
    else cout << "Good" << endl;
}

Measured memory_bytes: 256
n = int(input().split()[0])
c = list(filter(lambda x:x <= n,map(int,input().split())))

minimum = [ i for i in range(n+1) ]

for i in range(2,n+1):
    for j in c:
        if j <= i and minimum[i-j] + 1 < minimum[i]:
            minimum[i] = minimum[i-j]+1

print(minimum[n])

Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s,n;
int main(){
	scanf("%lld",&s);
	n=(s-1)/1000000000+1;
	printf("0 0 1 1000000000 %lld %lld\n",n,n*1000000000-s);
	return 0;
}

Measured memory_bytes: 256
f :: (Show a1, Show a2) => a1 -> a2 -> Int
f a b = max (length (show a)) (length (show  b))

main :: IO ()
main = do
  n <- readLn
  let xs = [f x (div n x) | x <- [1..10^5], n`mod`x == 0]
  print $ foldr1 min xs


Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
	while (1)
	{
		int b = 1;
		cin >> b;
		if (b == 0)
		{
			break;
		}
		vector<string> a;
		vector<string> d;
		for (int i = 0; i < b; i++)
		{
			string w;
			cin >> w;
			string ww;
			cin >> ww;
			a.push_back(w);
			d.push_back(ww);
		}
		int bb = 0;
		cin >> bb;
		vector<string> e;
		for (int i = 0; i < bb; i++)
		{
			string w;
			cin >> w;
			bool count = true;
			for (int i = 0; i < a.size(); i++)
			{
				if (count == false)
				{
					continue;
				}
				else if (w == a[i])
				{
					w = d[i];
					count = false;
				}
			}
			e.push_back(w);
		}
		for (int i = 0; i < e.size(); i++)
		{
			cout << e[i];
			if (i + 1 == e.size())
			{
				cout << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2840
n=int(input())
d=[0 for i in range(10**7)]
    
def jud(l):
    if len(set(l))==3:
        return 6
    if len(set(l))==2:
        return 3
    if len(set(l))==1:
        return 1

for i in range(1,101):
    for j in range(i,101):
        for k in range(j,101):
            l=[i,j,k]
            p=i**2+j**2+k**2+i*j+j*k+k*i
            d[p-1]+=jud(l)

for i in range(n):
    print(d[i])

Measured memory_bytes: 87328
def main():
    H, W = (int(i) for i in input().split())
    c = [input() for i in range(H)]
    cnt = 0
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                cnt += 1
    if H+W-1 == cnt:
        print("Possible")
    else:
        print("Impossible")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;


int main(){
    long long n;
    cin >> n;
    vector<long long> a = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    long long i = 0;
    while(a.size() < n){
        if(a[i] % 10 && a[i] % 10 != 9){
            a.push_back(a[i] * 10 + a[i] % 10 - 1);
            a.push_back(a[i] * 10 + a[i] % 10 );
            a.push_back(a[i] * 10 + a[i] % 10 + 1);
        }
        else if(a[i] % 10 == 9){
            a.push_back(a[i] * 10 + a[i] % 10 - 1);
            a.push_back(a[i] * 10 + a[i] % 10);
        }
        else{
            a.push_back(a[i] * 10 + a[i] % 10);
            a.push_back(a[i] * 10 + a[i] % 10 + 1);
        }
        i++;
    }
    cout << a[n - 1];
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int mypow(int n, int p) {
    if (p == 0) return 1;
    else if (p & 1) {
        return n * mypow(n, p - 1);
    } else {
        int half = mypow(n, p >> 1);
        return half * half;
    }
}

int main() {
    int x;
    cin >> x;
    int ans = 1;
    for (int j = 2; j <= sqrt(x); ++j) {
        int tmp = j;
        int cnt = 0;
        while (tmp < x) {
            tmp *= j;
            ++cnt;
        }
        if (tmp == x) ++cnt;
        else tmp /= j;
        if (cnt >= 2)
            ans = max(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define ll long long
using namespace std;
int ans[100005],bits;

ll _min(ll a,ll b,ll c,ll d){
	ll ans=a;
	if (b<ans) ans=b;
	if (c<ans) ans=c;
	if (d<ans) ans=d;
	return ans;
}

ll _max(ll a,ll b,ll c,ll d){
	ll ans=a;
	if (b>ans) ans=b;
	if (c>ans) ans=c;
	if (d>ans) ans=d;
	return ans;
}

int main(){

	int n;
	int K;
	cin>>n>>K;
	ll x[100],y[100];
	
	for (int i=1;i<=n;i++){
		cin>>x[i]>>y[i];
	}
	ll ans=4e18;
	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			for (int k=j;k<=n;k++){
				for (int l=k;l<=n;l++){
					ll L,R,U,D;
					L=_min(x[i],x[j],x[k],x[l]);
					R=_max(x[i],x[j],x[k],x[l]);
					D=_min(y[i],y[j],y[k],y[l]);
					U=_max(y[i],y[j],y[k],y[l]);
					int cnt=0;
					ll area=(R-L)*(U-D);
					for (int u=1;u<=n;u++){
						if (x[u]>=L&&x[u]<=R&&y[u]>=D&&y[u]<=U){
							cnt++;
						}
					}
					if (cnt>=K&&area<ans){
						ans=area;
						//printf("%d %d %d %d %d\n",L,R,D,U,cnt);
					}
							
				}
			}
		}
	}
	
	cout<<ans;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

flag = 1
a.each do |ae|
  if ae > 0
    flag = 0
    break
  end
end

ans = 1
if flag == 1 && k % 2 == 1
  a.sort!{|x,y| y<=>x}
  for i in 0..(k-1)
    (ans * a[i] < 0) ? (mag = -1):(mag = 1)
    ans = (ans * a[i]).abs % MOD
    ans *= mag
  end
  puts ans % MOD
else
  a.sort!{|x,y| y.abs<=>x.abs}
  cnt = 0
  for i in 0..(k-1)
    cnt += 1 if a[i] < 0
  end
  if a[k-1] == 0
    puts 0
  elsif cnt % 2 == 0 || n == k
    for i in 0..(k-1)
      (ans * a[i] < 0) ? (mag = -1):(mag = 1)
      ans = (ans * a[i]).abs % MOD
      ans *= mag
    end
    puts ans % MOD
  else
    idbef = idaft = -1
    befp = befm = aftp = aftm = -1
    for i in 0..(k-1)
      id = k-1-i
      befp = id if befp == -1 && a[id] >= 0
      befm = id if befm == -1 && a[id] < 0
      break if befp >= 0 && befm >= 0
    end
    for id in k..(n-1)
      aftp = id if aftp == -1 && a[id] >= 0
      aftm = id if aftm == -1 && a[id] < 0
      break if aftp >= 0 && aftm >= 0
    end
    
    if befp < 0 || aftm < 0
      idbef = befm
      idaft = aftp
    elsif befm < 0 || aftp < 0
      idbef = befp
      idaft = aftm
    else
      if (a[aftp]*a[befp]).abs >= (a[aftm]*a[befm]).abs
        idbef = befm
        idaft = aftp
      else
        idbef = befp
        idaft = aftm
      end
    end
    
    for i in 0..(k-1)
      if i != idbef
        (ans * a[i] < 0) ? (mag = -1):(mag = 1)
        ans = (ans * a[i]).abs % MOD
        ans *= mag
      end
    end
    (ans * a[idaft] < 0) ? (mag = -1):(mag = 1)
    ans = (ans * a[idaft]).abs % MOD
    ans *= mag
    puts ans % MOD
  end
end

Measured memory_bytes: 29788
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();

		int ans = 0;
		if (A - B < C) {
			ans = C - (A - B);
		}
		System.out.println(ans);

	}
}


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

int main()
{
    int row,col,D,i,j;
    cin>>row>>col>>D;
    int val,arr[100000][2],query,arrcost[100000]={0};
    for(i=1;i<=row;i++)
    {
        for(j=1;j<=col;j++)
        {
            cin>>val;
            arr[val][0]=i;
            arr[val][1]=j;
        }
    }
    for(i=D+1;i<=row*col;i++)
        arrcost[i]=abs(arr[i-D][0]-arr[i][0])+abs(arr[i-D][1]-arr[i][1])+arrcost[i-D];
    //for(i=1;i<=row*col;i++)
        //cout<<i<<" "<<arr[i][0]<<" "<<arr[i][1]<<endl;
    cin>>query;
    while(query--)
    {
        int l,r,cost=0;
        cin>>l>>r;
        /*while(l<r)
        {
            //cost+=abs(arr[l][0]-arr[l+D][0])+abs(arr[l][1]-arr[l+D][1]);
            cost+=arrcost[l+D];
            l=l+D;
        }*/
        cout<<abs(arrcost[r]-arrcost[l])<<endl;
    }
    return 0;
}



Measured memory_bytes: 2176
//
// Created by yamunaku on 2020/02/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    ll n, k;
    cin >> n >> k;
    ll a;
    vl minus, zero, plus;
    rep(i, n){
        cin >> a;
        if(a < 0) minus.push_back(a);
        else if(a > 0) plus.push_back(a);
        else zero.push_back(a);
    }
    for(auto &x:minus) x = -x;
    sort(all(minus)), sort(all(plus));
    ll m = minus.size(), z = zero.size(), p = plus.size();
    ll l = -LINF, r = LINF + 1;
    while(r - l > 1){
        ll mid = (l + r) / 2;
        ll count = 0;
        if(mid >= 0){
            count += z * (m + p) + z * (z - 1) / 2 + m * p;
            rep(i, p){
                count += min(i, (int)(upper_bound(all(plus), mid / plus[i]) - plus.begin()));
            }
            rep(i, m){
                count += min(i, (int)(upper_bound(all(minus), mid / minus[i]) - minus.begin()));
            }
        }else{
            rep(i, p){
                count += m - (lower_bound(all(minus), (-mid + plus[i] - 1) / plus[i]) - minus.begin());
            }
        }
        if(count < k){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 2548
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll ans=0;
  string s;
  cin>>s;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='o')ans++;
  }
  if(15-s.size()+ans>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 888
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if (s*t >= d)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

int main() {
map<char, int> M;
char s;
for(int i=0; i<4; i++){
cin >> s;
M[s]++;
}

if(M.size()!=2){
cout << "No";
return 0;
}else{
for(auto i:M){
if(i.second != 2){
cout << "No";
return 0;
}
}
}
cout << "Yes";
}

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

int main() {
  double a, b, x, rad;
  cin >> a >> b >> x;
  if(x*2 >= a*a*b){
    double c = b * 2 - x * 2 / a / a;
    rad = atan(c/a);
  }else {
    rad = atan(a*b*b/2/x);
  }
  cout << std::setprecision(12) << rad * 180 / 3.141592653589793 << endl;
}

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

int main(){	
	string s;
	int k ;
	cin >> k >> s;
	if(s.length() <= k){
		cout << s << endl;
		return 0;
	}
	rep(i,k){
		cout << s[i];
	}
	cout << "..." << endl;
	return 0;

}




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

typedef long long ll;

struct Dice {
    //top, front, left, right, back, bottom
public :
    int face[6];

    Dice(int _face[]) {
        for(int i = 0; i < 6; i++)
            face[i] = _face[i];
    };
    
    void roll(int a, int b, int c, int d) 
    {
        int t = face[d];
        face[d] = face[c];
        face[c] = face[b];
        face[b] = face[a];
        face[a] = t;
    }

    void rollX()
    {
        roll(0, 1, 5, 4);
    }

    void rollY()
    {
        roll(0, 3, 5, 2);
    }

    void rollZ()
    {
        roll(1, 3, 4, 2);
    }

    Dice** rollAll()
    {
        Dice *dices[24];
        for(int i = 0; i < 6; i++) {
            for(int j = 0; j < 4; j++) {
                dices[i * 4 + j] = new Dice(face);
                rollZ();
            }
            if((i & 1) > 0) rollX();
            else rollY();
        }
        return dices;
    }
};

int main()
{
    int n, face[] = {1, 2, 4, 3, 5, 6};
    while(cin >> n && n) {
        Dice dice(face);
        int sum = 0;
        string op;
        for(int i = 0; i < n; i++) {
            cin >> op;
            if(op == "North") {
                for(int k = 0; k < 3; k++)
                    dice.rollX();
            } else if(op == "East") {
                dice.rollY();
            } else if(op == "West") {
                for(int k = 0; k < 3; k++)
                    dice.rollY();
            } else if(op == "South") {
                dice.rollX();
            } else if(op == "Right") {
                for(int k = 0; k < 3; k++)
                    dice.rollZ();
            } else {
                dice.rollZ();
            }
            sum += dice.face[0];
        }
        cout << sum + 1 << endl;
        
    }
}

Measured memory_bytes: 0
import sys
import io
#sys.stdin = io.StringIO(input_string)
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
    
def resolve():
	from collections import deque
	
	n, q = map(int, input().split())
	adj = [[] for i in range(n+1)]
	for i in range(n-1):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = [0 for i in range(n)]
	for i in range(q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x
#	print(f"{adj=}\n{ans=}")

	def dfs(now, prv):
		for next in adj[now]:
#			print(f"{now=}, {next=}")
			if next == prv:
				continue
			ans[next] += ans[now]
			dfs(next, now)

	dfs(0, 0)
	print(*ans)

resolve()


Measured memory_bytes: 268748
S = int(input())
mod = 10 ** 9 + 7

def comb(n, r, mod):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, S + 1):
    fac.append((fac[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    finv.append((finv[-1] * inv[-1]) % mod)

max_size = (S+2)//3
ans = 0
for i in range(1, max_size+1):
    ans += comb(S-i*3+i-1, i-1, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 65200