akhauriyash/Code-Regression huggingface dataset:
#a
s=input()
n=len(s)+1
a=[-1]*n
INF = 10**6

indecies=set()

for i in range(1,n-1):
    if(s[i-1:i+1]=="><"):
        a[i]=0
        indecies.add(i)
    elif(s[i-1:i+1]=="<>"):
        a[i] = INF

if s[0]=="<":
    a[0] = 0
    indecies.add(0)
else:
    a[0] = INF

if s[n-2]==">":
    a[n-1] = 0
    indecies.add(n-1)
else:
    a[n-1] = INF
    
for ind in indecies:
    l=ind-1
    now = 1
    while(0<=l):
        if(a[l]<0):
            a[l]=now
            l -= 1
            now += 1
        else:
            if(a[l]==INF):
                a[l] = now
            else:
                a[l]=max(now, a[l])
            break
            
    r=ind+1
    now = 1
    while(r<n):
        if(a[r]<0):
            a[r]=now
            r += 1
            now += 1
        else:
            if(a[r]==INF):
                a[r] = now
            else:
                a[r]=max(now, a[r])
            break
            
print(sum(a))     

Measured memory_bytes: 23328
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
use std::cmp::max;
fn main() {
    let (a,b) = get!(i32,i32);

    println!("{}", max(max(a+b,a-b),a*b));
}


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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    map <char, char> m{
        {'A', 'T'}, {'T', 'A'}, {'G', 'C'}, {'C', 'G'}
    };

    char c; cin >> c;
    cout << m[c] << '\n';
    return 0;
}


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

using namespace std;

#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<string> vs;

typedef vector<vector<int>> vvi;
typedef vector<vector<ld>> vvd;
typedef vector<vector<ll>> vvl;

typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<ld>>> vvvd;
typedef vector<vector<vector<ll>>> vvvl;

constexpr int MOD = 1000000007;
constexpr char nl = '\n';

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

  int N;
  cin >> N;
  map<string, int> S;

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S[s] = 1;
  }

  cout << S.size() << nl;
}


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

	// ?????????????????\???
	int num1, num2, num3;
	scanf("%d %d %d", &num1, &num2, &num3);

	// ?????????????¬???????????????????????????????
	int table[num1][num2];
	
	for(int cnt1 = 0; cnt1 < num1; cnt1++) {
		
		for(int cnt2 = 0; cnt2 < num2; cnt2++) {
			
			scanf("%d", &table[cnt1][cnt2]);
		}
	}
	
	int grid[num2][num3];
	
	for(int cnt1 = 0; cnt1 < num2; cnt1++) {
		
		for(int cnt2 = 0; cnt2 < num3; cnt2++) {
			
			scanf("%d", &grid[cnt1][cnt2]);
		}
	}

	// 2??????????¬????????????????????¨?????????????
	long sum[num1][num3];
	
	for(int cnt1 = 0; cnt1 < num1; cnt1++) {
		
		for(int cnt2 = 0; cnt2 < num3; cnt2++) {
			
			sum[cnt1][cnt2] = 0;
		}
	}

	for (int cnt0 = 0; cnt0 < num1; cnt0++) {

		for (int cnt1 = 0; cnt1 < num3; cnt1++) {

			for (int cnt2 = 0; cnt2 < num2; cnt2++) {

				sum[cnt0][cnt1] += table[cnt0][cnt2] * grid[cnt2][cnt1];

			}
			
			if (cnt1 >= num3-1) {

				printf("%ld\n", sum[cnt0][cnt1]);

			} else {

				printf("%ld ", sum[cnt0][cnt1]);

			}
		}
	}
	return 0;
}

Measured memory_bytes: 1924
from math import gcd
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]
C = [0 for i in range(N)]
B[0] = A[0]
C[0] = A[N - 1]
for i in range(1, N):
    B[i] = gcd(B[i - 1], A[i])
    C[i] = gcd(C[i - 1], A[N - i - 1])


ans = 0
for i in range(N):
    if i != 0 and i != N - 1:
        ans = max(ans, gcd(B[i - 1], C[N - i - 2]))
    elif i == 0:
        ans = max(ans, C[N - 2])
    else:
        ans = max(ans, B[N - 2])

print(ans)


Measured memory_bytes: 21076
#include <stdio.h>

