akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int gcd(int a, int b);
int gcd(const std::vector<int>& arr);

int main() {

        int p, q, r;
        std::cin >> p >> q >> r;
        if (p < q) {
                if (q < r) {
                        std::cout << p + q << std::endl;
                }
                else {
                        std::cout << p + r << std::endl;
                }
        }
        else {
                if (p > r) {
                        std::cout << q + r << std::endl;
                }
                else {
                        std::cout << p + q << std::endl;
                }
        }
        return 0;
}

int gcd(int a, int b) {
        if (a > b) {
                std::swap(a, b);
        }

        for (int r = b % a; r != 0; b = a, a = r, r = b % a)
                ;

        return a;
}

int gcd(const std::vector<int>& arr) {
        const int size = arr.size();
        if (size == 0) {
                return 0;
        }
        else if (size == 1) {
                return arr[0];
        }

        int ret = gcd(arr[0], arr[1]);

        for (std::size_t i = 2; i < size && ret != 1; ++i) {
                ret = gcd(arr[i], ret);
        }

        return ret;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int main(){
  
  unsigned long int sum=0;
  int *A;
  int N=0;
  int i;
  scanf("%d", &N);
  
  A = (int *)malloc(N * sizeof(int));
  
  for(i=1;i<=N;i++){
    scanf("%d", &A[i]);
  }
  
  for(i=1;i<N;i++){
    if(A[i] > A[i+1]){
      sum = sum + (A[i] - A[i+1]);
      A[i+1] = A[i+1] +(A[i] - A[i+1]);
    }
  }
  
  printf("%lu",sum);
  
  free(A);
  
 return 0; 
}

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

int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for(int i=0; i<N; i++) {
    cin >> blue.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> red(M);
  for(int i=0; i<M; i++) {
    cin >> red.at(i);
  }
  
  int pt=0;
  int ans=0;
  for(int i=0; i<N; i++){
    pt=0;
    for(int j=0; j<N; j++){
      if(blue.at(i)==blue.at(j)){
        pt++;
      }
      //cout << pt << "!" << endl;
    }
    for(int k=0; k<M; k++){
      if(blue.at(i)==red.at(k)){
        pt--;
      }
    }
    if(ans<pt){
      ans=pt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

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();
		
		long ans = Long.MAX_VALUE;
		
		for(int f=0; f<2; f++) {
			long temp = 0;
			long last = 0;
			for(int i=0; i<N; i++) {
				if((i+f)%2==0) {
					long diff = Math.max(0, 1 - (last + a[i]));
					temp += diff;
					last += a[i]+diff;
				} else {
					long diff = Math.min(0, -1 - (last + a[i]));
					temp += -diff;
					last += a[i]+diff;
				}
			}
			ans = Math.min(ans, temp);
		}
		
		System.out.println(ans);
		
		sc.close();
	}
}


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


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), c(n+1);
    vector<int> ans;
    rep(i,m) cin >> a[i] >> b[i];

    queue<int> q;
    vector<vector<int>> node(n+1);
    rep(i,m){
        node[a[i]].push_back(b[i]);
        node[b[i]].push_back(a[i]);
    }

    rep(i,c.size()) c[i] = -1;
    c[1] = 0;
    q.push(1);
    while (!q.empty()){
        int cur = q.front(); q.pop();
        for(auto x:node[cur]){
            if(c[x] < 0){
                c[x] = cur;
                q.push(x);
            }
        }
    }

    
    for(int i = 2; i <= n; i++){
        for(auto x:node[i]){
            if(x == c[i]){
                ans.push_back(x);
                break;
            }
        }
    }

    if(ans.size() < n-1){
        put("No");
    }else{
        put("Yes");
        for(auto x:ans) put(x);
    }


    /*
    cout << endl;
    for(int i = 2; i <= n; i++){
        cout << i << ":";
        for(auto x:node[i]) cout << x << " ";
        cout << endl;
    }*/
    /*
    for(int i = 2; i <= n; i++){
        vector<int> c(n+1);
        rep(j,c.size()) c[j] = -1;
        queue<int> q;
        q.push(i);
        c[i] = 0;
        while (!q.empty()){
            int car = q.front(); q.pop();
            if(car == 1){
                ans.push_back(c[car]);
                //put(c[car]);
                //for(auto x:c) cout << x << " ";
                //cout << endl;
                break;
            }
            for(auto x:node[car]){
                if(c[x] < 0){
                    c[x] = c[car] + 1;
                    q.push(x);
                }
            }
            
        }
        
    }

    if(ans.size() < 1){
        put("No");
    }else{
        put("Yes");
        for(auto x:ans) put(x);
    }*/
}

