akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a;
	cin>>b;
	if(a=="H"&&b=="H"){
	
		printf("H\n");
}
	else if(a=="D"&&b=="D"){
	
	printf("H\n");
}
	else{
	
		printf("D\n");
	
}
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
	public static void Main()
	{
		while (true) {
			var line = Console.ReadLine().Split(' ');
			var a = int.Parse(line[0]);
			var b = int.Parse(line[2]);
			if (line[1] == "?")
			{
				break;
			}
			switch (line[1]) {
				case "+": Console.WriteLine(a + b); break;
				case "-": Console.WriteLine(a - b); break;
				case "/": Console.WriteLine(a / b); break;
				case "*": Console.WriteLine(a * b); break;

			}

		}
	}
}


Measured memory_bytes: 17928
from collections import Counter

N,M=map(int,input().split())
A=list(map(int,input().split()))

B=[0]
for Ai in A:
    B.append((B[-1]+Ai)%M)

C=Counter(B)
v=dict(C).values()
ans=sum([x*(x-1)//2 for x in v])

# print(B)
# print(C)
# print(v)
print(ans)

Measured memory_bytes: 63256
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)


n = int(input())
a = list(map(int, input().split()))

ans = 10 ** 9
for i in range(n - 1):
    ans = min(ans, gcd(a[i], a[i + 1]))

print(ans)

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

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

  if ( A == B ){
    cout << C << endl;
  }
   else if ( A == C ) {
     cout << B << endl;
   }
  else {
  cout << A << endl;  
}
}


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

int main() {
  int N;
  cin >> N;
  
  for(int i=0; i<N; i++){
    string co;
    cin >> co;
    if(co == "Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i != N-1)
      continue;
    else
      cout << "Three" << endl;
  }
}

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

int main(){
    string s;
    cin >> s;
    int ans = 700;
    if(s[0] == 'o') ans += 100;
    if(s[1] == 'o') ans += 100;
    if(s[2] == 'o') ans += 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		try{
			int[][] intNX = new int[50][2];
			int intLength =0;
			for(int i =  0; true; i++){
				String[] strLine = insBR.readLine().split(" ");
				if(!"0".equals(strLine[0]) || !"0".equals(strLine[1])){
					for(int j = 0; j < strLine.length; j++){
						intNX[i][j] = (Integer.parseInt(strLine[j]));
					}
				}else{
					break;
				}
				intLength++;
			}

			int intSum = 0;
			int[] intCount = new int[intLength];

			for(int h = 0; h < intLength; h++){
				for(int i = 1; i <= intNX[h][0] - 2; i++){
					for(int j = i + 1; i < j && j <= intNX[h][0] - 1; j++){
						for(int k = j + 1; j < k && k <= intNX[h][0]; k++){
							if(i != j && j != k && k != i){
								intSum = i + j + k;
								if(intSum == intNX[h][1]){
									intCount[h]++;
								}
							}
						}
					}
				}
			}



			for(int i = 0; i < intCount.length; i++){
				System.out.println(intCount[i]);
			}

		}catch(IOException e){
			e.printStackTrace();
		}catch(NumberFormatException e){
			e.printStackTrace();
		}
	}
}



Measured memory_bytes: 24884
function main(input)
{
  var line = input[0].split(' ');
  var smaller = Math.min(line[0], line[1]);
  var other = Math.max(line[0], line[1]);
  
  var res = ''
  for (var i = 1; i <= other; i++){
  	res += smaller
  }
  console.log(res)
  
}


main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))

Measured memory_bytes: 7372
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

int main() {
    ll N;
    string S;
    cin >> N >> S;
    ll r = 0, g = 0, b = 0;
    rep(i, N){
        if(S[i] == 'R') r++;
        if(S[i] == 'G') g++;
        if(S[i] == 'B') b++;
    }
    ll cnt = 0;
    FOR(dist, 1, N){
        rep(i, N){
            if(i+2*dist < N){
                if(S[i] != S[i+dist] && S[i+dist] != S[i+2*dist] && S[i] != S[i+2*dist]){
                    cnt++;
                }
            }
        }
    }
    cout << r*g*b - cnt;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
    String src;
    int n;
    
    Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
    src = sc.next();

    int count = 0;
    char c = ' ';
    
    for (int i = 0; i < src.length(); i++) {
      if ( c != src.charAt(i) ) {
        count++;
        c = src.charAt(i);
      }
    }
    
    System.out.println(count);
    
    return;
  }
}

    
    
    

Measured memory_bytes: 25940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, N;
  cin >> K >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i); 
  }
  int x;
  x = vec.at(N - 1);
  for(int i = 0; i < N - 1; i++){
    vec.at(N - i - 1) -= vec.at (N - i - 2);
  }
  vec.at(0) += K;
  vec.at(0) -= x;
  sort(vec.begin(), vec.end());
  cout << K - vec.at(N - 1) << endl; 
}


