akhauriyash/Code-Regression huggingface dataset:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def lcm(a, b):
    return a * b / fractions.gcd(a, b)

def main():
    a = int(input())
    b = int(input())
    for i in range(1, 4):
        if not (i == a or i == b):
            print(i)
            exit()


    
    

        


if __name__ == '__main__':
    main()


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    
    string s, t;
    cin >> s >> t;
    cout << t << s << '\n';


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n,m,a,b;
const ll mod=1e9+7;


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

ll mul(ll a, ll b)
{
    return (a*b)%mod;
}

ll step(ll a, int st)
{
    ll r = 1;
    while(st)
    {
        if(st % 2)
            r = mul(r, a);
        a = mul(a, a);
        st /= 2;
    }
    return r;
}

ll div2(ll a, ll b)
{
    return mul(a,step(b,mod-2));
}

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

    cin>>n>>m>>a>>b;
    //cout<<mod;

    /*cout<<step(2,n);
    return 0;*/

    ll tek=1;
    ll tek2=1;
    for(ll i=n+m-b-2;i>m-b-1;i--)
        tek2=mul(tek2,i);
    for(ll i=n-1;i>0;i--)
        tek2=div2(tek2,i);
    //cout<<tek2<<endl;
    //return 0;
    //cout<<"*"<<tek2<<endl;
    ll sol=0;
    sol=add(sol,mul(tek,tek2));
    for(int i=2;i<=n-a;i++)
    {
        tek=mul(tek,i+b-2);
        tek=div2(tek,i-1);
        //cout<<"*"<<tek<<endl;
        tek2=div2(tek2,m-b+n-i);
        tek2=mul(tek2,n-i+1);
        sol=add(sol,mul(tek,tek2));
        //cout<<"*"<<tek2<<endl;
    }
    cout<<sol;

	return 0;
}


Measured memory_bytes: 256
//ABC092 A
#include <iostream>
using namespace std;
int main(){
int  a,b,c,d;
cin>>a>>b>>c>>d;
if(a<=b&&c<=d){
    cout<<a+c<<endl;
    }
else if(a>b&&c<=d){
    cout<<b+c<<endl;
    }
else if(a<=b&&c>d){
    cout<<a+d<<endl;
}
else{
     cout<<b+d<<endl;
}
}

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

int main() {
    int N;
    std::cin >> N;

    int max = -1, min = 10000, a;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        max = std::max(max, a);
        min = std::min(min, a);
    }

    std::cout << max - min << std::endl;

    return 0;
}


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <stdio.h>
#include <string.h>

int main()
{
int n;
int runner;
int score;
int out;
char nyuuryoku[114514];
    scanf("%d",&n);
        for(int i=0;i<n;i++){
            runner=0;
            score=0;
            out=0;
            while(out<3){
                scanf("%s",nyuuryoku);
                    if(strcmp(nyuuryoku,"HIT")==0){
                        runner=runner+1;
                    }
                    else if(strcmp(nyuuryoku,"HOMERUN")==0){
                        score=score+runner+1;
                        runner=0;
                    }
                    else if(strcmp(nyuuryoku,"OUT")==0){
                        if(out==2&&runner>3){
                            score=score+runner-3;
                        }
                            
                           out=out+1;
                    }
            }
            printf("%d\n",score);
        }
                
}
// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/

Measured memory_bytes: 2736
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
l,r,d=map(int,input().split())
print(r//d-(l-1)//d)


Measured memory_bytes: 64996
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};

int main() {
    int a,b,c;
    cin >> a>>b>>c;
    if (b-a==c-b){cout << "YES" << endl;}
    else
    {
        cout << "NO" << endl;
    }
    
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
typedef vector<ll> v;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 2e9
#define ALL(v) v.begin(), v.end()
string s, t;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s >> t;
    vector<v> count(26);
    for (int i = 0; i < s.size(); i++)
    {
        count[s[i] - 'a'].push_back(i);
    }
    ll ind = 0, counts = 0;
    for (auto c : t)
    {
        if (count[c - 'a'].size() == 0)
        {
            cout << -1 << "\n";
            return 0;
        }
        auto itr = lower_bound(ALL(count[c - 'a']), ind);
        if (itr == count[c - 'a'].end())
        {
            counts++;
            ind = count[c - 'a'][0] + 1;
        }
        else
        {
            ind = *itr + 1;
        }
    }
    cout << counts * s.size() + ind << "\n";
}

