akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;


signed main(){
  int x,y,s;
  while(cin>>x>>y>>s,x){
    vector<pair<int,int>> m;
    for(int i=1;i<s;i++){
      for(int j=1;j<s;j++){
        int tmp=i*(100+x)/100+j*(100+x)/100;
        if(tmp==s)m.PB(MP(i,j));
      }
    }
    int ans=-1;
    for(auto t : m){
      int tmp=t.FR*(100+y)/100;
      tmp+=t.SC*(100+y)/100;
      ans=max(ans,tmp);
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define all(a) (a).begin(),(a).end()
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

signed main(){
    ios_base::sync_with_stdio(0);
    int l , r , d;
    cin >> l >> r >> d ;
    cout << r/d - (l-1)/d << endl ;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<char> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  set<char> st;
  for (char c : v) st.insert(c);
  if (st.size() == 3)
    cout << "Three" << endl;
  else if (st.size() == 4)
    cout << "Four" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF pow(10, 9) + 7
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

void solve(){
	
	ll H, W, cnt;
	cin >> H >> W;
	vs s(H);
	rep(i, H)  cin >> s[i];
	
	vvl res(H, vl(W));
	
	rep(i, H){
		cnt = 0;
		rep(j, W){
			if(s[i][j] == '#') cnt = 0;
			else{
				cnt += 1;
				res[i][j] += cnt;
			}
		}
	}
	
	rep(i, W){
		cnt = 0;
		rep(j, H){
			if(s[j][i] == '#') cnt = 0;
			else{
				cnt += 1;
				res[j][i] += cnt;
			}
		}
	}
	
	for(ll i = H - 1; i >= 0; i--){
		cnt = 0;
		for(ll j = W - 1; j >= 0; j--){
			if(s[i][j] == '#') cnt = 0;
			else{
				cnt += 1;
				res[i][j] += cnt;
			}
		}
	}
	
	for(ll i = W - 1; i >= 0; i--){
		cnt = 0;
		for(ll j = H - 1; j >= 0; j--){
			if(s[j][i] == '#') cnt = 0;
			else{
				cnt += 1;
				res[j][i] += cnt;
			}
		}
	}

	
	ll ans = 0;
	rep(i, H) rep(j, W) chmax(ans, res[i][j]);
	
	print(ans - 3);

}	

int main(){
    
    fastio;
	solve();
    
	return 0;
	
}


Measured memory_bytes: 38844
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, k, ans=0;

	cin>>n>>k;

	vi l(n);

	rep(i, n) cin>>l[i];

	sort(all(l)); reverse(all(l));

	rep(i, k){
		ans+=l[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define pii                pair < int , int >
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define vecsum(v)          accumulate(v.begin(), v.end(), 0)
#define adj_diff(a,b)      adjacent_difference(a.begin(), a.end(), b.begin())
#define IOTA(a,x)          iota(a.begin(), a.end(), x);
#define par_sum(a,sum)     partial_sum(a,a+sizeof(a),sum)


#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
int a[100005] ;
int dp[100005];

int i;
int main()
{

    int n;
    cin >> n;
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    for(int i = 0 ;i<=n;i++){
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i = 0 ; i < n ; i++){

        if( i + 1 < n ){
            dp[i+1] = min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        }
        if(i+2<n){
            dp[i+2] = min(dp[i+2],dp[i] +abs(a[i]-a[i+2]));
        }
    }

    cout << dp[n-1] << endl;



}




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

int main() {
    string s;
    cin >> s;
    
    int cnt[26] = {};
    for (auto c: s) {
        cnt[c-'a']++;
    }
    
    ll n = s.length();
    ll ans = n * (n-1) / 2 + 1;
    
    for (auto e: cnt) {
        ans -= (ll)e * (e-1) / 2;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k);(i)<(n);(i)++)
using namespace std;

int N,M;
vector<string> A,B;

// A[i][j] から始めて、B と一致しているか
bool check(int i, int j)
{
  FOR(x,0,M) {
    FOR(y,0,M) {
      if (A[i+x][j+y] != B[x][y]) return false;
    }
  }
  return true;
}

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

  A.resize(N);
  B.resize(M);

  FOR(i,0,N) cin >> A[i];
  FOR(i,0,M) cin >> B[i];


  bool flag = false;
  FOR(i,0,N-M+1) {
    FOR(j,0,N-M+1) {
      // 同じかどうか判定
      // チェックが成功したら、 抜ける
      if (check(i,j)) {
        flag = true;
        break;
      }
    }
  }

  string msg;
  if (flag) msg = "Yes";
  else msg = "No";

  cout << msg << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            int tmp = sc.nextInt();
            if(tmp%2==0){
                if(!(tmp%3==0 || tmp%5==0)){
                    System.out.println("DENIED");
                    return;
                }
            }
            else{
                continue;
            }
        }
        System.out.println("APPROVED");
        return;
    }
}


Measured memory_bytes: 23892
import math

if __name__ == '__main__':
    N, M = list(map(int, input().split()))

    if abs(N - M) >= 2:
        print(0)
    elif N == M:
        ans = (math.factorial(N) * math.factorial(M) * 2) % 1000000007
        print(ans)
    else:
        ans = (math.factorial(N) * math.factorial(M)) % 1000000007
        print(ans)

Measured memory_bytes: 5196
using System;
using System.Linq;
//using System.Collections.Generic;

class Test
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        A = A.Distinct().ToArray();
        Console.WriteLine(string.Join(" ", A));
    }
}



Measured memory_bytes: 35756
H, W = gets.to_s.split.map{|t|t.to_i}

# p '.'.ord #=> 46
# p '#'.ord #=> 35
S = Array.new(H){ gets.to_s.chomp.bytes } 

def bfs(sx, sy)
  
  dx = [1, 0, -1, 0]
  dy = [0, 1, 0, -1]
  
  q = [[sx,sy,1]]
  
  used = Array.new(H){ Array.new(W+1){ false } }
  while q.any?
    # q.uniq!
    x, y, d = q.shift
    used[x][y] = true
    d += 1
    4.times do |i|
      nx = x + dx[i]
      ny = y + dy[i]
      return d if nx == H - 1 && ny == W - 1
      if 0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == 46 && !used[nx][ny]
        used[nx][ny] = true
        q.push( [nx, ny, d] )
      end
    end
  end
  
  puts -1
  exit
end

p S.flatten.count(46) - bfs(0,0)

Measured memory_bytes: 1916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            int w = Integer.parseInt(reader.readLine());
            int n = Integer.parseInt(reader.readLine());
            int[] x = new int[w];
            for(int i = 0; i< w; i++){
                x[i] = i + 1;
            }
            int a ;
            int b ;
            for(int i = 0; i < n; i++){
                String line = reader.readLine();
                String[] s = line.split(",");
                a = Integer.parseInt(s[0]);
                b = Integer.parseInt(s[1]);
                int temp = x[a-1];
                x[a-1] = x[b-1];
                x[b-1] = temp;
            }
            for(int i = 0; i < w; i++){
                System.out.println(x[i]);
            }
        }catch(IOException e){

        }
    }
}


