akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Node implements Comparable<Node> {
  int i, j, step;
  Node(int i, int j, int step) {
    this.i = i;
    this.j = j;
    this.step = step;
  }

  public int compareTo(Node node) {
    return this.step - node.step;
  }
}

public class Main {
  private static int[] DI = new int[]{1, 0, -1, 0};
  private static int[] DJ = new int[]{0, 1, 0, -1};

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int h = in.nextInt();
    int w = in.nextInt();

    boolean[][] m = new boolean[h+2][w+2];
    int numWhite = 0;
    for (int i = 1; i <= h; i++) {
      String line = in.next();
      for (int j = 1; j <= w; j++) {
        m[i][j] = line.charAt(j - 1) == '.';
        if (m[i][j]) {
          numWhite++;
        }
      }
    }

    PriorityQueue<Node> q = new PriorityQueue<Node>();
    q.add(new Node(1, 1, 1));
    boolean[][] visited = new boolean[h+2][w+2];
    while (!q.isEmpty()) {
      Node node = q.poll();
      if (visited[node.i][node.j]) {
        continue;
      }
      if (node.i == h && node.j == w) {
        System.out.println(numWhite - node.step);
        return;
      }
      visited[node.i][node.j] = true;
      for (int k = 0; k < 4; k++) {
        int nextI = node.i + DI[k];
        int nextJ = node.j + DJ[k];
        if (!m[nextI][nextJ] || visited[nextI][nextJ]) {
          continue;
        }
        q.add(new Node(nextI, nextJ, node.step + 1));
      }
    }
    System.out.println(-1);
  }
}


Measured memory_bytes: 22100
X, K, D = map(int, input().split())

X = abs(X)

a = X // D

X -= min(a, K) * D
K -= min(a, K)

if K > 0 and abs(X) > abs(X - D):
    X -= D
    K -= 1

K %= 2

if K == 1:
    if abs(X + D) < abs(X - D):
        X += D
    else:
        X -= D

result = abs(X)

print(result)


Measured memory_bytes: 9192
from collections import deque
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
tree = [[] for i in range(n)]
counter = [0] * n
visited = [False] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    # tree[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x
queue = deque([0])
visited[0] = True
while queue:
    now = queue.pop()
    for j in tree[now]:
        if visited[j]:
            continue
        counter[j] += counter[now]
        visited[j] = True
        queue.append(j)
print(*counter)

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

int main(){
    vector<int> p(100001, 1);
    p[0] = 0;
    p[1] = 0;
    for(int i = 2; i <= 100000; i++){
        if(p[i]){
            int j = 2*i;
            while(j <= 100000){
                p[j] = 0;
                j += i;
            }
        }
    }

    vector<int> sum(100001);
    for(int i = 1; i <= 100000; i++){
        if(p[i] == 1 && p[(i+1)/2] == 1 && i % 2 == 1) sum[i] += sum[i-1] + 1;
        else sum[i] = sum[i-1];
    }

    /*for(int i = 0; i < 10; i++){
        if(p[i]) cout << i << ' ';
    }
    cout << endl;*/

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l-1] << endl;
    }
}

Measured memory_bytes: 3840
import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  implicit val box = readLine.trim.split(' ').map(it ⇒ new Box(it.toInt))
  println(
    readOrder(readLine.trim.toInt)
  )
  class Box(val capacity: Int, var using: Int = 0) {
    def restSpace: Int = capacity - using
  }
  @tailrec def readOrder(orderLimit: Int)(implicit box: Array[Box]): Int = {
    if (orderLimit == 0) 0
    else {
      val Array(t, x, d) = readLine.trim.split(' ').map(_.toInt)
      t match{
        case 1 if box(x - 1).restSpace >= d ⇒ {
          box(x - 1).using += d
          readOrder(orderLimit - 1)
        }
        case 2 if box(x - 1).using >= d ⇒ {
          box(x - 1).using -= d
          readOrder(orderLimit - 1)
        }
        case _ ⇒ x
      }
    }
  }
}


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

using namespace std;

typedef vector< vector<int> > Mat;

typedef long long ll;

