akhauriyash/Code-Regression huggingface dataset:
import math

H,W,k =list( map(int, input().split(" ")))
grid = [ list(input()) for _ in range(H) ]
s = 1
for w in range(W):
    for h in range(H):
        if grid[h][w] == "#": # 探索フェイズ
            grid[h][w] = s
            ue = h
            sita = h
            # 上方向への移動フェイズ
            for h1 in range(h-1,-1,-1):
                if grid[h1][w] == ".":
                    grid[h1][w]  = s
                    ue = h1
                else:
                    break
            for h1 in range(h+1,H):
                if grid[h1][w] == ".":
                    grid[h1][w]  = s
                    sita = h1
                else:
                    break
            # 横方向への移動フェイズ
            yoko = 1
            end = False

            while w + yoko != W:
                for h1 in range(ue,sita + 1):
                    if grid[h1][w + yoko] != ".":
                        end = True
                        break
                if end :
                    break
                for h1 in range(ue, sita + 1):
                    grid[h1][w + yoko] = s
                yoko +=1

            yoko = -1
            end = False

            while w + yoko != -1:
                for h1 in range(ue,sita + 1):
                    if grid[h1][w + yoko] != ".":
                        end = True
                        break
                if end :
                    break
                for h1 in range(ue, sita + 1):
                    grid[h1][w + yoko] = s
                yoko -=1

            s += 1#次の色塗り

for g in grid:
    print(*g)


