akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1e9;

int N;
int main(){
  while(cin>>N,N){
	VVI tm(N, VI(3));
	REP(i,N) REP(j,3) cin >> tm[i][j];
	VVI clk(N);
	REP(i,N){
	  SORT(tm[i]);
	  do{
		REP(d,60){
		  if((tm[i][0] + d)%5 != (tm[i][1]+d)%60/12) continue;
		  int t = ((tm[i][0]+d)%60)/5*60*60+(tm[i][1]+d)%60*60+(tm[i][2]+d)%60;
		  clk[i].PB(t);
		}
	  }while(next_permutation(ALL(tm[i])));
	}

	vector<vector<PII>> dp(2);
	REP(i,SZ(clk[0]))
	  dp[0].PB(MP(0,clk[0][i]));

	int crt = 0, nxt = 1;
	FOR(i,1,N){
	  dp[nxt].assign(SZ(clk[i]), MP(INF,INF));
	  REP(j,SZ(clk[i])){
		REP(k,SZ(dp[crt])){
		  int s = min(dp[crt][k].second, clk[i][j]);
		  int d = max(dp[crt][k].first + dp[crt][k].second, clk[i][j]) - s;
		  dp[nxt][j] = min(dp[nxt][j], MP(d, s));		  
		}
	  }
	  swap(crt, nxt);
	}
	
	PII ans = MP(INF, INF);
	REP(i,SZ(dp[crt])){
	  ans = min(ans, dp[crt][i]);
	}

	int s = ans.second;
	int e = ans.first + ans.second;
	printf("%02d:%02d:%02d %02d:%02d:%02d\n",
		   s/3600, s/60%60, s%60,
		   e/3600, e/60%60, e%60);
  }
  
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int base = 0, out = 0, point = 0;
		while (out != 3) {
			string s;
			cin >> s;
			if (s == "HIT") {
				if (base == 3) {
					point++;
				}
				else if (base < 3) {
					base++;
				}
			}
			else if (s == "HOMERUN") {
				point += base + 1;
				base = 0;
			}
			else {
				out++;
			}
		}
		cout << point << endl;
	}
}


Measured memory_bytes: 3140
import math

S_list = list(input().split('LR'))
for i in range(len(S_list)):
    if len(S_list) == 1:
        break
    if i==0:
        S_list[i] = S_list[i]+'L'
    elif i==len(S_list)-1:
        S_list[i] = 'R' + S_list[i]
    else:
        S_list[i] = 'R' + S_list[i] + 'L'

ans = []
for S in S_list:
    cnt = [0]*len(S)
    for i in range(len(S)-1):
        if S[i]+S[i+1]=='RL':
            R_idx = i
            L_idx = i+1
            break
    num_odd = math.floor(len(S)/2)
    num_even = math.ceil(len(S)/2)
    if R_idx%2==0:
        cnt[R_idx] = num_even
        cnt[L_idx] = num_odd
    else:
        cnt[R_idx] = num_odd
        cnt[L_idx] = num_even
    ans += cnt
print(*ans)

Measured memory_bytes: 12564
#include <iostream>
#include <set>
#include <array>
#include <string>

int main() {
	int n, q;
	std::string s;
	std::cin >> n >> s >> q;

	std::array<std::set<int>, 26> sets;
	for (int i = 0; i < n; ++i)
		sets[s[i] - 'a'].insert(i);

	for (int i = 0; i < q; ++i) {
		int kind;
		std::cin >> kind;

		if (kind == 1) {
			int idx;
			char c;
			std::cin >> idx >> c;
			--idx;

			sets[s[idx] - 'a'].erase(idx);
			s[idx] = c;
			sets[c - 'a'].insert(idx);
		}
		if (kind == 2) {
			int l, r;
			std::cin >> l >> r;
			--l, --r;

			int ans = 0;
			for (int j = 0; j < 26; ++j)
				if (sets[j].upper_bound(r) != sets[j].lower_bound(l))
					++ans;
			
			std::cout << ans << std::endl;
		}
	}
}

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

