akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<iostream>

using namespace std;

int main(void){
	int cnt=0,j;
	double weight,hun,i;
	double dou[10];

	while(cin>>weight){
		for(i=9;i>=0;i--){
			hun=pow(2,i);
			if(weight>=hun){
				weight-=hun;
				dou[cnt]=hun;
				cnt++;
			}
		}
		cout<<dou[cnt-1];
		for(j=cnt-2;j>=0;j--)
			cout<<' '<<dou[j];
		cout<<endl;
		cnt=0;
	}

	return 0;
}

Measured memory_bytes: 0
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

A, B, M = read_int()
a = read_int()
b = read_int()
xyc = [read_int() for _ in range(M)]

def solve():
    ans = min(a) + min(b)
    for x, y, c in xyc:
        ans = min(a[x - 1] + b[y - 1] - c, ans)
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 39072
from itertools import permutations
N, M = map(int, input().split())
T=[[]*N for _ in range(N)]
for _ in range(M):
  i ,j = map(int,input().split())
  T[i-1].append(j-1)
  T[j-1].append(i-1)

def main():
  ans = 0
  for p in permutations(range(1,N)): 
    c=0
    for n in p:
      if n not in T[c]:
        break
      c=n
    else:
      ans += 1
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int max;
	int n, i;
	int t, s;

	while (scanf("%d", &n), n){

		max = -9e6;
		t = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &s);
			t += s;
			max = fmax(t, max);
			if (t < 0) t = 0;
		}

		printf("%d\n", max);
	}
	return (0);
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,m,x;
	cin >> n >> m >> x;
	VL a(m),mas(n+1,0);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		mas[a[i]] = 1;
	}

	int up = 0,down = 0;
	for (int i = x; i <= n; i++) {
		up += mas[i];
	}
	for (int i = x; i >= 0; i--) {
		down += mas[i];
	}

	cout << min(up,down) << endl;
	return 0;
}


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

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = new int[N];
            answer[N / 2] = A[0];
            for (var i = 1; i < A.Length; i++)
            {
                var dx = (i + 1) / 2;
                if (i % 2 == 1) dx = -dx;
                answer[N / 2 + dx] = A[i];
            }
            if (N % 2 == 1) answer = answer.Reverse().ToArray();

            Console.WriteLine(string.Join(" ", answer));
        }
    }
}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

bool match(char a, char b) {
    return a == '?' || b == '?' || a == b;
}

constexpr int MAX = 4000;

