akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;cin>>S;
    int A=-1,Z=-1;
    for(int i=0;i<S.size();i++){
        if(S[i]=='A' && A==-1){
            A=i;
        }else if(S[i]=='Z'){
            Z=i;
        }
    }
    cout<<Z-A+1<<endl;
}

Measured memory_bytes: 3684
fun main (args: Array<String>) {
  val k = readLine()!!.toInt()

  var ans = 0
  for (a in 1..k) {
    for (b in 1..k) {
      val ab = gcd(a, b)
      for (c in 1..k) {
        ans += gcd(ab, c)
      }
    }
  }
  println(ans)
}

tailrec fun gcd(p: Int, q: Int): Int {
  if (p % q == 0) return q
  return gcd(q, p % q)
}

Measured memory_bytes: 34620
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let a, b = Scanf.sscanf (read_line ()) "%d %d" ( fun a b -> a, b)
let lst = List.range a `To b
          |> List.map string_of_int


let rec f lst =
        match lst with
                  [] -> 0
                | first :: rest -> 
                        let len2 = String.length first / 2 in
                        let h = String.sub first 0 len2 in
                        let t = String.sub (String.rev first) 0 len2 in
                        let n = f rest in
                                if h = t then
                                        1 + n
                                else
                                        n

let () =
        f lst 
        |> Printf.printf "%d\n"


Measured memory_bytes: 14720
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
 
using namespace std;
 
struct Item{
    ll w, v;
};
 
int main() {
    ios
    ll n, W;
    cin>>n>>W;
    vector <Item> a;
    repi(i, n){
        ll w, v;
        cin>>w>>v;
        a.pb({w,v});
        W = max(W, w);
    }
    vector <vector<ll>> dp(n, vector<ll>(W+1));
    repi(i, n){
        repi(j, W+1){
            if(j==0) dp[i][j] = 0;
            else if(i==0) dp[i][j] = (a[i].w <= j ? a[i].v : 0);
            else dp[i][j] = max(dp[i-1][j], (a[i].w <= j ? a[i].v + dp[i-1][j-a[i].w] : 0));
        }
    }
    cout<<dp[n-1][W];
    return 0;
}

Measured memory_bytes: 82276
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(2 * 10 ** 5 + 100)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265740
K, N = map(int, input().split())
A = list(map(int, input().split()))

max_dist = 0

for i in range(N-1):
    max_dist = max(A[i+1]-A[i], max_dist)

max_dist = max(max_dist, K-A[-1]+A[0])

print(K-max_dist)

Measured memory_bytes: 32304
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s >> t;
  cout << t << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int g[n];//gcd of index 0 to i
	g[0]=a[0];
	//g[0]=__gcd(a[0],a[1]);
	for(int i=1;i<n;i++)
	{
		g[i]=__gcd(g[i-1],a[i]);
	}
	int g2[n];//gcd of index n-1 to i
	g2[n-1]=a[n-1];
	for(int i=n-2;i>-1;i--)
	{
		g2[i]=__gcd(g2[i+1],a[i]);
	}
	int maxi=0;
	maxi=max(maxi,g2[1]);
	maxi=max(maxi,g[n-2]);
	for(int i=1;i<n-1;i++)
	{
		maxi=max(maxi,__gcd(g[i-1],g2[i+1]));
	}
	maxi=max(maxi,g[n-1]);
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	int N;
	cin >> N;
	int H[N];
	bool downed[N];
	for(int i=0;i<N;i++){
		cin >> H[i];
		downed[i]=false;
	}
	for(int i=0;i<N-1;i++){
		if(H[i]>H[i+1]){
			if(H[i]-1>H[i+1]){
				cout << "No" << endl;
				return 0;
			}else{
				H[i]-=1;
				downed[i]=true;
				for(int k=i-1;k>=0 && H[k]>H[k+1];k--){
					if(downed[k]){
						cout << "No" << endl;
						return 0;
					}else if(H[k]-1>H[k+1]){
						cout << "No" << endl;
						return 0;
					}else{
						H[k]-=1;
						downed[k]=true;
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;

int N, A, B, C, D;
string S;

int CHECK(void) {

	for (int i = B+1; i <= D; i++) {
		if ((S[i] == '#') && (S[i - 1] == '#')) { return -1; }
	}

	for (int i = A + 1; i <= C; i++) {
		if ((S[i] == '#') && (S[i - 1] == '#')) { return -1; }
	}

	if (C < B) { return 1; }

	int ret = 1;
	if (D < C) {
		ret = -1;
		for (int i = B + 1; i <= D+1; i++) {
			if ((S[i] == '.') && (S[i - 1] == '.') && (S[i - 2] == '.')) { ret = 1; }
		}
	}

		return ret;
}

int main(void) {


	cin >> N >> A >> B >> C >> D;
	cin >> S;

	S = "?" + S;

	if (CHECK() == 1) { cout<<"Yes" << endl; }
	else { cout << "No" << endl; }
	
	return 0;
}

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

#define int long long 

using namespace std;

void solve()
{
	int n,cnt=0;cin >> n;
	for(int i=1;i<n;i++)
	{
		if(n%i==0)
			cnt+=(n/i)-1;
		else
			cnt+=n/i;
	}
	cout << cnt << endl;
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //int t;cin >> t;while(t--)
    	solve();

    return 0;
}

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    
    int N, M;
    cin >> N >> M;
   
    vector<int> vec(M);
    REP(i, N) {
        int K;
        cin >> K;
        REP(j, K) {
            int a;
            cin >> a;
            ++vec[a-1];
        }
    }
    int ans = 0;
    REP(i, M) {
        if (vec[i] == N) ++ans;
    }
    print(ans);
}

signed main() {
    solve();
}


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

int ctoi(char);

int main()
{
    string s;
    // char strs;    

    while (1)
    {
        cin >> s;
        if (s == "0") break;
        int digs = 0;
        for (long unsigned int i = 0; i < s.length(); i++) {
            // char strs = s[i];
            digs += ctoi(s[i]);
        }
        cout << digs << endl;
    }
    return 0;
}

int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}


Measured memory_bytes: 3204
#include<stdio.h>
int main()
{
   int N;
   scanf("%d",&N);
   
  
   if ((N<=10&&N%1==0) || (N<=20&&N%2==0) || (N<=30&&N%3==0) || (N<=40&&N%4==0) || (N<50&&N%5==0) || (N<60&&N%6==0) || (N<70&&N%7==0)  || (N<80&&N%8==0) || (N<90&&N%9==0))
   {
	   printf("Yes\n");
   }
   else
	   printf("No\n");
   return 0;
} 

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 2005, M = 26, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int main(){
    init();

    ll x;  cin >> x;

    for(ll i = 1;i;i++){
        if(i * (i + 1) / 2 >= x)    return cout << i, 0;
    }
}


Measured memory_bytes: 256
//AUTHOR:: MOHAMMAD FAISAL
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// Codeforces Beginner Problems
//#include<bits/stdc++.h>
#include<iostream>
#include<bitset>
#include<string>
#include<algorithm>
#include <cctype>
#include<unordered_map>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<iterator>
using namespace std;
//string password;
int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool isVowel(char c)
{
    return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}
bool isPrime(long long n)
{
  if (n == 1)
  {
    return false;
  }
  long long int i = 2;
  while (i*i <= n)
  {
      if (n % i == 0)
      {
          return false;
      }
      i += 1;
  }
  return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.flush();
    string s;
    cin >> s;
    int n = (int)s.size();
    int count = 0;
    for(int i=0;i<n;i++)
        if(s[i]!=s[n-1-i])
            count++;
    cout<<count/2<<endl;
//        cout<<s[i]<<" "<<s[n-1-i]<<endl;
    return 0;
}


Measured memory_bytes: 256
let K = readLine()!.characters.split(" ").map{Int(String($0))!}[1]
let A = readLine()!.characters.split(" ").map{Int(String($0))!}
var arr = (0..<200000).map{_ in 0}
for i in A {
    arr[i-1] += 1
}
arr = arr.filter{$0>0}.sort()
print((0..<max(arr.count-K, 0)).reduce(0){$0+arr[$1]})

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

using namespace std;

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")

int main(){

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

   long long int n,a,b;
   cin >> n >> a >> b;
   long long int count = n/(a+b);
   long long int rem = n%(a+b);

   if(rem>a) rem = a;

   cout << count*a + rem << endl;

   
   return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, S;
    scan(N, S);
    auto A = aryread();
    auto dp = new long[][][](3, N + 1, S + 2);
    dp[0][0][0] = 1;
    immutable m = 998244353;
    foreach (i; 0 .. N)
    {
        dp[0][i + 1][0] = 1;
        foreach (j; 0 .. S + 1)
        {
            dp[1][i + 1][j] += dp[0][i][j] + dp[1][i][j];
            dp[1][i + 1][j] %= m;
            dp[1][i + 1][min(S + 1, j + A[i])] += dp[0][i][j] + dp[1][i][j];
            dp[1][i + 1][min(S + 1, j + A[i])] %= m;

            dp[2][i + 1][j] += dp[2][i][j] + dp[1][i][j];
            dp[2][i + 1][j] %= m;
            dp[2][i + 1][min(S + 1, j + A[i])] += dp[1][i][j] + dp[0][i][j];
            dp[2][i + 1][min(S + 1, j + A[i])] %= m;
        }
    }
    writeln(dp[2][N][S]);
}


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

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      long N = Long.parseLong(br.readLine());
      Set<Long> set = new HashSet<>();
      int ans = 0;
      for(long i = 2; i <= Math.sqrt(N); i++){
        if(func(N, i) == 1){
            set.add(i);
        }
      }
      for(long i = 1; i <= Math.sqrt(N-1); i++){
        if((N-1)%i == 0){
            set.add(i);
            set.add((N-1)/i);
        }
      }
      System.out.println(set.size()); 
    }catch(Exception e){
    }
  }
  static long func(long N, long i){
    if(N%i == 0){
        return func(N/i, i);
    }
    return N%i;
  }
}


Measured memory_bytes: 22996
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"regexp"
	"strings"
)

func main() {

	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	a := stdin.Text()
	passcount := 0
	log.Println("a[:1] : ", a[:1])
	if a[:1] == "A" {
		passcount++
	}
	slen := len(a)
	log.Println("a[2:slen-1]: ", a[2:slen-1])
	ccount := 0
	for _, c := range a[2 : slen-1] {
		if string(c) == "C" {
			ccount++
			log.Println("hasC ",string(c))
		}
	}
	if ccount == 1 {
		passcount++
	}

	if passcount == 2 {
		m := string(a[1:2]) + strings.Replace(a[2:slen-1], "C","",1) + string(a[slen-1:])
		log.Println("text m ", m)
		ism, _ := regexp.MatchString(`[A-Z]`, m)
		log.Println("ismatch ", ism)
		if ism == false {
			passcount++
		}
	}
	if passcount == 3 {
		fmt.Println("AC")
	} else {
		fmt.Println("WA")
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b,x;
	cin>>x>>a>>b;
	if(-a+b>=x+1)cout<<"dangerous"<<endl;
	else if(-a+b>0)cout<<"safe"<<endl;
	else cout<<"delicious"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int t_hp = a, a_hp = c;
    while(t_hp > 0){
        a_hp -= b;
        if(a_hp <= 0){
            cout << "Yes" << endl;
            break;
        }
        t_hp -= d;
        if(t_hp <= 0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
inline void read(int &n)
{
	n=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')
	{
		n=(n<<3)+(n<<1)+ch-'0';
		ch=getchar();
	}
	return;
}
const int N=300+10;
const int oo=1e9;
int mi(int a,int b){return a>b?b:a;}
int n,m,l,T,dp[N][N],f[N][N],x,y,c;
int main()
{
	memset(f,0x3f,sizeof(f));
	read(n);read(m);read(l);
	while(m--)
	{
		read(x);read(y);read(c);
		f[x][y]=f[y][x]=c;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			if(i!=k)
				for(int j=1;j<=n;j++)
					if(i!=j&&j!=k)
						f[i][j]=mi(f[i][j],f[i][k]+f[k][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(f[i][j]<=l)dp[i][j]=1;
			else dp[i][j]=oo;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			if(i!=k)
				for(int j=1;j<=n;j++)
					if(i!=j&&j!=k)
						dp[i][j]=mi(dp[i][j],dp[i][k]+dp[k][j]);
	read(T);
	while(T--)
	{
		read(x);read(y);
		if(dp[x][y]==oo)puts("-1");
		else printf("%d\n",dp[x][y]-1);
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define err(x) debug() << "[" << #x << ": " << x << "]\n"
template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);
struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator<<(pair<c,d> e){
    return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator<<(c a){
    cerr << boolalpha << a;
    return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator<<(c a){
    *this << "{";
    for (auto it = a.begin(); it != a.end(); it++)
        *this << ","[1 - (it != a.begin())] << *it;
    return *this << "}";
}
#else
template<class c>debug& operator<<(c){
    return *this;
}
#endif
};







int main() 
{
    
    int a, b;
    cin >> a >> b;
    
    int ans = 0;
    
    if (a > 5 && a < 13) ans += b / 2;
    if (a > 12) ans += b;
    
    cout << ans; 
    
}


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

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

    vector<string> res;

    for(int i = 0; i < s.length(); i++){
        for(int j = 1; j <= K; j++){
            res.push_back(s.substr(i,j));
        }
    }
    sort(res.begin(),res.end());
    res.erase(unique(res.begin(),res.end()),res.end());
    cout << res[K-1] << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

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

  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  bool ok = false;
  for (int m = 0; m <= n - 1; m++) {
    ll lo = - d * m + c * (n - 1 - m);
    ll hi = d * (n - 1 - m) - c * m;
    if (b - a >= lo && b - a <= hi) ok = true;
  }

  if (ok) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#define MAX_N 100'000

using namespace std;

int A[MAX_N];

int main() {
  int N;
  cin >> N;
  int odd_num = 0;
  int four_num = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] % 4 == 0) {
      ++four_num;
    } else if (A[i] % 2 == 1) {
      ++odd_num;
    }
  }
  if (four_num >= odd_num - (four_num + odd_num == N)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
int cnt[4001][4001];
int main(){
  string str1,str2;
  while(cin >> str1){
    cin >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    str1 = ' ' + str1;
    str2 = ' ' + str2;
    for(int i=1;i<=len1;i++){
      cnt[i][0] = 0;
    } 
    for(int i=1;i<=len2;i++){
      cnt[0][i] = 0;
    }
    int ret = 0;
    for(int i=1;i<=len1;i++){
      for(int j=1;j<=len2;j++){
	if(str1[i] == str2[j]){
	  cnt[i][j] = cnt[i-1][j-1] + 1;
	}
	else {
	  cnt[i][j] = 0;
	}
	ret = max(ret,cnt[i][j]);
      }
    }
    cout << ret << endl;
  }	
}

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

int main()
{
    string S;
    cin >> S;

    int len = S.size();
    string ans = "AC";
    if (S[0] != 'A') {
        ans="WA";
    }

    int cnt_c = 0;
    for (int i=1; i<len; i++){
        if (S[i]>='A' && S[i]<='Z' ){
            if(i==1 || i==len-1 || S[i] !='C') 
                ans = "WA";
            else ++cnt_c;
        } 
    }
    if(cnt_c!=1) ans = "WA";
    cout << ans <<endl;
    return 0;
}

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

int main(){
	string x;
	cin>>x;
	int ans=0;
	int len=x.length();
	if(x[0]=='R'&&x[1]=='R'&&x[2]=='R'){
		ans=3;
	}
	else if(x[0]=='R'&&x[1]=='R')
	{
		ans=2;
	}
	else if(x[1]=='R'&&x[2]=='R'){
		ans=2;
	}
	else if(x[0]=='R'){
		ans=1;
	}
	else if(x[1]=='R'){
		ans=1;
	}
	else if(x[2]=='R'){
		ans=1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){

	int K;
	cin>>K;
	
	vector<int> dis(K,Inf);
	queue<int> Q;
	dis[7%K]=1;
	Q.push(7%K);
	
	while(Q.size()!=0){
		int u = Q.front();
		Q.pop();
		int k = u*10+7;
		k %= K;
		if(dis[k]!=Inf)continue;
		dis[k] = dis[u]+1;
		Q.push(k);
	}
	
	if(dis[0]==Inf)cout<<-1<<endl;
	else cout<<dis[0]<<endl;
	
	return 0;
}

Measured memory_bytes: 7216
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

tableA = {
    "A": "00000",
    "B": "00001",
    "C": "00010",
    "D": "00011",
    "E": "00100",
    "F": "00101",
    "G": "00110",
    "H": "00111",
    "I": "01000",
    "J": "01001",
    "K": "01010",
    "L": "01011",
    "M": "01100",
    "N": "01101",
    "O": "01110",
    "P": "01111",
    "Q": "10000",
    "R": "10001",
    "S": "10010",
    "T": "10011",
    "U": "10100",
    "V": "10101",
    "W": "10110",
    "X": "10111",
    "Y": "11000",
    "Z": "11001",
    " ": "11010",
    ".": "11011",
    ",": "11100",
    "-": "11101",
    "'": "11110",
    "?": "11111"}

tableB = {
    "101": " ",
    "000000": "'",
    "000011": ",",
    "10010001": "-",
    "010001": ".",
    "000001": "?",
    "100101": "A",
    "10011010": "B",
    "0101": "C",
    "0001": "D",
    "110": "E",
    "01001": "F",
    "10011011": "G",
    "010000": "H",
    "0111": "I",
    "10011000": "J",
    "0110": "K",
    "00100": "L",
    "10011001": "M",
    "10011110": "N",
    "00101": "O",
    "111": "P",
    "10011111": "Q",
    "1000": "R",
    "00110": "S",
    "00111": "T",
    "10011100": "U",
    "10011101": "V",
    "000010": "W",
    "10010010": "X",
    "10010011": "Y",
    "10010000": "Z"}

def my_solve(s):
    # encode
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    # en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
    a = b = c = ''
    # for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
    # s = a
    a = s

    de = {
        '101': ' ', '000000': '\'', '000011': ',', '10010001': '-', '010001': '.', '000001': '?',
        '100101': 'A', '10011010': 'B', '0101': 'C', '0001': 'D', '110': 'E', '01001': 'F',
        '10011011': 'G', '010000': 'H', '0111': 'I', '10011000': 'J', '0110': 'K', '00100': 'L',
        '10011001': 'M', '10011110': 'N', '00101': 'O', '111': 'P', '10011111': 'Q', '1000': 'R',
        '00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V', '000010': 'W', '10010010': 'X',
        '10010011': 'Y', '10010000': 'Z'
    }
    for x in a:
        b += x
        if b in de: c += de[b];b = ''
    return c

    # tmp, ans = '', ''
    # for c in s:
    #     tmp += c
    #     if tmp in tableB:
    #         ans += tableB[tmp]
    #         tmp = ''
    # return ans

while True:
    try:
        s = input()
    except:
        break

    print(my_solve(s))

Measured memory_bytes: 11740
A,V=list(map(int,input().split()))
B,W=list(map(int,input().split()))
T=int(input())


if V<=W :
    ans = "NO"
else:
    if abs(B-A) <= abs(V-W)*T:
        ans = "YES"
    else:
        ans = "NO"

print(ans)        



Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define mod 1000000007

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define db long double
#define vlli vector<long long int >
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define cnl cout<<"\n";
#define fr(i,b) for(ll i=0; i<=b; i++)
#define frr(i,b) for(ll i=0;i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define PI 3.14159265



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

 bool comp(pair<long int ,long int>v1,pair<long int ,long int>v2){
          if(v1.ft==v2.ft) return v1.sd>v2.sd;
          else return v1<v2;
 }

 typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
ll i,j,k;
 

int main(){
   
  ll n; cin>>n;
  vlli v(n);
  frr(i,n) cin>>v[i];
  ll max=-1;
  ll p;
  frr(i,n){
    if(v[i]>max){
      max=v[i];
      p=i;
    }
  }
  sort(all(v));
  ll y=v[n-2];
  frr(i,n){
    if(i==p) cout<<y<<endl;
    else cout<<max<<endl;
  }





return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    string S;
    cin >> S;
    if (S[1] == 'B') cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n+1, 0);
  for (int i = 2; i <= n; ++i) {
    int tmp;
    cin >> tmp;
    ++vec[tmp];
  }
  for (int i = 1; i <= n; ++i)
    cout << vec[i] << endl;
}

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

using namespace std;

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0])
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

ll n, a[101010], as[101010], ans=0, mx,t;

int main(){

cin >> n >> t;
rep(i, 1, n){
cin >> a[i];
}
rep1(i,n, 1 ){
as[i]=max(as[i+1], a[i]);
}

rep(i, 1, n){
ll temp = as[i+1]-a[i];

mx = max(mx, temp);

}

rep(i, 1, n){
if(as[i]-a[i]==mx)ans++;
}

cout << ans << endl;


return 0;}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1};
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w; cin >> h >> w;
    vector<string> s(h); rep (i, h) cin >> s[i];
    bool ok = true;
    rep (i, h) {
        rep (j, w) {
            if (s[i][j] == '.') continue;
            bool tmp = false;
            rep (k, 4) {
                if (i + dy[k] < 0 || i + dy[k] >= h || j + dx[k] < 0 || j + dx[k] >= w) continue;
                if (s[i + dy[k]][j + dx[k]] == '#') tmp = true;
            }
            ok &= tmp;
        }
    }
    cout << (ok ? "Yes\n" : "No\n");
    return 0;
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  vector<P> vec(n);
  vector<P> s(n);
  rep(i, n) {
    int a, b; cin >> a >> b;
    vec[i] = P(a,b);
    int c = b;
    s[i] = P(c, i);
  }
  sort(s.begin(), s.end());
  int now = 0;
  rep(i, n) {
    int pos = s[i].second;
    debug(pos, vec[pos].first, vec[pos].second, vec[pos].second-vec[pos].first);
    now += vec[pos].first;
    debug(now);
    if (now > vec[pos].second) {
      debug(now, vec[pos].second);
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll N, M, X;
    cin >> N >> M >> X;
    vll C(N);
    vvll A(N, vll(M));
    rep(i, N){
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }

    ll m = LLONG_MAX;
    rep(b, 1<<N){
        bool valid = true;
        rep(i, M){
            ll tmp = 0;
            rep(j, N){
                if((b>>j)&1) tmp += A[j][i];
            }
            valid &= tmp>=X;
        }
        ll total = 0;
        rep(i, N){
            if((b>>i)&1) total += C[i];
        }
        if(valid) m = min(m, total);
    }
    if(m==LLONG_MAX) cout << -1 << endl;
    else cout << m << endl;
}


Measured memory_bytes: 3684
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;


int main(){
	int	N,candy1[100],candy2[100],sum1=0,sum2=0,max=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>candy1[i];
	}
	for(int i=0;i<N;i++){
		cin>>candy2[i];
	}
	for(int i=0;i<N;i++){
		int get=0;
		for(int j=0;j<=i;j++){
			get+=candy1[j];
		}
		for(int j=i;j<N;j++){
			get+=candy2[j];
		}
		if(max<get){
			max=get;
		}
	}
	cout<<max<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod=1e9+7;
const int N=2e5+100;
int a[N];
map<string,int> mp;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    if(n%1000) 
   cout<<1000-n%1000<<endl;
   else cout<<0;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define sort(v) sort(v.begin(),v.end()) 
#define pb push_back
/*
ll ar[1000000+9]={0}; 
vector<ll>v;
void seiv() { 
ll n=1000000,i,j; 
ar[1]=1; 
for(i=4;i<=n;i+=2)ar[i]=1; 
for(i=3;i<=n;i+=2) 
{ if(ar[i]==0) 
{ for(j=i*i;j<=n;j+=i*2)ar[j]=1; }
                
 } 
    for(i=2;i<=2244;i++){if(ar[i]==0)v.pb(i);}}*/
int main()
{
ll a,b,c,d,i,j,k,l;
cin>>a>>b;
if(a>=b)
  {
    for(i=1;i<=a;i++)cout<<b;
  }
        else 
        {
        for(i=1;i<=b;i++)cout<<a;
}
 }

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

#define itn int
#define vi vector<int>
#define pb push_back
#define srt sort(v.begin(), v.end())

//int infiint = std::numeric_limits<int>::max();
//float infiflt = std::numeric_limits<float>::infinity();


void solve() {
 	int n, m;
 	cin >> n >> m;
 	if(n <= m) {
 		cout << "Yes";
 	}
 	else
 		cout << "No";
}

int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt", "rt", stdin);

	solve();

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
int n,mod;
vector<int>v[100003];
long long dp1[100005],dp2[100003],fa[100003];
long long dfs1(int x,int p){
	fa[x]=p;
	dp1[x]=1;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]!=p)
			dp1[x]=dp1[x]*dfs1(v[x][i],x)%mod;
	dp1[x]++;dp1[x]%=mod; 
	return dp1[x];
}
void dfs2(int x,int p){
	vector<long long>a,b;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]==p)
			a.push_back(1),b.push_back(1);
		else
			a.push_back(dp1[v[x][i]]),
			b.push_back(dp1[v[x][i]]);
	for(int i=1;i<a.size();i++)a[i]=a[i-1]*a[i]%mod;
	for(int i=b.size()-2;i>-1;i--)b[i]=b[i+1]*b[i]%mod;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]!=p){
			long long ret=1;
			if(i)ret=ret*a[i-1]%mod;
			if(i<b.size()-1)ret=ret*b[i+1]%mod;
			ret=(ret*dp2[x]+1)%mod;
			dp2[v[x][i]]=ret;
			dfs2(v[x][i],x);
		}
}
int main(){
	scanf("%d%d",&n,&mod);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);a--;b--;
		v[a].push_back(b);
		v[b].push_back(a); 
	}
	dfs1(0,-1);
	dp2[0]=1;dfs2(0,-1);
	for(int i=0;i<n;i++){
		long long res=dp2[i];
		for(int j=0;j<v[i].size();j++)
			if(v[i][j]!=fa[i])
				res=res*dp1[v[i][j]]%mod;
		cout<<res<<endl;
	} 
}

Measured memory_bytes: 25088
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().AOJ0026();
	}
	
	int[][] p26 = new int[10][10];
	int c26=100;
	void AOJ0026(){
		int ans=0;
		while(sc.hasNext()){
			Scanner sc2 = new Scanner(sc.nextLine()).useDelimiter(",");
			int x=sc2.nextInt(), y=sc2.nextInt(), s=sc2.nextInt();
			// out.println("x"+x+" y"+y+" s"+s);
			ans=max(solve26(x,y),ans);
			ans=max(solve26(x-1,y),ans);	ans=max(solve26(x+1,y),ans);
			ans=max(solve26(x,y-1),ans);	ans=max(solve26(x,y+1),ans);
			if(s>=2){
				ans=max(solve26(x-1,y-1),ans);	ans=max(solve26(x-1,y+1),ans);
				ans=max(solve26(x+1,y-1),ans);	ans=max(solve26(x+1,y+1),ans);
			}
			if(s>=3){
				ans=max(solve26(x-2,y),ans);	ans=max(solve26(x+2,y),ans);
				ans=max(solve26(x,y-2),ans);	ans=max(solve26(x,y+2),ans);
			}
		}
		out.println(c26);
		out.println(ans);
	}
	int solve26(int x, int y){
		int r=-1;
		if(0<=x && x<=9 && 0<=y && y<=9){
			c26 -= p26[x][y]==0? 1: 0;
			p26[x][y]++;
			r=p26[x][y];
		}
		return r;
	}
	
	void AOJ0008(){	//Sum of 4 Integers
		while(sc.hasNext()){
			int ans=0, n=sc.nextInt();
			for(int a=0; a<10; a++){
				for(int b=0; b<10; b++){
					for(int c=0; c<10; c++){
						for(int d=0; d<10; d++){
							if((a+b+c+d)==n)	ans++;
						}
					}
				}
			}
			out.println(ans);
		}
	}
	
	void AOJ0055(){	// Sequence
		while(sc.hasNext()){
			double last=sc.nextDouble(), ans=last;
			for(int i=2; i<=10; i++){
				ans+= i%2==0? last*2: last/3;
				last = i%2==0? last*2: last/3;
				// out.println(last);
			}
			out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<math.h>
int main()
{
	long long i, h, s;
	while(~scanf("%lld", &h))
	{
		i = (log(h)/log(2))+1;
		s = pow(2,i)-1;
		printf("%lld\n", s);
	}
	return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int K,N;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}


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

  setComb();

  for(int i=1;i<=K;i++){
    ll x=hcomb(K-i,i);
    ll y=hcomb(N-K-(i-1),i+1);

    //cout<<i<<" "<<x<<" "<<y<<endl;

    ll z=x*y%MOD;
    cout<<(z+MOD)%MOD<<endl;
  }


  return 0;
}


Measured memory_bytes: 4992
let (w,h,x,y,r) = Scanf.scanf "%d %d %d %d %d\n" (fun w h x y r -> w,h,x,y,r)

let () =
  if x+r <= w && x-r >= 0 && y+r <= h && y-r >= 0 then print_endline "Yes"
  else print_endline "No"

Measured memory_bytes: 2248
//_NewBie_

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, p, mp=0;
    int pr[1000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>pr[i];
    }
    sort(pr, pr+n);
    for(int i=0;i<k;i++) mp+=pr[i];
    cout<<mp<<endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	private static final long MOD = 1_000_000_007L;

	private static final int[][] counts = { { 3, 2, 1 }, { 6, 2, 3 } };

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			char[] s1 = scanner.next().toCharArray();
			char[] s2 = scanner.next().toCharArray();
			int i = 0, prev = 0;
			long result = 1L;
			while (i < n) {
				if (s1[i] == s2[i]) {
					// 縦の並び
					result = result * counts[0][prev] % MOD;
					prev = 1;
					i++;
				} else {
					// 横の並び
					result = result * counts[1][prev] % MOD;
					prev = 2;
					i += 2;
				}
			}
			System.out.println(result);
		}
	}

	/**
	 * @param pathLists ノード間の連結パス一覧の配列
	 * @param src       開始ノード
	 * @param n         ノードの数
	 * @return 開始ノードからの距離の配列
	 */
	private static long[] dijkstra(List<Path>[] pathLists, int src, int n) {
		long[] distances = new long[n];
		Arrays.fill(distances, Long.MAX_VALUE);
		// 最短距離が確定したかどうか
		boolean[] fixed = new boolean[n];
		Arrays.fill(fixed, false);
		// 出発地点までの距離を0とする
		distances[src] = 0L;
		Queue<Path> queue = new PriorityQueue<>();
		queue.add(new Path(src, src, 0));
		while (!queue.isEmpty()) {
			int now = queue.poll().to;
			if (!fixed[now]) {
				fixed[now] = true;
				for (Path path : pathLists[now]) {
					if (!fixed[path.to] && distances[path.to] > distances[now] + path.cost) {
						distances[path.to] = distances[now] + path.cost;
						queue.add(new Path(path.to, path.to, distances[path.to]));
					}
				}
			}
		}
		return distances;
	}

	/**
	 * ノード間の一つのパスを表すクラス
	 */
	private static class Path implements Comparable<Path> {
		/** 開始ノード */
		@SuppressWarnings("unused")
		int from;
		/** 終了ノード */
		int to;
		/** 移動コスト */
		long cost;

		Path(int from, int to, long cost) {
			super();
			this.from = from;
			this.to = to;
			this.cost = cost;
		}

		@Override
		public int compareTo(Path path) {
			if (this.cost > path.cost) {
				return 1;
			} else if (this.cost == path.cost) {
				return 0;
			} else {
				return -1;
			}
		}
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
    int d,n;
    cin >> d >> n;
    if(d==0){
    	if(n==100){
    		cout << n+1 << endl;
    	}
    	else{
    		cout << n << endl;
    	}
    }
    else if(d==1){
    	if(n==100){
    		cout << 100*(n+1) << endl;
    	}
    	else{
    		cout << 100*n << endl;
    	}
    }
    else{
    	if(n==100){
    		cout << 10000*(n+1) << endl;
    	}
    	else{
    		cout << 10000*n << endl;
    	}

    }
    return 0;
}



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

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

	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= d; j += a[i]) {
			ans++;
		}
	}

	cout << ans + x << endl;


	return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  int A;
  cin >> A;
  
  if(A == 0 ) {
    if(N%500 == 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  if(A !=0 ) {
    if (N%500 <= A) {
    cout << "Yes" << endl;
    }
    else {
    cout << "No" << endl;
    }
  }
}  

  




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

using namespace std;
#define int long long
const int MOD = 1000000007;
int N;
int solve(int A, int B) {
	if (A > B) swap(A, B);
	int ans = 0;
	int x = A - 1;
	ans += x;
	A -= x;
	B -= x;
	while ((A + B) % 2 == 1) {
		B--;
		ans++;
	}
	ans += abs(A - B) / 2;
	return ans;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> N >> A >> B;
	int res = (int)1 << 60;
	if ((A + B) % 2 == 0) {
		res = abs(A - B) / 2;
	}

	res = min(res, solve(A, B));
	res = min(res, solve(N - A + 1, N - B + 1));

	cout << res << endl;
}

Measured memory_bytes: 256
N = int(input())
D = {True: 'S', False: 'W'}
E = {'o': True, 'x': False}
S = list(input())
for i in range(N):
    S[i] = E[S[i]]
# print(S)

L = {(True, True), (True, False), (False, True), (False, False)}

for a, b in L:
    ans = [None]*N
    ans[0], ans[1] = a, b
    for i in range(1, N-1):
        if not ans[i] ^ S[i]:
            ans[i+1] = ans[i-1]
        else:
            ans[i+1] = not ans[i-1]
    if ans[-1] ^ S[-1] == ans[-2] ^ ans[0] and ans[0] ^ S[0] == ans[-1] ^ ans[1]:
        for i in range(N):
            ans[i] = D[ans[i]]
        print(''.join(ans))
        exit()
else:
    print(-1)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int A[101010];
int D[101010];
vector<int> E[101010];
int ret;

int dfs(int cur) {
	if(cur==0) return 0;
	if(D[cur]>=0) return D[cur];
	return D[cur]=dfs(A[cur])+1;
}

int dfs2(int cur) {
	int ma=0;
	FORR(r,E[cur]) ma=max(ma,dfs2(r)+1);
	if(cur==0) return 0;
	
	if(ma==K-1 && A[cur]!=0) {
		ret++;
		return -1;
	}
	else {
		return ma;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>A[i];
		A[i]--;
		if(i) E[A[i]].push_back(i);
	}
	
	if(A[0]!=0) ret++;
	dfs2(0);
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

int n,sum;
vector<int> s;

int main(void) {
    cin>>n;
    for(int i=0;i<n;i++) {
        int x;cin>>x;
        s.push_back(x);
        sum+=x;
    }
    sort(s.begin(),s.end());

    if(sum%10) {
        cout<<sum<<endl;
        return 0;
    }

    for(int i=0;i<n;i++) {
        if(s[i]%10) {
            sum-=s[i];
            break;
        }
    }
    if(sum%10) cout<<sum<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _0034
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                int[] x = s.Split(',').Select(int.Parse).ToArray();
                int sum = 0;
                double limit = x.Sum() - x[10] - x[11]; limit = limit * x[10] / (x[10] + x[11]);
                for (int i = 0; true; i++)
                {
                    sum += x[i];
                    if (sum >= limit)
                    {
                        Console.WriteLine(i + 1);
                        break;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 9504
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
long long k,n,m,ans;
int main(){
	scanf("%lld%lld%lld",&k,&n,&m);
	if(k<=n) {
		printf("1\n");
		return 0;
	}
	if(n<=m) {
		printf("-1\n");
		return 0;
	}
	long long s=n-m,d=k-n;
	if(d%s==0) ans=d/s;
		else ans=d/s+1;
	printf("%lld\n",ans*2+1);
}



Measured memory_bytes: 256
#/usr/bin/python

def solve():
    n, k = map(int, input().split())
    a = sorted(map(int, input().split()), reverse=True)

    mod = 10 ** 9 + 7
    l = 0
    r = n - 1
    ans = 1

    if k % 2 == 1:
        ans = a[0]
        l = 1

    # If the maximum number is negative and k is odd, the answer is the product of the first k numbers.
    if ans < 0:
        mul = 1
        for i in range(k):
            mul = mul * a[i] % mod
        return mul

    # otherwise, multiply the leftmost two products and the rightmost two products, whichever is larger.
    for i in range(k//2):
        l_mul = a[l] * a[l+1]
        r_mul = a[r] * a[r-1]
        if l_mul >= r_mul:
            ans = ans * l_mul % mod
            l += 2
        else:
            ans = ans * r_mul % mod
            r -= 2

    return ans

print(solve())


Measured memory_bytes: 31728
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
const Nums = input.split('\n');
const N = Nums[0]*1;
const T = Nums[1].split(" ")[0]*1;
const A = Nums[1].split(" ")[1]*1;
const H = Nums[2].split(" ").map(x => x*1);

// 温度の計算配列
const X = H.map(x=> T-x*0.006);
// 欲しい値との絶対値の差を見る配列
const MinSearch = X.map(x => Math.abs(x - A));
// その中で最小を調べる
const ans = MinSearch.indexOf(Math.min(...MinSearch));
// 0スタートだったものに対して1スタートに変えるために+1をした
console.log(ans + 1);

Measured memory_bytes: 7860
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){

    long long N, M;
    cin >> N >> M;

    vector <long long> B(N + 1);
    B[0] = 0;
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        B[i + 1] = B[i] + a % M;
        B[i + 1] %= M;
    }
    map <long long, int> M1;
    vector <long long> M2;

    for (int i = 0; i < N + 1; i++){
        if (M1[B[i]] == 0){
            M2.push_back(B[i]);
        }
        M1[B[i]]++;
    }

    long long ans = 0;
    for (int i = 0; i < M2.size(); i++){
        long long a = M1[M2[i]];
        ans += a * (a-1) /2;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5496