akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=5e5+9,mod=998244353;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}
	inline int sub(int x,int y){return x>=y?x-y:x+mod-y;}
	inline int qpow(int x,int y){
		int ret=1;
		while(y){
			if(y&1) ret=1LL*x*ret%mod;
			x=1LL*x*x%mod,y>>=1;
		}
		return ret;
	}
	int fac[N],ifac[N],n,K;
	inline int C(int _n,int _m){
		if(_n<0 || _m<0 || _n<_m) return 0;
		return 1LL*fac[_n]*ifac[_m]%mod*ifac[_n-_m]%mod;
	}
	inline int calc(int R,int B){return sub(C(R+B,R),C(R+B,2*R-n+1));}

	int main(){
		n=read<int>(),K=read<int>();
		if(K<n) puts("0"),exit(0);
		fac[0]=ifac[0]=1;
		for(int i=1;i<=K;i++) fac[i]=1LL*fac[i-1]*i%mod;
		ifac[K]=qpow(fac[K],mod-2);
		for(int i=K-1;i>=1;i--) ifac[i]=1LL*ifac[i+1]*(i+1)%mod;

		int ans=0;
		for(int R=(K-1)/2+1;R<=K;R++){
			if(R==K-R) ans=add(ans,calc(R,K-R-1));
			else ans=add(ans,calc(R,K-R));
		}
		printf("%d\n",ans);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 7632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int[] a = new int[N + 1];
		for(int i = 1; i <= N; i++)
			a[i] = GetInt();

		int[] b = new int[N + 1];
		for(int i = N; i >= 1; i--)
		{
			int sum = 0;
			for(int j = 2 * i; j <= N; j += i)
				sum += b[j];

			if(sum % 2 != a[i])
				b[i] = 1;
		}

		int M = b.Count(x => x == 1);
		var list = new List<int>(M);
		for(int i = 1; i <= N; i++)
			if(b[i] == 1)
				list.Add(i);

		Console.WriteLine(M);
		if(M == 0)
			return;

		Console.WriteLine(string.Join(" ", list));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 32856
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	ll a, b, k; cin >> a >> b >> k;
	cout << max(0LL, a - k) << " " << max(0LL, b - max(0LL, k - a)) << endl;
	return 0;
}


Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n,k,q = map(int,input().split())
correct_member = [int(input())-1 for _ in range(q)]

ans = [k-q for _ in range(n)]

cormem_count = Counter(correct_member)

for k,v in cormem_count.items():
    ans[k] += v

for i in ans:
    YorN = "Yes" if i > 0 else "No"
    print(YorN)


Measured memory_bytes: 15880
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N;
int ans[20000];

int main() {
  cin >> N;

  if (N == 3) {
    cout << "2 5 63" << endl;
    return 0;
  }
  
  if (N == 4) {
    cout << "2 5 20 63" << endl;
    return 0;
  }

  if (N == 5) {
    cout << "2 4 6 3 9" << endl;
    return 0;
  }

  int sum = 0;
  int d_sum = 0;
  for (int i = 0; i < N; ++i) {
    if (i%4 == 0) ans[i] = 6*(i/4)+2;
    else if (i%4 == 1) ans[i] = 6*(i/4)+3;
    else if (i%4 == 2) ans[i] = 6*(i/4)+4;
    else if (i%4 == 3) ans[i] = 6*(i/4)+6;
    sum = (sum + ans[i]) % 6;
  }

  if (sum == 0) {

  } else if (sum == 2) {
    ans[4] = 6*(N/4)+6;
  } else if (sum == 3) {
    ans[5] = 6*(N/4)+6;
  } else if (sum == 5) {
    ans[5] = 6*(N/4)+4;
  }

  for (int i = 0; i < N; ++i) printf("%d%c", ans[i], i+1 != N ? ' ' : '\n');

  return 0;
}


Measured memory_bytes: 384
object Main extends App {
  import scala.math._
  
  val n = readLong
  val h = readLine.split(" ").map{_.toLong}.toArray
  