vector<int> fill_table(const string& a, const string& b, int M) {
    vector<int> res;
    debug(a);
    debug(b);
    int len_a = a.size(), len_b = b.size();
    for (int i = -M; i <= M; ++i) {
        bool ok = true;
        for (int j = max(0, i); j < min(len_a, i + len_b); ++j) {
            if (!match(a[j], b[j - i])) {ok = false; break;}
        }
        res.push_back(ok);
        if (ok) {debug(i);};
    }
    return res;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    vector<int> ab = fill_table(a, b, MAX);
    int ab_begin = -b.size();
    vector<int> ac = fill_table(a, c, MAX);
    int ac_begin = -c.size();
    vector<int> bc = fill_table(b, c, 4 * MAX);
    int bc_begin = -c.size();

    int res = 1e8;
    int len_a = a.size(), len_b = b.size(), len_c = c.size();
    for (int i = -MAX; i <= MAX; ++i) {
        for (int j = -MAX; j <= MAX; ++j) {
            if (ab[i + MAX] && ac[j + MAX] && bc[j - i + 4 * MAX]) {
                res = min<int>(res, max<int>({len_a, len_b + i, len_c + j}) - min<int>({0, i, j}));
                
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define ll long long

const int MOD = 1e9 + 7;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    REP(i, tx-sx) cout << "R";
    REP(i, ty-sy) cout << "U";
    REP(i, tx-sx) cout << "L";
    REP(i, ty-sy) cout << "D";
    cout << "D";
    REP(i, tx+1-sx) cout << "R";;
    REP(i, ty-(sy-1)) cout << "U";
    cout << "L";
    cout << "U";
    REP(i, tx-(sx-1)) cout << "L";
    REP(i, ty+1-sy) cout << "D";
    cout << "R" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int N,M;
int p[200000],q[200001],rr[400002];
int *r=rr+200001;
signed main(){
	int i,j;
	cin>>N>>M;
	for(i=0;i<N;i++){
		cin>>p[i];
		q[p[i]]++;
	}
	int ans=0;
	for(i=1;i<=N;i++){
		r[i-q[i]]++;
		r[i]--;
	}
	int u=0;
	for(i=1-N;i<N;i++){
		u+=r[i];
		r[i]=u;
		if(i>=0)
			ans+=(u==0);
	}
	for(i=0;i<M;i++){
		int x,y;
		cin>>x>>y;
		x--;
		r[p[x]-q[p[x]]]--;
		if(p[x]-q[p[x]]>=0&&r[p[x]-q[p[x]]]==0)
			ans++;
		q[p[x]]--;
		q[y]++;
		if(y-q[y]>=0&&r[y-q[y]]==0)
			ans--;
		r[y-q[y]]++;
		p[x]=y;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 7808
//O(N^2)
#include <stdio.h>
#include <x86intrin.h>
typedef unsigned int uint;
#pragma GCC optimize ("O3")
uint read(void){
    int flag = 0;
    uint num = 0;
    for(;;){
        int c = getchar_unlocked() - '0';
        if(0 <= c && c <= 9){
            num = num*10+c;
            flag = 1;
        }else if(flag){
            return num;
        }
    }
}
#define N 200000
uint a[N] __attribute__ ((aligned (16)));
uint b[N] __attribute__ ((aligned (16)));
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx")
int main(void){
    uint ss[4];
    uint s=0;
    uint n;
    n = read();
    for(uint i=0; i<n; i++){
        uint t = read();
        s ^= t;
        a[i] = t;
    }
    for(uint i=0; i<n; i++){
        uint t = read();
        s ^= t;
        b[i] = t;
    }
    if((n&1)==0){
        s = 0;
    }
    __m128i s0 = _mm_setzero_si128();
    __m128i s1 = _mm_setzero_si128();
    __m128i s2 = _mm_setzero_si128();
    __m128i s3 = _mm_setzero_si128();
    uint j;
    for(j=0; j<N; j+=4){
        __m128i d = _mm_load_si128((__m128i*)(b+j));
        __m128i d0 = _mm_shuffle_epi32(d, 0x00);
        __m128i d1 = _mm_shuffle_epi32(d, 0x55);
        __m128i d2 = _mm_shuffle_epi32(d, 0xAA);
        __m128i d3 = _mm_shuffle_epi32(d, 0xFF);
        uint i;
        for(i=0; i<N; i+=16){
            __m128i c0 = _mm_load_si128((__m128i*)(a+i+0));
            __m128i c1 = _mm_load_si128((__m128i*)(a+i+4));
            __m128i c2 = _mm_load_si128((__m128i*)(a+i+8));
            __m128i c3 = _mm_load_si128((__m128i*)(a+i+12));
            __m128i t0 = _mm_add_epi32(c0, d0);
            __m128i t1 = _mm_add_epi32(c1, d0);
            __m128i t2 = _mm_add_epi32(c2, d0);
            __m128i t3 = _mm_add_epi32(c3, d0);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
            t0 = _mm_add_epi32(c0, d1);
            t1 = _mm_add_epi32(c1, d1);
            t2 = _mm_add_epi32(c2, d1);
            t3 = _mm_add_epi32(c3, d1);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
            t0 = _mm_add_epi32(c0, d2);
            t1 = _mm_add_epi32(c1, d2);
            t2 = _mm_add_epi32(c2, d2);
            t3 = _mm_add_epi32(c3, d2);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
            t0 = _mm_add_epi32(c0, d3);
            t1 = _mm_add_epi32(c1, d3);
            t2 = _mm_add_epi32(c2, d3);
            t3 = _mm_add_epi32(c3, d3);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
        }
    }
    s0 = _mm_xor_si128(s0, s2);
    s1 = _mm_xor_si128(s1, s3);
    s0 = _mm_xor_si128(s0, s1);
    _mm_storeu_si128((__m128i*)ss, s0);
    ss[0] ^= ss[2];
    ss[1] ^= ss[3];
    ss[0] ^= ss[1];
    printf("%u\n", ss[0]^s);
    return 0;
}


Measured memory_bytes: 1664
import java.util.*;

public class Main {

  static int N; 
  static boolean[][] graph;
  static boolean[] visited;

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    N = sc.nextInt();
    int M = sc.nextInt();
    graph = new boolean[N][N];

    for (int i = 0; i < M; i++) {
      int a_ = sc.nextInt();
      int b_ = sc.nextInt();
      graph[a_-1][b_-1] = true;
      graph[b_-1][a_-1] = true;
    } 

    visited = new boolean[N];

    visited[0] = true;

    sc.close();

    int count = dfs(0);

    System.out.println(count);
    
  }

  static int dfs(int v){

    boolean allVisited = true;

    for (int i = 0; i < N; i++) {

      if (visited[i] == false) {
        allVisited = false;
        break;
      }
      
    }

    if (allVisited) {
      return 1;
    }

    int count = 0;

    for (int i = 0; i < N; i++) {

      if (graph[v][i] == false) {
        continue;
      }
      
      if (visited[i]) {
        continue;
      }
      
      visited[i] = true;
      
      count += dfs(i);

      visited[i] = false;

    }

    return count;
  }

}

Measured memory_bytes: 22996
N,M=map(int,input().split())
ACL=[0]*N
PL=[0]*N
AC=0
P=0
for i in range(M):
  p,S=input().split()
  p=int(p)
  p-=1
  if S =='AC':
    if ACL[p]==0:
      AC+=1
      P+=PL[p]
      ACL[p]=1
  else:
    PL[p]+=1
print(AC,P)

Measured memory_bytes: 4596
N,M = [int(a) for a in input().split()]
edges = {i:[] for i in range(1,N+1)}
for i in range(M):
  a,b = [int(a) for a in input().split()]
  edges[a].append(b)
  if a not in edges[b]:
    edges[b].append(a)

def search(lst):
  if len(lst) == N:
    return 1
  else:
    a = lst[-1]
    next = [n for n in edges[a] if n not in lst]
    if len(next) == 0:
      return 0

    tot = 0
    for n in next:
      tot += search(lst + [n])
    
    return tot


ans = search([1])

print(ans)

      

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,K;
  int x=1;
  
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    if(x>=K)
      x+=K;
    else
      x*=2;
  }
  
  cout << x << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static boolean[][] graph;
	static boolean[] vis;
	static int ans = 0;
	static int n, m;
	static int[] a, b;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		for(int i = 0 ; i < m ; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
		}
		graph = new boolean[n][n];
		vis = new boolean[n];
		for(int i = 0 ; i < m ; i++) {
			graph[a[i]][b[i]] = true;
			graph[b[i]][a[i]] = true;
		}
		dfs(0, 0);
		System.out.println(ans);
	}

	static void dfs(int x, int pos) {
		vis[x] = true;
		if(pos == n - 1) {
			boolean ok = true;
			for(int i = 0 ; i < n ; i++) {
				if(!vis[i]) ok = false;
			}
			if(ok) ans++;
			return;
		}
		for(int i = 0 ; i < n ; i++) {
			if(graph[x][i] && !vis[i]) {
				dfs(i, pos + 1);
				vis[i] = false;
			}
		}
		return;
	}

}


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

using namespace std;

inline int read()
{
    int ret=0,flag=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
    while(c>='0'&&c<='9')ret=ret*10+(c^'0'),c=getchar();
    return flag*ret;
}

struct use
{
    int val,col;
    bool operator<(const use &other)const
    {
        return val>other.val;
    }
};

const int N=1e5+5;
int x,y,a,b,c;
use s[N*3];

int main()
{
    x=read(),y=read(),a=read(),b=read(),c=read();
    int tot=0;
    for(int i=1;i<=a;i++)s[++tot]=(use){read(),1};
    for(int i=1;i<=b;i++)s[++tot]=(use){read(),2};
    for(int i=1;i<=c;i++)s[++tot]=(use){read(),3};
    sort(s+1,s+tot+1);
    int cnt1=0,cnt2=0,cnt3=0;
    long long ans=0;
    for(int i=1;i<=tot;i++)
    {
        if(s[i].col==1)
        {
            if(cnt1<x&&cnt1+cnt2+cnt3<x+y)
                ++cnt1,ans+=s[i].val;
        }
        else if(s[i].col==2)
        {
            if(cnt2<y&&cnt1+cnt2+cnt3<x+y)
                ++cnt2,ans+=s[i].val;
        }
        else
        {
            if(cnt1+cnt2+cnt3<x+y)
                ++cnt3,ans+=s[i].val;
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scaner sc = new Scaner();
        write wr = new write();

        int N=sc.Int1;
        int ans=0;
        for(int i=1;i<=N;++i){
            string x=i.ToString();
            if(x.Length%2==1){
                ans++;
            }
        }
    wr.wri(ans);

    }
}





class Scaner
{
    public string Str => Console.ReadLine();

    public string[] StrArr => Str.Split(' ');

    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public char[] CharArr => Str.ToArray();
    public long Long1 => LongArr[0];
    public int Int1 => IntArr[0];
    
}



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



Measured memory_bytes: 15444
#include<cstdio>
char str[10005];
bool used[1005];
int main(){
  scanf("%s",str+1);
  for(int i=1;str[i];++i){
    used[str[i]]=true;
  }
  if(used['W']^used['E']){
    printf("No\n");
  }else if(used['N']^used['S']){
    printf("No\n");
  }else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
from collections import deque
H,W = map(int,input().split())
mat = []
wsum = 0
for i in range(H):
    mat.append(list(input()))
    wsum += mat[i].count('.')
start = [0,0]
x1 = [0,0,1,-1]
y1 = [1,-1,0,0]
alr = [[-1 for i in range(W)] for j in range(H)]
alr[0][0] = 0
que = deque()
count = 0
que.append([0,0])
flag = False
while que:
    q = que.popleft()
    for i in range(4):
        if (0 <= q[0]+x1[i] <= H-1) and (0 <= q[1]+y1[i] <= W-1):
            if q[0]+x1[i] == H-1 and q[1]+y1[i] == W-1:
                count = alr[q[0]][q[1]] + 1
                flag = True
                que.clear()
            elif mat[q[0]+x1[i]][q[1]+y1[i]] == '.' and alr[q[0]+x1[i]][q[1]+y1[i]] == -1:
                alr[q[0]+x1[i]][q[1]+y1[i]] = alr[q[0]][q[1]] + 1
                que.append([q[0]+x1[i],q[1]+y1[i]])
if flag:
    print(wsum - (count+1))
else:
    print(-1)


Measured memory_bytes: 3444
def main():
    N = int(input())

    temp = int(N / 10)
    temp = temp * 10
    result = None

    if (N- temp) == 2 or (N- temp) == 4 or (N- temp) == 5 or (N- temp) == 7 or (N- temp) == 9 :
        result = 'hon'
    elif (N- temp) == 3 :
        result = 'bon'
    else :
        result = 'pon'

    print(result)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9136
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input!{
        h: usize,
        w: usize,
        mut s:[Chars; h]
    }

    let mut visited = vec![vec![false; w]; h];
    let mut block_num = 0;
    for y in 0..h {
        for x in 0..w {
            if s[y][x] == '#' {
                block_num += 1;
                visited[y][x] = true;
            }
        }
    }
    let mut queue = VecDeque::new();
    let start = (0,0);
    let goal = (h-1, w-1);
    let mut distance = 0;
    queue.push_back((start, 0));

    while let Some((pos, dist)) = queue.pop_front() {
        if visited[pos.0][pos.1] {
            continue;
        }
        visited[pos.0][pos.1] = true;
        if pos == goal {
            distance = dist;
            break;
        }

        for &(dy, dx) in [(0, 1), (1, 0), (-1, 0), (0, -1)].iter() {
            let (ny, nx) = (pos.0 as isize + dy, pos.1 as isize + dx);
            if ny < 0 || ny >= h as isize || nx < 0 || nx >= w as isize {
                continue;
            }

            queue.push_back(((ny as usize, nx as usize), dist + 1));
        }
    }
    if distance == 0{
        println!("-1");
    } else {
        let ans = w * h - block_num - distance - 1;
        println!("{}", ans);
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	long long int N, a[100000] = {},mini=1000000001,count = 0,sum=0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		sum += abs(a[i]);
		if (a[i] < 0)count++;
		mini = min(mini, abs(a[i]));
	}
	if (count % 2)cout << sum - 2 * mini;
	else cout << sum;
	return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for(int i = 1; i <= m; i++){
        int x;
        cin >> x;
        sum += x;
    }
    if(n - sum >= 0){
        cout << n - sum << '\n';
    } else {
        cout << -1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		H = sc.nextInt();
		W = sc.nextInt();
		K = sc.nextInt() - 1;
		dp[0][0] = 1;
		for(int h=1; h<=H; ++h) {
			for(int w=0; w<W; ++w) {
				for(int b=0; b<(1<<(W-1)); ++b) {   //横棒チェック、高さhでの横棒の位置を全探索
					int x = 3;
					boolean flg = false;
					while(x < 1<<20) {				
						if((x&b) == x) flg = true;
						x <<= 1;
					}
					if(flg) {
						continue;
					}else{

						if(w>0 && (b&(1<<(w-1)))>0) {			//左
							dp[h][w] += dp[h-1][w-1];
						}
						else if(w < W-1 && (b&(1<<w))>0) {		//右
							dp[h][w] += dp[h-1][w+1];
						}
						else {
							dp[h][w] += dp[h-1][w];
						}
						dp[h][w] %= MOD;
					}
				}
			}
		}
		System.out.println(dp[H][K]);

	}





}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
  
int main() {
  	int n,x,count=0;
  	while(true){
    	cin>>n>>x;
      	if(n==0 && x==0) break;
      	for(int i=1;i<=n;i++){
       	 	for(int j=1;j<=n;j++){
        		for(int k=1;k<=n;k++){
        			if(i+j+k==x && i!=j && i!=k && j!=k){
                   		count++; 
                    }
        		}
         	} 
        }
      cout<<count/6<<endl;
      count=0;
    }
}
 


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

int main() {
    string S; cin >> S;
    rep(i, 3){
        cout << S[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3592
l = list(map(int, input().split()))
i = 0
while True:
  l = sorted(l)
  if i >= 30:
    i = -1
    break
  if l[0] % 2 == 0 and l[1] % 2 == 0 and l[2] % 2 == 0:
    l[0] += (l[1] - l[0]) // 2
    l[2] -= (l[2] - l[1]) // 2
  else:
    break
  
  i += 1

print(i)


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
	int n=in.nextInt();
	int a[] = new int[n];
	int count = 0;
	
	for(int i=0;i<n;i++) {
		a[i] = in.nextInt();
	}
	while(true) {
		boolean jud = false;
		for(int i=0;i<n;i++) {
			if(a[i]%2==1) {
				jud = true;
			}
		}
		if(jud==true) {break;}
		for(int i=0;i<n;i++) {
			a[i] = a[i]/2;
		}
		count++;
	}
			System.out.println(count); 	
	}
}

Measured memory_bytes: 36128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
        int d = sc.nextInt();
        
    
		// 出力
		System.out.println(Math.max(a * b, c * d));
	}
}

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

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	
	int Z1 = (N + H - 1) / H;
	int Z2 = (N + W - 1) / W;
	cout << min(Z1, Z2) << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
dic = defaultdict(int)

ans = 0
#j-i = Ai+A　⇄　j-A[j] = A[i]+i
for i in range(n):
    Sum = A[i] + i
    dic[Sum] += 1
    Dif = i - A[i]
    ans += dic[Dif]
print(ans)


Measured memory_bytes: 61416
import sys
sys.setrecursionlimit(10000000)
def main():
    N = int(input())
    d = {}
    v = set()
    if N == 1:
        return 2
    for _ in range(N-1):
        x, y = map(int, input().split())
        if x in d:
            d[x].append(y)
        else:
            d[x] = [y]
        if y in d:
            d[y].append(x)
        else:
            d[y] = [x]
    w, b = dfs(1, d, v)
    return w + b
def dfs(node, d, v):
    v.add(node)
    l = []
    for i in d[node]:
        if i in v:
            continue
        w, b = dfs(i, d, v)
        l.append((w,b))
    w = 1
    b = 1
    for tw, tb in l:
        w *= (tw + tb)
        b *= tw
    return w, b

print(main() % (10**9 + 7))


Measured memory_bytes: 118012
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int sum = 0;

		for(int i = a;i <= b; i++){
			if(c % i == 0){
				sum ++;
			}
		}
		System.out.println(sum);
	}
}




