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

using namespace std; 
  int main()
  {
      int n,w;
      cin>>n>>w;
     int a[n][2];
     long int i,j;
     for(i=0;i<n;i++)
     {
         cin>>a[i][0]>>a[i][1];
     }
    long long int dp[w+1][n+1];
    for(i=0;i<=w;i++)
    {
        for(j=0;j<=n;j++)
        {
            if(i==0||j==0)
            dp[i][j]=0;
            else
            {
                if((i-a[j-1][0])>=0)
                dp[i][j]=max(dp[i][j-1],dp[i-a[j-1][0]][j-1]+a[j-1][1]);
                else
                dp[i][j]=dp[i][j-1];
            }
        }
    }
    cout<<dp[w][n]<<endl;
    
      
      return 0;
  }

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

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
 
  double max = 0;
  int water = 0;
  int sugar = 0;
  for (int ai = 0; 100 * a * ai <= f; ++ai) {
    for (int bi = 0; 100 * b * bi <= f; ++bi) {
      for (int ci = 0; c * ci <= f; ++ci) {
        for (int di = 0; d * di <= f; ++di) {
          int x = c * ci + d * di;
          int y = 100 * a * ai + 100 * b * bi;
          double noudo = (double)x / (x + y);
          if (noudo > max && x + y <= f && x <= e*y / 100) {
            max = noudo;
            water = y;
            sugar = x;
          }
        }
      }
    }
  }
  if (sugar == 0) water = 100 * a;
  cout << water + sugar << " " << sugar << endl;
}

Measured memory_bytes: 3636
N = int(input())
c = input()
a, b = c.count('R'), 0
ans = max(a,b)

for i in range(N):
  if c[i]=='R':
    a-=1
  else:
    b+=1
  now=max(a,b)
  ans=min(ans, now)

print(ans)

Measured memory_bytes: 9416
use std::io::BufRead;
use std::cmp::max;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}

impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap();
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone())
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone(), tmp_var[2].clone())
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());
    let (n, max_w): (usize, usize) = input!(r, usize, usize);
    let mut values: Vec<usize> = vec![0];
    let mut weights: Vec<usize> = vec![0];
    for i in 0..n {
        let (v, w): (usize, usize) = input!(r, usize, usize);
        values.push(v);
        weights.push(w);
    }
    let mut memo = vec![vec![0; max_w + 1]; n + 1];
    for i in 1..n+1 {
        for j in 0..max_w+1 {
            let now_w = weights[i];
            let now_v = values[i];
            if now_w > j {
                memo[i][j] = memo[i-1][j];
            } else {
                memo[i][j] = max(memo[i][j-now_w] + now_v, memo[i-1][j]);
            }
        }
    }
    println!("{:?}", memo[n][max_w]);
}



Measured memory_bytes: 13112
#!/usr/bin/env python3

from collections import Counter

N = int(input())
H = list(map(int, input().split()))
L = []
R = []

for i, j in enumerate(H):
    L.append(i+j)
    R.append(i-j)

b = Counter(R)
ans = 0

for i in L:
    ans += b.get(i,0)
print(ans)

Measured memory_bytes: 50872
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  int N;
  cin >> N;
  int D[N];
  rep(i, N){
    cin >> D[i];
  }
  int ans = 0;
  rep(i, N){
    repi(j, i+1, N){
      ans += D[i] * D[j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
#include<stdio.h>

int main(){
   int n;
   scanf("%d",&n);
   if(n%10 == 3){
      printf("bon\n");
   } else if((n%10 == 0) || (n%10 == 1) || (n%10 == 6) || (n%10 == 8)){
      printf("pon\n");
   } else {
      printf("hon\n");
   }
}


Measured memory_bytes: 1660
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())
    grid=[None]*(h+2)
    grid[0]=['#']*(w+2)
    grid[-1]=['#']*(w+2)
    for i in range(1,h+1):
        grid[i]=list('#'+input()+'#')

    # startは(1,1) goalは(h,w)
    dist=[[INF]*(w+1) for _ in range(h+1)]
    dist[1][1]=1
    from collections import deque
    from itertools import product

    # BFS
    Q=deque([(1,1)])
    while(Q):
        i,j=Q.popleft()
        # 上下左右の4方向をcheck
        for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]:
            if(grid[i+di][j+dj]=='#'): continue
            if(dist[i+di][j+dj]!=INF): continue
            dist[i+di][j+dj]=dist[i][j]+1
            Q.append((i+di,j+dj))

    if(dist[h][w]==INF):
        print(-1)
        return

    cnt=0
    for i in range(1,h+1):
        for j in range(1,w+1):
            cnt+=grid[i][j]=='.'
    print(cnt-dist[h][w])
resolve()

Measured memory_bytes: 41456
#include<bits/stdc++.h>
using namespace std;
const int n=100001;
int a[n];

void eratosthenes(){
    for(int i=0;i<n;i++){
        a[i]=1;
    }
    for(int i=2;i<sqrt(n);i++){
        if(a[i]){
            for(int j=0;i*(j+2)<n;j++){
                a[i*(j+2)]=0;
            }
        }
    }
    a[0]=a[1]=0;
}
int main(){
    eratosthenes();
    vector<int> b(n,0);
    for(int i=3;i<n;i+=2){
        if(a[i]==1&&a[(i+1)/2]==1) b[i]=1;
    }
    for(int i=1;i<n;i++){
        b[i]+=b[i-1];
    }
    int q;cin>>q;
    vector<int> ans(q);
    for(int i=0;i<q;i++){
        int l,r;cin>>l>>r;
        ans[i]=b[r]-b[l-1];
    }
    for(int i=0;i<q;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val dl = mutableListOf<Int>()
    readLine()!!.split(" ").map(String::toInt).sorted().reduce { a, b -> dl.add(b - a); b }
    dl.sort()
    print(if (m > n) dl.take(m - n).sum() else 0)
}

Measured memory_bytes: 54956
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    pw.println(
      IntStream.rangeClosed(1, n)
        .mapToObj(String::valueOf)
        .mapToInt(String::length)
        .filter(i -> i % 2 == 1)
        .count());
  }
}


