akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int32_t main()
{
    IOS;
    string s,a;
    cin>>s>>a;
    int ok=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=a[i])
            ok=1;
    }
    if(ok)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;


}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cstring>
#include <stack>
using namespace std;
int main(){
	stack <char> st;
	string s;
	cin >> s;
	int len = s.length();
	bool fc = false;
	bool ff = false;
	for(int i = 0; i < len; i++){
		st.push(s[i]);
		if(st.top() == 'C'){
			fc = true;
		}
		if(st.top() == 'F' && fc == true){
			ff = true;
		}
	}
	if(fc == true && ff == true){
		cout << "Yes";
	}else{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	for {
		var a, b int
		var op string
		fmt.Scan(&a, &op, &b)
		switch op {
		case "+":
			fmt.Println(a + b)
		case "-":
			fmt.Println(a - b)
		case "*":
			fmt.Println(a * b)
		case "/":
			fmt.Println(a / b)
		default:
			return
		}
	}
}



Measured memory_bytes: 1132
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()
    # a.insert(0, INF)
    a.append(-INF)

    kabu = 0
    kane = 1000

    turn = []
    for i in range(n):
        if a[i + 1] > a[i]:
            turn.append(1)
        elif a[i + 1] < a[i]:
            turn.append(-1)
        else:
            turn.append(0)

    katteruflg = False
    for i in range(len(turn)):
        if turn[i] == 1:
            if katteruflg:
                continue
            kabu = kane // a[i]
            kane -= a[i] * kabu
            katteruflg = True
        elif turn[i] == -1:
            kane += a[i] * kabu
            kabu = 0
            katteruflg = False

    print(kane)


if __name__ == '__main__':
    main()


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

int main()
{
    long n, a, b;
    cin >> n;
    cin >> a >> b;
    long r1 = a % n;
    long c = b - a;
    if (r1 == 0 or r1 + c >= n)
        cout << "OK\n";
    else
        cout << "NG\n";
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	static int N, M;
	//最短距離もわかったほうが面白いので一応格納しておく
	//問題を解く上では不要
	static int[][] dp;
	static List<int>[] pathList;
	static bool[] already;
	static Queue<int> nextStart;

	//探索
	static void Search(int start){
		foreach(int goal in pathList[start]){
				if(!already[goal]){
						//startが次の地点にとってのgoalとなる
						dp[goal][0] = start;
						dp[goal][1] = dp[start][1] + 1;

						//探索済みを示す
						already[goal] = true;

						//キューに追加
						nextStart.Enqueue(goal);
				}
		}

		//キューが空の場合、終了
		if(nextStart.Count() <= 0){
				return;
		}
		//次に探すべき地点を検索
		else{
				int nextS = nextStart.Dequeue();
				Search(nextS);
		}
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] S = Console.ReadLine().Split(' ');
		N = int.Parse(S[0]);
		M = int.Parse(S[1]);
		pathList = new List<int>[N];
		dp = new int[N][];
		already = new bool[N];

		nextStart = new Queue<int>();

		//初期化
		for(int i=0; i<N; i++){
				pathList[i] = new List<int>();
				dp[i] = new int[2];
		}

		//読み込む
		for(int i=0; i<M; i++){
				string[] line = Console.ReadLine().Split(' ');
				int Ai = int.Parse(line[0]);
				int Bi = int.Parse(line[1]);

				pathList[Ai-1].Add(Bi-1);
				pathList[Bi-1].Add(Ai-1);
		}

		//0から探す
		already[0] = true;
		Search(0);

		bool possible = true;

		for(int i=1; i<N; i++){
				if(already[i] = false){
						possible = false;
						break;
				}
		}
		if(possible){
			Console.WriteLine("Yes");
			for(int i=1; i<N; i++){
					Console.WriteLine(dp[i][0]+1);
			}
		}
		else{
			Console.WriteLine("No");
		}
	}
}



Measured memory_bytes: 51084
N = int(input())
A = [int(input()) for n in range(N)]

sortedA = list(reversed(sorted(A)))
for a in A:
  count = 0
  for b in sortedA:
    if b != a:
      print(b)
      break
    if a == b:
      if count == 0:
        count += 1
      else:
        print(b)
        break

