akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int k, cnt = 0; sc(k);
    queue<ll> que;
    rep(i, 1, 10) que.push(i);

    ll x;
    while (cnt != k){
        x = que.front(); que.pop();
        if (x % 10 != 0) que.push(10*x + x%10 -1);
        que.push(10*x + x%10);
        if (x % 10 != 9) que.push(10*x + x%10 + 1);
        cnt++;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 5236
def main(argv)
  a = gets.chomp.to_i
  b = gets.chomp.to_i

  puts '1' unless [a, b].include?(1)
  puts '2' unless [a, b].include?(2)
  puts '3' unless [a, b].include?(3)
end

if self.to_s == 'main' then
  main(ARGV)
end

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll i, j, k;
int main(){
    scanf("%lld", &N);
    j = N;
    while(j!=0){
        i += j % 10;
        j /= 10;
    }
    if(N%i==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ans := 0
	for i := 1; i <= n; i++ {
		for j := i; j <= n; j += i {
			ans += j
		}
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 1792
### https://atcoder.jp/contests/dp/tasks/dp_c
N = int(input())
Max_List = [[0] * 3 for i in range(N)]
for i in range(N):
    Current_List = list(map(int,input().split()))  
    if i == 0:
        Max_List[i] = Current_List
    else:
        Search_List = Max_List[i-1]
        for j in range(3):
            Current_Search_List = Search_List[1:3]
            Max_List[i][j] = max(Current_Search_List) + Current_List[j]
            Search_List.append(Search_List[0])
            del Search_List[0]
        

        
print(max(Max_List[-1]))

Measured memory_bytes: 32080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,a[100010];
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	if(n==1){
		cout << "Yes";
		return 0;
	}
	for(ll i=n-2;i>=0;i--){
		if(a[i]>a[i+1]+1){
			cout <<"No";
			return 0;
		}
		if(a[i]==a[i+1]+1){
			a[i]--;
		}
	}
	cout <<"Yes";
	// your code goes here
	return 0;
}

Measured memory_bytes: 1024
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int long long
#define setout(n,x) setw(n) << setfill(x)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d[i];
    }
    sort(all(d));
    int cnt = 1;
    rep(i,n-1){
        cnt += (d[i] < d[i+1]);
    }
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret, p = [], 2

    while p*p <= n:
        if n % p != 0:
            p += 1
            continue

        exp_v = 0
        while n%p == 0:
            exp_v += 1
            n //= p
        ret.append( [ret, exp_v] )

        p += 1

    if n != 1: ret.append( [n, 1] )

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print(len(prime_factor(g)) + 1)


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

using namespace std;
long long  p,n,m,z;
long long  t[1000],a[1000],b[1000],c[100000],d[100000],f[3][100000];
int main()
{
	p=1000000007;
    cin>>n>>m;
    t[0]=1;
    for (int i=1;i<=105;i++) t[i]=(t[i-1]*2)%p;
    for (int i=1;i<=m;i++)
      {
      	  cin>>a[i]>>b[i];	  
	  }
   for (int j=1;j<=m;j++)
	for (int i=1;i<=t[n]-1;i++)
	{
	  if ((1&i>>a[j]-1)&& (1&i>>b[j]-1)) c[i]++;
	  if ((1&i>>a[j]-1)|| (1&i>>b[j]-1)) d[i]++;
	}
   for (int i=1;i<=2;i++)
     for (int j=0;j<=t[n]-1;j++)
     {
      if (!(j&i)) continue;
      f[i][j]=t[c[j]];
      for (int k=j;k>=1;k=(k-1)&j)
      {
        f[i][j]=(f[i][j]+p-f[i][j-k]*t[c[k]])%p;
	  }
	 }
  for (int i=0;i<=t[n]-1;i++)                                                                                                                                                                                                                                  
    for (int j=0;j<=t[n]-1;j++)
    {
	 if ((i&j)!=0 || c[i]+c[j]!=c[i|j]) continue;
	 z=(z+(f[1][i]*f[2][j])%p*t[m-d[i|j]]) % p;
	}	 
	cout<<(t[m]-z+p)%p<<endl; 
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct FT {
	vector<ll> s;
	FT(int n) : s(n) {}
	void update(int pos, ll dif) { // a[pos] += dif
		for (; pos < sz(s); pos |= pos + 1) s[pos] += dif;
	}
	ll query(int pos) { // sum of values in [0, pos)
		ll res = 0;
		for (; pos > 0; pos &= pos - 1) res += s[pos-1];
		return res;
	}
	int lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum
		// Returns n if no sum is >= sum, or -1 if empty sum is.
		if (sum <= 0) return -1;
		int pos = 0;
		for (int pw = 1 << 25; pw; pw >>= 1) {
			if (pos + pw <= sz(s) && s[pos + pw-1] < sum)
				pos += pw, sum -= s[pos-1];
		}
		return pos;
	}
};


struct node {
	int val;
	node *l, *r;
};

node* build(int lx, int rx, vector<int>& p){
	node* v = new node();
	if(lx == rx){
		v->l = v->r = nullptr;
		v->val = p[lx];
	} else {
		v->l = build(lx, (lx + rx) / 2, p);
		v->r = build((lx + rx) / 2 + 1, rx, p);
		v->val = min(v->l->val, v->r->val);
	}
	return v;
}

const int M = 1e8;

int query_min(node* v, int lx, int rx, int qlx, int qrx){
	if(qlx > rx || lx > qrx) return M;
	if(qlx <= lx && rx <= qrx){
		return v->val;
	} else {
		return min(query_min(v->l, lx, (lx + rx) / 2, qlx, qrx),
				query_min(v->r, (lx + rx) / 2 + 1, rx, qlx, qrx));
	}
}

// kill at index

void kill(node* v, int lx, int rx, int kx, int val){
	if(kx < lx || rx < kx) return;
	if(lx == rx){
		v->val = M;
	} else {
		kill(v->l, lx, (lx + rx) / 2, kx, val);
		kill(v->r, (lx + rx) / 2 + 1, rx, kx, val);
		v->val = min(v->l->val, v->r->val);
	}
}

vector<int> a, p;
int n;
int k;

vector<int> res;

node* segtree;
void solve(int lx, int rx, int d){
	int v = query_min(segtree, 0, n-1, lx, rx);
	if(v > d + k) return;
	// assert(d == M || v > d);
	if(v == M) return;
	int idx = a[v];
	// assert(lx <= idx && idx <= rx);
	solve(lx, idx-1, v);
	res.push_back(v);
	kill(segtree, 0, n-1, idx, v);
	solve(lx, rx, d);
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	cin >> k;
	a.resize(n), p.resize(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i]--;
		p[a[i]] = i;
	}
	k--;
	segtree = build(0, n-1, p);
	solve(0, n-1, M);

	vector<int> ans(n);
	for(int i = 0; i < n; i++) ans[res[i]] = i;
	for(int i = 0; i < n; i++){
		cout << ans[i] + 1 << '\n';
	}
}

Measured memory_bytes: 73968
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    string s;
    cin >> s;
    vi sa = suffix_array(s);
    vi la = lcp_array(s,sa);
    ll n = s.size();
    ll sum=n*(n+1)/2;
    for(auto i:la){
        sum-=i;
    }
    print(sum);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 15696
#include <stdio.h>

int main( void ) {

	int month, day, days, nodiem[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, i;

	while ( scanf( "%d %d", &month, &day ) && month != 0 && day != 0 ) {
				
		days = 0;

		for ( i = 0; i < month - 1; i++ ) { days += nodiem[i]; }
		days += day;

		switch ( days % 7 ) {

			case 0: printf( "Wednesday\n" ); break;
			case 1: printf( "Thursday\n" ); break;
			case 2: printf( "Friday\n" ); break;
			case 3: printf( "Saturday\n" ); break;
			case 4: printf( "Sunday\n" ); break;
			case 5: printf( "Monday\n" ); break;
			case 6: printf( "Tuesday\n" ); break;

		}

	}

	return 0;

}

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

int main(){
	int n;
	cin >> n;
	bool res = true;
	rep(i, n){
		int a;
		cin >> a;
		if(a%2 == 0){
			if(a%3 != 0 && a%5 != 0) res = false;
		}
	}

	if(res) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;

	return 0;
}


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

using namespace std;


int main()
{
	int n,m; cin >> n >> m;
	int h[n];
	for(int i = 0; i < n; i++) cin >> h[i];
	vector<int> adj[n];
	for(int i = 0; i < m; i++){
		int x,y; cin >> x >> y;
		adj[--x].push_back(--y);
		adj[y].push_back(x);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(adj[i].size() == 0){ ans++; continue;}
		bool good = true;
		for(int e : adj[i]){
			good &= h[i] > h[e];	
		}
		if(good) ans++;
	}
	cout << ans;
}


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

using namespace std;

#define F first
#define S second
#define MAX_N 1e5+10

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vbl;

int main() {
  //freopen ("input.in", "r", stdin);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0 ; i < n ; i++) {
    cin >> a[i];
  }

  bool dp[k+1]; dp[0] = 0;

  for (int c = 1 ; c <= k ; c++) {
    bool v = 0;
    for (int i = 0 ; i < n ; i++) {
      if (c-a[i] >= 0) {
        if (dp[c-a[i]] == 0) v = 1;
      }
    }
    dp[c] = v;
  }

  if (dp[k]) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4104
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    string in,out;
    cin >> in;
    if(in == "Sunny") out =  "Cloudy";
    else if(in == "Cloudy") out = "Rainy";
    else out = "Sunny";
    cout << out << endl;
    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  rep(i,9){
    rep(j,9){
      cout << i+1<<"x"<<j+1 <<"="<<(i+1)*(j+1)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3012
import java.util.Scanner;

public class Main {

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

    int[] ans=new int[N];
    int cnt =1;
    for (int i = 0; i < N; i++) {
      int num = sc.nextInt();
      ans[num-1] = cnt++;
    }

    for (int i = 0; i < N; i++) {
      System.out.println(ans[i]);
    }


  }


}


Measured memory_bytes: 58880
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;

int main()
{

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

	ll n, k; cin >> n >> k;
	cout << min(n % k, k - (n % k)) << endl;
	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std; 
int n,k,x,y;
    long long ans=0;
int main(){
   
    cin>>n>>k>>x>>y;
    for(int i=1;i<=n;++i){
        if(i<=k){
            ans+=x; 
        }                  
        if(i>k){
            ans+=y;
        }
    }
    cout<<ans<<endl;  
    return 0;
}

Measured memory_bytes: 256
import sys
import decimal

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W, N = rl()
start = rl()
S = list(rs())
T = list(rs())
bool = True

# 上下左右で場合分け
cur = start[0]
for i in range(N):
    if S[i] == 'U':
        cur -= 1
    if cur == 0:
        bool = False
        break
    if T[i] == 'D' and cur < H:
        cur += 1
    
cur = start[0]
for i in range(N):

    if S[i] == 'D':
        cur += 1
    if cur == H+1:
        bool = False
        break
    if T[i] == 'U' and cur > 1:
        cur -= 1
    
cur = start[1]
for i in range(N):
    if S[i] == 'R':
        cur += 1
    if cur == W+1:
        bool = False
        break
    if T[i] == 'L' and cur > 1:
        cur -= 1    

cur = start[1]
for i in range(N):
    if S[i] == 'L':
        cur -= 1
    if cur == 0:
        bool = False
        break
    if T[i] == 'R' and cur < W:
        cur += 1

print('YES' if bool else 'NO')        

Measured memory_bytes: 8784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
ll n;cin >> n;
ll p[n];rep(i,n)cin>> p[i];
ll tem = 10000000,count=0;
for(int i=0;i<n;i++){
    tem=min(tem,p[i]);
    if(p[i]<=tem)count++;
}
cout << count << endl;
    return 0;
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int n,a[N*3],ct[N*3];
long long sum[N*3],mx[N*3],mn[N*3];
vector<int> v;

void update(int pos){
	for (int i=pos+1;i<N*3;i+=(i&-i)){
		ct[i]++;
		sum[i]+=v[pos];
	}
}

int queryCt(int pos){
	if (!pos){
		return 0;
	}
	int ret=0;
	for (int i=pos;i;i-=(i&-i)){
		ret+=ct[i];
	}
	return ret;
}

long long querySum(int pos){
	if (!pos){
		return 0;
	}
	long long ret=0;
	for (int i=pos;i;i-=(i&-i)){
		ret+=sum[i];
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=1;i<=n*3;i++){
		cin >> a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for (int i=1;i<=n*3;i++){
		int idx=lower_bound(v.begin(),v.end(),a[i])-v.begin();
		update(idx);
		if (i>=n){
			int l=1,r=v.size(),now=-1;
			while (l<=r){
				int mid=(l+r)>>1;
				if (i-queryCt(mid-1)>=n){
					now=mid;
					l=mid+1;
				}else{
					r=mid-1;
				}
			}
			assert (now!=-1);
			mx[i]=querySum(v.size())-querySum(now)+
			1ll*(n-(i-queryCt(now)))*v[now-1];
		}
	}
	memset(ct,0,sizeof(ct));
	memset(sum,0,sizeof(sum));
	for (int i=n*3;i;i--){
		int idx=lower_bound(v.begin(),v.end(),a[i])-v.begin();
		update(idx);
		if (n*3-i+1>=n){
			int l=1,r=v.size(),now=-1;
			while (l<=r){
				int mid=(l+r)>>1;
				if (queryCt(mid)>=n){
					now=mid;
					r=mid-1;
				}else{
					l=mid+1;
				}
			}
			assert (now!=-1);
			mn[i]=querySum(now-1)+
			1ll*(n-queryCt(now-1))*v[now-1];
		}
	}
	long long ans=LLONG_MIN;
	for (int i=n;n*3-i>=n;i++){
		ans=max(ans,mx[i]-mn[i+1]);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 10480
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  int n, q;  cin >> n >> q;
  fenwick_tree<long long> ft(n);
  for (int i = 0; i < n; ++i){
    int ai; cin >> ai;
    ft.add(i, ai);
  }
  while (q--){
    int tp; cin >> tp;
    if(tp==0){
      int i, x; cin >> i >> x;
      ft.add(i, x);
    } else {
      int l, r; cin >> l >> r;
      cout << ft.sum(l,r) << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 8228
//Name: Equal Sum Sets
//Level: 2
//Category: 数論,分割数,探索,メモ化,Memoize
//Note:

/**
 * 「n以下の数をk個使ってsを作る場合の数」を返す関数を考えると、状態数は NKS 個で抑えられる。
 * したがって、メモ化再帰の形で書き下せばよい。
 *
 * オーダーは O(N^2KS)。
 */
#include <iostream>
#include <array>

using namespace std;

int memo[21][11][156];
int dfs(int n, int k, int s) {
    if(s < 0) return 0;
    if(k == 0 && s == 0) return 1;
    if(n == 0) return 0;
    if(memo[n][k][s] != -1) return memo[n][k][s];
    memo[n][k][s] = 0;
    for(int i = n; i >= 1; --i) {
        memo[n][k][s] += dfs(i-1, k-1, s-i);
    }
    return memo[n][k][s];
}

bool solve() {
    int N, K, S;
    if(!(cin >> N >> K >> S)) return false;
    if(!N && !K && !S) return false;

    cout << dfs(N, K, S) << endl;
    return true;
}

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

    for (int n = 0; n < 21; n++) {
        for (int k = 0; k < 11; k++) {
            for (int s = 0; s < 156; s++) {
                memo[n][k][s] = -1;
            }
        }
    }
    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1332
import java.util.*;
public class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String [] args){
    int e;
    while(true){
      e = sc.nextInt();
      if(e == 0)break;
      System.out.println(solve(e));
    }
  }
  static int solve(int e){
    double x,y,z,res;
    int ans = e;
    double m;
    double Cz;
    for(z = 0; Math.pow(z, 3) <= e ;z++){
      Cz = Math.pow(z,3);
      for(y = 0; Math.pow(y, 2) <= e - Cz; y++){
        x = e - (Cz + Math.pow(y, 2));
        m = x + y + z;
        ans = Math.min(ans, (int)m);
      }
    }
    return ans;
  }
}

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

/*-------------------------- HRIDOY ROY -------------------------*/

#define     fRead           freopen("input.txt","r",stdin)
#define     fWrite          freopen("output.txt","w",stdout)

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     PLL             pair<lld,lld>
#define     MAX             100000000000014
#define     MIN             -100000000000014

#define     pi2             2.0*acos(0.0)


int main()
{
    int n,m;
    cin>>n>>m;

    for(int i = 0 ; i < m ;i++){
        int x;
        cin>>x;
        n-=x;
    }

    if(n < 0) printf("-1\n");
    else printf("%d\n",n);
}



Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
  string A;
  cin>>A;
  if(A.at(0)=='1'){A.at(0)='9';}
  else{A.at(0)='1';}
  if(A.at(1)=='1'){A.at(1)='9';}
  else{A.at(1)='1';}
  if(A.at(2)=='1'){A.at(2)='9';}
  else{A.at(2)='1';}
  cout<<A<<endl;
}


Measured memory_bytes: 3620
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans
import math
def main():
    temp=input().split(" ")
    n=(temp[0])
    a=(temp[1])
    temp=n+a
    temp=int(temp)
    ans1=math.sqrt(temp)
    ans1=math.floor(ans1)
    ans2=temp/math.sqrt(temp)
    if ans1==ans2:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main 
{ 
    public static void main(String[] args)
    {
       Scanner sc = new Scanner(System.in);  
       int n,m,l;
       n = sc.nextInt();
       m = sc.nextInt();
       l = sc.nextInt();
       long [] [] A = new long [n][m];
       long [] [] B = new long [m][l];
       for(int i=0; i<n; i++)  //input
       {
           for (int j = 0; j<m; j++)
           {
               A[i][j] = sc.nextLong();
           }
       }
        for(int i=0; i<m; i++)  //input
       {
           for (int j = 0; j<l; j++)
           {
               B[i][j] = sc.nextLong();
           }
       }
        
        for(int i=0; i<n; i++) //multiplying
        {
            for(int j = 0; j< l; j++)
            {
                long sum = 0;
                for(int k = 0; k< m;k++)
                {
                   sum = sum + A[i][k] * B[k][j];
                }
                if(j!=l-1)
                    {
                        System.out.print(sum + " ");
                    }
                else System.out.println(sum);
            
            }
        }
    }
}



Measured memory_bytes: 53428
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,a,b;
  map<int,int> mp;
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> a >> b;
    mp[a]++,mp[b]++;
  }
  for(auto p:mp) {
    if(p.second%2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 4352
#include<stdio.h>

int markForInt(char c){
	int n;
	if(c == 'S'){
		n = 0;
	}else if(c == 'H'){
		n = 1;
	}else if(c == 'C'){
		n = 2;
	}else if(c == 'D'){
		n = 3;
	}
	return n;
}
char intForMark(int n){
	char c;
	if(n == 0){
		c = 'S';
	}else if(n == 1){
		c = 'H';
	}else if(n == 2){
		c = 'C';
	}else if(n == 3){
		c = 'D';
	}
	return c;

}

int main()
{
	int n;
	int cards[4][13];
	int i, j;
		
	scanf("%d", &n);
	for(i = 0; i < 4; ++i){
		for(j = 0; j < 13; ++j){
			cards[i][j] = 0;
		}
	}
	
	for(i = 0; i < n; ++i){
		char mark;
		int num;
		scanf(" %c %d", &mark, &num);
		cards[markForInt(mark)][num - 1] = 1;
	}
	
	for(i = 0; i < 4; ++i){
		for(j = 0; j < 13; ++j){
			if(cards[i][j] == 0)printf("%c %d\n", intForMark(i), j + 1);
		}
	}

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n;
    cin>>n;
    vector<vector<int>> primes(int(1e6)+5);
    vector<bool> is_prime(int(1e6)+5,true);
    is_prime[0]=is_prime[1]=false;
    for(int i=0;i<is_prime.size();i++){
        if(is_prime[i]){
            primes[i].pb(i);
            for(int j=2;1ll*j*i<primes.size();j++){
                primes[j*i].pb(i);
            }
        }
    }
    vector<int> cnt(int(1e6)+5,0);
    int ans=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        ans=__gcd(ans,x);
        if(x>1){
            for(auto y:primes[x]) cnt[y]++;
        }
    }
    bool flag=true;
    vector<int> collect_primes;
    for(int i=2;i<primes.size();i++)
        if(cnt[i]>0){
            flag=(flag&&cnt[i]<2);
            collect_primes.pb(i);
        }
    if(flag){
        cout<<"pairwise coprime\n";
        return;
    }
    if(ans==1) cout<<"setwise coprime\n";
    else cout<<"not coprime\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 121852
#include <bits/stdc++.h>
using namespace std;
int main(){
  string res;
  int n,a,b,c,d;
  cin >> n;
  a = n / 1000;
  b = n % 1000 / 100;
  c = n % 1000 % 100 / 10;
  d = n % 1000 % 100 % 10;
  if(a == b && b == c){
    res = "Yes";
  }else{
    if(b == c && c == d){
      res = "Yes";
    }else{
      res = "No";
    }
  }
  cout << res << endl;
}

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

int main() {
  string S;
  cin >> S;
  char s3, s4, s5, s6;
/*  
  s3 = S[3];
  s4 = S[4];
  s5 = S[5];
  s6 = S[6];
  cout << s3 << s4 << s5 << s6 << endl;
  */
  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define all(x) x.begin(),x.end()
using namespace std;
vector<int>v;
int a[15], n;
int f() {
	int r = 0;
	for1(i, n) { r *= 10; r += a[i]; }
	return r;
}
void print(int p) {
	int x = 1;
	for0(i, n - 1)x *= 10;
	for0(i, n) {
		if (i)cout << ' ';
		cout << p / x; p %= x; x /= 10;
	}
	return;
}
signed main() {
	cin >> n;
	for1(i, n)a[i] = i;
	v.push_back(-1);
	do {
		v.push_back(f());
	} while (next_permutation(a + 1, a + n + 1));
	for1(i, n)cin >> a[i];
	int p = f();
	auto itr = lower_bound(all(v), p);
	itr--;
	if (*itr != -1) { print(*itr); cout << endl; }
	itr++;
	print(*itr); cout << endl;
	itr++;
	if (itr != v.end()) { print(*itr); cout << endl; }
}


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

int main(){
    long long N,Y;
    long long result=0;
    cin >> N >> Y;
    for(int a=0;a<=2000;a++){
        for(int b=0;b<=2000;b++){
            if(N-a-b<0){
                continue;
            }
            int c=N-a-b;
            result=10000*a+5000*b+1000*c;
            if(result==Y){
                cout << a << " " << b << " " << c << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct Node;
typedef Node* Node_ptr;
struct Node
{
  int key;
  Node_ptr prev, next;
  
  Node(int key_=-1, Node_ptr prev_=NULL, Node_ptr next_=NULL)
    : key(key_), prev(prev_), next(next_) {}
};


class LinkedList
{
private:
  
  Node_ptr head, tail;
  
public:
  
  LinkedList()
  {
    head = new Node();
    tail = new Node();
    head->next = tail; tail->prev = head;
  }
  
  ~LinkedList()
  {
    Node_ptr d = head->next;
    for(Node_ptr iter = head->next->next; iter!=tail; iter=iter->next) {
      delete d;
      d = iter;
    }
    delete d;
    delete head; delete tail;
  }
  
  bool empty()
  {
    return head->next == tail;
  }
  
  void insert(int x)
  {
    Node_ptr nd = new Node(x, head, head->next);
    nd->next->prev = nd;
    head->next = nd;
  }
  
  void erase(int x)
  {
    Node_ptr tprev, tnext;
    bool deleted = false;
    for(Node_ptr iter = head->next; iter!=tail; iter=iter->next) {
      if(iter->key == x) {
        tprev = iter->prev, tnext = iter->next;
        delete iter;
        deleted = true;
        break;
      }
    }
    if(!deleted) return;
    tprev->next = tnext;
    tnext->prev = tprev;
  }
  
  void erase_first()
  {
    if(empty()) return;
    Node_ptr tnext = head->next->next;
    delete head->next;
    head->next = tnext;
    tnext->prev = head;
  }
  
  void erase_last()
  {
    if(empty()) return;
    Node_ptr tprev = tail->prev->prev;
    delete tail->prev;
    tprev->next = tail;
    tail->prev = tprev;
  }
  
  void print()
  {
    for(Node_ptr iter = head->next; iter != tail; iter=iter->next) {
      if(iter!=head->next) cout << " ";
      cout << iter->key;
    }
    cout << endl;
  }

  
};

int main() {
  
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int Q_num; cin >> Q_num;
  LinkedList list;
  for(int q=0; q<Q_num; q++) {
    string s; cin >> s;
    if(s == "deleteFirst") list.erase_first();
    else if(s == "deleteLast") list.erase_last();
    else {
      int x; cin >> x;
      if(s == "insert") list.insert(x);
      if(s == "delete") list.erase(x);
    }
  }
  
  list.print();
  
  return 0;
}

Measured memory_bytes: 32480
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>

using namespace std;

struct Edge {
	int to, cost;
};
struct Node {
	int n, tf;
	double cost;
};
bool operator >(const Node& n1, const Node& n2) {
	return n1.cost > n2.cost;
}

#define INF 1e9
#define EPS 1e-12

int main() {
	int N, M, p, a, b;
	while ( cin >> N >> M >> p >> a >> b, N || M || p || a || b ) {
		--a, --b;

		vector<int> t(N);
		for (int i = 0; i < N; ++i) {
			cin >> t[i];
		}

		vector< vector<Edge> > edges(M);
		for (int i = 0; i < p; ++i) {
			int x, y, c; cin >> x >> y >> c; --x, --y;
			edges[x].push_back( (Edge){y, c} );
			edges[y].push_back( (Edge){x, c} );
		}

		bool gone[30][1 << 8] = {0};

		double ans = INF;
		priority_queue<Node, vector<Node>, greater<Node> > Q; Q.push( (Node){a, 0, 0} );
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			int n = node.n, tf = node.tf;
			double cost = node.cost;

			if (gone[n][tf]) continue;
			gone[n][tf] = true;

			if (n == b) {
				ans = min(ans, cost);
				continue;
			}

			for (int i = 0; i < edges[n].size(); ++i) {
				Edge& e = edges[n][i];
				for (int j = 0; j < N; ++j) {
					if ( (tf & (1 << j)) == 0 ) {
						Q.push( (Node){ e.to, (tf | (1 << j)), cost+(double)e.cost/t[j] });
					}
				}
			}
		}
		if (ans >= INF - EPS) {
			cout << "Impossible" << endl;
		}
		else {
			printf("%.10f\n", ans);
		}
	}
}

Measured memory_bytes: 18392
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[] 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 = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    auto D = aryread();
    long s;
    foreach (i; 0 .. N)
        foreach (j; i + 1 .. N)
        {
            s += D[i] * D[j];
        }
    writeln(s);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<pair<int,int>> p(N);
  vector<ll> h(N);
  rep(i,N){
    cin >> p[i].first >> p[i].second >> h[i];
  }
  rep(cx,101){
    rep(cy,101){
      ll H = -1;
      ll max_H = 1e10;
      rep(i,N){
        if(h[i]==0){
          ll max_H_ = abs(p[i].first - cx) + abs(p[i].second - cy);
          max_H = min(max_H, max_H_);
          if(H != -1 && max_H < H) break;
        }
        else{
          ll H_ = h[i] + abs(p[i].first - cx) + abs(p[i].second - cy);
          if(H == -1) H = H_;
          if(H != H_) break;
        }
        if(H != -1 && max_H < H) break;
        if(i == N-1)cout << cx << " " << cy << " " << H << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int r[100][100];
string s[100100];

int main(){
    ios::sync_with_stdio(0);
    int n;
    int n1;
    cin>>n;
    n1= n;
    string s;
    for(int i=0 ; i<n ; i++){
        cin>>s;
        for(int j=0 ; j<s.length() ; j++){
            r[i][s[j]-'a']++;
        }
    }
    string res="";
        for(int i=0 ; i<26 ; i++){
            int mn = 1e9;
            for(int j=0 ; j<n ; j++){
                mn = min(mn,r[j][i]);
            }
            while(mn--)
                res.push_back(i+'a');
        }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e3+10;
const int M=2e4+10;
int n;ll dp[N][M],ans;
struct node{int w,s,v;bool operator <(const node&e)const{return (w+s)<(e.w+e.s)||(w+s==e.w+e.s&&v>e.v);}}k[N];
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
		scanf("%d%d%d",&k[i].w,&k[i].s,&k[i].v);
	sort(k+1,k+n+1);
	for(register int i=1;i<=n;i++){
		for(register int j=0;j<=k[i-1].s+k[i-1].w;j++)
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
		for(register int j=0;j<=min(k[i].s,k[i-1].s+k[i-1].w);j++)
			dp[i][j+k[i].w]=max(dp[i][j+k[i].w],dp[i-1][j]+k[i].v);
	}
	for(register int i=1;i<=n;i++)
		for(register int j=0;j<=k[i].s+k[i].w;j++)
			ans=max(ans,dp[i][j]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 157568
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        mut s: Chars,
    }

    if *s.last().unwrap() == 's' {
        s.push('e');
        s.push('s');
    } else {
        s.push('s')
    }

    println!("{}", s.iter().join(""));
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2136
#include<iostream>
using namespace std;
int main(){
	int x, y, w = 0;
	cin >> x >> y;
	for (int i = 0; i <= x; i++) {
		if (i * 2 + (x - i) * 4 == y) {
			cout << "Yes" << endl;
		}
		else {
			w++;
		}
	}
	if (w == x + 1) {
		cout << "No" << endl;
	}
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
//const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;
int main()
{
    string s;
    cin >> s;
    if(s[s.size()-1] == 's'){
        s = s + "es";
    }else{
        s = s + "s";
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
// typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int N, K, R, S, P;
string T;

char win_hand(char);
int score_hand(char);

int main() {

    cin >> N >> K >> R >> S >> P >> T;
    // modKのグループに分ける
    vector<vector<char>> mod_groups(K, vector<char>(0));
    rep(i, N) { mod_groups[i % K].pb(T[i]); }
    int score = 0;
    rep(i, K) {
        // dp(i): i番目で出す最善の手
        char dp[mod_groups[i].size()];
        rep(j, mod_groups[i].size()) {
            if (dp[j - 1] != win_hand(mod_groups[i][j])) {
                dp[j] = win_hand(mod_groups[i][j]);
                score += score_hand(dp[j]);
            } else {
                dp[j] = 'n';
            }
        }
    }
    cout << score;
    return 0;
}

char win_hand(char opponent_hand) {
    switch (opponent_hand) {
    case 'r':
        return 'p';
    case 's':
        return 'r';
    case 'p':
        return 's';
    }
}

int score_hand(char hand) {
    switch (hand) {
    case 'r':
        return R;
    case 's':
        return S;
    case 'p':
        return P;
    }
}

Measured memory_bytes: 5120
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A<=9&&A>=1&&B<=9&&B>=1) {
				System.out.println(A*B);
		}else {
			System.out.println("-1");
		}
	}
}

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

static const int N=100;
static const int INF=(1<<21);

int n,g[N][N];
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++) d[i]=INF;
    d[s]=0;
    int u;
    while(!q.empty()) {
        u=q.front();q.pop();
        for(int v=0;v<n;v++) {
            if(g[u][v]==0) continue;
            if (d[v] != INF) continue;
            d[v]=d[u]+1;
            q.push(v); 
        }
    }
    for(int i=0;i<n;i++) {
        cout<<i+1<<" "<<((d[i]==INF) ? (-1) : d[i] )<<endl;
    }
}

int main(void) {
    int u,v,k;
    cin>>n;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) g[i][j]=0;
    }
    for(int i=0;i<n;i++) {
            cin>>u>>k;
            u--;
        for(int j=0;j<k;j++) {
            int v;cin>>v;
            v--;
            g[u][v]=1;
        }
    }
    bfs(0);
    return 0;
}

Measured memory_bytes: 3136
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
 
#define div1 1000000007
 
using namespace std;
 
int main(void)
{
    long long K, X;

    cin >> K >> X;

    if(500 * K >= X){
	cout << "Yes" << endl;
    }
    else{
	cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll N, A;
    scanf("%lld %lld", &N, &A);
    printf(((N%500)<=A)?"Yes\n":"No\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
int main() {
  int n,d,ans=0;
  cin>>n>>d;
  vector<vector<int>> x(n+1,vector<int>(d+1));
  repi(i,1,n+1) repi(j,1,d+1) cin>>x[i][j];
  
  repi(i,1,n){
    repi(j,i+1,n+1){
      int diff=0;
      repi(k,1,d+1){
        diff+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      for(int k=1;k*k<=diff;k++){
        if(k*k==diff) ans++;
      }
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
def main():
        
    import numpy as np

    N = int(input())
    numbers = list(map(int, input().split()))

    np_numbers = np.array(numbers, np.int64)

    module = 10 ** 9 + 7

    cumsum = np.cumsum(np_numbers)
    cumsum.tolist()
    summ = cumsum[-1]
    ans = 0

    for i in range(N):
        tmp = (summ - cumsum[i]) % module
        ans += ((np_numbers[i] % module) * tmp) % module
        
        ans %= module
        
        
        

    ans %= module

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49796
#include<cstdio>
 
using namespace std;
 
int main(){
int a, b;
 
scanf("%d%d", &a, &b);
 
if(a == 1){
printf("1");
}else if(a > b){
a = a - 1;
printf("%d", a);
}else{
printf("%d", a);
}
 
return 0;
}

Measured memory_bytes: 128