akhauriyash/Code-Regression huggingface dataset:
n=int(input())
w=[]
for i in range(n):
    w.append(input())

for i in range(n-1):
    s_1=w[i]
    s_2=w[i+1]
    if s_1[-1]!=s_2[0]:
        print("No")
        exit()

for i in range(n-1):
    flag=True
    for j in range(i+1,n):
        if w[i]==w[j]:
            flag=False
            print("No")
            exit()
if flag:
    print("Yes")

Measured memory_bytes: 3064
from collections import deque
d = deque()
n = int(input())
alist = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 0:
        d.append(alist[i])
    else:
        d.appendleft(alist[i])
if n % 2 == 0:
    d = list(d)
else:
    d = list(d)[::-1]
for element in d:
    print(element, end=" ")
print()


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

int main(){
	vector<vector<int>> bingo(3,vector<int>(3));
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >> bingo.at(i).at(j);
		}
	}
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(a==bingo.at(i).at(j)){
					bingo.at(i).at(j)=0;
				}
			}
		}
	}
	if((bingo.at(0).at(0)==0&&bingo.at(0).at(1)==0&&bingo.at(0).at(2)==0)||(bingo.at(1).at(0)==0&&bingo.at(1).at(1)==0&&bingo.at(1).at(2)==0)||(bingo.at(2).at(0)==0&&bingo.at(2).at(1)==0&&bingo.at(2).at(2)==0)||(bingo.at(0).at(0)==0&&bingo.at(1).at(0)==0&&bingo.at(2).at(0)==0)||(bingo.at(0).at(1)==0&&bingo.at(1).at(1)==0&&bingo.at(2).at(1)==0)||(bingo.at(0).at(2)==0&&bingo.at(1).at(2)==0&&bingo.at(2).at(2)==0)||(bingo.at(0).at(0)==0&&bingo.at(1).at(1)==0&&bingo.at(2).at(2)==0)||	(bingo.at(2).at(0)==0&&bingo.at(1).at(1)==0&&bingo.at(0).at(2)==0)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N, K, l[50], ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> l[i];
    sort(l, l + N);
    for (int i = 0; i < K; i++) ans += l[N-i-1];
    cout << ans << endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split()[:2])
AHW=[input() for _ in range(H)]

AHWr=[['#']*(W+2) for _ in range(H+2)]

for i in range(H+2):
    for j in range(W+2):
        if 1<= i and i<=H and 1<=j and j<=W:
            print(AHW[i-1][j-1],end="")
        else:
            print(AHWr[i][j],end="")
    print()



Measured memory_bytes: 4468
import itertools
n, a, b, c = map(int, input().split())
abc = sorted([a, b, c])
ll = [int(input()) for _ in range(n)]
ls = [0, 1, 2, 3]
m_cost = 10 ** 9
for i in itertools.product(ls, repeat=n):
    t = [[0, 0] for _ in range(4)]
    if 1 in i and 2 in i and 3 in i:
        for j in range(n):
            t[i[j]][0] += ll[j]
            t[i[j]][1] += 1
        st = sorted([t[1][0], t[2][0], t[3][0]])
        c = (t[1][1] + t[2][1] + t[3][1] - 3) * 10
        c += abs(abc[0] - st[0]) + abs(abc[1] - st[1]) + abs(abc[2] - st[2])
        m_cost = min(m_cost, c)
print(m_cost)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <set>

using namespace std;

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

int main() {
  set<int> ac;
  map<int, int> pre_wa;
  int penalty = 0;

  int n, m;
  cin >> n >> m;
  Rep(i, m) {
    int q;
    string res;
    cin >> q >> res;
    if (ac.find(q) != ac.end()) continue;

    if (res == "AC") {
      ac.insert(q);
      penalty += pre_wa[q];
    } else if (res == "WA") {
      pre_wa[q]++;
    }
  }

  cout << ac.size() << " " << penalty << endl;

  return 0;
}


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

using namespace std;

int main()
{
    bool mark[5] = {0};
    int a, b;
    cin >> a >> b;
    mark[a] = mark[b] = true;
    for (int i = 1; i <= 3; i++)
        if (!mark[i])
            cout << i;

    return 0;
}

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

#define endl '\n'
#define int long long int

