akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	vector<pair<int, P>> f(n);
	set<P> st;
	rep(i, 0, n) cin >> f[i].second.first >> f[i].second.second >> f[i].first;
	rep(i, 0, q) {
		int p; cin >> p;
		st.emplace(p, i);
	}
	sort(f.begin(), f.end());
	vector<int> ans(q, -1);
	rep(i, 0, n) {
		int s = f[i].second.first-f[i].first;
		int t = f[i].second.second - f[i].first;
		while (true) {
			auto idx = st.lower_bound({ s,-inf });
			if (idx == st.end() ||(*idx).first>=t) break;
			ans[(*idx).second] = f[i].first;
			st.erase(idx);
		}
	}
	rep(i, 0, q) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 19840
package main

import "fmt"

func main() {
	a := make([]int, 0)
	b := make([]int, 0)
	for{
		var anum, bnum int
		fmt.Scan(&anum)
		fmt.Scan(&bnum)
		if anum == 0 && bnum == 0 {
			break
		}
		a = append(a, anum)
		b = append(b, bnum)
	}

	for i:=0; i<len(a); i++{
		if a[i] >= b[i]{
			fmt.Printf("%d %d\n", b[i], a[i])
		}else{
			fmt.Printf("%d %d\n", a[i], b[i])
		}
	}
}


Measured memory_bytes: 1500
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define MP_ make_pair
#define PB_ push_back
#define UB_ upper_bound
#define LB_ lower_bound
#define PQ_ priority_queue
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)
#define CIN2(x,y) cin>>(x)>>(y)
#define CIN3(x,y,z) cin>>(x)>>(y)>>(z)
#define CIN4(x,y,z,w) cin>>(x)>>(y)>>(z)>>(w)
#define SCAD(x) scanf("%d",&(x))
#define SCALLD(x) scanf("%lld",&(x))
typedef long long int lli;
using namespace std;

int ctoi(char c)
{
  if( c >= '0' and c <= '9')
    {
      return (int)(c-'0');
    }

  return -1;
}

vector<string> split(string str, char ch)
{
  int first = 0;
  int last = str.find_first_of(ch);
  
  if(last == string::npos)
    {
      last = SIZ(str);
    }

  vector<string> result;

  while( first < SIZ(str) )
    {
      string Ssubstr(str, first, last - first);
      result.push_back(Ssubstr);
      first = last + 1;
      last = str.find_first_of(ch, first);

      if(last == string::npos)
	{
	  last = SIZ(str);
	}
    }
  
  return result;
}

/*--------------- the end of the template --------------------*/









int main()
{
  IOS; /* making cin faster */
  int x1,x2,x3,x4,y1,y2,y3,y4;

  CIN4(x1,y1,x2,y2);

  int vx = x2 - x1;
  int vy = y2 - y1;


  x3 = x2 - vy;
  y3 = y2 + vx;

  x4 = x3 - vx;
  y4 = y3 - vy;
  

 
  printf("%d %d %d %d\n",x3,y3,x4,y4);
  

}


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

#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define eb emplace_back
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Vi = vector<int>;

void run() {
    int n, k;
    cin >> n >> k;
    vector<int> ara(n), dp(n, 1e9);
    
    for (auto& i : ara) {
        cin >> i;
    } 
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= i+k && j < n; ++j) {
            dp[j] = min(dp[j], dp[i]+ abs(ara[i] - ara[j])); 
        }
    }
    cout << dp[n-1] << endl;
}

int main() 
{
    IO;
    double st = clock();
    run();
    cerr << "\n" << "time = " << (clock() - st) / CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 4044
n = gets.chop.to_i
a = gets.strip.split.map(&:to_i)

flg = true
cnt = 0

while flg
  a.map! do |i|
    if i.even?
      i/2
    else
      flg = false
      i
    end
  end
  cnt = cnt + 1
end

puts cnt - 1


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
/*RMQ  update:O(logN)  query:O(lonN)*/
const int MAX_N = 1<<17;
int n,dat[2*MAX_N-1];

//?????????
void init(int n_){
  //????´???°n???2???????????????
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=INT_MAX;
}

//[a,b)???????°????????±???????
//query(a,b,0,0,n)
void update(int a,int b,int x=-1,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return ;
  if(a<=l&&r<=b){
    if(x>=0)dat[k]=x;
    return;
  }
  
  if(dat[k]!=INT_MAX)dat[k*2+1]=dat[k*2+2]=dat[k];
  dat[k]=INT_MAX;
  update(a,b,x,k*2+1,l,(l+r)/2);
  update(a,b,x,k*2+2,(l+r)/2,r);
}

int main(){
  int q;
  cin>>n>>q;
  init(n);

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd==0){
      int s,t,x;
      cin>>s>>t>>x;
      update(s,t+1,x);
    }
    else {
      int idx;
      cin>>idx;
      update(idx,idx+1);
      cout <<dat[idx+n-1]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4088
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    data = sorted([Input() for _ in range(n)])
    amount = 0
    for x, y in data:
        get1 = min(y, m)
        m = m - get1
        amount += get1 * x
        if m <= 0:
            return amount

print(main())

Measured memory_bytes: 23332
// Author :mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second


ll const mod=1e9+7;
ll const N=5e5+5;
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return y; else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}



struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);}
};
struct compare {
    bool operator()(const pair<ll, ll>& value,  const ll& key){ return (value.first < key); }
    bool operator()(const ll& key, const pair<ll, ll>& value) { return (key < value.first); }
};