int main(){
	int data_sets[10000], data_sets2[10000], data_sets3[10000];
	int i = 0, j = 0;
	for(i=0;;i++){
		scanf("%d %d %d", &data_sets[i], &data_sets2[i], &data_sets3[i]);
		if(data_sets[i]==-1&&data_sets2[i]==-1&&data_sets3[i]==-1) break;
	}
	for(j=0;j<i;j++){
		if(data_sets[j]==-1 || data_sets2[j]==-1){
			printf("F\n");
		}else{
			int temp_add = data_sets[j] + data_sets2[j];
			if(temp_add >= 80){printf("A\n");}
			else if(temp_add >= 65){printf("B\n");}
			else if(temp_add >= 50){printf("C\n");}
			else if(temp_add >= 30){if(data_sets3[j]>=50){printf("C\n");}else{printf("D\n");}}
			else{printf("F\n");}
		}
	}
	return 0;
}

Measured memory_bytes: 1028
from collections import defaultdict


def main():
    n = int(input())
    strings = [input() for i in range(n)]
    s_dict = defaultdict(int)
    for s in strings:
        s_dict[s] -= 1
    s_sorted = sorted(s_dict.items(), key=lambda x: (x[1], x[0]))

    max_num = s_sorted[0][1]
    for t in s_sorted:
        if t[1] == max_num:
            print(t[0])
        else:
            break
 

if __name__ == "__main__":
    main()


Measured memory_bytes: 61076
N = int(input())
A = [int(input()) for i in range(N)]
seen = set()
p = 1
while True:
    if not p in seen:
        seen.add(p)
        if p == 2:
            print(len(seen) - 1)
            break
        p = A[p-1]
    else:
        print(-1)
        break

Measured memory_bytes: 18848
N = gets.to_i
ini = Hash.new(0)
N.times do |i|
	name = gets.chomp
	ini[name[0]] += 1
end

ans = 0
%w(M A R C H).combination(3).to_a.each do |s|
	ans += ini[s[0]] * ini[s[1]] * ini[s[2]]
end

p ans

Measured memory_bytes: 2044
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
lis = Is()
lis = sorted(lis)
print(lis[n//2]-lis[n//2 -1])

Measured memory_bytes: 15060
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int H, A;
	
	cin>>H>>A;
	
	cout<<(H + A - 1)/A<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
void main() {
	auto S = rs;
	if(S[2] == S[3] && S[4] == S[5]) writeln("Yes");
	else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge{int u,v,w;}vs[N<<1];
int n,q,tA[N],tB[N],ee,st[N],cnt,F1[N],F2[N],fa[N],m;
inline bool cmp(const edge &a,const edge &b){return a.w<b.w;}
inline int getfa(int x){return fa[x]==x? x:fa[x]=getfa(fa[x]);}
int main()
{
	// freopen("read.in","r",stdin);
	n=read(); m=q=read();
	memset(tA,0x3f,sizeof tA);
	memset(F1,0x3f,sizeof F1);
	while(q--)
	{
		int u=read(), v=read(), w=read();
		vs[++cnt]=(edge){u+1,v+1,w};
		tA[u]=min(tA[u],w+1); tA[v]=min(tA[v],w+2);
	}
	for(int i=0;i<n;i++) F1[i]=min(F1[((i-1)+n)%n]+2,tA[i]);
	for(int i=0;i<n;i++) F1[i]=min(F1[((i-1)+n)%n]+2,tA[i]);
	for(int i=0;i<n;i++) vs[++cnt]=(edge){i+1,(i+1)%n+1,F1[i]};
	// cout << cnt << endl;
	sort(vs+1,vs+1+cnt,cmp);
	// assert(0);
	for(int i=1;i<=n;i++) fa[i]=i;
	long long Ans=0;
	for(int i=1;i<=cnt;i++)
	{
		int f1=getfa(vs[i].u),f2=getfa(vs[i].v);
		if(f1!=f2) 
		{
			Ans+=vs[i].w;
			fa[f1]=f2; n--;
		}
		if(n==1) break;
	}
	cout << Ans << endl;  return 0;
}

Measured memory_bytes: 11392
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

#define all(x) x.begin(), x.end()
#define all_r(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, n) for(int i = n; i >= 0; --i)
#define f first
#define s second
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	switch(N % 10) {
		case 2: case 4: case 5: case 7: case 9:
		cout << "hon\n";
		break;
		case 0: case 1: case 6: case 8:
		cout << "pon\n";
		break;
		default:
		cout << "bon\n";
	}
 	return 0;
}

Measured memory_bytes: 3644
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
dict = {"r":p, "s":r, "p":s}
val = 0

for i in range(n):
  if i < k:
    val += dict[t[i]]
  elif t[i-k] != t[i]:
    val += dict[t[i]]
  else:
    t[i] = " "

print(val)

Measured memory_bytes: 4084
n = int(input())
t, x, y = [0], [0], [0]
for i in range(n):
    te, xe, ye = [int(e) for e in input().split()]
    t.append(te)
    x.append(xe)
    y.append(ye)

for i in range(1, n + 1):
    dt = t[i] - t[i-1]
    dx = abs(x[i] - x[i-1])
    dy = abs(y[i] - y[i-1])
    if dt < (dx + dy) or dt % 2 != (dx + dy) % 2:
        print('No')
        exit()

print('Yes')


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

int h, w;
int d[10][10];

int main() {
	cin >> h >> w;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			cin >> d[i][j];

	for (int k = 0; k < 10; k++)
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	int rv = 0;
	for (int i = 0, a; i < h; i++)
		for (int j = 0; j < w; j++) {
			cin >> a;
			if (a < 0)
				continue;
			rv += d[a][1];
		}

	cout << rv << endl;
}


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

/* 
 * g++ -std=c++17 A.cpp -o A
 */
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<vector<int>> vac(N+1);
  for (int i = 1; i <= N; i++) {
    int h;
    for (int k = 0; k < 3; k++) {
      cin>>h;
      vac[i].push_back(h);
    }
  }
  vector<vector<int>> dp(N+1);
  for (int i = 0; i < 3; i++)
    dp[1].push_back(vac[1][i]);
  for (int i = 2; i <= N; i++) {
    dp[i].push_back(vac[i][0] + max(dp[i-1][1], dp[i-1][2]));
    dp[i].push_back(vac[i][1] + max(dp[i-1][0], dp[i-1][2]));
    dp[i].push_back(vac[i][2] + max(dp[i-1][1], dp[i-1][0]));
  }
  cout << max(dp[N][0], max(dp[N][1], dp[N][2]));
  cout<<endl;
}

Measured memory_bytes: 11264
import itertools


def main():
    # S = input()
    N, M, Q = list(map(int, input().split(' ')))
    
    inputs = []
    for _ in range(Q):
        inputs.append(list(map(int, input().split(' '))))
    
    out = 0    
    # inputs = sorted(inputs, key=lambda x: x[-1], reverse=True)
    # print(inputs)

    # A = [0]*N
    # for i in range(M):
    #     for j in range(i, M):
    # As = list(itertools.combinations([i for i in range(1, M+1)], N))
    As = list(itertools.combinations_with_replacement([i for i in range(1, M+1)], N))
    
    # print(As)

    tmp = 0

    # print('--')
        
    
    for A in As:
        out = 0
        for i in range(len(inputs)):
            
            ai = inputs[i][0]
            bi = inputs[i][1]
            ci = inputs[i][2]
            di = inputs[i][3]
        
            if A[bi-1] - A[ai-1] == ci:
                # print(A, di)
                out += di
            tmp = max(tmp, out)
        # print('---')
    print(tmp)
                
        
        
        
    
    

    
    
main()

Measured memory_bytes: 84816
import java.util.*;
import java.text.DecimalFormat;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		int counter = 0;

		for (int i = 0; i < (S.length()/2); i++)
		{
			if (S.charAt(i) != S.charAt(S.length()-(i+1)))
				counter++;
		}

		System.out.println(counter);
	}
}

