akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

int BinaryMat_calcrank(mat A){
    int n = A.size(), m = A[0].size();
    int r = 0, j = 0;
    REP(i, n){
        bool f = false;
        while(!f && j < m){
            FOR(i2, i, n){
                if(A[i2][j]){
                    A[i].swap(A[i2]);
                    r++;
                    f = true;
                    break;
                }
            }
            if(f){
                FOR(i2, i + 1, n) if(A[i2][j]){
                    FOR(j2, j, m) A[i2][j2] ^= A[i][j2];
                }
            }
            j++;
        }
    }
    return r;
}

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N, M; cin >> N >> M;
    mat a(N, vec(M));
    REP(i, N) readv(a[i]);
    REP(i, N) REP(j, M) a[i][j] &= 1;

    int r = BinaryMat_calcrank(a);
    //cout << r << endl;

    int mod = 998244353;
    int ans = ((modpow(2, N, mod) - modpow(2, N - r, mod) + mod) * modpow(2, M - 1, mod)) % mod;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N;
    cin >> N;
    vector<int> ary;
    priority_queue<int> que;
    rep(i, N) {
        int ai;
        cin >> ai;
        ary.pb(ai);
        que.push(ai);
    }
    int first = que.top();
    que.pop();
    int second = que.top();
    rep(i, N) {
        if (ary[i] == first) {
            cout << second << endl;
        } else {
            cout << first << endl;
        }
    }
}

Measured memory_bytes: 3436
n=int(input())
ans=0
for i in range(1,n+1): #頂点数の総和を求める
 ans+=i*(n-i+1)
for _ in range(n-1): #各辺についてu*(n-v+1)を頂点数の総和から引く
 u,v=map(int,input().split())
 if u>v: #上記ではu<vを仮定しているのでu>vのときuとvを入れ替える
   u,v=v,u
 ans-=u*(n-v+1)
print(ans)

Measured memory_bytes: 9132
a, b = map(int, input().split())

if a == 1 and b == 1:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
else:
    if a < b:
        print("Bob")
    elif a == b:
        print("Draw")
    else:
        print("Alice")

Measured memory_bytes: 38256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var s = Console.ReadLine();
            var score = 0;

            for (var i = 0; i < nk[0] - 1; i++)
                if (s[i] == s[i + 1]) score++;

            var ans = Math.Min(score + 2 * nk[1], nk[0] - 1);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13536
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int N,M;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	if(N==1) {
		printf("%d\n",M);
		return 0;
	}
	int ans=1;
	for(int i=2;i*i<=M;i++)
		if(M%i==0) {
			int tmp=M/i;
			if(tmp/N>0)
				ans=max(ans,i);
			if(i/N>0)ans=max(ans,tmp);
		}
	printf("%d\n",ans);
	return 0;
}

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

#define MAX 2000001

int B[10001];
 
int main(){
 
  unsigned short *A,*C;
  int i,sumdata;

 
  scanf("%d",&sumdata);

  A = malloc(sizeof(short)*sumdata+1);
  C = malloc(sizeof(short)*sumdata +1);


  for(i = 0; i < sumdata; i++){
 
    scanf("%d",&A[i]);
 
    B[A[i]] = B[A[i]] + 1;
 
  }
 
 
  for(i =1; i <= 10000; i++){
 
    B[i] = B[i] + B[i -1];
 
  }
 
  /* for(i = 0; i < sumdata; i++){
 
    printf("%d ",B[i]);
 
    }*/
 
  for(i = sumdata -1; i >= 0 ; i--){
 
    /*  printf("%d ", B[A[i]]);*/
 
    C[B[A[i]]] = A[i];
 
    B[A[i]] = B[A[i]] -1;
 
  }
 
 
  for(i = 1; i < sumdata; i++){
 
    printf("%d ",C[i]);
 
  }
 
 
  printf("%d\n",C[sumdata]);
 
 
 
  return 0;
 
}

 

 

