akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A) rep(i,0,A.size()){cout<<(i ? " ":"")<<A[i];}cout<<endl;
const long mod=2019;
int main(){
	int N;cin>>N;
	long A[N];
	long sum=0,odd=0;
	rep(i,0,N){
		cin>>A[i];
		sum+=A[i];
		if(i%2==0) odd+=A[i];
	}long X[N];
	X[0]=odd-(sum/2);
	rep(i,1,N){
		X[i]=A[i-1]-X[i-1];
	}rep(i,0,N){
        cout<<(i ? " ":"")<<2*X[i];
    }cout<<endl;
}

Measured memory_bytes: 2816
#include <cstdio>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

ll N;
int main() {
	scanf("%lld", &N);
	ll a[N];
	rep(i, 0, N) scanf("%lld", &a[i]);

	ll AllXor = a[0];
	rep(i, 1, N) AllXor ^= a[i];

	rep(i, 0, N) {
		printf("%lld", AllXor ^ a[i]);
		if(i != N-1) printf(" ");
	}
	printf("\n");
    return 0;
}


Measured memory_bytes: 4632
n, k , q = list(map(int, input().split()))
answer = [0 for i in range(n)]
for i in range(q):
    answer[int(input()) - 1] += 1
for i in range(n):
    if k - (q - answer[i]) > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4620
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	
	int A[3];
	for (int i=0; i<3; i++) cin >> A[i];
	int five = 0;
	int seven = 0;
	
	for (int i=0; i<3; i++)
	{
		if (A[i] == 5){
			five++;
			
		}
		
		if (A[i] == 7) seven++;
	}
	
	if (five == 2 && seven == 1) cout << "YES" <<endl;
	else cout <<"NO" <<endl;
	
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 2019;
int main(){
    ll l,r;
    cin >> l >> r;
    ll mn = 3000;
    for(int i = l;i < min(l + MOD, r); i++){
        for(int j = i+1;j <= min(i+MOD+1, r); j++){
            mn = min(mn, ((i%MOD) * (j%MOD)) %MOD);
        }
    }
    cout << mn << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

x = [None for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    c = map(int, input().split())
    t = sum(map(lambda x: 2 ** (x - 1), c))
    x[i] = (a, t)

INF = 10 ** 9
dp = [INF for _ in range(2 ** n)]
dp[0] = 0

for ai, ti in x:
    for j in range(2 ** n):
        dp[ti | j] = min(dp[ti | j], dp[j] + ai)

if dp[-1] >= INF:
    ans = -1
else:
    ans = dp[-1]
print(ans)


Measured memory_bytes: 45160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt()%10;
		if(n==2 || n==4|| n==5||n==7||n==9) System.out.println("hon");
		else if(n==3) System.out.println("bon");
		else System.out.println("pon");
	}
}


Measured memory_bytes: 35724
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
#include <cassert>
#include <bit>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    ll n;cin>>n;
    string S;cin>>S;
    VI R,G,B;
    rep(i,n){
        if(S[i]=='R')R.push_back(i);
        else if(S[i]=='G')G.push_back(i);
        else B.push_back(i);
    }
    int ans=0;
for(auto r:R){
    for(auto g:G){
       int dif=abs(r-g);
       if(dif%2==0)if(binary_search(ALL(B),(r+g)/2))ans++;
       if(r<g){
           if(binary_search(ALL(B),g+dif))ans++;
           if(binary_search(ALL(B),r-dif))ans++;
       }
       else {
           if(binary_search(ALL(B),g-dif))ans++;
           if(binary_search(ALL(B),r+dif))ans++;
       }
    }
}
cout<<R.size()*G.size()*B.size()-ans<<endl;
}