Measured memory_bytes: 26256
#include<iostream>
using namespace std;
using ll = long long;
//10^9=10億 intの限界寸前
int main(){
	ll x;
	cin >> x;
	int year=0;
	ll sum=100;
	float benefit=0.01f;
	for(;sum<x;year++,sum+=sum/100);
	cout << year;
	return 0;
}

Measured memory_bytes: 3096
s = gets.scan(/./)
count_a = 0
count_b = 0
s.each.with_index { |c, i|
  if i % 2 == 0
    if c == "0"
      count_a += 1
    else
      count_b += 1
    end
  else
    if c == "1"
      count_a += 1
    else
      count_b += 1
    end
  end
}
puts [count_a, count_b].min


Measured memory_bytes: 11388
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const  long double eps = 1e-2;
const long double pi = acos(-1.0);
using namespace std;



void solve(){
    string s;
    cin >> s;
    int p = 0, g = 0;
    int n = s.length();
    int ans = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == 'g'){
            if (p < g){
                p++;
                ans++;
            } else g++;
        }
        if (s[i] == 'p'){
            if (p < g) p++;
            else{
                g++;
                ans--;
            }
        }
    }
    cout << ans << endl;
}
int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(3);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=998244353;

//for(i=0; i<N; i++) cin >> a[i];