  val dp = Array.fill[Long](n.toInt)(Long.MaxValue)
  dp(0) = 0
  dp(1) = abs(h(1) - h(0))
  
  
  for (i <- 2 until n.toInt) {
    dp(i) = min(min(dp(i),dp(i-1)+abs(h(i)-h(i-1))),dp(i-2)+abs(h(i)-h(i-2)))
  }
  
  println(dp(n.toInt-1))
}

Measured memory_bytes: 46712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int m=in();
	print(48-m);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std; 
typedef long long ll;
typedef unsigned long long int ull;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>  
#define ff first
#define ss second
#define pb push_back
#define Inf  1e18
#define inf -1e18
#define mod 1000000007
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll,ll>;
using umll = unordered_map<ll,ll>;
using sll = set<ll>;
using msll = multiset<ll>;
 
 
ll MUL(ll A,ll B){
  return (A%mod*B%mod)%mod;
}
 
ll ADD(ll A,ll B){
  return (A%mod+B%mod)%mod;
}
 
ull power(ll A,ll B) { 
    ull RES = 1;      
    while (B > 0) 
    { 
        if (B & 1) 
            RES = RES*A;  
        B = B>>1;  
        A = A*A;  
    } 
  return RES; 
}

 
void testcases(int cases){
  
  ll N;
  cin >> N;
  string S = "";
  while(N!=0){
    if(N==26){
      S+='z';
      break;
    }
    ll rem = N%26;
    if(rem==0)
      rem = 26;
    char ch =(char)(97 + rem - 1);
    S.push_back(ch);
    N-=rem;
    N/=26;
  }
  reverse(S.begin(),S.end());
  cout << S << "\n";
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
    ll t;
    t = 1;
   // cin >> t;
    ll Case =1 ;
    while(t--)
    {
      testcases(Case++);
    }
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

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

  map<ll, ll> a;
  map<ll, ll> b;

  ll x,y;
  rep(i, m){
    cin >> x>>y;
    if(x>y) swap(x,y);
    if(x==1) a[y]++;
    if(y==n) b[x]++;
  }
  string ans = "IMPOSSIBLE";
  for(auto x:a){
    if(b[x.first]) ans = "POSSIBLE"; 
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 22144
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string S,T;
int main() {
	cin>>S;
	int cnt=0;
	if(S.size()==3) {
		if(S[0]==S[2]) cout<<"Second"<<endl;
		else cout<<"First"<<endl;
		return 0;
	}
	for(int i=0;i<S.size();i++) {
		if(S[i]==S[0]||S[i]==S[S.size()-1]) T.push_back(S[i]);
		else cnt++;
	}
	if(S[0]==S[S.size()-1]&&T.size()%2==0) cnt++;
	if(S[0]!=S[S.size()-1]&&T.size()%2==1) cnt++;
	cout<<((cnt%2==0)?"Second":"First")<<endl;
}

Measured memory_bytes: 512
#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;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 405

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len;
ll psa[MAXN],dp[MAXN][MAXN];

ll solve(int l, int r){
    if(l+1 == r) return psa[r]-psa[l-1];
    if(l >= r) return 0;
    if(dp[l][r] != 0x3f3f3f3f3f3f3f3f) return dp[l][r];
    for(int i=r-1; i>=l; i--){
        ll tot = solve(l,i)+solve(i+1,r)+psa[r]-psa[l-1];
        dp[l][r] = min(dp[l][r],tot);
    }
    return dp[l][r];
}

int main(){
    scanf("%d",&len);
    for(int i=1; i<=len; i++){
        scanf(" %lld",&psa[i]);
        psa[i]+=psa[i-1];
    }
    memset(dp,0x3f,sizeof dp);
    printf("%lld\n",solve(1,len));
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        String s = in.next();
        System.out.println(s.replace(",", " "));
    }
}

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

using namespace std;

bool solve(const vector<string> &W)
{
    const int n = W.size();

    for (int i = 0; i < n - 1; ++i)
    {
        if (W[i].back() != W[i + 1].front())
        {
            return false;
        }
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            if (W[i] == W[j])
            {
                return false;
            }
        }
    }
    return true;
}