int N;
Mat operator *(const Mat& A, const Mat& B) {
	Mat res(N, vector<int>(N, 0));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				res[i][j] += A[i][k] * B[k][j];
			}
			res[i][j] = res[i][j] ? 1 : 0;
		}
	}
	return res;
}

Mat pow(Mat A, ll n) {
	Mat res = A;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			res[i][j] = i == j ? 1 : 0;
		}
	}

	for (ll i = 1; i <= n; i <<= 1) {
		if (n & i) {
			res = res * A;
		}
		A = A * A;
	}
	return res;
}

struct Compress {
	map<int, int> m;
	int msz;

	Compress() : msz(0) {}

	int get(int id) {
		return m.find(id) != m.end() ? m[id] : -1;
	}
	void add(int id) {
		m[id] = msz++;
	}
};

typedef pair<int, int> P;
int main() {
	int M, Z;
	while ( cin >> N >> M >> Z, N || M || Z ) {
		Compress c;

		int n = N;

		vector<P> v;
		for (int i = 0; i < M; ++i) {
			int s, d; cin >> s >> d; --s, --d;
			v.push_back( P(s, d) );
		}

		c.add(0);
		for (int i = 0; i < M; ++i) {
			int s = v[i].first, d = v[i].second;
			c.add(n*s+d);
			c.add(n*d+s);
		}

		N = c.msz;
		vector< vector<int> > m(N, vector<int>(N, 0));
		for (int i = 0; i < M; ++i) {
			int s = v[i].first, d = v[i].second;
			int sid = c.get(n*s+d), did = c.get(n*d+s);
			for (int j = 0; j < n; ++j) {
				if (j != d) {
					int id = c.get(n*s+j);
					if (id > -1) m[id][did] = 1;
				}
				if (j != s) {
					int id = c.get(n*d+j);
					if (id > -1) m[id][sid] = 1;
				}
			}
		}

		m = pow(m, Z);
/*
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cout << m[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;
*/
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			int id = c.get(n*(n-1)+i);
			if (id > -1 && m[0][id]) ans = 1;
		}
		if (ans) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(int argc, char** argv) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

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

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

    ll rez  = a[n-1]-a[0];
    int x = a[0];
    int y = a[n-1];
    int i=1, j=n-2;
    vector<pii> Q(4);
    for(int k=2; k<n; k++){
        Q[0] = make_pair(abs(x-a[i]), 0);
        Q[1] = make_pair(abs(y-a[i]), 1);
        Q[2] = make_pair(abs(x-a[j]), 2);
        Q[3] = make_pair(abs(y-a[j]), 3);
        sort(Q.begin(), Q.end());
        rez += Q[3].first;
        int next;
        if (Q[3].second / 2) {
            next = a[j];
            j--;
        }
        else {
            next = a[i];
            i++;
        }
        if (Q[3].second%2)
            y = next;
        else
            x = next;

    }
    cout << rez;
    return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<ll, ll> P;

const ll N = 1000000;
string s = "0";
ll n,n1,n2,n3,n4,n5,n0;
ll a[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  ll g = n % 100;
  for(int i= 5; i > 0; i--) {
    a[i] = g/i;
    g -= a[i] * i;
    n1 += a[i];
  }
  n2 = (n - g) - n1 * 100;
  if(0 <= n2 && n2 <= N*100) s = "1";
  cout << s << endl;
}


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

int main() {
	string N;
  	cin >> N;
  	
  	int ans = N.size();
  	
  	for(int i = 0; i < 2; i++){
      int cnt = 0;
      for(int j = 0; j < N.size(); j++){
        if( (j % 2 == 0) ^ (N.at(j) == (char)(i+'0'))) cnt++;
      }
      ans = min(ans, cnt);
    }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
int main(void){
    string s;cin>>s;
    string S;S="";
    rep(i,s.size()){
        if(i<s.size()-1&&s[i]=='B'&&s[i+1]=='C'){S+='x';i++;}
        else if(s[i]=='A')S+='a';
        else S+='z';
    }
    reverse(all(S));
    ll ans=0;ll count=0;
    rep(i,S.size()){
        if(S[i]=='x')count++;
        if(S[i]=='z')count=0;
        if(S[i]=='a')ans+=count;
    }
    cout<<ans;
}

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

int main() {
  
  int N; cin >> N;
  
  vector<int64_t> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i];
  
  if (N == 1) { cout << vec[0] << endl; return 0; }
  
  int64_t tmp = vec[0] / __gcd(vec[0], vec[1]) * vec[1];
  
  for (int i = 2; i < N; i++) tmp = tmp / __gcd(tmp, vec[i]) * vec[i];
  
  cout << tmp << endl;
  
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

    int n;
    cin>>n;
    int ans=1000-(n%1000);
    if(ans==1000) ans=0;
    cout<<ans<<endl;

}

Measured memory_bytes: 3620
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))
s = input()
dfs(0, s[0], int(s[0]))

