akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

constexpr int N = 1e6+6;
int n;
int cnt[N];

// int n,a,d,cnt[1000003],maxa=-(1<<30);

// void fenjie(int x)
// {
//     for(int i=2;i*i<=x;++i)
//     {
//         if(x%i == 0)
//         {
//             ++cnt[i];//因子含有i的数有cnt[i]个
//         }
//     }
//     if(x > 1) ++cnt[x];
// }

void fj(int x){//分解质因数
    for(int i=2;i*i<=x;){
        if(!(x%i)){
            ++cnt[i];//用桶记下来
            while(!(x%i)) x/=i;
        }
        else ++i;
    }
    if(x>1) ++cnt[x];//不要忘了这一句
}

int main()
{
   //IOS;
   int n;
   int a;
   scanf("%d%d",&n,&a);
   int k = a;
   int mxa = 0;
   rep(i,2,n)
   {
       scanf("%d",&a);
       mxa = max(mxa,a);
       k = __gcd(k,a);
       fj(a);
   }
   bool p1 = 1;
   rep(i,2,mxa)
   {
       if(cnt[i] >= 2)
       {
           p1 = 0;
           break;//说明不是两两互质了
       }
   }
   if(p1)puts("pairwise coprime");
   else if(p1 == 0 && k == 1) puts("setwise coprime");
   else puts("not coprime");
}
// int main(){
//     scanf("%d%d",&n,&a);
//     d=a;//d初始值为a
//     for(int i=2;i<=n;i++){
//         scanf("%d",&a);
//         if(maxa<a) maxa=a;//更新maxa
//         d=__gcd(d,a);//求n个数的公因数可以这么做
//         fenjie(a);//对a分解质因数
//     }
//     if(d==1){
//         for(int i=2;i<=maxa;i++)
//             if(cnt[i]>1) return puts("setwise coprime"),0;
//             //t[i]>1说明有几个数有相同的因子，则肯定有一对数不互质
//         return puts("pairwise coprime"),0;
//     }
//     else return puts("not coprime"),0;
//     return 0;
// }


Measured memory_bytes: 7672
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int[][] students = new int[n][n];
			int[][] x = new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					students[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int columnMax = -1;
				for(int j = 0; j < n; j++){
					if(columnMax < students[j][i])
						columnMax = students[j][i];
				}
				for(int j = 0; j < n; j++){
					if(columnMax == students[j][i])
						x[j][i] |= 2;
				}
			}
			for(int i = 0; i < n; i++){
				int rowMin = Integer.MAX_VALUE;
				for(int j = 0; j < n; j++){
					if(rowMin > students[i][j])
						rowMin = students[i][j];
				}
				for(int j = 0; j < n; j++){
					if(rowMin == students[i][j])
						x[i][j] |= 1;
				}
			}
			
			Set<Integer> both = new HashSet<Integer>();
            for(int i = 0;i < n;i++)
                for(int j = 0;j < n;j++)
                    if(x[i][j] == 3)
                        both.add(students[i][j]);
			
            if(both.size() == 1){
            	StringBuilder sb = new StringBuilder();
                for(int v : both){
                    sb.append(v + " ");
                }
                sb.deleteCharAt(sb.length() - 1);
                System.out.println(sb);
            }else{
            	System.out.println(0);
            }
		}
	}
}

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

