akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <time.h>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);

}
class Graph {
public:
	int vn;
	int sumcost = 0;
	vector<vector<pii>> g;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	virtual void con(int a, int b, int w = 1) = 0;
	int getWeight(int f, int t) {
		auto itr = lower_bound(ALL(g[f]), make_pair(t, INT_MIN));
		if (itr != g[f].end())
			return itr->second;
		return INT_MIN;
	}
	int Costsum() {
		return sumcost;
	}
	void scan(int edcount, bool oindexed = 0) {
		REP(i, edcount) {
			int a, b;
			scanf("%d %d", &a, &b);
			con(a - oindexed, b - oindexed);
		}
	}
};
class BiDGraph : public Graph {//無向
public:
	BiDGraph(int n) : Graph(n) {}

	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		sumcost++;
	}
};

signed main() {
	int n;
	scanf("%d", &n);
	BiDGraph g(n);
	g.scan(n-1,1);

	vector<double> per(n);

	function<double(int, int)> dfs = [&](int cur, int p) {
		double ret = 0;
		for (auto itr : g.g[cur]) {
			if (itr.first == p) continue;

			ret += (1+dfs(itr.first, cur))/(double)(g.g[cur].size()-(bool)(p+1));

		}
		return per[cur] = ret;
	};

	dfs(0,-1);
	vector<double> ans(n);
	function<void(int, int, double)> dfs2 = [&](int cur, int p, double par) {
		double np = par;
		double sum = np;
		for (auto itr : g.g[cur]) {
			if (itr.first == p) continue;
			sum += per[itr.first]+1;
		}
		ans[cur] = sum / g.g[cur].size();
		for (auto itr : g.g[cur]) {
			if (itr.first == p) continue;
			sum -= per[itr.first]+1;
			dfs2(itr.first, cur, 1+ (g.g[cur].size() - 1 ? sum/(g.g[cur].size() - 1) : 0));
			sum += per[itr.first]+1;
		}
	};
	dfs2(0, -1, 0);
	ans[0] = per[0];
	REP(i, n)
		printf("%.10lf\n", ans[i]);
	return 0;
}

Measured memory_bytes: 22016
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    n=int(input())
    A=[0]*(h*w)
    idx=0
    for i,a in enumerate(map(int,input().split())):
        cnt=0
        while(cnt<a):
            A[idx]=i+1
            cnt+=1
            idx+=1

    idx=0
    for i in range(h):
        G=[0]*w
        for j in range(w):
            G[j]=A[idx]
            idx+=1
        if(i&1): G=G[::-1]
        print(*G)
resolve()

Measured memory_bytes: 41712
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

ll f(ll y,ll m,ll d){
	ll tot=y*195+y/3*5;
	if(y%3==2)tot+=m*20;
	else tot+=m*20-m/2;
	tot+=d;
	return tot;
}

int main(){
	ll n;
	scanf("%lld",&n);
	ll T=f(999,0,0);
	while(n--){
		ll y,m,d;
		scanf("%lld%lld%lld",&y,&m,&d);
		printf("%lld\n",T-f(y-1,m-1,d-1));
	}
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int b,i,cnt=0,n;
    scanf("%lld",&n);
    int a[n+5];
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
        sort(a,a+n);
    for(i=0;i<n-1;i++)
    {
        if(a[i]==a[i+1])
            cnt++;
    }
    if(cnt==0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;

}


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

using namespace std;
typedef long long ll;
typedef long double ld;
using graph = vector<vector<int>>;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define all(x) (x).begin(),(x).end()
#define size(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define pb push_back
#define mp make_pair
#define f first
#define s second

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 (b<a) { a=b; return true; } return false; }

#define FIND(a,b) find(all(a),b)!=a.end()

