akhauriyash/Code-Regression huggingface dataset:
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
#define mod2 998244353

using namespace std;
ll n;

int main() {
	int a, b;
	cin >> a >> b;
	int c = b - a;
	int t = 0;
	reps(i, c) {
		t += i;
	}
	cout << t - b << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N,M=map(int,input().split())
ans=0
friendset=[0]*N
pset=set()#まだどの友人グループにも属していない人
for h in range(N):
    pset.add(h)
    friendset[h]=set()
for p in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    friendset[A].add(B)
    friendset[B].add(A)
#print(friendset)
while(len(pset)!=0):
    kouho=1
    d=deque()
    i=pset.pop()
    d.append(i)
    while(len(d)!=0):
        person=d.popleft()
        for k in friendset[person]:
            if k in pset:
                #print(person,k)
                d.append(k)
                pset.remove(k)
                friendset[k].remove(person)
                kouho+=1
    ans=max(kouho,ans)
print(ans)

Measured memory_bytes: 86184
#include<iostream>
#include<iostream>
#include<algorithm>
using namespace std;
int a;
int sum,ge;
int main()
{
	cin>>a;
	sum=(a%1000)/100;
	ge=a%10;
	if(sum==ge)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include<cmath> 

int main()
{

    long long x;
    std::cin >> x;

    long long div = x / 11;
    long long mod = x % 11;
    long long ans1 = 2 * div, ans2 = 2*div;

    if(mod) {
    if(mod > 5) {
        ans1 += 2;
    } else  {
        ans1++;
    }

    if(mod > 6) {
        ans2 += 2;
    }
    else
    {
        ans2++;
    }
    }

    std::cout << std::min(ans1, ans2) << "\n";
}

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int num(char c) {
  if (isdigit(c)) {
    return c - '0';
  } else {
    return 10;
  }
}
bool comp(int a, int b) {
  if(b>21) return 0;
  else return a<b;
}

int res;
bool ff;
void dfs(const vector<char> &v, int sum, int now, bool f) {
  if (now == v.size()) {
    if (comp(res, sum)) {
      ff = f;
      res = sum;
    }
    return;
  }
  if (v[now] == 'A') {
    dfs(v,sum+1,now+1, f);
    dfs(v,sum+11,now+1, 1);
  } else {
    dfs(v,sum+num(v[now]),now+1, f);
  }
}

int hoge(const vector<char> &v) {
  res = 0;
  ff = 0;
  dfs(v,0,0,0);
  return res;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    vector<char> v(2);
    cin >> v[0] >> v[1];
    char cc[8];
    REP(i, 8) {
      cin >> cc[i];
    }
    REP(i,8) {
      if (hoge(v) == 21 || hoge(v) == 0) break;
      
      if (hoge(v)<=16) {
        v.push_back(cc[i]);
      } else if (hoge(v)==17 && ff) {
        v.push_back(cc[i]);
      }
      // FOR(it, v) 
      //   cout << *it << " ";
      // cout << endl;
    }
    if (hoge(v)==0)
      cout << "bust" << endl;
    else if (v.size() == 2 && hoge(v)==21)
      cout << "blackjack" << endl;
    else cout << hoge(v) << endl;
  }
}

Measured memory_bytes: 0
n = int(input())
lines = []
for i in range(n):
    lines.append(list(map(int, input().split())))

prev = [0, 0, 0]
is_possible = "Yes"

for line in lines:
    pt, px, py = prev
    t, x, y = line
    dt = t - pt
    dx = x - px
    dy = y - py
    if dt < dx + dy:
        is_possible = "No"
        break

    if not dt & 1 == (dx + dy) & 1:
        is_possible = "No"
        break

    prev = line

print(is_possible)


Measured memory_bytes: 27380
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto ab = readints;
    int a = ab[0], b = ab[1];
    writeln(a <= b ? a : a - 1);
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>


int main(void){
	int N,i;
	long int sum,num;
 	scanf("%d",&N);
 	sum = 0;
 	for(i=1;i<=N;i++){
 		num = N/i;
 		//printf("%d,%d:",i,num);
 		//printf("%d\n",(((num + 1)*i*num)/2));
 		sum += ((num + 1)*i*num)/2;
 	}
 	printf("%ld\n",sum);
	return 0;
}



Measured memory_bytes: 1728
import numpy as np
h, w = map(int,input().split())

map=[list(input()) for _ in range(h)]
map = [[1 if s == '.' else 0 for s in map[i]] for i in range(h)]

map = np.array(map,dtype=int)
l=map.copy()
r=map.copy()
u=map.copy()
d=map.copy()

for i in range(1,h):
    u[i] += u[i-1]
    u[i] *= map[i]
for i in range(h-1, 0, -1):
    d[i-1] += d[i]
    d[i-1] *= map[i-1]
for i in range(1,w):
    l[:, i] += l[:, i-1]
    l[:, i] *= map[:, i]
for i in range(w-1, 0, -1):
    r[:, i-1] += r[:, i]
    r[:, i-1] *= map[:, i-1]

print((u+d+l+r).max()-3)

Measured memory_bytes: 251096
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n,A,B,x,y; LL ans,ret;
int main(){
	cin >> n >> A >> B;
	ans = max(abs(n-A),abs(n-B));
	ans = min(ans,max(abs(A-1),abs(B-1)));
	if (A%2==B%2){ ans = min(ans,abs(A-B)/2); }
	else{
		x = A,y = B,ret = 0;
		x -= A-1,y -= A-1,ret += A-1;
		x; y--; ret++;
		ret += abs(x-y)/2;
		ans = min(ans,ret);
		
		x = A,y = B,ret = 0;
		x += n-B,y += n-B,ret += n-B;
		x++; y; ret++;
		ret += abs(x-y)/2;
		ans = min(ans,ret);
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n,x,m = tuple([int(t)for t in input().split()])

    a = x
    s = a

    nextvalues = [a]
    values = set([a])

    for i in range(1,n):
        a = a*a % m
        if a in values:
            idx = nextvalues.index(a)
            size = i-idx
            sumofsubset = sum(nextvalues[idx:i])
            s += sumofsubset*((n-i)//size)+sum(nextvalues[idx:idx+(n-i)%size])
            break
        s += a
        nextvalues.append(a)
        values.add(a)
    print(s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 13112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
  
int s[21][41];
int main(void){
    int r, n, xl, xr, h;
    while(cin >> r >> n && r) {
        rep(i, 21) rep(j, 41) s[i][j] = 0;
        rep(i, n) {
            cin >> xl >> xr >> h;
            for(int y=0; y<h; ++y) {
                for(int x=xl+20; x<xr+20; ++x) {
                    s[y][x] = 1;
                }
            }
        }
        double mint = numeric_limits<double>::max();
        rep(y, 21) {
            for(int x=-r+20; x<r+20; ++x) {
                if(s[y][x] == 0) {
                    double t;
                    if(x<20) t = (double) y+r-sqrt(pow((double)r,2.0)-pow(x-19.0, 2.0));
                    else t = (double) y+r-sqrt(pow((double)r,2.0)-pow(x-20.0, 2.0));
                    mint = min(mint, t);
                }
            }
        }
        printf("%.4lf\n", mint);
    }
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define se second
#define fi first
using namespace std;
const int maxn = 2e3 + 10, mod = 1e9 + 7;
typedef pair<int,int> ii;
typedef pair<long long, long long> ll;
int a[32]= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

void _accepted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int main()
{
      _accepted_by_one_hit_();

      int x; cin >> x;
      cout << a[--x];
      
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int A = 0;
    int B = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &A, &B);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = A*B-A-B+1;
    
    if(1 == 0){
      /* 真の場合の処理 */
      
    }else{
      /* 偽の場合の処理 */
      
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}


Measured memory_bytes: 256
s=input()

#RRLLRRLLL
#022002200
#RLまでの距離が

result=[0]*len(s)
checked=[0]*len(s)

i=1
while i<len(s):
    if s[i-1]=="R" and s[i]=="L":
        

        #左を探索
        L=i-1
        j=0
        while L>=0:
            if s[L]=="R":
                if j%2==0:
                    result[i-1]+=1
                else:
                    result[i]+=1
            else:
                break
            j+=1
            L-=1

        #右を探索
        R=i
        j=0
        while R<len(s):
            if s[R]=="L":
                if j%2==0:
                    result[i]+=1
                else:
                    result[i-1]+=1
            else:
                i=R-1
                break
            j+=1
            R+=1

    i+=1

print(" ".join(map(str,result)))

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

namespace AtCoder.DP
{
    class EDPC_H
    {
        public static void Main()
        {
            const long mod = 1000000007;

            var hw = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var h = hw[0];
            var w = hw[1];

            var map = new char[h][];
            var dp = new long[h + 1, w + 1];

            for (int y = 0; y < h; y++)
                map[y] = Console.ReadLine().ToArray();

            dp[0, 1] = 1;
            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                    if (map[y][x] == '.')
                        dp[y + 1, x + 1] = (dp[y, x + 1] + dp[y + 1, x]) % mod;
            Console.WriteLine(dp[h, w]);
        }
    }
}


Measured memory_bytes: 26584
#include <stdio.h>

int min=1000000 ;


int main(void){
    int n,x ;
    scanf ("%d%d",&n,&x) ;
    
    for (int i=0; i<n; i++ ){
        
        int m[i] ;
        scanf ("%d",&m[i]) ;
        
        x -= m[i] ;
        
        if ( min>m[i] ){
            min = m[i] ;
        }
        
    }
    
    printf ("%d\n",n+x/min) ;

    return 0 ;
}

Measured memory_bytes: 128
from collections import defaultdict
from heapq import heappush, heappop
class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()
        
class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
N = int(input())
gp = Graph()
for _ in range(N-1):
    s,d,w = [int(x) for x in input().split()]
    gp.add_edge(s-1,d-1,w)
    gp.add_edge(d-1,s-1,w)

Q,K = [int(x) for x in input().split()]
xy = [[int(x) for x in input().split()]for _ in range(Q)]
di = Dijkstra(gp,K-1)
for x,y in xy:
    print(di.shortest_distance(x-1)+di.shortest_distance(y-1))


Measured memory_bytes: 92560
S=gets.chomp
ans=l=r=0
while l<S.size
  l+=1 until l==S.size || "ACGT".include?(S[l])
  r+=1 while r<S.size && "ACGT".include?(S[r])
  ans=[r-l,ans].max
  l=r+=1
end
p ans


Measured memory_bytes: 1788
import java.util.Scanner;

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

        // 入力(n)
        int n = sc.nextInt();

        int payment = n * 800;
        int rtnMoney = (n / 15) * 200;
        System.out.println(payment - rtnMoney);
        sc.close();
    }
}

Measured memory_bytes: 35520
N,X = (int(x) for x in input().split())
L = [int(x) for x in input().split()]
s = 0
i = 0
while (s <= X):
  if i >= N:
    print(N+1)
    quit()
  else:
    s = s + L[i]
    i = i + 1
print(i)

Measured memory_bytes: 2940
#include<stdio.h>
int main(void){
  int n, l[12], m, k=0, a, i;
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
  scanf("%d", &l[i]);
  }
  
  m=l[0];
  a=0;
    for(i=1; i<n; i++){
  if(m<l[i]){
    m=l[i];
    a=i;
  }
    }
  
      for(i=0; i<n; i++){
        if(i!=a){
          k+=l[i];
        }
    }
  
  if(m<k){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}


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

const int Max_n = 103;
int F[Max_n][10];
int P[Max_n][10];

int main(){
    int N;
    long long ans = -1000000000000;
    cin >> N;

    for(int i =0; i < N; i++) for(int j=0; j < 10; j++) cin >> F[i][j];
    for(int i =0; i < N; i++) for(int j=0; j <= 10; j++) cin >> P[i][j];
    
    for(int i =1; i < 1024; i++){
        
        long long temp_ans = 0;
        for(int n=0; n < N; n++){
            int state = i;
            int c=0;
            for(int j=0; j < 10; j++){   
                if((state %2) == 1){
                    c += F[n][j];
                }
                state /= 2;
            }
            temp_ans += P[n][c];
        }
        ans = max(ans, temp_ans);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	vector<int> nums;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (
		(a != 1 && b != 1 && c != 1 && d != 1) ||
		(a != 9 && b != 9 && c != 9 && d != 9) ||
		(a != 7 && b != 7 && c != 7 && d != 7) ||
		(a != 4 && b != 4 && c != 4 && d != 4)) {
		cout << "NO";
	}
	else {
		cout << "YES";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

    for (long i = 0; i < n - 1; i++) {
        if (a[i] > a[i + 1]) {
            ans += a[i] - a[i + 1];
            a[i + 1] = a[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4840
n,m = (int(x) for x in input().split())

table = [[0] for i in range(n)]
vector = [0 for j in range(m)]

# input table
i = 0
while i < n:
  table[i] = list(int(x) for x in input().split())
  i += 1

# input vector
i = 0
while i < m:
  vector[i] = int(input())
  i += 1

# calc C
for i in table:
  sum = 0
  for idx,j in enumerate(i):
    sum += j * vector[idx]
  print (sum)


Measured memory_bytes: 6036
#include<iostream>
#include<algorithm>
#define MAX_N 100000
#define MAX_E 200000
#define FOR(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
class uft{
public:
  int par[MAX_N];//親
  int rank[MAX_N];//木の深さ
  uft(int N);//コンストラクタ
  int find(int x);
  void unite(int x,int y);
  bool same(int x,int y);
};
uft::uft(int N){//コンストラクタ
  for(int i=0;i<N;i++){
    par[i]=i;
    rank[i]=0;
  }
}
int uft::find(int x){//xの根を返す
  if(par[x]==x) return x;//根の親は自分自身
  else return par[x]=find(par[x]);//再起で親を辿る
}
void uft::unite(int x,int y){//x,yを併合
  x=find(x);
  y=find(y);
  if(x==y) return ;//根が同じなら併合する必要なし

  if(rank[x]<rank[y]) par[x]=y;//木の深い方に浅い方をつける
  else{
    par[y]=x;
    if(rank[x]==rank[y]) rank[x]++;//同じ深さなら深さを増やす
  }
}
bool uft::same(int x,int y){//x,yが同じグループにいるかどうかを返す
  return find(x)==find(y);//根が同じかどうかを判断する
}
struct edge{//辺の情報
  int from,to,cost;
};
int V,E;//頂点の数、辺の数
edge e[MAX_E];
P px[MAX_N],py[MAX_N];
bool comp(const edge& e1,const edge& e2){//コストでソートするための準備
  return e1.cost<e2.cost;
}
ll kruskal(){
  ll res=0;
  sort(e,e+E,comp);//コストの小さい順にソート
  uft u(V);//頂点数VでUnionFind木を作成
  FOR(i,0,E){
    int f=e[i].from,t=e[i].to,c=e[i].cost;
    if(!u.same(f,t)){
      res+=c;
      u.unite(f,t);
    }
  }
  return res;
}
int main(){
  cin >> V;
  E=2*(V-1);
  FOR(i,0,V){
    cin >> px[i].first >> py[i].first;
    px[i].second=i;py[i].second=i;
  }
  sort(px,px+V);sort(py,py+V);
  FOR(i,0,V-1){
    e[i].from=px[i+1].second;
    e[i].to=px[i].second;
    e[i].cost=px[i+1].first-px[i].first;
    e[i+V-1].from=py[i+1].second;
    e[i+V-1].to=py[i].second;
    e[i+V-1].cost=py[i+1].first-py[i].first;
  }
  cout << kruskal() << "\n";
  return 0;
}












Measured memory_bytes: 4992
#include<stdio.h>

int Sort(int A[], int N) {
	int i, j;
	int count = 0;
	int min;
	for (i = 0; i < N; i++) {
		min = i;
		for (j = i; j < N; j++) {
			if (A[j] < A[min]) {
				min = j;
			}
		}
		if (i != min) {
			int temp = A[i];
			A[i] = A[min];
			A[min] = temp;
			count++;
		}
	}
	return count;
}

int main() {
	int A[100];
	int N;
	int i, count;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	count = Sort(A, N);
	for (i = 0; i < N; i++) {
		if (i > 0)
			printf(" ");
		printf("%d", A[i]);
	}
	printf("\n%d\n", count);
	return 0;
}


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

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    string a[3];
    for(int i=0;i<3;++i) cin >> a[i];

    int count = 0;
    for(int i=0;i<n;++i) {
        int cnt[3] = {0, 0, 0};
        for(int j=0;j<3;++j) {
            for(int k=0;k<3;++k) {
                if(j != k && a[j][i] != a[k][i]) {
                    ++cnt[j];
                }
            }
        }
        count += *min_element(cnt, cnt+3);
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// const int INF = 2100100100;
const int MOD = 1e9 + 7;

int dp[110000][13];


int main() {
  string S; cin >> S;
  int len = S.size();
  reverse(S.begin(), S.end());

  if (S[0] == '?') {
    REP(change, 10) {
      dp[0][change] = 1;
    }
  }
  else {
    dp[0][S[0] - '0'] = 1;
  }

  int base = 1;
  for(int i = 1; i < len; i++) {
    base *= 10;
    base %= 13;
    

    if (S[i] == '?') {
      REP(change, 10) {
        REP(old_r, 13) {
          int new_r = (base * change + old_r) % 13;
          // 貰うDP
          dp[i][new_r] += dp[i - 1][old_r];
          dp[i][new_r] %= MOD;
        }
      }
    }
    else {
      int change = S[i] - '0';
      REP(old_r, 13) {
        int new_r = (base * change + old_r) % 13;
        dp[i][new_r] += dp[i - 1][old_r];
        dp[i][new_r] %= MOD;
      }
    }
  }
  // REP(i, len) cout << dp[i][5] << endl;
  cout << dp[len - 1][5] << endl;

  return 0;
}

Measured memory_bytes: 5584
import sys
input = sys.stdin.readline
import numpy as np

H,W,D = map(int,input().split())
N = H*W
ND = N//D

# 各数値の書かれている位置, 1-indexed
X = np.zeros((D,ND+1),dtype=np.int64)
Y = np.zeros((D,ND+1),dtype=np.int64)

for x in range(H):
  row = input()
  for y,n in enumerate(row.split()):
    n = int(n)
    q,r = n//D,n%D
    X[r,q] = x
    Y[r,q] = y

# 0D+d から nD+d への移動コスト
MAGIC = np.zeros_like(X)
MAGIC[:,1:] = (np.abs(np.diff(X,axis = 1)) + np.abs(np.diff(Y,axis = 1))).cumsum(axis = 1)

Q = int(input())
for _ in range(Q):
  l,r = map(int,input().split())
  d = l%D
  print(MAGIC[d,r//D] - MAGIC[d,l//D])


Measured memory_bytes: 18712
import sys
from collections import deque
from functools import lru_cache
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(input())
    P = [tuple(read_values()) for _ in range(N)]
    mX = V(min)
    MX = V(max)
    mY = V(min)
    MY = V(max)

    for p in P:
        x = p[0] + p[1]
        y = p[0] - p[1]
        mX.ud(x)
        MX.ud(x)
        mY.ud(y)
        MY.ud(y)
    
    print(max(MX.v - mX.v, MY.v - mY.v))


if __name__ == "__main__":
    main()



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

using namespace std;
typedef long long ll;
int main()
{
    ll x,y;
    scanf("%lld%lld",&x,&y);
    int ans=1;
    while(1){
        if(x*2<=y){
            x*=2;
            ans++;
        }
        else break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    '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'
};

int main(){
    ll n;
    string S;
    cin >> n;
    ll cnt[52][27];
    llrep(i,52){
        llrep(j,27){
            cnt[i][j]=0;
        }
    }
    llrep(i,n){
        cin >> S;
        llrep(j,S.size()){
            cnt[i][S[j]-'a'] ++;
        }
    }
    ll minsize[27];
    // rep(i,27){
    //     min[i]=0;
    // }
    llrep(i,26){
        ll min  = INF;
        llrep(j,n){
            if (cnt[j][i] < min){
                min = cnt[j][i];
            }
        }
        minsize[i] = min;
    }
    llrep(i,26){
        llrep(j,minsize[i]){
            cout << alphabet[i];
        }
    }
    cout << "" << endl;
    // cout << 'a'-'a' << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define WHITE 0
#define BRACK 1

int notend();
int a[101][101],d[101],c[101],n;

int main(){
  int i,j,w=0,min,minj;

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    d[i] = INFINITY;
    c[i] = WHITE;
    for(j = 1; j <= n; j++){
      scanf("%d",&a[i][j]);
    }
  }

  c[1] = BRACK;
  i = 1;
  while(notend()){
    for(j = 1; j <= n; j++){
      if(a[i][j] != -1 && a[i][j] < d[j])
	d[j] = a[i][j];
    }
    min = INFINITY;
    for(j = 1; j <= n; j++){
      if(d[j] < min && c[j] != BRACK){
	min = d[j];
	i = j;
      }
    }
    w += min;
    c[i] = BRACK;
  }
      
  printf("%d\n",w);
  
  return 0;
}
      
int notend(){
  int i;
  for(i = 1; i <= n; i++){
    if(c[i] == WHITE)
      return 1;
  }
  return 0;
}



Measured memory_bytes: 2028
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	char x,y;
	int t,r;
	scanf("%c %c",&x,&y);
   	char str[6]={'A','B','C','D','E','F'};
   	int a[6];
   	for(int i=0;i<6;i++)
   	{
   		a[i]=str[i]-'A'+10;
	}
   	for(int i=0;i<6;i++)
   	{
   	   if(str[i]==x)
		  t=a[i];
	   if(str[i]==y)
		  r=a[i];
    }
   	if(t<r)
   	   printf("<\n");
   	else if(t>r)
   	   printf(">\n");
   	else
   	   printf("=\n");
   	return 0;
} 

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

int main(){
  long long N,d;
 d=0;
  cin>>N;
  vector<long long>a(N);
    for (int i=0;i<N;i++){
      cin>>a[i];
    }
  for(int i=0;i<N;i++){
    while(a[i]%2!=1){
      a[i]/=2;
      d++;
    }
  }
      cout<<d<<endl;

}


Measured memory_bytes: 384
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static final int INF = 1_000_000_000;
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    SegmentTree tree = new SegmentTree(N + 1);
    int[] next = new int[N + 1];
    tree.update(N, 0);
    for (int i = N - 1; i >= 0; i--) {
      if (s[i] == '0') {
        Cell min = tree.query(i + 1, i + 1 + M);
        tree.update(i, min.value + 1);
        next[i] = min.pos;
      }
    }
    if (tree.query(0, 1).value == INF) {
      System.out.println(-1);
    } else {
      StringBuilder sb = new StringBuilder();
      int p = 0;
      while (p < N) {
        int q = next[p];
        sb.append(q - p).append(' ');
        p = q;
      }
      sb.setLength(sb.length() - 1);
      System.out.println(sb.toString());
    }
  }

  private static class SegmentTree {
    private int n;
    private final Cell[] dat;

    private SegmentTree(int tmpn) {
      n = 1;
      while (n < tmpn) {
        n <<= 1;
      }
      dat = new Cell[n * 2 - 1];
      for (int i = 0; i < n * 2 - 1; i++) dat[i] = new Cell(-1, INF);
    }

    public Cell query(int left, int right) {
      return query(left, right, 0, 0, n);
    }

    private Cell query(int a, int b, int k, int l, int r) {
      if (r <= a || b <= l) return new Cell(-1, INF);
      if (a <= l && r <= b) return dat[k];
      Cell vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      Cell vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      if (vr.value < vl.value) return vr;
      return vl;
    }

    public void update(int k, int value) {
      int l = k + n - 1; // the number of non-leaf nodes is 2 * n - 1 - n = n - 1
      dat[l].pos = k;
      dat[l].value = value;
      while (l > 0) {
        l = (l - 1) / 2;
        Cell min = dat[l * 2 + 2].value < dat[l * 2 + 1].value ? dat[l * 2 + 2] : dat[l * 2 + 1];
        dat[l].pos = min.pos;
        dat[l].value = min.value;
      }
    }
  }

  private static class Cell {
    private int pos;
    private int value;

    private Cell(int pos, int value) {
      this.pos = pos;
      this.value = value;
    }
  }
}


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

struct RollingHash {
    vector<long long> hash, power;
    const int seed = 10007, mod  = 1e9 + 7;

    RollingHash(const string &s) {
        int n = (int)s.size();
        hash.assign( n + 1, 0);
        power.assign(n + 1, 1);
        for(int i = 0; i < n; ++i) power[i+1] = power[i] * seed % mod;

        for(int i = 0; i < n; ++i) {
            hash[i+1]  = (hash[i] * seed + s[i]) % mod;
            power[i+1] = power[i] * seed % mod;
        }
    }

    // [l, r)
    long long get_hash(int l, int r) {
        long long ret = (hash[r] - hash[l] * power[r-l] % mod + mod) % mod;
        return ret;
    }
};

struct UnionFind {
    vector<int> par, weight;
    UnionFind(int n) : par(n,-1), weight(n) {}
    bool unite(int x, int y, int w = 0) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y), w = -w;
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) {
        if(par[x] < 0) return x;
        int r = root(par[x]);
        return par[x] = r;
    }
    int sizeOf(int x) { return -par[root(x)]; }
};

int main() {
    string s,t; cin >> s >> t;
    int n = s.size();
    s = s + s + s;
    while(t.size()*2 > s.size()) s += s;

    int N = s.size();
    int m = t.size();
    vector<bool> match(N);

    RollingHash rh1(s), rh2(t);
    unsigned long long thash = rh2.get_hash(0, m);
    
    for(int i=0; i < N - m; ++i) {
        if(rh1.get_hash(i, i + m) == thash) match[i] = true;
    }

    // loop check & count
    UnionFind uf(N);
    for(int i = 0; i < n; ++i) {
        if(match[i] && match[(i + m) % n]) {
            if(!uf.unite(i, (i + m) % n)) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < N; ++i) if(match[i]) ans = max(ans, uf.sizeOf(i));
    cout << ans << endl;
    return 0;
}

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

int main()
{
    string s,t,u;
    cin>>s;
    int f=0;
    int ans=0;
    for(int i=0;i<s.length();i++)
    {
        t+=s[i];
        if(t!=u)
        {
            ans++;
            u=t;
            t="";
        }

    }
    cout<<ans<<endl;

}

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


int main(){
ll N, A,B;
cin>>N>>A>>B;
ll ans;
if(A%2 == B%2) ans = (B-A)/2;
else{
ans = min(A-1,N-B)+1+((B-A-1)/2);

}
cout<<ans<<endl;
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi=vector<int>;
using vii=vector<vi>;
using vl=vector<ll>;
using vll=vector<vl>;
using tpi=tuple<int, int, int>;

int main() {
    using vt=vector<tpi>;
    int N;
    cin >> N;
    vt tp;
    for (auto i = 0; i < N; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        tp.emplace_back(a, b, c);
    }

    vt dp(N);
    dp.at(0) = tp.at(0);
    for (auto i = 1; i < N; i++) {
        auto a = get<0>(tp.at(i)) + max(get<1>(dp.at(i - 1)), get<2>(dp.at(i - 1)));
        auto b = get<1>(tp.at(i)) + max(get<0>(dp.at(i - 1)), get<2>(dp.at(i - 1)));
        auto c = get<2>(tp.at(i)) + max(get<0>(dp.at(i - 1)), get<1>(dp.at(i - 1)));
        dp.at(i) = tpi(a, b, c);
    }

    auto ans = max(get<0>(dp.at(N - 1)), get<1>(dp.at(N - 1)));
    ans = max(ans, get<2>(dp.at(N - 1)));

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


Measured memory_bytes: 2676
m, n = input().split()
m = int(m)
n = int(n)
a = []
for i in range(m):
  row = input().rstrip()
  x = 0
  for c in row:
    x *= 2
    if c == "#":
      x += 1
  a.append(x)

b = []
for i in range(n):
  row = input().rstrip()
  x = 0
  for c in row:
    x *= 2
    if c == "#":
      x += 1
  b.append(x)
c = 2 ** n
found = False
for i in range(m - n + 1):
  for j in range(m - n + 1):
    if found:
      break
    found = True
    for k in range(n):
      if (((a[i+k] >> (m - n - j)) ^ b[k]) % c) != 0:
        found = False
        break
if found:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()

	for i := 1; i < 10; i++ {
		for j := 1; j < 10; j++ {
			if i*j == n {
				fmt.Println("Yes")
				return
			}
		}
	}

	fmt.Println("No")
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
inline void print(int x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) print(x/10);
     putchar(x%10+'0');
}
string s;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s;
	int l=s.size();
	cout<<s[0]<<l-2<<s[l-1]<<endl;
	//fclose (stdin);
	//fclose (stdout);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    int n; cin>>n;
    vector<int> l(n),r(n);
    rep(i,n){
        cin>>l.at(i)>>r.at(i);
        r.at(i)=-r.at(i);
    }

    sort(all(l),greater<int>());
    sort(all(r),greater<int>());
    int ans=0,sum=0;
    rep(i,n){
        sum+=l.at(i);
        chmax(ans,sum);
        sum+=r.at(i);
        chmax(ans,sum);
    }
    sum=0;
    rep(i,n){
        sum+=r.at(i);
        chmax(ans,sum);
        sum+=l.at(i);
        chmax(ans,sum);
    }
    cout<<ans*2<<endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template<typename G>
struct LowLink {
    const G &g;
    vector<int> used, ord, low;
    vector<int> articulation;
    vector<pair<int, int> > bridge;
    LowLink(const G &g):g(g) {};
    int dfs(int idx, int k, int par) {
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_articulation = false;
        int cnt = 0;
        for (auto &to : g[idx]) {
            if (!used[to]) {
                ++cnt;
                k = dfs(to, k, idx);
                low[idx] = min(low[idx], low[to]);
                is_articulation |= ~par && low[to] >= ord[idx];
                if (ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int)to));
            } else if (to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        is_articulation |= par == -1 && cnt > 1;
        if (is_articulation) articulation.push_back(idx);
        return k;
    };
    virtual void build() {
        used.assign(g.size(), 0);
        ord.assign(g.size(), 0);
        low.assign(g.size(), 0);
        int k = 0;
        for (int i = 0; i < g.size(); i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    };
};
template<typename G>
struct TwoEdgeConnectComponents : LowLink<G> {
    using LL = LowLink<G>;
    vector<int> comp;
    TwoEdgeConnectComponents(const G &g) : LL(g) {};
    int operator[] (const int &k) {
        return comp[k];
    };
    void dfs(int idx, int par, int &k) {
        if (~par && this->ord[par] >= this->low[idx]) comp[idx] = comp[par];
        else comp[idx] = k++;
        for (auto &to : this->g[idx]) {
            if (comp[to] == -1) dfs(to, idx, k);
        }
    };
    void build(G &t) {
        LL::build();
        comp.assign(this->g.size(), -1);
        int k = 0;
        for (int i = 0; i < comp.size(); i++) {
            if (comp[i] == -1) dfs(i, -1, k);
        }
        t.resize(k);
        for (auto &e : this->bridge) {
            int x = comp[e.first], y = comp[e.second];
            t[x].push_back(y);
            t[y].push_back(x);
        }
    }
};
vector<vector<int> > g;
vector<vector<int> > t;
int node_sum[100005];
int memo[100010][2];
int dp(int i, int par){
    for(auto e : t[i]){
        if(e != par) dp(e, i);
    }
    int n1 = 0;
    int n2 = node_sum[i];
    for(auto e : t[i]){
        if(e == par) continue;
        n1 += max(memo[e][0], memo[e][1]);
        n2 += memo[e][0];
    }
    memo[i][0] = n1;
    memo[i][1] = n2;

    return max(n1, n2);
}

int main() {
    int n, m;
    cin >> n >> m;
    
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    TwoEdgeConnectComponents<vector<vector<int> > > bcc(g);
    bcc.build(t);
    
    for (int i = 0; i < n; i++) {
        int u = bcc[i];
        node_sum[u]++;
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int u = bcc[i];
        if (memo[u][0] == 0 && memo[u][1] == 0) {
            ans += dp(u, -1);
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 17608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include<set>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;


//AGC008-A
int main() {
	ll x;
	scanf("%lld", &x);
	ll y;
	scanf("%lld", &y);
	
	ll result = INF;


	if (x == y) {
		result = 0;
	}
	else if (x < y) {
		if (x >= 0 && y >= 0) {
			result = y - x;
		}
		else if (x <= 0 && y <= 0) {
			result = y - x;
		}
		else {
			//x:- y:+

			if (abs(x) <= y) {
				result = 1ll + y - abs(x);
			}
			else if (abs(x) > y) {
				result = abs(x) - y + 1ll;
			}
		}
	}
	else if(x > y){
		if (x == 0) {
			result = abs(y) + 1ll;
		}
		else if (y == 0) {
			result = 1ll + x;
		}
		else if (x > 0 && y >= 0) {
			result = 1ll + x - y + 1ll;
		}
		else if (x < 0 && y <= 0) {
			result = 1ll + abs(y) - abs(x) + 1ll;
		}
		else {
			//x:+ y:-

			if (x >= abs(y)) {
				result = 1ll + x - abs(y);
			}
			else if(x < abs(y)) {
				result = abs(y) - x + 1ll;
			}
		}
	}

	printf("%lld\n", result);
}

//ABC097-C
/*
int main() {
	string s;
	cin >> s;
	ll K;
	cin >> K;

	ll len = s.length();
	set<string> st;

	for (ll i = 0; i < len; i++) {
		for (ll j = 1; j <= min(K, len - i); j++) {
			st.insert(s.substr(i, j));
		}
	}

	vector<string> A;
	for (auto item : st) {
		A.push_back(item);
	}

	std::sort(A.begin(), A.end());

	cout << A[K - 1];

}
*/


//ABC99-C
/*
int main() {
	ll N;
	scanf("%lld", &N);

	vector<ll> dp(N + 1, INF);
	dp[N] = 0;

	for (ll i = N; i > 0; i--) {
		if (dp[i] == INF) {
			continue;
		}

		dp[i - 1] = min(dp[i - 1], dp[i] + 1);

		ll draw = 6;
		while (true) {
			if (i >= draw) {
				dp[i - draw] = min(dp[i - draw], dp[i] + 1);
			}
			else {
				break;
			}

			draw *= 6;
		}

		draw = 9;
		while (true) {
			if (i >= draw) {
				dp[i - draw] = min(dp[i - draw], dp[i] + 1);
			}
			else {
				break;
			}

			draw *= 9;
		}
	}

	printf("%lld\n", dp[0]);
}
*/

//ARC100-C
//L1�����̑��a���ŏ�������ɂ͒����l
/*
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N, 0);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}

	vector<ll> B(N, 0);
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		B[i] = A[i] - (i + 1);
	}

	std::sort(B.begin(), B.end());

	ll b = B[N / 2];


	ll result = 0;

	for (ll i = 0; i < N; i++) {
		result += std::abs(A[i] - (b + i + 1));
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
use std::cmp::*;
fn main(){
    let n=read::<i32>();
    let k=read::<i32>();
    let mut a=1;
    for _ in 0..n{
        a+=min(a,k);
    }
    println!("{}",a)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll K;
  cin >> K;
  vll A(K);
  for(int i = 0; i < K; i++){
    cin >> A.at(i);
  }
  if(A.at(K-1) != 2){
    cout << -1 << endl;
    return 0;
  }
  ll maxn, minn;
  ll maxi, mini;
  for(int i = K-1; i >= 0; i--){
    if(i == K-1){
      maxn = 2; minn = 2;
      maxi = 3; mini = 2;
    }
    else{
      maxn = maxi / A.at(i) * A.at(i);
      minn = (mini + A.at(i) - 1) / A.at(i) * A.at(i);
      if(maxn < minn){
        cout << -1 << endl;
        return 0;
      }
      maxi = maxn + A.at(i) - 1;
      mini = minn;
    }
  }
  cout << mini << ' ' << maxi << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a[7]={1,3,5,7,8,10,12},x,y,i,c,d,e,f;
	int b[4]={4,6,9,11};
	scanf("%d %d",&x,&y);
	if(x==2||y==2) {
		printf("No\n");
	}
	else {
		c=0;
		d=0;
		for(i=0;i<4;i++){
			if(x==b[i]) {
				c=1;
			}
			if(y==b[i])	{
				d=1;
			}
		}
		if(d==c) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
/*		e=0;
		f=0;
		for(i=0;i<7;i++);{
			if(x==a[i]) {
				e=1;
			}
			if(y==a[i]) {
				f=1;
			}
		}
		if(e==f){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
*/
	}
	return 0;
}

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

int main() {
   int  A, B, C;
   cin >>  A >> B >> C;
   if (A == B){
       cout << C << endl;
   }
   if (A == C){
       cout << B << endl;
   }
   if (B == C){
       cout << A << endl;
   }
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


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

int main(){
    int n,m;
    cin>>n>>m;
    vvi to(n);
    rep(i,m){
        int u,v;
        cin>>u>>v;
        --u,--v;
        to[u].push_back(v);
        //to[v].push_back(u);
    }
    int s,t;
    cin>>s>>t;
    --s,--t;
    vvi dist(n,vi(3,INF));
    dist[s][0]=0;

    queue<P> q;
    q.push(P(s,0));
    while(q.size()){
        P now=q.front();q.pop();
        for(auto x:to[now.fs]){
            if(dist[x][(now.sc+1)%3]<INF)continue;
            dist[x][(now.sc+1)%3]=dist[now.fs][now.sc]+1;
            q.push(P(x,(now.sc+1)%3));
        }
    }
    int ans=dist[t][0];
    ans/=3;
    if(dist[t][0]==INF)ans=-1;
    cout<<ans<<endl;
    return 0;
}

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

int n, k, c;
string s;
int dp[200000];
int dq[200000];
int ep[200000];
int eq[200000];
int imos[200001];
int main() {
  cin >> n >> k >> c >> s;
  ++c;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'o') {
      ep[i] = i >= c ? dp[i - c] + 1 : 1;
    }
    dp[i] = max(ep[i], i == 0 ? 0 : dp[i - 1]);
  }
  
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      eq[i] = i + c < n ? dq[i + c] + 1 : 1;
    }
    dq[i] = max(eq[i], i == n - 1 ? 0 : dq[i + 1]);
  }
  
  for (int r = 0; r <= n; ++r) {
    if (r != n && s[r] != 'o') continue;
    int rem = k - (r == n ? 0 : eq[r]);
    int l = lower_bound(dp, dp + n, rem) - dp;
    if (rem <= 0) l = -1;
    ++imos[l + 1];
    --imos[r];
  }
  
  for (int i = 1; i < n; ++i) {
    imos[i] += imos[i - 1];
  }
  
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'o' && imos[i] == 0) {
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 5764
import sys
sx, sy, tx, ty = [int(n) for n in input().split()]
W = tx - sx
H = ty-sy
r1 = "U"*H + "R"*W
r2 = "D"*H + "L"*W
r3 = "D" + "R"*W + "R" + "U"*H + "U" + "L"
r4 = "U" + "L"*W + "L" + "D"*H + "D" + "R"
print(r1 + r2 + r3 + r4)

Measured memory_bytes: 3060