akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
char s[105];
int L, ans;
void check(int x) {
    int Left = x - 1, Right = x + 1;
    if((s[Left] == 'W' || s[Left] == '.' || Left == 0) && s[Right] == 'B') {
        for(int i = Left; i >= 1; i--)
            if(s[i] == '.')
                break;
            else if(s[i] == 'B')
                return ;
        int temp = 0;
        for(int i = Right; i <= L; i++)
            if(s[i] == 'B')
                temp++;
            else if(s[i] == '.')
                return ;
            else if(s[i] == 'W') {
                ans = max(ans, temp);
                return ;
            }
    }
    else if(s[Left] == 'B' && (s[Right] == 'W' || s[Right] == '.' || Right == L + 1)) {
        for(int i = Right; i <= L; i++)
            if(s[i] == '.')
                break;
            else if(s[i] == 'B')
                return ;
        int temp = 0;
        for(int i = Left; i >= 1; i--)
            if(s[i] == 'B')
                temp++;
            else if(s[i] == '.')
                return ;
            else if(s[i] == 'W') {
                ans = max(ans, temp);
                return ;
            }
    }
}
int main() {
    char k;
    cin >> L >> (s + 1);
    //cout << s + 1 << endl;
    for(int i = 1; i <= L; i++)
        if(s[i] == '.')
            check(i);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 

int main() {
  int n;
  rep(i,5){
    cin >> n;
    if(n == 0){
      cout << i+1 << endl;
      break;
    }
  }
}


Measured memory_bytes: 3592
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		//入力
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		//処理
		int ans = Math.max(a-b, Math.max(a+b, a*b));
		
		//出力
		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll num[50];
ll num2[50];
ll num3[50];
//ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<string,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
priority_queue<double> pq;


int main(void)
{
    double ans=0.0,d,d1,d2,sumd=0.0;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n>>m;
    n*500>=m?cout<<"Yes":cout<<"No";
    return 0;
}


Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let (mut a, b): (String, String) = parse_line().unwrap();
    a.push_str(&b);
    let x: f64 = a.parse().unwrap();
    let y = x.sqrt().round() as i64;
    if y.pow(2) == x as i64 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2512
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>

typedef long long ll;

using namespace std;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (A > B) {
    printf("0\n");
    return 0;
  }
  if (N == 1) {
    printf("%d\n", A == B);
  } else if (N == 2) {
    printf("1\n");
  } else {
    printf("%lld\n", (ll)(B - A) * (N - 2) + 1);
  }
}

Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
	int N, num[50], cnt = 0, i;
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &num[i]);
	for (i = 0; i < N; i++) if (num[i] - (i + 1) != 0) cnt += 1;
	if (cnt == 0 || cnt == 2) printf("YES\n"); else printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b;
  cin >> r >> g >> b ;
  int A = r*100 + g*10 + b;
  if(A % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

vec z_algorithm(string S)
{
    ll N = SZ(S);
    vec Z(N, 0);
    ll i = 1, j = 0, k;
    
    Z[0] = N;
    while(i < N) {
        while(i + j < N && S[j] == S[i+j]) ++j;
        Z[i] = j;

        if(j == 0) {
            ++i;
            continue;
        }

        k = 1;
        while(k < j && k + Z[k] < j) {
            Z[i+k] = Z[k];
            ++k;
        }

        i += k;
        j -= k;
    }

    return Z;
}

int main()
{
    ll N;
    string S;
    cin >> N;
    cin >> S;

    string T;
    vec Z;
    ll m = 0;
    REP(i,0,N) {
        T = S.substr(i);
        Z = z_algorithm(T);
        REP(j,1,SZ(Z)) {
            if(Z[j] <= j) m = MAX(m,Z[j]);
        }
    }
    PR(m);

    return 0;
}

/*

*/

Measured memory_bytes: 3676
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    int a,b;
    cin>>a>>b;
    vector<int> vec(b);
    int sum=0;
    rep(i,b){
        int k;
        cin>>k;
        sum+=k;
    }
    if(a>sum){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    
}



Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
Xb = input().rstrip()
p = Xb.count('1')
def popcount(x):
    return bin(x).count('1')
def calc(X):
    ans = 0
    while X!=0:
        X %= popcount(X)
        ans += 1
    return ans
Xp = 0
Xm = 0
tp = 1
tm = 1
b = 0
if p>1:
    flag = True
else:
    flag = False

for i in reversed(range(N)):
    if Xb[i]=='1':
        Xp += tp
        Xp %= (p+1)
        if flag:
            Xm += tm
            Xm %= (p-1)
    tp *= 2
    tp %= (p+1)
    if flag:
        tm *= 2
        tm %= (p-1)

for i in range(N):
    if Xb[i]=='1' and p==1:
        print(0)
        continue
    elif Xb[i]=='1':
        X = (Xm - pow(2,N-1-i,p-1)+p-1)%(p-1)
    else:
        X = (Xp + pow(2,N-1-i,p+1))%(p+1)
    print(calc(X)+1)








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

int H,W;
char F[555][555];
char R[555][555];
char B[555][555];
int main(){
  cin >> H >> W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> F[j][i];
      R[j][i] = F[j][i];
      B[j][i] = F[j][i];
    }
  }

  
  for(int i=0;i<H;i++){
    if( i & 1 )
      for(int j=0;j<W-1;j++)
	R[j][i] = '#';
    else
      for(int j=1;j<W;j++)
	B[j][i] = '#';
    R[0][i] = '#';
    B[W-1][i] = '#';
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cout << R[j][i];
    cout << endl;
  }
  cout << endl;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cout << B[j][i];
    cout << endl;
  }
    
}