vector<string> input()
{
    int n;
    cin >> n;
    vector<string> W(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> W[i];
    }
    return W;
}

int main()
{
    const vector<string> W = input();
    if (solve(W))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,(n)-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,(n)-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    ll d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y <= d*d)ans++;
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
int item[]={1,5,10,50,100,500};
int num[6];

int cash(int a){
	int t_num[6];
	int ret = 0;
	for(int i=0;i<6;i++){
		t_num[i] = num[i];
	}
	for(int i=5;i>=0;i--){
		if(a>=item[i] && t_num[i]){
			a-=item[i];
			t_num[i]--;
			ret++;
			i++;
		}
	}
	if(a!=0)return -1;
	return ret;
}

int plz(int a){
	int ret = 0;
	for(int i=5;i>=0;i--){
		if(a>=item[i]){
			a-=item[i];
			i++;
			ret++;
		}
	}
	return ret;
}

int main(){
	int m,n,t,ret;
	while(cin >> m && m){
		int ret = (1<<21);
		for(int i=0;i<6;i++){
			cin >> num[i];
		}
		for(int i=0;i<500;i++){
			if(~cash(m+i)){
				ret = min(ret,cash(m+i)+plz(i) );
			}
		}
		cout << ret << endl;
	}
}

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

int main(){
  ll h,w;
  cin >> h >> w;
  ll ans = 0;
  if(h == 1 || w == 1) ans = 1;
  else ans = (h*w+1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def smaller(x, y):
	if x < y: return x
	return y

N = int(input())
h = list(map(int, input().split()))
dp = [0]
for i in range(1, N):
	if i == 1: dp.append(abs(h[0]-h[1]))
	else: dp.append(smaller(dp[-1]+abs(h[i]-h[i-1]), dp[-2]+abs(h[i]-h[i-2])))
print(dp[N-1])

Measured memory_bytes: 55656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if(A>B){
    cout << A*2-1 << endl;
  }
  else if(A==B){
    cout << A+B << endl;
  }
  else{
    cout << B*2-1 << endl;
  }
}

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


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");
	public static void main(String[] args) {
		int s=sc.nextInt();
		ArrayList<Integer> cc = new ArrayList<>();
		cc.add(s);
		int tmp;
		for(int i=1;true;i++) {
			if(cc.get(i-1)%2==0)tmp=cc.get(i-1)/2;
			else tmp=cc.get(i-1)*3+1;
			if(cc.contains(tmp)) {
				p(i+1);
				break;
			}else {
				cc.add(tmp);
			}
			
		}
	}
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
}
	

Measured memory_bytes: 21204
from collections import deque
import sys, copy, itertools
input = sys.stdin.readline

h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
#SUBMAP =[['#']+['#']+list(input().rstrip())+['#']+['#'] for i in range(h)]
#MAP = [['#']*(w+4)] +[['#']*(w+4)]+SUBMAP+[['#']*(w+4)]+[['#']*(w+4)]
MAP =[list(input().rstrip()) for i in range(h)]
#print(MAP)

ch += -1
cw += -1
dh += -1
dw += -1

MOVE = [[1,0],[-1,0],[0,1],[0,-1]]
JUMP = [[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],[-1,-2],[-1,-1],[-1,1],[-1,2],[0,-2],[0,2],[1,-2],[1,-1],[1,1],[1,2],[2,-2],[2,-1],[2,0],[2,1],[2,2]]
STACK = deque([(ch,cw)])
STACKX = deque([(ch,cw)])
#print(STACKX)

ans = -1 #見つからなかった場合
MAP[ch][cw]=0
#print(MAP)

