akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size() - 1; ++i) {
    os << v[i] << " ";
  }
  if (v.size() > 0) {
    os << v[v.size() - 1] << endl;
  }
  return os;
}

int main() {
  int h,w,n;
  cin >> h >> w >> n;
  int sr, sc;
  cin >> sr >> sc;
  --sr;
  --sc;
  string s, t;
  cin >> s >> t;
  int tmp = sr;
  REP(i,n){
    if (s[i] == 'U') {
      tmp--;
    }
    if (tmp < 0) {
      cout << "NO" << endl;
      return 0;
    }
    if (t[i] == 'D' && tmp < h - 1){
      tmp++;
    }
  }
  tmp = sr;
  REP(i, n) {
    if (s[i] == 'D'){
      tmp++;
    }
    if (tmp > h - 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (t[i] == 'U' && tmp > 0){
      tmp--;
    }
  }
  tmp = sc;
  REP(i, n) {
    if (s[i] == 'L'){
      tmp--;
    }
    if (tmp < 0) {
      cout << "NO" << endl;
      return 0;
    }
    if (t[i] == 'R' && tmp < w - 1){
      tmp++;
    }
  }
  tmp = sc;
  REP(i, n) {
    if (s[i] == 'R'){
      tmp++;
    }
    if (tmp > w - 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (t[i] == 'L' && tmp > 0){
      tmp--;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 776
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
    ll res=1;
    while(b)
    {
        if(b&1LL)
            res=(res*a)%c;
        a=(a*a)%c;
        b>>=1;
    }
    return res;
}

int main()
{
    FASTIO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
     cin>>n;

    string s;
     cin>>s;
     string pat="ABC";
     int j=0;
     ll ans=0;

     for(int i=0;i<n;i++)
     {
        if(s[i]==pat[j])
        {
            j++;
        }
        else if(s[i]=='A')
            j=1;
        else
            j=0;

        if(j==3)
        {
            ans++;
            j=0;
        }
     }

     cout<<ans<<"\n";
    
    return 0;
}

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

signed main() {
  int K, T; cin >> K >> T;
  vector<int> a(T);
  rep(i, T) cin >> a[i];
  
  sort(all(a));
  
  int ans = 0;
  
  int k = 0;
  rep(i, T-1) k += a[i];
  
  if(k < a[T-1]) ans = a[T-1] - k - 1;
  
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m;
	while(cin>>n>>m,n+m)
	{
		int d[105]={};
		int a,b;
		for (int i = 0; i < n; ++i)
		{
			cin>>a>>b;
			--a;
			d[a]=max(d[a],b);
		}
		int ans=0;
		for (int i = 0; i < m; ++i) ans+=d[i];
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
  int tracks[10];
  int n;
  int p;

  p = 0;
  while (cin >> n) {
    if (n) {
      tracks[p++] = n;
    } else {
      cout << tracks[--p] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X,Y;
    cin >> X >> Y;
    
    int a = (4 * X - Y);
    if (a % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    a /= 2;
    int b = X - a;
    if (a>=0&&b>=0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    if(n==1){
        cout<<"Yes"<<endl;
        cout<<2<<endl;
        cout<<"1 1"<<endl;
        cout<<"1 1"<<endl;
        return 0;
    }
    int x=-1;
    REP(i,n){
        if(i*(i+1)/2==n){
            x=i;
            break;
        }
    }
    if(x==-1){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    vvi ans(x+1);
    int cnt=0;
    REP(i,x+1){
        REP(j,i){
            ans[i].pb(cnt);
            ans[j].pb(cnt);
            cnt++;
        }
    }
    cout<<x+1<<endl;
    REP(i,x+1){
        cout<<ans[i].size();
        REP(j,ans[i].size()){
            cout<<" "<<ans[i][j]+1;
        }cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 2304
input_line = input().split(" ")
X=int(input_line[0])
Y=int(input_line[1])
Z=4*X-Y
H=Z/2
R=X-H

if H<0 or 2*X>Y:
  print("No")
elif int(H)+int(R)==X and int(2*H)+int(4*R)==Y:
  print("Yes")
  
else:
  print("No")

Measured memory_bytes: 9188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;

LL l[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	LL k; cin >> k; cout << l[k] << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000000007

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))
#define mx 6e5 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#include<bits/stdc++.h>
#define ll long long
const int maxn = 20005;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
*x,S,T=*$<
eval"H,W,N,I,J="+x.join.split*?,
puts [[H,I,?U,?D],[W,J,?L,?R]].all?{|w,j,a,b|l=0
r=w
(1..N).all?{|k|T[~k]==a&&r<w&&r+=1
T[~k]==b&&l>0&&l-=1
S[~k]==a&&l<w&&l+=1
S[~k]==b&&r>0&&r-=1
l<r}&&l<j&&j<=r}?:YES: :NO

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

#define Ff(i,j,n)  for (i = j ; i < n; i++)
#define Fb(i,j,n)    for (i = (n - 1); i >= j; i--)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<long, long>
#define pi 3.14159265358979323846
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(), x.end()
#define trav(i,x) for(auto& i:x)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef vector < long long > vll;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;

// const ll mod = 998244353;
const ll N = 1e18;
// ll binpow(ll b, ll p) { ll ans = 1; while (p > 0) {if (p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;} return ans;}
// ll inv(ll x) {return binpow(x, mod - 2);}
// ll divide(ll x, ll y) {return ((x % mod) * (inv(y))) % mod;}


int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS
	int t = 1;
	// cin >> t;
	while (t--) {
		// string s;
		// int i;
		// cin >> s;
		// int p = 0;
		// int l = s.length();
		// Ff(i, 0, l)
		// p = (p + s[i] - '0') % N;
		// if (p % 9)cout << "No";
		// else cout << "Yes";
		// cout << endl;
		int n;
		cin >> n;
		int a[n];
		int i;
		Ff(i, 0, n)
		cin >> a[i];
		int p = 0;
		Ff(i, 1, n) {
			if (a[i] < a[i - 1]) {
				p += a[i - 1] - a[i];
				a[i] = a[i - 1];
			}
		}

		cout << p << endl;

	}


	return 0;
}

Measured memory_bytes: 5224
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

struct Info
{
	int id;
	string name;
	int score;

	Info()
	{

	}

	Info(int i, string s, int n)
	{
		id = i + 1;
		name = s;
		score = n;
	}
};

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

	vector<Info> info(n);

	for (int i = 0; i < n; i++)
	{
		string s;
		int n;
		cin >> s >> n;
		
		info.at(i) = Info(i, s, n);
	}

	sort(info.begin(), info.end(), [](const Info &a, const Info &b)
	{
		if (a.name != b.name)
		{
			return a.name < b.name;
		}
		else
		{
			return a.score > b.score;
		}
	}
	);


	for (int i = 0; i < n; i++)
	{
		cout << info.at(i).id << endl;
	}
}


Measured memory_bytes: 256
n,m,X,Y = map(int,input().split())
#print(n,m,X,Y)
x=list(map(int,input().split()))
x.append(X)
y=list(map(int,input().split()))
y.append(Y)
#print(max(x),min(y))
if X < Y:
    if max(x) < min(y):
        print('No War')
    else:
        print('War')
else:
    print('War')


Measured memory_bytes: 2940
package main

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

// Print frame
func main() {
	sc := bufio.NewScanner(os.Stdin)
	s := ""
	for {
		sc.Scan()
		ary := strings.Split(strings.TrimSpace(sc.Text()), " ")
		H, _ := strconv.Atoi(ary[0])
		W, _ := strconv.Atoi(ary[1])
		if H == 0 && W == 0 {
			break
		}
		for i := 0; i < H; i++ {
			for j := 0; j < W; j++ {
				if i == 0 || i == H-1 {
					s += "#"
				} else {
					if j == 0 || j == W-1 {
						s += "#"
					} else {
						s += "."
					}
				}
			}
			s += "\n"
		}
		s += "\n"
	}
	fmt.Print(s)
}



Measured memory_bytes: 8400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int []arr=new int[n];
		int []dp= new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		dp[0]=0;
		for(int i=1;i<n;i++) {
			if(i-2>=0) {
				dp[i]=Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]),dp[i-2]+Math.abs(arr[i]-arr[i-2]));
			}
			else
				dp[i]=dp[i-1]+Math.abs(arr[i]-arr[i-1]);
		}
		System.out.println(dp[n-1]);
	}

}


Measured memory_bytes: 59176
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2022202;
int fac[N],ifac[N];
int p=1e9+7;
ll ans=0;
ll power(int a,int b){
	int sum=1;
	for (; b; b>>=1){
		if (b&1)	sum=1ll*sum*a%p;
		a=1ll*a*a%p;
	}
	return sum;
}
ll C(int n,int m){return 1ll*fac[n]*ifac[m]%p*ifac[n-m]%p;}
ll calc(int n,int m){
	if (n<0||m<0)	return 0;
	ll sum=0;
	for (int i=1; i<=n+1; i++)
		sum=(sum+C(i+m,i))%p;
	return sum%p;
}

int main(){
	int n1,m1,n2,m2;
	scanf("%d%d%d%d",&n1,&m1,&n2,&m2);
	int n=n2+m2+1;
	ifac[0]=fac[0]=1;
	for (int i=1; i<=n; i++)	fac[i]=1ll*fac[i-1]*i%p;
	ifac[n]=power(fac[n],p-2);
	for (int i=n-1; i>=1; i--)	ifac[i]=1ll*ifac[i+1]*(i+1)%p;
	ll ans=calc(n2,m2)-calc(n2,m1-1)-calc(n1-1,m2)+calc(n1-1,m1-1);
	printf("%lld\n",(ans%p+p)%p);
	return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String mozi = scan.next();
		int matu = mozi.length();
		int count = 0;

		for(int i=0;i<matu;i++) {
			if(mozi.substring(i,i+1).equals(mozi.substring(matu-(i+1),matu-i))) {

				continue;

			}else {
				count++;
			}

		}

		System.out.println(count/2);
		scan.close();

	}

}


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

int main(){
  int a,b,c, f = 0, s = 0;
  cin>>a>>b>>c;
  if(a == 5)
    ++f;
  if(b == 5)
    ++f;
  if(c == 5)
    ++f;
  
  if(a == 7)
    ++s;
  if(b == 7)
    ++s;
  if(c == 7)
    ++s;
  
  if(s == 1 && f == 2)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[150][10][76];
int sec[150][10];
int val[150][10];
int size[150];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			scanf("%d",size+i);
			for(int j=0;j<size[i];j++){
				scanf("%d%d",&sec[i][j],&val[i][j]);
			}
		}
		for(int i=0;i<10;i++)
			for(int j=0;j<75;j++)
				dp[0][i][j]=99999999;
		for(int i=0;i<size[0];i++){
			dp[0][i][b]=0;
		}
		for(int i=0;i<size[1];i++){
			dp[1][i][b-1]=0;
		}
		for(int i=1;i<a;i++){
			for(int j=0;j<size[i];j++){
				int Min=1000000000;
				for(int k=0;k<size[i-1];k++){
					Min=min(Min,dp[i-1][k][b]+(val[i][j]+val[i-1][k])*abs(sec[i][j]-sec[i-1][k]));
				}
				dp[i][j][b]=Min;
			}
			if(i>1)
			for(int j=0;j<b;j++){
				for(int k=0;k<size[i];k++){
					int Min=1000000000;
					for(int l=0;l<size[i-1];l++){
						Min=min(Min,dp[i-1][l][j]+(val[i][k]+val[i-1][l])*abs(sec[i][k]-sec[i-1][l]));
					}
					for(int l=0;l<size[i-2];l++){
						Min=min(Min,dp[i-2][l][j+1]+(val[i][k]+val[i-2][l])*abs(sec[i][k]-sec[i-2][l]));
					}
					dp[i][k][j]=Min;
				}
			}
		}
		int ret=1000000000;
		for(int i=0;i<size[a-1];i++){
			for(int j=0;j<b+1;j++){
				ret=min(ret,dp[a-1][i][j]);
			}
		}
		for(int i=0;i<size[a-2];i++){
			for(int j=1;j<b+1;j++){
				ret=min(ret,dp[a-2][i][j]);
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> p)
{
    int cnt = 0;
    int duplicate = 0;
    for (int i = 0; i < N; i++)
    {
        if (p[i] == i + 1)
        {
            cnt++;
            if (i != N - 1)
            {
                swap(p[i], p[i + 1]);
            }
        }
    }
    cout << cnt << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> p(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
  int masu;
  int count=0;
  scanf("%d",&masu);
  if((masu/100)%2==1) count++;
  if((masu/10)%2==1) count++;
  if(masu%2==1) count++;
     printf("%d\n",count);
     return 0;
}



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

int main() {
  // n: lines, b: building, f: floor, r: room, v: persons
  int n, b, f, r, v;
  int tenants[4][3][10];  // [building][floor][room]
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        tenants[i][j][k] = 0;
      }   
    }   
  }

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    tenants[b - 1][f - 1][r - 1] += v;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << " " << tenants[i][j][k];
      }   
      cout << endl;
    }   
    if (i !=3) cout << "####################" << endl;
  }
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	long long n,m,k,a[2000005];
	long long b[2000005];
	long long ans=0;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
      	if(i!=0)
  		a[i]+=a[i-1];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
      	if(i!=0)
		b[i]+=b[i-1];
      if(k>=b[i]){
        ans=i+1;
      }
	}
  	b[m]=20000000000000001;
	for(int i=0;i<n;i++){
		long long ta=k-a[i];
		if(ta<0){
			continue;
		}
		auto tab=upper_bound(b,b+m+1,ta)-b;
		if(ans<i+tab+1){
			ans=i+tab+1;
		}
	}
  	if(k>=a[n-1]+b[m-1]){
      ans=n+m;
    }
	cout<<ans<<endl;
    return(0);
}

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