int main(){
	int a,b,x;cin>>a>>b>>x;
	if(a<=x&&x<=a+b)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
"""TLE
N = int(input())
sequence = list(input().split())
ans = []
for i in range(N):
    a_i = sequence[i]
    ans.append(a_i)
    ans = ans[::-1]
print(" ".join(ans))
"""

from collections import deque
n = int(input())
sequence = deque(map(int,input().split()))
ans = deque()
if n % 2 == 1:
    for i in range(n):
        if i % 2 == 0:
            ans.appendleft(sequence[0])
        else:
            ans.append(sequence[0])
        sequence.popleft()
        #print(ans)
else:
    for i in range(n):
        if i % 2 == 1:
            ans.appendleft(sequence[0])
        else:
            ans.append(sequence[0])
        sequence.popleft()
        #print(ans)
print(*ans)


Measured memory_bytes: 25540
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

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


Measured memory_bytes: 256
import Control.Monad
import Data.Array.Unboxed

main :: IO ()
main = do
  [n,q] <- map read . words <$> getLine
  s <- getLine
  lrs <- replicateM q $ (\[x,y] -> (x,y)) . map read . words <$> getLine :: IO [(Int,Int)]
  let acs = listArray (0,n-1) $ 0 : neighbour s 0 :: UArray Int Int
  forM_ lrs $ \(l,r) -> print $ acs!(r-1) - acs!(l-1)

neighbour :: String -> Int -> [Int]
neighbour [] _ = []
neighbour [_] _ = []
neighbour (x:y:xs) acc
  | [x,y] == "AC" = (acc + 1) : neighbour (y:xs) (acc + 1)
  | otherwise     = acc       : neighbour (y:xs) acc

Measured memory_bytes: 75260
N = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
List = factorization(N)
ans = 0
for i in range(len(List)):
  X = List[i][1]
  j = 1
  num = 0
  if List[i][0] != 1:
    while True:
      X -= j
      j += 1
      if X >= 0:
        num += 1
      else:
        break
    ans += num
  
print(ans)

Measured memory_bytes: 63436
n = int(input())
S = list(str(input()))
ans = 0
for i in range(1000):
    q = 0
    p = list(str(i).zfill(3))
    s = p[q]
    for j in range(len(S)):
        if s == S[j]:
            q+=1
            if q == 3:
                break
            else:
                s = p[q]
        else:
            continue
    if q == 3:
        ans += 1
print(ans)

Measured memory_bytes: 42732
l, r = gets.chop.split.map(&:to_i)
 
min_mod = 99999999
 
for i in l..r-1
  for j in i+1..r
    if min_mod > i*j % 2019
      min_mod = i*j % 2019
    end
    if min_mod == 0
      puts 0
      exit
    end
  end
end
 
puts min_mod

Measured memory_bytes: 1788
n = gets.to_i
a = gets.split.map(&:to_i)
prd = a[1]
2.upto(n - 1) do |i|
    prd ^= a[i]
end
ans = Array.new
ans.push(prd)
(n - 1).times do |i|
    prd ^= a[i] ^ a[i + 1]
    ans.push(prd)
end
puts ans * " "

Measured memory_bytes: 37440
<?php
$input = file_get_contents('php://stdin');
$inarr = explode(" ", $input);

$x = (int)$inarr[0];
$k = (int)$inarr[1];

$result = $x - $k*intdiv($x, $k);
$newResult = abs($result-$k);
if($newResult<$result){
  $result = $newResult;
}

echo $result;

?>

Measured memory_bytes: 4728
n=int(input())
dic = {}
max = 1
for i in range(n):
    s = input()
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
        if max < dic[s]:
            max = dic[s]
l = []
for i in dic.keys():
    if dic[i] == max:
        l += [i]
l.sort()
for i in l:
    print(i)

Measured memory_bytes: 91608
#include <bits/stdc++.h>
#define MAXN 200010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e18 + 7;


int main (){
    ios_base::sync_with_stdio(false);
    int x, a;
    cin >> x >> a;

    cout << (x < a? "0": "10") << endl;

    return 0;
}

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

int main(){
    int N, K, cnt=0;

    cin >> N >> K;
    rep(i, N){
        int h;
        cin >> h;
        if(h >= K) ++cnt;
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  char be = '!';
  ll cnt_r = 0, cnt_l = 0, ans = 0;
  ll cnt = 0, len_l = 0;
  if(s[0] == '>'){
    for(auto &c:s){
      if(c == '>') len_l++;
      else break;
    }
  }
  ans += len_l * (len_l+1) / 2;
  for(auto &c:s){
    cnt++;    
    if(cnt <= len_l) continue;
    if(be == '>' && c == '<'){
      ans += max(cnt_r,cnt_l) * (max(cnt_r,cnt_l)+1) / 2;
      ans += min(cnt_r,cnt_l) * (min(cnt_r,cnt_l)-1) / 2;
      cnt_r = 0;
      cnt_l = 0;
    }
    if(c == '<') cnt_r++;
    if(c == '>') cnt_l++;
    if(cnt_l == 0 && s.size() == cnt) ans += cnt_r * (cnt_r+1) / 2;
    if((be != '>' || c != '<') && s.size() == cnt && cnt_l!=0){
      ans += max(cnt_r,cnt_l) * (max(cnt_r,cnt_l)+1) / 2;
      ans += min(cnt_r,cnt_l) * (min(cnt_r,cnt_l)-1) / 2;      
    }
    be = c;
  }
  cout << ans << endl;
}


Measured memory_bytes: 900
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ; cin >> N;
    
    ll ans =0 ;
    ll before = 0;
    ll cnt = 1;
    
    rep(i, N){
        ll inp; cin >> inp;
        if(inp == before){
            cnt ++;
        }
        else{
            ans += (cnt/2);
            before = inp;
            cnt = 1;
        }
    }
    ans += (cnt/2);
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

long long int a[10000] = {0},x,y,p,j = 0,b[10000],c[10000];

int main(){

  long long int n;

  while(cin >> n, n){

    for(int i=0;i<=10000;i++) a[i] = 0;

    for(int i=0;i<n;i++){
      cin >> p >> x >> y;

      a[p] = x + y;
    }

    p = 0;

    for(int i=0;i<=10000;i++){
      if(a[0] < a[i]){
	a[0] = a[i];
	p = i;
      }
    }

    b[j] = p;
    c[j] = a[0];
    j++;
  }
  for(int i=0;i<j;i++) cout << b[i] << " " << c[i] << endl;
}

Measured memory_bytes: 1240
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
   if(a>b&&a>c){
       if(a==b+c){
           cout<<"Yes"<<endl;
       }
       if(a>b+c||a<b+c){
           cout<<"No"<<endl;
       }
   }
    if(c>b&&c>a){
       if(c==b+a){
           cout<<"Yes"<<endl;
       }
       if(c>b+a||c<b+a){
           cout<<"No"<<endl;
       }
   }
   if(b>c&&b>a){
       if(b==a+c){
           cout<<"Yes"<<endl;
       }
       if(b>a+c||b<c+a){
           cout<<"No"<<endl;
       }
   }
   if(a==b&&b==c){
       cout<<"No"<<endl;
   }
   

    
}


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

vector<vector<bool>> tree(26);

bool solve(int a,int b,int i,int j,int left,int right){
  if(b<=left||right<=a){
    return false;
  }
  if(a<=left&&right<=b){
    return tree.at(i).at(j);
  }
  bool x=solve(a,b,i,2*j+1,left,(left+right)/2);
  bool y=solve(a,b,i,2*j+2,(left+right)/2,right);
  return x||y;
}

int main(){
  int N;
  string S;
  cin>>N>>S;
  int n=1;
  while(n<N){
    n*=2;
  }
  for(int i=0;i<26;i++){
    tree.at(i).resize(2*n-1,false);
  }
  for(int i=0;i<N;i++){
    tree.at(S.at(i)-'a').at(n-1+i)=true;
  }
  for(int i=0;i<26;i++){
    for(int j=n-2;j>=0;j--){
      tree.at(i).at(j)=tree.at(i).at(2*j+1)||tree.at(i).at(2*j+2);
    }
  }
  int ans=0;
  for(int i=1;i<n;i++){
    int num=0;
    for(int j=0;j<26;j++){
      if(solve(0,i,j,0,0,n)&&solve(i,n,j,0,0,n)){
        num++;
      }
    }
    ans=max(ans,num);
  }
  cout<<ans<<endl;

}


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

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      List<long> ts = new List<long>();
      int N = int.Parse(Console.ReadLine());
      for(int i = 0; i < N; i++)
        ts.Add(long.Parse(Console.ReadLine()));

      long c = 1;
      foreach(long t in ts)
        c = GetLCM(c, t);

      Console.WriteLine(c);
      Console.ReadLine();
    }

    static long GetLCM(long a, long b)
    {
      return a / gcd(a, b) * b;
    }

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

    static long GetGCD(long a, long b)
    {
      Align(ref a, ref b);

      while(true)
      {
        long c = a % b;
        if(c == 0)
          return b;

        a = b;
        b = c;
      }
    }

    static void Align(ref long a, ref long b)
    {
      if(a >= b)
        return;

      long c = a;
      a = b;
      b = c;
    }
  }
}