Measured memory_bytes: 12288
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <tuple>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int n;

int dist(const vector<int>& a, const vector<int>& b) {
  int ret = 0;
  for (int i = 0; i < a.size(); ++i) ret += abs(a[i] - b[i]);
  return ret;
}

int calc(vector<int> a, vector<int> b) {
  if (a.size() < b.size()) swap(a, b);
  int ans = 1 << 30;
  int x = a.size() - b.size();
  vector<int> tmpb = b, tmpa = a;
  for (int rep = 0; rep < x; ++rep) b.push_back(n);
  ans = dist(a, b);
  for (int rep = 2; rep <= x; rep += 2) {
    b.pop_back(); b.pop_back();
    b.insert(b.begin(), 0); b.insert(b.begin(), 0);
    ans = min(ans, dist(a, b));
  }
  b = tmpb; a = tmpa;
  for (int rep = 0; rep < x; ++rep) b.push_back(n);
  ans = min(ans, dist(a, b));
  for (int rep = 2; rep <= n; ++rep) {
    b.push_back(n); b.push_back(n);
    a.insert(a.begin(), 0); a.insert(a.begin(), 0);
    ans = min(ans, dist(a, b));
  }
  b = tmpb; a = tmpa;
  if (x & 1) {
    ++x;
    a.push_back(n);
  }
  for (int rep = 0; rep < x; ++rep) b.insert(b.begin(), 0);
  ans = min(ans, dist(a, b));
  for (int rep = 2; rep <= n; ++rep) {
    b.insert(b.begin(), 0); b.insert(b.begin(), 0);
    a.push_back(n); a.push_back(n);
    ans = min(ans, dist(a, b));
  }
  return ans;
}

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

  string s, t;
  cin >> n >> s >> t;
  vector<int> a, b;
  for (int i = 1; i < n; ++i) if (s[i] != s[i - 1]) a.push_back(i);
  for (int i = 1; i < n; ++i) if (t[i] != t[i - 1]) b.push_back(i);
  int ans = 1 << 30;
  if (s[0] != t[0]) {
    a.insert(a.begin(), 0); ans = min(ans, calc(a, b)); a.erase(a.begin());
    b.insert(b.begin(), 0); ans = min(ans, calc(a, b)); b.erase(b.begin());
  } else ans = calc(a, b);

  cout << ans;

  return 0;
}


Measured memory_bytes: 784
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	r := reverse(s)

	var wrong int
	for i := 0; i < len(s); i++ {
		if s[i] != r[i] {
			wrong++
		}

	}

	fmt.Println(wrong / 2)
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

Measured memory_bytes: 512
N,M = map(int,input().split())
C = {i:[1,0] for i in range(1,N+1)}
C[1] = [1,1]
for _ in range(M):
    x,y = map(int,input().split())
    C[y][0] += 1
    if C[x][1]==1:
        C[y][1] = 1
    C[x][0] -= 1
    if C[x][0]==0:
        C[x][1]=0
cnt = 0
for i in range(1,N+1):
    if C[i][1]==1:
        cnt += 1
print(cnt)

Measured memory_bytes: 95152
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N = input()

    # 出力
    if '7' in N:
        print('Yes')
    else:
        print('No')
        


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

int main() {
	int n;
	cin >> n;
	vector< vector<int> > a(n, vector<int> (3, 0));
	
	for (int i=0; i<n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	vector< vector<int> > dp;
	dp = a;
	for (int i=1; i<n; i++) {
		dp[i][0] += max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] += max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] += max(dp[i-1][0], dp[i-1][1]); 
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
}

Measured memory_bytes: 11136
n, m = map(int, input().split())
ships = [[int(x) for x in input().split()] for x in range(m)]

judge = False
relay = []
goal = []

for ship in ships:
    if n in ship:
        goal.append(ship[0])
    elif 1 in ship:
        relay.append(ship[1])

res = False
if len(goal) == 0 or len(relay) == 0:
    print("IMPOSSIBLE")

else:
    print("IMPOSSIBLE" if not set(relay) & set(goal) else "POSSIBLE")

