akhauriyash/Code-Regression huggingface dataset:
N, A, B = list(map(int, input().strip().split()))

count = 0
for n in range(N+1):
  d1 = n//10**4
  d2 = (n-d1*10**4)//10**3
  d3 = (n-d1*10**4-d2*10**3)//10**2
  d4 = (n-d1*10**4-d2*10**3-d3*10**2)//10
  d5 = n%10

  if (A <= d1 + d2 + d3 + d4 + d5) and (B >= d1 + d2 + d3 + d4 + d5):
    count += d1*10**4 + d2*10**3 + d3*10**2 + d4*10 + d5
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <set>
#define ll long long
using namespace std;

int main() 
{
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n), min_cost(n, 1 << 30);
    for(ll i = 0; i < n; i++) {
        cin >> h.at(i);
    }

    min_cost.at(0) = 0;
    for(ll i = 1; i < n; i++) {
        for(ll j = 1; j <= k; j++) {
            if(i - j >= 0) {
                min_cost.at(i) = min(min_cost.at(i), min_cost.at(i - j) + abs(h.at(i) - h.at(i - j)));
            }
        }
    }

    cout << min_cost.at(n - 1) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main() {
    int a, b;

    cin >> a >> b;

    string result;
    if (a < b) {
        result = "a < b";
    } else if (a == b) {
        result = "a == b";
    } else {
        result = "a > b";
    }

    cout << result << endl;

    return 0;
}




Measured memory_bytes: 3204
"""Minimum cost Sort."""

def min_cost_sort(A):
    """Sort list A in ascending order.
 
    And return the switching cost in sorting.
    """
    B = list(A)
    B.sort()
    cost = 0
    min_w = B[0]
    for i, b in enumerate(B):
        tmp_cost = 0
        bi = A.index(b)
        cnt = 0
        while bi != i:
            cnt += 1
            st = B[bi]
            si = A.index(st)
            tmp_cost += b + st
            A[bi], A[si] = st, b
            bi = si
        if cnt:
            dec = cnt * (b - min_w)
            inc = 2 * (min_w + b)
            if dec < inc:
                cost += tmp_cost
            else:
                cost += tmp_cost - dec + inc
    return cost


n = input()

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

ans = min_cost_sort(A)