Measured memory_bytes: 1736
#coding:utf-8
n = int(input())
ans = 0

#n以下のすべての奇数について全探索
for i in range(1, n+1, 2):
    count = 0
    for j in range(1, i+1):
        if i % j == 0:
            count += 1
        if count == 8:
            ans += 1

print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int n;
	cin>>n;
	if((n/100)*5>=n%100)puts("1");
	else puts("0");
	return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int cnt = 0;
    int idx = n;
    vector<int> ans;
    while(1) {
//        cout << idx << endl;
        if ( idx == 0 ) {
            break;
        }
        int dif_num = m;
        while(1) {
            if ( dif_num == 0 ) {
                cout << -1 << endl;
                return 0;
            }
            if ( idx - dif_num < 0 ) {
                --dif_num;
                continue;
            }
            if ( s[idx-dif_num] != '1' ) {
                idx -= dif_num;
                ans.push_back(dif_num);
                break;
            }
            --dif_num;
        }
    }
    reverse(ans.begin(), ans.end());
    for ( int i = 0; i < ans.size(); ++i ) {
        if ( i >= 1 ) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1144
n,m,q=map(int,input().split())
l=[]
for i in range(q):
  l.append(list(map(int,input().split())))
li=[]
for i in range(m):
  li.append(i+1)
import itertools
ans=0
for lis in itertools.combinations_with_replacement(li, n):
  lis=list(lis)
  an=0
  for z in l:
    a,b,c,d=z
    if lis[b-1]-lis[a-1]==c:
      an+=d
  ans=max(an,ans)
print(ans)

Measured memory_bytes: 9212
// C.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;
typedef long long LL;


struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

int main(int argc, char *argv[])
{
	int n, m, k, l;
	cin >> n >> m;
	UnionFind uf(m);
	vector<int> lang(n, -1);
	for (int i = 0; i < n; ++i) {
		cin >> k;
		for (int j = 0; j < k; ++j) {
			cin >> l;
			--l;
			if (lang[i] < 0) {
				lang[i] = l;
			} else {
				uf.unite(lang[i], l);
			}
		}
	}
	int r = uf.root(lang[0]);
	bool ans = true;
	for (int i = 1; i < n; ++i) {
		if (uf.root(lang[i]) != r) {
			ans = false;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 4572
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
 
inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}
 
inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
 
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}
 
inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}
 
inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}
 
inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}
 
const int N = 2e5 + 5;

int arr[N];

void solve(){
  int k, n;
  cin >> k >> n;
  for(int i = 0; i < n; i++){
    cin >> arr[i];
  }
  vector<int> diff;
  for(int i = 1; i < n; i++){
    diff.push_back(arr[i] - arr[i - 1]);
  }
  diff.push_back(k - arr[n - 1] + arr[0]);
  sort(diff.begin(), diff.end());
  int ans = k - diff[diff.size() - 1];
  cout << ans;
}