Measured memory_bytes: 31416
#include<stdio.h>
#include<stdlib.h>
int main(void){
        int n,m,i,j,num,tmp;
        int *B,**A;
        scanf("%d %d",&n,&m);
        B = (int *)malloc(sizeof(int)*m);
        A = (int **)malloc(sizeof(int *)*n);
        for(i=0;i<n;i++){
                A[i] = (int *)malloc(sizeof(int )*m);
        }
        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        scanf("%d",&A[i][j]);
                }
        }
        for(i=0;i<m;i++){
                scanf("%d",&B[i]);
        }
        for(i=0;i<n;i++){
                tmp = 0;
                for(j = 0;j<m;j++){
                        tmp = tmp + A[i][j] * B[j];
                }
                printf("%d\n",tmp);
        }
        for(i=0;i<n;i++){
                free(A[i]);
        }
        free(A);
        return 0;
}

Measured memory_bytes: 636
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
list($n)=sscanf(trim(fgets(STDIN)),"%d");
$sc = new Scanner();
$p=array();
for($i=1;$i<=$n;$i++){
    $p[$i] = $sc->nextInt();
}
$cnt = 0;
for($i=1+1;$i<=$n-1;$i++){
    if(($p[$i] > $p[$i-1])&&($p[$i] < $p[$i+1])){
        $cnt++;
    }else if(($p[$i] < $p[$i-1])&&($p[$i] > $p[$i+1])){
        $cnt++;
    }
}
printf($cnt);
//$

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define mod 1000000007

// int power(int a,int b)
// {
//     if(b==0)
//     return 1;
//     if(b==1)
//     return a;
//     int ans=power(a,b/2);
//     if(b%2==0)
//     return (ans*ans)%mod;
//     else
//     return (((ans*ans)%mod)*a)%mod;
// }
void solve()
{
//   int n;cin>>n;
//   if(n==1)
//   cout<<0<<endl;
//   else if(n==2)
//   cout<<2<<endl;
//   else
//   {
//       int ans=(2*power(10,n-2))%mod;
//       cout<<ans<<endl;
//   }
int a;int b;int c;int d;cin>>a>>b>>c>>d;
  int ans=b*c;
  ans=max(ans,a*c);
  ans=max(ans,a*d);
  ans=max(ans,b*d);
  
   if(a<=0 && b>=0 || c<=0 && d>=0)
    ans=max(ans,0ll);
    
  cout<<ans<<endl;
}

int32_t main() 
{
    rapido;
    int t;
    // cin>>t;
     t=1;
    while(t--)
    solve();
    return 0;
}


/*
 int a;int b;int c;int d;cin>>a>>b>>c>>d;
  int ans=b*c;
  ans=max(ans,a*c);
  ans=max(ans,a*d);
  ans=max(ans,b*d);
  
   if(a<=0 && b>=0 || c<=0 && d>=0)
    ans=max(ans,0ll);
    
  cout<<ans<<endl;
  */

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   string S[N];
   map<string ,int> M;
   for (int i = 0; i < N; i++)
   {
      cin >> S[i];
      M[S[i]]++;
   }
   string ans[]= {"AC", "WA", "TLE", "RE"};
   for(int i = 0 ; i <4; i++){
      cout << ans[i] << " x " << M[ans[i]] << endl;
   }
   
   return 0;
}


Measured memory_bytes: 6676
#include <stdio.h>
#include <algorithm>

int main() {
	char str1[11], str2[11], str3[11];
	scanf("%s %s %s", str1, str2, str3);
	char out[4] = { 0 };
	out[0] = str1[0] - 0x20;
	out[1] = str2[0] - 0x20;
	out[2] = str3[0] - 0x20;
	printf("%s\n", out);
}

Measured memory_bytes: 128
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);

	        
	        int N = sc.nextInt();	
	        int[] a = new int[N];
	        for (int i=0 ; i<N; i++) {
	            a[Integer.parseInt(sc.next())-1] = i;
	        }
	        long ans=1;
	        long cnt=1;
	        for(int i=0;i<N;i++) {
	        	if(i!=N-1&&a[i]<a[i+1])cnt++;
	        	else {
	        		ans=Math.max(ans, cnt);
	        		cnt=1;
	        	}
	        }
	        ans=Math.max(ans, cnt);
	        ans=N-ans;
	        
	        
	        System.out.println(ans);
	    }
	}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[4001],d[4002][5];