int main(){
  int n;cin >> n;string s;cin >> s;
  int ans = 0;
  for(int i=1;i<n;++i){
    if(s[i-1] != s[i])ans += 1;
  }
  cout << ans+1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#define ll long long
#define C (c=getchar())
using namespace std;
const int N=100;
inline void read(int &a)
{
	a=0;int f=1;char c;C;
	while (c<'0'||c>'9') c=='-'?f=-1,C:C;
	while (c>='0'&&c<='9') a=(a<<3)+(a<<1)+(c-48),C;
	a*=f;
}
int a,b;
int t;
int map[105][105];
int main()
{
	register int i,j;
	read(a),read(b);
	bool f=0;
	if (a>b) t=a,a=b,b=t,f=1;
	puts("100 100");a--;
	for (i=1;i<=N;i+=4)
	{
		for (j=1;j<=N;j+=4)
		{
			if (b--)
			{
				map[i][j]=map[i+1][j]=map[i+2][j]=map[i][j+1]=map[i+1][j+1]=map[i+2][j+1]=map[i][j+2]=map[i+1][j+2]=map[i+2][j+2]=1;
			}
			else break;
		}
		if (b<=0) break; 
	}
	for (i=2;i<=N;i+=4)
	{
		for (j=2;j<=N;j+=4)
		{
			if (a--)
			{
				map[i][j]=0;
			}
			else break;
		}
		if (a<=0) break; 
	}
	for (i=1;i<=N;i++)
	{
		for (j=1;j<=N;j++)
		{
			map[i][j]=map[i][j]+f%2;
			if (map[i][j]==1) putchar('#');
			else putchar ('.');
		}
		puts("");
	}
}

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

int main() {
  int r, D, x;
cin >> r >> D >> x;
  rep(i, 10){
  x = r*x - D;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <math.h>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  string s, t;
  cin >> s >> t;
  if (s == t.substr(0, s.size())) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#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)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N;
	cin>>N;
	int a=0;
	rep(i,N){
		int x;
		cin>>x;
		while(x%2==0){
			x/=2;
			a++;
		}
	}
	cout<<a<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    string S;
    cin >> S;
    
    int ans = 0;
    
    rep(i,(S.size())/2){
        if(S[i] != S[S.size() - i - 1]){
            ans++;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict

s = ns()
dic = defaultdict(int)
for si in s:
    dic[si] += 1

ok = True
for _, v in dic.items():
    if v != 2:
        ok = False
        break

print("Yes" if ok else "No")



Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        String B = sc.next();
        int b_x = Integer.valueOf(B.substring(0, 1)), b_y = Integer.parseInt(B.substring(2));
        long a_x = A * b_x;
        long a_y = A * b_y / 100;
        System.out.println(a_x + a_y);
    }
}


Measured memory_bytes: 27080
s= str(input().strip())
K= int(input().strip())
parts = []
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        flg = 0
        if j-i > K:
            break
        parts.append(s[i:j])
v = sorted(parts)
vv = [v[0]]
tmp = v[0]
for k in range(1,len(v)):
    if v[k]!=tmp:
        vv.append(v[k])
        tmp = v[k]
    if len(vv)==K:
        break
        
print(vv[K-1])


Measured memory_bytes: 4596
#include<stdio.h> 

long long max(long long a, long long b) { return (a > b)? a : b; } 

long long  knapSack(long long W, long long wt[], long long val[], long long n) 
{  
      
long long i, w; 
long long K[n+1][W+1]; 
  
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 


int main() 
{ 
	
	long long n,W;
	scanf("%lld %lld",&n,&W);
	long long val[n] ; 
	long long wt[n]; 
	for(int i=0;i<n;i++){
		scanf("%lld %lld",&wt[i],&val[i]);
	}
	printf("%lld", knapSack(W, wt, val, n)); 
	return 0; 
} 


Measured memory_bytes: 79104
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=100100;
struct A{
	int u,v,w,next;
}e[maxn*2];
int g[maxn],n,d[maxn];
bool vis[maxn];
queue<int>Q;
int bfs(int a){
	int ans,maxx=0;
	memset(vis,false,sizeof(vis));
	memset(d,0,sizeof(d));
	vis[a]=true;
	Q.push(a);
	d[a]=0;
	while(!Q.empty()){
		int u=Q.front();
		Q.pop();
		for(int i=g[u];i>0;i=e[i].next){
			int v=e[i].v,w=e[i].w;
			if(!vis[v]){
				d[v]=d[u]+w;
				if(d[v]>maxx){
					maxx=d[v];
					ans=v;
				}
				vis[v]=true;
				Q.push(v);
			}
		}
	}
	return ans;
}
int main(){
	cin>>n;
	for(int i=1;i<=n-1;i++){
		int x,y,z;
		cin>>x>>y>>z;
		e[i]=(A){
			x,y,z,g[x]
		};g[x]=i;
		e[i-1+n]=(A){
			y,x,z,g[y] 
		};g[y]=i+n-1;
	}
	int temp=bfs(1);
	int ans=bfs(temp);
	cout<<d[ans]<<endl;
	return 0;
}

Measured memory_bytes: 7108
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int ans = sc.nextInt();
        for(int i = 0; i < N; i++){
            ans++;
            int a = sc.nextInt();
            ans += (D-1)/a;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 22868
//#pragma GCC optimize("03", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i,n) for(i=0;i<n;i++)
#define FORn(i,j,n) for(i=j;i<n;i++)
#define pb push_back
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define vli vector<lli>
#define vi vector<int>
#define vs vector<string>
#define vprint(v) for(auto t:v)cout<<t<<" "
#define endl "\n"

typedef long long int lli;
typedef long int li;

const lli mod=1000000007;
const lli limit=1000000;

using namespace std;

void fc(lli &x)
    {
        bool neg=false;
        register char c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

int main() {

    fast()
    lli n,q,t;
    lli temp,temp1,temp2,temp3;
    lli i,j,k;
    string s;
    cin>>s;
    
    bool flag=0;
    i=0;
    j=s.length()-1;
    while(i<j)if(s[i++]!=s[j--]){flag=1;break;}
    j=(s.length()-1)/2-1;
    i=0;
    if(!flag)while(i<j)if(s[i++]!=s[j--]){flag=1;break;}
    if(!flag){
        i=(s.length()+3)/2-1;
        j=s.length()-1;
        while(i<j)if(s[i++]!=s[j--]){flag=1;break;}
    }
    if(flag)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
 
}

Measured memory_bytes: 256
s = input()
if s[0] != 'A': print('WA')
else:
    c_cnt = 0
    end_p = len(s)-2
    for i in range(1,len(s)):
        
        # C判定
        if 2 <= i <= end_p and s[i] == 'C':
            c_cnt += 1
        
        # 小文字かどうか
        elif s[i] != s[i].lower():
            print('WA')
            exit()

    if c_cnt != 1:
        print('WA')
    else:
        print('AC')

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




int main()
{
  int  n;
  cin>>n;
  int  a[n];
  for(int  i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int max=*max_element(a,a+n);
  int mark[max+1]={0};

  for(int i=0;i<n;i++)
  {
    for(int x=a[i];x<=max;x+=a[i])
    {
      mark[x]++;
  }
    }
  int ans=0;
  for(int i=0;i<n;i++)
  {
    if(mark[a[i]]==1) 
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

double eps = 1e-9;
double pi = acos(-1);

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io

	string s;
	cin >> s;
	if(s[s.size() - 1] == 's')
		cout << s << "es\n";
	else
		cout << s << "s\n";


	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll x = 0;
  ll ans = 0;

  for(char c : s) {
    if (c == 'I') x++;
    else x--;
    chmax(ans, x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i, N) cin >> h[i];
  int ans = 0;
  while (true) {
    int temp = 0;

    rep(i, N - 1) {
      if (h[i] > 0 && h[i + 1] <= 0) temp++;
    }

    if (h[N - 1] > 0) temp++;

    if (temp == 0) break;
    ans += temp;
    rep(i, N) { h[i]--; }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int x, y; cin >> x >> y;
	int ans = 0;
	int a = 100000;
	if (x == 3)ans += a;
	if (x == 2)ans += a * 2;
	if (x == 1)ans += a * 3;
	if (y == 3)ans += a;
	if (y == 2)ans += a * 2;
	if (y == 1)ans += a * 3;
	if (x == 1 && y == 1)ans += a * 4;
	cout << ans << endl;
}


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

using namespace std;

char c[8][8];
char c2[8][8];
int main() {
 
    int n,m,k;
    cin >> n >> m >> k;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> c[i][j];

    int ans = 0;

    for (int mask = 0; mask < (1 << n); mask++) {
        for (int mask2 = 0; mask2 < (1 << m); mask2++) {
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < m; ++j) {
                    c2[i][j] = c[i][j];
                    if((mask & (1 << i)) or (mask2 & (1 << j)))
                        c2[i][j] = 'r';
                }

            int cur = 0;
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < m; ++j) 
                    cur += c2[i][j] == '#';

            ans += cur == k;
        }
    }

    cout << ans << "\n";

    return 0;
}


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

S = [0 for _ in range(N+1)]
T = [0 for _ in range(N+1)]
mod = 1000000007

for i in range(N-1):
    st = 0
    T[i+1] = T[i] + A[i]
    S[i+1] = S[i] + A[i+1] * T[i+1]

print(int(S[N-1] % mod))

Measured memory_bytes: 39836
#include<stdio.h>

int main(){
	int n = 0;
	int i = 0;
	int j = 0;
	int k = 0;
	
	scanf("%d",&n);
	
	for(i = 1 ; i <= n ; i++)
	{
			if(i % 3 == 0)
			{
				printf(" %d",i);
			}
		
			else if(i % 10 == 3)
			{
				printf(" %d",i);
			}
		
			else if(i / 10 %10 == 3)
			{
				printf(" %d",i);
			}
		
			else if(i / 100 %10 == 3)
			{
				printf(" %d",i);
			}
		
			else if(i / 1000 %10 == 3)
			{
				printf(" %d",i);
			}
		
	
	}

	

	printf("\n");
return 0 ;

}

Measured memory_bytes: 600
module Main where

import           Data.List

main :: IO ()
main = do
    [h, w] <- (map read . words) <$> getLine :: IO [Int]
    list   <-
        (map (map read . words)) <$> (sequence . take h . repeat) getLine :: IO
            [[Int]]
    let res1    = (map goRight . enumerate2d) list
    let list2   = (map snd) res1
    let result1 = (concat . map fst) res1
    let res2    = (map goRight . transpose) list2
    let result2 = (concat . map fst) res2
    let result  = concat [result1, result2]

    putStr
        $ (unlines . (((show . length) result) :) . map
              (unwords . (\((a, b), (c, d)) -> (map show) [a, b, c, d]))
          )
              result

    return ()
goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight list@[_         ] = ([], list)
goRight (     a : b : xs) = if even (snd a)
    then let res = goRight (b : xs) in (fst res, a : (snd res))
    else
        let res = goRight ((fst b, (snd b) + 1) : xs)
        in  ((fst a, fst b) : (fst res), (fst a, (snd a) - 1) : (snd res))

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d list =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)
        list


Measured memory_bytes: 87164
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

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


//Answer


int main() {

long long X,K,D,N;//X 初期　K　回数　D　歩幅
cin>>X>>K>>D;
if(X<0){
    X=-1*X;
}

if(K%2==1){
    X=X+D;
}
N=X/(2*D);
if((X-N*2*D)>((N+1)*2*D)-X){
        if(K>=2*N+1){
                cout<<(N+1)*2*D-X;
        }else{
          if(K%2==1){
            X=X-D;
          }
            cout<<X-K*D<<endl;
        }
}else{
    if(K>=2*N-1){
        cout<<X-N*2*D;
    }else{
          if(K%2==1){
            X=X-D;
          }
            cout<<X-K*D<<endl;
    }

}



}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
 
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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}
 
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-6;
 
const int MAX = 55;
LL N, A, B;
LL v[MAX];
 
LL comb(LL n,LL r){LL res = 1;RREP(i,r){res*=(n-i);res/=(r-i);}return res;}
 
int main() {
	scanf("%lld%lld%lld", &N, &A, &B);
	REP(i, N) {
		scanf("%lld", v + i);
	}
	sort(v, v + N);
	reverse(v, v + N);
	LL sum = 0;
	long double maave = 0;
	VI idxs;
	REP(i, B) {
		sum += v[i];
		if (i + 1 >= A) {
			maave = sum;
			break;
		}
	}
	sum = 0;
	REP(i, B) {
		sum += v[i];
		if (i + 1 >= A) {
			if (maave * (i + 1) == sum * A) {
				idxs.EB(i + 1);
			}
		}
	}
	cout << fixed << setprecision(10) << maave / A << endl;
	LL ans = 0;
	FORE(e, idxs) {
		assert(A <= e && e <= B);
		map<LL, int> mp, mp2;
		REP(i, e) {
			mp[v[i]]++;
		}
		FOR(i, e, N) {
			mp2[v[i]]++;
		}
		LL pre = 1;
		FORE(e, mp2) {
			pre *= comb(e.second + mp[e.first], mp[e.first]);
		}
		ans += pre;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int main(){
    int m1,m2,d1,d2;
    cin >> m1>>d1;
    cin >> m2>>d2;
    if(d2==1){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool f[2][2010];
int n,z,x[2010];
bool chk(int val){
    for (int i=0;i<=n;i++) f[0][i]=f[1][i]=0;
    int tmp0=1,tmp1=1;
    for (int i=n;i>=1;i--){
        f[0][i]=!((abs(x[i-1]-x[n])<=val)&tmp1);
        f[1][i]=!((abs(x[i-1]-x[n])>val)&tmp0);
        tmp0&=f[0][i];
        tmp1&=f[1][i];
    }
    return f[0][1];
}
int main(){
    scanf("%d %d %d",&n,&z,&x[0]);
    for (int i=1;i<=n;i++) scanf("%d",&x[i]);
    int L=0,R=1000000000;
    while (L!=R){
        int mid=(L+R)>>1;
        if (chk(mid)) L=mid+1;
        else R=mid;
    }
    printf("%d\n",L);
}

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

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int X;
	cin >> X;

	X -= 400;
	X = X / 200;
	X = (8 - X);
	cout << X << endl;

	return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S=="Sunny") cout << "Cloudy" << endl;
  if(S=="Cloudy") cout << "Rainy" << endl;
  if(S=="Rainy") cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {


	public static void main(String[]args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer c[] = new Integer[n],b[] = new Integer[n],a[] = new Integer[n];
		for (int i = 0 ; i < n ; ++i) {
			c[i] = sc.nextInt();
		}
		for (int i = 0 ; i  < n ; ++i) {
			b[i] = sc.nextInt();
		}
		for (int i = 0 ; i < n ; ++i) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);
		long tot = 0;
		for (int i = 0 ; i < n ; ++i) {
			int lo = 0, hi = n - 1;
			int ans = -1;
			while (lo <= hi) {
				int mid = lo + (hi - lo) / 2;
				if (a[mid] > b[i]) {
					hi = mid - 1;
					ans = mid;
				} else {
					lo = mid + 1;
				}
			}
			if (ans == -1) {
				continue;
			}
			long left = (n - ans);
			lo = 0;
			hi = n - 1;
			ans = -1;
			while (lo <= hi) {
				int mid = lo + (hi - lo) / 2;
				if (c[mid] < b[i]) {
					lo = mid + 1;
					ans = mid;
				} else {
					hi = mid - 1;
				}
			}
			if (ans == -1) {
				continue;
			}
			long right = ans + 1;
			tot += 1L*(right * left);
		}
		System.out.println(tot);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 54292
import Data.List

solve :: Int -> Int -> Int -> Int
solve h w k = (acc !! h) !! 0 where

  acc = iterate f iAcc where
    iAcc = map (iteF 1 0 . (== k)) [1..w]
    f acc = foldl1' (zipWith mAdd) (map (change acc) validH)

  validH = filter isValid (power !! (w - 1))

isValid q = not $ or $ zipWith (&&) q (tail q)

power = iterate (concatMap (\q -> [False:q, True:q])) [[]]

change [x]       []         = [x]
change (x:xs)    (False:bs) = x  : change xs     bs
change (x:x':xs) (True:bs)  = x' : change (x:xs) bs

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = (x + y) `mod` mPrime

iteF t e c = if c then t else e

tmain :: String -> Int
tmain cont =
  let [h,w,k] = map read (words cont)
  in solve h w k

main :: IO ()
main = putStrLn . show . tmain =<< getContents


Measured memory_bytes: 3324
#include<stdio.h>
int main()
{
    long long Q,H,S,D,N;
    int sum=0;
    scanf("%lld",&Q);
    scanf("%lld",&H);
    scanf("%lld",&S);
    scanf("%lld",&D);
    scanf("%lld",&N);
    
    long long x,y;
    x = Q * 4 < H * 2 ? Q * 4 : H * 2;
    y = x < S ? x : S;
    
     if (N % 2 == 0 && y * 2 > D)
	  {
            printf("%lld\n", D * (N / 2));
      } 
	  else if (N % 2 == 0 && y * 2 < D)
	  {
            printf("%lld\n", y * N);
      } 
	  else if (N % 2 != 0 && y * 2 > D) 
	  {
            printf("%lld\n", D * (N / 2) + y * (N % 2));
      } 
	  else if (N % 2 != 0 && y * 2 < D)
	  {
            printf("%lld\n", y * N);
      }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,T;cin>>n>>T;
    ll res=0,tmp=0;
    
    rep(i,n){
        ll t;cin>>t;
        if(i==0)continue;
        if(t>tmp+T){
            res+=T;
        }else{
            res+=(t-tmp);
        }
        tmp=t;
        
    }
    
    res+=T;
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, a, b, c;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d",&a ,&b, &c);
	if(a == b and b == c and a ==c)
		puts("Yes");
	else
		puts("No");
	
	return 0;
}

Measured memory_bytes: 256
# 2019/12/27

h,w=map(int,input().split())
s=[list('#'*(w+2))]
for _ in range(h):
    s+=[list('#'+input()+'#')]
s+=[list('#'*(w+2))]

L=[[0]*(w+2) for _ in range(h+2)]
U=[[0]*(w+2) for _ in range(h+2)]
R=[[0]*(w+2) for _ in range(h+2)]
D=[[0]*(w+2) for _ in range(h+2)]


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":continue
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

ans=0

for i in range(h,0,-1):
    for j in range(w,0,-1):
        if s[i][j]=="#":continue
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1
        lit=L[i][j]+U[i][j]+R[i][j]+D[i][j]-3
        ans=max(ans,lit)
print(ans)


Measured memory_bytes: 307592
/* kop Chy_Chy*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll , ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define si(x)   scanf("%d", &x)
#define sl(x)   scanf("%lld", &x)
#define pi(x)   printf("%d\n", x)
#define pl(x)   printf("%lld\n", x)
#define deb(x)  cout<< #x << " = " << x << endl // debugging kop 
#define mp      make_pair
#define pb      push_back
#define MOD     1000000007
#define PI      acos(-1)
#define ff      first
#define ss      second
#define newline printf("\n")
ll binpow(ll a, ll b); // binary exponentiation kop
void prime_factorization(ll n, vll &prime_factors); // prime factorization kop
ll gcd(ll a, ll b); // greatest common divisor kop. Use LONG LONG
void speedup() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int main(){
    speedup();
    int t = 1;
    // cin>> t;
    while(t--){
        // khela final Mamooo
        int x; cin>> x;
        if (x >= 1800 && x < 2000) cout<< 1 << "\n";
        else if(x >= 1600 && x < 1800) cout<< 2 << "\n";
        else if(x >= 1400 && x < 1600) cout<< 3 << "\n";
        else if(x >= 1200 && x < 1400) cout<< 4 << "\n";
        else if(x >= 1000 && x < 1200) cout<< 5 << "\n";
        else if(x >= 800 && x < 1000) cout<< 6 << "\n";
        else if(x >= 600 && x < 800) cout<< 7 << "\n";
        else if(x >= 400 && x < 600) cout<< 8 << "\n";
        
        
        
    }
    // kop kop return 
    return 0;
}


// kop kop functions:
ll binpow(ll a, ll b){
    a = a % MOD; ll res = 1;
    while(b > 0){
        if(b & 1) res *= a % MOD;
        a = a* a % MOD;b = b >> 1;}
    return res;
}
/*---------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
/*---------------------------------------------------------------------------------------------------------------*/
void prime_factorization(ll n, vll &prime_factors){
    // first two step taking care of composite number
    // taking care of 2
    while(n%2 == 0){
        prime_factors.pb(2);
        n = n / 2;
    }
    // now n must be odd. And the remaining prime divisors are odd. so we start from 3 and increamenting 2
    for(ll i = 3; i <= sqrt(n); i = i + 2){
        while(n%i == 0){
            prime_factors.pb(i);
            n = n / i;
        }
    }
    // now we are taking care of  n is prime number and greater than 2
    if(n > 2){
        prime_factors.pb(n);
    }
}
/*---------------------------------------------------------------------------------------------------------------*/














Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

ll mod=1e9+7;

int main(){
      string s;
      cin>>s;
      ll cntA=0;
      ll ans=0;
      ll now=0;
      while(1){
            if(now>=s.size()){
                  break;
            }
            if(s[now]=='A'){
                  cntA++;
            }
            else if(now<=s.size()-2&&s[now]=='B'&&s[now+1]=='C'){
                  ans+=cntA;
                  now+=2;
                  continue;
            }
            else{
                  cntA=0;
            }
            now++;
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 640
def solve_impl(ini, T):
    t = 0
    for Ci, Si, Fi in T[ini:]:
        # wait until start
        if t < Si:
            t = Si
        elif t % Fi != 0:
            t = t + Fi - t % Fi
        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	long long n, d;
	vector<vector<long long>> arr;
	vector<long long> cur;
	long long i, j, k;
	long long input;
	long long dist, root;
	int cnt = 0;

	scanf("%lld %lld", &n, &d);

	for (i = 0; i < n; i++)
	{
		cur.clear();

		for (j = 0; j < d; j++)
		{
			scanf("%lld", &input);

			cur.push_back(input);
		}

		for (j = 0; j < i; j++)
		{
			dist = 0;

			for (k = 0; k < d; k++)
			{
				dist += (arr[j][k] - cur[k])*(arr[j][k] - cur[k]);
			}

			root = (long long)sqrt((double)dist);

			if (root*root == dist)
			{
				cnt++;
			}
		}

		arr.push_back(cur);
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 256
N , M = map(int,input().split())

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

A.sort()

conv = []

for i in range(M) :
    B , C = map(int,input().split())
    conv.append([B,C])

sec = lambda A : A[1]
conv.sort(key=sec,reverse=True)

change = []
add = 0

# 大きいものからN個とる
for c in conv :
    for i in range(c[0]) :
        change.append(c[1])
        add += 1

    if(add >= N) :
        break

for i in range(min(N,len(change))) :
    if A[i] >= change[i] :
        break
    A[i] = change[i]

print(int(sum(A)))

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

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

int main() {
    cin >> n >> s >> k;
    char target = s.at(k-1);
    REP(i, 0, s.size()) {
        if (s.at(i) != target) cout << "*";
        else cout << s.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    const int nums[] = {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;
    std::cin >> K;

    std::cout << nums[K - 1];

    return 0;
}


Measured memory_bytes: 256
def dis(XY1, XY2):
    return abs(XY1[0]-XY2[0]) + abs(XY1[1]-XY2[1])

N, M = map(int,input().split())
AB = [0 for _ in range(N)]
CD = [0 for _ in range(M)]
for i in range(N):
    a,b = map(int,input().split())
    AB[i] = [a,b]
for i in range(M):
    c,d = map(int,input().split())
    CD[i] = [c,d]

for ab in AB:
    mini = 2*(10**9)
    id = 0
    for cd in CD:
        if mini > dis(ab,cd):
            mini = dis(ab,cd)
            id = CD.index(cd)+1
    print(id)

Measured memory_bytes: 3064
#include <stdio.h>

int Bsort(int *,int );

int main(){
  int N,i,A[100],count;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  count=Bsort(A,N);
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
  return 0;
}

int Bsort(int *A,int N){
  int count = 0,hantei = 1,i,j,x;
  for(i=0;hantei==1;i++){
    hantei=0;
    for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	x=A[j-1];
	A[j-1]=A[j];
	A[j]=x;
	hantei=1;
	count++;
      }
    }
  }
  return count;
}



Measured memory_bytes: 2124
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 200005;
struct Edge{
	int to,next;
}e[MAXN<<1];
bool safe[MAXN];
int dep[MAXN],n,x,y,cnt,head[MAXN];
inline void insert(int u,int v)
{
	e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
	e[++cnt].to=u,e[cnt].next=head[v],head[v]=cnt;
}
int u[MAXN],v[MAXN],pos[MAXN],out[MAXN],sz,fa[MAXN];
void dfs(int x)
{
	pos[x]=++sz;
	for(int i=head[x];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa[x])continue;
		dep[v]=dep[x]+1;
		fa[v]=x;
		dfs(v);
	}
	out[x]=sz;
}
inline bool judge(int x,int y)
{
	if(pos[x]>pos[y])swap(x,y);
	if(pos[y]>=pos[x] && pos[y]<=out[x])return dep[y]-dep[x]>2;
	return fa[x]!=fa[y];
}
namespace Sigma{
	struct Edge{
		int to,next;
	}e[MAXN<<1];
	int head[MAXN],cnt,ans;
	bool reach[MAXN];
	inline void insert(int u,int v)
	{
		e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
		e[++cnt].to=u,e[cnt].next=head[v],head[v]=cnt;
	}
	void getans(int x,int fa,int step)
	{
		reach[x]=1;
		for(int i=head[x];i;i=e[i].next){
			int v=e[i].to;
			if(v==fa)continue;
			if(step+1>=dep[v])continue;
			getans(v,x,step+1);
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<n;++i){
		scanf("%d%d",u+i,v+i);
	}
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		insert(u,v);
	}
	dfs(y);
	for(int i=1;i<n;++i){
		if(judge(u[i],v[i]))safe[u[i]]=safe[v[i]]=1;
		else Sigma::insert(u[i],v[i]);
	}
	Sigma::getans(x,0,0);
	int ans=0;
	for(int i=1;i<=n;++i)
		if(Sigma::reach[i]&&safe[i]){puts("-1");return 0;}
		else if(Sigma::reach[i])ans=max(ans,dep[i]);
	cout<<ans*2<<endl;
	return 0;
}


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

using namespace std;

int main() {
    long n;
    cin >> n;
    vector<long> a(n);
    for (long i = 0; i < n; ++i) {
        cin >> a[i];
    }
    long max_num = *max_element(a.begin(), a.end());
    vector<long> max_index;
    for (long i = 0; i < n; ++i) {
        if (a[i] == max_num) {
            max_index.push_back(i);
        }
    }
    if (max_index.size() > 1) {
        for (long i = 0; i < n; ++i) {
            cout << max_num << endl;
        }
        return 0;
    }
    long second_num = 0;
    for (long i = 0; i < n; ++i) {
        if (i == max_index[0]) {
            continue;
        } else {
            if (second_num < a[i]) {
                second_num = a[i];
            }
        }
    }

    for (long i = 0; i < n; ++i) {
        if (i == max_index[0]) {
            cout << second_num << endl;
        } else {
            cout << max_num << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
  long long int n,ans=0;
  cin>>n;
  vector<long long int>a(1000000),b(1000000);
  for(long long int i=0;i<n;i++){
    cin>>a[i];
    b[a[i]]++;
  }
   for(long long int i=0;i<=n;i++){
    ans = ans +(b[i]*(b[i]-1))/2;
  }
  for(long long int i=0;i<n;i++){
  	cout<<ans-(b[a[i]]*(b[a[i]]-1))/2+((b[a[i]]-1)*(b[a[i]]-2))/2<<endl;
  }
return 0;
}


Measured memory_bytes: 19072
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	int n,k;
	cin>>n>>k;
	k--;
	vi arr(n);
	for(int &i:arr)cin>>i;
	int mi = INT_MAX;
	REP(i,0,n-k-1) {
		if(arr[i+k]<0){
			mi=min(mi, -arr[i]);
		} else if(arr[i]<0) {
			mi = min(mi, min(-2*arr[i]+arr[i+k],2*arr[i+k]-arr[i]));
		} else mi=min(mi, arr[i+k]);
	}
	cout<<mi;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3724
#include <iostream>
using namespace std;
int main(){
	int N,K,X,Y;
	int ans;
	cin >> N >> K >> X >> Y;
	if(N > K){
		ans = K*X+(N-K)*Y;
	}else{
		ans = N*X;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
for i in range(n):
    a = int(input())
    if a not in d:
        d[a] = 1
    else:
        if d[a] == 1:
            d[a] = 0
        else:
            d[a] = 1

ans = 0
for kk in d.keys():
    if d[kk] == 1:
        ans += 1
print(ans)


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    
    if (str.contains("7")) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    } 
  }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll N, M;
ll ans = (ll)1e18;

void solve() {
    cin >> N >> M;
    if (N + M == 15) cout << "+" << endl;
    else if (N * M == 15) cout << "*" << endl;
    else cout << "x" << endl;
}

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


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

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

    int ans = -1;
    int taxb;
    int taxa;
    for(int price = 1009; price >= 1; price--){
        taxb = price * 0.08;
        taxa = price * 0.1;
        if(taxb == A and taxa == B){
            ans = price;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();
		if(s <= w) {
			System.out.println("unsafe");			
		}else {
			System.out.println("safe");						
		}
	}
}

Measured memory_bytes: 27012
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;

int main() {
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  printf("%.8f\n", sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2)));
  return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include <iostream>
// #include <iomanip>

using namespace std;

int main() {
  // 14 3
  int a, b;
  scanf("%d %d", &a, &b);

  int n = (b * 2 + 1);
  int r = a / n;
  if (a % n >= 1) {
    r++;
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vector<double> p(n);
    rep(i,n)cin>>p[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1));
    dp[1][1]=p[0];
    dp[1][0]=1-p[0];
    REP(i,1,n){
        rep(j,i+1){
            dp[i][j]+=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
        }
    }
    double ans=0;
    REP(i,n/2+1,n)ans+=dp[n][i];
    cout<<ans<<endl;
}

Measured memory_bytes: 70784