akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    while(1){
        int a[3];
        scanf("%d %d %d",a,a+1,a+2);
        if (a[0]==0&&a[1]==0&&a[2]==0) return 0;
        sort(a, a+3);
        short l=sqrt(a[0]*a[0]+a[1]*a[1]);
        int n;
        scanf("%d",&n);
        for (int i=0; i<n; i++) {
            int r;
            scanf("%d",&r);
            if (2*r<=l) printf("NA\n");
            else printf("OK\n");
        }
    }
}

Measured memory_bytes: 1028
import java.awt.Point;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static int n;
	static int[][] d;
	static Point[][] dp;
	
	private static Point calc(int from, int to)
	{
		if(dp[from][to] != null) return dp[from][to];
		
		ArrayList<Integer> branch = new ArrayList<Integer>();
		for(int i = 0;i < n;i++)
		{
			if(i == from || i == to) continue;
			if(d[to][i] > 0) branch.add(new Integer(i));
		}
		
		if(branch.size() == 0)
		{
			dp[from][to] = new Point(d[from][to], d[from][to]); 
			return dp[from][to];
		}
		else if(branch.size() == 1)
		{
			Point next = calc(to, branch.get(0).intValue());
			
			dp[from][to] = new Point(d[from][to] * 2 + next.x, d[from][to] * 3 + next.y); 
			return dp[from][to];
		}
		
		Point[] next = new Point[branch.size()];
		int maxnum = 0;
		int max = 0;
		for(int i = 0;i < branch.size();i++)
		{
			next[i] = calc(to, branch.get(i).intValue());
			int tmp = next[i].y - next[i].x;
			if(tmp > max)
			{
				max = tmp;
				maxnum = i;
			}
		}
		
		Point ret = new Point(d[from][to] * 2, d[from][to] * 3);
		for(int i = 0;i < next.length;i++)
		{
			if(maxnum == i)
				ret.x += next[i].x;
			else
				ret.x += next[i].y;
			
			ret.y += next[i].y;
		}
		
		dp[from][to] = ret; 
		return dp[from][to];
	}
	
	private static void start()
	{
		int min = Integer.MAX_VALUE;
		
		dp = new Point[n+1][n+1];
		for(int x = 0;x < n+1;x++)
			for(int y = 0;y < n+1;y++)
				dp[y][x] = null;
		
		for(int i = 0;i < n;i++)
		{
			Point p = calc(n, i);
			min = Math.min(min, p.x);
		}
		
		System.out.println(min);
	}
	
	public static void main(String[] args)
	{
		
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			n = sca.nextInt();
			if(n == 0) break;
			
			int i, j;
			int[] tmp = new int[n-1];
			
			d = new int[n+1][n+1];
			for(i = 0;i < n+1;i++)
				for(j = 0;j < n+1;j++)
					d[j][i] = 0;
			
			for(i = 0;i < n-1;i++)
				tmp[i] = sca.nextInt();
			
			for(i = 0;i < n-1;i++)
			{
				d[i+1][tmp[i]-1] = d[tmp[i]-1][i+1] = sca.nextInt();
			}
			
			start();
		}
	}
}