void nhap()
{
    scanf("%d",&n);
    string s;
    cin>>s;
    for (int i=0;i<n;++i)
    {
        if (s[i]=='R') a[i+1]=1;
        else if (s[i]=='G') a[i+1]=2;
        else a[i+1]=3;
    }
}

void process()
{
    for (int i=n;i>0;--i)
    {
        for (int j=1;j<4;++j)
        {
            d[i][j]=d[i+1][j]+(a[i]==j);
        }
    }
    long long kq=0;
    for (int i=1;i<n-1;++i)
    {
        for (int j=i+1;j<n;++j)
        {
            if (a[i]==a[j]) continue;
            for (int k=1;k<4;++k)
            {
                if (k!=a[i] && k!=a[j])
                {
                    kq+=d[j+1][k];
                    if (2*j-i<=n && a[2*j-i]==k)
                        kq--;
                    break;
                }
            }
        }
    }
    cout<<kq;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 3792
#!/usr/bin/ruby                                                                                                                                   
# -*- coding: utf-8 -*-                                                                                                                           

while true
  n, m = gets.split.map(&:to_i)
  if n == 0 && m == 0
    break
  end
  res = Array.new(m, 0)
  n.times {
    gets.split.map(&:to_i).each_with_index {|x, i|
      res[i] += x
    }
  }
  res.each_with_index.map {|x, i|
    [x, i+1]
  }.sort {|l, r|
    if l[0] == r[0]
      l[1] <=> r[1]
    else
      r[0] <=> l[0]
    end
  }.each_with_index {|x, i|
    if i > 0
      print " #{x[1]}"
    else
      print x[1]
    end
  }
  puts ""
end

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

using namespace std;

int n;
int d[100005];
int dp[30];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		d[i]=str[0]-'a';
	}
	for(int i=0;i<26;i++){
		dp[i]=155555;
	}
	dp[d[0]]=1;
	for(int i=1;i<n;i++){
		//printf("%d\n",d[i]);
		int res=155555;
		//printf("%d\n",i);
		res=min(dp[d[i-1]]+1,res);
		res=min(dp[d[i]],res);
		dp[d[i]]=res;
		//printf("%d\n",res);
	}
	printf("%d\n",dp[d[n-1]]);
	return 0;
}


Measured memory_bytes: 3660
//Written by Rhitwik Saha//
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vb          vector<bool>
#define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define ub(x)       upper_bound(x)
#define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N 			1e5+5
#define M           1000000007
#define MAX         100005
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
int i,j,k;

void Anon_mouS(){
	int h;
	cin>>h;
	int b=1;
	while(2*b<=h)b*=2;
	cout<<2*b-1<<endl;
}
int32_t main(){
    fastio;
    // file;
    // sieve();
    int q=1;
    // cin>>q;
    while(q--)Anon_mouS();
    return 0;
}


Measured memory_bytes: 256
H,W  =map(int,input().split())

a =[]

for i in range(H):
    temp = str(input())
    a.append(temp)
    

cnt =0

for i in range(H+2):
    
    if i==0 or i==H+1:
        print("#"*(W+2))
    else:
        print("#" + a[cnt] + "#")
        cnt+=1
        

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Pyon-Pyon River Crossing
public class Main{

	int[][][] dp;

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m)==0)break;
			int[][] x = new int[n][];
			int[][] a = new int[n][];
			int[] num = new int[n];
			for(int i=0;i<n;i++){
				int k = sc.nextInt();
				x[i] = new int[k];
				a[i] = new int[k];
				num[i] = k;
				for(int j=0;j<k;j++){
					x[i][j] = sc.nextInt();
					a[i][j] = sc.nextInt();
				}
			}
			dp = new int[n][m+1][];
			for(int i=0;i<n;i++){
				for(int j=0;j<=m;j++){
					dp[i][j] = new int[num[i]];
					Arrays.fill(dp[i][j], 1<<30);
				}
			}
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(n, new Comparator<int[]>(){
				public int compare(int[] o1, int[] o2) {
					return dp[o1[0]][o1[1]][o1[2]] - dp[o2[0]][o2[1]][o2[2]];
				}
			});
			for(int j=0;j<num[0];j++){
				dp[0][m][j] = 0;
				q.add(new int[]{0,m,j});
			}
			if(m>0)
				for(int j=0;j<num[1];j++){
					dp[1][m-1][j] = 0;
					q.add(new int[]{1,m-1,j});
				}
			int min = 1<<30;
			while(!q.isEmpty()){
				int[] p = q.poll();
				int i = p[0];
				int rest = p[1];
				int pos = p[2];
				if(n-1<=i||0<rest&&n-2<=i){
					min = Math.min(min, dp[i][rest][pos]);
					continue;
				}
				for(int j=0;j<num[i+1];j++){
					int v = dp[i][rest][pos] + (a[i][pos]+a[i+1][j])*Math.abs(x[i][pos]-x[i+1][j]);
					if(v<dp[i+1][rest][j]){
						dp[i+1][rest][j] = v;
						q.add(new int[]{i+1,rest,j});
					}
				}
				if(rest==0)continue;
				for(int j=0;j<num[i+2];j++){
					int v = dp[i][rest][pos] + (a[i][pos]+a[i+2][j])*Math.abs(x[i][pos]-x[i+2][j]);
					if(v<dp[i+2][rest-1][j]){
						dp[i+2][rest-1][j] = v;
						q.add(new int[]{i+2,rest-1,j});
					}
				}
			}
			System.out.println(min);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int K, S;
    cin >> K >> S;

    int cnt = 0;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            int Z = S-X-Y;
            if (Z >= 0 && Z <= K) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5,mod=998244353;
