akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    string s, t; cin>>s>>t;
    int n = s.size(), m = t.size();
    
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(s[i] == t[j]){
                chmax(dp[i+1][j+1], dp[i][j] + 1);
            }
            else{
                chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
            }
        }
    }

    int len = dp[n][m];
    int y = n, x = m;
    string ans = "";
    while(len > 0){
        if(dp[y][x] == dp[y-1][x]){
            y--;
        }
        else if(dp[y][x] == dp[y][x-1]){
            x--;
        }
        else{
            y--, x--;
            len--;
            ans += s[y];
        }
    }

    reverse(all(ans));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
#include <stdio.h>
int main (){
int a,b,i;
scanf ("%d",&b);
  a=b;
for (i=0;i<10000000;i++){
  if(a==4){
break;
}
  if (a%2==0){
  a=a/2;
  }
  else{
    a=3*a+1;
  }

}
  if(b>2){
  printf ("%d",i+4);
  }
  else if (b==2){
   printf ("4");
  } 
  else if (b==1){
   printf ("4");
  } 
return 0;
}

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

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int Y,X;
	cin>>Y>>X;
	vector<string> s(Y);
	for(int i = 0; i < Y; i++){
		cin>>s[i];
	}

	vector<vector<int> > hol(Y,vector<int>(X,0)),var(X,vector<int>(Y,0));
	for(int i = 0; i < Y; i++){
		int cnt = 0;
		int pos = 0;
		for(int j = 0; j < X; j++){
			if(s[i][j]=='#'){
				hol[i][j] = 0;
				for(int k = pos; k < j; k++){
					hol[i][k] = cnt;
				}
				cnt = 0;
				pos=j+1;
			}else{
				cnt++;
				if(j==X-1){
					for(int k = pos; k < X; k++){
						hol[i][k] = cnt;
					}
				}
			}
		}
	}

	// for(int i = 0; i < Y; i++){
	// 	for(int j = 0; j < X; j++){
	// 		cout<<hol[i][j] + var[j][i]<<" ";
	// 	}printf("\n");
	// }

	for(int i = 0; i < X; i++){
		int cnt = 0;
		int pos = 0;
		for(int j = 0; j < Y; j++){
			if(s[j][i]=='#'){
				var[i][j]=0;
				for(int k = pos; k < j; k++){
					var[i][k] = cnt;
				}
				cnt=0;
				pos=j+1;
			}else{
				cnt++;
				if(j==Y-1){
					for(int k = pos; k < Y; k++){
						var[i][k] = cnt;
					}
				}
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < Y; i++){
		for(int j = 0; j < X; j++){
			int res = hol[i][j] + var[j][i]-1;
			ans = max(ans,res);
		}
	}

	cout<<ans<<endl;

	// for(int i = 0; i < Y; i++){
	// 	for(int j = 0; j < X; j++){
	// 		cout<<hol[i][j] + var[j][i]<<" ";
	// 	}printf("\n");
	// }

	return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int N = rei();
	int K = rei()-1;
	string S = res();
	for(int i=0;i<N;i++){
		if(i == K){
			if(S[i] == 'A'){
				cout << 'a';
			}
			if(S[i] == 'B'){
				cout << 'b';
			}
			if(S[i] == 'C'){
				cout << 'c';
			}
		}
		else{
			cout << S[i];
		}
	}
	cout << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
using System;

namespace abc155A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            if ((A == B && B != C) || (A == C && B != C) || (A != B && B == C))
            {
                Console.WriteLine("Yes");
            }
            else
                Console.WriteLine("No");
        }
    }
}


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

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var sn = n.ToString();
            var ans = sn.Contains("7") ? "Yes" : "No";
          //  var xyz = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27532
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll a;
    long double b;
    cin >> a >> b;
    long double ans = ((long double)a)*b;
    ll solve = (ll)ans;
    cout << solve << endl;
    return 0;
}




Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 3e2 + 10;

double memo[nax][nax][nax], n;
int sushi[4], x;

double dp(int a, int b, int c){
	if (a + b + c <= 0){
		return 0.0;
	}
	if (memo[a][b][c] > -1){
		return memo[a][b][c];
	}
	double koef = n / (a + b + c);
	double ret = 0;
	if (a != 0){
		ret += (dp(a - 1, b, c) + koef) * a / (a + b + c);
	}
	if (b != 0){
		ret += (dp(a + 1, b - 1, c) + koef) * b / (a + b + c);
	}
	if (c != 0){
		ret += (dp(a, b + 1, c - 1) + koef) * c / (a + b + c);
	}
	return memo[a][b][c] = ret;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

	cin >> n;
	for (ll i = 0; i < n; i++){
		cin >> x;
		sushi[x]++;
	}
	for (ll i = 0; i <= n; i++){
		for (ll j = 0; j <= n; j++){
			for (ll k = 0; k <= n; k++){
				memo[i][j][k] = -1;
			}
		}
	}
	double save = dp(sushi[1], sushi[2], sushi[3]);
	cout << fixed << setprecision(10) << save << '\n';
}
  