Measured memory_bytes: 7532
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, a, b = gi()
ans = (n // (a + b)) * a + min(n % (a + b), a)
print(ans)

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define endl '\n'

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

	int n, k;
	cin >> n >> k;
	int h[n+1], ans[n+1];
	for(int i=1; i<=n; i++)
	{
		cin >> h[i];
		ans[i] = -1;
	}
	h[0] = h[1];
	ans[0] = ans[1] = 0;
	for(int i=2; i<=n; i++)
		if( ans[i] == -1 )
		{
			ans[i] = MOD;
			for(int j=1; j<=k && i>=j; j++)
				ans[i] = min( ans[i] , ans[i-j] + abs( h[i]-h[i-j] ) );
		}
	cout << ans[n];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k;
int main(){
    scanf("%lld",&k);
    int n=50;
    vector<ll> v(n,n-1);
    for(int i=0;i<n;i++)v[i]+=k/n;
    for(int i=0;i<n;i++)v[i]-=k%n;
    for(int i=0;i<k%n;i++)v[i]+=n+1;
    printf("%d\n",n);
    for(int i=0;i<n;i++)printf("%lld ",v[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
AB=[]
for _ in range(N):
    a,b=map(int,input().split())
    AB.append([a,b])
AB.sort(key=lambda x:x[0])
import heapq
h=[]
day=1
count=0
ans=0
while True:
    if day>M:
        break
    while count!=N:
        if AB[count][0]!=day:
            break
        heapq.heappush(h,-AB[count][1])
        count+=1
    if len(h)!=0:
        ans-=heapq.heappop(h)
    day+=1
print(ans)

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

MOD = 10 ** 9 + 7

N = int(input())
BN = list(map(int, input().split())) + [10**6]

ans = 0
ans += BN[0]
for i in range(N - 1):
    ans += min(BN[i], BN[i + 1])

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
vector < Pii > data;
int N,T,S;
int memo[3001][3001];
int solve(int index,int t){
    if(index == N || t >= T)return 0;
    if(memo[index][t]!=-1)return memo[index][t];

    int ret = max(solve(index,t+1),solve(index+1,t));
    bool f = true;
    
    if(t < S && t+data[index].se > S)f=false;
    if(t+data[index].se > T)f=false;
    
    if(f)ret = max(ret,solve(index+1,t+data[index].se)+data[index].fi);
    //printf("{%d,%d} = %d\n",index,t,ret);
    return memo[index][t] = ret;
}
int main(){
    memset(memo,-1,sizeof(memo));
    scanf("%d%d%d",&N,&T,&S);
    rep(i,N){
        int a,b;
        scanf("%d%d",&a,&b);
        data.PB(Pii(a,b));
    }
    printf("%d\n",solve(0,0));
    return 0;
}

Measured memory_bytes: 36804
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,z,w;cin>>n>>z>>w;
    vin a(n);rep(i,n)cin>>a[i];
    if(n>1)cout<<max(abs(w-a[n-1]),abs(a[n-2]-a[n-1]));
    else cout<<abs(w-a[0])<<endl;
}

Measured memory_bytes: 3560
N=int(input())
S=input()
a=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
ans=''
for i in (S):
  num=a.index(i)+N
  if(num>25):
    num-=26
  ans+=a[num]
print(ans)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
vector<map<int,int>> ch(31);
int imos[31][200010];

int main() {
  int n, C;
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    ch[c][s] = t;
  }
  for (int i = 1; i <= C; i++) {
    for (auto p: ch[i]) {
      if (p.second == 0) continue;
      imos[i][p.first * 2 - 1]++;
      imos[i][p.second * 2]--;
    }
    for (int j = 1; j <= 200000; j++) {
      imos[i][j] += imos[i][j - 1];
      if (imos[i][j] > 0) {
        imos[0][j]++;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= 200000; i++) {
    ans = max(ans, imos[0][i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 29184
N = gets.to_i
l = gets.split.map(&:to_i)
cnt = 0
(0..N-1).each do |i|
  (i+1..N-1).each do |j|
    (j+1..N-1).each do |k|
      next if i == j || j == k || i == k
      if l[i] != l[j] && l[j] != l[k] && l[i] != l[k] && 
        l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[i] + l[k] > l[j]
        cnt = cnt.succ
      end
    end
  end
end
puts cnt

Measured memory_bytes: 14344
N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]


def dist(i, j):
    sum = 0
    for i0, j0 in zip(i, j):
        sum += (i0-j0)**2
    return sum**0.5


ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if dist(X[i], X[j]) == int(dist(X[i], X[j])):
            ans += 1

print(ans)


Measured memory_bytes: 3188
#include<iostream>

int main(){
  int a, b;
  std::cin >> a >> b;
  if(a%3 == 0)
    std::cout << "Possible" << std::endl;
  else if(b%3 == 0)
    std::cout << "Possible" << std::endl;
  else if((a + b)%3 == 0)
    std::cout << "Possible" << std::endl;
  else
    std::cout << "Impossible" << std::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 rep1(i,n) for(ll i=1;i<=((ll)n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define meow(a) cout<<a<<" meow\n";
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
const ll maxn=200005;
const ll MOD=998244353;
double mypow(ll a,ll b){
	double res=1;
	while(b){
		if(b&1) res=res*a;
		a=a*a;

		b>>=1;
	}
	return res;
}
ll n,m;


int main()
{
    //IOS;
    while(cin>>n>>m)
    {
        priority_queue<ll,vector<ll>,greater<ll>> pq;
        ll sum=0;
        rep(i,n)
        {
            ll x;
            cin>>x;
            sum+=x;
            pq.push(x);
        }
        vii v;
        rep(i,m)
        {
            ll a,b;
            cin>>a>>b;
            v.pb(mp(b,a));
        }
        //cout<<pq.top()<<"\n";
        sort(v.begin(),v.end(),greater<pii>());
        //for(auto i:v) cout<<i.F<<" "<<i.S<<"\n";
        for(auto i:v)
        {

            if(i.F<=pq.top()) break;

            else
            {
                while(i.S--)
                {
                  if(i.F<=pq.top()) break;
                  sum-=pq.top();
                  pq.pop();
                  sum+=i.F;
                  pq.push(i.F);
                  //cout<<i.S<<" "<<sum<<"\n";
                }
            }
        }
        cout<<sum<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3188
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]+a[i+1]>b[i]:
        if a[i]>b[i]:
            ans+=b[i]
        else:
            a[i+1]-=b[i]-a[i]
            ans+=b[i]
    else:
        ans+=a[i]+a[i+1]
        a[i]=0
        a[i+1]=0
print(ans)


Measured memory_bytes: 18624
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int p[] = new int[N];
    boolean out = false;
    for (int i=0; i<N; i++) {
      p[i] = sc.nextInt();
    }

    out = hantei(p, N);

    if(!out){
      loop:for(int i=0; i<N-1; i++) {
        for (int j=i+1; j<N; j++) {
          int temp = 0;
          temp = p[i];
          p[i] = p[j];
          p[j] = temp;
          if(hantei(p, N)){
            out = true;
            break loop;
          } else {
            temp = p[j];
            p[j] = p[i];
            p[i] = temp;
          }
        }
      }
    }

    if(out){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  public static boolean hantei(int p[], int N){
    boolean out = false;
    for (int i=0; i<N-1; i++) {
      if(p[i] > p[i+1]){
        break;
      }
      if(i == N-2){
        out = true;
      }
    }
    return out;
  }
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk; 
	cin>>n;
	if(n>=30) printf("Yes\n");
	else printf("No\n");
} 

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;

int main(){

  string S;
  cin>>S;

  set<int> st;
  REP(i,0,S.size()){
    st.insert(S[i] - 'a');
  }

  REP(i,0,26){
    if(st.find(i) == st.end()){
      cout<<(char)('a' + i)<<endl;
      return 0;
    }
  }

  cout<<"None"<<endl;

  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int max = 0;
        int count = 0;
        for(int i = 0; i < N; i++)
        {
            int high = int.Parse(input[i]);
            if (max <= high) { max = high;
                count++;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main()
{
  int i;
  char number[1001]={0};
  int sum=0;
  
  while(1)
  {
    sum=0;
    cin >> number;
    
    for(i=0;number[i]!='\0';i++)
    {
      sum+=number[i]-'0';
    }
    if(number[0]=='0')
      break;
    cout << sum <<"\n";
    
  }
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        if (b == 1) cout << "Bob" << endl;
        else
            cout << "Alice" << endl;
    } else if (a < b) {
        if (a == 1) cout << "Alice" << endl;
        else
            cout << "Bob" << endl;
    } else
        cout << "Draw" << endl;
    return 0;
}

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

int main() {
	// your code goes here
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	string s,t;
	
	cin>>s>>t;
	
	string ans,c;
	ans="";
	
	char dp[s.length()+1][t.length()+1];
	vector<vector<int>>l(s.length()+1,vector<int>(t.length()+1,0));
	
	int i,j;
	for(i=0;i<s.length();i++)
	{
	    for(j=0;j<t.length();j++)
	    {
	        if(s[i]==t[j])
	        {
	           dp[i+1][j+1]='d'; 
	           l[i+1][j+1]=l[i][j]+1;
	        }
	        
	        if(l[i][j+1]>l[i+1][j+1])
	        {
	            dp[i+1][j+1]='l';
	            l[i+1][j+1]=l[i][j+1];
	        }
	        if(l[i+1][j]>l[i+1][j+1])
	        {
	            l[i+1][j+1]=l[i+1][j];
	            dp[i+1][j+1]='u';
	        } 
	       
	    }
	}
	

	
	i=s.length();j=t.length();
	while(i>0&&j>0)
	{
	    if(dp[i][j]=='u')
	         j--;
	      else if(dp[i][j]=='d')
	    {
	        c=ans;
	        ans=s[i-1]+c;
	        i--;j--;
	    }
	    else i--;
	}
	
	      
	
	
	
	cout<<ans;
	return 0;
}


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

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

    int tasteOfFullApplePie = 0;
    vector<int> appleTasteVec;
    for (int i = 1; i <= n; ++i)
    {
        int singleAppleTaste = l + i - 1;
        appleTasteVec.push_back(singleAppleTaste);
        tasteOfFullApplePie += (singleAppleTaste);
    }

    int minDiff = 300, ans;
    for (int i = 0; i < n; ++i)
    {
        int tasteOfSingleApplePie = 0;
        for (int singleAppleNum = 0; singleAppleNum < n; ++singleAppleNum)
        {
            if (i != singleAppleNum)
            {
                tasteOfSingleApplePie += appleTasteVec.at(singleAppleNum);
            }
        }

        int singleDiff = abs(tasteOfFullApplePie - tasteOfSingleApplePie);
        if (singleDiff < minDiff)
        {
            ans = tasteOfSingleApplePie;
            minDiff = singleDiff;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1=sc.nextInt();
        int n2=sc.nextInt();
        int n3=sc.nextInt();
        int time=0;
        if(n1==n2)
            time++;
        if(n1==n3)
            time++;
        if(n2==n3)
            time++;
        if(time==1)
            System.out.println("Yes");
        else
            System.out.println("No");
}}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  
  // 1からNまでの整数をAに格納
  for (int i = 0; i < N; i++) A.at(i) = i + 1;
  
  // 各Aに対して何回2で割れるかを判定
  int top_cnt = 0, top_A = 0;
  for (int i = 0; i < N; i++) {
    int cnt = 0, tmp_A = A.at(i);
    while(1) {
      // 奇数の場合break
      if (tmp_A % 2  == 1) {
        break;
      }
      cnt++;
      tmp_A /= 2;
    }
    if (cnt >= top_cnt) {
      top_A = A.at(i);
      top_cnt = cnt;
    }
  }
  cout << top_A << endl;
}


Measured memory_bytes: 256
K = int(input())
G = [[] for _ in range(K)]
for i in range(K):
    G[i].append((1, (i+1)%K))
    G[i].append((0, (i*10)%K))
from collections import deque
que = deque([1])
dist = [-1]*K
dist[1] = 0
"""while que:
    v = que.pop()
    d = dist[v]
    for nv, c in G[v]:
        if dist[nv]>=0:
            continue
        if c == 0:
            que.append(nv)
            dist[nv] = d
        else:
            que.appendleft(nv)
            dist[nv] = d+1
    print(que)"""
import heapq
inf = 10**10
def dijkstra(s, n, G):#スタート, 頂点数, グラフ:[[(cost, v)], ...]
    dist = [inf]*n
    edges = []#(sからvまでのコストの候補, v)
    dist[s] = 0
    for e in G[s]:
        heapq.heappush(edges, e)
    while edges:
        cost, v = heapq.heappop(edges)
        if dist[v] != inf:
            continue
        dist[v] = cost
        for c, nv in G[v]:
            if dist[nv] == inf:
                heapq.heappush(edges, (cost + c, nv))
    return dist
dist = dijkstra(1, K, G)
print(dist[0]+1)






Measured memory_bytes: 84528
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
S1 = list(map(int, input().split()))
S2 = list(map(int, input().split()))
T = [0] * N
for i in range(N):
    T[i] = sum(S1[0:i+1]) + sum(S2[i:N])
print(str(max(T)))


Measured memory_bytes: 2940
import scala.annotation.tailrec
object Main extends App {
  import scala.io.StdIn._

  println(if (solve(readLine.trim, readLine.trim)) "yes" else "no")
  class Str(private val str: String) {
    private[this] val memo = ('a' to 'z').map(c ⇒ str.indices.map(i ⇒ if (str(i) == c) i else Int.MaxValue).toArray.also(a ⇒ a.indices.reverse.tail.foreach(i ⇒ a(i) = math.min(a(i), a(i + 1))))).toArray
    def nextSameCharPosition(index: Int): Int = {
      if (index + 1 < str.length) memo(str(index) - 'a')(index + 1)
      else str.length
    }
  }
  def solve(target: String, pattern: String): Boolean = {
    val str = new Str(target)
    val inverse = calLongestPattern(target, pattern)
    @tailrec
    def sub(current: Int, longest: Int = 0): Boolean = {
      if (current < target.length){
        if (longest < pattern.length){
          if (target(current) == pattern(longest)){
            if (str.nextSameCharPosition(current) < target.length){
              if (inverse(str.nextSameCharPosition(current)) + longest < pattern.length) sub(current + 1, longest + 1)
              else false
            }else sub(current + 1, longest + 1)
          }else sub(current + 1, longest)
        }else sub(current + 1, longest)
      }else longest == pattern.length
    }
    sub(0)
  }
  def calLongestPattern(str: String, pattern: String): Array[Int] = {
    val result = Array.tabulate(str.length){_ ⇒ 0}
    @tailrec
    def sub(current: Int, longest: Int = 0): Unit = {
      if (current >= 0){
        if (longest < pattern.length && str(current) == pattern(pattern.length - longest - 1)){
          result(current) = longest + 1
          sub(current - 1, longest + 1)
        }else {
          result(current) = longest
          sub(current - 1, longest)
        }
      }
    }
    sub(result.length - 1)
    result
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 483672
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n;
    map<int,int>mp;
    int a[n];
    for(i = 0;i < n;i++)
    {
        cin>>a[i];
        mp[a[i]] = i+1;
    }
    for(i = 1;i < n;i++)
        cout<<mp[i]<<" ";
    cout<<mp[n]<<endl;
    return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
signed main()
{
	printf("%d",((!(getchar()-49))+(!(getchar()-49))+(!(getchar()-49))));
	return putchar(10),0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dpc[510][2][2], dpn[510][2][2];

int solve(string &s, string &t, int inc_equal) {
    int N = s.size(), M = t.size();
    fill(dpc[0][0], dpc[M+1][0], 0LL);

    int res = 0;
    dpc[0][0][0] = 1;
    for(int i=0; i<=N; i++) {
        for(int j=0; j<=M; j++) {
            for(int f=0; f<2; f++) {
                for(int l=0; l<2; l++) {
                    // fprintf(stderr, "dp[%lld][%lld][%lld][%lld] = %lld\n", i, j, f, l, dpc[j][f][l]);
                    if(i == N) continue;
                    
                    int lim = f ? 9 : s[i] - '0';
                    for(int x=0; x<=lim ;x++) {
                        int nl = l || x > 0;
                        if(j < M) {
                            int c = (t[j] - '0') == x;
                            if(c and nl) (dpn[j+1][f || x < lim][nl] += dpc[j][f][l]) %= MOD;
                            if(!j) (dpn[j  ][f || x < lim][nl] += dpc[j][f][l]) %= MOD;
                        }
                        if(j == M) {
                            (dpn[j][f || x < lim][nl] += dpc[j][f][l]) %= MOD;
                        }
                    }
                    dpc[j][f][l] = 0;
                }
            }
        }
        if(i < N) swap(dpc, dpn);
    }
    (res += dpc[M][1][1]) %= MOD;
    if(inc_equal) (res += dpc[M][0][1]) %= MOD;
    if(t == "0" and !(s == "0" and !inc_equal)) (res += 1) %= MOD;
    // fprintf(stderr, "res = %lld\n", res);
    return res;
}

signed main() {
    string A, B, C; cin >> A >> B >> C;
    int ans = (solve(B, C, 1) - solve(A, C, 0) + MOD) % MOD;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int N, L, Q;
int x[101010];
int bk[17][101010];
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N;
  REP(i,N) cin >> x[i];
  cin >> L >> Q;

  int pre = 0;
  for (int i=0; i<N; i++) {
    while (x[i] - x[pre] > L) pre++;
    bk[0][i] = pre; //i番目の頂点から次に行ける最も左の頂点番号
  }

  for (int i=1; i<17; i++) {
    for (int j=0; j<N; j++) {
      bk[i][j] = bk[i-1][bk[i-1][j]];
    }
  }

  for (; Q--;) {
    int a, b;
    cin >> a >> b;
    a--; b--;

    if (a == b) {
      puts("0");
      continue;
    }
    if (a > b) swap(a, b);

    int ret = 0;
    for (int i=16; i>=0; i--) {
      if (bk[i][b] > a) {
        ret += 1 << i;
        b = bk[i][b];
      }
    }

    cout << ret + 1 << endl;
  }
}

Measured memory_bytes: 14976
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

const int MOD1 = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int base1 = 233;
const int base2 = 999;
const int N = 3e5 + 233;
const int DELTA = 1e7;
int n, _pos[N];
char str[N]; 

inline int power(int a, int k, int MOD) {
	if (k < 0) k += MOD - 1;
	int ans = 1;
	for (; k; k >>= 1, a = (lo) a * a % MOD)
		if (k & 1) ans = (lo) ans * a % MOD;
	return ans;
}

struct val_t {
	int w1, w2;
	val_t (int w1 = 0, int w2 = 0) : w1(w1), w2(w2) {}
	inline void Set(int x, int t) {
		x += DELTA;
		(w1 += (lo) power(base1, x, MOD1) * (MOD1 + t) % MOD1) %= MOD1;
		(w2 += (lo) power(base2, x, MOD2) * (MOD2 + t) % MOD2) %= MOD2;
	}
	val_t rot(int d) {
		val_t a = *this;
		a.w1 = (lo) a.w1 * power(base1, d, MOD1) % MOD1;
		a.w2 = (lo) a.w2 * power(base2, d, MOD2) % MOD2;
		return a;
	}
};
val_t val[N];
map <val_t, int> mp;

val_t operator + (val_t a, val_t b) {
	return val_t((a.w1 + b.w1) % MOD1, (a.w2 + b.w2) % MOD2);
}

bool operator < (val_t a, val_t b) {
	return make_pair(a.w1, a.w2) < make_pair(b.w1, b.w2);
}

int main(void) {
	read(n);
	scanf("%s", str + 1);
	int pos = 0;
	for (int i = 1; i <= n; i++) {
		val[i] = val[i - 1];
		if (str[i] == '+' || str[i] == '-')
			val[i].Set(pos, str[i] == '+' ? 1 : -1);
		else 
			pos += str[i] == '>' ? 1 : -1;
		_pos[i] = pos;
	}
	val_t S = val[n];
	lo ans = 0;
	for (int i = n; i >= 0; i--) {
		val_t to = S.rot(_pos[i]) + val[i];
		if (mp.count(to)) ans += mp[to];
		mp[val[i]]++;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 19456
/**
 * Created by hiramekun at 20:51 on 2019-12-22.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    string s, t;
    cin >> n;
    cin >> s >> t;
    string ans;
    rep(i, n) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split(' ')))

dif_min = 100

for p in range(1, n+1):
    s1 = sum(w[:p])
    s2 = sum(w[p:])
    
    if abs(s1-s2) < dif_min:
        dif_min = abs(s1-s2)

print(dif_min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int sx, sy, tx, ty;
void input() { cin >> sx >> sy >> tx >> ty; }
void solve() {
  int dx = tx - sx, dy = ty - sy;

  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U' << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
string str;
deque<char>dq;
int main()
{
    int n;
    while(cin>>n>>str)
    {
        int f= 0;
        for(int i=0; i<n; i++)
        {
            if(str[i]=='(')
                dq.pb('('), f++;
            else
            {
                if(f)f--;
                else dq.pf('(');
                dq.pb(')');
            }
        }
        if(f)
        {
            while(f--)
                dq.pb(')');
        }
        while(!dq.empty())
            printf("%c", dq.front()), dq.pop_front();
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
#define pi       const int pi=3.1415926535
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int ans=0;
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n)cin>>v[i];
  rep(j,n){
    if(v[v[j]-1]==j+1)ans++;}
    ans/=2;
A:cout<<ans;    
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N];
int main() {
    int n,z,w;
    scanf("%d%d%d",&n,&z,&w);
    int maxx=-INF,minn=INF;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);

    int res=0;
    if(n==1)
        res=abs(a[n]-w);
    else
        res=max(abs(a[n-1]-a[n]),abs(a[n]-w));
    printf("%d\n",res);
    return 0;
}

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

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

int a, b, c;
bool ok = false;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b >> c;
    if (a == b && b == c) {
        ok = true;
    }
    if (ok) cout << "Yes\n";
    else cout << "No\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

const int MAX = 50100;

int a[MAX], b[MAX], o[MAX], ur[MAX], uc[MAX];

int main() {
  int r, c, q;
  while (true) {
    cin >> r >> c >> q;
    if (r == 0 && c == 0 && q == 0) break;
    rep (i, q) {
      cin >> a[i] >> b[i] >> o[i];
    }
    rep (i, r) ur[i] = 0;
    rep (i, c) uc[i] = 0;
    int h = r, w = c;
    long long res = 0;
    rep (iii, q) {
      int i = q - iii - 1;
      //cout << i << " " << res << endl;
      if (a[i] == 0) {
	if (ur[b[i]] == 1) continue;
	--h;
	if (o[i] == 1) res += w;
	ur[b[i]] = 1;
      } else {
	if (uc[b[i]] == 1) continue;
	--w;
	if (o[i] == 1) res += h;
	uc[b[i]] = 1;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

double f(double x, int l, int r, int v) {
	if (x < l)return v + (l - x);
	else if (r < x)return v + (x - r);
	else return v;
}

int n, t[100], v[100];
double cnt[4000010];
vector<P> vec;
double a, b, k, l;
double ans;

signed main() {
	cin >> n;
	vec.push_back({ 0,0 });
	for (int i = 0; i < n; i++)cin >> t[i];
	for (int i = 0; i < n; i++)cin >> v[i];
	for (int i = 0; i < n; i++) {
		vec.push_back({ vec[i].first + t[i],v[i] });
	}
	vec.push_back({ vec[n].first,0 });
	for (double i = 0; i <= vec[n].first; i += 0.5) {
		double coun = f(i, 0, 0, 0);
		for (int j = 0; j <= n; j++) {
			coun = min(coun, f(i, vec[j].first, vec[j + 1].first, vec[j + 1].second));
		}
		int c = i * 2.0;
		cnt[c] = coun;
	}
	a = 0;
	k = 0;
	l = 0;
	for (int i = 2; i <= vec[n].first * 2; i++) {
		if (cnt[i - 1] < cnt[i])b = 0;
		else if (cnt[i] < cnt[i - 1])b = 1;
		else b = 2;
		if (a != b) {
			ans += (k + cnt[i - 1]) / 2.0 * ((i - 1 - l) / 2.0);
			a = b;
			k = cnt[i - 1];
			l = i - 1;
		}
	}
	ans += (k + cnt[vec[n].first * 2]) / 2.0*(vec[n].first * 2 - l) / 2.0;
	printf("%.10f", ans);
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long modinv(long a){long M=MOD,b=M,u=1,v=0;while(b)u-=a/b*v,swap(u,v),a%=b,swap(a,b);return (u%M+M)%M;}

long foo (long N) {
  if (N == 0) return 0;
  long result = foo(N-1) + (N * (N-1) / 2);
  return result % MOD;
}

int main(void) {
  cout.precision(12);

  long N, M, K;
  cin >> N >> M >> K;

  vector<long> memo(N*M+1);
  memo[0] = 1;
  for (long i = 1; i <= N*M; i++) {
    memo[i] = (memo[i-1] * i) % MOD;
  }

  // 置き方
  long puttings = memo[N*M];
  puttings = (puttings * modinv(memo[K])) % MOD;
  puttings = (puttings * modinv(memo[N*M - K])) % MOD;

  // 期待値
  /*
  pair<long, long> n_expect = make_pair(foo(N), N*N);
  pair<long, long> m_expect = make_pair(foo(M), M*M);
  */
  // pair<long, long> expect = make_pair(foo(N) * M * M + foo(M) * N * N, N * N * M * M);

  // K == N*M のときのコスト
  long a = foo(N) * M * M + foo(M) * N * N;
  a %= MOD;
  a = (a * modinv(memo[2])) % MOD;

  long x = (N * M) * (N * M - 1) / 2;
  x %= MOD;
  long y = K * (K-1) / 2;
  y %= MOD;
  y *= puttings;
  y %= MOD;

  long result = a;
  result *= y;
  result %= MOD;
  result *= modinv(x);
  result %= MOD;

  result *= 2;
  result %= MOD;

/*
  cout << "puttings: " << puttings << endl;
  cout << "a: " << a << endl;
  cout << "x: " << x << endl;
  cout << "y: " << y << endl;
*/

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 8064
#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-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int a[4], b[4];
	for (int i = 0; i < 4; ++i)
		scanf("%d", a + i);
	for (int i = 0; i < 4; ++i)
		scanf("%d", b + i);
	int s = accumulate(a, a + 4, 0);
	int t = accumulate(b, b + 4, 0);
	printf("%d\n", max(s, t));
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,a,b)	for(int i=a;i<=b;i++)
using namespace std;
const int N=2e5+5,M=6008;
int n,k,x,y,m;
string c;
int f[M][M];
int calc(int x1,int y1)
{
	int x2=x1+k-1,y2=y1+k-1;
	return f[x2][y2]-f[x1-1][y2]-f[x2][y1-1]+f[x1-1][y1-1];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;	
	m=2*k;
	memset(f,0,sizeof(f));
	rep(i,1,n)
	{
		cin>>x>>y>>c;
		if(c=="W")
			y+=k;
		x%=m,y%=m;
		x++,y++;
		f[x][y]++;
	}
	rep(i,1,m)
		rep(j,1,m)
			f[i+m][j]=f[i][j+m]=f[i+m][j+m]=f[i][j];
	for(int i=1;i<=2*m;i++)
		for(int j=1;j<=2*m;j++)
			f[i][j]=f[i][j]+f[i][j-1]+f[i-1][j]-f[i-1][j-1];
	int res=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=m;j++)
		{
			int cnt=calc(i,j)+calc(i+k,j+k);
		//	cnt+=calc(i-k,j-k)+calc(i-k,j+k)+calc(i+k,j-k)+calc(i+k,j+k);
		//	cnt+=calc(i,j+m)+calc(i+m,j);
		//	cnt+=calc(i-m,j)+calc(i+m,j)+calc(i,j-m)+calc(i,j+m);
			res=max(res,cnt);
		}
	}
	cout<<res<<endl;
	return 0;
	
}

Measured memory_bytes: 141312
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    int sup = *max_element(a.begin(), a.end());
    int idx;
    for (int i=0; i<n; i++) {
        if (a[i] == sup) {
            idx = i; break;
        }
    }
    a.erase(a.begin() + idx);
    int ans = *max_element(a.begin(), a.end());
    for (int i=0; i<n; i++) {
        if (i == idx) cout << ans << '\n';
        else cout << sup << '\n';
    }
    
    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    for (int i = 1; i < 999; i++)
    if (i*(i+1)/2-a == (i+1)*(i+2)/2-b && i*(i+1)/2-a > 0) {
        cout << i*(i+1)/2-a;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

class Program{
	static void Main(){
		string s;
		while((s = Console.ReadLine()) != null){
			int w = int.Parse(s);
			for(int n = 1;; n *= 2){
				if(w % (n*2) != 0){
					Console.Write(n);
					w -= n;
					if(w > 0) Console.Write(" ");
					else break;
				}
			}
			Console.WriteLine();
		}
	}
}

Measured memory_bytes: 9084
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

void solve()
{
    ll n, m;
    cin >> n >> m;
    cout << (1 << m) * (m * 1900 + (n - m) * 100);
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

ll dis[111111], dis2[111111];
vector<ll> g[111111];
void dfs(ll x, ll p, ll d) {
	for (ll e : g[x])
		if (e != p)
			dfs(e, x, d + 1);
	dis[x] = d;
}
void dfs2(ll x, ll p, ll d) {
	for (ll e : g[x])
		if (e != p)
			dfs2(e, x, d + 1);
	if (d < dis[x])
		dis2[x] = d;
}

int main(){
	FASTIO;
	ll n, u, v; cin >> n >> u >> v;
	for ( int k = 0; k < n - 1; k++ ){
		ll x, y; cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(v, v, 0);
	memset(dis2, -1, sizeof dis2);
	dfs2(u, u, 0);
	ll ans = 0;
	for ( int k = 1; k <= n; k++ )
		if (dis2[k] != -1){
			/*
			if ((dis[k] - dis2[k]) % 2 == 0)
				ans = max(ans, dis[k] - 1);
			else
			*/
			ans = max(ans, dis[k]);
		}
	//debug(dis, n + 1);
	//debug(dis2, n + 1);
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	string s;
	cin>>s;
	bool cant_sorry = false;
	for(int i = 0 ; i < s.size() ; i++)
	{
		if(i&1)
		{
			if(s[i]=='L'||s[i]=='U'||s[i]=='D')
				continue;
			else
			{
				cant_sorry = true;
				break;
			}
		}
		else
		{
			if(s[i]=='R'||s[i]=='U'||s[i]=='D')
				continue;
			else
			{
				cant_sorry = true;
				break;
			}
		}
	}
	cout<<((cant_sorry)?"No":"Yes")<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static final int MAX  = 1000001;
	Scanner sc;
	boolean[] a;

	Main(){
		sc = new Scanner( System.in );
		a = new boolean[ MAX ];
		a[ 0 ] = false;
		a[ 1 ] = false;
		for( int i = 2; i < a.length; i++ ){
			a[ i ] = true;
		}
		for( int i = 2; i < MAX; i++ ){
			if( !a[ i ] ){ continue; }
			for( int j = i * 2; j < MAX; j += i ){
				a[ j ] = false;
			}
		}
	}
	void run(){
		while( true ){
			int a0 = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			int c = 0;
			int ans = 0;
			if( a0 == 0 && d == 0 && n == 0){ return; }
			for( int cur = a0; ; cur += d ){
				if( a[ cur ] ){
					if( ++c == n ){
						ans = cur;
						break;
					}
				}
			}
			System.out.println( ans );
		}
	}
	public static void main( String[] args ){
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<stdio.h>

int main(){

  int a,b,ans;
  int i=0;
  ans = 0;

  scanf("%d %d",&a,&b);

  while(i <= 1){
    if(a >= b){
      ans = ans + a;
      a--;
    }else if(a < b){
      ans = ans + b;
      b--;
    }
    i++;
  }

  printf("%d\n",ans);

  return (0);

}



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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMinimum(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMaximum(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {


    string N;
    cin >> N;

    string ans = "No";
    for (int i = 0; i < 3; ++i) {
        if(N[i] == '7')
        {
            ans = "Yes";
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(){
    int N;
    while(scanf("%d",&N)!=EOF){
            int count1 = 0,count2 = 0,count4 = 0;
        for(int i = 0;i<N;i++){
            int x;
            scanf("%d",&x);
            if(x%4==0){
                count4++;
            }else if(x%2 == 0&&  x%4!=0){
                count2++;
            }else{
                count1++;
            }
        }
    if(count2>0 && count1<=count4){
        printf("Yes");
    }else if(count2==0 && count1<=count4+1){
        printf("Yes");
    }else{
        printf("No");
    }
    }
    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())

if a <= 0 and 0 <= b:
    print("Zero")
elif a < 0 and b < 0:
    if (abs(a)-abs(b)+1) % 2 == 1:
        print("Negative")
    else:
        print("Positive")
else:
    print("Positive")


Measured memory_bytes: 61688
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n; cin>>n;
    string S;
    cin>>S;
    int s[n],a[150]={},b[150]={};
    int t;
    for(int i=0;i<n;i++){
        s[i]=S[i];
    }
    int k=0;
    int ans=0,Ans=0;
    while(k<n-1){
        ans=0;
        for(int i=90;i<150;i++){
            a[i]=0; b[i]=0;
        }
        for(int i=0;i<=k;i++){
            t=s[i]; a[t]++;
        }
        for(int i=k+1;i<n;i++){
            t=s[i]; b[t]++;
        }
        for(int i=90;i<150;i++){
            if(a[i]>0&&b[i]>0){
                ans++;
            }
        }
        Ans=max(Ans,ans);
        k++;
    }
    cout<<Ans<<endl;
    
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		char[] chars = input.toCharArray();
		
		if(chars[1] == chars[2] && (chars[0] == chars[1] || chars[2] == chars[3])){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
	}

}


Measured memory_bytes: 21204
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 1000001;
//
//
void solve(){
    int n;
    cin>>n;
    vector<ll> vec(n);
    ll g = 0;
    for(int i = 0; i < n; i++){
        cin>>vec[i];
        g = __gcd(g, vec[i]);
    }
    vector<int> hold(MAX, 0);
    int flag = 1;
    for(ll num : vec){
        for(ll i = 2; i*i <= num; i++){
            if(num%i == 0)
                hold[i]++;
            while(num%i == 0)
                num /= i;
            if(hold[i] > 1 ){
                // cout<<i;
                flag = 0;
                goto there;
            }
        }
        if(num != 1)
            hold[num]++;
        if(hold[num] > 1){
            flag = 0;
            goto there;
        }
    }
    there:
    if(flag){
        cout<<"pairwise coprime\n";
    }
    else if(g == 1){
        cout<<"setwise coprime\n";
    }
    else
        cout<<"not coprime\n";
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 15080
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var rdr = bufio.NewScanner(os.Stdin)

func main() {
	rdr.Scan()
	str := rdr.Text()
	if strings.Contains(str, "a") && strings.Contains(str, "b") && strings.Contains(str, "c"){
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

Measured memory_bytes: 640