akhauriyash/Code-Regression huggingface dataset:
# import sys
# readline = sys.stdin.buffer.readline

# from collections import deque
# from copy import copy,deepcopy
# from itertools import permutations,combinations
# from pprint import pprint

# def myinput():
#     return map(int,input().split())

# def mycol(data,col):
#     return [ row[col] for row in data ]

# def mysort(data,col):
#     data.sort(key=lambda x:x[col],reverse=False)
#     return data

s = input()
t = input()
if len(s)<len(t):
    print("UNRESTORABLE")
    exit()

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = list(s)

for l in range(len(t)):
    ans[i+l] = t[l]

ans2 = "".join(ans)

# if "?" in ans2:
ans3 = ans2.replace("?","a")
print(ans3)

Measured memory_bytes: 38384
N = int(input())
m = [2 * ((i - 1 + N % 2) // 2) + 1 - N % 2 for i in range(1, N + 1)]
for i, a in enumerate(sorted([int(a) for a in input().split()])):
  if m[i] != a:
    ret = 0
    break
else:
  ret = 2 ** (N // 2)

print(ret % (10 ** 9 + 7))

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

int main() {
 int A,B,C;
 cin>>A>>B>>C;
 if(A==5&&B==7&&C==5){
 	cout<<"YES"<<endl;
 }
 else if(A==7&&B==5&&C==5){
 	cout<<"YES"<<endl;
 }
else if(A==5&&B==5&&C==7){
 	cout<<"YES"<<endl;
 }
 else
 	cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void){
	int h, w;

	while (cin >> h >> w, h!=0 || w!=0){
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++)
				cout << "#";
				cout << "\n";
			}
			cout << "\n";
		}
	return 0;
}

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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    bool f[n][10];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    int p[n][11];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }

    int refven=-1*INT32_MAX;
//    cout << refven << "\n";
    for(int bit = 1; bit < (1<<10); ++bit) {
        int ven=0;
        for(int j = 0; j < n; j++) {
            int dopen=0;
            for(int i = 0; i < 10; i++) {
                if((bit&(1<<i))&&f[j][i]==true) dopen++;
            }
            ven+=p[j][dopen];
        }
        refven=max(refven,ven);
    }
    cout << refven << "\n";

    return 0;
}

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

using namespace std;
const int MAXN = 1e5 + 10;

int d[MAXN];
int n;

void solve() {
  sort(d, d+n);
  cout << (d[n / 2] - d[n / 2 - 1]) << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> d[i];
  }
  solve();
}


Measured memory_bytes: 640
n, m, xx, yy = map(int, input().split())
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
if x[-1] < y[0]:
    if xx < y[0] and yy > x[-1]:
        print("No War")
    else:
        print("War")
else:
    print("War")

Measured memory_bytes: 3060
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }
}

class AtCoder {

