akhauriyash/Code-Regression huggingface dataset:
n = int(input())
P =[]
s = 0
x0,y0 = [int(i) for i in input().split()]
for i in range(n-1):
    x,y = [int(i) for i in input().split()]
    P.append([x-x0,y-y0])
for i in range(n-2):
    s += P[i][0]*P[i+1][1] - P[i][1]*P[i+1][0]
print(abs(s)*0.5)

Measured memory_bytes: 7728
import collections
N = int(input())
a = list(map(int, input().split()))
cand = collections.Counter(a)
cand_list = cand.most_common(len(set(a)))
ans = 0
for i in range(len(set(a))):
  num = cand_list[i][0]
  count = cand[num] + cand[num + 1] + cand[num - 1]
  ans = max(ans,count)

print(ans)

Measured memory_bytes: 18012
#include <iostream>
#include <queue>
#include <algorithm>
#include <tuple>
#include <map>
using namespace std;

typedef tuple<int, int, int> state;

int N, K;
vector<int> V[2010];

int sakujo(int cent) {
  int visited[2010];
  fill(visited, visited+N, -1);
  queue<state> Q;
  int grand[2010];
  fill(grand, grand+N, -1);
  grand[cent] = cent;
  for (auto x : V[cent]) {
    grand[x] = x;
  }
  Q.push(make_tuple(cent, 0, 0));
  while (!Q.empty()) {
    state s = Q.front();
    int src = get<0>(s);
    int cnt = get<1>(s);
    int gra = get<2>(s);
    Q.pop();
    if (visited[src] == -1) {
      visited[src] = cnt;
      if (grand[src] == -1) {
        grand[src] = gra;
      }
      for (auto dst : V[src]) {
        if (visited[dst] == -1) {
          Q.push(make_tuple(dst, cnt+1, grand[src]));
        }
      }
    }
  }
  int cnt = 0;
  if (K%2 == 0) {
    for (auto i = 0; i < N; i++) {
      if (visited[i] <= K/2) cnt++;
    }
    return N - cnt;
  } else {
    map<int, int> M;
    for (auto i = 0; i < N; i++) {
      if (visited[i] <= K/2) {
        cnt++;
      } else if (visited[i] == K/2 + 1) {
        if (M.find(grand[i]) == M.end()) {
          M[grand[i]] = 1;
        } else {
          M[grand[i]]++;
        }
      }
    }
    int maxi = 0;
    for (auto x : M) {
      maxi = max(maxi, x.second);
    }
    cnt += maxi;      
    return N - cnt;
  }
}

