akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Net.NetworkInformation;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int W = sc.NextInt();
        long[] v, w;
        v = new long[N];
        w = new long[N];
        var dp = new long[10001];
        for (int i = 0; i <= 10000; i++)
        {
            dp[i] = long.MaxValue;
        }

        dp[0] = 0;

        for (int i = 0; i < N; i++)
        {
            v[i] = sc.NextInt();
            w[i] = sc.NextInt();
        }

        for (int i = 0; i < N; i++)
        {
            for (int j = 10000; j >= 0; j--)
            {
                if (dp[j] == long.MaxValue)
                    continue;
                dp[j + v[i]] = Math.Min(dp[j + v[i]], dp[j] + w[i]);
            }
        }

        for (int i = 10000; i >= 0; i--)
        {
            if (dp[i] <= W)
            {
                Console.WriteLine(i);
                return;
            }
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


Measured memory_bytes: 7908
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt1 = cnt2 = 0
for i in range(n):
    if a[i] <= b[i]:
        cnt1 += (b[i] - a[i]) // 2
    else:
        cnt2 += a[i] - b[i]
print("Yes" if cnt1 >= cnt2 else "No")

Measured memory_bytes: 4596
# encoding:utf-8

def main():
	s = input()
	k = int(input())
	substr = set()
	for start in range(len(s)):
		for end in range(start, start+5):
			if end <= len(s):
				substr.add(s[start:(end+1)])

	substr = list(substr)
	substr.sort()
	#print(substr)
	print(substr[k-1])

if __name__ == '__main__':
	main()

Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	int n, q;
	cin>>n>>q;
	map<int, int> h[2];
	n-=1;
	ll b=(ll)(n-1)*(n-1);
	rep(_, q){
		int f, x;
		cin>>f>>x; f--;
		auto it=h[f].lower_bound(x);
		int l;
		if(it==h[f].end()) l=n;
		else l=(it->second) -1;
		if(h[1-f][l]==0) h[1-f][l]=x;
		else h[1-f][l]=min(h[1-f][l], x);
		b-= l-1;
	}
	cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 8216
INF = 10 ** 12
N, K = gets.split.map(&:to_i)
$eat_costs = gets.split.map(&:to_i).sort
$food_costs = gets.split.map(&:to_i).sort { |a, b| b <=> a }

def possible?(limit)
  neccesary_training = 0
  N.times do |i|
    tmp_cost = $eat_costs[i] - limit / $food_costs[i]
    neccesary_training += tmp_cost if tmp_cost > 0
  end
  neccesary_training <= K
end

puts (0..INF).bsearch { |limit| possible?(limit) }


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

using namespace std;

long long int a[2000],n,memo[2000][2000];
bool done[2000][2000];

long long int search(long long int left,long long int right){
    long long int x,y,old;
    if(done[left][right]){
        return memo[left][right];
    }
    done[left][right]=true;
    if(left==right){
        memo[left][right]=0LL;
        return memo[left][right];
    }
    if((left+n-1)%n==right){
        memo[left][right]=min(a[left],a[right]);
        return memo[left][right];
    }
    if(a[left]>a[right]){
        x = (left+n-1)%n;
        y = right;
    }else{
        x = left;
        y = (right+1)%n;
    }
    memo[left][right]=max(search((x+n-1)%n,y)+a[x],search(x,(y+1)%n)+a[y]);
    return memo[left][right];
}

int main(void){
    long long int i,j,ans=-1;
    scanf("%lld",&n);
    for(i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            done[i][j]=false;
        }
    }
    for(i=0; i<n; i++){
        ans = max(search((i+n-1)%n,(i+1)%n)+a[i],ans);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 36404
n = int(input())
a = list(map(int, input().split()))
jud = [0] * n
ans = []
for i in range(n//2, n):
    if a[i] == 1:
        jud[i] = 1
        ans.append(i+1)
for i in range(n//2-1, -1, -1):
    cou = 0
    for j in range(2, n//(i+1)+1):
        cou ^= jud[(i+1)*j-1]
    if a[i] != cou:
        jud[i] = 1
        ans.append(i+1)
ans.sort()
print(jud.count(1))
print(*ans)

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

int main(){
    int N, L;
    cin >> N >> L;
    priority_queue<string, vector<string>, greater<string>> que;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        que.push(s);
    }

    string ans = "";
    while(!que.empty()){
        string target = que.top();
        ans += target;
        que.pop();
    }

    cout << ans << endl;
    return 0;

}

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

int main() {
  char c;
  cin >> c;

  if (c == 'a' ||
      c == 'i' ||
      c == 'u' ||
      c == 'e' ||
      c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll a,b,x;
    cin >> a >> b >> x;

    ll ans;

    if (a == 0) ans = b/x+1;
    else ans = b/x - (a-1)/x;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
while true
 n, x = gets.split.map(&:to_i)
break if n == 0 && x == 0 
com = 0

for i in 1..n
 for j in (i + 1)..n
  for k in (j + 1)..n

if i + j + k == x
com += 1
end

end
end
end

puts com
end


Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	int A[N];
	int B[N],C[N];
	for(int i=0;i<N;i++){
		cin>>A[i];
	}B[0]=A[0];C[N-1]=A[N-1];
    for(int j=1;j<N;j++){
		B[j]=__gcd(B[j-1],A[j]);
		C[N-j-1]=__gcd(C[N-j],A[N-j-1]);
	}int g=max(B[N-2],C[1]);
	for(int i=1;i<=N-2;i++){
		g=max(g,__gcd(B[i-1],C[i+1]));
	}cout<<g<<endl;
}

Measured memory_bytes: 1408
from collections import deque
H,W = map(int,input().split())
CH,CW = map(int,input().split())
DH,DW = map(int,input().split())
maze = [list(input()) for _ in range(H)]
 
def BFS(maze,s,g):
  q1 = deque([s])
  checked = []
  cost = [[-1]*W for _ in range(H)]
  m = 0
  while q1:
    h,w,n = q1.popleft()
    if cost[h][w]<0:
      cost[h][w] = n
      if (h,w)==g: return n
      dp = [(x-2,y-2) for x in range(5) for y in range(5) if (x-2)!=0 or (y-2)!=0]
      for dh,dw in dp:
        if 0<=h+dh<H and 0<=w+dw<W and maze[h+dh][w+dw]==".":
          if (dh,dw) in [(-1,0),(1,0),(0,-1),(0,1)]:
            q1.appendleft((h+dh,w+dw,n))
          else:
            q1.append((h+dh,w+dw,n+1))
  return cost[g[0]][g[1]]
print(BFS(maze,(CH-1,CW-1,0),(DH-1,DW-1)))

Measured memory_bytes: 251204
#include <bits/stdc++.h>
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

vector <int> v;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int x;
        scanf("%d",&x);
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    printf("%d",v[v.size()-1]-v[0]);
}

Measured memory_bytes: 256
import sys
from collections import deque

n, m = map(int, input().split())
link = [ [] for i in range(n)]
for i in sys.stdin.readlines():
    a, b = map(int, i.split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

d = deque([0])
ans = [-1]*n
ans[0] = 0
while d:
    p = d.pop()
    for v in link[p]:
        if ans[v] == -1:
            ans[v] = p+1
            d.appendleft(v)

if -1 in ans:
    print("No")
else:
    print("Yes")
    print(*ans[1:], sep="\n")


Measured memory_bytes: 47348
s[1<<17];k,A,B,a;main(M){for(scanf("%*d%d",s);~scanf("%d%d",&A,&B);M=1){for(;B/M/M;s[++M]-=k)s[M]+=k=~-A/M<B/M;for(k=B/M;k;s[M=B/k--+1]--)s[M=fmax(~-A/k+1,M)]++;}for(;k++<*s;)printf("%d ",a+=s[k]);}

Measured memory_bytes: 1280
import sys
import math

input = sys.stdin.readline


def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


N, M, L = map(int, input().split())
d = [[math.inf] * N for _ in range(N)]
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
warshall_floyd(d)
for i in range(N):
    for j in range(N):
        d[i][j] = 1 if d[i][j] <= L else math.inf
for i in range(N):
    d[i][i] = 0
warshall_floyd(d)


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if s == t:
        print(0)
    elif d[s][t] == math.inf:
        print(-1)
    else:
        print(d[s][t]-1)


Measured memory_bytes: 83016
import java.io.*;
import java.util.Arrays;

class Main
{
    public static void main(String[] args) throws IOException
    {
	BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

	String str = br.readLine();

	String[] sl = str.split(" ");

	int[] il = new int[sl.length];

	for(int i=0; i<il.length; i++){
	    il[i] = Integer.parseInt(sl[i]);
	}

	if(Math.abs(il[0] - il[2]) <= il[3]){
	    System.out.println("Yes");
	}
	else if(Math.abs(il[0] - il[1]) <= il[3] && Math.abs(il[1] - il[2]) <= il[3]){
	    System.out.println("Yes");
	}
	else{
	    System.out.println("No");
	}
    }
}

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

int main(){
  int n,a[3][3],b[11];
  bool appear[3][3];
  rep(i,3){
    rep(j,3){
      cin >>a[i][j];
    }
  }
  cin >>n;
  rep(i,n) cin >>b[i];
  rep(i,n){
    rep(j,n){
      appear[i][j] = false;
      rep(k,n){
        if(a[i][j] == b[k]) appear[i][j] = true;
      }
    }
  }
  string ans = "No";
  rep(i,3){
    if(appear[i][0] and appear[i][1] and appear[i][2]) ans = "Yes";
    if(appear[0][i] and appear[1][i] and appear[2][i]) ans = "Yes";
  }
  if(appear[0][0] and appear[1][1] and appear[2][2]) ans = "Yes";
  if(appear[0][2] and appear[1][1] and appear[2][0]) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
h=tuple(map(int,input().split()))

dp=[0]*n
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[-1])

Measured memory_bytes: 87096
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	int queue[100], input, i = 0;
	while (cin >> input) {
		if (input != 0) {
			queue[i] = input;
			++i;
		}
		else {
			--i;
			cout << queue[i] << endl;
			queue[i] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3008
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1
q=int(input())
ans=0
for i in dic:
  ans+=i*dic[i]
for i in range(q):
  b,c=map(int,input().split())
  if c in dic:
    if not b in dic:
      dic[b]=0
    dic[c]+=dic[b]
    ans+=dic[b]*(c-b)
    print(ans)
    dic[b]=0
  else:
    if not b in dic:
      dic[b]=0
    dic[c]=dic[b]
    ans+=dic[b]*(c-b)
    print(ans)
    dic[b]=0
  

Measured memory_bytes: 88304
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,cc=0,c=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    if(a < 400 && c1 == 0){ c1++;c++; }
    else if(400 <= a && a < 800 && c2 == 0){ c2++;c++; }
    else if(800 <= a && a < 1200 && c3 == 0){ c3++;c++; }
    else if(1200 <= a && a < 1600 && c4 == 0){ c4++;c++; }
    else if(1600 <= a && a < 2000 && c5 == 0){ c5++;c++; }
    else if(2000 <= a && a < 2400 && c6 == 0){ c6++;c++; }
    else if(2400 <= a && a < 2800 && c7 == 0){ c7++;c++; }
    else if(2800 <= a && a < 3200 && c8 == 0){ c8++;c++; }
    else if(3200 <= a)cc++;
  }
  if(c==0){
    printf("1 %d",cc);
  }else{
    printf("%d %d",c,c+cc);
  }
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


pint node[5][1024];
int dp[5][1024];
int size[5];
char buf[1024];
int manha(const pint& a, const pint& b)
{
	return abs(a.first-b.first) + abs(a.second-b.second);
}
int main()
{
	int w, h;
	while (scanf("%d%d", &w, &h), w|h)
	{
		memset(size, 0, sizeof(size));

		pint start, goal;
		for (int y = 0; y < h; ++y)
		{
			scanf("%s", buf);
			for (int x = 0; x < w; ++x)
			{
				if (isdigit(buf[x]))
				{
					int attr = buf[x] - '0' - 1;
					node[attr][size[attr]++] = pint(x, y);
				}
				else if (buf[x] == 'S')
					start = pint(x, y);
				else if (buf[x] == 'G')
					goal = pint(x, y);
			}
		}

		int attrs = 0;
		int no_attr;
		for (int i = 0; i < 5; ++i)
		{
			if (size[i])
				++attrs;
			else
				no_attr = i;
		}
		int hoge, piyo;
		if (attrs == 5)
			hoge = 0, piyo = 5;
		else if (attrs == 4)
			hoge = piyo = no_attr;
		else
		{
			puts("NA");
			continue;
		}

		const int INF = 2 << 24;
		int res = INF;
		int ans_attr = -1;
		for (int okido = hoge; okido <= piyo; ++okido)
		{
			int first = (okido + 1) % 5;
			int last = (okido + 4) % 5;

			for (int i = 0; i < 5; ++i)
				for (int j = 0; j < size[i]; ++j)
					dp[i][j] = INF;
			for (int i = 0; i < size[first]; ++i)
				dp[first][i] = manha(start, node[first][i]);

			for (int i = 0; i < 4; ++i)
			{
				int cur = (first + i) % 5;
				int next = (cur + 1) % 5;
				for (int j = 0; j < size[cur]; ++j)
					for (int k = 0; k < size[next]; ++k)
						dp[next][k] = min(dp[next][k], dp[cur][j] + manha(node[cur][j], node[next][k]));
			}

			int r = INF;
			for (int i = 0; i < size[last]; ++i)
				r = min(r, dp[last][i] + manha(node[last][i], goal));
			if (r < res)
			{
				res = r;
				ans_attr = okido + 1;
			}
		}
		printf("%d %d\n", ans_attr, res);
	}

	return 0;
}

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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=606;
const double EPS=1e-10;
int n,m,ind[MAXN];
vector<int>G1[MAXN],G2[MAXN];
double E[MAXN],P[MAXN];
int main() {
	n=read();m=read();
	for(int i=1,u,v;i<=m;++i)u=read(),v=read(),G1[u].pb(v),G2[v].pb(u);
//	queue<int>q;E[n]=0;q.push(n);
//	for(int i=1;i<=n;++i)ind[i]=G1[i].size();assert(ind[n]==0);
//	while(!q.empty()){
//		int u=q.front();q.pop();
//		if(G1[u].size())E[u]=E[u]/(double)G1[u].size()+1;
//		for(int i=0;i<(int)G2[u].size();++i){
//			int v=G2[u][i];
//			E[v]+=E[u];
//			ind[v]--;
//			if(!ind[v])q.push(v);
//		}
//	}
//	P[1]=1;assert(q.empty());q.push(1);
//	for(int i=1;i<=n;++i)ind[i]=G2[i].size();assert(ind[1]==0);
//	while(!q.empty()){
//		int u=q.front();q.pop();
//		for(int i=0;i<(int)G1[u].size();++i){
//			int v=G1[u][i];
//			P[v]+=P[u]/(double)G1[u].size();
//			ind[v]--;
//			if(!ind[v])q.push(v);
//		}
//	}
	E[n]=0;
	for(int i=n-1;i>=1;--i){
		for(int j=0;j<(int)G1[i].size();++j)E[i]+=E[G1[i][j]];
		E[i]=E[i]/(double)G1[i].size()+1;
	}
	P[1]=1;
	for(int i=1;i<n;++i){
		for(int j=0;j<(int)G1[i].size();++j)P[G1[i][j]]+=P[i]/(double)G1[i].size();
	}
	double ans=E[1];
	for(int i=1;i<n;++i){
		if((int)G1[i].size()==1)continue;
		double sumE=(E[i]-1)*(double)G1[i].size();
		for(int j=0;j<(int)G1[i].size();++j){
			ans=min(ans,E[1]-P[i]*(E[i]-((sumE-E[G1[i][j]])/((double)G1[i].size()-1)+1)));
		}
	}
	cout<<setiosflags(ios::fixed)<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
# AtCoder Beginner Contest 047
# A - キャンディーと2人の子供
a, b, c = map(int, input().split())
if a+b == c:
    print('Yes')
elif b+c == a:
    print('Yes')
elif c+a == b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
n = int(input())
ans = 1

for k in range(2, int(n ** 0.5) + 1):
    if n % k != 0:
        continue
    if (n // k) % k == 1:
        ans += 1
for i in range(2, 41):
    for k in range(2, n + 1):
        x = k ** i
        if x > n:
            break
        if n % x != 0:
            continue
        if (n // x) % k == 1:
            ans += 1
n -= 1
for k in range(1, int(n ** 0.5) + 1):
    if n % k != 0:
        continue
    if k * k == n or k == 1:
        ans += 1
    else:
        ans += 2
if(n == 1):
    ans -= 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli a,b,c,d,ans;
   cin>>a>>b>>c>>d;
   ans=max(a*c,a*d);
   ans=max(ans,b*c);
   ans=max(b*d,ans);
   cout<<ans<<"\n";
   return 0;
}//main


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

using namespace std;

const int mod = 1e9 + 7;

long long n, k, ans;
vector < vector <int> > a, zero;

vector < vector <int> > operator * (vector < vector <int> > a, vector < vector <int> > b){
      vector < vector <int> > c;
      c.resize(n + 1);
      for(int i = 1; i <= n; i ++)
            c[i].resize(n + 1);
      for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= n; j ++){
                  for(int k = 1; k <= n; k ++){
                        c[i][j] = c[i][j] + ((a[i][k] *1ll* b[k][j]) % mod);
                        c[i][j] %= mod;
                  }
            }
      }
      return c;
}

vector < vector <int> > bp(vector < vector <int> > a, long long n){
      vector < vector <int> > ret = zero;
      while(n){
            if(n & 1)
                  ret = (ret * a);
            a = a * a;
            n >>= 1;
      }
      return ret;
}

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

      a.resize(n + 1);
      zero.resize(n + 1);

      for(int i = 1; i <= n; i ++){
            a[i].resize(n + 1);
            zero[i].resize(n + 1);
            zero[i][i] = 1;
            for(int j = 1; j <= n; j ++){
                  scanf("%d", &a[i][j]);
            }
      }

      a = bp(a, k);

      for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= n; j ++){
                  ans = (ans + a[i][j]) % mod;
            }
      }

      cout << ans << endl;
}


Measured memory_bytes: 384
(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
;;(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defvar *radius* (read))

(format t "~,6F" (* 2 pi *radius*))


Measured memory_bytes: 23760
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)

int main(){
    int n,m;
    cin >> n >> m;
    vi a(n),b(n),c(m),d(m);
    rp(i,n){
        cin >> a[i] >> b[i];
    }
    rp(i,m){
        cin >> c[i] >> d[i];
    }
    vi e(n);
    rp(i,n){
        int min=INT_MAX;
        int p;
        rp(j,m){
            int dist = abs(a[i],c[j])+abs(b[i],d[j]);
            if(min>dist){
                min=dist;
                p=j;
            }
        }
        e[i]=p+1;
    }
    
    rp(i,n){
        cout << e[i] << endl;
    }

    return 0;
}






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

int cnt = 0;

void PrintfArray(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        if( i )
            cout << endl;
        cout << a[i];
    }
    cout << endl;
}

void insertionSort(int a[], int n, int g)
{
    for(int i = g; i < n; i++)
    {
        int temp = a[i];
        int j = i - g;
        while(j >= 0 && temp < a[j]){
            a[j+g] = a[j];
            j -= g;
            cnt ++;
        }
        a[j+g] = temp;
    }
}

void shellSort(int a[], int n)
{
    cnt = 0;
    vector<int> G;
    int g = 1;
    do{
        G.push_back(g);
        g = 3 * g + 1;
    }while(g<n);
    
    
    cout << G.size() << endl;
    
    for(int i=G.size()-1; i>=0; i--)
    {
        if(G.size()-i-1)
            cout << " ";
        cout << G[i];
    }
    cout << endl;
    
    for(int i=G.size()-1; i>=0; i--)
    {
        insertionSort(a, n, G[i]);
    }
}

int main() {
	int n;
	cin >> n;
	int* a = new int[n];
	for(int i = 0; i < n; i++)
	{
	    cin >> a[i];
	}
	shellSort(a, n);
	
	cout << cnt << endl;
	PrintfArray(a, n);
	
	
	return 0;
}

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

using namespace std;

typedef long long int ll;

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

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

int main()
{
	ll n,x;
	cin >> n >> x;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	vector<vector<ll> > b(n);
	for(int i = 0; i < n; i++){
		b[i].resize(n);
	}
	for(int i = 0; i < n; i++){
		b[0][i] = a[i];
	}
	for(int i = 1; i < n; i++){
		for(int j = 0; j < n; j++){
			int k = j-i;
			if(k<0) k += n;
			b[i][j] = min(b[i-1][j],a[k]);
		}
	}

	// for(int i = 0; i < n; i++){
	// 	cout << "k = " << i << endl;
	// 	for(int j = 0; j < n; j++){
	// 		cout << b[i][j] << " ";
	// 	}printf("\n");
	// }
	ll ans = INF*INF;
	for(int i = 0; i < n; i++){
		ll res = (ll)i*x + accumulate(all(b[i]),(ll)0);
		ans = min(ans,res);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 31616
n, k = map(int, input().split())
okasi = [0] * k
sunuke = [0] * n
for i in range(k):
    okasi[i] = int(input())
    work = list(map(int, input().split()))
    for j in range(okasi[i]):
        sunuke[work[j] - 1] += 1
print(sunuke.count(0))

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

#define      ll      long long int

vector<int> v;

int dp[13][100005];

int go(int at, int sum)
{
    if (at == (int) v.size() || sum <= 0) {
        return 0;
    }
    if (dp[at][sum] != -1) {
        return dp[at][sum];
    }
    int res = 1e9;
    for (int i = at; i < (int) v.size(); i++) {
        if (sum - v[i] >= 0) {
            res = min(res, 1 + go(i, sum - v[i]));
        }
    }
    dp[at][sum] = res;
    return res;
}

int main( )
{
    ll n, i, j, k;
    cin >> n;
    for (i = 6; i <= n; i = i * 6) {
        v.push_back(i);
    }
    for (i = 9; i <= n; i = i * 9) {
        v.push_back(i);
    }
    v.push_back(1);
    sort(v.begin(), v.end());
    memset(dp, -1, sizeof dp);
    cout << go(0, n) << '\n';
    return 0;
}

Measured memory_bytes: 11520
import sys
n, q = map(int, input().split())

A = [[] for _ in range(n)]
for _ in range(q):
    query = list(map(int,sys.stdin.readline().split()))
    # query = list(map(int, input().split()))
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(*A[query[1]])
    else:
        del A[query[1]][:]


Measured memory_bytes: 29772
#include <iostream>

using namespace std;

int main(){
    int N,S=0,temp;
    cin >> N;
    temp=N;
    do{
        S+=temp%10;
        temp/=10;
    }while(temp!=0);
    if(N%S==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main()
{
  string xyz ="";
int x=0,z=0,w=0,i=0,j=0,n=0;
std::cin >> x;
int y=100000;
rep(i,x){
  y*=1.05;
  y+=999;
  y/=1000;
  y*=1000;
}
std::cout << (int)y << '\n';
}



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

int main()
{
  int s;
  cin >> s;
  int s1, s2, s3;
  s1 =  s / 100;
  s2 = (s % 100) / 10;
  s3 = s % 10;
  cout << s1 + s2 + s3 << endl;

}

Measured memory_bytes: 256
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    A.sort()
    ans = 0
    comb = Combination(1000000)
    cnt = []
    for i in range(N-K+1):
        cnt.append(comb(N-i-1,K-1))
        ans -= comb(N-i-1,K-1) * A[i]
    for i in range(N,N-len(cnt),-1):
        ans += A[i-1] * (cnt[N-i])
        ans %= MOD
    print(ans)
    



if __name__ == "__main__":
    main()

Measured memory_bytes: 218104
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
}
char a[26];
signed main(){
	sc(s)
	int n=s.size();
	rep(0,i,26)a[i]=char(i+97);
	int ans=mod;
	rep(0,i,26){
		int b[110];
		int sum=0;
		int sa[110];
		b[0]=-1;
		rep(0,j,n){
			if(s[j]==a[i]){
				sum++;
				b[sum]=j;
			}
		}
		b[sum+1]=n;
		rep(0,i,sum+1)sa[i]=b[i+1]-b[i];		
		if(sum>0)ans=min(maxi(sa,0,sum+1),ans);
	}
	c(ans-1)	
}	


Measured memory_bytes: 256
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    c = collections.Counter()
    for i in range(N):
        S = input().strip()
        c[S] += 1

    ma = c.most_common()[0][1]

    ans = []
    for v in c.most_common():
        if v[1] == ma:
            ans.append(v[0])
        else:
            break
    ans.sort()

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43548
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    int n;
    ll ans;
    string s;
    cin>>n>>s;

    VI r, g, b;
    REP(i,n) {
        if (s[i] == 'R') r.push_back(i);
        else if (s[i] == 'G') g.push_back(i);
        else if (s[i] == 'B') b.push_back(i);
    }

    ans = r.size() * g.size() * b.size();

    REP(i,n-2) {
        FOR(j,1,n) {
            if (i + j * 2 >= n) break;

            if (s[i] != s[i+j] && s[i] != s[i+j*2] && s[i+j] != s[i+j*2])
                ans--;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(){
  int a[3];
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
  int k;
  scanf("%d",&k);
  int max = 0;
  int x;
  for(int i=0;i<3;i++){
    if(a[i] > max){
      max = a[i];
      x = i;
    }
  }
  for(int j=0;j<k;j++){
    max *= 2;
  }
  int y = 0;
  while(y < 3){
    if(y != x){
      max += a[y];
    }
    y++;
  }
  printf("%d",max);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define l long 
#define ll long long 
#define ld long double 
#define INF 1000000000000000
#define MOD 1000000007
#define MAX_N 1000006
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULLL);
using namespace std;
vector<ll> tree(MAX_N);
vector<ll> dp(MAX_N);
void build(l v,l tl,l tr)
{
    if(tl==tr)
    {
        tree[v]=dp[tl];
        return;
    }
    l tm=(tl+tr)>>1;
    build(2L*v,tl,tm);
    build(2L*v+1,tm+1,tr);
    tree[v]=max(tree[2L*v],tree[2L*v+1]);
    return;
}
void update(ll val,l pos,l v,l tl,l tr)
{
    if(tl==tr)
    {
        tree[v]=val;
        dp[pos]=val;
        return;
    }
    l tm=(tl+tr)>>1;
    if(pos<=tm)
    update(val,pos,2L*v,tl,tm);
    else 
    update(val,pos,2L*v+1,tm+1,tr);
    tree[v]=max(tree[2L*v],tree[2L*v+1]);
    return;
}
ll rng_max(l lo,l hi,l v,l tl,l tr)
{
    if(lo>hi)
    return -1;
    if(lo==tl&&hi==tr)
    return tree[v];
    l tm=(tl+tr)>>1;
    return max(rng_max(lo,min(hi,tm),2L*v,tl,tm),rng_max(max(lo,tm+1),hi,2L*v+1,tm+1,tr));
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    l n,x;
    cin>>n;
    vector<l> h;
    vector<ll> a;
    ll val;
    for(l i=0;i<n;i++)
    {
        cin>>x;
        h.push_back(x);
    }
    for(l i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
    }
    build(1L,0L,n);
    ll ans=0;
    for(l i=0;i<n;i++)
    {
        if(i==0)
        {
            update(a[i],h[i],1L,0L,n);
        }
        else 
        {
            val=rng_max(0L,h[i]-1,1L,0L,n);
            update(val+a[i],h[i],1L,0L,n);
        }
        ans=max(ans,dp[h[i]]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 23632
#include <iostream>
#include <cstring>
using namespace std;
const int N=110;
char str[N][N];
int f[N][N];
int main()
{
    int n,m;
    cin>>n>>m;
    memset(f,0x3f,sizeof f);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",str[i]+1);
    }
    // cout<<str[2][2]<<endl;
    f[1][1]=(str[1][1]=='#');
    // cout<<f[1][1]<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i>1)f[i][j]=min(f[i][j],f[i-1][j]+(str[i-1][j]=='.'&&str[i][j]=='#'));
            if(j>1)f[i][j]=min(f[i][j],f[i][j-1]+(str[i][j-1]=='.'&&str[i][j]=='#'));
        }
    }
    cout<<f[n][m]<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(s) for s in input().split()]
abss = [abs(a) for a in A]
signs = sum(1 if a < 0 else 0 for a in A)
if signs % 2 == 0:
    print(sum(abss))
else:
    minabs = min(abss)
    print(sum(abss) - 2 * minabs)


Measured memory_bytes: 65184
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <set>
#include <cmath>
#include <algorithm>

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int (i)=0;(i)<(n);(i)++)
//#define ForJ(n) for(int j=0;j<n;j++)
//#define ForK(n) for(int k=0;k<n;k++)
#define Pr(n) cout<<n<<endl;
#define INS(v,n) for(int i=0;i<n;i++){cin >>v.at(i);}//vector 代入
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;

int Product_set_min(int la,int ra,int lb,int rb){//A<B
    int r=0;;
    if (la<ra&&ra<lb&&lb<rb) {
        r= 0;
    }else if(la<=lb&&lb<=ra&&ra<=rb){
        r= lb;
    }else if(lb<=la&&la<=ra&&ra<=rb){
        r= la;
    }else if(lb<=la&&la<=rb&&rb<=ra){
        r= la;
    }else if(lb<rb&&rb<la&&la<ra){
        r= 0;
    }
    return r;
}
int Product_set_max(int la,int ra,int lb,int rb){//A<B
    int r=0;;
    if (la<ra&&ra<lb&&lb<rb) {
        r= 0;
    }else if(la<=lb&&lb<=ra&&ra<=rb){
        r= ra;
    }else if(lb<=la&&la<=ra&&ra<=rb){
        r= ra;
    }else if(lb<=la&&la<=rb&&rb<=ra){
        r= rb;
    }else if(lb<rb&&rb<la&&la<ra){
        r= 0;
    }
    return r;
}
signed  main(){
    int n,m;
    cin >>n>>m;
    vector<int> L(m),R(m);
    For(m, i){
        cin >> L.at(i)>>R.at(i);
    }
    int min = L[0];
    int max = R[0];
    int flag = 0;
    For(m-1, i){
        if (max-min>R[i+1]-L[i+1]) {
            swap(min, L[i+1]);
            swap(max, R[i+1]);
        }
        if (Product_set_min(min, max, L[i+1], R[i+1])==0) {
            flag++;
        }else{
            min = Product_set_min(min, max, L[i+1], R[i+1]);
            max = Product_set_max(min, max, L[i+1], R[i+1]);
        }
    }
    if(flag==0){
    Pr(max-min+1)
    }else{
        Pr(0)
    }
    return 0;
}



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

using namespace std;

int main(){
    int n, a, b, c, d;
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    string s;
    cin >> s;
    s = '$' + s + "#########";
    for(int i = 1; i <= n; i++){
        if(i == a && a != c){
            if(s[i + 1] == '.' && b != i + 1){
                a++;
            }else if(s[i + 1] == '#' && s[i + 2] == '.' && b != i + 2){
                a+=2;
            }else{
                if(b == i + 1){
                    if(c >= d && s[i + 2] == '.'){
                        a += 2;
                    }else{
                        a++;
                        if(s[i + 2] == '#' && s[i + 3] == '.')b += 2;
                        else if(s[i + 2] == '.')b++;
                        else{
							//cout << a << " " << b << endl;
                            printf("No\n");
                            return 0;                            
                        }
                    }
                }else if(b == i + 2){
                    if(s[i + 3] == '.')b++;
					else if(s[i + 3] == '#' && s[i + 4] == '.')b += 2;
					else {
						//cout << a << " " << b << endl;
						printf("No\n");
						return 0;						
					}
                    a+=2;
                }else{
					//cout << a << " " << b << endl;
                    printf("No\n");
                    return 0;
                }
            }
        }else if(i == b && b != d){
            if(s[i + 1] == '.' && a != i + 1){
                b++;
            }else if(s[i + 1] == '#' && s[i + 2] == '.' && a != i + 2){
                b+=2;
            }else{
                if(a == i + 1){
                    if(d >= c && s[i + 2] == '.'){
                        b += 2;
                    }else{
                        b++;
                        if(s[i + 2] == '#' && s[i + 3] == '.')a += 2;
                        else if(s[i + 2] == '.')a++;
                        else{
							//cout << a << " " << b << endl;
                            printf("No\n");
                            return 0;                            
                        }
                    }
                }else if(a == i + 2){
                    if(s[i + 3] == '.')a++;
					else if(s[i + 3] == '#' && s[i + 4] == '.')a += 2;
					else {
						//cout << a << " " << b << endl;
						printf("No\n");
						return 0;						
					}
                    b+=2;
                }else{
					//cout << a << " " << b << endl;
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
	//cout << a << " " << b << endl;
    if(a == c && b == d){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 772
// AOJ DPL_1_A Coin Changing Problem
//
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}

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

    int n;
    cin >> n;

    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int ans = 0;

    rep(i, n) {
        if (p[i] == i+1) {
            ans++;
            i++;
        }
    }

    cout << ans << endl;

}


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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;

using ll = long long;


int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    ll n, m;
    cin >> n >> m;

    cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;

    return 0;
%>

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(void)
{
    long long n,i;
    cin >> n;
    for(i=(long long)sqrt(n);i>=1;i--)
        if(n%i==0)
            break;
    cout << n/i+i-2;
    return 0;
}


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

using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>theval(n+1,0);
    vector<int>wrong(n+1,0);
    int acs=0,wrn=0;
    for(int i=0;i<m;i++){
        int a;
        string s;
        cin>>a>>s;
        if(theval[a]==0&&s=="AC"){acs++;theval[a]++;}
        else if(theval[a]==0&&s=="WA"){wrn++;wrong[a]++;}
        
    }
    for(int i=1;i<=n;i++){
        if(theval[i]==0){wrn-=wrong[i];}
    }
    cout<<acs<<" "<<wrn<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
    set<int> q;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
    	int t;
    	cin>>t;
    	q.insert(t);
    }
    cout<<q.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	n %= 1000;
	cout << (n == 0 ? 0 : 1000 - n) << endl;
	return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();

		Node_BT[] nodes = new Node_BT[n];
		for(int i=0; i<n; i++) {
			nodes[i] = new Node_BT();
		}

		for(int i=0; i<n; i++) {
			String cmd = sc.next();

			if(cmd.equals("insert")) {
				int key = sc.nextInt();
				nodes[i].id = i;
				nodes[i].key = key;

				if(i != 0) {
					int x = 0;

					while(nodes[x].left != -1 || nodes[x].right != -1) {

						if(nodes[i].key < nodes[x].key) {
							if(nodes[x].left == -1) {
								break;
							}
							x = nodes[x].left;
						} else {
							if(nodes[x].right == -1) {
								break;
							}
							x = nodes[x].right;
						}
					}

					nodes[i].parent = x;

					if(nodes[i].key < nodes[x].key) {
						nodes[x].left = i;
					} else {
						nodes[x].right = i;
					}
				}

			} else {
				nodes[0].inOrder(nodes);
				System.out.println();
				nodes[0].preOrder(nodes);
				System.out.println();

			}
		}
	}

	static class Node_BT {
		int id;
		int left = -1;
		int right = -1;
		int parent = -1;
		int key;

		void preOrder(Node_BT[] nodes) {
			System.out.print(" " + key);
			if(left != -1) {
				nodes[left].preOrder(nodes);
			}
			if(right != -1) {
				nodes[right].preOrder(nodes);
			}
		}

		void inOrder(Node_BT[] nodes) {
			if(left != -1) {
				nodes[left].inOrder(nodes);
			}
			System.out.print(" " + key);
			if(right != -1) {
				nodes[right].inOrder(nodes);
			}
		}

//		void postOrder(Node_BT[] nodes) {
//			if(left != -1) {
//				nodes[left].postOrder(nodes);
//			}
//			if(right != -1) {
//				nodes[right].postOrder(nodes);
//			}
//			System.out.print(" " + id);
//		}
	}

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 136724
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int A1[N];
  int A2[N];
  for (int i = 0; i < N; i++) {
    cin >> A1[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> A2[i];
  }
  int R1[N];
  int R2[N];
  R1[0] = A1[0];
  R2[N-1] = A2[N-1];
  for (int i = 1; i < N; i++) {
    R1[i] = R1[i-1] + A1[i];
    R2[N-1-i] = A2[N-1-i] + R2[N-1-i+1];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int res = R1[i]+R2[i];
    ans = max(ans,res);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628