while STACKX:
  
  while STACK:
    y, x = STACK.popleft()
    for dy,dx in MOVE:
      ny = y + dy
      nx = x + dx
      if not(0 <= ny < h) or not(0 <= nx < w) or MAP[ny][nx]!='.':
        STACKX.append((y,x))
        continue
      else:
        STACK.append((ny,nx))
        MAP[ny][nx] = MAP[y][x]
   
  #print(MAP)
  if MAP[dh][dw] != '.':
    ans = MAP[dh][dw]
  
  #print(STACKX)
  yy, xx = STACKX.popleft()
  for dyy,dxx in JUMP:
    nyy = yy + dyy
    nxx = xx + dxx
    if not(0 <= nyy < h) or not(0 <= nxx < w) or MAP[nyy][nxx]!='.':
      continue
    else:
      STACK.append((nyy,nxx))
      MAP[nyy][nxx] = MAP[yy][xx] + 1


      
      
#print(MAP)
print(ans)


Measured memory_bytes: 171368
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 200005
using namespace std;
lo int x,tut;
int main(){
	scanf("%lld",&x);
	for(lo int i=1;i<=100000;i++){
		if((i*(i+1)/2)>=x){
			tut=i;
			break;
		}
	}
	printf("%lld\n",tut);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  ll n, a, b; cin >> n >> a >> b;
  vector<ll> t(n); rep(i, n) cin >> t[i];

  ll ans = 0;

  for (int i = 0; i < n; i++)
    if (t[i] < a || t[i] >= b) ans++;

  outl(ans)
}


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

using namespace std;

int main(){
	
	int H,A;
	cin>>H>>A;
	
	  if(H%A){
	  	cout<<H/A+1<<endl;
	  	return 0;
	  }	
	  
	  else{
	  	cout<<H/A<<endl;
	  	return 0;
	  }
	
	
	return 0;
}

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

int main() {
	 int n,m,l;
	cin >> n; cin >> m; cin >> l;
	
	cout<< min(abs(n - m) + abs(m - l), min(abs(n - l) + abs(m - l), abs(n - l) + abs(n - m)));
}


Measured memory_bytes: 256
n = gets.chomp.to_i
ab = []
n.times do
  ab << gets.chomp.split.map(&:to_i)
end

ab.sort!{|i,j| i[1] <=> j[1] }

sum = 0
ab.each do |a, b| 
  sum += a
  if sum > b
    puts 'No'
    exit
  end
end

puts 'Yes'


