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

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n < 1000) {
            System.out.printf("ABC");
        } else {
            System.out.printf("ABD");
        }
    }
}


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

int main() {
    string s;
    cin>>s;
    ll p=0;
    for(int i=0;i<s.size()/2;i++)
    {
        if(s[i]!=s[s.size()-1-i])
        p++;
    }
    cout<<p<<endl;
   	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  int s;
  cin >> n >> k >> s;
  for (int i = 0; i < k; ++i) {
    cout << s << ' ';
  }
  if (++s > 1'000'000'000) {
    s = 1;
  }
  for (int i = k; i < n; ++i) {
    cout << s << ' ';
  }
  cout << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 1280
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}

int pow(int a, int b) {
  int res = 1;
  rep(i, b) res *= a;
  return res;
}
 
class Solver {
public:
  int H, W;
  int N, K;
  int A[MAX];

  bool ng(int y, int x) {
    return y < 0 || y >= H || x < 0 || x >= W;
  }

  void solve() {
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    int cnt = 1;
    int cur = K;
    while (cur < N) {
      cur += K - 1;
      cnt += 1;
    }
    cout << cnt << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


struct Point
{
  Point() : x(0.0), y(0.0) {}
  Point(double x, double y) : x(x), y(y) {}
  Point(const Point& p) : x(p.x), y(p.y) {}
  Point operator + (const Point& p)
  {
    return Point(this->x + p.x, this->y + p.y);
  }
  Point operator - (const Point& p)
  {
    return Point(this->x - p.x, this->y - p.y);
  }
  Point operator / (const double x)
  {
    return Point(this->x / x, this->y / x);
  }
  Point operator * (const double x)
  {
    return Point(this->x * x, this->y * x);
  }
  double x, y;
};

vector<Point> vp;

void KochCurve(int n)
{
  vp.push_back(Point(0, 0));
  vp.push_back(Point(100, 0));
  rep (i, n)
    {
      int ss = vp.size();
      rep (j, ss - 1)
      {
	Point p1 = vp[4 * j];
	Point p2 = vp[4 * j + 1];
	Point s = (p1 * 2 + p2) / 3;
	Point t = (p1 + p2 * 2) / 3;
	Point u = Point( ((t - s).x - sqrt(3) * (t - s).y) / 2, (sqrt(3) * (t - s).x + (t - s).y) / 2 ) + s;
	vp.insert(vp.begin() + 4 * j + 1, s);
	vp.insert(vp.begin() + 4 * j + 2, u);
	vp.insert(vp.begin() + 4 * j + 3, t);
      }
    }
}

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

    int n;
    cin >> n;

    KochCurve(n);

    cout << setprecision(10);
    rep (i, vp.size())
    {
      cout << vp[i].x << " " << vp[i].y <<  "\n";
    }

    return 0;
}




Measured memory_bytes: 3388
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

signed main(void) {
  string S;
  cin >> S;
  int N = S.length();

  int ans = 0;
  int red = 0;
  int blue = 0;
  rep(i, N) {
    if (S[i] == '0') {
      red++;
    } else if (S[i] == '1') {
      blue++;
    }
  }

  ans = min(red, blue) * 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int CountCandiesNumToGet(vector<vector<int> > map, int i) {
    int candiesToGet = 0;
    
    for (int j = 0; j <= i; j++)
    {
        candiesToGet += map.at(0).at(j);
    }

    for (int j = i; j < map.at(0).size(); j++)
    {
        candiesToGet += map.at(1).at(j);
    }
    // cout << candiesToGet << " ";
    return candiesToGet;
}

int main() {
    int width;
    cin >> width;
    vector<vector<int> > map(2, vector<int>(width));

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < width; j++)
        {
            cin >> map.at(i).at(j);
        }
    }

