akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    while(true){
        string num;
        cin >> num;
        int ans =0;
        if(num == "0")break;
        for(int i=0;i<num.size();i++){
            ans+= num[i] - '0';
        }
        cout << ans << endl;;
    }
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=3011;
const int MOD=1e9+7;

int n;
char s[N];
int dp[N][N],sum[N];
void Add(int &x,int y)
{
	x+=y;
	if(x>=MOD) x-=MOD;
}

int main()
{
	
	scanf("%d%s",&n,&s);
	for(int i=1;i<=n;i++)
		dp[i-1][n-i]=1;
	for(int len=n-1;len>0;len--)
	{
		bool ok=(s[n-len-1]=='<');
		if(ok) for(int i=0;i<=len;i++) Add(dp[i][len-i-1],dp[i][len-i]);
		if(!ok) for(int i=1;i<=len;i++) Add(dp[i-1][len-i],dp[i][len-i]);
		if(ok) for(int i=1;i<=len;i++) Add(dp[i][len-i-1],dp[i-1][len-i]);
		if(!ok) for(int i=len-1;i>=0;i--) Add(dp[i][len-i-1],dp[i+1][len-i-2]);
	}
	printf("%d\n",dp[0][0]);
	
	return 0;
}

Measured memory_bytes: 35200
# -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache

input = sys.stdin.readline

# N個整数
# a, b, c = list(map(int, input().split()))

# 1整数
# n = int(input())

# 空白区切りリスト整数
# b = list(map(int, input().split()))

# 空白区切り文字列
# t, d = input().split()

n = int(input())

mm = 9999999999999999

ll = []
for i in range(5):
    mm = min(mm, int(input()))
    # ll.append(int(input()))

print((n-1) // mm + 5)


Measured memory_bytes: 4188
import java.util.Scanner;
class Dice{
	private int num[] = new int[6];
	private int we[] = new int[4];
	private int ns[] = new int[4];
	public Dice(){
	}
	public void setNum(int n[]){
		for(int i = 0 ; i < 6 ; i++)
			num[i] = n[i];
		we[0] = ns[3] = num[5];
		we[2] = ns[1] = num[0];
		we[1] = num[3];
		we[3] = num[2];
		ns[0] = num[4];
		ns[2] = num[1];
	}
	public void setNum(int n1, int n2, int n3, int n4, int n5, int n6){
		int N1=n1, N2=n2, N3=n3, N4=n4, N5=n5, N6=n6;
		we[2] = ns[1] = num[0] = N1;
		ns[2] = num[1] = N2;
		we[3] = num[2] = N3;
		we[1] = num[3] = N4;
		ns[0] = num[4] = N5;
		we[0] = ns[3] = num[5] = N6;
	}
	public int getNum(int i, int n){
		if(i == 0)
			return we[n];
		else
			return ns[n];
	}
	public void print(int i, int n){
		if(i == 0)
			System.out.println(we[n]);
		else 
			System.out.println(ns[n]);
	}
	public void roll(String order){
		for(int i = 0 ; i < order.length() ; i++){
			switch(order.charAt(i)){
				case 'E' : setNum(num[3],num[1],num[0],num[5],num[4],num[2]); break;
				case 'W' : setNum(num[2],num[1],num[5],num[0],num[4],num[3]); break;
				case 'S' : setNum(num[4],num[0],num[2],num[3],num[5],num[1]); break;
				case 'N' : setNum(num[1],num[5],num[2],num[3],num[0],num[4]); break;
			}
		}
	}
}
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num[] = new int[6];
		for(int i = 0 ; i < 6 ; i++)
			num[i] = sc.nextInt();
		Dice dice = new Dice();
		dice.setNum(num);
		int n = sc.nextInt();
		for(int i = 0 ; i < n ; i++)
		{
			int up = sc.nextInt();
			int forward = sc.nextInt();
			for(int j = 0 ; j < 4 ; j++)
			{
				dice.roll("N");
				if(forward == dice.getNum(1,2))
					break;
			}
			if(forward != dice.getNum(1,2))
			{
				dice.roll("W");
				for(int j = 0 ; j < 4 ; j++)
				{
					dice.roll("N");
					if(forward == dice.getNum(1,2))
						break;
				}
			}
			for(int j = 0 ; j < 4 ; j++)
			{
				dice.roll("W");
				if(up == dice.getNum(0,2))
					break;
			}
			dice.print(0,3);
		}
	}
}


Measured memory_bytes: 26136
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int main(){
	long A,B,C,K;
	cin >> A >> B >> C >> K;
	if(A>=K)cout << K << endl;
	else if(A+B >= K) cout << A << endl;
	else cout << A - (K -(A+B)) << endl;

	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=3e5+10, maxm=1e6+10, lg=21, mod=1e9+7, inf=1e18;

string s;
ll n,dp[maxn][3][3],ans;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>s;
	dp[0][0][0]=1;
	for(int i=0;i<SZ(s);i++)for(int t0=0;t0<3;t0++)for(int t1=0;t1<3;t1++){
		if(s[i]!='0'){
			if(t0) (dp[i+1][t0-1][t1]+=dp[i][t0][t1])%=mod;
			else (dp[i+1][t0][min(t1+1,2)]+=dp[i][t0][t1])%=mod;
		}
		if(s[i]!='1'){
			if(t0>1) (dp[i+1][t0-1][t1]+=dp[i][t0][t1])%=mod;
			else (dp[i+1][t0+1][t1]+=dp[i][t0][t1])%=mod;
		}
	}
	for(int t0=0;t0<3;t0++)for(int t1=t0;t1<3;t1++) (ans+=dp[SZ(s)][t0][t1])%=mod;
	cout<<ans;
	
	return 0;
}


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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

