akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadInts();
            var b = ReadInts();
            var c = ReadInts();
            var a_time1 = DateTime.Parse($"{a[0]}:{a[1]}:{a[2]}");
            var a_time2 = DateTime.Parse($"{a[3]}:{a[4]}:{a[5]}");
            var a_time = a_time2 - a_time1;
            WriteLine(a_time.Hours+" "+a_time.Minutes+" "+a_time.Seconds);

            var b_time1 = DateTime.Parse($"{b[0]}:{b[1]}:{b[2]}");
            var b_time2 = DateTime.Parse($"{b[3]}:{b[4]}:{b[5]}");
            var b_time = b_time2 - b_time1;
            WriteLine(b_time.Hours + " " + b_time.Minutes + " " + b_time.Seconds);

            var c_time1 = DateTime.Parse($"{c[0]}:{c[1]}:{c[2]}");
            var c_time2 = DateTime.Parse($"{c[3]}:{c[4]}:{c[5]}");
            var c_time = c_time2 - c_time1;
            WriteLine(c_time.Hours + " " + c_time.Minutes + " " + c_time.Seconds);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 19688
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_HUMAN_MAX		100000									// 最大人数
#define D_VTX_MAX		200000									// 最大頂点数

// 内部変数
static FILE *szpFpI;											// 入力
static int siHCnt;												// 人数
static int siLCnt;												// 言語数
static int si1VNo[D_VTX_MAX];									// 代表頂点[頂点]

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 代表頂点 - 取得
int
fGetVNo(
	int piVNo					// <I> 頂点 0～
)
{
	// 自分が代表かチェック
	if (si1VNo[piVNo] == piVNo) {
		return piVNo;
	}

	// 下位へ
	si1VNo[piVNo] = fGetVNo(si1VNo[piVNo]);

	return si1VNo[piVNo];
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j, liRet;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 人数・言語数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siHCnt, &siLCnt);

	// 代表頂点 - 初期化
	for (i = 0; i < siHCnt + siLCnt; i++) {
		si1VNo[i] = i;
	}

	// 言語 - 取得
	int liVNo1, liVNo2;
	for (i = 0; i < siHCnt; i++) {

		// 言語数 - 取得
		int liCnt;
		fscanf(szpFpI, "%d", &liCnt);

		// 言語 - 取得
		for (j = 0; j < liCnt; j++) {
			int liLNo;
			fscanf(szpFpI, "%d", &liLNo);
			liLNo += siHCnt - 1;

			// 代表頂点 - 取得
			liVNo1 = fGetVNo(i);
			liVNo2 = fGetVNo(liLNo);

			// 代表頂点 - 統一
			if (liVNo1 != liVNo2) {
				si1VNo[liVNo2] = liVNo1;
			}
		}
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	}

	// 代表頂点 - 一致チェック
	liRet = 0;
	liVNo1 = fGetVNo(0);
	for (i = 1; i < siHCnt; i++) {
		liVNo2 = fGetVNo(i);
		if (liVNo1 != liVNo2) {			// 不一致
			liRet = -1;
			break;
		}
	}

	// 結果 - セット
	if (liRet == 0) {
		sprintf(lc1Out, "YES\n");
	}
	else {
		sprintf(lc1Out, "NO\n");
	}

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <map>
#include <string.h>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(a) (a).begin(), (a).end()
using namespace std;

int main(){
    int a, b , c;
    cin >> a >> b >> c;
    cout << min(c,b/a) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    while(1){
      cin >> h >> w;
      if(h==0 && w==0) break;
      for(int i=0;i<h*w;i++){
          cout << '#' ;
          if((i+1)%w==0) cout << endl;
      }
      cout << endl;
    }
    
}


Measured memory_bytes: 3080
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

vector<int> seq;

int n;
vector<int> G[100];

int idx,deg[100],depth[100];
void dfs(int u,int d){
	n++;
	depth[d]=u;

	while(G[u].size()<deg[u]){
		if(seq[idx]>0){
			deg[n]=seq[idx++];
			G[u].push_back(n);
			G[n].push_back(u);
			dfs(n,d+1);
		}
		else{
			int v=depth[d+seq[idx++]];
			G[u].push_back(v);
			G[v].push_back(u);
		}
	}
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		seq.clear();
		for(int a;scanf("%d",&a),a;) seq.push_back(a);

		n=0;
		idx=1;
		deg[0]=seq[0];
		rep(u,100) G[u].clear();
		dfs(0,0);

		rep(u,n){
			printf("%d",u+1);
			sort(G[u].begin(),G[u].end());
			rep(i,G[u].size()) printf(" %d",G[u][i]+1);
			puts("");
		}
	}

	return 0;
}

Measured memory_bytes: 1088
use std::collections::HashMap;

