akhauriyash/Code-Regression huggingface dataset:
# B
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int,input().split())) for i in range(N)]
ans = 0
for a in A:
    d = [a[k] * B[k] for k in range(M)]
    if sum(d) + C > 0:
        ans +=1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define INF 10000000000
#define MAX_N 100000
int main(){
  ll n,a;
  vector<ll> dp(MAX_N+1);
  fill(dp.begin(),dp.end(),INF);
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    *lower_bound(dp.begin(),dp.end(),a) = a;
  }
  cout << distance(dp.begin(),lower_bound(dp.begin(),dp.end(),INF) ) <<endl;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin >> s >> t;
    int n=s.length(),m=t.length();
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            
            if(s[i-1]==t[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    int index = dp[n][m]; 
   
   string ans=""; 
   int i = n, j = m; 
   while (i > 0 && j > 0) 
   { 
       
      if (s[i-1] == t[j-1]) 
      { 
          ans+= s[i-1]; 
          i--; j--; ;     
      } 
   
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   reverse(ans.begin(),ans.end());
   cout << ans;
} 
    

Measured memory_bytes: 70656
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    sc.nextLine();
    List<Long> l = new ArrayList<Long>();
    for(int i = 0;i < n;i++) {
      l.add(sc.nextLong());
    }

    if(l.contains(0L)) {
      System.out.println(0);
    }else {
      Long max = 1000000000L * 1000000000;

      Long sum = 1L;

      for(Long l2:l) {
        if(sum > max/l2) {
          System.out.println(-1);
          sum = 0L;
          return;
        }
        sum *= l2;
      }
      System.out.println(sum);
    }

    sc.close();
  }

}


Measured memory_bytes: 61772
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

U = 10 ** 4
fact = [1] * U
for n in range(1,U):
    fact[n] = fact[n-1] * n % MOD