Measured memory_bytes: 1024
n = int(input())
p = list(map(float, input().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
# dp[i][j]:i番目以前の商品を見たときに表の枚数がj枚となる確率の和

for i in range(1,n+1):
    for j in range(i+1):
            dp[i][j] = dp[i-1][j]*(1-p[i-1])
            if j>0:
                dp[i][j] += dp[i-1][j-1]*p[i-1]

ans = sum(dp[n][(n+1)//2:])

print(ans)

Measured memory_bytes: 254600
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

const string YES = "Yes";
const string NO = "No";

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

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


void solve(long long n, long long m){
    cout << (m == n ? "Yes" : "No") << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}

int main(void) {
    int x1, x2, x3, x4, y1, y2, y3, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    y3 = y2 + x2 - x1;
    x3 = x2 - (y2 - y1);
    y4 = y3 + (x3 - x2);
    x4 = x3 - (y3 - y2);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int V, E;
	cin >> V >> E;
	vector<vector<int> > G(V);
	for(int i = 0; i < E; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> dp(V, 1 << 30), par(V), depth(V);
	vector<bool> vis(V, false);
	function<void(int, int)> dfs = [&](int pos, int pre) {
		par[pos] = pre;
		vis[pos] = true;
		dp[pos] = depth[pos];
		for(int i : G[pos]) {
			if(i == pre) continue;
			if(!vis[i]) {
				depth[i] = depth[pos] + 1;
				dfs(i, pos);
				dp[pos] = min(dp[pos], dp[i]);
			}
			else {
				dp[pos] = min(dp[pos], depth[i]);
			}
		}
	};
	for(int i = 0; i < V; ++i) {
		if(!vis[i]) {
			dfs(i, -1);
		}
	}
	vector<pair<int, int> > bridges;
	for(int i = 0; i < V; ++i) {
		if(par[i] != -1) {
			if(dp[i] == depth[i]) {
				int a = i, b = par[i];
				if(a > b) swap(a, b);
				bridges.push_back(make_pair(a, b));
			}
		}
	}
	sort(bridges.begin(), bridges.end());
	for(pair<int, int> i : bridges) {
		cout << i.first << ' ' << i.second << '\n';
	}
	return 0;
}


Measured memory_bytes: 4908
#include <stdio.h>
#include <string.h>

int main()
{
    char s[11];
    scanf("%s",s);

    int len = strlen(s);

    int i;
    for (i = 0; i < len; i++)
    {
        if(len % 2 == 1)break;
        if(i % 2 == 0)
        {
            if(s[i] != 'h')break;
        }
        else
        {
            if(s[i] != 'i')break;
        }
    }
    
    if(i == len)printf("Yes");
    else printf("No");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include  <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define mod 1000000007
const int maxn = 1e5+10;

int main(){
		ios_base::sync_with_stdio(false);
		cin.tie(nullptr);
		int n;
		cin >> n;
		int m = INT_MIN;
		vector<pair<int, int>>s;
 		int count = 1;
 		for(int i = 0; i<n; i++){
			int x, y;
			cin >> x >> y;
			s.pb({x, y});
		}
 		for(int i = 0; i<n-1; i++){
			if(s[i].fi == s[i].se && s[i+1].fi == s[i+1].se)
				count+=1, m = max(m, count);
			else
				count = 1;
		}
		if(m >=3)cout << "Yes\n";
		else cout << "No\n";
		
			
    return 0;
}


Measured memory_bytes: 3640
#!/usr/bin/env python3

def main():
    A,B,C = map(int, input().split())
    K = int(input())
    max_val = max(A,B,C)
    baisu = 0
    for i in range(K):
        if i == 0:
            baisu = max_val * 2
        else:
            baisu = baisu * 2
    print(A+B+C - max_val + baisu)
    

if __name__ == "__main__":
    main()


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



int main() {
    string a;
    cin>>a;

    int val,co;
    for(int i=0;i<3;i++){
        if(a.at(i)=='o'){
            co++;
        }
    }
    val = 700 + co*100;

    cout<<val<<endl;


}


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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  if (a <= b) {
    cout << a << endl;
  } else {
    cout << a - 1 << endl;
  }

  return 0;
}


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

using namespace std;

int main(){
    int a[3*100000];
    long max_sum_l[100000+1], min_sum_r[100000+1];
    long sum_l = 0, sum_r = 0;
    priority_queue<int> que_l, que_r;
    int N;
    cin >> N;
    for(int i = 0; i < 3*N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < N; i++){
        que_l.push(-a[i]);
        sum_l += a[i];
        que_r.push(a[2*N+i]);
        sum_r += a[2*N+i];
    }
    max_sum_l[0] = sum_l;
    min_sum_r[N] = sum_r;
    for(int i = 0; i < N; i++){
        que_l.push(-a[N+i]);
        sum_l += a[N+i];
        sum_l += que_l.top();
        max_sum_l[i+1] = sum_l;
        //cout << que_l.top() << endl;
        que_l.pop();
        que_r.push(a[2*N-i-1]);
        sum_r += a[2*N-i-1];
        sum_r -= que_r.top();
        //cout << que_r.top() << endl;
        que_r.pop();
        min_sum_r[N-i-1] = sum_r;
    }
    long diff_max = -__LONG_MAX__;
    for(int i = 0; i <= N; i++){
        if(max_sum_l[i] - min_sum_r[i] > diff_max){
            diff_max = max_sum_l[i] - min_sum_r[i];
            //cout << i << ' ' << max_sum_l[i] << ' ' << min_sum_r[i] << endl;
        }
    }
    cout << diff_max << endl;
}

Measured memory_bytes: 3956
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
vector<int> G[100000];
int root;
int parent[17][100000];
int depth[100000];
void dfs(int v, int p, int d) {
	parent[0][v] = p;
	depth[v] = d;
	for (int i = 0; i < (int)G[v].size(); i++) {
		if (G[v][i] != p)dfs(G[v][i], v, d + 1);
	}
}
void init(int V) {
	dfs(root, -1, 0);
	for (int k = 0; k + 1 < 17; k++) {
		for (int v = 0; v < V; v++) {
			if (parent[k][v] < 0)parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
		}
	}
}
int lca(int u, int v) {
	if (depth[u] > depth[v])swap(u, v);
	for (int k = 0; k < 17; k++) {
		if ((depth[v] - depth[u]) >> k & 1) {
			v = parent[k][v];
		}
	}
	if (u == v)return u;
	for (int k = 16; k >= 0; k--) {
		if (parent[k][u] != parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}
int main() {
	int n; cin >> n;
	rep1(i, n - 1) {
		int p; cin >> p; p--; G[p].push_back(i);
	}
	root = 0;
	init(n);
	ll sum = 0;
	vector<int> v;
	rep(i, n) {
		if (depth[i] == 1)v.push_back(i);
	}
	sort(v.begin(), v.end());
		queue<int> q;
	rep(i, (int)v.size()) {
		q.push(v[i]);
	}
	int now = 0;
	while (!q.empty()) {
		int id = q.front(); q.pop();
		int pp = lca(now, id);
		sum += depth[now] + depth[id] - 2 * depth[pp];
		now = id;
		rep(j, (int)G[id].size()) {
			q.push(G[id][j]);
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 23432
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int nn = n;
    while(nn > 0) {
        sum += nn%10;
        nn /= 10;
    }
    if(n%sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3 or len(set(h)) == 1:
        print(*["3"]*5, sep='\n')
        continue
    for c in h:
        if c == 1:
            print("1" if 2 in h else "2")
        elif c == 2:
            print("1" if 3 in h else "2")
        else:
            print("1" if 1 in h else "2")

Measured memory_bytes: 7612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String sd = br.readLine();
			String t = br.readLine();

			System.out.println(ans(sd, t));
		}
	}

	private static String ans(String sd, String t) {
		for (int i = sd.length() - t.length(); i >= 0; i--) {
			if (isContainString(sd, t, i)) {
				char[] tmp = sd.toCharArray();
				for (int j = 0; j < t.length(); j++) {
					tmp[i + j] = t.charAt(j);
				}
				return new String(tmp).replaceAll("\\?", "a");
			}
		}

		return "UNRESTORABLE";
	}

	private static boolean isContainString(String sd, String t, int index) {
		for (int j = 0; j < t.length(); j++) {
			char sdChar = sd.charAt(index + j);
			char tChar = t.charAt(j);

			if (sdChar != '?') {
				if (tChar != sdChar) {
					return false;
				}
			}
		}
		return true;
	}
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n);
    REP(i, n) { cin >> a[i]; }
    sort(ALL(a));
    lint ai = a[n - 1];
    lint ans=0;
    lint aj;
    double d=1000000000;
    REP(i,n-1){
        if (d > abs(((double)ai / 2) - a[i]))
        {
            d =abs(((double)ai / 2) - a[i]);
            aj = a[i];
        }
    }


    cout << ai<<" "<<aj <<"\n";

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void CountingSort(int *A,int *B,int N,int max){
	int m=(max+2);
	int *C=(int*)malloc(sizeof(int)*m);
	for(int i=0;i<m;i++){
		C[i]=0;
	}
	for(int i=0;i<N;i++){
		C[A[i]]++;
		B[i]=0;
	}

	for(int i=1;i<m;i++){
		C[i]+=C[i-1];
	}

	for(int i=(N-1);i>=0;i--){
		B[C[A[i]]-1]=A[i];
		C[A[i]]--;
	}

}

int main(){
	int N;
	int *A,*B;
	int max=0;

	scanf("%d",&N);
	A=(int*)malloc(sizeof(int)*(N+1));
	B=(int*)malloc(sizeof(int)*(N+1));
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
		if(max<A[i]){max=A[i];}
	}

	CountingSort(A,B,N,max);
	
	for(int i=0;i<N;i++){
		printf("%d",B[i]);
		if(i==(N-1)){
			printf("\n");
		}else{
			printf(" ");
		}
	}
	
	return 0;
}


Measured memory_bytes: 17424
import java.util.*;

public class Main{
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    
    S = S.replaceAll("eraser","-");
    S = S.replaceAll("erase","-");
    S = S.replaceAll("dreamer","-");
    S = S.replaceAll("dream","-");
    S = S.replaceAll("-","");
    if(S.length() == 0)System.out.println("YES");
    else System.out.println("NO");
    }
}

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

int X, Y, n;
int area[16];
int used[10][10];
int ok[10][10];
int app[10][10];
int T[16];

int cnt;

bool check(int sy, int sx, int ey, int ex, int k)
{
	int t = T[k];
	for (int i = sy; i < ey; i++){
		for (int j = sx; j < ex; j++){
			if (used[i][j] != 0) return false;
			if (app[i][j] != 0 && app[i][j] != k) return false;
			if (app[i][j] == k) t--;
		}
	}
	return t == 0;
}

void Fill(int sy, int sx, int ey, int ex, int k)
{
	//if (k) printf("%d %d %d %d %d\n", k, sy, sx, ey, ex);
	
	for (int i = sy; i < ey; i++){
		for (int j = sx; j < ex; j++){
			used[i][j] = k;
		}
	}
}

void search(int k)
{
	if (k > n){
		cnt++;
		memcpy((int*)ok, (int*)used, sizeof(ok));
		
		/*for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				printf("%d ", ok[i][j]);
			}
			puts("");
		}*/
		
		return;
	}
	for (int i = 0; i < Y; i++){
		for (int j = 0; j < X; j++){
			for (int h = 1; i + h <= Y; h++){
				for (int w = 1; j + w <= X; w++){
					if (area[k] != h * w) continue;
					if (!check(i, j, i + h, j + w, k)) continue;
					Fill(i, j, i + h, j + w, k);
					search(k + 1);
					Fill(i, j, i + h, j + w, 0);
				}
			}
		}
	}
}

void solve()
{
	cnt = 0;
	search(1);
	if (cnt != 1) puts("NA");
	else {
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				if (j) printf(" ");
				printf("%d", ok[i][j]);
			}
			puts("");
		}
	}
}

int main()
{
	while (scanf("%d %d %d", &X, &Y, &n), X){
		memset(T, 0, sizeof(T));
		
		for (int i = 0; i < n; i++){
			int b, k;
			scanf("%d %d", &b, &k);
			area[b] = k;
		}
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++){
				scanf("%d", &app[i][j]);
				T[app[i][j]]++;
			}
		}
		solve();
	}
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		String ans = "";

		if (a + b == c) {
			ans = "Yes";
		} else if (b + c == a) {
			ans = "Yes";
		} else if (c + a == b) {
			ans = "Yes";
		} else {
			ans = "No";
		}
		System.out.println(ans);
	}

}

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

int main()
{
    int H, W;
    cin >> H >> W;

    char map[50][50] = {{0}};
    for (int count = 0; count < H; ++count)
    {
        cin >> map[count];
    }

    for (int x = 0; x < H; ++x)
    {
        for (int y = 0; y < W; ++y)
        {
            if (map[x][y] == '#')
            {
                if (x != 0 && map[x - 1][y] == '#')
                {
                }
                else if (x != 49 && map[x + 1][y] == '#')
                {
                }
                else if (y != 0 && map[x][y - 1] == '#')
                {
                }
                else if (y != 49 && map[x][y + 1] == '#')
                {
                }
                else
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#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) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N;
    cin >> N;
    vector<double> p(N);
    REP(i,0,N) cin >> p[i];

    vector<vector<double>> dp(N+1, vector<double>(N+1, 0.0));
    dp[0][0] = 1.0;
    REP(i,0,N) {
        REP(j,0,i+1) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    double res = 0.0;
    for(ll i=(N+1)/2; i<=N; ++i) res += dp[N][i];

    cout << fixed << setprecision(10) << res << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
typedef long long ll;
int n,q,k;
vector< pair<ll,int> > nei[100005];
ll d[100005];
//Write in Codeforces Custom Test!!!
void dfs(int root,int parent,ll dis){
    d[root]=dis;
    for(int i=0;i<nei[root].size();i++){
        if(nei[root][i].second!=parent){
            dfs(nei[root][i].second,root,dis+nei[root][i].first);
        }
    }
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        nei[a].push_back(make_pair(c,b));
        nei[b].push_back(make_pair(c,a));
    }
    memset(d,-1,n);
    cin>>q>>k;
    k--;
    dfs(k,-1,0);
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        cout<<d[a]+d[b]<<endl;
    }
}

Measured memory_bytes: 15872
# coding: utf-8
N = gets.to_i
L = gets.split.map {|e| e.to_i}
ans = 0

L.sort!
# aとbの二重ループで決めてしまって、Cを探す
(0..N-3).each do |i|
  (i+1..N-2).each do |j|
    t = L[i] + L[j]
    r = L.bsearch_index {|x| x >= t}
    r = N if r.nil?
    l = j + 1
    ans += r-l
  end
end

puts ans



Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, c, i, j, k, ans = 0, x, s;
	cin >> n >> c;
	vector<long long> a(n), v(n), f0(n, 0), f1(n, 0), g0(n,0), g1(n,0);
	for (i = 0; i < n; i++) cin >> a[i] >> v[i];

	s = 0;
	for (i = 0; i < n; i++) {
		s += v[i];
		
		x = s - a[i];
		if (i == 0) f0[i] = max(0LL, x);
		else f0[i] = max(f0[i - 1], x);

		x = s - a[i] - a[i];
		if (i == 0) f1[i] = max(0LL, x);
		else f1[i] = max(f1[i - 1], x);
	}

	s = 0;
	for (i = n - 1; i >= 0; i--) {
		s += v[i];

		x = s - (c - a[i]);
		if (i == n - 1) g0[i] = max(0LL, x);
		else g0[i] = max(g0[i + 1], x);

		x = s - (c - a[i]) * 2;
		if (i == n - 1) g1[i] = max(0LL, x);
		else g1[i] = max(g1[i + 1], x);
	}

	ans = 0;
	for (i = 0; i < n; i++) {
		ans = max(ans, max(g0[i], f0[i]));
		if (i < n - 1) {
			ans = max(ans, f1[i] + g0[i + 1]);
			ans = max(ans, f0[i] + g1[i + 1]);
		}
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 4992
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;

int N;
double dp[305][305][305];
bool flag[305][305][305];

double rec(int i, int j, int k) {

    if (flag[i][j][k]) return dp[i][j][k];
    flag[i][j][k] = true;

    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;

    if (i > 0) res += rec(i-1, j, k) * ((double)i / N);
    if (j > 0) res += rec(i+1, j-1, k) * ((double)j / N);
    if (k > 0) res += rec(i, j+1, k-1) * ((double)k / N);
    res += 1;
    res *= (double)N / (i+j+k);

    return dp[i][j][k] = res;
}


void solve() {
    cin >> N;
    vector<int> cnt(4);
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        cnt[a]++;
    }

    cout << setprecision(15) << rec(cnt[1], cnt[2], cnt[3]) << endl;
}


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

Measured memory_bytes: 127112
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
	int arr[n];
	int ar[n]={0};
	for(int i=0;i<n-1;i++)
        cin>>arr[i];
	for(int j=0;j<n-1;j++){
       ar[arr[j]]++;
	}
	for(int i=1;i<n;i++)
        cout<<ar[i]<<endl;
    cout<<0<<endl;
	return 0;
}


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

int main() {
	string S;
	cin >> S;
	int N = S.length();
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (S[i] == S[j]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		String[][] st = new String[3][3];
		Scanner sc = new Scanner(System.in);

		for(int i=0; i<=2; i++){
			String st1 = sc.next();
			for(int j=0; j<=2; j++){
				st[i][j] = String.valueOf(st1.charAt(j));
			}
		}
		System.out.println(st[0][0] + st[1][1] + st[2][2]);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n;
string s;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> s;
	int cnt = 0;
	string temp = "ABC";
	for(int i = 0; i < (int)s.length() - 2; i++){
		bool val = true;
		for(int j = 0; j < 3; j++)
			if(temp[j] != s[i + j]) val = false;
		if(val) cnt++;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int A, B;

    cin >> A >> B;

    if(A>=1 && A<=9 && B>=1 && B<=9){
        cout << A*B << endl;
    }

    else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const ll infl = 1e17;

ll powmod(ll x, ll y, ll mod)
{
    map<ll, ll> Z;
    Z[0] = 1;
    Z[1] = x;
    ll nowy = 1;
    ll nowx = x;
    while (nowy * 2 <= y)
    {
        nowy *= 2;
        nowx = nowx * nowx % mod;
        Z[nowy] = nowx;
    }
    ll nowz = nowy / 2;
    while (nowy < y)
    {
        if (nowz + nowy <= y)
        {
            nowy += nowz;
            nowx = (nowx * Z[nowz]) % mod;
        }
        nowz /= 2;
    }
    return nowx;
}

int main(){
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    ll L = 2 * n;
    vector<ll> kaijo(L+1, 0);
    kaijo[0] = 1;
    repf(i, 1, L+1)
        kaijo[i] = (kaijo[i - 1] * i) % mod;
    vector<ll> gyaku(L+1, 0);
    gyaku[L] = powmod(kaijo[L], mod - 2, mod);
    rep(i,L)
        gyaku[L-1-i] = gyaku[L-i] * (L-i) % mod;
    ll x = 100 * powmod(100 - c, mod - 2, mod) % mod;
    ll revab = powmod(a + b, mod - 2, mod);
    ll pa = (a * revab) % mod;
    ll pb = (b * revab) % mod;
    ll xa = powmod(pa, n, mod);
    ll xb = powmod(pb, n, mod);
    ll ans = 0;
    repf(m, n, 2 * n)
    {
        ll c = ((kaijo[m - 1] * gyaku[n - 1]) % mod * gyaku[m - n]) % mod;
        c = c * ((xa + xb) % mod) % mod;
        c = (c * m) % mod * x % mod;
        ans = (ans + c) % mod;
        xa = (xa * pb) % mod;
        xb = (xb * pa) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;


int main(){
	int n,w;
    cin>>n>>w;
    ll val=0;
    vector<pair<int,int>> a(n);

    REP(i,n){
        cin>>a[i].first>>a[i].second;
        val+=a[i].second;
    }
    vector<ll> dp(200007,100000000000);
    dp[0]=0;
    REP(i,n){
        for(int j=val;j>=0;j--){
            dp[j+a[i].second]=min(dp[j+a[i].second],dp[j]+a[i].first);
        }
    }
    int ans=0;
    REP(i,val+1){
        if(dp[i]<=w) ans=max(ans,i);
    }
    OUT(ans);
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(0,b+c-a) << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

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

int main()
{
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];    
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(ALL(a));    
    sort(ALL(b));
    sort(ALL(c));

    vector<ll> d(n);
    rep(i, n){
        d[i] = (ll)(c.size() - (upper_bound(ALL(c), b[i]) - c.begin()));
    }
    // prvec(a);
    // prvec(b);
    // prvec(c);
    // prvec(d);
    for(int i=n-2; i>=0; i--) d[i] += d[i+1];
    // prvec(d);
    ll ans = 0;
    rep(i, n){
        int t = upper_bound(ALL(b), a[i]) - b.begin();
        // pr(t);
        if(t<n) ans += (ll)d[t];
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 5356
n,y = map(int, input().split())
ans = [-1,-1,-1]
for i in range(n+1):
    for j in range(n+1):
        z = n-(i+j)
        s = 10000*i + 5000*j + 1000*z
        if z < 0:
            continue
        if s == y:
            ans[0] = i
            ans[1] = j
            ans[2] = z
print(ans[0],ans[1],ans[2])

Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int64_t exists[MAXN];

void init()
{
  int i = 1, n = 2;
  while (i < MAXN)
  {
    exists[i] = n;
    i += n;
    n++;
  }
}

int main()
{
  int64_t N;
  cin >> N;
  init();
  if (!exists[N])
  {
    cout << "No" << endl;
    return 0;
  }
  int64_t K = exists[N];
  cout << "Yes" << endl;
  cout << K << endl;
  vector<queue<int64_t>> vq(K);
  int64_t n = 1;
  for (int i = 0; i < K - 1; i++)
  {
    for (int j = i + 1; j < K; j++)
    {
      vq.at(i).push(n);
      vq.at(j).push(n);
      n++;
    }
  }
  for (int i = 0; i < K; i++)
  {
    cout << vq.at(i).size();
    while (vq.at(i).size())
    {
      cout << ' ' << vq.at(i).front();
      vq.at(i).pop();
    }
    cout << endl;
  }
}

Measured memory_bytes: 5864
import itertools

n,k = map(int, input().split())
d = []
A = []
for i in range(k):
    d.append(int(input()))
    A.append(map(int, input().split()))
B = list(itertools.chain.from_iterable(A))

ans=0
for i in range(n):
    if i+1 not in B:
        ans+=1
print(ans)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    while (true) {
        int n, x; cin >> n >> x;
        if (n == 0 && x == 0) break;
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) cnt++;
                }
            }
        }

        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
int main(void){
    int A = 0; int B = 0;
    char S[20] = {0};
    scanf("%ld %ld", &A, &B);
    scanf("%s", S);
    int flag = 0;
    for(int i = 0; i < A + B + 1; i++){
        if(i == A){
            if(S[i] != 45){
                flag = 1;
                break;
            }
        }else {
            if(S[i] < 48 || S[i] > 57){
                flag = 1;
                break;
            }
        }
    }
    if(flag == 1){
        printf("No\n");
    }else {
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
import doctest


def solve(N, h):
    """
    >>> solve(4, [10, 30, 40, 20])
    30
    """
    # dp[i] = 足場iにたどり着くまでの最小コスト
    dp = [None] * (N + 1)
    dp[1] = 0
    dp[2] = abs(h[1] - h[0])
    for i in range(3, N + 1):
        dp[i] = min(dp[i - 2] + abs(h[i - 1] - h[i - 3]), dp[i - 1] + abs(h[i - 1] - h[i - 2]))
    return dp[N]


# doctest.testmod()
N = int(input())
h = list(map(int, input().split()))
print(solve(N, h))

Measured memory_bytes: 18188
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int a,b,m;
    cin>>a>>b>>m;
    vector<int> aa(a);
    vector<int> bb(b);
    rep(i,a){
        cin>>aa[i];
    }
    rep(i,b){
        cin>>bb[i];
    }
    int ans = aa[0]+bb[0];
    rep(i,m){
        int x,y,c;
        cin>>x>>y>>c;
        ans=min(ans,aa[x-1]+bb[y-1]-c);
    }
    sort(aa.begin(),aa.end());
    sort(bb.begin(),bb.end());
    ans=min(ans,aa[0]+bb[0]);
    
    cout<<ans<<endl;
    
    
    
return 0;
}


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

int main(){
    int n;
    cin>>n;
    int count=0;
    if(n<10) count=n;
    else{
        count+=9;
        if(n>=100){
            if(n<1000) count+=(n-100)+1;
            else if(n<10000) count+=1000-100;
            else{
                count+=1000-100;
                if(n<=99999) count+=n-9999;
                else count+=100000-10000;
            }
        }
    }
    cout<<count<<endl;
}

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

using namespace std;

int n;
int a[205];
int cnt[105];

int read() {
    if (scanf("%d", &n) < 1) {
        return 0;
    }
    n *= 2;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    return 1;
}


void solve() {
    int ans = 0;
    sort(a, a + n, greater<int>());
    for (int i = 0; i < n - 1; i+=2) {
        ans += min(a[i], a[i + 1]);
    }
    printf("%d\n", ans);
}

int main() {
    //freopen("in", "r", stdin);
    while (1) {
        if (!read()) {
            break;
        }
        solve();
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007

using namespace std;


void solve()
{
    int k, a, b;

    cin >> k >> a >> b;

    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK\n";
            return;
        }
    }
    cout << "NG\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3640
/*abc110b*/
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = "No War";

        int ncitiesAN = scanner.nextInt();
        int ncitiesBM = scanner.nextInt();
        int capitalAX = scanner.nextInt();
        int capitalBY = scanner.nextInt();
        int[] coordsAx = new int[ncitiesAN+1];
        int[] coordsBy = new int[ncitiesBM+1];
        for(int i=0;i<ncitiesAN;i++){
            coordsAx[i] = scanner.nextInt();
        } //coordsAxの読み込み
        for(int i=0;i<ncitiesBM;i++){
            coordsBy[i] = scanner.nextInt();
        } //coordsByの読み込み

        coordsAx[ncitiesAN] = capitalAX;
        coordsBy[ncitiesBM] = capitalBY;

        Arrays.sort(coordsAx);
        Arrays.sort(coordsBy); //小さい順

        if(coordsAx[ncitiesAN] >= coordsBy[0]){
            s = "War";
        }
//        //debug
//        for(int i=0;i<ncitiesAN+1;i++){
//            out.print(String.valueOf(coordsAx[i])+" ");
//        } //coordsAxの読み込み
//        out.println();
//        for(int i=0;i<ncitiesBM+1;i++){
//            out.print(String.valueOf(coordsBy[i])+" ");
//        } //coordsByの読み込み
//        out.println();

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


Measured memory_bytes: 25300
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 2500005


ll K;
char S[1000005];
ll fact[SIZE],inv_fact[SIZE];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}



int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	scanf("%lld",&K);
	scanf("%s",S);

	ll len;
	for(len = 0; S[len] != '\0'; len++);

	ll ans = 0;

	for(ll tail = len-1; tail <= len-1+K; tail++){

		ll left = (tail+1)-len; //左にある数
		ll right = (len+K-(tail+1)); //右にある数

		ll tmp = nCk(tail,left);
		tmp *= mod_pow(25,left,MOD);
		tmp %= MOD;
		tmp *= mod_pow(26,right,MOD);
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 43820
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> S(n);
    S[0] = a[0];
    repi(i, n) S[i] = S[i-1] + a[i];

    ll res = 1e18;
    rep(i, n - 1) {
        res = min(res, abs(S[i] - (S[n-1] - S[i])));
    }
    put(res);

    return 0;
}

Measured memory_bytes: 6412
n = int(input())
cnt = {i:0 for i in "MARCH"}
for i in range(n):
  s = input()
  if s[0] in ["M", "A", "R", "C", "H"]:
    cnt[s[0]] += 1

one =   ["M", "M", "M", "M", "M", "M", "A", "A", "A", "R"]
two =   ["A", "A", "A", "R", "R", "C", "R", "R", "C", "C"]
three = ["R", "C", "H", "C", "H", "H", "C", "H", "H", "H"]

ans = 0
for i in range(10):
  ans += cnt[one[i]] * cnt[two[i]] * cnt[three[i]]
  
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int n;
  cin >> n;
  vector<int> S(n);
  rep(i, n)
  {
    cin >> S[i];
  }
  int q;
  cin >> q;
  vector<int> T(q);
  rep(i, q)
  {
    cin >> T[i];
  }
  SORT(S);
  SORT(T);
  int ans = 0;
  rep(i, q)
  {
    bool is_ok = binary_search(S.begin(), S.end(), T[i]);
    if(is_ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3420
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long min = 0;
        for(int i = (int) Math.sqrt(n); i>0; --i){
                if(n%i==0){
                    min = n/i;
                    break;
                }
        }
        System.out.println(getNums(min));
    }
    static int getNums(long n){
        int count  = 0;
        while(n>0){
            n /= 10;
            count++;
        }
        return count;
    }
}

Measured memory_bytes: 23380
from collections import Counter

n=int(input())
A=list(map(int,input().split()) )

left = [i+A[i] for i in range(n)]
right = [i-A[i] for i in range(n)]

r_counter = Counter(right)

ans = 0

for l in left:
    ans += r_counter[l]

print(ans)

Measured memory_bytes: 134912
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
bool prime[N];

bool yes(int x){
     for(int i = 2; i<=sqrt(x); ++i){
         if(i * (x/i) == x)return false;
     }
     return true;
}

int main(){
    int n;
    scanf("%d",&n);
    int c = 0;
    vector<int>prm;
    for(int i = 2; i<=55555; ++i) if(yes(i) && i%5 == 1){
         prm.push_back(i);
    }
    for(int i = 0; i<n; ++i)printf("%d ",prm[i]);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
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;}
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

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


Measured memory_bytes: 256
def getInput():
    n = int(input())
    a = [i for i in input().split(" ")]
    return n, a

def getNum(s):
    return int(s[1])

def swap(x, y):
    v = x
    x = y
    y = v
    return x, y

def bubbleSort(n, a):
    cnt = 0
    for j in range(n):
        init = True
        for i in range(n-1, -1, -1):
            if init:
                init = False
                continue
            if getNum(a[i]) > getNum(a[i+1]):
                a[i], a[i+1] = swap(a[i], a[i+1])
                cnt += 1
    print(" ".join([str(i) for i in a]))
    return a

def selectionSort(n, a):
    cnt = 0
    for i in range(n):
        id_min = i
        for j in range(i+1, n):
            if getNum(a[j]) < getNum(a[id_min]):
                id_min = j
        if id_min != i:
            a[i], a[id_min] = swap(a[i], a[id_min])
            cnt += 1
    print(" ".join([str(i) for i in a]))
    return a

def checkStability(n, a_sample, a):
    for i in range(n-1):
        flag1 = False
        flag2 = False
        if getNum(a_sample[i]) == getNum(a_sample[i+1]):
            for j in range(n):
                if a[j] == a_sample[i+1]:
                    flag1 = True
                if a[j] == a_sample[i]:
                    flag2 = True
                if (flag1==True)&(flag2==False):
                    print("Not stable")
                    return
    print("Stable")
    return


from copy import deepcopy
N, A = getInput()
a_bs = bubbleSort(deepcopy(N), deepcopy(A))
checkStability(deepcopy(N), deepcopy(a_bs), deepcopy(A))
a_ss = selectionSort(deepcopy(N), deepcopy(A))
checkStability(deepcopy(N), deepcopy(a_ss), deepcopy(A))



Measured memory_bytes: 6356