akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

const long long MAX = 110000;

long long dp[MAX][3];

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

  // init
  for(int i = 0; i < MAX; ++i){
    for(int j = 0; j < 3; ++j){
      dp[i][j] = -1;
    }
  }
  // initial condition
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  for(int i = 0; i < n; ++i){
    dp[i + 1][0] = max(dp[i][1] + a[i][0], dp[i][2] + a[i][0]);
    dp[i + 1][1] = max(dp[i][0] + a[i][1], dp[i][2] + a[i][1]);
    dp[i + 1][2] = max(dp[i][0] + a[i][2], dp[i][1] + a[i][2]);
  }

  long long res = 0;
  for(int i = 0; i < 3; ++i){
    res = max(res, dp[n][i]);
  }
  cout << res << endl;
}


Measured memory_bytes: 3968
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = LLONG_MAX, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

bool flag[100000];
int main() {
	cin >> N;
	rep(i, N) {
		cin >> A;
		flag[i] = (A == i + 1);
	}

	int cnt = 0;
	vector<int> cnts;
	rep(i, N) {
		if (flag[i]) {
			cnt++;
		}
		else {
			if(cnt != 0) cnts.push_back(cnt);
			cnt = 0;
		}
	}
	if (cnt != 0) cnts.push_back(cnt);

    ll ans = 0;
    rep(i, cnts.size()){
        ans += (cnts[i]+1)/2;
    }
    cout << ans;
}


Measured memory_bytes: 768
N = 10**6+1
K = gets.to_i

n = 0
ans = 0
ok = false
for i in 1..N
    n = (n*10 + 7) % K
    ans += 1
    if n == 0
        ok = true
        break
    end
end

if ok
    puts ans
else
    puts "-1"
end



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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    int a[51], b[51];
    a[0] = 1, a[1] = 5;
    b[0] = 1, b[1] = 3;
    rep(i, 50) {
        a[i + 1] = a[i] * 2 + 3;
        b[i + 1] = b[i] * 2 + 1;
    }
    int ok = N;
    int ans = 0;
    while(X > 0){
        while(X < a[ok] && X > 0) {
            X--; ok--;
        }
        if (X == 0) break;
        //cout << ok << endl;
        X -= a[ok];
        ans += b[ok];
        if(X == 0) break;
        X--;
        ans++;
    }
    cout << ans << endl;

    

    
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var c = 0
	for i := 0; i < n; i++ {
		var tmp int
      	fmt.Scan(&tmp)
		if tmp == c+1 {
			c++
		}
	}
	if c == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(n - c)
}

Measured memory_bytes: 5504
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	calc(a, b)
}

func calc(a, b int) error {
	if b%a == 0 {
		fmt.Println(a + b)
	} else {
		fmt.Println(b - a)
	}
	return nil
}

Measured memory_bytes: 512
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2052
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#define INF 100000000

#define MAX_N 10000
#define MAX_M 100

typedef long long int ll;
using namespace std;



int main(){

	int a,b,c;

	scanf("%d %d %d", &a, &b, &c);

	if(a < b && b < c)
		printf("Yes\n");
	else
		printf("No\n");




	return 0;

}

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

using namespace std;

void solve(){
	int x;
	cin >> x;
	if(x==1){
		cout << "0" << endl;
	}
	else{
		cout << "1" << endl;
	}

}

int main(){
/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif*/
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//int t;cin >> t;while(t--){solve();}
	solve();
	return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int, input().split()))