Measured memory_bytes: 1536
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
	ll n;cin>>n;
	std::vector<ll> v(n);
	rep(i,n)cin>>v[i];
	std::vector<ll> res(n);
	res[0]=0;
	res[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++)
		res[i]=min(abs(v[i]-v[i-1])+res[i-1],abs(v[i]-v[i-2])+res[i-2]);
	cout<<res[n-1]<<endl;
	// for(auto e: res)
		// cout<<e<<" ";
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}


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

int Fget(long long a, long long b) {
  string A, B;
  A = to_string(a);
  B = to_string(b);

  return max(A.size(), B.size());
}

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

  int ans = 100;

  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, Fget(i, n / i));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

#N_bin = bin(N)[2:]

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

ans = num2alpha(N)
ans=ans.lower()
print(ans)

Measured memory_bytes: 61852
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    K = int(input())
    if K <= 10:
        print(K)
        exit()

    q = deque(range(1, 10))
    K -= 9
    while q:
        v = q.popleft()
        sv = v % 10
        for i in (-1, 0, 1):
            if 0 <= sv + i < 10:
                if K == 1:
                    print(v * 10 + sv + i)
                    exit()
                K -= 1
                q.append(v * 10 + sv + i)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6084
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<string> w(n);
  for(int i = 0; i < n; i++)
  {
    cin >> w[i];
  }
  for(int i = 1; i < n; i++)
  {
    for(int j = 0; j < i; j++)
    {
      if(w[j] == w[i])
      {
        cout << "No";
        return 0;
      }
    }
    if(w[i][0] != w[i - 1][w[i - 1].size() - 1])
    {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    cout << n / 3 << "\n";
    return 0;
}

Measured memory_bytes: 3600
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        Reader.ReadLine();

        Dictionary<int, double> data1 = new Dictionary<int, double>();
        Reader.ReadLine().Split(' ').Select(a => double.Parse(a)).ToList().ForEach(a => data1.Add(data1.Count, a));
        Dictionary<int, double> data2 = new Dictionary<int, double>();
        Reader.ReadLine().Split(' ').Select(a => double.Parse(a)).ToList().ForEach(a => data2.Add(data2.Count, a));

        double ans1 = data1.Select(a => Math.Abs(a.Value - data2[a.Key])).Sum();
        double ans2 = Math.Sqrt(data1.Select(a => Math.Pow(a.Value - data2[a.Key], 2)).Sum());
        double ans3 = Math.Pow(data1.Select(a => Math.Pow(Math.Abs(a.Value - data2[a.Key]), 3)).Sum(), 1 / 3d);
        double ans4 = data1.Select(a => Math.Abs(a.Value - data2[a.Key])).Max();

        Console.WriteLine(ans1);
        Console.WriteLine(ans2);
        Console.WriteLine(ans3);
        Console.WriteLine(ans4);


    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"





3
1 2 3
2 0 4




";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 10476
n = int(input())
a = [int(input()) for _ in range(n)]

max_v1 = max(a)
max_i1 = a.index(max_v1)
a.remove(max_v1)
max_v2 = max(a)

for i in range(n):
    if i == max_i1:
        print(max_v2)
    else:
        print(max_v1)


Measured memory_bytes: 12520
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;
int inf = 2e9, mod = 1e9 + 7;

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n, m; cin >> n >> m;
    int val = 0;
    for(int i=0, cur, last;i<n;i++){
        cin >> cur;
        if(i) val = (val + i * (n - i) % mod * (cur - last) % mod ) % mod;
        last = cur;
    }
    int res = 0;
    for(int i=0, cur, last;i<m;i++){
        cin >> cur;
        if(i) res = (res + i * (m-i) % mod * (cur - last) % mod * val % mod) % mod;
        last = cur;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a;i < b;i++)
#define F first
#define S second
#define pb push_back
#define mk make_pair
#define debug(a) cerr << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
#define all(c) (c).begin(),(c).end()
typedef long long int ll;
typedef pair<ll,ll> ii;
const int INF = 0x3f3f3f3f;


int main(){
	ll a,b,c,d,x,y;
	while(cin >> a >> b >> c >> d){
		cout << max(max(a*c,a*d),max(b*d,b*c)) <<endl;
	}
 	return 0;
}

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

const int N = pow(10,5);

vector<bool> isp(N+1, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}

int main() {
  int x;
  cin >> x;
  int ans =0;


  // N以下の整数に対して素数判定をしてくれます。
  // nが素数ならば isp(n)=true、そうでなければ isp(n)=false
  sieve();
  
  for (int i=x; i<=100004; i++) 
  if (isp[i]){
     ans = i;
     break;
  }

  if(ans <= 99991){
    cout << ans << endl;
  }

  else{
    cout << 100003 << endl;
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
char ch[210000];
int a[210000],b[210000],bin[30],i,j,ans[210000],minn[68000000],n;
int main()
{
	scanf("%s",ch);
	n=strlen(ch);
	for (i=1;i<=n;i++)
	{
		a[i]=ch[i-1]-'a'+1;
	}
	bin[1]=1;
	for (i=2;i<=26;i++)  bin[i]=bin[i-1]<<1;
	for (i=1;i<=n;i++) b[i]=b[i-1]^bin[a[i]];
	memset(minn,0x7f,sizeof(minn));
	memset(ans,0x7f,sizeof(ans));
	minn[0]=0;
	for (i=1;i<=n;i++)
	{
		ans[i]=min(ans[i],minn[b[i]]+1);
		for (j=1;j<=26;j++)
		{
			ans[i]=min(ans[i],minn[b[i]^bin[j]]+1);
		}
		minn[b[i]]=min(minn[b[i]],ans[i]);
	}
	printf("%d\n",ans[n]);
	return 0;
}

Measured memory_bytes: 268672
#include<stdio.h>

int main()
{
  int i,sw=0,a[100],n,j,temp,flag=1;
  //enter
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
	scanf("%d",&a[i]);
      
    }

  while(flag){
    flag=0;
      for(j=n-1;j>=1;j--)
	{
	  if(a[j-1]>a[j])
	    {
	      temp=a[j];
	      a[j]=a[j-1];
	      a[j-1]=temp;
	      flag=1;
	      sw++;
	    }
       
	}
  }
    for(i=0;i<n;i++)
    {
      if(i>0)printf(" ");
      printf("%d",a[i]);
    }
    printf("\n");
  printf("%d\n",sw);

  return 0;
}





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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, k, a;
  cin >> n >> k;
  vector<ll> bin(n, 0);
  map<ll, ll> mp;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    a--;
    bin[a]++;
  }

  bin.erase(remove(ALL(bin), 0), bin.end());

  sort(ALL(bin));

  cout << accumulate(bin.begin(), bin.begin() + max(0, (int)bin.size() - k), 0LL);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4764
(r, c) = [int (i) for i in input().split()]

table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])