Measured memory_bytes: 167800
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int h, w;
	bool flag = false;
	cin >> h >> w;
	vector<string>a(h);
	vector<bool>kesiG(h,false);
	vector<bool>kesiR(w,false);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	for (int i = 0; i<h; i++) {
		if (a[i][0] == '.') {


			for (int j = 0; j < w; j++) {
				if (a[i][j] == '.'&&j==w-1) {
					kesiG[i]=true;
				}
				else if (a[i][j]=='#') {
					break;
				}
			}
		}
	}
	for (int i = 0; i<w; i++) {
		if (a[0][i] == '.') {

			//cout << i << endl;
			for (int j = 0; j < h; j++) {
				if (a[j][i] == '.'&&j == h - 1) {
					kesiR[i] = true;
					//cout << "bb" << endl;
				}
				else if (a[j][i] == '#') {
				//	cout << j << endl;
					break;
				}
			}
		}
	}
	
	for (int i = 0; i < h; i++) {
		
		bool flag = false;
		for (int j =0 ; j < w; j++) {
			if (kesiR[j] != true && kesiG[i] != true) {
				cout << a[i][j];
				flag = true;
			}
		}
		if (flag == true) {
			cout << endl;
		}
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int main(){
  char buf[1024];
  char c;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%c", &c);

  if(c=='A'){
    printf("T\n");
  }
  else if(c=='T'){
    printf("A\n");
  }
  else if(c=='C'){
    printf("G\n");
  }
  else{
    printf("C\n");
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        List<Double> list = IntStream.range(0, n).mapToDouble(i -> (double) sc.nextInt()).sorted().boxed().collect(Collectors.toList());
        while (list.size() > 1) {
            double x = (list.get(0) + list.get(1)) / 2;
            list.remove(0);
            list.remove(0);
            int size = list.size();
            if (size == 0) {
                list.add(x);
            } else {
                for (int i = 0; i < size; i++) {
                    if (x >= list.get(i)) {
                        list.add(i, x);
                        break;
                    }
                }
                if (size == list.size()) {
                    list.add(0, x);
                }
            }
        }
        System.out.println(list.get(0));
    }

}


Measured memory_bytes: 26580
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

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

    int a[n * 3];
    for(int i = 0; i < n * 3; i++) {
        cin >> a[i];
    }

    long f[n + 1];
    f[0] = 0;
    priority_queue<int, vector<int>, greater<int> > fpq;
    for(int i = 0; i < n; i++) {
        fpq.push(a[i]);
        f[0] += a[i];
    }
    for(int i = 0; i < n; i++) {
        fpq.push(a[n + i]);
        int tmp = fpq.top();
        fpq.pop();
        f[i + 1] = f[i] + a[n + i] - tmp;
    }

    long b[n + 1];
    b[n] = 0;
    priority_queue<int> bpq;
    for(int i = 0; i < n; i++) {
        bpq.push(a[n * 2 + i]);
        b[n] += a[n * 2 + i];
    }
    for(int i = n - 1; i >= 0; i--) {
        bpq.push(a[n + i]);
        int tmp = bpq.top();
        bpq.pop();
        b[i] = b[i + 1] + a[n + i] - tmp;
    }

    long ans = f[n] - b[n];
    for(int i = 0; i < n; i++) {
        ans = max(ans, f[i] - b[i]);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

// a * x + b * y == gcd(a, b) なるx, yを計算
// 返り値はgcd(a, b)
template<typename T>
T extgcd(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

ll f[300050], fi[300050];

ll comb(int x, int y) {
    return f[x] * fi[y] % MOD * fi[x - y] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll a, b, K;
    cin >> n >> a >> b >> K;
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = f[i - 1] * i % MOD;
    }
    {
        ll x, y;
        extgcd(f[n], MOD, x, y);
        fi[n] = (x + MOD) % MOD;
    }
    
    for (int i = n; i > 0; i--) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    ll ans = 0;
    for (ll i = 0; i <= n; i++) {
        if ((K - a * i) % b != 0) continue;
        ll j = (K - a * i) / b;
        if (j < 0 || j > n) continue;
        (ans += comb(n, i) * comb(n, j) % MOD) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] != t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3844
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = 0,b = 0,c = 0;
    for(int i = 0;i<s.length();i++){
      if (s.substring(i,i+1).equals("a")) {
        a++;
      }else if (s.substring(i,i+1).equals("b")) {
        b++;
      }else{
        c++;
      }
    }
    int max = Math.max(a,Math.max(b,c));
    int min = Math.min(a,Math.min(b,c));
    if (max-min<=1) {
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 48180
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1e9+7;
using namespace std;
typedef pair<int,int> pii;
int main(){
    int n,k;
    long long s;
    cin >> n >> k >> s;
    long long ans[n];
    if(k==0){
        if(s==1e9) s-=2;
        rep(i,n) ans[i]=s+1;
    }
    else{
        rep(i,k) ans[i]=s;
        if(s==1e9) s-=2;
        for(int i = k;i<n;i++) ans[i]=s+1;        
    }
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 2048
from collections import deque

s = deque(input())
q = int(input())
 
me = 1#1:sei  -1:gyaku
for i in range(q):
    t = input().split()
    if t[0] == '1':
        me *= -1
            
    else:# 0=2
        if t[1]=='1':#1=1
            s.appendleft(t[2]) if me == 1 else s.append(t[2])
        else:#1=2
            s.append(t[2]) if me == 1 else s.appendleft(t[2])
s= list(s) 
if me != 1:
    s = s[::-1]
print(''.join(s))

Measured memory_bytes: 8564
from statistics import median
from time import time

t = time()

N, K = [int(x) for x in input().split()]
line_in_dice = list([int(x) for x in input().split()])

result = [0] * (N + K)

result[0] = line_in_dice[0]
result[K] -= line_in_dice[0]

max_point = 0
max_value = 0

for i in range(1, N):
    result[i] += (result[i - 1] + line_in_dice[i])
    result[i + K] -= line_in_dice[i]

    if result[i] > max_value:
        max_point = i
        max_value = result[i]


def create_median(x):
    if x % 2 == 1:
        return (1 + x) // 2
    else:
        return ((x // 2) + (x // 2 + 1)) / 2


print(sum(create_median(x)
          for x in line_in_dice[max_point - K + 1: max_point+1]))


Measured memory_bytes: 36020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

bool possible(vector<ll> &A, vector<ll> &F, ll K, ll N, ll X){
    rep(i,N){
        if (A[i] * F[N - 1 - i] > X){
            ll t = X / F[N - 1 - i];
            K -= (A[i] - t);
        }
    }
    if (K >= 0) return true;
    return false;
}

int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N);
    vector<ll> F(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        cin >> F[i];
    }
    sort(all(A));
    sort(all(F));
    ll left = 0;
    ll right = 10000000000000;
    if (possible(A,F,K,N,0)) cout << 0 << endl;
    else{
        while(true){
            if (right - left == 1){
                cout << right << endl;
                break;
            }
            else{
                if (possible(A,F,K,N,(left + right) / 2)){
                    right = (left + right) / 2;
                }
                else{
                    left = (left + right) / 2;
                }
            }
        }
    }
}


Measured memory_bytes: 6424
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val text = when (N % 10) {
        2, 4, 5, 7, 9 -> "hon"
        0, 1, 6, 8 -> "pon"
        else -> "bon"
    }
    println(text)
}


Measured memory_bytes: 34356
from collections import defaultdict
def main3():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()

    c = defaultdict(int)
    for a in A:
        c[a] += 1

    if len(c) == 1:
        n = list(c.keys())
        if n[0] == 0:
            print("Yes")
        else:
            print("No")
    
    elif len(c) == 2:
        n = list(c.keys())
        if n[0] == 0 and c[n[1]] == 2*c[n[0]]:
            print("Yes")
        else:
            print("No")
    
    elif len(c) == 3:
        n = list(c.keys())

        if (n[0] ^ n[1] ^ n[2]) == 0 and (c[n[0]] == c[n[1]] == c[n[2]] == N//3):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

if __name__ == "__main__":
    main3()

Measured memory_bytes: 20496
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	out << ((N % 10 == 9 || N / 10 == 9) ?"Yes"  : "No") << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#!/usr/bin/env python3
#AGC6 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
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
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
t = input()
ans = 2*n
for i in range(n):
    if s[i:] == t[:n-i]:
        print(n+i)
        quit()
print(ans)


Measured memory_bytes: 38256
eval"X,Y,*A=#"+`tr ' ' ,`
b=X+Y-a=A.inject(0,:^)
r=b/2
50.downto(0){X<s=r|a&1<<_1 or r=s}
p r<1||r>X||b/2&a|b%2>0?-1:X-r

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

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

    int n;
    cin >> n;

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

    if (n == 2) {
        cout << abs(arr[0] - arr[1]);
        return 0;
    } else if (n == 1) {
        cout << 0;
        return 0;
    }
    int dp[n];
    dp[0] = arr[0];
    dp[1] = abs(arr[0] - arr[1]);
    dp[2] = abs(arr[0] - arr[2]);

    for (int i = 3; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
                dp[i - 2] + abs(arr[i] - arr[i - 2]));
    }

    cout << dp[n - 1];

    return 0;
}


Measured memory_bytes: 1024
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m = inpm()
SC = inpll(m)

ans = -1
for i in range(1000):
    if len(str(i)) != n:
        continue
    
    flg = True
    for sc in SC:
        if len(str(i)) < sc[0]:
            flg = False
            break
        if str(i)[sc[0]-1] != str(sc[1]):
            flg = False
            break
    if flg == True:
        ans = i
        break

print(ans)

Measured memory_bytes: 31288
import math
s = str(input())

n = len(s)
k1 = math.ceil((n+1)/2)
sr1 = s[::-1]

s2 = s[0:int(k1-1)]
n2 = len(s2)
k2 = math.ceil((n2+1)/2)
sr2 = s2[::-1]


if s[0:int(k1-1)] == sr1[0:int(k1-1)] and s2[0:int(k2-1)] == sr2[0:int(k2-1)]:
    print('Yes')
else:
    print('No')

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

using namespace std;

const int mod = 1e9 + 7;

int add(int a, int b) {

    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string k;
    int d;
    cin >> k >> d;
    int n = k.size();

    vector< vector<int> > dp(d, vector<int>(2));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        vector< vector<int> > new_dp(d, vector<int>(2));
        for(int sum = 0; sum < d; sum++) {
            for(int already_smaller = 0; already_smaller < 2; already_smaller++) {
                for(int digit = 0; digit < 10; digit++) {
                    if(digit > k[i] - '0' && !already_smaller)
                        break;
                    int sum2 = (sum + digit) % d, as = already_smaller;
                    if(digit < k[i] - '0')
                        as = 1;
                    new_dp[sum2][as] = add(new_dp[sum2][as], dp[sum][already_smaller]);
                }
            }
        }
        dp = new_dp;
    }

    cout << add(add(dp[0][0], dp[0][1]), mod - 1) << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  
  if (N == 1){
    if (A.at(0) == K){
      cout << "POSSIBLE" << endl;
    }
    else {
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  
  int X = A.at(0);
  int Y = A.at(1);
  int Z = X % Y;
  int count;

  for (int i = 1; i < N; i++) {
    count = 0;
    while (count == 0){
      if (Z == 0){
        if (i != N-1){
          X = A.at(i+1);
          Z = X % Y;
        }
        count++;
      }
      else {
        X = Y;
        Y = Z;
        Z = X % Y;
      }
    }
  }
  
  if (K <= A.at(N-1) && K % Y == 0){
    cout << "POSSIBLE" << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}
    

Measured memory_bytes: 3996
//
// Created on 2020/05/10.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll ans = LINF;
    bool ok = false;
    int m;
    int n;
    int x;
    cin>>n>>m>>x;
    vector<ll>price(n);
    vector<vector<int>>A(n,vector<int>(m));
    for (int i = 0; i < n; ++i) {
        cin>>price[i];
        for (int j = 0; j < m; ++j) {
            cin>>A[i][j];
        }
    }
    for (int bit = 0; bit < (1<<n); ++bit) {
        ll now_price = 0;
        vector<int>now_understand(m,0);
        for (int i = 0; i < n; ++i) {
            if(bit & (1<<i)){
                now_price += price[i];
                for (int j = 0; j < m; ++j) {
                    now_understand[j] += A[i][j];
                }
            }
        }
        bool temp_ok = true;
        for (int k = 0; k < m; ++k) {
            if(now_understand[k] < x) {
                temp_ok = false;
                break;
            }
        }
        if(temp_ok){
            ok = true;
            ans = min(ans,now_price);
        }
    }

    if (ok){
        cout<<ans<<endl;
    }else{
        cout<<-1<<endl;
    }

    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int ans = 0, cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 256
//D 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+10;
int cnt[maxn];
int main(){
	int n,x,y;
	cin >> n >> x >> y;
	for(int i = 1;i <= n;i++)
		for(int j = i+1;j <= n;j++){
			cnt[min(abs(i-j),abs(i-x) + abs(j-y) + 1)]++;
		}
	for(int i = 1;i < n;i++)cout << cnt[i] << endl;
	return 0;
}


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

int main(){
  string A;
  cin >> A;
  int count=0;
  for(int i=0;i<4;i++){
    if(A.at(i)=='+'){
      count++;
    }
    else{
      count--;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a[5];
    int val=INF;
    int id;
    for(int i=0;i<5;i++){
        cin>>a[i];
        int tmp=a[i]%10;
        if(tmp<val and tmp!=0){
            val=tmp;
            id=i;
        }
    }
    int ans=0;
    if(val==INF){
        for(int i=0;i<5;i++){
            ans+=a[i];
        }
    }else{
        for(int i=0;i<5;i++){
            if(i!=id){ans+=a[i];
            if(a[i]%10!=0)ans+=(10-a[i]%10);
            }
        }
        ans+=a[id];
    }
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <numeric>
#include <iterator>
using namespace std;

int main() {
	long long int N, M;
	cin >> N >> M;
	priority_queue<pair<long long int, long long int>> que;
	for (int i = 0; i < N; ++i) {
		long long int a;
		cin >> a;
		que.push({ a, 1 });
	}
	for (int i = 0; i < M; ++i) {
		long long int b, c;
		cin >> b >> c;
		que.push({ c, b });
	}

	long long int sum = 0;
	while (N > 0) {
		sum += que.top().first * min(que.top().second, N);
		N -= que.top().second;
		que.pop();
	}
	cout << sum << endl;
	return 0;
}	

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

int main(){
    string s; cin >> s;
    int ans=0;
    if (s[0]=='R'){
        ans++;
        if (s[1]=='R'){
            ans++;
            if (s[2]=='R'){
                ans++;
            }
        }
    }
    else{
        if (s[1]=='R'){
            ans++;
            if (s[2]=='R'){
                ans++;
            }
        }
        else{
            if (s[2]=='R'){
                ans++;
            }
        }
    }
    cout << ans << "\n";
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    ll a,v;
    cin >> a >> v;
    ll b,w;
    cin >> b >> w;
    ll t;
    cin >> t;
    if(a == b){
        cout << "YES" << endl;
        return 0;
    }else if(w >= v){
        cout << "NO" << endl;
        return 0;
    }
    if(abs(a-b) <= t*(v-w)){
        cout << "YES" << endl;
        return 0;
    }else{
        cout << "NO" << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
using namespace std;
const int N=200200,oo=1000000000;
int i,j,k,n,m,ch,Hn;
int a[N],ST[2][N][22],Lg2[N];
struct heap {
	int l,r,v;
	bool operator < (const heap &n) const {
		return a[v]<a[n.v];
	}
} H[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
int get_min(int k,int l,int r) {
	int t=Lg2[r-l+1];
	int t1=ST[k][l][t],t2=ST[k][r-(1<<t)+1][t];
	if (a[t1]<a[t2]) return t1;
	return t2;
}
void S(int x,int y) {
	heap t=H[x];H[x]=H[y];H[y]=t;
}
void up(int x) {
	while (x>1 && H[x]<H[x>>1]) S(x,x>>1),x>>=1;
}
void down(int x) {
	while ((x<<1)<=Hn) {
		int k=x<<1;
		if (k<Hn && H[k|1]<H[k]) k|=1;
		if (H[k]<H[x]) S(x,k),x=k;
		else break;
	}
}
int main() {
	R(n);
	m=0;
	while ((1<<m+1)<=n) m++;
	for (i=0;i<=m;i++) Lg2[1<<i]=i;
	for (i=3;i<=n;i++) if (!Lg2[i]) Lg2[i]=Lg2[i-1];
	a[0]=oo;
	for (i=1;i<=n;i++) {
		R(a[i]);
		int t=i&1;
		ST[t][i][0]=i;
	}
	for (j=1;j<=m;j++)
		for (i=1;i<=n;i++) if (i+(1<<j)-1<=n)
			for (k=0;k<2;k++) {
				if (a[ST[k][i][j-1]]<a[ST[k][i+(1<<j-1)][j-1]]) ST[k][i][j]=ST[k][i][j-1];
				else ST[k][i][j]=ST[k][i+(1<<j-1)][j-1];
			}
	H[1].l=1;H[1].r=n;H[1].v=get_min(1,1,n);
	Hn=1;down(1);
	for (i=1;i<=n;i+=2) {
		heap t=H[1];
		H[1]=H[Hn--];
		down(1);
		int t1=t.v,t2=get_min((t.v&1)^1,t.v+1,t.r);
		printf("%d %d ",a[t1],a[t2]);
		if (t.l<t1-1) {
			Hn++;
			H[Hn].l=t.l;
			H[Hn].r=t1-1;
			H[Hn].v=get_min(H[Hn].l&1,H[Hn].l,H[Hn].r);
			up(Hn);
		}
		if (t1+1<t2-1) {
			Hn++;
			H[Hn].l=t1+1;
			H[Hn].r=t2-1;
			H[Hn].v=get_min(H[Hn].l&1,H[Hn].l,H[Hn].r);
			up(Hn);
		}
		if (t2+1<t.r) {
			Hn++;
			H[Hn].l=t2+1;
			H[Hn].r=t.r;
			H[Hn].v=get_min(H[Hn].l&1,H[Hn].l,H[Hn].r);
			up(Hn);
		}
	}
}

Measured memory_bytes: 38144
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, P; string S; cin >> S;
    N = S.length();
    ll ans = 0;
    P = 2019;

    vector<ll> mods(P, 0);

    ll cur = 0, coef = 1;
    mods[cur]++;
    REP(i, 0, N) {
        cur = (cur + coef * (S[N - i - 1] - '0') % P) % P;
        coef = coef * 10 % P;
        mods[cur]++;
    }

    REP(i, 0, P) {
        ans += mods[i] * (mods[i] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3712
## main

n = gets.strip.to_i

ds = gets.strip.split(' ').map{|s| s.to_i}

gcd = ds.shift
for d in ds
  gcd = gcd.gcd(d)
end
#p gcd

dvs = []

k = 1
while k * k <= gcd
  if gcd % k == 0
    dvs << k
    k0 = gcd / k
    if k0 != k
      dvs << k0
    end
  end
  k += 1
end

puts dvs.sort

Measured memory_bytes: 6108
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;

int main() {
    int n;  int k; int l[50];
    cin >> n>>k;
    int c = 0; int ans = 0;
    rep(i, n) {
        cin >> l[i];
        c += l[i];
   }
    sort(l, l + n);
    rep(i, n-k) {
        ans -= l[i];
    }
    cout << ans + c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x;
    cin>>x;
    for(int k=1;;k++){
        if((x*k)%360==0){
            cout<<k<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def solve(N, A):
  tx1 = 0
  for i, n in enumerate(A):
    if i % 2 == 0:
      tx1 += n
    else:
      tx1 -= n
  ans = [tx1]
  for i, a in enumerate(A[:-1]):
    x = 2 * (a - (ans[i] // 2))
    ans.append(x)
  return ans

def main():
  N = readInts()[0]
  A = readInts()

  ans = solve(N, A)
  print(" ".join(map(str, ans)))

if __name__ == "__main__":
  main()


Measured memory_bytes: 19092
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
        int scanA =  scan.nextInt();
        int scanB =  scan.nextInt();
		int[] total = {scanA + scanB ,scanA - scanB ,scanA * scanB };
      	int max = total[0];
		for (int maxs : total){
        	max = Math.max(max , maxs );
        }
      	System.out.println(max);
    }
}


Measured memory_bytes: 21844
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest117-A
#  TODO https://atcoder.jp/contests/abc117/tasks/abc117_a

def solveProblem(StudyTime,TimeSpeed):
	answer = StudyTime/TimeSpeed
	return answer


if __name__ == '__main__':
	T,X = map(int,input().strip().split(' '))
	solution = solveProblem(T,X)
	print("{}".format(solution))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,_n;
pii a[200005];
ll tree[200005<<2];
void update(int ind,int val){
    ind+=_n-1;
    tree[ind]+=(ll)val;
    while(ind>1){
        ind/=2;
        tree[ind]=tree[ind*2]+tree[ind*2+1];
    }
}
ll query(int l,int r,int nl,int nr,int ind){
    if(l<=nl && nr<=r) return tree[ind];
    if(l>nr || r<nl) return 0;
    int mid=(nl+nr)>>1;
    return query(l,r,nl,mid,ind*2)+query(l,r,mid+1,nr,ind*2+1);
}
int main(){
    scanf("%d",&n);
    _n=512;
    for(int i=1;i<=n;i++){
        long double now=0;
        scanf("%Lf",&now);
        now*=(long double)1e9;
        a[i].fi+=9,a[i].se+=9;
        ll ha=round(now);
        while(ha%2==0) ha/=2,a[i].fi--;
        while(ha%5==0) ha/=5,a[i].se--;
    }
    sort(a+1,a+n+1);
    int now=1;
    ll ans=0;
    for(int i=n;i>=1;i--){
        while(now<=n && a[now].fi<=-a[i].fi)
            update(a[now].se+200,1),now++;
        ans+=query(1,-a[i].se+200,1,_n,1);
    }
    for(int i=1;i<=n;i++)
        if(a[i].fi<=0 && a[i].se<=0)
            ans--;
    printf("%lld\n",ans/2);
    return 0;
}

Measured memory_bytes: 5388
#include <iostream>
using namespace	std;
int main(){
  int h,w,hw[10][10],r=0;
  cin>>h>>w;
  for(int i=0;i<10;i++) for(int j=0;j<10;j++) cin>>hw[i][j];
  for(int k=0;k<10;k++) for(int i=0;i<10;i++) for(int j=0;j<10;j++) hw[i][j]=min(hw[i][j],hw[i][k]+hw[k][j]);
  for(int i=0,a;i<h;i++) for(int j=0;j<w&&cin>>a;j++) if(~a) r+=hw[a][1];
  cout<<r<<endl;
}



Measured memory_bytes: 256
s = input()

first = s[0:2]
second = s[2:]

def flg(s):
  if int(s) <= 12 and int(s) > 0:
    return 0
  else:
    return 1

f1 = flg(first)
f2 = flg(second)

if f1 == 0 and f2 == 1:
  print("MMYY")
if f1 == 1 and f2 == 0:
  print("YYMM")
if f1 == 0 and f2 == 0:
  print("AMBIGUOUS")
if f1 == 1 and f2 == 1:
  print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        vll x(5);
        rep(i, 0, 5) cin >> x[i];
        cout << find(all(x), 0) - x.begin() + 1 << endl;
}

Measured memory_bytes: 3592
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        h: [i64; n]
    };

    let mut h: Vec<i64> = h;
    let mut flag = true;

    h[0] -= 1;
    for i in 0..n - 1 {
        if h[i] > h[i + 1] {
            flag = false;
            break;
        } else if h[i] < h[i + 1] {
            h[i + 1] -= 1;
        }
    }

    if flag {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 3752
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

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

    int m = (int)(sqrt(n) + 1.0e-9);
    m *= 2;
    vector<int> cnt(m, 1);
    for(int i=1; i<=m/2; ++i)
        cnt[m-i] = (n / i) - max(m/2, (n / (i + 1)));

    vector<long long> dp(cnt.begin(), cnt.end());
    while(--k > 0){
        vector<long long> nextDp(m, 0);
        long long sum = 0;
        for(int i=0; i<m; ++i){
            sum += dp[i];
            sum %= MOD;
            nextDp[m-1-i] += sum * cnt[m-1-i];
            nextDp[m-1-i] %= MOD;
        }
        dp = move(nextDp);
    }
    long long ans = accumulate(dp.begin(), dp.end(), 0LL) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
s=input()
t=True
for i in range(0,len(s)//2):
    if s[i]!=s[len(s)-i-1]:
        print("No")
        exit()

for j in range(0,((len(s)-1)//2)//2):
        if s[j]!=s[((len(s)-1)//2)-j-1]:
            print("No")
            exit()

for j in range(0,((len(s)-1)//2)//2):
        if s[len(s)-j-1]!=s[len(s)-((len(s)-1)//2-j)]:
            print("No")
            exit()

print("Yes")


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

int main()
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int i, j, iplusj, remaining;
    int cnt = 0;
    for (i = 0; i <= n; i += r)
    {
        for (j = 0; (iplusj = (i + j)) <= n; j += g)
        {
            remaining = n - iplusj;
            if (!(remaining % b))
            {
                ++cnt;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    int n;
    double d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n){
        double x, y;
        cin >> x >> y;
        if(x * x  +  y * y <= d*d) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3744
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    vector<string> S(N);
    REP(i,N){
        cin>>S[i];
    }
    //inputend;
    sort(ALL(S));
    string NOW=S[0];
    int allcount=0;
    int count=1;
    REPi(i,1,N){
        if(S[i]==NOW){
            count+=1;
        }else{
            NOW=S[i];
            allcount=max(allcount,count);
            count=1;
        }
    }
    allcount=max(allcount,count);
    count=1;
    NOW=S[0];
    if(allcount==count){
        cout<<S[0]<<endl;
    }
    REPi(i,1,N){
        if(S[i]==NOW){
            count+=1;
        }else{
            NOW=S[i];
            count=1;
        }
        if(allcount==count){
            cout<<S[i]<<endl;
        }
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main(){

    ll N;
    cin >> N;

    pair<ll, ll> p;
    p.first = -1;
    p.second = -1;
    for(ll i = 1; i <= N; i++){
        ll j = i;
        ll cn = 0;
        while(true){
            if(j % 2 == 0){
                j /= 2;
                cn++;
            }else{
                break;
            }
        }
        if(p.first < cn){
            p.first = cn;
            p.second = i;
        }
    }

    cout << p.second << endl;

}

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

const int amax = 100000;
ll cnt[amax+1];

int main(){
  ll n,k; cin >>n >>k;
  rep(i,n){
    int a,b; cin >>a >>b;
    cnt[a]+=b;
  }
  for(int i = 1; i<=amax; i++){
    if(k<=cnt[i]) {
      cout << i << endl;
      return 0;
    }
    k-=cnt[i];
  }
  return 0;
}

Measured memory_bytes: 4368
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/abc077_b

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    N = int(input())
    ans = 1

    for i in range(int(N**0.5)+1):
        ans = i
    print(i**2)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3060
from collections import defaultdict

n, m = map(int, input().split())
ls = []

for _ in range(n):
    a, b = map(int, input().split())
    ls.append([a, b])


ls.sort()

i = 0
price = 0

for num in range(n):
    i += ls[num][1]
    price += ls[num][0]*ls[num][1]
    num1 = num
    if i > m:
        break

now_cnt = i - ls[num1][1]
answer = price - ls[num1][0]*ls[num1][1] + (m - now_cnt)*ls[num1][0]

print(answer)


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

int main(){
	int n;
    cin >> n;
    int p[n];
    int error = 0;
    for (int i = 0; i < n; i++){
    	cin >> p[i];
    }
    for (int j = 0; j < n; j++){
    	if (p[j] != j+1){
        	error += 1;
        }else{
            continue;
        }
        if (error > 2){
        	break;
        }
    }
    if (error == 0 || error == 2){
    	cout << "YES" << endl;
    }else{
    	cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int main(){
    int h,w; cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    ll dp[1010][1010] = {0};
    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            dp[i][j] %= MOD;
            if(i != h-1){
                if(a[i+1][j] == '.'){
                    dp[i+1][j] += dp[i][j];
                }
            }
            if(j != w-1){
                if(a[i][j+1] == '.'){
                    dp[i][j+1] += dp[i][j];
                }
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    s[3]='8';
    cout << s;
    
    return 0;
}

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

const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    int n;
    cin>>n;
    int cnt=0;
    rep(i,n){
        int di,dj;
        cin>>di>>dj;
        if(di==dj)++cnt;
        else cnt=0;

        if(cnt==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;

}

Measured memory_bytes: 3620
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

tot=0
for i in range(n):
  tot+=b[i]
for i in range(n-1):
  if a[i+1]==a[i]+1:
    tot+=c[a[i]-1]
print(tot)

Measured memory_bytes: 3064
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 50 + 10, N2 = 2e5, delta = 46639, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli n, a[N][N], ans[N][N];

lli f (lli x) {
	return x % mod;
}

void power (lli k) {
	if (!k) {
		memset (ans, 0, sizeof ans);
		for (lli i = 0; i < n; i++)
			ans[i][i] = 1;
		return;
	}
	power (k / 2);
	lli res[N][N];
	memset (res, 0, sizeof res);
	for (lli i = 0; i < n; i++)
		for (lli j = 0; j < n; j++)
			for (lli k = 0; k < n; k++)
				res[i][j] = f (res[i][j] + f (ans[i][k] * ans[k][j]));
	for (lli i = 0; i < n; i++)
		for (lli j = 0; j < n; j++) {
			ans[i][j] = res[i][j];
			res[i][j] = 0;
		}
	if (k & 1) {
		for (lli i = 0; i < n; i++)
			for (lli j = 0; j < n; j++)
				for (lli k = 0; k < n; k++)
					res[i][j] = f (res[i][j] + f (a[i][k] * ans[k][j]));
		for (lli i = 0; i < n; i++)
			for (lli j = 0; j < n; j++)
				ans[i][j] = res[i][j];
	}
}

int32_t main() {
	fast;
	lli k, cnt = 0;
	cin >> n >> k;
	for (lli i = 0; i < n; i++)
		for (lli j = 0; j < n; j++)
			cin >> a[i][j];
	power (k);
	for (lli i = 0; i < n; i++)
		for (lli j = 0; j < n; j++)
			cnt = f (cnt + ans[i][j]);
	cout << cnt << '\n';
	return 0;
}


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

ll mod = 1000000007;

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

    vector<ll> col(3);
    ll ans = 1;
    int colj;
    rep(i,N) {
        int cnt = 0;
        rep(j,3) {
            if (A[i] == col[j]) {
                ++cnt;
                colj = j;
            }
        }
        ++col[colj];
        ans = (ans * cnt) % mod;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

const ll mod[] = { 999999937, 1000000007 }, base = 10000103;

struct RollingHash
{
	int n;
	vector<ll> hs[2], pw[2];
	RollingHash() {};
	RollingHash(const string& s)
	{
		n = s.size();
		REP(i, 2)
		{
			hs[i].assign(n + 1, 0);
			pw[i].assign(n + 1, 0);
			hs[i][0] = 0;
			pw[i][0] = 1;
			REP(j, n)
			{
				pw[i][j + 1] = pw[i][j] * base%mod[i];
				hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i];
			}
		}
	}

	ll hash(int l, int r, int i)
	{
		return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) % mod[i];
	}

	bool match(int l1, int r1, int l2, int r2)
	{
		return (hash(l1, r1, 0) == hash(l2, r2, 0)) && (hash(l1, r1, 1) == hash(l2, r2, 1));
	}
};


int main()
{
	string s, t;
	cin >> s >> t;
	RollingHash rhs(s), rht(t);
	map<pii, int> mp;
	REP(i, s.size() - t.size() + 1)
	{
		int a = rhs.hash(i, i + t.size(), 0), b = rhs.hash(i, i + t.size(), 1);
		pii p = pii(a, b);
		mp[p]++;
	}
	ll ans = 0;
	REP(i, t.size())
	{
		ll a = rht.hash(0, t.size(), 0), b = rht.hash(0, t.size(), 1);
		a = (a - t[i]*rht.pw[0][t.size() - i - 1] + mod[0]*1000) % mod[0];
		b = (b - t[i]*rht.pw[1][t.size() - i - 1] + mod[1]*1000) % mod[1];
		REP(j, 26)
		{
			char c = 'a' + j;
			if (c == t[i]) continue;
			int pa = (a + c*rht.pw[0][t.size() - i - 1]) % mod[0], pb = (b + c*rht.pw[1][t.size() - i - 1]) % mod[1];
			pii p(pa, pb);
			if (mp.count(p)) ans += mp[p];
		}
		REP(j, 26)
		{
			char c = 'A' + j;
			if (c == t[i]) continue;
			int pa = (a + c*rht.pw[0][t.size() - i - 1]) % mod[0], pb = (b + c*rht.pw[1][t.size() - i - 1]) % mod[1];
			pii p(pa, pb);
			if (mp.count(p)) ans += mp[p];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 30696
// ------------------------------------
// Date:2018/ 3/11
// Problem:ABC 074 RestoringRoadNetwork d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;
const int MAX_N = 300;

int N;
int A[MAX_N][MAX_N];
bool state[MAX_N][MAX_N];

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

  cin >> N;

  REP(hi, N) {
    REP(wi, N) {
      cin >> A[hi][wi];
    }
  }
  
  bool ok = true;
  REP(k, N) {
    REP(i, N) {
      REP(j, N) {
	if (i == j || k == j || i == k) continue;
	if (A[i][k] + A[k][j] == A[i][j]) {
	  if (A[i][k] == 0 || A[k][j] == 0) continue;
	  A[i][j] = 0;
	} else if (A[i][k] + A[k][j] < A[i][j]) {
	  if (A[i][k] == 0 || A[k][j] == 0) continue;
	  ok = false;
	}
      }
    }
  }

  /*
  cout << endl;

  REP(i, N) {
    REP(j, N) {
      printf("%3d", A[i][j]);
    }
    cout << endl;
  }
  */

  ll ans = 0ll;
  REP(to, N) {
    REP(from, to) {
      ans += A[from][to];
    }
  }

  if (!ok) ans = -1ll;

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



Measured memory_bytes: 640