    /* 変数宣言 */
    final int A, B;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(A * B);
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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

Measured memory_bytes: 32620
#include <iostream>
#include <cstdio>
#define N 10005
using namespace std;

int a, b, c, d, cnt;
int v[N];
int main()
{
	int i;
	cin >> a >> b >> c >> d;
	for (i = a; i <= b; i++) v[i]++;
	for (i = c; i <= d; i++) v[i]++;
	for (i = 0; i <= 1000; i++) {
		if (v[i] == 2) cnt++;
	}
	cout << max(cnt - 1, 0) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main(){
  int a,b,c;

  std::cin >> a;
  std::cin >> b;
  std::cin >> c;

  if(a + b == c || a + c == b || b + c == a){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 256
//2008dC
I;int parse(char *p){
  switch(*p){
    case 'F': return 0;
    case 'T': return 1;
    case 'a': return (I>>0)&1;
    case 'b': return (I>>1)&1;
    case 'c': return (I>>2)&1;
    case 'd': return (I>>3)&1;
    case 'e': return (I>>4)&1;
    case 'f': return (I>>5)&1;
    case 'g': return (I>>6)&1;
    case 'h': return (I>>7)&1;
    case 'i': return (I>>8)&1;
    case 'j': return (I>>9)&1;
    case 'k': return (I>>10)&1;
    case '-': return !parse(p+1);
    case '(': {
                int x=0;
                p++;
                char *q=p;
                for(;;p++){
                  if(*p=='(')x++;
                  if(*p==')')x--;
                  if(x==0&&*p!='-')break;
                }
                p++;
                switch(*p){
                  case '*': return parse(q)&parse(p+1);
                  case '+': return parse(q)|parse(p+1);
                  case '-': return !parse(q)|parse(p+2);
                }
              }
  }
}

char p[1001],*q;main(){for(;scanf("%s",p),*p-'#';puts(I==2048?"YES":"NO")){
	q=strchr(p,'=')+1;
	for(I=0;I<2048;I++)if(parse(p)!=parse(q))break;
}exit(0);}

Measured memory_bytes: 552
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (k : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ls = iterate nextLunlun 0 :: [Int]
  print $ ls !! k

nextLunlun :: Int -> Int
nextLunlun = nextLunlun' . (`divMod` 10)
  where
    nextLunlun' (q, r) | q == 0 || r <= min 8 r' = 10 * q + succ r
                       | r'' == 0 = 10 * l'
                       | otherwise = 10 * l' + pred r''
      where
        r' = q `mod` 10
        l' = nextLunlun q
        r'' = l' `mod` 10

unsafeDigitToChar :: Int -> Char
unsafeDigitToChar = toEnum . (+ 48)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 9468
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,s
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) k,s
    m=0
    do i=0,k
        do j=0,k
            if (s-i-j<=k .and. s-i-j>=0)then
                m=m+1
            end if
        end do
    end do
    write(*,*) m
  
    stop
end program sample
  



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

int main(void){
  int n,ans=0;
  vector<int> vi;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    vi.push_back(t);
  }
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n; j++){
      ans += vi[i]*vi[j];
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
const ll N = 2e5 + 77;

int main()
{
  int n, k, a[N], b[N], sum[N] = {0};
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
  {
    scanf("%d", a + i);
    b[i] = a[i];
  }
  while (k > 0)
  {
    bool stop = true;
    for (int i = 1; i <= n; i++)
      stop &= b[i] == n, sum[i] = 0;
    // cout << k << " " << stop << endl;
    if (stop)
      break;
    for (int i = 1; i <= n; i++)
    {
      sum[max(1, i - b[i])] += 1;
      sum[min(n + 1, i + b[i] + 1)] -= 1;
    }
    for (int i = 1; i <= n; i++)
    {
      sum[i] += sum[i - 1];
      b[i] = sum[i];
    }
    --k;
  }

  for (int i = 1; i <= n; i++)
  {
    printf("%d ", b[i]);
  }
  return 0;
}

Measured memory_bytes: 6148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
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);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = b - a + 1;
	ll lcm = LCM(c, d);
	ans -= b/c - (a-1)/c;
	ans -= b/d - (a-1)/d;
	ans += b/lcm - (a-1)/lcm;

	cout << ans << endl;



}


Measured memory_bytes: 256
import * as fs from 'fs'
import {debug} from '../../util'

const input = fs.readFileSync('/dev/stdin', 'utf8').trim()

const output = (x: string | number | boolean): void => console.log(x)
const splitLine = (string: string): string[] => string.split('\n')
const splitBlank = (string: string): string[] => string.split(' ')
const toNumbers = (array: string[]): number[] => array.map(v => Number(v))
const range = (end: number, start :number = 0): number[] => [...Array(end - start)].map((v, i) => i + start)

// debug(input)

/* ここから */
const S = input
let hitachi = ''
let flag = false
for (const v of range(5)) {
    hitachi += 'hi'
    if (hitachi === S) {
        flag = true
        break
    }
}
flag ? output('Yes') : output('No')

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

int main() {
    int A, B, n = 0;
    cin >> A >> B;

    for(int i=A; i<=B; i++){
        
        if(i % 10 == i / 10000){
            if((i / 1000) % 10 == (i / 10) % 10){
                n++;
            }
        }
    }
    cout << n << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

int main(){
  int N;
  while(cin >> N){
    vector<int> L(N); cin >> L;

    sort(ALL(L));
    //    dump(L);

    vector<int> sum(3001);

    REP(i,N){
      sum[L[i]] += 1;
    }

    REP(i,3000){
      sum[i+1] += sum[i];
    }

    /*    REP(i,10){
      cerr << sum[i] << " ";
      }*/
    //cerr << endl;

    LLI ans = 0;

    REP(i,N){
      REP(j,N){
        if(i != j){
          int lb = abs(L[i]-L[j]);
          int ub = L[i]+L[j];
          
          ans += sum[ub-1] - sum[lb];

          if(lb < L[i] and L[i] < ub) --ans;
          if(lb < L[j] and L[j] < ub) --ans;
        }
      }
    }


    ans /= 6;
    


    cout << ans << endl;    
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(4);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(a.begin(), a.end());
  int x = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
  cout << (x == 1479 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
    int A[3];
    scanf("%d%d%d",&A[0],&A[1],&A[2]);
    int max = 0;
    for(int i = 0;i < 3;i++){
        max = max<A[i]?A[i]:max; //最大値更新
    }
    printf("%d\n",A[0]+A[1]+A[2]-max);
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import math
n = int(input())
a = list(map(int, input().split()))
res = 1 
if 0 in a:
  res = 0
else:
  for num in a:
    res *= num
    if res > 10**18:
      res = -1
      break
print(res)

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

class Program
{
	static void Main(string[] args)
	{			
		//文字列を読み込む
		int[] line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		int H = line[0];
		int N = line[1];
		int[] An = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		
		//最大値
		int sum = An.Sum();
		
		if(sum >= H){
				Console.WriteLine("Yes");
		}else{
				Console.WriteLine("No");
		}
	}
}

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

int main(){
  int l,r;
  cin >> l >> r;
  if(r/2019-l/2019){
    cout << 0 << endl;
    return 0;
  }
  l%=2019,r%=2019;
  int ans=2018;
  for(int i=l;i<r;i++){
    for(int j=i+1;j<=r;j++){
      ans=min(ans,i*j%2019);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#if defined(LOCAL)
#define PROBLEM_NAME "a"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define MAX(a,b)({__typeof__(a)__x=(a);__typeof__(b)__y=(b);__x<__y?__y:__x;})
#define MIN(a,b)({__typeof__(a)__x=(a);__typeof__(b)__y=(b);__x<__y?__x:__y;})

void solve(istream& cin, ostream& cout) {
  l n; cin >> n;
  vl a(n), b(n), c(n);
  F(i, 0, n) cin >> a[i];
  F(i, 0, n) cin >> b[i];
  F(i, 0, n) cin >> c[i];
  sort(all(a), greater<l>());
  sort(all(b), greater<l>());
  sort(all(c), greater<l>());
  l x = 0;
  vl bv(n);
  F(i, 0, n) {
    while (x < n and a[x] >= b[i]) x++;
    bv[i] = n - x;
  }
  B(i, 1, n) {bv[i - 1] += bv[i];}
  x = 0;
  l answer = 0;
  F(i, 0, n) {
    while (x < n and b[x] >= c[i]) x++;
    if (x == n) break;
    answer += bv[x];
  }
  cout << answer << endl;
}


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 3456
import scala.io.Source.stdin

object Main extends App {
  def fold(a:IndexedSeq[Int]):Int = {
    if(a.length==1) a(0)
    else fold( {for(i<- 1 until a.length) yield (a(i)+a(i-1))%10 } )
  }
  stdin.getLines.foreach { s=>
    println(fold(s.map(_.asDigit)))
  }
}

Measured memory_bytes: 44052
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector< vector< int> > input(2000001);
int N, M;


int main(){
    cin >> N >> M;
    REP(i, M){
        int a, b;
        cin >> a >> b;
        input[a].pb(b);
    }
    int flag = 0;
    REP(i, input[1].size()){
        if(count(input[input[1][i]].begin(), input[input[1][i]].end(), N) > 0){
            flag = 1;
        }
    }
    if(flag){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int c[n];
    for(int i=0;i<n;i++) c[i]=0;
    int d[n];
    for(int i=0;i<n;i++) d[i]=0;
    int a,b;
    for(int i=0;i<m;i++){
        cin >> a >> b;
        if(a==1) c[b-1]++;
        if(b==1) c[a-1]++;
        if(a==n) d[b-1]++;
        if(b==n) d[a-1]++;
    }
    bool flag=false;
    for(int i=1;i<n-1;i++){
        if(c[i]>0&&d[i]>0) flag=true;
    }
    if(flag) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

const int N = 200 * 1000 + 5;
vector <pair<int, int>> v[N];
vector <bool> vis(N);
vector <int> d(N);
bool ok = true;
void dfs(int s) {
	vis[s] = true;
	for (auto g : v[s]) {
		if(!vis[g.ff]) {
			d[g.ff] = d[s] + g.ss;
			dfs(g.ff);
		}
		else {
			if(d[g.ff] != d[s] + g.ss) {
				ok = false;
			}
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		v[x].push_back({y, w});
		v[y].push_back({x, -w});
	}
	for (int i = 1; i <= n; i++) {
		if(!vis[i]) {
			dfs(i);
		}
	}
	if(ok) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 14720
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val a = List.fill(n)(List.fill(sc.nextInt())(sc.nextInt()))
  val merged = a.foldLeft(Nil: List[Int])(_ ++ _)
  val kv = merged.groupMapReduce(identity)(_ => 1)(_ + _)
  val ans = kv.filter{ case (k, v) => v == n}.size
  println(ans)
}

Measured memory_bytes: 58424
#include <iostream>

using namespace std;

int FindSum(int n)
{
	int sum = 0;

	while (n != 0)
	{
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

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

	int sum = FindSum(n);

	if (n % sum == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{	
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int N,M,r,q;
int t[1001],n[1001],m[1001],s[1001];
int ts[51],te[51],qm[51];
int main(void){
	while(1){
		scanf("%d %d",&N,&M);
		if(N+M==0)break;
		scanf("%d",&r);
		for(int i=0;i<r;i++){
			scanf("%d %d %d %d",&t[i],&n[i],&m[i],&s[i]);
		}
		scanf("%d",&q);
		for(int i=0;i<q;i++){
			scanf("%d %d %d",&ts[i],&te[i],&qm[i]);
			int res=0,cnt=0,pt=0;
			for(int j=0;j<r;j++){
				if(m[j]==qm[i]){
					if(s[j]==1){
						cnt++;
						if(cnt==1)pt=t[j];
					}
					if(s[j]==0){
						cnt--;
						if(cnt==0){
							if(pt>=ts[i] && pt<=te[i]){
								if(t[j]>te[i])res+=te[i]-pt;
								if(t[j]>=ts[i] && t[j]<=te[i])res+=t[j]-pt;
							}
							if(pt<ts[i]){
								if(t[j]>te[i])res+=te[i]-ts[i];
								if(t[j]>=ts[i] && t[j]<=te[i])res+=t[j]-ts[i];
							}
						}
					}
				}
			}
			printf("%d\n",res);
		}
	}
	return 0;
}

Measured memory_bytes: 1044
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int n; cin>>n;
    vector<P> v(n); //r, l
    for(int i=0; i<n; i++){
        cin>>v[i].second>>v[i].first;
    }
    sort(v.begin(), v.end());
    const ll INF=1e18;
    ll mnr1[100010], mnr2[100010], mxl1[100010], mxl2[100010];
    mnr1[0]=INF;
    for(int i=0; i<n; i++) mnr1[i+1]=min(mnr1[i], v[i].first);
    mnr2[n]=INF;
    for(int i=n-1; i>=0; i--) mnr2[i]=min(mnr2[i+1], v[i].first);
    mxl1[0]=-INF;
    for(int i=0; i<n; i++) mxl1[i+1]=max(mxl1[i], v[i].second);
    mxl2[n]=-INF;
    for(int i=n-1; i>=0; i--) mxl2[i]=max(mxl2[i+1], v[i].second);
    ll ans=0;
    for(int i=0; i<n-1; i++){
        ans=max(ans, max(0ll, mnr1[i+1]-mxl1[i+1]+1)+max(0ll, mnr2[i+1]-mxl2[i+1]+1));
    }
    for(int i=0; i<n; i++){
        ans=max(ans, v[i].first-v[i].second+1+max(0ll, min(mnr1[i], mnr2[i+1])-max(mxl1[i], mxl2[i+1])+1));
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

int f(int temp)
{
    if (temp == 0)
    {
        return 0;
    }
    else
    {
        return f(temp % __builtin_popcount(temp)) + 1;
    }
}

int main()
{

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(n);
    int pc = 0;
    for (int i = 0; i < n; i++)
    {
        x.at(i) = s.at(i) - '0';
        if (x.at(i))
        {
            pc++;
        }
    }

    vector<int> ans(n);

    for (int i = 0; i < 2; i++)
    {
        int pc2 = pc;
        if (i == 0)
        {
            pc2++;
        }
        else
        {
            pc2--;
        }
        if(pc2 <= 0){
            continue;
        }
        int sum = 0;
        for (int j = 0; j < n; j++)
        {
            sum = (sum * 2) % pc2;
            sum += x.at(j);
        }
        int temp = 1;
        int temp2;
        for (int j = n - 1; j >= 0; j--)
        {
            if (i == 0)
            {
                if (x.at(j) == 0)
                {
                    temp2 = (sum + temp) % pc2;
                    ans.at(j) = f(temp2) + 1;
                }
            }
            else
            {
                if (x.at(j) == 1)
                {
                    temp2 = (sum - temp + pc2) % pc2;
                    ans.at(j) = f(temp2) + 1;
                }
            }
            temp = (temp * 2) % pc2;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << ans.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 4620
class Node {
  var val: Int
  var next: Node?
  init(_ v: Int) {
    self.val = v
  }
}
class Stack {
  var head: Node?
  
  var isEmpty: Bool { return head == nil }
  
  func push(_ v: Int) {
    let node = Node(v)
    node.next = head
    head = node
  }
  func pop() -> Int {
    let v = head!.val
    let tmp = head
    head = head?.next
    tmp?.next = nil
    return v
  }
}


let inp = readLine()!.split(separator: " ").map { Int($0)! }
let h = inp[0]
let w = inp[1]
var grid: [[Character]] = .init(repeating: [], count: h)

var memo: [[Int]] = .init(repeating: .init(repeating: 0, count: w), count: h)

for i in 0..<h {
  grid[i] = Array(readLine()!)
}

let stack = Stack()

var curSum = 0

for row in 0..<h {
  curSum = 0
  for col in 0..<w {
    if grid[row][col] == "#" {
      while !stack.isEmpty {
        let v = stack.pop()
        let r = v / w
        let c = v % w
        memo[r][c] += curSum
      }
      curSum = 0
    } else {
      curSum += 1
      let index = row * w + col
      stack.push(index)
    }
  }
  while !stack.isEmpty {
	let v = stack.pop()
   	let r = v / w
   	let c = v % w
  	memo[r][c] += curSum
  }
}


var ans = 0

for col in 0..<w {
  curSum = 0
  for row in 0..<h {
    if grid[row][col] == "#" {
      while !stack.isEmpty {
        let v = stack.pop()
        let r = v / w
        let c = v % w
        memo[r][c] += curSum
        ans = max(ans, memo[r][c])
      }
      curSum = 0
    } else {
      curSum += 1
      let index = row * w + col
      stack.push(index)
    }
  }
  while !stack.isEmpty {
	let v = stack.pop()
   	let r = v / w
   	let c = v % w
  	memo[r][c] += curSum
  	ans = max(ans, memo[r][c])
  }
}

print(max(ans - 1, 0))

Measured memory_bytes: 102328
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll x,y;
  cin >> x >> y;
  ll ans=0;
  while(x<y){
    ans++;
    x*=2;
  }
  if(x==y)ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ABC149B
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long A,B,K;
    cin>>A>>B>>K;
    if (A>=K) {
        A=A-K;
        cout<<A<<" "<<B<<endl;
    }else{
        B=B-(K-A);
        if(B<0){ // マイナスの値は無し
            B=0;
        }
        A=0;
        cout<<A<<" "<<B<<endl;
    }
    return 0;
}


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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  for (int i=0; i<3;i++){
   for(int j=0; j<3;j++){
     cin >> a.at(i).at(j);
   }
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  vector<vector<int>> c(3, vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<n;k++){
        if(a.at(i).at(j)==b.at(k))c.at(i).at(j)=1;
      }
    }
  }
  int f=0;
  if(c.at(0).at(0)==1 && c.at(0).at(1)==1 && c.at(0).at(2))f=1;
  if(c.at(1).at(0)==1 && c.at(1).at(1)==1 && c.at(1).at(2))f=1;
  if(c.at(2).at(0)==1 && c.at(2).at(1)==1 && c.at(2).at(2))f=1;
  if(c.at(0).at(0)==1 && c.at(1).at(0)==1 && c.at(2).at(0))f=1;
  if(c.at(0).at(1)==1 && c.at(1).at(1)==1 && c.at(2).at(1))f=1;
  if(c.at(0).at(2)==1 && c.at(1).at(2)==1 && c.at(2).at(2))f=1;
  if(c.at(0).at(0)==1 && c.at(1).at(1)==1 && c.at(2).at(2))f=1;
  if(c.at(2).at(0)==1 && c.at(1).at(1)==1 && c.at(0).at(2))f=1;
  
  if(f==1)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
s = list(input())
k = int(input())

countlap = [0]
for i in range(len(s) - 1):
    if s[i] == s[i+1]:
        countlap[-1] += 1
    else:
        countlap.append(0)
ans = 0
if len(countlap) == 1:
    ans = (len(s)*k)//2
elif s[0]==s[-1]:
    ans += (countlap[0]+1)//2 + (countlap[-1]+1)//2
    countlap[0] += countlap[-1] +1
    countlap[-1] = 0
    for i in range(1, len(countlap)):
        ans += ((countlap[i]+1)//2)*k
    ans += ((countlap[0]+1)//2)*(k-1)
else:
    for i in range(len(countlap)):
        ans += ((countlap[i]+1)//2)*k

print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e8 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, m, k;
int CASE;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};

int arr[MAXN];

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    ll c = b - a;
    if (c % 2 == 0) {
        printf("%lld", c / 2);
    } else {
        ll near = INF64;
        near = min(near, a - 1 + (((b % 2 == 1) ? 0 : 1) + c + 1) / 2);
        near = min(near, n - b + ((((a % 2) == (n % 2)) ? 0 : 1) + c + 1) / 2);
        printf("%lld", near);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int ball;
  int a[11], b[11];
  int num1=0, num2=0;
  int n;
  int i, j;

  a[0] = 0;
  b[0] = 0;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    num1 = 0;
    num2 = 0;

    for(j=0; j<11; j++){
      a[j] = 0;
      b[j] = 0;
    }

    for(j=0; j<10; j++){
      scanf("%d", &ball);
      if((ball > b[num2] && a[num1] <= b[num2]) || (ball > b[num2] && ball < a[num1])){
	num2++;
	b[num2] = ball;
      }else if(ball > a[num1] && a[num1] > b[num2] || (ball > a[num1] && ball < b[num2])){
	num1++;
	a[num1] = ball;
      }else{
	printf("NO\n");
	break;
      }
    }
    if(j == 10)printf("YES\n");
  }


  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=1e5+5;
const long long int MOD=1e9+7;
long long int x[MAX],y[MAX];
long long int ans,extra;
long long int n,m,dataB,dataA;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;++i) cin>>x[i];
	for(int i=1;i<=m;++i) cin>>y[i];
	sort(x+1,x+n+1);
	sort(y+1,y+m+1);
	for(long long int j=1;j<m;++j){
		long long int temp=((y[j+1]-y[j])*j)%MOD;
		temp=(temp*(m-j))%MOD;
		dataB=(dataB+temp)%MOD;
	}
	for(long long int j=1;j<n;++j){
		long long int temp=((x[j+1]-x[j])*j)%MOD;
		temp=(temp*(n-j))%MOD;
		dataA=(dataA+temp)%MOD;
	}
	cout<<(dataA*dataB)%MOD<<endl;
	return 0;
}


Measured memory_bytes: 1792
lst = list(map(int, input().split()))
c5 = c7 = 0
for x in lst:
    if x == 5:
        c5 += 1
    elif x == 7:
        c7 += 1
if c5 == 2 and c7 == 1:
    print("YES")
else:
    print("NO")

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

using namespace std;

int sum(int hoge) {
    string piyo = to_string(hoge);
    int result = 0;
    for(auto foo : piyo) result += foo - '0';
    return result;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int result = 0;
    for(int i = 1; i <= n; ++i) {
        if(sum(i) >= a && b >= sum(i)) result += i;
    }

    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}

int main()
{
	str s;
	cin >> s;
	int ans = 0;
	rep(i, s.size())
	{
		if (s.at(i) == '+')
		{
			ans++;
		}
		else
		{
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s;cin>>s;
  reverse(ALL(s));
  ll buft=0;
  for(i=0;i<s.size();i++){
    if(s[i]=='S'){
      if(buft>0){
        res++;
        buft--;
      }
    }
    else{
      buft++;
    }
  }
  cout<<s.size()-res*2<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

int main() {
    ll l, r, d; cin >> l >> r >> d;

    ll ans = 0;
    for(ll i = l; i <= r; ++i)
    {
        if (i%d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
  int n; cin >> n;
  ll sum = 0;
  rep(i,n) sum += i+1;
  sum -= n;
  cout << sum << endl;
}



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

int main()
{
    long long X, P=100;
    cin >> X;
    
    long long i = 1;
    while(P<X) {
        P += P / 100;
        i++;
    }
    cout << i - 1 << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private int n,q;
	private int[] A;

	private void mainrun() {
		scan = new Scanner(System.in);

		n = scan.nextInt();
		q = scan.nextInt();
		A = new int[n];

		Arrays.fill(A,Integer.MAX_VALUE);

		for(int i = 0;i < q;i++) {
			switch(scan.nextInt()) {
			case 0:
				update(scan.nextInt(),scan.nextInt());
				break;
			case 1:
				find(scan.nextInt(),scan.nextInt());
				break;
			}
		}

		scan.close();
	}

	private void update(int i,int x) {
		A[i] = x;
	}

	private void find(int s,int t) {
		int min = A[s];
		for(int i = s + 1;i <= t;i++) {
			min = Math.min(min, A[i]);
		}
		System.out.println(min);
	}
}



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

using namespace std;

#define X   first
#define Y   second

const int   N   = 3e3 + 1;
const int   mod = 1e9 + 7;

int add(int &a,int b)   {
    a += b;
    if(a >= mod)a -= mod;
    return  a;
}

string s;
int n, q;
int r[N];
int c[N];

int f[N][N];

int cal(int L,int C)    {
    if (C < 0)
        return  0;
    if (C > r[L - 1] - L + 1)
        return  0;
    if (L == n)
        return  1;
    C += c[r[L]] - c[r[L - 1]];
    if (f[L][C] < 0)
        f[L][C] = 0,
        add(f[L][C],cal(L + 1,C)),
        add(f[L][C],cal(L + 1,C - 1));
    return  f[L][C];
}

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> q;
    cin >> s;

    s = "#" + s;

    iota(r + 1,r + 1 + n,1);

    for(int i = 1 ; i <= q ; ++i)   {
        int L;  cin >> L;
        int R;  cin >> R;
        r[L] = max(r[L],R);
    }

    for(int i = 1 ; i <= n ; ++i)
        r[i] = max(r[i],r[i - 1]),
        c[i] = c[i - 1] + s[i] - '0';

    memset(f,-1,sizeof f);

    cout << cal(1,0);
}

Measured memory_bytes: 35584
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll a[10100], b[10100];
ll atot = 0, btot = 0;
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		atot += a[i];
	}
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &b[i]);
		btot += b[i];
	}
	if (atot > btot) { printf("No\n"); return 0; }
	int p = 1;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] > b[i])
		{
			while (p <= n && (b[p] - a[p]) / 2 <= 0) p++;
			if (p > n)
			{
				printf("No\n"); return 0;
			}
			ll t = min(a[i] - b[i], (b[p] - a[p]) / 2);
			b[i] += t; a[p] += (2 * t);
			i--;
			continue;
		}
	}
	bool flag = false;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] > b[i]) { flag = true; break; }
	}
	if (flag) printf("No\n");
	else printf("Yes\n");
	return 0;
}


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

typedef long long int ll;
#define MAX 1000005
int main(){
	int n;scanf("%d",&n);
	int a[n+1];
	int cnt[MAX];
	for (int i=0;i<MAX;i++) cnt[i]=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	
	int ans=0;
	for (int i=0;i<n;i++){
		//~ printf("a[i]=%d\n",a[i]);
		bool fnd=false;
		for (int d=1;d*d<=a[i];d++){
			if(a[i]%d==0){
				if((d!=a[i] && cnt[d]>0) or (d==a[i] && cnt[d]>1)){
					fnd=true;
					break;
				}
				int u=a[i]/d;
				if((u!=a[i] && cnt[u]>0) or (u==a[i] && cnt[u]>1)){
					fnd=true;
					break;
				}
			}
		}
		if(!fnd){
			ans+=1;
		}
	}
	printf("%d",ans);
}



Measured memory_bytes: 8500
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
result = {}
for i in s:
  if i not in result:
    result[i] = s.count(i) - t.count(i)
result = sorted(result.items(), key=lambda x:-x[1])
print(result[0][1] if result[0][1] > 0 else 0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,ans=1; cin>>N;
  vi memo(3);
  rep(i,0,N){
    int X; cin>>X;
    int count=0;
    rep(j,0,3){
      if(memo[j]==X){
        if(count==0)
          memo[j]++;
        count++;
        }
      }
    ans*=count;
    ans%=MOD;
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
// AOJ ALDS1_5_B Merge Sort
// 2018.4.30 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int w;
	if (!n) { pc('0'); return; }
	w = 0; while (n) buf[w++] = n%10 + '0', n/=10;
	while (w--) pc(buf[w]);
}

#define MAX_N 500002
int *a;
int w[MAX_N/2+2];
int cnt;

void merge(int low, int high) 
{ 
   int i, j, k, p, mid; 

   if (low < high) {
	   mid = (low + high) >> 1;
	   merge(low, mid);
	   merge(mid+1, high);

	   p = 0; cnt += high-low+1;
	   k = i = low; while (i <= mid) w[p++] = a[i++];
	   j = 0; while (i <= high && j < p) {
		   if (w[j] <= a[i]) a[k++] = w[j++];
		   else              a[k++] = a[i++];
	   }
	   while (j < p) a[k++] = w[j++];
   }
}

void merge_sort(int n, int *aa)
{
	a = aa;
	merge(0, n-1);
}

int aa[MAX_N];

int main()
{
	int n, i;
	
	n = in();
	for (i = 0; i < n; i++) aa[i] = in();

	cnt = 0;
	merge_sort(n, aa);
	mypr(a[0]); for (i = 1; i < n; i++) pc(' '), mypr(a[i]); pc('\n');
	mypr(cnt); pc('\n');
	return 0;
}


Measured memory_bytes: 4460
# Problem C - Trianglar Relationship

# input
N, K = map(int, input().split())

# initialization
nums = [0]*K
for i in range(1, N+1):
    nums[i%K] += 1
ans = 0

# count
for a in range(0, K):
    b = (K - a) % K # 余りがどうなる数になるべきか
    c = (K - a) % K
    if not (b+c)%K==0:
        continue
    ans += nums[a] * nums[b] * nums[c]

# output
print(ans)


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define push_back pb
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;
    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }
    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }
    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }
    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }
    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }
    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)

int H,W;
int A,B;
int main() {
	cin>>H>>W>>A>>B;
	modint ans = 0;
	for (int i = B; i < W; ++i){
		ans += H(H-A-1,i)*H(A-1,W-1-i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {            
	string s;
	cin >> s;

	int q;
	cin >> q;

	bool rev = false;
	deque<char> deq;
	for (auto u : s) deq.push_back(u);
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) rev ^= 1;
		else {
		 	int f;
			cin >> f;
			char c;
			cin >> c;
			
			if (!rev) {
			 	if (f == 1) {      
					deq.push_front(c);	
				} else {                
					deq.push_back(c);
				}
			} else {
                              if (f == 2) {      
					deq.push_front(c);	
				} else {                
					deq.push_back(c);
				}
			}
		}
	}                                      
                          
	string ans;
	for (auto u : deq) ans.push_back(u);

	if (rev) reverse(ans.begin(), ans.end());
	cout << ans << '\n';	
}


Measured memory_bytes: 1412