akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
int main() {
    int soo=1;
    while(soo==1){
    int n, m; int ans = 0;
	cin >> m;
	if(m==0){
	    soo=0;
	}
	else{
	 vector<int> sex(m);
	vector<int> sey(m);
	for (int i = 0; i < m; i++) {
		cin >> sex[i] >> sey[i];
	}
	cin >> n;
	vector<int> hox(n);
	vector<int> hoy(n);
	for(int i = 0; i < n; i++) {
		cin >> hox[i] >> hoy[i];
	}
	int das1 = 1;
	for (int i = 0; i < n and das1==1; i++) {
		int x = hox[i] - sex[0];//iは0に合わせるもの
		int y = hoy[i] - sey[0];
		int ok = 1;
		int das2=1;
		for (int j = 0; j < m and das2==1; j++) {
			int sx = sex[j] + x;
			int sy = sey[j] + y;
			int das3 = 0;
			for (int k = 0; k < n and das3 == 0; k++) {
				if (sx == hox[k] and sy == hoy[k]) {
					das3 = 1;
				}
			}
			if (das3 == 0) {
				das2 = 0;
			}

		}
		if (das2 == 1) {
			das1 = 0;
			cout << x << " " << y<<endl;
		}   
    }   
	}
	}
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
//const int maxn 2000;

int main(){
	int n,m,x,number;
	int l_money=0,r_money=0;
	cin>>n>>m>>x;
   	int a[n+1];
   	memset(a,0,n+1);
   	for(int i=0;i<m;i++)
   	{
   		cin>>number;
		a[number]=1;
   	}
   	for(int i=x;i>0;i--) if(a[i]==1) l_money++;
   	for(int i=x;i<n;i++) if(a[i]==1) r_money++;
   	cout<<min(l_money,r_money)<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from enum import Enum

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import product
    n = int(readline())
    s = input()

    for a, b in product(("S", "W"), repeat=2):
        kinds = [""] * n
        kinds[0] = a
        kinds[1] = b

        for i in range(1, n - 1):
            if kinds[i] is "S":
                if s[i] == "o":
                    kinds[i + 1] = kinds[i - 1]
                else:
                    if kinds[i - 1] == "S":
                        kinds[i + 1] = "W"
                    else:
                        kinds[i + 1] = "S"
            else:
                if s[i] == "o":
                    if kinds[i - 1] == "S":
                        kinds[i + 1] = "W"
                    else:
                        kinds[i + 1] = "S"
                else:
                    kinds[i + 1] = kinds[i - 1]
        ff = (s[n - 1] == "o") ^ (kinds[n - 1] == "W")
        fs = (s[0] == "o") ^ (kinds[0] == "W")
        f1 = False
        f2 = False
        if ff and (kinds[n - 2] == kinds[0]):
            f1 = True
        if not ff and (kinds[n - 2] != kinds[0]):
            f1 = True
        if fs and (kinds[n - 1] == kinds[1]):
            f2 = True
        if not fs and (kinds[n - 1] != kinds[1]):
            f2 = True

        if f1 and f2:
            res = "".join(kinds)
            print(res)
            sys.exit()
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77476
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
/////////////////////////(๑•﹏•๑｀)/////////////////////////
///AtCoder Beginner Contest 102///

int main() {
	int N; SCD(N);
	int M,m;
	M = 0; m = 1000000003;

	REP(i,N){
		int x; SCD(x);
		M = max(M,x);
		m = min(m,x);
	}
	PRINTD(M-m);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string lcs(string s,string s1)
{
int dp[s.length()+1][s1.length()+1];
for(int i=0; i<=s.length(); ++i)
{
for(int j=0; j<=s1.length(); ++j)
{
if(i==0||j==0)
dp[i][j]=0;
else if(s[i-1]==s1[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
int index = dp[s.length()][s1.length()];
char Lcs[index+1];
Lcs[index] = '\0';
int i = s.length(), j = s1.length();
while (i > 0 && j > 0)
{
if(s[i-1] == s1[j-1])
{
Lcs[index-1] = s[i-1];
i--; j--; index--;
}
else if (dp[i-1][j] > dp[i][j-1])
i--;
else
j--;
}
return Lcs;
}
int main()
{
string s,s1;
cin>>s>>s1;
cout<<lcs(s,s1);
}


Measured memory_bytes: 35456
n=STDIN.gets.to_i
t=0
h=0
n.times {
  s=STDIN.gets.split
  if(s[0].to_s > s[1].to_s)
    t += 3
  elsif(s[0].to_s < s[1].to_s)
    h += 3
  else
    t += 1
    h += 1
  end
}
printf("%d %d\n",t,h)

Measured memory_bytes: 8660
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int a,p;
    cin>>a>>p;
    a*=3;
    a+=p;
    cout<<a/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 200001;
const ll M = 1;
struct point {
    ll x, y;
    ll i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

vector<int> p;
void soe(int n = 1000001)
{
    bool P[n];
    P[0] = P[1] = 1;
    for(int i = 2; i < n; i++)
    {
        if(!P[i])
        {
            p.pb(i);
            for(int j = i + i; j < n; j += i)
            P[j] = 1;
        }
    }
}

ll fact[N], infact[N];
void work()
{
    fact[0] = fact[1] = infact[0] = infact[1] = 1;
    for(ll i = 2; i < N; i++)
    {
        fact[i] = fact[i - 1] * i % mod;
        infact[i] = fast_exp(fact[i], mod - 2);
    }
}

ll ncr(ll n,ll r)
{
    return fact[n] * infact[r] % mod * infact[n - r] % mod;
}

int main()
{
    fast;
    int _ = 1;
    work();
    //cin >> _;
    while(_--)
    {
        ll n, m, x = 0, y = 0, ans = 0, k = 0;
        cin >> n >> m >> k;
        for(int i = 0; i <= k; i++)
            ans = (ans + m * fast_exp(m - 1, n - i - 1) % mod * ncr(n - 1, i) % mod) % mod;
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
int h,w,n,a[10010],ans[110][110];
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int i=1,j=1,cnt=1;
	for (int k=0;k<h*w;k++)
	{
		ans[i][j]=cnt;
		a[cnt]--;
		if (!a[cnt])
		{
			cnt++;
		}
		if (i&1)
		{
			j++;
			if (j>w)
			{
				j=w;
				i++;
			}
		}
		else
		{
			j--;
			if (!j)
			{
				j=1;
				i++;
			}
		}
	}
	for (i=1;i<=h;i++)
	{
		for (j=1;j<=w;j++)
		{
			printf("%d ",ans[i][j]);
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int A,B,C;
  int v1,v2;
  
  scanf("%d %d %d", &A, &B, &C);
  v1 = A-B;
  v2 = C-v1;
  
  if(v2 > 0){
    printf("%d\n", v2);
  }
  else printf("0\n");
  
  return 0;
}


Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
//#include<unordered_map>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=2e5+5;
const int mod=998244353;
struct Node{
    int x,d;
}e[maxm];
int d[maxm];
int n;
bool cmp(Node a,Node b){
    return a.x<b.x;
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>e[i].x>>e[i].d;
    }
    sort(e+1,e+1+n,cmp);
    d[n]=2;
    stack<int>s;
    s.push(n);
    for(int i=n-1;i>=1;i--){
        while(!s.empty()&&e[i].x+e[i].d>e[s.top()].x)s.pop();
        d[i]=d[i+1];
        if(!s.empty())d[i]=(d[i]+d[s.top()])%mod;
        else d[i]=(d[i]+1)%mod;
        s.push(i);
    }
    cout<<d[1]<<endl;
    return 0;
}


Measured memory_bytes: 5760
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str):
    l = len(S)
    h = 0
    for i in range(l//2):
        if S[i]!=S[-(i+1)]:
            h+=1

    print(h)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12448
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  u64 size = s.size();
  u64 isg = 0;
  for (u64 i = 0; i < size; ++i) {
    if (s[i] == 'g') isg++;
  }
  cout << (isg-(size-isg))/2 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
  long n;
  long a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  long x = a - b;
  for (long long i=0;i<=n;i++) {
    long long m = d * (n-1-i) - c * i;
    long long l = c * (n-1-i) - d * i;
    if (m >= x && x >= l) {
      cout << "YES" << endl;
      return(0);
    }
  }
  cout << "NO" << endl;
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int big,regu,nob,ci,su,t;
    while(cin>>big>>regu>>nob>>ci>>su>>t,big,regu,nob,ci,su,t)
        cout<<100+ci*2+nob*7+regu*63+big*95-(t-su)*3<<endl;

}

Measured memory_bytes: 1160
import sys
import math
#a,b= map(int,input().split())
#li= [int(x) for x in input().split()]
dance=list(input())
i=0
for i in range(len(dance)):
  if i%2==0:
    if dance[i]=='L': 
      print("No")
      sys.exit()
  else:
    if dance[i]=='R':
      print("No")
      sys.exit()
print('Yes')
    




Measured memory_bytes: 3060
////////////////////////////////////////////////////////////////////////
//ファイル名：ITP_1_6_D_Matrix Vector Multiplication.c
//内容；行列ベクトル計算を行うプログラム
//
//入力：n × mの行列A、mの列ベクトルB
//
//出力：行列の計算結果を出力
//
//制約：n ≧ 0
////////////////////////////////////////////////////////////////////////

#include <stdio.h>

#define MATRIX_NUM_MAX 100

int main(void)
{
    //変数の宣言
    int i,j,a,b,n,m;

    int A[MATRIX_NUM_MAX][MATRIX_NUM_MAX] = {0};
    int B[MATRIX_NUM_MAX] = {0};
    int c[MATRIX_NUM_MAX] = {0};   

    //行列の長さの決定
    scanf("%d %d \n", &n, &m);

    //行列Aの要素を入力
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            scanf("%d", &a);
            A[i][j] = a;
        }
    }

    //列ベクトルBの要素を決定
    for(i=0; i<m; i++)
    {
        scanf("%d", &b);
        B[i] = b;
    }

    //行列の計算
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            c[i] = c[i] + A[i][j]*B[j];
        }
    }

    //計算結果の出力
    for(i=0; i<n; i++)
    {
        printf("%d\n", c[i]);
    }

    return 0;
}


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

int main(){
    int m;
    int n; cin >> n;
    vector<int> h(n); rep(i,n) cin >> h.at(i);
    
    m = h.at(0);

    for(int i = 0; i < n-1; i++){
        if(h.at(i) > m){
            m = h.at(i) - 1;
        }
        if(h.at(i+1) < m){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  for (int i = 0; i < m; ++i) {
    int s, t;
    cin >> s >> t;
    --s;
    --t;
    to[s].push_back(t);
  }

  double ret = 1e+60;
  for (int z = 0; z < n; ++z) {
    vector<double> dp(n);
    dp[n - 1] = 0;
    for (int i = n - 2; i >= 0; --i) {
      auto& tos = to[i];
      double max_e = -1;
      double sum_e = 0;
      for (int t : tos) {
        double e = dp[t];
        sum_e += e;
        max_e = max(max_e, e);
      }

      int num = tos.size();
      if (num > 1 && i == z) {
        sum_e -= max_e;
        --num;
      }
      dp[i] = sum_e / num + 1;
    }
    ret = min(ret, dp[0]);
  }
  cout << fixed << setprecision(10) << ret << "\n";

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+7;
struct edge {
	int t,nxt;
}e[N];
int n,num;
int fa[N];
#define pii pair<int,int>
#define mk make_pair
queue<pii>q;
map<pii,int>mp;
set<int>s[N];
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
int main() {
	scanf("%d",&n);num=n;
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1,u,v;i<2*n-1;i++) {
		scanf("%d%d",&u,&v);
		s[u].insert(v),s[v].insert(u);
		mp[mk(u,v)]++,mp[mk(v,u)]++;
		if (mp[mk(u,v)]==2) q.push(mk(u,v));
	}
	while (!q.empty()) {
		pii now=q.front();q.pop();
		int u=find(now.first),v=find(now.second);
		num--;fa[v]=u;
		s[u].erase(v);
		set<int>::iterator it;
		for (it=s[v].begin();it!=s[v].end();it++) {
			int to=*it;
			if (to==u) continue;
			s[to].erase(v);
			s[u].insert(to);s[to].insert(u);
			mp[mk(u,to)]++;mp[mk(to,u)]++;
			if (mp[mk(u,to)]==2) q.push(mk(u,to));
		}
		s[v].clear();
	}
	if (num>1) puts("NO");
	else puts("YES");
}

Measured memory_bytes: 61440
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int k = sc.nextInt();
  int count = 0;
  int here = 0;
  for(int i = 0;i < n;i++){
    int a = sc.nextInt();
    count++;
    if(a == 1)here = count;
  }
  int ans = 0;
  int p = here - 1;
  int q = n - here;
  if((p+q) % (k-1) == 0){
    ans += (p+q)/(k-1);
  }
  else{
    ans += (p+q)/(k-1) +1;
  }
  System.out.println(ans);
}}

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

int main() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    long long int ans=0;
    for(int i=1;i<=n;++i)
    {
        if(i%3!=0 && i%5!=0)
        {
            ans+=i;
        }
    }
    cout<<ans<<endl;
  	
   // cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main(void) {
  int i, j, k, n, max = -10e8;
  scanf("%d", &n);
  int p[n][n], sumt[n][n], sumy[n][n];
  for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) {
    scanf("%d", &p[i][j]);
    sumy[i][j] = sumt[i][j] = p[i][j];
  }
  for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) {
    if(i) sumt[i][j] += sumt[i - 1][j];
    if(j) sumy[i][j] += sumy[i][j - 1];
  }
  for(i = 0; i < n; ++i) {
    for(j = i; j < n; ++j) {
      int now = 0, fir = 0;
      if(i == j) {
        for(k = 0; k < n; ++k) {
          now += p[i][k];
          if(max < now) max = now;
          if(now < 0) now = 0;
        }
      } else {
        now = sumt[j - 1][0] - sumt[i][0];
        for(k = 0; k < n; ++k) {
          now += p[i][k] + p[j][k];
          int tmp = now;
          if(k) tmp += sumt[j - 1][k] - sumt[i][k];
          if(max < tmp) max = tmp;
          if(k && now < sumt[j][k] - sumt[i][k] + p[i][k]) now = sumt[j][k] - sumt[i][k] + p[i][k];
          if(max < tmp) max = tmp;
        }
      }
    }
  }
  printf("%d\n", max);
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    bool isodd = false;
    ll mn = 1e9;
    ll sum = 0;
    rep(i,N){
      cin >> A[i];
      if(A[i]<0) isodd = !isodd;
      mn = min(abs(A[i]),mn);
      sum += abs(A[i]);
    }

    if(isodd){
      cout << sum - 2*mn << endl;
    } else {
      cout << sum << endl;
    }
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N;
    private int[] A;
    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }

    private void Swap(ref int a, ref int b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    public void Solve()
    {
        Scan();
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            int minj = i;
            for (int j = i; j < N; j++)
            {
                if (A[j] < A[minj])
                {
                    minj = j;
                }
            }
            if (i != minj)
            {
                cnt++;
                Swap(ref A[i], ref A[minj]);
            }
        }
        Console.WriteLine(string.Join(" ", A.Select(i=>i.ToString()).ToArray()));
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 9568
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ba[j];
    }
    if(all(0,0,0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }else if(ba[end]>l){
    return all(end+1,ba[end],r);
  }else if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll a, b;
    cin>>a>>b;
    if((a+b)%2==0) cout<<(a+b)/2<<endl;
    else cout<<(a+b)/2+1<<endl;
    return 0;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<ll>v[100005];
multiset<ll>st;
signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
      
      ll n;
      cin>>n;
      ll a[n];
      for(int i=1;i<=n;i++)
      {
          cin>>a[i];
      }
      int j=0;
      for(int i=1;i<=n;i++)
      {
          if(i==1)
          {
              v[0].pb(a[i]);
              j++;
              st.insert(a[i]);
          }
          else
          {
              auto it1 = st.lower_bound(a[i]);
              if(it1==st.begin())
              {
                  v[j].pb(a[i]);
                  j++;
                  st.insert(a[i]);
              }
              else
              {
                  it1--;
                  st.erase(it1);
                  st.insert(a[i]);
              }
          }
      }
      cout<<j<<endl;
    
    
}
















Measured memory_bytes: 11136
from collections import defaultdict
dd = defaultdict(lambda:0)
n, k = map(int, input().split())
li = list(map(str, input().split()))
for i in li:
  dd[i] = 1
while True:
  n = str(n)
  b = True
  for i in n:
    if dd[i]==1:
      b = False
      break
  n = int(n)
  if b:
    print(n)
    break
    exit()
  n+=1

Measured memory_bytes: 9408
f=lambda:map(int,input().split())
H,W,M=f()
g=[set() for _ in range(H)]
ch=[0]*H
cw=[0]*W
for _ in range(M):
  h,w=f()
  g[h-1].add(w-1)
  ch[h-1]+=1
  cw[w-1]+=1
mh=max(ch)
mw=max(cw)
lh=[i for i in range(H) if ch[i]==mh]
lw=[i for i in range(W) if cw[i]==mw]
c=mh+mw
for i in lh:
  if len(g[i])<1: exit(print(c))
  for j in lw:
    if j not in g[i]: exit(print(c))
print(c-1)

Measured memory_bytes: 175740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s; cin>>s;
	int N=(int)s.size();
	int A[N+1],C[N+1]; A[0]=0; C[N-1]=0;
	int cnt[N+1]; cnt[0]=0;
	rep(i,1,N+1){
		A[i]=A[i-1]+(s[i-1]=='A' ? 1 : 0);
		C[i]=C[i-1]+(s[i-1]=='C' ? 1 : 0);
		cnt[i]=cnt[i-1]+(s[i-1]=='?' ? 1 : 0);
	}
	long three[2*N]; three[0]=1;
	rep(i,1,2*N) three[i]=(3*three[i-1])%mod;
	long ans=0;
    long a,c;
	rep(i,0,N){
        if(s[i]=='A'||s[i]=='C') continue;
		if(cnt[i]==0) a=A[i];
        else a=three[cnt[i]-1] * (cnt[i]+3*A[i]) %mod;
        if(cnt[N]-cnt[i+1]==0) c=C[N]-C[i+1];
        else c=three[cnt[N]-cnt[i+1]-1] * (cnt[N]-cnt[i+1]+3*(C[N]-C[i+1])) %mod;
		(ans += a*c % mod)%=mod;
        //cout<<a*c % mod<<endl;
	}cout<<ans<<endl;
}

Measured memory_bytes: 3200
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

map<ll,ll>m;
set<ll>s;

int main()
{
	FAST_IO;

 	ll n, ans = 0;
 	cin >> n;
 	ll a[n];
 	for(int i=0;i<n;i++) cin >> a[i], m[a[i]] += 1, s.insert(a[i]);
    for(auto it : s) ans += (m[it] * (m[it] - 1)) / 2;
    for(int i=0;i<n;i++)
    {
    	ll temp = ans;
    	temp -= (m[a[i]] * (m[a[i]] - 1)) / 2;
    	temp += max(0ll, ((m[a[i]] - 1) * (m[a[i]] - 2)) / 2);
    	cout << temp << endl;
    }
    return 0;
}

Measured memory_bytes: 17024
#include<iostream>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b == c || a+c==b || b+c==a){
  	cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
L grid[201][4],n;
int main()
{
    while(scanf("%lld",&n)&&n){
        L rmin=0,rmax=0,cmin=0,cmax=0,id=1,r,c,ni,di;
        for(L i=1;i<n;i++){
            scanf("%lld%lld",&ni,&di);
            if(di==0){
                grid[id][0]=grid[ni][0]-1;
                grid[id][1]=grid[ni][1];
                grid[id][2]=grid[ni][2]-1;
                grid[id][3]=grid[ni][3];

                cmin=min(cmin,grid[id][0]);

            }
            else if(di==1){
                grid[id][1]=grid[ni][1]+1;
                grid[id][0]=grid[ni][0];
                grid[id][2]=grid[ni][2];
                grid[id][3]=grid[ni][3]+1;
                rmax=max(rmax,grid[id][1]);

            }
            else if(di==2){
                grid[id][2]=grid[ni][2]+1;
                grid[id][0]=grid[ni][0]+1;
                grid[id][1]=grid[ni][1];
                grid[id][3]=grid[ni][3];
                cmax=max(cmax,grid[id][2]);

            }
            else {
                grid[id][3]=grid[ni][3]-1;
                grid[id][0]=grid[ni][0];
                grid[id][1]=grid[ni][1]-1;
                grid[id][2]=grid[ni][2];
                rmin=min(rmin,grid[id][3]);

            }
            id++;
        }
        //cout<<rmax<<" "<<rmin<<" || "<<cmax<<" "<<cmin<<endl;
        r=rmax-rmin+1;
        c=cmax-cmin+1;
        printf("%lld %lld\n",c,r);
        memset(grid,0,sizeof(grid));
    }
    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, 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 1; } return 0; }

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    vector<bool>isthere(pow(10,6)+1, false);
    map<int, bool>valid;

    for (int i=0; i<N; i++){
        int ai;
        cin >> ai;
        if (ai <= pow(10,6)){
            if (isthere[ai]){
                isthere[ai] = false;
                cnt--;
            }
            else{
                isthere[ai] = true;
                cnt++;
            }
        }
        else {
            if (valid[ai-pow(10,6)]){
                valid[ai-pow(10,6)] = false;
                cnt--;
            }
            else {
                valid[ai-pow(10,6)] = true;
                cnt++;
            }
        }
    }
    
    cout << cnt << endl;

}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void){
    char num[1024];
    int sum;
    int i;
    while(1){
        sum=0;
        i=0;
        scanf("%s",num);
        if(num[0]=='0')
            break;
        while(num[i]!='\0'){
            sum+=num[i]-'0';
            i++;
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 2108
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
a = [0] * N
b = [0] * N

for i in range(N):
    a[i], b[i] = map(int, input().split())

a, b = zip(*sorted(zip(a, b)))

count = 0
while K > 0:
    K -= b[count]
    count += 1

print(a[count - 1])

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

typedef long long ll;

int main()
{
    int N, T;
    int min = INT_MAX;
    int c, t;
    cin >> N >> T;

    for (int i = 0; i < N; ++i)
    {
        cin >> c >> t;
        if (t > T)
        {
            continue;
        }
        if (c < min)
        {
            min = c;
        }
    }
    if (min == INT_MAX)
    {
        cout << "TLE" << endl;
        return 0;
    }
    cout << min << endl;
}


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

long long n, ans;
long long dp[105][105];

long long find(long long x)
{
	while(x)
	{
		if(x / 10 == 0)
			return x;
		x /= 10;
	}
}

int main()
{
	cin >> n;
	
	for(long long i = 1; i <= n; ++i)
	{
		long long h = i;
		long long a1 = h % 10;
		long long a2 = find(h);
		dp[a2][a1]++;
	}
	
	for(long long i = 1; i <= 9; ++i)
		for(long long j = 1; j <= 9; ++j)
			ans += dp[i][j] * dp[j][i];
	
	cout << ans << endl;
	return 0;
}

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

int n, m;
string s, t;

int dp[2020][2020][2];

int main()
{
  cin >> m >> n;
  cin >> s >> t;

  int ans = 0;
  for (int i = 0; i <= m; i++){
    for (int j = 0; j <= n; j++){
      if (i){
        if (s[i - 1] == 'I'){
          dp[i][j][1] = dp[i - 1][j][0] + 1;
          ans = max(ans, dp[i][j][1]);
        }
        else if (dp[i - 1][j][1]){
          dp[i][j][0] = dp[i - 1][j][1] + 1;
        }
      }

      if (j){
        if (t[j - 1] == 'I'){
          dp[i][j][1] = max(dp[i][j][1], dp[i][j - 1][0] + 1);
          ans = max(ans, dp[i][j][1]);
        }
        else if (dp[i][j - 1][1]){
          dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][1] + 1);
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 34720
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int mi = INT_MAX;
    for (int i = 0; i <= s.length() - t.length(); i++)
    {
        string s1 = s.substr(i, t.length());
        int cnt = 0;
        for (int j = 0; j < t.length();j++){
            if(s1[j]!=t[j])
                cnt++;
        }
        mi = min(cnt, mi);
    }
    cout << mi << "\n";

    return 0;
}

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

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }

  vector<int> v;
  auto dfs = [&](auto&& dfs) {
    int r = 0;
    if (v.size() == n) {
      for (int i = 0; i < q; i++) {
        if (v[b[i]] - v[a[i]] == c[i]) r += d[i];
      }
      return r;
    }
    for (int i = (v.empty() ? 1 : v.back()); i <= m; i++) {
      v.push_back(i);
      r = max(r, dfs(dfs));
      v.pop_back();
    }
    return r;
  };
  cout << dfs(dfs) << endl;
}


Measured memory_bytes: 3632
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    vector<vector<int>> a_hit(3, vector<int>(3, 0));
    for(int j=0; j<3; j++){
        cin >> a[j][0] >> a[j][1] >> a[j][2];
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    bool bingo=false;

    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(b[i]==a[j][k]){
                    a_hit[j][k]=1;
                }
            }
        }
    }
    for(int j=0; j<3; j++){
        if(a_hit[j][0]==1 && a_hit[j][1]==1 && a_hit[j][2]==1){
            bingo=true;
        }
    }
    for(int k=0; k<3; k++){
        if(a_hit[0][k]==1 && a_hit[1][k]==1 && a_hit[2][k]==1){
            bingo=true;
        }
    }
    if(a_hit[0][0]==1 && a_hit[1][1]==1 && a_hit[2][2]==1){
        bingo=true;
    }
    if(a_hit[2][0]==1 && a_hit[1][1]==1 && a_hit[0][2]==1){
        bingo=true;
    }

    if(bingo==true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

# スイッチで全探索
bulb = []
for _ in range(M):
    enc = 0
    s = list(map(int, input().split(" ")))
    for k in range(s[0]):
        enc = enc | (1 << (s[k + 1] - 1))
    bulb.append(enc)

p = list(map(int, input().split(" ")))

ans = 0
for s in range((1 << N)):
    count = 0
    for i, enc in enumerate(bulb):
        if bin(enc & s).count("1") % 2 == p[i]:
            count += 1
    if count == M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int A[251];
int main(){
  int H;

  cin>>H;
  for(int i=1;i<=H;i++) cin>>A[i];
  

  for(int i=1;i<=H;i++){
    cout<<"node "<<i<<": key = "<<A[i]<<", ";
    if(i!=1) cout<<"parent key = "<<A[i/2]<<", ";
    if(i*2<=H) cout<<"left key = "<<A[i*2]<<", ";
    if(i*2+1<=H) cout<<"right key = "<<A[i*2+1]<<", ";
    cout<<endl;
  }

  return 0;
}
			


Measured memory_bytes: 3092
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import Control.Monad.State

main :: IO ()
main = do
  [_, q] <- map read <$> words <$> getLine
  que <- Queue [] <$> map (f . B.words) <$> B.lines <$> B.getContents
  solve q que
  where f [n, t] = (n, readi B.readInt t)
  
solve :: Int -> Queue (ByteString, Int) -> IO ()
solve q que = evalStateT (rrs 0) que
  where rrs :: Int -> StateT (Queue (ByteString, Int)) IO ()
        rrs ct = do
          que <- get
          unless (isEmptyQue que) $ do
            let (Just ((n, t), nque)) = deQue que
            if t > q then do
              put $ enQue (n, t - q) nque
              rrs (ct+q)
            else do
              lift $ putStrLn $ B.unpack n ++ " " ++ show (ct+t)
              put nque
              rrs (ct+t)

data Queue a = Queue [a] [a] deriving Show

enQue :: a -> Queue a -> Queue a
enQue x (Queue xs ys) = Queue (x:xs) ys

deQue :: Queue a -> Maybe (a, Queue a)
deQue (Queue [] []) = Nothing
deQue (Queue xs (y:ys)) = Just (y, Queue xs ys)
deQue (Queue xs []) = deQue (Queue [] (reverse xs))

isEmptyQue :: Queue a -> Bool
isEmptyQue (Queue [] []) = True
isEmptyQue _ = False

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n



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

#define ll   	long long
#define pb	    push_back
#define F   	first
#define S	    second
#define B   	begin()
#define E	    end()
#define FASTIO   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


using namespace std ;

int main()
{
    FASTIO ;
    int a[3];
    cin >> a[0] >> a[1] >> a[2] ;
    int x = 0 , y = 0 ;
    for ( int i = 0 ; i < 3 ; i++ )
    {
        if ( a[i] == 5 ) x++ ;
        else if ( a[i] == 7 ) y++ ;
    }
    cout << ( x == 2 && y == 1 ? "YES" : "NO" ) ;
    return 0;
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
    long long int n,min=1000000000000,i,a,b;
    cin>>n;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            a=i-1;
            b=(n/i)-1;
            if(a+b<min)
                min=a+b;
        }
    }
    cout<<min;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include<algorithm>

using namespace std;

int main()
{
  string s;
  cin >>s;
  char r,l,u,d;
  r='R';l='L';u='U';d='D';
  
  
  for(int i=0;;i++){
    if(s[i]!=r&&s[i]!=l&&s[i]!=u&&s[i]!=d){
      cout <<"Yes"; break;}
    else if(i%2==0&&s[i]==l){
      cout <<"No";break;}
    else if(i%2>0&&s[i]==r){
      cout <<"No";break;}
  }
  
  
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define MOD 1000000007

long long int ppow(long long int i, long long int j) {
	long long int res = 1LL;
	while (j) {
		if ((j & 1LL)) {
			res *= i;
			if (res >= MOD) {
				res %= MOD;
			}
		}
		j >>= 1;
		i *= i;
		if (i >= MOD) {
			i %= MOD;
		}
	}
	return res;
}
long long int gcd(long long int a, long long int b) {
	if (a > b) {
		swap(a, b);
	}
	while (a) {
		swap(a, b);
		a %= b;
	}
	return b;
}
long long int lcm(long long int a, long long int b) {
	return a / gcd(a, b)*b;
}
int h;
int w;
int n;
int main() {
	cin >> n;
	cin >> h;
	cin >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    int N,M; cin >> N >> M;
    vector<vector<char>> masu(N+2,vector<char>(M+2,'#'));
    vector<vector<int>> flag(N+2,vector<int>(M+2,0));
    int dy[4] = {1,0,-1,0};
    int dx[4] = {0,-1,0,1};
    map<char,int> mp;
    mp['v'] = 0; mp['<'] = 1; mp['^'] = 2; mp['>'] = 3;
    pii S;
    int dir = 0;
    for(int i = 1; i <= N;i++){
        for(int j = 1; j <= M; j++){
            cin >> masu[i][j];
            if(mp.count(masu[i][j])){
                dir = mp[masu[i][j]];
                masu[i][j] = '.';
                S = {i,j};
            }
        }
    }
    int y = S.first, x = S.second;
    int from_dir = dir;
    bool f = false;
    while(true){
        if(y == S.first && x == S.second && dir == from_dir && f) return -1;
       // cout << y << " " << x << " " << dir << endl;
        f = true;
        flag[y][x] = 1;
        if(masu[y][x] == 'G') break;
        
        int migi = (dir+1)%4;
        int migiy = y + dy[migi],migix = x + dx[migi];
        int maey = y + dy[dir],maex = x + dx[dir];
        
        if(masu[maey][maex] != '#' && masu[migiy][migix] != '#'){
            dir = migi;
            y = migiy; x = migix;
        }else if(masu[maey][maex] != '#'){
            y = maey; x = maex;
        }else if(masu[migiy][migix] != '#'){
            dir = migi;
            y = migiy; x = migix;
        }else{
            dir = (dir +3)%4;
        }
    }
    for(auto vec:flag) res += accumulate(vec.begin(),vec.end(),0);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3220
a,b,c,d=map(int,input().split())

if a>=0:
    if c>=0:
        print(b*d)
    elif c<0 and d>=0:
        print(b*d)
    elif d<0:
        print(a*d)

elif a<0 and b>=0:
    if c>=0:
        print(b*d)
    elif c<0 and d>=0:
        print(max(a*c,b*d))
    elif d<0:
        print(a*c)

elif b<0:
    if c>=0:
        print(b*c)
    elif c<0 and d>=0:
        print(a*c)
    elif d<0:
        print(a*c)


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

int main()
{
    int N , K , X , Y ;
    cin >> N >> K >> X >> Y ;

    if(N<=K)
    {
        cout << N*X << "\n" ;
    }
    else
    {
        cout << K*X + Y*(N-K) ;
    }
    return 0 ;
}


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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353

int lowbit(int x) {return x&(-x);}

string x,y;
int f[3010][3010];
pii pre[3010][3010];

int main(){
	cin>>x>>y;
	int n=x.size(),m=y.size();
	x=" "+x,y=" "+y;
	for (int i=0;i<=n;i++)
		for (int j=0;j<=m;j++) pre[i][j]=mp(-1,-1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) {
			if (x[i]!=y[j]) {
				f[i][j]=max(f[i][j-1],f[i-1][j]);
				if (f[i][j]==f[i][j-1]) pre[i][j]=mp(i,j-1);
				else pre[i][j]=mp(i-1,j);
			}
			else {
				f[i][j]=f[i-1][j-1]+1;
				pre[i][j]=mp(i-1,j-1);
			}
		}
	int i=n,j=m;
	string ans;
	while (i!=-1) {
		if (x[i]==y[j]&&x[i]!=' ') ans+=x[i];
		pii tmp=pre[i][j];
		i=tmp.fi,j=tmp.se;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {


	int n;
	cin >> n;

	VI d(n);
	REP(i, n)cin >> d[i];
	sort(ALL(d));

	if (d[n / 2 - 1] == d[n / 2]) {
		cout << 0 << endl;
		return 0;
	}
	cout << d[n / 2] - d[n / 2 - 1] << endl;

}



Measured memory_bytes: 640
/*
  AOJ 1285
  Title:Grey Area
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#define max(x,y) (((x)>(y))?(x):(y))

int n,w,step;
int histg[11];

main()
{
  int i,s,high,val;
  double ret;
  while(scanf("%d %d",&n, &w)  && (n||w))
    {
      memset(histg,0,sizeof(histg));
      for(i=step=high=0;i<n;i++)
	{
	  scanf("%d",&val);
	  s=(val/w);
	  step=max(step,s);
	  histg[s]++;
	  high=max(high,histg[s]);
	}
      for(i=0,ret=0.0;i<step;i++)
	ret += ((double)histg[i]*(step-i))/((double)high*step);
      printf("%lf\n",ret+0.01);
    }
  return(0);
}

Measured memory_bytes: 632
from collections import Counter
import sys

def main():

    num = int(input())
    data = list(map(int, input().split()))
    num_d = int(input())
    cheet_data = [list(map(int, input().split())) for i in range(num_d)]

    sum_data = sum(data)

    for i in range(num_d):
        a, b, = cheet_data[i]
        ans = sum_data - data[a - 1] + b
        print(ans)




if __name__ == '__main__':
    main()


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


int main(){
	int i, j;
	char s[10];

	scanf("%s", s);

	j = 0;
	for (i = 0; i < 6; i++) {
		if (s[i] == '1') {
			j++;
		}
	}
	printf("%d\n", j);

	return 0;
}


Measured memory_bytes: 128
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
#define int long long
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=100000+10;

int n,m,k;
int x[N],a[N];
int p[N],vis[N],sta[N],top;
int ans[N];

signed main() {
    n=read();
    for (re int i=1;i<=n;++i) x[i]=read();
    m=read(),k=read();
    for (re int i=1;i<=m;++i) a[i]=read();
    for (re int i=n;i;--i) x[i]-=x[i-1];
    for (re int i=1;i<=n;++i) p[i]=i;
    for (re int i=1;i<=m;++i) swap(p[a[i]],p[a[i]+1]);
    for (re int i=1;i<=n;++i) {
        if (vis[i]) continue;
        top=0;
        for (re int j=i;!vis[j];j=p[j]) sta[++top]=j,vis[j]=1;
        for (re int j=1;j<=top;++j) ans[sta[j]]=x[sta[(j+k-1)%top+1]];
    }
    for (re int i=1;i<=n;++i) ans[i]+=ans[i-1];
    for (re int i=1;i<=n;++i) printf("%.1lf\n",1.*ans[i]);
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
	double l;
	cin >> l;
	double h = l/3;
	double w = l/3;
	double o = l/3;
	cout << fixed << setprecision(12) << h*w*o << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n,tg=1;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;++i)cin >> a[i];
	for(int i=0;i<n;++i){
		if(tg==a[i]){
			tg++;
		}
	}
	if(tg!=1)cout << n - tg + 1 << endl;
	else cout << -1 << endl;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

    map<int,int> m;
    rep(i,n){
        int a;
        cin>>a;
        m[a]++;
    }

    int ans=0;
    for(auto e : m){
        if(e.second>=e.first) ans+=e.second-e.first;
        else ans+=e.second;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 8116