Measured memory_bytes: 9200
a = input().split()

S = a[0]
T = a[1]

b = list(map(int, input().split()))
A = b[0]
B = b[1]

c = input()

for i in range(2):
    if(c == a[i]):
        b[i] -= 1

print("%d %d" % (b[0], b[1]))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1000000007;
ll dp[110][32000], dp2[110][32000];

int main() {
    ll n, k;
    cin >> n >> k;
    ll m = 0;
    while ((m + 1) * (m + 1) <= n) m++;

    VL b(m + 1), cnt(m + 1);
    FOR(x,1,m){
        b[x] = n / x;
    }
    FOR(x,1,m){
        dp[0][x] = 1;
        if (x < m) cnt[x] = b[x] - b[x + 1];
        else cnt[x] = b[x] - m;
        if (x < m) dp2[0][x] = b[x] - b[x + 1];
        else dp2[0][x] = b[x] - m;
    }

    REP(i,k-1){
        ll s = 0, s2 = 0;
        FOR(x,1,m){
            s = (s + dp[i][x]) % mod;
            dp2[i + 1][x] = (dp2[i + 1][x] + cnt[x] * s) % mod;
        }
        FORR(x,m,1){
            s2 = (s2 + dp2[i][x]) % mod;
            dp[i + 1][x] = (dp[i + 1][x] + s2) % mod;
        }
        FOR(x,1,m){
            dp[i + 1][x] = (dp[i + 1][x] + s) % mod;
        }
    }

    // REP(i,k){
    //     FOR(x,1,m) cout << dp[i][x] << " ";
    //     cout << endl;
    //     FOR(x,1,m) cout << dp2[i][x] << " ";
    //     cout << endl;
    // }

    ll ans = 0;
    FOR(x,1,m){
        ans = (ans + dp[k - 1][x] + dp2[k - 1][x]) % mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 54016
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
	if (b == 0){
		return a;
	}
	return gcd(b, a % b);
}

int main(){
ll N;
cin >> N;
vector<ll> A(N);
for(ll i = 0; i < N; i++){
	cin >> A[i];
}
ll allgcd = A[0];
for(ll j = 1; j < N; j++){
	allgcd = gcd(A[j], allgcd);
}
ll ans = 0;
for(;;){
	if(allgcd % 2 == 0){
		ans++;
		allgcd = allgcd/2;
	} else {
		break;
	}
}
cout << ans << endl;

}

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

A.sort()
A.reverse()
ans = 0
if N%2 == 0 :
  ans += A[0]
  for i in range(int(N/2) - 1) :
    ans += A[i+1] * 2
if N%2 == 1 :
  ans += A[0]
  ans += A[int(N/2)]
  for i in range(int(N/2) - 1) :
    ans += A[i+1] * 2
    
print(ans)

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a[10000],b[10000],sum;

signed main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) {
        if (a[i] < b[i]) sum += (b[i]-a[i])/2;
        else sum -= (a[i]-b[i]);
    }
    if (sum < 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 384
def main():
    N = [str(_) for _ in input().split()]
    A = int(N[0])
    B = N[1]

    BB = B.split('.')
    result = A * int(BB[0])
    s = (A * int(BB[1][0]) * 10) + (A * int(BB[1][1]))
    
    result = result * 100 + s
    r = str(result)
    if len(r) <= 2:
        print(0)
    else:
        print(r[0:len(r)-2])

if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
a, b = map(int, raw_input().split())
s = raw_input().split('-')
print 'Yes' if len(s[0]) == a and not [_ for _ in s[0] if _ not in '0123456789'] and \
               len(s[1]) == b and not [_ for _ in s[1] if _ not in '1234567890'] else 'No'


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

int main() {
  int n, m;

  cin >> n;
  vector<int> t(n);

  for (int i = 0; i < n; i++) cin >> t[i];

  cin >> m;

  for (int i = 0; i < m; i++) {
    int p, x, ans = 0;
    cin >> p >> x;
    for (int i = 0; i < n; i++) {
      if (i == p - 1)
        ans += x;
      else
        ans += t[i];
    }
    cout << ans << endl;
  }

  return 0;
}

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b; cin >> a >> b;
    if(a >= 10 || b >= 10) cout << "-1\n";
    else cout << a*b << "\n";


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
struct edge{ll to,cost;};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}