fact_inv = [1] * U
fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for n in range(U-1,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD

C_to_A = [[] for _ in range(D+D+1)]
Y = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    Y += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
Y %= MOD

f = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    f[1:] += f[:-1].copy()
    np.add.at(f,A,1)
    f %= MOD
X = (f * f[::-1] % MOD).sum() % MOD

answer = (X - Y) * fact_inv[2] % MOD
print(answer)

Measured memory_bytes: 40384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#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++)
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
int h,w;
char maze[52][52];
int memo[52][52];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void bfs(int y,int x)
{
  queue<int> quey,quex;
  quey.push(y);quex.push(x);
  while(!quey.empty())
  {
    int tx,ty;
    ty=quey.front();quey.pop();
    tx=quex.front();quex.pop();
    rep(i,4)
    {
      if(memo[ty+dy[i]][tx+dx[i]]>0)continue;
      if(maze[ty+dy[i]][tx+dx[i]]=='.')
      {
        memo[ty+dy[i]][tx+dx[i]]=memo[ty][tx]+1;
        quey.push(ty+dy[i]);quex.push(tx+dx[i]);
      }
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  cin>>h>>w;
  rep(i,h+2)rep(j,w+2)maze[i][j]='#';
  int white=0;
  rep(i,h)rep(j,w){cin>>maze[i+1][j+1];if(maze[i+1][j+1]=='.')white++;}
  bfs(1,1);
  if(memo[h][w]==0)cout<<-1<<endl;
  else cout<<white-memo[h][w]-1<<endl;


  return 0;

}


Measured memory_bytes: 256
n, m = map(int, input().split())

student = []

for i in range(n):
    a, b = map(int, input().split())
    student.append((a, b))

point = []

for j in range(m):
    c, d = map(int, input().split())
    point.append((c, d))

for a, b in student:
    length = 10 ** 10
    pn = 0
    for j in range(m):
        c, d = point[j]
        if abs(a-c) + abs(b-d) < length:
            length = abs(a-c) + abs(b-d)
            pn = j + 1
    print(pn)

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

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long min = 100000000;
    for(long i = 1; i*i <= n; i++) {
      if(n % i == 0) {
        long j = n/i;
        int F = Math.max(Long.toString(i).length(), Long.toString(j).length());
        min = Math.min(min, F);
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 23764
N,M,C = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for i in range(N)]

count = 0
for i in range(N):
    sum = C
    for j in range(M):
        sum += A[i][j]*B[j]
    if sum>0:
        count+=1
print(count)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int a, b;
    cin >> a >> b;
    int c, d;
    cin >> c >> d;
    ATYN((abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d)))

    return 0;
}

Measured memory_bytes: 256
import Data.List

primeFactors 1 = []
primeFactors n =
    case factor of
        Just p -> p : primeFactors (n `div` p)
        Nothing -> []
    where factor = find (\x -> n `mod` x == 0) [2..n]

main = do
    n <- readLn
    let expos = map length $ group $ primeFactors $ product [1..n]
    let [a, b, c, d, e] = map (\m -> length $ filter (\e -> e >= m - 1) expos) [3, 5, 15, 25, 75]
    print $ e + d * (a - 1) + c * (b - 1) + b * (b - 1) * (a - 2) `div` 2

Measured memory_bytes: 764
n,m = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

length = X[m-1] - X[0]
L = []
for i in range(m-1):
	L.append(X[i+1] - X[i])
L.sort()

if n >= m:
	print(0)
else:
	print(length - sum(L[m-1-(n-1):m-1]))


Measured memory_bytes: 13960
import java.util.*;
public class Main
{

	public static void main(String [] args)
	{
	
		Scanner sc= new Scanner(System.in);
		int N = sc.nextInt();
		int W =sc.nextInt();
		
		int []w =new int[N+1];
		int []v =new int[N+1];
		
		for(int i=1;i<=N;i++)
		{
			w[i]=sc.nextInt();
			v[i]=sc.nextInt();
		}
		
		
		long [][]dp =new long[N+1][W+1];
		
		for(int i=0;i<N;i++) dp[i][0] =0;
		for(int i=0;i<W;i++) dp[0][i] =0;
		
		for(int i=1;i<=N;i++)
		{
			for(int j=1;j<=W;j++)
			{
				 if(w[i]>j) dp[i][j]=dp[i-1][j];
				 else
				dp[i][j]= Math.max(v[i]+dp[i-1][j-w[i]], dp[i-1][j]);
			}	
		}	
		
		System.out.println( dp[N][W]);	
	}

}

Measured memory_bytes: 140268
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
int main() {
    int n,ans;
    cin >> n;
    int tmp = n % 1000;
    if(tmp == 0){
        cout << 0 << endl;
    }else{
        ans = 1000 - tmp;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
# s = 'RUDLUDR'
s = gets.chomp
s = s.split('')
odd = s.each_slice(2).map(&:first)
even = s.each_slice(2).map { |v| v[1] if v.length == 2 }
even.compact!

j1 = odd.all? {|w| ['R', 'U', 'D'].include?(w) }
j2 = even.all? {|w| ['L', 'U', 'D'].include?(w) }

if j1 && j2
  print 'Yes'
else
  print 'No'
end


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

int main(void){
	long long k,n;
	cin>>n>>k;

	vector<long long> test;
	for (long long i = 0; i < n; ++i)
	{
		long long temp;
		cin>>temp;

		test.push_back(temp);
	}
	if(k>=n) cout<<0<<endl;
	else{
		sort(test.begin(), test.end());
		long long ans = 0;
		for (long long i = 0; i < n-k; ++i)
		{
			ans+=test[i];
		}
		cout<<ans<<endl;
	}
}	

Measured memory_bytes: 2420
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 18884
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = INF; ll z = 0, o = 1;
vl flag, color, D; vll path;
void warshall_floyd(int n) {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				path[i][j] = min(path[i][j], path[i][k] + path[k][j]);
			}
		}
	}
}
int main() {
	cin >> N >> M >> R;
	flag.resize(N);
	path.resize(N);
	D.resize(N);
	vl T(R);
	for (i = 0; i < R; i++) {
		cin >> T[i];
		T[i]--;
		flag[T[i]] = i + 1;
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			path[i].push_back(INF);
		}
	}
	for (i = 0; i < M; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		path[a][b] = c;
		path[b][a] = c;
	}
	warshall_floyd(N);
	sort(T.begin(), T.end());
	do {
		//debug(T);
		ll pre = 0;
		for (i = 0; i < R-1; i++) {
			pre += path[T[i]][T[i + 1]];
		}
		//debug(pre);
		ans = min(ans, pre);
	} while (next_permutation(T.begin(), T.end()));
	cout << ans;
}

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

int main() {

  int K, A, B;
  cin >> K >> A >> B;

  int check = (B / K) * K;

  if (A <= check) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }

  return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

using quad = tuple<ll, int, int, int>;

const int MAX_N = (int)(1e3 + 5);

ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];

vector<pair<ll, char>> whole;

int x, y, z;
int k;