using namespace std;
     
int gcd(int a, int b)
{
        return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b)
{
        return (a*b)/gcd(a,b);
}
int ncr(int n, int k)
{
        int res = 1;
        if ( k > n - k )
            k = n - k;
     
        for (int i = 0; i < k; ++i)
        {
            res *= (n - i);
            res /= (i + 1);
        }
        return res;
}

map<int, int> dpArr;

int dp(int arr[],int n)
{
        if(n<=1)
        {
            if( n == 0) return dpArr[0];
            return dpArr[1];
        }
        if(dpArr.count(n)){
            return dpArr[n];
        }
        dpArr[n] =  dp(arr,n-1) + abs(arr[n-1] - arr[n]);
        if(n > 1) dpArr[n] = min(dpArr[n], dp(arr, n-2)+ abs(arr[n-2] - arr[n]));
        return dpArr[n];
}
     
signed main()
{
        int n;
        cin >> n;
        int arr[n];
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        dpArr[0] = 0;
        dpArr[1] = abs(arr[0] - arr[1]);
        cout << dp(arr,n-1);
     
        return 0;
}

Measured memory_bytes: 15104
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static double[] min(int B , int M){
		double theta = M * 6.0;
		theta = theta * Math.PI / 180.0;		
		return new double[] { B * Math.cos(theta) , B * Math.sin(theta) };
	}
	static double[] hour(int A , int H , int M){
		double theta = H * 30.0;
		theta += M * 0.5;
		theta = theta * Math.PI / 180.0;
		return new double[] { A * Math.cos(theta) , A * Math.sin(theta) };
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt();
		int M = sc.nextInt();
		double mp[] = min(B , M);
		double hp[] = hour(A , H , M);
		double d = Math.hypot(mp[0] - hp[0], mp[1] - hp[1]);
		System.out.println(d);
	}
}


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

int main() {

  
long long A,B,N;
cin>>A>>B>>N;

if(N<B)
{
	cout<<floor((A*N)/B)<<endl;
}
else
{
	cout<<floor((A*(B-1))/B)<<endl;
}


	return 0;
}

Measured memory_bytes: 3728
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 3*1e5+5;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b;
    int pwur = qpow(b,e>>1);
    return pwur * pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    ///freopen("a.in","r",stdin);
    ///freopen("a.out","w",stdout);
    int n;
    cin>>n;
    vi v(n);
    int ans=0;
    rep(i,n){
        int a;
        cin>>a;
        while(a%2==0){
            a/=2;ans++;
        }
    }
    cout<<ans<<enl;


    return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>