Measured memory_bytes: 24228
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		int s = sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt();
		System.out.println(s / 60);
		System.out.println(s % 60);
	}
}

Measured memory_bytes: 12000
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s_4digits = input().rstrip()



    for bit in range(1 << len(s_4digits)-1):
        # 一文字目は必ずプラス
        ans = int(s_4digits[0])
        op_list = []
        plus_list = []
        for i in range(len(s_4digits)-1):

            if bit & (1<<i):
                plus_list.append(i)

        # 式の組み立て
        for j in range(len(s_4digits)-1):
            op_list.append("-")

        for num in plus_list:
            op_list[num] = "+"
        for i, op in enumerate(op_list):
            if op == "+":
                ans += int(s_4digits[i+1])
            else:
                ans -= int(s_4digits[i+1])

        if ans == 7:
            ans_str = s_4digits[0]
            for i, op in enumerate(op_list):
                ans_str += op + s_4digits[i+1]
            print(ans_str + "=7")
            exit()




if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include<climits>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
const double pi=acos(-1.0);
#define boost  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define sl(n) scanf("%lld",&n)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define f(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i > (ll)(b); i--)
#define ms(a,b) memset((a),(b),sizeof(a))
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define vec(g1) int temp;cin>>temp;g1,push_back(temp);
#define abs(x) ((x<0)?(-(x)):(x))
#define MAX 1000005
#define inf LLONG_MAX
#define MIN INT_MIN
//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}

/**.................................................................................................................................*/
int main(){
	boost;
   string s;
   cin>>s;
   int flag=0;
   f(i,1,s.size()){
   	if(s[i]==s[i-1]){flag=1; break;}
    }
    if(flag)cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
 	return 0;
}


Measured memory_bytes: 256
s=list(input())
count=0
# print('lens',len(s))
indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])
# print(indexes)
# print(ideal)
for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)

Measured memory_bytes: 22336
// Battle

func main() {
    let abcd = readLine()!.split(separator: " ").map{Int($0)!}
    var a = abcd[0]
    let b = abcd[1]
    var c = abcd[2]
    let d = abcd[3]

    while true {
        // 高橋くんの攻撃
        c -= b
        if c <= 0 {
            print("Yes")
            return
        }

        // 青木くんの攻撃
        a -= d
        if a <= 0 {
            print("No")
            return
        }
    }
}

main()

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