Measured memory_bytes: 27844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;
NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {
      insert(key); np++; size++;
    }
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	       if ( com[6] == 'F' ) deleteFirst();
	       else if ( com[6] == 'L' ) deleteLast();
      }
      else {
	       delete(key);
         nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}


NodePointer listSearch(int key){
  /* your code */
  NodePointer cur;
  cur=nil->next;
  while((cur!=nil)&&(cur->key!=key)){
    cur=cur->next;
  }
  return cur;
}

void init(void){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  deleteNode(nil->prev);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;

  /*

   your code


  */

}



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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

int n;
vector<int> d, f;
vector<vector<int>> g;
int Time = 0;
void dfs(int v){
  d[v] = ++Time;
  REP(i, g[v].size()){
    int nv = g[v][i];
    if(d[nv] != -1) continue;
    dfs(nv);
  }
  f[v] = ++Time;
}

int main(){
  cin >> n;
  d.resize(n,-1), f.resize(n), g.resize(n);
  REP(i, n){
    int u, k;
    cin >> u >> k;
    g[i].resize(k);
    REP(j, k){
      cin >> g[i][j];
      g[i][j]--;
    }
  }
  REP(i, n){
    if(d[i] == -1){
      dfs(i);
    }
  }
  REP(i, n){
    cout << i+1 << " " << d[i] <<" " <<  f[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
from itertools import permutations

N, M = map(int, input().split())
paths = [list(map(int, input().split())) for _ in range(M)]

points = [i for i in range(1, N+1)]
answer = 0

for point in permutations(points):
  if not point[0] == 1:
    continue
  for i in range(N-1):
    if sorted([point[i], point[i+1]]) not in paths:
      break
  else:
    answer += 1

print(answer)


Measured memory_bytes: 3064
#include <stdio.h>
int main() 
{
 int n,i,j;
 int vertex,edge,next;
 int G[100][100];
 
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
	for(j=0;j<n;j++)
	{
		G[i][j] = 0;
	}
 }
 
 for(i=0;i<n;i++)
 {
 	scanf("%d%d",&vertex,&edge);
 	for(j=0;j<edge;j++)
	{
		scanf("%d",&next);
		G[i][next-1] = 1;
	}
 }

 for(i=0;i<n;i++)
 {
 	for(j=0;j<n;j++)
	{
		if(j != n-1) printf("%d ",G[i][j]);
		else printf("%d\n",G[i][j]);
	}
 }

 return 0;
}

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

int main(){
	int W,H,N;
	cin>>W>>H>>N;
	
	int x[N],y[N],a[N];
	for(int i=0;i<N;i++)
		cin>>x[i]>>y[i]>>a[i];
	
	int x0=0,x1=W,y0=0,y1=H;
	
	for(int i=0;i<N;i++){
		if(a[i]==1&&x0<x[i])
			x0=x[i];
		if(a[i]==2&&x1>x[i])
			x1=x[i];
		if(a[i]==3&&y0<y[i])
			y0=y[i];
		if(a[i]==4&&y1>y[i])
			y1=y[i];
	}
	
	if(x0<x1&&y0<y1)
		cout<<(x1-x0)*(y1-y0)<<endl;
	else
		cout<<0<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int N;

    cin >> N;

    vector<int> A;

    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A.push_back(a);
    }

    sort(A.begin(), A.end());

    int suma = 0;
    int sumb = 0;

    for(int i = N-1; i >= 0; i--){
        if(i%2 != N%2){
            suma += A[i];
        }else{
            sumb += A[i];
        }
    }

    cout << suma - sumb << endl;

    return 0;
}

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

int main(){
    while(true){
        int n;
        cin>>n;
        if(n==0)break;
        int d[n]={};
        double mid=0;
        for(int i=0;i<n;i++){
            cin>>d[i];
            mid+=d[i];
        }
        mid/=n;
        double std_2=0;
        for(int i=0;i<n;i++){
            std_2+=pow(d[i]-mid,2);
        }
        double ans=sqrt(std_2/n);
        cout<<fixed<<setprecision(8);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3208
#include<stdio.h>
int n;
int i,j,h,w;
int main(void){
	while(scanf("%d",&n)!=EOF){
		int cnt=0;
		for(i=0;i<=9;i++){
			for(j=0;j<=9;j++){
				for(h=0;h<=9;h++){
					for(w=0;w<=9;w++){
						if(n==i+j+h+w){
							cnt++;
						}
					}
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
        char s[99999];
        int i, a, b;

        scanf("%s", s);

        for(i=0; s[i]!='\0'; i++){
                if(s[i]=='0') a++;
                else if(s[i]=='1') b++;
        }
        if(a<b) printf("%d\n", a*2);
        else printf("%d\n", b*2);

        return 0;
}


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

ll solve() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0, h;
    for ( int i = 0; i < N; i++ ) {
        cin >> h;
        if ( h >= K ) ans++;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-
G - Longest Path

問題文

N頂点 M 辺の有向グラフ G があります。
頂点には 1,2,…,N と番号が振られています。
各 i (1≤i≤M) について、i 番目の有向辺は頂点 xi から yi へ張られています。
Gは有向閉路を含みません。

Gの有向パスのうち、最長のものの長さを求めてください。
ただし、有向パスの長さとは、有向パスに含まれる辺の本数のことです。

制約
    入力はすべて整数である。
    2≤ N ≤10^5
    1≤ M ≤10^5
    1≤ xi,yi ≤N
    ペア (xi,yi)はすべて相異なる。
    Gは有向閉路を含まない。

入力

入力は以下の形式で標準入力から与えられる。

N M
x1 y1
x2 y2
:
xM yM

出力

Gの有向パスのうち、最長のものの長さを出力せよ。
-}

import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.List
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Unboxed.Mutable as MV
import Control.Monad.ST
import qualified Data.Map.Strict as M

t2 [a,b]=(a-1,b-1)
main=do
    [n,m] <- map read.words<$>getLine
    xys <- replicateM m $ t2.unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ UV.maximum $ f n m $ grp xys

grp = foldl' ad M.empty where
    ad m (x,y) = M.alter (al y) x m
    al y Nothing = Just [y]
    al y (Just l) = Just (y:l)

f n m !xys = runST $ do
    dp <- MV.replicate n (-1) :: ST s (MV.STVector s Int)
    forM_ [0..n-1] (dfs dp)
    UV.freeze dp
    where
        dfs dp s = do
            sk <- MV.read dp s
            if sk == (-1)
                then do
                    sm <- (+1).maximum.((-1):) <$> mapM (dfs dp) (nodes s)
                    MV.write dp s sm
                    return sm
                else
                    return sk
        nodes s = M.findWithDefault [] s xys



Measured memory_bytes: 42364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll>a(n),b(m),as(n + 1),bs(m + 1);
  rep(i,n)cin >> a[i];
  rep(i,m)cin >> b[i];
  rep(i,n)as[i + 1] += a[i] + as[i];
  rep(i,m)bs[i + 1] += b[i] + bs[i];
  int ans = 0;
  rep(i,n + 1){
    ll ok = k - as[i];
    if(ok < 0)continue;
    ans = max(ans,i + (int)(upper_bound(all(bs),ok) - bs.begin()));
  }
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 9540
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int sigma = 26;

struct Node {
  int go[sigma];
  int p, cnt, t, id, l, r;
};

const int maxn = (int) 4e5 + 5;
int n;
string s[maxn];
char tmp[maxn];
char alpha[sigma + 5];
Node trie[maxn];
int freenode;
int ver[maxn];

int newNode(int id, int l, int r, int p) {
  for (int i = 0; i < sigma; i++) {
    trie[freenode].go[i] = -1;
  }
  trie[freenode].cnt = 0;
  trie[freenode].t = -1;
  trie[freenode].id = id;
  trie[freenode].l = l;
  trie[freenode].r = r;
  trie[freenode].p = p;
  return freenode++;
}

int splitEdge(int v, int pos) {
  int u = newNode(trie[v].id, trie[v].l, pos, trie[v].p);
  trie[u].cnt = trie[v].cnt;
  trie[u].go[s[trie[v].id][pos] - 'a'] = v;
  trie[trie[v].p].go[s[trie[v].id][trie[v].l] - 'a'] = u;
  trie[v].l = pos;
  trie[v].p = u;
  return u;
}

void add(int id) {
  int v = 0;
  for (int i = 0; i < sz(s[id]);) {
    trie[v].cnt++;
    if (trie[v].go[s[id][i] - 'a'] == -1) {
      trie[v].go[s[id][i] - 'a'] = newNode(id, i, sz(s[id]), v);
      v = trie[v].go[s[id][i] - 'a'];
      trie[v].cnt++;
      trie[v].t = id;
      ver[id] = v;
      return;
    }
    v = trie[v].go[s[id][i] - 'a'];
    int vid = trie[v].id, l = trie[v].l, r = trie[v].r;
    for (int j = l; j < r; j++, i++) {
      if (i == sz(s[id]) || s[vid][j] != s[id][i]) {
        v = splitEdge(v, j);
        break;
      }
    }
  }
  trie[v].cnt++;
  trie[v].t = id;
  ver[id] = v;
}

int get(int v) {
  int ans = 0;
  int pr = v;
  v = trie[v].p;
  while (v != -1) {
    if (trie[v].t != -1) {
      ans++;
    }
    for (int i = 0; i < sigma; i++) {
      int c = alpha[i] - 'a';
      int u = trie[v].go[c];
      if (u == -1) {
        continue;
      }
      if (u == pr) {
        break;
      }
      ans += trie[u].cnt;
    }
    pr = v;
    v = trie[v].p;
  }
  return ans;
}

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  freenode = 0;
  newNode(-1, 0, 0, -1);
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    s[i] = tmp;
    add(i);
  }
  return true;
}

void solve() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d%s", &k, alpha);
    k--;
    printf("%d\n", get(ver[k]) + 1);
  }
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 23808
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
using namespace std;

const int MAX = 8000;
string s;
int x, y;
bitset<2 * MAX + 3> dpX, dpY;

int main() {
	int i, j;
	
	cin >> s >> x >> y;
	
	vector<int> splits;
	int len = 0;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == 'T') {
			splits.push_back(len);
			len = 0;
		}
		else {
			len++;
		}
	}
	splits.push_back(len);
	
	x -= splits[0];	//最初はx正方向にしかいけない
	
	if (x < -(int)s.length()) {
		cout << "No" << endl;
		return 0;
	}
	
	vector<int> xs;
	vector<int> ys;
	for (i = 1; i < splits.size(); i++) {
		if (i % 2 == 0) xs.push_back(splits[i]);
		else ys.push_back(splits[i]);
	}
	
	//x, y方向で独立に部分和問題を解く
	int trans = MAX;
	bitset<2 * MAX + 3> tmp1, tmp2;
	
	dpX[trans] = 1;
	for (i = 0; i < xs.size(); i++) {
		tmp1 = dpX >> xs[i];
		tmp2 = dpX << xs[i];
		dpX = tmp1 | tmp2;
	}
	
	dpY[trans] = 1;
	for (i = 0; i < ys.size(); i++) {
		tmp1 = dpY >> ys[i];
		tmp2 = dpY << ys[i];
		dpY = tmp1 | tmp2;
	}
	
	if (dpX[x + trans] == 1 && dpY[y + trans] == 1) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 384
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	string a, b;

	cin >> a >> b;

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());

	if (a < b) {
		Yes;
	}
	else {
		No;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	long long a[n+1], sum = 0, res = 1;
	for(int i = 0; i < n+1; i++) {
		cin >> a[i];
		sum += a[i];
	}

	if(n == 0) {
		if(a[0] == 1) {
			cout << "1" << endl;
			return 0;
		}
		else {
			cout << "-1" << endl;
			return 0;
		}
	}
	else {
		if(a[0] >= 1) {
			cout << "-1" << endl;
			return 0;
		}
		long long h[n+1];
		h[0] = 1;
		for (int i = 1; i < n+1; i++)
		{
			if(a[i] > 2 * (h[i-1] - a[i-1])) {
				cout << "-1" << endl;
				return 0;
			}
			else {
				h[i] = min(sum, 2 * (h[i-1] - a[i-1]));
				res += h[i];
				sum -= a[i];
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 5184
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <map>
#include <cctype>
using namespace std;

int main()
{
cout << setprecision(6);
cout << setiosflags(ios::scientific);
cout.flags(ios::fixed);

string str;
getline(cin, str);
for(int i=0; i<str.size(); i++){
if( isupper(str[i]) )
  str[i] = tolower(str[i]);
 else
   str[i] = toupper(str[i]);
}

cout << str << endl;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll A, B;
	cin >> A >> B;

	//約数列挙O(sqrt(N))
	ll sqrt_A = round(sqrt(A));
	vector<ll> a_div(0), b_div(0);
	rep1(i, sqrt_A + 1) {
		if (A % i == 0)
			a_div.pb(i);
	}
	ll tmp_size = a_div.size();
	rep(i, tmp_size) {
		a_div.pb(A / a_div[i]);
	}

	ll sqrt_B = round(sqrt(B));
	rep1(i, sqrt_B + 1) {
		if (B % i == 0)
			b_div.pb(i);
	}
	tmp_size = b_div.size();
	rep(i, tmp_size) {
		b_div.pb(B / b_div[i]);
	}
	sort(all(a_div));
	sort(all(b_div));

	//公約数列挙
	vector<ll> set_div;
	set_intersection(all(a_div), all(b_div), inserter(set_div, set_div.end()));

	if (A == 1 && B == 1) {
		cout << 1;
		return 0;
	}

	//素数判定&カウント
	bool tmp_flag;
	ll cnt = 0;
	rep(i, set_div.size()) {
		tmp_flag = true;
		for (ll j = 2; j <= sqrt(set_div[i]); j++) {
			if (set_div[i] % j == 0) {
				tmp_flag = false;
				break;
			}
		}
		if (tmp_flag) {
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}

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

int main(){
  int a = 0,b=0,N=0;
  string res = "No";
  cin >> N;
  vector<int> C(N);
  for(int i =0;i < N;i++){
    cin >> C.at(i);
  }
  sort(C.begin(),C.end());
  a = C.at(N-1);
  for(int i =0;i < N-1;i++){
    b = b + C.at(i);
  }
  if(a < b){
    res = "Yes";
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

bool isuru(int y){
    if(y % 400 == 0) return true;
    else if(y % 100 == 0) return false;
    else if(y % 4 == 0) return true;
    else return false;
}

signed main(){
    
    int y1, m1, d1; cin >> y1 >> m1 >> d1;
    int y2, m2, d2; cin >> y2 >> m2 >> d2;

    int cury = 1;
    int curm = 1;
    int curd = 1;
    int age1 = 0;
    int age2 = 0;

    bool isuru1 = false;   
    bool isuru2 = false;
    if(m1 == 2 and d1 == 29 and isuru(y1)) isuru1 = true;
    if(m2 == 2 and d2 == 29 and isuru(y2)) isuru2 = true;


    int ans = 0;
    while(cury < 10000){
        if(cury >= y1 and curm == m1 and curd == d1) age1++;
        if(isuru1 and !isuru(cury) and cury >= y1 and curm == 3 and curd == 1) age1++;

        if(cury >= y2 and curm == m2 and curd == d2) age2++;
        if(isuru2 and !isuru(cury) and cury >= y2 and curm == 3 and curd == 1) age2++;
        
        //cerr << cury << " " << curm << " " << curd << " " << age1 << " " << age2 << endl;       

        ans = max(ans, (int)abs(age1 - age2));
        
        curd++;
        if(!isuru(cury) and curm == 2 and curd == 29){
            curd = 1;
            curm++;
        }else if(isuru(cury) and curm == 2 and curd == 30){
            curd = 1;
            curm++;
        }else if((curm == 4 or curm == 6 or curm == 9 or curm == 11) and curd == 31){
            curd = 1;
            curm++;
        }else if(curd == 32){
            curd = 1;
            curm++;
        }

        if(curm == 13){
            curm = 1;
            cury++;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author wnqmw
 */
public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
        int numstones = Integer.parseInt(kb.readLine());
        
        int[] stones = new int[numstones];
        
        StringTokenizer st = new StringTokenizer(kb.readLine());
        for(int i = 0; i < numstones; i++){
            stones[i] = Integer.parseInt(st.nextToken());
        }
        
        System.out.println(dp(stones, numstones));
    }
    
    static int dp(int[] stones, int numstones){
        int[] dp = new int[numstones];
        
        dp[0] = 0;
        dp[1] = Math.abs(stones[0]-stones[1])+ dp[0];
        
        for(int i = 2; i < numstones; i++){
            dp[i] = Math.min(Math.abs(stones[i-2]-stones[i]) + dp[i-2], Math.abs(stones[i-1]-stones[i]) + dp[i-1]);
        }
        return dp[numstones-1];
    }
}


Measured memory_bytes: 31372
#C
import itertools
n, m, q = list(map(int, input().split()))
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
ans = 0
for i in range(q):
    a[i], b[i], c[i], d[i] = list(map(int, input().split()))
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    new_ans = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            new_ans += d[i]
    ans = max(ans, new_ans)
print(int(ans))

Measured memory_bytes: 9220
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  lld k;
  string s;
  cin >> k;
  cin.ignore(1);
  cin >> s;
  lld l = s.length();
  for (int i = 0; i < l; i++) {
    if (i >= k) {
      cout << "...";
      break;
    }
    cout << s[i];
  }
  cout << "\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n, m;
int cost[1010];
int open[1010];
int dp[1010][4100];
const int INF = 0x3f3f3f3f;
int main()
{
    usecppio
    cin >> n >> m;
    memset(dp,0x3f,sizeof(dp));
    int allkey = 0; 
    for (int i = 1; i<=m; i++)
    {
        int a, b;
        cin >> a >> b;
        cost[i] = a;
        for (int j = 0; j<b; j++)
        {
            int c;
            cin >> c;
            open[i] |= (1<<(c-1));
        }
        allkey |= open[i];
    }
    int nos = (1<<n);
    if (allkey!=nos-1)
    {
        cout << -1 << '\n'; return 0;
    }
    dp[0][0] = 0;
    for (int i = 1; i<=m; i++)
    {
        memcpy(dp[i], dp[i-1], sizeof(dp[i]));
        for (int k = 0; k<nos; k++)
        {
            int nk = k|open[i];
            dp[i][nk] = min(dp[i][nk], dp[i-1][k]+cost[i]);
        }
    }
    if (dp[m][nos-1] >= INF)
    {
        cout << -1 << '\n'; return 0;
    }
    cout << dp[m][nos-1] << '\n';
}

Measured memory_bytes: 16512
#include <iostream>
#include <map>
#include <functional>
using namespace std;
int main()
{
  string s;
  while(cin >> s){
    char c = s[0];
    string t;
    if(c == 'e'){
      s = s.substr(3);
      t = "e";
    }else{
      s = s.substr(7);
      t = "c";
    }
    multimap<int,string,greater<int> > m;
    while(s.length() != 0){
      if(s[0] != c){
        if(s[0] == 'e'){
          s = s.substr(3);
          t += "e";
          c = 'e';
        }else{
          s = s.substr(7);
          t += "c";
          c = 'c';
        }
      }else{
        m.insert(make_pair<int,string>(t.length(),t));
        c = s[0];
        if(c == 'e'){
          s = s.substr(3);
          t = "e";
        }else{
          s = s.substr(7);
          t = "c";
        }
      }
    }
    m.insert(make_pair<int,string>(t.length(),t));
    map<int,string>::iterator it = m.begin();
    string ans = (*it).second;
    if(ans[ans.length()-1] == 'c'){
      cout << "chicken" << endl;
    }else{
      cout << "egg" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
const int N=50+5;
int n,m,q,a[N],b[N],c[N],d[N],t[N],ans=-1;
void dfs(int cur,int pre)
{
    if(cur==n+1){
        int tot=0;
        for(int i=1;i<=q;i++)if(t[b[i]]-t[a[i]]==c[i])tot+=d[i];
        ans=max(ans,tot);
        return ;
    }
    for(int i=pre;i<=m;i++){t[cur]=i;dfs(cur+1,i);}
}
int main()
{
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(1,1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

;;

int main(){
  ;;
    int n, m;
    cin >> n >> m;
    ;
    cout << ((n-1)*(m-1)) << endl;;
}

Measured memory_bytes: 256
def prime_factorize(num):
    # 整数に対し素因数分解
    prime_factor = {}
    i = 2
    while i ** 2 <= num:
        while num % i == 0:
            num //= i
            if i in prime_factor.keys():
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor
def combination(n, r):
    # nCrを求める
    r = min(n-r, r)
    result = 1
    for i in range(n, n-r, -1):
        result *= i
    for i in range(1, r+1):
        result //= i
    return result

# 入力
n, m = map(int, input().split())
MOD = 10**9 + 7
P = prime_factorize(m)
ans = 1
for prime in P:
    k = combination(P[prime] + n - 1, P[prime]) % MOD
    ans *= k
    ans %= MOD

print(ans)

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

const ll mod = 998244353;

struct mint {
    ll x;

    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }

    mint &operator-=(const mint a) {
      if ((x += mod - a.x) >= mod) x -= mod;
      return *this;
    }

    mint &operator*=(const mint a) {
      (x *= a.x) %= mod;
      return *this;
    }

    mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
    }

    mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
    }

    mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
    }

    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
    }

    mint inv() const {
      return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
      return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
    }
};

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

  vector<ll> d(n);
  vector<ll> num(100010);
  ll maxv = 0LL;
  for (ll i = 0; i < n; i++) {
    cin >> d[i];
    num[d[i]]++;
    maxv = max(maxv, d[i]);
  }
  if(num[0] != 1 || d[0] != 0) {
    cout << 0 << '\n';
    return 0;
  }

  mint answer = 1;
  for (ll i = 0; i <= maxv; i++) {
    mint base = num[i];
    ll power = num[i + 1];
    answer *= base.pow(power);
  }
  cout << answer.x << '\n';
  return 0;
}

Measured memory_bytes: 4848
/* ex7_3
    suuxxu */

#include <stdio.h>
#include <stdbool.h>

int main(void){
    int height, width, i, j;
    bool memo_col[100] = {}; // 行が黒マスを含むか
    bool memo_row[100] = {}; // 列が黒マスを含むか
    char **square;

    // heightとwidthにH, Wを入力
    scanf("%d %d", &height, &width);

    // int型配列squareのメモリを動的確保
    square = (char**)calloc(height, sizeof(char*));
    if(square == NULL){
        fprintf(stderr, "memory allocation error.¥n"); exit(1);
    }
    for(i=0;i<height;i++){
        square[i] = (char*)calloc(width, sizeof(char));
        if(square[i] == NULL){
            fprintf(stderr, "memory allocation error.¥n");
            exit(1);
        }
    }

    // squareにa_{i,j}を入力
    for (i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            scanf(" %c", &square[i][j]);
        }
    }

    // squareの各要素が黒マスであるか確認
    for (i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            if (square[i][j] == '#'){
                memo_col[i] = true; // その行は黒マスを含む
                memo_row[j] = true; // その列は黒マスを含む
            }
        }
    }

    // 結果を出力
    for (i = 0; i < height; i++){
        if(memo_col[i] == true){ // 黒マスを含むなら出力
            for (j = 0; j < width; j++){
                if(memo_row[j] == true){ // 黒マスを含むなら出力
                    printf("%c", square[i][j]);
                }
            }
        printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 1616
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    n = N % 10
    if n in (2, 4, 5, 7, 9):
        print('hon')
    elif n in (0, 1, 6, 8):
        print('pon')
    else:
        print('bon')


main()


Measured memory_bytes: 9172
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;
vector <tuple<int,int,int>>relation;
string s,t;
int ans;
int main(){
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])
            ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 3436
#include <iostream>

using namespace std;
int main(){
  int num;
  cin >> num;
  int min;
  int max;
  cin >> min;
  max = min;
  for (int i = 0; i < num - 1; i++) {
    int temp;
    cin >> temp;
    min = min > temp ? temp : min;
    max = max < temp ? temp : max;
  }
  cout << max - min;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

int testcase_ends() {
  int N, M;
  scanf("%d %d", &N, &M);

  if (N == 0 && M == 0)
    return 1;

  std::vector<int> h(N+1), w(M+1);
  for (int i=1; i<=N; ++i) {
    int tmp;
    scanf("%d", &tmp);
    h[i] = h[i-1] + tmp;
  }

  for (int j=1; j<=M; ++j) {
    int tmp;
    scanf("%d", &tmp);
    w[j] = w[j-1] + tmp;
  }

  std::map<int, int> H, W;
  for (int i=0; i<=N; ++i)
    for (int j=i+1; j<=N; ++j)
      ++H[h[j]-h[i]];

  for (int i=0; i<=M; ++i)
    for (int j=i+1; j<=M; ++j)
      ++W[w[j]-w[i]];

  long long res=0;
  for (const std::pair<const int, int> &p: H)
    res += p.second * W[p.first];

  printf("%lld\n", res);
  return 0;
}

int main() {
  while (true)
    if (testcase_ends())
      break;

  return 0;
}

Measured memory_bytes: 34092
flag = False
a = []
s = input()
a.append(int(s))

def func(n):
    if n % 2 == 0:
        return n/2
    else :
        return n * 3 + 1

i = 0
while(flag == False):
    a.append(func(a[i]))
    for j in range(i - 1, -1, -1):
        if a[j] == a[i]:
            flag = True
            ans = i
            break
    i += 1

print(i)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

struct programs {
    int start;
    int end;
    int channel;
};

#define CHANNEL_MAX 30
#define TIME_MAX 200000

int main(void) {
    int num, cs;
    get_int2(&num, &cs);
    int i;

    static int map[CHANNEL_MAX][TIME_MAX+4];
    for(i = 0; i < num; i++) {
        int start, end, channel;
        get_int3(&start, &end, &channel);
        // 1-indexed -> 0-indexed
        channel--;
        // for avoiding 0.5
        start*=2;
        end*=2;
        map[channel][start]++;
        map[channel][end]--;
    }

    int c;
    // imos restore
    for(c = 0; c < cs; c++) {
        for(i = 1; i <= TIME_MAX+3; i++) {
            map[c][i] += map[c][i-1];
        }
    }
#ifdef DEBUG
    for(c = 0; c < cs; c++) {
        for(i = 0; i <= 100; i+=2) {
            printf(" %d", map[c][i]);
        }
        putchar('\n');
    }
#endif


    static int map2[TIME_MAX+4];
    for(c = 0; c < cs; c++) {
        int prev = 0;
        for(i = 0; i <= TIME_MAX+3; i++) {
            int cur = map[c][i];
            if(prev == 0 && cur == 1) {
                map2[i-1]++; // S-0.5
            } else if (prev == 1 && cur == 0) {
                map2[i]--; // T
            }
            prev = cur;
        }
    }

    int ans = map2[0];
    // imos restore
    for(i = 1; i <= TIME_MAX+3; i++) {
        map2[i] += map2[i-1];
        ans = max(ans, map2[i]);
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 24320
#include<stdio.h>
#include<stdlib.h>

int main() {
	char s[100];
	int S[100], top=0, a, b;
	while(scanf("%s", s) != EOF) {
		if(s[0] == '+') {
			a = S[--top];
			b = S[--top];
			S[top++] = a+b;
		} else if(s[0] == '-') {
			a = S[--top];
			b = S[--top];
			S[top++] = b-a;
		} else if(s[0] == '*') {
			a = S[--top];
			b = S[--top];
			S[top++] = b*a;
		} else {
			S[top++] = atoi(s);
		}
	}

	printf("%d\n", S[--top]);
}


Measured memory_bytes: 2712
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const long long MAX = 10000000;
const long long MOD = 998244353;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    long long ans = 0;
    long long n1, a, b, k, x, y;
    cin >> n1 >> a >> b >> k;

    for(x=0;x<=n1;x++) {
        y = (k - a*x) / b;
        if((k - a*x) % b == 0 && y <= n1 && y>=0) {
            //cout << x << " " << y << endl;
            ans = (ans + (COM(n1, x) * COM(n1, y))%MOD)%MOD; 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 234624