int main() {
  cin >> N >> K;
  for (auto i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  int mini = N;
  for (auto i = 0; i < N; i++) {
    mini = min(mini, sakujo(i));
  }
  cout << mini << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define It set<node>::iterator
#define endl '\n'
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=2e5+10;
const int inf=0x3f3f3f3f;

struct seg{
	int l,r,dat;
}t[4*maxn];

int n,k,c;
string s;
int f1[maxn],f2[maxn],f3[maxn],f4[maxn],max1[maxn],max2[maxn];
vector<int> v;

inline void push_up(int x){
	t[x].dat=max(t[x<<1].dat,t[x<<1|1].dat);
} 

inline void build(int l,int r,int x){
	t[x].l=l,t[x].r=r,t[x].dat=0;
	if(l==r) return ;
	int mid=(l+r)>>1;
	build(l,mid,x<<1);
	build(mid+1,r,x<<1|1);
	push_up(x);
}

inline void addval(int pos,int d,int x){
	if(t[x].r<pos||t[x].l>pos) return ;
	if(t[x].l==t[x].r){
		t[x].dat=max(t[x].dat,d);
		return ;
	}
	int mid=(t[x].l+t[x].r)>>1;
	if(pos<=mid) addval(pos,d,x<<1);
	if(pos>mid) addval(pos,d,x<<1|1);
	push_up(x);
}

inline int query(int l,int r,int x){
	if(l>r) return 0;
	if(t[x].l>=l&&t[x].r<=r) return t[x].dat;
	int mid=(t[x].l+t[x].r)>>1,res=0;
	if(l<=mid) res=max(res,query(l,r,x<<1));
	if(r>mid) res=max(res,query(l,r,x<<1|1));
	return res; 
} 

signed main(){
	cin>>n>>k>>c>>s;
	for(int i=n;i>=1;--i) if(s[i-1]=='o'){
		f1[i]=max1[min(n+1,i+c+1)]+1;
		max1[i]=max(max1[i],f1[i]);
	}else max1[i]=max1[i+1];
	for(int i=1;i<=n;++i) if(s[i-1]=='o'){
		f3[i]=max1[min(n+1,i+1)];
	}
	for(int i=1;i<=n;++i) if(s[i-1]=='o'){
		f2[i]=max2[max(0ll,i-c-1)]+1;
		max2[i]=max(max2[i],f2[i]);
	}else max2[i]=max2[i-1];
	for(int i=1;i<=n;++i) if(s[i-1]=='o'){
		f4[i]=max2[max(0ll,i-1)];
	}
/*	build(1,n,1);
	for(int i=n;i>=1;--i) if(s[i-1]=='o'){
		f1[i]=query(min(n+1,i+c+1),n,1)+1;
		addval(i,f1[i],1);
	}
	for(int i=1;i<=n;++i) if(s[i-1]=='o'){
		f3[i]=query(min(n+1,i+1),n,1);
	}
	build(1,n,1);
	for(int i=1;i<=n;++i) if(s[i-1]=='o'){
		f2[i]=query(1,max(0,i-c-1),1)+1;
		addval(i,f2[i],1);
	}
	for(int i=1;i<=n;++i) if(s[i-1]=='o'){
		f4[i]=query(1,max(0,i-1),1);
	}*/
	for(int i=1;i<=n;++i){
		if(s[i-1]=='x') continue;
		int val1=f1[i]+f2[i]-1,val2=f3[i]+f4[i];
//		if(val1>k||val2>k) return 0;
//		if(val1==k&&val2<k) v.pb(i); 
		if(val2<k) v.pb(i);
	}
	for(int i=0;i<v.size();++i) cout<<v[i]<<endl;
	return 0;
}

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

int main(){
	int dp[50001];
	int n,m;
	cin>>n>>m;
	for(int i=0;i<=n;i++){
		dp[i] = i;
	}
	for(int i=1;i<=m;i++){
		int c;
		cin>>c;
		for(int j=0;j<=n;j++){
			if(j>=c){
				dp[j] = min(dp[j],1+dp[j-c]);
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1356
import java.util.*;
public class Main{
	public static void main(String[] args){
		//abc
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();//制限
		//c-a<dこの時点でtrue
		//b-a<d&&c-a<dならtrue
		if((double)Math.abs(b - a) <= d && (double)Math.abs(c - b) <= d){
		System.out.println("Yes");
		}else if((double)Math.abs(c - a) <= d){
		System.out.println("Yes");
		}else{
		System.out.println("No");		
		}	
	}
}


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

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int ans=0;
    vector<bool> B(N,false);
    for(int i=N;i>=1;i--){
        int y=0;
        for(int k=i;k<=N;k+=i){
            if(B[k-1]) y++;
        }
        if(y%2!=A[i-1]){
            B[i-1]=true;
            ans++;
        }
    }
    cout<<ans<<endl;
    for(int i=0;i<N;i++){
        if(B[i]) cout<<i+1<<' ';
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main(void)
{
	int i, j, n, x, ans=0, flag;
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&x);
		if(x > 2  &&  x%2 != 0) {
			flag = 1;
			for (j=3; j<=sqrt(x); j+=2) {
				if(x%j == 0) {
					flag = 0;
					break;
				}
			}
			if(flag) ans++;
		} else if(x == 2) {
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    Scanner scan = new Scanner(System.in);
    char[] C;
    char next;

    Main(){
        C = scan.nextLine().toCharArray();
        next = C[0];
        next = (char)(C[0] + 1);
        System.out.println(next);
    }

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

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

int main() {
    int N, A[250];
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    for (int i = 0; i < N; i++) {
        int num, key, parentKey, leftKey, rightKey;
        num = i + 1;
        key = A[i];
        parentKey = (num / 2) - 1;
        leftKey = (num * 2) - 1;
        rightKey = (num * 2);
        
        printf("node %d: key = %d, ", num, key);
        
        if (parentKey >= 0 && parentKey < N) {
            printf("parent key = %d, ", A[parentKey]);
        }
        if (leftKey >= 0 && leftKey < N) {
            printf("left key = %d, ", A[leftKey]);
        }
        if (rightKey >= 0 && rightKey < N) {
            printf("right key = %d, ", A[rightKey]);
        }

        cout << endl;
    }

    return 0;
}



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

int main()
{
    int n;cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int xr=0;
    for(int i=0;i<n;i++)
    xr=xr^arr[i];
    for(int i=0;i<n;i++)
    arr[i]=xr^arr[i];
    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    
    return 0;
}

Measured memory_bytes: 4400
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String[] s = sc.next().split("");

        StringBuilder ans = new StringBuilder();
        ArrayList<String> list = new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");
        list.add("D");
        list.add("E");
        list.add("F");
        list.add("G");
        list.add("H");
        list.add("I");
        list.add("J");
        list.add("K");
        list.add("L");
        list.add("M");
        list.add("N");
        list.add("O");
        list.add("P");
        list.add("Q");
        list.add("R");
        list.add("S");
        list.add("T");
        list.add("U");
        list.add("V");
        list.add("W");
        list.add("X");
        list.add("Y");
        list.add("Z");
        // 26文字

        for (int i = 0; i < s.length; i++) {
            int index = list.indexOf(s[i]);
            ans.append(list.get((index + n) % 26));
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 25556
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef struct{
	int x,y,id;
} ii;
typedef tuple<int,ii,ii> t;
int dist(ii a,ii b){
	return min(abs(a.x-b.x),abs(a.y-b.y));
}
vector<int> up;
int fp(int u){
	if(up[u]<0) return u;
	else return up[u] = fp(up[u]);
}
void unite(int u,int v){
	int x = fp(u);
	int y = fp(v);
	if(x!=y) up[x]=y;
}
signed main() {
	int n;
	cin>>n;
	up.resize(n,-1);
	vector<ii> p(n);
	int i=0;
	for(auto &v:p)
	{
		v.id=i++;
		cin>>v.x>>v.y;
	}
	auto cmp= [](t a,t b){
		return get<0>(a)>get<0>(b);
	};
	priority_queue<t,vector<t>,decltype (cmp)> pq(cmp);
	sort(p.begin(),p.end(),[](ii lhs,ii rhs){return lhs.x<rhs.x;});
	for(auto it = p.begin();it!=prev(p.end());it++){
		int d = dist(*it,*next(it));
		pq.push(make_tuple(d,*it,*next(it)));
	}
	sort(p.begin(),p.end(),[](ii lhs,ii rhs){return lhs.y<rhs.y;});
		for(auto it = p.begin();it!=prev(p.end());it++){
			int d = dist(*it,*next(it));
			pq.push(make_tuple(d,*it,*next(it)));
		}
	int cnt = n;
	int res = 0;
	while(!pq.empty()){
		int d;
		ii a,b;
		tie(d,a,b) = pq.top();
		pq.pop();
		if(fp(a.id)!=fp(b.id)){
			n--;
			res+=d;
			unite(fp(a.id), fp(b.id));
		}
	}
	cout<<res<<endl;
}

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

#define MAX_N 500000

long long count = 0;
int A[MAX_N+1];

void merge(int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1 + 1]; int R[n2 + 1];

	for(int i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}

	for(int i = 0;i < n2; i++) {
		R[i] = A[mid + i];
	}

	L[n1] = R[n2] = 0x7FFFFFFF;
	int i = 0, j = 0;

	for(int k = left; k < right; k++) {
		if(L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			count += n1 - i;
			A[k] = R[j];
			j++;
		}
	}
}

void merge_sort(int left, int right) {
	if(right - left > 1) {
		int mid = (left + right) / 2;
		merge_sort(left, mid);
		merge_sort(mid, right);
		merge(left, mid, right);
	}
}

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

	for(int i = 0;i < n; i++) {
		cin >> A[i];
	}
	merge_sort(0, n);

	cout << count << endl;
}

Measured memory_bytes: 2720
#--import&define---------------------
import math

def yes():
    print("Yes")
def no():
    print("No")
#--my_library--------------------------------
#mapを利用した入力
# x,y = map(int,input().split())

#forを利用した入力
#l = []
#for i in range():
#    l.append(int(input()))
#--以下解答---------------------------------
x = input()
x = list(map(int,x.split()))
ans = 0
for i in range(3):
  ans += x[i]

if ans >= 22:
    print("bust")
else:
    print("win")



Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define f first
#define s second
using namespace std;

int h,w,ii,jj;
int X[8]={-1,1,-1,1,0,-1,0,1};
int Y[8]={-1,1,1,-1,1,0,-1,0};
char Donut[10][20];
vector<string> V;
string maxs;
map<string,pair<int,int> > M;

void Check(string s)
{
  if(maxs.length()<s.length())maxs=s;
  else if(maxs.length()==s.length()){
    if(maxs>s)maxs=s;
  }
}

void make(int x,int y)
{
  for(int k=0;k<8;k++){
    string S="";
    int a=x,b=y;
    S+=Donut[a][b];
    while(1){
      a+=Y[k];
      b+=X[k];
      if(a==-1)a=h-1;
      if(b==-1)b=w-1;
      if(a==h)a=0;
      if(b==w)b=0;
      if(a==x && b==y)break;
      S+=Donut[a][b];
      if(M[S].f==0 && M[S].s==0){
	M[S].f=x+1;
	M[S].s=y+1;
      }
      else {
	Check(S);
      }
    }
  }
}

int main()
{
  while(1){
    cin>>h>>w;
    if(h+w==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cin>>Donut[i][j];
    }
    M.clear();
    maxs="";
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	make(i,j);
      }
    }
    if(maxs=="")cout<<0<<endl;
    else cout<<maxs<<endl;
  }
  return 0;
}

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

int main () {
  string N;
  cin >> N;
  
  int64_t n= N.size(),ans=0;
  
  for (int tmp = 0; tmp < (1 << (n-1)); tmp++) {
    bitset<12> s(tmp); 
    
    int64_t sum = 0,t=N.at(0)-'0';
    
    for (int i = 0; i < n-1; i++) {
      if (s.test(i)) {
        t = (t*10)+N.at(i+1)-'0';
        
      }else{
        sum+=t;
        t=N.at(i+1)-'0';
      }
    }
    ans +=(sum+t);
  }
  cout << ans << endl;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, cox[100001], coy[100001];
P mx1, my1, mx2, my2;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		if(i%2){
			cox[x]++;
		}else{
			coy[x]++;
		}
	}
	for(int i=1;i<100001;i++){
		if(cox[i]>mx2.first){
			if(cox[i]>mx1.first){
				mx2 = mx1;
				mx1 = {cox[i], i};
			}else{
				mx2 = {cox[i], i};
			}
		}
		if(coy[i]>my2.first){
			if(coy[i]>my1.first){
				my2 = my1;
				my1 = {coy[i], i};
			}else{
				my2 = {coy[i], i};
			}
		}
	}
	if(mx1.second==my1.second){
		cout << n - max(mx1.first+my2.first, my1.first+mx2.first) << endl;
	}else{
		cout << n - mx1.first - my1.first << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000

ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }

#define M_PI       3.14159265358979323846   // pi
int main() {
	double a, b, x, l;
	scanf("%lf%lf%lf", &a,&b, &x);
	if (a * a * b / 2 > x) {
		printf("%.10f", 90 - atan(2 * x / (a * b * b)) * 180 / M_PI);
	}
	else {
		l = (b - x / pow(a, 2)) * 2;
		printf("%.10f", atan(l / a) * 180 / M_PI);
	}
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

 int main(void)
 {

 int tmp, n, i,max=-2147483,min=2147483;
 long long sum = 0;
 scanf("%d", &n);
for(i = 0; i < n; i++){
 scanf("%d", &tmp);
 sum += tmp;
 if(max<tmp){
     max=tmp;
 }
 if(tmp<min){
     min=tmp;
 }
 }

 printf("%d %d %lld\n",min,max,sum);

 return (0);
 }


Measured memory_bytes: 2104
n,m = map(int, input().split())
a = [int(a) for a in input().split()]
l = [0,2,5,5,4,5,6,3,7,6]
a.sort(reverse=True)
dp = [0]+[-1]*n
for i in range(1,n+1):
    for j in a:
        if l[j] <= i:
            dp[i] = max(dp[i], dp[i-l[j]]*10+j)
print(dp[-1])

Measured memory_bytes: 14692
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    int count = 0;
    for(int i = 0;i < 3;i++){
        if(S.at(i) == 'o'){
            count++;
        }
        else{
        continue;
        }
    }
    cout << 700 + count*100 << endl;
}

Measured memory_bytes: 256
a=gets.split.map(&:to_i)
b=Array.new
b.push((a[0]-a[1]).abs+(a[1]-a[2]).abs)
b.push((a[0]-a[2]).abs+(a[1]-a[2]).abs)
b.push((a[1]-a[0]).abs+(a[0]-a[2]).abs)
b.push((a[1]-a[2]).abs+(a[0]-a[2]).abs)
b.push((a[2]-a[0]).abs+(a[1]-a[0]).abs)
b.push((a[2]-a[1]).abs+(a[1]-a[0]).abs)
p b.min

Measured memory_bytes: 1788
#include <assert.h>
#include <stdio.h>
#pragma GCC optimize ("O3")

int main() {
  unsigned int k, n, i, first, last, a, max = 0;
  assert(scanf("%d %d", &k, &n) == 2);
  assert(scanf("%d", &first) == 1);
  last = first;
  for (i = 1; i < n; i++) {
    assert(scanf("%d", &a) == 1);
    a = a - last;
    last += a;
    if (max < a) {
      max = a;
    }
  }
  a = k - (last - first);
  if (max < a) {
    max = a;
  }
  printf("%d\n", k - max);
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {




        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                string[] strs = line.Split(' ');
                int n = int.Parse(strs[0]);
                int m = int.Parse(strs[1]);
                int p = int.Parse(strs[2]);
                if (n == 0) { break; }
                int[] kakefuda = new int[n];

                int total = 0;


                for (int i = 0; i < n; i++) {
                    kakefuda[i] = int.Parse(Console.ReadLine());
                    total += kakefuda[i] * 100;
                }

                if (kakefuda[m - 1] == 0) { Console.WriteLine(0); }
                else { Console.WriteLine((total - (total * p / 100)) / kakefuda[m - 1]); }


                    






            }
        }

        


    }
}

Measured memory_bytes: 5700
#include <bits/stdc++.h>
#define inf (long long)(1e17)
using namespace std;

long long n, x;

struct dat {
  long long b, l, u;
  dat(long long _b = 0, long long _l = 0, long long _u = 0)
      : b(_b), l(_l), u(_u) {}
  bool operator<(const dat &r) const {
    return b * l + (x - b) * u > r.b * r.l + (x - r.b) * r.u;
  }
};

long long sum = 0;
vector<dat> v;

long long solve();
bool ch(long long p);

int main() {
  cin >> n >> x;
  v.resize(n);
  for (auto &p : v) {
    cin >> p.b >> p.l >> p.u;
    sum += p.b * p.l;
  }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  if (!sum) return 0;
  long long lef = 0, righ = n * x;
  while (righ - lef > 1) {
    long long mid = (lef + righ) / 2;
    if (ch(mid))
      righ = mid;
    else
      lef = mid;
  }
  return righ;
}

bool ch(long long p) {
  long long all = p / x, now = sum;
  p %= x;
  for (int i = 0; i < all; ++i) now -= v[i].u * (x - v[i].b) + v[i].l * v[i].b;
  if (now <= 0) return 1;
  for (int i = 0; i < n; ++i) {
    if (i < all) {
      now += v[i].u * (x - v[i].b) + v[i].l * v[i].b;
      now -= v[all].u * (x - v[all].b) + v[all].l * v[all].b;
    }
    now -= v[i].l * min(p, v[i].b) + v[i].u * (p - min(p, v[i].b));
    if (now <= 0) return 1;
    now += v[i].l * min(p, v[i].b) + v[i].u * (p - min(p, v[i].b));
    if (i < all) {
      now -= v[i].u * (x - v[i].b) + v[i].l * v[i].b;
      now += v[all].u * (x - v[all].b) + v[all].l * v[all].b;
    }
  }
  return 0;
}

Measured memory_bytes: 5568
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<functional>
#include<fstream>

using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int r;
int w[2],h[2];
int x[2],y[2];
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};
int field[2][501][501];
bool used[2][501][501];
int INF=300000000;
int dp[2][100001];
int ans;

void dfs(int i,int sx,int sy){
	priority_queue<PP , vector<PP> , greater<PP> > que;
	int fl=1;
	que.push(PP(field[i][sx][sy],P(sx,sy)));
	used[i][sx][sy]=true;
	while(que.size() && fl<=100000){
		PP q=que.top();que.pop();
		int c=q.first;
		int mx=q.second.first,my=q.second.second;
		dp[i][fl]=max(dp[i][fl-1],c);
		fl++;
		for(int j=0;j<4;j++){
			int nx=mx+dx[j],ny=my+dy[j];
			if(nx>=0 && nx<w[i] && ny>=0 && ny<h[i] && used[i][nx][ny]==false){
				que.push(PP(field[i][nx][ny],P(nx,ny)));
				used[i][nx][ny]=true;
			}
		}
	}
}

int main(void){
	int st2=1;
	while(1){
		cin >> r;
		if(r==0)break;
		for(int i=1;i<=100000;i++)dp[0][i]=dp[1][i]=INF;
		dp[0][0]=dp[1][0]=0;
		memset(field,0,sizeof(field));
		memset(used,false,sizeof(used));
		cin >> w[0] >> h[0] >> x[0] >> y[0];
		for(int i=0;i<h[0];i++){
			for(int j=0;j<w[0];j++){
				cin >> field[0][j][i];
			}
		}
		cin >> w[1] >> h[1] >> x[1] >> y[1];
		for(int i=0;i<h[1];i++){
			for(int j=0;j<w[1];j++){
				cin >> field[1][j][i];
			}
		}
		for(int i=0;i<2;i++)dfs(i,x[i]-1,y[i]-1);
		ans=INF;

		for(int i=0;i<=r;i++){
			ans=min(ans,dp[0][i]+dp[1][r-i]);
		}
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 4700
# e 数位dp 还可以从右到左
# 参考 https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2019-02-16abc-155
# https://atcoder.jp/contests/abc155/submissions/10155415
# in your code
import numpy as np
DBG=0
def p(*args, **kargs):
    if DBG:print(*args, **kargs)
read = input 
rn = lambda :list(map(int, read().split()))

def sol(s):
    dp = 0, 1 # n, n + 1
    for x in map(int, s):
        c, d = dp
    #                     为什么这里x = 0的时候不受影响 c+0 << d+10，因为abs(c-d) < 1
        
        #    前一位没借位  前一位借位
        a = min(c + x,    d + 10 - x)# for ...n
        #    这里x=9为什么不受影响, c+10 >> d，因为abs(c-d) < 1
        b = min(c + x + 1,d + 10 - 1 - x )# for ...(n+1)
        
        # 因为a,b相差小于1。f(n), f(n+1)相差总是小于1，多给1元即可
        dp = a,b
        p(dp)
    return dp[0]
if DBG:
    pass
#     sol("100")
#     assert 8 == sol("36")
#     assert sol("91") == 3
#     assert 243 == sol("314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170")
print(sol(read()))

Measured memory_bytes: 16096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll n;cin >> n;
    vl a(n),b(n);
    vpl d(n);
    rep(i,n)cin >> a[i] >> b[i];
    rep(i,n)d[i].fi=a[i]+b[i],d[i].se=i;
    sort(all(d));rev(all(d));
    ll x=0,y=0;
    rep(i,n){
        if(i%2==0)x+=a[d[i].se];
        else y+=b[d[i].se];
    }
    cout << x-y <<endl;
}

Measured memory_bytes: 6404
x = [i for i in input()]
judge = 0
if x[0] == "A" :
  judge += 1
  if x[2:-1].count("C") == 1:
    judge += 1
    x.remove("A")
    x.remove("C")
    if "".join(x).islower():
      judge += 1
if judge == 3:
  print("AC")
else:
  print("WA")
    


Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 20
#define MAXM 1048600
#define MO 1000000007
int dp[2][MAXN+1][MAXM],n,m,k,tot,ans,c[MAXN+5][MAXN+5],nxt[MAXM][MAXN];
inline void Add(int &a,int b)
{
	a+=b;
	if(a>=MO) a-=MO;
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1,a,b;i<=k;i++)
	{
		scanf("%d%d",&a,&b);
		scanf("%d",&c[a][b-1]);
		c[a][b-1]++;
	}
	tot=1<<(n-1);
	for(int s=0;s<tot;s++)
		for(int j=0;j<n;j++)
			if(!((s>>j)&1))
			{
				nxt[s][j]=s|(1<<j);
				for(int l=j+1;l<n;l++)
					if((s>>l)&1)
					{
						nxt[s][j]^=(1<<l);
						break;
					}
			}
	dp[0][n][0]=1;
	for(int i=1,f;i<=m;i++)
	{
		f=i&1;
		for(int s=0;s<tot;s++) dp[f][0][s]=dp[!f][n][s];
		for(int j=1;j<=n;j++)
			for(int s=0;s<tot;s++) dp[!f][j][s]=0;
		for(int j=0;j<n;j++)
			for(int s=0;s<tot;s++)
				if(dp[f][j][s])
				{
					if(c[i][j]!=2&&((s>>j)&1)==0)
						(dp[f][j+1][s]+=dp[f][j][s])%=MO;
					if(c[i][j]!=1)
					{
						if((s>>j)&1) (dp[f][j+1][s]+=dp[f][j][s])%=MO;
						else (dp[f][j+1][nxt[s][j]]+=dp[f][j][s])%=MO;
					}
				}
	}
	int f=m&1;
	for(int s=0;s<tot;s++)
		(ans+=dp[f][n][s])%=MO;
	printf("%d\n",ans);
}

Measured memory_bytes: 215296
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
char a , b;
int ans = 0;
int main()
{
	while(cin >> a >> b){
	ans = 0;
	if(a == 'D') ans++;
	if(b == 'D') ans++;
	if(ans & 1) cout << 'D' << endl;
	else cout << 'H' << endl;
	}
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
S = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
mod = 10 ** 9 + 7
sum_dp = []
for i in range(N+1):
    sum_dp.append([0] * (M+1))

temp = 0
for i in range(1, N+1):
    for j in range(1, M+1):
        temp = 0
        if(S[i] == T[j]):
            temp = sum_dp[i-1][j-1] + 1
        sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp) % mod

print(sum_dp[N][M] + 1)


Measured memory_bytes: 73820
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		long[] ary=new long[N+2];
		ary[0]=0;
		for(int i=1; i<=N; i++) {
			ary[i]=sc.nextLong();
		}
		ary[N+1]=0;
		long sum=0;
		long ans=0;
		for(int i=0; i<=N+1; i++) {
			if(ary[i]==0) {
				ans+=sum/2;
				sum=0;
			}
			else {
				sum+=ary[i];
			}
		}
		pl(ans);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 37344
#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long n) {
  if (n < 2 or n > 2 and n % 2 == 0) return false;
  for (long long i = 3; i * i <= n; i += 2) if(n % i == 0) return false;
  return true;
}
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  vector<bool> b(1e5 + 10, false);
  for (int i = 3; i < 1e5; i += 2) {
    if (is_prime(i) and is_prime((i + 1) / 2)) b[i] = true;
  }
  vector<int> csum(1e5 + 10, 0);
  for (int i = 3; i < 1e5 + 10; i += 2) {
    csum[i] = csum[i - 2] + b[i];
  }
  int q; cin >> q;
  vector<int> l(q), r(q); for (int i = 0; i < q; i++) cin >> l[i] >> r[i];
  for (int i = 0; i < q; i++) {
    cout << csum[r[i]] - csum[max(l[i] - 2, 0)] << '\n';
  }
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[5][5];
bool vis[5][5];
int main(){
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int x;
		cin>>x;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(a[j][k]==x){
					vis[j][k]=1;
				}
			}
		}
	}
	bool flag=0;
	if(vis[0][0]&&vis[0][1]&&vis[0][2])flag=1;
	else if(vis[1][0]&&vis[1][1]&&vis[1][2])flag=1;
	else if(vis[2][0]&&vis[2][1]&&vis[2][2])flag=1;
	else if(vis[0][0]&&vis[1][0]&&vis[2][0])flag=1;
	else if(vis[0][1]&&vis[1][1]&&vis[2][1])flag=1;
	else if(vis[0][2]&&vis[1][2]&&vis[2][2])flag=1;
	else if(vis[0][0]&&vis[1][1]&&vis[2][2])flag=1;
	else if(vis[0][2]&&vis[1][1]&&vis[2][0])flag=1;
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
T = input()
M = len(T)