table.append([0 for _ in range(c + 1)])

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
    print(' '.join([str(column) for column in row]))

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

bool mymax(string a, string b){
	if(a.size() == b.size()){
		for(int i = 0; i < a.size(); ++i){
			if(a[i] - '0' == b[i] - '0') continue;
			return a[i] - '0' > b[i] - '0';
		}
	}else{
		return a.size() > b.size();
	}
	return false;
}

int main(void){
	int n, m;
	cin >> n >> m;
	vector<int> a(10, 0);
	int macchi[] = {0,2,5,5,4,5,6,3,7,6};
	for(int i = 0; i < m; ++i){
		int tmp;
		cin >> tmp;
		a[macchi[tmp]] = max(a[macchi[tmp]], tmp);
	}
	// for(int i = 2; i < 8; ++i){
	// 	cout << i << " : " << a[i] << endl;
	// }
	vector<string> dp(n+10,"");
	for(int i = 0; i < n; ++i){
		for(int j = 2; j < 8; ++j){
			if(a[j] == 0 || (dp[i] == "" && i !=0)) continue;
			string tmp = dp[i] + to_string(a[j]);
			if(mymax(tmp, dp[i+j])){
				dp[i+j] = tmp;
			}
		}
	}
	// for(int i = 0; i <= n; ++i){
	// 	cout << i << " " << dp[i] << endl;
	// }
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 32512
#include<stdio.h>

int a[1000000],b;

int binarysearch(int c){
  int d=0;
  int e=b;
  int f;

  while(d<e){
    f=(d+e)/2;
    if(c==a[f])return 1;
    if(c>a[f])d=f+1;
    else if(c<a[f])e=f;
  }
  return 0;
}

int main(){
  int d,c,i,k=0;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&d);
  for(i=0;i<d;i++){
    scanf("%d",&c);
    if(binarysearch(c))k=k+1;
  }
  printf("%d\n",k);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
typedef long long ll;

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef vector<vector<pair<int, int>>> GRA;

int i,j,N,K,x,y;
string c;
int m;
int A[4010][4010];
int B[2010][2010];

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

	REPI(0,N) {
		cin >> x >> y >> c;
		if (c[0] == 'W') y += K;
		x %= (2*K);
		y %= (2*K);
		//cout << "x=" << x << " y=" << y << endl;
		A[x][y]++;
		A[x+K][y+K]++;
		A[x+K][y]--;
		A[x][y+K]--;
		A[x+K][y+K]++;
		A[x+K+K][y+K+K]++;
		A[x+K+K][y+K]--;
		A[x+K][y+K+K]--;
	}
#if 0
	for (j=4*K-1;j>=0;j--) {
		REPI(0,4*K) cout << A[i][j] << " ";
		cout << endl;
	}
	cout << endl;
#endif
	REPI(1,4*K) REPJ(0,4*K) A[i][j] += A[i-1][j];
#if 0
	for (j=4*K-1;j>=0;j--) {
		REPI(0,4*K) cout << A[i][j] << " ";
		cout << endl;
	}
	cout << endl;
#endif
	REPI(0,4*K) REPJ(1,4*K) A[i][j] += A[i][j-1];
#if 0
	for (j=4*K-1;j>=0;j--) {
		REPI(0,4*K) cout << A[i][j] << " ";
		cout << endl;
	}
#endif
	REPI(0,4*K) REPJ(0,4*K) B[i%(2*K)][j%(2*K)] += A[i][j];
#if 0
	for (j=2*K-1;j>=0;j--) {
		REPI(0,2*K) cout << B[i][j] << " ";
		cout << endl;
	}
#endif
	REPI(0,4*K) REPJ(0,4*K) m = MAX(m,B[i][j]);
	
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 78720
#include <cstdio>

int main(){
    int a, b;
    char op;
    while(true){
        scanf("%d %c %d", &a, &op, &b);
        if (op == '+'){
            printf("%d\n", a+b);
        }else if (op == '-'){
            printf("%d\n", a-b);
        }else if (op == '*'){
            printf("%d\n", a*b);
        }else if (op == '/'){
            printf("%d\n", a/b);
        }else{
            break;
        }
    }
    return 0;
}


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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
	int x = 0, fh = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	return x * fh;
}