int get(int a, int b, int x) {
  int l = ((a - 1) / x + 1) * x;
  int r = b / x * x;
  return (r - l) / x + 1;
}

int lcm(int a, int b) {
  return a / __gcd(a, b) * b;
}

void MAIN() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (b - a + 1) - get(a, b, c) - get(a, b, d) + get(a, b, lcm(c, d)) << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

bool vis[1000010];
int dist[1000010];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    queue<int> q, d;
    q.push(0);
    d.push(0);
    clr(vis, false);
    vis[0] = true;
    dist[0] = 0;
    while (!q.empty())
    {
    	int m = q.front();
    	int w = d.front();
    	q.pop();
    	d.pop();
    	//continue;
    	if ( !vis[m+1] && m+1 <= n )
    	{
    		vis[m+1] = true;
    		dist[m+1] = w+1;
    		q.push(m+1);
    		d.push(w+1);
    	}
    	//continue;
    	for (int i = 6; m+i <= n; i *= 6)
    	{
    		if (vis[m+i]) continue;
    		vis[m+i] = true;
    		dist[m+i] = w+1;
    		q.push(m+i);
    		d.push(w+1);
    	}
    	for (int i = 9; m+i <= n; i *= 9)
    	{
    		if (vis[m+i]) continue;
    		vis[m+i] = true;
    		dist[m+i] = w+1;
    		q.push(m+i);
    		d.push(w+1);
    	}
    }
    cout << dist[n] << endl;
    return 0; 
}

Measured memory_bytes: 3712
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<String> result = new ArrayList<String>();
		
		int num = sc.nextInt();
		

		for(int i = 0; i < num; i++){
			result.add(isTriangle(sc.nextInt(), sc.nextInt(), sc.nextInt()));
		}
		
		for(int i = 0; i < result.size(); i++){
			System.out.println(result.get(i));
		}
	}
	
	private static String isTriangle(int x, int y, int z){
		int x2 = x * x;
		int y2 = y * y;
		int z2 = z * z;
		
		if(x2 + y2 == z2){
			return "YES";
		}
		else if(y2 + z2 == x2){
			return "YES";
		}
		else if(z2 + x2 == y2){
			return "YES";
		}
		else{
			return "NO";
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  string s;
  cin >> s;
  ll count = 0;
  rep(i,sz(s)){
    if(s[i]=='x'){
      count++;
    }
  }
  if(count<=7){
    print("YES");
  }
  else{
    print("NO");
  }
}

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

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

int N, K;
int P[5010], C[5010];

void dfs(int s, int v, vector<int>& res)
{
	if (s == v && !res.empty())return;
	res.push_back(C[v]);
	dfs(s, P[v], res);
}

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

	cin >> N >> K;
	rep(i, 0, N)
	{
		cin >> P[i];
		P[i]--;
	}
	rep(i, 0, N)cin >> C[i];

	int ans = -INF;
	rep(i, 0, N)
	{
		vector<int> pv;
		dfs(i, i, pv);

		int sum = 0;
		rep(j, 0, SZ(pv))
		{
			sum += pv[j];
		}
		//chmax(sum, 0LL);

		int res = -INF;

		int s = 0;
		int ma = -INF;
		rep(j, 0, min(SZ(pv), K))
		{
			s += pv[j];
			chmax(ma, s);
		}

		chmax(res, ma);

		int t = K / SZ(pv);

		{
			int cnt = K - t * SZ(pv);
			int tres = t * sum;
			if (cnt > 0)
			{
				s = 0;
				ma = -INF;
				rep(j, 0, cnt)
				{
					s += pv[j];
					chmax(ma, s);
				}
				tres += ma;
			}
			chmax(res, tres);
		}

		if(t>0)
		{
			t--;
			int cnt = K - t * SZ(pv);
			int tres = t * sum;
			if (cnt > 0)
			{
				s = 0;
				ma = -INF;
				rep(j, 0, SZ(pv))
				{
					s += pv[j];
					chmax(ma, s);
				}
				tres += ma;
			}
			chmax(res, tres);
		}

		chmax(ans, res);
	}

	cout << ans << endl;

	return 0;
}


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

long long N, L, A[6009];

pair<double, double> getpoint(long long G) {
	double v1 = cos(3.14159265358979 * G / (0.5 * L));
	double v2 = sin(3.14159265358979 * G / (0.5 * L));
	return make_pair(v1, v2);
}

