akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    string s;
    while(cin >> s){
        if(s == "-") break;
        int m;
        cin >> m;
        int ans = 0;
        int n = s.size();
        rep(i,m){
            int h;
            cin >> h;
            ans += h;
        }
        ans %= n;
        rep(i,n){
            cout << s[(i+ans)%n];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3200
S = input()
Q = int(input())
cnt = 0
l = []
r = []
for i in range(Q):
    q = list(input().split())
    if int(q[0]) == 1:
        cnt += 1
    else:
        if (cnt+int(q[1]))%2 == 0:
            r.append(q[2])
        else:
            l.append(q[2])
if cnt%2 == 0:
    l.reverse()
    print(''.join(l)+S+''.join(r))
else:
    r.reverse()
    print(''.join(r)+S[::-1]+''.join(l))

Measured memory_bytes: 5740
#include<bits/stdc++.h>
using namespace std;
int main(){cin.tie(0);ios::sync_with_stdio(false);int n;cin>>n;int t=0,x=0,y=0;bool flag=true;for(int i=0;i<n;i++){int a,b,c;cin>>a>>b>>c;int dl=abs(x-b)+abs(y-c),dt=a-t;if((dl-dt)>0 || (dl-dt)%2){flag=false;}t=a,x=b,y=c;}if(flag)cout<<"Yes"<<endl;else cout<<"No"<<endl;}

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

int main(){
  double a, b, c, d, e, f, x, y;
  while(cin >> a >> b >> c >> d >> e >> f){
    x=(c*e-b*f)/(a*e-d*b)+0.0001;
    y=(c*d-a*f)/(b*d-a*e)+0.0001;
    // x=round(x*1000)/1000;
    // y=round(y*1000)/1000;
    cout << fixed << setprecision(3) << x << " " << setprecision(3) << y << endl;
  }

  return 0;
}

  

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

int main(){

    int n,x;
    int ans=0;
    cin>>n>>x;
    vector<int> d(n+1);
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        d[i+1]=d[i]+t;
    }
    for(int i=0;i<n+1;i++){
        if(d[i]<=x) ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int MAX_N = 100000;
int MAX_W = 100000;

int main(){
  int N,M;
  cin>> N >> M;
  int count =0;
  int L,R;
  L =0;
  R =100000;
  vector<vector<int>> id(M, vector<int>(2));
  std::vector<int> v(N);
  REP(i,M){
      cin >>id.at(i).at(0) >> id.at(i).at(1);
      L = max(id.at(i).at(0),L);
      R = min(id.at(i).at(1),R);
  }
  if(L <= R){
    count = R - L + 1;
  }else{
    count =0;
  }
  cout << count << endl;
}


Measured memory_bytes: 6144
#include <iostream>
#include <cstdio>
#include <cstring>
#define MAX 100000
#define DEBUG
char compStr[4][8];
void init();
bool comp(char **);
int tate(char *,int);

int main(int argc, char *argv[])
{
  char str[MAX];
  
  init();
  scanf("%s",str);
  str[strlen(str)]= '\0';
  char *ptr1 = str;
  char **ptr2 = &ptr1;
  int flag = 0;
  
  if(tate(str,strlen(str)) == 0) std::cout << "NO" << "\n";
  else std::cout << "YES" << "\n";
#ifdef DEBUG
  
#endif

  
  return 0;
}
void init(){
  std::strcpy(compStr[0],"dreamer");
  std::strcpy(compStr[1],"eraser");
  std::strcpy(compStr[2],"erase");
  std::strcpy(compStr[3],"dream");

}

bool comp(char **ptr){
  for (int i = 0; i < 4; i++) {
    if(std::strncmp(*ptr,compStr[i],std::strlen(compStr[i])) == 0) {
      *ptr = *ptr+std::strlen(compStr[i]);
      return true;
    }else{

    }
  }
  return false;
}

int tate(char *str,int n){
  int ret = 0;
  if(n <= 0) return 1;
  
  for (int i = 0; i < 4; i++) {
    if(std::strncmp(str,compStr[i],std::strlen(compStr[i])) == 0) {
      ret += tate(str+strlen(compStr[i]),strlen(str+strlen(compStr[i])));
      
    }
  }
  return ret;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

#define rep(i,x,y) for(int (i)=(x);i<(y);(i)++)

string rev(string str) {
	string s;
	if (str.size() == 1) {
		return str;
	}
	for (int i = str.size() - 1; i >= 0; i--) {
		s += str.substr(i, 1);
	}

	return s;
}

int main()
{
	int n;
	cin >> n;
	rep(i, 0, n) {
		map<string, int> m;
		string str;
		cin >> str;
		m[str] = 1;

		rep(j, 1, str.size()) {
			string str1 = str.substr(0, j);
			string str2 = str.substr(j, str.size() - j);
			bool flag = true;

			m[str2 + str1] = 1;
			m[rev(str1) + str2] = 1;
			m[rev(str2) + str1] = 1;
			m[str1 + rev(str2)] = 1;
			m[str2 + rev(str1)] = 1;
			m[rev(str1) + rev(str2)] = 1;
			m[rev(str2) + rev(str1)] = 1;
		}

		cout << m.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 3268
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    ns = int(math.sqrt(n)) + 1
    minimum = n
    for i in range(1, ns):
        if n % i == 0:
            cost = (n//i) + i - 2
            if cost < minimum:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3188
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = [(key, a[key]) for key in a]
    for i in range(m):
        b, c = map(int, input().split())
        q.append((c,b))
    q.sort(reverse=True)
    acc = 0
    ans = 0
    for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 38896
#include<stdio.h>
int main ()
{
  int H, W, h, w, G, K;
  scanf("%d %d", &H, &W);
  scanf("%d %d", &h, &w);
  G=H*W;
  K=G-(h*W)-(H*w)+(h*w);
  printf("%d\n",K);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int x = stdIn.nextInt();
        int y = stdIn.nextInt();

        if(c - 0.5 * a - 0.5 * b > 0){
            System.out.println(a * x + b * y);
        }else{
            if(x < y){
                if(b * (y - x) + 2 * c * x <= 2 * c * y){
                    System.out.println(b * (y - x) + 2 * c * x);
                }else{
                    System.out.println(2 * c * y);
                }
            }else{
                if(a * (x - y) + 2 * c * y <= 2 * c * x){
                    System.out.println(a * (x - y) + 2 * c * y);
                }else{
                    System.out.println(2 * c * x);
                }
            }
        }
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
// InSane Code	...	

int main(int argc , char** argv){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	LL a , b;
	cin >> a >> b;
	cout << max(a+b , max(a-b,a*b)) << endl;
	return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  set<string> S;
  string item;
  
  for(int i=0; i<N; i++){
    cin >> item;
    S.insert(item);
  }
  
  cout << S.size() << endl;
  
}


Measured memory_bytes: 19220
#include<stdio.h>

int main(){
    int N, X;
    int m[200];
    int min = 2000;
    int sum =0;
    int ans;

    scanf("%d %d", &N, &X);
    for(int i=0; i<N; i++){
        scanf("%d", &m[i]);
        sum += m[i];
        if(m[i]<min){
            min = m[i];
        }
    }
    X = X-sum;
    ans = X/min + N;

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int[][] c = new int[3][3];

		int csum = 0;
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				c[i][j] = sc.nextInt();
				csum += c[i][j];
			}
		}

		int[] threesum = new int[6];
		threesum[0] = c[0][0] + c[1][1] + c[2][2];
		threesum[1] = c[0][0] + c[2][1] + c[1][2];
		threesum[2] = c[1][0] + c[0][1] + c[2][2];
		threesum[3] = c[1][0] + c[2][1] + c[0][2];
		threesum[4] = c[2][0] + c[1][1] + c[0][2];
		threesum[5] = c[2][0] + c[0][1] + c[1][2];
		for(int i=1;i<6;i++) {
			if(threesum[0] != threesum[i]) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");

	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

int main(int argc, void **argv)
{
	long long w, h, x, y;
	double a1, a2, max = 0.0;
	double a;

	scanf("%lld %lld %lld %lld", &w, &h, &x, &y);
	printf("%lf %d\n", (double)h * (double)w / 2.0, (x*2 == w && y*2 == h));

	return 0;
}


Measured memory_bytes: 128
//code by PARTH_4399 for competitive programming
#include<bits/stdc++.h>

using namespace std;

#define l long // -2^31 to +2^31-1 (upper limit ~ 2*(10^9))
#define ul unsigned long // 0 to +2^32-1
#define ll long long // -2^63 to +2^63-1 (upper limit ~ 9*(10^18))
#define ull unsigned long long // 0 to +2^64-1
#define mod(x, m) ((((x)%(m))+(m))%(m))
#define vi vector<int>
#define pi pair<int,int>
#define vl vector<ll int>
#define pl pair<ll int,ll int>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll MOD = 1e9 + 7;
const double pie = 3.141592653589793;

#define setcount(x) __builtin_popcount(x) // counts set bits
#define parity(x) __builtin_parity(x) // checks parity of the number
#define lzcount(x) __builtin_clz(x) // count leading zeros in binary representation of number
#define tzcount(x) __builtin_ctz(x) // count trailing zeros in binary representation of number

template<typename T> T inf() { return (T)__builtin_inf();} // syntax for use inf<datatype>();
template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return (a*b)/gcd(a,b); }
template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

string IntToString(ll a){ ostringstream temp; temp << a; return temp.str();}
ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M,only if M is prime
ll add(ll a,ll b,ll M) { return ( mod(a,M ) + mod(b,M ))%M; }
ll sub(ll a, ll b,ll M) { return (mod(a,M ) + M - mod(b,M ))%M; }
ll mult(ll a,ll b,ll M) { return  ( mod(a,M)*mod(b,M) ) %M ; }
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

/************************** main program **************************/

int main()
{
	FASTIO
	//code
	int count=0;
	char s[3],t[3];
	cin>>s>>t;
	if(s[0]==t[0])
	count++;
	if(s[1]==t[1])
	count++;
	if(s[2]==t[2])
	count++;
	cout<<count;
	return 0;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; string s, t;
    cin >> N >> s >> t;
    bool ok;
    rep(i, N){
        ok = true;
        int lim = N-i;
        rep(j, lim){
            if(s[i+j] != t[j]) ok = false;
        }
        if(ok){
            cout << N + i << endl;
            return 0;
        }
    }
    cout << 2*N << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
A = max(a)
B = A / 2
a.sort()

for i, v in enumerate(a):
  if v >= B:
    idx = i
    break
    
# idx と idx -1 の値の近いほうを採用する。
if abs(B - a[idx]) < abs(B - a[idx - 1]):
  print(A, a[idx])
else:
  print(A, a[idx - 1])

Measured memory_bytes: 14052
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,K;

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

    cout<<(N%K?1:0)<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

def is_pin(pp):
    idx = 0
    for p in pp:
        find_idx = s[idx:].find(p)
        nxt = idx + find_idx
        if find_idx == -1:
            return False
        else:
            idx = nxt+1
    return True
        
count = 0
for pin_n in range(1000):
    pin = str(pin_n).zfill(3)
    if is_pin(pin):
        count += 1
print(count)

Measured memory_bytes: 3060
class Dice:
  __table =[[0,1,2,3,4,5],[0,2,4,1,4,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
            [1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
            [2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
            [3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
            [4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
            [5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
  __another = []
  def __init__(self,dice):
    self.dice = dice
    for t in self.__table:
      a = []
      for k,v in enumerate(t):
        a.append(dice[v])      
      self.__another.append(a)
      
  def output(self):
    print(self.dice[0])
    
  def right_dise(self,a,b):
    for t in self.__another:
      if t[0] == a and t[1] == b:
        return t[2]

  def move(self,str):
    if str == 'N':
      temp = self.dice[0]
      self.dice[0] = self.dice[1]
      self.dice[1] = self.dice[5]
      self.dice[5] = self.dice[4]
      self.dice[4] = temp
    elif str == 'S':
      temp = self.dice[0]
      self.dice[0] = self.dice[4]
      self.dice[4] = self.dice[5]
      self.dice[5] = self.dice[1]
      self.dice[1] = temp

    elif str == 'E':
      temp = self.dice[0]
      self.dice[0] = self.dice[3]
      self.dice[3] = self.dice[5]
      self.dice[5] = self.dice[2]
      self.dice[2] = temp
      
    elif str == 'W':
      temp = self.dice[0]
      self.dice[0] = self.dice[2]
      self.dice[2] = self.dice[5]
      self.dice[5] = self.dice[3]
      self.dice[3] = temp      
  
      
di = list(map(int,input().split()))
di = Dice(di)
num = int(input())

while num > 0:
  v1,v2 = map(int,input().split())
  re = di.right_dise(v1,v2)
  print(re)
  num -= 1
  


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,M;
bool con[705][705];
vector<int>G[705];

int blcnt,whcnt;
int co[705];
void dfs(int x){
	if(co[x]==1)blcnt++;
	else whcnt++;
	for(int i:G[x]){
		if(!co[i]){
			co[i]=co[x]*-1;
			dfs(i);
		}else if(co[i]==co[x]){
			cout<<-1<<endl;exit(0);
		}
	}
}
signed main() {
	cin>>N>>M;
	rep(i,M){
		int a,b;cin>>a>>b;a--;b--;
		con[a][b]=true;
		con[b][a]=true;
	}
	rep(i,N)for(int j=i+1;j<N;j++)if(!con[i][j]){
		G[i].push_back(j);G[j].push_back(i);
	}
	vector<P>v;
	rep(i,N){
		if(!co[i]){
			co[i]=1;
			blcnt=0;whcnt=0;
			dfs(i);
			v.push_back({blcnt,whcnt});
		}
	}
	bitset<705>dp;
	dp.set(0);
	for(P p:v){
		dp=dp<<p.first|dp<<p.second;
	}
	int ans=inf;
	rep(i,N+1){
		if(dp[i]){
			chmin(ans,i*(i-1)/2+(N-i)*(N-i-1)/2);
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 6016
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int p[n], max_price, sum;
  max_price = 0;
  sum = 0;
  for(int i=0; i<n; i++){
    cin >> p[i];
    sum += p[i];
    max_price = max(max_price, p[i]);
  }
  sum -= max_price/2;
  cout << sum <<endl;
  return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String [] strArray = s.split("");
        int sum = 0;

        for (int i = 0; i < strArray.length; i++) {
            sum = sum + Integer.parseInt(strArray[i]);
        }
        
        System.out.println(sum);

    }
}

Measured memory_bytes: 22740
from sys import stdin


def main() -> None:
    n = int(input())
    dic = set()

    for i in range(n):
        s = next_str()
        dic.add(s)

    print(["Three", "Four"][int(len(dic) == 4)])


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
  fasterthanlight;
  int x, y;
  cin >> x >> y;
  if (y - (2 * x) >= 0 && (4*x-y)>=0)
  {
    if (y % 2 == 0)
      cout << "Yes";
    else
      cout << "No";
  }
  else
    cout << "No";
  //cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
  return 0;
}


Measured memory_bytes: 3640
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

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

int main(){    
  long long X;
  cin >> X;
  int A=10000,B=10000;

  for(long long i=0;i<=1000;i++){
    for(long long j=0;j<=1000;j++){
      if(X == pow(i,5)+pow(j,5)){
	A=i;
	B=j;
	break;
      }
    }
  }
  if(A!=10000 && B!=10000){
     cout << A <<" " << B*(-1) <<endl;
     return 0;
  }
 
  for(int i=0;i<=1000;i++){
    for(int j=0;j<=1000;j++){
      if(X == pow(i,5)-pow(j,5)){
	A=i;
	B=j;
	break;
      }
    }
  }
  if(A!=10000 && B!=10000){
    cout << A <<" " << B <<endl;
    return 0;
  }

 
}
 


Measured memory_bytes: 3968
/**
 * @author torith
 * @date 2018-10-13
 */

#include <bits/stdc++.h>

using namespace std;

int main(){

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

    char X;
    char before = 'a';
    int S_cnt = 0;
    int ans = 0;
    while(cin >> X){
        if(X == 'S'){
            S_cnt += 1;
        }else if (X == 'T' && S_cnt > 0){
            ans -= 2;
            S_cnt -= 1;
        }
        ans += 1;
        before = X;
    }
    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
fun main() {
    val (n, m, x) = readIntList()
    var min = Int.MAX_VALUE
    val arr = Array(n) { listOf<Int>() }
    repeat(n) {
        arr[it] = readIntList()
    }
    
    // buy 買うか買わないか
    fun chk(buy: BooleanArray) {
        var price = 0
        // 経験値
        val exp = IntArray(m) { 0 }
        // 目標達成したかしていないか
        val fin = BooleanArray(m) { false }
        repeat(n) {
            if(buy[it]) {
                price += arr[it][0]
                for(i in 1..m) {
                    exp[i - 1] += arr[it][i]
                    if(exp[i - 1] >= x) fin[i - 1] = true
                }
            }
        }
        if(fin.count{ it } == m) min = Math.min(min, price)
    }
    
    val buyList = BooleanArray(n) { false }
    fun create(d: Int) {
        // 本を買うか買わないかを一冊目から試す
        arrayOf(true, false).forEach{
            buyList[d] = it
            if(d + 1 == n) {
                // n冊全てに買うか買わないかを設定できたらチェック
                chk(buyList)
            } else {
                // 再帰で買うか買わないかを設定
                create(d + 1)
            }
        }
    }
    
    create(0)
    println(if(min == Int.MAX_VALUE) -1 else min)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	int n;cin >> n;
	
	if(n < 1200){
		cout << "ABC" << endl;
	}
	else if(n < 2800){
		cout << "ARC" << endl;
	}
	else{
		cout << "AGC" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#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++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int N;
  cin >> N;
  N/=2;
  int o,e;
  vector<int> odd(100005,0);
  vector<int> even(100005,0);
  rep(i, N){
  cin >> o >> e;
    odd[o]++;
    even[e]++; 
  }
  int od1=0,od2=0,ev1=0,ev2=0;
  int a=0,b=0,a1=0,b1=0;
  rep(i, 100005){
    if(a<=odd[i]){
      od2=od1;
      od1=i;
      a1=a;
    a=odd[i];       
    }
    else if(a1<=odd[i]){
      od2=i;
    a1=odd[i];       
    }
    
    
    if(b<=even[i]){
      ev2=ev1;
      ev1=i;
      b1=b;
    b=even[i];       
    }   
    else if(b1<=even[i]){
      ev2=i;
    b1=even[i];       
    }
  }
  
  int ans=0;
  int same=0;
  rep(i, 100005){
  ans+=odd[i]+even[i];
    if(a==odd[i]||b==even[i])
      same++;
  }
  
  if(od1!=ev1||same>2){
  cout << ans- odd[od1]-even[ev1]<< endl;
  }
  else{
  cout << min(ans- odd[od2]-even[ev1],ans- odd[od1]-even[ev2])<< endl;
  }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
#include <functional>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <climits>
typedef long long ll;
#define rll register ll
#define rint register int
#define rdouble register double
#define mem(a) memset(a,0,sizeof(a)
#define maxn int(1e7)
#define eps int(1e-6)
#define inf 0x3f3f3f3f
using namespace std;
int a[maxn+10],b[maxn+10],get[maxn+10],off[maxn+10],p[maxn+10];
int main()
{
    int n;
    scanf("%d", &n);
    int cnt=-1;
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        get[a[i]]++;
        off[b[i]]++;

        p[a[i]]++;
        p[b[i]]--;
        cnt=max(cnt,b[i]);
    }
    for(int i=1;i<=cnt;i++)
    {
        get[i]+=get[i-1];
        off[i]+=off[i-1];
        p[i]+=p[i-1];
    }
    int ans1=-1,ans2=-1;
    for(int i=1;i<=n;i++)
    {
        ans1=max(ans1,get[b[i]-1]-off[a[i]]);
    }
    for(int i=1;i<=cnt;i++)
    {
        
        ans2=max(ans2,p[i]);
    }
    printf("%d %d\n", ans1,ans2);

    return 0;
}



Measured memory_bytes: 5956
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        c: chars
    }
    let is_v = match c[0] {
        'a' | 'e' | 'i' | 'o' | 'u' => true,
        _ => false
    };
    println!("{}", if is_v {"vowel"} else {"consonant"})
}

Measured memory_bytes: 4352
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>

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

    std::vector<int> vec(n);
    for(int i = 0; i < n; ++i){
        std::cin >> vec.at(i);
    }
    vec.resize(2 * n);
    for(int i = 0; i < n; ++i){
        vec.at(i + n) = vec.at(i);
    }

    bool flg = true;
    int sum;
    for(int i = 0; i < n; ++i){
        sum = std::accumulate(vec.begin() + i + 1, vec.begin() + i + n, 0);
        
        if(vec.at(i) >= sum){
            flg = false;
            break;
        }
    }

    if(flg){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
X , N  =  map ( int , input().strip().split(" ") ) ;
s = input().strip() ;

if len(s) == 0 :
	set1 = set() ;
else :
	L   =  list ( map ( int , s.split(" ") ) ) ;
	set1 = set ( L ) ;

v1 = None ;
while v1 is None :
	for x in range ( 0 , 101 ) :
		if X + x in set1 : continue ;
		v1 = x; 
		break ;
v2 = None ;
while v2 is None :
	for x in range ( 0 , 101 ) :
		if X-x  in set1 : continue ;
		v2 = x; 
		break ;
if v1 < v2 :
	print ( X + v1 ) ;
else :
	print ( X - v2 ) ;

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read();
    vector<pair<int, int>> AB(N);
    for (auto& ab:AB) {
        ab.first = read();
        ab.second = read();
    }
    sort(AB.begin(), AB.end(), [](const pair<int, int>& x, const pair<int, int>& y){return x.second < y.second;});
    int_fast64_t sum = 0;
    for (auto& ab:AB) {
        sum += ab.first;
        if (sum > ab.second) {
            printf("No\n");
            return;
        }
    }
    printf("Yes\n");
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    int ans[2100]={0};
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int dis=min(j-i, abs(x-i)+1+abs(y-j));
            ans[dis]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    vector<vector<int> > x =
    {
        { a, b, -a-b+3*c },
        { -2*a-b+4*c, c, 2*a+b-2*c },
        { a+b-c, -b+2*c, -a+2*c },
    };

    for(int i=0; i<3; ++i)
        cout << x[i][0] << ' ' << x[i][1] << ' ' << x[i][2] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
#define INFL 1000000000000000001
#define M 1000000007
int n,h[100005],ans;
int main(void){
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];
	int l=0;
	for(int i=0;i<n-1;i++){
		if(h[i]<h[i+1])l=0;
		else l++;
		ans=max(ans,l);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#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 int MOD = 1e9+7;
const ll LINF = 1e18;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> N;
    map<string,int> arr;
    
    for (int i = 0; i < N; i++) 
    {
        cin >> S;
        arr[S]++;
    }

    cout << arr.size();
    return 0;
}

Measured memory_bytes: 19120
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,i,count=0;
char a[100];
scanf("%d",&n);
scanf("%s",a);

if((n%2)!=0)
{
printf("No");
exit (0);
}
else
{
	for(i=0;i<(n/2);i++)
	{
	if(a[i]!=a[(n/2)+i])
	count++;

	}
}
if(count>0)
printf("No");
else
printf("Yes");

}

Measured memory_bytes: 128
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class Program
{
    static void Main(string[] args)
    {
      //入力を受け取る
      var N = int.Parse(Console.ReadLine());
      var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
      Array.Sort(A);
      var min = A.Min();
      var min2 = min;
      var point = 0L;
      var point2 = 0L;
      while(A.Sum() != min2){
        for(long i = 0 ; i < N ; i++){
          if(i != point){
            //Console.WriteLine(point+" "+i);
            if(A[i]%min != 0 && A[i]%min < min2){
              min2 = A[i]%min;
              point2 = i;
            }
            A[i] = A[i]%min;
          }
        }
        min = min2;
        point = point2;
       // Console.WriteLine(String.Join(" ",A));
      }
      Console.WriteLine(min2);
    }

}




Measured memory_bytes: 23136
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "2018\n218\n" => "Yes",
    "2763\n0\n" => "No",
    "37\n514\n" => "Yes",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: u32,
        a: u32,
    }

    if n % 500 <= a {
        String::from("Yes")
    } else {
        String::from("No")
    }
}

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

using namespace std;
#define all(v) v.begin(), v.end()
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e5 + 5;
int par[N];
long long S[N];
bool mark[N], isval[N];
vector <pii> g[N];
vector < pair <int , pii> > edge;

void dfs(int v, int w) {
    mark[v] = 1;
    for (pii e : g[v]) {
        if (e.S > w) return ;
        if (!mark[e.F]) dfs(e.F, w);
    }
}

int getpar(int v) {return par[v] = (par[v] == v ? v : getpar(par[v]));}
bool Union(int u, int v, int w) {
    u = getpar(u), v = getpar(v);
    if (u == v) return S[u] >= w;
    par[v] = u, S[u] += S[v];
    return S[u] >= w;
}

int main()
{
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> S[i], par[i] = i;
    for (int i = 0; i < m; i++) {
        int u, v, w; cin >> u >> v >> w;
        edge.push_back({w, {u, v}});
    }
    sort(all(edge));
    for (int i = 0; i < m; i++) {
        int w = edge[i].F, u = edge[i].S.F, v = edge[i].S.S;
        g[u].push_back({v, w}), g[v].push_back({u, w});
        isval[i] = Union(u, v, w);
    }
    reverse(all(edge));
    int ans = 0;
    for (int i = 0; i < m; i++) {
        int w = edge[i].F, u = edge[i].S.F, v = edge[i].S.S;
        if (mark[u]) continue ;
        if (isval[m-i-1]) dfs(u, w);
        else ans++;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 11380
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;

typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

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

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	cout << n + pow(n, 2) + pow(n, 3);
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
#define inf 2e9
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define LL long long
using namespace std;
int n,m,a,s[100001];
long long ans;
map <int,LL> f;
int main(){
	cin>>n>>m;
	s[0]=0;
	f[0]++;
	for (int i=1;i<=n;i++){
		cin>>a;
		s[i]=(s[i-1]+a)%m;
		f[s[i]]++;
	}
	map<int,LL> :: iterator i;
	ans=0;
	for (i=f.begin();i!=f.end();i++){
		ans+=(i->second) * (i->second-1) /2 ;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    int mx = max({a, b, c});
    int d = 3*mx - a - b - c;
    if (d % 2 == 0) cout << d/2 << endl;
    else cout << (d+3)/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
ll i,j;
int main()
{IOS;
int t;
t=1;
while(t--)
{ll n,su=0;
cin>>n;
vl v(n);
for(i=0;i<n;i++)
{cin>>v[i];
}
sort(v.begin(),v.end(),greater<int>());

queue<int> q;
	q.push(v[0]);
	for (i = 1; i < n; i++)
		q.push( v[i]), q.push( v[i]);
	ll c = 0;
	for (i = 0; i < n - 1; i++)
		c += q.front(), q.pop();
	cout << c;
}
return 0;}



Measured memory_bytes: 6296
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E09 + 1;
const int MAX_N = 1E+05;

int N;
ll H;

ll A[MAX_N + 1], B[MAX_N + 1];

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

    cin >> N >> H;

    ll amax = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i];
        amax = max(amax, A[i]);
    }

    ll ans = 0;
    ll ats = 0;
    sort(B + 1, B + N + 1, greater<ll>());
    for (int i = 1; i <= N; i++) {
        if (B[i] <= amax || ats >= H)
            break;
        ans++;
        ats += B[i];
    }
    if (H - ats > 0) {
        ans += ceil(double(H - ats) / amax);
        //ans += (H - ats) / amax + ((H - ats) % amax == 0 ? 0 : 1);
    }
    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 5228
#include<bits/stdc++.h>
using namespace std;
int main(){
int X,A,B;
  cin>>X>>A>>B;
  if(B<=A)
    cout<<"delicious"<<endl;
  else if(A<B && B<=A+X)
    cout<<"safe"<<endl;
  else
    cout<<"dangerous"<<endl;
   return 0;
}

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

int main()
{
  int n,m;
  cin>>n>>m;
  
  vector<long> h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  
  vector<vector<int>> connect(n,vector<int>());
  vector<int> number(n,0);
  
  for(int i=0;i<m;i++)
  {
    int a,b;
    cin>>a>>b;
    connect[a-1].push_back(b);
    number[a-1]++;
    connect[b-1].push_back(a);
    number[b-1]++;
  }
  int result=0;
  

  
  for(int i=0;i<n;i++)
  {
    if(number[i]==0)
    {
      result++;
    }
    else
    {
      for(int j=0;j<number[i];j++)
      {
        if(h[i]<=h[connect[i][j]-1])
          break;
        else
          if(j==number[i]-1)
          {
            //cout<<i<<endl;
            result++;
          }
      }
    }
  }
  //for(int i=0;i<number[5];i++)
    //cout<<h[5]<<" "<<h[connect[5][i]-1]<<endl;
    cout<<result<<endl;
}

Measured memory_bytes: 9596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();

		int[][] c = new int[10][];

		for (int i = 0; i < 10; i++) {
			c[i] = new int[10];
			for (int j = 0; j < 10; j++) {
				c[i][j] = sc.nextInt();
			}
		}

		int[][] a = new int[h][];

		for (int i = 0; i < h; i++) {
			a[i] = new int[w];
			for (int j = 0; j < w; j++) {
				a[i][j] = sc.nextInt();
			}
		}

		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (c[i][j] > c[i][k] + c[k][j]) {
						c[i][j] = c[i][k] + c[k][j];
					}
				}
			}
		}
		int sum = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] >= 0) {
					sum += c[a[i][j]][1];
				}
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 48020
#include<iostream>
#include<map>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef pair<int,int>pii;
long long dp[2010][2010]={0},in[2020],n,o;
queue<pii>q;
int main(){
	cin>>n;
	rep(i,n){cin>>in[i];dp[i][1]=in[i],q.push(pii(i,1));}
	while(!q.empty()){
		pii r=q.front();q.pop();
		int a=r.first,b=r.second,s=(a+n-1)%n,t=(s+1+b)%n,w;
		rep(i,2){
			if(b%2&&in[s]<in[t])s=a;
			w=b%2?0:in[(i?t:s)];
			if(dp[s][++b]<dp[a][b-1]+w){dp[s][b]=dp[a][b-1]+w;if(b!=n)q.push(pii(s,b));}
			if(--b%2==0)s=a;
		}
	}
	rep(i,n)o=max(o,dp[i][n]);
	cout<<o<<endl;
}

Measured memory_bytes: 32664
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ld)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    ld a[100005];
    rep(i,n)cin >> a[i];
    rep(i,n)if(a[i] == 0){
        cout << 0 << endl;
        return 0;
    }
    ld ans = 1;
    rep(i,n){
        ans *= a[i];
        if(ans > LINF){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << (ll)ans << endl;
}


Measured memory_bytes: 5352
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    int ab=b-a;
    int ac=c-a;
    int ad=d-a;
    int ae=e-a;
    int cd=d-c;
    int ce=e-c;
    int bc=c-b;
    int bd=d-b;
    int be=e-b;
    int de=e-d;
    if(ab<=k&&ac<=k&&ad<=k&&ae<=k&&cd<=k&&ce<=k&&bc<=k&&bd<=k&&be<=k&&de<=k){
        cout<<"Yay!";
    }else{
        cout<<":(";
    }
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define PI 3.14159265358979323846264338327950L
#define e18 1000000000000000000

using namespace std;

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

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

    int N, K;
    cin >> N >> K;

    vector<int> li;

    REP(i, N)
    {
        int tmp;
        cin >> tmp;
        li.pb(tmp);
    }

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

    int ans = 0;

    REP(i, K)
    {
        ans += li[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
require 'prime'
h = Hash.new(1)
d = 10**9+7
n = gets.to_i
(1..n).each do |i|
    i.prime_division.each do |x,y|
        h[x] += y
    end
end
s = 1
h.each_value do |v|
    s = (s*v)%d
end
p s

Measured memory_bytes: 2300
//
// Created by 肖龙 on 2020/3/18.
//

#include<iostream>
#include <cmath>
#include <iomanip>

using namespace std;

typedef struct point{
    double x,y;
    void input(){
        cin>>x>>y;
    }
}Point,Vector;

typedef struct line{
    Point x;
    Vector k;
}Line;

typedef struct sugment{
    Point x,y;
    void input(){
        x.input();
        y.input();
    }
}Sug;

//点积
double dot(Vector x,Vector y){
    return x.x*y.x+x.y*y.y;
}

//叉积
double cross(Vector x,Vector y){
    return x.x*y.y-x.y*y.x;
}

double getlen(Vector x){
    return sqrt(dot(x,x));
}

Vector getV(Point x,Point y){
    Vector v;
    v.x=y.x-x.x;
    v.y=y.y-x.y;
    return v;
}
//点在直线的投影
Point Projection(Line x,Point y){
    Point answ;
    answ = x.x;

    double len = dot(x.k,getV(x.x,y));
    len/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    Vector temp  = x.k;
    temp.x /=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    temp.y/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    answ.x+=temp.x*len;
    answ.y+=temp.y*len;
    return answ;
}
//点与直线的对称点
Point Reflection(Line x,Point y){
    Point half = Projection(x,y);
    Point answ;
    answ.x=y.x+2*(half.x-y.x);
    answ.y=y.y+2*(half.y-y.y);
    return answ;
}

Point getCP(Sug x,Sug y){
    Point a,b,c,d,z;
    a=x.x;
    b=x.y;
    c=y.x;
    d=y.y;
    z.x=((b.x - a.x) * (c.x - d.x) * (c.y - a.y) -
         c.x * (b.x - a.x) * (c.y - d.y) + a.x * (b.y - a.y) * (c.x - d.x)) /
        ((b.y - a.y) * (c.x - d.x) - (b.x - a.x) * (c.y - d.y));
    z.y=((b.y - a.y) * (c.y - d.y) * (c.x - a.x) -
            c.y * (b.y - a.y) * (c.x - d.x) + a.y * (b.x - a.x) * (c.y - d.y))
        / ((b.x - a.x) * (c.y - d.y) - (b.y - a.y) * (c.x - d.x));
    return z;
}

int main(){
    int t;
    cin>>t;
    Sug x,y;
    Point z;
    while(t--){
        x.input();
        y.input();
        z=getCP(x,y);
        cout<<setprecision(10)<<setiosflags(ios::fixed)<<z.x<<" "<<z.y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3292
import java.util.*;
public class Main {
	static void print(int[][] a){
		for(int s=0;s<100;s++){
			for(int i=0;i<100;i++)if(a[s][i]!=-1)System.out.print(a[s][i]+" ");
			System.out.println();
		}
	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		//右か下に行ける最大値
		int[][] input = new int[100][100];
		int[][] dp = new int[5][5];
		for(int s=0;s<100;s++)for(int i=0;i<100;i++)input[s][i]=-1;
		String[] data = new String[100];
		int cnt=0;
		while(in.hasNext()){
			data[cnt]=in.nextLine();
			cnt++;
		}
		for(int s=0;s<cnt;s++){
			String[] a= data[s].split(",");
			for(int i=0;i<a.length;i++)input[s][i]=Integer.parseInt(a[i]);
		}
		
		for(int s=1;s<(cnt+1)/2;s++){
			for(int i=0;i<s;i++){
				if(input[s][i]==-1)break;
				int x=i,y=s-1;
				int max=0;
				if(y>=0||x>=0)max = input[y][x];
				if((x-1)>=0)max=Math.max(max,input[y][x-1]);
				input[s][i]+=max;
			}
		}
		for(int s=(cnt+1)/2;s<cnt;s++){
			for(int i=0;i<s;i++){
				if(input[s][i]==-1)break;
				int x=i,y=s-1;
				int max=0;
				if(y>=0||x>=0)max = input[y][x];
				if((x+1)>=0)max=Math.max(max,input[y][x+1]);
				input[s][i]+=max;
			}
		}
		System.out.println(input[cnt-1][0]);
	}
}

Measured memory_bytes: 21704