Measured memory_bytes: 227584
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  else:
    dfs(i+1, f+"-"+s[i+1], sum-int(s[i+1]))
    dfs(i+1, f+"+"+s[i+1], sum+int(s[i+1]))
    
s = input()
dfs(0, s[0], int(s[0]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

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

  vector<int> a(n);
  int tmp;
  r(i,n){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int ans=0;
  int i=0,j=0;
  while(i<n){
    int cc=a[i],f=0;
    while( a[i]==cc){
      f++;i++;
    }
    ans+=f%2;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

priority_queue<LP> qr;
priority_queue<LP,vector<LP>,greater<LP> >  ql;
ll N;
ll L[100000],R[100000];
ll used[100000];
ll ans = 0;

ll calc(ll b){
  ll res = 0;
  ll pos = 0;
  rep(i,N) used[i]=0;
  while(!ql.empty()) ql.pop();
  while(!qr.empty()) qr.pop();
  rep(i,N){
    ql.push(LP(R[i],i));
    qr.push(LP(L[i],i));
  }
  rep(i,N){

    LP p;
    if(b==1){
        while(1){
          p = ql.top();
          ql.pop();
          if(!used[p.sc]){
            used[p.sc]=1;
            break;
          }
        }
        if(R[p.sc] < pos){
          res += abs(R[p.sc] - pos);
          pos = R[p.sc];
        }
        else if(pos <= L[p.sc]){
          res += abs(L[p.sc] - pos );
          pos = L[p.sc];
        }
        b = 0;
    }
    else{
      while(1){
        p = qr.top();
        qr.pop();
        if(!used[p.sc]){
          used[p.sc]=1;
          break;
        }
      }
      if(L[p.sc] > pos){
        res += abs(L[p.sc] - pos);
        pos = L[p.sc];
      }
      else if(pos >= R[p.sc]){
        res += abs(R[p.sc] - pos );
        pos = R[p.sc];
      }
      b = 1;
    }
  }
  return res + abs(pos);
}

int main()
{
  cin>>N;
  rep(i,N) cin>>L[i]>>R[i];
  cout<<max(calc(0),calc(1))<<endl;
}


Measured memory_bytes: 5988
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 2e5 + 33, mod = 1e9 + 7;
int n, m, d[maxn], col[maxn];
vector<vi> g;
vector<pi> e;
queue<int> q;
map<pi, int> cost;
pi minmax(pi a) {
	if(a.second<a.first) swap(a.second, a.first);
	return a;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	g.resize(n+1);
	for(int f, t, i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].pb(t);
		g[t].pb(f);
		e.pb({f, t});
		if(d[f]==d[t]&&(!col[f]||!col[t])) {
			if(!col[f])
				q.push(f);
			if(!col[t])
				q.push(t);
			if(col[t])
				col[f]=col[t]^3;
			else if(col[f])
				col[t]=col[f]^3;
			else
				col[t] = 1, col[f] = 2;
			cost[minmax({f, t})] = d[f];
		}
	}
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(auto i : g[u]) {
			if(col[i]||d[i]<d[u]) continue;
			col[i] = col[u];
			cost[minmax({u, i})] = d[i]-d[u];
			q.push(i);
		}
	}
	for(int i = 1; i <= n; i++) if(!col[i]) return cout << -1, 0;
	for(int i = 1; i <= n; i++) cout << ("BW"[col[i]-1]);
	cout << '\n';
	for(auto i : e) {
		if(!cost.count(minmax(i))) cout << "1000000000\n";
		else cout << cost[minmax(i)] << '\n';
	}
}



Measured memory_bytes: 20716
import java.util.Scanner

object Main{
    def main(args:Array[String]):Unit = {
        val scan = new Scanner(System.in)
        val max = scan.nextInt()
        var res = Array[String]()
        for(i <- 1 to max){
            var a = scan.nextInt()
            var b = scan.nextInt()
            var c = scan.nextInt()
            if(Math.pow(a,2)+Math.pow(b,2) == Math.pow(c,2) ||
               Math.pow(c,2)+Math.pow(a,2) == Math.pow(b,2) ||
               Math.pow(c,2)+Math.pow(b,2) == Math.pow(a,2)
              )
              res :+= "YES"
            else
              res :+= "NO"
        }
        res.foreach(println _)
    }
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var sunukeeat = int.Parse(Console.ReadLine());

            var cashback = sunukeeat / 15 * 200;

            Console.WriteLine(sunukeeat * 800 - cashback);
        }
    }
}


Measured memory_bytes: 11092
import java.io.IOException;
import java.util.Scanner;


public class Main {

	
	