//defines...
#define ll long long
#define tata return;
#define pb push_back
#define mp make_pair
#define in insert
#define run ios_base::sync_with_stdio(false);cin.tie(NULL);
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define vec vector<ll>
#define setl set<ll>
#define mapl map<ll,ll>
#define shunno cout<<0<<endl;
#define pi 2*acos(0.0)1
#define hobena cout<<-1<<endl;




//typedefs...
typedef pair<ll,ll>pll;

//const..
const ll fx[]={0,1,0,-1};
const ll fy[]={1,0,-1,0};
const ll mod=1e9+7;

/*ll ncr(ll n, ll k)
{
    ll res = 1;


    if (k > n - k)
        k = n - k;

    for (int i = 0; i < k; ++i) {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}
*/
//to remove suffix of a number from a set of string
/*
for(int k=1; k<j.size(); k++)
                if(temp.count(string(j.begin()+k,j.end())))
					temp.erase(string(j.begin()+k,j.end()));
 */

void oka()
{
   map<char,ll>m;
   string a;
   cin>>a;
   for(ll i=0;i<a.size();i++)
   {
       m[a[i]]++;
   }
   for(ll i=0;i<a.size();i++)
   {
       if(m[a[i]]%2)
       {
           no
           tata
       }

   }
   yes





}
/*I'll paint it on the walls
     cause I'm the one at fault
    I'll never fight again and
         this is how it ends .*/






int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    run

    oka();




}

Measured memory_bytes: 3640
S = input()

count1 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            count1 += 1
    else:
        if S[i] == '1':
            count1 += 1

count2 = 0
for i in range(len(S)):
    if i % 2 == 1:
        if S[i] == '0':
            count2 += 1
    else:
        if S[i] == '1':
            count2 += 1

print(min(count1, count2))

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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    set<string> s2(s.begin(), s.end());
    cout << s2.size() << endl;
    return 0;
}

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

int main () {

    int A, B, C;
    cin >> A >> B >> C;

    if (A < B && A < C && C < B) {
        cout << "Yes" << endl;
    } else if (B < A && B < C && C < A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
BIN = [0] * 32

v = 1
for i in range(24, 0, -1):
    BIN[i] = v
    v *= 2
v = float(1) / 2
for i in range(25, 32):
    BIN[i] = v
    v /= 2

Q = int(input())

for i in range(Q):
    inp = format(int(input(),16),'b').zfill(32)
    res = float(0)
    for j, v in enumerate(list(inp)[1:]):
        #print(str(BIN[j]) + ' ' + v + ' '  + str(float(v) * BIN[j]))
        res += BIN[j+1] * int(v)

    print(('-' if inp[0] == '1' else '') + str(res))

Measured memory_bytes: 6748
#include<cstdio>
const int maxn = 100010;
int luck[maxn] = {0};
int main(){
    int n;
    int countluck = 0;
    int countunluck = 0;
    int counttwo = 0;
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&luck[i]);
        if(luck[i] % 4 == 0){
            countluck++;
        }else if(luck[i] % 2 == 0){
            counttwo++;
        }else{
            countunluck++;
        }
    }
    if(counttwo == 0){
        if(countunluck - 1 > countluck){
            printf("No\n");
        }else{
            printf("Yes\n");

        }
    }
    else if (counttwo > 0){
        if(countunluck  > countluck){
            printf("No\n");

        }else{
            printf("Yes\n");

        }
    }


    return 0;
}