int main(){
  int t;
  t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  ll w,h,x,y;cin>>w>>h>>x>>y;

  cout<<setprecision(8)<<(w*h)/2.0<<" ";
  
  if (2*x==w && 2*y==h) {
    cout<<1<<endl;
  }
  else {
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// back to back like I'm Jordan 96 97
const int MAXN = 1002;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)1e9 + 7;

signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0); 
  cout.tie(0);
  // freopen("FDT.txt","r",stdin);
  int n;
  cin >> n;
  vector<vector<int>> d(n, vector<int>(n)), a(n, vector<int>(n, 1));
  auto db = [&](){
    for(int i = 0; i < n; i ++){
      for(int j = 0; j < n; j ++) cout << d[i][j] << " ";
      cout << endl;
    }
    cout << "~~~~~~~~~~~~~~~~~~~~~\n";
  };
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < n; j ++) 
      d[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j));
  int ans = 0;
  vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
  // db();
  for(int ts = 0; ts < n*n; ts ++){
    int z;
    cin >> z;
    z --;
    int x = z/n, y = z%n;
    ans += d[x][y];
    a[x][y] = 0;

    // cout << x << " " << y << endl <<"drop " << cur << endl;
    queue<tuple<int,int,int>> bfs;
    bfs.push(make_tuple(x, y, d[x][y]));
    auto inside = [&](int X, int Y){
      return (X >= 0 && X < n && Y >= 0 && Y < n);
    };
    while(bfs.size()){
      int cx, cy, cv;
      tie(cx, cy, cv) = bfs.front();
      bfs.pop();
      if(d[cx][cy] != cv) continue;
      for(int i = 0; i < 4; i ++){
        int zx = cx + dx[i], zy = cy + dy[i];
        if(inside(zx, zy)){
          if(d[zx][zy] > cv + a[cx][cy]){
            d[zx][zy] = cv + a[cx][cy];
            bfs.push(make_tuple(zx, zy, d[zx][zy]));
          }
        }
      }
    }
    // db();
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 7588
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        double t = sc.nextInt();
        int sum = 0;
        int time = a;

        while( time < t+0.5){
            sum +=b;
            time += a;
            
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 21716
using System;

public class Test
{
	public static void Main()
	{
	int tate = 0, yoko = 0, menseki = 0, syu = 0;
            string[] data = Console.ReadLine().Split();//????????\?????????
            tate = int.Parse(data[0]);
            yoko = int.Parse(data[1]);
            menseki = tate * yoko;//??¢???????±?????????????
            syu = (tate * 2) + (yoko * 2);//??¨?????????????±?????????????
            Console.WriteLine("{0} {1}", menseki, syu);
	}
}

Measured memory_bytes: 9184
let () =
  let css = Array.init 3 (fun _ ->
    Array.init 3 (fun _ ->
      Scanf.scanf "%d " (fun c -> c))) in
  Array.init 3 (fun i ->
    Array.init 3 (fun j ->
      css.(i).(j) (* a_i + b_j *)
      - css.((i + 1) mod 3).(j) (* a_{i + 1} + b_j *))
    |> Array.to_list
    |> (fun (a :: as_) -> List.for_all (( = ) a) as_))
  |> Array.to_list
  |> List.for_all (fun b -> b)
  |> (function true -> "Yes" | _ -> "No")
  |> print_endline

Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = [collections.defaultdict(int) for _ in range(n)]
    for i in range(n):
        ai = a[i]
        s = S()
        for c in s:
            ai[c] += 1
    r = ''
    for c in string.ascii_lowercase:
        cc = min([t[c] for t in a])
        r += c * cc
    return r



print(main())


Measured memory_bytes: 7368
import math,itertools,bisect,sys,copy,queue
INF = 10**20

def LI(): return [int(x) for x in sys.stdin.readline().split()]

N = int(input())
A = [LI() for _ in range(N)]
a = copy.deepcopy(A)


for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] == 0 or A[i][k] == 0 or A[k][j] == 0: continue
            if A[i][j] > A[i][k] + A[k][j]:
                print (-1)
                exit (0)
            if A[i][j] == A[i][k] + A[k][j]:
                A[i][j] = 0
print (sum(sum(A[i]) for i in range(N) )//2)

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

long long findnum(long long n,long long a,long long b)
{
    if(a==b&&n==1)
    {
        return 1;
    }
    if(b<a||(n==1&&a!=b))
        return 0;
    long long sum=a+b;
    long long min1=(n-2)*a+sum;
    long long max1=(n-2)*b+sum;
    return max1-min1+1;
}
int main()
{
    long long N,A,B;
    cin>>N>>A>>B;
    long long m=findnum(N,A,B);
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b, c, count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (int i=a; i<=b; i++) {
        if (c % i == 0) count += 1;
        }
    printf("%d\n", count);
    return 0;
    }


Measured memory_bytes: 2108
#include<stdio.h>
int main(void)
{
	int c;
	scanf("%c",&c);
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
		printf("vowel\n");
	}
	else{
		printf("consonant\n");
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
# 平文
PLAIN = input()
PLAIN = PLAIN.lower()
# 秘密鍵
KEY = N

# 以下に、記述してください。
enc = ""

for char in list(PLAIN):
    ASCII = ord(char)
    num = ASCII - 97
    num = (num + KEY) % 26
    ASCII = num + 97
    enc += chr(ASCII)

print(enc.upper())

Measured memory_bytes: 3188
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
max_a = max(a)
if a.count(max(a)) == 1:
  sec_max = sorted(a)[-2]
else:
  sec_max = max_a

for i in range(n):
  if a[i] == max_a:
    print(sec_max)
  else:
    print(max_a)

Measured memory_bytes: 13384
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	ans := abs(abs(x) - abs(y))
	if x*y > 0 {
		if x > y {
			ans += 2
		}
	} else if x == 0 {
		if y < 0 {
			ans++
		}
	} else if y == 0 {
		if x > 0 {
			ans++
		}
	} else {
		ans++
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 512
let n = read_int ()
let g = Array.make n []
let ds = Array.make n 0
let rec f v p d = ds.(v) <- d; List.iter (fun (u, c) -> if u <> p then f u v (d + c)) g.(v)
let _ = for _ = 1 to n - 1 do Scanf.scanf " %d %d %d" @@ fun a b c -> g.(a - 1) <- (b - 1, c) :: g.(a - 1); g.(b - 1) <- (a - 1, c) :: g.(b - 1) done
let q, k = Scanf.scanf " %d %d" @@ fun a b -> a, b - 1
let _ = f k ~-1 0; for _ = 1 to q do Scanf.scanf " %d %d" @@ fun x y -> Printf.printf "%d\n" @@ ds.(x - 1) + ds.(y - 1) done

Measured memory_bytes: 24192
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
bool f[20000];
int n,m;
pair<int,pair<int,int> >t[20000];
int main(){
	while(cin>>n>>m&&n+m){
	for(int i=1;i<n;i++)f[i]=0;
	f[0]=1;
	for(int i=0;i<m;i++){
		cin>>t[i].X>>t[i].Y.X>>t[i].Y.Y;
		t[i].Y.X--,t[i].Y.Y--;
	}
	sort(t,t+m);
	for(int i=0;i<m;i++){
		if(f[t[i].Y.X])f[t[i].Y.Y]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++)ans+=f[i];
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll k;
    cin>>k;
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll ans=a[n-1]-a[0];
    for(int i=1;i<n;i++)
    {
        ll now=k-a[i];
        now+=a[i-1];
        ans=min(ans,now);
    }
    cout<<ans;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,A=0;
	cin>>N;
	for(int i=0; i<N; i++){
		int a,b;
		cin>>a>>b;
		A+=(b-a+1);
	}
	cout<<A<<endl;
}


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

using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    int vals[N];
    
    for(int i = 0; i < N; ++i) {
        cin >> vals[i];
    }
    long long DP[N][N]; // DP[i][j] = X-Y if vals[i..j] remains.
    for(int i = 0; i < N; ++i) {
        DP[i][i] = vals[i];
    }
    /* Transitions
    depending on i + j % 2
    if 1st guys turn
        DP[i][j] = max(DP[i - 1][j] + X[i], DP[i][j - 1] + X[j])
    else
        DP[i][j] = min(DP[i - 1][j] + X[i], DP[i][j - 1] + X[j])
    */ 
    for(int L = N - 1; L >= 0; --L) {
        for(int R = L + 1; R < N; ++R) {
            DP[L][R] = max(vals[L] - DP[L + 1][R], vals[R] - DP[L][R - 1]);
        }
    }
    cout << DP[0][N - 1] << endl;
}

Measured memory_bytes: 70400
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, k = LI()
if k > (n - 1) * (n - 2) // 2:
    print(-1)
else:
    print((n - 1) * (n - 2) // 2 - k  + (n - 1))
    edges = []
    for i in range(2, n+1):
        edges.append((1, i))
    cnt = 0
    for i in range(2, n+1):
        for j in range(i+1, n+1):
            if cnt == (n - 1) * (n - 2) // 2 - k:
                break
            edges.append((i, j))
            cnt += 1
        else:
            continue
        break
    for u, v in edges:
        print(u, v)

Measured memory_bytes: 74892
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N;
    cin >> N;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    lint sum = 0;
    vector<lint> cnt(100001);
    REP(i, N) {
        sum += A[i];
        cnt[A[i]]++;
    }
    int Q;
    cin >> Q;
    REP(q, Q) {
        lint B, C;
        cin >> B >> C;
        sum += (C-B) * cnt[B];
        cnt[C] += cnt[B];
        cnt[B] = 0;
        cout << sum << "\n";
    }
    
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
 
int n, m;
char a[22][22];
int d[22][22];
int ans;
queue <pair <int, int> > q;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	for(int i1 = 1; i1 <= n; i1++)
		for(int j1 = 1; j1 <= m; j1++)
			for(int i2 = 1; i2 <= n; i2++)
				for(int j2 = 1; j2 <= m; j2++)
				{
					if(a[i1][j1] != '.' || a[i2][j2] != '.') continue;
					for(int i = 1; i <= n; i++)
						for(int j = 1; j <= m; j++)	
							d[i][j] = 0;
					q.push(mp(i1, j1));
					d[i1][j1] = 1;
					while(!q.empty())
					{
						pair <int, int> v = q.front();
						q.pop();
						for(int i = 0; i < 4; i++)
						{
							int nx = dx[i] + v.F;
							int ny = dy[i] + v.S;
							if(!d[nx][ny] && a[nx][ny] == '.')
							{
								q.push(mp(nx, ny));
								d[nx][ny] = d[v.F][v.S] + 1;
							}
						}
					}
					ans = max(ans, d[i2][j2] - 1);
				}
	cout << ans;
}                                

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

k = inp()

keta = len(str(k))
ans = -1
tmp = 0
for i in range(1000001):
    tmp = ((tmp + (7 * pow(10,i,k)) % k)) % k
    if tmp == 0:
        ans = i+1
        break

print(ans)


Measured memory_bytes: 10324
#include <iostream>
#include <string>

using namespace std;

int min(int a, int b);
int calc(string t, string h);

int main() {

	string data_h;
	string data_t;
	int n = 0;
	int ans_h = 0;
	int ans_t = 0;
	int result[1000] = { 0 };

	cin >> n;
	
	for (int i = 0; i < n; i++) {

		cin >> data_t >> data_h;

		result[i] = calc(data_t, data_h);

	}

	for (int i = 0; i < n; i++) {

		switch (result[i]) {

		case 1:
			ans_t += 3;
			break;
		case 2:
			ans_h += 3;
			break;
		case 3:
			ans_t += 1;
			ans_h += 1;
			break;

		}

	}

	cout << ans_t << " " << ans_h << endl;

	return 0;

}

int min(int a,int b) {

	if (a >= b) {

		return b;

	}
	else {

		return a;

	}

}

int calc(string t, string h) {

	for (int u = 0; u < min(t.size(), h.size()); u++) {

		if (t[u] >h[u]) {

			return 1;

		}
		else if (t[u] < h[u]) {

			return 2;

		}

	}

	if (t.size() > h.size()) {

		return 1;

	}
	else if (t.size() < h.size()) {

		return 2;

	}
	else {

		return 3;

	}

}



Measured memory_bytes: 3184
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       x:usize,
       y:usize,
    }

    let mut ans: usize = 0;
    for i in 0..x + 1 {
        if i * 2 + (x - i) * 4 == y {
            echo!("Yes");
            return;
        }
    }

    echo!("No");
}


Measured memory_bytes: 2144
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]

cnt = 0

def count_even(x):
    global cnt
    while x % 2 == 0:
        cnt += 1
        x //= 2

for i in a:
    count_even(i)

print(cnt)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()
#define MOD 1000000007
#define mod 998244353

int main(){
	int N;
	cin >> N;
	vector<int> C(N), S(N), F(N), A(N);
	for (int i = 0;i < N - 1;i++) {
		cin >> C[i] >> S[i] >> F[i];
	}
	for (int i = 0;i < N;i++) {
		int x = 0;
		for (int j = i;j < N - 1;j++) {
			if (x <= S[j]) {
				x = S[j] + C[j];continue;
			}
			else {
				if ((x - S[j]) % F[j] == 0) {
					x += C[j];
				}
				else {
					x += F[j] - (x - S[j]) % F[j] + C[j];
				}
			}
		}
		cout << x << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
if len(H) == 1:
  print("Yes")
else:
  flag = 0
  H[0] -= 1
  for i in range(1,len(H)):
    if H[i] > H[i-1]:
      H[i] -= 1
    elif H[i] < H[i-1]:
      flag = 1
      break
  if flag:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 63984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sss = Console.ReadLine().Split(' ');
           Array.Sort(sss);
            Console.WriteLine("{0} {1} {2}",sss[0],sss[1],sss[2]);
        }
        }
    }