Measured memory_bytes: 18552
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
int main(){
    cin >> n;
    cout << n*800-n/15*200 << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int k; cin >> k;
    int cnt = (k + 1) / 2;
    cout << cnt * (k - cnt) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

int main() {
	// your code goes here
	int x, y;
	cin >> x >> y;
	for(int i = 0; i <= x ; ++i){
		if(y == (2*i + 4*(x-i))){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<iomanip>
using namespace std;

int main(){
   int a, b;
   cin >> a >> b;
   if (a <= 8 && b <= 8) cout << "Yay!" << endl;
   else cout << ":(" << endl;
}


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

int n, num;
bitset<32> magic_num;

int main() {
  cin >> n;
  vector<bitset<32>> a(n);
  rep (i, n) {
    cin >> num;
    a[i] = bitset<32> (num);
  }
  rep (i, n) {
    magic_num ^= a[i];
  }
  rep (i, n) {
    cout << (magic_num ^ a[i]).to_ulong();
    if (i != n - 1) cout << " ";
    else cout << endl;
  }
  return 0;
}


Measured memory_bytes: 4788
S = input()
T = input()
dp = [[0 for j in range(len(T)+1)] for i in range(len(S)+1)]

for i in range(len(S)) :
    for j in range(len(T)) :
        if S[i] == T[j] :
            dp[i+1][j+1] = dp[i][j] + 1
        else :
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

ans = ""

ind_x = len(T)
ind_y = len(S)

while ind_x * ind_y :
    if S[ind_y-1] == T[ind_x-1] :
        ans = S[ind_y-1] + ans
        ind_x -= 1
        ind_y -= 1
    elif dp[ind_y][ind_x] == dp[ind_y-1][ind_x] :
        ind_y -= 1
    else :
        ind_x -= 1
    

print(ans)


Measured memory_bytes: 120028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		if(i%3==0 or i%5==0)continue;
		sum+=i;
	}
	cout<<sum;
}

Measured memory_bytes: 3644
s=input()

if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)


Measured memory_bytes: 2940
def main():
    A, B, C = map(int, input().split())
    ans = 0

    if C >= A:
        ans += A
        C -= A
    else:
        ans += C
        C = 0

    if C <= B:
        ans += C + B
        C = 0
    else:
        ans += B * 2
        C -= B

    if C >= 1:
        ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9064
from sys import stdin,stdout

n = int(stdin.readline())
a = []
for i in range(n):
    x,y,z = map(int,stdin.readline().split())
    a.append([x,y,z])
dp = [[0,0,0] for i in range(n)]
dp[0] =  [a[0][0],a[0][1],a[0][2]] 
for i in range(1,n):
    dp[i][0] = a[i][0] + max( dp[i-1][1],dp[i-1][2] )
    dp[i][1] = a[i][1] + max( dp[i-1][0],dp[i-1][2] )
    dp[i][2] = a[i][2] + max( dp[i-1][0],dp[i-1][1] )
ans = max(dp[n-1])
stdout.write(str(ans))


Measured memory_bytes: 42484
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> H >> W >> N;
	vector<pair<int, int>>v(N);
	for (auto &i : v) {
		cin >> i.first >> i.second;
		i.first--, i.second--;
	}
	vector<int>box(W);
	for (int i = 1; i < W; i++)box[i] = i;
	sort(v.begin(), v.end());
	for (auto i : v) {
		int md = i.first % (1 * W);
		int l = -1, r = -1;
		if (md == i.second)l = 0;
		else if (md > i.second)l = md - i.second - 1;
		else l = i.second - md;
		i.second = W - 2 - i.second;
		if (md == i.second)r = 0;
		else if (md > i.second)r = md - i.second - 1;
		else r = i.second - md;
		i.second = W - 2 - i.second;
		r = W - 1 - r;
		if (i.first % (2 * W) >= W) {
			r = W -1- r, l = W - 1-l;
		}
	//	cout << l << " " << r << endl;
		swap(box[l], box[r]);
	}
	vector<int>ans(W);
	for (int i = 0; i < W; i++) {
		
		int p = i;
		int md = H % (2 * W);
		if (i & 1) {
			int minus = min(md, i);
			md -= minus;
			p -= minus;
			md--;
			if (md >= 0) {
				minus = min((int)W - 1, md);
				md -= minus;
				p += minus;
				md--;
			}
			if (md >= 0) {
				minus = min(p, md);
				md -= minus;
				p -= minus;
				md--;
			}
		}
		else {
			int minus = min(md, ((int)W - 1) - p);
			md -= minus;
			p += minus;
			md--;
			if (md >= 0) {
				minus = min(p, md);
				md -= minus;
				p -= minus;
				md--;
			}
			if (md >= 0) {
				minus = min((int)(W - 1), md);
				md -= minus;
				p += minus;
				md--;
			}
		}
		ans[p] = box[i];
		
	}
	vector<int>ret(W);
	for (int i = 0; i < W; i++) {
		ret[ans[i]] = i + 1;
	}
	for (auto i : ret)cout << i << endl;
}