int main(){
    int n;
    vector<int> home;

    cin>>n;

    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        home.push_back(x);
    }

    sort(home.begin(),home.end());

    cout<<home[n-1] - home[0]<<"\n";


}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a;
  int i,j,c=0;
  scanf("%d",&a);
  for(i=1;i<=a;i+=2)
  {
    int k=0;
    for(j=1;j<=i;j++)
    {
      if(i%j == 0) k++;
    }
    if(k==8) c++;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        if A[i+1] < B[i]:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += B[i]
            A[i+1] -= B[i]
else:
    print(ans)


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

foods = []
for i in range(m): foods.append(True)

for i in range(n):
    k = list(map(int, input().split()))
    k.pop(0)
    for j in range(1,m+1):
        if j not in k: foods[j-1] = False

print(foods.count(True))

Measured memory_bytes: 3060
A = list(input())
B = list(input())
C = list(input())

turn = "a"
while True:
    if turn == "a":
        if len(A) == 0:
            print("A")
            exit()
        turn = A[0]
        A = A[1:]
    elif turn == "b":
        if len(B) == 0:
            print("B")
            exit()
        turn = B[0]
        B = B[1:]
    elif turn == "c":
        if len(C) == 0:
            print("C")
            exit()
        turn = C[0]
        C = C[1:]


Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const lint mod=998244353;

void add(lint &x,lint y){
  x=(x+y)%mod;
}

map<string,lint>memo;


lint f(const string &s){
  int n=s.length();
  if(n==0){
    return 1;
  }
  if(memo.count(s))return memo[s];
  lint ans=0;
  int fac=s[n-1]=='1'?2:1;
  add(ans,fac*f(s.substr(0,n-1)));
  for(int k=2;k<=n;++k){
    for(int i=1;i*k<=n;++i){
      lint tmp=f(s.substr(0,n-i*k));
      string res(i,'1');
      rep(j,k){
	string t=s.substr(n-i*k+i*j,i);
	rep(l,i)
	  if(t[l]=='0')
	    res[l]='0';
      }
      tmp=tmp*f(res)%mod;
      add(ans,tmp);
    }
  }
  return memo[s]=ans;
}

int main(){
  string s;
  cin>>s;
  cout<<f(s)<<endl;
}


Measured memory_bytes: 5504
L = int(input())
A = [int(input()) for i in range(L)]
DP = [[0 for _ in range(5)] for _ in range(L+1)]

def cost(j,a):
    if(j == 0 or j == 4):
        return a
    elif(j == 1 or j == 3):
        if(a==0):
            return 2
        else:
            return a%2
    else:
        return (a+1)%2


for i in range(L):
    for j in range(5):
        DP[i+1][j] = min(DP[i][:(j+1)]) + cost(j,A[i])

print(min(DP[L]))

Measured memory_bytes: 74064
#pragma GCC optimize ("03")
#pragma GCC target("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"
 
const int mod=10e7+7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	int maxe=*max_element(a, a+n);
	int mine=*min_element(a, a+n);
	cout << maxe-mine;
}


Measured memory_bytes: 3512
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(string S) {
    return 7 - ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"].countUntil(S);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(S);
    else {
        auto ans = solve(S);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


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


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

  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.size()<=k) cout << s << endl;
  else{
    rep(i,k) cout << s[i];
    cout << "..." << endl;
  }
  
  
  return 0;
    

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

ll N, C;
vector<ll> x(100001, 0);
vector<ll> v(100001, 0);

int main(void){
    
    scanf("%lld %lld", &N, &C);
    for(int i = 0; i < N; ++i){
        ll a, b; scanf("%lld %lld", &a, &b);
        x[i] = a, v[i] = b;
    }
    
    ll sum = 0;
    vector<P> cal;
    for(int i = 0; i < N; ++i) sum += v[i], cal.push_back(make_pair(x[i], sum));
    sum = 0;
    vector<P> revcal;
    for(int i = N - 1; i >= 0; --i) sum += v[i], revcal.push_back(make_pair(C - x[i], sum));
    
    sum = 0;
    vector<ll> g;
    for(int i = 0; i < N; ++i){ sum = max(sum, cal[i].second - cal[i].first); g.push_back(sum); }
    sum = 0;
    vector<ll> t;
    for(int i = 0; i < N; ++i){ sum = max(sum, revcal[i].second - revcal[i].first); t.push_back(sum); }
    
    ll ans = 0;
    ans = max(*max_element(g.begin(), g.end()), *max_element(t.begin(), t.end()));
    for(int i = 0; i < N - 1; ++i){
        ans = max(ans, revcal[i].second - (revcal[i].first * 2) + g[(N - 1) - (i + 1)]);
        ans = max(ans, cal[i].second - (cal[i].first * 2) + t[(N - 1) - (i + 1)]);
    }
    printf("%lld\n", ans);
    
    return 0;
}

Measured memory_bytes: 8048
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {
	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		long a = ir.nextLong();
		long b = ir.nextLong();
		out.println((a * b % 2 == 0) ? "Even" : "Odd");
	}

	public static void main(String[] args) {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}

	static void tr(Object... o) {
		out.println(Arrays.deepToString(o));
		out.flush();
	}
}