int main(void) {
  // Here your code !
  scanf("%d %d %d %d", &x, &y, &z, &k);

  for (int i = 0; i < x; ++i) {
    scanf("%lld", &(a[i]));
  }

  for (int i = 0; i < y; ++i) {
    scanf("%lld", &(b[i]));
  }

  for (int i = 0; i < z; ++i) {
    scanf("%lld", &(c[i]));
  }

  sort(a, a + x, greater<ll>());
  sort(b, b + y, greater<ll>());
  sort(c, c + z, greater<ll>());

  priority_queue<quad> que;
  set<quad> st;

  que.push(make_tuple(a[0] + b[0] + c[0], 0, 0, 0));
  st.insert(make_tuple(a[0] + b[0] + c[0], 0, 0, 0));

  for (int i = 0; i < k; ++i) {
    quad tmp = que.top();
    que.pop();

    int ia = get<1>(tmp);
    int ib = get<2>(tmp);
    int ic = get<3>(tmp);

    printf("%lld\n", get<0>(tmp));

    int ina = min(ia + 1, x - 1);
    quad qa = make_tuple(a[ina] + b[ib] + c[ic], ina, ib, ic);
    if (st.find(qa) == st.end()) {
      que.push(qa);
      st.insert(qa);
    }

    int inb = min(ib + 1, y - 1);
    quad qb = make_tuple(a[ia] + b[inb] + c[ic], ia, inb, ic);
    if (st.find(qb) == st.end()) {
      que.push(qb);
      st.insert(qb);
    }

    int inc = min(ic + 1, z - 1);
    quad qc = make_tuple(a[ia] + b[ib] + c[inc], ia, ib, inc);
    if (st.find(qc) == st.end()) {
      que.push(qc);
      st.insert(qc);
    }
  }

  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	cout << b+min(a+b+1,c) << endl;
}



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

int n, k;
long long tree[100005], minD=1000000009, dif;


int main(){
    scanf("%d %d", &n, &k);
    for(int i=0; i<n; i++){
        scanf("%lld", &tree[i]);
    }
    sort(tree, tree+n);
    k--;
    for(int i=0; i<n-k; i++){

        dif = tree[i+k] - tree[i];
        if(dif < minD)
            minD = dif;
            //printf("%lld %lld -> %lld\n", tree[i+k], tree[i], dif);
    }

    printf("%lld\n", minD);
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws NumberFormatException, IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    while (input.ready())
    {
      String[] INPUT_STR = input.readLine().split(" ");
      int numCount = Integer.valueOf(INPUT_STR[0]);
      int sumNumber = Integer.valueOf(INPUT_STR[1]);

      if (numCount == 0 && sumNumber == 0)
      {
        break;
      }

      int ans = solver(numCount, sumNumber);
      System.out.println(ans);
    }

  }

  private static int solver(int numCount, int sumNumber)
  {
    return solver(numCount, sumNumber, 0, 0);
  }

  private static int solver(int numCount, int sumNumber, int currentSum, int startIndex)
  {
    int ret = 0;
    if (numCount - 1 == 0)
    {
      for (int i = startIndex; i < 10; i++)
      {
        if (currentSum + i == sumNumber)
        {
          ret++;
        }
      }
    }
    for (int i = startIndex; i < 10; i++)
    {
      ret += solver(numCount - 1, sumNumber, currentSum + i, i + 1);
    }
    return ret;
  }
}

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

int h[100005];
int memo[100005];
bool vis[100005];
int n;

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


int solve(int i) {
  if (vis[i]) return memo[i];
  if (i >= n - 1) return 0;

  int res = solve(i + 1) + abs(h[i] - h[i + 1]);
  
  if (i + 2 < n)
    res = min(res, solve(i + 2) + abs(h[i] - h[i + 2]));
    

  vis[i] = true;
  return memo[i] = res;

}

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

  fore(i, n)
    cin >> h[i];

  cout << solve(0) << endl;

  return 0;
}


Measured memory_bytes: 4224
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		String S = next();
		String T = next();

		String res = "";

		for(int i=0;i<N;i++) {
			res += S.substring(i,i+1);
			res += T.substring(i,i+1);
		}
		out.println(res);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 21844
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  ll m;cin>>m;
  vl a(n);
  rep(i,n)cin>>a[i];
  map<ll,ll>M;
  M[0]++;
  vl sum(n);
  sum[0]=a[0];
  sum[0]%=m;
  M[sum[0]]++;
  rep(i,n-1){
    sum[i+1]=a[i+1]+sum[i];
    sum[i+1]%=m;
    M[sum[i+1]]++;
  }
  ll ans=0;
  for(auto p:M){
    ans+=p.second*(p.second-1)/2;
  }
  cout<<ans<<endl;
}
  
  

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

const int MOD = 998244353;