count_even = 0
for i in range(n//2):
    if a[i*2+1]<=0:
        count_even += 1
count_odd = 0
for i in range((n+1)//2):
    if a[i*2]<=0:
        count_odd += 1
ans = 0
for i in range(n):
    ans += abs(a[i])
if (count_even - count_odd) % 2 == 0:
    print(ans)
else:
    a_abs = [abs(a[i]) for i in range(n)]
    print(ans - min(a_abs)*2)

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*ここから*/
int main() {
    char a,b;
    cin >> a >> b;
    if(a!=b){
        for(int i=0;i<2;i++){
            char c;
            cin >> c;
            if(c!=a&&c!=b){
                cout << "No" << endl;
                exit(0);
            }
        }
        cout << "Yes" << endl;  
    }else {
        char c,d;
        cin >> c >> d;
        if(c!=d||a==c){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    cin >> a >> b;
    if(b < a){
        cout << a + (a - 1) << endl;
    }
    else if(a < b){
        cout << b + (b - 1) << endl;
    }
    else{
        cout << a + b << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
        int N, K;
        int a=1;

        std::cin >> N;
        std::cin >> K;

        for(int i=0; i < N; i++){
                if(a>K){
                        a+=K;
                }
                else{
                        a=2*a;
                }
        }

        std::cout << a << std::endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  int n1, n2, n3, n4;
  string str;
  n1=0; n2=0; n3=0; n4=0;
  cin>>n;
  
  for(int i=0; i<n; i++){
    cin>>str;
    if(str=="AC"){
      n1++;
      continue;
    }else if(str=="WA"){
      n2++;
      continue;
    }else if(str=="TLE"){
      n3++;
      continue;
    }else if(str=="RE"){
      n4++;
    }
  }
  cout<<"AC x "<<n1<<"\n"
      <<"WA x "<<n2<<"\n"
      <<"TLE x "<<n3<<"\n"
      <<"RE x "<<n4<<"\n";
  
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

class UnionFind {
private:
  ll n;
  vll P;
  ll root(ll x);
  void setN(ll N);
  void init();

public:
  UnionFind(ll N);
  void unite(ll x, ll y);
  bool same(ll x, ll y);
};

// コンストラクタ
UnionFind::UnionFind(ll N) {
  setN(N);
  init();
}

// nを変更
void UnionFind::setN(ll N) { n = N; }

// Union-Find Treeを初期化する
void UnionFind::init() {
  P.clear();
  rep(i, n) { P.push_back(i); }
}

// 根の値を返す
ll UnionFind::root(ll x) {
  if (P[x] == x) { return x; }
  return (P[x] = root(P[x])); // パス圧縮しつつ返す
}

// 木を結合する（rankはとりあえず無視）
void UnionFind::unite(ll x, ll y) { P[root(x)] = root(y); }

// xとyが同じ集合にあるか判別
bool UnionFind::same(ll x, ll y) {
  if (root(x) == root(y)) {
    return true;
  } else {
    return false;
  }
}

// ----本問について----
// 問題：橋の取り壊し
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/0180
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

struct edge {
  ll w, s, e; // weight, start, end

  // コンストラクタ
  edge(ll W, ll S, ll E) {
    w = W;
    s = S;
    e = E;
  }
};

// edge用の比較関数
bool cmpI(const edge &a, const edge &b) { return a.w < b.w; }

// グローバル変数（入力）
ll n, m;
vector<edge> edges;

// 入力
void input() {
  edges.clear();
  rep(i, m) {
    ll a, b, cost;
    cin >> a >> b >> cost;
    edges.push_back(edge(cost, a, b));
  }
}

// 最小全域木の重みの合計を求める（クラスカル法）．
void solve() {
  sort(edges.begin(), edges.end(), cmpI); // 辺を重みをキーに昇順ソート
  UnionFind u(n);                         // UnionFind木を初期化
  ll ans = 0;
  rep(i, edges.size()) {
    if (!u.same(edges[i].s, edges[i].e)) { // 閉路ができない
      u.unite(edges[i].s, edges[i].e);     // 辺を張る
      ans += edges[i].w;
    }
  }
  cout << ans << endl;
}

int main() {
  while (cin >> n >> m && n > 0) {
    input();
    solve();
  }
  return 0;
}



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


int main() {
    vector<int> g1{1, 3, 5, 7, 8, 10, 12};
    vector<int> g2{4, 6, 9, 11};
    
    int x, y;
    cin >> x >> y;
    if (
        (
         count(g1.begin(), g1.end(), x) > 0 &&
         count(g1.begin(), g1.end(), y) > 0
        ) ||
        (
         count(g2.begin(), g2.end(), x) > 0 &&
         count(g2.begin(), g2.end(), y) > 0
        )
    ) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
class Heap:
    def __init__(self,nodes):
        self.nodes = nodes

    def buildHeap(self):
        for i in range(int(len(self.nodes)/2),-1,-1):
            self.siftDown(i)

    def siftDown(self,start):
        while (2*start+1 < len(self.nodes)):
            c = 2*start+1
            if (c+1 < len(self.nodes) and self.nodes[c+1] < self.nodes[c]):
                c += 1
            if (self.nodes[c] < self.nodes[start]):
                self.nodes[start], self.nodes[c] = self.nodes[c], self.nodes[start]
                start = c
            else:
                return

    def getMin(self):
        min = self.nodes[0]
        self.nodes[0] = self.nodes[-1]
        del(self.nodes[-1])
        self.siftDown(0)
        return min


nStr, strLen = map(int,input().split())
nodes = []
for i in range(nStr):
    nodes.append(input())

heap = Heap(nodes)
heap.buildHeap()

minStr = ''
for i in range(nStr):
    minStr += heap.getMin()

print(minStr)



Measured memory_bytes: 3064
n, m = [int(el) for el in input().split(' ')]
c = [int(el) for el in input().split(' ')]

t = [0] + [float('inf') for _ in range(n)]

for i in range(m):
    for j in range(c[i], n+1):
        t[j] = min(t[j], t[j-c[i]] + 1)
print(t[n])

Measured memory_bytes: 9660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010;
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
  else{
    int ans = INF;
    ans = min(ans,a*b);
    ans = min(ans,c*b);
    ans = min(ans,a*c);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){

	int buildings[4][3][10];
	int notices,b,f,r,v;

	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				buildings[i][j][k] = 0;
			}
		}
	}

	cin >> notices;

	for(int i=0;i<notices;i++){
		cin >> b >> f >> r >> v;

		buildings[b-1][f-1][r-1] += v;
		if(buildings[b-1][f-1][r-1] < 0) buildings[b-1][f-1][r-1] = 0;
	}

	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				cout << " " << buildings[i][j][k];
				if(k == 9)
					cout << endl;

			}
		}
		if(i != 3)
			cout << "####################" << endl;
	}

	return 0;
}


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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if(max(a, k) == a) cout << k << endl;
  else if(k <= a + b) cout << a << endl;
  else cout << a - (k - a - b) << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int dp[(int)1e5+5];
bool recur(vector<int> &inp,int k){
    if(k<0)return true;
    if(dp[k]!=-1)return dp[k];
    for(int i=0;i<inp.size();i++){
        if (recur(inp,k-inp[i])==false)
        {
            return dp[k]=true;
        }
    }
    return dp[k]=false;
}
void solve(){
    int n,k;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    vector<int> inp(n);
    vector<int> used(n,0);
    for (int i = 0; i < n; i++)
    {
        cin>>inp[i];
    }

    if(recur(inp,k))cout<<"First";
    else cout<<"Second";
}

int main() {
    int t=1;
    for (int i = 0; i < t; i++)
    {
        // cout<<"Case #"<<(i+1)<<": ";
        // cout<<'\n';
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 7044
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
	int[] x;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		n = readln().strip().to!int;
		x = readln().strip().split().map!(to!int).array();
	}
}

auto main2(Input* input)
{
	with (input)
	{
        int min = int.max;
        foreach (pos; 1..101)
        {
            auto cost = 0;
            foreach (xi; x)
                cost += (xi - pos) ^^ 2;
            if (min > cost)
                min = cost;
        }
        return min;
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`2
1 4`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 5);
	}

	unittest // example2
	{
		string example =
`7
14 14 2 13 56 2 37`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 2354);
	}

	unittest // example3
	{
		string example =
``;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == _placeholder_);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main(){
   string s, t; cin >> s >> t;
   int N = s.size();
   int M = t.size();
   vector<vector<int>> pos(26);
   for (int i = 0; i < N; i++){
     pos[s[i] - 'a'].push_back(i);
   }

   bool ok = true;
   for (int i = 0; i < M; i++){
     if (pos[t[i] - 'a'].size() == 0){
       ok = false;
     }
   }

   if (!ok){
     cout << -1 << endl;
   }

   else {
     ll ans = -1;
     for (int i = 0; i < M; i++){
       auto itr = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), ans % N);
       if (itr != pos[t[i] - 'a'].end()) ans += *itr - ans % N;
       else ans += N - ans % N + pos[t[i] - 'a'].front();
     }
     cout << ans + 1 << endl;
   }
 }


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
vector<int> A;