void File() {
#ifdef zjp_shadow
	freopen ("connect.in", "r", stdin);
	freopen ("connect.out", "w", stdout);
#endif
}

const int N = 16;

int n, m, sumw;
int dp[N][1 << N], sum[1 << N], G[N][N], num[1 << N];

#define lowbit(x) (x & -x)

#define Get(i, v, k) for(register int sta = k, v = __builtin_ctz(sta), i; i = 1 << v, sta; v = __builtin_ctz(sta ^= i))

int main () {

	File(); Set(dp, 0);

	n = read(); m = read();

	For (i, 0, n - 1) num[1 << i] = i;
	For (i, 1, m) {
		int u = read() - 1, v = read() - 1, w = read(); 
		G[u][v] = G[v][u] = w; sumw += w;
	}

	int maxsta = (1 << n) - 1;
	For (i, 1, maxsta) {
		int u = __builtin_ctz(i);
		sum[i] = sum[i ^ (1 << u)];
		Get(j, v, i) sum[i] += G[u][v];
	}

	Set(dp, -0x3f);
	for (int i = 1; i <= maxsta; i += 2) {
		dp[0][i] = sum[i];
		For (S, 0, n - 1) if (dp[S][i] >= 0) {
			int rest = maxsta ^ i;
			for (register int sub =	rest; sub; (-- sub) &= rest)
				chkmax(dp[S][i | sub], dp[S][i] + sum[sub ^ (1 << S)]);
			Get(j, v, rest) if (G[S][v])
				chkmax(dp[v][i | j], dp[S][i] + G[S][v]);
		}
	}

	printf ("%d\n", sumw - dp[n - 1][maxsta]);

	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

signed main() {
  init();
  ll N, A, B;
  cin >> N >> A >> B;
  vll P(N);
  cin >> P;

  ll count1 = 0;
  ll count2 = 0;
  ll count3 = 0;

  rep(i, N) {
    if (P[i] <= A)
      count1++;
    else if (A < P[i] and P[i] <= B)
      count2++;
    else
      count3++;
  }

  ll ans = min({count1, count2, count3});
  ANS;

  return 0;
}

Measured memory_bytes: 3668
import math
import itertools

n = int(input())
t = [list(map(int, input().split())) for i in range(n)]
ans = 0

for v in itertools.permutations(t, n):
    for i in range(len(v)-1):
        x = (v[i+1][0]-v[i][0])**2
        y = (v[i+1][1]-v[i][1])**2
        ans += math.sqrt(x + y)

print(ans/math.factorial(n))

Measured memory_bytes: 3064
/// However long the night,
///     The dawn will break
/// ICPC next year

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

typedef unsigned long long ll ;
typedef vector<ll> vll ;
typedef vector<vll> vvll ;

#define Sz(matrix ,n ,m) matrix.assign(n, vll(m));

const int N = 1e5+5 ;
ll l ,a ,b ,mod ;

vvll matrixMult(vvll matA, vvll matB) {
	vvll ret(matA.size(), vll(matB[0].size()));
	for (int i = 0; i < ret.size(); i++)
		for (int j = 0; j < ret[0].size(); j++)
			for (int k = 0; k < matA[0].size(); k++) {
				ret[i][j] += (matA[i][k] * matB[k][j]) % mod;
				ret[i][j] = (ret[i][j]%mod+mod)%mod;
			}
	return ret;
}
vvll matrixPower(vvll mat, long long p) {
	if (p == 1) return mat;
	if (p % 2 == 1)
		return matrixMult(mat, matrixPower(mat, p - 1));
	vvll cur = matrixPower(mat, p / 2);
	return matrixMult(cur, cur);
}


int main(){
    cin >> l >> a >> b >> mod ;

    long long ans = 0 ,cur = a ;
    for(long long L=1;l;L*=10){
        if(L*10<=cur) continue ;

        vvll base ,multi ;
        Sz(base ,3,3);
        Sz(multi ,3,3);

        base[0][0] = ans ;
        base[0][1] = cur%mod ;
        base[0][2] = b%mod ;

        multi[0][0] = L%mod*10%mod ;
        multi[1][0] = multi[1][1] = multi[2][1] = multi[2][2] = 1 ;

        ll s = cur ,en = L*10-1 ;
        ll x = (en-s)/b ;
        en = cur + x*b ;

        ll cnt = (en-s)/b+1 ;
        cnt = min(cnt ,l);

        vvll ansMat = matrixMult(base ,matrixPower(multi ,cnt)) ;
        ans = ansMat[0][0] ;
        l -= cnt ;
        cur = en + b ;
    }
    cout << ans ;
    return 0;
}
/***

 Base
 (ans ,cur ,b)

 (ans ,cur ,b) -> (ans*L+cur ,cur+b ,b)


 Multi
 L 0 0
 1 1 0
 0 1 1



**/


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

int main(){
  int a,b;
  int t,h,k;
  cin >> a >> b;
  t = a+b;
  h = a-b;
  k = a*b;
  vector<int> vec;
  vec = {t,h,k};
  sort(vec.begin(),vec.end());

  cout << vec.at(2) << endl;
  return 0;
}

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

using namespace std;

int main() {
  char b;
  
  cin >> b;
  
  if (b == 'A') { cout << 'T' << endl; }
  if (b == 'T') { cout << 'A' << endl; }
  if (b == 'C') { cout << 'G' << endl; }
  if (b == 'G') { cout << 'C' << endl; }
  
  return 0;
}

Measured memory_bytes: 256
//#include<iostream>
#include<stdio.h>
//using namespace std;
int main(){
  double a,b,c,d,e,f,x,y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
  y=(c*d-f*a)/(b*d-e*a);
  x=(c-b*y)/a;
  if(x==-0)x=0;
  if(y==-0)y=0;
  printf("%.3f %.3f\n",x,y);
  } 
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end(),greater<int>());

    int min_diff = INF;
    rep(i,n-k+1)
    {
        int tmp_diff = h[i] - h[i+k-1];
        if(i==0 || tmp_diff < min_diff)
            min_diff = tmp_diff;
    }

    cout << min_diff << endl;

    return 0;
}

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

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


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;

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

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