int main() {
	cin >> N >> L; L *= 2;
	for (int i = 0; i < N; i++) { cin >> A[i]; A[i] *= 2; }
	for (int i = N; i < 2 * N; i++) A[i] = A[i - N] + L;

	pair<double, double> ans = make_pair(0.0, 0.0);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) continue;

			int s1 = i, s2 = j; if (s1 > s2) s2 += N;
			pair<double, double> T = getpoint((A[s1] + A[s2]) / 2LL);
			ans.first += 1.0 * T.first * (1.0 * (N - (s2 - s1) - 1));
			ans.second += 1.0 * T.second * (1.0 * (N - (s2 - s1) - 1));
		}
	}

	double V = 1.0 * N * (1.0 * N - 1.0) * (1.0 * N - 2.0) / 6.0;
	printf("%.12lf %.12lf\n", ans.first / V, ans.second / V);
	return 0;
}

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

int main(){
	int E,Y;
	int a[] = {0, 1867, 1911, 1925, 1988};
	cin >> E >> Y;
	if(E == 0){
		if(a[4] < Y)cout << "H"<<Y-a[4]<<endl;
		else if(a[3] < Y)cout << "S"<<Y-a[3]<<endl;
		else if(a[2] < Y)cout << "T"<<Y-a[2]<<endl;
		else if(a[1] < Y)cout << "M"<<Y-a[1]<<endl;
	}else {
		cout << a[E]+Y<<endl;
	}
	return 0;
}


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

#define ll long long
#define MOD 1000000007


int main(){
    int n;
    cin>>n;
    
    vector<int> s(n+1,0);
    
    int k;
    cin>>k;
    
    int d;
    int a;
    
    for(int i=0;i<k;i++){
        cin>>d;
        for(int i=0;i<d;i++){
            cin>>a;
            s.at(a)++;
        }
    }
    
    int co=0;
    for(int i=1;i<=n;i++){
        if(s.at(i)==0){
            co++;
        }
    }
    cout<<co<<endl;
}



Measured memory_bytes: 3636
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a[5] = {0,0,1,1,1};
	int b[5] ={0};
	map<char,ll> m;
	int n;
	cin>>n;
	string s;
	for(int i = 0; i<n; i++)
	{
		cin>>s;
		m[s[0]]++;
	}
	b[0] = m['M'],b[1] = m['A'],b[2] = m['R'],b[3]=m['C'],b[4] = m['H'];
	ll ans = 0;
	do{
		ll t = 1;
		for(int i = 0; i<5; i++)
			if(a[i])
			t *= b[i];
		
		ans += t;
	}while(next_permutation(a,a+5));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
void drop(int x,int y,int *k,int d[10][10]){
	if(x>=0&&y>=0&&x<10&&y<10){
		if(d[y][x]==0)
			*k=*k-1;
		d[y][x]++;	
	}
}

int main(){
	
	int d[10][10]={0};
	char comma;
	int x,y,s;
	int k=100;
	while(cin>>x>>comma>>y>>comma>>s){
		if(s>=1){
			drop(x,y,&k,d);
			drop(x+1,y,&k,d);
			drop(x,y+1,&k,d);
			drop(x-1,y,&k,d);
			drop(x,y-1,&k,d);
	}
		if(s>=2){
			drop(x+1,y+1,&k,d);
			drop(x+1,y-1,&k,d);
			drop(x-1,y-1,&k,d);
			drop(x-1,y+1,&k,d);
		}
		if(s>=3){
			drop(x-2,y,&k,d);
			drop(x+2,y,&k,d);
			drop(x,y-2,&k,d);
			drop(x,y+2,&k,d);
		}
	}
	cout<<k<<endl;
	int max=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(max<d[i][j])
				max=d[i][j];
		}
	}
	cout<<max<<endl;
}

Measured memory_bytes: 1160
//author: Harsh :)
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  char c;
  cin>>c;
  if(isupper(c)) cout<<"A";
  else cout<<"a";
  return 0;

}


Measured memory_bytes: 3576
// Crt. 2019-12-09  20:29:14
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, d[N];
int tot, fir[N], nxt[N << 1], to[N << 1];
long long a[N], f[N];

inline void addE(int u, int v) {
    nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v;
}