int w[N],lim,f[N],n,m,g[N],h[N],rev[N],fac[N],ifac[N],inv[N];
void NTT(int a[])
{
	for(int i=0;i<lim;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<lim;i<<=1)
		for(int j=0;j<lim;j+=i<<1)
			for(int k=0;k<i;k++)
			{
				int x=a[j+k],y=1ll*a[i+j+k]*w[i+k]%mod;
				a[j+k]=(x+y)%mod,a[i+j+k]=(x-y)%mod;
			} 
}
int qpower(int a,int b)
{
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;
	return ans;
}
void make(int n)
{
	lim=1;while(lim<=n*2)lim<<=1;
	for(int i=1;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)?(lim>>1):0);
	fac[0]=1;
	for(int i=1;i<=n+2;i++)
		fac[i]=1ll*fac[i-1]*i%mod,
		inv[i]=i==1?1:1ll*(mod-mod/i)*inv[mod%i]%mod;
	ifac[0]=1;
	for(int i=1;i<=n+2;i++)ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
	for(int i=1;i<lim;i<<=1)
	{
		int g=qpower(3,(mod-1)/(i<<1));
		w[i]=1;
		for(int j=1;j<i;j++)w[i+j]=1ll*w[i+j-1]*g%mod;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	make(n);f[0]=1;
	for(int i=0;i<=n;i++)h[i]=ifac[i+2];
	NTT(h);
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<=n;j++)g[j]=1ll*f[j]*ifac[j]%mod;
		for(int j=n+1;j<lim;j++)g[j]=0;
		NTT(g);
		for(int j=0;j<lim;j++)g[j]=1ll*g[j]*h[j]%mod;
		reverse(g+1,g+lim);NTT(g);int ivl=mod-(mod-1)/lim;
		for(int j=0;j<=n;j++)f[j]=(-1ll*f[j]*j+1ll*g[j]*ivl%mod*fac[j+2])%mod;
	}
	int C=1,ans=0;
	for(int i=0;i<=n;i++)ans=(ans+1ll*C*f[i])%mod,C=1ll*C*(n-i)%mod*inv[i+1]%mod;
	cout<<(ans+mod)%mod<<endl;
}

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

    long num,distance,x,y;
    long cnt =0;
    

    cin >> num >> distance;
    
    long dis_lst[num][2];

    for(long i=0; i<num; i++)
    {
        cin >> dis_lst[i][0]>>dis_lst[i][1];
    }

    for(long i=0; i<num; i++)
    {
        x = dis_lst[i][0];
        y = dis_lst[i][1];
        if(x*x + y*y <= distance*distance)
        {
            cnt++;
        }
    }

    cout<<cnt;
 
    return 0;
}


Measured memory_bytes: 6732
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	string str;
	int k;
	cin >> k >> str;
	if(str.size() <= k) cout << str << '\n';
	else {
		cout << str.substr(0, k) << "...\n";
	}
}



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

int isprime(int x)
{
    if (x == 2)
    {
        return true;
    }
    if (x < 2 || x % 2 == 0)
    {
        return false;
    }
    int i = 3;
    while (i <= sqrt(x))
    {
        if (x % i == 0)
        {
            return false;
        }
        i = i + 2;
    }
    return true;
}

int main()
{
    int n;
    int ans = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        int temp;
        cin >> temp;
        if (isprime(temp))
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int W, H, N;
int x[100], y[100], a[100];

void solve() {
    int left = 0, right = W, top = H, bottom = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] == 1) left = max(left, x[i]);
        if (a[i] == 2) right = min(right, x[i]);
        if (a[i] == 3) bottom = max(bottom, y[i]);
        if (a[i] == 4) top = min(top, y[i]);
    }
    if (left >= right || top <= bottom) {
        printf("0\n");
    } else {
        printf("%d\n", (right - left) * (top - bottom));
    }
}

int main() {
    cin >> W >> H >> N;
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> a[i];
    }
    solve();
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    int A[100002];
    int preres=0;

    scanf("%d",&N);

    for(int i=1;i<=N;i++)
        scanf("%d",&A[i]);
    
    A[0]=0;
    A[N+1]=0;
    
    for(int i=1;i<=N+1;i++)
        preres += abs(A[i]-A[i-1]);
    
    int dif,after,res;
    for(int i=1;i<=N;i++)
    {
        dif = abs(A[i]-A[i-1])+abs(A[i+1]-A[i]);
        after = abs(A[i+1]-A[i-1]);
        res = preres - dif + after;
        printf("%d\n",res);
    }


    return 0;
}