fn main() {
    let mut line = String::new();
    let stdin = std::io::stdin();
    let _ = stdin.read_line(&mut line);
    line.clear();
    let _ = stdin.read_line(&mut line);
    let a: Vec<_> = line.split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect();
    let (mut map1, mut map2) = (HashMap::new(), HashMap::new());
    for (i, &x) in a.iter().enumerate() {
        let i = i as i64;
        map1.insert(x+i, *map1.get(&(x+i)).unwrap_or(&0)+1);
        map2.insert(i-x, *map2.get(&(i-x)).unwrap_or(&0)+1);
    }
    let mut cnt = 0;
    for (k, v) in map1.iter() {
        if let Some(n) = map2.get(k) {
            cnt += (*n as i64)*(*v as i64);
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 16140
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	//Number of items available and max capacity of Knapsack
	int items, capacity;
	cin >> items >> capacity;

	//Store the value sum for each combination of items with weight w
	long long dp[capacity+1];
	//set all dp values to zero in order to compare max value
	memset(dp,0,sizeof dp);

	//read every weight and value of item
	int weight, value;	
	for (int i = 0; i < items; ++i)
	{
		cin >> weight >> value;
		//cw is the current weight inside the knapsack
		for (int cw = capacity - weight;cw>=0;cw--){
			//Check max value between (don't put item, put item)
			//Then memoize current answer
			dp[cw + weight] = max(dp[cw + weight], dp[cw] + value);
		}
	}
	//Set answer to zero in order to compare max value
	long long answer = 0;
	//Loop through dp to get max possible value
	for (int i=0; i<=capacity; ++i)
	{
		answer = max(answer,dp[i]);
	}
	//Print max possible sum of values
	cout << answer << endl;

}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
int n,m,K;
int in[100005];
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&in[i]);
	sort(in+1,in+n+1);
	printf("%d\n",in[n/2+1]-in[n/2]);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define Boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void Crack() {
	string S,T;
    cin >> S >> T;
    long n = S.size();
    long m = T.size();
    long mn,ans = 1000000;
    for(int i=0;i<n;i++) {
        mn = 0;
        if(i>n-m) break;
        for(int j=0;j<m;j++) {
            if(S[i+j]!=T[j]) mn++;
            // cout << S[i+j];
        }
        // cout << endl;
        ans = min(ans,mn);
    }
    cout << ans << endl;
}

int main() {
	Boost;
    Crack();
	return 0;
}

Measured memory_bytes: 3648
def examA():
    a, b = LI()
    ans = "x"
    if a+b==15:
        ans = "+"
    elif a*b==15:
        ans = "*"
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

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

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

 string s;
 cin>>s;
 int f=1;
 if(s.size()&1)
 f=0;
 for(int i=0;i<s.size();i++)
 if(i&1){
 if(s[i]!='i')
 f=0;
 }
 else
 {
      if(s[i]!='h')
      f=0;
 }
if(f)
cout<<"Yes";
else
cout<<"No";

} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int N;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        scanner.close();
    }

    public static void main(String[] args) {
        init();
        // logic
        logic();
    }

    static void logic() {
        int splitter = N;
        int total = 0;

        for (; splitter != 0; splitter /= 10) {
            total += splitter % 10;
        }

        System.out.println((N % total == 0) ? "Yes" : "No");
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,2){
        cin >> A[i];
    }
    //sort(A,A+3);
    if(A[0]+A[1]>9) cout << "error" << endl;
    else cout <<  A[0]+A[1] << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
ll n;
int main() {
	cin>>n;
	ll res=1LL;
	for (int i = 1; i <= n; ++i) {
		res = res* (ll)i % mod;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    VV<ll> dp(size(s)+1, V<ll>(2, 0));
    dp[0][0] = 1;
    // dp[i][j]:=i-1桁まで見て j = 0 -> a + b == L かも　j = 1 -> a + b < L が確定
    rep(i, size(s)) {
        (dp[i+1][0] += dp[i][0] * (s[i] == '1' ? 2 : 1)) %= MOD;
        (dp[i+1][1] += (s[i] == '1'? 1 : 0) * dp[i][0]) %= MOD;
        (dp[i+1][1] += dp[i][1] * 3) %= MOD;
    }
    cout << (dp[size(s)][0] + dp[size(s)][1]) % MOD << endl;
}

Measured memory_bytes: 8740
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

map<LL, LL> pre;
int a, b, c, d;

constexpr LL inf = LL(1e18);

LL get(LL n) {
	if(n == 0)
		return 0;
	if(pre.find(n) != pre.end())
		return pre[n];
	debug(n);

	LL ans = inf;
	pre[n] = ans;
	if(n <= ans / d and n * d <= ans)
		ans = min(ans, n * d);

	auto consider = [&](int cost, int div) {
		LL m = n;
		while(m % div)
			--m;
		ans = min(ans, get(m / div) + cost + d * abs(m - n));
		m = n;
		while(m % div)
			++m;
		ans = min(ans, get(m / div) + cost + d * abs(m - n));
	};
	consider(a, 2);
	consider(b, 3);
	consider(c, 5);
	return pre[n] = ans;
}

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

	int t;
	cin >> t;
	while(t --> 0) {
		LL n;
		cin >> n >> a >> b >> c >> d;
		debug(n, a, b, c, d);

		pre.clear();
		constexpr int mult = 2 * 3 * 5;
		LL ans = inf;
		for(LL i = max<LL>(1, n - mult); i <= n + mult; ++i)
			ans = min(ans, get(i) + abs(n - i) * d);
		debug(pre);
		cout << ans << '\n';
	}
}