int func(int val) {
    int ret = 0;
    REP(i, N) {
        ret += abs(A[i] + val);
    }
    return ret;
}


// [lb, ub] の範囲の値を下に凸な func 関数で得られるとき、
// 三分探索で最小解を求める
// func は返り値 ll, 引数ひとつで型 ll の関数を与える
ll tri_search(ll lb, ll ub, function< ll(ll) > func) {
    while(ub - lb > 1) {
        ll t1 = (2 * lb + ub) / 3;
        ll t2 = (lb + 2 * ub) / 3;
        if(func(t1) > func(t2)) {   // 上に凸ならここの不等号を逆転させれば OK
            if(lb == t1) { break; } // もう変化しないくらい範囲が狭くなった
            lb = t1;
        }
        else {
            if(ub == t2) { break; }
            ub = t2;
        }
    }

    // この時点でだいたい ub - lb <= 6 くらいになってるはず
    ll ret = LLINF;                 // 上に凸ならここを -LLINF にする
    for(ll i = lb; i <= ub; ++i) {
        ret = min(ret, func(i));    // 上に凸ならここを max にする
    }
    return ret;
}

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

    cin >> N;
    A.resize(N);
    REP(i, N) { 
        cin >> A[i];
        A[i] -= (i + 1);
    }

    int ans = tri_search(-INF * 2, INF * 2, func);

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1792
def solve(i: int, A: list, meolist: list, m: int):
    if m == 0:
        return True
    elif m in meolist[i].keys():
        return meolist[i][m]
    
    if i >= len(A):
        meolist[i][m] = False
    elif solve(i + 1, A, meolist, m - A[i]) is True:
        meolist[i][m] = True
    elif solve(i + 1, A, meolist, m) is True:
        meolist[i][m] = True
    else:
        meolist[i][m] = False

    return meolist[i][m]