int main(){
    int N; cin >> N;
    string S; cin >> S;
    vector<vector<int>> cnt;
    vector<int> c(3, 0);
    cnt.push_back(c);
    for(int i=0;i<S.size();i++){
        if(S[i] == 'R') c[0]++;
        if(S[i] == 'G') c[1]++;
        if(S[i] == 'B') c[2]++;
        cnt.push_back(c);
    }
    for(auto& v : cnt) sort(v.begin(), v.end());
    long long res = 1;
    for(int i=2;i<=N;i++) res = (res * i) % MOD;
    for(int i=1;i<cnt.size();i++){
        for(int j=0;j<2;j++){
            if(cnt[i][j] > cnt[i-1][j]) res = (res * (cnt[i][j+1] - cnt[i-1][j])) % MOD;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 23028
#include<bits/stdc++.h>
#define P pair<int,int>
#define fir first
#define sec second
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int N=105;
int a[N],n;
int ksm(int x,int y)
{
	int res=1;
	while (y){if (y&1) res=(ll)res*x%mod;x=(ll)x*x%mod;y>>=1;}
	return res;
}
void up(int &x,int y){x=x-mod+y;x=(x<0)?x+mod:x;}
P dfs(int l,int r,int h)//笛卡尔树,s1表示存在相同相邻，s2表示010101相邻不同 
{
	int Min=inf,cnt=0;
	for (int i=l;i<=r;i++) Min=min(Min,a[i]);
	for (int i=l;i<=r;i++) if (Min==a[i]) cnt++;
	if (cnt==r-l+1)//边界，矩形 
	  return P(((ll)ksm(2,r-l+1)-2+mod)%mod,ksm(2,Min-h));
	int s1=1,s2=1,blo=0;cnt=0;
    for (int i=l,L=l,R=l-1;i<=r;i++)
    {
    	if (a[i]!=Min) R=i;else cnt++;
    	if (a[i]==Min||i==r)
    	{
    		if (L<=R)
    		{
    		  blo++; 
    		  P now=dfs(L,R,Min);
			  s1=(ll)s1*(now.fir+(ll)now.sec*2%mod)%mod;//全集 
			  s2=(ll)s2*now.sec%mod;//01交替 
			}
    		L=i+1,R=i;
		}
	}
	s1=((ll)s1-(ll)s2*ksm(2,blo)%mod+mod)%mod;//存在相同相邻 
	P ans;
	ans.fir=(ll)s1*ksm(2,cnt)%mod;
	ans.fir=((ll)ans.fir+((ll)ksm(2,cnt)*ksm(2,blo)%mod-2+mod)%mod*s2%mod)%mod; 
	ans.sec=(ll)s2*ksm(2,Min-h)%mod;
	return ans;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	P now=dfs(1,n,0);//[1,n]当前底层高度 
	printf("%d\n",((ll)now.fir+now.sec)%mod);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;
ll n, a[300000], b[4], res = INF;

int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (ll i = 2; i < n - 1; i++) {
        ll ss = 0, sb = i, bs = i, bb = n;
        while(sb > ss + 1){
            ll mid = (ss + sb) / 2;
            if (a[mid] > a[i] - a[mid]) {
                sb = mid;
            } else {
                ss = mid;
            }
        }
        ll anss = (a[i] - a[ss] * 2 > a[sb] * 2 - a[i] ? sb : ss);
        while(bb > bs + 1){
            ll mid = (bs + bb) / 2;
            if (a[mid] - a[i] > a[n] - a[mid]) {
                bb = mid;
            } else {
                bs = mid;
            }
        }
        ll ansb = (a[n] + a[i] - a[bs] * 2 > a[bb] * 2 - a[n] - a[i] ? bb : bs);
        b[0] = a[anss], b[1] = a[i] - a[anss], b[2] = a[ansb] - a[i], b[3] = a[n] - a[ansb];
        sort(b, b + 4);
        res = min(res, b[3] - b[0]);
    }
    cout << res << endl;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<vector<int>> rooms(0);  // とりあえず0-indexed
    vector<int> deg(0);            // ドアの個数
    map<int, int> d2r;
    int rec, dist = 0;
    cin >> rec;
    rooms.push_back(vector<int>(0));
    deg.push_back(rec);
    d2r[dist] = 0;
    while (cin >> rec, rec != 0) {
      while (rooms[d2r[dist]].size() == deg[d2r[dist]]) dist--;

      if (rec > 0) {
        deg.push_back(rec);
        dist++;
        rooms.push_back(vector<int>(1, d2r[dist - 1]));
        d2r[dist] = rooms.size() - 1;
        rooms[d2r[dist - 1]].push_back(d2r[dist]);
      } else {
        rooms[d2r[dist]].push_back(d2r[dist + rec]);
        rooms[d2r[dist + rec]].push_back(d2r[dist]);
      }
    }
    for (int r = 0; r < rooms.size(); r++) {
      sort(rooms[r].begin(), rooms[r].end());
      cout << r + 1 << ' ';
      for (int j = 0; j < rooms[r].size(); j++) {
        cout << rooms[r][j] + 1 << (j == rooms[r].size() - 1 ? "" : " ");
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
typedef bitset<64> b64;
int main(){
	b64 b;
	int n,x;
	cin>>n;
	vector<b64> v(n);
	for(int i=0,j;i<n;i++)for(cin>>j;j--;v[i][x]=1)cin>>x;
	int q,a;
	for(cin>>q;q--;){
		cin>>a;
		if(a==0)cin>>x,cout<<b[x]<<endl;
		if(a==1)cin>>x,b|=v[x];
		if(a==2)cin>>x,b&=~v[x];
		if(a==3)cin>>x,b^=v[x];
		if(a==4)cin>>x,cout<<((b&v[x])==v[x])<<endl;
		if(a==5)cin>>x,cout<<(b&v[x]).any()<<endl;
		if(a==6)cin>>x,cout<<(b&v[x]).none()<<endl;
		if(a==7)cin>>x,cout<<(b&v[x]).count()<<endl;
		if(a==8)cin>>x,cout<<(b&v[x]).to_ulong()<<endl;
	}
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  string s;cin>>s;
  int n=s.size();
  int maxv=0;
  repi(i,1,n){
    if((n-i)%2!=0)continue;
    bool flag=true;
    rep(j,(n-i)/2)if(s[j]!=s[j+(n-i)/2])flag=false;
    if(flag==true)maxv=max(maxv,n-i);
  }
  cout<<maxv<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int,int> P;
int w,h,n;
int X1[500],X2[500],Y1[500],Y2[500];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
bool fld[3000][3000];
int compress(int *x1,int *x2,int w) {
	vector<int> xs;
	for(int i=0;i<n;i++) {
		for(int d=-1;d<=1;d++) {
			int tx1=x1[i]+d,tx2=x2[i]+d;
			if(0<=tx1&&tx1<w) xs.push_back(tx1);
			if(0<=tx2&&tx2<w) xs.push_back(tx2);
		}
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=0;i<n;i++) {
		x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
		x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
	}
	return xs.size();
}
int main() {
	while(scanf("%d %d",&w,&h),w) {
		scanf("%d",&n);
		for(int i=0;i<n;i++) {
			scanf("%d %d %d %d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
		}
		w=compress(X1,X2,w);
		h=compress(Y1,Y2,h);
		memset(fld,0,sizeof(fld));
		for(int i=0;i<n;i++) {
			for(int y=Y1[i];y<Y2[i];y++) {
				for(int x=X1[i];x<X2[i];x++) {
					fld[x][y]=true;
				}
			}
		}
		int ans=0;
		for(int y=0;y<h;y++) {
			for(int x=0;x<w;x++) {
				if(fld[x][y]) continue;
				ans++;
				queue<P> Q;
				Q.push(P(x,y));
				while(!Q.empty()) {
					P p=Q.front();Q.pop();
					for(int i=0;i<4;i++) {
						int nx=p.first+dx[i],ny=p.second+dy[i];
						if(0>nx||nx>=w||0>ny||ny>=h) continue;
						if(fld[nx][ny]) continue;
						fld[nx][ny]=true;
						Q.push(P(nx,ny));
					}
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 9872
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100005];
int sum[100005];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c=0,d=0;
  cin >>a>>b;
  if(a==1) d+=3;
  else{
    if(a==2) d+=2;
    if(a==3) d+=1;
  }
  if(b==1) d+=3;
  if(b==2) d+=2;
  if(b==3) d+=1;
  if(a==1&&b==1) d+=4;
  cout <<d*100000<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int a, b; cin >> a >> b;

  if(a%2==0 || b%2==0) cout << "Even" << endl;
  else cout << "Odd" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{
	int i , j;
	for(i = 1; i <= 9; i++)
	{
		for(j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll x;
    cin>>x;
    ll val = 100;
    ll ans = 0;
    for(ll t=1;val<x;t++)
    {
        val = val*1.01;
        
        ans = t;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
import java.util.*;
import java.math.*;
         
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            BigDecimal height = new BigDecimal(sc.next());
            BigDecimal width = new BigDecimal(sc.next());

            BigDecimal ans = new BigDecimal("0");
            BigDecimal two = new BigDecimal("2");
            BigDecimal zero = new BigDecimal("0");
            BigDecimal one = new BigDecimal("1");

            if(height.equals(one) || width.equals(one)){
                ans = one;
            }else if(height.remainder(two).equals(zero) || width.remainder(two).equals(zero)){
                ans = height.multiply(width).divide(two);
            }else{
                ans = (height.multiply(width).add(one)).divide(two);
            }

            System.out.println(ans);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

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

int n, s;
int ans;

void tadoru(int f, int step, int sum)
{
	if(step == n){
		if(sum == s){
			ans++;
		} else {
			return;
		}
	}
	if(sum > s) return;

	for(int i=f+1; i<10; i++){
		tadoru(i, step+1, sum+i);
	}
	return;
}

int main()
{
	while(cin>>n>>s){
		if(!n&&!s) break;
		ans = 0;
		tadoru(-1, 0, 0);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


map<string, int> mp;

int
main(void){  
  int n;
  cin >> n;
  string s[n];
  
  string p_s;
  int p_s_l;

  REP(i, n) cin >> s[i];
  
  REP(i, n){
    if( i > 0 && p_s[p_s_l-1] != s[i][0]){
      cout << "No" << endl;
      return 0;
    }
    
    //cout << p_s[p_s_l - 1] << endl;
    
    if(mp[s[i]] == 0){
      mp[s[i]]++;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
    p_s = s[i];
    p_s_l = p_s.length();
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,x;
    cin >> a >> b >> x;
    int ans=0;
    if(a>=2*b){
        ans=x/500*b;
        if(x%500!=0){
            ans+=b;
        }
    }else{
        ans=x/1000*a;
        if(x%1000!=0){
            if(a>b&&x%1000<=500){
                ans+=b;
            }else{
                ans+=a;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3112
n=int(input())
a=list(map(int,input().split()))
asum=[0]*n
MOD=10**9+7
ai=0
for i in range(n-1,-1,-1):
    ai+=a[i]
    ai%=MOD
    asum[i]=ai
ans=0
for i in range(n-1):
    ans+=a[i]*asum[i+1]
    ans%=MOD
print(ans)

Measured memory_bytes: 31760
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define MAX 100

struct state {
    int x;
    int y;
    int h;
};

int get_top_height(int N, int Cx, int Cy, const vector<state> &info);
int get_height(int H, int X, int Cx, int Y, int Cy);
int judge_center(int N, int Cx, int Cy, const vector<state> &info);

int main(){
    int N;
    cin >> N;
    vector<state> info(N);

    for (int i = 0; i < N; ++i) cin >> info[i].x >> info[i].y >> info[i].h;

    for (int tmp_x = 0; tmp_x <= MAX; ++tmp_x){
        for (int tmp_y = 0; tmp_y <= MAX; ++tmp_y){
            int H = judge_center(N, tmp_x, tmp_y, info);
            if (H != -1){
                cout << tmp_x << " " << tmp_y << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}

int judge_center(int N, int Cx, int Cy, const vector<state> &info){
    int tmp_H = get_top_height(N, Cx, Cy, info);
    for (int i = 0; i < N; ++i){
        if (info[i].h != get_height(tmp_H, info[i].x, Cx, info[i].y, Cy)) return -1;
    }
    return tmp_H;
}

int get_top_height(int N, int Cx, int Cy, const vector<state> &info){
    for (int i = 0; i < N; ++i){
        if (info[i].h > 0) return info[i].h + abs(info[i].x - Cx) + abs(info[i].y - Cy);
    }
    return 0;
}

int get_height(int H, int X, int Cx, int Y, int Cy){
    return max(H - abs(X - Cx) - abs(Y - Cy), 0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100009];
int arr[100009];
ll sum = 0;
long long Frog1(int n){
 
    if(n==0) return 0;
    else if(n==1) return abs(arr[n] - arr[n-1]);
    if(dp[n]!=-1) return dp[n];
    else {
            ll x = Frog1(n-1);
            ll y = Frog1(n-2);
        dp[n] = min(abs (arr[n-1] - arr[n]) + x,abs(arr[n-2] - arr[n]) + y);
        //cout << n << " = " << dp[n] << endl;
         return dp[n];
    }
}
 
 
int main()
{
    int n;
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for(int i=0;i<n;i++) cin >> arr[i];
    cout << Frog1(n-1) << endl;
}

Measured memory_bytes: 6144
#include <stdio.h>
long long p=1000000007;
long long rui(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b==2)return (a*a)%p;
    if(b%2)return (rui(rui(a,(b-1)/2),2)*a)%p;
    else return rui(rui(a,b/2),2)%p;
}
int main(void){
   long long n,m;
   scanf("%lld%lld",&n,&m);
   int a[32000];
   for(int i=0;i<32000;i++){
       a[i]=0;
   }
   int x;
   while(x){
       x=0;
       for(int i=2;i*i<=m;i++){
           if(m%i==0){
               x=1;
               m/=i;
               a[i]++;
               break;
           }
       }
   }
   long long ans=1;
   if(m<32000)a[m]++;
   else ans*=n;
   long long inv[40];
   for(int i=1;i<40;i++){
       inv[i]=rui(i,p-2);
   }
   for(int i=2;i<32000;i++){
       if(a[i]){
           for(int j=1;j<=a[i];j++){
               ans*=inv[j];
               ans%=p;
               ans*=n+a[i]-j;
               ans%=p;
           }
       }
   }
   printf("%lld\n",ans);
}


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

using namespace std;
using int64 = long long;

int main() {
    int64 n, ans = LONG_MAX;
    cin >> n;

    for (int64 i=1; i*i<=n; i++) {
        if (n%i == 0)
            ans = min(ans, i + (n/i) - 2);
    }

    cout << ans << endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1
 
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
typedef std::pair<int,int> P;
int main(){
	int A,B;
	cin>>A>>B;
	cout<<max({A+B,A*B,A-B});
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    lint k; cin>>k;
    int one = 0;
    int j = 0;
    while(1){
        if(s[j] == '1') one++;
        else break;
        j++;
    }
    if(k<=one) print(1);
    else print(s[one]);
    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>a>>b>>c;
  if(a==b&&b==c){
    s="No";
  }else if(a==b||b==c||a==c){
    s="Yes";
  }else{
    s="No";
  }
  cout <<s;
}

Measured memory_bytes: 3624
n, m = map(int, input().split())
a = input().split()
a = [int(i) for i in a]
s = sum(a)
dif = (1 / (4*m)) * s
cont = 0
for i in a:
     cont += (1 if i >= dif else 0)
print ('Yes' if cont >= m else 'No')


Measured memory_bytes: 38384
#include<iostream>

using namespace std;

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

int cell[101], n;
double mem[101][101];

double solve(int k, int t) {
  if (mem[k][t] > -0.5) return mem[k][t];
  if (k == n) return 1;
  if (t <= 0) return 0;
  double res = 0;
  rep (i, 6) {
    int next = k + i + 1;
    if (next > n) next = 2 * n - next;
    if (cell[next] == 2) next = 0;
    res += solve(next, t - 1 - (cell[next] == 1 ? 1 : 0));
  }
  return mem[k][t] = res /= 6;
}

int main() {
  int t, l, b, c;
  cout.setf(ios::fixed);
  cout.precision(12);
  while (cin >> n >> t >> l >> b, n) {
    rep (i, n + 1) rep (j, t + 1) mem[i][j] = -1;
    rep (i, n + 1) cell[i] = 0;
    rep (i, l) {
      cin >> c;
      cell[c] = 1;
    }
    rep (i, b) {
      cin >> c;
      cell[c] = 2;
    }
    cout << solve(0, t) << endl;
  }
  return 0;
}

Measured memory_bytes: 1312
#include <cstdio>

int main(){
	int n,a[100];
	while(scanf("%d",&n), n != 0){
		for(int i = 0; i < n; i++){
			scanf("%d",&a[i]);
		}
		int c = 0;
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				if(a[i] > a[j]){
					c++;
				}
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

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

using namespace std;

int main()
{
  int K, T;
  pair< int, int > A[10000];
  cin >> K >> T;
  for(int i = 0; i < T; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }


  int ret = 0, prev = -1;

  for(int i = 0; i < K; i++) {
    sort(A, A + T);
    int now = T - 1;
    if(prev == A[now].second) {
      if(T - 2 >= 0 && A[T - 2].first > 0) now = T - 2;
    }
    if(prev == A[now].second) ++ret;
    A[now].first--;
    prev = A[now].second;
  }
  cout << ret << endl;
}

Measured memory_bytes: 384
import sys
n, K = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))

p = [float('inf') for _ in range(n)]
p[0] = 0
for i in range(1, n):
    for k in range(1, K+1):
        if i-k >=0:
            tmp = abs(H[i]-H[i-k]) + p[i-k]
            if p[i] > tmp:
                p[i] = tmp

print(p[-1])

Measured memory_bytes: 57052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1d(V,T,a) vector<T> V (a)
#define MAT2d(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3d(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

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 LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int solve1(int N) {
  using pair = pair<ll, ll>;
  vector<pair> w;
  w.reserve(N);
  REP(i,N) {
    ll a,b;
    cin >> a >> b;
    w.push_back(make_pair(a,b));
  }
  sort(w.begin(), w.end(), [](const pair& x, const pair& y) {
        return x.second < y.second;
      });
  ll t = 0;
  for(auto& x:w) {
    t += x.first;
    if (t > x.second) {
      cout << "No" << endl;
      return  0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

int solve2(int N) {
  using pair = pair<ll, ll>;
  vector<pair> w;
  w.reserve(N);
  auto comp = [](const pair& x, const pair& y) {return x.second > y.second;};
  priority_queue<pair, vector<pair>,decltype(comp)> que(comp, move(w));
  REP(i,N) {
    ll a,b;
    cin >> a >> b;
    que.push(make_pair(a,b));
  }
  ll t = 0;
  while(!que.empty()) {
    pair x = que.top();
    t += x.first;
    if (t > x.second) {
      cout << "No" << endl;
      return  0;
    }
    que.pop();
  }
  cout << "Yes" << endl;
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  // return solve1(N);
  return solve2(N);
}


Measured memory_bytes: 3456
(defun main ()
  (let* ((n (read))
         (k (read))
         (b (make-array `(,(1+ n)) :initial-element 0))
         (a (make-array `(,(1+ n)) :initial-element 0))
         (stop t))
    ;; read 
    (loop :for i :from 1 :to n
          :do (setf (aref a i) (read)))
    ;;
    (loop :named main-loop
          :for _ :from 1 :to k
          :do (progn 
                (loop :for i :from 1 :to n
                      :do (let ((l (max 1 (- i (aref a i))))
                                (r (min n (+ i (aref a i)))))
                            (incf (aref b l))
                            (if (<= (1+ r) n) (decf (aref b (1+ r))))))
                (loop :for i :from 2 :to n
                      :do (incf (aref b i) (aref b (1- i))))
                (loop :for i :from 1 :to n
                      :do (setf stop (and stop (= (aref b i) n)))
                      :do (setf (aref a i) (aref b i))
                      :do (setf (aref b i) 0))
                (if stop
                    (return-from main-loop)
                    (setf stop t))))
    ;;
    (when (> n 1)
      (loop :for i :from 1 :to (1- n)
            :do (format t "~A " (aref a i))))
    (format t "~A~%" (aref a n))))
(main)


Measured memory_bytes: 80036
while True:
    a,op,b = input().split()
    a,b =map(int,(a,b))
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(int(a/b))
    elif op == "?":
        break


Measured memory_bytes: 5600
open System

let N = Console.ReadLine() |> int
let D = Console.ReadLine().Split() |> Array.map int

let mutable sum = 0

for x in [ 0 .. N-1 ] do
    for y in [ x .. N-1 ] do
        sum <- sum + (if x<>y then D.[x] * D.[y] else 0)
        
printfn "%d" sum

Measured memory_bytes: 14044
n = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(n-2):
  if P[i]<P[i+1]<P[i+2] or P[i+2] < P[i+1] < P[i]:
    ans += 1
  else:
    pass
  
print(ans)

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

int main() {
  int n, h, s, c;
  s = 0;
  cin >> h >> n;
  for(int i = 0; i < n; i++){
    cin >> c;
    s = s + c;
  }
  if(h <= s)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(){
  string S;
  cin >> S;
  
  int N = S.size()+1;
  int cnt=1;
  vector<int> a(N,-1);
  if(S[0]=='<') a[0]=0;
  if(S[N-2]=='>') a[N-1]=0;
  
  for(int i=0; i<N-1; i++){
    if(S[i]==S[i+1]){
      cnt++;
      if(i+1==N-2){
        if(S[i]=='<' && a[i+2]<cnt){
          a[i+2]=cnt;
        }
        if(S[i]=='>' && a[i-cnt+2]<cnt){
          a[i-cnt+2]=cnt;
        }
      }
    }else{
      if(S[i]=='<' && a[i+1]<cnt){
        a[i+1]=cnt;
      }
      if(S[i]=='>' && a[i-cnt+1]<cnt){
        a[i-cnt+1]=cnt;
      }
      if(S[i]=='>' && S[i+1]=='<'){
        a[i+1]=0;
      }
      cnt=1;
    }
  }
  
  long long int ans = 0;
  for(int j=1; j<N; j++){
    if(a[j]==-1 && S[j]=='<') a[j] = a[j-1]+1;
  }
  for(int k=N-2; k>-1; k--){
    if(a[k]==-1 && S[k]=='>') a[k] = a[k+1]+1;
  }
  
  for(int l=0; l<N; l++){
    ans += a[l];
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 2820
N = int(input())
ls = [int(i) for i in input().split()]
if len(ls) == 1:
  print(ls[0]*2)
else:
  als = [ls[0]]
  for n in range(1, N-1):
    als.append(min(ls[n-1], ls[n]))
  als.append(ls[-1])
  print(sum(als))

Measured memory_bytes: 9032
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

array<ll,2> inv(ll a,ll m){
    array<ll,2> val;
    a=a%m;
    if(a==1){
        val[0]=1;
        val[1]=0;
    }else{
        array<ll,2> hoge;
        ll k=m/a,mm=m%a;
        hoge=inv(mm,a);
        val[1]=hoge[0]-k*a;
        val[0]=hoge[1]-k*hoge[0]+k*m;
    }
    if(val[0]>m-1){
        ll n=val[0]/m;
        val[0]=val[0]%m;
        val[1]=val[1]+n*a;
    }
    return val;
}

ll comb(ll a,ll b,ll m){
    if(b==0) return 1;
    if(b==1) return a%m;
    return ((((a%m)*inv(b,m)[0])%m)*comb(a-1,b-1,m))%m;
}


int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    ll ans=0;
    ll hoge=comb(N*M-2,K-2,mod);
    ll MM=(M*M)%mod;
    ll NN=(N*N)%mod;
    Rep(d,N-1){
        ans=(ans+(N-d)*(MM*hoge)%mod*d)%mod;
    }
    Rep(d,M-1){
        ans=(ans+(M-d)*(NN*hoge)%mod*d)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
int main(){
    // Your code here!
    char s[5];
    scanf("%s",s);
    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
        printf("Bad");
    }else{
        printf("Good");
    }
    return 0;
}

Measured memory_bytes: 128