Measured memory_bytes: 3648
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    int ar[3001][3001],n,m;
    ll dp[3001][3001][4];
    int func(int i,int j,int k)
    {
        if(i==0 || j==0)
        {
            cout<<"ERROR"<<endl;
            return 0;
        }
        if(dp[i][j][k]!=-1)
            return dp[i][j][k];
        if(k==0)
            return dp[i][j][k]=0;
        if(i==1 && j==1)
        {
            return dp[i][j][k]=ar[i][j];
        }
        if(j-1>0)
        {
            dp[i][j][k]=max(dp[i][j][k],max(func(i,j-1,k),ar[i][j]+func(i,j-1,k-1)));
        }
        if(i-1>0)
        {
            dp[i][j][k]=max(dp[i][j][k],ar[i][j]+func(i-1,j,3));
        }
        // cout<<i<<" "<<j<<" "<<k<<"..."<<dp[i][j][k]<<endl;
        return dp[i][j][k];
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,m,i,j,a,b,k,c;
            cin>>n>>m;
            for(i=1;i<=n;++i)
            {
                for(j=1;j<=m;++j)
                {
                    for(k=0;k<=3;++k)
                        dp[i][j][k]=-1;
                }
            }
            cin>>k;
            for(i=1;i<=k;++i)
            {
                cin>>a>>b>>c;
                ar[a][b]=c;
            }
            ll ans=0;
            for(i=0;i<=3;++i)
                ans=max(ans,func(n,m,i));
            cout<<ans<<endl;
        }
        return 0;
    }


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

int main() {
	int N , A;
  	cin >> N;
    int MAX = 31;
	for(int i = 0; i < N ; i++){
		int wattakaisu = 0;
        cin >> A;
        while(A % 2 == 0){
          wattakaisu++;
          A /= 2;
        }
        if(MAX > wattakaisu){
        	MAX = wattakaisu;
        }
    }
    cout << MAX << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int cnt = 0;
    cin >> N;
    int a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    int flag = 1;
    int i = 0;
    while(flag){
        flag = 0;
        for(int j = N-1; j > i; j--){
            if(a[j] < a[j-1]) {
                swap(a[j], a[j-1]);
                cnt++;
            }
            flag = 1;
        }
        i++;
    }
    for(int i=0; i<N; i++){
        if(i-N+1) cout << a[i] << " ";
        else cout <<a[i] << endl;
    }
    cout << cnt  << endl;
    return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        
        printlnArray(a);
        for (int i = 1; i < n; i++) {
            int temp = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > temp) {
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = temp;
            printlnArray(a);
        }
    }

    private static void printlnArray(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);
    }
}


Measured memory_bytes: 29988
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        String a = sc.next();
        String b = sc.next();

        if (a.equals("H")) {
            _out.println(b);
        } else {
            if (b.equals("H")) {
                _out.println("D");
            } else {
                _out.println("H");
            }
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <cstdio>
 
#define gc getchar_unlocked
#define N 309

using namespace std;
 
int a[N][N];

int main(){	
	int i,j,t1,t2,t3,t4,n,k,flag;
	long long int ans;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				if(a[i][k]+a[k][j]<a[i][j]){
					printf("-1\n");
					return 0;
				}
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			flag=0;
			for(k=1;k<=n;k++){
				if(a[i][k]+a[k][j]==a[i][j] && i!=j && i!=k && j!=k){
					flag=1;
				}
			}
			if(!flag){
				ans+=(1ll*a[i][j]);
			}
		}
	}
	ans/=2;
	printf("%lld\n",ans);
	return 0;	
}