int main(){
    int n; cin >> n;
    FORS(i, 1, 50000){
        int x = i * 1.08;
        if(n == x){
            cout << i << "\n";
            return 0;
        }
        if(n < x) break;
    }
    cout << ":(\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int w[100005];
int main()
{
    int n,a,b,num=0;
    cin>>n;
    while (n--)
    {
        cin>>a>>b;
        for (int i=a;i<=b;i++)
        {
            if (w[i]==0)
            {
               num++;
               w[i]=1;
            }

        }
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
ans=[A[0]]

def gcd(a,b):
    while b>=1:
        a,b=b,a%b
    return a

i=1
while i<=N-1:
    ans.append(gcd(A[i],ans[-1]))
    i+=1

print(ans[-1])

Measured memory_bytes: 14252
def main():
    N, *AB = map(int, open(0).read().split())
    ans = 0
    for i in range(N):
        index = N - 1 - i
        a = AB[index * 2 + 0] + ans
        b = AB[index * 2 + 1]
        remainder = a % b
        ans += (b - remainder) % b
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 25124
while True:
    H, W =map(int,input().split())
    
    if(H == W == 0):
        break
    
    for i in range(H):
        for j in range(W):
            if((i + j) % 2 == 0):
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()    


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

int main() {
    int n, score;
    string name;
    cin >> n;
    vector<tuple<string, int, int>> restaurant(n);
    for (int i = 0; i < n; ++i) {
        cin >> name >> score;
        get<0>(restaurant.at(i)) = name;
        get<1>(restaurant.at(i)) = score * -1;
        get<2>(restaurant.at(i)) = i + 1;
    }
    sort(restaurant.begin(), restaurant.end());
    for (int j = 0; j < n; ++j) cout << get<2>(restaurant.at(j)) << endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 998244353;
const int N = 1e5+23;

int h[N];

long long binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

void solve() {
  int n; scanf("%d", &n);
  for (int d, i = 0; i < n; ++i) {
    scanf("%d", &d);
    if (!i && d) {
      puts("0");
      return;
    }
    ++h[d];
  }
  if (h[0] > 1) {
    puts("0");
    return;
  }
  long long ans = 1;
  for (int i = 0; i < n-1; ++i) {
    if (!h[i] && h[i+1]) {
      puts("0");
      return;
    }
    (ans *= binpow(h[i], h[i+1])) %= mod;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	decltype(d)::iterator result= unique(d.begin(), d.end());
	d.erase(result, d.end());

	cout << d.size() << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int arr[10]={111,222,333,444,555,666,777,888,999};
int main()
{
	int n,ans;
	while(~scanf("%d",&n))
	{
		for(int i=0;i<9;++i)
		{
			if(arr[i]>=n)
			{
				ans=arr[i];
				break;
			 } 
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1010,T=1000,P=998244353;
int n,A,B,ans,a,b,iv[N],fc[N],vf[N],p[N],f[N][N];
int main(){
	scanf("%d",&n);
	iv[1]=fc[0]=vf[0]=p[0]=f[0][0]=1;
	FOR(i,2,T) iv[i]=1ll*iv[P%i]*(P-P/i)%P;
	FOR(i,1,T) fc[i]=1ll*fc[i-1]*i%P,vf[i]=1ll*vf[i-1]*iv[i]%P;
	FOR(x,1,n){
		scanf("%d%d",&a,&b);
		(A+=a)%=P,(B+=b)%=P;
		FOR(i,1,B) p[i]=1ll*p[i-1]*a%P;
		ROF(i,A,a)ROF(j,B,0)FOR(k,0,min(j,b-1)) 
			(f[i][j]+=P-1ll*f[i-a][j-k]*vf[k]%P*p[k]%P)%=P;
	}
	FOR(i,1,A){
		FOR(j,1,B+1) p[j]=1ll*p[j-1]*iv[i]%P;
		FOR(j,0,B) (ans+=1ll*fc[j]*p[j+1]%P*f[i][j]%P)%=P;
	}
	cout<<(P-1ll*ans*A%P)%P<<'\n';
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
	int N,M;
	cin>>N>>M;
	vector<int> veca(M);
	vector<int> vecb(M);
	vector<int> vecc(N);
	for(int i=0; i<M; i++){
		cin>>veca[i]>>vecb[i];
	}
	
	for(int i=0; i<M; i++){
	    int u;
	    int l;
	    u=veca.at(i)-1;
	    l=vecb.at(i)-1;
	    vecc.at(u)++;
		vecc.at(l)++;
	}
	
	for(int i=0; i<N; i++){
		cout<<vecc.at(i)<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

vector <pair<int, long long> > edges[100000];
bool used[100000];
long long cost_from_start[100000];
long long dfs_max;
long long dfs_min;

bool dfs(int cur, long long cost){
    used[cur] = true;
    cost_from_start[cur] = cost;
    dfs_max = max(dfs_max, cost);
    dfs_min = min(dfs_min, cost);
    for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i].first;
        long long d = edges[cur][i].second;
        if(used[next]){
            if(cost_from_start[next] != cost_from_start[cur] + d){
                return false;
            }
        } else {
            if(!dfs(next, cost + d)){
                return false;
            }
        }
    }
    return true;
}

int main(){
    int N;
    int M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int L;
        int R;
        long long D;
        cin >> L >> R >> D;
        edges[L - 1].push_back(make_pair(R - 1, D));
        edges[R - 1].push_back(make_pair(L - 1, - D));
    }

    for(int i = 0; i < N; i++){
        if(used[i]){
            continue;
        }
        dfs_max = LLONG_MIN;
        dfs_min = LLONG_MAX;
        if(!dfs(i, 0)){
            cout << "No" << endl;
            return 0;
        }
        if(dfs_max - dfs_min > 1000000000){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    
    cout << endl;
    return 0;
}


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

#define int long long

int dp[1002][1002];
const int mod=1e9+7;

int32_t main()
{
  int H,W;

  cin>>H>>W;

  char a[H+2][W+2];
  dp[1][1]=1;
  for(int i=1;i<=H;i++)
  {
    for(int j=1;j<=W;j++)
    {
      cin>>a[i][j];
    }
  }
 
  for(int i=1;i<=H;i++)
  {
    for(int j=1;j<=W;j++)
    {
     if(a[i][j]=='.')
      dp[i][j]=(dp[i][j]+(dp[i-1][j]+dp[i][j-1])%mod);
    }
  }
  
  cout<<dp[H][W];

  return 0;  
}   

Measured memory_bytes: 9088
#include "bits/stdc++.h"
using namespace std;

int main() {
	int A, B, C, X, Y, ans = 1000000000;
	cin >> A >> B >> C >> X >> Y;
	for (int i = 0; i <= max(X, Y); i++) {
		int Z = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i);
		ans = min(ans, Z);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,ii> iii;
typedef pair<int, iii> iiii;
typedef pair<double, ii> dii;
typedef long long ll;
typedef pair<ll, ii> lii;
const int INF = 1000000000;
const double EPS = 1e-9;
#define LSOne(S) (S & (-S))
int mods(int a, int b) { return (b + (a%b)) % b; }

int n, h[100005], dp[100005]; 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> h[i];

    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));

    cout << dp[n-1] << '\n';

 
    return 0;
}

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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll res = 0;
    ll prev = a[0];
    rep1(i, n){
        if(a[i] < prev){
            res += prev-a[i];
        }
        else prev = a[i];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4776
from itertools import combinations
def main():
    h,w,k = tuple([int(t)for t in input().split()])

    a = [list(input()) for _ in [0]*h]

    ans = 0
    for i in range(h+1):
        for rcom in combinations(range(h),i):
            for j in range(w+1):
                for ccom in combinations(range(w),j):
                    s = 0
                    for x in range(h*w):
                        if x//w in rcom or x%w in ccom:
                            continue
                        if a[x//w][x%w] == '#':
                            s += 1
                    if s==k:
                        ans +=1
                

    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9148
def main():
    N = int(input())
    if N % 2 == 1:
        print(0)
        exit()

    N //= 2
    ans = 0
    for i in range(1,100):
        tmp = N // (5 ** i)
        ans += tmp

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
//
// Created by Hideaki Imamura on 2020-03-14.
//
# include <bits/stdc++.h>

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll a, b, c;

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.print(a/b +" "+ a%b +" "+ String.format("%.8f", 1.0*a/b));
        System.out.println();
    }
}


Measured memory_bytes: 26416
use std::io;
use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
fn mypow(n:i64, mut x:i64, n_mod : i64)->i64{
    // n**x
    let mut temp = n;
    let mut result = 1;

    while x != 0{
        if x & 1 != 0{
            result *= temp;
            result %= n_mod;
        }
        x /= 2;
        temp *= temp;
        temp %= n_mod;
    }

    result
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;
#[allow(dead_code)]
const N_PRIME : i64 = 1000000007;

////////////////////////////////////////////////

fn f(xs:&Vec<i64>)->(HashMap<i64, usize>, usize){
    let mut r = HashMap::new();
    let mut max_v = 0;

    for x in xs.iter(){
        if r.contains_key(x){
            let v = r[x];
            r.insert(*x, v+1);
        }else{
            r.insert(*x, 1);
        }
        max_v = cmp::max(max_v, *x as usize);
    }

    (r, max_v)
}

const N_DIV : i64 = 998244353;

fn abort(){
    println!("0");
    std::process::exit(0);
}

fn main(){
    let n = read_int();
    let xs = read_ints();

    if xs[0] != 0{
        abort();
    }

    let (hm, m )= f(&xs);

    if hm[&0] != 1{
        abort();
    }

    let mut n = 1;
    for i in 1..m+1{
        if hm.contains_key(&(i as i64)) == false{
            abort();
        }

        let last_n = hm[&((i - 1)as i64)];
        let now_n = hm[&(i as i64)];

        n *= mypow(last_n as i64, now_n as i64, N_DIV);
        n %= N_DIV;
    }
    println!("{}",n);
}

Measured memory_bytes: 12188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int k,s;
    cin>>k>>s;

    int ans=0;
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            int z=s-(x+y);
            if(0<=z && z<=k) ans++;
        }
    }

    cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  ll ans = 0;
  cin >> n;
  vector<int> a(n),b(n);
  priority_queue<P> que;

  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n; i++) {
    cin >> b[i];
    if(a[i] != b[i]) que.push(P(b[i],i));
  }

  while(!que.empty()){
    int v,m,l,r,s,k;
    tie(v,m) = que.top();
    que.pop();
    l = (m-1+n) % n; r = (m+1) % n;
    s = b[l]+b[r];
    k = (b[m]-a[m])/s;

    if(b[m] <= s) continue;
    
    b[m] -= k*s;
    if(b[m] > a[m] && k != 0) que.push(P(b[m],m));
    ans += k;
  }

  for(int i=0; i<n; i++){
    if(a[i] != b[i]){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    string s,t;
    cin >> s >> t;
    map<char,char>A;
    map<char,char>B;
    int f=1;

    REP(i,s.size()){
        if('a'<=A[s[i]] && A[s[i]]<='z' && A[s[i]]!=t[i] || 'a'<=B[t[i]] && B[t[i]]<='z' && B[t[i]]!=s[i])  f= 0;
        A[s[i]]=t[i]; B[t[i]]= s[i];
        // cout << f;
    }
    cout << ((f)?"Yes":"No") << endl;
}


Measured memory_bytes: 916