Measured memory_bytes: 48600
#include<stdio.h>
int main()
{
  int h,w,x,y;
  while(1){scanf("%d%d",&h,&w);
    if(h==0&&w==0)break;
      for(x=0;x<h;x++){
      for(y=0;y<w;y++){
	printf("#");
      }
      printf("\n");}
      printf("\n");
    }  
      return 0;
  }

Measured memory_bytes: 572
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s.compare(t) <  0)  
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;

int f(int n) { return (n % 10 == 0 ? n : n / 10 * 10 + 10); }
int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  int ans = numeric_limits<int>::max();
  ans = min(ans, f(A) + f(B) + f(C) + f(D) + E);
  ans = min(ans, f(A) + f(B) + f(C) + f(E) + D);
  ans = min(ans, f(A) + f(B) + f(D) + f(E) + C);
  ans = min(ans, f(A) + f(C) + f(D) + f(E) + B);
  ans = min(ans, f(B) + f(C) + f(D) + f(E) + A);
  cout << ans << endl;
}

Measured memory_bytes: 764
from collections import Counter
_=input()
s=list(Counter(list(input())).values())
mod=10**9+7
dp=[0]*len(s)
dp[0]=s[0]
for i in range(1,len(s)):
  dp[i]=dp[i-1]*(s[i]+1)+s[i]
print(dp[-1]%mod)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

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

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
vector<int> used;
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> v(n, 1);

  ll res = 0;
  for (int i = 2; i <= n; ++i) {
    int count = 1;
    while(count * i - 1 < n){
      v[count*i-1]++;
      count++;
    }
  }

  for (int i = 0; i < n; ++i) {
    res += v[i] * (i+1);
  }

  cout << res << endl;

}


Measured memory_bytes: 81324
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <unordered_map>
#include <iomanip>


using namespace std;
#define ASCII 97


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

	int height = 0,counter = 0,max = 0,pre_height = 0;
	for (int i = 0; i < num; i++) {
		cin >> height;
		if (height <= pre_height) {
			counter++;
		}
		else {
			if (max < counter) {
				max = counter;
			}
			counter = 0;
		}
		pre_height = height;
	}

	if (max < counter) {
		max = counter;
	}
	cout << max << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long  ll;
//typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set
// this for long double
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 1010;
const int INF = 1e8;
const ll MOD1=1073741824;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
string bin_rep(int n)
{
          string s="";
      for(int i=31;i>=0;i--)
   {
           if(n&(1<<i)) s+='1';
           else s+='0';
   }
   return s;
}
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int s,w;
 cin>>s>>w;
 if(w>=s) cout<<"unsafe";
 else cout<<"safe";
 
 
 
 
 
    
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

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

int main(){
	int a[15];
	for(int i=0;i<10;i++) cin >> a[i];
	sort(a,a+10);
	reverse(a,a+10);
	for(int i=0;i<3;i++){
		cout << a[i] <<"\n";
	}

	return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int q;
	string s;
	cin >> s >> q;
	deque<char> dq;
	rep (i, s.size()) dq.push_back(s[i]);
	int odd = 0;
	rep (i, q) {
	  int t;
	  cin >> t;
	  if (t == 1) {
		odd++;
	  } else {
		int f;
		char c;
		cin >> f >> c;
		if (f == 1) {
		  if (odd % 2) dq.push_back(c);
		  else dq.push_front(c);
		} else { 
		  if (odd % 2) dq.push_front(c);
		  else dq.push_back(c);
		}
	  }
	}
	if (odd % 2) {
	  while (!dq.empty()) {
		cout << (char)(dq.back());
		dq.pop_back();
	  }
	} else {
	  while (!dq.empty()) {
		cout << (char)(dq.front());
		dq.pop_front();
	  }
	}
	cout << endl;
    
    return 0;
}


Measured memory_bytes: 4008
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(1,k+1):
    for j in a:
        if i-j<0:continue
        if dp[i-j]==False:dp[i]=True
if dp[k]:print("First")
else:print("Second")

Measured memory_bytes: 9516
N, A, B = map(int, input().split())
cnt = 0
if (B - A) % 2:
  if A - 1 <= N - B:
    cnt = A
    B -= A
    A = 1
  else:
    cnt = N - B + 1
    A += N - B + 1
    B = N