	public static void main(String args[]) throws NumberFormatException, IOException{
		//??°?????\???(????????????????????????)???next()??????????????§??????????????????nextInt??§??????Int??????
		/*
		Scanner in = new Scanner(System.in);
		int inputA=in.nextInt();
		int inputB=in.nextInt();
		
		System.out.println(inputA*inputB+" "+(inputA+inputB)*2);
		*/
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		
		ChangeTime(a);
	}
	public static  void ChangeTime(int Input_seconds){
		int hours=Input_seconds/3600;
		int minutes=(Input_seconds-3600*hours)/60;
		int seconds=Input_seconds-3600*hours-60*minutes;
		
		System.out.println(hours+":"+minutes+":"+seconds);
	}
	
}

Measured memory_bytes: 26184
#include <bits/stdc++.h>
        using namespace std;
         
     int main() {
          int N ;
          cin >> N; 
          int total =0;
          int answer =0; 
          int alice =0; 
       
      	  vector<int> math(N);
            for (int i = 0; i < N; i++) {
        		cin >> math.at(i);
                total = total + math.at(i);
      	    }
     sort( math.begin(), math.end() );
     reverse(math.begin(), math.end());
     for (int i = 0; i < N; i = i+2 ) {
                alice = alice + math.at(i);
      	    }  
     cout << 2* alice - total << endl; 
     }

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	for (ll& x: a) cin >> x;
	ll res = 0;
	for (int i = 1; i < n; ++i) {
		if (a[i] < a[i-1]) {
			res += a[i-1]-a[i];
			a[i] = a[i-1];
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 4740
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	ll N;
	cin >> N;

	vector<int> cnt(N+1,1);
	cnt[0] = 0;
	for (ll i = 2; i <= N; i++) {
		for (ll j = 1; j *i<= N; j++) {
			cnt[j * i]++;
		}
	}

	ll ans = 0;
	for (ll k = 1; k <= N; k++) {
		ans += k * cnt[k];
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> B(N);
  for(int i = 0; i < N; ++i){
    int a;
    cin >> a;
    --a;
    ++B[a];
  }
  sort(B.begin(), B.end());
  for(auto b : B) cerr << b << " ";
  cerr << endl;
  priority_queue<int> pq;
  for(int i = 0; i < N; ++i)
    pq.push(-B[i]);
  vector<int> ans(N);
  for(int i = N-1; i >= 0; --i){
    ans[i] = -pq.top();
    // cerr << i << " " << -pq.top() << endl;
    if(!i) break;
    int t = -pq.top();
    pq.pop();
    while(t){
      int k = pq.top();
      pq.pop();
      --k, --t;
      pq.push(k);
    }
  }
  for(int i = 0; i < N; ++i)
    cout << ans[i] << endl;
}


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

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

  vector<int> dp(N);
  dp[0] = 0;
  dp[1] = max(h[1] - h[0],h[0] - h[1]);

  for(int i = 2;i < N;i++){
    int abs_1 = max(h[i] - h[i-1],h[i-1] - h[i]);
    int abs_2 = max(h[i] - h[i-2],h[i-2] - h[i]);

    dp[i] = min(dp[i-1]+abs_1,dp[i-2]+abs_2);
  }

  cout << dp[N-1] << endl;
}


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

int a,b;
int main(){
  cin >> a >> b;
  if (a<=5){
    cout << 0;
  }
  else if(a<13){
    cout << b/2;
  }
  else{
    cout << b;
  }
  return 0;
}

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

const int N = 1e5 + 10; 

int q[N] , a[N]; //用数组hash

int main(){
	
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i ++) cin >> a[i];
	
	for(int i = 0 ; i < n ; i ++)
		q[a[i] - 1]++ , q[a[i]]++ , q[a[i] + 1]++; // 记录三种操作数出现的次数
	
	int maxn = 0;
	for(int i = 1 ; i < N ; i ++) maxn = max(maxn , q[i]); // 求最大
	
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 4344
// In the name of god
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
long long int n,a[maxn],b[maxn],c[maxn],dp1[maxn],dp2[maxn],dp3[maxn],x,y,z;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y>>z;
		if(i==0){
			dp1[i]=x;
			dp2[i]=y;
			dp3[i]=z;
		}
		else{
			dp1[i]=max(dp2[i-1],dp3[i-1])+x;
			dp2[i]=max(dp1[i-1],dp3[i-1])+y;
			dp3[i]=max(dp1[i-1],dp2[i-1])+z;
		}
	}
	cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]));
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define IOS ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define deb(x) cout << #x << " " << x << endl;
#define fi(i,a,b) for(int i = a; i<b; i++)
#define fd(i,a,b) for(int i = a; i>=b; i--)
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define N 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
using namespace std;

//*************************************************************************************

void solve () {

    int n; cin>>n;
    cout<<(n*(n+1))/2<<endl;
}

