akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int N,K;
int a[110];
// K個の山で先手が勝つか？
int dp[110000] = {0};

int rec(int k){
  if(dp[k]>0) return dp[k];
  int count = 0; // 先手が可能な手数
  int win = 0; // 後手が負ける場合の数
  for(int i=0;i<N;++i){
    if(k-a[i] >= 0){ // 先手が行動可能
      count++;
      if(rec(k-a[i])==1){ // k-a[i]の大きさの山で先手が負ける＝kの山で先手が勝てる
        win++;
      }
    }
  }
  if(count==0) return dp[k] = 1; //取れる手がなかったら先手の負け
  else if(win > 0) return dp[k] = 2; //勝てる手が一つでもあったらkの山では先手の勝ち
  else return dp[k] = 1;
}
      
      

int main(){
  cin >> N >> K;
  for(int i=0;i<N;++i) cin >> a[i];
  
  if(rec(K)==2) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}

Measured memory_bytes: 5376
#define CPP17
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#ifdef CPP17
#include <variant>
#endif

#define endl codeforces

#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
using size_type = ssize_t;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

template <typename T, std::size_t Head, std::size_t... Tail> 
struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };

template <typename T, std::size_t Head> 
struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };

template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

#ifdef CPP17
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { 
    if constexpr (std::is_invocable<F, Args...>::value) { 
        t = f(args...); 
    } else { 
        for (size_type i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); 
    } 
}
#endif

template <typename T> vec<T> make_v(size_type sz) { return vec<T>(sz); }

template <typename T, typename... Tail> 
auto make_v(size_type hs, Tail&&... ts) { 
    auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); 
    return vec<decltype(v)>(hs, v); 
}

namespace init__ { 
struct InitIO { 
    InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } 
} init_io; 
}
#define CPP17


ll solve() {
    ll k;
    std::cin >> k;
    vec<bool> found(k + 10);
    ll cur = 0;
    for (ll i = 1;; i++) {
        cur = (cur * 10 + 7) % k;
        if (cur == 0) return i;
        if (found[cur]) break;
        found[cur] = true;
    }
    return -1;
}

