akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
using namespace std;
#define N 1000000
typedef pair<int,int>P;
bool isprime[N+1];
int cave [1000][1000];
int xindex[N+1];
int yindex[N+1];
P dp[1000][1000];

int m,n;

P find(int cx,int cy){
	P ans;
	if(isprime[n])
		dp[cx][cy].first=1,dp[cx][cy].second=cave[cx][cy];
	else
		dp[cx][cy].first=0,dp[cx][cy].second=0;
	ans=dp[cx][cy];
	for(int y=cy+1;y<1000;y++){
		for(int x=0;x<1000;x++){
			if(cave[x][y]<=m){
				bool isP=isprime[cave[x][y]];
				bool pass=false;
				if(x&&cave[x-1][y-1]<=m&&dp[x-1][y-1].first!=-1){
					if(dp[x][y].first<dp[x-1][y-1].first||(dp[x][y].first==dp[x-1][y-1].first&&dp[x][y].second<dp[x-1][y-1].second)){
						dp[x][y]=dp[x-1][y-1];
						pass=true;
					}
				}
				
				if(cave[x][y-1]<=m&& dp[x][y-1].first!=-1){
					if(dp[x][y].first<dp[x][y-1].first||(dp[x][y].first==dp[x][y-1].first&&dp[x][y].second<dp[x][y-1].second)){
						dp[x][y]=dp[x][y-1];
						pass=true;
					}
				}
				
				if(x<999&&cave[x+1][y-1]<=m&&dp[x+1][y-1].first!=-1){
					if(dp[x][y].first<dp[x+1][y-1].first||(dp[x][y].first==dp[x+1][y-1].first&&dp[x][y].second<dp[x+1][y-1].second)){
						dp[x][y]=dp[x+1][y-1];
						pass=true;
					}
				}
				
				if(isP&&pass)
					dp[x][y].first++,dp[x][y].second=cave[x][y];
					
				if(ans.first<dp[x][y].first||(ans.first==dp[x][y].first&&ans.second<dp[x][y].second))
					ans=dp[x][y];
				//cout << ans.first <<" " << ans.second << endl;
			}
		}
	}
	return ans;
}