Measured memory_bytes: 512
/**
 * Author: Behradm
 * Created: 04-04-2020 17:32:57
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout.precision(6);
	cout << fixed;
	ll n, k;
	cin >> n >> k;
	if(n <= k){
		if(n >= k/2)
			cout << k-n << '\n';
		else
			cout << n << '\n';
		return 0;
	}
	
	ll res = 0;
	if(k <= n/2){
		res = n-((n/k)*k);
		while(true){
			if(abs(res-k) > res) //abs(res-k) > res
				break;
			res = abs(res-k);
		}
	} else{
		res = abs(n-(((n/k)+1)*k));
		while(true){
			if(abs(res-k) > res)
				break;
			res = abs(res-k);
		}
	}


	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define int        long long
# define all(vc)   vc.begin(),vc.end()
# define all2(vc)  vc.rbegin(),vc.rend()
# define pb        push_back
# define fi        first
# define se        second
# define speed     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
 
using namespace std;

void solve(){
    int n = 0, k = 0;
    cin >> n >> k;
    vector <int> ar(k), v;
    int  mn = 1e9, sum = 0;
    for (int i = 0; i < k; ++i){
        cin >> ar[i];
        if( i ){
             v.pb( ar[i] - ar[i - 1] );
             sum += ar[i] - ar[i - 1];
        }
    }
    sort(all2(v));
    if( v[0] <= (n - ar[ k - 1 ]) + ar[0] ) cout << sum;
    else{
         sum -= v[0];
         cout << sum + ( (n - ar[ k - 1 ]) + ar[0] );
    }

}

int32_t main(){
    speed;
    cout<<fixed<<setprecision(0);
    int t = 1;
    //cin >> t;
    while( t-- ){
         solve();
         cout<<'\n';
    }

    time;
}



Measured memory_bytes: 4980
package main

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

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (n, k int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc), scanInt(sc)
}

func resolve(n, k int) int {
	l, h := n/k, (n+(k/2))/k
	rL := l * l * l
	rH := h * h * h
	if k%2 == 0 {
		return rL + rH //- l - h
	}
	return rL // - l
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
struct sa{
    int A;
    int B;
    int C;
};
int solve(sa *a,int n){
   int dp[n+1][3];
     dp[0][0]=a[0].A;
    dp[0][1]=a[0].B;
    dp[0][2]=a[0].C;
    for(int i=1;i<n;i++){
        dp[i][0]=a[i].A+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i].B+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i].C+max(dp[i-1][1],dp[i-1][0]);
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main(){
    int n;
    cin>>n;
    sa a[n];
    for(int i=0;i<n;i++){
        cin>>a[i].A;
        cin>>a[i].B;
        cin>>a[i].C;
        
    }
    cout<<solve(a,n);
}

Measured memory_bytes: 2560
#include<algorithm>
#include<iostream>
#include<vector>

bool used[10000];
std::vector<int> primes;

void sieve()
{
	used[0] = used[1] = true;
	for( int i = 2; i <= 10000; ++i )
	{
		if( !used[i] )
		{
			primes.push_back( i );

			for( int j = i; j <= 10000; j += i )
				used[j] = true;
		}
	}

	return;
}

int main()
{
	sieve();

	int n;
	while( std::cin >> n, n )
	{
		int i = std::upper_bound( primes.begin(), primes.end(), n ) - primes.begin() - 1;
		while( i > 0 && primes[i] - primes[i-1] != 2 )
			--i;

		std::cout << primes[i-1] << ' ' << primes[i] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<long long> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(),a.end(),greater<long long>());
    long long ans = 0;
    for(int i=1; i<n; i++){
        ans += a[(i/2)];
    }
    cout<<ans<<endl;
}

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

typedef long long ll;

const int N = 1e5;
const ll MOD = 1000000007;

int n;
int li[N+5];
int a[4];

int main(){
	scanf("%d",&n);
	ll ans = 1;
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
		ll mult = 0;
		for(int j=0;j<3;j++){
			if(li[i] == a[j]){
				mult++;
			}
		}
		ans = (ans*mult)%MOD;
		for(int j=0;j<3;j++){
			if(li[i] == a[j]){
				a[j]++;
				break;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

int main(void)
{
    int n,k;
    cin >> n>>k;
    int sum = 0;
    int cnt = 0;
    while (n - 1 > sum)
    {
        sum += k - 1;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
k=int(input())
for _ in range(k):
  if a<b<c:
    print('Yes')
    exit()
  elif a>=b:
    b=b*2
  else:
    c=c*2
if a<b<c:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 61664
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc141_c
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            int n = input[0];
            int k = input[1];
            int q = input[2];

            List<int> seikai_num = new List<int>();
            for (int index = 0; index < n; index++)
            {
                seikai_num.Add(0);
            }


            for (int index = 0; index < q; index++)
            {
                int seikaisya_index = int.Parse(Console.ReadLine()) - 1;

                seikai_num[seikaisya_index]++;
            }

            string res = "";
            for (int index = 0; index < n; index++)
            {


                if (k - q + seikai_num[index] > 0)
                {
                    res = "Yes";
                }
                else
                {
                    res = "No";
                }

                Console.WriteLine(res);
            }

        }
    }
}


Measured memory_bytes: 16604
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define endl "\n"
    #define MOD 1000000007
    #define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
    #define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
    //    for(auto& it : m)
    void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
    ll int power(ll int x, ll int y, ll int p)  
    {  
       ll int res = 1;     // Initialize result  
     
        x = x % p; // Update x if it is more than or  
                    // equal to p
       
        if (x == 0) return 0; // In case x is divisible by p;
     
        while (y > 0)  
        {  
            // If y is odd, multiply x with result  
            if (y & 1)  
                res = (res*x) % p;  
     
            // y must be even now  
            y = y>>1; // y = y/2  
            x = (x*x) % p;  
        }  
        return res;  
    }  
     
    ll int modInverse(ll int a,ll int m)
    {
        ll int g = __gcd(a, m);
       
            // If a and m are relatively prime, then modulo inverse
            // is a^(m-2) mode m
           
           return      power(a, m-2, m);
       
    }
     
     
    int main()
    {
     
      fastio();
     
    ll int T=1;
   // cin>>T;
     
    for(ll int test=1;test<=T;test++)
    {
         ll int a,b,c,k;
         cin>>a>>b>>c>>k;
         while(b<=a&&k){b*=2;k--;}
         while(c<=b&&k){c*=2;k--;}
         if(b>a&&c>b)
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    
    }
     
     
     
    return 0;}

Measured memory_bytes: 3608
local function uf_initialize(n)
  local parent = {}
  for i = 1, n do parent[i] = i end
  return parent
end

local function uf_findroot(idx, parent)
  local idx_update = idx
  while parent[idx] ~= idx do
    idx = parent[idx]
  end
  while parent[idx_update] ~= idx do
    parent[idx_update], idx_update = idx, parent[idx_update]
  end
  return idx
end

local n, m = io.read("*n", "*n")
local lang = {}
for i = 1, m do
  lang[i] = {}
end
for i = 1, n do
  local k = io.read("*n")
  for j = 1, k do
    local l = io.read("*n")
    table.insert(lang[l], i)
  end
end

local parent = uf_initialize(n)
for i = 1, m do
  if 0 < #lang[i] then
    local r = uf_findroot(lang[i][1], parent)
    for j = 2, #lang[i] do
      local tgt = lang[i][j]
      local tr = uf_findroot(tgt, parent)
      parent[tr], parent[tgt] = r, r
    end
  end
end
local cand = uf_findroot(1, parent)
for i = 2, n do
  local z = uf_findroot(i, parent)
  if z ~= cand then print("NO") os.exit() end
end
print("YES")


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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long blue = 0;
  long long r = N/(A+B)*A;
  long long p = min(N%(A+B),A);
  cout << r+p << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int place = sc.nextInt();
		Integer point[] = new Integer[place];
		for(int i = 0; i < place; i ++) {
			point[i] = sc.nextInt();
		}
		Arrays.sort(point, Collections.reverseOrder());
		long diff[] = new long[place - 1];
		for(int i = 0; i < place - 1; i ++) {
			diff[i] = point[i] - point[i + 1];
		}
		long sum = 0;
		Arrays.sort(diff);
		if(num < place) {
			for(int i = 0; i < place - num; i ++) {
				sum += diff[i];
			}
		}
		System.out.println(sum);
	}
}

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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)

 
int main() 
{ 
	JJ;
    char ch; cin>>ch;
    if(ch>='A'&& ch<='Z')
    	cout<<"A"<<endl;
    else
    	cout<<"a"<<endl;
    
} 

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int x, y;
  cin >> x >> y;
  cout << (x+y/2) << endl;
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>a(N-1),b(N-1);
  for(int i=0;i<N-1;i++)cin>>a[i]>>b[i];
  for(int i=0;i<N-1;i++)a[i]--,b[i]--;
  vector<vector<int>>e(N);
  for(int i=0;i<N-1;i++){
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }
  vector<int>B(N,-1),W(N,-1);

  queue<pii>bq;
  bq.push({0,0});
  while(bq.size()){
    int now=bq.front().first;
    int num=bq.front().second;
    bq.pop();
    B[now]=num;
    for(auto it:e[now]){
      if(B[it]==-1)bq.push({it,num+1});
    }
  }

  queue<pii>wq;
  wq.push({N-1,0});
  while(wq.size()){
    int now=wq.front().first;
    int num=wq.front().second;
    wq.pop();
    W[now]=num;
    for(auto it:e[now]){
      if(W[it]==-1)wq.push({it,num+1});
    }
  }

  int sw=0;
  int sb=0;
  for(int i=1;i<N-1;i++){
    if(W[i]<B[i])sw++;
    else sb++;
  }

  if(sb>sw)cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
  return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef struct edge{
  int from, to; long cost;
  edge(int f, int t, long c){
    from = f; to = t; cost = c;
  }
}edge;
typedef struct node{
  int id; long xc, yc;
  node(int i, long x, long y){
    id = i; xc = x; yc = y;
  }
}node;

int main(){
  int n; cin >> n;
  vector<node> p(n, node(-1, -1, -1));
  rep(i, n){
    long x, y; cin >> x >> y;
    p[i] = node(i, x, y);
  }
  vector<edge> e[n];
  sort(p.begin(), p.end(), [](const node &a, const node &b){return a.xc < b.xc;});
  rep(i, n-1){
    e[p[i].id].push_back(edge(p[i].id, p[i+1].id, p[i+1].xc-p[i].xc));
    e[p[i+1].id].push_back(edge(p[i+1].id, p[i].id, p[i+1].xc-p[i].xc));
  }
  sort(p.begin(), p.end(), [](const node &a, const node &b){return a.yc < b.yc;});
  rep(i, n-1){
    e[p[i].id].push_back(edge(p[i].id, p[i+1].id, p[i+1].yc-p[i].yc));
    e[p[i+1].id].push_back(edge(p[i+1].id, p[i].id, p[i+1].yc-p[i].yc));
  }
  vector<bool> used(n, false);
  long ans = 0;
  auto c = [](const edge &a, const edge &b){return a.cost > b.cost;};
  priority_queue<edge, vector<edge>, decltype(c)> que(c);
  used[0] = true;
  rep(i, e[0].size()) que.push(e[0][i]);
  while(!que.empty()){
    edge t = que.top(); que.pop();
    if(used[t.to]) continue;
    used[t.to] = true;
    rep(i, e[t.to].size()) que.push(e[t.to][i]);
    ans += t.cost;
  }
  cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> teki(N+1);
    vector<int> taoseru(N);

    for(int i=0; i<N+1; i++){
        cin >> teki[i];
    }
    for(int i=0; i<N; i++){
        cin >> taoseru[i];
    }

    long long int ans = 0;

    for(int i=0; i<N; i++){
        if(taoseru[i]>=teki[i]){
            ans += teki[i];
            ans += min(teki[i+1], taoseru[i]-teki[i]);
            teki[i+1] = teki[i+1] - min(teki[i+1], taoseru[i]-teki[i]);
            teki[i] = 0;
        }
        else{
            ans += taoseru[i];
            teki[i] -= taoseru[i];
        }
    }

    cout << ans << endl;
}


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

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

bool XOR(bool a, bool b){ return (a + b) % 2; }

int main() {
  // 小数点以下10桁まで
  // cout << fixed << setprecision(10);

  int N;
  std::cin >> N;
  std::vector<int> A(N);
  vector<vector<int>> x(N, vector<int>(N));
  vector<vector<int>> y(N, vector<int>(N));
  for (size_t i = 0; i < N; i++) {
    std::cin >> A.at(i);
    for (size_t j = 0; j < A.at(i); j++) {
      std::cin >> x.at(i).at(j) >> y.at(i).at(j);
      x.at(i).at(j) -= 1;
    }
  }

  int maximum = 0;
  // {0, 1, ..., N-1} の部分集合の全探索
  // 1が正直者、0が不親切な人
  for (size_t bit = 0; bit < (1<<N); bit++) {
    bool alright = true;
    int honest = 0;
    for (size_t i = 0; i < N; i++) {
      if (bit & 1<<i) {
        honest += 1;
        for (size_t j = 0; j < A.at(i); j++) {
          if (XOR(bit & 1<<x.at(i).at(j), y.at(i).at(j) == 1)) alright = false;
        }
      }
    }
    if (alright) maximum = max(maximum, honest);
  }

  cout << maximum << endl;
}


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

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

	int m = min(a,b);
	int cnt = 0;
	for(int i = m; i >= 1; i--){
		if(a%i==0 && b%i==0) cnt++;
		if(cnt==k){
			cout<<i;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(b==1) cout<<0;
    else if(b<=a) cout<<1;
    else
    {
        int i=2;
        while(i*(a-1)+1<b) i++;
        cout<<i;
    }
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
struct suffix_array {
	struct entry {
		pair<int, int> nr;
		int p;
		bool operator<(const entry &other) const {
			return nr < other.nr;
		}
	};
	string s;
	int n;
	vector<vector<int> > P;
	vector<entry> L;
	vector<int> idx;
	suffix_array(string _s) :s(_s), n(s.size()) {
		L = vector<entry>(n);
		P.push_back(vector<int>(n));
		idx = vector<int>(n+1);
		for (int i = 0; i < n; i++) {
			P[0][i] = s[i];
		}
		for (int stp = 1, cnt = 1; (cnt >> 1) < n; stp++, cnt <<= 1) {
			P.push_back(vector<int>(n));
			for (int i = 0; i < n; i++) {
				L[i].p = i;
				L[i].nr = make_pair(P[stp - 1][i], i + cnt < n ? P[stp - 1][i + cnt] : -1);
			}
			sort(L.begin(), L.end());
			for (int i = 0; i < n; i++) {
				if (i > 0 && L[i].nr == L[i - 1].nr) {
					P[stp][L[i].p] = P[stp][L[i - 1].p];
				}
				else {
					P[stp][L[i].p] = i;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			idx[P[P.size() - 1][i]] = i;
		}
		idx[n] = n;
	}
	int lower_bound(string &T) {
		int l = -1, r = n;
		while (r - l > 1) {
			int m = (l + r) / 2;
			string tmp = "";
			for (int i = 0; i < T.size(); i++) {
				if (idx[m] + i >= n) break;
				tmp.push_back(s[idx[m] + i]);
			}
			if (tmp >= T) {
				r = m;
			}
			else {
				l = m;
			}
		}
		return r;
	}
	int upper_bound(string &T) {
		int l = -1, r = n;
		while (r - l>1) {
			int m = (l + r) / 2;
			string tmp = "";
			for (int i = 0; i < T.size(); i++) {
				if (idx[m] + i >= n) break;
				tmp.push_back(s[idx[m] + i]);
			}
			if (tmp>T) {
				r = m;
			}
			else {
				l = m;
			}
		}
		return r;
	}
};
int main() {
	string S, T;
	cin >> S >> T;
	suffix_array sa(S);
	int l = sa.lower_bound(T);
	int r = sa.upper_bound(T);
	vector<int> ans;
	for (int i = l; i < r; i++) {
		ans.push_back(sa.idx[i]);
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3304
import java.util.*;

class Main{

    int n, w, d;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            w = sc.nextInt();
            d = sc.nextInt();
            if(n==0 && w==0 && d==0) break;

            //x, y, w, h
            ArrayList<int[]> q = new ArrayList<int[]>();
            q.add(new int[]{0,0,w,d});

            for(int i=0; i<n; i++){
                int p = sc.nextInt()-1;
                int s = sc.nextInt();

                int[] qq = q.get(p);
                q.remove(p);
                int x = qq[0], y = qq[1], W = qq[2], H = qq[3];
                s = s%((W+1)*2+(H-1)*2);

                int nx = x, ny = y;
                
                while(nx+1<=x+W && s-1>=0){nx++; s--;}
                while(ny+1<=y+H && s-1>=0){ny++; s--;}
                while(nx-1>=x && s-1>=0){nx--; s--;}
                while(ny-1>=y && s-1>=0){ny--; s--;}

                if(nx==x || nx==x+W){
                    int ny1 = ny-y, ny2 = H+y-ny;
                    int[] n1 = {x, y, W, ny1};
                    int[] n2 = {x, ny, W, ny2};
                    if(ny1<ny2){
                        q.add(n1); q.add(n2);
                    }else{
                        q.add(n2); q.add(n1);
                    }
                }else{
                    int nx1 = nx-x, nx2 = W+x-nx;
                    int[] n1 = {x, y, nx1, H};
                    int[] n2 = {nx, y, nx2, H};
                    if(nx1<nx2){
                        q.add(n1); q.add(n2);
                    }else{
                        q.add(n2); q.add(n1);
                    }
                }
            }

            PriorityQueue<Integer> ans = new PriorityQueue<Integer>(10, new Comparator<Integer>(){
                    public int compare(Integer a, Integer b){
                        return (int)(a-b);
                    }
                });

            for(int i=0; i<q.size(); i++){
                int[] qq = q.get(i);
                ans.add(new Integer(qq[2] * qq[3]));
            }

            while(ans.size()>1) System.out.print(ans.poll()+" ");
            if(ans.size()==1) System.out.println(ans.poll());
            else System.out.println();
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 39444
import math
sosu = 10 ** 9 + 7
N, K = map(int, input().split())
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def conv(n, r):
    bunbo = math.factorial(n) % sosu
    bunsi1 = mod_inv(math.factorial(r), sosu)
    bunsi2 = mod_inv(math.factorial(n-r), sosu)
    ans = bunbo * bunsi1 * bunsi2 % sosu
    return(ans)
#print(conv(1997,2))

for i in range(1, K+1):
    if N-K+1 >= i:
        fir = conv(K-1, i-1)
        sec = conv(N-K+1, i)
        ans = fir * sec % sosu
        print(int(ans))
    else:
        print(0)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  if (n == 1) cout << abs(w - a[0]) << endl;
  else cout << max(abs(w - a[n - 1]), abs(a[n - 2] - a[n - 1])) << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int paper[10][10],i,j,size,max=0,w=0;

	for(i=0;i<10;i++)
		for(j=0;j<10;j++)
			paper[i][j]=0;
	
	while(scanf("%d,%d,%d",&i,&j,&size)!=EOF){
			paper[i][j]+=1;
			if(i+1<10)
			paper[i+1][j]+=1;
			if(i-1>=0)
			paper[i-1][j]+=1;
			if(j+1<10)
			paper[i][j+1]+=1;
			if(j-1>=0)
			paper[i][j-1]+=1;
			if(size>1)//サイズが2以上の時に追加
			{
			  if(i+1<10 && j+1<10)
				paper[i+1][j+1]+=1;
			  if(i+1<10 && j-1>=0)
				paper[i+1][j-1]+=1;
			  if(i-1>=0 && j+1<10)
				paper[i-1][j+1]+=1;
			  if(i-1>=0 && j-1>=0)
				paper[i-1][j-1]+=1;
			}
			if(size==3)//サイズが3の時に追加
			{
				if(i+2<10)  
				    paper[i+2][j]+=1;
			    if(i-2>=0)
					paper[i-2][j]+=1;
				if(j+2<10)
					paper[i][j+2]+=1;
				if(j-2>=0)
					paper[i][j-2]+=1;
			}
	}

	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(paper[i][j]==0)
				w++;
			if(paper[i][j]>max)
				max=paper[i][j];
		}
	}
	printf("%d\n",w);
	printf("%d\n",max);
	return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

int main(){

    ll n, k; cin >> n >> k;
    ll r, s, p; cin >> r >> s >> p;
    string t; cin >> t;

    vector<vector<char>> tt(k);
    rep(i, t.size()){
        tt[i%k].push_back(t[i]);
    }

    map<char, ll> cnt;
    map<char, char> win;
    win['r'] = 'p';
    win['s'] = 'r';
    win['p'] = 's';

    char old;
    rep(i, tt.size()){
        rep(j, tt[i].size()){
            if(j==0){
                cnt[win[tt[i][j]]]++;
                old = win[tt[i][j]];
            }
            else{
                if(win[tt[i][j]] != old){
                    cnt[win[tt[i][j]]]++;
                    old = win[tt[i][j]];
                }
                else{
                    old = 'x';
                }
            }
        }
    }

    cout << cnt['r']*r + cnt['s']*s + cnt['p']*p << endl;

    return 0;
}

Measured memory_bytes: 8232
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
C = Counter(D)
ans = 0
if C[0] != 1 or D[0] != 0:
    print(ans)
else:
    for i, n in C.items():
        if i == 0:
            ans = 1
            continue
        ans *= pow(C[i-1], n, MOD)
        ans %= MOD
    print(ans)


Measured memory_bytes: 19928
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    string s;
    char l;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        int x=s[i]-'A';
        x=(x+n)%26;
        l='A'+x;
        cout<<l;

    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005
using namespace std;

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

int n,k,h[MAXN],dp[MAXN];

// dp[i] = i. tasa minimum kac maliyetle gliriz.

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> h[i];

	dp[1] = 0;
	for (int i = 2; i <= n; i++)
	{
		dp[i] = inf;
		for (int j = 1; j <= k; j++) {
			if(i-j <= 0) break;
				dp[i] = min(dp[i],abs(h[i]-h[i-j]) + dp[i-j]);
		}
		// cout << i << " " << dp[i] << endl;
	}

	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
signed main(){
  int a;
  cin>>a;
  string b;
  cin>>b;
  vector<bool> k(1000,0);
  rep(i,1000){
  int c=i/100;
  int d=i/10-c*10;
  int e=i%10;
    bool f=0,g=0,h=0;
    rep(j,a){
      if(g&&b[j]-48==e){
        k[i]=1;
        }
    if(f&&b[j]-48==d)
      g=1;
      if(b[j]-48==c)
      f=1;
    }
  }
  int ans=0;
  rep(i,1000){
  if(k[i]==1)
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
use proconio::input;
use std::cmp;

// 購入と売却は交互
// 次に購入するなら0、売却するなら1
//
// 購入するときは0株しか持っていない
// 購入するときは金額を最大化する
// 売却するときは株数を最大にする？

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    // (金額, 株数)
    let mut dp = vec![vec![(0i64, 0i64); n + 5]; 2];
    dp[0][0] = (1000, 0);
    for i in 1..=n {
        dp[0][i] = dp[0][i - 1];
        dp[1][i] = dp[1][i - 1];

        // 購入する
        let (money, kabu) = dp[0][i - 1];
        if kabu + money / a[i - 1] > dp[1][i].1 {
            dp[1][i] = (money % a[i - 1], kabu + money / a[i - 1]);
        } else if kabu + money / a[i - 1] == dp[1][i].1 {
            if money % a[i - 1] > dp[1][i].0 {
                dp[1][i] = (money % a[i - 1], kabu + money / a[i - 1]);
            }
        }
        // 売却する
        let (money, kabu) = dp[1][i - 1];
        if money + kabu * a[i - 1] > dp[0][i].0 {
            dp[0][i] = (money + kabu * a[i - 1], 0);
        }
    }

    // dbg!(&dp);

    let ans = dp[0][n].0;
    println!("{}", ans);
}


Measured memory_bytes: 2196
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *r, *l, *p;

};

Node *root, *NIL;

Node * find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->l;
    else u = u->r;
  }
  return u;
}

void insert(int k){
  Node *x = root,*y = NIL, *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }
    else{
      x = x->r;
    }
  }

  z->p = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->l = z;
    }
    else{
      y->r = z;
    }
  }
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->key);
  inorder(u->r);
}

void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  int n, i, x;
  string com;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    cin >> com;
    if(com[0] == 'f'){
      scanf("%d", &x);
      Node *t = find(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    }
    else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 22076