if __name__ == '__main__':
    n = int(input())
    A = [int(num) for num in input().split(' ')]
    m = int(input())
    mlist = [int(num) for num in input().split(' ')]

    # Memory array, store the num already cal
    meolist = [{} for i in range(n + 1)]

    for num in mlist:
        if solve(0, A, meolist, num):
            print('yes')
        else:
            print('no')


Measured memory_bytes: 7416
from collections import Counter
from collections import defaultdict

def li():
    return [int(x) for x in input().split()]

H, W, M = li()
PH, PW = [], []
PF = defaultdict(int)

for i in range(M):
    h, w = li()
    PH.append(h)
    PW.append(w)
    PF[h, w] += 1

frequency_h_list = Counter(PH).most_common()
frequency_w_list = Counter(PW).most_common()

most_common_h_cnt = frequency_h_list[0][1]
most_common_w_cnt = frequency_w_list[0][1]

most_common_h_list = [x[0] for x in frequency_h_list if x[1] == most_common_h_cnt]
most_common_w_list = [x[0] for x in frequency_w_list if x[1] == most_common_w_cnt]

diff = -1
for h in most_common_h_list:
    for w in most_common_w_list:
        if PF[h, w] == 0:
            diff = 0
            break

cnt = most_common_h_cnt + most_common_w_cnt + diff

print(cnt)

Measured memory_bytes: 262656
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll h,w;
  cin >> h >> w;

  std::vector<vector<char>> a(h,vector<char>(w));
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      cin >> a.at(i).at(j);
    }
  }

  char data;
  ll first,mas=0;
  for(ll i=0;i<h;i++){
    first=1;
    for(ll j=0;j<w;j++){
      data=a.at(i).at(j);

      if(data=='#'){
        if(mas>j){
          cout << "Impossible" << endl;
          return 0;
        }
        else if(mas==j){
          mas=j;
          first=0;
        }
        else if(mas+1==j && first==0){
          mas=j;
        }
        else{

          if(first==0){
          cout << "Impossible" << endl;
          return 0;
          }

        }
      }

    }
  }

  cout << "Possible" << endl;
  return 0;

  }

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ll n , m ;
vector<vector<ll>> hen;
vector<ll> a;

ll f(ll x){
    if(a.at(x)!=INF) return a.at(x);
    ll rec = 0;
    for(auto a:hen.at(x)){
        rec = max(rec,f(a));
    }
    a.at(x) = rec+1;
    return rec+1;
}


int main(){
    cin >> n >> m;
    hen.resize(n,vector<ll>(0));
    a.resize(n,INF);

    rep(i,m){
        ll x,y; cin >> x >> y;
        x--; y--;
        hen.at(x).push_back(y);
    }
    //rep(i,n){for(auto a:hen.at(i)){cout << a;} cout << endl;}
    for(ll i=0;i<n;i++){
        if(a.at(i)!=INF)continue;
        f(i);
    }
    //rep(i,n) cout << a.at(i) << endl;
    ll ans = 0;
    rep(i,n) ans = max(ans,a.at(i));
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 8576
import java.util.*;

public class Main{
//public class abc167_a{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int h1 = scan.nextInt();
		int m1 = scan.nextInt();
		int h2 = scan.nextInt();
		int m2 = scan.nextInt();
		int k = scan.nextInt();

		int f1 = h1 *60 +m1;
		int f2 = h2* 60 + m2;

		int ans = f2 - (f1 +k);
		if(ans <= 0){
			System.out.println( 0);
		}else{
			System.out.println( ans );
		}

	}

}