Measured memory_bytes: 4536
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow != 0){
        if(pow&1==1){ans = (ans*base);}
        base = (base*base);
        pow/=2;
        }
        return ans;
}
//ll inv(ll x){return expo(x,mod-2);}

ll lt[1234][1234], rt[1234][1234], upper[1234][1234], lower[1234][1234];

int dist(int x1, int y1, int x2, int y2){
    return abs(x1-x2)+abs(y1-y2);
}


int arr[123456];

int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);

    string s;
    cin >> s;
    string s1;
    map <pair<char,char>, int> mp;
    map <int,int> mp1;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != 'x'){
                s1 += s[i];
                //mp[s[i]].push_back(i);
        }
    }
    int cond = 1;
    int n1 = s1.size();
    for(int i = 0; i < s1.size(); i++){
        if(s1[i] != s1[n1-1-i]) cond = 0;
    }
    if(!cond){
       cout << -1; return 0;
    }

       int l1 = 0, l2 = 0;

       for(int i = 0; i < s.size(); i++){
           if(s[i] == 'x') l1++;
           else break;
       }
       for(int i = s.size()-1; i >= 0; i--){
           if(s[i] == 'x') l2++;
           else break;
       }
       vector <int> vec1;
       for(int i = 0; i < s.size(); i++){
           if(s[i] != 'x'){
              char c = s[i];
              int ind = i;
              i++;
              while(i < s.size() && s[i] == 'x') i++;
              if(i == s.size()) break;
              int l = i - ind-1;
              vec1.push_back(l);
              i--;
           }
       }
       ll ans = abs(l1-l2);
       int n2 = vec1.size();
       for(int i = 0; i < vec1.size()/2; i++){
           ans += abs(vec1[i] - vec1[n2-i-1]);
       }
       cout << ans;
}


Measured memory_bytes: 1216
#include <iostream>
using namespace std;
int main() {
  int n,a[4][13],num;
  char marks,mark[4]={'S','H','C','D'};
  cin>>n;
  for (int i = 0; i < 13; i++) {
    for (int j = 0; j < 4 ; j++) {
    a[j][i]=0;
    }
  }
  for (int k = 0; k <n; k++) {
    cin>>marks>>num;
     for (int j = 0; j < 4; j++) {
           if(marks==mark[j]){
           a[j][num-1]=1;
           break;
           }
         }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13 ; j++) {
    if(a[i][j]==0)cout<<mark[i]<<" "<<j+1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
def check_around(h,w,a,max_h,max_w)
    if h == 0 && w == 0
        return false if a[h+1][w] == '#' && a[h][w+1] == '#'
    elsif h == max_h && w == max_w
        return false if a[h-1][w] == '#' && a[h][w-1] == '#'
    elsif h == 0 && w == max_w
        return true if a[h][w-1] == '#' && a[h+1][w] == '#'
    elsif h == max_h && w == 0
        return true if a[h-1][w] == '#' && a[h][w+1] == '#'
    elsif h == 0
        return false if a[h][w-1] == '#' && a[h][w+1] == '#' && a[h+1][w] == '#'
    elsif h == max_h
        return false if a[h][w-1] == '#' && a[h][w+1] == '#' && a[h-1][w] == '#'
    elsif w == 0
        return false if a[h-1][w] == '#' && a[h+1][w] == '#' && a[h][w+1] == '#'
    elsif w == max_w
        return false if a[h-1][w] == '#' && a[h+1][w] == '#' && a[h][w-1] == '#'
    else
        count = 0
        count += 1 if a[h-1][w] == '#'
        count += 1 if a[h+1][w] == '#'
        count += 1 if a[h][w-1] == '#'
        count += 1 if a[h][w+1] == '#'
        return false if count >= 3
    end
    true
end

def solver(h,w,a,max_h,max_w)
    return 'Impossible' if check_around(h,w,a,max_h,max_w) == false
    return 'Possible' if h == max_h && w == max_w
    return 'Possible' if w+1 <= max_w && a[h][w+1] == '#' && solver(h,w+1,a,max_h,max_w) == 'Possible'
    return 'Possible' if h+1 <= max_h && a[h+1][w] == '#' && solver(h+1,w,a,max_h,max_w) == 'Possible'
    'Impossible'
end

H,W = gets.split.map &:to_i

a = []
H.times do
    a << gets.chomp.split(//)
end
h = 0
w = 0

puts solver(h,w,a,H-1,W-1)


Measured memory_bytes: 1788
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
     	int n = sc.nextInt();
     	String s = sc.next();
     	int counter = 0;
     	int ans = n;
     	for(int i=1;i<s.length();i++){
     		if(s.charAt(i)=='E'){
     			counter++;
     		}
     	} 
     	int count = 0;
     	ans = counter;
     	for(int i=1;i<s.length();i++){
     		if(s.charAt(i-1)=='W'){
     			count++;
     		}
     		if(s.charAt(i)=='E'){
     			counter--;
     		}
     		ans = Math.min(ans, count+counter);
     	}

     	System.out.println(ans);
    }
}

Measured memory_bytes: 30680
func main() {
    let K = Int(readLine()!)!
    
    var i = 1
    var sev = 7
    var buf = 0

    if K % 2 == 0 {
        print(-1)
    } else {
        while true {
            buf = sev % K
            if buf == 0 {
                print( i )
                break
            } else {
                sev = buf * 10 + 7
                i += 1
            }
            if i > 1000000 {
                print(-1)
                break
            }
        }
    }
}

main()



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

class UnionFind {
public:
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    UnionFind uf(n);
    vector<set<int>> s(n);
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        --a,--b;
        uf.merge(a,b);
        s[a].insert(b);
        s[b].insert(a);
    }
    for(int i=0;i<k;++i){
        int c,d;
        cin>>c>>d;
        --c,--d;
        if(!uf.issame(c,d)) continue;
        s[c].insert(d);
        s[d].insert(c);
    }

    for(int i=0;i<n;++i){
        int m=uf.size(i)-1-s[i].size();
        cout<<m<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 27012
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		int a = 0, z = 0;
		for(int i=0;i<s.length();i++){
			if(s.charAt(i)=='A'){
				a = i;
				break;
			}
		}
		
		for(int i=s.length()-1;i>=0;i--){
			if(s.charAt(i)=='Z'){
				z = i;
				break;
			}
		}
		
		System.out.println(z-a+1);
	}
}


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