Measured memory_bytes: 1664
n = int(input())

digits = 1
base = 10
for i in range(0, 20):
    if n < 10 ** i:
        digits = i
        break

smallest_digit = n % 10
largest_digit = n // (10 ** (digits - 1)) % 10
mid_digit_pattern = (n - largest_digit * (10 ** (digits - 1))) // 10 + 1

def count_pattern(a, b, dig):
    if dig == 1 and a != b:
        return 0
    elif dig == 1:
        return 1
    elif dig == digits:
        if a > largest_digit:
            return 0
        elif a < largest_digit:
            return 10 ** (dig - 2)
        elif b <= smallest_digit:
            return mid_digit_pattern
        elif b > smallest_digit:
            return mid_digit_pattern - 1
        else:
            assert False, "Can't reach here"
    else:
        return 10 ** (dig - 2)

result = 0
if digits == 1:
    result = n
else:
    counts = {}
    for i in range(1, 10):
        for j in range(1, 10):
            state = (i, j)
            counts[state] = sum([count_pattern(i, j, d) for d in range(1, digits + 1)])

    for state in counts.keys():
        result += counts[state] * counts[tuple(reversed(state))]

print(result)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
double dp[305][305][305];
signed main(){
	IOS;
	ll n;cin >> n;
	int c[4];
	memset(c,0,sizeof(c));
	for(ll i=0;i<n;i++){
		int a; cin >> a;
		c[a]++;
	}
	// double dp[2*n][n+1][n+1];
	memset(dp, (double)(0),sizeof(dp));
	// cout << c[1] << " " <<c[2] << " " <<c[3] << endl;
	for(int k=0;k<=c[3];k++){
		for(int j = 0 ; j <= c[2]+c[3] ; j++)
			for(int i = 0 ; i <= c[1]+c[2]+c[3]; i++){
				if(i+j+k>0)
					dp[i][j][k] = (double) (n)/( (i)+ (j)+ (k));
				if(i){
					// cout << dp[i-1][j][k] << " ";

					dp[i][j][k]+=(dp[i-1][j][k]*( (double)(i)/ (i+j+k)));
				
				}
				if(j) dp[i][j][k]+=(dp[i+1][j-1][k]*((double)(j)/ (i+j+k)));
				if(k) dp[i][j][k]+=(dp[i][j+1][k-1]*((double)(k)/ (i+j+k)));
				// cout << dp[i][j][k] << endl;
			}
	}
	cout <<setprecision(18) <<  dp[c[1]][c[2]][c[3]] << endl;


	return 0;
}




Measured memory_bytes: 221952
// AOJ 1243 Weather Forecast
// 2018/1/21

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n;
int date[367];
int cd[4];
char mk[367][10][8][8][8][8];
int pos[12] = {0,1,2,3,0,4,5,6,0,7,8,9};
int mv[9][2] = {{0,0},{0,1},{0,-1},{1,0},{-1,0},{0,2},{0,-2},{2,0},{-2,0}};

char check(int k, int x, int y, int *cd)
{
	int a = ((x - 1) << 2) + y;
	if ((date[k] & (1<< a  ))  || (date[k] & (1<<(a+4))) ||
		(date[k] & (1<<(a+1))) || (date[k] & (1<<(a+5)))) return 0;
	if (mk[k][pos[a]][cd[0]][cd[1]][cd[2]][cd[3]]) return 0;
    return 1;
}

int dfs(int k, int x, int y, int *cd)
{
	int i, j, t, x2, y2;
	int a[5];

	if (k == n) return 1;
	for (i = 0; i < 9; i++) {
		if (!k && i) break;
		t = k + 1, x2 = x + mv[i][0], y2 = y + mv[i][1];
		if (x2 < 1 || x2 > 3 || y2 < 1 || y2 > 3) continue;
		for (j = 0; j < 4; j++) a[j] = cd[j] + 1;
		if (x2 == 1 && y2 == 1) a[0] = 0;
		if (x2 == 1 && y2 == 3) a[1] = 0;
		if (x2 == 3 && y2 == 1) a[2] = 0;
		if (x2 == 3 && y2 == 3) a[3] = 0;
		if (a[0] >= 7 || a[1] >= 7 || a[2] >= 7 || a[3] >= 7) continue;

		if (check(t, x2, y2, a)) {
			mk[t][pos[((x2-1)<<2)+y2]][a[0]][a[1]][a[2]][a[3]] = 1;
			if (dfs(t, x2, y2, a)) return 1;
		}
	}
	return 0;
}

int main ()
{
	int i, j;
	char buf[40], *p;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		n = atoi(buf);

		memset(date, 0, sizeof(date));
		for (i = 1; i <= n; i++) {
			fgets(p=buf, 40, stdin);
			for (j = 1; j <= 16; j++) {
				while (*p < '0') p++;
				date[i] |= (*p++ & 0xf) << j;
			}
		}

		memset(mk, 0, sizeof(mk));
		memset(cd, 0, sizeof(cd));
		putchar('0' + dfs(0, 2, 2, cd));
		putchar('\n');
	}
	return 0;
}


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