Measured memory_bytes: 22868
# ALDS1_5_D

class mergeSort:
    def __init__(self, a):
        self.a = a

    def mergeSort(self, left, right):
        if left + 1 < right: # rightはリストの末尾 +1
            middle = (left + right) // 2
            v1 = self.mergeSort(left, middle)
            v2 = self.mergeSort(middle, right)
            v3 = self.merge(left, middle, right)
            return v1 + v2 + v3
        else:
            return 0
    
    def merge(self, left, mid, right):
        l = [a[i] for i in range(left, mid)]
        r = [a[i] for i in range(mid, right)]
        l.append(float("inf"))
        r.append(float("inf"))
        p = 0 # l's
        q = 0 # r's
        cnt = 0
        for k in range(left, right):
            if l[p] > r[q]: # 反転することになる
                self.a[k] = r[q]
                if l[p] != float("inf"):
                    cnt += (mid - left) - p
                q += 1
            else:
                self.a[k] = l[p]
                p += 1
        return cnt

n = int(input())
a = list(map(int, input().split()))
ms = mergeSort(a)
print(ms.mergeSort(0, n))


Measured memory_bytes: 28356
A,B,C,D = map(int,input().split())
pBC = B//C
pAC = (A-1)//C
pBD = B//D
pAD = (A-1)//D
def gcd(a,b):
  while b!=0:
    a,b = b,a%b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)
CDlcm = lcm(C,D)
pBCD = B//CDlcm
pACD = (A-1)//CDlcm
ans =(B - A + 1) - ((pBC - pAC) + (pBD - pAD) - (pBCD - pACD))
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int Next[N][26],F[N],G[N];
char a[N];int n,k,i,now;
int main(){
	scanf("%s",a+1);n=strlen(a+1);
	F[n]=1;G[n]=0;
	for (k=0;k<26;k++) Next[n][k]=n+1;
	for (i=n-1;i>=0;i--){
		memcpy(Next[i],Next[i+1],sizeof(Next[i+1]));
		Next[i][a[i+1]-'a']=i+1;F[i]=1e9;
		for (k=0;k<26;k++){
		  now=Next[i][k]==n+1?1:F[Next[i][k]]+1;
		  if (now<F[i])
		    F[i]=now,G[i]=k;
		}
		//printf("%d %d %d\n",i,F[i],G[i]);
	}
	for (i=0;i<=n;i=Next[i][G[i]])
	  printf("%c",G[i]+'a');
}

Measured memory_bytes: 22272
A,B,C,D,E,F = map(int,input().split())

waters = set()
for wb in range(0,F+1,100*B):
    wa = 0
    while wa + wb <= F:
        waters.add(wa + wb)
        wa += 100*A
waters.remove(0)

sugars = set()
for sd in range(0,F+1,D):
    sc = 0
    while sc + sd <= F:
        sugars.add(sc + sd)
        sc += C

best = -1
best_w = best_s = 0
for w in sorted(waters):
    for s in sorted(sugars):
        if 100*s > w*E: continue
        if w+s > F: continue
        if best < 100*s / (w+s):
            best = 100*s / (w+s)
            best_w = w
            best_s = s