int main(void){
	// prime generator
	for(int i=0;i<=N;i++)
		isprime[i]=true;
	isprime[0]=isprime[1]=false;
	for(int i=2;i<=N;i++)
		if(isprime[i])
			for(int j=2*i;j<=N;j+=i)
				isprime[j]=false;
	// cave generator
	int x=499,y=500,tmp=1;
	cave[x][y]=1;
	xindex[1]=x;
	yindex[1]=y;
	for(int i=1;i<=N;){
		for(int j=0;j<tmp;j++){
			if(i>N)
				break;
			x++;
			i++;
			cave[x][y]=i;
			xindex[i]=x;
			yindex[i]=y;
		}
		for(int j=0;j<tmp;j++){
			if(i>N)
				break;
			y--;
			i++;
			cave[x][y]=i;
			xindex[i]=x;
			yindex[i]=y;
		}
		tmp++;
		for(int j=0;j<tmp;j++){
			if(i>N)
				break;
			x--;
			i++;
			cave[x][y]=i;
			xindex[i]=x;
			yindex[i]=y;
		}
		for(int j=0;j<tmp;j++){
			if(i>N)
				break;
			y++;
			i++;
			cave[x][y]=i;
			xindex[i]=x;
			yindex[i]=y;
		}
		tmp++;
	}
	while(cin >> m >> n ,m|n){
		for(int i=0;i<1000;i++)
			for(int j=0;j<1000;j++)
				dp[i][j].first=dp[i][j].second=-1;
		P ans=find(xindex[n],yindex[n]);
		if(ans.first==0)
			ans.second=0;
		cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 21672
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n=s.length();
    vector<vector<long> >dp(n,vector<long>(13,0));
    if(s[0]=='?'){
        for(int i=0;i<=9;i++)dp[0][i] = 1;
    }else{
        dp[0][(int)(s[0]-'0')]=1;
    }
    long const MOD = 1e9+7;
    for(int i=1;i<n;i++){
        int num = (int)(s[i]-'0');
        for(int j=0;j<13;j++){
            if(s[i]=='?'){
                for(int k=0;k<=9;k++){
                    dp[i][(10*j+k)%13] += dp[i-1][j];
                    dp[i][(10*j+k)%13] %= MOD;
                }
            }else{
                dp[i][(10*j+num)%13] += dp[i-1][j];
                dp[i][(10*j+num)%13] %= MOD;
            }
        }
    }
    cout << dp[n-1][5] << endl;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(ll x){
	if (x<0){
		putchar('-'),write(-x);
		return;
	}
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,a[3003];
bool vis[3003][3003];
ll dp[3003][3003];
ll dfs(int l,int r,bool u){
	if (l==r){
		if (u) return a[l];
		return -a[l];
	}
	if (vis[l][r]) return dp[l][r];
	vis[l][r]=1;
	if (u) dp[l][r]=max(dfs(l+1,r,0)+a[l],dfs(l,r-1,0)+a[r]);
	else dp[l][r]=min(dfs(l+1,r,1)-a[l],dfs(l,r-1,1)-a[r]);
	return dp[l][r];
}
int main(){
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	write(dfs(1,n,1));
}

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}

void solve()
{
   string s;
   cin>>s;
   int n;
   n = s.length();
   if( s[n-1]=='s')
   {
       s +="es";
   }
   else
   {
       s +='s';
   }
   cout<<s<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3668
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		if(x == 1)
			System.out.println(0);
		else if(x == 0)
			System.out.println(1);
	}
}

Measured memory_bytes: 35684
#include<bits/stdc++.h>
 
#define pb push_back
#define MP make_pair
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
using namespace std;
 
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;
ll mod = 1e9 + 7  ;
int arr[21][2097152] ; 
int val[22][22] ;
int n ;
int rec(int i,int mask){
  //cout<<i<<" "<<mask<<endl ; 
  if(i==n) return 1  ;
 // cout<<"yeah"<<endl ; 
  if(arr[i][mask] != -1 )  return arr[i][mask] ; 
   //cout<<"yeah"<<endl ; 
 
  ll tot  = 0  ; 

  rep(j,0,n){
      int t = (mask & (1<<j)); 
     
      if( (val[i][j]==1) && t ){
        
          tot =  (tot +rec(i+1 , mask^(1<<j)))%mod  ;
      }
  }
  arr[i][mask] = tot ; 
  return tot ; 
}

int main(){
 
     
    cin>>n ; 
    rep(i,0,n) rep(j,0,n) cin>>val[i][j] ; 
    
    int ed = (1<<n)-1 ;
   // cout<<ed<<endl ;
    rep(i,0,ed+1){
        rep(j,0,21) arr[j][i] = -1 ; 
    }


    cout<<rec(0,ed)<<endl ;

 return 0 ; 

}





Measured memory_bytes: 172288
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in xrange(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1

n = int(raw_input())
A = map(int, raw_input().split())
q = partition(A, 0, n-1)
s = ""
for i, x in enumerate(A):
    if i == q:
        s += "[" + str(x) + "]"
    else:
        s += str(x)
    s += " "
print s[:len(s)-1]

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int K, T; cin >> K >> T;
  int ma = 0;
  rep(i, T) { int t; cin >> t; amax(ma, t); }
  cout << max(0, ma - 1 - (K - ma)) << '\n';
}


Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val n = readLine.split(" ").map(_.toInt)
    val d = new Array[Int](n(0))
    val g = new Array[ArrayBuffer[Int]](n(0))

    for(i<-0 until n(0)) g(i) = new ArrayBuffer[Int]
    for(i<-0 until n(1)) {
      val v = readLine.split(" ").map(_.toInt)
      g(v(0)) += v(1)
      g(v(1)) += v(0)
    }

    def scan(i:Int, connected:Int):Unit = {
      if(d(i)==0) d(i) = connected

      if(g(i).length > 0) {
        for(j<-0 until g(i).length) {
          if(d(g(i)(j))==0) {
            scan(g(i)(j), connected)
          }
        }
      }
    }

    var connected = 1
    for(i<-0 until n(0)) {
      if(d(i)==0) {
        scan(i, connected)
        connected += 1
      }
    }

    val q = readInt
    for(i<-0 until q) {
      val s = readLine.split(" ").map(_.toInt)
      if(d(s(0)) == d(s(1))) println("yes")
      else println("no")
    }
  }
}