int main(){
  int n; cin >> n;
  vector<string> w(n);
  bool ok = true;
  for(int i= 0; i< n; i++){
    cin >> w.at(i);
  }
  for(int i = 1; i < n; i++){
    if(w.at(i).at(0) != w.at(i-1).at(w.at(i-1).size()-1)) ok = false;
  }
  sort(w.begin(), w.end());
  for(int i = 0; i < n-1; i++){
    if(w.at(i) == w.at(i+1)) ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}
       

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict, Counter
import itertools

mask = (1 << 10) - 1

symmetry = dict()
decode = dict()
counter = defaultdict(int)

def encode(a,b,c,d):
    t = 1 << 40
    for x,y,z,w in [(a,b,c,d), (b,c,d,a), (c,d,a,b), (d,a,b,c)]:
        u = x + (y << 10) + (z << 20) + (w << 30)
        if t > u:
            t = u
    return t

N = int(input())
tiles = []
for _ in range(N):
    a,b,c,d = map(int,input().split())
    t = encode(a,b,c,d)
    tiles.append(t)
    counter[t] += 1
    if a == b == c == d:
        symmetry[t] = 4
    elif a == c and b == d:
        symmetry[t] = 2
    else:
        symmetry[t] = 1
    decode[t] = (a,b,c,d)

P = [(1,n,n*(n-1),n*(n-1)*(n-2),n*(n-1)*(n-2)*(n-3)) for n in range(N+1)]
P += [(0,0,0,0,0)] * (N+1) # 負数代入対策

power = [[n ** e for e in range(5)] for n in range(5)]

answer = 0
for bottom, top in itertools.combinations(tiles,2):
    counter[bottom] -= 1
    counter[top] -= 1
    a,b,c,d = decode[bottom]
    e,f,g,h = decode[top]
    for x,y,z,w in [(e,f,g,h), (f,g,h,e), (g,h,e,f), (h,e,f,g)]:
        # a,b,c,d
        # x,w,z,y 
        tiles = [encode(p,q,r,s) for p,q,r,s in [(b,a,x,w), (c,b,w,z), (d,c,z,y), (a,d,y,x)]]
        need = Counter(tiles)
        x = 1
        for tile, cnt in need.items():
            have = counter[tile]
            if have < cnt:
                x = 0
                break
            x *= P[counter[tile]][cnt] # 残っている個数、必要枚数
            x *= power[symmetry[tile]][cnt]
        answer += x
    counter[bottom] += 1
    counter[top] += 1

# 上下を固定した分
answer //= 3
print(answer)

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;
template<typename T>
using reversed_priority_queue = \
    std::priority_queue<T, std::vector<T>, std::greater<T> >;

struct Edge {
  ll next, yen, snuuk;
};

const ll INF = ((ll)1)<<62;
const ll OFFSET = 1000000000000000ll;

vector<Edge> edges[200000];
vector<ll> c_yen(200000, INF); // startからの円での距離
vector<ll> c_snuuk(200000, INF); // endからのsnuukでの距離

signed main() {
  ll N, M, S, T;
  cin >> N >> M >> S >> T;
  rep(i,M) {
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    edges[u].push_back({v,a,b});
    edges[v].push_back({u,a,b});
  }

  {
    reversed_priority_queue<PLL> q;
    q.push({0, S});
    while(!q.empty()) {
      ll v, yen;
      tie(yen, v) = q.top();
      q.pop();
      if (c_yen[v] <= yen)
        continue;
      c_yen[v] = yen;
      for (auto e : edges[v]) {
        q.push({yen+e.yen, e.next});
      }
    }
  }
  {
    reversed_priority_queue<PLL> q;
    q.push({0, T});
    while(!q.empty()) {
      ll v, snuuk;
      tie(snuuk, v) = q.top();
      q.pop();
      if (c_snuuk[v] <= snuuk)
        continue;
      c_snuuk[v] = snuuk;
      for (auto e : edges[v]) {
        q.push({snuuk+e.snuuk, e.next});
      }
    }
  }

  vector<ll> ans(N+1);
  ll p = c_yen[N] + c_snuuk[N];
  ans[N-1] = c_yen[N] + c_snuuk[N];
  for (ll i=N-2; i>=0; i--) {
    ans[i] = min(ans[i+1], c_yen[i+1] + c_snuuk[i+1]);
  }

  rep(i,N){
    printf("%lld\n", OFFSET - ans[i]);
  }
  return 0;
}


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

int main()
{
	int a,b,x;
	cin>>a>>b;

	   if((a+b)%2==0)
	      x=(a+b)/2;
	   else
	      x=(a+b)/2+1;
	   
	cout<<x;
    return 0;	
}

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

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;

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

    if(a>b )cout<<0<<nl;
    else if(n==1 and a!=b)cout<<0<<nl;
    else
    {
        ll  ans;
        ans=n*(b-a)+2*(a-b)+1;
        cout<<ans<<nl;
    }

    bdyptb;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)
        cout<<a-1<<" "<<b<<endl;
    else if(u==t)
        cout<<a<<" "<<b-1<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int n, s, memo[9][102][1001];