Measured memory_bytes: 640
import java.util.*;
import java.math.*;
import java.io.*;


public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int num = 1;
        int ans = 0;
        while(num < b) {
            num--;
            num += a;
            ans++;
        }
        System.out.println(ans);


    } 
}

Measured memory_bytes: 21716
#!/usr/bin/env python
# coding: utf-8

# In[10]:


X,Y,A,B,C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)


# In[14]:


p_list = p[:X]
q_list = q[:Y]
mylist = sorted(p_list + q_list + r, reverse=True)
ans = 0
for i in range(X+Y):
    ans += mylist[i]
print(ans)


# In[ ]:






Measured memory_bytes: 29392
#include<stdio.h>
int linearSearch();
int key,S[10000],T[500],k=0,j,i,q,n;
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&T[i]);
  linearSearch();
  printf("%d\n",k);
  return 0;
}

int linearSearch()
{
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(T[i] == S[j]){k++;
      break;
      }
    }
  }

}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n,x;
    ci(n>>x);
  vll A(n);
  FOR(i,0,n){
    ll a;
    ci(a);
    A[i]=max(a-x,x-a);
  }
  SORT(A);
  ll g=0;
  FOR(i,0,n){
    g=gcd(A[i],g);
  }
  co(g);
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int gcd(int a,int b);
int compare(const void* a, const void* b);

int main(void){
    int N;
    int i,j,z;
    int ret = 0; 
    int add_bl = 0;
    char S[200000][11];
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%s",S[i]);
    }
    qsort(S,N,sizeof(*S),compare);
    ret = 1;
    for(i=1;i<N;i++){
        if (strcmp(S[i],S[i-1]) != 0){
            ret++;
        }
    }
    printf("%d\n",ret);
    return 0;

}
int compare(const void* a, const void* b){
    return strcmp(a, b);
}
// 最大公約数
int gcd(int a,int b){
    int c;
    int tmp;
    if(b > a){  //bがaより大きい場合bとaを入れ替える
        c = a;
        a = b;
        b = c;
    }
    tmp = a % b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


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

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int a[501][501];
int b[31][31];
int r[3][31];

int main(){
	int n, c; cin >> n >> c;
	for(int i = 1; i <= c; i++) for(int j = 1; j <= c; j++){
		int t; cin >> t; b[i][j] = t;
	}
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
		int t; cin >> t; a[i][j] = t;
		for(int l = 1; l <= c; l++){
			int s = (i + j) % 3;
			r[s][l] += b[t][l];
		}
	}
	int answer = inf;
	for(int i = 1; i <= c; i++){
		for(int j = 1; j <= c; j++){
			if(i != j){
				for(int k = 1; k <= c; k++){
					if(i != k && j != k){
						answer = min(answer, r[2][i] + r[1][j] + r[0][k]);
					}
				}
			}
		}
	}
	cout << answer << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a * c, a * d, b * c, b * d});
    if(a <= 0 and 0 <= b)
        ans = max(ans, 0LL);
    if(0 >= c and 0 <= d)
        ans = max(ans, 0LL);
    cout << ans << endl;

    time_taken();
    return 0;
}

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

using namespace std;