int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[111];
  
  ll ans=0;
  for(i=1; i<=N; i++) {
    cin >> a[i];
    
    ans+=(a[i]%2&&i%2);
    
    
  }
  pt(ans);
}
 
 




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

using namespace std;

#define ll long long
#define pii pair<ll, ll> 

const int NAX = 1e5 + 10;

#define pb push_back

const long long mod = 1e9 + 7;

vector<int> tree[NAX];


pii dfs(int v, int p){
	ll cur_black = 1; ll cur_white = 1;
	for(int i = 0; i < tree[v].size(); i++){
		if(tree[v][i] != p){
			pii p = dfs(tree[v][i], v);//first is cur_black
			cur_black = (cur_black * p.second)%mod;
			cur_white = (cur_white * (p.first + p.second)%mod)%mod;
		}
	}
	
	return make_pair(cur_black, cur_white);
}

int
main(void){
	int n; cin >> n;
	for(int i = 0; i < n - 1; i++){
		int u, v; cin >> u >> v;
		--u; --v;
		tree[u].pb(v);
		tree[v].pb(u);
	}
	
	pii ans = dfs(0, -1);
	
	cout << (ans.first + ans.second)%mod;
}





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

int main()
{
    string t;
    int n = 0, s = 0, w = 0, e = 0;
    cin >> t;
    for(int i = 0; i < t.size(); i++){
        if(t[i] == 'N') n++;
        else if(t[i] == 'S') s++;
        else if(t[i] == 'W') w++;
        else e++;
    }
    
    bool d = true;

    if((n > 0 && s == 0)||(n == 0 && s > 0)||(w > 0 && e == 0)||(w == 0 && e > 0)) d = false;

    if(d) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int N = reader.nextInt();
		int M = reader.nextInt();
		Map<Integer, ArrayList<Integer>> price = new HashMap<Integer, ArrayList<Integer>>();
		for (int i=0; i<N; i++) {
		    int a = reader.nextInt();
		    int b = reader.nextInt();
		    if (!price.containsKey(a)) {
		        price.put(a, new ArrayList<Integer>());
		    }
		    price.get(a).add(b);
		}
		solver(N, M, price);
	}
	
	public static void solver(int N, int M, Map<Integer, ArrayList<Integer>> price) {
		// write logic
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
		int ans = 0;
		for (int i=0; i<M; i++) {
		    ArrayList<Integer> tmp = price.get(i+1);
		    if (tmp != null) {
    		    for (int t : tmp) {
    		        pq.offer(t);
    		    }
		    }
		    if (pq.size() == 0) continue;
		    ans += pq.poll();
		}
		System.out.println(ans);
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 51080
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream> 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;

#define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b))
using ll = long long;
const int INF = 1e9;

const int N = 1000;
const int MOD = 1e9+7;
string a[N];
ll dp[N][N];

const char WALL = '#';

int main() {
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = i == 0 ? 1 : 0; j < m; ++j) {
            if (a[i][j] == WALL) continue;
            if (i > 0) {
                dp[i][j] += dp[i-1][j];
            }
            if (j > 0) {
                dp[i][j] += dp[i][j-1];
            }
            dp[i][j] %= MOD;
        }
    }
    cout << dp[n-1][m-1] << endl;
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    string S;
    cin >> S;
    int ans = 0;
    for (int i = 1; i < S.length(); ++i)
        ans += S[i] != S[i - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}