Measured memory_bytes: 6652
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
map<ll,ll> mp;
ll n,q,a,m,k,ans,fa[100000],ra[100000],c[100000],s[100000],L,MOD=1e9+7,b;
vector<ll> v,u;
ll find(ll x){
    if(x==fa[x])return x;
    return fa[x]=find(fa[x]);
}
void uni(ll x,ll y){
    x=find(x),y=find(y);
    if(x==y)return ;
    if(ra[x]<ra[y])swap(x,y);
    fa[y]=x;
    ra[x]+=ra[y];
    return ;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
void ini(void){
    m=1;
    while(m<n)m*=2;
    v.resize(2*m,1LL);
    u.resize(2*m,0);
}
void STadd1(ll a,ll b,ll c){
    a+=m-1;
    v[a]=b;
    u[a]=c;
    while(a){
        a=(a-1)/2;
        v[a]=lcm(v[2*a+1],v[2*a+2]);
    }
    return ;
}
void STadd2(ll a,ll c){
    a+=m-1;
    while(a){
        a=(a-1)/2;
        u[a]=(v[a]/v[2*a+1])%MOD*u[2*a+1]%MOD+(v[a]/v[2*a+2])%MOD*u[2*a+2]%MOD;
        u[a]%=MOD;
    }
    return ;
}
ll STlcm(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return 1LL;
    if(a<=l&&r<=b)return v[k];
    ll vr=STlcm(a,b,2*k+1,l,(r+l)/2);
    ll vl=STlcm(a,b,2*k+2,(r+l)/2,r);
    return lcm(vr,vl);
}

ll STquery(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return u[k]*((L/v[k])%MOD)%MOD;
    ll vr=STquery(a,b,2*k+1,l,(r+l)/2);
    ll vl=STquery(a,b,2*k+2,(r+l)/2,r);
    
    return (vr+vl)%MOD;
}
int main(void){
    for(int i=0;i<100000;i++)fa[i]=i;
    for(int i=0;i<100000;i++)ra[i]=1;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>a;
        a--;
        uni(i,a);
    }
    for(ll i=0;i<n;i++){
        mp[find(i)]+=i+1;
        mp[find(i)]%=MOD;
        c[i]=ra[find(i)];
    }
    for(int i=0;i<n;i++){
        s[i]=mp[find(i)];
    }
    ini();
    for(int i=0;i<n;i++){
        STadd1(i,c[i],s[i]);
    }
    
    for(int i=0;i<n;i++){
        STadd2(i,s[i]);
    }
    while(q--){
        cin>>a>>b;
        a--,b--;
        L=STlcm(a,b+1,0,0,m);
        cout<<STquery(a,b+1,0,0,m)<<endl;
    }
}



Measured memory_bytes: 10508
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int ans = INF;
	rep(i, max(X, Y) + 1) {
		int tmp = i * C * 2;
		tmp += max(0, (X - i)) * A +  max(0, (Y - i)) * B;
		ans = min(ans, tmp);
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
void swap(int *xp, int *yp) 
{ 
    int temp = *xp; 
    *xp = *yp; 
    *yp = temp; 
}
void sort(int arr[], int n) 
{ 
   int i, j; 
   for (i = 0; i < n-1; i++)      
       for (j = 0; j < n-i-1; j++)  
           if (arr[j] > arr[j+1]) 
              swap(&arr[j], &arr[j+1]); 
} 
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int arr[1000];
    for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
    sort(arr,n);
    int ans=0;
    for(int i=0;i<k;i++)
    ans+=arr[i];
    printf("%d",ans);
}

Measured memory_bytes: 1700
N = int(input())
h = list(map(int,input().split()))

h.append(0)
pre = True 
next = True 
cnt = 0
for i in range(N):
    if h[i+1]>h[i]:
        next = True 
        if pre == False:
            cnt -= h[i]
    elif h[i+1]<h[i]:
        next = False
        if pre == True:
            cnt += h[i]
    else:
        next = pre 
    pre = next 
print(cnt)

Measured memory_bytes: 9208
import java.util.*;
	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	}

Measured memory_bytes: 35512
s=list(input())

hugou=[]
for i in range(8):
  z=[]
  k=0
  ans=0
  for j in range(3):
    if k==0:
      z.append(s[k])
      ans+=int(s[k])
    if ((i>>j)&1):
      z.append("+")
      k+=1
      ans+=int(s[k])
      z.append(s[k])
    else:
      z.append("-")
      k+=1
      ans-=int(s[k])
      z.append(s[k])
  if ans==7:
    print("".join(z)+"=7")
    break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int maxn = 1e6 + 10;
array <ll, maxn> cnt, spf;