Measured memory_bytes: 8452
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin>>s;
	string s1 = "ABC", s2 = "ARC";
	if(s == s1){
		cout<<s2<<endl;
	}
	else{
		cout<<s1<<endl;
	}
	return 0;
}


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

int main() {
  string A, B;
  cin >> A >> B;
  if (A.size()>B.size()) cout << "GREATER" << endl;
  else if (A.size()<B.size()) cout << "LESS" << endl;
  else {
    bool equal = true;
    for (int i=0; i<A.size(); i++) {
      if (A.at(i)>B.at(i)) {
        equal = false;
        cout << "GREATER" << endl;
        break;
      }
      else if (A.at(i)<B.at(i)) {
        equal = false;
        cout << "LESS" << endl;
        break;
      }
    }
    if (equal) cout << "EQUAL" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))

ans = 10**12
for b in range(1<<n):
    c = 0
    for i in range(n):
        if ((b>>i)&1) == 1:
            c += 1
    if c != k: continue
    t = 0
    h = 0
    for i in range(n):
        if ((b>>i)&1) == 0:
            h = max(h, a[i])
            continue
        if h < a[i]:
            h = a[i]
            continue
        if h >= a[i]:
            t += h - a[i] + 1
            h += 1
            continue
    ans = min(ans, t)
print(ans)


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

using namespace std;

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

  int res=0;
  if(a[0]==b[0]) res++;
  if(a[1]==b[1]) res++;
  if(a[2]==b[2]) res++;
 
   cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
#define IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define f first
#define s second
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

template<typename T1, typename T2> inline void chkmax(T1 & x, T2 y) {if (x < y) x = y;}
template<typename T1, typename T2> inline void chkmin(T1 & x, T2 y) {if (x > y) x = y;}

int main() {
    IO;
    // freopen("input.txt", "r", stdin);
    string st;
    cin >> st;
    st[3] = '8';
    cout << st;
    return 0;
}

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

int main() {
    int n, t=0, h=0;
    string t_card,h_card;
    cin >> n;
    while(n--){
        cin>> t_card >> h_card;
        if(t_card > h_card)
            t += 3;
        else if(t_card < h_card)
            h += 3;
        else{
                t++;
                h++;
            }
    }
    cout<< t << " " << h << endl;
}


Measured memory_bytes: 3240
# 2019-11-11 18:30:26(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *p = (int(x) for x in sys.stdin.read().split())
    total_cost = sum(p) - max(p) // 2
    print(total_cost)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな

signed main(){
    set<string> st;
    int n;
    cin >> n;
    while(n--){
        string BUFF,c;
        cin >> BUFF >> c;
        if(BUFF=="insert") st.insert(c);
        else cout << (st.find(c)!=st.end()?"yes":"no") << endl;
    }
}



Measured memory_bytes: 32128
require "time"
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end


a = s()
t = Time.parse(a)
if t > Time.parse("2019/4/30") 
  puts "TBD"
else
  puts "Heisei"
end


Measured memory_bytes: 2296
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int asc(const void *a,const void *b){
    return *(char *)a-*(char *)b;
}
int desc(const void *a,const void *b){
    return *(char *)b-*(char *)a;
}
int main(void){
    char s[101],t[101];
    scanf("%s",s);
    scanf("%s",t);
    qsort(s,strlen(s),sizeof(char),asc);
    qsort(t,strlen(t),sizeof(char),desc);
    if(strcmp(s,t)<0) printf("Yes");
    else printf("No");
    return 0;
}


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