template<typename T>
static inline T fin() { T t; cin >> t; return std::move(t); }

int main() {
  i64 n, m;
  cin >> n >> m;
  vector<i64> a(n), b(n);
  for(int i = 0;i < n;i++) cin >> a[i] >> b[i];
  vector<pair<i64, i64>> vec;
  for(int i = 0;i < n;i++) {
    vec.push_back({ m - a[i], b[i] });
  }
  sort(all(vec));
  reverse(all(vec));
  i64 vi = 0;
  priority_queue<i64> que;
  i64 ans = 0;
  for(int i = m - 1;i >= 0;i--) {
    while(vi < vec.size() && vec[vi].first == i) {
      que.push(vec[vi].second);
      vi++;
    }
    if(!que.empty()) {
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5232
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

S = input()

# 半分あれば任意の色に揃えられる
if len(S) % 2 == 1:
    ans = len(S) // 2 + 1
    L = len(S) // 2
    r = len(S) // 2
else:
    ans = len(S) // 2
    L = len(S) // 2
    r = len(S) // 2 - 1

# 真ん中の色は全部一緒じゃないと揃えられない
color = S[L]
while L - 1 >= 0 and S[L - 1] == S[r + 1] == color:
    L -= 1
    r += 1
    ans += 1
print(ans)


Measured memory_bytes: 3188
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N-1);
  rep(i,N) cin>>A.at(i);
  rep(i,N) A.at(i) -=1;
  rep(i,N) cin>>B.at(i);
  rep(i,N-1) cin>>C.at(i);
  int sum=0;
  int flag=0;
  rep(i,N){
    sum += B.at( A.at(i) );
  }
  rep(i,N-1){
   if(A.at(i)+1==A.at(i+1))sum+=C.at( A.at(i) );
  }
	cout << sum <<endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import bisect

s=list(map(lambda x : ord(x)-97,list(input())))
t=list(map(lambda x : ord(x)-97,list(input())))
#print(s)

alpha=[[] for i in range(26)]
#print(alpha)

for index,item in enumerate(s):
    alpha[item].append(index)
    #print(alpha)

loc=-1
count=0

for index,item in enumerate(t):
    temp=bisect.bisect(alpha[item],loc)
    if len(alpha[item])==0:
        print(-1)
        exit()
    if temp==len(alpha[item]):
        count+=1
        loc=alpha[item][0]
    else:
        loc=alpha[item][temp]
    #print(loc,count)
print(loc+1+count*len(s))





Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc066_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int ans = 0;
  for (int i = S.size() - 3; i > 0; i -= 2) {
    bool ok = true;
    rep(j, i / 2) {
      char a = S[j];
      char b = S[i / 2 + 1 + j];
      if (a != b) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = i + 1;
      break;
    }
  }

  cout << ans << endl;
}

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

namespace ConsoleApplication54
{
    class Program
    {
        static void Main()
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] W = new int[a[0]];
            int[] B = new int[a[0]];
            int[] R = new int[a[0]];
            for (int b = 0; b < a[0]; b++)
            {
                string t = Console.ReadLine();
                for(int c = 0; c < a[1]; c++)
                {
                        switch (t[c]) {
                        case 'W': B[b]++; R[b]++;break;
                        case 'B': W[b]++; R[b]++;break;
                        case 'R': B[b]++; W[b]++;break;
                    }
                }
            }
            int x = int.MaxValue, y=0;
            for(int d = 1; d <=a[0] - 2; d++)
            {
                for(int e = 1; e <= a[0] - 1 - d; e++)
                {
                    y = 0;
                    for(int f = 0; f <d; f++)
                    {
                        y += W[f];
                    }
                    for (int f = 0; f < e; f++)
                    {
                        y += B[d+f];
                    }
                    for (int f = 0; f < a[0]-e-d; f++)
                    {
                        y += R[d+e+f];
                    }
                    if (x > y) { x = y; }
                }
            }
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 9556
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		String s = "No";

		for(int i = 0; i <= X; i ++){
			if(Y == (2 * i + 4 * (X - i))){
				s = "Yes";
				break;
			}
		}
		System.out.println(s);
	}
}

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