int main(){

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    IOS;

    int t=1;
    while(t--){solve();}
    return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,Q;
int a[MAX],b[MAX],c[MAX];
#define lson (now<<1)
#define rson (now<<1|1)
int t[MAX<<2],mn[MAX<<2];
void pushup(int now){mn[now]=mn[lson]+mn[rson];}
void Build(int now,int l,int r)
{
	if(l==r){t[now]=c[l];mn[now]=c[l]==0;return;}
	int mid=(l+r)>>1;
	Build(lson,l,mid);Build(rson,mid+1,r);
	pushup(now);
}
void Modify(int now,int l,int r,int p,int w)
{
	if(l==r){t[now]+=w;mn[now]=t[now]==0;return;}
	int mid=(l+r)>>1;
	if(p<=mid)Modify(lson,l,mid,p,w);
	else Modify(rson,mid+1,r,p,w);
	pushup(now);
}
int main()
{
	n=read();Q=read();
	for(int i=1;i<=n;++i)b[a[i]=read()]++;
	for(int i=1;i<=n;++i)if(b[i])c[max(1,i-b[i]+1)]+=1,c[i+1]-=1;
	for(int i=1;i<=n;++i)c[i]+=c[i-1];
	Build(1,1,n);
	while(Q--)
	{
		int x=read(),v=read();
		b[a[x]]--;if(a[x]-b[a[x]]>0)Modify(1,1,n,a[x]-b[a[x]],-1);
		a[x]=v;
		if(a[x]-b[a[x]]>0)Modify(1,1,n,a[x]-b[a[x]],1);b[a[x]]++;
		printf("%d\n",mn[1]);
	}
	return 0;
}


Measured memory_bytes: 10112
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vii vector <int>::iterator 
#define vd vector <double>
#define vdd vector <double>::iterator
#define vs vector <string>
#define vss vector <string>::iterator
#define vc vector <char>
#define vcc vector <char>::iterator
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
#define SORT(x)     sort(x.begin(),x.end())
#define fill(x,y)   memset(x, y, sizeof(x))
#define PI 2*acos(0.0)
#define fio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main(){
   ll t;
   cin >> t;
   map <string , int> m;
   m["AC"] = 0;
   m["WA"] = 0;
   m["TLE"] = 0;
   m["RE"] = 0;
   while(t--){
       string s;
       cin >> s;
       if(m.count(s) == 0)
            m[s] = 1;
        else
            m[s]++;
   }
   /*map <string , int>:: iterator it;
   for(it= m.begin(); it!=m.end(); it++)
        cout << it->first << " x " << it->second << endl;*/
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.buffer.readline
import copy

def main():
    H,W,A,B = map(int,input().split())
    MOD = 10**9+7
    fac = [0 for _ in range(H+W+1)]
    fac[0],fac[1] = 1,1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    
    for i in range(2,H+W+1):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
        invfac[i] = (invfac[i-1]*inv[i])%MOD
        
    def coef(x,y):
        num = (((fac[x+y]*invfac[x])%MOD)*invfac[y]%MOD)
        return num

    ans = 0
    for i in range(H-A):
        able = coef(i,B-1)*coef(H-i-1,W-B-1)
        ans += able
        ans %= MOD
        
    print(ans)  

if __name__ == "__main__":
    main()


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

struct UnionFindTree{
    vector<int> v;
    vector<int> rank;
    UnionFindTree(int n){
        v = vector<int>(n);
        rank = vector<int>(n, 0);
        for(int i=0; i<n; i++) v[i]=i;
    }
    int Find(int x){
        if(v[x] != x){
            v[x] = Find(v[x]);
        }
        return v[x];
    }
    void Union(int a, int b){
        a = Find(a);
        b = Find(b);
        if(rank[a] < rank[b]){
            v[a] = b;
        }else{
            v[b] = a;
            if(rank[a] == rank[b]){
                rank[a]++;
            }
        }
    }
};

struct edge{
	int x,y,c;
	edge(int x, int y, int c):x(x),y(y),c(c){}
	edge(){}
	bool operator < (const edge &a) const{
		return c < a.c;
	}
};

bool isConnected(int n, vector<edge> &bridge, vector<bool> &canuse){
	UnionFindTree uft(n);
	for(int i=0; i<(int)bridge.size(); i++){
		if(canuse[bridge[i].x] && canuse[bridge[i].y]){
			uft.Union(bridge[i].x, bridge[i].y);
		}
	}
	
	int root = -1;
	for(int i=0; i<n; i++){
		if(canuse[i]){
			if(root!=-1 && root!=uft.Find(i)) return false;
			if(root==-1) root = uft.Find(i);
		}
	}
	return true;
}

int main(){
	while(1){
		int n,m;
		cin >> n >> m;
		if(n==0) break;
		
		vector<pair<int,int> > time(n);
		for(int i=0; i<n; i++){
			int h;
			cin >> h;
			time[i] = make_pair(h, i);
		}
		sort(time.begin(), time.end());
		reverse(time.begin(), time.end());
		
		vector<edge> bridge(m);
		for(int i=0; i<m; i++){
			int a,b,c;
			cin >> a >> b >> c;
			a--; b--;
			bridge[i] = edge(a,b,c);
		}
		sort(bridge.begin(), bridge.end());
		
		vector<bool> usable(n, false);
		int lasti = 0;
		for(int i=0; i<n; i++){
			usable[time[i].second] = true;
			while(i+1<n && time[i].first==time[i+1].first){
				i++;
				usable[time[i].second] = true;
			}
			if(!isConnected(n, bridge, usable)) lasti = i+1;
		}
		
		UnionFindTree uft(n);
		fill(usable.begin(), usable.end(), false);
		int ans=0;
		for(int i=0; i<lasti; i++){
			usable[time[i].second] = true;
		}
		for(int i=lasti; i<n; i++){
			usable[time[i].second] = true;
			while(i+1<n && time[i].first==time[i+1].first){
				i++;
				usable[time[i].second] = true;
			}
			for(int j=0; j<m; j++){
				edge e = bridge[j];
				if(usable[e.x] && usable[e.y] && uft.Find(e.x)!=uft.Find(e.y)){
					ans += e.c;
					uft.Union(e.x, e.y);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
// #define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int K; cin >> K;
  string S; cin >> S;
  if(S.size()>K) {
    S = S.substr(0,K) + "...";
  }
  cout << S << endl;
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool flip = true;
    deque<char> fr, ba;
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            flip = !flip;
        } else {
            int depan;
            cin >> depan;
            char c;
            cin >> c;
            if (depan == 1) {
                if (flip) fr.push_front(c);
                else ba.push_back(c);
            } else {
                if (flip) ba.push_back(c);
                else fr.push_front(c);
            }
        }
    }
    if (!flip) reverse(s.begin(), s.end());
    if (!flip) {
        swap(fr, ba);
    }
    while (sz(fr)) {
        if (flip) {
            cout << fr.front();
            fr.pop_front();
        } else {
            cout << fr.back();
            fr.pop_back();
        }
    }
    cout << s;
    while (sz(ba)) {
        if (flip) {
            cout << ba.front();
            ba.pop_front();
        } else {
            cout << ba.back();
            ba.pop_back();
        }
    }
    cout << '\n';
    return 0;
}

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

const int INF = 1 << 28;

int main(){
  bool boin[256] = {false};
  boin['a'] = boin['i'] = boin['u'] = boin['e'] = boin['o'] = true;
  for (;;) {
    int n;
    std::cin >> n;
    if (n == 0) {
      break;
    }
    std::vector<std::string> list;
    for (int i = 0; i < n; ++i) {
      std::string atom;
      std::cin >> atom;
      std::stringstream ss;
      bool flag = false;
      for (int j = 0; j < atom.length(); ++j) {
        if (j == 0 || flag) {
          ss << atom[j];
        }
        flag = boin[atom[j]];
      }
      list.push_back(ss.str());
    }
    int max = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (i == j) {
          break;
        }
        if (list[i] == list[j]) {
          max = INF;
          continue;
        }
        bool flag = false;
        for (int k = 0; k < std::min(list[i].length(), list[j].length()); ++k) {
          if (list[i][k] != list[j][k]) {
            max = std::max(max, k + 1);
            flag = true;
            break;
          }
        }
        if (!flag) {
          max = std::max(max, (int)std::min(list[i].length(), list[j].length()) + 1);
        }
      }
    }
    std::cout << (max == INF ? -1 : max) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3160
while True:
    x, y = map(int, raw_input().split())
    if x==0: break
    l = [[True for col in range(x)] for row in range(y)]
    ans = [[1 for col in range(x)] for row in range(y)]
    for i in range(input()):
        dx, dy = map(int, raw_input().split())
        l[dy-1][dx-1] = False
        if dy==1:
            for j in range(dx-1,x): ans[0][j] = 0
        if dx==1:
            for j in range(dy-1,y): ans[j][0] = 0
    for i in range(1,y):
        for j in range(1,x):
            if l[i][j]: ans[i][j] = ans[i-1][j] + ans[i][j-1]
            else : ans[i][j] = 0 
    print ans[y-1][x-1]

Measured memory_bytes: 6432
#include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll> 
#define loop(i,a,b) for(ll i=a; i<b; i++)
using namespace std;
#define MAXN 1000001
#define MOD 1000000007

void solve(){
    ll n,k;
    cin>>n>>k;
    vl a(n+1),l(n+1,-1);
    ll x=1,ans,ct;
    loop(i,1,n+1) cin>>a[i];
    loop(i,1,k+1){
        x=a[x];
        if(l[x]==-1){
            l[x]=i;
            if(i==k) ans=x;
        }
        else{
            ct=i-l[x];
            k-=i;
            k%=ct;
            loop(i,0,k) x=a[x];
            ans=x;
            break;
        }
    }
    cout<<ans;
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t=1;
    //int t;cin>>t;    
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6332
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ab = [LI() for _ in range(n)]
ab.sort(key=itemgetter(1))
time = 0
for a, b in ab:
    time += a
    if time > b:
        print('No')
        quit()
print('Yes')

Measured memory_bytes: 114112
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int cnt[10005][1500];

int main()
{
    int N,M;
    while(cin >> N >> M) {
        if(N == 0 && M == 0) break;
        
        int ptime[1005];
        memset(ptime,0,sizeof(ptime));

        int r;
        cin >> r;
        
        vector<pair<pair<int,int>,int> > v;
        rep(i,r) {
            int t,n,m,s;
            cin >> t >> n >> m >> s;

            if(s == 1) {
                ptime[n] = t;
            }
            else {
                pair<int,int> p = make_pair(ptime[n],t);
                v.push_back(make_pair(p,m));
            }
        }

        memset(cnt,0,sizeof(cnt));
        rep(i,v.size()) {
            int start = v[i].first.first;
            int end = v[i].first.second;
            int num = v[i].second;

            cnt[num][start]++;
            cnt[num][end+1]--;
        }

        rep(i,M+1) {
            REP(j,540,1500) {
                cnt[i][j+1] += cnt[i][j];
            }
        }

        vector<pair<pair<int,int>,int> > res;
        rep(i,M+1) {
            REP(j,540,1500) {
                if(cnt[i][j] > 0) {
                    int s = j;
                    while(cnt[i][j+1] > 0) {
                        j++;
                    }
                    
                    pair<int,int> p = make_pair(s,j);
                    res.push_back(make_pair(p,i));
                }
            }
        }


        int q;
        cin >> q;

        rep(i,q) {
            int s,t,m;
            cin >> s >> t >> m;
            
            int ans = 0;
            rep(j,res.size()) {
                int start = res[j].first.first;
                int end = res[j].first.second;
                int num = res[j].second;
                
                if(num != m) continue;

                if(end < s || t < start) continue;
                else if(start <= s && t <= end) {
                    ans += t - s;
                }
                else if(s < start && t <= end) {
                    ans += t - start;
                }
                else if(start <= s && end < t) {
                    ans += end - s;
                }
                else if(s < start && end < t) {
                    ans += end - start;
                }
            }
            cout << ans << endl;
        }
    }

    return 0;
}

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

int main(){
  string niti;
  cin >> niti;
  string YEAR=niti.substr(0,4);
  int year=stoi(YEAR);
  string MONTH=niti.substr(5,2);
  int month=stoi(MONTH);
  if(year>2019) cout << "TBD" <<endl;
  if(year==2019 && month >4) cout << "TBD" << endl;
  else if (year <=2019) cout << "Heisei" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    if (s[0] == 'S') cout << "Cloudy" << E;
    else if (s[0] == 'C') cout << "Rainy" << E;
    else if (s[0] == 'R') cout << "Sunny" << E;
    //system("pause");
    return 0;
}

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

long long n;
long double q,h,s,d;

int main() {
    cin >> q >> h >> s >> d >> n;
    h /= 2.00;
    s /= 4.00;
    d /= 8.00;
    long long x = (n/2LL)*2LL;
    long long ans = min(q*4LL*x,min(h*4LL*x,min(s*4LL*x,d*4LL*x)));
    if(n&1){
        ans += min(q*4LL,min(h*4LL,s*4LL));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    string s;
    cin>>s;
    int n=sz(s);
    
    vector<vector<ll>> dp(n+1,vector<ll>(13,0));
    dp[0][0]=1;
    
    rep(i,n){
        rep(d,13){
            if(s[i]=='?'){
                rep(j,10){
                    int now=j;
                    dp[i+1][(d*10+now)%13] += dp[i][d];
                    dp[i+1][(d*10+now)%13] %= MOD;
                }
            }
            else {
                int now=s[i]-'0';
                dp[i+1][(d*10+now)%13] += dp[i][d];
                dp[i+1][(d*10+now)%13] %= MOD;
            }
        }
    }
    
    cout<<dp[n][5]<<endl;
}


Measured memory_bytes: 13696
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
char mp[55][55];
int dist[55][55];
int main() {
	int h, w;
	cin >> h >> w;
	int sharpcount = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> mp[i][j];
			if (mp[i][j] == '#') {
				sharpcount++;
			}
			dist[i][j] = inf;
		}
	}
	dist[0][0] = 0;
	queue<P>que;
	que.push(make_pair(0, 0));
	while (!que.empty()) {
		int nowx = que.front().second;
		int nowy = que.front().first;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int newx = nowx + dx[i];
			int newy = nowy + dy[i];
			if (newx >= 0 && newx < w && newy >= 0 && newy < h && dist[newy][newx] == inf && mp[newy][newx] == '.') {
				dist[newy][newx] = dist[nowy][nowx] + 1;
				que.push(make_pair(newy, newx));
			}
		}
	}
	
	if (dist[h - 1][w - 1] != inf) {
		cout << h * w - (sharpcount + dist[h - 1][w - 1] + 1) << endl;
	}
	else {
		cout << "-1" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
def print_ans(S):
    """Test Case
    >>> print_ans("ASSA")
    Yes
    >>> print_ans("STOP")
    No
    >>> print_ans("FFEE")
    Yes
    """
    ans_arr = []
    ans_arr.append(S[0])


    for s_ch in S[1:]:
        for a_ch in ans_arr:
            if s_ch != a_ch:
                ans_arr.append(s_ch)
    if len(set(ans_arr)) == 2:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)




Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  	int n;
    cin >> n;
    int p[n];
    for(int i=0;i<n;i++){
      cin >> p[i];
    }

    int ans = 0;
    for(int i=1;i<n-1;i++){
      if((p[i]-p[i-1])*(p[i+1]-p[i])>0) ans++;
    }
    cout << ans <<endl;

    
  	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;
int main() {

	int n; cin >> n;
	vector<double> v;
	for (int i = 0; i < n; i++) { 
		int vv; cin >> vv;
		v.emplace_back(vv);
	}

	
	
	do {
		sort(v.begin(),v.end());

		double ave =  (v[0] + v[1]) / 2;
		v[1] = ave;
		v.erase(v.begin());

		//for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; }
		//cout << endl;

	} while (v.size() != 1);

	cout << v[0] << endl;


	return 0;
}


Measured memory_bytes: 256
num = int(input())
T = 0
H = 0
for i in range(num):
    line = list(map(str, input().split()))
    sorted_line = sorted(line)
    if line[0] == line[1]:
        T += 1
        H += 1
    elif line[0] == sorted_line[0]:
        H += 3
    elif line[0] == sorted_line[1]:
        T += 3
print(T,H)


Measured memory_bytes: 5596
N, X, Y = map(int, input().split())
# グラフの作成 数字が小さい方から大きい方への有向グラフ
g = [[i-1, i+1] for i in range(N)]
g[0].remove(-1)
g[N-1].remove(N)
g[X-1].append(Y-1)
g[Y-1].append(X-1)

ans_list = [0] * N
# 各頂点からの最短経路長を計算
for i in range(N):
    queue = g[i]
    seen = [False] * N
    length = 0
    while queue:
        length += 1
        add = []
        for qi in queue:
            if seen[qi] == False:
                if i < qi:
                    ans_list[length] += 1
                seen[qi] = True
                add += g[qi]
        queue = list(set(add))

# 答えの出力
for k in range(1, N):
    print(ans_list[k])


Measured memory_bytes: 49244
#include <stdio.h>
#include <stdlib.h>
int main(){
    int N;
    scanf("%d",&N);
    int *d;
    int i;
    d = malloc(sizeof(int)*N);
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    int count = 0;
    int data[101];
    for(i=1;i<=100;i++){
        data[i]  =0;
    }
    for(i=1;i<=100;i++){
        for(int j = 0;j<N;j++){
        if(i==d[j])data[i ]=1;
        }
    }
    for(i=0;i<=100;i++){
        count+=data[i];
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<tuple>
#include<algorithm>

using namespace std;

int main(){
    int r,d,x;

    cin >> r >> d >> x;

    for(int i=0; i<10; i++)
    {
        int cal = x*r-d;
        x = cal;
        cout << cal << endl;
    }
}

Measured memory_bytes: 256
/*
	ARIJIT SUR 
	@duke_knight
	@surcode
	IIT ISM 
 */
#include<bits/stdc++.h>
#define SIZE 100008
#define mod (ll)(1e9+7)
#define INF 0x3f3f3f3f
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(a) (a>0?a:-a)
#define all(a) a.begin(),a.end()
#define pb push_back
#define pi pair<int,int>
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a) {for(int i1=0;i1<a.size();i1++) cin>>a[i1];}
#define display(a) {for(int i1=0;i1<a.size();i1++) cout<<a[i1]<<" "; cout<<endl;}
#define check(i,j) (i>=0 && j>=0 && i<h && j<w)
#define val(i,j) (check(i,j)?dp[i][j]:0)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long ll;
void solve(){
	int h,w;
    cin>>h>>w;
    int dp[h][w], a[h][w];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) {
        char ch ;
        cin>>ch;
        a[i][j] = (ch=='.'?1:0);
    }
    dp[0][0] = 1;
    for(int i=0;i<h;i++){
        for (int j=0;j<w;j++)
        {
            if(a[i][j])
            dp[i][j] += (val(i-1,j) + val(i,j-1))%mod;
            else dp[i][j] = 0;  
        }
    }
    printf("%d\n",dp[h-1][w-1]);
}
int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    ll ans = 0;
    int right = 0;
    int sum = 0;
    rep(left, N) {
        while (right < N && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            ++right;
        }
        ans += right - left;

        sum -= a[left];
    }

    cout << ans << endl;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///

#include "bits/stdc++.h"

using namespace std;
struct Edge { int from; int to; int cost; };
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
struct Scc {
	int n;
	vector<vector<int>> g,
		rg;//??????????????°??????
	vector<int> cmp,//cmp[i]???i????±????????????£??????????????????
		visited, 
		num;//??°??????????????§???????????\???
	Scc(int N) {
		n = N;
		cmp.resize(n);
		visited.resize(n);
		g.resize(n);
		rg.resize(n);
	}
	void add_edge(int from, int to) {
		g[from].push_back(to);
		rg[to].push_back(from);
	}

	void dfs(int v) {
		visited[v] = true;
		for (int i = 0; i < g[v].size(); ++i) {
			if (!visited[g[v][i]])dfs(g[v][i]);
		}
		num.push_back(v);
	}

	void rdfs(int v, int k) {
		visited[v] = true;
		cmp[v] = k;
		for (int i = 0; i < rg[v].size(); ++i) {
			if (!visited[rg[v][i]])rdfs(rg[v][i], k);
		}
	}
	int calc() {
		for (int i = 0; i < n; ++i)visited[i] = false;
		num.clear();
		for (int i = 0; i < n; ++i) {
			if (!visited[i])dfs(i);
		}
		for (int i = 0; i < n; ++i)visited[i] = false;
		int k = 0;
		for (int i = num.size() - 1; i >= 0; --i) {
			if (!visited[num[i]]) {
				rdfs(num[i], k);
				++k;
			}
		}
		return k;
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	Scc scc(n);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		scc.add_edge(a, b);
	}
	scc.calc();
	int q;
	cin >> q;
	REP(i, q) {
		int a, b;
		cin >> a >> b;
		if (scc.cmp[a] == scc.cmp[b])cout << 1 << endl;
		else cout << 0 << endl;
	}


}

Measured memory_bytes: 4500
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <sstream>

using namespace std;

int l;

string exchange(const string s)
{
    stringstream s1, s2, ret;
    string tmp;
    int a, b;

    tmp = s;
    sort(tmp.begin(), tmp.end());
    s1 << tmp;
    reverse(tmp.begin(), tmp.end());
    s2 << tmp;
    
    s1 >> a;
    s2 >> b;
    a = b - a;
    ret << a;
    return ret.str();
    // int a, b;
    // string a_s, b_s;
    // stringstream s1, s2, ret;
    
    // a_s = b_s = s;
    
    // sort(a_s.begin(), a_s.end());
    // sort(b_s.begin(), b_s.end(), greater<char>());
    // s1 << a_s;
    // s2 << b_s;

    // s1 >> a;
    // s2 >> b;
    // a = b - a;
    // ret << a;

    // return ret.str();
}

int main()
{
    string s;

    while (cin >> s >> l, s != "0" || l) {
        map<string, int> m;

        while (s.size() < l)
            s = '0' + s;
        m[s] = 0;

        for (int i = 1; ; i++) {
            s = exchange(s);

            string tmp = s;
            while (tmp.size() < l)
                tmp = '0' + tmp;

            if (m.count(tmp) != 0) {
                cout << m[tmp] << " " << s << " " << i - m[tmp] << endl;
                break;
            }
            else
                m[tmp] = i;
            s = tmp;
        }
    }

    return 0;
}

Measured memory_bytes: 1264
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b;
    cin>>a>>b;
    cout<<(a<10&&b<10?a*b:-1)<<endl;
}

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

main() {
    int N,X; cin >> N >> X;
    int A[N]; int ma = 999999999; int sum=0;
    rep(i,N){
        cin >> A[i];
        sum+=A[i];
        ma=min(ma,A[i]);
    }
    cout << (X-sum)/ma+N << endl;
    return 0;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  long long ans=0;
  for(int i=k+1;i<=n;++i){
    ans+=i-k;
    if(k==0) --ans;
    ans+=(long long)(n-i+1)/i*(i-k)+max(0,(n-i+1)%i-k);
  }
  cout<<ans<<endl;
}
    


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int i = sc.nextInt();
		long sum = 0;

		//入力した数分繰り返す
		for (int j = 1; j <= i; j++) {

			//Jが3、5両方割りきれる
			if (j % 3 == 0 && j % 5 == 0) {
				continue;
			}
			//Jが3で割り切れる
			else if (j % 3 == 0) {
				continue;
			}
			//Jが5で割り切れる
			else if (j % 5 == 0) {
				continue;
			}
			//3でも5でも割り切れない
			else {

			}
			sum += j;

		}
		System.out.println(sum);

		sc.close();

	}

}


Measured memory_bytes: 35608