Measured memory_bytes: 88840
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    
    int *L;
    L = new int[N];
    
    int sum = 0;
    
    int i;
    for(i = 0; i < N; i++){
        cin >> L[i];
        sum += L[i];
    }
    
    for(i = 0; i < N; i++){
        if(sum - 2*L[i] <= 0){
            cout << "No" << endl;
            delete[] L;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    delete[] L;
    return 0;
}


Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

cnt = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        b = (N - r * R - g * G) / B
        if 0 <= b and b % 1 == 0:
            #print(r, g, int(b))
            cnt += 1
print(cnt)

Measured memory_bytes: 41068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            Console.WriteLine(Line().Replace("2017", "2018"));
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

#define S 21
#define N 100

unsigned long long int dp[N][S];

int main() {
  int i, j;
  int n, a;

  scanf("%d", &n);

  for(i = 0; i < N; i++) {
    for(j = 0; j < S; j++) dp[i][j]=0ULL;
  }

  scanf("%d", &a);
  dp[0][a] = 1ULL;

  for(i = 1; i < n - 1; i++) {
    int v;
    scanf("%d", &v);
    for(j = 0; j < S; j++) {
      if (j + v < S) dp[i][j + v] += dp[i - 1][j];
      if (j - v >= 0) dp[i][j - v] += dp[i - 1][j];
    }
  }

  scanf("%d", &a);
  printf("%llu\n", dp[n - 2][a]);

  return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    int a[n],b[n];

    for(int i=0;i<n;i++){
        int x,y; cin >> x >> y;
        a[i] = x+y;
        b[i] = x-y;
    }

    sort(a, a+n);
    sort(b, b+n);

    cout << max(b[n-1] - b[0], a[n-1] - a[0]) << "\n";



}


Measured memory_bytes: 6776
#include<iostream>
#include<algorithm>
#include <string>
#include<vector>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int c = 1; c <= n - 1; c++) {
		int r = n - c;
		for (int a = 1; a * a <= r; a++) {
			if (a * a == r) {
				ans++;
			}
			else {
				if (r % a == 0) {
					ans += 2;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        boolean[] mochiExists = new boolean[100 + 1];
        for (int i = 0; i < n; i++) {
            mochiExists[sc.nextInt()] = true;
        }
        
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (mochiExists[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
S = input()
q = [list(map(int, input().split())) for _ in range(Q)]
f = [0 for _ in range(N)]
for i in range(2, N + 1):
    if S[i - 2:i] == "AC":
        f[i - 1] += f[i - 2] + 1
    else:
        f[i - 1] += f[i - 2]
for i in range(Q):
    print(f[q[i][1] - 1] - f[q[i][0] - 1])

Measured memory_bytes: 64476
import java.util.Scanner;
public class Main {
	private boolean stringMach(char[] base,String boardStr) {
		
		int boardStrlen = boardStr.length()-1; 
		int baseIndex = 0;
		for(int i=0;i<boardStrlen;i++){
			if(base[baseIndex]==boardStr.charAt(i)){
				baseIndex++;
				for(int j=i+1;j<boardStrlen;j++){
					if(base[baseIndex]==boardStr.charAt(j)){
						int margin = j-i;
						baseIndex++;
						for(int k=j+margin;k<=boardStrlen;k+=margin){
							if(base[baseIndex]==boardStr.charAt(k)){
								baseIndex++;
							}else k=boardStrlen;
								if(baseIndex==base.length){
									return true;
								}
							}
						}
					baseIndex = 1;
					}
				}
			baseIndex = 0;
			}
		return false;
	}
	
	public void doIt(){
		Scanner sc = new Scanner(System.in);
		int boardNam = sc.nextInt();
		String [] board  = new String[boardNam];
		char base[] = sc.next().toCharArray();
		int trueNum = 0;
		for(int i=0;i<boardNam;i++){
			board[i] = sc.next();
		}
		for(int i=0;i<boardNam;i++){
			if(stringMach(base, board[i])){
				trueNum++;
			}
		}
		System.out.println(trueNum);
	}
	
	public static void main(String[] args){
		new Main().doIt();
	}
}

Measured memory_bytes: 27696
x=list(input())
cnt=0
for i in range(3):
 if x[i]=="R":
  cnt+=1
if cnt==0:
 print(0)
elif cnt==1:
 print(1)
elif cnt==2 and x[1]=="S":
 print(1)
elif cnt==2 and x[1]=="R":
 print(2)
elif cnt==3:
 print(3)

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

class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		try {
			String input = br.readLine();
			int x;

			x = Integer.parseInt(input);
			
			if (!(x >= 1 && x <= 100)) {
				throw new IllegalArgumentException();
			}
			
			System.out.println((int)Math.pow(x, 3));
		
		} catch(NumberFormatException e) {
			e.printStackTrace();
		} catch(IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24216
import itertools
N, A, B, C = map(int, input().split())
target = [C, B, A]
L = []
for i in range(N):
    L.append(int(input()))

products = list(itertools.product([0, 1, 2, 3], repeat=N))

ans = float("inf")
for p in products:
    scores = [[0, 0], [0, 0], [0, 0], [0, 0]]
    for i in range(len(p)):
        scores[p[i]][0] += L[i]
        scores[p[i]][1] += 1
    temp = [elem[0] for elem in scores[:3]]
    cost = sum([10 * (elem[1] - 1) for elem in scores[:3] if elem[1] >= 1])
    if 0 in temp:
        continue
    sorted(temp)
    cost += sum([abs(target[i] - temp[i]) for i in range(3)])
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 13044
from sys import stdin,stdout
def fn(sm):
    if sm==0:return 1
    elif sm<0:return 0
    if sm in dp:return dp[sm]
    ans=0
    for cur in range(3,2001):
        ans+=fn(sm-cur)
    dp[sm]=ans%M
    return dp[sm]
M=10**9+7
n=int(stdin.readline())
# a,b,c,d=list(map(int,stdin.readline().split()))
# pp=int(pow(10,n-2))
# ans=(pp*n*(n-1))
dp={}
ans=fn(n)
print(ans%M)

Measured memory_bytes: 9300
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.to_list as_
  |> List.sort (fun i j -> compare j i)
  |> List.mapi (fun i a -> (i, a))
  |> List.partition (fun (i, _) -> i mod 2 = 0)
  |> (fun (as_, bs) -> [as_; bs])
  |> List.map (List.map snd)
  |> List.map (List.fold_left ( + ) 0)
  |> (fun [a; b] -> a - b)
  |> Printf.printf "%d\n"

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
 int $(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }

signed main(){
  int a,b,c=1;
  cin>>a>>b;
  for(int i=0;i<b;i++)
    c*=2;
  cout<<(100*a+1800*b)*c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int c[10][10];
int a[202][202];

signed main() {
  INIT;
	VAR(int, H, W);
	REP(hi, 10) {
		REP(wi, 10) {
			cin >> c[hi][wi];
		}
	}

	REP(h, 10) {
		REP(i, 10) {
			REP(j, 10) {
				c[i][j] = min(c[i][j], c[i][h] + c[h][j]);
			}
		}
	}

	int ans = 0;
	REP(hi, H) {
		REP(wi, W) {
			cin >> a[hi][wi];
			if (a[hi][wi] < 0 || a[hi][wi] == 1) continue;
			ans += c[a[hi][wi]][1];
		}
	}
	OUT(ans)BR;

  
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
using ull = unsigned long long;

int main(){
	int N;
	scanf("%d", &N);
	unsigned A[N], min = 1e9;
	ull ans = 0;
	bool fugou = false;
	for (int i = 0; i < N; ++i){
		int tmp;
		scanf("%d", &tmp);
		unsigned plus = abs(tmp);
		if(min > plus) min = plus;
		ans += plus;
		fugou ^= tmp < 0;
	}
	printf("%llu\n", ans - (fugou ? min << 1 : 0));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int n;
   cin>>n;
   int s=sqrt(n);
   cout<<s*s;

 return 0;
}








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

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  for(int i =0; i < n; i++){
    cin >> a.at(i);
  }
  for(int i =0; i < n; i++){
    cin >> b.at(i);
  }
  for(int i =0; i < n ; i++){
    c.at(i) = a.at(i) - b.at(i);
  }
  
  int x = 0;

  for(int i =0; i < n ; i++){
    if(c.at(i) > 0){
      x += c.at(i);
    }
  }
  
  cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 165, task E, 2020/05/02
//ms,
/*
*/

int main(void){
  int A, B, K;
  int i=0;

  cin >>K >>A >>B;
  for(i=A;i<B+1;i++){
    if(i%K == 0){
      cout <<"OK" <<endl;
      break;
    }
  }
  if(B+1 <= i) cout <<"NG" <<endl;

  return 0;
}
/*
*/


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define DEBUG 1
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE

    ios_base::sync_with_stdio(false); cin.tie(0);
#endif
  	int n; cin >> n;
  	vi a(n); for (int &x : a) cin >> x;
  	sort(a.begin(), a.end());
  	if (a[n / 2] == a[n / 2 - 1]) cout << "0\n";
  	else cout << a[n / 2] - a[n / 2 - 1] << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    int next[26];
    int ans[n+2];
    int to[n+2];
    int ch[n+2];
    ans[n+1] = 0;
    to[n+1] = -1;
    for(int i = 0; i<26; i++){
        next[i] = n+1;
    }
    for(int i = n-1; i>=0; i--){
        ans[i] = ans[next[0]]+1;
        to[i] = next[0];
        ch[i] = 0;
        for(int j = 1; j<26; j++){
            if(ans[next[j]]+1<ans[i]){
                ans[i] = ans[next[j]]+1;
                to[i] = next[j];
                ch[i] = j;
            }
        }
        next[(int)(s[i]-'a')] = i;
    }
    ans[n] = ans[next[0]]+1;
    to[n] = next[0];
    ch[n] = 0;
    for(int j = 1; j<26; j++){
        if(ans[next[j]]+1<ans[n]){
            ans[n] = ans[next[j]]+1;
            to[n] = next[j];
            ch[n] = j;
        }
    }
    string ret = "";
    int now = n;
    while(now!=n+1){
        ret += alpha[ch[now]];
        now = to[now];
    }
    cout << ret << endl;
}

Measured memory_bytes: 2964
#include <algorithm>
#include <iostream>
#include <vector>

template <typename T>
struct Point {
  T x, y;
};

template <typename T>
struct Rectangle {
  Point<T> ul, br;
};

template <typename T>
uint32_t id(T value, const std::vector<T>& scale) {
  return std::lower_bound(scale.begin(), scale.end(), value) - scale.begin();
}

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::vector<Rectangle<int32_t>> R(N);
  std::vector<int32_t> x_scale(2 * N), y_scale(2 * N);
  for (uint32_t n = 0; n < N; n++) {
    std::cin >> R[n].ul.x >> R[n].ul.y >> R[n].br.x >> R[n].br.y;
    x_scale[2 * n] = R[n].ul.x, x_scale[2 * n + 1] = R[n].br.x;
    y_scale[2 * n] = R[n].ul.y, y_scale[2 * n + 1] = R[n].br.y;
  }

  std::sort(x_scale.begin(), x_scale.end());
  std::sort(y_scale.begin(), y_scale.end());
  x_scale.erase(std::unique(x_scale.begin(), x_scale.end()), x_scale.end());
  y_scale.erase(std::unique(y_scale.begin(), y_scale.end()), y_scale.end());

  std::vector<std::vector<int32_t>> area(
      y_scale.size(), std::vector<int32_t>(x_scale.size(), 0));
  for (uint32_t n = 0; n < N; n++) {
    uint32_t ul_x_id = id(R[n].ul.x, x_scale), ul_y_id = id(R[n].ul.y, y_scale);
    uint32_t br_x_id = id(R[n].br.x, x_scale), br_y_id = id(R[n].br.y, y_scale);
    area[ul_y_id][ul_x_id]++;
    if (br_x_id < x_scale.size() && br_y_id < y_scale.size())
      area[br_y_id][br_x_id]++;
    if (br_x_id < x_scale.size()) area[ul_y_id][br_x_id]--;
    if (br_y_id < y_scale.size()) area[br_y_id][ul_x_id]--;
  }

  for (uint32_t y = 0; y < y_scale.size(); y++) {
    for (uint32_t x = 1; x < x_scale.size(); x++) {
      area[y][x] += area[y][x - 1];
    }
  }
  for (uint32_t y = 1; y < y_scale.size(); y++) {
    for (uint32_t x = 0; x < x_scale.size(); x++) {
      area[y][x] += area[y - 1][x];
    }
  }

  uint64_t sum = 0;
  for (uint32_t y = 0; y < y_scale.size(); y++) {
    for (uint32_t x = 0; x < x_scale.size(); x++) {
      if (area[y][x]) {
        sum += static_cast<uint64_t>(x_scale[x + 1] - x_scale[x]) *
               static_cast<uint64_t>(y_scale[y + 1] - y_scale[y]);
      }
    }
  }

  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 65636
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1000000000

void test_case()
{
	int h, w;
	cin >> h >> w;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--;
	cw--;
	dh--;
	dw--;
	string s[h];

	for (int i = 0; i < h; i++)
		cin >> s[i];

	map<pii, vector<pii>> adj;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] != '#')
				for (int x = max(0, i - 2); x <= min(h - 1, i + 2); x++) {
					for (int y = max(0, j - 2); y <= min(w - 1, j + 2); y++) {
						if (s[x][y] != '#')
							adj[ {i, j}].pb({x, y});
					}
				}
		}
	}

	priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> q;

	q.push({0, {ch, cw}});
	vector<vector<int>> d(h, vector<int>(w, INT_MAX));
	d[ch][cw] = 0;
	int dx[4] = {1, -1, 0, 0};
	int dy[4] = {0, 0, 1, -1};

	while (!q.empty()) {

		int d_v = q.top().first;
		pii p = q.top().second;

		q.pop();

		if (d_v != d[p.first][p.second])
			continue;

		if (p == make_pair(dh, dw)) {
			cout << d_v;
			return;
		}

		for (int i = 0; i < 4; i++) {
			int tox = p.first + dx[i];
			int toy = p.second + dy[i];
			if (tox >= 0 && toy >= 0 && tox < h && toy < w && s[tox][toy] != '#' && d[tox][toy] > d[p.first][p.second]) {
				d[tox][toy] = d[p.first][p.second];
				q.push({d[tox][toy], {tox, toy}});
				// cout << d[tox][toy] << ':' << tox << ' ' << toy << '\n';
			}
		}

		for (pii pr : adj[p]) {
			if (d[pr.first][pr.second] > d[p.first][p.second] + 1) {
				d[pr.first][pr.second] = d[p.first][p.second] + 1;
				q.push({d[pr.first][pr.second], pr});
				// cout << d[pr.first][pr.second] << ':' << pr.first << ' ' << pr.second << '\n';
			}
		}

	}
	cout << "-1";

}


int main()
{
	fastio
	// int t;
	// cin >> t;
	// while (t--)
	test_case();
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	 cout << hex;
	cin >> n;
	cin >> hex;
	REP(a, n) {
		ll cnt = 0;
		ll ans = 0;
		vl v(9);
		REP(i, 9)cin >> v[i];
		
		REP(i, 32) {
			ll tmp = 0;
			REP(j, 8)tmp += ((1 << i)&v[j]) >> i;
			if ((cnt + tmp) % 2 != ((1 << i)&v[8]) >> i) {
				ans |= 1ll << i;
				cnt = (cnt + (8 - tmp)) / 2;

			}
			else cnt = (cnt + tmp) / 2;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int x) {
    int root = (int)sqrt(x);
    for (int i = 2; i <= root; i++) {
        if (x % i == 0) return false;
    }
    return true;
}


int main()
{
    int n;
    scanf("%d", &n);
    printf("2 ");
    int ans = n - 1;
    int cnt = 3;
    while (ans) {
        if (isPrime(cnt) && cnt % 5 == 1) {
            printf("%d ", cnt);
            ans--;
        }
        cnt++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int N,M,K;
vector<pair<int,int>> AB;
vector<pair<int,int>> CD;

vector<int> par;
vector<int> rnk;
void init(int N){ rep(i,N) {par[i] = i; rnk[i] = 0;} }
int root(int x) {
  return par[x] == x? x : par[x] = root(par[x]);
}
bool same(int x, int y) { return root(x) == root(y); }
void unite(int x, int y){
  x = root(x); y = root(y);
  if(x==y) return;

  if(rnk[x] < rnk[y]) par[x] = y;
  else{
    par[y] = x;
    if(rnk[x] == rnk[y]) rnk[x]++;
  }
}


int main(){
  cin >> N >> M >> K;
  AB.resize(M);
  rep(i,M){
    cin >> AB[i].first >> AB[i].second;
    AB[i].first--;
    AB[i].second--;
    if(AB[i].first>AB[i].second){
      int tmp = AB[i].first;
      AB[i].first = AB[i].second;
      AB[i].second = tmp;
    }
  }
  CD.resize(K);
  rep(i,K) {
    cin >> CD[i].first >> CD[i].second;
    CD[i].first--;
    CD[i].second--;
  }
  par.resize(N); rnk.resize(N);
  init(N);
  rep(i,M) {
    unite(AB[i].first,AB[i].second);
  }

  vector<int> ans(N);
  map<int,int> mp;
  rep(i,N){
    par[i] = root(i);
    mp[par[i]]++;
  }
  rep(i,N){
    ans[i] = mp[par[i]]-1;
  }
  rep(i,M){
    if(same(AB[i].first,AB[i].second)){
      ans[AB[i].first]--;
      ans[AB[i].second]--;
    }
  }
  rep(i,K){
    if(same(CD[i].first,CD[i].second)){
      ans[CD[i].first]--;
      ans[CD[i].second]--;
    }
  }
  rep(i,N){
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>

int main(int argc, char const *argv[]) {
    long long N, K;
    std::cin >> N >> K;
    if (K % 2 != 0) {
        std::cout << (N / K) * (N / K) * (N / K) << '\n';
    } else {
        std::cout << (N / K) * (N / K) * (N / K) + ((N + K / 2) / K) *
                                                       ((N + K / 2) / K) *
                                                       ((N + K / 2) / K)
                  << '\n';
    }

    return 0;
}


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

using namespace std;

long long knapsack(vector<pair<long long, long long> > v, long long n, long long w) {
    vector<vector<long long> > dp(n+1, vector<long long>(w+1));
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= w; j++) {
            if(i == 0 || j == 0) {
                dp[i][j] = 0;
            } else if(v[i-1].first <= j) {
                dp[i][j] = max(v[i-1].second + dp[i-1][j-v[i-1].first], dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    return dp[n][w];
}

int main() {
    long long n, w;
    cin >> n >> w;
    vector<pair<long long, long long> > v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }
    cout << knapsack(v, n, w);
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int 
#define MOD 1000000007
#define fi(i,a,n) for(lli i = a; i < n; i++)
#define fd(i,a,n) for(lli i = a; i > n; i--)
#define fv(i,a) for(auto i:a)
#define pb push_back
#define mp make_pair


int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout<<fixed<<setprecision(10);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
lli t=1;
//cin>>t;
while(t--)
{
	lli n;
	cin>>n;
	vector<pair<int,int>>arr(n);
	fi(i,0,n)
	cin>>arr[i].first>>arr[i].second;
	fi(i,2,n)
	{
		if(arr[i].first==arr[i].second && arr[i-1].first==arr[i-1].second && arr[i-2].first==arr[i-2].second)
		{
			cout<<"Yes";
			return 0;
		}
	}	
	cout<<"No";
}
return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main() {
	int r, D;
	ll x;
	cin >> r >> D >> x;
	for(int i=0; i<10; ++i){
	    x *= r;
	    x -= D;
	    cout << x << endl;
	}
	return 0;
}


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

int main(){

  std::stack<int> st;

  int N = 0;
  int a;

  while(N <= 100 && std::cin >> a){
    if(a != 0){
      st.push(a);
    }
    else{
      std::cout << st.top() << std::endl;
      st.pop();
	}
    ++N;
  }
}



Measured memory_bytes: 3056
import java.util.Scanner;

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

    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    String T = sc.next();
    int count = 0;

    for (int i = 0; i < 3; i++) {
      if (S.charAt(i) == T.charAt(i)) {
        count++;
      }
    }

    System.out.println(count);

    sc.close();
  }
}


Measured memory_bytes: 23892
// https://atcoder.jp/contests/abc057/tasks/abc057_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int INF = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, t1, t2;
    cin >> n >> m;
    vector<pii> peo, chk;
    REP(i, n) {
        cin >> t1 >> t2;
        peo.emplace_back(t1, t2);
    }
    REP(i, m) {
        cin >> t1 >> t2;
        chk.emplace_back(t1, t2);
    }
    REP(i, n) {
        int dist = INF;
        int index = -1;
        REP(j, m) {
            int t = abs(peo[i].first - chk[j].first) +
                    abs(peo[i].second - chk[j].second);
            if (t < dist) {
                index = j;
                dist = t;
            }
        }
        cout << index + 1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

vector<int> price(20);
queue<ll> thr;
int n,m;
ll x;
void check(int i,int pri,vector<int>total,vector<vector<int>>data){
    int ok=0;
    if(i==n){
        int cnt=0;
        rep(j,0,m){
            if(total.at(j)>=x){
                cnt++;
            }
        }
        if(cnt==m){
            thr.push(pri);
            ok=1;
            //cout << "wai" <<endl;
        }
    }else{
        check(i+1,pri,total,data);
        
        rep(j,0,m){
            total.at(j) += data.at(i).at(j);
        }
        check(i+1,pri+price.at(i),total,data);

    }
    return;

}
int main(){
    vector<vector<int>> data(20,vector<int>(20));
    cin >> n >> m >> x;
    
    rep(i,0,n){
        cin >> price.at(i);
        rep(j,0,m){
            cin >> data.at(i).at(j);
        }
    }
    vector<int> total(m);
    check(0,0,total,data);
    if(!thr.empty()){
        ll minp = 1300000;
        while(!thr.empty()){
            minp=min(minp,thr.front());
            thr.pop();
        }
        cout << minp << endl;
    }else{
        cout << -1 << endl;
    }
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, m, s[100], c[100], i, ans=0, f=0;
    cin >> n >> m;
    for(i=0;i<m;i++){
        cin >> s[i] >> c[i];
    }
    if(n==1){
        for(ans=0;ans<=9;ans++){
            for(i=0;i<m;i++){
                if(ans==c[i]) f++;
            }
            if(f==m){
                cout << ans <<endl;
                return 0;
            }
            f=0;
        }
        cout << -1 <<endl;
        return 0;
    }
    if(n==2){
        for(ans=10;ans<=99;ans++){
            for(i=0;i<m;i++){
                if(s[i]==1){
                    if((ans/10)==c[i]) f++;
                }
                else if(s[i]==2){
                    if((ans%10)==c[i]) f++;
                }
            }
            if(f==m){
                cout << ans <<endl;
                return 0;
            }
            f=0;
        }
        cout << -1 <<endl;
        return 0;
    }
    if(n==3){
        for(ans=100;ans<=999;ans++){
            for(i=0;i<m;i++){
                if(s[i]==1){
                    if((ans/100)==c[i]) f++;
                }
                else if(s[i]==2){
                    int tmp=ans;
                    tmp=tmp/10;
                    tmp=tmp%10;
                    if(tmp==c[i]) f++;
                }
                else if(s[i]==3){
                    if((ans%10)==c[i]) f++;
                }
            }
            if(f==m){
                cout << ans <<endl;
                return 0;
            }
            f=0;
        }
        cout << -1 <<endl;
        return 0;
    }
    return 0;
}

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

int main(){
  int A,B;
  int total=0;
  cin >> A >> B;
  if(A>B){
    total+=A;
    A--;
  }
  else{
    total+=B;
    B--;
  }
  if(A>B){
    total+=A;
    A--;
  }
  else{
    total+=B;
    B--;
  }
 cout << total <<endl;
}
  
  

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

// clang-format off
#define rep(i, n) for(int i=0; i< (n); i++)
#define reps(i, a, n) for(int i=a; i < (n); i++)

const int INF{1001001001};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

int main(){
    int n;
    cin >> n;
    
    if(n < 1000)cout << "ABC";
    else cout << "ABD" << endl;
    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int nmax = 40, abmax = 10, inf = 1e6;

int n, ma, mb;
int a[nmax], b[nmax], c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

void solve() {
   for (int i = 0; i < n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            chmin(dp[i+1][ca][cb], dp[i][ca][cb]);
            if (ca+a[i] <= nmax*abmax && cb+b[i] <= nmax*abmax) {
               chmin(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
            }
         }
      }
   }

   int ans = inf;
   for (int ca = 1; ca <= nmax*abmax; ca++) {
      for (int cb = 1; cb <= nmax*abmax; cb++) {
         if (ca*mb==cb*ma) {
            chmin(ans, dp[n][ca][cb]);
         }
      }
   }

   if (ans == inf) ans = -1;
   cout << ans << endl;
}

int main() {
   cin >> n >> ma >> mb;
   rep (i, n) cin >> a[i] >> b[i] >> c[i];

   for (int i = 0; i <= n; i++) {
      for (int ca = 0; ca <= nmax*abmax; ca++) {
         for (int cb = 0; cb <= nmax*abmax; cb++) {
            dp[i][ca][cb] = inf;
         }
      }
   }
   dp[0][0][0] = 0;

   solve();

   return 0;
}

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

int main()
{
    int n,a[105],cost=4000005;
    scanf("%d",&n);

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

    for(int i=-100; i<=100; i++)
    {
        int sum=0;
        for(int j=0; j<n; j++)
        {
            int t = (i-a[j])*(i-a[j]);
            sum+=t;

        }

        if(sum<cost)
            cost=sum;
    }
    printf("%d\n",cost);

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
	ll n;
	cin >> n;
	for(int i = sqrt(n); i > 0; i--){
		if(n % i == 0){
			cout << i + (n / i) - 2;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<long long>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int MOD=1e9+7;
int INF=1e9+7;
//
int H,W;
char hoge;
int cnt;
//
int main(){
  cin>>H>>W;
  FOR(i,0,H){
    FOR(j,0,W){
      cin>>hoge;
      if(hoge=='#'){
        cnt++;
      }
    }
  }
  if(cnt==H+W-1){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IL inline
#define _ 1000005
#define ll long long
#define ld long double
using namespace std ; 

IL ll gi(){
	ll data = 0 , m = 1; char ch = 0 ; 
	while((ch != '-') && (ch < '0' || ch > '9')) ch = getchar() ; 
	if(ch == '-'){m = 0 ; ch = getchar() ; }
	while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar() ; }
	return (m) ? data : -data ; 
}

int n , m , z , Q , MOD , g , mod ; 
int U[_] , V[_] , C[_] , dsu[7 * _] , ok[2][_] ; 

IL int Find(int x) {return dsu[x] ^ x ? dsu[x] = Find(dsu[x]) : x ; }
IL int ID(int u,int q,int p){return u + n * (q * 3 + p) ; }

int main() {
	n = gi() ; m = gi() ; Q = gi() ; MOD = gi() ;
	for(int i = 1; i <= m; i ++) {
		U[i] = gi() , V[i] = gi() ;  C[i] = gi() ;
		if(i == 2) g = abs(C[i] - C[1]) ;
		else if(i > 2) g = __gcd((int)(abs(C[i] - C[1])) , g) ; 
	}
	if(!g) g = MOD ; 
	z = C[1] % g ; mod = __gcd(MOD , 3 * g) ;
	for(int i = 0,t = 1; i <= mod + 1; i += 2,t = 4ll * t % mod) ok[0][1ll * z * t % mod] = true ; 
	for(int i = 1,t = 2; i <= mod + 1; i += 2,t = 4ll * t % mod) ok[1][1ll * z * t % mod] = true ; 
	
    //for(int i=0,j=z;i<mod<<1;++i,j=(j<<1)%mod)ok[i&1][j]=1;
	for(int i = 1; i <= 6 * n; i ++) dsu[i] = i ; 
	
	for(int i = 1; i <= m; i ++) {
		int c = (C[i] - z) / g ; 
		c %= 3 ; 
		for(int q = 0; q < 2; q ++) 
			for(int p = 0; p < 3; p ++) {
				dsu[Find(ID(U[i],q,p))] = Find(ID(V[i] , q ^ 1 , (2*p+c)%3)) ; 
				dsu[Find(ID(V[i],q,p))] = Find(ID(U[i] , q ^ 1 , (2*p+c)%3)) ; 
			}
	}
	int s , t , r ;
	while(Q --) {
		s = gi() ; t = gi() ; r = gi() ; r = (r + z) % mod ; 
		bool flag = false ; 
		for(int q = 0; q < 2; q ++) 
			for(int p = 0; p < 3; p ++) 
				if(Find(ID(t,0,0)) == Find(ID(s,q,p))) {
					if(ok[q][(r - p * g % mod + mod) % mod]) flag |= ok[q][(r - p * g % mod + mod) % mod] ; 
				}
		if(flag) puts("YES") ; 
		else puts("NO") ; 
	}
	return 0 ;
}


Measured memory_bytes: 18816
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'o')++count;
	}

	if (15 - s.length() + count >= 8) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

A,B = list(map(int,input().split()))
GCD = gcd(A,B)
CD = []
for i in range(1,int(GCD**(0.5))+1):
    if GCD % i == 0:
        CD.append(i)
        if not i == GCD//i:
            CD.append(GCD//i)
CD.sort()
ans = 1
tmp_idx = 0
CD.pop(0)
CD_old = CD[:]
while (len(CD_old)>0):
    tmp = CD_old.pop(0)
    CD_new = []
    for i in range(len(CD_old)):
        if not CD_old[i] % tmp == 0:
            CD_new.append(CD_old[i])
    ans += 1
    CD_old = CD_new
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int K,N; 
	int ans=0;
	cin>>N>>K;

	vector<int> v(N);
	for(int i=0;i<N;i++)cin>>v.at(i);
	sort(v.begin(),v.end());
	
	for(int i=0;i<K;i++) ans+=v.at(i);
	cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int gcd(int,int);

int main(){
    int x,y;
    cin>>x>>y;
    int i;
    int gcdans;
    if (x>=y) gcdans=gcd(x,y); else gcdans=gcd(y,x);
    cout<<gcdans<<endl;
    return 0;
}

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

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (long long)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005
 
int32_t main(){
sp;
    int bit[61] = {0};
    int n;
    cin>>n;
    for(int i = 1; i <= n; ++i){
        int x;
        cin>>x;
        for(int j = 0; j < 61; ++j){
            if(x&(1LL<<j))
                ++bit[j];
        }
    }
    int ans = 0;
    for(int i = 0; i < 61; ++i){
        int in = bit[i];
        int out = n - bit[i];
        int val = (1LL<<i);
        val %= mod;
        ans += (1LL *(1LL * in * out) % mod * val) % mod;
        ans %= mod;
    }
    cout<<ans;
    return 0;
}

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

int main(){
    long long int n,x,ac=0,ans=0,max=0;
    string s="Yes";
    cin>>n;
    vector<long long int>a(10000000);
    vector<long long int>b(10000000);
    vector<long long int>c(10000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        
        if(a[i+1]-a[i]<-1){
               s="No";
        }
        else if(a[i+1]-a[i]==-1){
            if(ac==0){
                ac=1;
            }
            else{
                s="No";
            }
        }            
        else{
            if(a[i+1]!=a[i]){
            	ac=0;
            }
        }
        
       
    }
 
    cout<<s<<endl;


    return 0;
}

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

main(){
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  bool ansis = false;
  for(int i=n-1; i>=m-1; --i){
    if(s[i] == '?' || s[i] == t[m-1]){
      ansis = true;
      for(int j=0; j<m; ++j){
        if(s[i-j] != '?' && s[i-j] != t[m-1-j]) ansis = false;
      }
      if(ansis){
        for(int j=0; j<m; ++j){
          s[i-j] = t[m-1-j];
        }
        break;
      }
    }
    if(ansis) break;
  }
  if(!ansis){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i=0; i<n; ++i){
    if(s[i] == '?') s[i] = 'a';
  }
  cout << s << endl;
}

Measured memory_bytes: 3504
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    using namespace std;
    #define INF 10000000;
     
    int main() {
        string s,sum;
        cin >> s;
        for(int i=0;i<s.size();i++){
            if(i%2 == 0)sum += s[i];
        }
        cout << sum <<endl;
    }

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

long long n,ans;
bool p;

void exgcd(long long a,long long b,long long &d,long long &x,long long &y){
	if(!b)d=a,x=1,y=0;
	else exgcd(b,a%b,d,y,x),y-=(a/b)*x;
}

int main(){
	scanf("%lld",&n);
	n*=2LL;
	ans=n-1;
	for(long long i=1;i*i<=n;i++)if(n%i==0){
		long long d,x,y;
		exgcd(i,n/i,d,x,y);
		if(d>1)continue;
		if(x>0&&i*x-1>0)ans=min(ans,i*x-1);
		if(x<0&&i*(-x)>0)ans=min(ans,i*(-x)); 
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int A, B, K;
string s;
int main(){
	cin >> A >> B >> K;

	if (2*K >= B - A + 2) {
		for (int i = A; i <= B; ++i) {
			cout << i << endl;
		}
	}
	else {
		for (int i = A; i < A + K; ++i) {
			cout << i << endl;
		}
		for (int i = B - K + 1; i <= B; ++i) {
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k, q int
	fmt.Scan(&n, &k, &q)

	ans := make([]int, n)
	for i := 0; i < q; i++ {
		var a int
		fmt.Scan(&a)
		ans[a-1] += 1
	}

	for _, v := range ans {
		if v+k-q > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s, a = "2019/04/30";
    cin >> s;
    if(s <= a) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

Measured memory_bytes: 256
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
INF = 10**15
DD = ((1,0),(0,1),(-1,0),(0,-1))
S = input()
if 'A' in S and 'B' in S:
    print ('Yes')
else:
    print ('No')


Measured memory_bytes: 40556