int main(){
    int a, b, c, x;
    int matched = 0;
    int price;
    int count50=0;
    int count100=0;
    int count500=0;
    cin >> a >> b >> c >> x;


    for(int i = 0; i <= a; i++){
      count100 = 0;
      count50 = 0;
      for(int j = 0; j <= b; j++){
        count50 = 0;
        for(int k = 0; k <= c; k++){
          if (count500*500 + count100*100 + count50*50 == x) matched++;
          count50++;
        }
        count100++;
      }
      count500++;
    }
    cout << matched << endl;
    return 0;
}


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

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const long INF = 1e15;
using namespace std;
using namespace atcoder;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,Q; cin >> N >> Q;
    dsu d(N);
    rep(i,Q) {
        int t,u,v;
        cin >> t >> u >> v;
        if(t) {
            if(d.same(u,v)){
                cout << 1 << "\n";
            } else {
                cout << 0 << "\n";
            }
        } else {
            d.merge(u,v);
        }
    }
}


Measured memory_bytes: 3944
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn max(a: i32, b: i32) -> i32 {
    if a > b {a} else {b}
}

fn main() {
    input!{
        a: i32,
        b: i32,
    }
    let answer = if a == b {a * 2} else {max(a, b) * 2 - 1};
    println!("{}", answer);
}



Measured memory_bytes: 4352
#include <iostream>
#include <set>
 
#define YesNo(b) ((b) ? "Yes" : "No")

int main()
{
    std::string S, T;
    std::cin >> S >> T;

    std::set<int> bucS[26], bucT[26];
    for (size_t i = 0; i < S.size(); i++)
    {
        bucS[S[i]-'a'].insert(i);
        bucT[T[i]-'a'].insert(i);
    }
    
    bool ans = true;
    for (size_t i = 0; i < 26; i++)
    {
        if (bucT[i].size() == 0) continue;
        
        int is = S[*(bucT[i].begin())] - 'a';
        
        ans = ans && (bucS[is] == bucT[i]);
    }

    std::cout << YesNo(ans) << std::endl;
}


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

using namespace std;

int main(){
  int h1,h2;
  cin>>h1>>h2;

  int k1,k2;
  cin>>k1>>k2;

  int a,b,c,d;
  cin>>a>>b>>c>>d;

  if( h1 * a + ( h1 / 10 ) * c + h2 * b + ( h2 / 20 ) * d < k1 * a + ( k1 / 10 ) * c + k2 * b + ( k2 / 20 ) * d )
    cout<<"kenjiro"<<endl;

  if( h1 * a + ( h1 / 10 ) * c + h2 * b + ( h2 / 20 ) * d > k1 * a + ( k1 / 10 ) * c + k2 * b + ( k2 / 20 ) * d )
    cout<<"hiroshi"<<endl;

  if( h1 * a + ( h1 / 10 ) * c + h2 * b + ( h2 / 20 ) * d == k1 * a + ( k1 / 10 ) * c + k2 * b + ( k2 / 20 ) * d )
    cout<<"even"<<endl;

  return 0;
}

  



Measured memory_bytes: 3100
from itertools import permutations
n = int(input())
n_2 = [i for i in range(1,n+1)]
p = list(map(int,input().split()))
q = list(map(int,input().split()))

c = 1
ans = [0,0]
for i in permutations(n_2,n):
    #print(i)
    if list(i) == p:
        ans[0] += c
    if list(i) == q:
        ans[1] += c
    c += 1

print(abs(ans[1]-ans[0]))
        


Measured memory_bytes: 73924
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=char(n%10+48);n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;



int main(){
	int d, t, s;
	scan(d, t, s);
	puts(d <= t*s ? "Yes" : "No");
}

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