print(ans)

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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String _s = sc.next();
    char[] t = sc.next().toCharArray();
    _s += _s;
    char[] s = _s.toCharArray();
    int N = s.length;
    int M = t.length;
    for(int i = 0; i < N; i++){
      s[i] -= 'a';
    }
    for(int i = 0; i < M; i++){
      t[i] -= 'a';
    }
    int[][] map = new int[N][26];
    for(int[] is : map){
      Arrays.fill(is, Integer.MAX_VALUE / 3);
    }
    for(int i = 0; i < N; i++){
      map[i][s[i]] = 0;
    }
    for(int i = 0; i < 26; i++){
      for(int j = N - 1; j >= 0; j--){
        map[j][i] = Math.min(map[j][i], map[(j + 1) % N][i] + 1);
      }
    }
    
    for(int i = 0; i < 26; i++){
      for(int j = 0; j < N; j++){
        if(map[j][i] == 0){
          map[j][i] = map[(j + 1) % N][i] + 1;
        }
      }
    }
    
    long ans = 0;
    int idx = N/2 - 1;
    if(map[N/2 - 1][t[0]] > Integer.MAX_VALUE / 5){
      System.out.println(-1);
      return;
    }
    ans += map[N/2 - 1][t[0]];
    idx += map[N/2 - 1][t[0]];
    idx %= N/2;
    for(int i = 1; i < M; i++){
      if(map[idx][t[i]] > Integer.MAX_VALUE / 5){
        System.out.println(-1);
        return;
      }
      ans += map[idx][t[i]];
      idx += map[idx][t[i]];
      idx %= N/2;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 56976
import java.util.Scanner;

 class Main {

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    public static long divisibleBy(long a, long b, long num){
        long from,to;
        if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num;

        to = b/num;
        return to-from;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long c= in.nextLong();
        long d = in.nextLong();

        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        long lcm= (c*d)/gcd(c,d);
        long nums = b-a+1;
        long divisibleByC = divisibleBy(a,b,c);
        long divisibleByD = divisibleBy(a,b,d);
        long divisibleByLCM = divisibleBy(a,b,lcm);

        long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM);
        System.out.println(ans);

    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;

  for ( int i = 0; i < n; ++i ) {
    if ( (i + 1) == k ){
      cout << (char)tolower(s[i]);
    }else{
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

class B105 {
public:
    int get(int n){
        int res = 0;
        rep(i, 1, n){
            if(n%i==0) ++res;
        }
        return res;
    }
	void solve(std::istream& in, std::ostream& out) {
		int n; in >> n;
        int res = 0;
		rep(i, 1, n){
            if(i&1 and get(i) == 8) ++res;
        }
        out << res;
	}
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	B105 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
//ITP1_7_B
//????????????  45???

using System;
using System.Collections.Generic;

class ITP1_7_B
{
    static void Main(string[] args)
    {

        int count = 0;
        int[] result = new int[100];

        while (true)
        {
            int[] st = Array.ConvertAll<string, int>((Console.ReadLine().Split(' ')), delegate (string value)
            {
                return int.Parse(value);
            });

            if (st[0] == 0 && st[1] == 0)
                break;
            else
                result[count++] = judge(st[0], st[1]);

        }

        for (int i = 0; i < count; i++)
            Console.WriteLine(result[i]);

    }

    private static int judge(int n, int x)
    {
        int ans = 0;

        for(int i = 1;i <= n; i++)
        {
            for(int j = i + 1;j <= n; j++)
            {
                for(int k = j + 1;k <= n; k++)
                {
                    if (x == k + j + i)
                        ans++;
                }
            }    
        }

        return ans;
    }
}

Measured memory_bytes: 9060
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define ub             upper_bound
#define fi             first
#define mp             make_pair
#define vll            vector<ll>
#define se             second
#define mod            1000000007
#define endl            "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)       for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)       {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}


int main()
{
   ll t=1;
 // cin>>t;
   while(t--)
   { ll d,t,s;
     ll n,i,j;
    long long sum=0,ans=0;

     cin>>n;
     vll v(n);
     inp(v,n);
     for(i=0;i<n;i++)
     {
        sum+=v[i];
     }
     for(i=0;i<n;i++)
     { sum-=v[i];
       ans+=(((v[i]%mod)*(sum%mod))%mod);

     }
     cout<<(ans%mod)<<endl;

   }
   return 0;
}


Measured memory_bytes: 4836
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,W,H;
string S[200];

int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>H>>W;
    cout<<(N-H+1)*(N-W+1)<<endl;
    
}


Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
ans = "Yes"
tmp = A[0]
for a in A[1:]:
    tmp ^= a
if tmp == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)


Measured memory_bytes: 14100
#include <stdio.h>

int main(void)
{
  int a,b,c,d;
  int damage_T=0;
  int damage_A=0;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  for(int i=1;i<1000;i++){
    damage_A += b;
    if(damage_A >= c){
      printf("Yes\n");
      break;
    }
    damage_T += d;
    if(damage_T >= a){
      printf("No\n");
      break;
    }
  }
  return 0;
}


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

int main()
{
	int nNum = 0;
	cin >> nNum;
	int nProfit = INT_MIN, nInprice = INT_MAX;
	int nTemp = 0;
	for (int i = 0; i < nNum; ++i)
	{
		cin >> nTemp;
		nProfit = max(nProfit, nTemp - nInprice);
		nInprice = min(nInprice, nTemp);
	}
	cout << nProfit << endl;
	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000000;

int main(){
  int H,W;
  int h,w;
  cin >> H >> W;
  cin >> h >> w;

  int all = H * W;
  all -= h * W;
  all -= (H - h) * w;

  cout << all << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

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

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

void enqueue(P x){
    Q[tail]=x;
    tail=(tail+1)%LEN;
}

P dequeue(){
    P x=Q[head];
    head=(head+1)%LEN;
    return x;
}

int min(int a,int b){return a<b ? a: b;}

int main(){
    int elaps=0,c;
    int i,q;
    P u;
    scanf("%d %d",&n,&q);
    for(i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head=1;tail=n+1;
    
    while(head!=tail){
        u=dequeue();
        c=min(q,u.t);
        u.t-=c;
        elaps +=c;
        if(u.t>0)enqueue(u);
        else{
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}


Measured memory_bytes: 11936
#include <stdio.h>

int main(void)
{int a,b,c,i;
	i=0;
	scanf("%d %d %d",&a,&b,&c);
	for(a;a<=b;a++){
	if(c%a==0)
	i=i+1;
	else
	i=i;
	}
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 596
//
// Created by 李青坪 on 2018/11/7.
//

#include <cstdio>
#include <algorithm>
#include <set>

#define MAXN 100
#define INFINITY 1<<21
#define NIL -1
using namespace std;

int n;
int graph[MAXN][MAXN];
int d[MAXN];
int parent[MAXN];
set<int> S;
set<int> V_S;

void init(){
    S.insert(0);
    for (int j = 1; j < n; ++j) {
        V_S.insert(j);
    }
    fill(d, d+n, INFINITY);
    d[0] = 0;
    for (int k = 1; k < n; ++k) {
        d[k] = graph[0][k];
        parent[k] = 0;
    }
    fill(parent, parent+n, NIL);
}

int findMinEdge(){
    int min = INFINITY;
    int u = NIL;
    set<int>::iterator it;
    for (it = V_S.begin(); it != V_S.end(); ++it){
        if (min > d[*it]){
            min = d[*it];
            u = *it;
        }
    }
    return u;
}

void updateMinWeight(int u){
    set<int>::iterator it;
    for (it = V_S.begin(); it != V_S.end(); ++it){
        if (d[u] + graph[u][*it] < d[*it]){
            d[*it] = d[u]  + graph[u][*it];
            parent[*it] = u;
        }
    }
}

void dijkstra(){
    while (!V_S.empty()){
        int u = findMinEdge();
        S.insert(u);
        V_S.erase(V_S.find(u));
        updateMinWeight(u);
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        fill(graph[i], graph[i]+n, INFINITY);
    }
    int u, k;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        int v, w;
        for (int j = 0; j < k; ++j) {
            scanf("%d %d", &v, &w);
            graph[u][v] = w;
        }
    }
    init();
    dijkstra();
    for (int l = 0; l < n; ++l) {
        printf("%d %d\n", l, d[l]);
    }
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
 */


Measured memory_bytes: 2852
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[100][100],color[100],d[100],f[100],t;
void depthfv(int);
void depth(void);
int main(){
  int i,j,k,l,m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&k,&l);
    k--;
    for(j=0;j<l;j++){
      scanf("%d",&m);
      m--;
      M[k][m]=1;
    }
  }
  depth();
  return 0;
}
void depthfv(int u){
  int i;
  color[u]=GRAY;
  d[u]=++t;
  for(i=0;i<n;i++){
    if(M[u][i]==0)continue;
    if(color[i]==WHITE){
      depthfv(i);
    }
  }
  color[u]=BLACK;
  f[u]=++t;
}
void depth(){
  int i;
  for(i=0;i<n;i++)color[i]=WHITE;
  t=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE)depthfv(i);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}



Measured memory_bytes: 2108
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int x,y,z; cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " "  << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1 << 18;
const int MAXL = 1e5 + 7;
int v[MAXN], w[MAXN], dep[MAXN];
int dp[(1 << 9) + 7][MAXL];
int main() {
    int bound = 9;
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) dep[i] = dep[i / 2] + 1;
    for (int i = 1; i <= n; i++) scanf("%d %d", &w[i], &v[i]);
    for (int i = 1; i <= n && dep[i] <= bound; i++) {
        for (int j = 0; j < MAXL; j++) {
            dp[i][j] = dp[i / 2][j];
            if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            if (j >= v[i]) dp[i][j] = max(dp[i][j], dp[i / 2][j - v[i]] + w[i]);
        }
    }
    int q; scanf("%d", &q);
    while (q--) {
        int u, L; scanf("%d %d", &u, &L);
        vector<int>vec;
        if (dep[u] <= bound) {
            printf("%d\n", dp[u][L]);
            continue;
        }
        while (dep[u] > bound) {
            vec.push_back(u);
            u /= 2;
        }
        int sz = vec.size();
        int ans = 0;
        for (int s = 0; s < (1 << sz); s++) {
            int sumw = 0, sumv = 0;
            for (int i = 0; i < sz; i++) if (s >> i & 1) sumv += v[vec[i]], sumw += w[vec[i]];
            if (L >= sumv) ans = max(ans, sumw + dp[u][L - sumv]);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 206488
#include <stdio.h>
#include <stdlib.h>
#define M 100
void bubbleSort(int *A,int N);
int main(){
  int N;
  int i;
  int A[M];
  scanf("%d",&N);
  if(N < 1 || N > M) exit(1);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]< 0 || A[i] > 100) exit(2);
  }
  bubbleSort(A,N);
  return 0;
}

void bubbleSort(int *A,int N){
  int i,j;
  int flag;
  int temp;
  int c=0;
  flag = 1;
  
  while(flag){
    flag = 0;
    for(j = N-1;j>=1;j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp; 
	c++;
	flag = 1;
      }
    }
  }
  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",c);
}



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

int main() {
    int k, x;
    cin >> k >> x;
    for (int i = 0; i < k; i++) {
        cout << x-k+i+1 << ' ';
    }
    for (int i = 1; i < k; i++) {
        cout << x+i;
        if (i != k-1) cout << ' ';
    }
    cout << endl;
}

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

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

  map<int, int64_t> data;
  int a_buf;
  int64_t b_buf;
  for(int i=0; i<N; i++){
    cin >> a_buf >> b_buf;
    if(data.count(a_buf)){
      data.at(a_buf)+= b_buf;
    }
    else{
      data[a_buf]= b_buf;      
    }
  }
  
  int64_t N_tmp= 0;
  for(auto e:data){
    int a; int64_t b;
    tie(a,b)= e;
    N_tmp+= b;
    if(N_tmp >= K){
      cout << a << endl;
      break;
    }
  }
}

Measured memory_bytes: 4224
#include<stdio.h>

int main(){
  int i;
  int n;
  int a,b,c;
  while(scanf("%d", &n), n!=0){
    for(i=0; i<n; i++){
      scanf("%d %d %d", &a,&b,&c);
      if(a==100||b==100||c==100){ 
	puts("A"); continue;
      }
      else if((a+b)/2>=90){
	puts("A"); continue;
      }
      else if((a+b+c)/3>=80){
	puts("A"); continue;
      }
      else if((a+b+c)/3>=70){
	puts("B"); continue;
      }
      else if((a+b+c)/3>=50&&(a>=80||b>=80)){
	puts("B"); continue;
      }
      else 
	puts("C"); continue;
    }
  }

  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cstdio>

int main(int argc, char* argv[])
{
  int N;
  std::cin >> N;

  int max_num = N / 4;

  std::string judge = "No";
  for (int i = 0; i <= max_num; i++) {
    if ((N - i * 4) % 7 == 0) {
      judge = "Yes";
    }
  }

  std::cout << judge << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define esc(ret) cout << (ret) << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) ((a) & 1 == (b) & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int mod = 1e9 + 7;
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll N; cin >> N;
	ll tmp,N2 = N;
	prique<ll> que;
	rep(i,N){
		cin >> tmp; que.push(tmp);
	}
	while((tmp = que.top()) >= N2){
		que.pop();
		ll d = (tmp - N2) / N + 1;
		//cout << tmp << ' ' << d << endl;
		que.push(tmp - d * (N + 1));
		N2 -= d;
	}
	esc(N - N2);
}



Measured memory_bytes: 256
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const s: string = tmp.shift().split(" ")[0];
    for (let i = 0, len = (s.length - 1) / 2; i < len; i++) {
      if (s.charAt(i) != s.charAt(s.length - 1 - i)) {
        return "No";
      }
    }
    const sh: string = s.substr(0, (s.length - 1) / 2);
    for (let i = 0, len = (sh.length - 1) / 2; i < len; i++) {
      if (sh.charAt(i) != sh.charAt(sh.length - 1 - i)) {
        return "No";
      }
    }
    return `Yes`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 11468
import sys

def main():
    input = sys.stdin.readline
    A = list(map(int, input().split()))

    wat1 = A[0] * 100
    wat2 = A[1] * 100
    sug1 = A[2]
    sug2 = A[3]
    max_conc = A[4]
    max_volume = A[5]
    max_suger = max_conc * max_volume // 100

    W = set()
    for i in range(31):
        for j in range(31):
            w = wat1 * i + wat2 * j
            if w <= max_volume:
                W.add(w)

    S = set()
    for i in range(max_suger):
        for j in range(max_suger):
            s = sug1 * i + sug2 * j
            if s <= max_volume:
                S.add(s)

    vol = 0
    suger = 0
    conc = 0
    for w in W:
        if w == 0:
            continue
        for s in S:
            cur_conc = s / (w / 100)
            if cur_conc > max_conc:
                continue

            cur_conc = 100 * s / (w + s)
            if cur_conc >= conc and w+s <= max_volume:
                conc = cur_conc
                vol = w + s
                suger = s

    print(vol, suger)


if __name__ == '__main__':
    main()


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

//ライブラリ始まり

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  long long ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//ライブラリ終わり
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int ans = 700;
  string S;
  cin >> S;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'o') {
      ans += 100;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
string s;
int L[26]={};
int main(){
  cin >> s;
  for(int i=0;i<s.size();i++){
    L[s[i]-'a']++;
  }
  for(int i=0;i<26;i++){
    if(L[i]==0){
      char ans = i + 'a';
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $a = $sc->nextInt();
  $b = $sc->nextInt();
  $c = $sc->nextInt();
  $x = $sc->nextInt();

//  $a = array();
//  for ($i = 0; $i < $n; $i++) {
//    $a[] = $sc->nextInt();
//  }


} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $a = 30;
  $b = 40;
  $c = 50;
  $x = 6000;


}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

for ($i = 0; $i <= $a; $i++) {
  for ($j = 0; $j <= $b; $j++) {
    for ($k = 0; $k <= $c; $k++) {
      if ($i * 500 + $j * 100 + $k * 50 == $x) { $ans++; }
    }
  }
}


//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


Measured memory_bytes: 3700
import sys

def main():
    N = int(input())

    i = 0
    S = []
    while i < N:
        S.append(list(str(input())))
        i += 1
    if N == 1:
        ans = sorted(S[0])
        print(''.join(ans))
        sys.exit()

    i = 0
    while i < N - 1:
        sset = set(S[i]) & set(S[i+1])
        i += 2

    ans = []
    for a in sset:
        i = 0
        n = []
        while i < N:
            n.append(S[i].count(a))
            i += 1
        small = min(n)
        ans.append(a * small)

    ans.sort()
    print(''.join(ans))

main()


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

using namespace std;

int main() {
	int m1,d1,m2,d2;
	int check;
	cin >> m1 >> d1;
	cin >> m2 >> d2;
	switch(m1) {
		case 4:
		case 6:
		case 9:
		case 11:
			check = 30;
			break;
		case 2:
			check = 2;
			break;
		case 1:
		case 3:
		case 5:
		case 7:
		case 10:
		case 12:
			check = 31;
			break;
	}
	if((check == 30 && d1 == 30)||(check == 2 && d1 == 28 ) || (check == 31 && d1 == 31)){
		cout << "1";
	}else{
		cout << "0";
	}
	return 0;
}



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

int main(){
    int a,b;
    cin >> a >> b;
    ll ans = ll(a)*b / __gcd(a,b);
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int a,b;
  int total;
  cin >> a >>b;
  if(a==0)total = 1;
  else if (a==1) total = 100;
  else if (a==2) total = 100*100;
  total *= b;
  if(a==0&&b==100)total+=1;
  if(a==1&&b==100)total+=100;
  if(a==2&&b==100)total+=10000;

  cout << total<<endl;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())

if a == b == c:
    if a % 2:
        print(0)
    else:
        print(-1)
else:
    cnt = 0
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        na = (b+c)//2
        nb = (a+c)//2
        nc = (a+b)//2
        cnt += 1
        a = na; b = nb; c = nc
    print(cnt)

Measured memory_bytes: 39888
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

struct edge{
  int to, w;
};

using graph = vector<vector<edge>>;

int main() {
  int n; cin >> n;
  graph g(n);

  REP(i, n-1){
    int u, v, w; cin >> u >> v >> w;
    --u; --v;

    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }

  vector<int> col(n, -1);
  function<void(int, int, int)> dfs = [&](int u, int bu, int d){
    if(d % 2 == 0)
      col[u] = 0;
    else
      col[u] = 1;

    for(auto e : g[u]){
      if(e.to != bu) dfs(e.to, u, d + e.w);
    }

  };

  dfs(0, -1, 0);

  for(int x : col) cout << x << endl;

  return 0;
}


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

public class Main {
    static long mod = (long) 1e9 + 7;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int m = sc.nextInt();
        long a = 0;
        for (int i = 0; i < n; i++) {
            long x = sc.nextLong();
            a = (a + x * i) % mod;
            a = (a - x * (n - 1 - i)) % mod;
            if (a < 0) a += mod;
        }
        long b = 0;
        for (int i = 0; i < m; i++) {
            long x = sc.nextLong();
            b = (b + x * i) % mod;
            b = (b - x * (m - 1 - i)) % mod;
            if (b < 0) b += mod;
        }
        out.println((a * b) % mod);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 54140
#include<cstdio>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int fld[101][101],H,W,ans,what;
char c;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void dfs(int y,int x,int fl){
    if(fld[y][x]!=fl||x<0||y<0||x>W-1||y>H-1)return;
    fld[y][x]=0;
    for(int i=0;i<4;i++){
        dfs(y+dy[i],x+dx[i],fl);
    }
}
signed main(){
    for(;;){
        cin>>H>>W;
        if(H==0&&W==0)break;
        ans=0;
        fill(fld[0],fld[0]+101*101,0);
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>c;
                if(c=='@')fld[i][j]=1;//????????´
                if(c=='#')fld[i][j]=2;//??????
                if(c=='*')fld[i][j]=3;//?????????
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(fld[i][j]!=0){
                    ans++;
                    what=fld[i][j];
                    dfs(i,j,what);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define ford(b,a) for(int i=b;i>=a;i--)
typedef pair<int, int> pi;
#define PI 3.14159265359
#define vi vector<int>
long long mod=1000000007;
//int count=INT_MAX;
 
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
vi vis;
void dfs(vector<vi> &g,int u,int &c){
    vis[u]=1;
    c++;
    fori(0,g[u].size()){
        int v=g[u][i];
        if(!vis[v]){
            dfs(g,v,c);
        }
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcases=1;
    //cin>>testcases;
    //cout<<t;
    //scanf("%d",&t);
    //int t=testcases;
    while(testcases--){
        int n,m;
        cin>>n>>m;
        vector<vi> g(n);
        fori(0,m){
            int u,v;
            cin>>u>>v;
            u--;
            v--;
            g[u].pb(v);
            g[v].pb(u);
        }
        int ans=0;
        vis=vi(n,0);
        fori(0,n){
            if(!vis[i]){
                int c=0;
                dfs(g,i,c);
                ans=max(ans,c);
            }
        }
        cout<<ans<<endl;
    }               

    return 0;
}

Measured memory_bytes: 24216
N, M = map(int,input().split())

tg = [input() for _ in range(N)]

#tmpl0〜M-1
tmpl = [input() for _ in range(M)]

#tg0〜N-Mにつき、tmpl0を探し、一致したら同じ添字のtmpl1~M-1を探す
for i in range(0,N-M+1):
  for j in range(0,N-M+1):
    if tmpl[0] == tg[i][j:j+M]:
      if N == 1:
        print('Yes')
        exit()
      for k in range(1,M):
        if tmpl[k] != tg[i+k][j:j+M]: break
      else:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 3064
N = int(input())
x = list(map(int,input().split()))
i = 0
j = 0
k = 0
tri = 0
for i in range(0,N):
    s1 = x[i] 
    j = 0
    for j in range(i+1,N):
        s2 = x[j]
        k = 0
        if s1 != s2:
            for k in range(j+1,N):
                s3 = x[k]
                if s1 != s3 and s2 != s3:
                    sum_1 = s1 + s2
                    sum_2 = s2 + s3
                    sum_3 = s3 + s1
                    if sum_1 > s3 and sum_2 > s1 and sum_3 > s2:
                        tri += 1
print(tri)


Measured memory_bytes: 9204
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
  int N; cin >> N;
  double P[30005] = {};
  for (int i = 1; i<= N; i++)
  {
    cin >> P[i];
  }
  
  double dp[30005] = {};
  dp[0] = 1 - P[1];
  dp[1] = P[1];
  
  for (int i = 2; i <= N; i++)
  {
    double front = P[i], back = 1 - P[i];
    for (int j = N; j >= 0; j--)
    {
      dp[j + 1] += dp[j] * front;
      dp[j] *= back;
    }
  }
  
  /*
  for (int i = 0; i <= N; i++)
  {
    cout << dp[i] << " ";
  }
  cout << endl;
  return 0;
  */
  
  double ans = 0;
  for (int k = N / 2 + 1; k <= N; k++)
  {
    ans += dp[k];
  }
  
  printf("%.10f", ans);
  return 0;
}

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

int main(){
    int64_t N;
    cin >> N;
    int64_t ans = N-1;
    for(int64_t i=1; i*i<=N; i++) if(N%i == 0){
        int64_t res = i + N/i - 2;
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
'use strict';
function Main(input) {
let result = []

for (let i=0; i<input.length; i++) {
  distingish(input[i]);
}

function distingish(str) {
  switch (str) {
    case "0":
      result.push("0");
      break;
    case "1":
      result.push("1");
      break;
    case "B":
      result.pop();
      break;
  }
}

console.log(result.join(""));

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        if(n % 1000 == 0){
            System.out.println(0);
        }else{
            System.out.println(1000 - n % 1000);
        }
    }
}


Measured memory_bytes: 35728
N, K = gets.split.map(&:to_i)
DIV = 998244353
s = []
K.times do
  s << gets.split.map(&:to_i)
end
dpsum = Array.new(N + 1, 0)
dpsum[1] = 1
dp = nil
(2..N).each do |i|
  dp = 0
  s.each do |s_i|
    l, r = s_i
    i_l = i - r
    i_l = 1 if i_l < 1
    i_r = i - l
    next if i_r < 1
    dp += dpsum[i_r] - dpsum[i_l - 1]
    dp = dp % DIV
  end
  dpsum[i] = dpsum[i - 1] + dp
  dpsum[i] = dpsum[i] % DIV
end
puts dp

Measured memory_bytes: 15872
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
	int n;
	cin>>n;
	
	
	if(n%1000==0)
	{
		cout<<0;
	}
	else
	{
		cout<<1000-(n%1000);
	}
	return 0;
}

Measured memory_bytes: 3648
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main() {
    let a:usize;
    let b:usize;
    input!(a,b);
    println!("{}",a*b-(a+b-1));
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S=="SAT"){
    cout << "1";
  }else if(S=="FRI"){
    cout << "2";
  }else if(S=="THU"){
    cout << "3";
  }else if(S=="WED"){
    cout << "4";
  }else if(S=="TUE"){
    cout << "5";
  }else if(S=="MON"){
    cout << "6";
  }else if(S=="SUN"){
    cout << "7";
  }
  return(0);
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

signed main() {
  int n;
  cin >> n;

  vec<int> v;
  rep (i, 1000) {
    v.push_back(n);
    if (n % 2 == 0) {
      n /= 2;
    } else {
      n = 3 * n + 1;
    }
  }

  for (int i = 0; i < 1000; i++) {
    int hoge = v[i];
    for (int j = 0; j < i; j++) {
      if (v[j] == hoge) {
        cout << i + 1 << endl;
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 5e3 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	}while(isdigit(ch));
	return res * sign;
}
int n,m,a[Maxn][205],sta[205][Maxn],top[205];
ll sum[Maxn],ans,res,pre[Maxn];
int main()
{
	rg int tmp;
	cin>>n>>m;
	for(int i=1;i<n;i++)
		sum[i]=sum[i-1]+read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=read();
	for(int i=1;i<=m;i++)
	{
		sta[i][top[i]=1]=n+1;
		a[n+1][i]=Inf;
	}
	for(rg int i=n;i>=1;i--)
	{
		res=0;
		for(rg int j=1;j<=m;j++)
		{
			tmp=0;
			while(a[sta[j][top[j]]][j]<a[i][j])
			{
				pre[sta[j][top[j]]]-=a[sta[j][top[j]]][j]-tmp;
				tmp=a[sta[j][top[j]]][j];
				top[j]--;
			}
			pre[sta[j][top[j]]]-=a[i][j]-tmp;
			res+=a[i][j];
		}
		for(rg int j=i;j<=n;j++)
		{
			res+=pre[j];
			ans=max(ans,res-sum[j-1]+sum[i-1]);
		}
		for(rg int j=1;j<=m;j++)
		{
			sta[j][++top[j]]=i;
			pre[i]+=a[i][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6784
a,b = map(int,input().split())
ans = 0
if a == 1:ans += 300000
elif a == 2:ans += 200000
elif a == 3:ans += 100000
if b == 1:ans += 300000
elif b == 2:ans += 200000
elif b == 3:ans += 100000
if ans == 600000:ans += 400000
print(ans)

Measured memory_bytes: 3064
import qualified Data.Char as Ch

f "" ln = 0
f (c:cs) ln
   | d == 0 = d + f cs (ln - 1)
   | otherwise = max (d + f cs (ln - 1)) ((ln - 1) * 9 + d - 1)
   where d = Ch.ord c - Ch.ord '0'

main = do
   inp <- getLine
   let ln = length inp in print $ f inp ln


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

int main(void)
{
    double x1,x2,x3,x4,y1,y2,y3,y4,p1,p2;
    int n;
    
    cin >> n;
    
    rep(i,n)
    {
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        p1 = (y2-y1)/(x2-x1);
        p2 = (y4-y3)/(x4-x3);
        if(p1 == p2)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
	int x;
	
	while(scanf("%d",&x)!=EOF)
	{
		int a[14]={};
		a[x]++;
		for(int i=0;i<4;i++)
		{
			scanf(",%d",&x);
			a[x]++;
		}
		int c=0,z=0;
		for(int i=1;i<=13;i++)c=max(c,a[i]);
		for(int i=1;i<=13;i++)if(c==a[i])z++;
		if(c==2&&z==1)
		{
			cout<<"one pair"<<endl;
		}
		else if(c==2&&z==2)
		{
			cout<<"two pair"<<endl;
		}
		else if(c==3)
		{
			for(int i=1;i<=13;i++)
			{
				if(a[i]==2)
				{
					cout<<"full house"<<endl;
					break;
				}
				if(i==13)
				{
					cout<<"three card"<<endl;
				}
			}
		}
		else if(c==4)
		{
			cout<<"four card"<<endl;
		}
		else
		{
			bool e=false;
			for(int i=1;i<=10;i++)
			{
				bool hoge=true;
				for(int l=0;l<5;l++)
				{
					int g=i+l;
					if(g>13)
					{
						g-=13;
					}
					if(a[g]==0)hoge=false;
				}
				if(hoge==true)e=true;
			}
			if(e)cout<<"straight"<<endl;
			else cout<<"null"<<endl;
			
		}
	}
}

Measured memory_bytes: 1204
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
def shellSort(A, n):
    global cnt
    cnt = 0
    G = [1]
    while G[0] < n // 3:
        G[0:0] = [G[0] * 3 + 1]
    m = len(G)
    print(m)
    print(' '.join([str(g) for g in G]))
    for g in G:
        insertionSort(A, n, g)
    print(cnt)

n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
shellSort(A, n)
for a in A:
    print(a)



Measured memory_bytes: 45524
#include<stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int count;
	int i;
	
	count = 0;

	scanf("%d %d %d",&a,&b,&c);
	//scanf("%d",&b);
	//scanf("%d",&c);
		
	for(i = a; i<=b ; i++){
		if(c % i == 0){
		count++;
		}		
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        if(i==n-1){
            cout << v[0];
            break;
        }
        cout << v[n-i-1] << " ";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3112