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

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

        while(true){
            int h = scan.nextInt();
            int w = scan.nextInt();
            boolean b ;
            if(h == 0 && w == 0)break;
            for(int i = 0;i < h;i++){
                if(i % 2 == 0)b = true;
                else b = false;
                for(int j = 0;j < w;j++){
                    if(b){
                    System.out.print("#");
                    b = false;
                    }else{
                        System.out.print(".");
                        b = true;
                    }
                }
                System.out.println();
            }
            System.out.println();

        }

        scan.close();
    }

    

}


Measured memory_bytes: 34580
from collections import Counter


def pf(x):
  if x == 1:
    return []
  r = []
  while not x & 1:
    r += [2]
    x >>= 1
  i = 3
  m = int(x ** 0.5)
  while i < m + 1:
    while not x % i:
      r += [i]
      x //= i
    i += 2
  if x != 1:
    r += [x]
  return r


def main():
  n = int(input())
  
  pp = pf(n)
 
  cc = Counter(pp)
  
  res = 0
  
  for c, v in cc.items():
    i = 1
    while True:
      if i > v:
        break
      v -= i
      res += 1
      i += 1
      
  print(res)


if __name__ == "__main__":
  main()


Measured memory_bytes: 66432
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, K;
    cin >> n >> K;

    string S;
    cin >> S;

    bool has0 = false;
    rep(i, n) {
        if (S[i] == '0') {
            has0 = true;
            break;
        }
    }

    if(!has0) {
        put(S.size());
        return;
    }

    typedef pair<ll, ll> P;
    vector<P> C;
    C.push_back(P(0, 1));
    C.push_back(P(1, S[0] - '0'));
    repi(i, n) {
        if (S[i] != S[i - 1]) {
            C.push_back(P(1, S[i] - '0'));
        }
        else {
            C[C.size()-1].first++;
        }
    }
    C.push_back(P(0, 1));

    vector<ll> Sc(C.size());
    Sc[0] = C[0].first;
    repi(i, Sc.size()) {
        Sc[i] = Sc[i-1] + C[i].first;
    }

    ll res = 0;
    rep(i, C.size()) {
        if (C[i].second == 0) {
            // i-1 ~ (i + 2K)
            ll i1 = max(0LL, i - 2);
            ll i2 = min((ll)C.size() - 1, i + 2 * K - 1);
            ll num = Sc[i2] - Sc[i1]; 
            res = max(res, num);
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 5772
def compute(a,b):
	# print(a,b)
	n = len(a)
	cnt = 0
	for i in range(n):
		if(a[i] == b[i]):
			cnt+=1
	return cnt

s = input()
t = input()
# print(s,t)


sl = len(s)
tl = len(t)

ans = tl

tmp1 = s[0:tl]
tmp2 = t 
# print(compute(tmp1,tmp2))
ans = min(tl - compute(tmp1,tmp2), ans)
# ans = min(tl - compute(tmp1[::-1], tmp2[::-1]), ans)

for i in range(sl-tl):
	tmp1 = s[i:i+tl]
	tmp2 = t
	ans = min(tl - compute(tmp1,tmp2), ans)
	# ans = min(tl - compute(tmp1[::-1], tmp2[::-1]), ans)

print(ans)


Measured memory_bytes: 66584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}









int main() {
  int x,y;
  cin >> x >> y;
  bool ok = true;
  if (y >= 2*x&&y <= 4*x&&y%2==0) cout <<"Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    vector<char> s;
    char in;
    for(int i=0; i<3; i++){
        cin >> in;
        s.push_back(in);
    }
    sort(s.begin(), s.end());
    if(s[0]=='a' && s[1]=='b' && s[2]=='c'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//url:https://atcoder.jp/contests/dp/tasks/dp_d
//problem name:D - Knapsack 1

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
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;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int N;
ll W;
vecl weight(110),value(110);
vector<vector<ll>> dp(110,vector<ll>(100010));

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 87296
#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=1e6+9,mod=1e9+7;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
LL n,m;
LL fac[maxn],fav[maxn];
LL mul(LL x,LL y){ return 1ll*x*y%mod; }
LL C(LL N,LL M){
	return 1ll*fac[N]*fav[N-M]%mod*fav[M]%mod;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL Pow(LL base,LL b){
	LL ret(1);
	while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
int main(){
    n=Read(); m=Read();
    fac[0]=1; for(LL i=1;i<=m;++i) fac[i]=mul(fac[i-1],i);
    fav[m]=Pow(fac[m],mod-2);
    for(LL i=m;i>=1;--i) fav[i-1]=mul(fav[i],i);
    LL ans(1ll*C(m,n)*C(m,n)%mod*fac[n]%mod*fac[n]%mod);
    for(LL i=1;i<=n;++i){
    	
    	LL tmp=1ll*C(n,i)*C(m,i)%mod*fac[i]%mod*C(m-i,n-i)%mod*fac[n-i]%mod*C(m-i,n-i)%mod*fac[n-i]%mod;
    	if(i&1) ans=dec(ans,tmp);
    	else ans=add(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

 private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1);

 private String inputData = null;

 private String[] data;

 private int left;

 private int right;

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

 public void start() {
  try {
   this.inputData = reader.readLine();
  } catch (IOException e) {
   e.printStackTrace();
  }

  this.data = this.inputData.split(" ");

  this.left = Integer.parseInt(this.data[0]);
  this.right = Integer.parseInt(this.data[1]);

  if (left > right) {
   System.out.println("a > b");
  } else if (left < right) {
   System.out.println("a < b");
  } else {
   System.out.println("a == b");
  }

 }

}

Measured memory_bytes: 17028
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int N;
	long long a;
	scanf("%d", &N);
	for(int i=1; i<=N; i++)
	{
		a = i * i;
		if(a > N)
		{
			printf("%d\n", (i - 1) * (i - 1));
			break;
		}
		else if(a == N)
		{
			printf("%d\n", N);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL k,a[55]={};
	cin>>k;
	int n=50;
	if(k<50){
		FOR(i,0,(k%n))a[i]=50;
	}else{
		FOR(i,0,n)a[i]+=50+(k/n-1);
		int t=k%n;
		FOR(ii,0,t){
			a[ii]+=n;
			FOR(jj,0,n){
				if(ii!=jj)a[jj]--;
			}
		}
	}
	cout<<n<<endl;
	FOR(i,0,n){
		if(i!=n-1){
			cout<<a[i]<<" ";
		}else{
			cout<<a[i]<<endl;
		}
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct node{
	vector<int> children;
	int mindepth=0;
};
node A[100005];
int x;
void dfs(int x){
	if (A[x].children.empty()) return;
	vector<int> tmpv;
	for (auto y: A[x].children){
		dfs(y);
		tmpv.push_back(A[y].mindepth);
	}
	sort (tmpv.begin(), tmpv.end());
	int cnt=1, maxi=0;
	for (int i=tmpv.size()-1; i>=0; i--,cnt++){
		maxi=max(maxi, cnt+tmpv[i]);
	}
	A[x].mindepth=maxi;
}
int n;
int main(){
	cin>>n;
	for (int i=1; i<n; i++){
		cin>>x;
		A[x-1].children.push_back(i);
	}
	dfs(0);
	cout<<A[0].mindepth<<endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL K, N;
void decr(int n, deque<int>& xs){
  if(xs.empty()) return;
  
  if(xs.back() > 1){
	--xs.back();
	while(SZ(xs) < n)
	  xs.PB(K);
  }
  else
	xs.pop_back();
}

void solve(LL n, deque<int>& xs){
  if(n == 1){
	xs.PB(K/2);
	return;
  }
  
  if(n%2 == 0){
	solve(n-1, xs);
	xs.push_front(K/2+1);
  }
  else{
	solve(n-1, xs);
	decr(n, xs);
	xs.push_front(K/2+1);
  }
}

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

  cin >> K >> N;
  if(K % 2 == 0){
	cout << K/2;
	REP(i,N-1) cout << " " << K;
	cout << endl;
	return 0;
  }

  if(K == 1){
	REP(i,(N+1)/2) cout << (i?" ":"") << 1;
	cout << endl;
	return 0;
  }
  if(N == 1){
	cout << K/2+1 << endl;
	return 0;
  }

  deque<int> ans;
  ans.PB(K/2+1);
  solve(N-1, ans);
  REP(i,SZ(ans))
	cout << (i?" ":"") << ans[i];
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 17664
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve(){
    ll n;cin>>n;
    ll a[n+1];
    bool zero=false;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]==0)zero=true;
    }
    if(zero)
    {
        cout<<0<<endl;
        return;
    }
    ll res=1;
    for(ll i=1;i<=n;i++)
    {
        ll temp=res*a[i];
//        cout<<"temp= "<<temp<<endl;
        if(temp/res!=a[i] or temp/a[i]!=res or temp>1000000000000000000ll or temp<=0)
        {
            cout<<-1<<endl;
            return;
        }
        res=temp;
    }
    if(res>1000000000000000000ll or res<=0)
    cout<<-1<<endl;
    else
    cout<<res<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

//    cin.tie(NULL);cout.tie(NULL);

    solve();
    return 0;
}


Measured memory_bytes: 4432
import sys
from heapq import *

input = sys.stdin.readline

N, M = list(map(int,input().split()))

error = 10000000000

q = []
minc = [error]*(2**N)
for i in range(M):
	a, b = list(map(int,input().split()))
	c = list(map(int,input().split()))
	c10 = 0
	for ci in c:
		c10 += 2**(ci-1)

	minc[c10] = min(minc[c10],a)

while True:
	tmin = min(minc)
	if tmin==minc[-1]: break
	ti = minc.index(tmin)
	for i, mini in enumerate(minc):
		if mini!=error:
			ni = ti | i
			minc[ni] = min(minc[ni],tmin+mini)
	minc[ti] = error

ans = minc[-1]
if ans==error: ans = -1
print(ans)

Measured memory_bytes: 43356
#include<stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if(w>0 && h>0 && x>0 && y>0){

            if(x<w && y<h){
                if(w-x>=r && h-y>=r)
                    printf("Yes\n");
                else
                    printf("No\n");
    }
        else
            printf("No\n");
    }
    else if(w<0 && h>0 && x<0 && y>0){

             if(x<w && y<h){
                if(w-x>=r && h-y>=r)
                    printf("Yes\n");
                else
                    printf("No\n");
    }
     else
            printf("No\n");
    }

    else if(w<0 && h<0 && x<0 && y<0){
                     if(x<w && y<h){
                if(w-x>=r && h-y>=r)
                    printf("Yes\n");
                else
                    printf("No\n");
    }
     else
            printf("No\n");
    }
     else if(w>0 && h<0 && x>0 && y<0){
                     if(x<w && y<h){
                if(w-x>=r && h-y>=r)
                    printf("Yes\n");
                else
                    printf("No\n");
    }
     else
            printf("No\n");
     }

       else
          printf("No\n");

    return 0;



}



Measured memory_bytes: 2692
fun main(args: Array<String>) {
    val numbers = readLine()
        ?.split(" ")
        ?.map { it.toInt() }
        ?: return
    val totalCount = numbers[0]
    val expectedAmount = numbers[1]

    for (i in 0..totalCount) {
        for (j in 0..(totalCount - i)) {
            val k = totalCount - (i + j)
            if (k < 0) {
                continue
            }
            val amount = 10000 * i + 5000 * j + 1000 * k
            if (amount == expectedAmount) {
                println("$i $j $k")
                return
            }
        }
    }
    println("-1 -1 -1")
}

Measured memory_bytes: 38004
table = Array.new(100){ Array.new(100){0} }
table[0][1] = table[1][0] = 1
readlines.each do |l|
  i,j = l.split.map(&:to_i)
  if i==0 && j==0
    if table.each_with_index.all?{|c,i| c.inject(:+).even?  }
      puts "OK"
    else
      puts "NG"
    end
    table = Array.new(100){ Array.new(100){0} }
    table[0][1] = table[1][0] = 1
  else
    table[i-1][j-1] += 1
    table[j-1][i-1] += 1
  end
end

Measured memory_bytes: 6500
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int w = Integer.parseInt(str[0]);
    int a = Integer.parseInt(str[1]);
    int b = Integer.parseInt(str[2]);
    
    if(b+w<a)
      System.out.println(a-(b+w));
    else if(a+w<b)
      System.out.println(b-(a+w));
    else
      System.out.println(0);
  }
}

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

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

  vector<int> dp(n);
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for (int i = 2; i < n; i++)
  {
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;  
}

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

using namespace std;
#define int long long
#define double long double
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
#define FI first
#define SE second
typedef pair<int, int> pii;
#define l_b lower_bound
#define u_b upper_bound

int N, M;
int K;

signed main() {
    cin >> N >> M >> K;
    rep(i, N + 1) {
        rep(j, M + 1) {
            if (i * M + j * N - i * j * 2 == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-12 12:15:30

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
	int a, b;
	cin >> a >> b;
	cout << max(a+b, max(2*a-1, 2*b-1))  << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

	ll N;
	cin >> N;

	vector<ll> a(N);
	rep(i,N) cin >> a[i];

	vector<ll> ans;

	ans.PB(a[0]);

	REP(i,N-1){
		auto itr = lower_bound(ALL(ans), a[i]);
        //cout << *itr << endl;
		if(a[i] <= ans[0]){
			ans.insert(ans.begin(),a[i]);
          	//cout << a[i] << endl;
		}else{
           // cout << distance(ans.begin(),itr) << endl;
			ans[(int)(distance(ans.begin(),itr))-1] = a[i];
		}
      
      	
	}
  
  //for(ll j:ans)cout << j << ' ';
      	//cout << endl;


	cout << sz(ans) << endl;
		 	

}


Measured memory_bytes: 2168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <cassert>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
int n, m, a, b;
int num[maxn];

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d %d", &n, &m);
    while (m--) {
        scanf("%d %d", &a, &b); ++num[a]; ++num[b];
    }
    bool flag = true;
    for (int i = 1; i <= n; ++i) { if (num[i] % 2) { flag = false; break; } }
    if (flag) { printf("YES\n"); } else { printf("NO\n"); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;

    int p[1000];
    rep(i, N) cin >> p[i];

    sort(p, p+N);
    int sum=0;
    rep(i, K) sum+=p[i];

    cout << sum << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static int minDistance(String word1, String word2) {
        int[][] dp;
        dp = new int[word1.length() + 1][word2.length() + 1];
        for (int i = 0; i <= word1.length(); i++) {
            dp[i] = new int[word2.length() + 1];
        }

        for (int w1Idx = word1.length(); w1Idx >= 0; w1Idx--) {
            for (int w2Idx = word2.length(); w2Idx >= 0; w2Idx--) {
                if (w1Idx == word1.length() || w2Idx == word2.length()) {
                    dp[w1Idx][w2Idx] = Math.max(word1.length() - w1Idx, word2.length() - w2Idx);
                    continue;
                }
                int replaceCost = dp[w1Idx + 1][w2Idx + 1]
                        + (word1.charAt(w1Idx) == word2.charAt(w2Idx) ? 0 : 1);
                int insert1Cost = dp[w1Idx + 1][w2Idx] + 1;
                int insert2Cost = dp[w1Idx][w2Idx + 1] + 1;
                dp[w1Idx][w2Idx] = Math.min(insert1Cost, insert2Cost);
                dp[w1Idx][w2Idx] = Math.min(dp[w1Idx][w2Idx], replaceCost);
            }
        }
        return dp[0][0];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String w1 = in.nextLine();
        String w2 = in.nextLine();
        System.out.println(minDistance(w1, w2));
    }
}

Measured memory_bytes: 35068
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;
 
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;
 
 
signed main()
{
    int n, m;
    cin >> n >> m;
    std::vector<int> s(n);
    std::vector<int> t(m);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    int out = 1;
 
    std::vector<int> sumarray(n, 0);
    for (int i = 0; i < m; i++) {
        int temp = 0;
        for (int j = 0; j < n; j++) {
            if (j == 0) {
                temp += sumarray[j];
                if (t[i] == s[j]) {
                    sumarray[j] += 1;
                }
            } else {
                if (t[i] == s[j]) {
                    int prev = temp + sumarray[j];
                    sumarray[j] += (temp + 1) % MOD;
                    temp = prev;
                } else {
                    temp += sumarray[j];
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        out += sumarray[i];
        out %= MOD;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MN 210000
using namespace std;
 
ll n,k,l,r,ne[MN],w[26];
char s[MN];
void work(ll r){
	if (r<=n) for (ll i=0;i<r;i++) w[s[i]-'a']++;else{
		ll _s=0,_t=1,S=1,T=0;
		for (;S*n+T*k<r;) S+=_s,T+=_t,_s=S-_s,_t=T-_t;
		work(r-_s*n-_t*k);
		for (ll i=0;i<k;i++) w[s[i]-'a']+=_t;
		for (ll i=0;i<n;i++) w[s[i]-'a']+=_s;
	}
}
int main(){
	scanf("%s%lld%lld",s,&l,&r);
	n=strlen(s)/2;ne[0]=-1;
	for (ll i=1;i<n;i++){
		ll j=ne[i-1];
		while (j!=-1&&s[i]!=s[j+1]) j=ne[j];
		ne[i]=j+(s[i]==s[j+1]);
	}
	k=n-ne[n-1]-1;
	work(l-1);
	for (ll i=0;i<26;i++) w[i]=-w[i];
	work(r);
	for (ll i=0;i<26;i++) printf("%lld ",w[i]);
}

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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

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

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



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


    int D[N];
    rep(i,N){
        cin >> D[i];
    }

    int ans = 0;
    rep(i,N){
        for(int j = i+1 ; j<N ; j++){
            ans += D[i]*D[j];
        }
    }

    cout <<ans << endl;



}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
    double a, b;
    cin >> a >> b;
    ll A = (ll)a, B = (ll)b;
    cout << fixed << setprecision(10);
    cout << A/B << ' ' << A%B << ' ' << a/b << endl;
}


Measured memory_bytes: 3280
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as IS
main=putStrLn.solve.map(map(fst.fromJust.B.readInt).B.words).B.lines=<<B.getContents
solve([n,m]:ab)=if any(flip IS.member e)s then"POSSIBLE"else"IMPOSSIBLE"where
  (s,e)=foldr (f n)([],IS.empty)ab
f n[a,b](s,e)
  |a==1=(b:s,e)
  |b==n=(s,IS.insert a e)
  |otherwise=(s,e)

Measured memory_bytes: 63868
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n,m,a=0;
    cin >> n;
    vector<string>s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    vector<string>t(m);
    for(int i=0;i<m;i++){
        cin >> t[i];
    }
    for(int i=0;i<n;i++){
        int h=count(s.begin(),s.end(),s[i])-count(t.begin(),t.end(),s[i]);
        a=max(h,a);
    }
    cout << a;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
    string st="";
    char s[100];
    cin>>s;
    for(int i=0;s[i];i++){
        if(isalpha(s[i])) st+=s[i];
        else st+=" ";
    }
    cout<<st<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    
    String s;
    int i, ans, sum, x, y;

    void run(){
	while(sc.hasNext()){
	    s = sc.next();
	    ans = 0;
	    sum = 0;
	    x = change(s.substring(0, 1));
	    if(s.length()>1){
		for(i=1; i<s.length(); i++){
		    y = change(s.substring(i, i+1));
		    //System.out.println(x+" "+y);
		    if(x>y){
			ans += (x+sum);
			sum = 0;
		    }
		    else if(x<y){
			ans -= (x+sum);
			sum = 0;
		    }
		    else if(x==y){
			sum += x;
		    }
		    x = y;
		    //System.out.println("*"+ans+" "+sum);
		}
		ans += (y+sum);
	    }
	    else ans = x;
	    System.out.println(ans);
	}
    }

    int change(String a){
	if(a.equals("I"))
	    return 1;
	else if(a.equals("V"))
	    return 5;
	else if(a.equals("X"))
	    return 10;
	else if(a.equals("L"))
	    return 50;
	else if(a.equals("C"))
	    return 100;	
	else if(a.equals("D"))
	    return 500;
	else if(a.equals("M"))
	    return 1000;
	return 0;  // エラー扱い
    }
}

Measured memory_bytes: 15316
X = int(input())
L = []
ANS = []
for i in range(1,33) :
    for j in range(2,11) :
        if i**j <= 1192 :
            l = i**j
            L.append(l)
L = list(set(L))
L = sorted(L)
for j in range(len(L)) :
    if L[j] <= X < L[j+1] :
        ans = L[j]
        ANS.append(ans)
print(max(ANS))




Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main() {
	char str[2048];
	int len;
	char words[1024][1024];
	int words_size = 0;
	char word_list[1024][1024];
	int word_list_size = 0;
	int i, j;

	memset(words, '\0', sizeof(words));
	memset(word_list, '\0', sizeof(word_list));
	memset(str, '\0', sizeof(str));

	fgets(str, 2048, stdin);
	len = strlen(str);

	for(i = 0; i < len;) {
		if(str[i] == '.' || str[i] == ' ' || str[i] == ',' || str[i] == '\n') {
			i++;
			continue;
		}

		else {
			j = 0;
			while(!(str[i + j] == '.' || str[i + j] == ' ' || str[i + j] == ',' || str[i + j] == '\n') && str[i + j]) {
				words[words_size][j] = str[i + j];
				j++;
			}
			words_size++;
			i += j;
		}
	}

	for(i = 0; i < words_size; i++) {
		int flag = 1;
		for(j = 0; (j < word_list_size) && flag; j++) {
			if(!strcmp(word_list[j], words[i]))
				flag = 0;
		}
		// /*

		flag = 0;
		for(j = 0; j < strlen(words[i]) && !flag; j++) {
			if(!('0' <= words[i][j] && words[i][j] <= '9'))
				flag = 1;
		}
		// */

		if(flag && (2 < strlen(words[i])) && (strlen(words[i]) < 7)) {
			strcpy(word_list[word_list_size], words[i]);
			word_list_size++;
		}
	}

	for(i = 0; i < word_list_size; i++) {
		printf("%s", word_list[i]);
		if(i < word_list_size - 1)
			putchar(' ');
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 2592
class ExponentiationTable
  
  def initialize(x, mod = nil )
    @x = x
    @mod = mod
    @table = [x]
  end
  
  def pow(n)
    res = 1
    i = 0
    while n > 0
      if (n & 1) != 0
        res *= @table[i]
        res %= @mod if @mod
      end
      i += 1
      @table[i] ||= ( @table[i-1] ** 2) 
      @table[i] %= @mod if @mod
      n >>= 1
    end
    # p @table
    res
  end
end

mod = 1_000_000_007

gets

h = Hash.new{|h, k| h[k] = [0, 0] }
genten_iwashi = 0

$<.read.split.map(&:to_i).each_slice(2) do |(a,b)|

  if 0 == a | b
    genten_iwashi += 1
  else
    f = a.zero? || (a > 0 && b > 0) || (a < 0 && b < 0)
    r = ( f ? Rational(a,b) : -Rational(b,a) )
    h[r][ f ? 0 : 1 ] += 1
  end
end

ans = 1
heiwa_iwashi = 0
two = ExponentiationTable.new(2, mod)

h.values.each do |(s, t)|
  # if s == 0 || t == 0
    # heiwa_iwashi += (s + t)
  # else
    ans *= ( two.pow(s) + two.pow(t) - 1)
    ans %= mod
  # end
end
# ans = ( ans * two.pow(heiwa_iwashi) ) % mod
ans = ( ans - 1 + genten_iwashi ) % mod

puts ans

Measured memory_bytes: 72592
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		LinkedList<Integer> S = new LinkedList<Integer>();
		String x;
		while(sc.hasNext()){
			x=sc.next();
			if(x.charAt(0)=='+'){
				int a=(int) S.pop();
				int b=(int) S.pop();
				S.push(a+b);
			}
			if(x.charAt(0)=='-'){
				int a=(int) S.pop();
				int b=(int) S.pop();
				S.push(b-a);
			}
			if(x.charAt(0)=='*'){
				int a=(int) S.pop();
				int b=(int) S.pop();
				S.push(a*b);
			}else if('0'<=x.charAt(0) && x.charAt(0)<='9'){
				S.push(Integer.parseInt(x));
			}
		}
		System.out.println(S.pop());
	}

}

Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 1;
const ll mo = 998244353;


int main()
{
ll n;
string  s ;
cin >> n >> s ;
ll r=0,g=0,b=0;

rep(i,3*n){
  if(s[i]=='B'){
    if(r>0&&g>0){ans*=min(r,g);ans%=mo;r--;g--;}
    else if(r>0){if(r-b>0)ans*=r-b;ans%=mo;b++;}
    else if(g>0){if(g-b>0)ans*=g-b;ans%=mo;b++;}
    else b++;
  }
  if(s[i]=='R'){
    if(b>0&&g>0){ans*=min(b,g);ans%=mo;b--;g--;}
    else if(b>0){if(b-r>0)ans*=b-r;ans%=mo;r++;}
    else if(g>0){if(g-r>0)ans*=g-r;ans%=mo;r++;}
    else r++;
  }
  if(s[i]=='G'){
    if(r>0&&b>0){ans*=min(r,b);ans%=mo;r--;b--;}
    else if(r>0){if(r-g>0)ans*=r-g;ans%=mo;g++;}
    else if(b>0){if(b-g>0)ans*=b-g;ans%=mo;g++;}
    else g++;
  }
}
rep(i,n){
  ans*=i+1;
  ans%=mo;
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 900
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;
using namespace std;

void Main()
{
   int N = 0;
   int i;
   bitset<100000> S;
   string Str;
   cin >> Str;
   for (const auto s : Str)
   {
      if (s == '1')
         S.set(N);
      N++;
   }
   bitset<100000> odd;
   bitset<100000> even;
   for (i = 0; i < 50000; i++)
   {
      odd.flip(i * 2);
      even.flip(i * 2 + 1);
   }
   odd &= S;
   even &= S;
   int od = (N + 1) / 2 - odd.count(), ev = N / 2 - even.count();
   if (od <= ev)
   {
      cout << (od + even.count()) << endl;
   }
   else
   {
      cout << (ev + odd.count()) << endl;
   }
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff;   //譌?剞螟ァ
int N;
map<string, int> m;
bool visit[100000];
char s[10000000];
vector<int> v[100000];
/*
int dfs(int u)
{
	visit[u]=1;
	int ans = 0;
	for(int i=0;i<edge[u].size();i++)
	{
		int v=edge[u][i];
		if(visit[v]==1)
			continue;
		visit[v]=1;
		if(d[v]==1)
			ans+=dfs(v);
		else
			ans+=1;
	}
	return ans;
}
*/
int cnt = 0;

void DFS(int O)
{
    visit[O] = true;

    if( v[O].size() == 0 ) cnt++;
    else
    {
        for(int vi = 0, vn = v[O].size(); vi < vn; vi++)
        {
            if( !visit[v[O][vi] ] ) DFS(v[O][vi] );
        }
    }
}

int main()
{
    while( scanf("%d", &N) )
    {
        if( N == 0 ) break;
        m.clear();

        int clk = 1; cnt = 0;

        fill(visit, visit+100000, false);
        for(int vi = 0; vi < 100000; vi++) v[vi].clear();

        for(int Ni = 0; Ni < N; Ni++)
        {
            scanf("%s", s);
            int sn = strlen(s);

            int gp; string p = "";

            for(int si = 0; si < sn; si++)
            {
                if( s[si] == ':' )
                {
                    if( m[p] == 0 ) m[p] = clk++;
                    gp = m[p]; p = "";
                    clk++;
                }
                else if( s[si] == ',' || s[si] == '.' )
                {
                    if( m[p] == 0 ) m[p] = clk++;
                    v[gp].push_back(m[p] ); p = "";
                }
                else p += s[si];
            }
        }

        DFS(1);
        printf("%d\n", cnt);
    }
}

Measured memory_bytes: 5556
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

flg = False
#縦
for i in range(3):
    if a[0][i] in b:
        if a[1][i] in b:
            if a[2][i] in b:
                flg = True
                break

for i in range(3):
    if a[i][0] in b:
        if a[i][1] in b:
            if a[i][2] in b:
                flg = True
                break

#斜め
if a[0][0] in b:
    if a[1][1] in b:
        if a[2][2] in b:
            flg = True

if a[0][2] in b:
    if a[1][1] in b:
        if a[2][0] in b:
            flg = True

if flg:
    print('Yes')      
else:
    print('No')

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

int main()
{
  int N,i,r,d;
  cin >> N;
  for(i=1;i<=9;i++){
    r = N%i;
    if(r==0){
      d = N/i;
      if(d>=1 and d<=9){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
from collections import defaultdict
dic1 = defaultdict(int)
for i in range(3):
    n,m = map(int,readline().split())
    dic1[n] += 1
    dic1[m] += 1

lst1 = list(dic1.values())
lst1.sort()

if lst1 == [1,1,2,2]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 65148
import java.util.Arrays;
import java.util.Scanner;

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

		int s = sc.nextInt();
		int[] t = new int[s];
		for (int i = 0; i < s; i++) t[i] = sc.nextInt();

		Arrays.sort(t);
		int nowNum = 1;
		int count = 0;
		int ansCount = 0;
		for (int i = 0; i < t.length; i++) {
			if (nowNum != t[i]) {
				if (nowNum > count) ansCount += count;
				nowNum = t[i];
				count = 0;

			}
			count++;
			if (count > t[i]) {
				ansCount++;
			}
		}

		if (nowNum > count) ansCount += count;

		System.out.println(ansCount);
	}

}

Measured memory_bytes: 50420
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=1100;
const int INF=10000000;
typedef pair<int,int> P;
char s[maxn][maxn];
int d[maxn][maxn];
int H,W,n;
P point[maxn];
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int bfs(int sx,int sy,int gx,int gy)
{
    queue<P>que;
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
        d[i][j]=-1;
    que.push(P(sx,sy));
    d[sx][sy]=0;
    while(que.size()){
        P p=que.front(); que.pop();
        if(p.first==gx&&p.second==gy) break;
        for(int i=0;i<4;i++)
        {
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(nx>=0&&nx<H&&ny>=0&&ny<W&&s[nx][ny]!='X'&&d[nx][ny]==-1){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];
}
int main()
{
    while(cin>>H>>W>>n)
    {
        for(int i=0;i<H;i++)
            for(int j=0;j<W;j++)
            cin>>s[i][j];
        int sx,sy,gx,gy;
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                if(s[i][j]=='S')
                {
                    sx=i; sy=j; break;
                }
            }
        }
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                if(s[i][j]>='1'&&s[i][j]<='9')
                {
                    int t=s[i][j]-'0';
                    point[t].first=i;
                    point[t].second=j;
                }
            }
        }
        int cnt=0;
        for(int i=1;i<=n;i++){
            gx=point[i].first;
            gy=point[i].second;
            cnt+=bfs(sx,sy,gx,gy);
            sx=gx;
            sy=gy;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 8372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second

int main()
{
    ll c1=0,c2=0,c3=0,c4=0;
    ll n;cin >> n;
    for(int i=0;i<n;i++)
    {
        string x;cin >> x;
        if(x=="AC") c1++;
        if(x=="WA") c2++;
        if(x=="TLE") c3++;
        if(x=="RE") c4++;
    }
    cout << "AC x" << " " << c1 << endl;
    cout << "WA x" << " " << c2 << endl;
    cout << "TLE x" << " " << c3 << endl;
    cout << "RE x" << " " << c4 << endl;
    
}

Measured memory_bytes: 3632
//om namah shivaaay//
#include <bits/stdc++.h>
#define input int t;cin>>t;while(t--)
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout.precision(10)
 #define ll long long
 #define vi  vector<int>vec
 #define pb push_back
 #define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
 #define f(i, a, b) for (int i = 0; i < (b); i++)
 #define w(t) int t;cin>>t;while(t --)
#define fr(i, a, b) for (int i = (a); i >= (b); i--)
 const int N=1e5 +5;
 using namespace std;
 int main()
 {
    Om_namah_Shivaay;
    ll d;
     int count=0;
    ll t;
    cin>>t>>d;
    while(t--)
  {
	  ll a,b;
	  cin>>a>>b; 
	 
	  if(a*a+b*b<=d*d)
	  count++;
	   
 }
cout<<count<<endl;
 }


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a!=b && b!=c && c!=a){printf("3");}
	else if(a==b && b==c){printf("1");}
	else printf("2");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2e3+10;
int cnt[MAXN];
int main(){
    int n,x,y;
    while(~scanf("%d %d %d",&n,&x,&y)){
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(i<=x&&j>=y){
                    cnt[j-i-(y-x-1)]++;
                }else if(i>=x&&i<=y&&j>=x&&j<=y){
                    cnt[min(j-i,i-x+y-j+1)]++;
                }else if(i>=x&&i<=y&&j>y){
                    cnt[min(j-i,i-x+j-y+1)]++;
                }else if(i<x&&j>=x&&j<=y){
                    cnt[min(j-i,x-i+y-j+1)]++;
                }else{
                    cnt[j-i]++;
                }
            }
        }
        for(int i=1;i<=n-1;i++){
            printf("%d\n",cnt[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

		int max = 0;
		int cnt = 0;
		for (int i = 0; i <= 1; i++) {
			if (A >= B) {
				max = A;
				A -= 1;
			} else {
				max = B;
				B -= 1;
			}
			cnt += max;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 35728
#include <stdio.h>

int main(void) {

    int K;

    int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    scanf("%d", &K);

    printf("%d\n", A[K-1]);

    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int a[100001],L;
int n,p,ok;
int main(){
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n;i++){
		if(a[i]+a[i+1]>=L){
			p=i,ok=1;
		}
	}
	if(!ok) puts("Impossible");
	else{
		puts("Possible");
		for(int i=1;i<p;i++) printf("%d\n",i);
		for(int i=n-1;i>p;i--) printf("%d\n",i);
		printf("%d\n",p);
	}
	return 0;
}

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

int main()
{
	string a;
	cin>>a;
	int cnt = 0;
	int len = a.size();
	for(int i = 0; i < len; ++i){
		if(a[i] == 'C' && cnt == 0) cnt++;
		if(a[i] == 'F' && cnt == 1) cnt++;
	}
	if( cnt == 2) puts("Yes\n");
	else puts("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int M = 1000 + 10;
int n,r[M];
int main()
{
    int a,b;
    bool vis = false;
    cin >> a >> b;
    for(int i=1;i<=3;i++)
    {
        if((i*a*b)%2 == 1)
        {
            cout << "Yes" ;
            vis = true;
            break;
        }
    }
    if(vis == false) cout << "No" ;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   int n=0,x=0,i=0,sum=0,rem=0,t=0;
    cin>>n>>x; 
    int m[n]={0};
    for(i=0;i<n;i++)
	{
		cin>>m[i];
		sum=sum+m[i];
	}
	sort(m,m+n);
	rem=x-sum;
	if(rem<m[0])
	cout<<n;
	else
	{
		t=n+(rem/m[0]);
		cout<<t;
	}
	
	
	return 0;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
    int x , a , b ;
    std::cin >> x >> a >> b;
    int w = abs(x - a), y = abs(x - b);
    if (w < y)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "B" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,y = map(int,input().split())
ok = False
ans = []
for tenk in range(0,2001):
    if ok :
        break
    for fivek in range(0,2001):
        if n-tenk-fivek >= 0 and 10000*tenk + 5000*fivek + 1000*(n-tenk-fivek) == y:
            ans.append(tenk)
            ans.append(fivek)
            ans.append(n-tenk-fivek)
            ok = True
            break
if ok:
    print(ans[0],ans[1],ans[2])
else :
    print('-1 -1 -1')        

Measured memory_bytes: 3064