print(best_w+best_s, best_s)

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int h,w; cin >> h >> w;
  string ans;
  for(int i=0;i<h;i++){
    cin >> ans;
  	cout << ans <<endl;
  	cout << ans <<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	int ans = 0;
	int N, H, W;
	cin >> N >> H >> W;
	int A, B;
	for (int i = 0; i < N; i++) {
		cin >> A >> B;
		if (A >= H && B >= W) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<math.h>

using namespace std;
#define ll long long
#define pb push_back
#define ld long double
#define mod 1000000007
ll cd(ll a,ll b)
{
	if(a==0)return b;
	else if (b==0)return a;
	else return cd(b,a%b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll x,k,d;
	cin>>x>>k>>d;
	if(x<0)x=-x;
	if(x/d>=k)
	{
		cout<<x-k*d<<endl;
	}
	else
	{
		ll cor=x-(x/d)*d;
		ll rem=k-x/d;
		if(rem%2==0)cout<<cor<<endl;
		else
		{
			cout<<d-cor<<endl;
		}
		
	}
	return 0;
	
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int n, m;

  while (cin >> n >> m) {
    if (!n && !m) { break; }
    vector<int> p(n+1, 0);
    rep(i, n) { cin >> p[i]; }

    vector<int> sum_two;

    rep(i, n+1) rep(j, n+1) sum_two.push_back(p[i]+p[j]);
    sort(sum_two.begin(), sum_two.end());

    int ans = 0;
    rep(a, n) {
      rep(b, n) {
        int sum = p[a]+p[b];
        if (sum <= m) {
          auto it = upper_bound(sum_two.begin(), sum_two.end(), m-sum); 
          if (it != sum_two.begin()) { --it; }
          ans = max(ans, sum+(*it));
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool winner = true;
	while(a > 0 && c > 0){
		c -= b;
		if(c <= 0 ) break;
		a -= d;
		if(a <= 0){
			winner = false;
			break;
		}
	}
	if(winner) cout << "Yes" << endl;
	else cout << "No" << endl;	

	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
struct node
{
    string a;
}s[1005];
int l;
bool cmp(node x,node y)
{
    for(int i=0;i<l;i++)
    {
        if(x.a[i]!=y.a[i])
            return x.a[i]<y.a[i];
    }
    return x.a[0]<y.a[0];
}
int main()
{
    int n;
    cin>>n>>l;
    for(int i=0;i<n;i++) cin>>s[i].a;
    sort(s,s+n,cmp);
    for(int i=0;i<n;i++) cout<<s[i].a;
    printf("\n");
}


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


int main(){
	int n;
	while(cin>>n&&n){
		vector<int> pipe,joint;
		for(int i=0;i<n;i++){
			int a;
			cin>>a;
			pipe.push_back(a);
		}
		for(int i=0;i<n-1;i++){
			int a;
			cin>>a;
			joint.push_back(a);
		}
		int sum=accumulate(pipe.begin(),pipe.end(),0);
		unsigned int m=n;
		unsigned int ans=m*sum;
		sort(joint.begin(),joint.end(),greater<int>());
		for(int i=0;i<n-1;i++){
			m--;
			sum+=joint[i];
			ans=max(ans,m*sum);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1860
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int H, W, D;  //行・列・間隔
vector<P> A(90010);  //A[i]: iの数値マスの座標
vector<long long> C(90010);  //魔力消費累積和
int Q;  //クエリ数
vector<P> LR(100010);  //各クエリ格納

void CumS(int d){
  for(int i = d+1; i <= H * W; i++)
    C[i] = C[i-d] +
                 abs(A[i].first - A[i-D].first) +
                 abs(A[i].second - A[i-D].second);
}

void Query(int q){
  for(int i = 0; i < q; i++){
    int r = LR[i].second; int l = LR[i].first;
    cout << C[r] - C[l] << endl;
  }
}


int main(){
  cin >> H >> W >> D;
 
  int a; 
  for(int i = 1; i <= H; i++){ for(int j = 1; j <= W; j++){ 
      cin >> a; A[a] = {i, j};  //数値aのマスの座標(i,j)
  }}

  cin >> Q;
  for(int i = 0; i < Q; i++) 
    cin >> LR[i].first >> LR[i].second;  //クエリ入力

  CumS(D);  //累積和の計算
  Query(Q); //各クエリに対する出力

  return 0;
}





Measured memory_bytes: 3328
#include<stdio.h>
#define INFTY 1000000000
#define MAX 500000

int cnt=0,A[MAX];

void merge(int A[], int left, int mid, int right){
  int n1,n2,i,j,k;
  int L[MAX],R[MAX];
  n1 = mid - left;
  n2 = right - mid;
  
    
   for(i = 0;i<n1;i++){
     L[i] = A[left + i];
   }
 for(i = 0;i<n2;i++){
   R[i] = A[mid + i];
 }
 L[n1] = INFTY;
 R[n2] = INFTY;
    i = 0;
    j = 0;
    for(k = left;k<right;k++){
      cnt++;
      if(L[i] <= R[j]){
	A[k] = L[i];
	i++;
      }
      else {
	A[k] = R[j];
	j++;
	}
    }
}

void mergeSort(int A[], int left, int right){
  int mid =0;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
      }
}
int main(){

  int i,n;
 
  scanf("%d",&n);

  for(i=0;i<n;i++){
      scanf("%d",&A[i]);
  }
  
  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i != n-1) printf(" ");
  }
 
  printf("\n"); 
  printf("%d\n",cnt);
  
  return 0;
  
}

  
  

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A, B, C;
    cin >> A >> B >> C;
    int k = 0;
    for (; k < 500000000; ++k) {
        if (A & 1 || B & 1 || C & 1) {
            break;
        }
        ll a = (B + C) / 2, b = (A + C) / 2, c = (A + B) / 2;
        A = a;
        B = b;
        C = c;
    }

    cout << (k == 500000000 ? -1 : k) << endl;
}


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

int main(){
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)
    cout<<"Possible"<<endl;
    else
    cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int x,a,b;cin>>x>>a>>b;
  if(b<=a)cout<<"delicious"<<endl;
  else if(b-a<=x)cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    questions = []
    for i in range(1, len(inputs)):
        questions.append(string_to_int(inputs[i]))

    cumulative_sum = [0]
    for i in range(0, len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            cumulative_sum.append(cumulative_sum[-1] + 1)
        else:
            cumulative_sum.append(cumulative_sum[-1])

    results = []
    for [start, end] in questions:
        results.append(cumulative_sum[end-1] - cumulative_sum[start-1])

    return results


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [_, N] = string_to_int(input())
    ret = solve(inputs(N+1))
    for r in ret:
        print(r)
    # print(ret)


Measured memory_bytes: 41252
from collections import Counter
n = int(input())
S = [input() for _ in range(n)]
s_counters = [Counter(s) for s in S]
base = s_counters[0]
for i in range(1, n):
    base = base & s_counters[i]
ans = []
for k, v in base.items():
    ans += (k * v)
print("".join(sorted(ans)))

Measured memory_bytes: 3436
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func doGoBack(board []string, i, j int, prev rune) bool {
	switch {
	case prev == 'D' && j > 0 && board[i][j-1] == '#':
		return true
	case prev == 'R' && i > 0 && board[i-1][j] == '#':
		return true
	default:
		return false
	}
}

func canGoDown(board []string, h int, i, j int) bool {
	switch {
	case i < h-1 && board[i+1][j] == '#':
		return true
	default:
		return false
	}
}

func canGoRight(board []string, w int, i, j int) bool {
	switch {
	case j < w-1 && board[i][j+1] == '#':
		return true
	default:
		return false
	}
}

func dfs(board []string, h, w int, i, j int, prev rune) bool {
	switch {
	case i == h-1 && j == w-1 && !doGoBack(board, i, j, prev):
		return true
	case doGoBack(board, i, j, prev):
		return false
	case canGoDown(board, h, i, j) && canGoRight(board, w, i, j):
		return false
	case canGoDown(board, h, i, j):
		return dfs(board, h, w, i+1, j, 'D')
	case canGoRight(board, w, i, j):
		return dfs(board, h, w, i, j+1, 'R')
	default:
		return false
	}
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	h, w := nextInt(), nextInt()

	board := make([]string, h)
	for i := 0; i < h; i++ {
		sc.Scan()
		board[i] = sc.Text()
	}

	switch {
	case dfs(board, h, w, 0, 0, 'S'):
		fmt.Println("Possible")
	default:
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 640
import math

N, A = list(map(int, input().split()))
dist = []
for i in range(N):
  dist.append(list(map(int, input().split())))
  
counter = 0
for i in range(N):
  if math.sqrt(dist[i][0]**2 + dist[i][1]**2) <= A:
    counter += 1

print(str(counter))
  

Measured memory_bytes: 45428
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int e[4];
    
    for(int i=0; i<4; i++) cin >> e[i];
    sort(e, e+4);
    
    //for(int i=0; i<4; i++) cout << e[i] << endl;
    
    if(e[0]==e[1] && e[2]==e[3]) cout << "yes" << endl;
    else cout << "no" << endl;
    
    return 0;
}

Measured memory_bytes: 3116
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 5005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

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

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	char S[MAX_N];
	scanf("%s", S);
	int N = strlen(S);
	int count[2] = { 0 };
	for (int i = 0; i < N; i++) count[S[i] - '0']++;
	printf("%d\n", min(count[0], count[1]) << 1);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{

	int w, h, i, d;

	while (1)
	{
		scanf("%d %d", &w, &h);
		if (w + h == 0)
		{
			return 0;
		}

		for (i = 0; i < w; i++){

			for (d = 0; d <  h; d++)
			{
				printf("#");
			}
			printf("\n");


		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};



int32_t main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif 

int a;
cin>>a;
cout<<a+a*a+a*a*a<<"\n";



}





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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    mat A(N, vec(32));
    REP(i,0,N) {
        ll a;
        cin >> a;
        REP(j,0,32) {
            A[i][j] += a >> j;
        }
    }
    vec sum(32);
    REP(i,0,N) {
        REP(j,0,32) {
            sum[j] += A[i][j];
        }
    }
    REP(j,0,32) sum[j] %= 2;

    ll b;
    REP(i,0,N) {
        b = 0;
        REP(j,0,32) b += ((A[i][j] + sum[j]) % 2) << j;
        PR(b);
    }


    return 0;
}

/*



*/

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


int N;
vector<int> H;


void input() {
    cin >> N;
    H = vector<int>(N);
    rep(i, N) cin >> H[i];
}


int main() {
    input();
    int ans = 0;
    for (int i = 1; i < N; i++) {
        if (H[i-1] > H[i]) {
            ans += H[i-1] - H[i];
        }
    }
    ans += H.back();
    cout << ans << endl;
}


Measured memory_bytes: 256
def make_key(a, b):
    return str(a) + '-' + str(b)


N = int(input())
nums = {}
for i in range(1, 10):
    for j in range(1, 10):
        nums[make_key(i, j)] = 0

ans = 0
for n in range(1, N + 1):
    strn = str(n)
    if strn[-1] != '0':
        key = make_key(strn[0], strn[-1])
        nums[key] += 1


for key, value in nums.items():
    a, b = map(int, key.split('-'))
    if a == b:
        ans += value ** 2
    else:
        key2 = make_key(b, a)
        ans += value * nums[key2]

print(ans)

Measured memory_bytes: 40556
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * https://abc049.contest.atcoder.jp/tasks/arc065_b
 */
public class Main {


	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int L = Integer.parseInt(sc.next());
		Node[] nodeList1 = new Node[N];
		Node[] nodeList2 = new Node[N];
		for(int i=0; i<N; i++){
			nodeList1[i] = new Node(i);	
			nodeList2[i] = new Node(i);
		}
		for(int i=0; i<K; i++){
			int x = Integer.parseInt(sc.next())-1;
			int y = Integer.parseInt(sc.next())-1;
			unite(nodeList1, x, y);
		}
		for(int i=0; i<L; i++){
			int x = Integer.parseInt(sc.next())-1;
			int y = Integer.parseInt(sc.next())-1;
			unite(nodeList2, x, y);
		}
		sc.close();
		
		Map<String,Integer> map = new HashMap<>();
		String[] key = new String[N];
		for(int i=0; i<N; i++){
			int a = findRoot(nodeList1, i).id;
			int b = findRoot(nodeList2, i).id;
			key[i] =  a+"."+b;
		}
		for(int i=0; i<N; i++){
			if(map.containsKey(key[i])){
				map.put(key[i], map.get(key[i])+1);
			}else{
				map.put(key[i], 1);
			}
		}
		
		for(int i=0; i<N; i++){
			System.out.println(map.get(key[i]));
		}
	}
	
	static class Node{
		int id;
		int height = 0;
		Node parent;
		Node left, right;
		Node(int id){
			this.id = id;
			this.parent = this;
		}
	}
	
	static boolean isUnion(Node[] nodeList, int id1, int id2){
		return findRoot(nodeList, id1) == findRoot(nodeList, id2);
	}
	
	static void unite(Node[] nodeList, int id1, int id2){
		Node node1 = findRoot(nodeList, id1);
		Node node2 = findRoot(nodeList, id2);
		if(node1==node2) return;
		if(node1.height==node2.height){
			node2.parent = node1;
			node1.height++;
		}else if(node1.height>node2.height){
			node2.parent = node1;
		}else{
			node1.parent = node2;
		}
	}
	
	static Node findRoot(Node[] nodeList, int id){
		Node node = nodeList[id];
		while(node.parent != node){
			node = node.parent;
		}
		return node;
	}
	
}

Measured memory_bytes: 128576
#include<bits/stdc++.h>
using namespace std;
string a;
int b[15],q;
int main()
{
     cin>>a;
     for(int i=0;i<a.size();i++)
     {
        if(a[i]=='0')
		{
		 q++;
		 b[q]=0;
		} 
        if(a[i]=='1')
		{
		 q++;
		 b[q]=1;
		}  
        if(a[i]=='B'&&q>=1)
		q--; 
     }    
    for(int i=1;i<=q;i++)
	cout<<b[i];
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

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

ll digitcal(ll x){
  ll n=0;
  while(x>0){
    x/=10;
    n++;
  }
  return n;
}

int main() {
  ll n;
  cin>>n;
  ll ans=100;
  for(ll i=1;i<=sqrt(n);i++){
    if(n%i==0){
      ll temp=max(digitcal(i),digitcal(n/i));
      ans=min(ans,temp);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3648
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	msi mp;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}






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

int main() {
  ll ans=0,n,tmp=0;
  string s;
  char c;
  cin >> s;
  n=sz(s);
  rep(i,n){
  	c= (i%2==0) ? '0' : '1';
  	if(s.at(i)!=c) tmp++;
  }
  ans=min(tmp,n-tmp);
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
void dfs(ll x,ll d,ll c, vector<vector<ll>> &g, vector<ll> &ans,vector<ll> &mx)
{
  if(mx[x]>=d)return;
  mx[x]=d;
  if(ans[x]==0)ans[x]=c;
  for (auto p : g[x])
  {
    dfs(p,d-1,c,g,ans,mx);
  }
  return;
}
int main()
{
ll n,m;
cin >> n >> m ;
vector<vector<ll>> g(n);
vector<ll> ans(n,0);
vector<ll> mx(n,-1);
rep(i, m)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1); //無向辺
}
ll q ;
cin >> q ;
vector<vector<ll>> que(q, vector<ll>(3,0) );
rep(i,q){
  cin >> que[q-i-1][0] >> que[q-i-1][1] >> que[q-i-1][2] ;
}
rep(i,q){
  dfs(que[i][0]-1,que[i][1],que[i][2],g,ans,mx);
}
for(auto an:ans)cout << an << endl;
return 0;
}

Measured memory_bytes: 15860
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String s = in.next();
        int f=0;
        for(int i=0;i<3;i++) if(s.charAt(i)==s.charAt(i+1)) f=1;
        out.println(f==0?"Good":"Bad");
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21332
#include <stdio.h>
int parent(int);
int left(int);
int right(int);
  
int main(){
  int i,res,A[251];
  scanf("%d",&res);
  for(i=1; i<=res; i++){
    scanf("%d",&A[i]);
}

  for(i=1; i<=res; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1){printf("parent key = %d, ",A[parent(i)]);}
    if(left(i) <= res){printf("left key = %d, ",A[left(i)]);}
    if(right(i) <= res){printf("right key = %d, ",A[right(i)]);}
    printf("\n");
  }


   return 0;
}

int parent(int p){
  return p/2;

}

int left(int l){
  return l*2;
}

int right(int r){
  return (r*2)+1;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(void) {
	int count=0;
	string str;
	cin >> str;

	for (int i = 0; i < 3; i++) {
		if (str[i] == '1')
			count++;
	}


	cout << count << endl;

	return 0;
}

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

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

    vector<long long int> xb(n), yb(n);
    vector<pair<long long int, long long int>> ball;
    long long int amax = 0, amin = 1e9 + 1;
    
    for(int i=0; i<n; i++){
        long long int x, y;
        cin >> x >> y;
        if(x < y) swap(x,y);
        xb[i] = x;
        yb[i] = y;

        amax = max(amax, x);
        amin = min(amin, y);
    }

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    multiset<long long int> blue;
    vector<long long int> draw_max, draw_min;
    for(int i=0; i<n; i++){
        if(xb[i] == amax){ draw_min.push_back(yb[i]); blue.insert(yb[i]); continue; }
        if(yb[i] == amin){ draw_max.push_back(xb[i]); blue.insert(xb[i]); continue; }

        ball.push_back({yb[i], xb[i]}); blue.insert(yb[i]);
    }
    bool flag = false;
    if(draw_min.size() == 1 && draw_min[0] == amax) flag = true;

    sort(xb.begin(),xb.end());
    sort(yb.begin(),yb.end());

    // case(1) amax = Rmax, amin = Bmin
    long long int ans = (xb[n-1]-xb[0]) * (yb[n-1]-yb[0]);

    // case(2) amax = Rmax, amin = Rmin (and Bmax != amax, Bmin != Bmin)
    if(flag == false){
        sort(ball.begin(), ball.end());

        long long int bmax = *prev(blue.end());
        long long int bmin = *blue.begin();
        long long int diff = bmax - bmin;

        for(auto b : ball){
            blue.erase(blue.find(b.first));
            blue.insert(b.second);

            bmax = *prev(blue.end());
            bmin = *blue.begin();
            diff = min(diff, bmax - bmin);
        }
        ans = min(ans, (amax - amin) * diff);
    }

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

Measured memory_bytes: 18908
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;

int n, m, q;
vector<int> g[100005];
int color[100005];
int f[100005], vv[100005], dd[100005], cc[100005];

void dfs(int v, int d, int c) {
	if (f[v] >= d) return;
	if (!color[v]) color[v] = c;
	f[v] = d;
	FOR(i, g[v].size()) {
		dfs(g[v][i], d-1, c);
	}
	return;
}


int main(int argc, char const *argv[]) {
	cin >> n >> m;

	FOR(i, m) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	cin >> q;
	FOR(i, q) {
		cin >> vv[i] >> dd[i] >> cc[i];
	}
	fill(f, f+n+1, -1);
	fill(color, color+n+1, 0);
	for (int i = q-1; i >= 0; i--) {
		dfs(vv[i], dd[i], cc[i]);
		// FOR(j, n) cout << color[j+1] << " ";
		// cout << endl;
	}
	for (int i = 1; i <= n; i++) cout << color[i] << endl;
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t,n;
    cin>>t;
    cin>>n;
    int*arr=new int[n];
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
    }
    int sum=0;

    for(int i=0;i<n;i++)
    {
    	sum+=arr[i];
    }
    if(sum>t)
    	cout<<-1;
    else
    	cout<<t-sum;
   
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int a = 1; a <= n; a++){
        ans += (n+a-1)/a-1;
    }
    cout << ans << endl;
    return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n,m;
    cin >> n >> m;

    int ans = 0;
    if(n>1) ans += ((n-1)*n)/2;
    if(m>1) ans += (m*(m-1))/2;

    cout << ans << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  bool flag = false;
  bool s = false;
  int ans = 0;
  REP(i, N - 1) {
    if(s == false) {
      if(A[i] < A[i + 1]) {
        flag = true;
        s = true;
        continue;
      }
      else if(A[i] > A[i + 1]) {
        flag = false;
        s = true;
        continue;
      }
      else if(A[i] == A[i + 1]) {
        continue;
      }
      s = true;
    }
    if(flag == true) {
      if(A[i] > A[i + 1]) {
        ans++;
        s = false;
      }
    } else {
      if(A[i] < A[i + 1]) {
        ans++;
        s = false;
      }
    }
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
int main() {
	string str, st, s;
	cin >> str >> st >> s;
	if (str[distance(str.begin(), str.end()) - 1] == st[0]) {
		if (st[distance(st.begin(), st.end()) - 1] == s[0]) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}

Measured memory_bytes: 256