print(cnt + (B - A) // 2)

Measured memory_bytes: 3060
# def dfs(now,val,cost):
#     if now == n:
#         return val - cost
#     else:
#         return max(dfs(now+1,val+v[now],cost+c[now]),dfs(now+1,val,cost))

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

# print(dfs(0,0,0))
ans = 0
for i in range(n):
    tmp = v[i] - c[i]
    if tmp > 0:
        ans += tmp
print(ans)


Measured memory_bytes: 2940
using System;

namespace ABC136_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var ans = new long[S.Length];

            var tempR = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'L' && tempR > 0)
                {
                    ans[i] = tempR / 2;
                    ans[i - 1] = tempR / 2;
                    if (tempR % 2 == 1) ans[i - 1]++;
                    tempR = 0;

                    var tempL = 0;
                    for (int j = 0; i + j < S.Length; j++)
                    {
                        if (S[i + j] == 'R') break;
                        tempL++;
                    }

                    ans[i] += tempL / 2;
                    ans[i - 1] += tempL / 2;
                    if (tempL % 2 == 1) ans[i]++;
                }
                else if (S[i] == 'R')
                    tempR++;
            }

            Console.WriteLine(string.Join(" ", ans));
        }
    }
}


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

int main() {
  ll n,k;
  cin>>n>>k;
  ll ans=k;
  for(int i=1;i<n;i++) ans*=(k-1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	ans := "YES"
	list := map[int]bool{}
	for i := 0; i < 10; i++ {
		list[i] = false
	}
	check := []int{1, 9, 7, 4}
	for i := 0; i < 4; i++ {
		list[nextInt()] = true
	}
	for _, c := range check {
		if !list[c] {
			ans = "NO"
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

vi fcnt(100005);

void solve(int testCaseNumber = 1)
{
    int n;
    cin >> n;
    int sum = 0;
    rep(i, 1, n)
    {
        int x;
        cin >> x;
        fcnt[x]++;
        sum += x;
    }
    int q;
    cin >> q;
    while (q--)
    {
        int b, c;
        cin >> b >> c;
        sum -= fcnt[b] * b;
        sum += fcnt[b] * c;
        fcnt[c] += fcnt[b];
        fcnt[b] = 0;
        cnl(sum);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3868
#include <stdio.h>

int main(void)
{
    int z, zzz, x, y, max, t;

    while(scanf("%d", &z), z)
    {
        max = 0, zzz = z * z * z;

        for(x = 1; x < z; x++)
            for(y = 1; y <= x; y++)
            {
                t = x * x * x + y * y * y;
                if(t > zzz) break;
                else if(t > max) max = t;
            }
        printf("%d\n", zzz - max);
    }

    return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin >> x;
	for(ll a = -1000; a <= 1000; a++){
		ll a5 = a*a*a*a*a;
		for(ll b = -1000; b <= 1000; b++){
			ll b5 = b*b*b*b*b;
			if(a5  - b5 == x){
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;

void dfs(vector<int> adj[],vector<bool>&visi,int src){
    visi[src]=true;
    for(int i=0;i<adj[src].size();i++){
        if(visi[adj[src][i]]==false)
          dfs(adj,visi,adj[src][i]);
    }
}

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> adj[n+1];
  while(m--){
      int x,y;
      cin>>x>>y;
      adj[x].push_back(y);
      adj[y].push_back(x);
  }
  vector<bool> visi(n+1,false);
  int comp=0;
  for(int i=1;i<=n;i++){
      if(visi[i]==false){
          dfs(adj,visi,i);
          comp++;
      }
  }
  cout<<comp-1<<endl;
}

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    
    int n, m;
    std::cin >> n >> m;

    int sum = 0;

    for (int i = 0; i < m; ++i) {
        int a;
        std::cin >> a;
        sum += a;
    }

    if (n - sum < 0) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << n - sum << std::endl;
    }





	return 0;
}


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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int a, b, k;
  scanf("%d%d%d", &k, &a, &b);
  bool w = 0;
  rep(i, a, b + 1)
    w |= (i % k == 0);
  if (w) puts("OK");
  else puts("NG");
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}



Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
	 int water,sugar;
	 Scanner sc=new Scanner(System.in);
	 int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt(),D=sc.nextInt(),E=sc.nextInt(),F=sc.nextInt();
	 double noudo=0.0;
	 int maxm=0;
	 int maxsugar=0;
	 double maxnoudo=0.0;
	 for(int a=0;a*A*100<=F;a++) {
		 for(int b=0;b*100<=F-a*A*100;b++) {
			 water=100*A*a+100*B*b;
			 if(water==0) {
				 continue;
			 }
			 for(int c=0;c*C<=F-water;c++) {
				 for(int d=0;d*D<=F-water-c*C;d++) {
				     sugar=c*C+d*D;
					 noudo=(double)sugar/((double)sugar+(double)water);
						
				  if(sugar<=E*(A*a+B*b)&&noudo>=maxnoudo) {
					 maxnoudo=noudo;
					 maxm=sugar+water;
					 maxsugar=sugar;
					 
				  }
					 
				 }
				 
				 
			 }
			 
		 }
	 }
	 System.out.println(maxm+" "+maxsugar);
	 
 }
}


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

vector <int> l, r;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	l.resize(m);
	r.resize(m);
	for (int i = 0; i < m; i++){
		cin >> l[i] >> r[i];
	}
	int A = *(min_element(r.begin(), r.end()));
	int B = *(max_element(l.begin(), l.end()));
	if (A < B)
		cout << 0;
	else
		cout << A - B + 1;
}

Measured memory_bytes: 1024
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

i = j = 0

visited = [[None] * W for _ in range(H)]

def dp(i, j):
    global H, W
    visited[i][j] = True
    if i == H - 1 and j == W - 1: return True
    #
    if i + 1 >= H:
        d = False
    else:
        d = (A[i + 1][j] == '#')
    #
    if j + 1 >= W:
        r = False
    else:
        r = (A[i][j + 1] == '#')
    #
    if d and not r:
        return dp(i + 1, j)
    elif not d and r:
        return dp(i, j + 1)
    else:
        return False

if dp(0, 0):
    ans = 'Possible'
    for i in range(H):
        for j in range(W):
            if not visited[i][j] and A[i][j] == '#':
                ans = 'Impossible'
    #
    print(ans)
else:
    print('Impossible')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> pii;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
const int MAXN = 2e4 + 10;
const int INF = 1e9;

//#define DEBUG

int main(){
  FastIO;
  #ifdef DEBUG
    freopen("input.txt", "r", stdin);
  #endif
  ll a, b;
  cin >> a >> b;
  ll sum = 0;
  if (a == 1)sum += 3;
  if (a == 2)sum += 2;
  if (a == 3)sum += 1;
  if (b == 1)sum += 3;
  if (b == 2)sum += 2;
  if (b == 3)sum += 1;
  if (a == 1 && b == 1)sum += 4;
  cout << sum * 100000 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int four=0, odd=0;
  ll tmp;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    if(tmp%4==0) four++;
    else if(tmp%2==1) odd++;
  }
  if(four+odd==N) {
    if(odd<=four+1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else {
    if(odd<=four) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}



Measured memory_bytes: 3588
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
using namespace std;

signed main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		cout << min(a, b) << " " << max(a, b) << endl;
	}
}

Measured memory_bytes: 3012
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        MyScanner scan = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = scan.nextInt();
        int k = scan.nextInt();

        if (k == 1) {
            out.println(0);
        } else {
            out.println(n - k);
        }

        out.close();
    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------

}

Measured memory_bytes: 21204
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int A = a[0];
        int P = a[1];
        int X = A * 3 + P;
        int Y = X / 2;
        Console.WriteLine(Y);
    }
}

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