int main()
{
  string s, p;
  cin >> s >> p;
  s += s;

  if (s.find(p) != -1)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3196
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

typedef pair<pii,pii> C;

C norm(C c) {
    return min(min(C{{c.x.y, c.y.x}, {c.y.y, c.x.x}}, C{{c.y.y,c.x.x},{c.x.y,c.y.x}}), min(c, {c.y,c.x}));
}

int get(const C&c, int i) {
    switch(i&3) {
        case 0: return c.x.x;
        case 1: return c.x.y;
        case 2: return c.y.x;
        case 3: return c.y.y;
    }
}

int rot(const C&c) {
    if (c.x == c.y) {
        if (c.x.x == c.x.y) return 4;
        else return 2;
    } else return 1;
}

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    int N; cin >> N;

    unordered_map<C, int> P;
    vector<C> Q;
    for (int i = 0; i < N; i++) {
        int a,b,c,d; cin >> a >> b >> c >> d;
        C x{{a,b},{c,d}};
        x = norm(x);
        P[x] += 1;
        Q.push_back(x);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        C &p = Q[i];
        for (int j = i+1; j < N; j++) {
            C &q = Q[j];
            for (int k = 0; k < 4; k++) {
                ll cur = 1;
                C u[4];
                for (int l = 0; l < 4; l++) {
                    u[l] = norm({{get(p,l+1),get(p,l)},{get(q,k-l+1),get(q,k-l)}});
                    int opts = P[u[l]];
                    if (u[l] == p) --opts;
                    if (u[l] == q) --opts;
                    for (int m = 0; m < l; m++) {
                        if (u[m] == u[l]) --opts;
                    }
                    if (opts <= 0) {
                        cur = 0;
                    } else {
                        cur *= opts*rot(u[l]);
                    }
                }
                ans += cur;
            }
        }
    }

    cout << ans/3 << endl;
}


Measured memory_bytes: 76880
H, W = list(map(int, input().split()))
A = [list(map(lambda c : int(c)%2, input().split())) for _ in range(H)]

ops = []
for r in range(H):
    pair_list = []
    pair_left = None
    for c in range(W):
        if A[r][c]==1:
            if pair_left!=None: pair_list.append((pair_left, c))
            pair_left = None if pair_left!=None else c

    if pair_left!=None and r!=H-1:
        ops.append((r+1, pair_left+1, r+2, pair_left+1))
        A[r+1][pair_left] += 1
        A[r+1][pair_left] %= 2
      	
    for pair_left, pair_right in pair_list:
        for c_ in range(pair_left, pair_right):
            ops.append((r+1, c_+1, r+1, c_+2))

print(len(ops))
for op in ops:
    print(*op)

Measured memory_bytes: 26652
import numpy as np

H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
visited = [[-1]*W for _ in range(H)]
que = [[0,0]]
direction = [[1,0],[0,1],[-1,0],[0,-1]]
visited[0][0] = 1
while que:
  h, w = que.pop(0)
  for dh, dw in direction:
    if h+dh<0 or H<=h+dh or w+dw<0 or W<=w+dw:
      continue
    if G[h+dh][w+dw] == '#':
      continue
    if visited[h+dh][w+dw] != -1:
      continue
    que.append([h+dh, w+dw])
    visited[h+dh][w+dw] = visited[h][w]+1
cnt = 0
for i in range(H):
  for j in range(W):
    if G[i][j] == '#':
      cnt += 1
if visited[H-1][W-1] != -1:
  ans = H*W-visited[H-1][W-1]-cnt
else:
  ans = -1
print(ans)


Measured memory_bytes: 12436
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

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

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define ll unsigned long long
#define Pair pair<ll,ll>

const ll mod = 1e9+7;

ll N, M;

ll C[100050][35]={1};


void solve(){
	ll Ans=1;
	vector<Pair> ans;
	ll m=sqrt(M)+1;

	//cout << m << endl;

	ll count;
	for(ll i=2;i<m;i++){
		count=0;
		while(M%i == 0){
			M /= i; count++;
		}
		if(count != 0) ans.push_back({i,count});
	}
	if(M > 1) ans.push_back({M,1});

	// for(int i=0; i<ans.size();i++){
	// 	cout << ans[i].first << ", " << ans[i].second << endl;
	// }



	for(int i=0; i<ans.size();i++){
		Ans *= C[N-1+ans[i].second][ans[i].second];
		Ans %= mod;

	}

	cout << Ans << endl;





}

