akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
int main(){ 
	int k; cin >> k;
	int lcm = 360 * k / __gcd(360, k);
	cout << lcm / k << endl; 
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;

int main(void){
    int a[4];
    for(int i=0;i<3;i++){
        cin >> a[i];
    }
    sort(a,a+3);
    int x,y;
    x = a[0]+a[1];
    y = a[2];
    if(x==y){
        cout << "Yes" << endl; 
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef pair<ll,int> LL_IP;

#define ARRAY_MAX 1005

int imos[ARRAY_MAX][ARRAY_MAX];

int main(){

    int n;
    cin >> n;
    int x1,y1,x2,y2;
    int maxi_x2 = -1,maxi_y2 = -1;
    REP(i,n){
        cin >> x1 >> y1 >> x2 >> y2;
        imos[x1][y1]++;
        imos[x2][y2]++;
        imos[x1][y2]--;
        imos[x2][y1]--;
        maxi_x2 = max(maxi_x2,x2);
        maxi_y2 = max(maxi_y2,y2);
    }
    //cout << maxi_x2 << " " << maxi_y2 << endl;



    //縦imos
    for(int i = 0;i <= maxi_y2;i++){
        for(int j = 0;j <= maxi_y2+1;j++){
            imos[j+1][i] += imos[j][i];
        }
    }

    

    //横imos
    for(int i = 0;i <= maxi_x2;i++){
        for(int j = 0;j <= maxi_y2+1;j++){
            imos[i][j+1] += imos[i][j];
        }
    }

    /*for(int i = 0;i <= maxi_x2+1;i++){
        for(int j = 0;j <= maxi_y2+1;j++){
            cout << imos[i][j] << " ";
        }
        cout << endl;
    }*/
   

    int ans = -1;
    for(int i = 0;i <= maxi_x2;i++){
        for(int j = 0;j <= maxi_y2;j++){
            ans = max(ans,imos[i][j]);
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 7068
x, y = map(int, input().split())
if (x+y)%3 != 0:
    print(0)
    exit()

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 = 10**9+7
N = 10**6
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 )
 
 
# a = (2*x-y)//3
# b = (2*y-x)//3
a = y - (x+y)//3
b = x - (x+y)//3
n = a+b
r = a
res = cmb(n,r,mod)
print(res)

Measured memory_bytes: 127560
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////

int n,a,b,v[55];

int c[51][51];
void cominit(){
  rep(i,51){
    rep(j,i+1){
      if(j == 0 || j == i){
        c[i][j] = 1LL;
      }else{
        c[i][j] = (c[i-1][j-1] + c[i-1][j]);
      }
    }
  }
}

signed main(){
  cin>>n>>a>>b;rep(i,n)cin>>v[i];
  sort(v,v+n,greater<int>());
  double sum = 0, ave = 0;
  rep(i,n){
    sum += v[i];
    if(i+1 < a || b < i+1)continue;
    chmax(ave, sum/(i+1));
  }
  cominit();
  map<int, int> mp;
  rep(i,n)mp[v[i]]++;
  int ans = 0;sum = 0;
  rep(i,n){
    sum += v[i];
    if(i+1 < a || b < i+1)continue;
    if(sum/(i+1) == ave){
      map<int,int> cmp;int k = 1;
      rep(j,i+1)cmp[v[j]]++;
      rep(j,i+1){
        if(j > 0 && v[j-1] == v[j])continue;
        k *= c[mp[v[j]]][cmp[v[j]]];
      };
      ans += k;
    }
  }
  cout << fixed << ave << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**4
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,X,Y = LI()

c = [0 for _ in range(N+1)]

for k in range(1,N):
    j = 1
    m = [0 for _ in range(N+1)]
    j = 1
    for i in range(k+1,N+1):
        m[i] = j
        j += 1
    if k <= X:
        j = X - k + 1
        a = 0
        while j + a < m[Y - a]:
            m[Y -a] = j + a
            a += 1
        a = 1
        if Y + a <= N:
            while j + a < m[Y + a]:
                m[Y + a] = j + a
                a += 1
                if Y + a > N : break
    elif k <= Y:
        j = k - X + 1
        a = 0
        while j + a < m[Y - a]:
            m[Y -a] = j + a
            a += 1
        a = 1
        if Y + a <= N:
            while j + a < m[Y + a]:
                m[Y + a] = j + a
                a += 1
                if Y + a > N : break
    for i in range(k+1,N+1):
        c[m[i]] += 1
for k in range(1,N):
    print (c[k])






Measured memory_bytes: 73304
NIL = -1

class Node:
    parent = NIL
    left = NIL
    right = NIL

def getDepth(u):
    d = 0
    while T[u].parent != NIL:
        u = T[u].parent
        d += 1
    return d

def getChildren(u):
    c = T[u].left
    result = []
    while c != NIL:
        result.append(c)
        c = T[c].right
    return result

n = int(input())
T = [0]*n
for i in range(n):
    T[i] = Node()
    
for i in range(n):
    tmp = list(map(int,input().split()))
    id = tmp.pop(0)
    k = tmp.pop(0)
    c = tmp
    if k != 0:
        for j in range(len(c)):
            T[c[j]].parent = id
        T[id].left = c[0]
        for j in range(len(c)-1):
            T[c[j]].right = c[j+1]
            
for i in range(n):
    d = getDepth(i)
    c = getChildren(i)
    if d == 0:
        t = 'root'
    elif c == []:
        t = 'leaf'
    else:
        t = 'internal node'
    print('node ',i,': ','parent = ',T[i].parent,', depth = ',d,', ',t,', ',c,sep = '')

Measured memory_bytes: 30744
#include<iostream>
#define M 52
#include<queue>
#include<cstring>
using namespace std;
struct P{
	int ax,ay,bx,by,cost;
	P(){}
	P(int h,int j,int k,int l,int co):
	ax(h),ay(j),bx(k),by(l),cost(co){}
};
int main(){
	bool s[M][M],d[M][M][M][M],u;
	int w,h,tx,ty,kx,ky,dx[]={1,-1,0,0},dy[]={0,0,-1,1};
	while(cin>>w>>h,w||h){
		cin>>tx>>ty;tx--;ty--;
		cin>>kx>>ky;kx--;ky--;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				cin>>s[i][j];
		queue<P> que;
		memset(d,0,sizeof(d));
		d[tx][ty][kx][ky]=1;
		que.push(P(tx,ty,kx,ky,0));
		u=true;
		while(!que.empty()){
			P p=que.front();
			que.pop();
			if(p.cost>=100)
				break;
			if(p.ax==p.bx&&p.ay==p.by){
				cout<<p.cost<<endl;
				u=false;
				break;
			}
			int ntx,nty,nkx,nky;
			for(int i=0;i<4;i++){
				ntx=p.ax+dx[i];
				nty=p.ay+dy[i];
				nkx=p.bx-dx[i];
				nky=p.by-dy[i];
				if(!(ntx>=0&&ntx<w&&nty>=0&&nty<h)||s[nty][ntx]==1){
					ntx=p.ax;nty=p.ay;
				}
				if(!(nkx>=0&&nkx<w&&nky>=0&&nky<h)||s[nky][nkx]==1){
					nkx=p.bx;nky=p.by;
				}
				if(d[ntx][nty][nkx][nky]!=1)
					que.push(P(ntx,nty,nkx,nky,p.cost+1));
				d[ntx][nty][nkx][nky]=1;
			}
		}
		if(u)
		cout<<"NA"<<endl;
	}
	return 0;
}

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

using namespace std;

int mod = (int)1e9 + 7;

int add(int a, int b) {
	return (a + b) % mod;
}

int dp[(int)1e3 + 7][(int)1e3 + 7];
char c[(int)1e3 + 7][(int)1e3 + 7];
int n, m;

main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		getchar();
		for (int j = 1; j <= m; j++) {
			c[i][j] = getchar();
		}
	}
	for (int i = 1; i <= n; i++) {
		if (c[i][1] == '#') break;
		dp[i][1] = 1;
	}
	for (int i = 1; i <= m; i++) { 
		if (c[1][i] == '#') break;
		dp[1][i] = 1;
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 2; j <= m; j++) {
			if (c[i][j] == '.') {
				dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	cout << dp[n][m];
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};

int main(){
    int n,m;cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;cin >> a >> b;
        --a;--b;

        uf.unite(a, b);
    }

    int ans = 0;
    rep(i,n){
        chmax(ans, uf.size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4012
import "dart:io";

void main() {
  var n = int.parse(stdin.readLineSync()); 
  var sum = 0;
  
  for (int i = 0; i <= n; i++) {
  	if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  print(sum);
}

Measured memory_bytes: 13152
#include<stdio.h>
int main()
{int a,b,c,d,e,f;
 scanf("%d %d %d %d",&a,&b,&c,&d);
 
 if(a%d==0) e=a/d;
 else e=a/d+1;
 
  if(c%b==0) f=c/b;
 else f=c/b+1;
 
 if(f<=e) printf("Yes");
 else printf("No");
return 0;
}

Measured memory_bytes: 1728
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;
#define DEBUG 0
#define lli long long int

const lli N_MAX = 100;
lli N;
lli B[N_MAX];
lli ans = 0;

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

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

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve(long long N, std::string S){
    vector<int> cntW(N,0);
    vector<int> cntE(N,0);
    // int cntW=0, cntE=0;
    for (ll i = 1; i < N; i++) {
        if(S[i-1]=='W') {
            cntW[i]=cntW[i-1]+1;
        } else {
            cntW[i]=cntW[i-1];
        }
        if(S[N-1-i+1]=='E') {
            cntE[N-1-i]=cntE[N-1-i+1]+1;
        } else {
            cntE[N-1-i]=cntE[N-1-i+1];
        }
    }
    int val = cntW[0]+cntE[0];
    for (ll i = 0; i < N; i++) {
        val = min(val, cntW[i]+cntE[i]);
    }
    cout << val << "\n";
    // vout(cntW);
    // vout(cntE);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3332
import java.util.*;
public class Main {
	public static void main(String[] args){
    //読み方を格納数r
    String yomi[] = {"hon","pon","bon"};
    int index = 0;
    //標準入力のインスタンス作成
		Scanner sc = new Scanner(System.in);
		// 整数Nの入力
		int N = sc.nextInt();
		// 出力
    int keta_1 = N%10;
    if ( keta_1 == 0 || keta_1==1 || keta_1==6 || keta_1==8 ){
      index=1;
    }else if( keta_1==3 ){
      index=2;
    }
		System.out.println(yomi[index]);
	}
}


Measured memory_bytes: 35760
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,min=0,max=0;cin>>N;
    vector<int> color(9,0);
    REP(i,N){
        int a;
        cin>>a;
        int index = (a/400>8)?8:a/400;
        color[index]++;
    }
    REP(i,8){
        if(color[i]>0)min++;
    }
    max=min+color[8];
    if(min==0)min++;
    printf("%d %d\n",min,max);
}

Measured memory_bytes: 256
N = int(input())
if N == 1:
    u = ''.join(sorted(list(input())))
    print(u)
else:
    os = input()
    news = ''
    l = [-1] * len(os)
    for _ in range(N-1):
        s = input()
        for i,c in enumerate(os):
            for j,d in enumerate(s):
                if c == d:
                    if j in l:pass
                    else:
                        l[i] = j
                        news = news + c
                        break
        os = news
        news = ''
        l = [-1] * len(os)
    u = ''.join(sorted(list(os)))
    print(u)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//
int n;
vector<int> px,py,qx,qy;
int dp[8100][8100];
struct vevev{
	vector<int> a;vector<int> b;vector<int> ab;
};
vevev compress(vector<int> x1,vector<int> x2){
	vector<int> xs;
	for(int i=0;i<n;i++){
		for(int j=0;j<=1;j++){
			xs.push_back(x1[i]+j);
			xs.push_back(x2[i]+j);
		}
	}
	xs.push_back(1e9+7);
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=0;i<n;i++){
		x1[i]=lower_bound(xs.begin(),xs.end(),x1[i])-xs.begin();
		x2[i]=lower_bound(xs.begin(),xs.end(),x2[i])-xs.begin();
	}
	vevev v;
	v.a=x1;v.b=x2;v.ab=xs;
	return v;
}
//
int main(){
	cin>>n;
	px.resize(n);
	py.resize(n);
	qx.resize(n);
	qy.resize(n);
	for(int i=0;i<n;i++){
		cin>>px[i]>>py[i]>>qx[i]>>qy[i];
	}
	vevev x=compress(px,qx);
	vevev y=compress(py,qy);
	px=x.a;qx=x.b;vector<int> X=x.ab;
	py=y.a;qy=y.b;vector<int> Y=y.ab;
	for(int i=0;i<n;i++){
		dp[px[i]][py[i]]++;
		dp[qx[i]][qy[i]]++;
		dp[px[i]][qy[i]]--;
		dp[qx[i]][py[i]]--;
	}
	for(int i=0;i<X.size()-1;i++){
		for(int j=1;j<Y.size()-1;j++){
			dp[i][j]+=dp[i][j-1];
		}
	}
	for(int i=0;i<Y.size()-1;i++){
		for(int j=1;j<X.size()-1;j++){
			dp[j][i]+=dp[j-1][i];
		}
	}
	long long ans=0;
	for(int i=0;i<X.size()-1;i++){
		for(int j=0;j<Y.size()-1;j++){
			if(dp[i][j]){
				ans+=(long long)(X[i+1]-X[i])*(Y[j+1]-Y[j]);
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256408
#include <stdio.h>

int main(void)
{
	int d, i, area;
	while(scanf("%d", &d) != EOF){
		area = 0;
		for(i = 0;i <= 600 - d;i += d){
			area += d * i * i;
		}
		printf("%d\n", area);
	}

	return 0;
}

Measured memory_bytes: 596
N, M, X, Y =map( int, input().split())
x = list(map( int, input().split()))
y = list(map( int, input().split()))
 
x = sorted(x)
y = sorted(y)
 
for i in range(X + 1, Y + 1):
  if( x[N-1] < i <= y[0]):
    print('No War')
    exit()
    
print('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 200005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int dif,N;
char cad[maxn];

struct dos
{
    int men,bal;
    bool operator < (const dos &h) const {
        return men>h.men;
    }
};
vector<dos> a,b;

bool cumpl(vector<dos> &v )
{
    sort(all(v));

    int sum=0;
    for(auto a:v){
        if(sum+a.men < 0 )
            return 0;
        sum+=a.bal;
    }
    return 1;
}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    for(int i=1;i<=N;i++){
        cin >> cad;
        int l = strlen(cad) , men=0,c=0;
        for(int j=0;j<l;j++){
            if(cad[j]=='(')
                c++ , dif++;
            else
                c-- , dif--;
            men = min(men,c);
        }
        if(c>=0)
            a.pb( {men,c} );
        else{
            men = c =0;
            for(int j=l-1;j>=0;j--){
                if(cad[j]==')')
                    c++;
                else
                    c--;
            men = min(men,c);
            }
            b.pb( {men,c} );
        }
    }
    if(dif){
        cout << "No\n";
        return 0;
    }

    if( cumpl(a) && cumpl(b)  )
        cout << "Yes\n";
    else
        cout << "No\n";

}


Measured memory_bytes: 11216
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

void Main(){
    int N;
    scanf("%d", &N);
    vector<long long> A(N);
    vector<long long> sum(N, 0);
    for(int i = 0; i < N; i++){
        scanf("%lld", &A[i]);
        if(i == 0)sum[i] = A[i];
        else sum[i] = sum[i - 1] + A[i];
    }
    
    long long ans = INF;
    for(int i = 0; i < N - 1; i++){
        long long snuke = sum[i];
        long long racc = sum[N - 1] - sum[i];
        if(ans > abs(snuke - racc)) ans = abs(snuke - racc);
    }
    
    printf("%lld\n", ans);
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
}


Measured memory_bytes: 3456
var lines = [];
var s = []; var p = [];
var N, M, ans = 0;

var readline = require('readline')
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});


rl.on('line', (x) => {
    lines.push(x)
});

rl.on('close', () => {
    N = Number(lines[0].split(" ")[0])
    M = Number(lines[0].split(" ")[1])

    for (var i = 0; i < M; i++) { s.push(lines[i + 1].split(" ").filter((v, i) => i > 0).map(i => Number(i))); }
    p = lines[M + 1].split(" ");

    dfs(0, []);
    console.log(ans)
});

function dfs(n, comb) {
    if (n === N) { calc(comb); return (0) }
    else {
        for (var i = 0; i < 2; i++) {
            comb[n] = i
            dfs(n + 1, comb)
        }
    }
}

function calc(comb) {
    var on = 0;
    for (var i = 0; i < s.length; i++) {
        var cnt = 0;

        for (var j = 0; j < s[i].length; j++) { if (comb[s[i][j] - 1] === 1) { cnt++; } }
        if (cnt % 2 === Number(p[i])) { on++ }
    }

    if (on === M) { ans++ }
    return (0)
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	vi a(n + 1), b(n);

	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];

	ll cnt = 0;

	rep(i, n) {
		if (b[i] < a[i]) {
			cnt += b[i];
		}
		else {
			cnt += a[i];
			cnt += min(b[i] - a[i], a[i + 1]);
			a[i + 1] = max(a[i + 1] - (b[i] - a[i]), 0);
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int n;
    long int x;
    scanf("%d",&n);
    scanf("%ld",&x);
    int a[n];
    int count=0,i;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    } 
    int q[n+1];
    q[1]=0;
    for(i=2;i<=n+1;i++)
    {
        q[i]=q[i-1]+a[i-1];
    }
    for(i=1;i<=n+1;i++)
    {
        if(q[i]<x || q[i]==x)
        {
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

bool is_able(double mid, const vector<double>& a, int k){
    int cnt = 0;
    rep(i, a.size()){
        if(a[i]<=mid) continue;
        cnt += (int)(a[i]/mid);
    }
    if(cnt>k) return false;
    else return true;
}

int main()
{
    int n, k; cin >> n >> k;
    vector<double> a(n);
    rep(i, n) cin >> a[i];

    double left=0.0, right=(double)INF;
    double mid = (left+right)/2;
    double ans = right;
    rep(i, 1000){
        bool t = is_able(mid, a, k);
        if(t){
            right = mid;
            chmin(ans, mid);
        }else{
            left = mid;
        }
        mid = (left + right)/2;
    }

    // pr((int)(3.0 / 2.0));
    pr((int)ceil(ans));
    return 0;}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<string> s(3);
	rep(i,3) cin >> s.at(i);
	vector<int> a(3);
	int k = 0;
	int win = 0;
	while(true){
		if(a.at(k) >= s[k].size()){
			win = k;
			break;
		}
		a.at(k)++;
		k = s[k][a.at(k) - 1] - 'a';
	}
	char ans = 'A' + win;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const int mod=1e9+7;
void solve()
{
  int n,k;
  cin>>n>>k;
  vector<int> V(n);
  for(int i=0;i<n;i++)
  cin>>V[i];
  ll sum=0;
  sort(V.begin(),V.end());
  for(int i=0;i<k;i++)
  sum+=V[i];
  cout<<sum<<endl;
}

int main()
{
  fastio
  solve();
}


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

using ll = long long;
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  bool no = false;
  rep(i, s.size()) {
    if (s[i] != t[i]) {
      no = true;
    }
  }
  if ((int)s.size() + 1 != (int)t.size()) {
    no = true;
  }
  if (!no) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC162_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            long ans = 0;
            for (int i = 1; i <= N; i++)
            {
                if (i % 3 == 0 || i % 5 == 0)
                {
                    continue;
                }
                ans += i;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17480
A,B,C = map(int, input().split())
n = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  if A == B == C:
    print ('-1')
    exit()
  else:
    a = B/2 + C/2
    b = A/2 + C/2
    c = A/2 + B/2
    A = a
    B = b
    C = c
    n += 1
  
  
print(n)

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
long long dp[100002],w[102],v[102];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	for(int i=0;i<n;i++){
		for(int j=m;j-w[i]>=0;j--){
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	long long ans=0;
	for(int i=0;i<=m;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int r, c, k;
int grid[3005][3005];
int dp[3005][3005][4]; //row col left
int32_t main() {

    fast
    cin >> r >> c >> k;
    int x, y, value;

    for(int i = 0; i < k; i++) {
        cin >> x >> y >> value;
        grid[x][y] = value;
    }
    for(int i = 1; i <= r; i++) {
        for(int j = 1; j <= c; j++) {
            for(int k=0;k<=3;k++){
                dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+grid[i][j]);
                dp[i][j][2]=max(dp[i][j][2],dp[i-1][j][k]+grid[i][j]);
                dp[i][j][3]=max(dp[i][j][3],dp[i-1][j][k]+grid[i][j]);

                if(k>0){
                    dp[i][j][k]=max({dp[i][j][k],dp[i][j-1][k-1]+grid[i][j],dp[i][j-1][k]});
                }
            }
        }
    }

    int ans=0;
    for(int i=0;i<4;i++)ans=max(ans,dp[r][c][i]);
    cout << ans<< endl;




    return 0;
}



Measured memory_bytes: 355664
S = input()
N = int(input())

cnt = 0
ans = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
        if i == len(S)-2:
            ans += (cnt + 1) // 2
    else:
        if cnt != 0:
            ans += (cnt + 1) // 2
        cnt = 0

if S[0] == S[len(S)-1]:
    fcnt = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            fcnt += 1
        else:
            break
    bcnt = 0
    for i in range(len(S)-1, 0, -1):
        if S[i] == S[i - 1]:
            bcnt += 1
        else:
            break
    if fcnt%2 == 0 and bcnt%2 == 0:
        if fcnt == len(S)-1:
            print((ans+ans+1)*N//2)
        else:
            print((ans+1)*N-1)
    else:
        print(ans*N)
else:
    print(ans*N)

Measured memory_bytes: 40464
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;


int main() {
	int n;
	vector<int> v(n + 1, 0);
	unordered_map<int, vector<int> > um;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		v[a]++;
		v[b]++;
		um[a].push_back(b);
		um[b].push_back(a);
	}
	vector<int> c;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		c.push_back(t);
	}
	sort(c.begin(), c.end());

	vector<int> single;
	for (int i = 1; i <= n; i++)
		if (v[i] == 1)
			single.push_back(i);

	int res = 0;
	int index = 0;
	vector<int> print (n + 1, 0);
	while (single.size() > 0) {
		vector<int> s;
		while (single.size() > 0) {
			int t = single[single.size() - 1];
			single.pop_back();
			print[t] = c[index++];
			res += print[t];
			for (auto num : um[t]) {
				v[num]--;
				if (v[num] == 1) {
					s.push_back(num);
				}
			}

		}
		single = s;
	}
	cout << res - *max_element(c.begin(), c.end()) << endl;
	for (int i = 1; i <= n; i++)
		if (i == 1)
			cout << print[i];
		else
			cout << " " << print[i];
	cout << endl;
}

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

using i8   = int8_t;
using u8   = uint8_t;
using i16  = int16_t;
using u16  = uint16_t;
using i32  = int32_t;
using u32  = uint32_t;
using i64  = int64_t;
using u64  = uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;

using f32  = float;
using f64  = double;
using f80  = __float80;
using f128 = __float128;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'000LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

// {{{ util
#define FOR(i, start, end) for(i64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cc) { return (f)(begin(cc), end(cc), ## __VA_ARGS__); })(c))

template<typename T, typename U>
bool chmax(T& xmax, const U& x) {
    if(xmax < x) {
        xmax = x;
        return true;
    }
    else {
        return false;
    }
}

template<typename T, typename U>
bool chmin(T& xmin, const U& x) {
    if(x < xmin) {
        xmin = x;
        return true;
    }
    else {
        return false;
    }
}

template<typename T>
void RD(T& x) {
    cin >> x;
#ifdef PROCON_LOCAL
    assert(cin);
#endif
}

template<typename T>
void RD(vector<T>& v, int n) {
    v.reserve(n);
    REP(_, n) {
        T e; RD(e);
        v.emplace_back(e);
    }
}

template<typename T>
void PRINT(const T& x) {
    cout << x;
}

template<typename T>
void PRINT(const vector<T>& v) {
    for(auto first = begin(v), it = first; it != end(v); ++it) {
        if(it != first)
            cout << ' ';
        cout << *it;
    }
}

template<typename T>
void PRINTLN(const T& x) {
    PRINT(x);
    cout << '\n';
}

template<typename T>
void DBG_IMPL(i64 line, const char* expr, const T& value) {
#ifdef PROCON_LOCAL
    cerr << "[LINE " << line << "]: ";
    cerr << expr << " = " << value << "\n";
#endif
}

#define DBG(expr) DBG_IMPL(__LINE__, #expr, (expr))
// }}}

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

i64 N;
i64 M;
vector<pair<i64,i64>> X;

void solve() {
    ALL(sort, X);

    i64 ans = 0;
    for(const auto& e : X) {
        if(M == 0) break;

        i64 k = min(M, e.second);
        ans += e.first * k;
        M -= k;
    }

    PRINTLN(ans);
}

signed main() {
    RD(N);
    RD(M);

    X.reserve(N);
    REP(_, N) {
        i64 a, b; RD(a); RD(b);
        X.emplace_back(a,b);
    }

    solve();

    return 0;
}


Measured memory_bytes: 1792
def check(points)
	product = points.cycle.each_cons(3).take(4).map do |p1, p2 ,p3|
		v1 = [p2[0] - p1[0], p2[1] - p1[1]]
		v2 = [p3[0] - p2[0], p3[1] - p2[1]]
		v1[0] * v2[1] - v1[1] * v2[0]
	end.inject(&:*)

	return 0 < product
end

$<.each_line do |line|
	puts check(line.split(',').map(&:to_r).each_slice(2)) ? 'YES' : 'NO'
end

Measured memory_bytes: 6148
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/****@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*****/
/**********************************************************/

#include <bits/stdc++.h>
using namespace std;
//              Typedefs
typedef long long               ll;
typedef unsigned long long      ull;

//              Templates
template<class T>               using min_heap = \
                                priority_queue<T, \
                                std::vector<T>, std::greater<T>>;

//              Basic-Defs
#define PB                      push_back
#define MP                      make_pair
#define SP                      " "
#define NL                      "\n"
#define all(v)                  v.begin(), v.end()

//              DEBUG--SECTION
#define DE                      cout<<"HERE\n";
#define DE1(x)                  cout<<x<<"###\n";
#define DE2(x,y)                cout<<x<<"####"<<y<<"\n";
#define Pause                   system("pause");

//              Functions
#define clr(arr,value)          memset(arr,value,sizeof(arr))
#define __FAST_IO               ios_base::sync_with_stdio(0);\
                                cin.tie(0);cout.tie(0);
#define NUM1(x)                 __builtin_popcount(x)
#define LCM(x,y)                (x*y)/__gcd(x,y)

//              Sizes--Math     0123456789
#define MOD                     1000000007   //1e9+7 
#define MAX                     100050      
#define INF                     1e18
#define PI                      acos(-1)
#define eps                     1e-6

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    
    ll i,j,k,n,m,T; //basic variables

    cin>>n>>k;

    ll arr[n+5];
    clr(arr,0);

    for(i=0;i<k;i++){
    	ll d;
    	cin>>d;
    	for(j=1;j<=d;j++){
    		ll x;
    		cin>>x;
    		arr[x] = 1;
    	}
    }
    ll coun = 0;
    for(i=1;i<=n;i++){
    	if(arr[i]!=1) coun++;
    }

    cout<<coun<<NL;


    /// Don't forget to set array size....
    return 0;
}




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

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

  if ((N/10) % 111 == 0 || (N%1000) % 111 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    char ch=getchar();
    int f=1;
    for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
    if (ch=='-') f=-1,ch=getchar();
    for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
    x*=f;
}
int n,m,u,v;
int sg[100010];
int main()
{
	read(n),read(m);
	for (int i=1;i<=m;i++)
	{
		read(u),read(v);
		sg[u]^=1,sg[v]^=1;
	}
	for (int i=1;i<=n;i++)
		if (sg[i])
		{
			puts("NO");
			return 0;
		}
	puts("YES");
	return 0;
 } 

Measured memory_bytes: 640
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int n,m,q,a[N],b[N],c[N],col[N][12];
vector<int> g[N];
void dfs(int x,int dep,int id){
	if(dep<0||col[x][dep]) return ;
	col[x][dep]=max(col[x][dep],id);
	for(int to:g[x]) dfs(to,dep-1,id);
}
signed main(){
	cin>>n>>m;
	for(int i=1,a,b;i<=m;i++) scanf("%d %d",&a,&b),g[a].push_back(b),g[b].push_back(a);
	cin>>q;
	for(int i=1;i<=q;i++) scanf("%d %d %d",&a[i],&b[i],&c[i]);
	for(int i=q;i>=1;i--) dfs(a[i],b[i],i);
	for(int i=1;i<=n;i++){
		int ans=0;
		for(int j=0;j<=10;j++)	ans=max(ans,col[i][j]);
		printf("%d\n",c[ans]);
	}
	return 0;
}


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

using namespace std;

void A_160()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

int main()
{
  A_160();
}

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

using P = pair<int, int>;
int H, W;
vector<vector<char>> maze;  // 迷路の内容を保存する配列
vector<vector<int>> dist;   // 距離を記録しておく配列
P s, g;

// 幅優先探索
void bfs(P s) {
    const int INF = 1e8;
    dist.assign(H, vector<int>(W, INF));  // 初期化

    queue<pair<int, int>> que;
    que.emplace(s);
    if (maze[s.first][s.second] == '#') {
        dist[s.first][s.second] = 1;
    } else {
        dist[s.first][s.second] = 0;
    }
    while (que.size() != 0) {
        pair<int, int> now = que.front();
        que.pop();
        int dy[4] = {0, 1};  // dx,dy は次の探索場所への距離を表す（４方向分）
        int dx[4] = {1, 0};
        for (int i = 0; i < 2; i++) {
            int ny = now.first + dy[i];
            int nx = now.second + dx[i];
            if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
            if (maze[now.first][now.second] != maze[ny][nx] && maze[ny][nx] == '#') {  //色が違うかつ黒
                if (dist[ny][nx] > dist[now.first][now.second] + 1) {
                    que.push(make_pair(ny, nx));
                    dist[ny][nx] = dist[now.first][now.second] + 1;
                }
            } else {  // 変わる
                if (dist[ny][nx] > dist[now.first][now.second]) {
                    que.push(make_pair(ny, nx));
                    dist[ny][nx] = dist[now.first][now.second];
                }
            }
        }
    }
}

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

    cin >> H >> W;
    s = make_pair(0, 0);
    g = make_pair(H - 1, W - 1);

    maze.assign(H, vector<char>(W, '.'));  // 初期化
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cin >> maze[i][j];
    }

    bfs(s);
    cout << dist[g.first][g.second] << endl;

    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += max(0, bisect_left(L, L[i]+L[j]) - j - 1)
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using pll = pair<ll,ll>;
const ll INF64 = 1LL << 60;
const int INF = (1 << 29);

int main(){
    int n; cin >> n;
    map<ll,int> mp;
    rep(i,n){
        ll a; cin >> a;
        auto iti = mp.find(a);
        if(iti == mp.end()) mp[a] = 1;
        else{
            if(mp[a]==1) mp[a] = 0;
            else mp[a] = 1;
        }
    }

    int ans = 0;
    for(auto x: mp){
        ans += x.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9708
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
#define FIND(v,i) find(v.begin(),v.end(),i);

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int a,b,c;
    cin >> a >> b >> c;
    bool bb=0;
    REP(i,1000000){
        if(a*(i+1)%b==c){
            bb=1;
            break;
        }
    }
    cout << (bb ? "YES" : "NO");
/////////////////////////////////////////////
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::{HashMap, HashSet, VecDeque};

//{{{
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//}}}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let mut cnt = 0;
    for i in 1..n + 1 {
        if i % 2 == 1 {
            cnt += 1;
        }
    }
    if cnt >= k {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int main()
{
    fastio;
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    int p[a],q[b],r[c];
    for(int i=0;i<a;i++)cin>>p[i];
    for(int i=0;i<b;i++)cin>>q[i];
    for(int i=0;i<c;i++)cin>>r[i];
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    reverse(p,p+a);
    reverse(q,q+b);
    reverse(r,r+c);
    vector<int>xx;
    for(int i=0;i<x;i++)
        xx.pb(p[i]);
    for(int i=0;i<y;i++)
        xx.pb(q[i]);
    sort(all(xx));
    reverse(all(xx));
    stack<int>re,ma;
    for(int i=c-1;i>=0;i--)
        re.push(r[i]);
    for(int i : xx)
        ma.push(i);
    ll ans = 0;
    while(100)
    {
        if(re.empty() || ma.empty())
            break;
        if(ma.top()<re.top())
        {
            ma.pop();
            ans+=re.top();
            re.pop();
        }
        else break;
    }
    while(!ma.empty())
    {
        ans+=ma.top();
        ma.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
using namespace std;

int w,ai,bi,af,bf;

int main()
{
	IO
	cin>>w>>ai>>bi;
	af = ai+w;
	bf = bi+w;
	
	if(af <= bi){
		cout<<bi-af<<endl;
		return 0;
	}
	if(bf <= ai){
		cout<<ai-bf<<endl;
		return 0;
	} 
	cout<<"0"<<endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> ret(N);
    for(int i = 1 ; i <= N ; ++i){
        for(int j = i+1; j <= N; ++j){
            int d = min({j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)});
            ret[d] += 1;
        }
    }
    for(int i = 1 ; i < N ; ++i){
        cout << ret[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [sorted(input()) for i in range(N)]

from collections import Counter

common = Counter(S[0])
for i in range(1, N):
    c = Counter(S[i])
    dels = []
    for char, count in common.items():
        if char in c:
            if c[char] < count:
                common[char] = c[char]
        else:
            dels.append(char)
    for d in dels:
        del common[d]

ans = []
for k, v in common.items():
    ans.append(k * v)
print(''.join(sorted(ans)))



Measured memory_bytes: 39024