Measured memory_bytes: 23764
#!/usr/bin/perl

my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);
( my $s = <STDIN> ) =~ s/[\x00-\x20]+$//io;

my $mx = 0;
for(my $i=1;$i<$n;$i++){
  my %c1 = ();
  my %c2 = ();
  for(my $j=0;$j<$n;$j++){
    my $cc = substr($s,$j,1);
    if( $j<$i ){
      $c1{$cc} ++;
    } else {
      $c2{$cc} ++;
    }
  }
  my $ct = 0;
  foreach my $cc ( 'a' .. 'z' ){
    $ct++ if $c1{$cc}>0 and $c2{$cc}>0;
  }
  $mx = $ct if $ct > $mx;
}
print "$mx\n";



Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;

int linearSearch(vector<int> &v, int key){
	int n = v.size();
	int i = 0;
	while(v[i] != key){
		i++;
		if(i == n)
			return -1;
	}
	return i;
}

int binarySearch(vector<int> &v, int key){
	int left = 0;
	int right = v.size();
	while(left < right){
		int mid = (left + right) / 2;
		if(v[mid] == key)
			return mid;
		else {
			if(key < v[mid])
				right = mid;
			else left = mid + 1;
		}
	}
	return -1;
}

int main(){
	int n,q;
	vector<int> S,T;
	cin >> n;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		S.push_back(tmp);
	}
	cin >> q;
	for(int i = 0; i < q; i++){
		int tmp;
		cin >> tmp;
		T.push_back(tmp);
	}

	int cnt = 0;
	for(int i = 0; i < q; i++)
		if(binarySearch(S,T[i]) != -1) cnt++;
	cout << cnt << endl;
}

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

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const int64_t INF = INT64_MAX;