Measured memory_bytes: 9972
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int n;
    cin >> n;
    vector<P> ba(n);
    rep(i,n) cin >> ba[i].second >> ba[i].first;
    sort(ba.begin(), ba.end());
    ll tot = 0;
    rep(i,n){
        if(tot+ba[i].second > ba[i].first){
            cout << "No" << endl;
            return 0;
        }
        tot+=ba[i].second;
    }
    cout << "Yes" << endl;

    return 0;
}

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

int main(){
  string str, str2;
  cin >> str >> str2;
  str2.erase(str.size());
  //cout << str << endl;
  //cout << str2 << endl;
  if(str == str2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K, S = MAP()

MAX = 10 ** 9
if S == MAX:
    A = [1] * (N-K) + [MAX] * K
    print(*A)
    exit()

A = [S] * K + [MAX] * (N-K)
print(*A)


Measured memory_bytes: 6780
#include<iostream>
using namespace std;
int m,D[1401][1401]={m=0},h,w,f,i,j;
main(){
	cin>>h>>w;
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		cin>>f;
		if(!f){
			D[i+1][j+1]=min(D[i][j],min(D[i+1][j],D[i][j+1]))+1;
			m=max(m,D[i+1][j+1]);}
	}
	cout<<m*m<<endl;
}


Measured memory_bytes: 9684
# -*- coding: utf-8 -*-
#ARC093C
import sys

n= int(input())
tmp = input().split()
a = list(map(lambda a: int(a), tmp))

total=0
ex=0
for i in range(0,n):
	total+=abs(a[i]-ex)
	ex=a[i]
total+=abs(ex)

print(total-abs(a[0]-0)-abs(a[1]-a[0])+abs(a[1]-0))
for i in range(1,n-1):
	print(total-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))