int main() {
  int n; cin >> n;
  cout << n*(n-1)/2 - n/2 << endl;
  for(int i=1; i<=n-1; i++) {
    for(int j=i+1; j<=n; j++) {
      if (n%2) {
        if (i+j!=n) cout << i << " " << j << endl;
      } else {
        if (i+j!=n+1) cout << i << " " << j << endl;
      }
    }
  }
  return 0;
}

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

int pc_num,student_num;
short student_used[10000][1260];
short student_used2[10000][1260];

int main(void) {
	int kiroku_num;
	int query_num;
	int i,j;
	int k_zikoku,k_pc,k_student,k_type;
	int q_start,q_end,q_student;
	while(1) {
		scanf("%d%d",&pc_num,&student_num);
		if(pc_num==0 && student_num==0)break;
		memset(student_used,0,sizeof(student_used));
		memset(student_used2,0,sizeof(student_used2));
		scanf("%d",&kiroku_num);
		for(i=0;i<kiroku_num;i++) {
			scanf("%d%d%d%d",&k_zikoku,&k_pc,&k_student,&k_type);
			k_pc--;k_student--;
			if(k_type==1) {
				student_used[k_student][k_zikoku]++;
			} else {
				student_used[k_student][k_zikoku]--;
			}
		}
		for(i=0;i<student_num;i++) {
			for(j=540;j<1260;j++) {
				student_used[i][j]+=student_used[i][j-1];
				if(student_used[i][j]>0)student_used2[i][j]=1;
				student_used2[i][j]+=student_used2[i][j-1];
			}
		}
		scanf("%d",&query_num);
		for(i=0;i<query_num;i++) {
			scanf("%d%d%d",&q_start,&q_end,&q_student);
			q_student--;
			printf("%d\n",student_used2[q_student][q_end-1]-
				student_used2[q_student][q_start-1]);
		}
	}
	return 0;
}