Measured memory_bytes: 3700
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		String N = scan.next();

		char[] inputArray = N.toCharArray();

		if (inputArray[0] == inputArray[1] &&
				inputArray[1] == inputArray[2]) {
			System.out.println("Yes");
			return;
		}

		if (inputArray[1] == inputArray[2] &&
				inputArray[2] == inputArray[3]) {
			System.out.println("Yes");
			return;
		}

		System.out.println("No");
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 26940
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++)
    {
        if (s[i] != s[n - 1 - i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < (n - 1) / 2; i++)
    {
        if (s[i] != s[(n - 1) / 2 - 1 - i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> idx(N);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](int a, int b) { return A[a] < A[b]; });
  for (int i = 0; i < N; i++) {
    cout << idx[i] + 1 << (i == N - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1664
import java.io.PrintWriter;
import java.util.Scanner;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner("1000");
		//int n = Integer.parseInt(sc.next());
		String str = sc.next();
		char c[] = str.toCharArray();
		int n = c.length;
		int max = 0;
		int tmpmax1 = 0;
		int tmpmax2 = 0;
		for(int i = 0; i < n ; i++)
		{
			if((int)(c[i]-'0') == i%2)
			{
				tmpmax1++;
			}
			else
			{
				tmpmax2++;
			}
		}
		int ans;
		if(tmpmax1>tmpmax2)
		{
			ans = tmpmax2;
		}
		else
		{
			ans = tmpmax1;
		}
		//int x, y, z;
		//int n = Integer.parseInt(sc.next());
		//int na[] = new int[n];
		//int ans;
		//for(int i = 0; i < n ; i++)
		//{
		//	na[i] = Integer.parseInt(sc.next());
		//}


		PrintWriter out = new PrintWriter(System.out);

		out.println(ans);
		out.flush();
	}
}


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


int main()
{
	int D, G, p[11], c[11];
	cin >> D >> G;
	for (int i = 0; i < D; ++i)
		cin >> p[i] >> c[i];

	int ans = 1e9;
	for (int bit = 0; bit < 1 << D; ++bit)
	{
		int sum = 0, num = 0, rest = -1;
		for (int i = 0; i < D; ++i)
		{
			if (bit & 1 << i)
			{
				sum += (i + 1) * 100 * p[i] + c[i];
				num += p[i];
			}
			else 
			{
				rest = i;
			}
		}
		if (sum < G)
		{
			int x = 100 * (rest + 1);
			int need = (G - sum + x - 1) / x;
			if (need > p[rest])
			{
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3608
import Data.Int (Int64)

totalAmount :: Integral a => a -> a -> a -> a -> a
totalAmount n k x y = a1 + a2
    where
        a1 = x * min k n
        a2 = (*) y $ max 0 $ n - k

main :: IO ()
main = do
    n <- readLn :: IO Int64
    k <- readLn :: IO Int64
    x <- readLn :: IO Int64
    y <- readLn :: IO Int64
    print $ totalAmount n k x y


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

long gcd(long a, long b) {
  long smaller = min(a, b);
  long bigger = max(a, b);
  long surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

long lcm(long a, long b) {
  return a * b / gcd(a, b);
}

int main() {
  long a, b;
  long ans = 0;
  cin >> a >> b;
  ans = lcm(a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt(); 
        
        int K = sc.nextInt();
        
        int cnt = 0;
        
        int [] nums =new int [100002];
        
        for (int i = 0; i < N; i++){
        
            nums[i] = sc.nextInt();
        
        }
        
        sc.close();

        for (int i = 0; i < N; i++){
            
            if (nums[i] >= K) {
                cnt++;
            
            }
        }

        System.out.println(cnt);


        
    }
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;


int main(){
	int N, X, Y;
	vector<int> G[2010];
	int dis[2010];
	cin >> N >> X >> Y;
    X--; Y--;
	rep(i,N-1){
		G[i].emplace_back(i+1);
		G[i+1].emplace_back(i);
	}
	G[X].emplace_back(Y);
	G[Y].emplace_back(X);
	int ans[2010]={0};
	rep(s,N){
		rep(i,N) dis[i]=-1;
		dis[s]=0;
		queue<int> q;
		q.push(s);
		while(!q.empty()){
			int n=q.front();
			q.pop();
			rep(i,G[n].size()){
				int next=G[n][i];
				if(dis[next]!=-1) continue;
				q.push(next);
				dis[next]=dis[n]+1;
				ans[dis[n]+1]++;
			}
		}
	}
	for(int i=1; i<N; i++) cout << ans[i]/2 << endl;

	return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
#define MOD 1000000007

ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if(p&1==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}
ll modinv(ll a, int b){// a/b mod MOD
    ll res=1;
    int n=MOD-2;
    ll x=b;
    while(n>0){
        if(n&1==1){
            res*=x;
            res%=MOD;
        }
        x*=x;
        x%=MOD;
        n>>=1;
    }
    res*=a;
    res%=MOD;
    return res;
}
int main() {
    int N; cin>>N;
    vector<ll> C(N);
    for (int i = 0; i < N; i++){
        cin>>C[i];
    }
    sort(C.begin(),C.end());
    ll ans=0;
    for (int i = 0; i < N; i++){
        ans+=(C[i]*(N-i+1))%MOD;
        ans%=MOD;
    }
    ans*=mod_pow(2,2*N-2);
    ans%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 4892
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  n,m = list(map(int,input().split()))
  a =  list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  for i in a:
    ans += i  
  if ans > n:
    print(-1)
  else:
    print(n-ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 9848
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

lli k;

int main()
{
  while (scanf("%lld", &k) != EOF)
  {
    bool can = false;
    lli ans, pot = 7, sum = 0;
    for (ans = 1; ans < 1e7; ans++, pot = pot * 10 % k)
    {
      sum = (sum + pot % k) % k;
      if (sum == 0)
      {
        can = true;
        break;
      }
    }
    if (!can) ans = -1;
    printf("%lld\n", ans);
  }
  return 0;
}

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


def main():
    N, M = map(int, input().split())
    INF = 10 ** 10
    p = 2 ** N
    dp = [INF] * p
    dp[0] = 0

    for _ in range(M):
        a, b = map(int, input().split())
        c = sum([2 ** (i - 1) for i in map(int, input().split())])
        for i in range(p):
            dp[i | c] = min(dp[i] + a, dp[i | c])

    if dp[-1] != INF:
        print(dp[-1])
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	string s; cin >> s;
	int y = stoi(s.substr(0, 4));
	int m = stoi(s.substr(5, 2));
	int d = stoi(s.substr(8, 2));
	dump(y, m, d);
	if (y < 2019) {
		cout << "Heisei" << endl;
	}
	else if (y == 2019) {
		if (m < 5) {
			cout << "Heisei" << endl;
		}
		else {
			cout << "TBD" << endl;
		}
	}
	else {
		cout << "TBD" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,m,i;cin>>n>>m;
	llint ans=0;
	vector<vector<int>>go(n);
	vector<vector<int>>ro(n);
	for(i=0;i<m;i++){
		int a,b;cin>>a>>b;a--;b--;
		go[a].pub(b);
		ro[b].pub(a);
	}
	vector<int>col(n,-1);
	vector<int>sla(n,-1);
	queue<int>que;
	for(i=0;i<n;i++){
		if(col[i]!=-1){continue;}
		//スライドできるスペースがあるか確認する
		llint kaz[3]={0};
		bool bra=0;
		que.push(i);
		col[i]=0;sla[i]=0;
		int su=0,st=0;
		llint cou=0;
		while(que.size()){
			int ter=que.front();
			que.pop();
			int c=col[ter];
			int s=sla[ter];
			maxeq(su,s);
			mineq(st,s);
			kaz[c]++;
			for(auto it:go[ter]){
				cou++;
				if(col[it]==-1){sla[it]=s+1;col[it]=(c+1)%3;que.push(it);}
				else if(col[it]!=(c+1)%3){bra=1;}
			}
			for(auto it:ro[ter]){
				if(col[it]==-1){sla[it]=s-1;col[it]=(c+2)%3;que.push(it);}
				else if(col[it]!=(c+2)%3){bra=1;}
			}
		}
		if(bra){ans+=(kaz[0]+kaz[1]+kaz[2])*(kaz[0]+kaz[1]+kaz[2]);}
		else if(su-st<2){ans+=cou;}
		else{ans+=kaz[0]*kaz[1]+kaz[1]*kaz[2]+kaz[2]*kaz[0];}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const ll INF = 1LL << 50;

struct Edge {
    int from;
    int to;
    ll cost;
};

int main() {
    int N, M, P;
    cin >> N >> M >> P;
    vector<Edge> edges(M);
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        c = P - c;
        edges[i] = {a, b, c};
    }
    vector<ll> dist(N, INF);
    dist[0] = 0;
    for(int loop = 0; loop < N - 1; ++loop) {
        for(auto &e : edges) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
            }
        }
    }
    vector<bool> negative(N);
    for(int loop = 0; loop < N; ++loop) {
        for(auto &e : edges) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                negative[e.to] = true;
            }
            if(negative[e.from] == true) {
                negative[e.to] = true;
            }
        }
    }
    ll ans = -dist[N - 1];
    if(negative[N - 1]) cout << -1 << endl;
    else {
        if(ans < 0) cout << 0 << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<utility>
#include<vector>

#define INF 1000000007

using ll = long long;
using namespace std;

int main(void){

    int n;
    cin >> n;
    ll a[n], b[n];
    for(int i=0;i<n;i++)cin >> a[i] >> b[i];

    ll ans = 0;
    for(int i=n-1;i>=0;i--){
        if((a[i]+ans) % b[i] != 0)ans += b[i] - ((a[i]+ans) % b[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
c = list(input())

ans = 0
l = 0
r = N-1
while l < r:
    if c[l] == "W":
        for i in range(r,l,-1):
            if c[i] == "R":
                ans += 1
                r = i-1
                break
        else:
            l = N
            break
    l += 1

print(ans)

Measured memory_bytes: 73804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
#define PB push_back
#define M 1000000007
#define B 500
double pi=3.1415926535;
int m,tt;
int judge(double t){
    double xk,yk,zk,xm,ym,zm;
    double arg;
    arg=pi/180*m;
    arg+=(t/41667*2*pi);
    zm=0;
    xm=cos(arg)*380000;
    ym=sin(arg)*380000;
    arg=t*2*pi/120;
    yk=ym;
    zk=zm+cos(arg)*1900;
    xk=xm-sin(arg)*1900;
    double k;
    k=(xk*xm+yk*ym+zk*zm)/(xk*xk+yk*yk+zk*zk);
    double xh,yh,zh;
    xh=xk*k;
    yh=yk*k;
    zh=zk*k;
    double xd,yd,zd;
    xd=xh-xm;
    yd=yh-ym;
    zd=zh-zm;
    if(k<=1&&xd*xd+yd*yd+zd*zd<1800*1800){
        return 1;
    }
    else return 0;
}
int main(void){
   scanf("%d%d",&m,&tt);
   double ans=0;
   for(int i=0;i<=tt*B;i++){
       ans+=judge(D(i)/B);
   }
   printf("%lf\n",ans/B);
}


Measured memory_bytes: 3564
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

N, A, B, C, D = map(int, input().split())
mod = 10**9+7
comb = Combination(1010)
dp = [0]*(N+1)
dp[0] = 1
for n_person in range(A, B+1):
    dp_new = dp[:]
    for i, v in enumerate(dp):
        c = 1
        rem = N-i
        for n_groups in range(1, C):
            if rem < n_person:
                break
            c = c * comb(rem, n_person) % mod
            rem -= n_person
        else:
            for n_groups in range(C, D+1):
                if rem < n_person:
                    break
                c = c * comb(rem, n_person) % mod
                rem -= n_person
                dp_new[N-rem] = (dp_new[N-rem] + c * comb.facinv[n_groups] * v) % mod
    dp = dp_new
print(dp[N])


Measured memory_bytes: 53212
import sys
sys.setrecursionlimit(10 ** 7)


def F(S):
    arr = list(S)
    prev = 'A'
    cnt = 0
    for x in S:
        if x == prev:
            cnt += 1
            prev = 'A'
        else:
            prev = x
    return cnt


def main():
    S = input()
    K = int(input())

    arr = [F(S*i) for i in range(10)]

    if K < 10:
        ans = arr[K]
    else:
        if K & 1:
            d = arr[9] - arr[7]
            ans = arr[9] + d * ((K-9)//2)
        else:
            d = arr[8] - arr[6]
            ans = arr[8] + d * ((K-8)//2)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int h, w;
    cin >> h >> w;

    int while_num = 0;
    char maze[50][50];
    rep(i, h){
        rep(j, w){
            cin >> maze[i][j];
            if(maze[i][j] == '.') ++while_num;
        }
    }

    int cnt[50][50] = {0};
    queue<pair<int, int>> search;

    search.push(pair<int, int>(0, 0));
    cnt[0][0] = 1;
    while(true && search.size() > 0){
        int x = search.front().first;
        int y = search.front().second;
        search.pop();

        if(x == w-1 && y == h-1){
            break;
        }

        rep(i, 4){
            int mx = x + dx[i];
            int my = y + dy[i];
            if(0 <= mx && mx < w && 0 <= my && my < h && maze[my][mx] == '.' && cnt[my][mx] == 0){
                cnt[my][mx] = cnt[y][x] + 1;
                search.push(pair<int, int>(mx, my));
            }
        }
    }

    if(cnt[h-1][w-1] == 0){
        cout << -1 << endl;
    }else{
        cout << while_num - cnt[h-1][w-1] << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N, V[21], C[21],sum;
	sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> V[i];
	}
	for (int i = 0; i < N; i++){
		cin >> C[i];
	}
	//入力終わり
	for (int i = 0; i < N; i++){
		if (V[i] > C[i]){
			sum += V[i] - C[i];
		}
	}
	
	cout << sum << endl;
	return 0;
}

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

int main(){
  
  int a,b;
  cin >> a >> b;

  if (a == 1 && b == 2)
  {
    cout << "3" << endl;
  }
  if (a == 2 && b == 3)
  {
    cout << "1" << endl;
  }
  if (a == 3 && b == 1)
  {
    cout << "2" << endl;
  }

  if (a == 2 && b == 1)
  {
    cout << "3" << endl;
  }
  if (a == 3 && b == 2)
  {
    cout << "1" << endl;
  }
  if (a == 1 && b == 3)
  {
    cout << "2" << endl;
  }

  return 0;
}


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

using namespace std;

struct WeightedUnionFind {
    std::vector<int> par; // pos: parent node, neg: rank of tree
    std::vector<int> dw;

    WeightedUnionFind(int N) : par(N, -1), dw(N, 0) {}

    int find(int x){
        if(par[x] < 0) return x;
        int p = find(par[x]);
        dw[x] = dw[par[x]] + dw[x];
        return par[x] = p;
    }

    int weight(int x){
        find(x);
        return dw[x];
    }

    bool unite(int x, int y, int w){ // x+w = y
        w = w + weight(x) - weight(y);
        x = find(x); y = find(y);
        if(x == y) return false; // unspecified.

        int rx = -par[x], ry = -par[y];
        if(rx < ry){ // merge technique
            std::swap(x, y);
            w = -w;
        }
        par[x] = -(rx+ry);
        par[y] = x;
        dw[y] = w;
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int dist(int x, int y){ // x, y must be in same group.
        return weight(y) - weight(x);
    }
};


int main(void){
    int N, M;
    cin >> N >> M;
    WeightedUnionFind wuf(N);
    for(int i=0;i<M;i++){
        int L, R, D;
        cin >> L >> R >> D;

        if(wuf.same(L, R) && wuf.dist(L, R) == D) continue;

        if(wuf.unite(L, R, D) == false){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
  int n,l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i,n) a[i] = l+i;
  int sum = 0;
  rep(i,n) sum += a[i];
  int ans = 1e9;
  
  rep(i,n){
    int t = sum - a[i];
    if(abs(sum-t)<abs(sum-ans)) ans = t;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, i, j, judge = 0;

    scanf("%d", &n);

    for (i = 1; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            if (judge == 0 && n == i*j) {
                printf("Yes\n");
                judge = 1;
                break;
            }
        }
    }
    if (judge == 0) {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++)
	{
			if((x-i)*2+(i)*4==y)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 3620
M,D = map(int, input().split())

ans = 0

if D <= 21:
    ans = 0
else:
    for d_ in range(22,D+1):
        d = list(map(int, str(d_)))
        if int(d[0])<2 or int(d[1])<2:
            continue
        for m in range(1,M+1):
            if d[0] * d[1] == m:
                ans += 1
print(ans)

Measured memory_bytes: 3064
import sys
K = int(input())
count = 0
nine = ""

arr = []
arr_sunuke = []
for k in range(14):
    for i in range(10):
        for j in range(10):
            for l in range(10):
                if i == 0 and nine != "":
                    pass
                else:
                    arr.append(int(str(i)+str(j)+str(l)+nine))
                    arr_sunuke.append(i + j + l + k*9)
    nine = nine + str(9)

arr.remove(0)
arr_sunuke.remove(0)
arr_sunuke2 = [arr[i]/arr_sunuke[i] for i in range(len(arr))]

ans = []
tmp = 10**15
for i in range(len(arr)-1, -1, -1):
    if arr_sunuke2[i] <= tmp:
        ans.append(arr[i])
        tmp = arr_sunuke2[i]

ans = ans[::-1]
for i in range(K):
    print(ans[i])

Measured memory_bytes: 4200
N, W = map(int, input().split())
w = {}
v = {}

for i in range(N):
    w[i+1], v[i+1] = map(int, input().split())

dp = {}
dp[0] = {}

for i in range(W+1):
    dp[0][i] = 0

for i in range(1, N+1):
    dp[i] = {}
    for j in range(0,W+1):
        if j >= w[i]:
            dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Measured memory_bytes: 830608
# coding:utf-8
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split(' '))
if N <= 1:
    print(0) if M <= 1 else print(N + comb(M, 2))
elif M <= 1:
    print(comb(N, 2))
else:
    print(comb(N, 2) + comb(M, 2))


Measured memory_bytes: 3060
from sys import stdin,stdout
n,m=map(int,stdin.readline().split())
H=list(map(int,stdin.readline().split()))
L=[0]*n
for i in range(m):
	a,b=map(int,stdin.readline().split())
	L[a-1]=max(L[a-1],H[b-1])
	L[b-1]=max(L[b-1],H[a-1])
ans=0
for i in range(n):
	if H[i]>L[i]:
		ans+=1
		
stdout.write(str(ans))

Measured memory_bytes: 20248
use v5.18; # strict say state
use warnings;

my ($h, $w) = split / /, <STDIN>;
if ($h==1 || $w==1) {
  say 1;
  exit;
}
my $ans = int(($w+1)/2)*$h;
$ans -= int($h/2) if $w%2>0;
say $ans;

Measured memory_bytes: 640
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,t;
  cin>>n>>t;
  vector<int> cnt(200);
  rep(i,n){
    string s;
    cin>>s;
    cnt[s[0]]++;
  }
  priority_queue<pii> q;
  reps(c,'A','Z'+1) if(cnt[c]) q.emplace(cnt[c],c);
  int re=0;
  while(1){
    int f=1;
    vector<pii> tmp;
    rep(i,t){
      if(q.empty()){
	f=0; break;
      }
      pii p=q.top(); q.pop();
      if(p.X>1) tmp.eb(p.X-1,p.Y);
    }
    if(f) ++re;
    else break;
    for(pii p:tmp) q.push(p);
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200000)

MOD = 1000000007  # type: int

def h(L, i):
    return pow(3, len(L)-i, MOD)

def g(L, i):
    if len(L) == i:
        return 1
    if L[i] == '1':
        return ((2 * g(L, i+1)) % MOD + h(L, i+1)) % MOD
    return g(L, i+1)

def solve(L: str):
    return g(L, 0)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = next(tokens)  # type: str
    print(solve(L))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, z, w;cin >> n >> z >> w;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    if(n == 1){
        cout << abs(a[0] - w) << endl;
        return 0;
    }
    int diff = abs(a[n-1] - a[n-2]);
    int last = a[n-1];
    if(abs(w - last) > diff){
        cout << abs(w - last) << endl;
    }else{
        cout << diff << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<vector<int>> A(N, vector<int>(2));
  REP(i, N) cin >> A[i][0];
  REP(i, N) cin >> A[i][1];

  A[0][1] += A[0][0];
  FOR(i, 1, N){
    A[i][0] += A[i-1][0];
    A[i][1] += max(A[i][0], A[i-1][1]);
  }

  cout << A[N-1][1] << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int N,X;
    cin >> N >> X;
    int t = INT_MAX;
    int ans = N;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        X -= tmp;
        t = min(t,tmp);
    }
    while(t <= X){
        X -= t;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
A = []
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
A.append(A_1)
A.append(A_2)
A.append(A_3)

N = int(input())
b = []

for i in range(N):
    b.append(int(input()))

c = [[0,0,0],[0,0,0],[0,0,0]]
for j in range(N):
    for p in range(3):
        for l in range(3):
            if b[j] == A[p][l]:
                c[p][l] = 1

check = 0
for d in range(N):
    for o in range(3):
        if c[o][0] == 1 and c[o][1] == 1 and c[o][2] == 1:
            check += 1
            break

    for g in range(3):
        if c[0][g] == 1 and c[1][g] == 1 and c[2][g] == 1:
            check += 1
            break

    if c[0][0] == 1 and c[1][1] == 1 and c[2][2] == 1:
        check += 1
    if c[0][2] == 1 and c[1][1] == 1 and c[2][0] == 1:
        check += 1
    if check != 0:
        break

if check != 0:
    print('Yes')
else :
    print('No')

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

struct sword
{
    int d,t;
    sword(){}
    sword(int pd, int pt) : d(pd), t(pt) {}
};

bool operator < (const sword &a, const sword &b)
{
    if(a.d != b.d) return a.d > b.d;
    return a.t > b.t;
}

vector<sword> v;
  
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,h,a,b,ans,x;
    while(cin >> n >> h)
    {
        v.clear();
        for(int i = 0; i < n; i++)
        {
            cin >> a >> b;
            v.emplace_back(a,1);
            v.emplace_back(b,0);
        }

        sort(v.begin(), v.end());
        ans = 0;
        for(int i = 0; i < (int)v.size(); i++)
            if(v[i].t == 0)
            {
                h -= v[i].d;
                ans++;
                if(h <= 0)
                    break;
            }
            else
            {
                x = ceil(h * 1.0 / v[i].d);
                ans += x;
                break;
            }
        cout << ans << '\n';
    }
    return 0;
} 

Measured memory_bytes: 2420
//https://atcoder.jp/contests/dp/tasks/dp_b
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin>>n>>k;
	vector<ll> h;
	for(ll i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		h.push_back(x);
	}
	vector<ll>cost(n,INT_MAX);
	cost[0]=0;
	for(int i=0;i<n;i++)
	{
		int j=0;
		ll min_cost=INT_MAX;
		for(j=i+1;j<=i+k;j++)
		{
			if(j<n)
			{
				cost[j]=min(cost[j],cost[i]+abs(h[i]-h[j]));
			}
		}
	}
	cout<<cost[cost.size()-1]<<"\n";	
	return 0;
}

Measured memory_bytes: 1908
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

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

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

    }

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

int main(){
    cin>>N;
    rep(i,0,N){
        cin>>h[i];
    }
    h[0]--;
    rep(i,1,N){
        if(h[i]<h[i-1]){
            cout<<"No"<<endl;
            return 0;
        }else{
            h[i]= max(h[i-1],h[i]-1);
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    string s, ans;
    cin >> s;
    if(s[2] == s[3] & s[4] == s[5]){
        ans = "Yes";
    } else {
        ans = "No";
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  li n,a,b,d; cin >>n >>a >>b; d=a-b;
  if(df)print("d:",d);
  vector<li> h(n);
  li ng=0,ok=0;
  for(auto& x:h){
    cin >>x;
    ok+=x/b+1;
  }
  if(df)print(ok,ng);
  auto judge
    =[&](li k){
       li s=k*b,cnt=0; 
       for(auto x:h){
         if((x-=s)>0){
           cnt+=(x+d-1)/d;
           //           if(df)printf("rem:%ld->cnt%d ",x,cnt);
         }
       }
       if(df) print("k:",k,"cnt:",cnt,cnt<=k);
       return (cnt<=k);
     };
  
  while(ok-ng>1){
    li mid=(ok+ng)/2;
    (judge(mid)?ok:ng)=mid;
  }
  print(ok);
  
}


Measured memory_bytes: 1024
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        long a=gl();
        long b=gl();
        long c=gl();
        if(c-b-a<=0) {
        	System.out.println("No");
        } else {
        	long l=4*a*b;
        	long r=(c-a-b)*(c-a-b);
        	if(r>l) {
        	    System.out.println("Yes");
        	} else {
        		System.out.println("No");
        	}
        }
        //System.out.println(N-max);
	}

	public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
		/** serialVersionUID. */
	    private static final long serialVersionUID = 6411527075103472113L;

	    public Pair(final K key, final V value) {
	        super(key, value);
	    }

		@Override
		public int compareTo(Pair<K, V> o) {

			Comparable key = (Comparable)this.getKey();
			Comparable key2 = (Comparable)o.getKey();

			return key.compareTo(key2);
		}

	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35612
#include<stdio.h>
#define M 40

int n,pos;
int a[M],b[M];

void solve(int l, int r) {
	int x, i;
	x = a[pos];
	if (l > r) return;
	if (l == r) {
		if (b[l] == a[0]) printf("%d", b[l]);
		else              printf("%d ", b[l]);
		pos++;
		return;
	}
	pos++;

	for (i = l; i <= r; i++)
		if (b[i] == x) break;

	solve(l, i - 1);
	solve(i + 1, r);

	if (x == a[0]) printf("%d", x);
	else           printf("%d ", x);
}


int main(){

  scanf("%d", &n);
  for(int  i=0 ; i<n ; i++)
    scanf("%d", &a[i]);

  for(int  i=0 ; i<n ; i++)
    scanf("%d", &b[i]);
  
  pos = 0;
  solve( 0, n-1);
  printf("\n");

  return 0;
}







Measured memory_bytes: 2120
#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 n;
  map<int,int> mp;
  cin >> n;
  
  for(int i = 2; i <= n; i++){
    int a;
    cin >> a;
    mp[a]++;
  }
  
  for(int i = 1; i <=n; i++) cout << mp[i] << endl;
  
}

Measured memory_bytes: 13020
# https://www.planeta.tokyo/entry/3963/
# N = 3
# X =[[['Fuji', '5'], 1], [['Fuji', '2'], 2], [['Angus', '3'], 3]]
N = int(input())
X = [[input().split(), i + 1] for i in range(N)]   #最終的に出力するのが番号なので、番号も一緒に入れ込んだリストを生成しておきます。
X = sorted(X, key = lambda x:(x[0][0], -int(x[0][1]))) 
for i in range(N):
    print(X[i][1])

Measured memory_bytes: 3060