bool compare1(const pair<ll,ll> &a,const pair<ll,ll> &b)
{   if(a.first<b.first) return true ;
    else if(a.first==b.first) return (a.second > b.second);
    else return false;
}


int main()
{

        ios_base::sync_with_stdio(false); cin.tie(NULL);
        
        int tt=1;
        //cin>>tt;
        
        while(tt--)
        {
                ll n,m;
                cin>>n>>m;
                set<ll>s;
                ll sum=0;
                for(int i=0;i<m;i++){
                    ll x; cin>>x;
                    sum+=x;
                    
                }
                
                if(sum>=n)
                    cout<<"Yes"<<endl;
                else
                    cout<<"No"<<endl;
                    
                    

        }



}


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

using namespace std;

int main(){
	
	int n, a;
	cin >> n >> a;
	bool dp = false;
	
	
	for(;n >= 500;){
		n -= 500;
	}
	
	if(n <= a)dp = true;
	
	
	
	cout << ((dp)?"Yes":"No");
	
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] H = new int[N];

	    
	    for (int i=0; i<N; i++) {
	    	H[i] = Integer.parseInt(scanner.next());
	    }

	    int c=0;
	    while(true) {
	    	boolean flg= false;
	    	for (int i=0; i<N; i++) {
		    	if (H[i] != 0) {
		    		H[i]--;
		    		flg=true;
		    	} else if(flg) {
		    		break;
		    	}
		    }
	    	if (!flg) {
	    		break;
	    	}
	    	c++;
	    }

	    System.out.println(c);
	}
}

Measured memory_bytes: 35716
package main

// Solution for https://atcoder.jp/contests/abc071/tasks/abc071_a

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var x, a, b int
	con.Scan(&x, &a, &b)
	xa := x - a
	if xa < 0 {
		xa = -xa
	}
	xb := x - b
	if xb < 0 {
		xb = -xb
	}
	if xa < xb {
		con.Println("A")
	} else {
		con.Println("B")
	}
	return nil
}


Measured memory_bytes: 1844
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    if n==1:
        print('Hello World')
        exit()
    else:
        a = int(input())
        b = int(input())
        print(a+b)

if __name__ == '__main__':
    main()

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