st = -1

for i in range(N-M, -1, -1):
  if all(S[i+j] in (T[j], "?") for j in range(M)):
    st = i
    break

newS = S.replace("?", "a")

if st == -1:
  print("UNRESTORABLE")
else:
  ans = ""
  for i in range(N):
    if st <= i <= st+M-1:
      ans += T[i-st]
    else:
      ans += newS[i]
  print(ans)

Measured memory_bytes: 8988
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    if N >= M:
        print(0)
    else:
        X.sort()
        diff = [y-x for x,y in zip(X[0:M-1], X[1:])]
        diff.sort()
        ans = sum(diff[:M-N])
        print(ans)

if __name__ == "__main__":
    main()

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

int main () {
 int W, H, x, y, r;
 cin >> W >> H >> x >> y >> r;
    
    if ( 0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H ){
        cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    
    return 0;
}    

Measured memory_bytes: 1160
s=input()
t=input()
if s==t:
    print('No')
    exit()
s=list(s)
t=list(t)
s=sorted(s)
t=sorted(t,reverse=True)

s=''.join(list(s))
t=''.join(list(t))
l=[s,t]
l.sort()
if l[0]==s:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
N, T = gets.split.map(&:to_i)
T_LIST = gets.split.map(&:to_i)

ans = 0

T_LIST.each_with_index do |t, i|
  if i != N - 1
    ans += [T_LIST[i + 1] - t, T].min
  else
    ans += T
  end
end

puts ans


Measured memory_bytes: 19844
#include <stdio.h>

int main()
{
int a[4][13]={0};
int i, j, k, x, n;
char m;

scanf("%d", &n);

for(k = 0; k < n; k++){
scanf(" %c%d", &m, &x);
if(m == 'S')
a[0][x - 1] = 1;
else if(m == 'H')
a[1][x - 1] = 1;
else if(m == 'C')
a[2][x - 1] = 1;
else if(m == 'D')
a[3][x - 1] = 1;
}

for(i = 0; i < 4; i++){
for(j = 0; j < 13; j++){
if(a[i][j] == 0){
if(i == 0)
printf("S %d\n", j + 1);
else if(i == 1)
printf("H %d\n", j + 1);
else if(i == 2)
printf("C %d\n", j + 1);
else if(i == 3)
printf("D %d\n", j + 1);
}
}
}
return 0;
}


Measured memory_bytes: 2044
package main

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

var sc = bufio.NewScanner(os.Stdin)

type task struct{
	name string
	time int 
}

func scan() task{
	sc.Scan()
	var t task
	input := strings.Split(sc.Text(), " ")
	name, time_s := input[0], input[1]
	time, _  := strconv.Atoi(time_s)
	t.name, t.time = name, time
	return t
}

func deque(list *[]task, point *int) task{
	t := (*list)[*point]
	*point++
	return t
}
func main(){
	var n, q, time, point, cnt int
	fmt.Scan(&n, &q)
	list := make([]task, n, 50000)
	for i:=0; i<n; i++{
		list[i] = scan()
	}
	for{
		t := deque(&list, &point)
		if t.time > q{
			t.time -= q
			time += q
			list = append(list, t)
		} else {
			time += t.time
			cnt++
			fmt.Println(t.name, time)
		}
		if cnt == n{
			break
		}
	}
}


Measured memory_bytes: 18500
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
// #define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

ll mod;
// 繰り返し二乗法 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    mod=2019;ll p=2019;
    string s;cin>>s;
    ll n=(ll)s.size();


    if(p==2){
        ll ans=0;
        reverse(ALL(s));
        rep(i,n){
            if((s[i]-'0')%2==0){
                ans+=n-i;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    if(p==5){
        ll ans=0;
        reverse(ALL(s));
        rep(i,n){
            if((s[i]-'0')%5==0){
                ans+=n-i;
            }
        }
        cout<<ans<<endl;
        return 0;
    }



    reverse(ALL(s));
    ll num=0;
    vector<ll> a(n+1);a[0]=0;
    rep(i,n){
        num=num+pow_mod(10%p,i)*(s[i]-'0')%mod;
        num%=mod;
        a[i+1]=num;
    }
    vector<ll> cnt(p+1,0);
    rep(i,n+1) cnt[a[i]]++;
    ll ans=0;
    rep(i,p){
        ans+=cnt[i]*(cnt[i]-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

/*
6 7 
389675
*/


Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
double calc(double x1, double y1, double x2, double y2)
{
	return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int main()
{
	boost;
	int n, i;
	cin >> n;
	vector <pair <int, int> > v(n);
	fo(i, 0, n)
	cin >> v[i].f >> v[i].s;
	int ind[n];
	fo(i, 0, n)
	ind[i] = i;
	double ans = 0;
	int cnt = 0;
	do
	{
		double res = 0;
		fo(i, 0, n - 1)
		res += calc((double)v[ind[i]].f, (double)v[ind[i]].s, (double)v[ind[i + 1]].f, (double)v[ind[i + 1]].s);
		ans += res;
		cnt++;
	}while(next_permutation(ind, ind + n));
	ans /= (double)cnt;
	cout << fixed << setprecision(10) << ans;
}

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

string S, T;

int main() {
  cin >> S >> T;
  cout << T << S << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int i = 0; 7*i<=n; i++){
    if((n - 7*i)%4==0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
def binary(n, k):
  cnt = 0
  while 1 <= n <= k-1:
    cnt += 1
    n *= 2
    if n >= k:
      break
  return cnt
ans = 0
for i in range(1, n+1):
  ans += (1/n)*(1/2)**(binary(i, k))
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vct vector<ll>
#define umap unordered_map<ll,ll>
#define mpp map<ll,ll>
#define stt set<ll>
#define pir pair<ll,ll>
#define vpp vector<pair<ll,ll> >

ll poww(ll x,ll y,ll m){   
    ll res=1;
    while(y){if(y%2==0){x=(x*x)%m;y=y/2;}else{res=(res*x)%m;y--;}}
    return res;
}
void prt(vct v)
{
    // cout<<"\n";
    for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
    cout<<"\n";
    
}
vct siev(ll n)
{
    vct ans;ll ar[n+1];
    memset(ar,-1,sizeof(ar));ar[0]=0;ar[1]=0;
    for(ll i=2;i<=n;i++)
    {if(ar[i]==-1){ans.push_back(i);ar[i]=1;for(ll j=2*i;j<=n;j=j+i)ar[j]=0;}}
    return ans;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)if(n%i==0)return false;
    return true;
}

vct divsors(ll n)
{
    vct ans;ans.push_back(1);
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ans.push_back(i);
            if(i!=(n/i))ans.push_back(n/i);
        }
    }
    return ans;
}
ll cnd(ll n){ll cnt=0;while(n){cnt++;n=n/10;}return cnt;}

ll fibdig(ll n)
{
    if (n == 1) 
        return 1; 
    long double d = (n * log10(1.6180339887498948)) -((log10(5)) / 2);
    return ceil(d); 
}


ll t;ll n,m,k;
// vct v;
ll t1,t2;
ll mod=1000000007;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // setprecision(10);
    cin>>n;
    vpp v;
    for(ll i=0;i<n;i++)
    {
        cin>>t;
        v.push_back({t,i+1});
    }
    sort(v.begin(),v.end());
    for(ll i=0;i<n;i++)
    {
        cout<<v[i].second<<" ";
    }
}

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

int main() {
	int A, B, K;
	int count = 0;
	int ans;

	cin >> A >> B >> K;

	int tmp = min(A,B);
	while (count < K) {
		if (A % tmp == 0 && B % tmp == 0) {
			count++;
			ans = tmp;
		}
		tmp--;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);lin(M);lin(K);
  bool OK=false;
  
  rep(i,N+1){
    rep(j,M+1){
      if(K==i*M+j*N-2*i*j) OK=true;
    }
  }
  
  if(OK)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
def is_sorted(t_list):
    for i in range(len(t_list)):
        if t_list[i] != i + 1:
            return False
    return True


n = int(input())
p_list = list(map(int, input().split()))
ret = False

if is_sorted(p_list):
    print('YES')
    exit()

for i in range(n):
    for j in range(i+1, n):
        p_list[i], p_list[j] = p_list[j], p_list[i]
        if is_sorted(p_list):
            print('YES')
            exit()
        else:
            p_list[i], p_list[j] = p_list[j], p_list[i]

print('NO')


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

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

    string S;
    cin >> S;

    int win = 0;
    int lose = 0;
    for (auto s: S) {
        win += s == 'o';
        lose += s == 'x';
    }

    if (lose >= 8) {
        cout << "NO" << '\n';
    } else {
        cout << "YES" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<set>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second
 
using namespace std;

int main(){
  string s;
  cin >> s;
  Srep(5) cout << s[i];
  cout << ' ';
  Lrep(i,6,13) cout << s[i];
  cout << ' ';
  Lrep(i,14,19) cout << s[i];
}

Measured memory_bytes: 3612
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 0
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll a[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

ll f(ll x) {
    ll res = 0;

    forn (i, n)
        res += abs(a[i] - x);

    return res;
}

void solve() {
    forn (i, n)
        a[i] -= i + 1;

    sort(a, a + n);
    cout << f(a[n / 2]) << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N;

  void init() {
    scanf("%lld", &N);
  }

  void solve() {
    if(N==1) {
      printf("Yes\n2\n1 1\n1 1\n");
      return;
    }
    vector<vector<ll> > vec;
    vec.push_back({1, 2});
    vec.push_back({2, 3});
    vec.push_back({3, 1});
    ll cur = 3, d = 3;
    while(cur < N) {
      ll s = cur;
      for(auto& v : vec) {
        v.push_back(++s);
      }
      vector<ll> v;
      for(ll i = cur+1; i<=cur+d; i++) {
        v.push_back(i);
      }
      vec.push_back(v);
      cur += d;
      d++;
    }
    if(cur!=N) {
      printf("No\n");
      return;
    }
    printf("Yes\n");
    printf("%lld\n", vec.size());
    for(const auto& v : vec) {
      printf("%lld", v.size());
      for(const auto& t : v) {
        printf(" %lld", t);
      }
      printf("\n");
    }
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 3840
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#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++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

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

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + k)
sa = [0] * n
for i in range(1, n+1):
    sa[i - 1] = a[i] - a[i - 1]
print(sum(sa) - max(sa))

Measured memory_bytes: 77644
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

    if(n[n.size()-1] == '3')  cout<<"bon"<<endl;
    else if(n[n.size()-1] =='0'|| n[n.size()-1] =='1'||n[n.size()-1] =='6'|| n[n.size()-1] =='8')   cout<<"pon"<<endl;
    else    cout<<"hon"<<endl;


 return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int r;
	cin >> r;
	double area = 2.0 * (22.0/7.0) * r;
	cout << fixed << setprecision(10) << area;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC150(void);
void ABC151(void);
void ABC152(void);
void ABC153(void);
void ABC154(void);
void ABC155(void);
void ABC156(void);
void ABC157(void);
void ABC158(void);
void ABC159(void);

int main(void){
    ABC152();
}

void ABC152(){
    int a,b;
    cin>>a>>b;
    for(i=0;i<max(a,b);i++){
        cout<<min(a,b);
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int n,k; cin >> n >> k;
  vi p(n); rep(i,n) cin >> p[i];
  sort(all(p));
  int ans = 0;
  rep(i,k) ans += p[i];
  cout << ans;
}


Measured memory_bytes: 3632