akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t ;
  int n1=s.size(),n=t.size(),cnt=0,sum=t.size();
  for(int i=0;i<=n1-n;i++){
    for(int j=0;j<n;j++){
      if(t[j]!=s[i+j])cnt++;
    }
    sum=min(sum,cnt);
    cnt=0;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(' ').map { it.toLong() }
    val B = readLine()!!.split(' ').map { it.toLong() }
    var rest = LongArray(N)
    var score = LongArray(N + 1)
    for (i in 0 until N + 1) {
        when (i) {
            0 -> {
                if (A[i] < B[i]) {
                    score[i] = A[i]
                    rest[i] = B[i] - A[i]
                } else {
                    score[i] = B[i]
                    rest[i] = 0L
                }
            }
            N -> {
                score[i] = Math.min(A[i], rest[i - 1])
            }
            else -> {
                if ((A[i] - rest[i - 1]) < B[i]) {
                    score[i] = A[i]
                    rest[i] = Math.min(B[i] - A[i] + rest[i - 1], B[i])
                } else {
                    score[i] = B[i] + rest[i - 1]
                    rest[i] = 0L
                }
            }
        }
    }
    var total = 0L
    for (i in 0 until N + 1) {
        total += score[i]
    }
    println(total)
}

Measured memory_bytes: 86612
#include <iostream>
using namespace std;
#define N 10000
int main(){
    int a;
    for(int i=1;i<=N;i++){
        cin >> a;
        if(a==0){
            break;
        }
        else{
            cout << "Case " << i << ": " << a << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++);
#define end return 0;
 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,c,d,e;
ll x[100005],y[100005],z[100005];
ll dp[100005];

int main(){
    cin>>n;
	for(i=1;i<=n;i++){
		cin>>x[i];
	}
	for(i=1;i<=n;i++){
		if(x[x[i]]==i)ans++;
	}
	p(ans/2);
	return 0;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;

    REP(i, (int)s.length())
    {
        cout << "x";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
//16:20~
using namespace std;
typedef long long int llint;
const llint big=((llint)1<<(llint)50);
const int mod=1000000007;
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pub push_back
#define res resize
#define ins insert
int main(void){
	int n,m,i,j,a,b,uni=0,team;
	cin>>n>>m;
	vector<vector<int>>win(n);//???????????????????????????
	vector<int>low(n);//????????????????????°
	vector<int>ans;
	queue<int>que;
	for(i=0;i<m;i++){
		cin>>a>>b;a--;b--;
		win[a].pub(b);
		low[b]++;
	}
	for(i=0;i<n;i++){if(low[i]==0){que.push(i);}}
	while(que.size()!=0){
		if(que.size()>1){uni=1;}
		team=que.front();
		ans.pub(team);
		que.pop();
		for(int i=0;i<win[team].size();i++){
			low[win[team][i]]--;
			if(low[win[team][i]]==0){que.push(win[team][i]);}
		}
	}
	for(i=0;i<n;i++){cout<<ans[i]+1<<endl;}
	cout<<uni<<endl;
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


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

    ll sum = 0;
    ll cost = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        if (i % 2 == 0) {
            if (sum <= 0) {
                cost += 1 - sum;
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cost += sum + 1;
                sum = -1;
            }
        }
    }
    ll ans = cost;
    cost = 0;
    sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        if (i % 2 == 1) {
            if (sum <= 0) {
                cost += 1 - sum;
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cost += sum + 1;
                sum = -1;
            }
        }
    }

    cout << min(ans, cost);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <set>
 
using namespace std;
 
#define MAX_V 100
#define MAX_E 10000
#define INF 1e9
typedef pair<int,int> pii;
 
struct Edge{
  int u,v,cost;
  Edge(){}
  Edge(int u,int v,int cost) : u(u),v(v),cost(cost) {}
};
 
bool cmp(const Edge &e1,const Edge &e2){
  return e1.cost < e2.cost;
}
 
int V,E,par[MAX_V],rank[MAX_V],wmin;
Edge es[MAX_E];
 
void init(){
  for(int i = 0 ; i < V ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}
 
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(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]){
      rank[x]++;
    }
  }
}
 
bool same(int x,int y){
  return find(x) == find(y);
}
 
int kruskal(){
  init();
  sort(es,es+E,cmp);
  set<pii> v;
  int max = 0, min = INF;
  for(int i = 0 ; i < E ; i++){
    Edge e = es[i];
    if(!same(e.u,e.v) && wmin <= e.cost){
      unite(e.u,e.v);
      v.insert(pii(e.u,e.v));
      max = std::max(max,e.cost);
      min = std::min(min,e.cost);
    } 
  }
  if((int)v.size() != V-1){
    return INF;
  }
  return max-min;
}
 
int main(){
  while(cin >> V >> E, (V | E)){
    int a,b,c;
    set<int> w;
    for(int i = 0 ; i < E ; i++){
      cin >> a >> b >> c;
      a--, b--;
      es[i] = Edge(a,b,c);
      w.insert(c);
    }
    int res = 1e9;
    set<int>::iterator it;
    for(it = w.begin() ; it != w.end() ; ++it){
      wmin = *it;
      res = min(res,kruskal());
    }
    cout << (res == INF ? -1 : res) << endl;
  }
  return 0;
}

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

using namespace std;

int  main() {
	char S[111111];
	cin >> S;

	char ans[26] = {};

	for (int i = 0; S[i]; i++) {
		ans[S[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		if (ans[i] == 0) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}

	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <algorithm>
#define yabs(x) (((x)<0)?(-(x)):(x))

using namespace std;
typedef long long LL;

const int N=1e5+10;

struct Point
{
	int x,y,id;
	Point (int x=0,int y=0,int id=0):x(x),y(y),id(id){}
	bool operator < ( const Point &A ) const { return y<A.y || (y==A.y && id<A.id);  }
};

int n,a,b,D,f[N],sz[N],ans[N],pos[N];
Point P[N],E[N];

int distances(int a,int b) { return max(yabs(P[a].x-P[b].x),yabs(P[a].y-P[b].y)); }

void Init()
{
	scanf("%d%d%d",&n,&a,&b);
	int x,y;
	for (int i=1;i<=n;++i)
	{
		scanf("%d%d",&x,&y);
		P[i].x=x+y; P[i].y=x-y;
	}
	D=distances(a,b);
}

map<pair<int,int>,bool>app;

bool cmpx(const Point &A,const Point &B) { return A.x<B.x || (A.x==B.x && A.y<B.y); }
bool cmpy(const Point &A,const Point &B) { return A.y<B.y || (A.y==B.y && A.x<B.x); }

set<Point>Q;

int find(int a) { return a==f[a]?a:f[a]=find(f[a]); }

void Merge(int a,int b)
{
	a=find(a); b=find(b);
	if (a==b) return ;
	f[a]=b; sz[b]+=sz[a];
}

int Findlr(int l,int r,LL val)
{
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (P[mid].y<=val) l=mid+1;
		else r=mid-1;
	}
	return r;
}

void Work()
{
	Q.clear();
	for (int i=1;i<=n;++i) pos[P[i].id]=i;
	int p=2,nowx=P[1].x,l=1,r=1;Q.insert(P[1]);
	for (int i=2;i<=n;++i)
	{
		while (P[i].x-nowx>D)
		{
			Q.clear(); nowx=1e9;
			if (p<=n) nowx=P[p].x,l=r=p,Q.insert(P[p]),++p;
			else return ;
		}
		while (nowx==P[p].x && p<=n) Q.insert(P[p]),r=p,++p;
		if (P[i].x-nowx!=D || Q.empty()) continue;
		
		set<Point>::iterator it=Q.upper_bound(Point(nowx,P[i].y));
		
		if (it==Q.end()) it--;
		while (it!=Q.begin() && (*it).y>=P[i].y-D) --it;
		while ((*it).y<P[i].y-D && it!=Q.end()) ++it;
		
		int top=0;
		while (it!=Q.end() && (*it).y<=P[i].y+D)
		{
			Merge(P[i].id,(*it).id);
			E[++top]=*it;
			++it;
		}
		
		if (top) ans[P[i].id]+=Findlr(l,r,1ll*P[i].y+D)-Findlr(l,r,1ll*P[i].y-D-1);
		for (int j=2;j<top;++j) Q.erase(E[j]);
		
	}
}

void Solve()
{
	for (int i=1;i<=n;++i) P[i].id=i,f[i]=i,sz[i]=1;
	
	sort(P+1,P+n+1,cmpx);
	Work();
	
	for (int i=1;i<=n;++i) swap(P[i].x,P[i].y);
	
	sort(P+1,P+n+1,cmpx);
	Work();
	
	for (int i=1;i<=n;++i) app[make_pair(P[i].x,P[i].y)]=1;
	for (int i=1;i<=n;++i) 
	{
		if (app[make_pair(P[i].x+D,P[i].y-D)]) ans[P[i].id]--;
		if (app[make_pair(P[i].x+D,P[i].y+D)]) ans[P[i].id]--;
	}
	LL anss=0;
	for (int i=1;i<=n;++i)
		if (find(i)==find(a)) anss+=ans[i];
	printf("%lld\n",anss);
}

int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 22912
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include<unordered_map>
#include<unordered_set>

using namespace std;
#define IO                 \
	ios::sync_with_stdio(0); \
cin.tie(0);              \
cout.tie(0);
#define forn(i, n) for (int i = 0; i < n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define mp make_pair
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define getcurrtime() \
	cerr << "Time = " << ((double)clock() / CLOCKS_PER_SEC) << endl

#define watch(x) cerr << (#x) << " is " << (x) << endl;

#ifndef LOCAL
#define cerr if(false)cerr
#endif
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll P=1e9+7;
double PI=3.141592653589793;
const int arrn = 4e6 + 1;

int n,m,q;
vector<pair<pii,pii>> cost;
int ans=0;

vector<int> proc;
void recur(int val){
	if(val==n-1){
		int cnt=0;
		while((int)proc.size()<m){
		 	proc.pb(val);
			cnt++;
		}
//		for(auto i:proc) cout << i << ' ';
//		cout << endl;
		int cur=0;
		for(auto i:cost){
			if(proc[i.fi.se]-proc[i.fi.fi]==i.se.fi) cur+=i.se.se;
		}	
		ans=max(ans,cur);
		while(cnt--) proc.rb();
		return;
	}
	int cnt=0;
	for(int i=0;(int)proc.size()<=m;i++){
		recur(val+1);
		proc.pb(val);
		cnt++;
	}
	while(cnt--) proc.rb();
}


void solve(){
	cin >> m >> n >> q;
	cost.resize(q);
	forn(i,q){
		cin >> cost[i].fi.fi >> cost[i].fi.se >> cost[i].se.fi >> cost[i].se.se;
		cost[i].fi.fi--;cost[i].fi.se--;
	}
	recur(0);
	cout << ans;
}

int main() {
	IO;
	int T=1;
//	cin >> T;
	forn(c,T){
		solve();
	}
}



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

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  ll N, K; cin >> N >> K;
  vector < pair<ll, int> > DT(N);
  
  for (int i = 0; i < N; i++){
    int T, D; cin >> T >> D; T--;
    DT[i] = make_pair(D, T);
  }
  sort(DT.begin(), DT.end(), greater< pair<ll, int> > ());

  vector <int> cnt(N);
  ll ans = 0, X = 0;
  priority_queue < pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > que;

  for (int i = 0; i < K; i++){
    que.push(DT[i]);
    ans += DT[i].first;
    if (cnt[DT[i].second] == 0) X++;
    cnt[DT[i].second]++;
  }
  ans += X * X;

  ll now = ans;
  for (int i = K; i < N; i++){
    if (cnt[DT[i].second] == 0){
      while (!que.empty()){
        pair <ll, int> P = que.top(); que.pop();

        if (cnt[P.second] > 1){
          now += DT[i].first - P.first;
          now += (X + 1) * (X + 1) - X * X;
          X++; cnt[P.second]--;
          cnt[DT[i].second]++;
          break;
        }
      }
      ans = max(now, ans);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4340
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    sort(A.rbegin(), A.rend());

    int64_t ans = A[0];
    for(int i=2; i<N; i++) {
        ans += A[i/2];
    }

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


Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<char,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> P(N+1,0);
    vector<ll> X(M,0);
    vector<ll> Y(M,0);
    for(ll i=1;i<=N;i++){
        cin>>P[i]
    ;}
    for(ll i=0;i<M;i++){
        cin>>X[i]>>Y[i]
    ;}

    UnionFind tree(N+1);
    for(ll i=0;i<M;i++){
        tree.unite(X[i],Y[i])
    ;}
    ll ans=0;
    for(ll i=1;i<=N;i++){
        if(tree.same(i,P[i]))ans++;
    ;}
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;




int main(){
	ll n;
	cin >> n;

	vector<ll> v(n);
	rep(i, 0, n) cin >> v[i];

	rep(i, 1, n)v[i] += v[i - 1];


	//1項目正
	ll ans1=0;
	ll all=0;
	bool fl = 0;
	rep(i,0,n) {
		if (fl == 0 && v[i] + all <= 0) {
			ans1 += 1LL - (v[i] + all);
			all += 1LL - (v[i] + all);
			fl = 1;
		}
		else if (fl == 1 && v[i] + all >= 0) {
			ans1 += 1LL + (v[i] + all);
			all += -1LL - (v[i] + all);
			fl = 0;
		}
		else if (fl==1) {
			fl = 0;
		}
		else {
			fl = 1;
		}
	}

	//1項目負
	ll ans2 = 0LL;
	all = 0LL;
	fl = 1;
	rep(i, 0, n) {
		if (fl == 0 && v[i] + all <= 0) {
			ans2 += 1LL - (v[i] + all);
			all += 1LL - (v[i] + all);
			fl = 1;
		}
		else if (fl == 1 && v[i] + all >= 0) {
			ans2 += 1LL + (v[i] + all);
			all += -1LL - (v[i] + all);
			fl = 0;
		}
		else if (fl == 1) {
			fl = 0;
		}
		else {
			fl = 1;
		}
	}


	cout << min(ans1, ans2) << endl;





	return 0;
}

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

ll pow(ll x,ll y,ll mod){
    if(y==0) return 1;
    else if(y%2==1){
        return x*pow(x,y-1,mod)%mod;
    }
    else{
        ll p=pow(x,y/2,mod);
        return p*p%mod;
    }
}
ll com(ll x,ll y,ll mod){
    ll ans=1;
    for(ll i=x;i>x-y;i--){
        ans*=i; ans%=mod;
    }
    //cout << ans << endl;
    for(ll i=1; i<=y; i++){
        ans*=pow(i,mod-2,mod); ans%=mod;
    }
    return ans;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=pow(2,n,MOD);
    ans -= com(n,a,MOD)+com(n,b,MOD)+1;
    while(ans<0) ans+=MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long C = long.Parse(str[2]);
		long D = long.Parse(str[3]);
		long Amax = -101;
		long Bmin = 101;
		string[] str2 = Console.ReadLine().Split();
		long[] AA = new long[A];
		long[] BB = new long[B];
		for(var i=0;i<A;i++){
			AA[i] = long.Parse(str2[i]);
			Amax = Math.Max(AA[i],Amax);
		}
		string[] str3 = Console.ReadLine().Split();
		for(var i=0;i<B;i++){
			BB[i] = long.Parse(str3[i]);
			Bmin = Math.Min(BB[i],Bmin);
		}
		string ans = "War";
		for(var i=C+1;i<=D;i++){
		if(Amax < i && Bmin >= i){
			ans = "No War";
			break;
		}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
		String[] x = sc.nextLine().split(" ");
		int s,g,d;
		int answer = 0;
		d = Integer.parseInt(x[1]);
		for (int i =0;i < Integer.parseInt(x[0]);i++) {
			String[] y = sc.nextLine().split(" ");
			s = Integer.parseInt(y[0]);
			g = Integer.parseInt(y[1]);
			if (Math.sqrt(Math.pow(s,2) + Math.pow(g,2)) <= d) {
				answer += 1;
			}
		}
		System.out.print(answer);
	}

}

Measured memory_bytes: 61368
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll x, a, b;
    cin >> x >> a >> b;
    if(abs(x - a) > abs(x - b)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
//#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define rep(i,n,N) for(int i=n;i<=N;i++)
#define rap(i,n,N) for(int i=(int)n;i>=(int)N;i--)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define sf se.fi
#define ss se.se
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<piii,pii>
#define pdd pair<double,double>
#define endl "\n"
const ll MAX=3e5+5;
const ll MAX2 = 11;
const int MOD=1000000000 + 7;
const ll INF=20000;
const int nr[]={1,0,-1,0,1,1,-1,-1};
const int nc[]={0,1,0,-1,1,-1,1,-1};

int n,m,q,x[505][505],le,ri,ans;

int main(){
	cout<<fixed<<setprecision(6);
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>q;
    while(m--){
    	cin>>le>>ri;
    	x[le][ri]++;
	}
	rep(j,1,n)rap(i,n,1)x[i][j]+=x[i+1][j];
	while(q--){
		cin>>le>>ri;
		ans = 0;
		rep(i,le,ri)ans+=x[le][i];
		cout<<ans<<endl;
	}
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n, k; cin >> n >> k;
    chmin(k, n);
    vi h(n); rep(i,n) cin >> h[i];

    vi dp(112345, inf);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 1; j <= k; ++j) {
            chmin(dp[i+j], dp[i] + abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << '\n';
}

Measured memory_bytes: 1152
arr = Array.new
while str = STDIN.gets
    op1,op2=str.chomp.split.map{|v|v.to_i}
    break if op1==0 && op2==0
    arr.insert(arr.length,[op1,op2])
end

arr.each do |elm|
    if elm[0]>elm[1] then print elm[1]," ",elm[0],"\n"
    else print elm[0]," ",elm[1],"\n"
    end
end

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


const int N=1e5+19;
 
int A[N],B[N],C[N];
int n,m,res;


int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

void work(int &x,int &y){
	int tmp=min(x,y);
	x-=tmp,y-=tmp,res+=tmp;
}

int main(){
	n=IN();m=IN();
	for(int i=0;i<n;i++){
		A[IN()]++;
	}
	for(int i=0;i<N;i++){
		B[i%m]+=A[i]%2;
		C[i%m]+=A[i]-A[i]%2;
	}
	for (int i=1;2*i<m;i++){
		work(B[i],B[m-i]);
		work(B[i],C[m-i]);
		work(C[i],B[m-i]);
		res+=C[i]/2;
		res+=C[m-i]/2;
	}
	if (m%2==0)
		res+=(B[m/2]+C[m/2])/2;
	
	res += (B[0]+C[0])/2;
	
	printf("%d\n",res);
	return 0;
}

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

struct Coordinate {
  int x;
  int y;
  Coordinate() : x(0), y(0) {}
};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int64_t> X(N);
  vector<int64_t> Y(N);
  vector<Coordinate> coords(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i) >> Y.at(i);
    coords.at(i).x = X.at(i);
    coords.at(i).y = Y.at(i);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  int64_t ans = numeric_limits<int64_t>::max();
  for (int ix_min = 0; ix_min < N - 1; ix_min++) {
    for (int ix_max = ix_min + 1; ix_max < N; ix_max++) {
      for (int iy_min = 0; iy_min < N - 1; iy_min++) {
        for (int iy_max = iy_min + 1; iy_max < N; iy_max++) {
          int64_t xmin = X.at(ix_min);
          int64_t xmax = X.at(ix_max);
          int64_t ymin = Y.at(iy_min);
          int64_t ymax = Y.at(iy_max);
          // 内部の点の数を数える
          int count = 0;
          for (int i = 0; i < N; i++) {
            if (xmin <= coords.at(i).x && coords.at(i).x <= xmax && ymin <= coords.at(i).y && coords.at(i).y <= ymax){
              count++;
            }
          }
          if (K <= count) {
            ans = min(ans, static_cast<int64_t>(xmax - xmin) * static_cast<int64_t>(ymax - ymin));
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))

cost = []
for i in range(N):
    c = 1 if i + 1 in A else 0
    cost.append(c)

print(min(sum(cost[:X - 1]), sum(cost[X - 1:])))


Measured memory_bytes: 2940
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
inf = float("inf")

s = input()
t = input()
# print(s, t)

len_s, len_t = len(s), len(t)
max_len = max(len_s, len_t)
dp = [[0 for j in range(max_len + 1)] for i in range(max_len + 1)]

for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

# pprint(dp)
# print(dp[len(s)][len(t)])

res = ''
i, j = len_s, len_t
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        # (i - 1, j) -> (i, j)
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        # (i, j - 1) -> (i, j)
        j -= 1
    else:
        # (i - 1, j - 1) -> (i, j)
        res = s[i - 1] + res
        i -= 1
        j -= 1

print(res)


Measured memory_bytes: 119900
#include <iostream>
using namespace std;
int main() {
    long long int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(max(max(a, b)*max(c,d),  min(a,b)*min(c,d)), max(max(a, b)*min(c,d),  min(a,b)*max(c,d))) << endl;;
}


Measured memory_bytes: 3192
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! dbg { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

#[fastout]
fn main() {
    input! {
        n: usize,
        x: usize,
        m: usize,
    }
    let mut r = x;
    let mut l = vec![x];
    let mut set = BTreeSet::new();
    set.insert(x);
    loop {
        r = (r * r) % m;
        l.push(r);
        if set.contains(&r) {
            break;
        }
        set.insert(r);
    }
    let l_len = l.len();
    let mut ans = 0;
    let mut k1 = 0;
    for i in 0..l_len {
        if l[i] == l[l_len - 1] {
            k1 = i;
            break;
        }
        ans += l[i];
    }
    l.pop();
    let k2 = l_len - k1 - 1;
    let mut ll = l[k1..]
        .iter()
        .scan(0, |arr, a| {
            *arr += a;
            Some(*arr)
        })
        .collect::<Vec<_>>();
    ll.insert(0, 0);
    if n > k1 {
        ans += ll[k2] * ((n - k1) / k2) + ll[(n - k1) % k2];
    }
    println!("{}", ans);
}


Measured memory_bytes: 3640
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	string s;
	cin >> s;

	int r = 0;
	int b = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') r++;
		if (s[i] == 'B')b++;
	}

	if (r > b)
		printf("Yes\n");
	else
		printf("No\n");

ProgramEndPointLabel:;

	system("pause");

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power%MOD;
    power = (power*power)%MOD;
    p /= 2;
  }

  return res;
}

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

  ll n;
  cin>>n;
  ll ans=mpow(10,n)+mpow(8,n)-2*mpow(9,n);
  ans=(ans+2*MOD)%MOD;
  cout<<ans<<endl;
}



Measured memory_bytes: 3636
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,p,a[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(;i++<n;)
	{
		p=(10*p+7)%n;
		if(!p)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int main() {
	ull L, R;
	cin >> L >> R;

	ull result = ULLONG_MAX;

	for( ull i = L; i < R; ++i ) {
		for( ull j = i+1; j <= R; ++j ) {
			result = min( result, (i*j) % 2019 );

			if( result == 0 ) { break; }
		}

		if( result == 0 ) { break; }
	}

	cout << result << endl;
}


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

using namespace std;

typedef long long ll;

ll mod;

ll powimod(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

ll powi(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
    cin>>a[i];
    }
    for(int i=k+1;i<=n;i++)
    {
    if(a[i]>a[i-k]) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    }
}


Measured memory_bytes: 4440
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int h[110][110];
int a;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

vector<edge> G[500];
int level[500];
int iter[500];

void add_edge(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v==t)return f;

	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t,int n){
	int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,m))>0){
			flow+=f;
		}
	}
}

bool C(int v){
	int s=n+m,t=s+1;
	for(int i=0;i<=s+2;i++){
		G[i].clear();
	}
	if(m-a*n>0)add_edge(s,s+2,m-a*n);
	for(int i=0;i<n;i++){
		add_edge(s,i,a);
		if(m-a*n>0)add_edge(s+2,i,1);
		for(int j=0;j<m;j++){
			if(h[i][j]<=v)add_edge(i,n+j,1);
		}
	}
	for(int i=0;i<m;i++){
		add_edge(n+i,t,1);
	}
	int val=max_flow(s,t,m);
	return (val==m);
}

int main(void){
	scanf("%d%d",&n,&m);
	int maxi=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&h[i][j]);
			maxi=max(maxi,h[i][j]);
		}
	}
	a=m/n;
	printf("%d\n",(a*n==m)?0:1);
	int l=-1,r=maxi;
	while(r-l>1){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 3360
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int A, B, C, X;
int a = 0, b = 0, c = 0;
int num = 0;

int main() {
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	scanf("%d", &X);


	for (int c = X / 50; c >= 0; c -= 2, b += 1) {
		for (int _a = a, _b = b; _b >= 0; _b -= 5, _a += 1) {
			if (_a <= A && _b <= B && c <= C) num++;
		}
	}

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

	return 0;
}

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

int main(){
  ull n;
  cin >> n;
  ull ans = 0;
  rep(i,n){
    ull num;
    cin >> num;
    ans += num-1;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String S = keyboard.next();
		
		String[] tile = S.split("");
		
		String Start = tile[0];
		int countG = 0;
		int countK = 0;
		
			for (int g = 0; g < tile.length; g = g+2) {
				 if (tile[g].equals(Start)) {
					 countK ++;
				 }else {
					 countG ++;
				 }
				 	if (g != tile.length - 1) {
				 		int k = g + 1;
				 if (tile[k].equals(Start)) {
					 countG ++;
				 	}else{
					 countK ++;
				 		}
				 	}
			}
			
			int kotae = 0;
			
			kotae = countG < countK ? countG : countK;
		
		System.out.println(kotae);
		keyboard.close();
	}
}

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

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

    string ns;

    int ans=0;
    for(int i=n;i<1000;i++){
        ns = to_string(i);

        if(ns[0]==ns[1] && ns[1] == ns[2]){
            ans = i;
            break;
        }
    }
    cout << ans;

}

Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    t = str(input().rstrip('\n'))
    s = collections.Counter(t).most_common()
    k = int(input().rstrip('\n'))
    s.sort()
    d = {}
    for key, v in s:
        for i in range(len(t)):
            if t[i] == key:
                for j in range(i + 1, i + 6):
                    d[t[i:j]] = 1
        if len(d) >= k:
            print(sorted(d.items())[k-1][0])
            exit()


if __name__ == '__main__':
    slove()


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

int main() {
  int64_t x;
  cin >> x;
  for(int64_t i=0; i<=500; i++){
    for(int64_t j=i; j<=500; j++){
      if(j*j*j*j*j-i*i*i*i*i==x){
        cout << j << " " << i << endl;
        break;
      }
      if(j*j*j*j*j+i*i*i*i*i==x){
        cout << j << " " << -i << endl;
        break;
      }
    }
  }
      
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979323846264338327950L
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,h,m;
	cin>>a>>b>>h>>m;
	
	ld rad=2*pi*((ld)h/12.0+((ld)m/60.0)/12.0-((ld)m/60.0));
	ld res=a*a+b*b-2*a*b*cosl(rad);
	cout<<fixed<<setprecision(20)<<sqrt(res)<<"\n";
	return 0;
}


Measured memory_bytes: 4152
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

bool used[2000000] = {false};
int main(){
    ll n, m;
    cin >> n >> m;

    vector<int> a(m);
    vector<int> b(m);
    vector<int> start;
    vector<int> goal;
    rep(i, m){
        cin >> a[i] >> b[i];
        if(a[i] == 1)start.push_back(b[i]);
        if(b[i] == n)goal.push_back(a[i]);
    }

    sort(ALL(start));
    sort(ALL(goal));
    rep(i, min(start.size(), goal.size())){
        int pos;
        if(start.size() <= goal.size()){
            pos = lower_bound(ALL(goal), start[i]) - goal.begin();
            if(goal[pos] == start[i]){
                //cout << b[pos] << "&" << a[i] << endl;
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
        else{
            pos = lower_bound(ALL(start), goal[i]) - start.begin();
            if(start[pos] == goal[i]){
                //cout << b[pos] << "&" << a[i] << endl;
                cout << "POSSIBLE" << endl;
                return 0;
            }
        } 
    }
    cout << "IMPOSSIBLE" << endl;
}

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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  uint64_t sum = 0;
  int ans = n;
  for (int i = n-1; 0 <= i; --i) {
    if (sum + a[i] < k) sum += a[i];
    else ans = min(ans, i);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans=0
isLoop=True
while(isLoop):
    c=0
    for i in range(0, N):
        if A[i]%2==0:
            c+=1
        else:
            isLoop=False

    if c==N:
        for i in range(0, N):
            A[i] = A[i]/2

        ans+=1

print(ans)

Measured memory_bytes: 3064
N = int(input())

A = [0] * N
x = [[0]*N for _ in range(N)]
y = [[0]*N for _ in range(N)]

#input
for i in range(N):
    A[i] = int(input())
    for j in range(A[i]):
        x[i][j], y[i][j] = map(int, input().split())

ans = 0

# 1: 正直者 0: 不親切
for i in range(2**N):
    bit = bin(i)[2:].zfill(N)
    # 検証
    checked = 1
    for j in range(N):
        if bit[j] == "1":  # j が正直者のとき
            for k in range(A[j]):
                if int(bit[x[j][k] - 1]) != y[j][k]:
                    checked = 0
                    break
    if checked == 1:
        ans = max(ans, bit.count("1"))

print(ans)


Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
from itertools import product


def read():
    N, K = map(int, input().strip().split())
    return N, K


def binom2(n):
    return n * (n-1) // 2


def print_graph(pairs):
    print(len(pairs))
    for x, y in pairs:
        print("%d %d" % (x, y))


def solve(N, K):
    B = binom2(N-1)
    if K > B:
        print(-1)
        return
    XY = []
    y = N
    for x in range(1, N):
        XY.append((x, y))
    k = B
    # k=0でB対あるので、K対になるまで辺を1本ずつ増やす
    for x in range(1, N):
        for y in range(x+1, N):
            if k == K:
                print_graph(XY)
                return
            XY.append((x, y))
            k -= 1
    print_graph(XY)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(x) cout<<x<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
	vector<ll> Parent;
public:
	UnionFind(ll N){
		Parent = vector<ll>(N, -1);
	}

	ll root(ll A){
		if(Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	ll size(ll A){
		return -Parent[root(A)];
	}

	bool connect(ll A, ll B){
		A = root(A);
		B = root(B);
		if(A == B){
			return false;
		}
		if(size(A) < size(B)) swap(A, B);
		Parent[A] += Parent[B];
		Parent[B] = A;
		return true;
	}

	bool isSame(ll A, ll B){
		return root(A) == root(B);
	}
};

ll n,m;


signed main()
{
	cin.tie( 0 ); ios::sync_with_stdio( false );
	cin>>n>>m;
	vpll ab(m);
	rep(i,m){
		ll a,b; cin>>a>>b; a--,b--;
		ab[i]={a,b};
	}
	ll ans=0;
	rep(i,m){
		UnionFind uf(n);
		rep(j,m){
			if(i==j) continue;
			uf.connect(ab[j].first,ab[j].second);
		}
		bool ok=true;
		rep(i,n){
			if(!uf.isSame(0LL,i)) ok=false;
		}
		if(!ok) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    import sys
    sys.setrecursionlimit(1000000)

    N = int(input())
    A = [[]]
    for _ in range(N):
        A.append([0]+list(map(int,input().split())))

    #AR[i][j] => iにとって選手jとの試合が何番目か
    AR = [[]]
    for i in range(1,N+1):
        AR.append([0]*(N+1))
        for j in range(1,N):
            b = A[i][j]
            AR[i][b] = j

    edges =[[[] for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            jForI = AR[i][j]
            if jForI < N-1:
                nxForI = A[i][jForI+1]
                edges[i][j].append((min(i,nxForI),max(i,nxForI)))
            iForJ = AR[j][i]
            if iForJ < N-1:
                nxForJ = A[j][iForJ+1]
                edges[i][j].append((min(j,nxForJ),max(j,nxForJ)))
    del A
    del AR

    steps = {}
    def dfs(i,j):
        #iとjの試合を1日目とし、試合終了まで何日かかるかを返す。
        if (i,j) not in steps:
            steps[(i,j)] = 0
            res = 1
            for a,b in edges[i][j]:
                res = max(res,dfs(a,b)+1)
            steps[(i,j)] = res
        elif steps[(i,j)] == 0:
            print(-1)
            exit()
        return steps[(i,j)]

    ans = 0
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            ans = max(ans,dfs(i,j))
    print(ans)
main()

Measured memory_bytes: 304380
// *
// *
// *  Created By : Pritish Thakkar 
// *  Hackerrank : ma5terdrag0n
// *  CodeChef : solo_loser
// *  Hackerearth : pritish9
// *------------------------------------
// *  OS : Ubuntu 16.04
// *  Language : CPP14
// *  Editor : Sublime Text 3
// *  C++ compiler : g++
// *
// *
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

bool isUpper(char c) {return (c >= 'A' && c <= 'Z');}
bool isLower(char c) {return (c >= 'a' && c <= 'z');}
bool iplpha(char c) {return (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z');}
bool isnum(char c){return (c >= '0' and c <= '9');}
bool isalnum(char c) {return (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z')||(c >= '0' && c <= '9');}
char toUpper(char c){return isUpper(c)?c:c-'a'+'A';}
char toLower(char c){return isLower(c)?c:c+'a'-'A';}
bool isvowel(char c){c = toLower(c); return (c == 'a' or c == 'e' or c == 'i' or c == 'i' or c == 'o' or c == 'u');}
template<typename t> t gcd(t a, t b){return ((b == 0) ? a : gcd(b, a%b));} 
template<typename t> t lcm(t a, t b){return (a * (b / gcd(a, b)));}
template <typename T> T modpow(T base, T exp, T modulus) {base %= modulus;T result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
string toLowerCase(string s){rep(s.size()){if(!isLower(s[i])){s[i] = toLower(s[i]);}}return s;}
string toUpperCase(string s){rep(s.size()){s[i] = toUpper(s[i]);}return s;}
template<typename T> void cumulative(T *a, T *b, T n){rep(n){i ? b[i] = b[i-1] + a[i] : b[i] = a[i];}}
bool ispal(string s){ll lo, hi;lo = 0;hi = s.length()-1;while(lo <= hi){if(s[lo] != s[hi]){return 0;}lo++;--hi;}return 1;}
template<class T >string toString(T n){string v = "";while(n){v.pb(n % 10 + '0');n /= 10;}reverse(all(v));return v;}

//--------------------------------------------------------------------

bool fun(ll *a, ll idx){
    bool ok = 1;
    for(int i = idx + 1 ; i < 26 ; i ++){
        if(a[i])return 1;
    }
    return 0;
}

void solve(){
    string a, b;
    cin >> a >> b;
    sort(all(a));
    sort(all(b));
    reverse(all(b));
    cout << ((a < b) ? "Yes" : "No");
}
 
int main(){
    std::ios::sync_with_stdio(0);
    // int start = clock();
    #ifdef ONLINE_JUDGE
    #else
//      freopen("input.in" , "r" , stdin);
      // freopen("output.txt", "w", stdout);
    #endif
    solve();
    // cout << n;
    // int stop = clock();
    // cout << (stop - start) / 1000.0000<< endl;
}












Measured memory_bytes: 256
import sys
N = int(input())
array = []
for I in range(N): array.append(int(input()))
for J in array:
    if not ( 100 <= J <= 10000 ): sys.exit()
if not ( 2 <= N <= 10 ): sys.exit()

print(int(max(array)/2) + sum(array) - max(array))

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#define ll long long int
#include <cmath>
using namespace std;
const unsigned int m = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   	int t;
   	//cin>>t;
   	t=1;
   	while(t--)
   	{
      int k;
      cin>>k;
      string s;
      cin>>s;
      int n=s.size();
      if(n<=k)
        cout<<s<<endl;
      else
      {
          for(int i=0;i<k;i++)
          {
              cout<<s[i];
          }
          cout<<"..."<<endl;
      }
	}
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main (){
    string S;
    cin >> S;

    S[0] = '2';
    S[1] = '0';
    S[2] = '1';
    S[3] = '8';

    cout << S << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	ll r,d,x;
	cin >> r >> d >> x;
	rep(i,0,10){
		x = r*x - d;
		cout << x << endl;
	}
}


Measured memory_bytes: 256
hoge = list()
for elem in (elem for elem in input().split()):
    if elem == '+':
        elem = int(hoge.pop()) + int(hoge.pop())
    elif elem == '*':
        elem = int(hoge.pop()) * int(hoge.pop())
    elif elem == '-':
        elem = -1*int(hoge.pop()) + int(hoge.pop())
    hoge.append(elem)
print (elem)


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

using namespace std;

const int N = 2e5 + 5;

int n, a[N];

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for (int i = 2; i <= n; i++) {
        if (a[i] == a[i - 1]) {
            return cout << "NO", 0;
        }
    }
    
    cout << "YES";
    return 0;
}

Measured memory_bytes: 1024