class State
{
public:
    int x, y, d;

    State(int x0, int y0, int d0)
    {
        x = x0;
        y = y0;
        d = d0;
    }

    bool operator<(const State &other) const
    {
        return x < other.x;
    }
};

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    vector<string> c(H);
    for (int i = 0; i < H; i++)
    {
        cin >> c.at(i);
    }

    x1--;
    y1--;
    x2--;
    y2--;

    vector<vector<vector<int64_t>>> g(H, vector<vector<int64_t>>(W, vector<int64_t>(4, INF)));
    priority_queue<pair<int64_t, State>, vector<pair<int64_t, State>>, greater<pair<int64_t, State>>> q;
    auto push = [&](int x, int y, int d, int64_t c) {
        if (g.at(x).at(y).at(d) <= c)
            return;
        g.at(x).at(y).at(d) = c;
        q.push(make_pair(c, State(x, y, d)));
    };
    for (int d = 0; d < 4; d++)
    {
        push(x1, y1, d, 0);
    }

    while (!q.empty())
    {
        int64_t cost = q.top().first;
        int x = q.top().second.x, y = q.top().second.y, d = q.top().second.d;
        q.pop();

        for (int nd = 0; nd < 4; nd++)
            push(x, y, nd, (cost + K - 1) / K * K);

        int nx = x + dx.at(d), ny = y + dy.at(d);
        if (nx < 0 || H <= nx || ny < 0 || W <= ny)
            continue;
        if (c.at(nx).at(ny) == '@')
            continue;
        push(x + dx.at(d), y + dy.at(d), d, cost + 1);
    }

    int64_t res = INF;
    for (int d = 0; d < 4; d++)
    {
        if (g.at(x2).at(y2).at(d) == INF)
            continue;
        int64_t t = g.at(x2).at(y2).at(d);
        res = min(res, (t + K - 1) / K);
    }
    cout << (res == INF ? -1 : res) << endl;

    return 0;
}


Measured memory_bytes: 144828
#include<bits/stdc++.h>
using namespace std;
const int N = 2e3 + 11;
#define FOR(i, a, b) for(int i = (a);i <= (b); i++)
#define ROF(i, a, b) for(int i = (a);i >= (b); i--)
#define pb push_back
int n, f[N], sz[N], sum[N];
char s[N];
vector<int> G[N];
void dp(int u, int fa){
    sz[u] = s[u] == '1';
    sum[u] = 0;
    int ma = 0, pos = 0;
    for(int v : G[u]){
        if(v == fa)continue;
        dp(v, u);
        sz[u] += sz[v];
        sum[u] += sum[v] + sz[v];
        if(sum[v] + sz[v] > ma)ma = sum[v] + sz[v], pos = v;
    }
    if(!pos)return ;
    if(ma <= sum[u] - ma)f[u] = sum[u] >> 1;
    else f[u] = sum[u] - ma + min(f[pos], (2 * ma - sum[u]) >> 1);
    //printf("u=%d f=%d sum-ma=%d fpos=%d xxx=%d\n", u, f[u], sum[u] - ma, f[pos], (2 * ma - sum[u]) >> 1);

    //printf("u=%d sum=%d sz=%d ma=%d\n", u, sum[u], sz[u], ma);

}
int main(){
    cin>>n>>s + 1;
    int u, v;
    FOR(i, 1, n - 1){
        scanf("%d%d", &u, &v);
        G[u].pb(v); G[v].pb(u);
    }
    int ans = 1e9;
    FOR(i, 1, n){
        memset(sz, 0, sizeof sz);
        memset(f, 0, sizeof f);
        memset(sum, 0, sizeof sum);
        dp(i, i);
        if(!(sum[i] & 1) && sum[i] == f[i] * 2)ans = min(ans, f[i]);
        //printf("i=%d sum=%d f=%d\n", i, sum[i], f[i]);
    }
    if(ans != 1e9)cout<<ans<<endl;
    else puts("-1");
    return 0;
}

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


void dfs(int u,vector<vector<int>>&g,vector<bool> &vis){
 
 vis[u]=1;
 for(auto v:g[u]){
      
        if(vis[v]==0){
        dfs(v,g,vis);
        }
 }

}

int main()
{

    int count=0;
int n,m;
cin>>n>>m;

vector<vector<int>> g(n+1);
vector<bool> vis(n+1,false);

for(int i=0;i<m;i++){

int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);

}


for(int i=1;i<=n;i++){

  if(vis[i]==false){
     
    dfs(i,g,vis);
    count++;
}
}
cout<<count-1<<endl;

}


Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n, k, x, y; cin >> n >> k >> x >> y;
    if(n <= k) cout << x * n << endl;
    else cout << x * k + y * (n - k) << endl;
}

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