    int maxCandiesToGet = 0;
    for (int i = 0; i < width; i++)
    {
        int candiesToGet = CountCandiesNumToGet(map, i);
        // スコープの外で宣言している変数をもう一度宣言できる（仕様おかしい...）
        maxCandiesToGet = max(maxCandiesToGet, candiesToGet);
    }
    cout << maxCandiesToGet << endl; 
}   

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        double num = 0.006;
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();
        int T = sc.nextInt();
        int A = sc.nextInt();
        sc.nextLine();
        int num2 = Integer.MAX_VALUE;
        int tmp;
        int ans = 0;
        for(int i = 0; i < N; i++){
            tmp = sc.nextInt();
            tmp = T*1000 - tmp*6;
            tmp = Math.abs(A*1000 - tmp);
            if(tmp < num2){
                num2 = tmp;
                ans = i+1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
 
using namespace std;
 
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
 
void insertionSort(int A[],int n,int g) {
    for(int i=g;i<n;i++) {
        int v = A[i];
        int j = i - g;
        while(j>=0 && A[j] >v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}
 
void shellSort(int A[], int n) {
    for(int h=1; ;) {
        if(h>n) break;
        G.push_back(h);
        h = 3*h + 1;
    }
     
    for(int i=G.size()-1; i>=0; i--) {
        insertionSort(A, n, G[i]);
    }
}
 
int main(void) {
    cin >> n;
    for(int i=0; i<n; i++) scanf("%d",&A[i]);
    cnt = 0;
 
    shellSort(A,n);
     
    cout << G.size() << endl;
    for(int i=G.size()-1; i>=0; i--) {
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
    for(int i=0;i<n;i++) printf("%d\n",A[i]);
     
    return 0;
}

Measured memory_bytes: 7216
N,M,X = list(map(int,input().split()))


a = list(map(int,input().split()))

cntm = 0
cntp = 0

for i in range(M):
    if X < a[i]:
        cntm += 1

    else:
        cntp += 1


if cntm < cntp:
    print(cntm)

else:
    print(cntp)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
ll six[10], nine[10];
int dp[100010];
int main() {
	int n;
	cin >> n;
	rep(i,10) {
		six[i] = (ll)pow(6,i+1);
		nine[i] = (ll)pow(9,i+1);
	}

	rep(i,n+1) dp[i] = INF;
	dp[0] = 0;
	rep(i,n+1) {
		rep(j,10) {
			if (six[j] > i) continue;
			dp[i] = min(dp[i], dp[i-six[j]])+1;
		}
		rep(j,10) {
			if (nine[j] > i) continue;
			dp[i] = min(dp[i],dp[i-nine[j]]+1);
		}
		if (i > 0) dp[i] = min(dp[i], dp[i-1]+1);
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    ll dist[n+1];
    ll a[m],b[m],c[m];
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        c[i]=-c[i];
    }
    for(int i=1;i<=n;i++){
        dist[i]=inf;
    }
    dist[1]=0;

    for(int t=0;t<n-1;t++){
        for(int i=0;i<m;i++){
            if(dist[a[i]]==inf)
                continue;
            if(dist[b[i]]>dist[a[i]]+c[i]){
                dist[b[i]]=dist[a[i]]+c[i];
            }
        }
    }

    ll ans=dist[n];

    bool negative[n+1];
    for(int i=1;i<=n;i++){
        negative[i]=false;
    }

    for(int t=0;t<n;t++){
        for(int i=0;i<m;i++){
            if(dist[a[i]]==inf)
                continue;
            if(dist[b[i]]>dist[a[i]]+c[i]){
                dist[b[i]]=dist[a[i]]+c[i];
                negative[b[i]]=true;
            }
            if(negative[a[i]]==true)
                negative[b[i]]=true;
        }
    }

    if(negative[n])
        cout<<"inf"<<endl;
    else
        cout<<-ans<<endl;
    return 0;
}


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

using namespace std;
#define int long long
#define N 666666
struct str{
	int vis[66];
}st[N];
signed main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		for(int j=0;j<s.size();j++){
			st[i].vis[s[j]-'a']++;
		}
	}
	for(int i=0;i<26;i++){
		int minx=st[0].vis[i];
		for(int j=1;j<n;j++) minx=min(minx,st[j].vis[i]);
		for(int j=0;j<minx;j++) cout<<(char)('a'+i);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String input1 = sc.nextLine();
	    String input2 = sc.nextLine();
		String before = input2.substring(0, input2.length()-1);
		String result = input1.equals(before) ? "Yes" : "No";
	    System.out.println(result);
	}
}


Measured memory_bytes: 35560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>

using namespace std;

int ac[1000000]={0};
int pe[1000000]={0};

int main()
{
    int n, m;

    cin >> n >> m;
    int acn = 0, pen = 0;
    for(int i = 0;i < m;i++)
    {
        int p;
        string S;
        cin >> p >> S;
        if(S == "AC" && ac[p] == 0)
        {
            ac[p]=1;
            acn++;
        }
        else
        {
            if(ac[p] == 0)
            {
                pe[p]++;
            }
        }
    }
    for(int i =1;i <= n;i++)
    {
        if(ac[i]==1)
        {
            pen+=pe[i];
        }
    }

    cout << acn << " " << pen << endl;
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++)cout << c[pos] << " ";
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5 + 7;

#ifdef LOCAL
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__)
#endif

void solve(){
    int i , j , n ;

}
signed main()
{
    int tc , i ,j;
    int n;
    cin >> n;
    int sum=0;
    for(i=1 ; i<=n ; i++)
    {
        if(i%15==0 || i%5==0 || i%3==0){
        }
        else{
            sum+=i;
        }

    }
    cout << sum << endl;

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

// End of template code!
int main() 
{
    buff();
    long long n, m;
    cin >> n >> m;
    vector< long long > v(n);

    for(auto& x : v) cin >> x;

    long long ans = 0;

    for(int i = 1; i < n; ++i)
    {
        if(v[i] + v[i - 1] > m) {
            long long delta = (v[i] + v[i - 1] - m);
            ans += min(delta, v[i]); 
            v[i] -= min(delta, v[i]);
            if(v[i - 1] > m) {
                ans += (v[i - 1] - m);
                v[i - 1] = m;
            }
        }
    }

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



Measured memory_bytes: 1024
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

class Bucket {
public:
  int size;
  vector<long long> v;
  long long addSum;
  long long stageNum;
  Bucket(int n) {
    size = n;
    v.resize(n);
    addSum = 0;
    stageNum = 0;
  }
  // add a [l, r)
  void add(int l, int r, long long a) {
    if (l <= 0 && r >= size) {
      addSum += a;
    } else {
      for (int i = max(0, l); i < min(size, r); i++)
        v[i] += a;
    }
  }
  // add [l, r)
  int addStage(int l, int r, long long a) {
    if (l <= 0 && r >= size) {
      stageNum++;
      add(l, r, a);
      return size;
    } else {
      int c = 0;
      for (int i = max(0, l); i < min(size, r); i++) {
        v[i] += a + c++;
      }
      return c;
    }
  }
  long long get(int i) {
    if (stageNum > 0) {
      for (int i = 0; i < size; i++)
        v[i] += stageNum * i;
      stageNum = 0;
    }
    if (addSum > 0) {
      for (int i = 0; i < size; i++)
        v[i] += addSum;
      addSum = 0;
    }
    return v[i];
  }
};

class Buckets {
public:
  vector<Bucket> b;
  int size;
  int bsize;
  int num;
  Buckets(int n) {
    size = n;
    bsize = (n + 299) / 300;
    for (; n > 0; n -= bsize) {
      Bucket c(bsize);
      b.push_back(c);
    }
    num = b.size();
  }
  void add(int l, int r, long long a) {
    for (int i = 0; i < num; i++)
      b[i].add(l - bsize * i, r - bsize * i, a);
  }
  int addStage(int l, int r) {
    int c = 0;
    for (int i = 0; i < num; i++) {
      c += b[i].addStage(l - bsize * i, r - bsize * i, c);
    }
    return c;
  }
  long long get(int i) { return b[i / bsize].get(i - (i / bsize) * bsize); }
};

int main() {
  int n, m;
  cin >> n >> m;
  Buckets b(m);
  int base;
  long long sum = 0;
  cin >> base;
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    if (a > base) {
      b.addStage(base, a);
      sum += a - base;
    } else {
      int c = b.addStage(base, m);
      b.addStage(0, a);
      b.add(0, a, c);
      sum += m - base;
      sum += a;
    }
    base = a;
  }
  long long ma = 0;
  for (int i = 0; i < m; i++) {
    ma = max(ma, b.get(i));
  }
  cout << sum - ma << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))


def warshall_floyd(d, n):

    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

def main():
    n, m, l = LI()
    mem = [[INF for _ in range(n)] for _ in range(n)]
    for i in range(m):
        a, b, c = LI()
        mem[a-1][b-1] = c
        mem[b-1][a-1] = c
    for i in range(n):
        mem[i][i] = 0
    mem = warshall_floyd(mem, n)
    new_mem = [[INF for _ in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if mem[i][j] <= l:
                new_mem[i][j] = 1

    new_mem = warshall_floyd(new_mem, n)
    q = II()
    for i in range(q):
        s, t = LI()
        print(new_mem[s-1][t-1] - 1 if new_mem[s-1][t-1] < INF else -1)


if __name__ == '__main__':
    main()

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

int q(char x){
  if(x=='0' ||x=='1' ||x=='2' ||x=='3' ||x=='4' ||x=='5' ||x=='6' ||x=='7' ||x=='8' ||x=='9'){
    return 1;
  }
  else{
    return 0;
  }
}

int main(){
  int A,B;
  cin >> A>>B;
  int ans=0;
  string S;
  cin >> S;
  
  for(int i=0;i<A;i++){
    if(q(S[i])==0){
      ans ++;
    }
  }
  if(S[A]!='-'){
    ans ++;
  }
  for(int i=A+1;i<B+A+1;i++){
    if(q(S[i])==0){
      ans ++;
    }
  }
  
  if(ans == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
      
}

Measured memory_bytes: 256
# Setup
import sys
sys.setrecursionlimit(4100000)
n = int(input())
a = [int(i) for i in input().split()]
balls = [0] * (n+1)

for i in reversed(range(1,n+1)):
    temp = i*2
    current = 0
    while temp <= n:
        current += balls[temp]
        temp += i
    if current%2 == 0:
        if a[i-1] == 0:
            balls[i] = 0
        else:
            balls[i] = 1
    else:
        if a[i-1] == 1:
            balls[i] = 0
        else:
            balls[i] = 1
counter = 0
# if balls[1
for i in range(n):
    if balls[i+1] == 1:
        counter += 1
print(counter)
for i in range(n):
    if balls[i+1] == 1:
        print(i+1)
# print(balls)

Measured memory_bytes: 7276
import java.util.Scanner

val sc = Scanner(System.`in`)
val a = sc.nextInt()
val b = sc.nextInt()
val c = sc.nextInt()
val d = sc.nextInt()
val e = sc.nextInt()

fun main(args: Array<String>) {
    var list = mutableListOf(a, b, c, d, e)
    var tmp = 0
    var maxIdx = 0
    for (i in 0 until  list.size) {
        if (diff(list[i]) > tmp) {
            tmp = diff(list[i])
            maxIdx = i
        }
    }
    var total = 0
    for (i in 0 until list.size) {
        if (i == maxIdx) {
            total += list[maxIdx]
        } else {
            total += (list[i] + diff(list[i]))
        }
    }
    println(total)
}

fun diff(v: Int): Int {
    return if (v % 10 == 0) {
        0
    } else {
        10 - (v % 10)
    }
}

Measured memory_bytes: 31396
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2*i;
    r = 2*i+1;
    
    if(l<=H && A[l]>A[i]) largest = l;
    else largest = i;
    if(r<=H && A[r]>A[largest]) largest = r;
    
    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if(H<1) return -INFTY;
    maxv=A[1];
    A[1]=A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i,int key){
    if(key<A[i]) return;
    A[i]=key;
    while(i>1 && A[i/2]<A[i]){
        swap(A[i],A[i/2]);
        i=i/2;
    }
}

void insert(int key){
    H++;
    A[H]= -INFTY;
    increaseKey(H,key);
}

int main(){
    int key;
    char com[10];

    while(1){
        scanf("%s",com);
        if(com[0]=='e' && com[1]=='n') break;
        if(com[0]=='i'){
            scanf("%d",&key);
            insert(key);
        }else{
            printf("%d\n",extract());
        }
    }
    
    return 0;
}


Measured memory_bytes: 6616
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj,n,m,a,b,c,d,e,g,h,r,w,l;
ll num,ans;
ll x[500005],y[500005],z[500005];
bool dame,flag;
ll ok,ng;
char s[500005],t[500005];


int main(){
	cin >> x[0] >> x[1] >> x[2] >> x[3];
	sort(x,x+4);
	if(x[0] = 1 && x[1] == 4 && x[2] == 7 && x[3] == 9){
		p("YES");
	}else{
		p("NO");
	}
	return 0;
}

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

 
 
int main(){
   int N,X,T;

   cin >> N >> X >> T;

   if (N%X==0){
       cout << T*N/X << endl;
   }
   else{
       cout << (N/X)*T + T << endl;
   }
 
    return 0;
}

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

int main(){
  int x;
  int a;
  int min = 1000001;
  int max = -1000001;
  long long sum = 0;
  cin >> x;
  for (int i = 0; i < x; i++){
    cin >> a;
    sum += a;
    if(a > max){
      max = a;
    }
    if(a < min){
      min = a;
    }
  }
  cout << min << " " << max << " " << sum << endl;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int N, K;
vector<int> edge[100000];

ll rec(int cur, int prev) {
  ll res = 1;
  ll color = prev == -1 ? K - 1 : K - 2;

  rep(i, edge[cur].size()) {
    if (edge[cur][i] == prev) continue;
    res = res * rec(edge[cur][i], cur) % MOD;
    res = res * (color--) % MOD;
  }

  return res;
}

int main() {
  cin >> N >> K;
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].eb(b);
    edge[b].eb(a);
  }

  int ans = rec(0, -1) * K % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,p,q,ans=0;
vl v,kosuu(300000,0),aa;
string s1,s2;
ll solve(){
    for(ll i=n;i>0;i--){
        if(v[i-1]!=kosuu[i]){
            aa.push_back(i);
            for(ll j=1;j<sqrt(i)+0.01;j++){
                if(i%j==0){
                    if(j*j==i){
                        kosuu[j]=1-kosuu[j];
                    }
                    else{
                        kosuu[j]=1-kosuu[j];
                        kosuu[i/j]=1-kosuu[i/j];
                    }
                }
            }
        }
    }
    
    cout<<aa.size()<<endl;
    rep(i,aa.size()){
        cout<<aa[i];
        if(i!=aa.size()-1)cout<<" ";
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    input(v,n);
    solve();

}

Measured memory_bytes: 6896
#include<bits/stdc++.h>
#include<iostream>
#define ll long long
using namespace std;
const int maxn=1e6+20;
const ll mod=1000009;
//ll a[2000][2000];
ll n,m;
ll a[maxn],f[maxn];

int main()
{
    ll i,n,m,j,k,l;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        f[i]=a[i]-i;
    }
    sort(f+1,f+1+n);
    ll b=f[(n)/2+1];
    if(n%2==0)
    {
        b=(b+f[(n)/2])/2;
    }
    k=0;
    for(int i=1;i<=n;i++)
    {
        k+=abs(b-f[i]);
    }
    printf("%lld\n",k);
    return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 1;
vector <int> freq_cnt(maxN, 0);
vector <bool> visited(maxN, false);
int main() {

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        ++freq_cnt[k];
    }
    int ans = 0;
    for (int i = 1; i < maxN; ++i) {
        if (freq_cnt[i] == 0 || visited[i]) {
            continue;
        }
        if (freq_cnt[i] == 1 && !visited[i]) {
            ++ans;
        }
        for (int j = i; j < maxN; j += i) {
            visited[j] = true;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6996
//http://drken1215.hatenablog.com/entry/2019/04/03/125400

#include <iostream>
using namespace std;

// 入力
long long N;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったか, counter: 答え
void func(long long cur, int use, long long &counter){
    if (cur > N) return; // ベースケース
    if (use == 0b111) ++counter; // 答えを増やす

    // 7 を付け加える
    func(cur * 10 + 7, use | 0b001, counter);

    // 5 を付け加える
    func(cur * 10 + 5, use | 0b010, counter);

    // 3 を付け加える
    func(cur * 10 + 3, use | 0b100, counter);
}

int main() {
    cin >> N;
    long long res = 0;
    func(0, 0, res);
    cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    public class Music
    {
        public string Name = string.Empty;
        public int Length = 0;
    }


    static void Main(string[] args)
    {

        var _N = int.Parse(Console.ReadLine());
        var playList = new List<Music>();
        for(var i = 0; i < _N; i++)
        {
            var tmp = Console.ReadLine().Split();
            playList.Add(new Music
            {
                Name = tmp[0],
                Length = int.Parse(tmp[1]),
            });
        }
        var title = Console.ReadLine();
        var index = playList.FindIndex(x => x.Name == title);
        var sum = 0;
        for(var i = index + 1; i < playList.Count; i++)
        {
            sum += playList[i].Length;
        }
        Console.WriteLine(sum);
    }
}


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

int main(){
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for(int i=1; i<=N; i++){
        if(i+K-1<=N) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import collections
N = int(input())
a = list(map(int, input().split()))
numbers = []
for i in range(N):
    numbers.append(a[i])
    numbers.append(a[i] + 1)
    numbers.append(a[i] - 1)

num_count = collections.Counter(numbers)
print(max(num_count.values()))

Measured memory_bytes: 27360
// https://atcoder.jp/contests/dp/tasks/dp_h
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define infinity (ll)4e18
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    ll h, w;
    cin >> h >> w;
    ll dp[h + 1][w + 1];
    memset(dp, 0, sizeof(dp));
    char s[2000];
    for (ll i = 0; i < h; i++)
    {
        cin >> s;
        for (ll j = 0; j < w; j++)
            if (s[j] == '#')
                dp[i + 1][j + 1] = -1;
    }
    dp[0][1]++;
    for (ll i = 1; i <= h; i++)
        for (ll j = 1; j <= w; j++)
        {
            if (dp[i][j] == -1)
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    cout << dp[h][w] % mod << endl;
    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
int main(){
using namespace std;
int N;
int count = 0;
int ans;
cin >> N;

vector<int> A(N);
for(int i=0;i<N;i++)
{
cin >> A[i];
}
for(int i=0;i<N;i++){
if(A[i] % 2 == 0) count ++;
}
if(count != 0){
ans = pow(3,N) - pow(2,count);
}else{
ans = pow(3,N) - 1;
}

cout << ans << endl;
}

Measured memory_bytes: 384
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    long long n, k;
    cin >> n >> k;
    
    long long ok = 0, ng = k + 1;
    while(ng - ok > 1) {
        long long md = (ok + ng) / 2;
        ([&]{
            long long sum = 0, tmp = md;
            int cnt = 0;
            while(cnt < n && tmp > 0) {
                sum += tmp;
                tmp /= 2;
                ++cnt;
            }
            return sum <= k;
        }() ? ok : ng) = md;
    }

    cout << ok << '\n';
    return 0;

}



Measured memory_bytes: 3100
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int M; cin >> M;
	vector<ll> d(M), c(M);
	rep(i,M) cin >> d[i] >> c[i];
	ll sum = 0;
	ll keta = 0;
	rep(i,M) {
		sum += d[i]*c[i];
		keta += c[i];
	}

	cout << (sum-1) / 9 + keta - 1 << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int A, B;
  cin >> A >> B;
  if (A > 8 || B > 8)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var b = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        Array.Sort(a);
        Array.Sort(c);

        var ans = 0L;
        for (int i = 0; i < n; i++)
        {
            var x = m1(b[i], a, 0, n - 1);
            var y = n - m1(b[i] + 1, c, 0, n - 1);
            ans += x * y;
        }

        Console.WriteLine(ans);
    }

    static long m1(int n, int[] a, long x, long y)
    {
        var z = (x + y) / 2;
        if (y < x)
        {
            return x;
        }
        else if (a[z] < n)
        {
            return m1(n, a, z + 1, y);
        }
        else
        {
            return m1(n, a, x, z - 1);
        }
    }
}

Measured memory_bytes: 39044
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(), A.end()
#define MEM(a, b) memset(a, b, sizeof(a))
#define FOR(n) for (int i = 0; i < n; ++i)
#define FOR_(n) for (int i = 1; i <= n; ++i)
#define FOR_J(n) for (int j = 0; j < n; ++j)
#define FOR_J_(n) for (int j = 1; j <= n; ++j)
#define IT_FOR(A) for (auto i = A.begin(); i != A.end(); ++i)
#define INF 0x3f3f3f3f
#define N ((int)1e6)
//#define max(_a,_b) (((_a) > (_b)) ? (_a) : (_b))
//#define min(_a,_b) (((_a) < (_b)) ? (_a) : (_b))
const int mod = 1000000007;
typedef long long ll;

inline int read() {
	int x = 0, w = 1;
	char ch = 0;
	while (ch < '0' || ch > '9') {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return x * w;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("wa4.txt","w",stdout);
	int _ = 1;
	//_ = read();
	while (_--) {
		int n,k;
		int p[2000] = { 0 };
		n = read();
		k = read();
		FOR(n)
			p[i] = read();
		sort(p, p + n);
		int sum = 0;
		FOR(k)
			sum += p[i];
		cout << sum;
	}
	return 0;
}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
 
    void solve() throws IOException {
        int n = ni();
        int q = ni();
        graph= new ArrayList<>();
        for (int i = 0; i < n; i++){
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < n-1; i++) {
            int a = ni()-1;
            int b = ni()-1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        int[] point = new int[n];
        for (int i = 0; i < q; i++) {
            int p = ni()-1;
            int x = ni();
            point[p] += x;
        }
        int[]state = new int[n];
        state[0] =1;
        dfs(0,state,point);
        for (int i = 0; i < point.length; i++) {
            out.print(point[i]);
            out.print(" ");
        }
    }
    void dfs(int node, int[]state, int[]point){
        for (Integer next : graph.get(node)) {
            if(state[next] == 0){
                point[next] += point[node];
                state[next]=1;
                dfs(next, state, point);
                state[next]=0;
            }
        }
    }
    ArrayList<ArrayList<Integer>> graph;
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.flush();
        out.close();
    }
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

const int X = 4;
const int Y = 50;
const int C = 100;
int x, y, z;
int v[X+1];
double dp[Y+1][Y*C+1];
double p;

int main() {
  int i, j, k;
  while (1) {
    scanf("%d%d%d ", &x, &y, &z);
    if (!x && !y && !z) break;
    p = 1.0/(double)x; 
    for (i=0; i<x; i++) scanf("%d ", v+i);
    map<int, PII > ev;
    for (i=0; i<z; i++) {
      int n, e, a; 
      scanf("%d%d%d ", &n, &e, &a);
      ev[n] = make_pair(e, a);
    }

    memset(dp, 0.0, sizeof(dp));
    dp[0][0] = 1.0;
    for (i=0; i<y; i++)
      for (j=0; j<=y*C; j++)
        if (dp[i][j] > EPS) {
          for (k=0; k<x; k++) {
            int ni = i + v[k], nj = j;
            if (ni >= y) {
              ni = y;
            } else if (ev.find(ni) != ev.end()) {
              if (ev[ni].first == 1)
                ni = min(y, ni + ev[ni].second); 
              else if (ev[ni].first == 2)
                nj += ev[ni].second; 
              else if (ev[ni].first == 3) {
                nj -= ev[ni].second; 
                if (nj < 0) nj = 0;
              }
            }
            dp[ni][nj] += dp[i][j]*p;
          }
        }
    double res = 0.0;
    for (j=0; j<=y*C; j++)
      res += (double)j * dp[y][j];
    printf("%d\n", (int)res);
  }

	return 0;
}

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


map<char,string> l1;
map<string,char> l2;
void init(){
l1[' ']="101";
l1['\'']="000000";
l1[',']="000011";
l1['-']="10010001";
l1['.']="010001";
l1['?']="000001";
l1['A']="100101";
l1['B']="10011010";
l1['C']="0101";
l1['D']="0001";
l1['E']="110";
l1['F']="01001";
l1['G']="10011011";
l1['H']="010000";
l1['I']="0111";
l1['J']="10011000";
l1['K']="0110";
l1['L']="00100";
l1['M']="10011001";
l1['N']="10011110";
l1['O']="00101";
l1['P']="111";
l1['Q']="10011111";
l1['R']="1000";
l1['S']="00110";
l1['T']="00111";
l1['U']="10011100";
l1['V']="10011101";
l1['W']="000010";
l1['X']="10010010";
l1['Y']="10010011";
l1['Z']="10010000";


l2["00000"]='A';
l2["00001"]='B';
l2["00010"]='C';
l2["00011"]='D';
l2["00100"]='E';
l2["00101"]='F';
l2["00110"]='G';
l2["00111"]='H';
l2["01000"]='I';
l2["01001"]='J';
l2["01010"]='K';
l2["01011"]='L';
l2["01100"]='M';
l2["01101"]='N';
l2["01110"]='O';
l2["01111"]='P';
l2["10000"]='Q';
l2["10001"]='R';
l2["10010"]='S';
l2["10011"]='T';
l2["10100"]='U';
l2["10101"]='V';
l2["10110"]='W';
l2["10111"]='X';
l2["11000"]='Y';
l2["11001"]='Z';
l2["11010"]=' ';
l2["11011"]='.';
l2["11100"]=',';
l2["11101"]='-';
l2["11110"]='\'';
l2["11111"]='?';
}


string solve(string s){
  string tmp = "";
  for(int i=0;i<s.size();i++){
    tmp += l1[s[i]];
  }
  while(tmp.size()%5!=0){
    tmp += '0';
  }
  
  string res = "";
  while(tmp.size()!=0){
    res += l2[tmp.substr(0,5)];
    tmp = tmp.substr(5);
  }

  return res;
}


int main(){
  init();
  string s;
  while(getline(cin,s)){
    cout<<solve(s)<<endl;
  }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int i,s,t,n,j,sum;
int lit,fr[12],ap[12];
int d[30004];
bitset <120> aparitii;
int main()
{
   cin>>n;
   string s;
   cin>>s;
   for(i=s.size()-1;i>=0;i--){
    lit=s[i]-'0';
    if(d[i+1]!=100){
        for(j=0;j<=9;j++)
        if(fr[j]>=1)
            aparitii[lit*10+j]=1;
    }
        d[i]=aparitii.count();
    fr[lit]++;
   }
   int nrdist=0;
   for(i=0;i<n-2&&nrdist<10;i++){
    lit=s[i]-'0';
    ap[lit]++;
    if(ap[lit]>1)
        continue;
    nrdist++;
        sum+=d[i+1];
   }
   cout<<sum;
}


Measured memory_bytes: 384
import sys
#import numpy as np
#import math
from fractions import Fraction
import itertools

input=sys.stdin.readline

n,m=map(int,input().split())
v=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
c=0
for i in range(2**n):
    s=[0]*n
    for j in range(n):
        if i>>j&1==1:
            s[j]=1
        else:
            s[j]=0
    for k in range(m):
        cnt=0
        for j in v[k][1:]:
          cnt+=s[j-1]
        if cnt%2!=p[k]:
          break
    else:
        c+=1
print(c)

Measured memory_bytes: 69100
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    if (N < 1200) {
        cout << "ABC";
    } else if (N < 2800) {
        cout << "ARC";
    } else {
        cout << "AGC";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>dp;
bool f(vector<int>&A,int k)
{
    if(k<=0)
        return false;
    if(dp[k]!=-1)
        return dp[k];
    for(int i=0;i<A.size();i++)
    {
        if(k>=A[i])
        {
            if(f(A,k-A[i]))
                continue;
            return dp[k]=1;
        }
    }
    return dp[k]=0;
}

int main()
{
    
    int n,k;
    cin>>n>>k;
    vector<int>A(n);
    dp.resize(k+1,-1);
    for(int &i:A)
        cin>>i;
    if(f(A,k))
        cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 5376
using System.Collections.Generic;
using System.Text;
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(ReadLine());
        var list = new LinkedList<int>();
        for (var i = 0; i < n; i++)
        {
            var inputArr = ReadLine().Split(' ');
            switch (inputArr[0])
            {
                case "insert":
                    list.AddFirst(int.Parse(inputArr[1]));
                    break;
                case "delete":
                    list.Remove(int.Parse(inputArr[1]));
                    break;
                case "deleteFirst":
                    list.RemoveFirst();
                    break;
                case "deleteLast":
                    list.RemoveLast();
                    break;
            }
        }
        var result = new StringBuilder();
        foreach(var x in list)
        {
            result.Append(x+" ");
        }
        WriteLine(result.ToString().Trim());
    }
}


Measured memory_bytes: 69388
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)1e9+1
#define MOD (long long)1e9+7
#define INF64 (long long)1e18+1

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  //INPUT
  llint K,X;
  cin >> K >> X;

  //SOLVE
  llint ans;
  ans = X-K+1;

  //OUTPUT
  rep(i,0,2*K-1) {
    cout << ans;
    if (i!=2*K-2) {
      cout << " ";
    } else {
      cout << endl;
    }
    ans++;
  }

  return 0;
}


Measured memory_bytes: 768