int main(){
	cin >> N >> M;

	for(int i=1; i<=N+30; i++) {
		C[i][0] = 1;
		for(int j=1; j<=min(i,30); j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
	}

	solve();
	return 0;
}

Measured memory_bytes: 27648
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#a, b = map(int, input().split())
N = int(input())
P = list(map(int, input().split()))

max = P[0]
sum = 1
for i in range(1, N) :
  if max > P[i] :
    max = P[i]
    sum += 1
print (sum)






Measured memory_bytes: 77296
#include<bits/stdc++.h>
using namespace std;
//const int M=1000000007;
const int N=300005,E=524288;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int n,m,p,M;
int i,j,k,a,b,c,d;
long long dp[4][105][105][105],C[105][105],f[105][10005];
long long u[105][105][105],v[105][105][105];
long long x[105][105][105],y[105][105][105];
int main()
{
	scanf("%d %d %d %d",&n,&m,&p,&M);
	f[0][0]=1;
	for(i=1;i<=p;++i)
	{
		f[i][0]=1;
		for(j=1;j<=n*m;++j)
			f[i][j]=f[i][j-1]*i%M;
	}
	for(i=0;i<=100;++i)
	{
		C[i][0]=C[i][i]=1;
		for(j=1;j<i;++j)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
	}
	for(a=1;a<=p;++a)
		for(b=0;b<=100;++b)
			for(i=0;i<=100;++i)
			{
				u[a][b][i]=f[a][(n-b)*i]*f[p-a][b*i]%M;
				v[a][b][i]=f[a][(m-b)*i]*f[p-a][b*i]%M;
				x[a][b][i]=f[a][(n-b)*i]*f[p-a+1][b*i]%M;
				y[a][b][i]=f[a][(m-b)*i]*f[p-a+1][b*i]%M;
			}
	dp[0][p+1][n][m]=1;
	for(a=p;a>=1;--a)
		for(b=n;b>=0;--b)
			for(c=m;c>=0;--c)
			{
				long long s=0;
				for(i=0;i+c<=m;++i)
					s=(s+(i&1?u[a][b][i]:-u[a][b][i])*C[m-c][i]%M*dp[0][a+1][b][c+i])%M;
				dp[3][a][b][c]=s;
				s=0;
				for(i=0;i+b<=n;++i)
					s=(s+(i&1?v[a][c][i]:-v[a][c][i])*C[n-b][i]%M*dp[3][a][b+i][c])%M;
				dp[2][a][b][c]=s;
				s=0;
				for(i=0;i+c<=m;++i)
					s=(s+x[a][b][i]*C[m-c][i]%M*dp[2][a][b][c+i])%M;
				dp[1][a][b][c]=s;
				s=0;
				for(i=0;i+b<=n;++i)
					s=(s+y[a][c][i]*C[n-b][i]%M*dp[1][a][b+i][c])%M;
				dp[0][a][b][c]=s;
			}
	cout<<(dp[0][1][0][0]%M+M)%M;
}

Measured memory_bytes: 80512
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	N := list[0]
	X := list[1]
	L := getStdinIntArr()
	D := make([]int, 0)
	D = append(D, 0)

	cnt := 1
	for i := 0; i < N; i++ {
		D1 := D[i] + L[i]
		D = append(D, D1)
		if D1 > X {
			break
		}
		cnt++
	}

	fmt.Printf("%d\n", cnt)
}

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 640
package main

import(
    "fmt"
)



func main() {
    var n int
    fmt.Scan(&n)
    var a = make([]int, n)
    for i := 0; i<n ; i++{
        fmt.Scan(&a[i])
    }
    ans := 0
    for i := 1; i < n-1 ; i++{
        if (a[i-1] < a[i] && a[i] < a[i+1]) || (a[i-1] > a[i] && a[i] > a[i+1]){
            ans++
        }
    }
    fmt.Println(ans)
}





func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 998244353;
int N;
int a[300];
int S;
ll dp[310][90000];
ll dp2[310][90000];
ll A,B,C;
ll Ans;