print(total-abs(a[n-1]-a[n-2])-abs(0-a[n-1])+abs(0-a[n-2]))




Measured memory_bytes: 15232
#include<stdio.h>
int main(void){
	int i,j,cnt=0,tmp,N,A[100],min=100,mins=0;
	scanf("%d", &N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	for(i=0;i<N-1;i++){
		min=A[i];
		mins=i;
		for(j=i+1;j<N;j++){
			if(A[j]<min){
				mins=j;
				min=A[j];
			}
		}
		if(mins!=i){
			tmp=A[i];
			A[i]=A[mins];
			A[mins]=tmp;
			cnt++;
		}
	}
	printf("%d",A[0]);
	for(i=1;i<N;i++) printf(" %d",A[i]);
	printf("\n");
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 604
// AOJ 0373: Checkered Pattern
// 2018.1.22 bal4u@uu

#include <stdio.h>

#define ABS(a)  ((a)>=0?(a):-(a))

int s[2][1001];
char buf[2005];

int in()
{
	int n = 0;
	int c = getchar();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar();
	while (c >= '0');
	return n;
}

int main()
{
	int w, h, a, x, y, x1, y1, ans;
	char *p;

	w = in(), h = in();
	ans = x1 = y1 = 0;
	for (y = 0; y < h; y++) {
		fgets(p=buf, 2005, stdin);
		a = *p & 1, y1 += a, s[a][0] += a;
		for (x = 1; x < w; x++) p += 2, s[a][x] += *p & 1;
	}

	for (x = 0; x < w; x++) {
		if (s[1][x] && (s[1][x] !=   y1 || s[0][x])) goto done;
		if (s[0][x] && (s[0][x] != h-y1 || s[1][x])) goto done;
		if (s[1][x]) x1++;
	}

	if (ABS(2*x1-w) > 1 || ABS(2*y1-h) > 1) goto done;
	a = x1*y1+(w-x1)*(h-y1);
	if (ABS(2*a-h*w) > 1) goto done;
	ans = 1;
done:
	puts(ans? "yes": "no");
	return 0;
}



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

int main()
{
	string O, E;
	cin >> O >> E;
	int i = 1;
	while (true) {
		if (i % 2 == 1 && ((i - 1) / 2)<O.length())
			cout << O.at((i - 1) / 2);
		else if (i % 2 == 0 && (i / 2 - 1) < E.length()) {
			cout << E.at(i / 2 - 1);
		}
		else {
			break;
		}
		i++;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    //Console画面（黒画面）を利用するときに書くおまじない
    {
        string input = Console.ReadLine();
        string[] inputList = input.Split(' ');

        int A = int.Parse(inputList[0]);
        int B = int.Parse(inputList[1]);

        int ans = A * B;

        if (A>9 || B>9)
        {
            Console.Write("-1");
        }
        else
        {
            Console.Write(ans);
        }
            }
}

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

signed main(void)
{
	string s;
	int cnt, ans;

	cin >> s;
	cnt = 0;
	ans = 0;
	rep(i, 3)
	{
		if (s[i] == 'R')
		{
			cnt++;
			ans = max(cnt, ans);
		}
		else
			cnt = 0; 
	}
	cout << ans << endl;
	return 0;
}


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

long n;
map<long, long> emap, omap;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    long v;
    long fmaxo=0, smaxo=0, fmaxe=0, smaxe=0;
    for(long i=0; i<n; i++){
        cin >> v;
        if(i%2) {
            omap[v]++;
        }
        else {
            emap[v]++;
        }
    }
    long fid=0, sid=0;
    for(auto& it: omap){
        if(it.second>sid){
            sid = it.second;
            smaxo = it.first;
        }
        if(sid>fid){
            swap(smaxo, fmaxo);
            swap(sid, fid);
        }
        }
    fid=0, sid=0;
    for(auto& it: emap){
        if(it.second>sid){
            sid = it.second;
            smaxe = it.first;
        }
        if(sid>fid){
            swap(smaxe, fmaxe);
            swap(sid, fid);
        }
        }

    long ans = 0;
    if(fmaxe != fmaxo){
        ans = n - omap[fmaxo] - emap[fmaxe];
    }else{
        ans = min(n -omap[fmaxo] -emap[smaxe], n-omap[smaxo]-emap[fmaxe]);
    }
    printf("%ld", ans);

}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T 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;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
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;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll l,n;cin>>l>>n;
  vector<ll>x(n);
  rep(i,0,n)cin>>x[i];
  vector<ll>a(n+1);
  rep(i,0,n)a[i+1]=a[i]+x[i];
  vector<ll>b(n+1);
  rrep(i,0,n)b[i]=b[i+1]+l-x[i];
  res=l-x[0];
  chmax(res,x[n-1]);
  rep(i,0,n-1){
    ll lim=min(i+1,n-i-1);
    buf=0;
    buf+=2*(a[i+1]-a[i-lim+1]);
    buf+=2*(b[i+1]-b[i+lim+1]);
    //ll dl=((i==0)?x[i]-0:x[i]-x[i-1]);
    //ll dr=((i==n-2)?l-x[i+1]:x[i+2]-x[i+1]);
    //cout<<i spa buf spa x[i] spa x[i+1]<<endl;
    chmax(res,buf-min(x[i],l-x[i+1]));
    if(lim<i+1){
      chmax(res,2*(a[i]-a[i-lim]+b[i+1]-b[i+lim+1])+x[i]);
    }
    if(lim<n-i-1){
      chmax(res,2*(a[i+1]-a[i-lim+1]+b[i+2]-b[i+lim+2])+l-x[i+1]);
      //cout<<i spa a[i+1]-a[i-lim+1] spa b[i+2]-b[i+lim+2] spa x[i+1]<<endl;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i, j;
	int n;
	int card[4][14];
	char mark[2];
	int num;
	char *mark_str = "SHCD";
	
	memset(card, 0, sizeof(card));
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%s%d", mark, &num);
		switch (mark[0]){
		case 'S':
			card[0][num] = 1;
			break;

		case 'H':
			card[1][num] = 1;
			break;

		case 'C':
			card[2][num] = 1;
			break;

		case 'D':
			card[3][num] = 1;
			break;
		}
	}
	
	for (i = 0; i <= 3; i++){
		for (j = 1; j <= 13; j++){
			if (card[i][j] == 0){
				printf("%c %d\n", mark_str[i], j);
			}
		}
	}
	
	return (0);
}




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

#define ll long long
 int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int n,r,t;
     cin>>n>>r;
     if(n>9){
     	cout<<r;
     }else{
     	t =100*(10-n);
     	cout<<r+t;
     }
     
     return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                b = False
                t = [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]
                for ti, tj in t:
                    if 0 <= ti < h and 0 <= tj < w:
                        if s[ti][tj] == "#":
                            b = True
                            break
                if not b:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    slove()


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


int main(){
    int N,P;
    while(cin>>N>>P, N != 0 && P != 0){
        vector<int> stone(N,0);
        int p = P-1;//ｐは椀の中の石の数
        stone[0]++;
        int i = 0;
        while(stone[i] != P){
            i = (i+1)%N;
            if(p > 0){
                stone[i]++;
                p--;
            }
            else if(stone[i] != 0){
                swap(p,stone[i]);
            }
        }
        cout<<i<<endl;
    }

}



Measured memory_bytes: 3080
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define rep(i,n) for(int i=0;i<n;i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){

  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  vector<int> B(N,0);
  REP(i,N){
    cin>>A[i];
  }
  REP(i,N){
    for(int j=-A[i];j<=A[i];j++){
      if(i+j>=0&&i+j<N){
      }
    }
  }


  for(int i=0;i<min(K,42);i++){
    for(int j=0;j<N;j++){
      int l=max(0,j-A[j]);
      int r=j+A[j];
      B[l]++;
      if(r+1<N){
        B[r+1]--;
      }
    }
    for(int j=0;j<N-1;j++){
      B[j+1]+=B[j];

    }
    for(int j=0;j<N;j++){
      A[j]=B[j];
      B[j]=0;
    }
  }
  REP(i,N){
    cout<<A[i]<<" ";
  }
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx, dy = ty - sy;

  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');

  dx++;
  dy++;
  cout << 'L' << string(dy, 'U') << string(dx, 'R') << 'D';
  cout << 'R' << string(dy, 'D') << string(dx, 'L') << 'U';
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256