int main(void){

  int m, f, r;
  while(1){
      scanf("%d %d %d", &m, &f, &r);

      if(m == -1 && f == -1 && r == -1){
        break;
      }

      if(m == -1 || f == -1){
        printf("F\n");
      }
      else if(m + f  >= 80){
        printf("A\n");
      }
      else if(m + f >= 65){
        printf("B\n");
      }
      else if(m + f >= 50){
        printf("C\n");
      }
      else if(m + f >= 30){
        if(r >= 50){
          printf("C\n");
        }
        else{
          printf("D\n");
        }
      }
      else{
        printf("F\n");
      }
  }
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int K;
    cin >> K;
    string ans = "";
    
    for(int i = 0;i < N;i++){
        if(S[i] == S[K - 1]){
            ans += S[K - 1];
        }else{
            ans += "*";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
 
int main(){
   string X;
   cin >> X;
   int cnts = 0, cntt = 0, ans = 0;
   char pre = X[0];

   REP(i, X.size()){
      if(X[i] == 'S'){
         cnts++;
      }
      else{
         if(cnts){
            cnts--;
         }
         else{
            ans++;
         }
      }
   }
   ans += cnts;
   cout << ans << endl;
   return 0;
}


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

using namespace std;
#define For(i,l,r) for (int i = l; i <= r; ++i)

char A[111111];
int n, k;
int main() {
	scanf("%s", A + 1);
	n = strlen(A + 1);
	scanf("%d", &k);
	For(i,1,n) {
		if (A[i] == 'a') continue ;
		int need = 'z' - A[i] + 1;
		if (k < need) {
			continue ;
		}
		k -= need; A[i] = 'a';
	}
	k %= 26;
	For(i,1,k) {
		++A[n];
		if (A[n] > 'z') A[n] = 'a';
	}
	puts(A + 1);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int aa[] = { 0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };

int main() {
	int x, y;
	
	scanf("%d%d", &x, &y);
	printf(aa[x] == aa[y] ? "Yes\n" : "No\n");
	return 0;
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int a[30], b[30];

string s1, s2;

void read() {
  cin >> s1 >> s2;
}

void solve() {
  for(int i = 0; s1[i]; ++i) {
    int nr1 = s1[i] - 'a' + 1;
    int nr2 = s2[i] - 'a' + 1;
    if (a[nr1] > 0) {
      if (a[nr1] != nr2) {
        cout << "No";
        return;
      }
    } else a[nr1] = nr2;
    if (b[nr2] > 0) {
      if (b[nr2] != nr1) {
        cout << "No";
        return;
      }
    } else b[nr2] = nr1;
  }
  cout << "Yes";
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 916
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    long double r;
    cin >> r;
    printf("%0.6Lf\n", (long double)(6.283185307179586232 * r));
    return 0;
}

Measured memory_bytes: 3784
#include<stdio.h>

int main(void){
	int x=0,a=0,b=0;
	scanf("%d %d %d",&x,&a,&b);
	
	if(0-a+b > x){
		printf("dangerous\n");
	}else if(0-a+b >0){
		printf("safe\n");	
	}else{
		printf("delicious\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 100005
using namespace std;

int main() {
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());
  cout << A[2]-A[0] << endl;
  return 0;
}

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

int main(void){
    int N;
    int a[100000];
    cin >> N;
	for(int i=0 ; i<N ; i++){
        cin >> a[i];    
    }
    sort(a, a+N);
  
    int ans_a = a[N-1];
    int ans_b = 0;
    int temp;
    for(int i=0 ; i < N -1 ; i++){
        temp = abs(2* a[i] - ans_a);
        //cout << a[i] << " " <<  temp << " " << abs(ans_b - med) << endl;  
        if (temp < abs(2 * ans_b - ans_a)) ans_b = a[i];
    }
    cout <<  ans_a << " " << ans_b << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vll vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//以上テンプレ

int main(){
    ll N,W;
    cin>>N>>W;
    vll dp(110,vl(100020,0));
    ll g,v;
    rep(i,N){
        cin>>g>>v;
        rep(j,W+1){
        if(j-g>=0) chmax(dp.at(i+1).at(j),dp.at(i).at(j-g)+v);
        chmax(dp.at(i+1).at(j),dp.at(i).at(j));
        }
    }
    cout<<dp.at(N).at(W)<<endl;
}

Measured memory_bytes: 87424
s = input()
t = input()

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i+1):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[k] != s[j+k-i] and s[j+k-i] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

for i in range(len(s)-len(t)+1):
    if s[i] == "?":
        if s[i:i+len(t)] == "?"*len(t):
            tmps = s[:i] + t + s[i+len(t):]
            for p in range(len(s)):
                if tmps[p] == "?":
                    tmps = tmps[:p] + "a" + tmps[p+1:]
            ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a = scan.nextInt();
        int b = scan.nextInt();
        StringBuilder sb = new StringBuilder();
        if (a == b) {
            for (int i = 0; i < Math.min(a,b); i++) {
                sb.append(a);
            }
        } else {
            int min = Math.min(a, b);
            int max = Math.max(a, b);
            for (int i = 0; i < max; i++) {
                sb.append(min);
            }
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 23764
def resolve():
    A, B = list(map(int, input().split()))
    ans = A
    i = A + 1
    warped = False
    while i <= B:
        if not warped and i % 4 == 0:
            i = B - B%4
            warped = True
        else:
            ans = ans ^ i
            i += 1
    print(ans)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38256
import qualified Data.List as L
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
main = do
  path1 <- getIntList
  path2 <- getIntList
  path3 <- getIntList
  let
    result1 = check path1 path2 path3
    result2 = check path1 path3 path2
    result3 = check path2 path1 path3
    result4 = check path2 path3 path1
    result5 = check path3 path1 path2
    result6 = check path3 path2 path1
  putStrLn $ if result1 || result2 || result3 || result4 || result5 || result6 then "YES" else "NO"
check [a1, b1] [a2, b2] [a3, b3] =
  check2 a1 b1 a2 b2 a3 b3 ||
  check2 a1 b1 a2 b2 b3 a3 ||
  check2 a1 b1 b2 a2 a3 b3 ||
  check2 a1 b1 b2 a2 b3 a3 ||
  check2 b1 a1 a2 b2 a3 b3 ||
  check2 b1 a1 b2 a2 a3 b3 ||
  check2 b1 a1 a2 b2 b3 a3 ||
  check2 b1 a1 b2 a2 b3 a3
check2 a1 b1 a2 b2 a3 b3 =
  b1 == a2 && b2 == a3 && [1,2,3,4] == L.sort [a1, a2, a3, b3]

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    vector<bool> red(n,false);
    vector<int32> cnt(n,1);
    red[0] = true;
    int32 ans = 1;
    REP(i,m){
        int32 x,y;
        cin >> x >> y;
        x--;y--;
        if(red[x] && !red[y]){
            ans++;
            red[y] = true;
        }
        if(red[x] && cnt[x] == 1){
            red[x] = false;
            ans--;
        }
        cnt[x]--;
        cnt[y]++;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int sortCount = 0;
        for (int i = 0; i < N; i++) {
            int flag = 0;
            int minj = i;
            for (int j = i; j < N; j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                    flag = 1;
                }
            }
            if (flag == 1) {
                int tmp = A[i];
                A[i] = A[minj];
                A[minj] = tmp;
                sortCount++;
            }
        }
        String delimiter = "";
        for (int a : A) {
            System.out.print(delimiter + a);
            delimiter = " ";
        }
        System.out.println();
        System.out.println(sortCount);
        sc.close();
    }
}


Measured memory_bytes: 26440
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <set>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

int mod = 1000000007;
struct mint{
    ll x;
    //コンストラクタ
    mint(ll x=0):x((x%mod+mod)%mod){}

    // %は若干遅いから，%を使わないようにしている
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x-= mod;
        return *this;
    }

    mint& operator-=(const mint a){
        if((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint power(ll t) const { // x^t
        if(!t) return 1;
        mint ans = power(t >> 1);
        ans *= ans;
        if(t&1) ans *= *this;
        return ans;
    }

    //素数が絡むやつ
    mint inv() const{
        return power(mod-2);
    }
    mint& operator/=(const mint a){
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const{
        mint res(*this);
        return res /= a;
    }
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(void){
    int n;
    cin >> n;
    int a[n];
    mint sum = 0;
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }

    mint ans = 0;
    REP(i,n){
        sum -= a[i];
        mint b(a[i]);
        ans += b * sum;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  map<char, ll> mp;
  rep(i, n) mp[s[i]]++;
  ll c = mp.size();
  bool ans = true;
  if(c == 1) {
    if(n > 1) ans = false;
  } else if(c == 2) {
    if(n > 2) ans = false;
  } else {
    ll r = (n + 2) / 3;
    for(auto v : mp)
      if(v.second > r) ans = false;
  }
  cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3728
"""
n, y = map(int, input().split())
a = -1
b = -1
c = -1
for i in range(n):
    for j in range(n - i):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            a = i
            b = j
            c = n - i - j
print(a, b, c)
"""
n, y = map(int, input().split())
a = -1
b = -1
c = -1
for i in range(min(y // 10000, n), -1, -1):
    for j in range(n - i, -1, -1):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            a = i
            b = j
            c = n - i - j
print(a, b, c)


Measured memory_bytes: 3064
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int a, b, c, k;cin>>a>>b>>c>>k;
  int cnt=0;
  while(a>=b){b*=2;cnt++;}
  while(b>=c){c*=2;cnt++;}
  cout<<(cnt<=k?"Yes":"No")<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3660
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		Long n = sc.nextLong();
		Long k = sc.nextLong();

		System.out.println(Math.min(n%k, k-n%k));
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long n, a, b;

int main() {
    cin >> n >> a >> b;
    long long cnt = n / (a+b);
    long long rest = n % (a+b);
    cout << cnt*a + min(a, rest) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int INF=0x3f3f3f3f;
const int N=2000005;

int a[N];

int read() {
    int x=0,v=1; char ch=getchar();
    for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
    for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
    return x*v;
}

bool check(int l,int r) {
    int mx = 0, mn = INF;
    for (int i = l; i <= r; i++) {
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    if (mn < l || mx > r) return true;
    int r1 = 0, r2 = 0;
    for(int i=l;i<=r;i++){
        if(a[i] != i){
            if(a[i]<i){//那么他是从小的换过来的
                if(r1<a[i]) r1=a[i];
                else return true;
            }else{//那么他是从大的换过来的
                if(r2<a[i]) r2=a[i];
                else return true;
            }
        }
    }
    return false;
}

int main(void) {
    int n=read(),x;
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=n;i++){
        if(a[i] != i){
            for(x=i;a[x+1]==x+1&&a[x+2]!=x+2;) x+= 2;
            x=min(x,n);// 得到交换的段，也就是这个是分段的，有些段是跨不过去的
            if(check(i, x)) return puts("No"), 0;
            i=x;
        }
    }
    return puts("Yes"),0;
}


Measured memory_bytes: 1408
#include <cstdio>

int main()
{
  int R, G, B, n;
  scanf("%d%d%d%d", &R, &G, &B, &n);
  int ans = 0;
  for (int r = 0; r <= n / R; ++r)
  {
    for (int g = 0; g <= (n - r * R) / G; ++g)
    {
      if ((n - r * R - g * G) % B == 0) ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	cout << (a + b + c >= 22 ? "bust" : "win") << "\n";	
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> box(n, 1);
    vector<bool> red(n, false);
    red[0] = true;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        box[a]--;
        box[b]++;
        if(red[a]) red[b] = true;
        if(box[a] == 0) red[a] = false;
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(red[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3700
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		int max = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			if (map.containsKey(x)) {
				map.put(x, map.get(x) + 1);
			} else {
				map.put(x, 1);
			}
			max = Math.max(max, x);
		}
		boolean flag = true;
		if (max % 2 == 0) {
			for (int i = max; i > max / 2; i--) {
				if (!map.containsKey(i) || map.get(i) < 2) {
					flag = false;
					break;
				}
			}
			if (!map.containsKey(max / 2) || map.get(max / 2) != 1) {
				flag = false;
			}
		} else {
			for (int i = max; i > max / 2 + 1; i--) {
				if (!map.containsKey(i) || map.get(i) < 2) {
					flag = false;
					break;
				}
			}
			if (!map.containsKey(max / 2 + 1) || map.get(max / 2 + 1) != 2) {
				flag = false;
			}
		}
		if (flag) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
	int a, b, x;
	cin >> a >> b >> x;
	if (a > x)
	{
		cout << "NO\n";
	}
	else
	{
		if (a + b >= x)
		{
			cout << "YES\n";
		}
		else
		{
			cout << "NO\n";
		}
	}

	return 0;
}

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

using namespace std;

const long long MOD = 1e9 + 7;

// a 0, t 1, g 2 , c 3

long long memo[105][4][4][4];

bool check(int prev[3], int cur){
	if (prev[1] == 0 && prev[2] == 2 && cur == 3){
		return false;
	}
	if (prev[1] == 2 && prev[2] == 0 && cur == 3){
		return false;
	}
	if (prev[1] == 0 && prev[2] == 3 && cur == 2){
		return false;
	}
	if (prev[0] == 0 && prev[2] == 2 && cur == 3){
		return false;
	}
	if (prev[0] == 0 && prev[1] == 2 && cur == 3){
		return false;
	}

	return true;
}

bool check3(int prev[3]){
	if (prev[0] == 0 && prev[1] == 2 && prev[2] == 3){
		return false;
	}
	if (prev[0] == 2 && prev[1] == 0 && prev[2] == 3){
		return false;
	}
	if (prev[0] == 0 && prev[1] == 3 && prev[2] == 2){
		return false;
	}
	return true;
}

long long calc(int k, int N, int prev[3]){
	long long ret = 0;

	if(memo[k][prev[0]][prev[1]][prev[2]] != -1){
		return memo[k][prev[0]][prev[1]][prev[2]];
	}

	for (int i = 0; i < 4; i++){
		if(check(prev, i)){
			if (k == N){
				ret += 1;
			} else {
				int prev_n[3] = {prev[1], prev[2], i};
				ret += calc(k + 1, N, prev_n);
				ret %= MOD;
			}
		}
	}
	ret %= MOD;
	memo[k][prev[0]][prev[1]][prev[2]] = ret;
	return ret;
}

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

	if(N == 3){
		cout << 61 << endl;
		return 0;
	}

	for (int i = 0; i < 105; i++){
		for (int j = 0; j < 4; j++){
			for (int k = 0; k < 4; k++){
				for (int l = 0; l < 4; l++){
					memo[i][j][k][l] = -1;
				}
			}
		}
	}

	long long ans = 0;
	for (int j = 0; j < 4; j++){
		for (int k = 0; k < 4; k++){
			for (int l = 0; l < 4; l++){
				int prev[3] = {j, k, l};
				if(check3(prev)){
					ans += calc(4, N, prev);
					ans %= MOD;
				}
			}
		}
	}

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

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <sstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define np(v) next_permutation(v.begin(), v.end())
#define pll pair < long long, long long>
#define all(a) a.begin(), a.end()
#define ull unsigned long long
#define pii pair < int, int >
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define y1 stupid_cmath
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define ll long long
#define f first
#define s second

const int inf = (int)3e6;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

string s;
int ans = 0, cur0, cur1;

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> s;
    int n = s.length();
    cur0 = cur1 = n;
    for(int i = 0; i < n; ++i){
        if(s[i] == '0'){
            int cur = max(min(i + 1, n - i), max(i, n - i - 1));
            cur0 = min(cur0, cur);
        }else{
            int cur = max(min(i + 1, n - i), max(i, n - i - 1));
            cur1 = min(cur1, cur);
        }
    }
    cout << max(cur0, cur1) << endl;
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

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

	string s;
	cin >> s;

	if (a >= 3200) COL(s);
	else COL("red");


	return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:(x[1], x[0]))

t = 0
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 61196
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("test_1.txt"));
		// Scanner sc = new Scanner(new File("test_2.txt"));
		// Scanner sc = new Scanner(new File("in4.txt"));
		int N = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}
		
		int ans = 0;
		for (int n : list) {
			boolean is_prime = true;
			for (int i = 2; i * i <= n; i++)
				if (n % i == 0)
					is_prime = false;
			if (is_prime)
				ans++;
		}
		System.out.println(ans);		
		
	}
}

Measured memory_bytes: 35872
#include<bits/stdc++.h>
#define int long long
using namespace std;
string str;
signed main()
{
	cin>>str;
	int len=str.length(),ans=0;
	for (int i=0;i<len;i++) ans+=signed(str[i])-signed('0');
	if (ans%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3780
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A[9];
    rep(ni,9){
        cin >> A[ni];
    }
    int B[9]={};

    int N;
    cin >> N;
    int b;
    rep(ni,N){
        cin >> b;
        rep(mi,9){
            if(A[mi]==b) B[mi]=1;
        }
    }
    if(B[0]==1){
        if(B[1]==1 && B[2]==1){
            cout << "Yes" << endl;
        }else if(B[4]==1 && B[8]==1){
            cout << "Yes" << endl;
        }else if(B[3]==1 && B[6]==1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(B[6]==1){
        if(B[7]==1 && B[8]==1){
            cout << "Yes" << endl;
        }else if(B[4]==1 && B[2]==1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(B[2]==1){
        if(B[5]==1 && B[8]==1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(B[3]==1){
        if(B[4]==1 && B[5]==1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }







    

}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
ans = n
index = 0
v = 0
for i, (bf, af) in enumerate(zip(a, a[1:])):
    v += bf
    for _ in range(index, i + 1):
        if v ^ af == v + af:
            break
        v -= a[index]
        index += 1
    ans += i + 1 - index
print(ans)


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int l = -1, r = -1;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == s[i+1]){
            l = i; r = i+1;
            break;
        }
        if(i < s.length()-2 and s[i] == s[i+2]){
            l = i; r = i+2;
            break;
        }
    }
    if(l == -1){
        cout << -1 << ' ' << -1 << endl;
    }else {
        cout << l + 1 << ' ' << r + 1 << endl;
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


const int INF=1001001001001001001ll;

int N;

vpint G[444444];
int dist[444444];
int pre[444444];

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main(){
    cin>>N;
    rep(i,N){
        int x;cin>>x;
        G[i].pb({i+N,x});
        G[i+N].pb({i,x});
    }
    rep(i,N-1){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].pb({b,c});
        G[b].pb({a,c});
    }

    fill_n(dist,2*N,INF);
    priority_queue<pint,vector<pint>,greater<pint>>que;
    rep(i,N){
        dist[i+N]=0;
        pre[i+N]=i+N;
        que.push({0,i+N});
    }

    while(que.size()){
        int c,v;
        tie(c,v)=que.top();
        que.pop();
        if(dist[v]<c)continue;
        for(auto &e:G[v]){
            if(dist[e.fi]<=c+e.se)continue;
            dist[e.fi]=c+e.se;
            pre[e.fi]=pre[v];
            que.push({dist[e.fi],e.fi});
        }
    }

    UnionFindTree uf(N);
    int ans=0;
    vector<tuple<int,int,int>>es;
    rep(i,N){
        for(auto &e:G[i]){
            int u=pre[i]-N;
            int v=pre[e.fi]-N;
            int c=dist[i]+dist[e.fi]+e.se;
            es.pb(make_tuple(c,u,v));
        }
    }
    sort(all(es));
    rep(i,es.size()){
        int c,u,v;
        tie(c,u,v)=es[i];
        if(uf.areSame(u,v))continue;
        uf.unite(u,v);
        ans+=c;
    }
    cout<<ans<<endl;
    return 0;
}


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

vector<vector<ll>> v(100010);


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

    
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans = 0;
    sort(a,a+n,greater<ll>());
    for(int i=k;i<n;i++){
        ans += a[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <ctime>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <functional>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#ifndef M_PI
#define M_PI 3.141592653589793238462643383279
#endif

#define int long long

#define mp make_pair
#define mt make_tuple
#define fr first
#define sc second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>

#define debug(x) cerr << #x << " = " << x << ", line = " << __LINE__ << endl

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef tuple<long long, long long, long long> tlll;
typedef tuple<int, int, int> tiii;
typedef tuple<int, int, int, int> tiiii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MOD = 1e9 + 7;



int32_t main()
{
#ifdef chikibambony
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int j = 0; j < n; ++j) {
        cin >> b[j];
    }
    reverse(all(b));
    int c = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            c = a[i];
            break;
        }
    }
    int l = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == c && b[i] == c) {
            l = i;
            break;
        }
    }
    int r = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == c && b[i] == c) {
            r = i;
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] != c && b[i] != c && l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }

    if (l <= r) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    for (int i = 0; i < n; ++i) {
        cout << b[i] << ' ';
        assert(b[i] != a[i]);
    }
    cout << "\n";

    return 0;
}

// mdn you are great bro

Measured memory_bytes: 6352
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, M) = nextIntList()
    val H = listOf(0) + nextIntList()
    val G = Graph(N, H)
    repeat(M) {
        val (a, b) = nextIntList()
        G.addEdge(a, b)
        G.addEdge(b, a)
    }
    val ans = G.peaks()
    println(ans)
}

class Graph(private val v: Int, private val H: List<Int>) {
    private val vec = Array(v + 1) { mutableListOf<E>() }

    fun addEdge(a: Int, b: Int, c: Int) = addEdge(a, b, c.toLong())
    fun addEdge(a: Int, b: Int, c: Long = 0L) {
        vec[a].add(E(b, c))
    }

    fun neighborsOf(v: Int) = vec[v].map(E::v).toTypedArray()

    fun peaks(): Int {
        var ans = 0
        for (i in 1..v) {
            val h = H[i]
            if (neighborsOf(i).all { H[it] < h }) ans++
        }
        return ans
    }

    data class E(val v: Int, val c: Long)
}

Measured memory_bytes: 83764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>


#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"



using namespace std;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


#define INF 2000000000


int main() {
 
    int n;
    int tmp;
	string str;
	map<string,int> mp;

    cin >> n ;
    
  for(int i=0; i<n; i++){
    cin >> str;
    if(mp.count(str)){
      mp[str]++;
    }
    else{
      mp[str] = 1;
    }
  }
    tmp = 0;    
      for(auto p : mp ){
        tmp= max(tmp,p.second);
        }    
    
    for(auto p : mp){
        if(p.second == tmp){
            cout << p.first << endl;
        }
    }
    
	//cout << mp[str] << endl ;
  	
  
}


Measured memory_bytes: 25216
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int h[110][110];
int a;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

vector<edge> G[500];
int level[500];
int iter[500];

void add_edge(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v==t)return f;

	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t,int n){
	int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,m))>0){
			flow+=f;
		}
	}
}

bool C(int v){
	int s=n+m,t=s+1;
	for(int i=0;i<=s+2;i++){
		G[i].clear();
	}
	if(m-a*n>0)add_edge(s,s+2,m-a*n);
	for(int i=0;i<n;i++){
		add_edge(s,i,a);
		if(m-a*n>0)add_edge(s+2,i,1);
		for(int j=0;j<m;j++){
			if(h[i][j]<=v)add_edge(i,n+j,1);
		}
	}
	for(int i=0;i<m;i++){
		add_edge(n+i,t,1);
	}
	int val=max_flow(s,t,m);
	return (val==m);
}

int main(void){
	scanf("%d%d",&n,&m);
	int maxi=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&h[i][j]);
			maxi=max(maxi,h[i][j]);
		}
	}
	a=m/n;
	printf("%d\n",(a*n==m)?0:1);
	int l=-1,r=maxi;
	while(r-l>1){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}

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

struct process{
	string team;
	int time;
};

int main(){
	int n, q, sum = 0;
	queue<process> a;

	cin>>n>>q;
	for(int i=0;i<n;i++){
		struct process x;
		cin>>x.team>>x.time;	
		a.push(x);
	}

	while(!a.empty()){
		if(a.front().time <= q){
			sum += a.front().time;
			cout<<a.front().team<<" "<<sum<<endl;
			a.pop();
		} else {
			sum += q;
			a.front().time -= q;
			a.push(a.front());
			a.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 4404
#include <iostream>
#include <set>
#include <vector>

using namespace std;
multiset<long long> s;
vector<int> v;
int main(){
	int i,n,ans = 0;
	cin >> n;
	for(i=0;i<n;i++){
		int x; cin >> x;
		s.insert(x);
	}
	long long res = 1;
	for(i=0;i<35;i++){
		v.push_back(res);
		res *= 2;
	}
	while(s.size()){
		long long x = *s.rbegin();
		auto it = s.lower_bound(x);
		s.erase(it);
		for(i=(int)v.size()-1;i>=0;i--){
			if(s.count(v[i] - x)){
				auto ite = s.lower_bound(v[i] - x);
				ans++; s.erase(ite);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define Size 200000

// キューで実装すべき機能は以下の通り
// initialization -> void init()
// emptyの判定 -> empty()
// キューへ要素を定数時間で加える ->  push()
// キューの要素を定数時間で取り出す -> pop()

struct Queue{
  
    int table[Size];
    int tail, head; // headはキューの先頭を指す　tailはキューの末尾+1の場所を指す
    
    // initialization
    void init(){
        head = tail = 0;
    }
    
    bool empty(){
        return head == tail;
    }
    
    void push(int x){
        table[tail] = x;
        tail++;
        tail %= Size; // ポインタを循環させる
    }
    
    int pop(){
        if (empty()) return 0;
        
        int result = table[head]; // FIFO
        head++;
        head %= Size; // ポインタを循環させる
        return result;
    }
    
};

int main(){
    
    Queue queue, queue2;
    
    int n, q, num;
    
    string table[Size];
    
    cin >> n >> q;
    
    queue.init();
    queue2.init();
    
    for (int i = 0; i < n; i++){
        cin >> table[i] >> num;
        
        queue.push(num);
        queue2.push(i);
    }
    
    int now = 0, a, b;
    
    while(!queue.empty()){
        
        a = queue.pop();
        b = queue2.pop();
        
        if (a <= q){
            now += a, cout << table[b] << " " << now << endl; 
        }
        else{
            now += q;
            a -= q;
            queue.push(a);
            queue2.push(b);
        }
    }
    
}











Measured memory_bytes: 8368