int rec(int c = 0, int pre = -1, int sum = 0) {
	if (c == n) {
		return sum == s;
	}
	if (sum > s) {
		return 0;
	}
	if (memo[c][pre + 1][sum] != -1) {
		return memo[c][pre + 1][sum];
	}
	int res = 0;
	range (i, pre + 1, 101) {
		res += rec(c + 1, i, sum + i);
	}
	return memo[c][pre + 1][sum] = res;
}

signed main() {
	while (cin >> n >> s, n) {
		memset(memo, -1, sizeof(memo));
		cout << rec() << endl;
	}
	return 0;
}


Measured memory_bytes: 10260
#include<stdio.h>

int main(){
	char className [9][15];
	int a[9],b[9];
	int i;

	for(i = 0; i < 9; i++){
		scanf("%s %d %d", className[i], &a[i], &b[i]);
	}

	for(i = 0; i < 9; i++){
		printf("%s %d %d\n", className[i], a[i] + b[i], a[i] * 200 + b[i] * 300);
	}

	return 0;
	}

Measured memory_bytes: 1024
param_n = int(input())
param_list = list(map(int, input().split()))

if param_n in [0,1,2]:
  print(0)

else:
  param_list.sort()
  
  #print(param_list)
  
  param_count = 0
  int_len = len(param_list)
  
  for small in range(0, int_len):
    for middle in range(small+1, int_len):
      for large in range(middle+1, int_len):
        list_tmp = list()
        list_tmp.append(param_list[small])
        list_tmp.append(param_list[middle])
        list_tmp.append(param_list[large])
        
        # print(len(set(list_tmp)) == 3)
        
        if (len(set(list_tmp)) == 3) & (list_tmp[0] + list_tmp[1] > list_tmp[2]):
          param_count = param_count + 1
          
  print(param_count)
  

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

