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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

void Main(){
    int n, m;
    cin >> n >> m;
    VI av(m);
    int sum_a = 0;
    REP(i, m) {
        int j;
        cin >> j;
        sum_a += j;
    }
    cout << max(-1, n - sum_a) << en;
    
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

char s[1000001];

int main(void) {
    int n, m, i, seq, count;

    while (scanf("%d", &n) == 1 && n) {
        scanf("%d\n", &m);
        scanf("%s", s);
        for (i = 0, seq = 0, count = 0;
             i < m; i++) {
            if ((seq % 2 == 0) && s[i] == 'I') {
                seq++;
                if (seq / 2 >= n) {
                    count++;
                }
            }
            else if (seq % 2 && s[i] == 'O') {
                seq++;
            }
            else {
                seq = s[i] == 'I';
            }
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 1580
a, b, c, x = [int(input()) for i in range(4)]

ans = 0
for i in range(0, min(a + 1, (x // 500) + 1)):
    start = min(500 * i, x)
    for j in range(0, min(b + 1, ((x - start) // 100) + 1)):
        start1 = min(start + j * 100, x)
        left = x - start1
        if left // 50 <= c:
            ans += 1
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==1||n==2){
        cout<<n;
    return 0;
    }
    
    int f;
    while(f=1)
    {
        f=0;
        for(int i=2;i<=n/2;i++)
        {
            if(n%i==0)
                f=1;
        }
        if(f==0) break;
        else n++;
    }
    cout<<n<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int[]l = new int[n];

    int cou = 1;
    int d = 0;
    int a = 0;
    for(int i=0; i<n; i++) {
    	l[i] = sc.nextInt();
    	if(d <= x ) {
    		d += l[i];
    		cou++;
     	}
    }
    if(d <= x) {
    	System.out.print(cou);
    }else {
    	System.out.print(cou-1);
    }
}
}

Measured memory_bytes: 36120
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        k: usize,
        x: usize,
    }
    let ans = if 500 * k >= x {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, m, a;
  scanf("%lld%lld", &n, &m);
  for(i = 0; i < m; ++i) scanf("%lld", &a), n -= a;
  printf("%lld", n >= 0 ? n : -1);
  return 0;
}

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

vector<ll> cand;

void dfs(ll n, ll d, ll md) {
    if (d == md) {
        cand.push_back(n);
        return;
    }
    for (int i = 0; i <= 9; i++) {
        if (abs(n%10-i) <= 1) dfs(n*10+i, d+1, md);
    }
    return;
}

int main() {
    int K;
    cin >> K;
    
    for (int i = 1; i <= 12; i++) {
        for (int j = 1; j <= 9; j++) dfs(j, 1, i);
    }
    sort(cand.begin(), cand.end());
    cout << cand[K-1] << endl;
    return 0;
}

Measured memory_bytes: 18792
#include<stdio.h>


int main() {
    int a[200],b[200],c;
    int i,j,digit;
    i=0;
    while (scanf("%d",&a[i])!=EOF) {
        scanf("%d",&b[i]);
        i++;
    }
    for (j = 0; j < i; j++) {
        c=a[j]+b[j];
        digit=1;
        while((c=c/10)!=0)digit++;
    printf("%d\n",digit);
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

long int pow(long int n, int m){
  if(m<=0){
    return 1;
  }else{
    return n * pow(n,m-1);
  }
}

typedef unsigned int uint;

int main(){
  string s;
  cin >> s;
  int ans = s.size();
  int Scount = 0;
  for(int i=0; i<s.size(); ++i){
    char c = s[i];
    if(c == 'S'){
      Scount++;
    }else if(c == 'T'){
      if(Scount > 0){
        Scount--;
        ans -= 2;
      }
    }else{
      Scount = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
 
#define Death Komachi
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;i++)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;i--)
#define LL long long
#define M 100004
 
int n,A[M];
LL x,y;
void Stop(){
	puts("-1");
	exit(0);
}
int main(){
	scanf("%d",&n);
	REP(i,1,n+1)scanf("%d",&A[i]);
	if(A[n]!=2)Stop();
	x=2,y=3;
	
	DREP(i,n,1){
		int a=A[i-1];
		x=(x+a-1)/a*a;
		y=y/a*a+a-1;
		if(x>y)Stop();
	}
	printf("%lld %lld\n",x,y);
	return 0;
}

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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,ans; string str;

int solve(){
    cin>>n;
    double x=n;
    n=(n+1)/2;
    double t=n/x;
    cout<<fixed<<setprecision(10)<<t;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string s;
    string t;
    char c=' ';
    bool aru[2][30]={};
    
    
    cin >> s;
    cin >> t;
    
    for(int i=0; i<s.size(); i++){
        
        aru[0][s[i]-'a']=true;
        aru[1][t[i]-'a']=true;
        
    }
    int aa,bb;
    aa=0;
    bb=0;
    for(int i=0;i<26;i++){
        if(aru[0][i])aa++;
        if(aru[1][i])bb++;
    }
    
    if(aa!=bb){
         cout << "No" << endl;
                    
        return 0;
                    
    }
    
    for(int i=0; i<=25; i++){
        
        c = ' ';
        
        for(int j=0; j<t.size(); j++){
            
            if(t[j]-'a'==i){
                
                if(c==' '){
                    
                    c = s[j];
                    
                } else if(c!=s[j]){
                    
                    cout << "No" << endl;
                    
                    return 0;
                    
                }
                
            }
            
        }
        
    }
    
    cout << "Yes" << endl;

    return 0;
    
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+18;

int main() {
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    vector<Int> p(n), a(n), b(n);
    for (Int i = 1; i <= n; i++) {
        Int p;
        cin >> p;
        a[p - 1] = b[p - 1] = i;
    }
    for (Int i = 0; i < n - 1; i++) a[i + 1] += a[i];
    for (Int i = n - 1; i > 0; i--) b[i - 1] += b[i];
    for (Int i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
    for (Int i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A+B+1-C>=0) {
    cout << B+C << endl;
  }
  else if (A==0 && C==0){
    cout << B << endl;
  }
  else {
    cout << A+2*B+1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>

using namespace std;

int main()
{
  vector<int> dx({-1, +1,  0,  0});
  vector<int> dy({ 0,  0, -1, +1});
  
  int H, W;
  cin >> H >> W;
  
  vector<vector<char> > board(H, vector<char> (W));
  for (int i = 0; i < H; ++i) {
    string S;
    cin >> S;
    for (int j = 0; j < W; ++j) {
      board[i][j] = S[j];
    }
  }

  vector<bool> visited(1000 * 1000, false);
  int remaining = H * W;
  
  queue<int> q;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == '#') {
	int hash = i * 1000 + j;
	q.push(hash);
	visited[hash] = true;
	--remaining;
      }
    }
  }
  queue<int> nq;

  if (remaining == 0) {
    cout << "0" << endl;
    return 0;
  }

  int round = 1;
  while (remaining > 0) {
    while (not q.empty()) {
      int hash = q.front();
      q.pop();
      int x = hash / 1000;
      int y = hash % 1000;
      for (int i = 0; i < 4; ++i) {
	int xx = x + dx[i];
	int yy = y + dy[i];
	if (xx < 0 or xx >= H or yy < 0 or yy >= W) continue;
	int hash = xx * 1000 + yy;
	if (not visited[hash]) {
	  visited[hash] = true;
	  --remaining;
	  nq.push(hash);
	  if (remaining == 0) {
	    cout << round << endl;
	    return 0;
	  }
	}
      }
    }
    swap(q, nq);
    ++round;
  }
  
  return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s;
	cin >> s;
	int k ;
	cin >> k;
	int n = s.size();
	for(int i=0;i<n;i++)
	{
		if(('z'+1-s[i])%26<=k)
		{
			k -= ('z'+1-s[i])%26;
			s[i]='a';
			
		}
	}
	//cout<<k<<endl;
	s.back() = 'a'+(s.back()-'a'+k)%26;
	cout<<s<<endl;
	return 0;
}

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

int main(){
	int n;
	int ans = 0;
	string str;
	cin >> n >> str;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		bool ok = false;
		for(int j = 0; j < s.size(); j++){
			if(s[j] == str[0]){
				for(int k = j+1; k < s.size(); k++){
					if(s[k] == str[1]){
						int l = k-j;
						bool tmp = true;
						for(int t = 2; t < str.size(); t++){
							if(k+(t-1)*l >= s.size()){
								tmp = false;
								break;
							}
							if(str[t] != s[k+(t-1)*l]){
								tmp = false;
								break;
							}
						}
						if(tmp){
							ans++;
							ok = true;
						}
					}
					if(ok) break;
				}
			}
			if(ok) break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin>>N;
	double T,A;
	cin>>T>>A;
	vector<double> vi;
	for(int i=0;i<N;i++)
	{
		double k;
		cin>>k;
		k = k*0.006;
		vi.push_back(T-k);
	}
	double mi=1e17;
	int pos = -1;
	for(int i=0;i<vi.size();i++)
	{
		if(abs(vi[i]-A)<mi)
		{
			mi = abs(vi[i]-A);
			pos = i+1;
		}
	}
	cout<<pos<<endl;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    VI V(N),C(N);
    LL ans = 0;
    REP(i,N) cin>>V[i];
    REP(i,N) cin>>C[i];
    REP(i,N)
    {
        if(V[i] - C[i] > 0) ans += (V[i]-C[i]);
        dump(ans)
    }
    cout << ans<< endl;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int w = sc.nextInt();
		int size_S = S.length();
		for(int i = 0; i < size_S ; i += w) {
			System.out.print(S.charAt(i));
		}

	}

}

Measured memory_bytes: 21716
def main():
    N = int(input())
    ans = [0]*(N)
    for x in range(1, 105):
        for y in range(1, 105):
            for z in range(1, 105):
                if N < x**2 + y**2 + z**2 + x*y + y*z + z*x:
                    break
                ans[x**2 + y**2 + z**2 + x*y + y*z + z*x - 1] += 1

    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 73940
#include <bits/stdc++.h>
using namespace std ;
int main () {
    int N; cin>>N ;
    int sum = 0 , maxL = 0;
    for (int i = 0; i < N ; ++i ) {
      int L; cin>>L;
      sum += L;
      maxL = max(maxL,L);
    }
    if (maxL<sum-maxL) {
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int r, g, b, sum;
    cin >> r >> g >> b;
    sum = r*100 + g*10 + b;
    if(sum%4 == 0)
    {
        cout << "YES" <<endl;
    }else{
        cout << "NO" <<endl;
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	if(A+B>=C) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())

substring_list = []
for i in range(1, 5+1):
    for start in range(len(s) - i + 1):
        substring_list.append(s[start:start+i])

# print(substring_list)
substring_list = sorted(set(substring_list))
print(substring_list[k-1])



Measured memory_bytes: 5068
N,K=map(int,input().split())
a=list(map(int,input().split()))
l=[]
ans=[]
for i in range(N):
    buf=0
    for j in range(i,N):
        buf=buf+a[j]
        l.append(buf)
#print(l)
for i in range(40,-1,-1):
    piv=[]
    for j in range(len(l)):
        if (l[j]>>i)&1:
            piv.append(l[j])
    if len(piv)>=K:
        l=piv
        ans.append(i)
    #print(piv,l)
cnt=0
for i in ans:
    cnt=cnt+pow(2,i)
print(cnt)

Measured memory_bytes: 65916
implicit none
integer:: n, i, j, a, b, ans, t
integer,allocatable,dimension(:):: p

read(5,*) n
!read(5,*) n, a, b
!allocate(p(n))
!read(5,*) (p(i),i=1,n)

if (n == 7 .or. n == 5 .or. n == 3) then
    write(6, *) "YES"
else
    write(6, *) "NO"    
endif

end

Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(i=a;i<b;i++)
    #define rfo(i,b,a) for(i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e3 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int m;
    char s[MAX][MAX];
    int dp[MAX][MAX];
    void solve()
    {
        cin>>n>>m;
        fo(i,1,n+1)
        {
            fo(j,1,m+1)
            {
                cin>>s[i][j];
            }
        }
        
        dp[1][1]=1;
         fo(i,1,n+1)
        {
            fo(j,1,m+1)
            {
                if(i==j&& j==1)
                continue;
                
                if(s[i][j]=='.')
               {
                   dp[i][j]=dp[i-1][j]+dp[i][j-1];
                   if(dp[i][j]>=MOD)
                   dp[i][j]-=MOD;
                   
               }
               
               else
               dp[i][j]=0;
            }
        }
        cout<<dp[n][m]<<endl;
    	
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
      	
      	// int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
      	ios_base::sync_with_stdio(0);
      	cin.tie(NULL);
      	
      	// cin>>t;while(t--)
      	solve();
      	
    	return 0;
      }

Measured memory_bytes: 20224
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;

int main()
{

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

	switch (a) {
	case 1:
		ans = 1;
		break;
	case 2:
		ans = 1;
		if (b >= 2)ans = 2;
		break;
	case 3:
		ans = 2;
		if (b >= 3)ans = 3;
		break;
	case 4:
		ans = 3;
		if (b >= 4)ans = 4;
		break;
	case 5:
		ans = 4;
		if (b >= 5)ans = 5;
		break;
	case 6:
		ans = 5;
		if (b >= 6)ans = 6;
		break;
	case 7:
		ans = 6;
		if (b >= 7)ans = 7;
		break;
	case 8:
		ans = 7;
		if (b >= 8)ans = 8;
		break;
	case 9:
		ans = 8;
		if (b >= 9)ans = 9;
		break;
	case 10:
		ans = 9;
		if (b >= 10)ans = 10;
		break;
	case 11:
		ans = 10;
		if (b >= 11)ans = 11;
		break;
	case 12:
		ans = 11;
		if (b >= 12)ans = 12;
		break;
	}

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();

    let n : i32 = iter.next().unwrap().parse().unwrap();
    let h : Vec<i32> = (0..n)
        .map(|_| { iter.next().unwrap().parse().unwrap() })
        .collect();
    let mut max_h = 0 ;
    let mut ans = 0;

    for x in h {
        if max_h < x {
            max_h = x;
        }
        if max_h <= x {
            ans += 1;
        }
    }
    
    println!("{}", ans);
}


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

int main() {
    int N, M;
    cin>>N>>M;
    string S;
    cin>>S;
    reverse(S.begin(), S.end());
    int now = 0;
    bool can = true;
    bool tmpcan;
    vector<int> ans;
    while(now < S.size()-1){
        tmpcan = false;
        for(int step=M;step>0;--step){
            if(S[now+step]=='0'){
                now += step;
                ans.push_back(step);
                tmpcan = true;
                break;
            }
        }
        if(!tmpcan) {
            can = false;
            break;
        }
    }
    if(can){
        reverse(ans.begin(), ans.end());
        for(int i=0;i<ans.size();++i){
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
    else cout<<-1<<endl;
}


Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = (1e7 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
vector<int> vt;
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


bool check(string s)
{
	int n = s.length();
	for(int i  = 0 ; i < n-1 ; i++)
	{
		if(abs(s[i] - s[i+1]) > 1)
		{
			return false;
		}
	}

	return true;
}

void sieve()
{
	
	int cnt = 0;
	for(int i = 1; i <= siz ; i++)
	{
		int num = i;
		ostringstream strg;
		strg<< num;
		string s1 = strg.str();
		if(check(s1))
		{
			cnt++;
		}
	}

	cout<<cnt;

}



signed main()
{

	speedrap
	//sieve();
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		set<int> st;
		for(int i = 2 ; i*i <= n ; i++)
		{
			int m = n;
			if(n%i == 0)
			{
				int div1 = i;
				int div2 = n/i;
				while(m %div1 ==0)
				{
					m/=div1;
				}

				if(m % div1 == 1)
				{
					st.insert(div1);
				}
				m = n;

				while(m%div2 == 0)
				{
					m/= div2;
				}

				if(m%div2 == 1)
				{
					st.insert(div2);
				}
			}
		}

		n--;

		auto it = st.begin();

		// for(it =st.begin() ; it!= st.end() ; it++)
		// {
		// 	cout<<*it<<" ";
		// }cout<<"\n";
		for(int i = 1 ; i*i <= n ; i++)
		{
			if(n%i == 0)
			{
				st.insert(i);
				st.insert(n/i);
			}
		}

		st.erase(1);

		// for(it =st.begin() ; it!= st.end() ; it++)
		// {
		// 	cout<<*it<<" ";
		// }cout<<"\n";
		st.insert(n+1);
		cout<<(int)(st.size())<<"\n";
	}
}

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

int main(){
    int n,m,c,ans = 0;
    cin >> n >> m >> c;
    vector<int> data_b(m);
    vector<vector<int>> data_a(n, vector<int>(m));
    for (int i = 0; i < m; i++){
        cin >> data_b.at(i);
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> data_a.at(i).at(j);
        }
    }
    for (int i = 0; i < n; i++){
        int sum = 0;
        for (int j = 0; j < m; j++){
            sum += data_a.at(i).at(j) * data_b.at(j);
        }
        if(sum + c > 0)ans ++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll pl = x / d;
	ll mn = pl + 1;
	if (mn > k) {
		cout << x - k * d << endl;
	}
	else {
		if ((k - mn) % 2)cout << x % d << endl;
		else cout << abs(x % d - d) << endl;
	}
}

Measured memory_bytes: 3632
import qualified Data.Vector as V
f l i n=if i==1 then n else if n>(V.length l) then -1 else f l (l V.! i) (n+1)
main=do
 n<-getLine
 l<-V.fromList.map ((+(-1)).read).lines<$>getContents
 print$f l 0 0

Measured memory_bytes: 33276
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){

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

    int k = (a+b)/2;
   
    if(abs(a-k) == abs(b-k)){
        cout << k <<endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	int N,X,Y;
	cin>>N>>X>>Y;
	int G[N+2][3]={0};
	G[1][0]=2;
	rep(i,2,N+1){
		G[i][0]=i+1;
		G[i][1]=i-1;
	}
	G[X][2]=Y;

	rep(i,1,N+1){
		DBG("i=",i,G[i][0],G[i][1]);
	}

	vector<pair<int,int>>ans[N+1];

	rep(i,1,N+1){
		queue<int> q;
		q.push(i);
		int dist[N+1]={0};
		pair<int,int>tmp;
		while(!q.empty()){
			int v=q.front();q.pop();
			DBG("i=",i,"v=",v);
			rep(j,0,3){
				DBG("j=",j,"G[v][j]=",G[v][j]);
				if(G[v][j]==0) continue;
				if(G[v][j]==N+1) continue;
				if(dist[G[v][j]]>0) continue;
				dist[G[v][j]]=dist[v]+1;
				DBG("dist[G[v][j]]=",dist[G[v][j]],"dist[v]=",dist[v]);
				if(i<G[v][j]){
					tmp.first=i;
					tmp.second=G[v][j];
					ans[dist[v]+1].pb(tmp);
				}
				q.push(G[v][j]);
			}
		}
	}
	rep(i,1,N){
//		for( auto p : ans[i] ){
//			cout<<'('<<p.first<<','<<p.second<<')'<<',';
//		}
//		cout<<endl;
		cout<<ans[i].size()<<endl;
	}
	return 0;
}


Measured memory_bytes: 23936
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    int ans = 1;
    if(c-a-b <= 0) ans = 0;
    else{
        if((c-a-b)*(c-a-b) <= 4*a*b) ans = 0;
    }
    if(ans == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    sort(a.begin(), a.end());
    unordered_set<int> s;
    int ans = n;
    rep(i, n){
        if(s.find(a[i]) != s.end()){
            ans--;
            continue;
        }else{
            if(i < n-1){
                if(a[i] == a[i+1]){
                    ans--;
                    s.insert(a[i]);
                    continue;
                }
            }
            for(int j = 1; j * j <= a[i]; j++){
                if(a[i] % j == 0 && s.find(j) != s.end()){
                    ans--;
                    break;
                }else if(j > 1 && a[i] % j == 0 && s.find(a[i]/j) != s.end()){
                    ans--;
                    break;
                }
            }
            s.insert(a[i]);
        }
    }
    cout << ans << endl;
}

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

#define int long long

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 3, INF = 2000ll * 1000 * 1000 * MAXN + 3, D = 1000 * 1000 * 1000 + 7, MAXM = 200 * 1000 + 3;













int n, m, s, t, d[2 + 1][MAXN], cnt[2 + 1][MAXN], w[MAXM], e[MAXM], ans;
vector<int> g[MAXN];
set<pii> p;


void dij(int x, int y) {
	fill(d[y], d[y] + n, INF);
	p.insert({0, x});
	d[y][x] = 0;
	cnt[y][x] = 1;
	while (!p.empty()) {
		int f = p.begin() -> second;
		p.erase(p.begin());
		for (auto i : g[f]) {
			int z = f ^ e[i];
			if (d[y][f] + w[i] < d[y][z]) {
				p.erase({d[y][z], z});
				d[y][z] = d[y][f] + w[i];
				p.insert((pii){d[y][z], z});
				cnt[y][z] = cnt[y][f];
			} else if (d[y][f] + w[i] == d[y][z]) cnt[y][z] = (cnt[y][z] + cnt[y][f]) % D;
		}
	}
}



int32_t main() {
	cin >> n >> m >> s >> t;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v >> w[i];
		g[--u].push_back(i), g[--v].push_back(i);
		e[i] = u ^ v;
	}
	s--, t--;
	dij(s, 0), dij(t, 1);
	ans = cnt[0][t] * cnt[1][s] % D;
	int q = d[0][t];
	for (int i = 0; i < n; i++) {
		int a = cnt[0][i], x = d[0][i], o = cnt[1][i];
		for (auto j : g[i]) {
			int zz = e[j] ^ i;
			int y = d[1][zz], b = cnt[1][zz];
			if (x + w[j] != d[0][zz] || y + w[j] != d[1][i] || x + y + w[j] != q || abs(x - y) >= w[j]) continue;
			ans = ((ans - a * b % D * a % D * b % D) + D) % D;
		}
		if (q == d[0][i] + d[1][i] && d[0][i] == d[1][i]) ans = ((ans - a * o % D * a % D * o % D) + D) % D;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 23784
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int a;
	long long y = 1000000000,x=0;
	cin >> a;
	vector<int> s(a);
	for (int i = 0; i < a; i++) {
		cin >> s[i];
		if (x < s[i])x = s[i];
		if (y > s[i])y = s[i];
	}
	cout << x - y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    vector<char> alph(26);
    ll a = 0;
    for(char c = 'a';c <= 'z';c++,a++)alph[a] = c;
    ll N;
    cin >> N;
    vector<char> ans;
    while(N){
        N--;
        ans.push_back(alph[N % 26]);
        N /= 26;
    }
    for(ll i = ans.size() - 1;i >= 0;i--)cout << ans[i];
    cout << endl;
    //rep(i,26)cout << alph[i] << endl;
    //cout << ans[0];
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
	ll n,a,b;
	cin >> n >> a >>b;
	ll r = n/(a+b);
	if(n%(a+b) < a)
		cout << a*(r)+n%(a+b) <<endl;
	else{
		cout << a*r+a <<endl;
	}
}

signed main() {
	boost;
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#define MAXN 100005

using namespace std;
typedef long long ll;

int N, a[MAXN], cnt, cnt2, B[MAXN], B2[MAXN], B3[MAXN], B4[MAXN];
int maxim, maxim2, maxim3, maxim4, ans, ans1, ans2, ans3, ans4;

int main ()
{
	cin >> N;
	for ( int i = 0; i < N; i++ )
		cin >> a[i];
	
	cnt2 = (N / 2);
	cnt = cnt2 + (N % 2 == 1);
	for ( int i = 0; i < N; i += 2 )
	{
		B[a[i]]++;
		if ( B[a[i]] > maxim )
			maxim = B[a[i]], ans1 = a[i];
	}
	for ( int i = 1; i < N; i += 2 )
	{
		B2[a[i]]++;
		if ( B2[a[i]] > maxim2 )
			maxim2 = B2[a[i]], ans2 = a[i];
	}

	if ( ans1 != ans2 )
		ans = (cnt - maxim) + (cnt2 - maxim2);
	else
	{
		for ( int i = 0; i < N; i += 2 )
		{
			B3[a[i]]++;
			if ( B3[a[i]] > maxim3 && a[i] != ans1 )
				maxim3 = B3[a[i]], ans3 = a[i];
		}
		for ( int i = 1; i < N; i += 2 )
		{
			B4[a[i]]++;
			if ( B4[a[i]] > maxim4 && a[i] != ans1 )
				maxim4 = B4[a[i]], ans4 = a[i];
		}

		ans = min ( (cnt - maxim) + (cnt2 - maxim4), (cnt - maxim3) + (cnt2 - maxim2) );
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    String str=scan.next();
    int count=0;
    int dount=0;
    for(int i=0;i<str.length();i++){
      if(str.substring(i,i+1).equals("0")){
        count++;
      }else{
        dount++;
      }
    }
    count=Math.min(count,dount);
    System.out.println(2*count);
  }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    cout << A[A.size() - 1] - A[0] << endl;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<60;
vector<pair<int,ll>> E[20050];

ll dfs(int s,int g,int pre){
    if( s == g) return 0ll;
    ll ret = inf;
    for(auto v : E[s]){
        if(v.first == pre)continue;
        ret = min(ret,dfs(v.first,g,s)+v.second);
    }
    return ret;
}
int main(){
    int n,m,r;
    cin>>n>>m>>r;
    vector<int> rd(r);
    for(auto &a : rd) cin>>a,a--;
    vector<vector<ll>> d(n+1,vector<ll>(n+1,inf));
    for(int i=0;i<n;++i) d[i][i] = 0;
    for(int i=0;i<m;++i){
        int a,b;ll c;
        cin>>a>>b>>c;
        a--;b--;
        d[a][b] = min(d[a][b],c);
        d[b][a] = min(d[b][a],c);
    }
    for(int i=0;i<n;++i)for(int j=0;j<n;++j)for(int k=0;k<n;++k)d[j][k] = min(d[j][k],d[j][i] + d[i][k]); 
    sort(rd.begin(),rd.end());
    ll ret = inf;
    do{
        ll tmp = 0l;
        for(int i=0;i<r-1;++i)tmp += d[rd[i]][rd[i+1]];
        ret = min(ret,tmp);
    }while(next_permutation(rd.begin(),rd.end()));
    cout << ret << endl;
    return 0;
}



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

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}


#define incID(i, l, r) for(int i = (l); i < (r); i++)
#define inc(i, n) incID(i, 0, n)
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }


// ---- ----

int n, k;
vector<int> vec[100000];
bool has[100000];
int mi[100000];
int ma[100000];

void prod(int x, int y) {
	if(has[y]) {
		bool flag = true;
		if(has[x] && (mi[x] - mi[y]) % 2 == 0) { flag = false; }
		setmax(mi[x], mi[y] - 1);
		setmin(ma[x], ma[y] + 1);
		has[x] = true;
		if(mi[x] > ma[x]) { flag = false; }
		if(! flag) {
			puts("No");
			exit(0);
		}
	}
}

bool dfs(int node, int pre) {
	if(pre != -1) { prod(node, pre); }
	for(auto && i : vec[node]) {
		if(i != pre) {
			dfs(i, node);
			prod(node, i);
		}
	}
}

int main() {
	reader(&n);
	inc(i, n - 1) {
		int a, b;
		reader(&a, &b);
		a--; b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	fill(mi, mi + n, -1000000);
	fill(ma, ma + n,  2000000);
	reader(&k);
	inc(j, k) {
		int v, p;
		reader(&v, &p);
		v--;
		mi[v] = p;
		ma[v] = p;
		has[v] = true;
	}
	
	dfs(0, -1);
	dfs(0, -1);
	
	puts("Yes");
	inc(i, n) { writerLn(mi[i]); }
	
	return 0;
}


Measured memory_bytes: 11904
local read = io.read

local n = read("n")
local h_t = {}
for i = 1, n do
	h_t[i] = read("n")
end

local count = 0
for i = 1, n do
	local l, r = i, i
	local h_l = h_t[l]
	while h_t[r + 1] and h_t[r + 1] >= h_t[l] do
		r = r + 1
	end
	local r_plus_1 = h_t[r + 1] or 0

	for j = l, r do
		h_t[j] = h_t[j] - (h_l - r_plus_1)
	end
	count = count + h_l - r_plus_1
end

print(count)


Measured memory_bytes: 2788
#include<stdio.h>
long long int arr[10000000];
void lucas()
{
    long long int i,j;
    arr[0]=2;
    arr[1]=1;
    for(i=2;i<=10000000;i++)
    {
        arr[i]=arr[i-2]+arr[i-1];
    }
}
int main()
{
    lucas();
    long long int i,j,k,l,m;
    while(scanf("%lld",&m)==1)
    {
        printf("%lld\n",arr[m]);
    }
    return 0;
}


Measured memory_bytes: 78336
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int x,y,a,b;
    cin>>x>>y>>a>>b;
    int dx=a-x,dy=b-y;
    cout<<string(dy,'U');
    cout<<string(dx,'R');
    cout<<string(dy,'D');
    cout<<string(dx,'L');
    cout<<'L'<<string(dy+1,'U');
    cout<<string(dx+1,'R');
    cout<<"DR"<<string(dy+1,'D');
    cout<<string(dx+1,'L')<<'U';




    return 0;
}


Measured memory_bytes: 3648
import java.util.*;

import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	Main(){
		new AOJ2161();
	}
	class AOJ2161{
		AOJ2161(){
			while(sc.hasNext()){
				N=sc.nextInt();
				M=sc.nextInt();
				if((N|M)==0)	break;
				solve();
			}
		}
		int N,M;
		class Edge implements Comparable<Edge>{
			int f,t;
			double w;
			Edge(int f,int t,double w){
				this.f=f;	this.t=t;	this.w=w;
			}
			@Override public int compareTo(Edge o){
				if(this.w<o.w)	return -1;
				if(this.w>o.w)	return 1;
				return 0;
			}
		}
		void solve(){
			int[] x=new int[N],y=new int[N],s=new int[N];
			for(int i=0; i<N; ++i){
				x[i]=sc.nextInt();
				y[i]=sc.nextInt();
				s[i]=sc.nextInt();
			}
			ArrayList<Edge> es=new ArrayList<Edge>(N*M);
			// 0~N-1, N~N+N-1
			for(int i=0; i<M; ++i){
				int xx=sc.nextInt(),yy=sc.nextInt();
				for(int j=0; j<N; ++j){
					int a=x[j]-xx, b=y[j]-yy;
					es.add(new Edge(j, N+i, sqrt(a*a+b*b)/s[j]));
				}
			}
			Collections.sort(es);
			G=new ArrayList<ArrayList<Integer>>(N+M);
			for(int i=0; i<N+M; ++i)	G.add(new ArrayList<Integer>());
			double ans=0.0;
			for(Edge e:es){
				ans=e.w;
				G.get(e.f).add(e.t);
				G.get(e.t).add(e.f);
				int ret=bipartiteMatching(G, N+M);
//				System.out.println(ret+" "+ans);
				if(ret>=M)	break;
			}
			System.out.printf("%.8f\n", ans);
		}
		int[] match;
		boolean[] used;
		ArrayList<ArrayList<Integer>> G;
		int bipartiteMatching(ArrayList<ArrayList<Integer>> G,int V){
			this.G=G;
			match=new int[V];
			Arrays.fill(match, -1);
			used=new boolean[V];
			int ret=0;
			for(int v=0; v<V; ++v){
				if(match[v]<0){
					Arrays.fill(used, false);
					if(dfs(v))	++ret;
				}
			}
			return ret;
		}
		boolean dfs(int v){
			used[v]=true;
			for(int u: G.get(v)){
				int w=match[u];
				if(w<0 || !used[w] && dfs(w)){
					match[v]=u;
					match[u]=v;
					return true;
				}
			}
			return false;
		}
	}

}

Measured memory_bytes: 66348
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
int main()
{
	int n, m;
	cin >> n >> m;
	double limit = 1. / 4. / m, sum = 0;
	vecd v(n);
	rep(i, n){
		cin >> v[i];
		sum += v[i];
	}
	limit *= sum;
	sort(all(v),greater<double>());
	rep(i, m)
		if (v[i] < limit)
		{
			cout << "No" << endl;
			return 0;
		}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,mx,dis[110],dep[110],ans1,s[110];
long long ans2=0x3f3f3f3f3f3f3f3f;
vector<int>E[110];
void dfs(int v,int fa)
{
	dis[v]=1;
	int d=0;
	for(auto u:E[v])
	{
		if(u==fa)continue;
		dep[u]=dep[v]+1;
		dfs(u,v);++d;
		mx=max(mx,dis[v]+dis[u]);
		dis[v]=max(dis[v],dis[u]+1);
	}
	s[dep[v]]=max(s[dep[v]],d);
}
void calc1(int x)
{
	memset(s,0,sizeof(s));
	dep[x]=1,dfs(x,0);
	if(dis[x]!=ans1)return ;
	long long res=1;
	for(int i=1;i<ans1;++i)res*=s[i];
	ans2=min(ans2,res);
}
void calc2(int x,int y)
{
	memset(s,0,sizeof(s));
	dep[x]=1,dfs(x,y),dep[y]=1,dfs(y,x);
	if(dis[x]>ans1||dis[y]>ans1)return ;
	long long res=1;
	for(int i=1;i<ans1;++i)res*=s[i];
	ans2=min(ans2,res*2);
}
int main()
{
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		E[x].push_back(y),E[y].push_back(x);
	}
	dfs(1,0);
	ans1=(mx+1)/2;
	printf("%d ",ans1);
	for(int i=1;i<=n;++i)
	{
		calc1(i);
		for(auto j:E[i])if(j>i)calc2(i,j);
	}
	printf("%lld",ans2);
	return 0;
}


Measured memory_bytes: 256