using namespace std;

int main() {
    int N, M, C;
    int sum = 0, ans = 0;
    vector<int> B(20,0);
    vector<vector<int> > A(20, vector<int>(20,0));

    cin >> N >> M >> C;

    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i < N; i++) {
        sum = 0;
        for (int j = 0; j < M; j++) {
            sum += A[i][j] * B[j];
        }
        sum += C;
        if (sum > 0) ans++;
    }

    cout << ans;

    return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,k[1000],cou[1000];
int  main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>k[i];
        for(int u=0;u<k[i];u++){
            int b;
            cin>>b;
            cou[b]++;
        }
    }
    for(int i=0;i<m+1;i++){
        if(cou[i]==n)ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
 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 trapezoid=(a+b)*h/2;
   
   System.out.println(trapezoid);
 }
}

Measured memory_bytes: 21844
def calc():
  N = map(int, input().split())
  A = list(map(int, input().split()))
  for a in A:
    if a == 0:
      return 0
  ans = 1
  for a in A:
    ans *= a
    if (ans > 10 ** 18):
      return -1
  return ans

print(calc())

Measured memory_bytes: 21772
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,ans;
  cin >> s;
  ans = "";
  for(int i = 0;i < s.size();i++) {
    if(s.at(i) == '0') {
      ans.push_back('0');
    }else if(s.at(i) == '1') {
      ans.push_back('1');
    }else {
      if(ans.size() != 0) {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(rand()&1)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 724
N = gets.to_i
As = gets.split.map(&:to_i)

@a = Array.new(2*N + 1)

def cnt(x)
  pt, r = N, 0
  @a.fill(0)
  As.inject(0) do |s, a|
    @a[pt] += 1
    if a < x
      r += @a[pt]
      pt += 1
    else
      pt -= 1
      r -= @a[pt]
    end
    s + r
  end
end

puts As.sort.reverse.bsearch{|x| 4*cnt(x) <= N*(N + 1)}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> num(N + 1, 0);
    ll cnt = 0;
    ll streak = 0;
    for(int i = 1 ; i <= N; i++){
        cin >> num[i];
        if(num[i] == i){
            cnt++;
            streak++;
            if(streak % 2 == 0){
                cnt--;
            }
        }else{
            streak = 0;
        }
    }

    cout << cnt << endl;

}

Measured memory_bytes: 1024
while True:
    n,k = map(int,input().split())
    if n==k==0:
        break
    a =[]
    for i in range(n):
        a.append(int(input()))
    ans = sum(a[0:k:])
    tmp = ans
    for i in range(n-k):
        tmp += a[k+i]
        tmp -= a[i]
        if ans < tmp:
            ans = tmp
    print(ans)


Measured memory_bytes: 9872
#include<stdio.h>

int main(){
  int sum, i, a;
  while(1){
    scanf("%d", &sum);
    if(sum == 0)return 0;
    for(i = 0;i < 9;i++){
      scanf("%d", &a);
      sum -= a;
    }
    printf("%d\n", sum);
  }
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

bool is_prime(int n){
    switch(n) {
        case 0: // fall-through
        case 1: return false;
        case 2: return true;
    } // n > 2 が保証された

    if(n % 2 == 0) return false;

    // 上で i=2 相当は調べたので、i=3から奇数のみ調べる
    for(unsigned i = 3; i * i <= n; i += 2) {
        if(n % i == 0) return false;
    }

    return true;
}

//FUNCTION
void solve(void)
{
  int N = 100001;
  vector<int> vec(N,0);
  for (int i = 1; i < N; i++)
  {
    if(is_prime(i)&&is_prime((i+1)/2))
    {
      vec[i] = 1;
    }
  }
  for (int i = 0; i < N-1; i++)
  {
    vec[i+1] += vec[i];
  }
  int Q; cin>>Q; 
  for (int i = 0; i < Q; i++)
  {
    int L,R;
    cin>>L>>R;
    cout<<vec[R] - vec[L-1]<<endl;
  }
    

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 998244353;

int parent[N];

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

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

int main()
{
    IOS
    int x, y;
    cin >> x >> y;
    string res = "No";
    for(int c=0;c<=x;c++) {
        int t = x - c;
        if(2*c + 4*t == y) res = "Yes";
    }
    cout << res << endl;
    return 0; 
}



Measured memory_bytes: 3664
#include <iostream>
                    #include<cmath>
                    #include<string>
                    using namespace std;
                    int main()
                    {
                       int a,b,c;
                      cin>>a>>b>>c;
                      int h=(a+b)*c;
                      int j=h/2;
                      cout<<j;
                        
                    }

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	ll x;
	cin >> x;
	ll res = 1000*(x/500);
	x %= 500;
	res += 5*(x/5);
	cout << res;
    return 0;
}


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

#include <algorithm>
#include <cstdio>
using namespace std;

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

  for(int i=n-1; i>=0; i--) {
    printf("%d", a[i]);
    if(i!=0) printf(" ");
  }

  printf("\n");
  return 0;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


class FactorialMod{
    void calc_inverse(){
        inverse[0] = 0;
        inverse[1] = 1;
        for(int i=2; i<=max_num; i++){
            inverse[i] = MOD-((MOD/i)*inverse[MOD%i]%MOD);
        }
    }

    void calc_factorial_inverse(){
        factorial[0] = factorial_inverse[0] = 1;
        for (int i=1; i<=max_num; i++) {
            factorial[i] = (factorial[i-1]*i)%MOD;
            factorial_inverse[i] = (factorial_inverse[i-1]*inverse[i])%MOD;
        }
    }

    public:
        int max_num;
        vector<ll> inverse; 
        vector<ll> factorial;
        vector<ll> factorial_inverse;
        FactorialMod(int _max_num){
            max_num = _max_num;
            inverse = vector<ll>(max_num+1);
            factorial = vector<ll>(max_num+1);
            factorial_inverse = vector<ll>(max_num+1);
            calc_inverse();
            calc_factorial_inverse();
        }

        ll combination(int n, int k){
            return (((factorial[n]*factorial_inverse[k])%MOD)*factorial_inverse[n-k])%MOD;
        }

        ll multiChoose(int n, int k){
            return combination(n+k-1, k);
        }
};

ll modpow(ll x, ll n){
    ll res=1, dig=x;
    while(n){
        if(n&1) res = res*dig%MOD;
        dig = dig*dig%MOD;
        n /= 2;
    }
    return res;
}

int main(){
    ll n, k;    cin >> n >> k;
    //重複組み合わせは配列倍(n+k)にする
    FactorialMod calc_mod(n);
    vector<ll> a(n);    
    REP(i, n)   cin >> a[i];
    sort(ALL(a));
    ll res=0;
    REP(i, n){
        ll tar=0;
        if(k-1<=i) tar += calc_mod.combination(i, k-1);
        if(i+k-1<n) tar -= calc_mod.combination(n-i-1, k-1);
        res = (res+tar*a[i])%MOD;
    }
    cout << res << endl;

}

Measured memory_bytes: 6416
(defun name-sorted (restaurants)
  (sort (copy-list restaurants)
        #'string-lessp :key #'second))

(defun point-sorted (restaurants)
  (sort (copy-list restaurants)
        #'(lambda (a b) (> (third a) (third b)))))

(defun main ()
  (let* ((count (read))
         (restaurants (loop :for i :from 1 :to count
                            :collect (list i (read) (read)))))
    (loop :for restaurant :in (name-sorted (point-sorted restaurants))
          :do (format t "~A~%" (first restaurant)))))

(main)


Measured memory_bytes: 4452
// 未来の僕へ　写経ACなのでちゃんと復習しましょう

#include <iostream>
#include <string>

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

string s, t;
int nxt[26][500000];
int n;
long long ans = 0;
int last[26];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s >> t;
    n = s.size();
    s = s + s;
    fill(last, last + 26, 2 * n);
    for (int i = s.size() - 1; i >= n; i--)
    {
        last[s[i] - 'a'] = i;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = 0; j < 26; j++) nxt[j][i] = last[j];
        last[s[i] - 'a'] = i;
    }
    long long pos = n - 1;
    for (int i = 0; i < t.size(); i++)
    {
        int go = nxt[t[i] - 'a'][pos];
        if (go == 2 * n)
        {
            cout << -1;
            return 0;
        }
        ans += go - pos;
        go %= n;
        pos = go;
    }
    cout << ans << endl;
}


Measured memory_bytes: 48492
#include <iostream>
#include <string>
#include <vector>

#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using lint = long int;
using llint = long long int;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;

    int ans = 0;
    for (size_t i = 0; i < s.size(); i++) {
        int cnt = 0;
        for (size_t j = i; j < s.size(); j++) {
            char ch = s.at(j);
            if (ch == 'A' || ch == 'T' || ch == 'G' || ch == 'C') {
                cnt++;
                ans = max(ans, cnt);
            } else {
                cnt = 0;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N, K = map(int, lines.pop(0).split(' '))

    x = y = 0

    for i in range(1, N+1):
        if i % K == 0:
            x += 1
        elif K % 2 == 0 and i % K == K//2:
            y += 1
    if K % 2 == 0:
        print(x**3 + y**3)
    else:
        print(x**3)


#
# main
#

# 1. use list instead of stdin
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int st[12], n, m, q, a[52], b[52], c[52], d[52];
long long curr, res;
inline void Back(int k) {
    if (k == n + 1) {
        curr = 0;
        for (int i = 1; i <= q; ++i)
            curr += d[i] * (st[b[i]] - st[a[i]] == c[i]);
        res = max(res, curr);
        return;
    }
    for (int i = st[k-1]; i <= m; ++i)
        st[k] = i, Back(k + 1);
}
int main() {
    DAU
    cin >> n >> m >> q;
    for (int i = 1; i <= q; ++i)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
 	st[0] = 1;
    Back(1);
    cout << res;
    PLEC
}


Measured memory_bytes: 3652