int n;
int a[200001];
map <int, int> m;
long long ans;

int main(){
  cin >> n;

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

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

    ans+=m[i-a[i]];
  }

  cout << ans << endl;
}

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

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int board[][] = new int[3][3];
        for (int y = 0;y < 3;++y){
            for (int x = 0;x < 3;++x){
                board[x][y] = sc.nextInt();
            }
        }
        if(search(board)){
            System.out.println("Yes");
        }
        else System.out.println("No");
    }

    public static boolean search(int board[][]){
        int k = 0;
        for (int j = 1;j <= 2;++j){
            for (int i = 0;i < 3;++i){
                if(i == 0){
                    k = board[0][j] - board[0][0];
                }
                else{
                    if(k != board[i][j] - board[i][0]){
                        return false;
                    }
                }
            }
        }
        for (int j = 1;j <= 2;++j){
            for (int i = 0;i < 3;++i){
                if(i == 0){
                    k = board[j][0] - board[0][0];
                }
                else{
                    if(k != board[j][i] - board[0][i]){
                        return false;
                    }
                }
            }
        }
        return true;
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
unsigned gcd(unsigned a, unsigned b) {
    while (1) {
        if (a < b) swap(a, b);
        if (!b) break;
        a %= b;
    }
    return a;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans;
  ll e = c * d / gcd(c, d);
  ans = (b-a+1) - (b/c - (a-1)/c) - (b/d - (a-1)/d) + (b/e - (a-1)/e);
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const int mod = 1e9 + 7;

#define int ll
#define INF LINF

/*
typedef struct Vertex{
    int x;
    int y;
    int dir; // 0:up 1:right 2:down 3:left
} vertex;
 */

using vertex = pair<pair<int, int>, int>;

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

signed main(){
    int h, w, k;
    cin >> h >> w >> k;
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;

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

    vector<vector<vector<int>>> dis(h, vector<vector<int>>(w, vector<int>(4, INF)));
    priority_queue<pair<int, vertex>, vector<pair<int, vertex>>, greater<pair<int, vertex>>> que;

    for (int i = 0; i < 4; ++i) {
        dis[sx][sy][i] = 0;
        que.push(pair<int, vertex>(0, pair<pll, ll>(pll(sx, sy), i)));
    }

    while(!que.empty()) {
        pair<int, vertex> p = que.top();
        que.pop();
        vertex nv = p.second;
        int x = nv.first.first;
        int y = nv.first.second;
        int dir = nv.second;
        if (dis[x][y][dir] != p.first) continue;

        int nd = (((dis[x][y][dir] + k - 1) / k) * k) + 1;
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w || c[nx][ny] == '@') continue;

            if (i == dir) {
                if (dis[nx][ny][i] > dis[x][y][i] + 1) {
                    dis[nx][ny][i] = dis[x][y][i] + 1;
                    que.push(pair<int, vertex>(dis[nx][ny][i], pair<pll, ll>(pll(nx, ny), i)));
                }
            }else {
                if (dis[nx][ny][i] > nd){
                    dis[nx][ny][i] = nd;
                    que.push(pair<int, vertex>(nd, pair<pll, ll>(pll(nx, ny), i)));
                }
            }

        }
    }

    int res = INF;
    for (int i = 0; i < 4; ++i) {
        res = min(res, dis[gx][gy][i]);
    }

    if (res == INF) cout << "-1" << endl;
    else cout << (res + k - 1) / k << endl;
}