int main() {
  int N;
  cin >> N;
  
  if (N/10%111 == 0)
    cout << "Yes" << endl;
  
  else if (N%1000%111 == 0)
    cout << "Yes" << endl;
  
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=3e5+10,mod=1e9+7,INF=0x3f3f3f3f;
vector<int> d;
int rt[maxn],ls[maxn*22],rs[maxn*22],mx[maxn*22],id;
void upd(int pre,int& now,int p,int c,int l,int r){
	now=++id;
	ls[now]=ls[pre];
	rs[now]=rs[pre];
	mx[now]=max(c,mx[pre]);
	if (l==r)
		return;
	int m=(l+r)>>1;
	if (p<=m)
		upd(ls[pre],ls[now],p,c,l,m);
	else
		upd(rs[pre],rs[now],p,c,m+1,r);
}
int qry(int now,int L,int R,int l,int r){
	if (L>R)
		return 0;
	if (L<=l&&r<=R)
		return mx[now];
	int m=(l+r)>>1;
	int res=0;
	if (L<=m)
		res=max(res,qry(ls[now],L,R,l,m));
	if (R>m)
		res=max(res,qry(rs[now],L,R,m+1,r));
	return res;
}
inline int hs(int x){
	return lower_bound(All(d),x)-d.begin()+1;
}
int a[maxn],ans[maxn];
vector<int> e[maxn];
void dfs(int u,int fa){
	int res=qry(rt[fa],1,hs(a[u])-1,1,sz(d));
	ans[u]=max(ans[fa],res+1);
	upd(rt[fa],rt[u],hs(a[u]),res+1,1,sz(d));
	//dd(u),dd(hs(a[u])),de(res);
	for (int i=0;i<sz(e[u]);++i){
		int v=e[u][i];
		if (v==fa)	continue;
		dfs(v,u);
	}
}
int main()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		d.pb(a[i]);
	}
	sort(All(d));
	d.erase(unique(All(d)),d.end());
	for (int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	dfs(1,0);
	for (int i=1;i<=n;++i)
		printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 73044
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
inline void solve(void){
  ll x,y,z;
  in(x,y,z);
  swap(x,y);
  swap(x,z);
  out(x,y,z);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define int long long
int f[50][50][50],n,N,ans;
char s[50][50];
int dp(int l,int r,int mid){
	if(f[l][r][mid]!=-1)return f[l][r][mid];
	if(l==r)return f[l][r][mid]=1;
	if(l==mid||mid==r)return f[l][r][mid]=0;
	int ans=0;
	for(int j=l;j<=mid-1;j++)
		for(int k=mid+1;k<=r;k++)
			if(s[j][k]=='1')
				for(int p=j;p<=mid-1;p++)
					for(int q=mid+1;q<=k;q++)
						ans+=dp(l,p,j)*dp(p+1,q-1,mid)*dp(q,r,k);
	return f[l][r][mid]=ans;
}
signed main(){
	scanf("%lld",&n);
	N=2*n;
	for(int i=1;i<=N;i++)
		scanf("%s",s[i]+1);
	memset(f,-1,sizeof(f));
	for(int i=2;i<=N;i++)
		if(s[1][i]=='1')
			ans+=dp(2,N,i);
	printf("%lld\n",ans);
	return 0;		
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>

using namespace std;

long long child[105];

int main(){
    int N;
    long long x;
    cin >> N >> x;
    for(int i=1; i<=N; i++){
        cin >> child[i];
    }
    sort(child+1, child+N+1);
    if(x < child[1]){
        cout << "0" << endl;
     } else {
        int temp = 0;
        while(x >= child[temp+1] && temp < N){
            temp++;
            x-= child[temp];
        }
        if(x != 0 && temp == N) temp --;
        cout << temp  << endl;
     }
}

Measured memory_bytes: 256
from collections import defaultdict


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for i in range(1, n + 1):
        f = f * i % MOD
        factorials.append(f)
    return factorials


n, x = map(int, input().split())
sss = list(map(int, input().split()))
sss.sort(reverse=True)
ms = sss.pop()
MOD = 10 ** 9 + 7
factorials = prepare(n, MOD)
dp = {x: 1}
ans = 0
for i, s in enumerate(sss):
    ndp = defaultdict(lambda: 0)
    k = n - i
    for y, c in dp.items():
        if y < s:
            ndp[y] = (ndp[y] + c * k) % MOD
        else:
            z = y % s
            ndp[y] = (ndp[y] + c * (k - 1)) % MOD
            if z < ms:
                ans = (ans + z * c * factorials[k - 1]) % MOD
            else:
                ndp[z] = (ndp[z] + c) % MOD
    dp = ndp

for y, c in dp.items():
    ans = (ans + (y % ms) * c) % MOD

print(ans)


Measured memory_bytes: 5520
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

int main(){
	int n;
  cin >> n;
  string s;
  cin >> s;
  bool pos = (n%2 == 0);
  if(pos){
  	for(int i = 0; i < n/2; ++i){
    	pos&=(s[i] == s[i+n/2]);
    }
  }
  if(pos)cout << "Yes";
  else cout << "No";
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int l,r,sl,sr,n,ans;
char st[10];
int huan(char ch){
	if (ch == 'M') return 0;
	if (ch == 'F') return 1;
	return 2;
}
int main(){
	scanf("%d",&n);
	l = 0;
	r = n;
	printf("%d\n",0);
	fflush(stdout);
	scanf("%s",st);
	ans = huan(st[0]);
	sl = ans;
	sr = ans;
	while (ans != 2){
		int m = (l + r) / 2;
		printf("%d\n",m);
		fflush(stdout);
		scanf("%s",st);
		ans = huan(st[0]);
		if ((m - l) % 2 != (ans + 2 - sl) % 2){
			r = m;
			sr = ans;
		}
		else{
			l = m;
			sl = ans;
		}
	}
}

Measured memory_bytes: 852
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, m, n, l;
int ans;

const int N = 100001;
double x[N], y[N];
ll K;
int p[N], q[N], v[N];

int main() {
	//freopen("x.in", "r", stdin);

	cin >> n;
	F1(i, n) {
		cin >> x[i];
		p[i] = i;
	}
	cin >> m >> K;
	F0(i, m) {
		cin >> j;
		swap(p[j - 1], p[j]);
	}
	
	// j, p[j], p[p[j]] ..
	// 

	F1(i, n - 1) if (!v[i]) {
		int j = i;
		vector<int> z;
		while (!v[j]) {
			z.push_back(j);
			v[j] = 1;
			j = p[j];
		}
		F0(j, SZ(z)) {
			q[z[j]] = z[(j + K) % SZ(z)];
		}
	}

	y[1] = x[1];
	for (int i = 2; i <= n; i++) {
		y[i] = y[i - 1] + (x[q[i - 1] + 1] - x[q[i - 1]]);
	}

	F1(i, n){
		printf("%.10lf\n", y[i]);
	}
	return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i, n) for(int i = 1; i <= (int)(n); i++)
#define co(x) cout<<x<<endl
typedef long long int lint;

int main(){
  int A,B,C,D;
  cin >> A >> B  >> C >> D;
  if((C-1)/B > (A-1)/D){co("No");}
  else{co("Yes");}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int M = 25;
int n, d;
int g[M][M];
int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n >> d;
  for(int i=0;i<n;i++) {
    for(int j=0;j<d;j++) {
      cin >> g[i][j];
    }
  }
  int ans = 0;
  for(int i=0;i<n;i++) {
    for(int j=i+1;j<n;j++) {
      int sum = 0;
      for(int k=0;k<d;k++) {
        sum+=(g[i][k] - g[j][k])*(g[i][k] - g[j][k]);
      }
      int sq=sqrt(sum);
      if (sq*sq==sum) ans++;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
s = input()

flag = True
n = len(s)
for i in range(n//4):
  if s[i] == s[(n-1)//2 -1 - i] == s[(n+3)//2 -1 + i] == s[n-1 - i]:
    if (n//2) % 2 == 1:
      if s[n//4] != s[n-1 - n//4]:
        flag = False
        break
      else:
        continue
    else:
      continue
  else:
    flag = False
    break

if flag == True:
  print('Yes')
else:
  print('No')

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, M) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A, A + M, [](pll a, pll b) { return a.second < b.second; });
    ll left = 0;
    ll ans = 0;
    REP(i, M) {
        if (A[i].first <= left && left < A[i].second)
            continue;
        ans++;
        left = A[i].second - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792