Measured memory_bytes: 27032
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,d;
int main(){FAST;
cin>>n>>d;
d*=d;
ll ans = 0;
for(ll i=1;i<=n;++i){
  ll x,y;cin>>x>>y;
  if(x*x+y*y<=d)++ans;
}
cout<<ans;
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>

#define LEN 100005

typedef struct pp
{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head,tail,n;

void enqueue(P);

P dequeue(void);

int main()
{
  int elaps = 0;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);

  for(i = 1;i <= n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
    }
  head = 1;
  tail = n + 1;

  while(1)
    {
      if(head == tail)
	{
	  break;
	}
      if(Q[head].t > q)
	{
	  Q[head].t = Q[head].t - q;
	  u = dequeue();
	  enqueue(u);
	  elaps += q;
	}
      else
	{
	  elaps += Q[head].t;
	  printf("%s %d\n",Q[head].name,elaps);
	  u = dequeue();
	}
    }
  return 0;
}

void enqueue(P x)
{
  if(head ==(tail + 1)%(LEN + 1))
    {
      printf("Error(overflow)\n");
      exit(1);
    }
      Q[tail] = x;
      if(tail + 1 == LEN + 1)
	{
	  tail = 0;
	}
      else{tail++;}
}

P dequeue()
{
  P x;
  if(head == tail)
    {
      printf("Error(underfllor)\n");
    }
  x = Q[head];
  if(head + 1 == LEN + 1)
    {
      head = 0;
    }
  else{head++;}
  return x;
}



Measured memory_bytes: 11880
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;
const int n2 = 1e7;
bool primes[n2+1];
vector<int> u;

void seive()
{
	primes[1]=primes[0]= 0;
	for(int i = 2; i<=sqrt(n2); i++)
		if(primes[i])
			for(int j = i*i; j<=n2; j+=i)
				primes[j]=0;
	for(int i = 2; i<n2; i++)
		if(primes[i])
			u.push_back(i);
}

void divisors(ll n, set<ll> &s)
{
	for(int i = 1;i<=sqrt(n); i++)
	{
		if(n%i==0)
		{
			s.insert(i);
			s.insert(n/i);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	set<ll>s,h;
	memset(primes,1,n2);
	seive();
	divisors(n,h);
	for(auto it:h)
	{
		if(it==1)
			continue;
		else if(it==n)
		{
			s.insert(n);
			continue;
		}
		ll t = n,t2 = n;
		ll r = n/it;
		while(t%it==0)
		{
			t/=it;
		}
		while(t2%r==0 && r>1) t2/=r;
		if(t%it==1)
			s.insert(it);
		if(t2%r==1)
			s.insert(r);
	}
	divisors(n-1,s);
	// for(auto it:s)
	// 	cout<<it<<" ";
	cout<<s.size()-1<<endl;
	return 0;
}

Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 998244353
#define ff first
#define ss second
#define pb push_back
#define inf 10000000000

							
									//nestedcode

long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) % M;
        a = (a * a)%M;
        b >>= 1;
    }
    return res;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,s,i,j,ans;
    cin>>n>>s;
    ll dp[n+5][s+5];
    ll a[n+5];
    ans = 0;
    for(i=0;i<n;i++){
    	cin>>a[i];
	}
	dp[0][a[0]] = binpow(2,n-1);
	dp[0][0] = binpow(2,n);
	for(i=1;i<=s;i++){
		if(i!=a[0])
		dp[0][i] = 0;
	} 
	for(i=1;i<n;i++){
		for(j=0;j<=s;j++){
			dp[i][j] = dp[i-1][j];
		}
		for(j=0;j<=s;j++){
			if(a[i] + j > s){
				continue;
			}
			dp[i][a[i] + j] += (dp[i-1][j]*binpow(2,M-2))%M;
			dp[i][a[i] + j] %= M;
 		}
	}
	

	ans = dp[n-1][s];
	cout<<ans;
	
}

Measured memory_bytes: 74064
import copy

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)


