akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;

LL n,m,ans;
//vector<int>e[N];
int Write[20],WRI;
void judge(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int read(){int d=0,f=1; char c=getchar(); while (c<'0'||c>'9'){if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') d=d*10+c-48,c=getchar(); return d*f;}
void write(int x){if (!x){putchar('0'); return;}if (x<0) putchar('-'),x=-x;for (WRI=1;x;x/=10,WRI++) Write[WRI]=x%10;for (int i=WRI-1;i;i--) putchar((char)(Write[i]+48));}
int main()
{
	//judge();
	scanf("%lld%lld",&n,&m);
	if (n>=2&&m>=2) printf("%lld",(n-2)*(m-2));
	else if (n==1&&m==1) printf("1");
	else if (n==1) printf("%lld",m-2);
	else printf("%lld",n-2);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
char s[110];
int main()
{
	scanf("%s",s+1);int len=strlen(s+1);
	if(s[1]!='A') printf("WA\n");
	else
	{
		bool pd=1;int num=0;
		for(int i=2;i<len;i++)
		{
			if(i==2&&s[i]>='A'&&s[i]<='Z') {pd=0;break;}
			if(s[i]=='C') num++;
			else if(s[i]>='A'&&s[i]<='Z') {pd=0;break;}
		}
		if(pd&&s[len]<='z'&&s[len]>='a'&&num==1) printf("AC\n");
		else printf("WA\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdint.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MIN(a,b) ((a<b) ? a : b)
#define MAX_N 200000

int main(void) {
  int64_t N, T;
  scanf("%ld %ld", &N, &T);

  int64_t t[MAX_N];
  rep(i, N) {
    scanf("%ld", &t[i]);
  }

  int64_t ANS = 0;
  for(int i = 1; i < N; i++) {
    ANS += MIN((t[i] - t[i-1]), T);
  }
  ANS+=T;
  printf("%ld\n", ANS);
  return 0;
}


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

A = sorted(A,reverse=True)

if N <= 3:
  ans = sum(A[:-1])
elif N % 2 == 0:
  ans = A[0] + sum(A[1:(N-2)//2+1])*2
elif N % 2 == 1:
  ans = A[0] + sum(A[1:(N-2)//2+1])*2 + A[1+(N-2)//2]
  
print(ans)


Measured memory_bytes: 31484
#include <cstdio>
int a, b, c, d;

int main() {
	while(~scanf("%d %d %d %d", &a, &b, &c, &d)) {
		if(a + b < c + d) puts("Right");
		else if(a + b == c + d) puts("Balanced");
		else puts("Left");
	}
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	ll ans = 1;
	rep(i, n){
		ans *= i+1;
		if(ans > 1000000007) ans %= 1000000007;
	}
	if(ans >= 1000000007) ans %= 1000000007;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    std::cin >> n >>m;
    int a[2][200000];
    std::set<int> p,q;
    for (int i = 0; i < m; i++) {
        std::cin >> a[0][i] >> a[1][i];
        if(a[0][i]==1){
            p.insert(a[1][i]);
        }
        if(a[1][i]==n){
            q.insert(a[0][i]);
        }
    }
    for (auto itr=p.begin();itr!=p.end();++itr) {
        auto it =q.find(*itr);
        if(it != q.end()){
            std::cout << "POSSIBLE" << std::endl;
            return 0;
        }
    }
    std::cout << "IMPOSSIBLE" << std::endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

int main() {
  string s;
  while(cin >> s) {
    int joi = 0, ioi = 0;
    rep(i, s.size() - 2) {
      if(s.substr(i, 3) == "JOI") joi++;
      if(s.substr(i, 3) == "IOI") ioi++;
    }
    cout << joi << endl << ioi << endl;
  }
  return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

char grid[110][110];
bool visited[110][110];
int H,W;

void dfs(int x, int y, char mark){
    if( x < 0 || y >= H || x >= W || y < 0 ) return;
    if( grid[y][x] != mark || visited[y][x] ) return;
    visited[y][x] = true;
    dfs(x-1,y,mark); dfs(x+1,y,mark); dfs(x,y-1,mark); dfs(x,y+1,mark);
}

int main(){
    int i,j,k,res;

    while( cin >> H >> W, H|W ){
        memset(visited, false, sizeof(visited));
        res = 0;

        rep(i,H) cin >> grid[i];

        rep(i,H){
            rep(j,W){
                if( !visited[i][j] ){
                    res++;
                    dfs(j,i,grid[i][j]);
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 0
# include <bits/stdc++.h>
  using namespace std;
# define res(a,b,c) for (int64 a=b ; a<c ; a++)
# define ress(a,b)  for (auto a = b.begin() ; a!=b.end() ; a++) 
# define all(con) con.begin() , con.end()
# define INF (int)1e9  
# define MOD 1000000007
# define pb push_back   
# define mp make_pair
# define f first
# define s second   
# define MAX numeric_limits<int>::max() 
# define MIN numeric_limits<int64>::min()
# define mymin -1000000000000000001
# define mymax 1000000000000000001
# define watch(x) cout<<(#x)<<" is "<<(x)<<endl
# define in(x) cin>>(x)
# define inn(x,y) cin>>(x)>>(y)  
# define out(x) cout<<(x)<<"\n"  
# define outt(x,y) cout<<(x)<<" "<<(y)<<"\n"  
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64,int64> pi; 
bool doubleSame(double a, double b)
{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }

struct itemSet{
	int64 wt, val;
};

vector<vector<int64>> dp(101,vector<int64>(100001,-1));

int64 binaryKnap(int64 ind, vector<itemSet> &item, int64 n, int64 cap)
{
	if(ind>n) return 0;

	if(dp[ind][cap]!=-1) return dp[ind][cap];

	if(cap<item[ind].wt)
		return dp[ind][cap] = binaryKnap(ind+1, item, n, cap);

	int64 a1 = 0, a2 = 0;
	a1 = item[ind].val + binaryKnap(ind+1, item, n, cap-item[ind].wt);
	a2 = binaryKnap(ind+1, item, n, cap);
	return dp[ind][cap] = max(a1,a2);
}

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

	vector<itemSet> item(n+1);
	for(int64 i = 1 ; i<=n ; i++)
		cin>>item[i].wt>>item[i].val;

	cout<<binaryKnap(1,item,n,cap);
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int x[100005], y[100005], w[100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	map<pair<int, int>, int> mp;
	rep(i, 0, n) {
		read(x[i], y[i], w[i]);
		mp[{x[i], y[i]}] = w[i];
	}
	int ans = 0;
	rep(i, 0, n) {
		ll x = ::x[i], y = ::y[i];
		for (int dx : {-1, 1}) for (int dy : {-1, 1})
			chmax(ans, mp[{x, y}] + mp[{x + dx, y}] + mp[{x, y + dy}] + mp[{x + dx, y + dy}]);
	}
	write(ans, "/", 1);
}



Measured memory_bytes: 60552
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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


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

	string T[3] = { "KIH","B","R" };

	string ans = "NO";

	rep(j, 16) {
		string A;
		if ((j >> 3) % 2 == 1) { A = "A"; }
		
		rep(k, 3) {
			A += T[k];
			if ((j >> k) % 2 == 1) { A += "A"; }
		}

		if (S == A) { ans = "YES"; }
	}
	cout << ans << endl;
	
	system("PAUSE");
}


Measured memory_bytes: 504
from collections import Counter
mod = 10**9 + 7
n = int(input())
s = [i for i in input()]
cnt = Counter(s)
l = len(cnt)
val = list(cnt.values())
val = [i + 1 for i in val if i != 1]
ans = 2**(l-len(val)) % mod
for vi in val: ans *= vi % mod
print((ans - 1) % mod)

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

import sys
import os
from collections import deque


N = int(sys.stdin.readline())
q = deque()

for i in range(N):
    lst = sys.stdin.readline().split()
    command = lst[0]
    if command == 'insert':
        q.appendleft(lst[1])
    elif command == 'delete':
        try:
            q.remove(lst[1])
        except Exception:
            pass
    elif command == 'deleteFirst':
        q.popleft()
    elif command == 'deleteLast':
        q.pop()

print(*q)

Measured memory_bytes: 71952
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    string res = "yes";
    for(int i=1; i<s.size(); i++){
        if(s.at(i) == s.at(i-1)){
            res = "no";
            break;
        }
    }
    cout << res << endl;
}


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

int main(void)
{
    int n, d, ret;
    scanf("%d%d", &n, &d);
    if(n%(2*d+1)==0) ret=n/(2*d+1);
    else ret=n/(2*d+1)+1;

    printf("%d", ret);

    return 0;
}

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

int main(){
	int h,w,c=0;
	bool a=true;
	vector<int> ans;
	cin>>h>>w;
	int board[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>board[i][j];
		}
	}
	for(int i=0;i<h;i++){
		if(a){
			for(int j=0;j<w;j++){
				if(j==w-1 && i==h-1) break;
				if(j==w-1 && i!=h-1){
					if(board[i][j]%2==1){
						board[i][j]--;
						board[i+1][j]++;
						c++;
						ans.push_back(i+1);
						ans.push_back(j+1);
						ans.push_back(i+2);
						ans.push_back(j+1);
					}
				}else{
					if(board[i][j]%2==1){
						board[i][j]--;
						board[i][j+1]++;
						c++;
						ans.push_back(i+1);
						ans.push_back(j+1);
						ans.push_back(i+1);
						ans.push_back(j+2);
					}
				}
			}
			a=false;
		}else{
			for(int j=w-1;j>=0;j--){
				if(j==0 && i==h-1) break;
				if(j==0 && i!=h-1){
					if(board[i][j]%2==1){
						board[i][j]--;
						board[i+1][j]++;
						c++;
						ans.push_back(i+1);
						ans.push_back(j+1);
						ans.push_back(i+2);
						ans.push_back(j+1);
					}
				}else{
					if(board[i][j]%2==1){
						board[i][j]--;
						board[i][j-1]++;
						c++;
						ans.push_back(i+1);
						ans.push_back(j+1);
						ans.push_back(i+1);
						ans.push_back(j);
					}
				}
			}
			a=true;
		}
	}
	cout<<c<<endl;
	for(int i=0;i<ans.size();i++){
		cout<<ans[i];
		if(i%4==3) cout<<endl;
		else cout<<" ";
	}
	return 0;
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

int h,w;
char mp[100][100];
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};

void f(int y,int x){
  rep(i,4){
    int ny=y+dy[i];int nx=x+dx[i];
    if(0<=nx&&nx<w&&0<=ny&&ny<h&&mp[ny][nx]=='#'){
      mp[ny][nx]='.';
      f(ny,nx);
    }
  }
}

signed main(){
  cin>>h>>w;
  rep(i,h)rep(j,w)cin>>mp[i][j];

  rep(i,h){
    rep(j,w){
      if(mp[i][j]=='#'){
        int flag=false;
        rep(k,4){
          if(mp[i+dy[k]][j+dx[k]]=='#')flag=true;
        }
        if(flag)f(i,j);
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(mp[i][j]=='#'){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;

class A5{
  static int n;
  static string[] str;
  static int[] A;
  static int q;
  static string[] str2;
  static int[] M;

  public static void Main(){
    n = int.Parse(Console.ReadLine());
    str = Console.ReadLine().Split(' ');
    A = new int[n];
    q = int.Parse(Console.ReadLine());
    str2 = Console.ReadLine().Split(' ');
    M = new int[q];


    for(int i = 0;i < n;i++){
      A[i] = int.Parse(str[i]);
    }
    for(int i = 0;i < q;i++){
      M[i] = int.Parse(str2[i]);
    }

    for(int i = 0;i < q;i++){
      if(Solve(0,M[i]))
       Console.WriteLine("yes");
      else Console.WriteLine("no");
    }
}

  static bool Solve(int i,int m){
      if(m == 0) return true;
      if(i >= n) return false;
      bool res = Solve(i + 1,m)|| Solve(i + 1,m - A[i]);
      return res;
    }
}


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

int main(){
  int D;
  int G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  
  int max_count = 0;
  
  for(int i=0;i<D;i++){
    cin >> p.at(i) >> c.at(i);
    max_count += p.at(i);
  }
  
  int answer_count = max_count;
  
  for(int bit=0;bit<(1<<D);bit++){
    bitset<10> s(bit);
    int sum = 0;
    int count = 0;
    for(int i=D-1;i>=0;--i){
      if((bit>>i)&1){
        for(int j=0;j<p.at(i);++j){
          sum+=100*(i+1);
          count++;
          if(j+1==p.at(i)) sum += c.at(i);
          if((sum>=G)&&(count<=answer_count)){
              answer_count = count;
              break;
          }
        }    
      }
    }
  }
  
  cout << answer_count << endl;

  
}

Measured memory_bytes: 3640
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b) = (v[0], v[1]);
    if b % a == 0 {
        println!("{}", a + b);
    } else {
        println!("{}", b - a);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
int n,m,q;
vector<int> e[100005];
int v[100005],d[100005],c[100005];
int color[100005],dist[100005];
 
void dfs(int u,int d,int col)
{
    if(d<=dist[u]) return;
    dist[u]=d;
    if(color[u]==-1) color[u]=col;
    for(int i=0;i<e[u].size();i++)
        dfs(e[u][i],d-1,col);
}
 
int main()
{
 
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>v[i]>>d[i]>>c[i];
        v[i]--;
    }
    memset(dist,-1,sizeof(dist));
    memset(color,-1,sizeof(color));
    for(int i=q-1;i>=0;i--)
        dfs(v[i],d[i],c[i]);
    for(int i=0;i<n;i++)
        cout<<((color[i]==-1)?0:color[i])<<'\n';
 
    return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int A[333][333];
int cnt[333],pos[333];
bool u[333];
int main(){
    DRII(N,M);
    REP(i,N)REP(j,M)RI(A[i][j]);
    int an=300;
    REP(i,M){
        PII ma;
        MS0(cnt);
        REP(j,N)cnt[A[j][pos[j]]]++;
        REPP(j,1,M+1){
            ma=max(ma,MP(cnt[j],j));
        }
        an=min(an,ma.F);
        u[ma.S]=1;
        if(i==M-1)break;
        REP(j,N){
            while(u[A[j][pos[j]]])pos[j]++;
        }
    }
    printf("%d\n",an);
    return 0;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using ld = long double;
constexpr ll INF = 1ll << 60;

// tgt以下の組み合わせはいくつあるか
ll judge(const vector<ll>& A, ll tgt) {
    const ll N = A.size();
    ll cnt = 0;
    rep(i, N) {
        if (A[i] == 0) {
            if (tgt >= 0)cnt += (N - 1) - i;
        }
        else if (A[i] > 0) {
            if (tgt <= 0)continue;
            ll ntgt = tgt / A[i];
            auto itr = upper_bound(A.begin() + i + 1, A.end(), ntgt);
            ll size = itr - (A.begin() + i);
            size--;
            cnt += size;
        }
        else { // A[i]<0
            ll ntgt = (tgt >= 0 ? tgt / A[i] : ceill((ld)tgt / A[i]));
            ll size = A.end() - lower_bound(A.begin() + i + 1, A.end(), ntgt);
            cnt += size;
        }
    }
    return cnt;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];
    sort(A.begin(), A.end());

    ll l = -INF, r = INF;
    while (abs(r - l) > 1) { // O(logA)
        ll mid = (r + l) / 2;
        ll cnt = judge(A, mid);
        (cnt < K ? l : r) = mid; // 怪しい所
    }
    cout << r << endl;
    return 0;
}


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

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) { li res = 1; while (b) { if (b % 2) res = (res * a) % mod;
a = (a * a) % mod; b /= 2; } return res; }

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) { li cnt = 0; while (n) { n &= (n - 1); cnt++; } return cnt; }

void solve() {
	vector<int> v;
	for (int i = 0; i < 3; i++) {
		int x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < 2; i++) {
		ans += v[i + 1] - v[i];
	}
	cout << ans;
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int n;

int main(int argc, char** argv) {
	//freopen("i.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	sort(a,a+n);
	int cnt = 0;
	int l = 0, r = 0;
	
	for(int i=n-1;i>=1;i--) {
		if(a[i] == a[i-1]) {
			if(cnt == 0)l = a[i];
			else r = a[i];
			cnt ++;
			i --;
		}
		if(cnt == 2)break;
	}
	cout<<(long long)l * r<<endl;
	return 0;
}

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

int main(){
  int  N, number = 0;
  cin >> N;
  for(int  i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    number += r - l + 1;
  }
  cout << number << endl;
}

Measured memory_bytes: 3528
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

int main() {
    int n, m, a[300][300], r = 300;
    cin >> n >> m;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
    set<int> c;
    for (int i = 1; i <= m; i++) c.insert(i);
    int b[301];
    while (!c.empty()) {
        for (int i = 1; i <= m; i++) b[i] = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (c.find(a[i][j]) != c.end()) {
                    b[a[i][j]]++;
                    break;
                }
        int w = 1;
        for (int i = 1; i <= m; i++) w = max(w, b[i]);
        for (int i = 1; i <= m; i++) if (b[i] == w)c.erase(i);
        r = min(r, w);
    }
    cout << r << endl;
}

Measured memory_bytes: 640
import numpy as np
  
input()
S = np.asarray(list(str(input())))

rw = S[S=="."].size
rb = S[S=="#"].size
lw = 0
lb = 0
res = lb + rw
for s in S:
 if s == "#":
  rb -= 1
  lb += 1
 else:
  rw -= 1
  lw += 1
 res = min(res,lb+rw)
print(res)


Measured memory_bytes: 23800
def dfs(fld, check, n, m, depth)
  ok = true
  n.times do |y|
    m.times do |x|
      if check[y][x] == depth && fld[y][x] == '*'
        l = r = x
        loop do
          check[y][r] = depth + 1
          break if fld[y][r + 1] != '*'
          r += 1
        end
        ml = mr = -2
        (l-1..r+1).each do |i|
          ml = i - l if fld[y + 1][i] == '*' && ml == -2
          mr = i - r if fld[y + 1][i] == '*' && ml != -2
        end
        yy = y + 1; xl = l + ml; xr = r + mr
        loop do
          check[yy][xl] = check[yy][xr] = depth + 1
          (xl+1...xr).each{ |k| check[yy][k] = depth + 2 }
          if fld[yy + 1][xl + ml] != '*'
            (xl+1...xr).each{ |k| check[yy][k] = depth + 1 }
            break
          end
          yy += 1; xl += ml; xr += mr
        end
        s = ((r - l + 1) + (xr - xl + 1)) * (yy - y + 1) / 2
        $ret[s] ||= 0
        $ret[s] += 1
        ok = false
      end
    end
  end
  return true if ok
  return true if dfs(fld, check, n, m, depth + 2)
end

l = false
while n = gets.to_i
  break if n == 0
  if l
    10.times{ print '-' }
    puts
  end
  l = true
  fld = n.times.map{ gets.chomp.split('').unshift(' ').push(' ') }
  m = fld.map{ |f| f.size }.max
  fld.each{ |f| (m - f.size).times{ f.push(' ') } }
  fld = [ [' '] * m, *fld, [' '] * m ]
  $ret = {}
  check = (n+2).times.map{ [0] * m }
  dfs(fld, check, n+2, m, 0)
  $ret.sort.each{ |k, v| puts "#{k} #{v}" }
end

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)

int dx[4]={1, -1, 0, 0};
int dy[4]={0, 0, 1, -1};

int main(void) {
    int a,b,h;
    cin >>a >>b >>h;
    cout << (a+b)*h/2 << endl;
    return 0;
}


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

int main(){
    int N, ai, i, alice=0, bob=0;
    vector<int> va;

    cin >> N;
    for (i=0; i<N; i++) {
        cin >> ai;
        va.push_back(ai);
    }
    sort(va.begin(), va.end(), greater<int>());

    for (i=0; i<N; i+=2) alice += va[i];
    for (i=1; i<N; i+=2) bob += va[i];

    cout << alice - bob << endl;

    return 0;

}


Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

access = []
for i in 1..N do
  access[i-1] = []
end
for i in 1..M do
  from = lines[i][0]
  to = lines[i][1]
  access[to-1].push(from)
  access[from-1].push(to)
end

visited = []
for i in 1..N do
  visited[i-1] = false
end

num_group = 0
for i in 1..N do
  if visited[i-1] == false then
    num_group += 1
    targets = [i]
    while targets != [] do
      j = targets.pop
      visited[j-1] = true
      access[j-1].each do |k|
        if visited[k-1] == false then
          targets.push(k)
          visited[k-1] = true
        end
      end
    end
  end
end
    
puts num_group - 1

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

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

    int N; cin >> N;
    if(N == 1) {
        cout << "Yes" << endl;
        cout << 2 << endl;
        rep(i,2) cout << "1 1" << endl;
        return 0;
    }

    int num = 0, res;
    rep(i,100000) {
        num += i;
        if(N == num) {res = i; break;}
        if(N < num) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    cout << res+1 << endl;

    cout << res;
    int tmp = 0;
    REP(i,1,res+1) {
        tmp += i;
        cout << " " << tmp;
    } cout << endl;

    cout << res;
    tmp = 1;
    rep(i,res) {
        tmp += i;
        cout << " " << tmp;
    } cout << endl;

    tmp = 1;
    REP(i,1,res) {
        tmp += i;
        int ttmp = tmp;

        cout << res;
        rep(j,i+1) {
            cout << " " << ttmp;
            ttmp += 1;
        }
        ttmp -= 1;

        int cnt = i + 1;
        REP(j,i,res-1) {
            ttmp += cnt;
            cnt++;
            cout << " " << ttmp;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>

using namespace std;
using P = pair <int, int>;

const int INF = 1000000000;

int main() {
    int N;
    int answer = INF;

    cin >> N;
    vector<int> X(N);

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

    sort(X.begin(), X.end());

    for (int p = X[0]; p <= X[X.size() - 1]; p++) {
        int res = 0;
        for (int i = 0; i < X.size(); i++) {
            res += (X[i] - p) * (X[i] - p);
        }
        answer = min(res, answer);
    }

    cout << answer << endl;

    return 0; 
}

Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (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;
}

const ll INF = 1LL << 60;
ll h[110000];
ll dp[110000];

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

    int N, K;
    cin >> N >> K;
    rep(i, N) cin >> h[i];

    rep(i, 110000) dp[i] = INF;

    dp[0] = 0;

    rep(i, N) {
        for(int j = 1; j <= K; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    COUT(dp[N - 1]);
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 998244353
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    vl a(n);
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    sort(all(a));
    if(sum % 10 != 0) cout << sum << endl;
    else{
        rep(i,n){
            if(a[i] % 10 != 0){
                cout << sum-a[i] << endl;
                return 0;
            }
        }
        puts("0");
    }
}


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

using namespace std;


int main(){
int k;
cin>>k;
				
 int arr[33]={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};
				
cout<<arr[k-1]<<endl;
}

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

int cnt=0;
const int MAX=500000;
int L[MAX/2+2], R[MAX/2+2];

inline void merge(int A[], int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i=0; i<n1; i++){
		L[i] = A[left+i]; 
	}
	for(int i=0; i<n2; i++){
		R[i] = A[mid+i];
	}
	L[n1] = 2000000000;
	R[n2] = 2000000000;
	
	int i=0, j=0;
	for(int k=left; k<right; k++){
		cnt++;
		if(L[i] <= R[j]){
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
		}
	}
}

inline void merge_sort(int A[], int left, int right){
	if (left+1 < right){
		int mid = (left+right)/2;
		merge_sort(A, left, mid);
		merge_sort(A, mid, right);
		merge(A, left, mid, right);
	}
}




int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int A[n];
	for(int i=0; i<n; i++){
		cin >> A[i];
	}
	
	merge_sort(A, 0, n);
	for(int i=0; i<n; i++){
		if(i==0) cout << A[i];
		else cout << " " << A[i];
	}
	cout << "\n" << cnt << "\n";

	return 0;
}

Measured memory_bytes: 7044
import java.util.*;


public class Main {
	
	void AOJ0009(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int count=0;
			boolean[] prime = new boolean[n+1];
			Arrays.fill(prime, true);
			for(int i=2; i<=n; i++){
				if(prime[i]){
					count++;
					for(int j=i+i; j<=n; j+=i)	prime[j]=false;
				}
			}
			System.out.println(count);
		}
	}
	
	ArrayList<Integer> Sieve(int n){
	     ArrayList<Integer> prime = new ArrayList<Integer>();
	     if(n<2)	return prime;
	     boolean[] list = new boolean[n];
	     Arrays.fill(list, true);
	     list[1]=false;
	     for (int i=2; i<n; i++) {
	          if (list[i]) {
	               prime.add(i);
	               for (int j=i+i; j<n; j+=i)	list[j] = false;
	          }
	     }
	     return prime;
	}

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

}

Measured memory_bytes: 16000
// Oh boi here we go again
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

ll a[N], b[N];
int n, m;

main(){
    cin >> n >> m;
    ll lcm = 1;
    for (int i = 1; i <= n; i++){
        scanf("%lld", &a[i]);
        b[i] = a[i] / 2;
        lcm = lcm * b[i] / __gcd(lcm, b[i]);
        if (lcm > m){
            puts("0");
            return 0;
        }
    }
    bool good = true;
    for (int i = 1; i <= n; i++)
        if ((lcm / b[i]) % 2 == 0)
            good = false;
    if (!good)
        puts("0");
    else {
        cout << (m / lcm + 1) / 2;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()
int n;
ll a,b,v[N],bst=oo;
bool can(int md){
	ll lf=md;
	ll c=a-b;
	for(int i=0; i<n && lf>=0; ++i){
		ll cur=max(0ll, v[i]-md*b);
		lf-=(cur+c-1)/c;
	}
	if(lf>=0)
		bst=min(bst,1ll*md);
	return lf>=0;
}
int main(){
	cin>>n>>a>>b;
	for(int i=0; i<n; ++i)
		scanf("%lld",&v[i]);
	int lo=1, hi=oo, md;
	while(lo<=hi){
		md=(lo+hi)/2;
		if(can(md))
			hi=md-1;
		else
			lo=md+1;
	}
	cout<<bst<<endl;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

constexpr int ORD(int n){
  int res = 1;
  for(int i=0; i < n; i++){
    res *= 10;
  }
  res++;
  return res;
}

using namespace std;

char s[101];

int main(){
  unsigned long long k = 0;
  scanf("%s\n", s);
  scanf("%lld", &k);
  k--;
  int first_non_one = 0;
  int n = strlen(s);
  for(int i=0; i < n; i++){
    if(s[i] != '1'){
      first_non_one = i;
      break;
    }
  }
  
  if(k <= first_non_one && k < n){
    printf("%c\n", s[k]);
  }else{
    printf("%c\n", s[first_non_one]);
  }
  return 0;
}


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

int main() {
  long long  a, b, c, d, n;
  cin >> a >> b >> c >> d >> n;

  c = min({c, 4 * a, 2 * b});

  d = min(2 * c, d);

  cout << n / 2 * d + (n & 1 ? c : 0) << endl;
}


Measured memory_bytes: 256
import numpy as np
N,K = map(int,input().split())
numberList = np.array(range(1,N+1)).tolist()
for d in range(1,K+1):
    num = input()
    array = list(map(int, input().strip().split()))
    for i in array:
        if i in numberList:
            numberList.remove(i)
print(len(numberList))

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  set<char> st;
  rep(i, n) {
    char s;
    cin >> s;
    st.insert(s);
  }
  cout << (st.size() == 3 ? "Three" : "Four") << endl;

  return 0;
}


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

int main()
{
  int n;

  long long money = 1000;

  cin >> n;

  vector<int> a(n);

  rep(i, n)
  {
    cin >> a.at(i);
  }

  rep(i, n - 1)
  {

    if (a.at(i) < a.at(i + 1))
    {
      long long x = money / a.at(i);
      money -= (x * a.at(i));
      money += (x * a.at(i + 1));
    }
  }

  cout << money;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
int main(){
	string str;
	while(cin>>str){
		for(int i=0;i<str.length();i++){
			if(str[i]!='@') cout<<str[i];
			else if(str[i]=='@'){
				int a=str[i+1]-48;
				for(int j=0;j<a;j++) cout<<str[i+2];
				i+=2;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <stdio.h>

using namespace std;

void trace(int A[], int N) {
	for (int i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]); 	
	}
	printf("\n");
}

int bubbleSort(int A[], int N) {
	int flag = 1;
	int count = 0;

	while (flag) {
		flag = 0;

		for (int i = N - 1; i > 0; i--) {
			if (A[i] < A[i - 1]) {
				int tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				
				flag = 1;
				count++;
			}
		}

	}
	
	trace(A, N);

	return count;
}

int main() {
	int N;
	int A[100];
	int count;
	
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	
	count = bubbleSort(A, N);			

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define LL long long
using namespace std;

LL n, mod = 1000000007;
LL dp[21][(1<<21)], a[22][22];

LL solve(int pos, int bit) {
	if(pos == n) return 1;
	LL &ret = dp[pos][bit];
	if(ret != -1) return ret;
	ret = 0;
	for(int i = 0; i < n; i++) {
		if(a[pos][i] && !(bit&(1<<i))) {
			ret = (ret + solve(pos+1, bit|(1<<i))) % mod;
		}
	}
	return ret;
}

int main() {
	cin>>n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin>>a[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(0, 0)<<endl;
	return 0;
}


Measured memory_bytes: 344448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N =2e5+5;
ll t[2*N],h[N],b[N],n,ans=0;
pair<ll,ll> a[N];

ll query(ll l, ll r)
{
	ll ret=0;
	for(l+=n,r+=n;l<r;l>>=1,r>>=1)
	{
		if(l&1)ret=max(ret,t[l++]);
		if(r&1)ret=max(ret,t[--r]);
	}
	return ret;
}

ll update( ll x, ll v)
{
	x+=n;
	while(x>=1)
	{
		t[x]=max(t[x],v);
		x>>=1;
	}
}


int main()
{
    ios_base::sync_with_stdio(false);

    clr(t);
	cin>>n;forn(i,n){cin>>h[i];a[i].F=h[i];a[i].S=i;}forn(i,n)cin>>b[i];
	sort(a,a+n);
	forn(i,n)
	{
		//cout<<a[i].F<<" "<<a[i].S<<" ";
		ll x=a[i].S;
		ll k=query(0,x);//cout<<k<<" ";
		ll v=k+b[x];
		ans=max(ans,v);
		update(x,v);//cout<<query(x,x+1)<<endl;
		//cout<<x<<" "<<v<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n,y;
  cin>>n>>y;
  for(Int i=0;i<=n;i++){
    for(Int j=0;i+j<=n;j++){
      Int k=n-(i+j);
      if(i*10000+j*5000+k*1000==y){
	cout<<i<<" "<<j<<" "<<k<<endl;
	return 0;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

ll com(int n,int r){
  if(r == 0) return 1;
  else return (n-r+1)*com(n,r-1)/r;
}


int main(){
  int N, M;
  cin >> N >> M;
  cout << com(N,2) + com(M,2) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>


using namespace std;
int a[100][100];
int main() {
	memset(a, 0 ,sizeof(a));
	a[0][0] = 2;
	a[1][0] = 1;
	int i, j;
	for (i = 2; i < 100; i++) {
		for (j = 0; j < 100; j++) {
			a[i][j] = a[i-1][j] + a[i-2][j] + a[i][j];
			if (a[i][j] > 9) {
				a[i][j+1] = a[i][j] / 10 + a[i][j+1];
				a[i][j] = a[i][j] % 10;
			}
		}
	}
	int n;
	while (scanf("%d", &n) == 1) {
		for (i = 99; i >= 0; i--) {
			if (a[n][i] != 0) break;
		}
		for (j = i; j >= 0; j--) {
			printf("%d", a[n][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
a, b, c, x = map(int, [input() for i in range(4)])

count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                count = count + 1
print(count)

Measured memory_bytes: 9176
#include<stdio.h>
int main(void)
{
	int s,a,b,c,d,z,w,y;
	scanf("%d",&s);
	a=s/1000;
	b=s%1000;
	c=b/100;
	d=b%100;
	z=d/10;
	w=d%10;
	if(a==c ||c==z ||z==w){
		printf("Bad\n");
	}
	else{
		printf("Good\n");
	}
	return 0;
}

Measured memory_bytes: 128
def check(x, y, count):
	array[x][y] = "$"
	count += 1
	if array[x + 1][y] == "." : count = check(x + 1, y, count)
	if array[x - 1][y] == "." : count = check(x - 1, y, count)
	if array[x][y + 1] == "." : count = check(x, y + 1, count)
	if array[x][y - 1] == "." : count = check(x, y - 1, count)
	return count

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (h + 2)))
	for i in range(0, w) : array.append(list("$" + raw_input() + "$"))
	array.append(list("$" * (h + 2)))
	
	x = 1
	y = 1
	for i in range(1, w + 1):
		if "@" in array[i]:
			x = i
			y = array[i].index("@")
	
	print check(x, y, 0)

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

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXSIZE 3005

LL tab[MAXSIZE];
LL dp[MAXSIZE][MAXSIZE];

int n;

int main(){	//wniosek: rozkminiaj wiecej dp[l][r];
	
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin>>n;
	FOR(i,1,n)
		cin>>tab[i];
	
	FOR(dl,1,n){		
		FOR(l,1,n){
			int r=dl+l-1;
			if(r>n)
				break;
		
			if(n%2==dl%2)	//hey Taro!
				dp[l][r]=max(dp[l][r-1]+tab[r],dp[l+1][r]+tab[l]);
			else
				dp[l][r]=min(dp[l][r-1]-tab[r],dp[l+1][r]-tab[l]);
			//cout<<l<<" "<<r<<"\n";
		}
	}
	
	cout<<dp[1][n];
	return 0;
}


Measured memory_bytes: 70016
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d))
// priority_queue<int,vector<int>,greater<int>>
ll ans[10000000];
int solve(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n){
    ll le = i;
    while(i + 1 < n && s[i] == s[i + 1])i++;
    ll len = i - le + 1;
    if(s[i] == 'L'){
      ans[le] += (len + 1) / 2;
      ans[le - 1] += len / 2;
    }
    else{
      ans[i] += (len + 1) / 2;
      ans[i + 1] += len / 2;
    }
  }
  rep(i,n){
    if(i > 0)cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll hs(n);
  rep(i, n) cin >> hs[i];

  ll l = 0, ysf = 0;
  while (l < n) {
    if (hs[l] == 0) {
      l++;
      continue;
    }
    ll r = l;
    while (r < n && hs[r] > 0) {
      r++;
    }
    for (ll i = l; i < r; i++) {
      hs[i]--;
    }
    ysf++;
  }

  cout << ysf << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
using namespace std;
int main () {
	int a, arr[25], arr2[25],jum, hsl=0;
	scanf("%d", &a);
	for (int i=0; i<a; i++){
		scanf("%d", &arr[i]);
	}
	for (int i=0; i<a; i++){
		scanf("%d", &arr2[i]);
	}
	for (int i=0; i<a; i++){
		jum=arr[i]-arr2[i];
		if(jum>0){
			hsl=hsl+jum;
		}
	}
	printf("%d\n", hsl);
}

Measured memory_bytes: 128