int main() {
    std::cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 3764
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline long IN(void)
{
  long x=0;int f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=8;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;;
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,p){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,m){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return OUT(l),0;
}

Measured memory_bytes: 3040
import Control.Monad

main :: IO ()
main = do
  t <- readLn
  if t == 0
    then return ()
    else do
      n <- readLn
      ls <- replicateM n getLine
      let ls' = map (map read . words) ls
      putStrLn $ solve t ls'
      main

solve :: Int -> [[Int]] -> String
solve t []
  | t <= 0 = "OK"
  | otherwise = show t
solve t ([a,b]:xs)
  | t <= 0 = "OK"
  | otherwise = solve (t - (b - a)) xs

Measured memory_bytes: 4124
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  int c = 0;
  rep(i, n) c += a[a[i]] == i;
  cout << c / 2 << endl;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n, k, x, y int
	fmt.Scan(&n)
	fmt.Scan(&k)
	fmt.Scan(&x)
	fmt.Scan(&y)
	if n > k {
		fmt.Println(k*x + (n-k)*y)
	} else {
		fmt.Println(n * x)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans=a+b;
    if (a>0 and b<0){
        cout << "Zero" << endl;
    }else if (a<0 and b>0){
        cout << "Zero" << endl;
    }else if (a==0 or b==0){
        cout << "Zero" << endl;
    }else if (a>0 and b>0){
        cout << "Positive" << endl;
    }else if (ans%2==0){
        cout << "Negative" << endl;
    }else{
        cout << "Positive" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
#define ll long long
#define INF 1000000007
signed main(){
    int n,l;
    cin>>n>>l;
    int memo=1;
    int sum=(n+1)*n/2+l*n-n;
    for(int i=2;i<=n;i++){
        if(abs(memo+l-1)>abs(i+l-1))memo=i;
    }
    cout<<sum-(memo+l-1)<<endl;
    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=pair<ll,ll>;
const ll MOD=1e9+7;
const int MAX=1e5;
const ll INF=(1ll<<62)-1;
signed main(){
    int S,W; cin>>S>>W;
    string ans="safe";
    if(W>=S) ans="unsafe";
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int[] array;
    public static void main(String[] args) {
        read();
        solve();
    }

    static void read(){
        array = new int[10];
        for(int i = 0; i < 10; i++){
            array[i] = sc.nextInt();
        }
    }

    static void solve(){
        Arrays.sort(array);
        System.out.println(array[9]);
        System.out.println(array[8]);
        System.out.println(array[7]);
    }

}

Measured memory_bytes: 26232
S = str(input())
lists = []
result = []
max = 0
for i in range(len(S)):
    for j in range(len(S)):
        result.append(S[i:len(S) - j])
for i in range(len(result)):
    cnt = 0
    for j in range(len(result[i])):
        m = list(result[i])
        if m[j] == "A" or m[j] == "C" or m[j] == "G" or m[j] == "T":
            cnt += 1
    if cnt == len(result[i]):
        lists.append(result[i])
        if max < len(result[i]):
            max = len(result[i])
print(max)


Measured memory_bytes: 3064
import math

n,k = map(int,input().split())
ans = 0
pre_ans = 0
for i in range(1,n+1):
    twoNum = 1
    score = i
    while score < k:
        score *= 2
        twoNum *= 2
    ans += twoNum**-1 / n
print(round(ans,12))

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

int main() {
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0) {
			int j = S1.top(); S1.pop();
			sum += (i - j);
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	int t = 0;
	while (S2.size() > 0) { ans.push_back(S2.top().second); S2.pop(); }
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A - B == 0){
        cout << C;
    }else if(A - C == 0) {
        cout << B;
    }else if(B - C == 0) {
        cout << A;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
int main(){
  int n,t,j,i;
  cin>>n>>t;
  vector< pair<int,int> >a(n);
  for(i=0;i<n;i++){
    cin>>a[i].second;
    cin>>a[i].first;
  }
  int ans=2000;
  sort(a.begin(),a.end());
  for(j=0;j<n;j++){
    if(a[j].first>t){
      break;
    }
    else
      ans=min(ans,a[j].second);
  }
  if(ans==2000)
    cout<<"TLE";
  else
    cout<<ans;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

#define rep(i, first, to) for(int i = first; i < to; ++i)

using namespace std;
typedef long long ll;

bool match(int x, int y, int *group, int n) {
	rep(i, 0, n) {
		if(group[i] == x) {
			rep(j, 0, n) {
				if (group[j] == y) {
					return true;
				}
			}
		}

	}
	return false;
}
int main() {

	int x, y;
	cin >> x >> y;
	bool judge = false;
	int group1[] = {1, 3, 5, 7, 8, 10, 12};
	int group2[] = {4, 6, 9, 11};
	int group3[] = {2};
	if (match(x, y, group1, 7) || match(x, y, group2, 4) || match(x, y, group3, 1)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
n,m = map(int,input().split())

pro = [0]*n

ac = set([])

ans = 0

pen = 0

for _ in range(m):
    l = input().split()
    s = l[1]
    p = int(l[0])    
    if s == "AC":
        if p not in ac:
            ans += 1
            pen += pro[p-1]
            ac.add(p)
            
    else:
        if p not in ac:
            pro[p-1] += 1
            
print(ans,pen)

Measured memory_bytes: 17984
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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 ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  ll N, M; cin >> N >> M;
  vector<P> vec;
  rep(i, N){
    int a, b; cin >> a >> b;
    vec.push_back(make_pair(a, b));
  }
  sort(vec.begin(), vec.end());
  ll tot = 0;
  ll ans = 0;
  rep(i, N){
    ll a = vec[i].first;
    ll b = vec[i].second;
    if (tot + b < M) {
      tot += b;
      ans += a * b;
    }
    else{
      ll c = M - tot;
      tot += c;
      ans += a * c;
    }
    if (tot == M) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    ll n;
    int k;
    cin >> n >> k;
    int ans = 1;
    while(true) {
        if (n < k) break;
        ans++;
        n /= k;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
vector<vector<int>>d(maxn);
int h,w,k;
string s[maxn];
int sx,sy,ex,ey;
int xx[5]={58,0,0,1,-1};
int yy[5]={58,1,-1,0,0};

void bfs()
{
    queue<pair<int,int>>q;
    q.push({sx,sy});
    d[sx][sy]=0;
    while(!q.empty())
    {
        int x=q.front().first;
        int y=q.front().second;
        if(x==ex&&y==ey)
        {
            return;
        }
        q.pop();
        for(int i=1;i<=4;i++)
        {
            for(int j=0;j<k;j++)
            {
                int tx=xx[i]+x;
                int ty=yy[i]+y;
                if(i==1)
                    ty+=j;
                if(i==2)
                    ty-=j;
                if(i==3)
                    tx+=j;
                if(i==4)
                    tx-=j;
                if(tx<0||ty<0||tx>h-1||ty>w-1||s[tx][ty]=='@'||d[tx][ty]<d[x][y]+1)
                {
                    break;
                }
                if(d[tx][ty]>d[x][y]+1) //同样长的话不能走 否则TLE
                {
                    d[tx][ty]=d[x][y]+1;
                    q.push({tx,ty});
                }
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w>>k;
    cin>>sx>>sy>>ex>>ey;
    sx--,sy--,ex--,ey--;
    for(int i=0;i<h;i++)
        cin>>s[i];
    int g=1e9;
    for(int i=0;i<h+5;i++)
    {
        for(int j=0;j<w+5;j++)
        {
            d[i].pb(g);
        }
    }
    bfs();
    if(d[ex][ey]==1e9)
    {
        cout<<-1<<'\n';
    }
    else
        cout<<d[ex][ey]<<'\n';





}


Measured memory_bytes: 84488
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
    string[] str=Console.ReadLine().Split(' ');
    int[] input=new int[N];
      for(int i=0;i<N;i++){
        input[i]=int.Parse(str[i]);
      }
      for(int j=1;j<N;j++){
        Console.Write((Array.IndexOf(input,j)+1)+" ");
      }
      Console.Write(Array.IndexOf(input,N)+1);
    }
    
  }

}

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
#define M 100005
#define ll long long
int n,A[M];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i]);
		A[i]*=2;
	}
	ll ret=A[1];
	bool f=0;
	for(int i=2;i<n;i++){
		if(f)ret+=A[i];
		else ret-=A[i];
		f^=1;
	}
	ll ans;
	ans=(A[n]+ret)/2;
	printf("%lld ",ans);
	for(int i=1;i<n;i++){
		ans=A[i]-ans;
		printf("%lld ",ans);
	}
	return 0;
}

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

	#define E "\n"
	#define int long long 
	#define f(i,l,n) for(int i=l;i<n;i++)

	int solve()
	{
		int n,k;
		cin >> n >> k;
		int frq[n+1]={0};

		f(i,0,k)
		{
			int d;
			cin >> d;
			f(j,0,d) 
			{
				int temp;
				cin >> temp;
				frq[temp]=1;
			}
		}

		int ans=0;

		f(i,1,n+1) ans+=(frq[i]==0);

		cout<<ans;
		return 0;
	}

	int32_t main()
	{

	  int t=1;
	  //cin >>t;
	  while(t--) solve();

	}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> W(N);
    for (int i = 0; i < N; i++)
    {
        cin >> W[i];
    }
    // sort(W.begin(), W.end());
    // cout << W << endl;
    int sum1 = 0, sum2 = 0;
    int ans = 10000000;
    for (int i = 1; i <= N; i++)
    {
        for (int s1 = 0; s1 < i; s1++)
        {
            sum1 += W[s1];
        }

        for (int s2 = N - 1; s2 >= i; s2--)
        {
            sum2 += W[s2];
        }
        // cout << "sum1: " << sum1 << " sum2: " << sum2 << endl;
        ans = min(ans, abs(sum1 - sum2));
        sum1 = 0, sum2 = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int A[3][3],f[3][3];

int main() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }
    int n; cin >> n;
    vector<int> b(101);
    for (int i = 0; i < n; i++) {
        int t; cin >> t;
        b[t] = 1;
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (b[A[i][j]]) f[i][j] = 1;
        }
    }
    string ans = "No";
    for (int i = 0; i < 3; i++) if (f[i][0] && f[i][1] && f[i][2]) ans = "Yes";
    for (int i = 0; i < 3; i++) if (f[0][i] && f[1][i] && f[2][i]) ans = "Yes";
    if (f[0][0] && f[1][1] && f[2][2]) ans = "Yes";
    if (f[0][2] && f[1][1] && f[2][0]) ans = "Yes";
    cout << ans << "\n";
}

Measured memory_bytes: 256
// AOJ 0114: Electro-Fly
// 2017.8.23 bal4u@uu
// 1017.11.18

#include <stdio.h>

long long gcd(long long a, long long b)
{
	long long r;
	if (a < b) r = a, a = b, b = r;
	while (b) r = a % b, a = b, b = r; return a;
}

int main()
{
	int a1, a2, a3, m1, m2, m3, b1, b2, b3, n, a, b, c;
	long long ans;
	
	while (scanf("%d%d%d%d%d%d", &a1, &m1, &a2, &m2, &a3, &m3) && a1) {
		n = 0, b1 = b2 = b3 = 1, a = b = c = 0;
		while (1) {
			if (!a) b1 = (b1 * a1) % m1;
			if (!b) b2 = (b2 * a2) % m2;
			if (!c) b3 = (b3 * a3) % m3;
			n++;
			if (!a && b1 == 1) a = n;
			if (!b && b2 == 1) b = n;
			if (!c && b3 == 1) c = n;
			if (a && b && c) break;
		}
		ans = (long long)a / gcd(a,   b) * b;
		ans =          ans / gcd(ans, c) * c;
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main(){
	vector <long long> h;
	long long n,k,t,mi=10000000000;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>t;
		h.push_back(t);
	}
	sort(h.begin(),h.end());
	for(int i=0;i<n-k+1;i++){
		mi=min(mi,h[i+k-1]-h[i]);
	}
	cout<<mi<<endl;
	return 0;
}

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

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

int main(){
    int n,m,a,b;
    cin>>n>>m;
    vector<int>w(1000000);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        w[a-1]++;
        w[b-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<w[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	int x;
  cin>>x;
  if(x>=30)
    cout<<"Yes\n";
  else
    cout<<"No\n";

    }

Measured memory_bytes: 3612
N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt_ls = [0] * N
wa_cnt = 0
for i in range(M):
    p, s = input().split(' ')
    idx = int(p) - 1
    if not idx in ac_set:
        if s == 'AC':
            wa_cnt += wa_cnt_ls[idx]
            ac_set.add(idx)
        else:
            wa_cnt_ls[idx] += 1
print(len(ac_set), wa_cnt)

Measured memory_bytes: 18284
n = int(input())
h = list(map(int, input().split()))
result = 0
while True:
  start = n
  for i in range(n):
    if h[i] != 0:
      start = i
      break
  if start == n:
    break
  end = n - 1
  count = 101
  for i in range(start, n):
    if h[i] == 0:
      end = i - 1
      break
    if h[i] < count:
      count = h[i]
  for i in range(start, end + 1):
    h[i] -= count
  result += count
print(result)


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

struct UnionFind {
    vector<int> d; // d[a]=bのとき、「aの親がbである」ということを表す。

    UnionFind(int n=0): d(n, -1) {} // 全て根であるとみなす。d[x]==-1のとき、そのノードは根である。

    int find(int x) {
        if (d[x] < 0) return x; // 今の頂点が根ならその値を返す
        return d[x] = find(d[x]); // 経路縮約（メモ化）
    }

    bool unite(int x, int y) { // Minimum Spanning Treeのためにboolを返す実装にしている。
        int rx = find(x);
        int ry = find(y);

        if (rx == ry) return false;
        if (d[rx] > d[ry]) swap(rx, ry); // マイナスサイズなので不等号が逆。xのサイズの方が大きいようにする。
        d[rx] += d[ry]; // 連結成分のサイズを管理するためのコード
        d[ry] = rx; // xにyをくっつける。yの値をxの根とする。
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    cout << ans << " ";
  }
  cout << endl;
}


Measured memory_bytes: 6784
#include "bits/stdc++.h"
using namespace std;
vector<string> v;
int h,w;
string s[10];

string search(int a,int b,int d)
{
	int dirx[8]={1,1,0,-1,-1,-1,0,1};
	int diry[8]={0,-1,-1,-1,0,1,1,1};
	string ret;
	int i=a;
	int j=b;
	do{
		ret+=s[i][j];
		i+=dirx[d];
		j+=diry[d];
		if(i==-1)
			i=h-1;
		if(i==h)
			i=0;
		if(j==-1)
			j=w-1;
		if(j==w)
			j=0;
	}while(!(i==a && j==b));
	return ret;
}

bool comp(string a,string b)
{
	if(a.size()==b.size())
		return a<b;
	else
		return a.size()>b.size();
}

string itti(string a,string b)
{
	string ret;
	for(int i=0;i<min(a.size(),b.size());i++)
	{
		if(a[i]!=b[i])
			break;
		ret+=a[i];
	}
	return ret;
}

int main()
{
	while(1)
	{
		v.clear();
		cin>>h>>w;
		if(h==0)
			break;
		for(int i=0;i<h;i++)
			cin>>s[i];
		
		//すべての始点を調べる
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				for(int k=0;k<8;k++)
					v.push_back(search(i,j,k));
			}
		}

		sort(v.begin(),v.end());
		string ans="0";
		for(int i=1;i<v.size();i++)
		{
			string tmp=itti(v[i],v[i-1]);
			if(comp(tmp,ans))
				ans=tmp;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3400
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    counter = Counter(a_list)

    ans = 1
    if n % 2 != 0:
        for i in range(0, n, 2):
            c = counter[i]
            if (i == 0 and c != 1) or c == 0:
                print(0)
                exit()
            else:
                ans *= c
    else:
        for i in range(1, n, 2):
            c = counter[i]
            if c == 0:
                print(0)
                exit()
            else:
                ans *= c
    print(ans % (10 ** 9 + 7))
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 14820
def BubbleSort(C, N):
    '''C: list of str((S|H|C|D)+str(int)) -> list of str, str
    '''
    cli = C.copy()
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(cli[j][1:]) < int(cli[j - 1][1:]):
                cli[j], cli[j-1] = cli[j-1], cli[j]
    return cli, "Stable"

def SelectionSort(C,N):
    '''C: list of str((S|H|C|D)+str(int)) -> list of str, str
    '''
    cli = C.copy()
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(cli[j][1:]) < int(cli[minj][1:]):
                minj = j
        cli[i], cli[minj] = cli[minj], cli[i]
    return cli, isStable(cli, C)
def isStable(L1, L2):
    '''list of str(sorted), list of str -> str('Stable' or 'Not stable')
    '''
    s1, s2 = None, None
    #i1, i2 = None, None
    for i in range(len(L1)-1):
        for j in range(i+1, len(L1)):
            if int(L1[i][1:]) == int(L1[j][1:]):
                s1, s2 = L1[i], L1[j]  #i < j
                if L2.index(s1) >= L2.index(s2):
                    return 'Not stable'
    return 'Stable'
def printlist(L):
    for itm in L[:-1]:
        print(itm, end = ' ')
    print(L[-1])

N = int(input())
C = list(input().split())

L, s = BubbleSort(C, N)
printlist(L)
print(s)
L, s = SelectionSort(C, N)
printlist(L)
print(s)



Measured memory_bytes: 5620
#include <stdio.h>
#include <stdint.h>

void swap(uint32_t *a, uint32_t *b) {
  uint32_t tmp = *a;
  *a = *b, *b = tmp;
}

int main() {

  uint32_t A, B, C;
  scanf("%u %u %u", &A, &B, &C);

  if(A>B)
    swap(&A, &B);
  if(B>C)
    swap(&B, &C);
  if(A>B)
    swap(&A, &B);

  if(A == 5 && B == 5 && C == 7)
    puts("YES");
  else
    puts("NO");

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int H,N; 
  int A[100000];

  cin >> H >> N;

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

  for(int i =0;i < N;++i) H = H - A[i];

  if(H > 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  cout << endl;

  return 0;

}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
#define local 0
string T;
ll q;
void myassert(bool b){
	if(b) return;
	vector<ll> v;
	FOR(i,1,1e18) v.pb(i);
	return;
}
ll editdist(string x,string y){
	ll n=x.size(), m=y.size();
	vector<vector<ll>> dp(n+1, vector<ll>(m+1,LLINF));
	dp[n][m]=0;
	FOR(i,0,n-1) dp[i][m]=n-i;
	FOR(j,0,m-1) dp[n][j]=m-j;
	DEC(i,n-1,0) DEC(j,m-1,0) {
		if(x[i] == y[j]) {
			dp[i][j]=dp[i+1][j+1];
		}else{
			dp[i][j]=min({dp[i+1][j+1], dp[i+1][j], dp[i][j+1]})+1;
		}
	}
	return dp[0][0];
}
ll ask(string S){
	myassert(++q <= 850);
	cout<<"? "<<S<<endl;
	ll x; 
	if(!local) cin>>x;
	else x=editdist(T,S), cout<<"Answer is: "<<x<<endl;
	return x;
}
void answer(string S){
	cout<<"! "<<S<<endl;if(local)assert(T==S),cout<<"used: "<<q<<endl;
	exit(0);
}
map<ll,char>mp;
ll co, len[62], total;
string repeat(char x){
	string ret="";
	FOR(i,1,128) ret+=x;
	return ret;
}
string repeat(char x,ll times){
	string S="";
	while(times--) S += x;
	return S;
}
string prefix(string S,ll sz){
	string X="";
	FOR(i,0,sz-1) X+=S[i];
	return X;
}
bool correct(string S){
	return ask(S) == total - S.size();
}
string concat(string a,string b,string c){
	return a+b+c;
}
vector<pi> order;
int main(){
	FAST
	if(local) {
		// FOR(i,1,64) T += 'a';
		// FOR(i,1,64) T += rand('b','r');
		// cout<<T<<endl;
		cin>>T;
	}
	FOR(i,'a','z') mp[co++]=char(i);
	FOR(i,'A','Z') mp[co++]=char(i);
	FOR(i,'0','9') mp[co++]=char(i);
	assert(co==62);
	for(auto i:mp) len[i.f]=128-ask(repeat(i.s)), total+=len[i.f], order.eb(len[i.f],i.f);
	//sort(all(order),greater<pi>());
	string cfm="";
	for(auto i:order) if(i.f) {
		string now = repeat(mp[i.s], i.f);
		string small, big;
		if(cfm.size()>now.size()) big=cfm, small=now;
		else big=now,small=cfm;
		string res="";
		while(small.size()){
			ll st=-1, en=siz(big);
			while(en-st>1){
				ll mid=(st+en)>>1;
				if(correct(concat(res, prefix(big, mid+1), small)))st=mid;
				else en=mid;
			}
			++st;
			while(st--) res += big[0], big.erase(big.begin());
			res+=small[0];
			small.erase(small.begin());
		}
		FOR(i,0,siz(big)-1) res+=big[i];
		cfm=res;
	}
	answer(cfm);
}


Measured memory_bytes: 3796
def main():
    n, a, b = map(int, input().split())
    xs = list(map(int, input().split()))
    res = 0
    for i in range(n - 1):
        res += min(b, (xs[i + 1] - xs[i]) * a)
    print(res)


if __name__ == '__main__':
    main()


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

int main(int argc, char** argv) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S, T;
    cin >> S >> T;
    int ls = S.length(), lt = T.length(), cs[ls + 1], ct[lt + 1];
    memset(cs, 0, sizeof cs);
    memset(ct, 0, sizeof ct);
    for (int i = 1; i <= ls; ++i) cs[i] = cs[i - 1] + (S[i - 1] == 'B'? 2 : 1);
    for (int i = 1; i <= lt; ++i) ct[i] = ct[i - 1] + (T[i - 1] == 'B'? 2 : 1);
    int q;
    cin >> q;
    for (int i = 0, a, b, c, d; i < q; ++i) {
        cin >> a >> b >> c >> d;
        cout << ((cs[b] - cs[a - 1]) % 3 == (ct[d] - ct[c - 1]) % 3? "YES" : "NO") << "\n";
    }
    return 0;
}


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

using namespace std;

int n;

int main()
{
    cin>>n;

    int a=n%10;

    if(a==2||a==4||a==5||a==7||a==9)

        cout<<"hon"<<"\n";

    else if(a==0||a==1||a==6||a==8)
        cout<<"pon"<<"\n";

     else
     cout<<"bon"<<"\n";

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
const string nyan("(=^・ω・^=)");

int N, K, t, c, res;
string S;
vector<pair<bool, int>>v;

int main() {
	cin >> N >> K >> S;
	v.push_back(mkp(S.front() == '1', 0));
	for (int i = 0; i < N; ++i) {
		if (v.back().first ^ (S[i] == '1')) {
			v.push_back(mkp(S[i] == '1', 1));
		}
		else {
			++v.back().second;
		}
	}
	for (int i = 0; i < v.size(); ++i) {
		if (!v[i].first)++t;
	}
	if (t <= K) {
		cout << N << endl;
	}
	else {
		t = 0;
		v.push_back(mkp(0, 0));
		if (v.front().first) {
			for (int i = 0; i <= K * 2; ++i) {
				t += v[i].second;
			}
			res = t;
			for (int i = K * 2 + 1; i < v.size() - 1; i += 2) {
				t += v[i].second + v[i + 1].second;
				t -= v[i - K * 2 - 1].second + v[i - K * 2].second;
				res = max(t, res);
			}
		}
		else {
			for (int i = 0; i < K * 2; ++i) {
				t += v[i].second;
			}
			res = t;
			t -= v.front().second;
			for (int i = K * 2; i < v.size() - 1; i += 2) {
				t += v[i].second + v[i + 1].second;
				res = max(t, res);
				t -= v[i - K * 2 + 1].second + v[i - K * 2 + 2].second;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1528
#include <stdio.h>
int main(void)
{
    char tenki[3];
    int i,count=0;
    scanf("%s",tenki);
    for(i=0;i<3;i++)
    {
        if(tenki[i]=='R')
        {
            count++;
        }
    }
    if(count==2&&tenki[1]!='R')
    {
        count=1;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 1732
comb = [[1] for _ in range(51)]

for i in range(1, 51):
    for j in range(1, i):
        comb[i].append(comb[i - 1][j - 1] + comb[i - 1][j])
    comb[i].append(1)

n, p = map(int, input().split())
a = list(map(int, input().split()))
even = 0
odd = 0
for ai in a:
    if ai % 2 == 0:
        even += 1
    else:
        odd += 1
ans = 0
for i in range(p, odd + 1, 2):
    ans += 2 ** even * comb[odd][i]

print(ans)

Measured memory_bytes: 39152
#include<stdio.h>
 
int main(void){
    int i,n;
    scanf("%d",&n);
 
    int a[n];
    for(i=0; i<n; i++)
        scanf("%d",&a[i]);
    for(i=n-1; i>=0; i--){
        if(i!=n-1) printf(" ");
        printf("%d",a[i]);
    }
    putchar('\n');
    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

  lint ans = 0;
  for(lint i=1; i<=N; i++) {
    for(lint j=i; j<=N; j+=i) {
      ans += j;
    }
  }

  cout << ans << endl;
}

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

int main() {
	int n, m, x, b1=0, b2=0;
	int a[101];
	for (int i = 0;i < 101;i++) a[i] = 0;
	cin >> n >> m >> x;
	for (int i = 0;i < m;i++) cin >> a[i];
	for (int i = 0;i < m;i++) {
		if (a[i] < x) b1++;
		else b2++;
	}
	if (b1 < b2) cout << b1 << endl;
	else cout << b2 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    vector<ll> x(n), L(n-1);
    rep(i, n) {
        cin >> x[i];
    }
    rep(i, n-1) {
        L[i] = x[i+1] - x[i];
    }

    ll ans = 0;
    rep(i, n-1) {
        if(a*L[i] < b) {
            ans += a*L[i];
        }
        else {
            ans += b;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
n, y = map(int, input().split())

m_max = int(y/10000)
g_max = int(y/5000)

flag = 0
for m in range(0,m_max+1):
    for g in range(0,g_max+1):
        s = n - m - g
        if s >= 0 :
            yen = m * 10000 + g * 5000 + s * 1000
            if yen == y :
                result = str(m) + " " + str(g) + " " + str(s)
                flag = 1
                break
    if flag == 1 :
        break
            
if flag == 0 :
    print("-1 -1 -1")
else :
    print(result)

Measured memory_bytes: 3064
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var HN = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var H = HN[0]; var N = HN[1];
            var A = new int[N + 1];
            var B = new int[N + 1];
            for (int i = 1; i < N + 1; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                A[i] = ab[0]; B[i] = ab[1];
            }
            var DP = new int[N + 1, H + 1];
            for (int i = 0; i < H + 1; i++) DP[0, i] = int.MaxValue;
            for (int magic = 1; magic < N + 1; magic++)
            {
                for (int damage = 0; damage < H + 1; damage++)
                {
                    if (damage <= A[magic])
                    {
                        DP[magic, damage] = Math.Min(DP[magic - 1, damage], B[magic]);
                    }
                    else
                    {
                        DP[magic, damage] = Math.Min(DP[magic, damage - A[magic]] + B[magic], DP[magic - 1, damage]);
                    }
                }
            }
            Console.WriteLine(DP[N, H]);
        }
    }
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int mod = 998244353;

const int N = 10005;
int fact[N], invfact[N];
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (((ll) x) * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}
void pre(){
	fact[0] = invfact[0] = 1;
	for(int i = 1;i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for(int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k){
	if(n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int f[3005][2 * 3005];
int g[N];

inline int getSum(int m, int i, int j){
	return sub(f[m][j], i <= 1 ? 0 : f[m][i - 2]);
}

int main(){
	pre();
	int n, x;
	cin >> n >> x;
	int ans = 0;
	f[0][0] = 1;
	g[0] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 2 * i; j >= 0; j--)
			for(int k = 1; k <= 2; k++) if(j - k >= 0){
				f[i][j] = add(f[i][j], f[i - 1][j - k]);
				g[j] = add(g[j], g[j - k]);
			}
	}

	for(int i = 0; i <= n; i++)
		for(int j = 2; j <= 2 * n; j++) f[i][j] = add(f[i][j - 2], f[i][j]);

	// total sum < x
	for(int i = 0; i < x; i++) ans = add(ans, g[i]);
	for(int t = 2; t + 1 <= n; t++){
		for(int m = 0; m + t + 1 <= n; m++){
			int mn = (t + 1) >> 1;
			int mx = t - 1;
			if(x - 2 * mn - 2 >= 0)
				ans = add(ans, mul(C(n, m + t + 1), getSum(m, max(0, x - 2 * (mx + 1)), x - 2 * (mn + 1))));
		}
	}
	if((x & 1)){
		// all 2's
		for(int t = (x + 1) / 2; t <= n; t++) ans = add(ans, C(n, t));
	}
	cout << ans;
}

Measured memory_bytes: 70784
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] nm = sc.intarr;
            int n = nm[0];
            int m = nm[1];
            var list = new List<List<int>>();

            int count = 0;

            for(int i=0; i<n; i++)
            {
                list.Add(sc.intarr.ToList());
            }

            int[] check = new int[m];

            foreach(var array in list)
            {
                for(int i=1; i<=array[0]; i++)
                {
                    check[array[i]-1]++;
                }
            }

            foreach(var elm in check)
            {
                if(elm == n)
                {
                    count++;
                }
            }

            wr.wri(count);
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
loop {
	t = gets
	if t == nil
		break
	end

	t = t.split(",")
	dist = []

	dist[0] = 0.0
	10.times do |i|
		dist[i+1] = dist[i] + t[i].to_f
	end
	v1 = t[10].to_f
	v2 = t[11].to_f
	v = v1 + v2
	d = v1.to_f * dist[10].to_f / v.to_f

	11.times do |i|
		if dist[i].to_f >= d
			puts i
			break
		end
	end
}

Measured memory_bytes: 6112
#include<cstdio>
#include<cstring>
using namespace std;

int main(){

    char s[200005];
    scanf("%s",s);
    int length=strlen(s);
    bool fa=1;
    int be,en;
    for(int i=0;i<length;i++){
        if(s[i]=='A'&&fa) be=i,fa=0;//找第一个a，找到了fa改变
        if(s[i]=='Z') en=i;
    }
    printf("%d\n",en-be+1);
    return 0;
}


Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	vector<vector<int>>mp(1000011, vector<int>(26, 0));
	cin >> N;
	vector<string>s(N);
	vector<string>t(N);
	vector<int>p(N);
	vector<vector<int>>edge(1000011, vector<int>(26, -1));
	vector<int>node(1000011);
	int nx = 1;
	vector<int>parent(1000011, -1);
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		t[i] = s[i];
		reverse(t[i].begin(), t[i].end());
		t[i].pop_back();
		int st = 0;
		for (auto j : t[i]) {
			if (edge[st][j - 'a'] == -1) {
				edge[st][j - 'a'] = nx;
				parent[nx] = st;
				st = nx;
				nx++;
			}
			else {
				st = edge[st][j - 'a'];
			}
		}
		node[st] = 1;
		p[i] = st;
	}
	for (int i = 0; i < N; i++) {
		mp[p[i]][s[i][0] - 'a']++;
	}
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		int cn = p[i];
		vector<int>box(26);
		box[s[i][0] - 'a']=1;
		int idx = 1;
		while (cn) {
			cn = parent[cn];
			box[s[i][idx] - 'a'] = 1;
			idx++;
			if (node[cn]) {
				for (int j = 0; j < 26; j++) {
					if(box[j])ans += mp[cn][j];
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 289836
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int>l(n), r(n);
	for (int i = 0; i < n; i++)cin >> l[i] >> r[i];
	cout << abs(accumulate(l.begin(), l.end(), 0) - accumulate(r.begin(), r.end(), 0)) + n << endl;
}

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

int main(){
    string s;cin>>s;
    int ans = 0;
    rep(i,4)if(s[i]=='2')ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingDeque;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			
			double ans = Integer.MAX_VALUE;
			int number = -1;
			for(int i = 0; i < N; i++){
				final int n = sc.nextInt();
				final double l = sc.nextInt() / 100.0;
				final double w = sc.nextInt();
				
				final double bmi = w / (l*l);
				
				if(Math.abs(22 - bmi) < Math.abs(22 - ans)){
					ans = bmi;
					number = n;
				}
			}
			
			System.out.println(number);
		}
		
	}

}

Measured memory_bytes: 12000