Measured memory_bytes: 144936
#include <stdio.h>

int main(void){

	char buf[26];
    scanf("%s",buf);
	int flag = 0;
	int size;
	int s;

    for (s = 0; buf[s] != '\0';s++);
	size = s;

	for(int i = 0; i < size; i++){
		for(int j = 0; j < size; j++){
			if(i != j && buf[i] == buf[j]){ flag = 1; }
		}
	}

	if(flag == 0){printf("yes");}
	else if(flag == 1){printf("no");}

	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    if(a%x != 0) a = (a/x+1)*x;
    if(b%x != 0) b = (b/x)*x;
    cout << (b-a)/x+1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define rep(j, n) for (int i = j; i < n; i++)
#define repd(j, n) for (int i = j; i > n; i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

ll burg(ll x, ll y) {
	vector<ll> a(x + 1), b(x + 1);
	a[0] = 1;
	b[0] = 1;
	rep(1, x + 1) {
		a[i] = 2 * a[i - 1] + 3;
		b[i] = 2 * b[i - 1] + 1;
	}
	if (x==0) {
		if (y == 0) { return 0; }
		else {
			return 1;
		}
	}
	if (y == 1) {
		return 0;
	}
	if (y > 1 && y <= a[x - 1] + 1) {
		return burg(x - 1, y - 1);
	}
	if (y ==a[x - 1] + 2) {
		return b[x - 1] + 1;
	}
	if (y > 2 + a[x - 1] && y <= 2 * a[x - 1] + 2) {
		return b[x - 1] + 1 + burg(x - 1, y - 2 - a[x - 1]);
	}
	 if(y==2*a[x-1]+3) {
		 return 2 * b[x - 1] + 1;
	}
}

int main() {
	ll n, k;
	cin>>n>>k;
	cout << burg(n,k) << endl;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> d(n);
  for(int i=0; i<n; i++)cin>>d[i];
  int m;
  cin>>m;
  vector<int> t(m);
  for(int i=0; i<m; i++)cin>>t[i];

  sort(d.begin(),d.end());
  sort(t.begin(),t.end());

  int i=0,j=0;
  while(i<n && j<m){
    if(d[i]<t[j])i++;
    else if(d[i]==t[j]){
      i++;
      j++;
    }else break;
  }

  if(j==m)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
}

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

using namespace std;

typedef long long ll;

#define REP(i, a, b) for (i = a; i < b; i++)
#define REP_ITER(it, v) for (it = v.begin(); it != v.end(); it++)

#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(0)

#define TEST(test) \
    int test;      \
    cin >> test;   \
    while (test--)

#define cll(a, b) cin >> a >> b
#define YES cout << "YES\n"
#define NO cout << "NO\n"

#define vi vector<int>
#define vi_iterator vector<int>::iterator

#define si set<int>
#define si_iterator set<int>::iterator

double pi = 2 * acos(0.0);
int i, j;
int main()
{
    FASTIO;
    ll n;
    cin >> n;
    ll arr[n];
    ll barr[n];
    REP(i,0,n){
        cin >> arr[i];
        barr[arr[i]-1]=i+1;
    }
    REP(i,0,n){
        cout << barr[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5180
//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2007;
const int MAXS = (int)2007 * 2007;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
ll n, k, dp[MAXN][MAXN], fact[MAXS], facrev[MAXS];
ll pwr(ll a, ll b)
{
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll c = pwr(a, b / 2);
	c = (c * c) % MOD;
	if(b % 2)
		c = (c * a) % MOD;
	return c;
}
ll inv(ll p)
{
	return pwr(p, MOD - 2);
}
ll C(ll n, ll k)
{
	ll mul = fact[n];
	mul = (mul * facrev[k]) % MOD;
	mul = (mul * facrev[n - k]) % MOD;
	return mul;
}
ll f(ll open, ll i)
{
	if(open > i || open < 0)
		return 0;
	if(dp[open][i] != -1)
		return dp[open][i];
	if(open + i == 0)
		return dp[open][i] = 1;
	ll sz = i * k - open;
	ll ans = f(open + 1, i);
	ll ans2 = f(open - 1, i - 1) * i % MOD * C(sz - 1, k - 2) % MOD;
	return dp[open][i] = (ans + ans2) % MOD;
}
int main()
{	
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	fact[0] = 1;
	for (int i = 1; i < MAXS; i++)
		fact[i] = (fact[i - 1] * i) % MOD;
	facrev[MAXS - 1] = inv(fact[MAXS - 1]);
	for (int i = MAXS - 1; i > 0; i--)
		facrev[i - 1] = (facrev[i] * i) % MOD;
	for (int i = 0; i < MAXN; i++)
		for (int j = 0; j < MAXN; j++)
			dp[i][j] = -1;
	if(k == 1)
		return cout << 1, 0;
	cout << f(0, n);
}

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

#define int long long

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,r,g,b,ans;
    r=g=b=ans=0;
    string s;
    cin>>n>>s;
    for(int x=0;x<n;x++){
      for(int y=x+1;y<n;y++){
        if(s[x]==s[y])continue;
        if(min(s[x],s[y])!='B'){//no blue...
          ans+=b;
          if((x-(y-x))>=0 && s[x-(y-x)]=='B')ans--;
        }else if(max(s[x],s[y])!='R'){
          ans+=r;
          if((x-(y-x))>=0 && s[x-(y-x)]=='R')ans--;
        }else{
          ans+=g;
          if((x-(y-x))>=0 && s[x-(y-x)]=='G')ans--;
        }
      }
      if(s[x]=='R')r++;
      else if(s[x]=='G')g++;
      else if(s[x]=='B')b++;
    }
    cout<<ans<<'\n';
    return 0;
}
/*

*/


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 300;
ll A[MAX_N][MAX_N];

int main(){
  cin >> N;
  REP(i, N) REP(j, N) cin >> A[i][j];

  bool flag[N][N];
  REP(i, N) REP(j, N) flag[i][j] = true;

  REP(u, N - 1) {
    for(int v = u + 1; v < N; v++) {
      REP(s, N) {
        if(s != u && s != v) {
          if(A[u][s] + A[s][v] < A[u][v]) {
            cout << -1 << endl;
            return 0;
          }
          if(A[u][s] + A[s][v] == A[u][v]) {
            flag[u][v] = false;
          }
        }
      }
    }
  }

  ll ans = 0;
  REP(u, N - 1) {
    for(int v = u + 1; v < N; v++) {
      if(flag[u][v]) ans+= A[u][v];
    }
  }

  cout << ans << endl;


  return 0;
}


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

long long int func(long long int a,long long int b,long long int n)
{
	long long int res = floor((a*n*1.0)/b);
	res -= a*floor(n*1.0/b);
	return res;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long int a,b,n;

	cin >> a >> b >> n;

	/*
	long long int lo = 1;
	long long int hi = n;
	while(hi - lo >= 3)
	{
		long long int x1 = (2*lo + hi)/3;
		long long int x2 = (lo + 2*hi)/3;
		if(func(a,b,x1) >= func(a,b,x2))
		{
			hi = x2;
		}
		else
		{
			lo = x1;
		}
	}

	long long int res = -1e18;
	for(long long int i = lo; i<=hi;i++)
	{
		res = max(res,func(a,b,i));
	}
	*/

	long long int res = func(a,b,min(b-1,n));

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 3756
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int l;
int a[111111];

int dp[111111];
int solve(int i){
  if(dp[i]) return dp[i];
  int ret = 0;
  if(a[i-1] > a[i])ret = solve(i-1);
  if(a[i+1] > a[i])ret = max(ret,solve(i+1));
  return dp[i] = ret + l - a[i];
}

int main(void){
  scanf("%d%d",&n,&l);
  for(int i = 1; i <= n; i++){
    scanf("%d",a+i);
  }
  a[0] = a[n+1] = 0;
  int res = 0;
  for(int i = 1; i <= n; i++){
    res = max(res,solve(i));
  }
  printf("%d\n",res);
}

Measured memory_bytes: 2980
#include <iostream>

int main() {
    int N;
    std::cin >> N;
    int num[N];
    for (int i = 0; i < N; i++) {num[i] = i + 1;}

    int result = 0;
    int before = 0;
    if (N == 1) {
        result = 1;
    }
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        while (num[i] % 2 == 0) {
            num[i] /= 2;
            cnt++;
        }
        if (before < cnt) {
            before = cnt;
            result = i + 1;
        }
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    long long h;
    int n;
    long long tot = 0;
    cin >> h >> n;
    rep(i, n){
        int a;
        cin >> a;
        tot += a;
    }
    if(h > tot) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main(){
	char c;
  	cin >> c;
    switch(c){
      case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
        cout << "vowel\n";
        break;
      default:
        cout << "consonant\n";
        break;
        
    }
  
  
}

Measured memory_bytes: 3040
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int n,w,h;
int a[15],b[15],c[15],f[10][10];
int fn(int d[][10],int p){
  int i,j,k,l,m;
  int ct=0;
  if(p==n){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(d[j][i]==0)
	  break;
      }
      if(j!=w)
	break;
    }
    if(i==h){
      for(i=0;i<h;i++){
	for(j=0;j<w;j++)
	  f[j][i]=d[j][i];
      }
      ct=1;
    }
  }else{
    for(i=1;i<a[p]+1;i++){
      if(a[p]%i==0){
	for(j=0;j<i;j++){
	  if(b[p]-j>-1&&b[p]+i-j-1<w){
	    for(k=0;k<a[p]/i;k++){
	      if(c[p]-k>-1&&c[p]+a[p]/i-k-1<h){
		for(l=0;l<i;l++){
		  for(m=0;m<a[p]/i;m++){
		    if(d[b[p]-j+l][c[p]-k+m])
		      break;
		  }
		  if(m!=a[p]/i)
		    break;
		}
		if(l==i){
		  int e[10][10];
		  memcpy(e,d,sizeof(e));
		  for(l=0;l<i;l++)
		    for(m=0;m<a[p]/i;m++)
		      e[b[p]-j+l][c[p]-k+m]=p+1;
		  ct+=fn(e,p+1);
		  if(ct>1)
		    return ct;
		}
	      }
	    }
	  }
	}
      }
    }
  }
  return ct;
}
int main(){
  int i,j;
  while(cin>>w>>h>>n&&w+h+n){
    for(i=0;i<n;i++){
      int p,q;
      cin>>p>>q;
      p--;
      a[p]=q;
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	int p;
	cin>>p;
	if(p){
	  p--;
	  b[p]=j;
	  c[p]=i;
	}
      }
    }
    int d[10][10];
    memset(d,0,sizeof(d));
    if(fn(d,0)==1){
      for(i=0;i<h;i++){
	for(j=0;j<w-1;j++)
	  cout<<f[j][i]<<" ";
	cout<<f[j][i]<<endl;
      }
    }else
      cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n;cin>>n;
  //caricurate
  ll i,j;vll a;ll k=6;
  while(k<100001){
    a.pb(k);k*=6;
  }
  k=1;
  while(k<100001){
    a.pb(k);k*=9;
  }
  vsort(a);ll sz=a.size();vll dp(200000,0);
  rep(i,n+1){
    rep(j,sz){
      if(dp[i+a[j]]){dp[i+a[j]]=min(dp[i]+1,dp[i+a[j]]);}
      else{dp[i+a[j]]=dp[i]+1;}
    }
  }
  //output
  cout<<dp[n]<<endl;
}

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

int stoi(string& s){
	int ret=0;
	for(unsigned int i=0;i<s.length();++i){
		ret+=s[i]-'0';
		ret*=10;
	}
	return ret/=10;
}

int stoi(string& s,int a , int b){
	string tmp=s.substr(a , b);
	return stoi(tmp);
}

int stoi(string&s , int n){
	string tmp=s.substr(0,n);
	return stoi(tmp);
}



int main(){
	int q;
	cin >> q;
	for(int i=0;i<q;++i){
		int cnt=0;
		string s;
		int org;
		cin >> s;
		org=stoi(s);
		int mul1,mul2;
		bool b=true;
		while(s.size()!=1){
			int mx=0;
			for(unsigned int j=1;j<s.size();++j){
			mul1=stoi(s,j);
			mul2=stoi(s,j,s.size()-j);
			mx=max(mx,mul1*mul2);
			}
			if(mx==org){
				b=false;
				break;
			}
			s=to_string(mx);
			cnt++;
		}
		cout << (b ?cnt:-1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N;
ll A[200020];
ll dp[200020][5];

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%lld", A + i);
	for(int i=0;i<=N;i++) rep(j, 5) dp[i][j] = 1e18;
	dp[0][0] = 0;
	int ar[5] = {0, 1, 2, 1, 0};
	for(int i=0;i<N;i++) {
		ll x = A[i+1];
		ll val[3] = {};
		if(x == 0) val[1] = 2, val[2] = 1;
		else if(x % 2 == 1) val[0] = x, val[1] = 1;
		else val[0] = x, val[2] = 1;
		rep(j, 5) {
			for(int k=j;k<5;k++) {
				ll v = val[ar[k]];
				dp[i+1][k] = min(dp[i+1][k], dp[i][j] + v);
			}
		}
	}
	printf("%lld\n", *min_element(dp[N], dp[N] + 5));
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

bool inp[1000001];

int main() {
    memset(inp, false, sizeof(inp));
    inp[0] = inp[1] = true;
    for(int i=2; i*i<=1000000; ++i)
        if(!inp[i])
            for(int j=2; i*j<=1000000; ++j)
                inp[i*j] = true;

    int a,b;
    while(cin>>a>>b, a|b) {
        vector<int> af,bf;
        for(int i=1; i<=max(a,b); ++i) {
            if(inp[i]) continue;
            if(a%i == 0) af.push_back(i);
            if(b%i == 0) bf.push_back(i);
        }

        int maxaf = af.back(); af.pop_back();
        int maxbf = bf.back(); bf.pop_back();

        for(int i=0; i<af.size(); ++i) maxaf -= af[i];
        for(int i=0; i<bf.size(); ++i) maxbf -= bf[i];

        if(maxaf > maxbf) cout<<"a"<<endl;
        else cout<<"b"<<endl;
    }
}

Measured memory_bytes: 1868
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;

int main(void){
    int h, w, n, sr, sc;
    string s, t;
    cin >> h >> w >> n >> sr >> sc;
    cin >> s >> t;
    
    int taka[4], aoki[4];
    char d[4] = {'L', 'R', 'U', 'D'};
    taka[0] = taka[1] = taka[2] = taka[3] = 0;
    aoki[0] = aoki[1] = aoki[2] = aoki[3] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            if (char(s[i]) == d[j]) taka[j]++;
            if (char(t[i]) == d[j]) aoki[j]++;
        }
    }
    
    if (taka[0] < sc && taka[1] < w - sc + 1 && taka[2] < sr && taka[3] < h - sr + 1) {
        cout << "YES" << endl;
        return 0;
    }
    
    int tmp_c = sc;
    for (int i = 0; i < n; i++) {
        if (char(s[i]) == 'L') tmp_c--;
        if (tmp_c == 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (char(t[i]) == 'R') tmp_c = min(tmp_c + 1, w);
    }
    
    tmp_c = sc;
    for (int i = 0; i < n; i++) {
        if (char(s[i]) == 'R') tmp_c++;
        if (tmp_c == w + 1) {
            cout << "NO" << endl;
            return 0;
        }
        if (char(t[i]) == 'L') tmp_c = max(tmp_c - 1, 1);
    }
    
    int tmp_r = sr;
    for (int i = 0; i < n; i++) {
        if (char(s[i]) == 'U') tmp_r--;
        if (tmp_r == 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (char(t[i]) == 'D') tmp_r = min(tmp_r + 1, h);
    }
    
    tmp_r = sr;
    for (int i = 0; i < n; i++) {
        if (char(s[i]) == 'D') tmp_r++;
        if (tmp_r == h + 1) {
            cout << "NO" << endl;
            return 0;
        }
        if (char(t[i]) == 'U') tmp_r = max(tmp_r - 1, 1);
    }
    
    cout << "YES" << endl;
    
    /*
    for (int i = 0; i < 4; i++) cout << taka[i] << " ";
    cout << endl;
    for (int i = 0; i < 4; i++) cout << aoki[i] << " ";
    cout << endl;*/
    
}

Measured memory_bytes: 776
from collections import defaultdict
n,m = map(int,input().split())
d = defaultdict(int)
for i in range(m):
    a,b = map(int,input().split())
    d[a] += 1
    d[b] += 1
ans = True
for i in d.values():
    if i % 2 != 0:
        ans = False
if ans:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 87036
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int m = max(A, max(B, C));
    if((m * 3 - (A + B + C)) % 2 == 0) {
        cout << (m * 3 - (A + B + C)) / 2 << endl;
    } else {
        cout << ((m + 1) * 3 - (A + B + C)) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cmath>
#include <algorithm>
using namespace std;
 
int main()
{
    int a,b,c,d,n;
    cin>>n>>a>>b>>c>>d;
    int ans=(int)1e9;
    int mapx[4],mapy[4];
    for(int i=1;i<=n;i++) {
        mapx[0] = (a - 1) % i;
        mapy[0] = (a - 1) / i;
        mapx[1] = (b - 1) % i;
        mapy[1] = (b- 1) / i;
        mapx[2] = (c - 1) % i;
        mapy[2] = (c - 1) / i;
        mapx[3] = (d - 1) % i;
        mapy[3] = (d- 1) / i;
        ans = min(ans, abs(mapx[0] - mapx[1]) + abs(mapy[0] - mapy[1]) + abs(mapx[3] - mapx[2]) + abs(mapy[3] - mapy[2]));
    }
    cout<<ans<<endl;
}  

Measured memory_bytes: 1164
import java.util.*;
import java.io.*;

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

	//入力文字列
	String s;
	s = scan.next();

	StringBuffer sb = new StringBuffer(s);

	if(s.length() == 2){
	    System.out.println(s);
	}else{
	    //反転用文字列
	    String dst = sb.reverse().toString();
	    System.out.println(dst);
	}
    }
}
	


Measured memory_bytes: 21844
#include <stdio.h>

int main()
{

  int a, b, c;

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

  if (c < a + b)
  {
    printf("%d\n", b + c);
  }
  else if (c == a + b)
  {
    printf("%d\n", b + c);
  }
  else
  {
    printf("%d\n", b + a + b + 1);
  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ran 1111111
int n;
long long int a[ran];
bool good[ran];
int pos[ran],lpos;
long long int out[ran];
map<int,long long int> Map;
int main(){
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	a[0] = 0;
	pos[0] = 0;
	for(int i=1; i<=n; i++)
		if(lpos == 0 || a[i] > a[pos[lpos]]){
			pos[++lpos] = i;
			good[i] = true;
		}
	for(int i=n; i>=1; i--){
		Map[a[i]] ++;
		if(good[i]){
			long long int oo = 0;
			int base = a[pos[lpos-1]];
			long long int tot = 0;
			while(!Map.empty() && Map.rbegin()->first > base){
				tot += Map.rbegin()->second;
				oo += Map.rbegin()->second * (Map.rbegin()->first - base);
				Map.erase(Map.rbegin()->first);
			}
			Map[base] += tot;
			out[i] = oo;
			lpos--;
		}
	}
	for(int i=1; i<=n; i++)
		cout<<out[i]<<endl;
	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

int main(){

    int N;
    cin >> N;
    int input;
    int magic_counter = 0;
    int now = 0;
    for(int i = 0; i < N; i++){
        cin >> input;

        if(now == 0){
            now = input;
        }else{
            if(now == input){
                magic_counter++;
                now = 0;
            }else{
                now = input;
            }
        }
    }

    cout << magic_counter << endl;
    return 0;

}


Measured memory_bytes: 256