void dfs(int u, int p) {
    if (d[u] == 1) return f[u] = a[u], void();
    long long tmp, sum = 0, mxv = 0;
    for (int i = fir[u], v; i; i = nxt[i]) {
        v = to[i];
        if (v == p) continue;
        dfs(v, u);
        sum += f[v];
        mxv = max(mxv, f[v]);
    }
    f[u] = 2 * a[u] - sum;
    tmp = (sum - a[u]) * 2;
    if (f[u] < 0 || tmp < 0) puts("NO"), exit(0);
    if (sum - mxv < tmp / 2) puts("NO"), exit(0);
}

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;

    for (int i = 1; i <= n; ++i)
        scanf("%lld", a + i);
    for (int i = 1, u, v; i < n; ++i)
        scanf("%d%d", &u, &v),
        addE(u, v), addE(v, u),
        ++d[u], ++d[v];

    if (n == 2) return puts(a[1] == a[2] ? "YES" : "NO"), 0;

    int root = 1;
    while (d[root] == 1) ++root;

    dfs(root, 0);

    puts(f[root] ? "NO" : "YES");

    return 0;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  string ans = "Yes";
  if (S.size() % 2 != 0) {
    ans = "No";
  }
  for (int i = 0; i < N / 2; i++) {
    if (S.at(i) != S.at(N / 2 + i)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: usize = read();
    let mut vec: Vec<Vec<i64>> = Vec::new();
    for i in 0..n {
        vec.push((0..3).map(|_| read()).collect());
    }
    let mut dp: Vec<Vec<i64>> = Vec::new();
    for i in 0..100010 {
        dp.push(vec![0,0,0]);
    }

    for i in 0..n {
        for j in 0..3 {
            for k in 0..3 {
                if j == k {
                    continue;
                }
                dp[i+1][k] = cmp::max(dp[i+1][k], dp[i][j] + vec[i][k]);
            }
        }
    }

    let mut max = 0;
    for i in 0..3 {
        max = cmp::max(max, dp[n][i]);
    }

    println!("{}", max);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed 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 gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 18684
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
  int n, m;
  cin>>n>>m;
  int a[n];
  //long long sa[n];// mod_sa[i]= summation of a[0]~a[i]
  const int mm=m;
  map<int, int> mod_m_count;// mod_m_count[i] = # of sa[j] that satisfies sa[j] mod m = i
  //long long mod_m_count[mm];
  long long sum =0;
  long long ans =0;
  
  ans += mod_m_count[0];
  mod_m_count[0]++;
  for(int i=0; i<n; i++)
  {
    cin>>a[i];
    sum+= a[i];
    sum = sum%m;
    ans += mod_m_count[sum];
    mod_m_count[sum]++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3584
package main

import (
	"fmt"
)

func main() {
	var a, b int
	if _, err := fmt.Scan(&a, &b); err != nil {
		panic(err)
	}

	d := a / b
	f := a % b
	r := float64(a) / float64(b)
	fmt.Printf("%d %d %.5f\n", d, f, r)
}



Measured memory_bytes: 1156
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 n: usize = read();
    let m: usize = read();
    let mut arr = vec![true; n + 1];
    for _ in 0..m {
        let x: usize = read();
        arr[x] = false;
    }

    let mut dp = vec![0; n + 1];
    dp[0] = 1;
    if arr[1] {
        dp[1] = 1;
    }
    for i in 2..=n {
        if arr[i - 1] {
            dp[i] += dp[i - 1];
        }
        if arr[i - 2] {
            dp[i] += dp[i - 2];
        }
        dp[i] %= 1_000_000_007
    }
    println!("{}", dp[n]);
}


Measured memory_bytes: 2524
# include <iostream>
# include <string>
# include <set>
# include <algorithm>
# include <cmath>
# include <vector>
# include <string>
# include <map>
# include <iomanip>
# include <queue>
# include <stack>
# include <deque>

using namespace std;

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

    if( abs( a- b ) % 2 == 1 ){
        cout << "IMPOSSIBLE";
    }
    else{
        cout << (a + b ) /2;
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a, b;

    while (true) {
      a = scanner.nextInt();
      b = scanner.nextInt();
      if (a == 0 && b == 0) break;

      for (int i = 0; i < b; ++i) System.out.print("#");
      System.out.println();

      for (int i = 0; i < a - 2; ++i) {
        System.out.print("#");
        for (int j = 0; j < b - 2; ++j) System.out.printf(".");
        System.out.println("#");
      }
      for (int i = 0; i < b; ++i) System.out.print("#");
      System.out.println("\n");
    }
  }
}


Measured memory_bytes: 53120
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>

using namespace std; using ll=long long; const int INF=1e2; using P=pair<ll,ll>;

int main() {
  int n; cin>>n;
  ll a[3*n]; for(int i=0;i<3*n;i++) cin>>a[i];
  ll b[n+1]={}, c[n+1]={}, sm;
  priority_queue<ll, vector<ll>, greater<ll>> que1;
  priority_queue<ll> que2;
  for(int i=0;i<n;i++) {
    b[0] += a[i]; que1.push(a[i]);
  } sm=b[0];
  for(int i=1;i<=n;i++) {
    que1.push(a[n-1+i]); sm += a[n-1+i];
    sm -= que1.top(); que1.pop(); b[i] = sm;
  }
  for(int i=0;i<n;i++) {
    c[0] += a[3*n-1-i]; que2.push(a[3*n-1-i]);
  } sm=c[0];
  for(int i=1;i<=n;i++) {
    que2.push(a[2*n-i]); sm += a[2*n-i];
    sm -= que2.top(); que2.pop(); c[i] = sm;
  }
  /*
  for(int i=0;i<=n;i++) {
    cout<<b[i]<<" ";
  } cout<<endl;

  for(int i=0;i<=n;i++) {
    cout<<c[i]<<" ";
  } cout<<endl;
 */
  ll an=-1e18;
  for(int i=0;i<=n;i++) {
    an = max(an, b[i]-c[n-i]);
  }
  cout<<an<<endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, char, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 1000000007;

static const ll INF = 1e15;

typedef ll Weight;
struct Edge {
	int from, to;
	Weight weight;
	Edge(int src, int dst) :
		from(src), to(dst), weight(0) { }

	Edge(int src, int dst, Weight weight) :
		from(src), to(dst), weight(weight) { }
};
bool operator < (const Edge& e, const Edge& f) {
	return e.weight != f.weight ? e.weight > f.weight :
	e.from != f.from ? e.from < f.from : e.to < f.to;
}

struct UndirectionalCompare {
	bool operator() (const Edge& e, const Edge& f) const {
		if (min(e.from, e.to) != min(f.from, f.to))
			return min(e.from, e.to) < min(f.from, f.to);
		return max(e.from, e.to) < max(f.from, f.to);
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
typedef set<Edge, UndirectionalCompare> Edgeset;

struct stronglyConnectedComponents_solver {

	void visit(const Graph& g, int v, vector< vector<int> >& scc,
		stack<int>& S, vector<bool>& inS,
		vector<int>& low, vector<int>& num, int& time) {
		low[v] = num[v] = ++time;
		S.push(v); inS[v] = true;
		for(const auto& e : g[v]) {
			int w = e.to;
			if (num[w] == 0) {
				visit(g, w, scc, S, inS, low, num, time);
				low[v] = min(low[v], low[w]);
			}
			else if (inS[w])
				low[v] = min(low[v], num[w]);
		}
		if (low[v] == num[v]) {
			scc.push_back(vector<int>());
			while (1) {
				int w = S.top(); S.pop(); inS[w] = false;
				scc.back().emplace_back(w);
				if (v == w) break;
			}
		}
	}
	void stronglyConnectedComponents(const Graph& g,
		vector< vector<int> >& scc) {
		const int n = g.size();
		vector<int> num(n), low(n);
		stack<int> S;
		vector<bool> inS(n);
		int time = 0;
		rep(u, n) if (num[u] == 0)
			visit(g, u, scc, S, inS, low, num, time);
	}
};

int main(void)
{
	int v, e;
	cin >> v >> e;

	Graph g(v);
	rep(i, e) {
		int s, t;
		cin >> s >> t;
		g[s].push_back({s,t,0});
	}
	stronglyConnectedComponents_solver solver;
	vector<vector<int>> line;
	solver.stronglyConnectedComponents(g, line);
	vector<int> colors(v,0);
	for (int i = 0; i < line.size();i++) {
		for (auto j : line[i]) {
			colors[j] = i;
		}
	}
	int q;
	cin >> q;
	vector<int> ret;	
	rep(i, q) {
		int u, v;
		cin >> u >> v;
		if (colors[u] == colors[v]) {
			ret.push_back(1);
		}
		else {
			ret.push_back(0);
		}
	}
	rep(i, q) {
		cout << ret[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 4888
import numpy as np
N=int(input())
F_ab=len(str(N))
sqrt_N=int(np.sqrt(N))
for a in range(2,sqrt_N+1):
    if N%a==0:
        F_ab=min(F_ab,max(len(str(a)),len(str(N//a))))
    
print(F_ab)

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

using namespace std;

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

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

const int N = 26, D = 365;

using namespace std;
int main() {
    int d;
    cin >> d;
    vector<int> c(N), hi(D);
    vector<vector<int>> s(D, vector<int>(N));
    for (int i = 0; i < N; ++i)
        cin >> c[i];
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < N; ++j)
            cin >> s[i][j];
        hi[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();
    }
    vector<vector<int>> nxt(D, vector<int>(N, D));
    for (int i = d - 1; i > 0; --i) {
        for (int j = 0; j < N; ++j)
            if (j == hi[i])
                nxt[i - 1][j] = i;
            else
                nxt[i - 1][j] = nxt[i][j];
    }
    vector<int> ans;
    vector<int> last(N, 0);
    for (int i = 1; i <= d; ++i) {
        int maxt = 0;
        double maxg = INT_MIN;
        for (int j = 0; j < N; ++j) {
            double gain = s[i - 1][j];
            for (int k = 0; k < N; ++k)
                if (k != j) {
                    int tot = nxt[i - 1][k] - last[k];
                    int now = i - 1 - last[k];
                    double loss = c[k] * (tot * (tot - 1) - now * (now - 1));
                    gain -= loss;
                }
            if (gain > maxg) {
                maxg = gain;
                maxt = j;
            }
        }
        last[maxt] = i;
        ans.emplace_back(maxt + 1);
    }
    for (int i : ans)
        cout << i << endl;
}


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

using namespace std;

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    cout << (x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 3076
#include <cstdio>

int main() {
    //入力
    int a,b,c;
    std::scanf("%d%d%d",&a,&b,&c);
    if(a <= b && b <= c) {
        std::printf("%d %d %d",a,b,c);
    }
    else if(b <= a && a <= c) {
        std::printf("%d %d %d",b,a,c);
    }
    else if(a <= c && c <= b) {
        std::printf("%d %d %d",a,c,b);
    }
    else if(b <= c && c <= a) {
        std::printf("%d %d %d",b,c,a);
    }
    else if(c <= a && a <= b) {
        std::printf("%d %d %d",c,a,b);
    }
    else if(c <= b && b <= a) {
        std::printf("%d %d %d",c,b,a);
    }
    std::printf("\n");
    
    return 0;
}


Measured memory_bytes: 2716
#include <bits/stdc++.h>
#define lli long long int
#define MAX(A,B) A>B?A:B
#define MIN(A,B) A<B?A:B
#define gcd(A,B) __gcd(A,B)
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define modulo 998244353
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<int,double> pid;

int main()
{
    int x;
    scanf("%d",&x);
    if (!((x-3)*(x-5)*(x-7)))
        printf("YES");
    else
        printf("NO");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
ll M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
ll MOD=998244353;
const double PI = 3.141592653589793238460;
bitset<N>bs;
//vector<vector<int>>arr;

int main()
{
    int n;
    cin>>n;
    int minindex=n;
    int x;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x<=minindex)ans++;
        minindex=min(minindex,x);
    }
    cout<<ans;
}


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;
typedef pair <double,double> P;

double f (P p1, P p2) {
  return sqrt((p1.first-p2.first)*(p1.first-p2.first)+(p1.second-p2.second)*(p1.second-p2.second));
}

int main() {
  int n;
  cin>>n;
  P xy[10];
  rep(i,n) {
    double x,y;
    cin>>x>>y;
    xy[i]={x,y};
  }
  vector<int> v;
  rep(i,n) v.push_back(i);

  double ans=0;
  int cnt=0;
  do {
    rep(i,n-1) {
      ans+=f(xy[v[i]],xy[v[i+1]]);
    }
    cnt++;
  } while(next_permutation(v.begin(), v.end()));

  printf("%.10lf\n",ans/cnt);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
array = list(map(int,input().split(' ')))

left= array[0]
right = sum(array) - left

prev = 0
for i in range(0,n-1):
    diff = abs(left - right)
    left = left + array[i+1]
    right = right - array[i+1]

    if(i == 0):
        prev = diff
    else:
        if diff < prev:
            prev = diff
print(prev)


Measured memory_bytes: 86492
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,i,ans=0;
  cin >> n;
  vector<int> p(n+3,0);
  for (i=0;i<n;i++) cin >> p.at(i);
  for (i=1;i<n-1;i++) if ((p.at(i-1)-p.at(i)) * (p.at(i)-p.at(i+1)) > 0) ans++;
  cout << ans << 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;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int n;

int main(){
    string s,t;
	cin >> s >> t;
	
	int count = 0;
	
	rep(i,3){
    	if(s[i] == t[i]) count++;
    }
	
	cout << count <<endl;
	
    
    return 0;	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        
        if (S.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }
}


Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
#define N 100005

int n,x[N],l,le,ri,mid,t[20][N];
int q,a,b,ans,bates;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i=1;i<=n;i++) cin >> x[i];
	cin >> l;
	for (int i=1;i<=n;i++){
		le=i; ri=n;
		while (le<=ri){
			mid=(le+ri)>>1;
			if (x[mid]<=x[i]+l){
				t[0][i]=mid; le=mid+1;
			}else ri=mid-1;
		}
	}
	for (int i=1;(1<<i)<=n;i++){
		for (int j=1;j<=n;j++)
		t[i][j]=t[i-1][t[i-1][j]];
	}
	for (;(1<<bates)<=n;bates++);
	bates--;
	cin >> q;
	while (q--){
		cin >> a >> b; ans=0;
		if (a>b) swap(a,b);
		for (int i=bates;i>=0;i--){
			if (i&&t[i-1][a]==t[i][a]||
			a==t[i][a]) continue;
			if (t[i][a]<b){
				ans+=(1<<i); a=t[i][a];
			}
		}
		cout << ans+1 << "\n";
	}
}

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

int main() {
    vector<int> n(4), ans{1,4,7,9};
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    sort(n.begin(), n.end());
    if(n == ans)  cout << "YES" << "\n";
    else  cout << "NO" << "\n";
}


Measured memory_bytes: 256
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 a:i32 = read();
    let b:i32 = read();
    if a < b {
    println!("a < b");
    } else if a == b{
    println!("a == b");
    } else {
    println!("a > b");

    }

}


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

int main(){
  int n, m, t, d, st, sh;
  while (cin >> n >> m, n||m){
    st = 0;
    sh = 0;
    vector<int> ta, ha;
    for (int i = 0; i < n; ++i){
      cin >> t;
      ta.push_back(t);
      st += t;
    }
    for (int i = 0; i < m; ++i){
      cin >> t;
      ha.push_back(t);
      sh += t;
    }
    sort(ta.begin(), ta.end());
    sort(ha.begin(), ha.end());
    if ((st - sh) % 2) cout << -1 << endl;
    else{
      d = (sh - st) / 2;
      int i = 0;
      int j = 0;
      t = 1;
      while ((i < n) && (j < m) && t){
	if (ta[i] + d < ha[j]) ++i;
	else if (ta[i] + d == ha[j]){
	  cout << ta[i] << " " << ha[j] << endl;
	  t = 0;
	}else ++j;
      }
      if (t) cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 3024
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  uint16_t a,b,c,d,e,k;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;

  bool yay = e-a<=k;

  cout << (yay? "Yay!" : ":(") << endl;

  return 0;
}


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

for i in range(len(A)):
  if A[i]%4 == 0:
    X[2] += 1
  elif A[i]%2 == 0:
    X[1] += 1
  else:
    X[0] += 1

if 2*X[2] + 1 >= N:
  print("Yes")
elif 2*X[2] + X[1]>= N:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 20260
#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 = 1e9;

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;

  while (n > 0) {
    n /= k;
    ans++;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))



int main(void){
  int n;
  cin >> n;
  int ind[n];
  rep(i,n){
    int tmp;
	cin >> tmp;
	ind[n-tmp] = i;
  }

  multiset<int> s;
  s.insert(-1);
  s.insert(-1);
  s.insert(n);
  s.insert(n);
  s.insert(ind[0]);

  ll ans = 0;
  rep(i,n-1){
	auto x = s.insert(ind[i+1]);
	ll left1 = *x-*prev(x,1);
	ll left2 = *prev(x,1)-*prev(x,2);
	ll right1 = *next(x,1)-*x;
	ll right2 = *next(x,2)-*next(x,1);
		
	//cout << left2 << " " << left1 << " " << right1 << " " << right2 << endl;
	ans += (n-(i+1))*(left1*right2+left2*right1);
  }

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


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

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


Measured memory_bytes: 3632
#include <cstdio>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,a,b,fac[200100],inv[200100],ans;

int calc(int n,int m)
{
    return LL(fac[n+m-2])*inv[n-1]%p*inv[m-1]%p;
}

int main()
{
    scanf("%d%d%d%d",&n,&m,&a,&b);
    fac[0]=fac[1]=inv[0]=inv[1]=1;
    repu(i,2,n+m)
        inv[i]=LL(p-p/i)*inv[p%i]%p;
    repu(i,2,n+m)
        fac[i]=LL(fac[i-1])*i%p,inv[i]=LL(inv[i-1])*inv[i]%p;
    repu(i,b+1,m)
        ans=(ans+LL(calc(n-a,i))*calc(a,m-i+1))%p;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
const int N = 1e5 + 11, K = 20;
const int mod = 1e9 + 7 , inf = 2e9;
ll dp[102][N];
int w[N] , v[N];
int main()
{
#ifndef ONLINE_JUDGE
	//freopen("inp.txt", "r", stdin);
#endif
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		scanf("%d%d", w + i, v + i);
	for (int j = 0; j <= k; j++)
		if (j >= w[n - 1]) dp[n - 1][j] = v[n - 1];
	for (int i = n - 2; i >= 0; i--)
	{
		for (int j = 0; j <= k; j++)
		{
			dp[i][j] = dp[i + 1][j];
			if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[0][k];
	return 0;
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll A[3][3];
    bool B[3][3];
    for(ll i = 0; i < 3; i++)
    {
        for(ll j = 0; j < 3; j++)
        {
            cin >> A[i][j];
            B[i][j] = false;
        }
    }

    
    ll N;
    cin >> N;

    ll b[N];
    for(ll i = 0; i < N; i++)
    {
        cin >> b[i];
    }

    for(ll i = 0; i < 3; i++)
    {
        for(ll j = 0; j < 3; j++)
        {
            for(ll k = 0; k < N; k++)
            {
                if(b[k] == A[i][j])
                {
                    B[i][j] = true;
                    break;
                }
            }
        }
    }

    if(B[0][0] == true && B[0][1] == true && B[0][2] == true)cout << "Yes" << endl;
    else if(B[1][0] == true && B[1][1] == true && B[1][2] == true)cout << "Yes" << endl;
    else if(B[2][0] == true && B[2][1] == true && B[2][2] == true)cout << "Yes" << endl;
    else if(B[0][0] == true && B[1][0] == true && B[2][0] == true)cout << "Yes" << endl;
    else if(B[0][1] == true && B[1][1] == true && B[2][1] == true)cout << "Yes" << endl;
    else if(B[0][2] == true && B[1][2] == true && B[2][2] == true)cout << "Yes" << endl;
    else if(B[0][0] == true && B[1][1] == true && B[2][2] == true)cout << "Yes" << endl;
    else if(B[0][2] == true && B[1][1] == true && B[2][0] == true)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b) {
  if (a == 0) {
    return b;
  } else if (b == 0) {
    return a;
  } else {
    return gcd(b, a%b);
  }
}

int main() {
  int a, b, k, g, i;
  scanf("%d%d%d", &a, &b, &k);
  g = gcd(a, b);
  for (i = g; i > 0; i--) {
    if (a%i == 0 && b%i == 0) {
      k--;
    }
    if (k == 0) {
      break;
    }
  }
  printf("%d\n", i);
  return 0;
}


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

using namespace std;

int main() {
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= 'A' && str[i] <= 'Z') {
			str[i] += 32;
		}
		else if (str[i] >= 'a' && str[i] <= 'z') {
			str[i] -= 32;
		}
	}
	cout << str << endl;
	
	return 0;
}


Measured memory_bytes: 3156
N = int(input())
A_list = [0] * N

for i in range(N):
    A_list[i] = int(input())

A_list_sorted = sorted(A_list)

M1 = A_list_sorted[-1]
M2 = A_list_sorted[-2]

for i in range(N):
    if A_list[i] == M1:
        print(M2)
    else:
        print(M1)


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    ll cnt=0,cc=0,sum=0;
    rep(i,n){
        sum+=a[i];
        if(i%2==0&&sum<=0){
            cnt+=1-sum;
            sum=1;
        }
        else if(i%2!=0&&sum>=0){
            cnt+=sum+1;
            sum=-1;
        }
    }
    sum=0;
    rep(i,n){
        sum+=a[i];
        if(i%2!=0&&sum<=0){
            cc+=1-sum;
            sum=1;
        }
        else if(i%2==0&&sum>=0){
            cc+=sum+1;
            sum=-1;
        }
    }
    cout<<min(cnt,cc)<<endl;
    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if( (a+b)==c || (a+c)==b || (b+c)==a ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main(){
	int t;
	cin >> t;
	for(int a = 0;a < t;a++){
		int n,k,x[100000],sum;
		vector<int> vec;
		cin >> n >> k;
		for(int i = 0;i < n;i++) {
			cin >> x[i];
			if(i) vec.push_back(x[i] - x[i - 1]);
		}
		sum = x[n - 1] - x[0];
		sort(vec.begin(),vec.end(),greater<int>());
		for(int i = 0;i < min(n,k) - 1;i++){
			sum -= vec[i];
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<ll> A(N);

  ll sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  
  ll block_sum = N * (N+1LL)/ 2;

  if(sum % block_sum == 0){
    ll cnt = sum / block_sum; // 操作回数

    vector<ll> diff(N);
    for(int i = 0; i < N-1; i++){
      diff[i] = A[i] - A[i+1] + cnt;
    }

    diff[N-1] = A[N-1] - A[0] + cnt;

    ll cnt_tmp = 0;
    bool ok = true;
    for(int i = 0; i < N; i++){
      if(diff[i] % N == 0 && diff[i] / N >= 0){
        cnt_tmp += diff[i] / N;
      }else{
        ok = false;
      }
    }

    if(ok && cnt_tmp == cnt){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b
# 転倒数はどのように増えるのか？
# もとの配列の転倒数と結合したときに増える転倒数に分解する
# もとの配列の転倒数はただ単純にK回掛ければいい
# 結合したときに増える転倒数はK*(K-1)//2をかける

N, K = read_ints()
A = read_ints()

n_origin = 0  # Aの転倒数
for a, b in combinations(A, r=2):
    if a > b:
        n_origin += 1

n_append = 0  # A+Aを結合したときに転倒数がいくつ増えるか
# これは愚直に各要素にたいして、以下の数がいくつあるか数え上げてもいいが、
# 結合したときの転倒数-2*n_originでも求められそう
for a, b in combinations(A + A, r=2):
    if a > b:
        n_append += 1
n_append -= n_origin * 2
print((n_origin * K + n_append * (K - 1) * K // 2) % MOD)


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

using namespace std;

typedef long long ll;
typedef long double ld;

const ld PIE = atan2(0, -1);
const ll MOD = 1e9 + 7;
const int MAXN = 2e3 + 5;

int n;
int a[MAXN];
ll dp[MAXN][MAXN];

bool cmp(int i, int j) {
	return a[i] > a[j];
}

void solve() {
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	vector<int> indices;
	for (int i = 0; i < n; ++i) indices.push_back(i);
	sort(indices.begin(), indices.end(), cmp);
	dp[1][0] = abs(indices[0] - 0) * 1ll * a[indices[0]];
	dp[0][0] = abs(indices[0] - n + 1) * 1ll * a[indices[0]];
	for (int i = 1; i < n; ++i) {
		int ind = indices[i];
		int activeness = a[ind];
		for (int prevleft = 0; prevleft <= i; ++prevleft) {
			int lpos = prevleft, rpos = n - (i - prevleft) - 1;
			ll curval = dp[prevleft][i - 1];
			dp[prevleft][i] = max(dp[prevleft][i], curval + abs(rpos - ind) * 1ll * activeness);
			dp[prevleft + 1][i] = max(dp[prevleft + 1][i], curval + abs(lpos - ind) * 1ll * activeness);
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		ans = max(ans, dp[i][n - 1]);
	}
	cout << ans << "\n";
}

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

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

int main() {
    string s;
    cin >> s;
    vector<char> ans;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '0') {
            ans.push_back('0');
        }
        if(s[i] == '1') {
            ans.push_back('1');
        }
        if(s[i] == 'B' && ans.size() > 0) {
            ans.pop_back();
        }
    }
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N; int last[202020]; ll dp[202020] = {};
  rep(i, 202020){
    last[i] = -1;
  }
  dp[0] = 1; 
  for(int i=0; i<=N-1; i++){
    int a; cin >> a; a--;
    if(i==0){
      last[a] = i; continue;
    }
    if(last[a]!=-1 && last[a]!=i-1) dp[i] = dp[i-1] + dp[last[a]];
    else dp[i] = dp[i-1];
    dp[i]%=mod;
    //cout << dp[i] << endl;
    //cout << last[a] << endl;
    last[a] = i;
  }
  cout << dp[N-1] << endl;
}
      

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000003
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
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; }
using namespace std;

//AGC034
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    string s; cin>>s;
    bool scan=true,fcan=true;
    for(int i=a-1; i<c-1; i++){
        if(s[i]=='#' and s[i+1]=='#')scan=false;
    }
    for(int i=b-1; i<d-1; i++){
        if(s[i]=='#' and s[i+1]=='#')fcan=false;
    }

    if(!scan or !fcan)cout<<"No"<<endl;
    else if(c<d){
        cout<<"Yes"<<endl;
    }else{
        for(int i=b-2; i<d-1; i++){
            if(s[i]=='.' and s[i+1]=='.' and s[i+2]=='.'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 592