int main(){
    string A;
    cin>>A;
    int l = A.size();
    string B = A;
    if(l==1) {
        printf("0\n");
    }
    else {
        int ans1=0;
        for(int i=1;i<l;i++) {

            if(A[i] == A[i-1]) {
                ans1++;
                if(A[i]=='0') A[i]='1';
                else A[i]='0';
            }
        }
        int ans2=1;
        if(B[0]=='0') B[0]='1';
        else B[0]='0';
//        cout<<B<<endl;
        for(int i=1;i<l;i++) {
//            cout<<B<<endl;
            if(B[i]==B[i-1]) {
                ans2++;
                if(B[i]=='0') B[i]='1';
                else B[i]='0';
            }
        }
//        cout<<B<<endl;
//        cout<<ans1<<" "<<ans2<<endl;
        cout<<min(ans1,ans2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

const int MAX = (1<<15);
typedef pair<int,int> P;

int dp[MAX];

int main(){

  for(int i = 0; i*i < MAX; i++)
    for(int j = i; j*j+i*i < MAX; j++)
      for(int k = j; k*k+j*j+i*i < MAX; k++)
	for(int l = k; l*l+k*k+j*j+i*i < MAX; l++){
	  int n = i*i+j*j+k*k+l*l;
	  if(n < MAX) dp[n]++;
	}
  int in;
  while(cin >> in && in) cout << dp[in] << endl;
  return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
#define re register
#define rep(i,a,b) for(re int i=a,i##end=b; i<=i##end; i++)
#define drep(i,a,b) for(re int i=a,i##end=b; i>=i##end; i--)
#define repp(i,a,b) for(re int i=a,i##end=b; i<i##end; i++)
#define drepp(i,a,b) for(re int i=a,i##end=b; i>i##end; i--)
#define Erep(i,x) for(int i=head[x]; ~i; i=Edge[i].nxt)
#define ll long long
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define lowbit(x) (x&-x)
#define ms(x,a) memset(x,a,sizeof x)
using namespace std;
template <class T> inline bool Max(T &x, T y){
	return x<y?x=y,1:0;
}
template <class T> inline bool Min(T &x, T y){
	return x>y?x=y,1:0;
}
template <class T> inline T rd() {
	static char ch;static bool neg;
	static T x=0;
	for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
	for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
	return x=(neg?-x:x);
}
const int M=1e5+5;

struct task{
	int x,y;
	bool operator < (const task &_) const {
		return y<_.y;
	}
}A[M];

bool cmp(task x, task y){
	return x.x<y.x;
}

priority_queue<task>Q;

int main(){
	int n=rd<int>(),m=rd<int>();
	rep(i,1,n) A[i].x=rd<int>(),A[i].y=rd<int>();
	sort(A+1,A+n+1,cmp);
	int ans=0;
	int at=1;
	int res=1;
	while(!Q.empty()) Q.pop();
	rep(i,1,m){
		while(A[res].x==i && res<=n) Q.push(A[res]),res++;
		if(!Q.empty()) ans+=Q.top().y,Q.pop();
	}
	printf("%d\n",ans);
	return 0;
}



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

int main(){
  int a,b,c,d,sum;
  cin >> a >> b >> c >> d;
  
  if(a < b){
    sum = a;
  }else{
    sum = b;
  }
  
  if(c < d){
    sum += c;
  }else{
    sum += d;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
import math
s=int(input())
if s==1:
  print("0 0 1 0 0 1")
  exit()
c=math.ceil(math.sqrt(s))
sa=c**2-s
for i in range(1, s):
  if sa%i==0 and sa/i <= 10**9:
    print("0 0 {} {} {} {}".format(c, i, sa//i, c))
    exit()

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (auto& x : A) cin >> x;
    map<int, ll> mp;
    for (int x : A) ++mp[x];
    ll res = 0;
    for (auto& e : mp) {
      ll c = e.snd;
      res += c * (c - 1) / 2;
    }
    for (int x : A) {
      ll ans = res;
      ans -= mp[x] * (mp[x] - 1) / 2;
      ans += (mp[x] - 1) * (mp[x] - 2) / 2;
      cout << ans << endl;
    }
  }
  return 0;
}


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

int main() {
	int n, m; cin >> n >> m;
	vector<int> l(m), r(m);
	for (int i = 0; i < m; i++) cin >> l[i] >> r[i];
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	int lmax = l[l.size()-1];
	int rmin = r[0];
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i >= lmax && i <= rmin) ans++;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    string o, e;
    cin >> o >> e;
    string ans = "";
    int i = 0;
    while(i < o.size()-1){
        ans += o[i];
        ans += e[i];
        i++;
    }
    if(o.size() > e.size()) ans += o[o.size()-1];
    else{
        ans += o[o.size()-1];
        ans += e[e.size()-1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
require 'pp'

base = 'z'.codepoints[0]
a = 'a'.codepoints[0]
o = gets.chomp!
orig = o.chars
s = o.codepoints
k = gets.to_i

memo = s.map {|x| (base - x + 1) % 26 }
#pp s
#pp memo

ans = Array.new(s.length)
memo.each_with_index do |x, i|
    if k >= x
        k -= x
        ans[i] = "a"
    else
        ans[i] = orig[i]
    end
end

ans[-1] = ((ans[-1].codepoints[0] - a + k) % 26 + a).chr
puts ans.join


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

int main(){
  int N;
  int audience = 0;
  cin >> N;
  for(int i = 0;i<N;i++){
    int l,r;
    cin >> l >> r;
    audience += r - l + 1;
  }
  
  cout << audience << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
DP = [0] * N  # N番目までに使用する最小エネルギ-
for n in range(1, N):
    if n == 1:
        DP[1] = abs(H[1] - H[0])
    else:
        DP[n] = min(abs(H[n] - H[n - 2]) + DP[n - 2], abs(H[n] - H[n - 1]) + DP[n - 1])
print(DP[-1])


Measured memory_bytes: 13980
#include <iostream>

namespace Mylib{
    using namespace std;
}

int main(void){
    using namespace std;
    long N,A,B;//Aが青,Bが赤
    cin >> N >> A >> B;
    
    long sum=A+B;
    long sub=N/sum;
    long ans=0;
    ans=sub*A;
    if((N%sum)>A){
        ans+=A;
    }else{
        ans+=N%sum;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N,M = list(map(int,input().split()))
    ab = [list(map(int,input().split())) for i in range(M)]

    uf = UnionFind(N+1)
    for i in range(M):
        uf.union(ab[i][0],ab[i][1])
    print(max([uf.size(i) for i in range(1,N)]))

if __name__ == '__main__':
    main()





Measured memory_bytes: 120260
#include<stdio.h>
int main() {
	long long int a, b, c, d, m, n, k,result=0;
	long long int s[200005] = {};
	char str[200005];
	scanf("%lld",&n);
	a = 100000;
	for (int i = 0; i < n; i++) {
		scanf("%lld", &s[i]);
		result += s[i];
		s[i] *= n;
		
	}

	for (int i = 0; i < n; i++) {
		if (s[i] - result >= 0) {
			c = s[i] - result;
		}
		else {
			c = -s[i] + result;
		}
		if (c < a) {
			a = c;
			b = i;
	}
		
	}


	printf("%lld",b);
}

Measured memory_bytes: 1664
import Foundation

func main(){
   let n = Int(readLine()!)!

   var cache = [Int](repeating: 0, count: n+1)
   
   for x in 1...100 {
      for y in 1...100 {
         for z in 1...100 {
            let computed = x*x + y*y + z*z + x*y + y*z + z*x
            if computed <= n {
               cache[computed] += 1
            }
         }
      }
   }
   for i in 1...n {
      print(cache[i])
   }
}
main()


Measured memory_bytes: 13088
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;

    int ans = 0;
    while (n > 0) {
        n -= x;
        ans += t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
import sys
import math
input = sys.stdin.readline

N, D = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)]

count = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for d in range(D):
            tmp += abs(x[i][d] - x[j][d])**2
        t = 1
        while t*t <= tmp:
            if t*t == tmp:
                count += 1
            t += 1

print(count)


Measured memory_bytes: 3064
/*package whatever //do not write package name here */

import java.io.*;
import java.util.Scanner;



public class Main {
	public static void main (String[] args)throws IOException {
// 		System.out.println("GfG!");
// Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[]= br.readLine().split(" ");

long  n= Long.parseLong(s[0]);
long a=Long.parseLong(s[1]);
long b= Long.parseLong(s[2]);
if(a==0 && b==0){
    System.out.println(0);
}
else{
long sum= a+b;
sum=n%sum;
if(sum>a)
sum=a;

long x= n/(a+b);

System.out.println(x*a+sum);
}
	}
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
using namespace std;
static const int N = 100;
int main() {
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;

	for (int i = 1; i <= n; i++)cin >> p[i - 1] >> p[i];

	for (int i = 1; i <= n; i++)m[i][i] = 0;

	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k < j; k++) {
				m[i][j] = min(m[i][j], m[i][k] +  m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
//
vi data;
 
signed main()
{
    Int(n);

    data.assign(n, 0);

    rep(i,n) {
        cin >> data[i];
    }

    int sum = 0, ans = 0;

    rep(i, n) {
        sum += data[i];
        if (i % 2) {
            if (sum >= 0) {
                ans += sum + 1;
                sum = -1;
            }
        } else {
            if (sum <= 0) {
                ans += -(sum - 1);
                sum = 1;
            }
        }
        //cout << ans << endl;;
        //cout << sum << " " ;
    }
//    cout << ans << endl;



    sum = 0; int ansb = 0;
                
    rep(i, n) {
        sum += data[i];
        if (i % 2) {
            if (sum <= 0) {
                ansb += -(sum - 1);
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                ansb += sum + 1;
                sum = -1;
            }
        }
        //cout << ansb << endl;
    }

    cout << min(ans, ansb) << endl;



    return 0;
}



Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	long[] Ai = new long[N+1];
    	for (int i = 0; i < Ai.length; i++) {
    		Ai[i] = sc.nextLong();
    	}
    	long tmp = 0L;
    	long hunt = 0L;
    	for (int i = 0; i < N; i++) {
    		long B = sc.nextLong();
    		long Btmp = B + tmp;
    		if (Ai[i] <= B + tmp) {
    			if (Ai[i] <= tmp) {
    				tmp = B;
    			} else {
    				tmp = B + tmp - Ai[i];
    			}
    			hunt += Ai[i];
    		} else {
    			tmp = 0L;
    			hunt += Btmp;
    		}
    	}
    	if (Ai[N] <= tmp) {
    		hunt += Ai[N];
    	} else {
    		hunt += tmp;
    	}
    	System.out.println(hunt);
    }
}

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

struct dice{
    int l[6];
    void roll(int a, int b, int c, int d){
        int t = l[a];
        l[a] = l[b];
        l[b] = l[c];
        l[c] = l[d];
        l[d] = t;}
    void roll_x() {roll(0, 2, 5, 3);}
    void roll_y() {roll(0, 1, 5, 4);}
    void roll_z() {roll(1, 2, 4, 3);}
    int find_l3(int a, int b){
        REP(i, 4) {
            roll_x();
            REP(j, 4) {
                roll_y();
                REP(k, 4) {
                    roll_z();
                    if (l[0] == a && l[1] == b) return l[2];}}}
    }
};

int main(){
    dice d;
    REP(i, 6) cin >> d.l[i];
    int q; cin >> q;
    REP(i, q) {
        int a, b; cin >> a >> b;
        cout << d.find_l3(a, b) << endl;}
}

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

int ans = 0;
vector<int> num(5, 0);

bool asc(int x, int y) {
  if(x % 10 == y % 10) return x < y;
  if(x % 10 == 0) return 1;
  if(y % 10 == 0) return 0;
  return x % 10 > y % 10;
}

int main() {
  for(int i = 0; i < 5; ++i) cin >> num[i];
  sort(num.begin(), num.end(), asc);
  for(int i = 0; i < 4; ++i) ans += (num[i] + 9) / 10 * 10;
  cout << ans + num[4] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

 using namespace std;
 typedef long long ll;

 int main(void){
 ll H,W;
 cin >> H >> W;

 if(H == 1 || W == 1){
 cout << 1 << endl;
 } else {
 cout << (H * W + 1) / 2 << endl;
 }

 return 0;
 }


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

vector<P>g[60];
vector<int>es;

bool dfs(int v, int tv, int p=-1){
  //aがbに到達した
  if(v==tv)return true;
  for(P u:g[v]){
    if(u.first==p)continue;
    //aからbまでの経路はtrue(esに経路が入る)
    if(dfs(u.first,tv,v)){
      es.push_back(u.second);
      return true;
    }
  }
  return false;
}

int main(){
  int n; cin>>n;
  rep(i,n-1){
    int a,b; cin>>a>>b;
    a--; b--;
    g[a].push_back(P(b,i));
    g[b].push_back(P(a,i));
  }
  int m; cin>>m;
  vector<ll>Eset(m);
  rep(i,m){
    int a,b; cin>>a>>b;
    a--; b--;
    es=vector<int>();
    dfs(a,b);
    //辺のidをlong longで管理(1ならその辺を含む)
    for(int bit:es){
      Eset[i]|=1LL<<bit;
    }
  }
  //包除原理
  ll ans=0;
  //i=0のとき　全体を表す
  rep(i,1<<m){
    ll mask=0;
    //条件の辺を白で塗る
    rep(j,m){
      if(i>>j&1)mask|=Eset[j];
    }
    int white=__builtin_popcountll(mask);
    //決定していない辺の個数はn-1-white個
    ll cnt=1LL<<(n-1-white);
    int pc=__builtin_popcount(i);
    if(pc%2==0)ans+=cnt;
    else ans-=cnt;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    if(a.size()==b.size()){
		
    for(int i=0;i<a.size();i++){
		cout<<a[i]<<b[i];
	}
}
    else{
		for(int i=0;i<b.size();i++){
			cout<<a[i]<<b[i];
		}
		cout<<a[a.size()-1];
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
 int X;
  cin >>X;
  repl(i,X,2*X) {
    if(IsPrime(i)) {
      cout<<i<<endl;
      break;
    }
    else {
      continue;
    }
  }
  
}

Measured memory_bytes: 256
N,A,B,C,D=(int(x) for x in input().split())

x=N//A
if N%A>0:
    x=x+1
    
y=N//C
if N%C>0:
    y=y+1

if x*B<=y*D:
    print(x*B)
else:
    print(y*D)


Measured memory_bytes: 5604
R, C, K = map(int, input().split())
A = [[0] * 4 for _ in range(C+1)]
B = [[-1] * (C+1) for _ in range(R+1)]
for k in range(K):
    r, c, v = map(int, input().split())
    B[r][c] = v

for r in range(1, R+1):
    D = A[:]
    for c in range(1, C+1):
        if B[r][c] == -1:
            A[c][0] = max(A[c-1][0], max(D[c]))
            A[c][1] = max(A[c-1][1], max(D[c]))
            A[c][2] = max(A[c-1][2], max(D[c])) 
            A[c][3] = max(A[c-1][3], max(D[c]))
        else:
            A[c][0] = max(A[c-1][0], max(D[c]))
            A[c][1] = max(A[c-1][1], A[c-1][0]+B[r][c], max(D[c])+B[r][c])
            A[c][2] = max(A[c-1][2], A[c-1][1]+B[r][c])
            A[c][3] = max(A[c-1][3], A[c-1][2]+B[r][c])
print(max(A[-1]))

Measured memory_bytes: 165092
h = Hash.new(0)
h[0] = 1

cur = 0
p10 = 1

ans = 0
gets.to_s.chomp.bytes.reverse_each do |c|
  cur = ( cur + ( c - 48 ) * p10 ) % 2019
  ans += h[cur]
  h[cur] += 1
  p10 *= 10
  p10 %= 2019 if p10 >= 2019
end

puts ans

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  long result = 0;
  for (int a = 0; a < N-2; a++) {
    for (int b = a+1; b < N-1; b++) {
      for (int c = b+1; c < N; c++) {
        if (L[c] >= L[a] + L[b]) break;
        if (L[b] < L[a] + L[c]) result++;
      }
    }
  }
  cout << result << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll fac[200010],finv[200010];

ll comb(ll n,ll r){
  if(n<0||r<0||n-r<0) return 0;
  else return (fac[n]*finv[r]%mod)*finv[n-r]%mod;
}

ll H(ll n,ll r){
  return comb(n+r-1,r);
}

ll n,k;

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

  fac[0]=1;
  rep(i,200000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,200001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>n>>k;
  repl(i,1,k+1){
    ll b=H(i,k-i);
    ll t=H(i+1,n-k-(i-1));
    cout<<b*t%mod<<endl;
  }

  return 0;
}


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

using namespace std;

typedef long long ll;
 
int main(){
    int now = 1;
    ll n, k; cin >> n >> k;
    vector<ll> a(n + 1);
    vector<ll> b(n + 1);
    for(int i = 1;i <= n;i++){
        cin >> b[i];
    }
    
    while(k > 0){
        if(k % 2 == 1)
            now = b[now];
        for(int i = 1;i <= n;i++){
            a[i] = b[b[i]];
        }
        for(int i = 1;i <= n;i++){
            b[i] = a[i];
        }
        k = k / 2;
    }
    cout << now;
}

Measured memory_bytes: 6424
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if (a> b){
        cout << "a > b" << endl;
    }else if( a < b){
        cout << "a < b" << endl;
    }else {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3108
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	string s;
	cin>>n>>s;

	vector<int> vec;

	int count = 0;
	int tmp = 0;
	char cur = s[0];

	if(s[0] == '#'){
		vec.push_back(0);
	}

	int sum=0;
	while(1){
		if (s[count] == '.'){
			sum++;
		}
		if (s[count] == cur){
			tmp++;
		}else{
			vec.push_back(tmp);
			if (cur == '.'){
				cur = '#';
			}else{
				cur = '.';
			}
			tmp = 1;
		}
		count ++;
		if(count == n){
			vec.push_back(tmp);
			break;
		}
	}

	int ans = sum;
	int v_size = vec.size();
	for (int i=0;i<v_size;i++)
	{
		if(!(i%2)){//even
			sum -= vec[i];
		}else{ //odd
			sum += vec[i];
		}
		if(sum < ans){
			ans = sum;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1532
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		long ans = Long.MAX_VALUE;
		long[] arr = new long[N+1];
		for (int i = 0; i < N; i++) {
			arr[i] += reader.nextLong();
			arr[i+1] = arr[i];
		}
		long last = arr[N-1];
		for (int i = 0; i < N-1; i++) {
			long gap = Math.abs(arr[i]-(last-arr[i]));
			ans = Math.min(ans, gap);
		}


		System.out.println(ans);
		reader.close();

	}
}

Measured memory_bytes: 85972
#include <bits/stdc++.h>
#define MAX 1000000
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

/* ----------------------------------------------------------------------------------- */

int n, k;
vector<int> d;
vector<vector<int>> a;

void input() {
	cin >> n >> k;
	d.resize(k);
	a.resize(k, vector<int>());

	for (int i = 0; i < k; i++) {
		cin >> d[i];
		a[i].resize(d[i]);
		for (int j = 0; j < d[i]; j++) {
			cin >> a[i][j];
		}
	}
}

void solve() {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		bool have = false;
		for(auto v : a) {
			for (auto p : v) {
				if (p == i) {
					have = true;
				}
			}
		}
		if(!have) {
			ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	input();
	solve();

	// __test {
	// 	solve();
	// }
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            long[] H = new long[N];

            for (int i = 0; i < N; i++) {
                H[i] = sc.nextLong();
            }

            H[0] = H[0] - 1;
            for (int i = 1; i < N; i++) {
                if (H[i] > H[i - 1]) {
                    H[i] = H[i] - 1;
                }

                if (H[i] < H[i - 1]) {
                    System.out.println("No");
                    System.exit(0);
                }
            }

            System.out.println("Yes");
        }
    }

}


Measured memory_bytes: 62860
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  string s;
  int i,j,n;
  cin >> s;
  n=s.size();
  j=n-1,i=0;
  while(i<=j){
    if(s[i]!=s[j]){
      printf("No\n");
      return 0;
    }
    i++,j--;
  }
  i=0,j=(n-1)/2-1;
  while(i<=j){
      
    if(s[i]!=s[j]){
      printf("No\n");
      return 0;
    }
    i++,j--;
  }
  i=(n+3)/2-1,j=n-1;
  while(i<=j){
    if(s[i]!=s[j]){
      printf("No\n");
      return 0;
    }
    i++,j--;
  }
  printf("Yes\n");
  return 0;
}

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

int main()
{
  int N; cin >> N;
  vector<int> A(N + 1);
  for (int i = 0; i < N + 1; i++) cin >> A[i];
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B[i];

  long long  ans = 0, lest = A[0];
  for (int i = 0; i < N; i++)
  {
    if (lest >= B[i]) {
      ans += B[i];
      lest = A[i + 1];
    }
    else {
      ans += lest;
      B[i] -= lest;
      ans += min(B[i], A[i + 1]);
      lest = max(A[i + 1] - B[i], 0);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define forn(i, a, b) for(int i = a; i < b; i++)


#define trarr(a,n) forn(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) forn(i,0,n)forn(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 2e5+10;

void solve(int _t){
	int h, w;
	cin >> h >> w;
	string s[h];
	for(int i = 0; i < h; i++) cin >> s[i];
	ll dp[h][w];
	dp[0][0] = s[0][0] =='.';
	for(int i = 1; i < h; i++){
		dp[i][0] = dp[i-1][0];
		if(s[i][0] == '#') dp[i][0] = 0;
	}	
	for(int i = 1; i < w; i++){
		dp[0][i] = dp[0][i-1];
		if(s[0][i] == '#') dp[0][i] = 0;
	}	
	for(int i = 1; i < h; i++) for(int j = 1; j < w; j++){
		dp[i][j] = dp[i-1][j];
		dp[i][j] += dp[i][j-1];
		dp[i][j] %= P;
		if(s[i][j] == '#') dp[i][j] = 0;
	}
	cout<<dp[h-1][w-1]<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	forn(test, 1, t+1){
		solve(test);
	}
	return 0;
}

Measured memory_bytes: 12516
def main():
    x=list(input())
    ans=cnt=key=0
    for i in range(len(x)):
        if key==0 and x[i]=="T":
            ans+=1
        elif x[i]=="S":
            key=1
            cnt+=1
        elif key==1 and x[i]=="T":
            cnt-=1
            if cnt==0:
                key=0
    ans+=cnt
    print(ans)
main()

Measured memory_bytes: 61552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  vector<int> tr(4);
  rep(i, s.size()){
    tr.at(i) = s.at(i) - '0';
  }
  rep(bit, 1 << 3){
    int ans = tr.at(0);
    rep(i, 3){
      if((bit & (1 << i)) == 0) ans += tr.at(i+1);
      else ans -= tr.at(i+1);
    }
    if(ans == 7){
      cout << tr.at(0);
      rep(i, 3){
        if((bit & (1 << i)) == 0) cout << '+';
        else cout << '-';
        cout << tr.at(i+1);
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

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

#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, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int main() {
  //std::cout << std::fixed << std::setprecision(20);
  int64_t mod = 1e+9 + 7;
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  REP(i,N) cin >> A[i];

  int64_t sum = 0;
  
  FOR(i,0,60){
    int64_t p = 0;
    int64_t q = 0;
    REP(j,N){
      if((A[j] >> i) & 1) p++;
      else q++;    
    }
    //p %= mod;
    // %= mod;
    int64_t tmp = (1ll << i ) % mod;
    int64_t pq = p * q % mod;
    tmp = tmp * pq % mod;
    sum = (sum + tmp) % mod;
  }
  cout << sum << endl;
}

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

const int M = 1e9+7;

int mul(int a, int b){
    return 1LL*a*b%M;
}

int add(int a, int b){
    return (a%M+b%M)%M;
}

int sub(int a, int b){
    return ((a%M - b%M)+M)%M;
}

int pow(int a, int b){
    int res = 1;
    while(b>0){
        if(b&1) res = mul(res,a);
        a = mul(a,a);
        b/=2;
    }
    return res%M;
}
//this is the solution for problem E. reused it.
// simple soln is to bruteforce
int main(){
    int n,k;
    cin>>k;
    n = 3;
    int res = 0;
    int arr[k+1];
    for(int i = k; i >= 1; i--){
           int t = pow(k/i, n); 
           for(int j = i*2; j<=k; j+=i) t = sub(t,arr[j]);
           res = add(res,mul(t,i));
           arr[i] = t;
    }
    cout<<res;
}


Measured memory_bytes: 3604
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
 
show_flg=False
show_flg=True



n=I()

ans=':('
for i in range(n,-1,-1):
    if int(i*1.08)==n:
        ans=i
        break
    
    
print(ans)


Measured memory_bytes: 39020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int cnt[100005];
int32_t main(){
	int n; cin>>n;
	for(int i=0, x; i<n; i++){
		cin>>x; cnt[x]++;
	}
	ll sum=0ll;
	for(int i=1; i<=100000; i++) sum+=(ll)cnt[i]*1ll*i;
	int q; cin>>q;
	for(;q--;){
		int b, c; cin>>b>>c;
		sum+=(c-b)*1ll*cnt[b];
		cnt[c]+=cnt[b]; cnt[b]=0;
		cout<<sum<<endl;
	}
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] dx = {-1,0};
		int[] dy = {0,-1};
		
		long mod = (long) 1e9 + 7;
		
		long ans = 1;
		int nvh0 = 0;
		for(int j=0;j<N;j++){
			int nvh = 0;
			if(j<N-1 && S[0][j+1] == S[0][j]){
				nvh = 2;
			} else {
				nvh = 1;
			}
			long c = 0;
			if(nvh0 == 0){
				c = nvh == 1 ? 3 : 6;
			} else {
				if(nvh0 == 2 && nvh == 2) c = 3;
				if(nvh0 == 1 && nvh == 2) c = 2;
				if(nvh0 == 2 && nvh == 1) c = 1;
				if(nvh0 == 1 && nvh == 1) c = 2;
			}
			ans *= c; ans %= mod;
			nvh0 = nvh;
			if(nvh == 2) j++;
		}
		
		Console.WriteLine(ans);
		
	}
	
	bool InRange(int t,int l, int r){
		return l <= t && t < r;
	}
	
	int N;
	String[] S;
	public Sol(){
		N = ri();
		S = new String[2];
		for(int i=0;i<2;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main (void){
    int a, b;
    cin >> a >> b;
    if (a == 1) {
        if (b == 2) {
            cout << 3 << endl;
            } else if (b == 3) {
                cout << 2 << endl;
            }
    }else if (a == 2) {
        if (b == 1) {
            cout << 3 << endl;
            } else if (b == 3) {
                cout << 1 << endl;
            }
    }else if (a == 3) {
        if (b == 1) {
            cout << 2 << endl;
            } else if (b == 2) {
                cout << 1 << endl;
            }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

pair<int, int> get_max_dist(int v, int p, const vector<vector<int>> &adj) {
  pair<int, int> result = {0, v};
  for (int u : adj[v]) {
    if (u == p) continue;
    pair<int, int> res = get_max_dist(u, v, adj);
    res.first += 1;
    result = max(result, res);
  }
  return result;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b), --a, --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  pair<int, int> v1 = get_max_dist(0, -1, adj);
  int diameter = get_max_dist(v1.second, -1, adj).first;
  bool result;
  if (diameter == 0) result = true;
  else if (diameter == 1) result = false;
  else result = (diameter - 2) % 3 <= 1;
  if (result) printf("First\n");
  else printf("Second\n");
  return 0;
}


Measured memory_bytes: 26752