Measured memory_bytes: 152016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N;
vector<vector<Pi>> G;
vector<int> es[50][50];

bool dfs(int s, int t, int u, int p){
    if(u == t) return true;

    for(auto v : G[u]){
        if(v.first == p) continue;
        if(dfs(s,t,v.first,u)){
            es[s][t].push_back(v.second);
            return true;
        }
    }
    return false;
}

int main(){
    cin >> N;
    G.resize(N);
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b,i);
        G[b].emplace_back(a,i);
    }

    int M; cin >> M;
    vector<Pi> uv(M);
    rep(i,M){
        cin >> uv[i].first >> uv[i].second;
        uv[i].first--; uv[i].second--;
        dfs(uv[i].first,uv[i].second,uv[i].first,-1);
    }
    ll ans = 0;
    //rep(i,es[0][2].size()) cout << es[0][2][i] << " ";
    //cout << endl;
    repr(i,1,1<<M){
        int cnt = __builtin_popcount(i);
        vector<bool> ok(N-1,false);
        rep(j,M){
            if(i>>j&1){
                int k = es[uv[j].first][uv[j].second].size();
                rep(l,k){
                    ok[es[uv[j].first][uv[j].second][l]] = true;
                }
            }
        }
        int cnt2 = 0;
        rep(j,N-1) if(ok[j]) cnt2++;
        //cout << st.size() << endl;
        if(cnt % 2 == 1) ans += 1LL<<(N-1-cnt2);
        else ans -= 1LL<<(N-1-cnt2);
    }
    cout << (1LL<<(N-1))-ans << endl;

}


Measured memory_bytes: 256
N = input()
N0 = int(N[0])
N1 = int(N[1])
N2 = int(N[2])

if N0 == 7:
    print("Yes")
elif N1 == 7:
    print("Yes")
elif N2 == 7:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>
#include <set>

//#define int long long
//typedef long long ll;
using ll = long long;
//using R = double;

//#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define MOD 1000000007

const int INF = int(1e9);

using namespace std;

typedef vector<int> V;
typedef vector<V> VV;

//const int DAT_SIZE = (1 << 18) - 1;
const int MAX_SIZE = 1 << 17;
//const int MAX_SIZE = 3;



