akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
using namespace std;
int min (int a, int b){
  if(a<b) return a;
  else return b;
}
int max (int a, int b){
  if(a>b) return a;
  else return b;
}
int main(){
  int a,b,k;
  cin >>a>>b>>k;

  for(int i=a ;i<=min(a+k-1,b); i++)
  cout << i<<endl;
  for(int i=max(b-k+1,a+k) ;i<=b; i++)
  cout << i<<endl;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll n;
  cin >> n;
  VI H(n);
  rep(i,n){
    cin >> H[i];
  }
  int maxHeight = 0;
  ll ans = 0;
  rep(i,n){
    if(maxHeight <= H[i]){
      ans++;
      maxHeight = max(H[i],maxHeight);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



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

    for(ll i = 1; i <= 3500; i++){
        for(ll j = 1; j <= 3500; j++){
            if(4 * i * j - (i + j) * n <= 0)continue;

            if(n * i * j % (4 * i * j - (i + j) * n) == 0){
              	ll k = n * i * j / (4 * i * j - (i + j) * n);
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 256
((input: string): void => {
    const [[_, k], s]: any[] = (
        (h) => [h[0].split(" ").map(Number), h[1].trim()]
    )(input.split(/\n/))
    const hoge = s.split("").map(
        (v, i) => i+1==k ? v.toLowerCase() : v
    ).join("");
    console.log(hoge);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>


int main(void)
{	
	int h, w, i, j;
	
	for( ; ; ){
		scanf(" %d %d", &h, &w );
		if(h==0 && w==0) break;
		
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	
	}
	
	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> Cij(3, vector<int>(3));
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> Cij.at(i).at(j);
    }
  }
  
  bool t = true;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
      if (Cij.at(i).at(0) - Cij.at(i+1).at(0) != Cij.at(i).at(j) - Cij.at(i+1).at(j)) {
        t = false;
        break;
      }
    }
  }
  for (int j = 0; j < 2; j++) {
    for (int i = 0; i < 3; i++) {
      if (Cij.at(0).at(j) - Cij.at(0).at(j+1) != Cij.at(i).at(j) - Cij.at(i).at(j+1)) {
        t = false;
        break;
      }
    }
  }
  if (t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
typedef long long int ll;
typedef double f;
int main()
{
  f n,d,x,y,z;
  ll l=0;
  cin>>n>>d;
  while(n--)
  {
    cin>>x>>y;
    z=sqrt((x*x)+(y*y));
    if(z<=d)
      l++;
  } 
  cout<<l<<"\n";
  return 0;
}  

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

int main()
{
    int a[9]={111,222,333,444,555,666,777,888,999};
    int n;
    cin>>n;
    for(int i=0;i<9;i++)
        if(a[i]>=n)
    {
        cout<<a[i];
        break;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  N = N % 100;
  N = N % 10;
  if(N == 3) {
    cout << "bon" << endl;
  }
  else if(N == 0 || N == 1) {
    cout << "pon" << endl;
  }
  else if(N == 6 || N == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;//for StringBuilder
class c
{
    static void Main()
    {
        var kx = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int k = kx[0], x = kx[1];
        if (k * 500 >= x) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

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


using namespace std;

int main() {
    int n,i;
    cin >> n;
    int a[n],num[n];
    
    for(i = 0; i < n; i++) {
        cin >> a[i];
        num[a[i]-1] = (i+1);
    }
    for(i = 0; i < n; i++) {
        cout << num[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
 
void _main() {
  int A, B, T;
  cin >> A >> B >> T;
 
  int ans = 0;
  for (int i=1; i*A<=T; i++) {
    ans += B;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int main(){
  int n;
  cin >> n;
  VS s(n);
  VI p(n);
  vector<tuple<string,int,int>> tpl(n);
  REP(i,0,n){
    cin >> s[i] >> p[i];
    tpl[i] = make_tuple(s[i], 100-p[i], i+1);
  }
  
  sort(tpl.begin(),tpl.end());
  
  REP(i,0,n){
    cout << get<2>(tpl[i]) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    long long ans = a[n-1];
    for (int i = n-2, k = n-2; k > 0; i--) {
        if (k > 1) { ans += 2 * a[i]; k -= 2; }
        else { ans += a[i]; k = 0; }
    }
    cout << ans << endl;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int X, Y;
    cin >> X >> Y;

    if (X * 2 <= Y && X * 4 >= Y && Y % 2 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a[n];
    double sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=1.0*a[i];
    }
    double ave=sum/n;
    double diff=INF,ans;
    for(int i=0;i<n;i++){
        double tmp=abs(1.0*a[i]-ave);
        if(diff>tmp){
            diff=tmp;
            ans=i;
        }
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
///BISMILLAH'IR  RO'HMANIR  ROH'IM
///RIFAT SHARIAR SAKIL
///SOFTWARE ENGINEERING(SUST)

#include<stdio.h>
#include<string.h>
int main()
{
  char S[100];
  gets(S);
  if(strcmp(S,"Sunny")==0) {printf("Cloudy");}
   if(strcmp(S,"Cloudy")==0) {printf("Rainy");}
    if(strcmp(S,"Rainy")==0) {printf("Sunny");}
  return 0;
}



Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

print(int((1900*M+100*(N-M))*(2**M)))


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int a[4];
  while(cin >> a[0]) {
    REP(i,3)
      cin >> a[i+1];
    int hit = 0;
    int blow = 0;
    REP(i,4) {
      int b;
      cin >> b;
      if (b == a[i])
        hit++;
      else {
        REP(j,4)
          if (b==a[j])
            blow++;
      }
    }
    printf("%d %d\n", hit, blow);
  }
}

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

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
S = [input() for _ in range(n)]
U = []
L = []
for s in S:
  l, r = 0, 0
  for t in s:
    if t == "(":
      r += 1
    else:
      if r > 0:
        r -= 1
      else:
        l += 1
  if l <= r:
    U.append((l, r-l))
  else:
    L.append((r, l-r))
U.sort()
L.sort()
s, t = 0, 0
for a, c in U:
  if s < a:
    print("No")
    exit()
  s += c
for a, c in L:
  if t < a:
    print("No")
    exit()
  t += c
if s != t:
  print("No")
  exit()
print("Yes")

Measured memory_bytes: 248092
# encoding: "utf-8"

from collections import defaultdict

# class Stdin:
#     @staticmethod
#     def read_line(converter=str):
#         return [converter(x) for x in input().split()]
    
#     @staticmethod
#     def read_lines(n, converter=str):
#         result = list()
#         for _ in range(n):
#             result.append(Stdin.read_line(converter))
#         return result
    
#     @staticmethod
#     def convert(data, converter):
#         assert(len(data) == len(converter))
#         return tuple(map(lambda x, f: f(x), data, converter))

#     @staticmethod
#     def convert_lines(datas, n, converter):
#         return [converter(data, n, converter) for data in datas]


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    cnt = xs.count(fst)
    # for x in xs:
    #     if x != fst:
    #         break
    #     cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    for key in xs:
        ys[key] += 1
        ys[key-1] += 1
        ys[key+1] += 1

    print(max(ys.values()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20284
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int count=0;
			boolean flag=true;
			String str[]=new String[n];
			int c[]=new int[n];
			for(int i=0; i<n; i++){
				str[i]=sc.next();
				c[i]=sc.nextInt();
			}
			
			for(int i=0; i<n; i++){
				
				if(str[i].equals("(")){
					count+=c[i];
				}
				else if(str[i].equals(")")){
					if(count==0){
						flag=false;
						break;
					}
					count-=c[i];
					if(count < 0){
						flag=false;
						break;
					}
				}
			}
			if(flag && count==0){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}

	}

}

Measured memory_bytes: 24796
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  // sortの引数には開始位置と終了位置
  sort(p.begin(), p.end());
  int ans = 0;
  // 前からk個取って出力
  rep(i,k) ans += p[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
 
void bubble(int N,char s[],int a[]){
    int i,j,tmp;
    char x;
     
    for(i=0;i<N-1;i++){
        for(j=0;j<N-i-1;j++){
           if(a[j]>a[j+1]){
               tmp=a[j];
               a[j]=a[j+1];
               a[j+1]=tmp;
                
               x=s[j];
               s[j]=s[j+1];
               s[j+1]=x;
           } 
        }
    }
}
 
void selection(int N,char s[],int a[]){
    int i,j,min,tmp;
    char x;
     
    for(i=0;i<N-1;i++){
        min=i;
        for(j=i;j<N;j++){
            if(a[j]<a[min]){
                min=j;
            }
        }
        tmp=a[i];
        a[i]=a[min];
        a[min]=tmp;
         
        x=s[i];
        s[i]=s[min];
        s[min]=x;
    }
}
 
int main(void){
    char s[36],t[36];
    int a[36]={};
    int b[36]={};
    int i,N;
     
    scanf("%d",&N);
    getchar();
    for(i=0;i<N;i++){
        scanf("%c%d",&s[i],&a[i]);
        getchar();
        b[i]=a[i];
    }
    strcpy(t,s);
     
    bubble(N,s,a);
    for(i=0;i<N;i++){
        printf("%c%d",s[i],a[i]);
        if(i!=N-1)printf(" ");
    }
    puts("\nStable");
     
    selection(N,t,b);
    for(i=0;i<N;i++){
        printf("%c%d",t[i],b[i]);
        if(i!=N-1)printf(" ");
    }
    puts("");
     
    if(strcmp(s,t)==0){
        puts("Stable");
    }
    else puts("Not stable");
     
    return 0;
}

Measured memory_bytes: 632
public class Main {
    public static void main(String[] a) {
    		for (int i = 1; i < 10; i++) {
    			for (int j = 1; j < 10; j++) {
    				System.out.println(i + "x" + j + "=" + i*j);
    			}
    		}
    }
}

Measured memory_bytes: 16856
#include<iostream>

using namespace std;

int main(void)
{
  int a,b,c,d; cin>>a>>b>>c>>d;
  
  int d1,d2,d3;
  d1=abs(b-a);
  d2=abs(c-b);
  d3=abs(c-a);
  
  if(d1<=d){
    if(d2<=d){
      puts("Yes"); return 0;
    }
  }
  if(d3<=d){puts("Yes"); return 0;}
  
  puts("No");
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r):
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

from bisect import bisect_right
from operator import add
def resolve():
    n, d, a = map(int, input().split())
    X = [None] * n
    XH = [None] * n
    for i in range(n):
        x, h = map(int, input().split())
        X[i] = x
        XH[i] = x, (h - 1) // a + 1

    X.sort()
    XH.sort()

    tree = SegmentTree([0] * (n + 1), add, 0)
    res = 0
    for i in range(n):
        x, h = XH[i]
        damage = tree.sum(0, i + 1)
        if h < damage:
            continue
        res += h - damage
        tree.add(i, h - damage)
        tree.add(bisect_right(X, x + 2 * d), - h + damage)

    print(res)
resolve()

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

a = [list(input()) for _ in range(H)]

h = [False]*H
w = [False]*W

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            h[i] = True
            w[j] = True
for i in range(H):
    if h[i]:
        for j in range(W):
            if w[j]:
                print(a[i][j],end="")
        print()

Measured memory_bytes: 4596
import numpy as np
s = int(input())
a = np.full(1000001,-1)
a[0] = s
for i in range(1,1000001):
    if a[i-1] % 2 == 0:
        a[i] = a[i-1] // 2
    elif a[i-1] % 2 != 0:
        a[i] = 3*a[i-1] + 1
    
    if a[i] in set(a[:i-1]):
        print(i+1)
        break


Measured memory_bytes: 34512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long H;
        H = sc.nextLong();
        long W;
        W = sc.nextLong();
        if((H==1)||(W==1)){
            System.out.print(1);
        }else if((W*H)%2==0){
            System.out.print(H*W/2);
        }else{
            System.out.print(H*W/2+1);
        }  
    }

    
}

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

int main(){
    int N;
    double count;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
      cin >> a[i];
      if(a[i]%4==0){
        count += 1.0;
      }else if(a[i]%4==2){
        count += 0.5;
      }
    }

    if(count >= N/2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}

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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 998244353;
const int N = 3023;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int a[N], dpk[2][4*N][N], dp[N*4][N], sz, s, ans[N];

void add(int &a, int b){
    a += b;
    if (a >= MOD) a -= MOD;
}

void solve(int l, int r, int v = 0, bool tp = 1){
    dpk[1][v][0] = 1;
    for (int i = 0; i <= r-l; i++){
        int x = a[r-i];
        if (tp) x = a[l+i];
        for (int j = s; j >= x; j--){
            add(dpk[i&1][v][j], dpk[i&1^1][v][j-x]);
        }
        for (int j = 0; j <= s; j++){
            add(dpk[i&1][v][j], dpk[i&1^1][v][j]);
            add(dp[v][j], dpk[i&1][v][j]);
      //      cout << dpk[i&1][v][j] << " ";
            dpk[i&1^1][v][j] = 0;
        }
       // cout << endl;
    }
    //cout <<tp<< " "<< l << " " << r << " " << endl;
    for (int i = 0; i <= s; i++){
        //cout << dp[v][i] << " ";
    }
    //cout << endl;
    if (l == r){
        add(ans[a[l]], 1);
        return;
    }
    int mid = l+r >> 1, lv = v+v+1, rv = v+v+2;
    solve(l, mid, lv, 0);
    solve(mid+1, r, rv, 1);
    for (int i = 0; i <= s; i++){
        add(ans[s], 1ll * dp[lv][i] * dp[rv][s-i] % MOD);
    }

}

void solve(){
    int n;
    cin >> n >> s;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    solve(1, n);
    cout << ans[s];
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    for (int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 295168
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>

#define mod 104857601
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)

const double eps = 0.000000001;
#define ll long long
#define leps 1e-18
#define mkp make_pair
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) begin(v), end(v)
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

// Utils
random_device rd;
mt19937 mt(rd());

const int N_ = 100001;
vector<int> primes;
int *least_prime;
void cieve() {
  least_prime = new int[N_];
  fill(least_prime, least_prime + N_, -1);

  for (int i = 2; i < N_; i++) {
    if (least_prime[i] == -1) {
      least_prime[i] = i;
      primes.pb(i);
    }
    for (auto &c: primes) {
      if (c * i >= N_ || c > least_prime[i]) break;
      least_prime[c * i] = c;
    }
  }
}

template<typename NType>
NType gcd(NType a, NType b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template<typename NType>
NType lcm(NType a, NType b) { return a / gcd(a, b) * b; }
template<typename NType>
NType phi(NType n_) {
  NType ans = n_;
  for (NType i = 2; i * i <= n_; i++) {
    if (n_ % i == 0) {
      while (n_ % i == 0) n_ /= i;
      ans -= ans / i;
    }
  }
  if (n_ > 1) ans -= ans / n_;
  return ans;
}

int binpow(ll a, int n, const int M = mod) {
  ll res = 1;
  while (n) {
    if (n & 1) {
      res = (a * res) % M;
      n--;
    } else {
      a = (a * a) % M;
      n >>= 1;
    }
  }
  ((res %= M) += M) %= M;
  return res;
}
// End of Utils

//ofstream cout("/Users/user/Desktop/test.txt");

void solve(int T) {
  int n;
  cin >> n;
  list<char> mylist;
  string s;
  getline(cin, s);
  getline(cin, s);

  for(char c : s){
    mylist.push_back(c);
  }

  int ans = 0;
  while(!mylist.empty()){
    while(!mylist.empty() && mylist.front() == 'R')
      mylist.pop_front();
    while(!mylist.empty() && mylist.back() == 'W')
      mylist.pop_back();

    if(!mylist.empty()){
      swap(mylist.back(), mylist.front());
      ans ++;
    }
  }
  cout << ans << endl;
}

#define MULTIPLE_TEST 0
#define PRECALC_CIEVE 0
int main(int argc, char const *argv[]){
  if (PRECALC_CIEVE) cieve();
  int t{1};
  if (MULTIPLE_TEST) scanf("%d\n", &t);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int i = 1;
  while (t-- > 0) {
    solve(i++);
  }
}


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

int main(void){
    // Here your code !
    int N;
    cin >> N;

    int ar[N];
    int sum = 0;
    for (int i = 0; i < N; i++) {cin >> ar[i]; sum += ar[i];}

    sort(ar, ar + N);

    if (sum % 10 != 0) {cout << sum << endl; return 0;}

    for (int i = 0; i < N; i++) {
        if ((sum - ar[i]) % 10 != 0) {cout << (sum - ar[i]) << endl; return 0;}
    }

    cout << 0 << endl;

    return 0;
}


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

void rate() {
int x, y, z;
	cin >> x >> y >> z;
	if (x*x + y*y == z*z || y*y + z*z == x*x || z*z + x*x == y*y) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}

}

int main() {
	int i, k;
		cin >> k;
		for (i = 1; i <= k; i = i + 1) {
			rate();
		}
	
	return 0;
}

Measured memory_bytes: 1120
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
for i in range(1,N):
  B.append(B[-1]+A[i])
B = [0]+B
ans=0

d=dict(Counter(B))
for num in d:
  ans += d[num]*(d[num]-1)//2
  
print(ans)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K;
ll X[55], Y[55], ans = INF;

int Solve(int A, int B, int C, int D){
  ll x[4] = {X[A], X[B], X[C], X[D]};
  ll y[4] = {Y[A], Y[B], Y[C], Y[D]};
  sort(x, x + 4); sort(y, y + 4);

  if (x[0] == x[3] || y[0] == y[3]) return 0;

  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (x[0] <= X[i] && X[i] <= x[3] && y[0] <= Y[i] && Y[i] <= y[3]) cnt++;
  }

  if (cnt >= K){
    ans = min(ans, (x[3] - x[0]) * (y[3] - y[0]));
  }
  return 0;
}

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

  for (int i = 0; i < N; i++){
    for (int j = i; j < N; j++){
      for (int k = j; k < N; k++){
        for (int l = k; l < N; l++){
          Solve(i, j, k, l);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll n;
string s;
int main()
{
  cin >> n >> s;
  ll ans = 0;
  REP(i, 10) REP(j, 10) REP(k, 10) {
    bool one = false;
    bool two = false;
    bool three = false;
    REP(l, n) {
      if (two && s[l] - '0' == k) three = true;
      if (one && s[l] - '0' == j) two = true;
      if (s[l] - '0' == i) one = true;
    }
    if (one && two && three) ++ans;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 384
//
//  main.cpp
//  ALDS1_6_B
//
//  Created by ptyuan on 2018/10/29.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdio>

int partition(int *A, int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j = p; j <= r - 1; j++) {
        if (A[j] <= x) {
            i++;
            int temp = A[j];
            A[j] = A[i];
            A[i] = temp;
        }
    }
    A[r] = A[i + 1];
    A[i + 1] = x;
    return i + 1;
}

int main(int argc, const char * argv[]) {
    int n = 0;
    int A[100000];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", A + i);
    }
 
    int p = partition(A, 0, n - 1);
    for (int i = 0; i < n; i++) {
        int indexValue = A[i];
        if (i > 0) {
            printf(" ");
        }
        if (i == p) {
            printf("[%d]", indexValue);
        } else {
            printf("%d", indexValue);
        }
    }
    printf("\n");
    return 0;
}



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

int main(){
 string a;
  cin>>a;
  int b,ans,c;
  b=a.size();
  ans=1000000;
  for(int i=0;i<b-2;i++){
  c=(a[i]-'0')*100+(a[i+1]-'0')*10+a[i+2]-'0';
   ans=min(ans,abs(753-c));
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        for (int j = 0; j < h; j++) {
            for (int i = 0; i < w; i++) {
                if ((i + j) % 2 == 0) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

typedef long double lld;

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))

int N;
string S[110];
int P[110];
int a[110];

int main()
{
	cin >> N;
	REP(i, N) cin >> S[i] >> P[i];

	REP(i, N)
	{
		if (i == 0)
		{
			a[i] = 1;
			continue;
		}
		//さらに階上時間計算する
		REP(j, i)
		{
			//iが新たに比較するもじれつ　
			//jが今の比較するべき文字列
			if (S[i] < S[a[j] - 1] || (S[i] == S[a[j] - 1] && P[i] >= P[a[j] - 1]))
			{
//				cout << S[i] << " " << P[i] << endl;
//				cout << S[a[j]] << " " << P[a[j]] << endl;
				for (int k = i + 1; k > j; k--)
				{
					a[k] = a[k - 1];
				}
//				cout << "j = " << j << endl;
				a[j] = i + 1;
				REP(l, i + 1)
				{
//					cout << a[l] << endl;
				}
//				cout << endl;
				break;
			}
			if (j == i - 1)
			{
				a[j + 1] = i + 1;
				REP(l, i + 1)
				{
//					cout << a[l] << endl;
				}
//				cout << endl;
			}
		}
	}

	REP(i, N) cout << a[i] << endl;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
a[0]-=1
c = [a[0]%4,a[1]%4]
d = [0,0]

for i in range(len(c)):
    if c[i]==0:
        d[i]=a[i]
    elif c[i]==1:
        d[i]=1
    elif c[i]==2:
        d[i]=a[i]+1
    else:
        d[i]=0

print(d[0]^d[1])


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <utility>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

int main(){
    int d,g;
    cin >> d >> g;
    vector<pii> vec;
    int p,c;
    rep(i,d){
        cin >> p >> c;
        vec.push_back(make_pair(p,c));
    }
    vec.push_back(make_pair(0,0));

    int ans = 1e9;

    rep(i,(1<<d) ){
        int total = 0;  
        int cnt = 0;  
        int last = 0;
        vector<bool> s(d+1,false);

        rep(j,d){
            if((i & (1 << j)) != 0){
                s[j] = true;
            }
        }


        rep(j,d){
            if(s[j]){
                total += vec[j].first * (100 * (j+1));
                total += vec[j].second;
                cnt += vec[j].first;
                last = j;
            }
        }

        last++;

        if( vec[last].first == 0){
            for(int j = last-2; j>=0;j--){
                if(!s[j]){
                    last = j;
                    break;
                }
            }
        }

        if(total < g){
            int ls = 100*(last+1);
            if(g-total > vec[last].first * ls){
                continue;
            }else{
                int tmp = (g-total+ls-1)/ls;
                if(tmp > vec[last].first){
                    continue;
                }else{
                    ans = min(ans,cnt + tmp);
                }
            }
        }else{
            ans = min(ans,cnt);
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	fio();
	string s;
	cin >> s;
	s = '0' + s;

	int n = s.size();
	vll dp(n + 1, vl(2, INF));
	dp[0][0] = 0;
	rep (i, n) {
		rep (j, 2) {
			int x = s[n - 1 - i] - '0' + j;
			rep (k, min(x + 1, 9LL)) {
				int nj;
				if (k < x) nj = 1;
				else nj = 0;
				ll add = k;
				if (k < x) add += k + 10 - x;
				chmin(dp[i + 1][nj], dp[i][j] + add);
			}
		}
	}
	cout << dp[n][0] << endl;
}

Measured memory_bytes: 55880
n,x,y=map(int,input().split())

l=[0 for i in range(n-1)]
for i in range(1,n):
    for j in range(i+1,n+1):
        if x>j and x>i:
            l[j-i-1]+=1
        elif y>j>=x and x>i:
            l[min(j-i,y-j+x-i+1)-1]+=1
        elif j>=y and x>i:
            l[j-y+x-i+1-1]+=1
        elif y>j>=x and y>i>=x:
            l[min(j-i,y-j+i-x+1)-1]+=1
        elif j>=y and y>i>=x:
            l[min(j-i,j-y+i-x+1)-1]+=1
        elif j>=y and i>=y:
            l[j-i-1]+=1

for i in l:
    print(i)


Measured memory_bytes: 47836
import java.awt.Point;
import java.awt.event.FocusAdapter;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

import javax.naming.InitialContext;
 
public class Main {
     
	static int W, H;
	static int[][] map;
	static int sx, sy;
	
    static void start()
    {
    	LinkedList<Point> queue = new LinkedList<Point>();
    	queue.offer(new Point(sx, sy));
    	
    	int[][] check = new int[H][W];
    	for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				check[y][x] = 0;
			}
		}
    	
    	while (!queue.isEmpty()) {
			Point p = queue.poll();
			if(check[p.y][p.x] == 1) continue;
			if(map[p.y][p.x] == 1) continue;
			check[p.y][p.x] = 1;
			if(0 < p.x) queue.offer(new Point(p.x-1, p.y));
			if(p.x < W-1) queue.offer(new Point(p.x+1, p.y));
			if(0 < p.y) queue.offer(new Point(p.x, p.y-1));
			if(p.y < H-1) queue.offer(new Point(p.x, p.y+1));
		}
    	
    	int count = 0;
    	for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				if(check[y][x] == 1) count++;
			}
		}
    	
    	System.out.println(count);
    }
     
    public static void main(String[] args)
    {
        Scanner sca = new Scanner(System.in);
        
        while(true)
        {
        	W = sca.nextInt();
        	H = sca.nextInt();
        	if(W == 0) break;
        	
        	map = new int[H][W];
        	for (int y = 0; y < H; y++) {
        		String str = sca.next();
				for (int x = 0; x < W; x++) {
					switch (str.charAt(x)) {
					case '.': map[y][x] = 0; break;
					case '#': map[y][x] = 1; break;
					case '@':
						map[y][x] = 0;
						sy = y;
						sx = x;
						break;
					}
				}
			}
            
            start();
        }
        
    }
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a[20], b[20], c[20];
		for(int j = 0; j < 10; j++){
			cin >> a[j]; 
		}

		int ai = 0, bi = 0, ci = 0;
		b[0] = 0;
		c[0] = 0;
		while(ai < 10){
			if(b[bi] > c[ci]){
				if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else{
					break;
				}
			}else{
				if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else{
					break;
				}
			}
		}

		if(ai == 10){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

int n;
int main()
{
	std::cin >> n;

	int d1 = 0, d2 = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;

		if (a % 4 == 0)
			++d1;
		else if (a % 2 != 0)
			++d2;
	}

	if (d1 >= d2 || d1 + 1 == d2 && n - d1 - d2 == 0)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
	return 0;
}


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

int main(){
  int H,W; cin >> H >> W;
  char s[H][W]; for(int i = 0; i < H; i++)for(int j = 0; j < W; j++) cin >> s[i][j];
  
  /*for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
          cout << s[i][j];
      }
      cout << endl;
  }*/
  
  bool Draw = true;
  
  //内部調査
  for(int i = 1; i < H-1; i++){
      for(int j = 1; j < W-1; j++){
          if(s[i][j] == '#'){
              if(s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.') Draw = false;
          }
      }
  }
  
  //4隅調査
  if(s[0][0] == '#'){
      if(s[0][1] == '.' && s[1][0] == '.') Draw = false;
  }
  if(s[0][W-1] == '#'){
      if(s[0][W-2] == '.' && s[1][W-1] == '.') Draw = false;
  }
  if(s[H-1][0] == '#'){
      if(s[H-1][1] == '.' && s[H-2][0] == '.') Draw = false;
  }
  if(s[H-1][W-1] == '#'){
      if(s[H-2][W-1] == '.' && s[H-1][W-2] == '.') Draw = false;
  }
  
  //左辺調査
  for(int i = 0; i < H; i++){
      int j = 0;
      if(i == 0 && j == 0) continue;
      if(i == H-1 && j == 0) continue;
      if(s[i][j] == '#'){
          if(s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j+1] == '.') Draw = false;
      }
  }
  
  //右辺調査
  for(int i = 0; i < H; i++){
      int j = W-1;
      if(i == 0 && j == W-1) continue;
      if(i == H-1 && j == W-1) continue;
      if(s[i][j] == '#'){
          if(s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.')Draw = false;
      }
  }
  
  //上辺調査
    for(int j = 0; j < W; j++){
      int i = 0;
      if(i == 0 && j == 0) continue;
      if(i == 0 && j == W-1) continue;
      if(s[i][j] == '#'){
          if(s[i][j-1] == '.' && s[i][j+1] == '.' && s[i+1][j] == '.') Draw = false;
      }
    }
    
  //下辺調査
    for(int j = 0; j < W; j++){
      int i = H-1;
      if(i == H-1 && j == 0) continue;
      if(i == H-1 && j == W-1) continue;
      if(s[i][j] == '#'){
          if(s[i][j-1] == '.' && s[i][j+1] == '.' && s[i-1][j] == '.') Draw = false;
      }
    }
    
    if(Draw) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long tint;

const int INF = 1e6;
const long double PI = acos(-1);
 
int main() {
	int a, b, k; cin >> a >> b >> k;
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0 && b%i==0) k--;
		if(k == 0){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
ll dp[1005];
int pre[1005];
vi way;
int main()
{
    int n;
    cin>>n;
    vi a(n+1);
    ll ans=-0x3f3f3f3f3f3f3f3f,ed=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        dp[i]=a[i];
        for(int j=i-2;j>=0;j-=2)
        {
            if(dp[j]+a[i]>dp[i])
            {
                dp[i]=dp[j]+a[i];
                pre[i]=j;
            }
        }
        if(dp[i]>ans)
        {
            ans=dp[i];
            ed=i;
        }
    }
    print(ans);
    for(int i=n;i>ed;i--)
        way.push_back(i);
    int cur=ed;
    while(cur)
    {
        int pp=pre[cur];
        if(!pp)
        {
            for(int i=1;i<cur;i++) way.push_back(1);
        }
        else{
            int mid=(pp+cur)/2;
            int len=cur-mid;
            for(int i=0;i<len;i++) way.push_back(mid-i);
        }
        cur=pp;
    }
    print(way.size());
    for(auto u:way) print(u);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

int N, K;
vector<vector<int> > G;

void rec(ll &res, int v, int pv, int depth){
	int cnt;
	if(depth == 0) cnt = K - 1;
	else cnt = K - 2;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == pv) continue;
		rec(res, G[v][i], v, depth + 1);
		res *= cnt;
		res %= MOD;
		cnt--;
	}
}

int main(){
	cin >> N >> K;
	G.assign(N, vector<int>());
	for(int i = 0; i < N - 1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll res = 1;
	rec(res, 0, -1, 0);
	cout << (res * K) % MOD << endl;
	return 0;
}


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int n, m;
  double dp[128][128];
  double g[128][128];
  while(scanf("%d%d", &n, &m) && n+m){
    rep(i, n) rep(j, n) scanf("%lf", &g[i][j]);

      memset(dp, 0, sizeof(dp));
    rep(i, n) dp[i][0] = 1.0;

    /*    rep(i, n){
      rep(j, m) printf("%.2lf ", dp[i][j]);
      puts("");
      }*/

    REP(i, 1, m){
      rep(j, n){
	rep(k, n){
	  dp[j][i] = max(dp[j][i], dp[k][i-1]*g[k][j]);
	  //	  printf("%d %d %d %.2lf\n", i, j, k, g[k][j]);
	}
      }
      /*      rep(i, n){
	rep(j, m) printf("%.2lf ", dp[i][j]);
	puts("");
	}*/
    }

    /*    rep(i, n){
      rep(j, m) printf("%.3lf ", dp[i][j]);
      puts("");
      }*/
    double res = 0;
    rep(i, n) res = max(res, dp[i][m-1]);
    //    res *= 100;
    //    int tmp = (int)res + 0.5;
    //    res = (double)tmp / 100;
    printf("%.2lf\n", res);
  }
  return 0;
}

Measured memory_bytes: 1488
class Factorials:
    def __init__(self, n=10**6, mod=10**9 + 7):
        self.mod = mod

        # self.fac[i] ≡ i! (factorial:階乗)
        self.fac = [1]
        num = 1
        for i in range(1, n+1):
            num *= i
            num %= mod
            self.fac.append(num)

        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        num = pow(num, mod-2, mod)
        self.rec = [1 for i in range(n+1)]
        self.rec[n] = num
        for i in range(n-1, 0, -1):
            num *= i + 1
            num %= mod
            self.rec[i] = num

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod
    
    # perm(n, r) ≡ nPr
    def perm(self, n, r):
        return self.fac[n] * self.rec[n-r] % self.mod

    # fact(n) ≡ n!
    def fact(self, n):
        return self.fac[n]

def main():
    mod = 10**9 + 7
    n, m = map(int, input().split())

    if m == 1:
        print(1)
        exit()

    factors = []
    for i in range(2, m+1):
        if i * i > m:
            if m > 1:
                factors.append(1)
            break

        if m % i == 0:
            num = 1
            m //= i
            while m % i == 0:
                num += 1
                m //= i
            factors.append(num)

    fct = Factorials(n=n+max(factors), mod=mod)

    ans = 1
    for i in factors:
        ans *= fct.comb(n+i-1, i)
        ans %= mod

    print(ans)

main()

Measured memory_bytes: 74732
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
#define int ll
#define N 100005
#define pb push_back
#define pv(x) cout<<#x<<": ";for(auto k:x){ cout<<k<<" "; }cout<<endl;
#define dbg(x) cout<<#x<<": "<<x<<endl;

int n,m,ni,mi;
// int num[N];
int ok=false;


int x;

void solve(){
  int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> v(n, vector<int>(m));
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        for(int j = 0; j < m; j++)cin >> v[i][j];
    }
	int mn=12345678;
	int all = 1<<n;
	for(int i=0;i<all;i++){
		vector<int> book(m);
		int cursum=0;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				cursum+=p[j];
				for(int k=0;k<m;k++){
					book[k]+=v[j][k];
				}
			}
		}
		int flag=1;
		for(int k=0;k<m;k++){
			if(book[k]<x)flag=0;
		}
		if(flag){
			mn=min(mn,cursum);
		}
	}
	cout<<(mn==12345678?-1:mn)<<endl;
}

int32_t main(){cin.tie(0);ios_base::sync_with_stdio(NULL);
	int t=1;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 3652