akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<string, int> mp;
#define ll long long

int main() {
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    int a = h * w;
    int b = x + y;
    if (a % 2 == 1 && b % 2 == 1) {
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3088
using System;

class Class01
{
    public static void Main(string[] args)
    {
        while (true)
        {
            int a, b;
            string s = Console.ReadLine();
            if (s == null) break;
            string[] ss = s.Split();
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            if (a < b)
            {
                int c = a;
                a = b;
                b = c;
            }

            int gc = gcd(a, b);
            Console.WriteLine("{0} {1}", gc, lcm(a, b, gc));
        }
    }

    public static int gcd(int a, int b)
    {
        while (true)
        {
            if ((a % b) == 0) return b;
            int c = a;
            a = b;
            b = c % b;
        }
    }

    public static int lcm(int a, int b, int gc)
    {
        return (a / gc) * (b / gc) * gc;
    }
}

Measured memory_bytes: 9128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

struct Edge
{
	int src, dst;
	int weight;
	Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) {}

	bool operator< (const Edge& e)const
	{
		return weight != e.weight ? weight > e.weight :
			src != e.src ? src < e.src : dst < e.dst;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void Dijkstra(const Graph& g, int s, vi& dist, vi& prev)
{
	int n = g.size();
	dist.assign(n, INT_MAX);
	dist[s] = 0;
	prev.assign(n, -1);
	
	priority_queue<Edge> Q;
	Q.push(Edge(-2, s, 0));

	while(!Q.empty()){
		Edge e = Q.top();
		Q.pop();
		if(prev[e.dst] != -1)
			continue;
		prev[e.dst] = e.src;

		rep(i, g[e.dst].size()){
			int pw = e.weight + g[e.dst][i].weight;
			if(dist[g[e.dst][i].dst] > pw){
				dist[g[e.dst][i].dst] = pw;
				Q.push(Edge(g[e.dst][i].src, g[e.dst][i].dst, pw));
			}
		}
	}
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	
	Graph g(n);
	rep(i, m){
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		--a; --b;
		g[a].push_back(Edge(a, b, c));
		g[b].push_back(Edge(b, a, d));
	}
	
	int x1, x2, y1, y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	--x1; --x2;
	
	vi dist, prev;
	Dijkstra(g, x1, dist, prev);
	int cost = dist[x2];
	Dijkstra(g, x2, dist, prev);
	cost += dist[x1];
	
	printf("%d\n", y1-y2-cost);
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int main(void)
{
	ll n,s,a,b,k;
	scanf("%lld",&n);
	s=MAX(1,n/4);
	FOR(a,s,3501){
		FOR(b,s,3501){
			k=4*a*b-n*a-n*b;
			if(k>=1&&(n*a*b)%k==0){
				printf("%lld %lld %lld\n",a,b,(n*a*b)/k);
				return 0;
			}
		}
	}
	return 0;
}
    

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

int main() {
    string s; cin >> s;
    for (int d = (s.size()-1)/2; d >= 1; d--) {
        bool valid = true;
        for (int i = 0; i < d; i++) {
            valid &= s[i] == s[d+i];
        }
        if (valid) {
            cout << d*2 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n,m;
  cin>>n>>m;
  map<int,int> modulo[m];
  vector<int> cnt(m,0);
  int x;
  REP(i,n){
    cin>>x;
    modulo[x%m][x]++;
    cnt[x%m]++;
  }
  int ans=0;
  int d;
  if(m%2==0){
    d = m/2-1;
    ans += cnt[m/2]/2;
  }else{
    d = (m-1)/2;
  }
  int diff;
  for(int i=0;i<=d;i++){
    if(i==0){
      ans += cnt[0]/2;
    }else{
      if(cnt[i]>=cnt[m-i]){
        diff = cnt[i]-cnt[m-i];
        for(auto p:modulo[i]){
          if(diff<2)break;
          if(p.second>=diff){
            ans += diff/2;
            break;
          }else{
            if(p.second%2==0){
              diff -= p.second;
            }else{
              diff -= ((p.second-1)/2)*2;
            }
            ans += p.second/2;
          }
        }
        ans += cnt[m-i];
      }else{
        diff = cnt[m-i]-cnt[i];
        for(auto p:modulo[m-i]){
          if(diff<2)break;
          if(p.second>=diff){
            ans += diff/2;
            break;
          }else{
            if(p.second%2==0){
              diff -= p.second;
            }else{
              diff -= ((p.second-1)/2)*2;
            }
            ans += p.second/2;
          }
        }
        ans += cnt[i];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9984
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			String st[]=in.next().split(",");
			int a[]=new int[st.length];
			int n=0;
			for(int i=0;i<5;i++)
				a[i]=Integer.valueOf(st[i]);
			for(int i=0;i<4;i++)
				for(int j=i+1;j<5;j++)
					if(a[i]==a[j])
						n++;
			Arrays.sort(a);
			switch(n)
			{
			case 1:
				System.out.println("one pair");
				break;
			case 2:
				System.out.println("two pair");
				break;
			case 3:
				System.out.println("three card");
				break;
			case 4:
				System.out.println("full house");
				break;
			case 6:
				System.out.println("four card");
				break;
			default:
				if(straight(a))
					System.out.println("straight");
				else
					System.out.println("null");
			}
		}
	}
	public static boolean straight(int a[])
	{
		if(a[0]+1==a[1]&&a[1]+1==a[2]&&a[2]+1==a[3]&&a[3]+1==a[4])
			return true;
		else if(a[0]==1&&a[1]==10&&a[2]==11&&a[3]==12&&a[4]==13)
			return true;
		else
			return false;
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<map>
using namespace std;
int main(){
    map<int,int>v;
    int a,b,c;
    cin>>a>>b>>c;
    v[a]++;
    v[b]++;
    v[c]++;
    if(v[5]==2&&v[7]==1){
        cout<<"YES"<<endl;
    }
    else
    cout<<"NO";
}

Measured memory_bytes: 3592
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))

right = [0 for _ in range(N + 1)]
left = [0 for _ in range(N + 1)]

for i, a in enumerate(A):
    for j, b in enumerate(A):
        if i < j and a > b:
            right[i] += 1
        elif i > j and a > b:
            left[i] += 1

res = 0

for i, (r, l) in enumerate(zip(right, left)):
    res = (res + K * (K + 1) // 2 * r) % MOD
    res = (res + (K - 1) * K // 2 * l) % MOD

print(res)


Measured memory_bytes: 3188
function main(input) {
    var result = 0;
    const args = input.split("");
    const len = args.length;
    for (i = 0; i < len; i++) {
        if (args[i] == 1) {
            var result = result+1;
        }
    }
    console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#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; }
using namespace std;


int main(){
  ll N,ans=1,mx=0;
  cin>>N;
  
  vector<ll> P;
  REP(i,N){
    ll a;
    cin>>a;
    if(i==0 && a>0){
      co(0);
      return 0;
    }
    if(i>0 && a==0){
      co(0);
      return 0;
    }
    P.push_back(a);
    mx=max(mx,a);
  }
  
  SORT(P);
  
  
  
  ll A[2000000];
  REP(i,2000000) A[i]=0;
  
  for(ll i=0; i<P.size(); ++i){
    A[P.at(i)]++;
  }
  
  
  
  for(ll i=1; i<=mx; ++i){
    if(A[i]==0){
      co(0);
      return 0;
    }
    for(ll j=0; j<A[i]; ++j){
      ans=ans*A[i-1]%998244353;
    }
  }
  
  co(ans);
}

Measured memory_bytes: 16756
n=int(input())
a=[int(i) for i in input().split()]

l=[0]
def ruiseki(a):
    for i in range(len(a)):
        l.append(l[i]+a[i])

ruiseki(a)

import collections
cl=collections.Counter(l)


def c(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))
ans=0
for i in set(l):
    ans+=c(int(cl[i]),2)

print(ans)

Measured memory_bytes: 47604
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string();  
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
   lli n;
    cin>>n;
    lli a[n];
    for(lli i=0;i<n;i++)cin>>a[i];
    lli ans=0;
	for(lli i=1;i<n-1;i++){
		if(a[i]>min(a[i-1],a[i+1]) && a[i]<max(a[i-1],a[i+1]))ans++;
	}
	cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
signed main(){
  vector<int> A{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin >> k;
  k--;
  cout << A[k] << endl;
  return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
a_1 = list(map(int, input().split()))
a_2 = [0] * (n+1)
for i in a_1:
    a_2[i] = 1
a, b = a_2[:x].count(1), a_2[x:].count(1)
print(min([a, b]))

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d ;
  int migi = a + b;
  int hidari = c + d;
  if (migi > hidari) {
    cout << "Left" << endl;
  }else if(migi == hidari){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,H,W;
    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W + 1) << endl;
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

dist=abs(a-b)
diff_sp=(v-w)
if diff_sp <= 0:
  if dist == 0:
    print("YES")
  else:
    print("NO")
else:
  if diff_sp*t >= dist:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {

    private static Scanner sc;

    public Main() {
    }

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

    int[] nums = new int[4];

    private void solve() {
        String N = sc.next();
        for (int i = 0; i < 4; i++) {
            nums[i] = Character.getNumericValue(N.charAt(i));
        }
        calc(nums[0], 0, String.valueOf(nums[0]));
    }
    boolean flg = false;
    void calc(int sum, int idx, String f) {
        if (flg) {
            return;
        }
        if (idx == 3) {
            if (sum == 7) {
                System.out.println(f + "=7");
                flg = true;
            }
            return;
        }

        calc(sum + nums[idx + 1], idx + 1, f + "+" + nums[idx + 1]);
        calc(sum - nums[idx + 1], idx + 1, f + "-" + nums[idx + 1]);
    }
}


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

using namespace std;

int main (void) {
    int A, B, C;
    cin >> A >> B >> C;

    int ans = 0;

    /* 3つの数の偶奇をそろえる */
    int a = A % 2;
    int b = B % 2;
    int c = C % 2;
    if ( a != b && a != c ) {
        B++;
        C++;
        ans++;
    }
    else if ( b != a && b != c ) {
        A++;
        C++;
        ans++;
    }
    else if ( c != a && c != b ) {
        A++;
        B++;
        ans++;
    }

    /* 一番大きい値にそろえる */
    int m = max(A, max(B, C));
    while ( A < m ) {
        A += 2;
        ans++;
    }
    while ( B < m ) {
        B += 2;
        ans++;
    }
    while ( C < m ) {
        C += 2;
        ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	print((n+1)/2)
	return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n); for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  ll N,K;cin>>N>>K;vl a(N);
  rep(i,N){
    cin>>a[i];
  }
  vl b(N);
  
  vl d(N);d[0]=a[0];
  rep(i,N-1){
    d[i+1]=max(d[i],a[i+1]);
  }
  ll ans=100000000000;
  for(int tmp ; tmp<(1<<N-1);tmp++){
    bitset<14> s(tmp);
    ll cnt=0;
    b =d;
    if(s.count()>=K-1){
      for(int i=0;i<N-1;i++){
        b[i+1]=max(b[i],b[i+1]);
        if(s.test(i)){
          if(b[i]>a[i+1]){
            cnt+=b[i]-a[i+1]+1;
            b[i+1] =b[i]+1;
          }
          else if(b[i]<a[i+1]){
            b[i+1]=a[i+1];
          }
          else if(b[i]==a[i+1]){
            cnt+=1;
            b[i+1]=b[i]+1;
          }
        }
      }
      ans =min(cnt,ans);
    }
    else continue;
  }
  cout<<ans<<endl;
}


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

signed main(){
  int N;
  cin>>N;
  std::vector<int> x(N),y(N),h(N);
  for(int i=0;i<N;i++)cin>>x[i]>>y[i]>>h[i];
  int H,X,Y;
  int ans=0;
  int out=0;
  int fin=0;
  int Hmin;
  for(int i=0;i<=100&&fin==0;i++){
    for(int j=0;j<=100&&fin==0;j++){
      out=0;
      //cout<<i<<" "<<j<<endl;
      H=0;
      Hmin=1e18;
      for(int k=0;k<N&&out==0&&fin==0;k++){
        if(h[k]){
          if(H==0)H=h[k]+abs(i-x[k])+abs(j-y[k]);
          else if(H!=h[k]+abs(i-x[k])+abs(j-y[k]))out++;
        }
        else{
          Hmin=min(abs(i-x[k])+abs(j-y[k]),Hmin);
        }
        if(out==0&&k==N-1&&H<=Hmin){
          ans=H;
          X=i;
          Y=j;
          fin++;
        }
      }
    }
  }

  cout<<X<<" "<<Y<<" "<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a1, a2, a3;
	scanf ("%d", &a1);
	scanf ("%d", &a2);
	scanf ("%d", &a3);
	
	int tot;
	tot = a1 + a2 + a3;
	if (tot >= 22){
		printf ("bust\n");
	}
	else
	printf ("win\n");
	
	return 0;
}

Measured memory_bytes: 2028
from math import sqrt
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

N = int(input())

def solv_quadratic_equation(a, b, c):
    D2 = b**2 - 4*a*c
    if D2<0:
        return 0.1, 0.1
    D = sqrt(D2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2

for n in range(1,N+1):
    ans=0
    if n < 6:
        print(0)
        continue
    for x in range(1,int(sqrt(n-3))+1):
        for y in range(1,int(sqrt(n-3))+1):
            z1,z2=solv_quadratic_equation(1,x+y, x**2+y**2+x*y-n)
            if z1.is_integer() and z1>=1:
                ans+=1
            if z2.is_integer() and z2>=1:
                ans+=1

    print(ans)

Measured memory_bytes: 70356
eval"N,K,*A,D=#{`tr ' 
' ,`}(0..255).map{[0]*101}"
D[0][0]=1
A.map{|a|N.times{|j|256.times{D[_1^a][i=N-j]+=D[_1][i-1]*i}}}
p D[K].sum.%10**9+7

Measured memory_bytes: 21344
#include<bits/stdc++.h>
using namespace std;
double a[15][15];
int main(){
	std::ios::sync_with_stdio(false);
	int n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++)
		for(int j=0;j<d;j++)
			cin>>a[i][j];
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			double s=0;
			for(int k=0;k<d;k++){
				s+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			s=sqrt(s);
			if(fabs(int(s)-s)==0)
				ans++;
		}
	}
	cout<<ans<<"\n";
}

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



int main(){
  string a;
  cin >> a;
  if( a <= "2019/04/30" ){cout << "Heisei" << endl;}
  else{cout << "TBD" << endl;}
}

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

#define fi  first
#define se  second
#define mp  make_pair
#define pb  push_back
#define ll  long long
#define mod 1000000007
#define pii pair<int, int>
#define pie 2.0*acos(0.0)

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

    pii arr[n]; int time[n];
    for (int i = 0; i < n; i++) cin >> time[i] >> arr[i].fi >> arr[i].se;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            if (arr[i].fi == 0 && arr[i].se == 0) {
                if (time[i] % 2) {
                    cout << "No" << endl;
                    return 0;
                } else continue;
            }

            int x = abs(0 - arr[i].fi), y = abs(0 - arr[i].se);
            if (x + y > time[i]) {
                cout << "No" << endl;
                return 0;
            }
            else {
                int fuck = time[i] - (x + y);
                if (fuck % 2) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
        else {
            int d = abs(time[i] - time[i - 1]);
            if (arr[i - 1].fi == arr[i].fi && arr[i - 1].se == arr[i].se) {
                if (d % 2) {
                    cout << "No" << endl;
                    return 0;
                } else continue;
            }

            int x = abs(arr[i - 1].fi - arr[i].fi);
            int y = abs(arr[i - 1].se - arr[i].se);
            if (x + y > d) {
                cout << "No" << endl;
                return 0;
            }
            else {
                int fuck = d - (x + y);
                if (fuck % 2) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
n=int(input())
A=list(map(int,input().split()))+[1000001]
A.sort()
m,ans=max(A)+1,0
li=[0 for _ in range(m)]
li[0]=1

for i in range(n):
  a=A[i]
  if not li[a]:
    if A[i+1] != a:
      ans += 1
    for i in range(a,m,a):
      li[i] = 1

print(ans)

Measured memory_bytes: 32248
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int M;
	int X, sum = 0, con = 0, ans = 0;
	vector<int> d, c;
	
	cin>>M;
	
	
	d.resize(M);
	c.resize(M);
	
	for(int i = 0; i < M; i++){
		cin>>d[i]>>c[i];
		sum += d[i] * c[i];
		con += c[i];
	}
	
	ans = con-1;
	
	
	cout<<ans+(sum-1)/9<<endl; //これでACできるってマジ？？！！
	
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    if(n % 2) {
        cout << "No" << endl;
        return 0;
    }
    rep(i,n/2){
        if(s[i] != s[i + (n/2)]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	long double w, h, x, y;
	int k = 0;
	cin >> w >> h >> x >> y;
	long double S = h / 2.0 * w;
	if (h / 2 == y && w / 2 == x)k = 1;

	cout << fixed << setprecision(12) << S;
	cout << " " << k << endl;
	return 0;
}



Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int l[220],n,i,ans=0;
	cin >> n;
	n*=2;
	for(i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l,l+n);
	for(i=0; i<n; i+=2){
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>

struct dice {
	int f[6];
} ;

void change(struct dice *p, char c)
{
	int temp = p->f[0];
	if (c == 'N') {
		p->f[0] = p->f[1];
		p->f[1] = p->f[5];
		p->f[5] = p->f[4];
		p->f[4] = temp;
	}
	else if (c == 'E') {
		p->f[0] = p->f[3];
		p->f[3] = p->f[5];
		p->f[5] = p->f[2];
		p->f[2] = temp;
	}
	else if (c == 'S') {
		p->f[0] = p->f[4];
		p->f[4] = p->f[5];
		p->f[5] = p->f[1];
		p->f[1] = temp;
	}
	else if (c == 'W') {
		p->f[0] = p->f[2];
		p->f[2] = p->f[5];
		p->f[5] = p->f[3];
		p->f[3] = temp;
	}
}

int main()
{
	int i;

	struct dice s;
	char str[100];

	for (i = 0; i < 6; i++)
		scanf("%d", &s.f[i]);
	scanf("%s", str);
	
	for (i = 0; i < strlen(str); i++) {
		change(&s, str[i]);
	}
	printf("%d\n", s.f[0]);


	return 0;
}


Measured memory_bytes: 596
from itertools import combinations

# from scipy.special import comb
import sys

n = int(input())
march = ["M", "A", "R", "C", "H"]
num_mar = {}
# num_mar = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
s = []
for i in range(n):
    t = input()
    if t[0] not in march:
        continue
    s.append(t)
    if t[0] not in num_mar.keys():
        num_mar[t[0]] = 1
    else:
        num_mar[t[0]] += 1

# print(num_mar, s)

len_num_mar = len(num_mar.keys())
# print(len_num_mar)


if len_num_mar < 3:
    print(0)
    sys.exit()

# first_pick = comb(len_num_mar, 3, exact=True)
# ans = first_pick
ans = 0

for keys in combinations(num_mar.keys(), 3):
    res = 1
    for k in keys:
        res *= num_mar[k]
    ans += res


# for k in num_mar.keys():
#     ans *= num_mar[k]
print(ans)


Measured memory_bytes: 9780
//define DEBUG for debug
//#define DEBUG

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair 
#define pb push_back
#define MAX 100000+100
#define MOD 1000000007
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef DEBUG
	freopen("i.txt","r",stdin);
	freopen("o.txt","w",stdout);
#endif
	
	string a,b;cin >> a >> b;
	cout << b << a;

	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if (i*500 + j*100 + k*50) == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060
import java.util.*;
public class Main{
 public static void main (String[ ]args){
 Scanner scan=new Scanner(System.in) ;
 int a=scan.nextInt();
 int b=scan.nextInt();
 int c=scan.nextInt();
 if(a==7&&b==5&&c==5){System.out.println("YES");}
 else if(a==5&&b==7&&c==5){System.out.println("YES");}
 else if(a==5&&b==5&&c==7){System.out.println("YES");}
 else{System.out.println("NO");}
 }
}

Measured memory_bytes: 9940
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    int min_ = min(x, y);
    if(a + b < 2 * c){
        ans += min_ * (a + b);
    }else{
        ans += min_ * 2 * c;
    }
    if((x - min_) * a + (y - min_) * b < (x - min_) * 2 * c + (y - min_) * 2 * c){
        ans += (x - min_) * a + (y - min_) * b;
    }else{
        ans += (x - min_) * 2 * c + (y - min_) * 2 * c;
    }
    print(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

static void C_task();

int main()
{
	C_task();

	fflush(stdout);
	return 0;
}

static void C_task()
{
	int L, R;
	get2int(L, R);

	LLONG minMod = 2020;
	for (LLONG i = L; i < std::min(R, L + 2021); i++) {
		for (LLONG j = i + 1; j <= std::min(R, L + 2021); j++) {
			LLONG tmp = (i * j) % 2019;
			minMod = tp_min<LLONG>(tmp, minMod);
		}
	}

	printf("%lld\n", minMod);
}


Measured memory_bytes: 256
import sys
X, Y = map(int, sys.stdin.readline().rstrip().split())
a = (4 * X - Y) / 2
b = (Y - 2 * X) / 2
if a.is_integer() and b.is_integer() and a >= 0 and b >= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#include<bits/stdc++.h>
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && b!=c)cout<<"Yes";
	else if(b==c && b!=a)cout<<"Yes";
	else if(a==c && a!=b)cout<<"Yes";
	else cout<<"No";
}


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

int main(){
	int a, b;
	cin >> a >> b;
	if (a == b)
	{
		cout << a << endl;
	}else if(a < b){
		cout << a << endl;
	}else{
		cout << a - 1 << endl;
	}
	
	return 0;
}

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

#define ll long long
#define forr(i,n) for(ll i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

ll power(ll a,ll b){ll r=1;while(b--)r*=a;return r;}
int solve(vector<int> h,int n,vector<int> dp){
    if(n==1)return h[n];
    else if(n==2) return min(h[2],h[1]);
    if(dp[n]!=-1)return dp[n];
    dp[n]=min(abs(h[n]-h[n-1])+solve(h,n-1,dp),abs(h[n]-h[n-2])+solve(h,n-2,dp));
    return dp[n];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int n;cin>>n;
    vector<int> v(n),dp(n,1000000000);
    f(i,0,n)cin>>v[i];dp[0]=0;dp[1]=abs(v[1]-v[0]);
    f(i,2,n){
        dp[i]=min(dp[i],min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2])));
    }cs(dp[n-1]);
    //for(auto x:dp)ce(x);
    
    

  }


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

using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a%2==1){
    if(b%2==1){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
vector<int> divisor(int n){//約数列挙
  if(n == 57)return vector<int>{1, 57};
  vector<int> ret;
  for(int i = 1;i*i <= n;i++){
    if(n % i == 0){
      ret.push_back(i);
      if(n/i != i)ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
////////////////////////////////////////////////////////////////////


int n;set<int> st;
signed main(){
  cin>>n;
  vector<int> div = divisor(n-1);
  rep(i,div.size())if(div[i] != 1)st.insert(div[i]);
  div = divisor(n);
  rep(i,div.size()){
    if(div[i] == 1)continue;
    int m = n;
    while((m % div[i]) == 0){
      m /= div[i];
    }
    if(m % div[i] == 1)st.insert(div[i]);
  }
  cout << st.size() << endl;
}


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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




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

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"

int32_t main(){
	boost;
	int n, k;
	cin >> n >> k;
	vector < int > a(n) , b(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	sort(a.begin() , a.end());
	sort(b.rbegin() , b.rend());
	
	auto okk = [&]( int m ) {
		auto v1 = a, v2 = b;
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			cnt += max(0ll , a[i] - m / b[i]);
		}
		return cnt <= k;
	};

	int l = 0, r = 1e12, ans = 0;
	while(l <= r) {
		int m = (l + r) / 2;
		if(okk(m)) {
			ans = m;
			r = m - 1;
		}
		else
			l = m + 1;
	}
	cout << ans << endl;
}


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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int num_root() { // 幾つの木があるかを出力
        set<int> s;
        for (auto it: par) {
            s.insert(root(it));
        }
        return s.size();
    }
};

int main() {
    int n, m;
    vector<int> a, b;
    cin >> n >> m;

    UnionFind tree(2 * n);
    for(int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        if (z % 2 == 0) {
            tree.unite(x - 1, y - 1);
            tree.unite(x + n - 1, y + n - 1);
        } else {
            tree.unite(x - 1, y + n - 1);
            tree.unite(x + n - 1, y - 1);
        }
    }

    int res = tree.num_root() / 2;
    cout << res << endl;

    return 0;
}

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

using namespace std;

using lint = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  lint s, w;
  cin >> s >> w;
  if (s > w) {
    cout << "safe" << endl;
  } else {
    cout << "unsafe" << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

pre = 0
score = 0
for i in A:
  score += B[i-1]  
  if pre == (i-1) and i != 1:
    score += C[pre-1]
  pre = i
    
print(score)    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fname "D"
#define cerr if(false)cerr
#define bug(x) cerr << (#x) << " = " << (x) << endl
#define ll long long
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define ARR0(a, n) {cerr <<(#a)<< ": ["; REP0(i, n) cerr<< ' ' << a[i] <<','; cerr<<']'<<endl;}
#define ARR1(a, n) {cerr <<(#a)<< ": ["; REP1(i, n) cerr<< ' ' << a[i] <<','; cerr<<']'<<endl;}
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define LB lower_bound
#define UB upper_bound
#define X first
#define Y second

using namespace std;
template<typename T, typename V>
inline void bugp(const pair<T, V> &x) {cerr << '{' << x.X << ", " << x.Y << '}' << endl;}
template<typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {cerr << '{' << x.X << ", {" << x.Y.X << ", " << x.Y.Y << "}}" << endl;}
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ll, int> li;
typedef pair<ll, ii> lii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int N = 5005;
int c[N], p[N], leng[N];
ll d[N];

int main()
{
    
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, k;
    cin >> n >> k;
    REP1(i, n) cin >> p[i];
    REP1(i, n) cin >> c[i];
    int id, prev, len, cnt, s;
    ll w, ans = LLONG_MIN, val;
    REP1(i, n) {
        bug(i);
        memset(leng, 0, sizeof leng);
        d[i] = cnt = 0;
        id = p[i];
        prev = i;
        while(!leng[id] && id != i) {
            leng[id] = leng[prev] + 1;
            d[id] = d[prev] + c[id];
            bug(id); bug(leng[id]); bug(d[id]);
            ++cnt;
            if(cnt <= k) ans = max(ans, d[id]);
            else break;
            prev = id;
            id = p[id];
        }
        if(cnt >= k) continue;
        bug(d[prev]); bug(c[id]);
        ans = max(ans, d[prev] + c[id]);
        ++cnt;
        w = d[prev] + c[id] - d[id];
        len = leng[prev] + 1 - leng[id];
        bug(w); bug(len);
        if(w > 0 && (k - cnt)) {
            if((k - cnt) % len == 0) {
                val = ((k - cnt) / len - 1) * w + d[prev] + c[id];
                ans = max(ans, val);
                s = id;
                do {
                    s = p[s];
                    ans = max(ans, val + c[s]);
                    val += c[s];
                } while(s != id);
            }
            else {
                val = (k - cnt) / len * w + d[prev] + c[id];
                ans = max(ans, val);
                s = p[id];
                cnt = (k - cnt) % len;
                while(cnt) {
                    --cnt;
                    ans = max(ans, val + c[s]);
                    val += c[s];
                    s = p[s];
                }
            }
        }
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 3748
#!/usr/bin/env python3
# CGL_7_D: Circles - Cross Points of a Circle and a line

from math import sqrt


def cross_point(circle, p1, p2):
    x0, y0, r = circle
    x1, y1 = p1
    x2, y2 = p2

    p1p2 = norm((x2-x1, y2-y1))
    op1 = norm((x0-x1, y0-y1))
    rr = r*r
    dp = dot((x0-x1, y0-y1), (x2-x1, y2-y1))

    d = dp*dp - p1p2 * (op1 - rr)

    if abs(d) < 1e-10:
        t = dp / p1p2
        return [(x1 + t*(x2-x1), y1 + t*(y2-y1))]
    elif d > 1e-10:
        t1 = (dp+sqrt(d)) / p1p2
        t2 = (dp-sqrt(d)) / p1p2
        return [(x1 + t1*(x2-x1), y1 + t1*(y2-y1)),
                (x1 + t2*(x2-x1), y1 + t2*(y2-y1))]
    else:
        return None


def norm(v):
    x, y = v
    return x**2 + y**2


def dot(v1, v2):
    x1, y1 = v1
    x2, y2 = v2
    return x1*x2 + y1*y2


def run():
    c = [int(i) for i in input().split()]
    q = int(input())

    for _ in range(q):
        x1, y1, x2, y2 = [int(i) for i in input().split()]
        ps = cross_point(c, (x1, y1), (x2, y2))

        if ps is None:
            raise ValueError('the circle and line do not intersect')
        if len(ps) == 1:
            ps *= 2

        p1, p2 = ps
        if p1 > p2:
            p1, p2 = p2, p1

        print("{:.8f} {:.8f} {:.8f} {:.8f}".format(*p1, *p2))


if __name__ == '__main__':
    run()



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

using namespace std;

int main(void){
  string s,t;
  cin >> s;
  cin >> t;
  int count = 0;
  for(int i=0;i<s.length();i++){
    if(s[i] != t[i]){
      count++;
    }
  }
  cout << count << endl; 
  return 0;
}


Measured memory_bytes: 3924
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
using namespace std;

int main()
{
    int N, A, B;
    cin >> N;
    if (N == 1){cout << "Hello World" << endl;}
    else if (N == 2){
        cin >> A >> B;
        cout << A + B << endl;
    }
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	string s,t;cin>>s>>t;
	int n=s.size();
	for(int i=0;i<n;i++){
		s.pub(s[0]);
		s.erase(s.begin());
		if(s==t){cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class CSubarraySum {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n,k,s;in>>n>>k>>s;
        rep(i,k) out<<s<<' ';
        if(s==pow(10,9)) rep(i,n-k) out<<1<<' ';
        else rep(i, n-k) out<<s+1<<' ';


	}
};


int main() {
	CSubarraySum solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3180