void solve() {
   for (int i = 1; i < maxn; i++) {
      spf[i] = i;
   }
   for (int i = 2; i < maxn; i += 2) {
      spf[i] = 2;
   }
   for (ll i = 3; i * i < maxn; i++) {
      if (spf[i] == i) {
         for (ll j = i * i; j < maxn; j += i) {
            if (spf[j] == j)
               spf[j] = i;
         }
      }
   }
   int n;
   cin >> n;
   vector <ll> a(n);
   for (auto &i : a) {
      cin >> i;
   }
   auto update = [&] (ll val) {
      set <ll> s;
      while (val != 1) {
         s.insert(spf[val]);
         val /= spf[val];
      }
      for (auto i : s)
         cnt[i]++;
   };
   for (int i = 0; i < n; i++) {
      update(a[i]);
   }
   ll hcf = a[0];
   bool pair = false;
   for (int i = 0; i < n; i++) {
      hcf = __gcd(hcf, a[i]);
   }
   for (int i = 0; i < maxn; i++) {
      if (cnt[i] > 1ll) {
         pair = true;
      }
   }
   if (hcf > 1) {
      cout << "not coprime\n";
   } else if (hcf == 1 && pair) {
      cout << "setwise coprime\n";
   } else {
      cout << "pairwise coprime\n";
   }
}

int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);

   solve();

   return 0;
}

Measured memory_bytes: 26532
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   int sum=0,n,d,x,a;
   cin>>n>>d>>x;
   for(int i=0;i<n;i++)
   {
       cin>>a;
       for(int j=1;j<=d;j+=a)
        sum++;
   }
   cout<<sum+x<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
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(a>b){a=b; return true;} return false;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}


constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    lint a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    set<lint> S;
    for(lint k=0;;++k){
        lint t = div_ceil(k*(a+b)-c, (lint)60);
        if(t < 0) continue;
        if(t*60 <= k*(a+b)+a-c){
            printf("%lld\n", t*60+c);
            return 0;
        }
        if(S.find(t*60 - (a+b)*k-c) != S.end()){
            puts("-1");
            return 0;
        }
        S.insert(t*60 - (a+b)*k-c);
    }
}


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

using namespace std;

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

        vector<int> a;
        a.resize(n);

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

        int c = 1;

        int max_val = max(a[0],a[1]);
        if(a[1] >= max_val){
                c++;
        }

        for(int i = 2 ; i < n; i++){
                max_val = max(max_val,a[i]);
                if(a[i] >= max_val){
                        c++;
                }
        }

        cout << c << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int partition(int *,int,int);
void swap(int *,int *);
int main(){
  int *A,i,n,point;
  scanf("%d",&n);
  A = (int *)malloc(n * sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  point = partition(A,0,n);

  for(i=0;i<point-1;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[point-1]);
  for(i=point;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  
  return 0;
}
int partition(int *A,int p,int r){
  int x,i,j;
  x = A[r-1];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  // swap(&A[i+1],&A[r-1]);
    return i+1;
}



void swap(int *x,int *y){
  int r;
  r=*x;
  *x=*y;
  *y=r;
}



Measured memory_bytes: 2124
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    PrintWriter out = new PrintWriter(System.out);
    int N;

    void run() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        printAns(0, 0, 0, "");
        out.flush();
    }

    void printAns(int d, int curC, int maxC, String s) {
        if (d == 1 && curC == 1) {
            return;
        }
        if (d == N) {
            out.println(s);
            return;
        }

        if (curC == maxC) {
            for (int i = 0; i <= curC + 1; i++) {
                printAns(d + 1, i, Math.max(i, maxC), s + (char) ('a' + i));
            }
        } else {
            for (int i = 0; i <= maxC + 1; i++) {
                printAns(d + 1, i, Math.max(i, maxC), s + (char) ('a' + i));
            }
        }

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

}


Measured memory_bytes: 47352
n=int(input())
code=input().split()
a=[0]*8
i=0
k=0
for j in range(n):
    if int(code[j])<400:
        a[0]=1
    elif int(code[j])<800:
        a[1]=1
    elif int(code[j])<1200:
        a[2]=1
    elif int(code[j])<1600:
        a[3]=1
    elif int(code[j])<2000:
        a[4]=1
    elif int(code[j])<2400:
        a[5]=1
    elif int(code[j])<2800:
        a[6]=1
    elif int(code[j])<3200:
        a[7]=1
    else:
        i+=1
for z in range(8):
    if a[z]==1:
        k+=1
if k>0:
    print(k, i+k,sep=" ")
else:
    print(1, i,sep=" ")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int s = a*b;
        int l = (a+b)*2;
        System.out.println(s+" "+l);
    }
}