Measured memory_bytes: 14560
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int n= in.nextInt();
			int a[] = new int[n];
			int ans = 0;
			for(int i=0; i<n; i++)
				a[i]=in.nextInt();
			Arrays.sort(a);
			int sum[]= new int [n];
			sum[0]=a[0];
			for(int i=1; i<n; i++)
				sum[i]=a[i]+sum[i-1];
			for(int i=0; i<n ;i++)
			ans+=sum[i];
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
int main(){
	int much[]={6000,4000,3000,2000};
	int num;
	int kind;
	int monny=0;
	for(int i=0;i<4;++i){
		cin>>kind>>num;
		cout<<much[kind-1]*num<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
 
 int main(){
 	int i;
 	double total, a;
 	while (scanf("%lf", &a) != EOF){
 		total = a;
 		for (i = 2; i <= 10; i++){
 			if (i%2 == 0){
 				a *= 2;
 				total += a;
 			}else {
 				a /= 3.0;
 				total += a;
 			}
 		}
 		printf("%f\n", total);
 	}
 	return 0;
 }

Measured memory_bytes: 648
#include <stdio.h>

int main(void){
  int n;
  long long a[100005];
  
  scanf("%d", &n);
  for(int i=0;i<n;i++){
    scanf("%lld", &a[i]);
  }
  
  int zero = 0;
  for(int i=0;i<n;i++) if(a[i]==0) zero++;
  if(zero>0){
    printf("0\n");
    return 0;
  }
  long long prod = 1;
  for(int i=0;i<n;i++){
    if(a[i] <= 1000000000000000000/prod){
      prod *=a[i];
    }else{
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld", prod);
  
    
    

}


Measured memory_bytes: 2468
#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lc "\n"
#define forr(i,a,n)  for(ll i=a;i<n;i++)
#define forrr(i,a,n)  for(int i=a;i<=n;i++)
using namespace std;

int main()
{
    IOS;
    ll n,c=0;
    cin>>n;
    forrr(i,1,n)
    {
        forrr(j,1,n)
        {

                if(i*j<n){c++;}
                else{break;}

        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3652
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val A = sc.nextInt
  val B = sc.nextInt
  val K = sc.nextInt - 1

  // AからA+Kまで出力(ただしBを超えたら終わり)
  for (i <- A to A + K) {
    if (i <= B) {
      println(i)
    }
  }

  // B-KからBまで出力(ただし、A+K以上である必要がある)
  for (j <- B-K to B) {
    if (j > A + K) {
      println(j)
    }
  }
}

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

int main()
{
    string s;
    cin>>s;
    int sum=0,a,i;
    for(i=0;s[i]!='\0';i++)
    {
        a=s[i]-48;
        sum=sum+a;
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3692
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll h,n;cin>>h>>n;
    vector<ll>a(n+1),b(n+1);
    ll amax=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        chmax(amax,a[i]);
    }
    ll dp1[100001];ll ans=INF;
    for(ll i=0;i<=10000+amax;i++)dp1[i]=INF;
    dp1[0]=0;
    for(ll i=1;i<=n;i++){
        for(ll j=a[i];j<=h+10000;j++){
            ll ncnt=j/a[i];
            chmin(dp1[j],dp1[j-ncnt*a[i]]+b[i]*ncnt);
            chmin(dp1[j],dp1[j-a[i]]+b[i]);
        }
    }
    for(ll i=h;i<=h+amax;i++)
        chmin(ans,dp1[i]);
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String[] str = new String[n];
        for(int i = 0; i<n; i++){
            str[i] = sc.next();
        }

        int acCount = 0;
        int waCount = 0;
        int tleCount = 0;
        int reCount = 0;

        for(int j = 0; j<n; j++){
            if(str[j].equals("AC")){
                acCount++;
            }
            else if(str[j].equals("WA")){
                waCount++;
            }
            else if(str[j].equals("TLE")){
                tleCount++;
            }
            else if(str[j].equals("RE")){
                reCount++;
            }
        }
        System.out.printf("AC x %d\n", acCount);
        System.out.printf("WA x %d\n", waCount);
        System.out.printf("TLE x %d\n", tleCount);
        System.out.printf("RE x %d\n", reCount);



    }
}

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



int main() {
    long int n, a, b;
    cin >> n >> a >> b;
    
    long int ans = n / (a+b) * a;
    
    n %= a + b;
    if(n < a)
        cout << ans + n << endl;
    else
        cout << ans + a << endl;
    
    return 0;
}




Measured memory_bytes: 3596
#include<stdio.h>

bool binarySearch(int A[], int n, int key) {
    int mid;
    int left = 0, right = n;

    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid]) {
            return true;
        } else if (key < A[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    return false;
}

int main() {
    int A[100000];
    int n, q, key;
    int count = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        scanf("%d", &key);
        if (binarySearch(A, n, key))  count++;
    }
    
    printf("%d\n", count);
}

Measured memory_bytes: 3044
n=int(input())
A=list(map(int,input().split()))
choice=[0]*n
ans=[]
cnt=0
for i in reversed(range(n)):
    a=i+1
    c=0
    a+=i+1
    while a<=n:
        c+=choice[a-1]
        a+=i+1
    if c%2!=A[i]:
        choice[i]+=1
        ans.append(i+1)
        cnt+=1
if cnt==0:
    print(0)
else:
    print(cnt)
    ans.sort()
    print(*ans, sep=' ')

Measured memory_bytes: 14116
import itertools
n = int(input())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
ls=list(itertools.permutations(range(1,n+1)))
for i in range(len(ls)):
    a = map(str,ls[i])
    ls[i] = "".join(a)
a = "".join(map(str,s))
b = "".join(map(str,t))
print(abs(ls.index(b)-ls.index(a)))

Measured memory_bytes: 8180
fun main(arg: Array<String>) {
    val N = nextInt()
    val S = next()
    var (R, G, B) = listOf<Long>(0, 0, 0)
    S.forEach {
        when (it) {
            'R' -> R += 1
            'G' -> G += 1
            'B' -> B += 1
            else -> { }
        }
    }
    val total = R * G * B
    var exc = 0L
    for (n in 0 until N - 2) {
        for (m in n + 1 until N - 1) {
            val k = m + (m - n)
            if (k >= N) continue
            if (S[n] != S[m] && S[n] != S[k] && S[m] != S[k]) exc += 1
        }
    }
    val ans = total - exc
    println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfInt(vararg offset: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + offset[index % offset.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfLong(vararg offset: Long) = listOfString().map { java.lang.Long.parseLong(it) }.mapIndexed { index, long -> long + offset[index % offset.size] }
fun listOfDouble(offset: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + offset }
fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }


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

import copy
A1 = copy.copy(A)
A2 = copy.copy(A)
# バブルソート
flag = 1
while flag:
    flag = 0
    for j in range(N-1, 0, -1):
        if int(A1[j][1]) < int(A1[j-1][1]):
            # A1[j]とA1[j-1]を交換する
            A1[j], A1[j-1] = A1[j-1], A1[j]
            flag = 1    # このフラグは、逆の隣接要素があるかどうかのフラグ
                        # 一回操作したあとはもう一回全体を走査して、逆の隣接要素があるかを確かめる

# セレクションソート
for i in range(0, N):
    minj = i
    for j in range(i, N): # minjを探す
        if int(A2[j][1]) < int(A2[minj][1]): 
            minj = j
    A2[i], A2[minj] = A2[minj], A2[i]

print(*A1)
print('Stable')
print(*A2)

if A1 == A2:
    print('Stable')
else:
    print('Not stable')


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

int main () {
	unsigned start;
	unsigned result = 0;
	string s;
	cin >> s;
	
	for (unsigned i = 0; i < s.size();) {
		start = i;
		while (s[i] == 'J') {
			i++;
		}
		unsigned lj = i - start;
		
		start = i;
		while (s[i] == 'O') {
			i++;
		}
		unsigned lo = i - start;
		
		start = i;
		while (s[i] == 'I') {
			i++;
		}
		unsigned li = i - start;
		
		if (lo <= lj && lo <= li) {
			result = max(result, lo);
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 2048
def resolve():
    S = input()

    S_list = list(S)

    if len(S_list) % 2 == 0:
        s_len = int(len(S_list) / 2)
        if S == s_len * 'hi':
            print('Yes')
            return

    print('No')
    return

if __name__ == "__main__":
    resolve()

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

using namespace std;
#define int long long

const int N = 5e5 + 10;
const int MOD = 1e9 + 7;

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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if(sum % (n*(n + 1) / 2) != 0)  {
        cout << "NO";
        return 0;
    }

    int cnt = sum / (n * (n + 1) / 2);
    for(int i = 0; i < n; ++i) {
        b[i] = a[(i +1) % n] - a[i] - cnt;
    }

    bool flag = false;
    for(int i = 0; i < n; ++i)  if(b[i] > 0 || (-b[i]) % n != 0)    {
        flag = true;
        break;
    }
    if(flag) {
        cout << "NO";
    } else cout << "YES";
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=1e5+6;
ll a[N];
ll ans[N];
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	for(int i=0; i<n; i++) {
		cin>>a[i];
	}
	/*
	   a[0]=ans[0]+ans[1]
	   a[1]=ans[1]+ans[2]
	   a[2]=ans[2]+ans[3]
	   a[3]=ans[3]+ans[4]
	         ........
	           a[last]=ans[last]+ans[0]
	 */
	int an=0;
	for(int i=n-1; i>=0; i--) {
		if((i%2)==((n-1)%2)) {
			an+=a[i];
		}
		else{
			an-=a[i];
		}
	}

	//an+=a[n-1];
	ans[0]=an/2;


	for(int i=0; i<n-1; i++) {
		ans[i+1]=a[i]-ans[i];
	}

	for(int i=0; i<n; i++) {
		ans[i]=ans[i]*2;
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define test int t; cin>>t; while(t--)
vector<int>arr[200001];
int vis[200001],di[200001];
void bfs(int root)
{

    queue<int> que;


    que.push(root);


    di[root] = 0;


    vis[root] = 1;


    while (!que.empty()) {


       root = que.front();
       que.pop();
        for (int i = 0; i < arr[root].size(); i++) {

            int b = arr[root][i];

            if (!vis[b]) {


                que.push(b);


                di[b] = di[root] + 1;


                vis[b] = 1;
            }
        }
    }
}







int main()
{
    int n,m,a,b;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        arr[a].push_back(b);
        arr[b].push_back(a);

    }
    bfs(1);
    if(di[n]>2 || di[n]==0)
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    else cout<<"POSSIBLE"<<endl;

}


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

int main()
{
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
        ll k,x;
        cin>>k>>x;
        k = k*500;
        if(k>=x) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define endl "\n"

#define k first
#define v second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define ALL(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.k << ", " << p.v << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n, m;
    cin >> n >> m;
    unordered_map<int, int> dict;
    vi v(n + 1, 0);
    // prefil the left most digit to -1
    v[1] = -1;
    for (int i = 1; i <= m; i++) {
        int s, c;
        cin >> s >> c;
        if (v[s] != 0 && v[s] != -1 && v[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        v[s] = c;
    }
    // if left most is still -1 which means theres no requirements for it
    // then we prefil to lowest possible
    if (n > 1 && v[1] == -1) {
        v[1] = 1;
    }
    string s;
    for (auto &i : v) {
        s += to_string(i);
    }
    auto c = stoi(s);
    if (c == 0 && n == 1) {
        cout << 0 << endl;
        return 0;
    }
    while (c) {
        c /= 10;
        n--;
    }
    if (n) {
        cout << -1 << endl;
    } else {
        cout << stoi(s) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define MAX 10000000
typedef long long ll;

bool prime[MAX];

void calcPrime(){
	for( ll i = 2; i < MAX; i++ ) prime[i] = true;
	for( ll i = 2; i < MAX; i++ ){
		if( prime[i] ){
			for( ll j = i+i; j < MAX; j += i ) prime[j] = false;
		}
	}
}

int main(){
	calcPrime();
	int n;
	while( cin >> n, n ){
		int cnt = 0;
		for( int i = 2; i <= n/2 ; i++ ){
			if( prime[i] && prime[n-i] ) cnt++;
		}
		cout << cnt << endl;
	}
}

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

int main() {
  int n, m;
  string s;
  bool found = false;
  cin >> n >> m;
  vector<string> ns, ms;
  for (int i=0; i<n; i++) {
    cin >> s;
    ns.push_back(s);
  }
  for (int i=0; i<m; i++) {
    cin >> s;
    ms.push_back(s);
  }
  for (int i=0; i<=n-m; i++) {
    for (int j=0; j<=n-m; j++) {
      found = true;
      for (int k=0; k<m; k++) {
        if (ns[i+k].substr(j,m)!=ms[k]) {
          found = false;
          break;
        }
      }
      if (found) break;
    }
    if (found) break;
  }
  if (found) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string one;
      string two;
      
      cin >> one;
  	  cin >> two;
      
      int N = one.size();
      int count = 0;
      
      for(int i=0;i<N;i++){
        if (one[i] == two [i]){
          count++;
        }
      }
     
      cout << count << endl;
    }

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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  
  int i = min(A, B);
  int count = 0;
  while(count != K){
    if(A%i == 0 && B%i == 0){
      count++;
    }
    i--;
  }
  i++;
  
  cout << i << endl;
}

Measured memory_bytes: 256