int main()
{
  int n; cin>>n;
  vector<vector<int>> a(2, vector<int>(n, 0));
  rep(i, 2) rep(j, n) {
    cin>>a[i][j];
    if (j > 0) a[i][j] += a[i][j-1];
  }
  int ans = 0;
  rep(i, n) {
    int tmp = a[0][i] + a[1][n-1];
    if (i > 0) tmp -= a[1][i-1];
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()

e = '0'
s = 0
li = []
for v in S:
  if v == e:
    s += 1
  else:
    li.append(s)
    s = 1
    e = v
if ( s > 0):
  li.append(s)

lis = [0]*( len(li) + 1 )
for i in range(len(li)):
  lis[i+1] = lis[i] + li[i]

gg = lis[-1]
sm = 100000000000000000000
for v in lis:
  sm = min(sm,max(v,gg-v))
print ( sm )


Measured memory_bytes: 42864
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
#define mod 1000000007;

int main(void){
  int a,b;
  bool flag = false;
  cin >> a >> b;
  string stra[50],strb[50];
  for(int i=0;i<a;i++){
    cin >> stra[i];
  }
  for(int i=0;i<b;i++){
    cin >> strb[i];
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<a;j++){
      if(stra[i][j]==strb[0][0])flag=true;//ここで始点を合わせてる
      if(flag){
        for(int ii=0;ii<b;ii++){
          for(int jj=0;jj<b;jj++){
            if(stra[i+ii][j+jj]!=strb[ii][jj]){
              flag =false;
              break;//aの始点プラス新しい座標を足す
            }
          }
          if(flag==false)break;
        }
      }
      if(flag)break;
    }
    if(flag)break;
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, nulong long_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    string s;
    cin >> s >> k;
    vector<string> go;
    map<string, int> mob;
    for (int z = 1; z < 10; z++) {
        for (int i = 0; i < s.size(); i++) {
            string t = "";
            for (int j = i, m = 0; j < s.size() && m < z; j++, m++) {
                t += s[j];
            }
            if (t.size() == z && mob.find(t) == mob.end()) {
                go.push_back(t);
            }
            mob[t] = 1;
        }
    }
    sort(go.begin(), go.end());
    cout << go[k - 1] << '\n';
    return 0;
}


Measured memory_bytes: 7828
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;
		static int[] dp;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			dp = new int[n + 1];
			Arrays.fill(dp, Integer.MAX_VALUE);
			System.out.println(helper(n));
		}

		private int helper(int n) {
			if (n < 6)
				return n;
			if (dp[n] != Integer.MAX_VALUE)
				return dp[n];
			int ans = Integer.MAX_VALUE;
			for (int i = 6; i <= n; i *= 6) {
				ans = Math.min(ans, 1+helper(n - i));
			}
			for (int i = 9; i <= n; i *= 9) {
				ans = Math.min(ans, 1+helper(n - i));
			}
			dp[n] = ans;
			return ans;
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


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

int main() {
	int i, j, r, c, a[101][101], sr[101] = {}, sc[101] = {}, s = 0;
	cin >> r >> c;
	for (i = 1; i <= r; i++) {
		for (j = 1; j <= c; j++) {
			cin >> a[i][j];
		}
	}
	for (i = 1; i <= r; i++) {
		for (j = 1; j <= c; j++) {
			sr[i] += a[i][j];
		}
	}
	for (j = 1; j <= c; j++) {
		for (i = 1; i <= r; i++) {
			sc[j] += a[i][j];
		}
	}
	for (i = 1; i <= r; i++) {
		s += sr[i];
	}
	for (i = 1; i <= r; i++) {
		for (j = 1; j <= c; j++) {
			cout << a[i][j] << " ";
		}
		cout << sr[i] << endl;
	}
	for (j = 1; j <= c; j++) {
		cout << sc[j] << " ";
	}
	cout << s << endl;
	return 0;
}

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

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        long lcm = lcm(n, m);
        
        int dn = (int) (lcm / m);
        int dm = (int) (lcm / n);
       
        for (int i = 0; i < n; i++) {
            if (i % dn == 0) {
                if (s.charAt(i) != t.charAt((i/dn) * dm)) {
                    so.println(-1);
                    return;
                }
            }
        }
        so.println(lcm);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        
        return gcd(n, m % n);
    }
    
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
}


Measured memory_bytes: 26764
// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_A

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

vector<ll> dat;
int N;

void update(int k, int a) {
  k += N - 1;
  ll old = dat[k];
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = dat[k * 2 + 1] | dat[k * 2 + 2];
    if ( dat[k * 2 + 1] & old == 0 &&  dat[k * 2 + 2] & old == 0) {
      dat[k] = dat[k] - old;
    }
  }
}