Measured memory_bytes: 26132
n, m, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l_sum = 0
r_sum = 0
a.each do |v|
  if v < x
    l_sum += 1
  else
    r_sum += 1
  end
end
puts [l_sum, r_sum].min


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

int main()
{
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    int ans = 1;
    while (ans*(y+z)+z <= x) ans ++;
    printf("%d\n", ans-1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define l long long
int main()
{
    string s,s1;
    cin>>s;
    cin>>s1;
    int c=0;
    vector<char>v;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]!=s1[i])
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3912
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int main() {
	return 0 & putchar(getchar() ^ 1);
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}


int dp[303][303],N,a[303];
int f(int i,int j){
	if(i>=j)return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	if(i+1==j)return dp[i][j] = (abs(a[i]-a[i+1]) <= 1) * 2;
	if(f(i+1,j-1)==j-i-1&&abs(a[i]-a[j])<=1)return dp[i][j] = j-i+1;
	dp[i][j] = 0;
	rep(mid,i+1,j+1){
		chmax(dp[i][j],f(i,mid-1)+f(mid,j));
	}
	return dp[i][j];
}

signed main()
{
	//IOS();
	vector<int>ans;
	while(1){
		int N;
		cin >> N;
		if(!N)break;
		rep(i,0,N)cin>>a[i];
		rep(i,0,303)rep(j,0,303)dp[i][j] = -1;
		ans.push_back(f(0,N-1));
	}
	for(auto e:ans)cout<<e<<endl;
}



Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    string s;
    cin >> s;
    
    int zero = 0, one = 0;
    // 0-start
    repeat (i, s.length()) {
        if (i % 2 == 0) { // be zero
            if (s[i] == '1') ++zero;
        }
        else { // be one
            if (s[i] == '0') ++zero;
        }
    }
    
    // 1-start
    repeat (i, s.length()) {
        if (i % 2 == 0) { // be one
            if (s[i] == '0') ++one;
        }
        else { // be zero
            if (s[i] == '1') ++one;
        }
    }
    
    cout << min(zero, one) << endl;
}

Measured memory_bytes: 512
// ATC001_B
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1

class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M, A, B;
    cin >> N >> M;
    UnionFind uf(N);

    // calculation
    REP(i, M) {
        cin >> A >> B;
        uf.merge(A-1, B-1);
    }
    int ans=0;
    int tmp;
    REP(i, N) {
        tmp = uf.size(i);
        if(ans<tmp){
            ans=tmp;
        }
    }
    cout<<ans;
    return 0;
}

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

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

  string S1(S.size(), '0');
  string S2(S.size(), '1');
  for (int i = 1; i < S.size(); i += 2) {
    S1.at(i) += 1;
    S2.at(i) -= 1;
  }

  int ans = 0;
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != S1.at(i)) {
      ans1++;
    }
    if (S.at(i) != S2.at(i)) {
      ans2++;
    }
  }
  ans = min(ans1, ans2);

  printf("%d", ans);
  return 0;
}


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

int a[26];
int main() {
	for(int i=0; i<26; ++i) {
		a[i]=0;
	}

	string s; cin >> s;

	for(int i=0; i<s.length(); ++i) {
		if (a[(s[i]-'a')] > 0) {
			cout << "no" << endl;
			return 0;
		}
		a[(s[i]-'a')]++;
	}
	
	cout << "yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256