signed main()
{
    int x;
    
    cin >> x;
    if (x < 1200) {
    	cout << "ABC" << endl;
    } else {
    	cout << "ARC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=(0);i<(n);i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 1e5+1;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if(!e)return 1;
    if(e&1) return qpow(b,e-1)*b;
    int pwur=qpow(b,e>>1);
    return pwur*pwur;
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n;
    cin>>n;
    vector<string>s(n);
    rep(i,n)cin>>s[i];
    map<char,int>mp;
    rep(i,n)mp[s[i][0]]++;
    string march="MARCH";
    int ans=0;
    rep(i,5)rep2(j,i+1,5)rep2(k,j+1,5){
        ans+=mp[march[i]]*mp[march[j]]*mp[march[k]];
    }
    cout<<ans<<enl;

    return 0;
}


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

using namespace std;

int main()
{

    string s;
    cin >> s;
    if(s[0] >= 'a' && s[0] <= 'z')
    {
        cout << "a";
    }else
    {
        cout << "A";
    }


    return 0;

}


Measured memory_bytes: 3620
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, Q = getlist()
	c = getlist()
	LR = []
	lastappeared = [None] * N

	ans = [0] * Q
	for i in range(Q):
		l, r = getlist()
		l -= 1; r -= 1
		LR.append([r, l, i])

	LR.sort(key = lambda x:x[0])
	Seg = SegmentTree(N)
	right = 0
	for r, l, i in LR:
		while right <= r:
			itr = c[right] - 1
			if lastappeared[itr] == None:
				Seg.update(right, 1)
			else:
				Seg.update(lastappeared[itr], 0)
				Seg.update(right, 1)
			lastappeared[itr] = right
			right += 1

		if l == 0:
			anspre = Seg.query(0, r)
		else:
			anspre = Seg.query(l, r)
		ans[i] = anspre

	for i in range(Q):
		print(ans[i])



if __name__ == '__main__':
	main()

Measured memory_bytes: 180408
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);


    string o,e; cin >> o >> e;
    REP(i,o.size()+e.size()){
    if(i & 1) cout << e[i/2];
    else cout << o[i/2];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, m;
   cin >> n >> m;
   cout << (n == m ? "Yes" : "No") << endl;
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a, b, c, count;
    count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (int i = a; i <= b; i++){
        if (c % i == 0){
            count += 1;
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vin a(n);
  rep(i,0,n)cin>>a[i];
  int ans=0;
  rep(i,0,n){
   if(i%2==0 && a[i]%2==1)ans++; 
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
_, K = map(int, input().split())
S = input()

runlengths = []  # 両脇を逆立ちの数字の連続数にする
if S[0] == "0":
    runlengths.append(0)

pre_s = S[0]
cnt = 1
for s in S[1:]:
    if pre_s != s:
        runlengths.append(cnt)
        pre_s = s
        cnt = 1
    else:
        cnt += 1

runlengths.append(cnt)
if S[-1] == "0":
    runlengths.append(0)

if len(runlengths) < K * 2 + 1:
    runlengths.extend([0]*((K*2+1)-len(runlengths)))

# print(runlengths)


con = sum(runlengths[0:K*2+1])
max_con = con
for e_new in range(K*2+2, len(runlengths), 2):
    s_old = e_new - (K*2+2)
    con = con - runlengths[s_old] - runlengths[s_old+1] +\
        runlengths[e_new-1] + runlengths[e_new]
    max_con = max(max_con, con)

print(max_con)


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

using namespace std;

#define int long long

constexpr int INF = 1LL << 60;
constexpr double EPS = 1.0e-11;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

constexpr int MAX_N = 5 * 100005;

string s;
int a[MAX_N];
char dc[] = {'<', '>'};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(16);
    cout << fixed;

    cin >> s;

    int cur = 0, j = 1;
    for (char c : s)
    {
        if (c == '<') cur++;
        else cur = 0;
        a[j] = max(a[j], cur);
        j++;
    }
    std::reverse(s.begin(), s.end());
    cur = 0;
    j = 1;
    for (char c : s)
    {
        if (c == '>') cur++;
        else cur = 0;
        a[s.size() - j] = max(a[s.size() - j], cur);
        j++;
    }

    int ans = 0;
    for (int i = 0; i <= s.size(); i++) ans += a[i];

    cout << ans << endl;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
int f(int a[26],int b[26]){
  int ret=0;
  rep(i,26) if(a[i]!=0 and b[i]!=0) ret++;
  return ret;
}
int main(){
  int n;
  string s;
  cin>>n>>s;
  int h[26]={},t[26]={};
  rep(i,s.size()) t[(int)s[i]-'a']++;
  int ans=0;
  rep(i,s.size()){
    t[(int)s[i]-'a']--;
    h[(int)s[i]-'a']++;
    ans=max(ans,f(h,t));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
vector<int> adj[MAXN];
char col[MAXN];

bool alive[MAXN];
int deg[MAXN];
int q[MAXN],qhead,qtail;

bool gain[MAXN];

pair<ll,ll> dfspath(int at,int par) { // returns (longest path starting here,longest path in subtree)
	ll mxsofar=gain[at]?n:0;
	pair<ll,ll> ret=MP(mxsofar,mxsofar);
	REPSZ(i,adj[at]) {
		int to=adj[at][i]; if(to==par||!alive[to]) continue;
		pair<ll,ll> cur=dfspath(to,at);
		ll curpath=cur.first+1+(gain[at]?n:0);
		ret.first=max(ret.first,curpath);
		ret.second=max(ret.second,cur.second);
		ret.second=max(ret.second,mxsofar+cur.first+1);
		mxsofar=max(mxsofar,curpath);
	}
	return ret;
}

int solve() {
	bool anywhite=false; REP(i,n) if(col[i]=='W') anywhite=true; if(!anywhite) return 0;

	REP(i,n) alive[i]=true,deg[i]=SZ(adj[i]); qhead=qtail=0;
	REP(i,n) if(deg[i]==1&&col[i]=='B') alive[i]=false,q[qhead++]=i;
	while(qtail<qhead) {
		int at=q[qtail++];
		REPSZ(i,adj[at]) {
			int to=adj[at][i]; if(!alive[to]) continue;
			if(--deg[to]<=1&&col[to]=='B') alive[to]=false,q[qhead++]=to;
		}
	}
	REP(i,n) if(alive[i]&&deg[i]<=1) assert(col[i]=='W');
	REP(i,n) gain[i]=alive[i]&&(col[i]=='B'&&deg[i]%2==1||col[i]=='W'&&deg[i]%2==0);
	int numalive=0; REP(i,n) if(alive[i]) ++numalive; if(numalive==1) return 1;
	//printf("alive:"); REP(i,n) if(alive[i]) printf(" %d",i+1); puts("");
	//printf("gain:"); REP(i,n) if(gain[i]) printf(" %d",i+1); puts("");

	int root=-1; REP(i,n) if(alive[i]) { root=i; break; } assert(root!=-1);
	pair<ll,ll> longpath=dfspath(root,-1);
	int longedges=longpath.second%n,longgain=longpath.second/n;
	int degsum=0; REP(i,n) if(alive[i]) degsum+=deg[i];
	int gaincnt=0; REP(i,n) if(gain[i]) ++gaincnt;
	//printf("degsum=%d gaincnt=%d longedges=%d longgain=%d\n",degsum,gaincnt,longedges,longgain);
	return degsum+gaincnt-longedges-longgain+(longedges-1-longgain)+1;
}

void run() {
	scanf("%d",&n); REP(i,n-1) { int a,b; scanf("%d%d",&a,&b); --a,--b; adj[a].PB(b); adj[b].PB(a); } REP(i,n) scanf(" %c",&col[i]);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 13312
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int MAX_N = 100005;
int N, L[MAX_N], R[MAX_N];

ll f(int p) {
    multiset<pii> LR, RL;
    rep(i, N) {
        LR.insert({ L[i],R[i] });
        RL.insert({ R[i],L[i] });
    }

    int x = 0;
    ll sm = 0;
    while (sz(LR)) {
        int l, r;
        if (p) {
            tie(l, r) = *LR.rbegin();
            if (l > x) {
                sm += l - x;
                x = l;
            } else {
                break;
            }
        } else {
            tie(r, l) = *RL.begin();
            if (r < x) {
                sm += x - r;
                x = r;
            } else {
                break;
            }
        }
        LR.erase(LR.find({ l,r }));
        RL.erase(RL.find({ r,l }));
        p = 1 - p;
    }

    sm += abs(x);
    RT sm;
}

void solve() {
    cin >> N;
    rep(i, N) {
        cin >> L[i] >> R[i];
    }

    ll re = max(f(0), f(1));
    cout << re << endl;
}

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

Measured memory_bytes: 10368
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{

	int A,B,C;
	cin>>A>>B>>C;
	if (A==B){
		cout<<C<<endl;
	}else if (A==C){
		cout<<B<<endl;
	}else{
		cout<<A<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
<?php

while ( ! feof(STDIN) ) {
  $row = trim(fgets(STDIN));
  list($a,$b) = explode(' ', $row);
  if ($a == 0 && $b == 0)exit;
  echo $a < $b ? $a." ".$b : $b." ".$a;
  echo PHP_EOL;
}

Measured memory_bytes: 15108
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<string, int> si;
typedef vector<string> vs;
const int INF = 1 << 29;
#define mp make_pair
#define fi first
#define se second
int n, k, digit;
set<int> d;

bool isFound(int num) {
    while (num != 0) {
        int last = num % 10;
        if (d.find(last) != d.end()) return false;
        num /= 10;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> digit;
        d.insert(digit);
    }
    int i;
    for (i = n; !isFound(i); i++);
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long h,u,dp[1009][1009];
char a[1009][1009];
int main() {
    cin >> h>>u;
    for(int i=1;i<=h;i++)
    	for(int j=1;j<=u;j++)
    		cin>>a[i][j];
    for(int i=1;i<=h;i++)
    	for(int j=1;j<=u;j++)
    		if(i==1 && j==1)
    		    dp[1][1]=1;
    		else if(a[i][j]=='.')
    				dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%(long long)(pow(10,9)+7);
    cout<<dp[h][u];
}

Measured memory_bytes: 9088
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int H, W, K;

    cin >> H >> W >> K;

    vector<vector<char> > c(H, vector<char>(W));

    rep(i,H) {
        rep(j,W) {
            cin >> c[i][j];
        }
    }

    int powh = pow(2,H);
    int poww = pow(2,W);

    int ans = 0;

    rep(i,powh) {
        rep(j, poww) {
            int black = 0;
            int row = i;
            rep(k, H) {
                if(row%2==0) {
                    int col = j;
                    rep(l,W) {
                        if(col%2==0) {
                            black += (c[k][l] == '#');
                        }
                        col/=2;
                    }
                }
                row /= 2;
            }
            ans += (black == K);
        }
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)

int main() {
    ll N, X, T;
    cin >> N >> X >> T;

    if(N % X == 0) {
        cout << (N / X) * T << endl;
    } else {
        cout << (N / X + 1) * T << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	vl vec(n);
	rep(i,0,n) cin>>vec[i];
	vl p=vec;
	sort(all(vec));
	ll k=vec[n/2-1];
	ll l=vec[n/2];
	//cout<<k<<" "<<l<<" ";
	vl ans(n);
	rep(i,1,n+1){
		if(p[i-1]<=k) ans[i-1]=l;
		else ans[i-1]=k;
	}
	rep(i,0,n) cout<<ans[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 6912
# ord("A") → 65
# ord("C") → 67
# ord("Z") → 90
# ord("a") → 97

S=list(input())
S_int=list(map(lambda x:ord(x),S))

flg=False

if S[0]=="A":
    if S[2:-1].count("C")==1:
        remove_omoji=[x for x in S_int if x>96]
        if len(S_int)-2==len(remove_omoji): flg=True

print("AC" if flg else "WA")

Measured memory_bytes: 3064
//....SARANSH GUPTA....\\

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007
int main()
{
    FIO
    ll t;
    cin>>t;
    cout<<t+t*t+t*t*t;
}

Measured memory_bytes: 3612
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
    long[,] vertexes = new long[n,2];//ここに受け取る
    long answer = 0;
    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      vertexes[i,0] = nums[0];
      vertexes[i,1] = nums[1];
    }

    for(int i = n-1; i >= 0; i--)
    {
      if((vertexes[i,0]+answer) % vertexes[i,1] != 0)
        answer += vertexes[i,1] - ((vertexes[i,0]+answer) % vertexes[i,1]);
    }
    
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 17300
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  string s;
  cin>>s;
  bool ans=true;
  for(int i=sz(s)-1;i>=0;i--){
    if(i-4>=0){
      if(s[i]=='m'&&s[i-1]=='a'&&s[i-2]=='e'&&s[i-3]=='r'&&s[i-4]=='d'){
        i-=4;
        continue;
      }
      else if(s[i]=='e'&&s[i-1]=='s'&&s[i-2]=='a'&&s[i-3]=='r'&&s[i-4]=='e'){
        i-=4;
        continue;
      }
    }
    if(i-6>=0){
      if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='m'&&s[i-3]=='a'&&s[i-4]=='e'&&s[i-5]=='r'&&s[i-6]=='d'){
        i-=6;
        continue;
      }
    }
    if(i-5>=0){
      if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='s'&&s[i-3]=='a'&&s[i-4]=='r'&&s[i-5]=='e'){
        i-=5;
        continue;
      }
    }
    ans=false;
    break;
  }
  YES(ans);
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <list>
#include <utility>
using namespace std;

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

	vector<list<long> > a(n);

	for (int i = 0; i < q; i++) {
		int u, s, t;
		cin >> u;
		
		if (u == 0) {
			long x;
			cin >> t >> x;
			a[t].push_back(x);
		}
		else if (u == 1) {
			cin >> t;
			list<long>::iterator itr = a[t].begin();
			while (itr != a[t].end()) {
				if (itr != a[t].begin())
					cout << " ";
				cout << *itr;
				itr++;
			}
			cout << endl;
		}
		else if (u == 2) {
			cin >> s >> t;
			a[t].splice(a[t].end(), std::move(a[s]));
		}
	}

	return 0;
}


Measured memory_bytes: 18624
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
  let x:usize = read();
  let mut sum = 0;
  for i in 1..=x {
    sum += i;
    if sum >= x {
      println!("{}", i);
      return
    }
  }
  println!("{}", x);
}

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

int main(){
    int A,B;
    cin >> A >> B;

    if (A >= 13){
        cout << B << endl;
    }

    else if ((A<13) && (A>=6)){
        cout << (B/2) << endl;
    }

    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,D;
  cin >> N >> D;
  
  int count = 0;
  vector<long long>X(N);
  vector<long long>Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i) >> Y.at(i);
    long long B = X.at(i)*X.at(i);
    long long C = Y.at(i)*Y.at(i);
    long long A = ceil(sqrt(B + C));
    if (A <= D){
      count++;
    }
  }
  cout << count << endl;
}
  

Measured memory_bytes: 6412
#include <iostream>
#include <map>
#include <vector>

using namespace std;

void failure () {
  cout << "No" << endl;
  exit(0);
}

typedef long long ll;

const ll INF = 1e12 + 5;
const int MAX_N = 2e5 + 5;
const int COLS = 1e5;

int row (int idx) {
  return idx;
}

int col (int idx) {
  return idx + COLS;
}

int vis [MAX_N];
ll val [MAX_N];
vector<pair<int, ll>> adj [MAX_N];

void dfs (int u, ll &rm, ll &cm) {
  vis[u] = 1;
  if (u < COLS) rm = min(rm, val[u]);
  else cm = min(cm, val[u]);
  
  for (auto nxt : adj[u]) {
    if (!vis[nxt.first]) {
      val[nxt.first] = nxt.second - val[u];
      dfs(nxt.first, rm, cm);
    } else if (val[nxt.first] != nxt.second - val[u]) {
      failure();
    }
  }
}

int main () {
  ios::sync_with_stdio(false);
  
  int R, C;
  cin >> R >> C;

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int r, c, a;
    cin >> r >> c >> a;

    adj[row(r)].push_back({col(c), a});
    adj[col(c)].push_back({row(r), a});
  }

  for (int i = 1; i <= R; i++) {
    if (!vis[row(i)]) {
      ll rm = INF, cm = INF;
      dfs(row(i), rm, cm);
      if (rm + cm < 0) failure();
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 23712
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
typedef tuple<ll,int,int> T;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int>  q(n);
    for(int i=0;i<n;i++)q[a[i]-1]=i;
    int cnt=1;
    int ans=1;
    for(int i=0;i<n-1;i++){
             if(q[i]<q[i+1])cnt++;
             else cnt=1;
             ans=max(cnt,ans);
    }
    cout<<n-ans<<endl;
}


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

//答えが合わない場合はlong long型を疑うこと！

int main(){
    long long n,ans=0,cost=0;
    cin >> n;
    vector<long long> a(n+2,0);
    for(int i=1;i<n+1;++i){
        cin >> a.at(i);
    }
    rep(i,n+1){
        cost+=abs(a.at(i+1)-a.at(i));
    }
    rep(i,n){
            ans=cost+abs(a.at(i+2)-a.at(i))-abs(a.at(i+1)-a.at(i))-abs(a.at(i+2)-a.at(i+1));
        cout << ans << endl;
    }
}

Measured memory_bytes: 2048
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

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

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

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "tmp.cpp"

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

  int n, k;
  cin >> n >> k;
  vi a(n);
  REP(i, n) { cin >> a[i]; }
  REP(j, k) {
    vi imos(n + 2, 0);
    REP(i, n) {
      imos[max(0, i + 1 - a[i])]++;
      imos[min(n + 1, i + 1 + a[i] + 1)]--;
    }
    FOR(i, 1, n + 1) { imos[i] += imos[i - 1]; }

    bool fin = true;
    REP(i, n) {
      if (imos[i + 1] != n)
        fin = false;
      a[i] = imos[i + 1];
    }
    if (fin)
      break;
  }

  REP(i, n) { cout << a[i] << (i == n - 1 ? "\n" : " "); }
  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> A, B, C;

	cin >> N;
	A.resize(N);
	B.resize(N+1);
	C.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	for (int i = 1; i <= N; ++i)
		cin >> B[i];
	for (int i = 1; i <= N-1; ++i)
		cin >> C[i];

	llong ans = B[A[0]];
	for (int i = 1; i < N; ++i) {
		ans += B[A[i]];
		if (A[i] == A[i-1] + 1)
			ans += C[A[i]-1];
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll mod = 1e9 + 7;

ll solve(void)
{
	ll n, m;
	cin >> n >> m;

	map<ll, vll> mp;

	for (ll i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		mp[a].push_back(b);
	}

	priority_queue<ll> q;
	ll ans = 0;
	for (ll i = 1; i <= m; i++)
	{
		for (auto a: mp[i])
			q.push(a);
		if (q.empty()) { continue; }
		ans += q.top();
		q.pop();
	}

	cout << ans << endl;

	return 0;
}

int main(void)
{
	// 追加２, 以降 cin の入力元が 'input.txt' になる
	// std::ifstream in("data.txt");
	// std::cin.rdbuf(in.rdbuf());

	while(solve()){}

	return 0;
}

Measured memory_bytes: 14240
using System;
using System.Linq;

namespace ABC137C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = CIN.Int();
            string[] S = new string[N];
            for (int i = 0; i < N; i++)
            {
                char[] A =  CIN.String().ToCharArray();
                Array.Sort(A);
                S[i] = new string(A);
            }
            Array.Sort(S);

            string first = S[0];
            long ans = 0;
            long cur = 0;
            for (int i = 1; i < N; i++)
            {
                if (first.Equals(S[i]))
                {
                    cur++;
                    continue;
                }

                first = S[i];
                ans += (cur + 1) * cur / 2;
                cur = 0;
            }

            ans += (cur + 1) * cur / 2;
            
            Console.WriteLine(ans);
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 24148
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N), sub(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
    sub.at(i) = data.at(i);
  }
  int count = 0;
  sort(sub.begin(), sub.end());
  for(int i = 0; i < N; i++){
    if(data.at(i) != sub.at(i))count++;
  }
  if(count <= 2)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

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


    if(X >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

int main(){
    int r,D,x;
    cin >> r >> D >> x;
    int xlist[11];
    xlist[0] = x;
    for (int i = 1; i < 11; i++)
    {
        xlist[i] = r*xlist[i-1]-D;
        cout << xlist[i] << endl;
    }
   return 0; 

}

Measured memory_bytes: 256
# Coding is about expressing your feeling, and
# there is always a better way to express your feeling_feelme
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007


n=ii1()
ans=[0]*(n+1)
for i in range(1,102):
    for j in range(1,102):
        for k in range(1,102):
            res=i*i + j*j +k*k +i*j +j*k + k*i
            if res<n+1:
                ans[res]+=1
for i in range(1,n+1):
    print(ans[i])






Measured memory_bytes: 9668
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    string S;
    ll K;
    cin >> S >> K ;
    int c = 1;
    rep(i,S.size()){
        if (c>=K){
            cout << S[i];
            rn 0;
        }
        if (S[i] != '1'){
            cout << S[i] << endl;
            rn 0;
        }
        else c++;
    }
    cout << "1";
    rn 0;
}


Measured memory_bytes: 256
n,*h=map(int,open(0).read().split())
dp=[10**18]*(n+1)
dp[0]=0
h=h+[0]
for i in range(n-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
  dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[n-1])



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

int main(){
  int H,W,i,j;
  cin>>H>>W;
  string s;
  char sharp='#';
  for(i=0;i<W+2;i++){
    cout<<sharp;
  }
  cout<<endl;
  for(i=0;i<H;i++){
    cin>>s;
    cout<<sharp<<s<<sharp<<endl;
  }
  for(i=0;i<W+2;i++){
    cout<<sharp;
  }
}

Measured memory_bytes: 256