int find(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return dat[k];
  else {
    int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
    return vl | vr;
  }
}

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

  cin >> N;
  string S; cin >> S;

  ll Q; cin >> Q;
  ll N_ = N;
  N = 1;
  while (N < N_) N *= 2;
  dat = vector<ll>(2 * N - 1, 0);
  for (ll i = 0; i < N; i++) {
    update(i, 1 << (S[i] - 'a' + 1));
  }

  for (ll i = 0; i < Q; i++) {
    int q;
    cin >> q;
    if (q == 1) {
      int x; char y; cin >> x >> y;
      update(x - 1, 1 << (y - 'a' + 1));
    } else {
      int x, y; cin >> x >> y;
      x--; y--;
      int temp = find(x, y + 1, 0, 0, N);
      int ans = 0;
      for (ll i = 0; i < 30; i++) {
        ans += temp % 2;
        temp /= 2;
      }
      cout << ans << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 9116
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

	transform(a.begin(), a.end(), a.begin(), ::toupper);
	transform(b.begin(), b.end(), b.begin(), ::toupper);
	transform(c.begin(), c.end(), c.begin(), ::toupper);

	cout << a[0] << b[0] << c[0] << endl;


	return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int MAXN = 1e6 + 1;

vector<pair<int, int>> adj[MAXN];
int resenje[MAXN];

void dfs(int s)
{
    for(auto e : adj[s])
    {
        //cout << e.fi << ' ' << e.se << '\n';

        if(resenje[e.fi]==-1)
        {
            if(e.se % 2 == 0)
            {
                resenje[e.fi]=resenje[s];
            }
            else
            {
                resenje[e.fi]=((resenje[s]==1)?(0):(1));
            }

            dfs(e.fi);
        }
    }
}

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

    int n;
    cin >> n;

    memset(resenje, -1, sizeof(resenje));

    for(int i = 0; i < n - 1; ++i)
    {
        int a, b, w;
        cin >> a >> b >> w;
        adj[a].pb(mp(b, w));
        adj[b].pb(mp(a, w));
    }

    resenje[1]=1;
    dfs(1);

    for(int i = 1; i <= n; ++i)
    {
        cout << resenje[i] << '\n';
    }
}


Measured memory_bytes: 32256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    fp((s[0] == s[1])||(s[1] == s[2])||(s[2] == s[3]),"Bad","Good");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int N = scanner.nextInt();
        int sum = 0;
        for(int i =0; i < N; i++) {
            sum += scanner.nextInt();
        }
        if(sum >= H) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

int main(){
  int n;
  cin>>n;
  int ans = 0;
  int tmp = 0;
  int pre; cin >> pre;
  for(int i=1; i<n; i++){
    int h; cin>>h;
    if(h<=pre) tmp++;
    else{
      ans = max(ans,tmp);
      tmp=0;
    }
    pre = h;
  }
  ans=max(ans, tmp);
  
  cout << ans<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  map<int,int> mapp;
  int d;
  for (int i = 0; i < N; i++) {
    cin >> d;
    mapp[d]++;
  }
  cout << mapp.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int get(int a){
    int sum = 0;
    while(a > 0){
        sum += a % 10;
        a/=10;
    }
    return sum;
}

int N;
int main(){

    int ans = 1 << 29;

    cin >> N;
    for(int i = 1; i < N; i++){
        int j = N - i;
        ans = min(ans, get(i) + get(j));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N//R+1):
    nR = N-r*R
    for g in range(0,nR//G+1):
        nG = nR-g*G
        if nG%B==0:
            cnt += 1
print(cnt)


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

int main() {

    long long int x;

    cin >> x;

    long long int point = 0;

    point += x/11*2;

    if((x%11) > 6){
        point += 2;
    }
    else if((x%11) > 0){
        point++;
    }

    cout << point << endl;

    return 0;
}

Measured memory_bytes: 256
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    h, w = list(map(int,ipti().split()))

    s = [0]*h

    for row in range(h):
        s[row] = list(map(str,input().split()))

    for row in range(h):
        for col in range(w):
            if s[row][col] == "snuke":
                print(chr(col+65)+str(row+1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

ll dp[410][410]; //dp[i][j]:[i,j)のスライムが合体するまでの最小コスト

int main(){
    int N; cin>>N;
    vector<ll> a(N),ruiseki(N+1);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        ruiseki[i+1]=ruiseki[i]+a[i];
    }

    memset(dp,0, sizeof(dp)); //dp[i][i]=0

    for(int len=2;len<=N;++len){
        for(int i=0;i+len<=N;++i){
            ll tmp=(ll)1e18;
            for(int j=i+1;j<i+len;++j){
                tmp=min(tmp,dp[i][j]+dp[j][i+len]+ruiseki[i+len]-ruiseki[i]);
            }
            dp[i][i+len]=tmp;
        }
    }
    cout<<dp[0][N]<<endl;
    return 0;
}

Measured memory_bytes: 1536
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())

    f = [0] * (N+1)
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if tmp <= N:
                    f[tmp] += 1
    
    print("\n".join(map(str, f[1:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 70808
#include <iostream>
#include <cmath>

 using namespace std;
 typedef long long ll;

 int main(void){
 long double a,b,c;
 cin >> a >> b >> c;

 long double eps = 1.0E-14;

 if(sqrt(a) + sqrt(b) + eps < sqrt(c)){
 cout << "Yes" << endl;
 } else {
 cout << "No" << endl;
 }

 return 0;
 }


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def solve():
    w = list(input().rstrip())
    s = set(w)
    for i in s:
        if len([x for x in w if x == i]) % 2 == 1:
            print('No')
            exit()
    print('Yes')

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

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

    ll n,m;
    cin>>n>>m;
    vector<ll> x(n),y(m);
    FOR(i,0,n) cin>>x[i];
    FOR(i,0,m) cin>>y[i];

    ll X=0;

    FOR(i,0,n-1){
        X+=((x[i+1]-x[i])%MOD)*(i+1)*(n-i-1)%MOD;
        X%=MOD;
    }

    ll S=0;

    FOR(i,0,m-1){
        S+=(X*(y[i+1]-y[i])%MOD)*(i+1)*(m-i-1)%MOD;
        S%=MOD;
    }

    cout<<S<<endl;


}
//666

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

int a[1010];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long double res = 0;
  long double sum = 0;

  for (int i = 0; i < n; i++) {
    sum += (long double)1.0 / a[i];
  }
  res = 1 / sum;
  cout << std::setprecision(16) << res << endl;
  //cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int N, M;
static const int MAX = 200000;
int A[MAX];

int main(){
	cin >> N >> M;

	for(int i = 2; i <= N - 1; i++){
		A[i] = 0;
	}

	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		if(a == 1){
			A[b]++;
		}
		if(b == N){
			A[a]++;
		}
	}

	bool flg = false;
	for(int i = 2; i <= N - 1; i++){
		if(A[i] == 2) flg = true;
	}
	if(flg){
		cout << "POSSIBLE" << endl;
	}else{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

ll calc(ll n,ll t){
    ll x=n/t;
    return x*(x+1)/2;
}

signed main () {
    ll n;cin >> n;
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        ll tmp = i*calc(n,i);
        ans+=tmp;
    }
    cout << ans << endl;
}//https://atcoder.jp/contests/abc172/tasks/abc172_d

Measured memory_bytes: 3612
#include <iostream>

int main()
{
    int n;
    std::cin >> n;
    int b,f,r,v;
    int p[5][4][11]={{}};
    char mark;
    int num;
    
    for(int i = 0; i < n; i++)
    {
        std::cin>>b>>f>>r>>v; 
        p[b][f][r]+=v;
        if(p[b][f][r]<0){p[b][f][r] = 0;}
    }

    for(b = 1; b <= 4; b++)
    {
        for(f = 1; f <= 3; f++)
        {
            for(r = 1; r <= 10; r++)
            {
                if(r==10){std::cout<<p[b][f][r];}
                else if(r==1){std::cout<<" "<<p[b][f][r]<<" ";}
                else{std::cout<<p[b][f][r]<<" ";}
            }
            std::cout<<std::endl;
        }
        if(b<4)std::cout<<"####################"<<std::endl;
    }
    return 0;
}




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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, cnt = 1;
    cin >> n;
    vector<int> p(n), q(n), num(n);
    rep (i, n) {
        cin >> p[i];
        num[i] = i + 1;
    }
    rep (i, n) cin >> q[i];
    int a = -1, b = -1;
    do {
        if (a == -1) {
            bool ok = true;
            rep (i, n) if (num[i] != p[i]) ok = false; 
            if (ok) a = cnt;
        }
        if (b == -1) {
            bool ok = true;
            rep (i, n) if (num[i] != q[i]) ok = false;
            if (ok) b = cnt;
        }
        cnt++;
    } while (next_permutation(num.begin(), num.end()));
    cout << abs(a - b) << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio;
	cin.tie(NULL);
	cout.tie(NULL);
	long long int i,j,k,l,m,n;
	cin>>n>>m;
	k=1000000007;
	string s[n];
	long long dp[n][m];
	dp[0][0]=1;
	for(i=0;i<n;i++)
	cin>>s[i];
	for(i=1;i<m;i++)
	{
		if(dp[0][i-1]==0)
		dp[0][i]=0;
		else if(s[0][i]=='#')
		dp[0][i]=0;
		else
		dp[0][i]=1;
	}
	for(i=1;i<n;i++)
	{
		if(dp[i-1][0]==0)
		dp[i][0]=0;
		else if(s[i][0]=='#')
		dp[i][0]=0;
		else
		dp[i][0]=1;
	}
	for(i=1;i<n;i++)
	{
		for(j=1;j<m;j++)
		{
			if(s[i][j]=='#')
			dp[i][j]=0;
			else
			dp[i][j]=(dp[i-1][j]%k+dp[i][j-1]%k)%k;
		}
	}
	dp[n-1][m-1]=(dp[n-1][m-1])%(1000000007);
	cout<<dp[n-1][m-1]<<endl;
	return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;
int inf = 1000000000;
// dp[i][j] = i ???????????§??§?????? j ??§?????????
// dp[i][j] = dp[i][j-?] + v[i];

int dp[1001][1001];

int main(){

  int W, N, l;
  l = 1;
  while(cin >> W){
    if( W == 0 ) break;
    cin >> N;
    vector<int> v(N);
    vector<int> w(N);
    for(int i=0; i<N; i++) scanf("%d,%d", &v[i], &w[i]);

    for(int i=0; i<1001; i++) for(int j=0; j<1001; j++) dp[i][j] = 0;

    for(int i=0; i<N; i++){
      for(int j=0; j<=W; j++){
        if( j - w[i] >= 0 ) dp[i+1][j] = max(dp[i][j], dp[i][ j - w[i] ] + v[i]);
        else dp[i+1][j] = dp[i][j];
        // dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
      }
    }

    int answ = 1;
    for(int i=1; i<=W; i++){
      if( dp[N][answ] < dp[N][i] ){
        answ = i;
      }
    }

    cout << "Case " << l << ":" << endl;
    cout << dp[N][W] << endl;
    cout << answ << endl;

    l++;
  }




  return 0;
}

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

typedef long long ll;
const ll INF = 1LL << 60;

int main(void){
    int N;
    cin >> N;
    
    vector<int> h(110000);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    
    vector<ll> dp(110000,INF);
    dp[0] = 0;
    
    for(int i = 1; i < N; i++){
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));  
        if(i > 1){
            dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }
    
    cout << dp[N-1] << endl;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;

int pref[200005];
ll ct[2019];
int p[200005];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int res = 0;
    int n = s.length();
    p[0] = 1;
    for(int i=1; i<=200000; i++)
    {
        p[i] = (p[i-1] * 10) % 2019;
    }
    for(int i=n-1; i>=0; i--)
    {
        int c = s[i] - '0';
        res = (res + p[n-1-i] * c)%2019;
        pref[i] = res;
    }

    ll ans = 0;
    ct[0] = 1;
    for(int i=n-1; i>=0; i--)
    {
        //cout << pref[i] << " " << ct[pref[i]] << "\n";
        ans += ct[pref[i]];
        ct[pref[i]]++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5324
#include <bits/stdc++.h>
using namespace std;
int n, t, l, r, imos[100009];
int main() {
	scanf("%d%d", &n, &t);
	for(int i = 0; i < n; i++) scanf("%d%d", &l, &r), imos[l]++, imos[r]--;
	int ret = 0, sum = 0;
	for(int i = 0; i < t; i++) {
		sum += imos[i];
		ret = max(ret, sum);
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll n,k;cin>>n>>k;
    map<ll,ll> mp;
    for(int i=0;i<n;i++){
        ll a,b;cin>>a>>b;
        mp[a]+=b;
    }
    ll cnt=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        P p=*itr;
        cnt += p.second;
        if(cnt>=k){
            cout<<p.first<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 4224
import java.util.Scanner;
 
public class Main {
	
    static char ch1[];
    static char ch2[];
    
    static int ch_int(char ch[]){
        int i=0, sum=0;
        while(i<ch.length){
            if('2'<=ch[i] && ch[i]<='9'){
                int tmp = ch[i]-'0';
                i++;
                if(ch[i]=='m'){
                    sum += tmp*1000;
                }
                else if(ch[i]=='c'){
                    sum += tmp*100;
                }
                else if(ch[i]=='x'){
                    sum += tmp*10;
                }
                else if(ch[i]=='i'){
                    sum += tmp;
                }
            }
            else if(ch[i]=='m'){
                sum += 1000;
            }
            else if(ch[i]=='c'){
                sum += 100;
            }
            else if(ch[i]=='x'){
                sum += 10;
            }
            else if(ch[i]=='i'){
                sum += 1;
            }
            i++;
        }
        return sum; 
    }
    
    static char[] int_ch(int n){
        int i=0;
        char ch[] = new char[8];
        while(true){
            if(n==0){
            	break;
            }
            if(1000<=n){
                if(n/1000!=1){
                    ch[i] = (char) (n/1000);
                    ch[i] += '0';
                    i++;
                    ch[i] = 'm';
                }
                else{
                    ch[i] = 'm';
                }
                n %= 1000;
            }
            else if(100<=n){
                if(n/100!=1){
                    ch[i] = (char) (n/100);
                    ch[i] += '0';
                    i++;
                    ch[i] = 'c';
                }
                else{
                    ch[i]='c';
                }
                n %= 100;
            }
            else if(10<=n){
                if(n/10!=1){
                    ch[i] = (char) (n/10);
                    ch[i] += '0';
                    i++;
                    ch[i] = 'x';
                }
                else{
                    ch[i] = 'x';
                }
                n %= 10;
            }
            else if(1<=n){
                if(n!=1){
                    ch[i] = (char)n;
                    ch[i] += '0';
                    i++;
                    ch[i] = 'i';
                }
                else{
                    ch[i] = 'i';
                }
                n %= 1;
            }
            i++;
        }
        char ans[] = new char[i];
        for(int j=0;j<i;j++){
            ans[j] = ch[j];
        }
        return ans;
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            ch1 = sc.next().toCharArray();
            ch2 = sc.next().toCharArray();
            int tmp1 = ch_int(ch1);
            int tmp2 = ch_int(ch2);
            char ans[] = int_ch(tmp1+tmp2);
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 12000