using namespace std;

int bubble(vector<int> &vec,int to,int changes){
    if(to==0) return changes;
    for(int i=0;i<to;i++){
        if(vec[i] > vec[i+1]){
            int tmp = vec[i];
            vec[i] = vec[i+1];
            vec[i+1] = tmp;
            changes++;
        }
    }
    return bubble(vec,to-1,changes);
}

int main(){
    int n = 0;
    while(cin >> n && n != 0){
        vector<int> vec;
        for(int i=0;i<n;i++){
            int x;
            cin >> x;
            vec.push_back(x);
        }
        cout << bubble(vec,vec.size()-1,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
bool is_prime(long long a){
  for(long long i = 2; a >= i*i; i++){
    if(!(a%i))return false;
  }
  return true;
}
int main(){
  long long a;cin>>a;
  if(is_prime(a)){
    cout << a-1 << endl;
    return 0;
  }
  long long ans = a;
  for(long long i = 2; a >= i*i; i++){
    if(!(a%i)){
      ans = min(ans,i+a/i-2);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n;
	int num[100005];
	int seq[100005];
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>num[i];
	}
	for(int i=1;i<=n;i++)
	{
		seq[num[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<seq[i]<<" ";
	}
	return 0;
 }

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int A, B;

	cin >> A >> B;

	if ((A + B) % 2 == 0) {
		cout << (A + B) / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll ans = 0ll;
    int c = 0;
    rep(i,0,s.size()){
        if(s[i]=='W'){
            ans += (i-c);
            c++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include <cstdint>
#include <cstdio>
#include <utility>
#include <vector>

#include <atcoder/modint>
#include <atcoder/lazysegtree>

using mi = atcoder::modint998244353;

struct neko {
  intmax_t zeros = 0, ones = 0, invs = 0;
  neko() = default;
  neko(intmax_t z, intmax_t o, intmax_t i): zeros(z), ones(o), invs(i) {}
};

neko op(neko x, neko y) {
  // 分割統治で転倒数を求めるやつを考えるとそれはそうという気持ちになる
  return neko(x.zeros+y.zeros, x.ones+y.ones, x.invs+y.invs+(x.ones*y.zeros));
}
neko e() { return neko(); }
neko mapping(bool f, neko x) {
  if (!f) return x;
  return neko(x.ones, x.zeros, (x.zeros*x.ones)-x.invs);
}
bool composition(bool f, bool g) {
  return f ^ g;
}
bool id() {
  return false;
}

int main() {
  int n, q;
  scanf("%d %d", &n, &q);

  std::vector<neko> a(n);
  for (auto& ai: a) {
    int tmp;
    scanf("%d", &tmp);
    if (tmp == 0) {
      ai = neko(1, 0, 0);
    } else {
      ai = neko(0, 1, 0);
    }
  }

  atcoder::lazy_segtree<neko, op, e, bool, mapping, composition, id> st(a);

  for (int i = 0; i < q; ++i) {
    int t, l, r;
    scanf("%d %d %d", &t, &l, &r);
    --l;

    if (t == 1) {
      st.apply(l, r, true);
    } else if (t == 2) {
      printf("%jd\n", st.prod(l, r).invs);
    }
  }
}


Measured memory_bytes: 20464
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

// 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 = 1000000007;
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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

mint dp[2009][2009];

int main(){
  int n,m;
  int a[2009],b[2009];
  cin>>n>>m;
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];

  rep(i,n+1)dp[i][0]=1;
  rep(i,m+1)dp[0][i]=1;
  rep(i,n){
    rep(j,m){
      if(a[i]==b[j]){
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1];
      }
      else{
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j];
      }
    }
  }

  cout<<dp[n][m].x<<endl;

  return(0);
}


Measured memory_bytes: 31744
if __name__ == '__main__':
    c =[list(map(int, input().split())) for _ in range(3)]

    answer = 'No'
    for a1 in range(101):
        for a2 in range(101):
            for a3 in range(101):
                b1 = (c[0][0] + c[1][0] + c[2][0]) - (a1 + a2 + a3)
                b2 = (c[0][1] + c[1][1] + c[2][1]) - (a1 + a2 + a3)
                b3 = (c[0][2] + c[1][2] + c[2][2]) - (a1 + a2 + a3)

                if b1 % 3 == 0 and b2 % 3 == 0 and b3 % 3 == 0:
                    answer = 'Yes'
                    break
    print(answer)

Measured memory_bytes: 3064
from collections import defaultdict

n,k,q = list(map(int,input().split()))
d = defaultdict(int)
for _ in range(q):
    t = int(input())
    d[t-1] += 1

for i in range(n):
    if k - q + d[i] > 0:print("Yes")
    else:print("No")

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

int main(){
  int N,A;
  
  cin >> N;
  cin >> A;
  
  if ( 1<=N<=100 && 0<=A<=N*N ){
    cout << N*N - A << endl;
  }
  else {
    cout << "error" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	if (a>b){
		cout<<(a-1);
	}
	else{
		cout<<min(a,b);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
priority_queue<long long>q[3];
long long a[N],b[N],c[N],ans;
int main(){
	int n,m,A,B,C;
	cin>>n>>m>>A>>B>>C; 
	for(int i=1;i<=A;i++)scanf("%lld",&a[i]),q[0].push(a[i]);
	for(int i=1;i<=B;i++)scanf("%lld",&b[i]),q[1].push(b[i]);
	for(int i=1;i<=C;i++)scanf("%lld",&c[i]),q[2].push(c[i]);
	for(int i=1;i<=n;i++){
		long long t=q[0].top();q[0].pop();
		q[2].push(t);
	}
	for(int i=1;i<=m;i++){
		long long t=q[1].top();q[1].pop();
		q[2].push(t);
	}
	for(int i=1;i<=n+m;i++){
		ans+=q[2].top();q[2].pop();
	}
	cout<<ans;
} 

Measured memory_bytes: 11492
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;

int n,u,v,a,b,dp[2][N],ans;
vector <int> adj[N];
queue <int> q;
bool vis[2][N];

void bfs(int node,int idx)
{
	q.push(node);
	vis[idx][node]=true;
	dp[idx][node]=0;

	while(not q.empty())
	{
		int node=q.front();
		q.pop();

		for(auto child:adj[node])
		{
			if(vis[idx][child]) continue;
			q.push(child);
			vis[idx][child]=true;
			dp[idx][child]=dp[idx][node]+1;
		}
	}
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	u=a,v=b;
	bfs(u,0),bfs(v,1);
	for(int i=1;i<=n;i++)
	{
		if(dp[0][i]<=dp[1][i])
			ans=max(ans,dp[1][i]-1);
	}
	printf("%d",ans);
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;

int number(State &begin);
int term(State &begin);
int expression(State &begin);
int factor(State &begin);

int number(State &begin) {
	int ret = 0;
	
	while (isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	// cout << "number :: " << ret << endl;
	return ret;
}
int term(State &begin) {
	int ret = factor(begin);
	
	while(1) {
		if (*begin == '*') {
			begin++;
			// cout << "go factor // *" << endl;
			ret *= factor(begin);
		}
		else if (*begin == '/') {
			begin++;
			// cout << "go factor // /" << endl;
			ret /= factor(begin);
		}
		else break;
	}
	// // cout << "term :: " << ret << endl;
    return ret;
}
int expression(State &begin) {
	int ret = term(begin);
	
	while(1) {
		if (*begin == '+') {
			begin++;
			// // cout << "go term // +" << endl;
			ret += term(begin);
		}
		else if (*begin == '-') {
			begin++;
			// // cout << "go term // -" << endl;
			ret -= term(begin);
        }
        else break;
	}
	// // cout << "expression :: " << ret << endl;
	return ret;
}
int factor(State &begin) {
	if (*begin == '(') {
		begin++; 
		// // cout << "go expression" << endl;
		int ret = expression(begin);
		// // cout << "factor :: " << ret << endl;
		begin++;
		return ret;
	}
	else return number(begin);
}

int main(void) {
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++) {
		string s;
		getline(cin, s);
		
		State begin = s.begin();
		 // cout << "Start !!!" << endl;
		cout << expression(begin) << endl;
	}
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int n;
string s;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>s;
    n=s.length();
    int cnt=0;
    for (int i=0; i<n; ) {
	int j=i;
	while (j<n && s[i]==s[j]) j++;
	cnt++;
	i=j;
    }

    cnt--;
    out(cnt);
  

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long ans = 1;
		int mod = (int) Math.pow(10, 9) + 7;
		for (int i = 2; i <= n; i++) {
			for (int j = 2; (i % j != 0 && j < i) || j == i; j++) {
				if (j == i) {
					int s = 0;
					for (int k = 1; k <= n; k++) {
						s += findS(k, i);

					}

					ans = (ans % mod * (s + 1) % mod) % mod;

				}
			}
		}
		System.out.println(ans);
	}

	private static int findS(int k, int i) {
		int s = 0;
		for (int j = k; j % i == 0; j /= i) {

			s++;

		}
		return s;
	}
}


Measured memory_bytes: 21460
#include <iostream>

using namespace std;

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

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

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] * 4 * m >= s) {
            cnt++;
        }
    }

    cout << (cnt >= m ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
T = []
mod = 998244353
for i in range(K):
    L, R = map(int, input().split())
    T.append([L, R])
dp = [0]*(N+1)
dp[1] = 1
Total = [0]*(N+1)
Total[1] = 1
for i in range(2, N+1):
    for j in range(K):
        L, R = T[j]
        dp[i] += Total[max(0, i-L)] - Total[max(0, i-R-1)]
    dp[i] %= mod
    Total[i] = Total[i-1] + dp[i]
    Total[i] %= mod
print(dp[N])

Measured memory_bytes: 71632
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/*double sort(const double *a,const double *b){
return *b-*a;
}*/
int main(void){
  int n;
  scanf("%d",&n);
  double a[n];
  for(int i=0;i<n;i++){
	scanf("%lf",&a[i]);
  }
  //qsort(a,n,sizeof(a[0]),sort);
   for(int i=0;i<n-1;i++){
	for(int j=i+1;j<n;j++){
	if(a[i]<a[j]){
      double w=a[i];
      a[i]=a[j];
      a[j]=w;
  }
    }}
double sum=0;
  for(int i=0;i<n-1;i++){
    //printf("%lf\n",a[i]/pow(2,i+1));
	sum+=a[i]/pow(2,i+1);
  }
  sum+=a[n-1]/pow(2,n-1);
  printf("%lf",sum);
  return 0;
}

Measured memory_bytes: 128
# -*- coding utf-8 -*-

x=int(input())

if x==1:
    print("1")
elif 2<=x<4:
    print("2")
elif 4<=x<8:
    print("4")
elif 8<=x<16:
    print("8")
elif 16<=x<32:
    print("16")
elif 32<=x<64:
    print("32")
elif 64<=x<=100:
    print("64")


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define INF 2000000000
#define ull unsigned long long

int main(){
    int n;
    scanf("%d",&n);
    if (n%10==3) {
        printf("bon");
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
        printf("pon");
    }else{
        printf("hon");
    }
    return 0;
}


Measured memory_bytes: 1728
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
import numpy as np
B = abs(np.array(A)-X)
i = np.where(B == min(B))[0][0]
if A[i]-X > 0:
    print(min(M-i,i))
else:
    print(min(i+1,M-i-1))

Measured memory_bytes: 14432
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<vector>
#include<list>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set<int>aa;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(aa.find(x)==aa.end())
        {
            aa.insert(x);
        }
        else
            aa.erase(x);
    }
    cout<<aa.size()<<endl;
    return 0;
}


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

typedef int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], int first, int last){
    int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int gcd(int x, int y){
    if (y == 0) return x;
    else        return gcd(y, x % y);
}

int main() {
    long long int x,ans,sen,go,sen_a,go_a;
    scanf("%lld",&x);
    sen_a=x%500;
    sen=(x-sen_a)/500;
    go_a=(x-(sen*500))%5;
    go=(x-(sen*500)-go_a)/5;
    ans=(sen*1000)+(go*5);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 128
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = Counter(D)
if 0 not in D.keys():
    print(0)
    exit()
if D[0] > 1:
    print(0)
    exit()
max_key = max(D.keys())
cnt = [0] * (max_key + 1)
for i in range(0, max_key + 1):
    cnt[i] = D[i]
ans = 1
for i in range(1, len(cnt)):
    ans *= (cnt[i-1] ** cnt[i])
    ans %= 998244353
print(ans % 998244353)

Measured memory_bytes: 99876
from heapq import heapify, heappop, heappush

n = int(input())
a = list(map(int, input().split()))
b = a[::-1]

left_q = a[:n]
heapify(left_q)
sum_left = sum(left_q)
left = [sum_left]

right_q = [-i for i in b[:n]]
heapify(right_q)
sum_right = sum(right_q)
right = [sum_right]

for i in range(n):
    if a[i+n] > left_q[0]:
        min_a = heappop(left_q)
        sum_left -= min_a
        sum_left += a[i+n]
        heappush(left_q, a[i+n])
    left.append(sum_left)
    if b[i+n] < -right_q[0]:
        min_b = heappop(right_q)
        sum_right -= min_b
        sum_right += -b[i+n]
        heappush(right_q,-b[i+n])
    right.append(sum_right)
ans = -float("inf")
for i, j in zip(left, right[::-1]):
    ans = max(ans, j+i)
print(ans)

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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a%3==0||b%3==0||(a+b)%3==0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int[] x;
		int[] y;
		x = new int[200];
		y = new int[200];
		for (int i = 0; i < 200; i++) {
			x[i] = 0;
			y[i] = 0;
		}

		while (true) {
			String N = s.next();
			int n = Integer.parseInt(N);
			if (n == 0)
				break;

			for (int t = 1; t < n; t++) {
				String Num1 = s.next();
				String Num2 = s.next();
				int num1 = Integer.parseInt(Num1);
				int num2 = Integer.parseInt(Num2);

				switch (num2) {
				case 0:
					x[t] = x[num1] - 1;
					y[t] = y[num1];
					break;
				case 1:
					x[t] = x[num1];
					y[t] = y[num1] - 1;
					break;
				case 2:
					x[t] = x[num1] + 1;
					y[t] = y[num1];
					break;
				case 3:
					x[t] = x[num1];
					y[t] = y[num1] + 1;
					break;
				}
			}

			int width, height;
			int xmax = 0;
			int xmin = 0;
			int ymax = 0;
			int ymin = 0;

			for (int i = 0; i < n; i++) {
				xmax = Math.max(xmax, x[i]);
				xmin = Math.min(xmin, x[i]);
				ymax = Math.max(ymax, y[i]);
				ymin = Math.min(ymin, y[i]);
			}

			width = xmax - xmin + 1;
			height = ymax - ymin + 1;
			System.out.println(width+" "+height);
		}
	}
}

Measured memory_bytes: 27260
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define w(x) (x<=n?a[x]:b[x-n-1])
using namespace std;

int n,m,tot,a[100100],b[100100],c[200100],fa[200100],cnt[200100],ans;

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

bool cmp(int x,int y)
{
    return w(x)<w(y);
}

int find(int x)
{
    if (fa[x]==x)
        return x;
    return fa[x]=find(fa[x]);
}

int main()
{
    n=getint();
    repu(i,1,n)
        a[0]^=a[i]=getint();
    repu(i,1,n)
        b[0]^=b[i]=getint();
    repu(i,0,n)
        if (!i || a[i]!=b[i])
            c[++tot]=i,c[++tot]=i+n+1;
    sort(c+1,c+1+tot,cmp);
    int lst=-1;
    repu(i,1,tot)
        m+=w(c[i])!=lst,lst=w(c[i]),w(c[i])=m;
    repu(i,1,m)
        fa[i]=i;
    repu(i,0,n)
        if (a[i]!=b[i])
        {
            ++cnt[a[i]],--cnt[b[i]];
            fa[find(a[i])]=find(b[i]);
        }
    ans=tot/2-2;
    repu(i,1,m)
    {
        ans+=fa[i]==i;
        if (cnt[i])
        {
            puts("-1");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4096
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>

using namespace std;

const int mod = 1e9 + 7;
long long n, dp[2000005][3][3];

int main() {
    cin >> n;
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i][0][0] = (dp[i - 1][0][0] * 8) % mod;
        dp[i][1][0] = (dp[i - 1][1][0] * 9 + dp[i - 1][0][0]) % mod;
        dp[i][0][1] = (dp[i - 1][0][1] * 9 + dp[i - 1][0][0]) % mod;
        dp[i][1][1] = (dp[i - 1][0][1] + dp[i - 1][1][0] + dp[i - 1][1][1] * 10) % mod;
    }
    cout << dp[n][1][1] << endl;
    return 0;
}

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

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			long N = scan.nextLong();
		ArrayList<Long> zenyaku_a = enum_div(N);
		ArrayList<Long> zenyaku_b = enum_div2(zenyaku_a,N);
			
		long min=zenyaku_a.get(0)+zenyaku_b.get(0);
		
			for(int i = 1;i<zenyaku_a.size();i++) {
				if(min>zenyaku_a.get(i)+zenyaku_b.get(i)) {
					min = zenyaku_a.get(i)+zenyaku_b.get(i);
				}
			}
			
			
			System.out.println(min-2);
			;
			
		}
		
		
	}
	
	
	
	
	
	private static ArrayList<Long> enum_div(long n){//数字１〜ｎまでの約数を全部Allaylistに詰め込むメソッド
		ArrayList<Long> ret = new ArrayList<Long>();
		for(long i = 1;i*i<=n;i++) {
			if(n%i==0) {
				ret.add(i);
				if(i!=1&&i*i!=n){
					ret.add(n/i);
				}
			}
		}
		
		ret.add(n);
		
		//ただここまでだと格納した約数はソートされてない
		
		Collections.sort(ret);//int型、Sting型くらいの格納した奴ならコレクションクラスのソートが使える。
		//ソートしてからcollections.reverseつかえば降順にもできる
		return ret;
		
		
	}
	
	private static ArrayList<Long> enum_div2(ArrayList<Long> a,long n){//数字１〜ｎまでの約数を全部Allaylistに詰め込むメソッド
		ArrayList<Long> ret = new ArrayList<Long>();
		for(int i =0;i<a.size();i++) {
		ret.add(n/a.get(i));
		}
		
		return ret;
		
		
	}
	
	
	
	
	
	
	
		

	}


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

#define pi acos(-1)
#define eps 1e-9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define clock 1.0*clock()/CLOCKS_PER_SEC
#define filein freopen("in.txt","r",stdin)
#define fileout freopen("out.txt","w",stdout)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int dr[]={0,-1,0,1,-1,-1,1,1};
const int dc[]={1,0,-1,0,1,-1,-1,1};
const int maxx = 0;

int main ()
{
	ll a,t;
	cin>>a>>t;
	ll prev,ans=0;
	cin>>prev;
	for(ll i=1;i<a;i++){
		ll now;
		cin>>now;
		if(now-prev>=t) ans += t;
		else ans += (now-prev);
		prev = now;
	}
	ans += t;
	cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    char n[3];

    cin >> n;

    if((n[0]=='7') ||(n[1]=='7') || (n[2]=='7')) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3632
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    if A[i] % 2 == 0:
        if A[i] % 3 == 0 or A[i] % 5 ==0:
            continue
        else:
            print('DENIED')
            exit()
print('APPROVED')

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

int C[128];

int main() {
  C['J'] = 0;
  C['O'] = 1;
  C['I'] = 2;
  for(int H, W; cin >> H >> W;) {
    vector<vector<int> > G(H);
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        char c; cin >> c;
        G[i].push_back(C[(int)c]);
      }
    }
    vector<vector<int> > F(2);
    for(int i = 0; i < 2; ++i) {
      for(int j = 0; j < 2; ++j) {
        char c; cin >> c;
        F[i].push_back(C[(int)c]);
      }
    }

    vector<vector<int> > A(H, vector<int>(W, 0));
    vector<vector<vector<int> > > B(H, vector<vector<int> >(W, vector<int>(3, 0)));
    int S = 0;
    for(int i = 0; i+2 <= H; ++i) {
      for(int j = 0; j+2 <= W; ++j) {
        vector<int> pi, pj, pc;
        for(int a = 0; a < 2; ++a) {
          for(int b = 0; b < 2; ++b) {
            if(G[i+a][j+b] != F[a][b]) {
              pi.push_back(i+a);
              pj.push_back(j+b);
              pc.push_back(F[a][b]);
            }
          }
        }
        if(pi.empty()) {
          S += 1;
          A[i][j] = 1;
        } else if(pi.size() == 1) {
          B[pi[0]][pj[0]][pc[0]] += 1;
        }
      }
    }
    int res = S;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        for(int k = 0; k < 3; ++k) {
          int T = S + B[i][j][k] - A[i][j];
          if(i) T -= A[i-1][j];
          if(j) T -= A[i][j-1];
          if(i && j) T -= A[i-1][j-1];
          res = max(res, T);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 63836
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[300][300];
	bool owari = 0;
	rep(i, N) rep(j, N) A[i][j] = getint();
	rep(i, N) A[i][i] = 1e9;

	ll kotae = 0;
	rep(i, N) {
		rep(j, i) {
			auto a = A[i] + j;
			auto b = A[i];
			auto c = A[j];
			bool B = 1;
			rep(k, N) {
				if (*a > b[k] + c[k]) {
					printf("-1");
					return 0;
				}
				if (*a == b[k] + c[k]) B = 0;
			}
			if (B) kotae += *a;
		}
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N=2e5;
int n,cnt,hd[N],v[N],nxt[N],w[N];
long long d[N];
void add(int x,int y,int z){
	v[++cnt]=y;
	nxt[cnt]=hd[x];
	w[cnt]=z;
	hd[x]=cnt;
}
void dfs(int u,int fa){
    for(int i=hd[u];i;i=nxt[i])
    if(v[i]!=fa){
        d[v[i]]=d[u]+w[i];
        dfs(v[i],u);
    }
}
int main(){
    cin>>n;
    for(int i=1,x,y,z;i<n;i++){
		cin>>x>>y>>z;
		add(x,y,z);
		add(y,x,z);
	}
    dfs(1,0);
    for(int i=1;i<=n;i++){
        int op=d[i]&1;
        cout<<op<<endl;
    }
}

Measured memory_bytes: 6144