Measured memory_bytes: 48000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IO std::ios::sync_with_stdio(false);std::cin.tie(0)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back
int main(){
	int w,s;
	cin>>s>>w;
	if(w>=s) cout<<"unsafe";
	else cout<<"safe";
}

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

int main() {
  int tmpA = -1, tmpZ;
  string s;
  cin >> s;

  for (int i = 0; i < s.length(); i++)
  {
    if (tmpA == -1 && s[i] == 'A')
    {
      tmpA = i;
    }

    if (s[i] == 'Z')
    {
      tmpZ = i;
    }
  }
  cout << tmpZ - tmpA + 1 << endl;
}


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

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

int main(){
	string  S;
	cin >> S;
	string ans;	
	if (S[S.size()-1] == 's') ans = S + "es";
	else ans = S + "s";
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3632
d = int(input())#365
clist = list(map(int,input().split()))#満足度の下がりやすさci, clist[i-1]でci
satisfactionlist = []#satisfactionlist[d-1][i-1]でsd,i
for _ in range(d):
    satisfactionlist.append(list(map(int,input().split())))

def decrease(clist,d,lastlist):
    sum = 0
    for i in range(26):
        sum += clist[i]*(d-lastlist[i])
    return sum

def calculate(d,clist,satisfactionlist,orderlist):
    satisfaction = 0
    lastlist = [0 for _ in range(26)]#lastlist[i-1] = last(d,i)
    for j in range(d):
        i = orderlist[j]#コンテストiをd日目にやると
        satisfaction += satisfactionlist[j][i-1]
        lastlist[i-1] = j+1
        satisfaction -= decrease(clist,j+1,lastlist)
    #print(satisfaction)
    return satisfaction

orderlist = []
for day in range(d):
    combined1 = [x + y for (x, y) in zip(clist, satisfactionlist[day])]
    max_value = max(combined1)
    max_index = combined1.index(max_value)
    orderlist.append(max_index+1)

for ans in orderlist:
    print(ans)


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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;


map<ll,ll> prime_num(map<ll,ll> &prime, ll N){
    int i=2;
    while(i*i<=N){
        if(N%i!=0){
            i++;
            continue;
        }
        int count=0;
        while(N%i==0){
            N/=i;
            count++;
        }
        prime[i]+=count;
        i++;
    }
    if(N!=1) prime[N]+=1;
    return prime;
}

int main(){
    int N;
    cin >> N;
    const int mod=1e9+7;
    map<ll,ll> prime;
    for(int i=2;i<=N;i++){
        prime_num(prime, i);
    }
    long long ans=1;
    for(auto kani : prime){
        ans*=kani.second+1;
        ans%=mod;
    }
    cout << ans << endl;
}

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

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

int main(){
	int S, W;
	cin >> S >> W;
	if (S <= W) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
	ll H,W;cin>>H>>W;
    vector<vector<char>> data(H,vech(W)),data2(2*H,vech(W));rep0(i,H){rep0(j,W){cin>>data[i][j];}}
    rep0(i,2*H){
        rep0(j,W){
            cout<<data[i/2][j];
        }
        cout<<endl;
    }
}



Measured memory_bytes: 256
import sys
n,a,b,c,d=map(int,input().split())
s=input()
for i in range(a-1,c-2):
  if s[i]=='#' and s[i+1]=='#':
    print('No')
    sys.exit()
for i in range(b-1,d-2):
  if s[i]=='#' and s[i+1]=='#':
    print('No')
    sys.exit()
if d<c:
  failflag=1
  for i in range(b-1,d):
    if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
      failflag=0
  if failflag==1:
    print('No')
    sys.exit()
print('Yes')
  

Measured memory_bytes: 68360
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 #define int long long int
#define nl "\n"
using namespace std;

void code()
{       
    string s,t;
    cin>>s>>t;
    int maxm = INT_MIN;
    for(int i=0; i<=((int)s.size() - (int)t.size()); i++)
        {
            int count = 0;
            for(int j=i; j<i+(int)t.size(); j++)
            {
                if(s[j]==t[j-i])
                    count++;
            }
            maxm = max(maxm,count);
        }    
    cout<<(int)t.size() - maxm;
        
}
signed main()

{

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
        
        FAST_IO;
        int t = 1;

        // cin>>t;

        while(t--)
        {
                code();
        }
        

#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif

        return 0;
}


Measured memory_bytes: 3636
import qualified Data.IntSet as IS
main = mapM_ (print . solve) . analyze . map read . lines =<< getContents
analyze (n:cs) = let (ss,bs) = splitAt n cs in (n,ss):analyze bs
analyze [] = []
solve::(Int,[Int])->Int
solve (_,ss) = IS.foldr g 0 . foldr f (IS.singleton 0) $ ss
f::Int->IS.IntSet->IS.IntSet
f s vs = IS.union vs . IS.map (+s) $ vs
g::Int->Int->Int
g v m = if v`mod`10/=0 then max v m else m

Measured memory_bytes: 2300
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[2009]; long long dp[2009][2009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = n - 1; i >= 1; i--) {
		int lb = n - 1, r = i, rb = (i + 1) % n;
		for (int j = 0; j < n; j++) {
			if(i & 1) dp[j][r] = (a[lb] > a[r] ? dp[lb][r] : dp[j][rb]);
			else dp[j][r] = max(dp[lb][r] + a[lb], dp[j][rb] + a[r]);
			if (++lb == n) lb = 0;
			if (++r == n) r = 0;
			if (++rb == n) rb = 0;
		}
	}
	long long ret = 0;
	for (int i = 0; i < n; i++) ret = max(ret, dp[i][(i + 1 == n ? 0 : i + 1)] + a[i]);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 34480
N=int(input())
t=list(map(int,input().split()))
l=1
k=t[0]
a=0
for i in range(N):
    while l<N and k&t[l]==0:
        k+=t[l]
        l+=1
    a+=l-i
    k-=t[i]
print(a)    

Measured memory_bytes: 24584
h, w, d = map(int, input().split())
A = []

for _ in range(h):
    line = list(map(int, input().split()))
    A.append(line)

num_to_xy = [[0, 0] for i in range(h*w + 1)]

for y in range(h):
    for x in range(w):
        num = A[y][x]
        num_to_xy[num] = [x, y]

costs = [0] * (h*w+1)

for start in range(1, d+1):
    cost = 0
    num = start
    sx, sy = num_to_xy[num]
    while num <= h*w:
        nx, ny = num_to_xy[num]
        cost += abs(nx-sx) + abs(ny-sy)
        costs[num] = cost
        sx, sy = nx, ny
        num += d

q = int(input())

for _ in range(q):
    l, r = map(int, input().split())
    print(costs[r] - costs[l])

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    cin >> n;
    int res = 1000-n % 1000;
    if(res==1000)
        res = 0;
    c(res);
}
			

Measured memory_bytes: 3636