ll pow_MOD(ll x,ll n){//x^n
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    res %= MOD;
    return res;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        S += a[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= S; j++){
            if(j-a[i-1] >= 0){
                dp[i][j] = (dp[i-1][j] * 2) % MOD + dp[i-1][j-a[i-1]]; 
            }else{
                dp[i][j] = dp[i-1][j] * 2;
            }
            dp[i][j] %= MOD;
        }
    }
    
    for(int i = (S + 1)/2; i <= S; i++){
        A += dp[N][i];
    }
    
    dp2[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= S; j++){
            if(j-a[i-1] >= 0){
                dp2[i][j] = dp2[i-1][j] + dp2[i-1][j-a[i-1]]; 
            }else{
                dp2[i][j] = dp2[i-1][j];
            }
            dp2[i][j] %= MOD;
        }
    }
    if(S % 2){
        B = 0;
    }else{
        B = dp2[N][S/2];
    }
    
    C = 0;
    Ans = ((((pow_MOD(3, N) - 3 * A) % MOD) + MOD) % MOD + 3 * B) % MOD - C;
    
    cout << Ans << endl;
    
}

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

int main(){
  int a, b, ans;
  cin >> a >> b;
  ans = -1;
  double price = 0;
  while (price <= 10000){
    if ((int)(price*0.08) == a && (int)(price*0.1) == b){
      ans = (int)price;
      break;
    }
    price++;
  }

  cout << ans << endl;

  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  int x;
  cin >> x;
  x /= 100;
  cout << "ai1333";
  rep(i,x) cout << '3';
  puts("");
  compute();
  return 0;
}



Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n, m;
    cin >> n >> m;
    if(!n)
        return false;
    vector<int> c(m);
    vector<int> x(n);
    for(int i = 0; i < m; ++i)
        cin >> c[i];
    for(int i = 0; i < n; ++i)
        cin >> x[i];

    vector<i64> dp(256, INF);
    dp[128] = 0;
    for(int i = 0; i < n; ++i){
        vector<i64> nex(256, INF);
        for(int j = 0; j < 256; ++j){
            for(auto p : c){
                int k = min(max(0, j + p), 255);
                chmin(nex[k], dp[j] + (x[i] - k) * (x[i] - k));
            }

        }
        dp = move(nex);
    }
    cout << *min_element(dp.begin(), dp.end()) << endl;
    return true;
}

signed main(){
    while(solve());
}



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

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

  vector<long long> A(X), B(Y), C(Z);

  for(int i=0; i<X; ++i)
    cin >> A[i];

  for(int i=0; i<Y; ++i)
    cin >> B[i];

  for(int i=0; i<Z; ++i)
    cin >> C[i];

  // A + B の上位K個
  vector<long long> AB;
  for(int i=0; i<X; ++i)
  {
    for(int j=0; j<Y; ++j)
    {
      AB.push_back(A[i] + B[j]);
    }
  }

  sort(AB.begin(), AB.end(), greater<long long>());
  AB.resize(K);

  // AB と C
  vector<long long> ABC;
  for(int i=0; i<AB.size(); ++i)
  {
    for(int j=0;j<Z;++j)
    {
      ABC.push_back(AB[i]+C[j]);
    }
  }

  sort(ABC.begin(), ABC.end(), greater<long long>());

  // 出力
  for(int k=0; k<K; ++k)
  {
    cout << ABC[k] << endl;
  }

  return 0;
}

Measured memory_bytes: 42984
import sys
from bisect import bisect_left, bisect_right

N=input()
L=map(int, sys.stdin.readline().split())
L.sort()

ans=0
for i in range(N):
    for j in range(i+1,N):
        a=L[i]
        b=L[j]
        max_c=a+b
        min_c=max(a-b,b-a)
        p_max_c=bisect_left(L,max_c)
        p_min_c=max(bisect_right(L,min_c),j)
        ans+=p_max_c-p_min_c-1

print ans

Measured memory_bytes: 34408
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

bool vector_finder(std::vector<int> vec, int number) { // vector 内にnumberがあるかどうか
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance( vec.begin(), itr );
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}

int main() {
	int x; 
	cin >> x;
	if (x >= 30) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = -1

for k in sorted(d.keys())[::-1]:
    if ans == -1 and d[k] >= 4:
        print(k*k)
        exit()
    elif ans == -1 and d[k] >= 2:
        ans = k
    elif ans != -1 and d[k] >= 2:
        print(ans*k)
        exit()

print(0)

Measured memory_bytes: 18600