typedef long long ll;
const ll InF = 1e15;

int main() {
  int n;
  cin>>n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin>>d[i];
  sort(d.begin(),d.end());
  if (n % 2 != 0) {
    cout<<0<<endl;
  } else {
    int low = n /2 - 1;
    int high = low + 1;
    int ans = d[high] - d[low];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 640
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
   



int main(){
   IOS

   
   int n; cin>>n;
   vi a(n);

   ll sum = 0;
   unordered_map<int,int> mp;
   for(int &x : a)cin>>x, sum += x, mp[x]++;

   int q; cin>>q;
   while(q--){
      int b, c; cin>>b>>c;

      int cnt = mp[b];
      mp.erase(mp.find(b));

      sum += (ll) cnt * (c - b);
      cout<<sum<<"\n";
      mp[c]+= cnt;
   }
   


}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
   if(b&1) res = res * a % mod;
        a = a * a % mod;
   b >>= 1;
    }

    return res;
}



Measured memory_bytes: 6992
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,W;
  cin>>N>>W;
  ll w[N],v[N];
  rep(i,N){
    cin>>w[i]>>v[i];
  }
  ll dp[N][W+1];
  rep(i,N){
    rep(j,W+1){
      dp[i][j]=-INF;
    }
  }
  dp[0][0]=0;
  dp[0][w[0]]=v[0];
  rep(i,N-1){
    rep(j,W+1){
       dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
       if(j+w[i+1]<=W)
          dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]],dp[i][j]+v[i+1]);
    }
  }
  ll ans=-INF;
  rep(i,W+1){
    ans=max(dp[N-1][i],ans);
  }
  cout<<ans<<endl;
  

}
  


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#include <string>
using namespace std;
int intinput() {
	int x;
	cin >> x;
	return x;
}
vector <int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
string stringinput() {
	string x;
	cin >> x;
	return x;
}
int main(){
	int ans = 0;
	int n = intinput();
	vector <int> a(10000);
	a = forintinput(n);
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	for(int i = 0; i < n-1; i++){
		ans += a[i] - a[i+1];
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const ll MOD0 = 1e9+7;
const ll MOD1 = 1e9+9;
const ll base = 4007;

ll modpow(ll a, int n, ll q){
	ll ret = 1, k = a;
	for(int i=0; (1<<i)<=n; i++){
		if( (1<<i)&n ) ret = ret * k % q;
		k = k*k % q;
	}
	return ret;
}

int main(){

//	ll p=0;
//	{
//		bool f[10000]={};
//		for(int i=2; i<10000; i++){
//			if( !f[i] ){
//				if( i>4005 ){
//					p = i;
//					break;
//				}
//				for(int j=i; j<10000; j+=i) f[j] = true;
//			}
//		}
//	}

	string s[2];
	rep(i,2) cin >> s[i];

	int ans = 0;
	ll hs[2][2][4005]={};
	rep(l,min(s[0].length(),s[1].length()) ){
		//cout << l << endl;
		set<pii> st;
		rep(k,2){
			rep(i,s[k].length()-l){
				int c = s[k][i+l] - 'a' + 1;
				hs[k][0][i] += modpow(base, c, MOD0);
				hs[k][0][i] %= MOD0;
				hs[k][1][i] += modpow(base, c, MOD1);
				hs[k][1][i] %= MOD1;
				auto key = pii(hs[k][0][i], hs[k][1][i]);
				if( k == 0 ){
					//cout << "insert " << i << " " << l+1 << " " << key << endl;
					st.insert( key );
				}else{
					//cout << "count  " << i << " " << l+1 << " " << key << endl;
					if( st.count(key) ){
						ans = max(ans, l+1);
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3488
#include <iostream>
#include<string>
#include<map>

using namespace std;

int main() {
	
	map<string, int> ball;
	string s, t;
	cin >> s >> t;

	int a, b;
	cin >> a >> b;

	ball[s] += a;
	ball[t] += b;

	string u;
	cin >> u;

	ball[u] -= 1;

	cout << ball[s] << " " << ball[t] << endl;

	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.algorithm,
    std.numeric, std.math, std.range;

void main()
{
    long n;
    readf("%d", &n);

    long ans = 0;
    foreach (x; 1 .. 10)
    {
        if (x > n)
        {
            break;
        }
        ans++;
    }
    foreach (x; 100 .. 1000)
    {
        if (x > n)
        {
            break;
        }
        ans++;
    }
    foreach (x; 10000 .. 100000)
    {
        if (x > n)
        {
            break;
        }
        ans++;
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll t[1<<20];
priority_queue< P, vector<P>, greater<P> > pq;

multiset<ll> st;

int main(void){
	int n,m,i,k,v;
	ll s;
	cin >> n;
	m = (1<<n);
	for(i=0; i<m; ++i){
		cin >> s;
		st.insert(-s);
	}
	st.insert(INF);
	pq.push(P(0,1));
	t[0] = INF;
	while(!pq.empty()){
		k = pq.top().first;
		v = pq.top().second;
		pq.pop();
		s = -(*st.upper_bound(-t[v-1]));
		if(s==-INF){
			cout << "No" << endl;
			return 0;
		}
		t[v] = s;
		while(k<n){
			++k;
			v *= 2;
			t[v] = s;
			pq.push(P(k,v+1));
		}
		st.erase(st.find(-s));
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 21880
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  cin>>n;
  vector<ll>v(n,0);
  multiset<double>st;
  for(ll i=0;i<n;i++){
    cin>>v[i];
    st.insert(v[i]);
  }
  for(ll i=0;i<n-1;i++){
    auto i1=st.begin();
    auto i2=i1;
    i2++;
    double tmp=(double)(*i1+*i2)/2;
    st.erase(i1);
    st.erase(i2);
    st.insert(tmp);
  }
  std::cout << std::fixed;
  cout<<setprecision(8)<<*st.begin()<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        for (int i = 0 ; i < a ; i++) {
            if ((i * b + c) % a == 0) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");

    }

}

Measured memory_bytes: 20948
n=int(input())
a=[]
for i in range(1,n+1):
    a.append(i)
p=list(map(int,input().split()))
q=list(map(int,input().split()))
from itertools import permutations
perm=permutations(a)
aa=0
bb=0
count=0
for i in perm:
    f=True
    for j in range(n):
        if(i[j]!=p[j]):
            f=False
    if(f):
        aa=count
    f=True
    for j in range(n):
        if(i[j]!=q[j]):
            f=False
    if(f):
        bb=count
    if(aa and bb):
        break
    count+=1
    # print(count,aa,bb)
print(abs(aa-bb))

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


int main(){
    int N;
    long long C;

    cin>>N>>C;

    vector<long long> x(N);
    vector<long long> v(N);

    for(int i = 0;i < N;i++){
        cin>>x[i]>>v[i];
    }

    long long res = 0;

{
    long long sum = 0;

    for(int i = 0;i < N;i++){
        sum += v[i];
        res = max(res,sum - x[i]);  
    }

    sum = 0;

    for(int i = N - 1; i >= 0;i--){
        sum += v[i];
        res = max(res,sum - (C - x[i]));
    }
}


{
    vector<long long> left(N);
    vector<long long> right(N);
    long long sum = 0;

    for(int i=0;i < N;i++){
        sum += v[i];
        left[i] = sum - x[i] * 2;
    }

    sum = 0;

    for(int i = N - 1;i >= 0;i--){
        sum += v[i];
        right[i] = sum - (C - x[i]);
    }

    for(int i = 1;i < N;i++){
        left[i] = max(left[i],left[i-1]);
    }

    for(int i = N - 2; i >= 0;i--){
        right[i] = max(right[i+1],right[i]);
    }

    for(int i = 0;i < N -1;i++){
        res = max(res,left[i] + right[i+1]);
    }
 
} 

{
    vector<long long> left(N);
    vector<long long> right(N);
    long long sum = 0;

    for(int i=0;i < N;i++){
        sum += v[i];
        left[i] = sum - x[i];
    }

    sum = 0;

    for(int i = N - 1;i >= 0;i--){
        sum += v[i];
        right[i] = sum - (C - x[i]) * 2;
    }

    for(int i = 1;i < N;i++){
        left[i] = max(left[i],left[i-1]);
    }

    for(int i = N - 2; i >= 0;i--){
        right[i] = max(right[i+1],right[i]);
    }

    for(int i = 0;i < N -1;i++){
        res = max(res,left[i] + right[i+1]);
    }
 
} 

    cout<<res<<endl;
}


Measured memory_bytes: 3424
#include <cstdio>           // printf(), scanf()

static const double EPS = 1e-10;
class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x, a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }
};

struct Segment
{
	Point p1, p2;
};

typedef Point Vector;
typedef Segment Line;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

Point
project(Segment s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / norm(base);
	return s.p1 + base * r;
}

Point
reflect(Segment s, Point p)
{
	return p + (project(s, p) - p) * 2.0;
}

int
main(int argc, char** argv)
{
	Segment s;
	Point p, a;
	int q;
	int x, y;
	int x1, y1, x2, y2;
	int i;

	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	s.p1.x = x1, s.p1.y = y1;
	s.p2.x = x2, s.p2.y = y2;

	scanf("%d", &q);
	for (i = 0; i < q; ++i)
	{
		scanf("%d %d", &x, &y);
		p.x = x, p.y = y;

		a = reflect(s, p);
		printf("%.10f %.10f\n", a.x, a.y);
	}

	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll Euclid(ll A, ll B){
    if(A<B) swap(A, B);
    ll C = B;
    while(C != 0){
        C = A%B;
        A = B;
        B = C;
    }
    return A;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll tmp = A[0];
    REP(i, N) tmp = Euclid(tmp, A[i]);
    bool flag = false;
    REP(i, N){
    	if(A[i] >= K && (A[i] - K)%tmp == 0) flag = true;
    }
    cout << (flag ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 1024
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll logx=30;
const ll N=4e2+5;
const ll INF=1e18+5;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll n,a[N],pre[N],dp[N][N];

ll F(ll L,ll R)
{
	ll mini=INF;
	if(L==R){return 0;}
	if(dp[L][R]!=-1){return dp[L][R];}
	for(ll i=L;i<R;i++){mini=min(mini,F(L,i)+F(i+1,R)+pre[R]-pre[L-1]);}
	return dp[L][R]=mini;
}

int main()
{
	cin>>n;
	ms(dp,-1);
	ll sum=0;
	for(ll i=1;i<=n;i++){cin>>a[i];sum+=a[i];pre[i]=sum;}
	cout<<F(1,n)<<endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
int main ()
{
    int i,l,a=0;
    char st[10];
    gets(st);
    l=strlen(st);
    for(i=0;i<l;i++)
    {

        if(st[i]=='A')
            a=1;
        else if(st[i]=='C')
        {

            if(a==1)
            {

            printf("Yes\n");
            return 0;
            }


        }
        else a=0;
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
/*
    Those who cannot remember the past are condemned to repeat it.
                                            - Dynamic Programming
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        long[] pre = new long[1001];

        for(int i=1 ; i<=1000 ; i++) pre[i] = i + pre[i-1];

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        int[] a = new int[n];
        st = new StringTokenizer(br.readLine());
        for(int i=0 ; i<n ; i++) a[i] = Integer.parseInt(st.nextToken());

        double sum = 0;
        double ans = 0;
        for(int i=0 ; i<k ; i++) {
            sum += (double)pre[a[i]]/a[i];
        }

        ans = Math.max(sum, ans);

        for(int i=k ; i<n ; i++) {
            sum -= (double)pre[a[i-k]]/a[i-k];
            sum += (double)pre[a[i]]/a[i];
            ans = Math.max(sum, ans);
        }

        pw.println(ans);


        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 44828
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, x;
    set <ll> s;
    cin >> n;
    for(i = 0; i < n; i++)
        cin >> x, s.insert(x);
    cout << (s.size() == n ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 9600
sl=list(input())
cl=[]

cl.append(sl[0])

for i in range(1,4):
  if cl.count(sl[i]) == 0:
    cl.append(sl[i])


if len(cl)!=2 :
  answer='No'
elif sl.count(cl[0])==2 and sl.count(cl[1])==2:
  answer='Yes'
else:
  answer='No'
  
print(answer)

Measured memory_bytes: 3060
k = int(input())
aList = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')

print(aList[k-1])

Measured memory_bytes: 2940
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define fast_cin ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define pb push_back
#define all(con) (con).begin(), (con).end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<b;++i)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define rpe(i,a,b) for(i=a-1;i>=b;i--)
#define rp(i,n) rep(i,0,n)
#define fr(i,n) fre(i,1,n)
#define ff(i,a,b) for(int i=a;i<=b;i++)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif
 
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
 
int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
		res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}
 
const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;
 
const int N = 1e5 + 10 ;
 
void solve() {
        int n;
        cin>>n;
        map<int,int> m;
        for(int i=0;i<n;i++) {
                int x;
                cin>>x;
                if(m[x]>0) {
                        cout<<"NO"<<endl;
                        return;
                }
                else {
                        m[x]++;
                }
        }
        cout<<"YES"<<endl;
}
 
signed main() {
        fast_cin;
	
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
        #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    	#endif
	
	int tests=1;
	// cin>>tests;
	while(tests--) {
		solve();
	}
 
return 0 ;
}
 

Measured memory_bytes: 12800
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

const int INF = 1000, MAX = 200;
string a, b;
int num;
int mat[MAX][MAX];
bool dmat[MAX][MAX];
bool visited[MAX];

void input() {
	string s;
	cin >> s;

	const int pos = s.find('-');
	a = s.substr(0, pos);
	b = s.substr(pos + 1);
}

void dfs(int v) {
	visited[v] = true;
	for(int i = 0; i < num; ++i)
		if(!visited[i] && dmat[v][i])
			dfs(i);
}

bool check(int from, int to) {
	if(mat[from][to] % 2 == 0)
		return false;
	memset(visited, false, sizeof(visited));
	dfs(from);
	return visited[to];
}

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

	for(int n; cin >> n, n;) {
		map<string, int> convert;
		memset(dmat, false, sizeof(dmat));
		fill(mat[0], mat[0] + MAX * MAX, INF);
		for(int i = 0; i < num; ++i)
			mat[i][i] = 0;

		while(n--) {
			input();

			if(!convert.count(a))
				convert.insert(make_pair(a, convert.size()));

			if(!convert.count(b))
				convert.insert(make_pair(b, convert.size()));

			const int a_id = convert[a], b_id = convert[b];
			dmat[a_id][b_id] = mat[a_id][b_id] = mat[b_id][a_id] = 1;
		}

		num = convert.size();
		for(int k = 0; k < num; ++k)
			for(int i = 0; i < num; ++i)
				for(int j = 0; j < num; ++j)
					chmin(mat[i][j], mat[i][k] + mat[k][j]);

		vector<vector<bool> > same(num, vector<bool>(num, false));
		for(int i = 0; i < num; ++i) {
			for(int j = i + 1; j < num; ++j) {
				if(mat[i][j] & 1)
					continue;

				bool is_same = false;

				for(int k = 0; k < num; ++k) {
					if(i == k || j == k)
						continue;

					if((dmat[i][k] && dmat[j][k]) || (dmat[k][i] && dmat[k][j]))
						is_same = true;

					if((dmat[i][k] && dmat[k][j]) || (dmat[j][k] && dmat[k][i]))
						goto next;
				}

				same[i][j] = same[j][i] = is_same;
			next:;
			}
		}

		for(int i = 0; i < num; ++i)
			for(int j = 0; j < num; ++j)
				dmat[i][j] |= same[i][j];

		int m;
		cin >> m;

		cout << convert.size() << endl;
		while(m--) {
			input();
			if(!convert.count(a) || !convert.count(b))
				cout << "NO" << endl;
			else
				cout << (check(convert[a], convert[b]) ? "YES" : "NO") << endl;			
		}
	}

	return EXIT_SUCCESS;
}

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

const int N = 1e5 + 10;

long long st[N], delta[N], coef[N];
int n, top, Q;

void solve(long long val, long long coef) {
  int ind = upper_bound(st + 1, st + top + 1, val) - st - 1;
  if(!ind) {
    delta[1] += coef;
    delta[val + 1] -= coef;
  } else {
    ::coef[ind] += val / st[ind] * coef;
    solve(val % st[ind], coef);
  }
}

int main(void) {
  scanf("%d%d", &n, &Q);
  st[++top] = n;
  for(int i = 1; i <= Q; i++) {
    long long x;
    scanf("%lld", &x);
    while(top && st[top] >= x) {
      top--;
    }
    st[++top] = x;
  }
  coef[top] = 1;
  for(int i = top; i > 1; i--) {
    coef[i - 1] += st[i] / st[i - 1] * coef[i];
    solve(st[i] % st[i - 1], coef[i]);
  }
  delta[1] += coef[1];
  delta[st[1] + 1] -= coef[1];
  for(int i = 1; i <= n; i++) {
    printf("%lld\n", delta[i] += delta[i - 1]);
  }
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  
  double m = 0;
  rep(i, N) m += a[i];
  m /= N;
  int M = round(m);
  
  int ans = 0;
  rep(i, N) ans += abs(M-a[i])*abs(M-a[i]);
  cout << ans << endl;
  
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main(){
    unsigned long long int n,a,b;

    cin >> n >> a >> b;

    unsigned long long int x = n/(a+b), ans;

    ans = x*a;

    unsigned long long int nokori = n-(a+b)*x;

    if(nokori >= a) ans+=a;
    else ans+=nokori;

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define piii pair<ll, pii>
#define MOD 1000000007
#define M 100005
#define inf 1000000005
using namespace std;
ll dp[M][3];
int main(){
    //ll t; cin>> t; while(t--){
        ll n;
        cin>> n;

        for(ll i =0;i<n;i++){
            ll a[3];
            cin>> a[0] >> a[1] >> a[2];
            if(i==0)
            for(ll j =0;j<3;j++){
                dp[i][j] = a[j];
            }
            else {
                for(ll j =0;j<3;j++){
                    for(ll k =0;k<3;k++){
                        if(j != k) dp[i][k] = max(dp[i][k], dp[i-1][j]+a[k]);
                    }
                }
            }

        }
        cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t, u;
    ll a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s)
    {
        a--;
    }
    else
    {
        b--;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256