akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
struct Point
{
	int x, y;
	Point() {};
	Point(int x, int y) : x(x), y(y) {};
};
int W, H;
bool field[8][8];
int blank;
Point start;
bool res;

void check(Point p, int count)
{
	if (res)
	{
		return;
	}
	for (int i = 0; i < 4; ++i)
	{
		if (start.x == p.x + dx[i] && start.y == p.y + dy[i] && count == blank - 1)
		{
			res = true;
			return;
		}
	}

	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (field[i][j] == false)
			{
				for (int k = 0; k < 4; ++k)
				{
					int nx = j + dx[k];
					int ny = i + dy[k];
					if (0 <= nx && nx < W && 0 <= ny && ny < H && ((nx == start.x && ny == start.y) || (nx == p.x && ny == p.y)))
					{
						goto NEXT;
					}
				}
				int emptyNext = 0;
				for (int k = 0; k < 4; ++k)
				{
					int nx = j + dx[k];
					int ny = i + dy[k];
					if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == false)
					{
						++emptyNext;
					}
				}
				if (emptyNext == 1)
				{
					return;
				}
			}
		NEXT:
			;
		}
	}
	for (int i = 0; i < 4; ++i)
	{
		int nx = p.x + dx[i];
		int ny = p.y + dy[i];
		if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == false)
		{
			field[ny][nx] = true;
			check(Point(nx, ny), count + 1);
			field[ny][nx] = false;
		}
	}
}

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while (cin >> W >> H, W || H)
	{
		memset(field, 0, sizeof(field));
		bool registered = false;
		blank = 0;
		res = false;
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
			{
				cin >> field[i][j];
				if (field[i][j] == false)
				{
					++blank;
				}
				if (registered == false && field[i][j] == false)
				{
					start.x = j;
					start.y = i;
					registered = true;
				}
			}
		}
		if (blank % 2 == 1)
		{
			cout << "No" << endl;
			goto END;
		}
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
			{
				if (field[i][j] == false)
				{
					int emptyNext = 0;
					for (int k = 0; k < 4; ++k)
					{
						int nx = j + dx[k];
						int ny = i + dy[k];
						if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == false)
						{
							++emptyNext;
						}
					}
					if (emptyNext == 1)
					{
						cout << "No" << endl;
						goto END;
					}
				}
			}
		}
		field[start.y][start.x] = true;
		check(start, 0);
		if (res)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	END:
		;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1188
s=list(input())
t=list(input())

sw=0
for i in range(-len(t),-len(s)-1,-1):
    ss=s[i:]
    cnt=0
    for j in range(len(t)):
        if ss[j]==t[j] or ss[j]=='?':
            cnt+=1
    if cnt==len(t):
        sw=1
        s=s[:i]+t+ss[len(t):]
        break
a=''.join(s)
aa=a.replace('?','a')
print(aa if sw==1 else 'UNRESTORABLE')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, cnt;
string S[3];

int main() {
	cin >> N;
	for (int i = 0; i != 3; ++i)
		cin >> S[i];
	for (int i = 0; i != N; ++i) {
		set<char>st;
		for (int j = 0; j != 3; ++j) {
			st.insert(S[j][i]);
		}
		cnt += st.size() - 1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
flag = True
u = [input() for i in range(int(input()))]
for i in range(int(input())):
	t = input()
	if t in u:
		if flag:
			print('Opened by {}'.format(t))
			flag = not flag
		else:
			print('Closed by {}'.format(t))
			flag = not flag
	else:
		print('Unknown {}'.format(t))

Measured memory_bytes: 7712
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



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

	vector< vector<int> >v(n+1,vector<int>(3,0));
	rep(i, 1, n+1) {
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	}


	rep(i, 1, n+1) {
		if (abs(v[i][1]-v[i-1][1])+abs(v[i][2] - v[i - 1][2])<=v[i][0]-v[i-1][0]) {
			if ((v[i][0]-v[i-1][0])%2 == 0) {
				if (abs(v[i][1]+v[i][2])%2 == abs(v[i-1][1] + v[i-1][2])%2) {
					continue;
				}
				else {
					cout << "No" << endl;
					exit(0);
				}
			}
			else {
				if (abs(v[i][1] + v[i][2]) % 2 != abs(v[i - 1][1] + v[i - 1][2]) % 2) {
					continue;
				}
				else {
					cout << "No" << endl;
					exit(0);
				}
			}
		}
		else {
			cout << "No" << endl;
			exit(0);
		}
	}

	cout << "Yes" << endl;




	return 0;

}

Measured memory_bytes: 5760
from itertools import combinations
l,r = map(int, input().split())
if (r//673 - (l-1)//673 > 0)&(r-l >= 2):
    print(0)
else:
    print(min([l[0] * l[1] % 2019 for l in list(combinations(range(l,r+1),2))]))

Measured memory_bytes: 14372
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<cstring>
#include<queue>
#include<stack>
using namespace std;

#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define frn(i,n) for(int i=n-1;i>=0;i--)
#define fr1(i,n) for(ll i=1;i<=n;i++)
#define frn1(i,n) for(int i=n;i>0;i--)
#define N 100002
#define ll long long
#define mid(a,b) a+(b-a)/2


void solve(){
    int n;
    cin>>n;
    unsigned long long sum=0;
    unsigned long long arr[200005];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        //sum+=arr[i];
    }
    unsigned long long ans=0;
    for(int i=n-2;i>=0;i--){
        sum+=arr[i+1];
      	ans = (ans%mod + ((arr[i]%mod)*(sum%mod))%mod)%mod;
    }
    cout<<ans<<endl;
}


int main(){
    ios_base::sync_with_stdio(false);   
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 5176
#include <stdio.h>
 
int main(void){
    char ch;
    int alpha[26]={0},i;
    while(scanf("%c",&ch)!=EOF){
        if('A'<=ch && ch<= 'Z'){
            alpha[ch-'A']++;
        }
        else if('a'<=ch && ch<= 'z'){
            alpha[ch-'a']++;
        }
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n",'a'+i,alpha[i]);
    }
    return 0;
}


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

int main(void)
{
  int r,c,i,j,k;
  int a[102][102]={};

  cin >> r >> c;

  for(j = 1; j <= r; j++){
    a[c+1][j] = 0;
    for(i = 1; i <= c; i++){
      cin >> a[i][j];
      a[c+1][j] = a[c+1][j] + a[i][j];
    }
  }

  for(i = 1; i <= c+1; i++){
    a[i][r+1] = 0;
    for(j = 1; j <= r; j++){
      a[i][r+1] = a[i][r+1] + a[i][j];
    }
  }

  for(j = 1; j <= r+1; j++){
    for(i = 1; i <= c+1; i++){
      cout << a[i][j];
      if(i!=c+1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = 0;
  rep(i, 101) {
    if (a < i && i <= b && c < i && i <= d) ans++;
  }
  ANS;
  return 0;
}

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


using namespace std;

long long n;

int main() {
    scanf("%lld", &n);

    long long m;
    long long ans = 0;
    long long div;
    for (div=1; div*div<=n; div++) {
        if (n%div==0) {
            m = (n - div)/div;
            if (m!=0 && n/m==n%m)
                ans += m;
            //printf("++ %d\n", m);
            if (div*div!=n) {
                m = (n - n/div)/(n/div);
                //printf("** %d\n", m);
                if (m!=0 && n/m==n%m)
                    ans += m;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}








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

int main(){
    int N, mod;
    cin >> N;
    vector<int> vec(N);
    mod = 1000000007;
    int64_t sum = 0;
    long ans = 0;
    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
        sum += vec.at(i);
        sum %= mod;
    }
    for (int i = 0; i < N; i++){
        sum -= vec.at(i);
        if (sum < 0) sum += mod;
        ans += sum * vec.at(i);
        ans %= mod;
    }
    cout << ans <<endl;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	if (n == 3) {
		cout << 2 << '\n';
		cout << 1 << " " << 3 << '\n';
		cout << 2 << " " << 3 << '\n';
		return 0;
	}
	if (n == 4) cout << 4 << '\n';
	else cout << (n / 2) * 4 << '\n';
	int t = (n / 2) * 2;
	for (int i = 1; i < n / 2; i++) {
		cout << i << " " << i + 1 << '\n';
		cout << i << " " << t - i << '\n';
		cout << t + 1 - i << " " << i + 1 << '\n';
		cout << t + 1 - i << " " << t - i << '\n';
	}
	if (n > 4) {
		if (n % 2 == 0) {
			cout << 1 << " " << n / 2 << '\n';
			cout << 1 << " " << n / 2 + 1 << '\n';
			cout << n << " " << n / 2 << '\n';
			cout << n << " " << n / 2 + 1 << '\n';
		}
		else {
			cout << n << " " << 1 << '\n';
			cout << n << " " << n / 2 << '\n';
			cout << n << " " << n / 2 + 1 << '\n';
			cout << n << " " << t << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;
const int N=105;

int n,a[N];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    ll sum=1000,k=0;
    for(int i=1;i<=n;i++)
    {
        sum+=k*a[i],k=0;
        if(a[i+1]>a[i])
        {
            k=sum/a[i];
            sum%=a[i];
        }
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 3808
def gcd_(a, b):
    if a < b:  a, b = b, a
    if b == 0:  return a
    return gcd_(b, a % b)

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

N, X = list(map(int,input().split()))
a = list(map(int,input().split()))
p = [abs(X - a[i]) for i in range(N)]
ans = gcd(p)
print(ans)

Measured memory_bytes: 89876
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+3;
int a[N][3],d[N][3];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,i,j,n,m,l,r,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    for(i=1;i<=n;i++)
    {
        d[i][0]=max(d[i-1][1],d[i-1][2])+a[i][0];
        d[i][1]=max(d[i-1][0],d[i-1][2])+a[i][1];
        d[i][2]=max(d[i-1][0],d[i-1][1])+a[i][2];
    }
    cout<<max(d[n][0],max(d[n][1],d[n][2]))<<"\n";
    return 0;
}

Measured memory_bytes: 2560
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
Hlist = inpl()

maxJ = 0
temp = 0
for i in range(len(Hlist)-1):
    if Hlist[i+1]<=Hlist[i]:
        temp+=1
    else:
        if temp > maxJ: maxJ = temp
        temp = 0

print(max(maxJ,temp))

Measured memory_bytes: 23424
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    cout << ( a + b ) % 24 << endl;

    return 0;
}


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

int main()
{
    long N;
    cin >> N;
    long a[200001];
    a[0] = 0;
    for (long i = 1; i <= 200000; i++)
    {
        a[i] = 1 + a[i % bitset<32>(i).count()];
    }
    string X;
    cin >> X;
    long minus_one_sum = 0;
    long plus_one_sum = 0;
    long base_ones = 0;
    for (long i = 0; i < N; i++)
    {
        if (X[i] == '1')
        {
            base_ones += 1;
        }
    }
    long m_prev[N];
    long p_prev[N];
    m_prev[0] = 1;
    p_prev[0] = 1;
    for (long i = 1; i < N; i++)
    {
        if (base_ones == 1)
        {
            m_prev[i] = 0;
        }
        else
        {
            m_prev[i] = (m_prev[i - 1] * 2) % (base_ones - 1);
        }
        p_prev[i] = (p_prev[i - 1] * 2) % (base_ones + 1);
    }
    for (long i = N - 1; i >= 0; i--)
    {
        if (X[i] == '1')
        {
            if (base_ones != 1)
                minus_one_sum += m_prev[N - 1 - i] % (base_ones - 1);
            plus_one_sum += p_prev[N - 1 - i] % (base_ones + 1);
        }
    }
    // cout << base_ones << endl;
    // cout << base_sum << endl;

    for (long i = 0; i < X.length(); i++)
    {
        if (X[i] == '1')
        {
            if (base_ones == 1)
            {
                cout << 0 << endl;
                continue;
            }
            long ones = base_ones - 1;
            long sum = minus_one_sum - m_prev[N - 1 - i];
            if (sum < 0)
            {
                sum += ones;
            }
            cout << (a[sum % ones] + 1) << endl;
        }
        else
        {
            long ones = base_ones + 1;
            long sum = plus_one_sum + p_prev[N - 1 - i];
            cout << (a[sum % ones] + 1) << endl;
        }
        // cout << sum << " " << ones << endl;
    }
}

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

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

    int c=0;
    for(int i=1;i<=n;i++)
    {
        int s=0;
        for(int j=1;j<=i;j++)
        {
            if(i % j==0) s++;
        }
        if(s==8 && (i % 2 ==1)) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 888
# 標準入力
num = int(input())
data = list(map(int, input().split()))

# 初期化
alice = 0
bob = 0

# 降順にソート
data = sorted(data, reverse=True)

for i in range(num):
    if i % 2 == 0:
        alice += int(data[i])
    else:
        bob += int(data[i])

print(alice - bob)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
}



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

class Tree
{
public:
	int val;
	Tree *l,*r;
	
	Tree()
	:l(NULL),r(NULL),val(-1)
	{}
	
	~Tree()
	{
		if(l) delete l;
		if(r) delete r;
	}
};

int p,cnt,w[9];
string expr;

void parse(Tree* t)
{
	if(expr[p]=='(')
	{
		t->l=new Tree;
		t->r=new Tree;
		p++;
	}
	if(expr[p]=='(') parse(t->l);
	if(isdigit(expr[p]))
	{
		t->l->val=expr[p]-'0';
		p++;
	}
	
	if(expr[p]==' ') p++;
	
	if(expr[p]=='(') parse(t->r);
	if(isdigit(expr[p]))
	{
		t->r->val=expr[p]-'0';
		p++;
	}
	p++;
}

void Adj(Tree* t, vector<Tree*>& ret)
{
	if(t->val==-1) 
	{
		ret.push_back(t);
		Adj(t->l, ret);
		Adj(t->r, ret);
	}
}

int check(Tree* t)
{
	int val;
	if(t->val<0)
	{
		int l=check(t->l);
		int r=check(t->r);
		
		if(t->val==-1) val=l&r;
		if(t->val==-2) val=l|r;
		if(t->val==-3) val=l^r;
	}
	else val=w[(t->val)];
	
	return val;
}

void Attach(int ps, vector<Tree*>& ct, Tree* t)
{
	if(ps==ct.size()) 
	{
		if(check(t)==15) cnt++;
	}
	else
	{
		for(int i=1; i<=3; i++)
		{
			ct[ps]->val=-i;
			Attach(ps+1, ct, t);
		}
	}
}

int main()
{
	while(1)
	{
		p=0,cnt=0;
		getline(cin,expr);
		if(expr.size()==0) getline(cin,expr);
		if(expr[0]=='E'||expr[0]=='N') break;
		
		Tree* t = new Tree;
		parse(t);
		vector<Tree*> ct;
		Adj(t,ct);
		int N;
		cin >> N;
		for(int i=1; i<=N; i++)
		{
			int v=0;
			for(int j=0; j<4; j++)
			{
				int t;
				cin >> t;
				v|=(t<<j);
			}
			w[i]=v;
		}
		
		Attach(0,ct,t);
		cout << cnt << endl;
		delete t;
	}
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main(){
    let (n, k) = get_int2();
    let n = n as usize;

    let mut gr:Vec<Vec<usize>> = vec![vec![];n];
    let mut edges: Vec<(usize, usize)> = Vec::with_capacity(n-1);

    for _ in 0..n-1{
        let (a, b) = get_int2();
        let a = (a - 1) as usize;
        let b = (b - 1) as usize;

        gr[a].push(b);
        gr[b].push(a);
        edges.push((a, b));
    }
    let gr = gr;
    let edges = edges;

    let nothing = std::usize::MAX;

    let mut res = 0;
    if k % 2 == 0{
        for v in 0..n{
            res = max(res, dfs(&gr, k/2, nothing, v));
        }
    } else {
        for (u, v) in edges{
            res = max(res, dfs(&gr, (k-1)/2, u, v) + dfs(&gr, (k-1)/2, v, u));
        }
    }
    println!("{}", n - res);

}

fn dfs(gr: &Vec<Vec<usize>>, depth: i64, prev: usize, v: usize) -> usize{
    if depth < 0 {
        0
    } else {
        let mut res = 1;
        for next in &gr[v]{
            let next = *next;
            if next != prev{
                res += dfs(&gr, depth - 1, v, next);
            }
        }
        res
    }
}

#[allow(dead_code)]
fn get_string() -> String{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf
}

#[allow(dead_code)]
fn get_int() -> i64{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

#[allow(dead_code)]
fn get_ints() -> Vec<i64>{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn get_int2() -> (i64, i64){
    let v = get_ints();
    (v[0], v[1])
}

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int n, cc;
int d[31][31];
int c[510][510];
int s[3][31];

int main()
{
	cin >> n >> cc;
	rep(i, cc) {
		rep(j, cc) {
			cin >> d[i][j]; //コスト
		}
	}
	rep(i, n) {
		rep(j, n) {
			cin >> c[i][j]; //色
			c[i][j]--;
			rep(k, cc) {
				s[(i + j) % 3][k] += d[c[i][j]][k]; //コストを計算しておく
			}
		}
	}
	int ans = INF;
	rep(i, cc) { //30通り
		rep(j, cc) {
			if (i != j) { //29通り
				rep(k, cc) {
					if (i != k && j != k) { //28通り
						ans = min(ans, s[0][i] + s[1][j] + s[2][k]);
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n; scanf("%d", &n);
    printf("ABC%3d\n", n);
}

Measured memory_bytes: 256
program sushi
implicit none

integer(8) :: i,j,k
integer(8) :: n,c
integer(8) :: x(200000)=0,v(200000)=0
integer(8) :: v_sum_a(200000)=0,v_sum_b(200000)=0
integer(8) :: ans1=0,ans2=0,ans3=0,ans4=0
integer(8) :: ans2_a(0:200000)=0,ans2_b(0:200000)=0,ans4_a(0:200000)=0,ans4_b(0:200000)=0
integer(8) :: val=0,ans2_best=0,ans4_best=0,ans=0

read(*,*) n,c

do i= 1,n
	read(*,*) x(i),v(i)
enddo

!時計周りに回した時のカロリー累積和
do i=1,n
	if(i == 1) then
		v_sum_a(i) = v(1)
	else
		v_sum_a(i) = v_sum_a(i-1) + v(i)
	endif
enddo

!反時計周りに回した時のカロリー累積和
do i=n,1,-1
	if(i == n) then
		v_sum_b(i) = v(n)
	else
		v_sum_b(i) = v_sum_b(i+1) + v(i)
	endif
enddo



!ans1 : 時計回りに進んで終了
do i=1,n
	ans1 = max(ans1,v_sum_a(i)-x(i))
enddo

!ans2 : 時計回りに進んでから、反時計回りに戻る
!まずは時計回りの最適値を求める。
!1～i番目の寿司の間で自由に取れて原点まで戻ったときの、カロリーの最大値
do i = 1,n
	val = v_sum_a(i) - 2 * x(i)
	ans2_a(i) = max(ans2_a(i-1),val)
enddo

!反時計周りでi～nまで取れるときの最大値
do i=n,1,-1
	val = v_sum_b(i) - (c - x(i))
	ans2_b(i) = max(ans2_b(i+1),val)
enddo

do i=0,n
	val = ans2_a(i) + ans2_b(i+1)
	ans2 = max(ans2,val)
enddo

!ans3 : 反時計回りに進んで終了
do i=1,n
	ans3 = max(ans3,v_sum_b(i)-(c-x(i)))
enddo

!ans4 : 反時計回りに進んでから、時計回りに戻る
!まずは時計回りの最適値を求める。
do i = 1,n
	val = v_sum_a(i) - x(i)
	ans4_a(i) = max(ans4_a(i-1),val)
enddo

!反時計周りでi～nまで取れるときの最大値
do i=n,1,-1
	val = v_sum_b(i) - 2 * (c - x(i))
	ans4_b(i) = max(ans4_b(i+1),val)
enddo

do i=0,n
	val = ans4_a(i) + ans4_b(i+1)
	ans4 = max(ans4,val)
enddo

ans = max(0,ans1,ans2,ans3,ans4)
write(*,*) ans

end program

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


int main(){
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    
    if(abs(a-b)<=t*(v-w))
        cout <<"YES"<<endl;
    else
        cout <<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 3600
for i in range(input()):
	train = raw_input()
	ans = set()
	for i in range(len(train)):
		f = train[:i]; rf = f[::-1]
		b = train[i:]; rb = b[::-1]
		ans |= set([f+b,rf+b,f+rb,rf+rb,b+f,rb+f,b+rf,rb+rf])
	print len(ans)

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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder from = new StringBuilder(in.readLine());
		StringBuilder to = new StringBuilder();
		final char zero = '0';
		final char one = '1';
		int c1 = 0;
		for(int i = 0; i < from.length(); i++) {
			if(i%2 == 0) {
				to.append(zero);
			}else {
				to.append(one);
			}
			if(from.charAt(i) != to.charAt(i)) {
				c1++;
			}
		}
		to = new StringBuilder();
		int c2 = 0;
		for(int i = 0; i < from.length(); i++) {
			if(i%2 == 0) {
				to.append(one);
			}else {
				to.append(zero);
			}
			if(from.charAt(i) != to.charAt(i)) {
				c2++;
			}
		}
		System.out.println(c1<c2?c1:c2);
	}
}

Measured memory_bytes: 25428
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
n=len(s)
one,zero=0,0
for i in range(n):
    if int(s[i])==1:
        one+=1
    else:
        zero+=1
print(n-abs(one-zero))

Measured memory_bytes: 3700
function time(x){
   x=x.split("").map(Number);
   return x[0]*10*60+x[1]*60+x[2]*10+x[3];
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var npq=arr.shift();
   if(npq=="0 0 0")break;
   npq=npq.split(" ");
   var n=npq[0]-0;
   var p=time(npq[1]);
   var q=time(npq[2]);
   var tv=[];
   for(var i=p;i<q;i++)tv[i]=0;
   for(var i=0;i<n;i++){
      var cm=arr.shift();
      var ary=arr.shift().split(" ");
      for(var j=0;j<cm;j++){
         var start=time(ary.shift());
         var stop=time(ary.shift());
         for(var k=start;k<stop;k++)tv[k]++;
      }
   }
   var max=0;
   var cnt=0;
   for(var i=p;i<q;i++){
      if(tv[i]!=n){cnt++;}
      else {max=Math.max(max,cnt);cnt=0;}
   }
   max=Math.max(max,cnt);
   console.log(max);
}

Measured memory_bytes: 15268
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAX = 810;
char in[MAX][MAX];
int len[MAX][MAX];
int h, w, k;

int dlt[4][2] = {{-1, 0}, {+1, 0},
                 {0, -1}, {0, +1}};

void Bfs(int x, int y){
  queue<pii> q;
  len[x][y] = 0;
  q.push(mp(x, y));

  while(!q.empty()){
    auto vr = q.front();
    q.pop();
    x = vr.fi, y = vr.se;
    for(int d = 0;d < 4;++d){
      int nx = x + dlt[d][0];
      int ny = y + dlt[d][1];
      if(nx >= 0 && ny >= 0 &&
         nx < h && ny < w){
        if(in[nx][ny] != '#' && len[nx][ny] == -1){
          len[nx][ny] = len[x][y] + 1;
          q.push(mp(nx, ny));
        }
      }
    }
  }
}

int main(){
  memset(len, -1, sizeof len);

  scanf("%d%d%d", &h, &w, &k);
  for(int i = 0;i < h;++i)
    scanf("%s", &in[i]);

  for(int i = 0;i < h;++i)
    for(int j = 0;j < w;++j)
      if(in[i][j] == 'S')
        Bfs(i, j);

  int ans = 1E9;
  for(int i = 0;i < h;++i)
    for(int j = 0;j < w;++j)
      if(len[i][j] >= 0 && len[i][j] <= k){
        int need = 1;
        int left = min(min(abs(0 - i), abs(h - 1 - i)),
                       min(abs(0 - j), abs(w - 1 - j)));
        need += (left + k - 1) / k;
        relaxMin(ans, need);
      }

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

  return 0;
}


Measured memory_bytes: 3456
// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include <bits/stdc++.h>
#include <ext/rope> 
using namespace __gnu_cxx;
using namespace std;
#define TEST  int test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007

const int INF = (int)1e8;
const int N = 500005;
int A[N];

int main()
{
    set<int>se;
    int n, cnt=0;
    si(n);
    for(int i=0;i<n;i++){
        si(A[i]);
        A[i] = A[i]/400;
        if(A[i]<8)
            se.insert(A[i]);
        else
            cnt++;
    }

    int num = (int)se.size();
    int mini = num;
    int maxi = num;
    
    
    maxi = mini + cnt;
    if(mini == 0 && cnt>0)
        mini=1;

    pis(mini), pi(maxi);
    
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CStep solver = new CStep();
        solver.solve(1, in, out);
        out.close();
    }

    static class CStep {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = Long.parseLong(in.next());
            }
            long ans = 0;
            for (int i = 1; i < n; i++) {
                if (a[i - 1] - a[i] > 0) {
                    ans += a[i - 1] - a[i];
                    a[i] += a[i - 1] - a[i];
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



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

char toggle(char s) {
  if (s == '1') {
    return '0';
  } else {
    return '1';
  }
}

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

  int num = 0;
  char p = *s.begin();
  for (string::iterator i = s.begin() + 1; i != s.end(); i++) {
    p = toggle(p);
    if (*i != p) {
      num++;
    }
  }
  cout << num;
  return 0;
}

Measured memory_bytes: 512
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let (a, b, k) = {
        let line = get_input();
        let mut split = line.split_whitespace();
        let a: usize = split.next().unwrap().parse().unwrap();
        let b: usize = split.next().unwrap().parse().unwrap();
        let k: usize = split.next().unwrap().parse().unwrap();
        (a, b, if k > b - a + 1 { b - a + 1 } else { k })
    };

    let mut n:Vec<usize> = (a..a+k).collect();
    let mut n2:Vec<usize> = (b-k+1..b+1).collect();
    n.append(&mut n2);

    n.sort();
    n.dedup();

    for i in n {
        println!("{}", i);
    }
}

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

int main(){
  int A, B;
  cin >> A >> B;
  if(A == B) cout << A + B << endl;
  else{
  	int ans = 0;
  	int a = max(A, B);
  	ans += a;
  	a--;
  	ans += a;
  	cout << ans << endl;
  }
}

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

typedef long long LL;

struct sushi {
    LL dist, energy;
};

sushi sushi_seq[100005];

LL sum_right[100005];
LL sum_left[100005];

int main() {
    LL N, C, x, v, max_rf = 0, max_lf = 0, sum_lf = 0;
    LL max_rr = 0, max_ll = 0, sum_rr = 0;
    cin >> N >> C;

    sushi_seq[0].dist = sushi_seq[0].energy = 0;

    for (int i = 1; i <= N; i++) {
        cin >> x >> v;
        sushi_seq[i].dist = x; sushi_seq[i].energy = v;
    }

    // 2OB + OAの場合
    for (int i = 0; i <= N; i++) {
        if (i != 0) {
            sum_lf += sushi_seq[i].energy;
            if (max_rf < sum_lf - sushi_seq[i].dist) {
                max_rf = sum_lf - sushi_seq[i].dist;
            }
        }
        sum_right[i] = max_rf;
    }

    sum_left[0] = 0;
    sum_lf = 0;

    for (int i = 1; i <= N; i++) {
        sum_lf += sushi_seq[N + 1 - i].energy;
        sum_left[i] = sum_lf;
    }

    for (int i = 0; i <= N; i++) {
        if (i == 0) {
            max_lf = max(max_lf, sum_left[i] + sum_right[N]);   
        }
        else {
            max_lf = max(max_lf, sum_left[i] - 2 * (C - sushi_seq[N - i + 1].dist) + sum_right[N - i]);
        }
    }

    // 2OA + OBの場合
    for (int i = 0; i <= N; i++) {
        if (i != 0) {
            sum_rr += sushi_seq[N - i + 1].energy;
            if (max_ll < sum_rr - (C - sushi_seq[N - i + 1].dist)){
                max_ll = sum_rr - (C - sushi_seq[N - i + 1].dist);
            }
        }
        sum_left[i] = max_ll;
    }

    sum_rr = 0;
    for (int i = 0; i <= N; i++) {
        sum_rr += sushi_seq[i].energy;
        sum_right[i] = sum_rr;
    }

    for (int i = 0; i <= N; i++) {
        if (i == 0) {
            max_rr = max(max_rr, sum_right[i] + sum_left[N]);
        }
        else {
            max_rr = max(max_rr, sum_right[i] - 2 * sushi_seq[i].dist + sum_left[N - i]);
        }
    }

    cout << max(max_lf, max_rr) << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#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;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#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 INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)


typedef map<string, int> map_type;
typedef pair<string, int> value_type;

struct second_order {
  bool operator()(const value_type& x, const value_type& y) const {
    if( x.second != y.second) return x.second < y.second;
    return x.first > y.first;
  }
};

typedef priority_queue<value_type, vector<value_type>, second_order> pqueue_type;


pqueue_type map_to_pqueue(map_type m) {
    pqueue_type que;
    for(auto it=m.begin(); it!=m.end(); ++it) {
        que.push(*it);
    }
    return que;
}


int main(void){
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d;
    cin >> n;
    s = min(s, 2*min(h, 2*q));
    ll cost = 0;
    if(s*2 <= d) {
        cost = n*s;
    }else {
        cost = (n/2)*d + (n%2)*s;
    }
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	class position{

		double x;

		double y;

		double dist(position p){

			return Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));

		}

		position(String str){

			Scanner in = new Scanner(str.replace(',', ' '));

			x = in.nextDouble();

			y = in.nextDouble();

		}

	}

	void run(){

		position org = new position(sc.nextLine());

		position a = org;

		position b = org;

		double sum = 0;

		for(;sc.hasNextLine();){

			a = new position(sc.nextLine()); 

			

			double z=(org.dist(a)+org.dist(b)+a.dist(b))/2;

			sum += Math.sqrt(z*(z-org.dist(a))*(z-org.dist(b))*(z-a.dist(b)));

			b = a;

		}

		System.out.println(sum);

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 13000
def main(input_str):
    nums = list(map(int, input_str.split()))

    count = 0
    for num_1 in range(nums[0]+1):
        for num_2 in range(nums[0]+1):
            if 0 <= nums[1]-(num_1+num_2) <= nums[0]:
                count += 1

    return count


if __name__ == "__main__":
    input_str = input()
    print(main(input_str))


Measured memory_bytes: 40556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,tmp;
    cin>>n;
    cout<<!n<<endl;

}


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

int main()
{
	int x,y; cin>>x>>y;
	if (x<y){
		for(int i=0;i<y;i++)
		{
			cout<<x;
		}}
	else{
		for(int i=0;i<x;i++)
		{
			cout<<y;
		}
	}
}


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


# See:
# https://img.atcoder.jp/arc074/editorial.pdf
def calc(h, w):
    ans = float('inf')

    # Key Insight: ABCのC問題の基本は全探索
    # 分割方法は4通り
    # h, wを入れ替えれば実質2通り

    # 長方形Aの面積saを全探索
    for hi in range(1, h):
        sa = hi * w

        # 残りの長方形の扱い
        # 縦に2分割
        wi = w // 2
        sb = (h - hi) * wi
        sc = (h - hi) * (w - wi)
        ans = min(ans, max(sa, sb, sc) - min(sa, sb, sc))

        # 横に2分割
        hj = (h - hi) // 2
        sb = hj * w
        sc = (h - hi - hj) * w
        ans = min(ans, max(sa, sb, sc) - min(sa, sb, sc))

    return ans


def main():
    h, w = map(int, input().split())

    print(min(calc(h, w), calc(w, h)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;cin>>n;
    map<vector<int>,int> s;
    ll ans = 0;
    rep(i,n){
        string t;cin >> t;
        vector<int> tmp(26,0);
        rep(j,10){
            tmp[t[j]-'a']++;
        }
        ans += s[tmp]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18944
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int x[100001];
int y[100001];
int t[100001];

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

	t[0] = 0;
	x[0] = 0;
	y[0] = 0;

	repe(i, 1, N) {
		cin >> t[i] >> x[i] >> y[i];
	}

	repe(i, 1, N) {
		int T = t[i] - t[i - 1];
		int X = x[i] - x[i - 1];
		X = (X < 0) ? -X : X;
		int Y = y[i] - y[i - 1];
		Y = (Y < 0) ? -Y : Y;

		if ((X + Y) > T || (T - (X + Y)) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll r = 0;
    for (int i = 1; i * i <= n; i++) {
        r += i * i;
        r += (ll)(n / i - i) * i * (n / i + (i + 1));
    }

    cout << r << endl;

    return 0;
}

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

struct st { int x, y, d; };
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int main()
{
  int H, W, ans = 0;
  cin >> H >> W;
  char Maze[H][W];
  rep(i, H) {
    rep(j, W) {
      char c;
      cin >> c;
      if (c == '.') ans++;
      Maze[i][j] = c; 
    }
  }

  vector<vector<int>> vs(H, vector<int>(W, 0));
  queue<st> q;
  q.push({0, 0, 0});
  vs[0][0] = true;

  while (!q.empty()) {
    st p = q.front(); q.pop();
    if (p.x == W-1 && p.y == H-1) {
      ans -= p.d+1;
      cout << ans << endl;
      return 0;
    }
    
    rep(i, 4) {
      int nx = p.x + dx[i], ny = p.y + dy[i];
      if (Maze[ny][nx] == '#' || nx >= W || nx < 0 || ny >= H || ny < 0 || vs[ny][nx]) continue;
      vs[ny][nx] = true;
      q.push({nx, ny, p.d+1});
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct
{
    char name[10];
    int time;
}Task;
Task Q[100001];
int head=1, tail=1, n;
void enqueue(Task x)
{
    Q[tail]=x;
    if(tail==n) tail=1;
    else tail++;
}
Task dequeue(void)
{
    if(head==(n+1)) head=2;
    else head++;
    return Q[head-1];
}
int main()
{
    Task u;
    int q, time, i, count=0;
    long int sum;
    char name[10];

    scanf("%d %d", &n, &q);

    for(i=1;i<=n;i++)
        scanf("%s %ld", &Q[i].name, &Q[i].time);

    while(count!=n)
    {
        u=dequeue();
        if(u.time<=q)
        {
            sum+=u.time;
            printf("%s %d\n", u.name, sum);
            count++;
        }
        else
        {
            sum+=q;
            u.time-=q;
            enqueue(u);
        }
    }

    return 0;
}

Measured memory_bytes: 1380
#include<iostream>
using namespace std; 
int main( ){
  int a,b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if( op == '?' )break;
    if( op == '+' )printf("%d\n",a+b);
    if( op == '-' )printf("%d\n",a-b);
    if( op == '*' )printf("%d\n",a*b);
    if( op == '/' )printf("%d\n",a/b);
  }
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1010;

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) {
	    res=res*x;
	    res%=mod;
	}
	x=x*x;
	x%=mod;
	y=y/2;
    }
    
    res%=mod;
    res+=mod;
    return res%mod;
}

ll add(ll x, ll y) {
    x %= mod;
    y %= mod;
    x += y;
    x %= mod;
    return x;
}


ll C[maxn][maxn];
ll fac[maxn*maxn], ifac[maxn*maxn], inv[maxn*maxn];

int n,a,b,c,d;


ll nck(int n, int k) {
    if (n<k) return 0;
    return C[n][k];
}

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

    //idk why my code doesn't work

    for (int i=0; i<=1000; i++) {
	C[i][0] = C[i][i] = 1;
	for (int j=1; j<i; j++) {
	    C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
	}
    }
    assert(C[4][2]==6);

    fac[0]=ifac[0]=1;
    for (int i=1; i<=1000000; i++) {
	fac[i]=fac[i-1]*i%mod;
    }
    
    inv[1]=1;
    for (int i=2; i<=1000000; i++) {
	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
    }

    for (int i=1; i<=1000000; i++) {
	ifac[i] = ifac[i-1]*inv[i]%mod;
    }
    assert(ifac[1] == 1);
    assert(inv[6] == ifac[3]);
    assert(inv[47] == pw(47, mod-2));



    cin>>n>>a>>b>>c>>d;

    vector<ll> dp(n+1, 0);//num ways to use j ppl at the current iteration
    dp[0] = 1;

    for (int i=a; i<=b; i++) {
	vector<ll> nxt(n+1, 0);

	for (int j=0; j<=n; j++) {
	    if (dp[j] == 0) continue;
	    ll ways = 1;
	    for (int k=0; k<=n-j; k+=i) {
		if (k==0 || (c<=k/i && k/i<=d)) {
		    nxt[j+k] = add(nxt[j+k], dp[j]*ways);
		}

		ways = ways*nck(n-j-k, i)%mod*inv[k/i+1]%mod;
			
	    }
	}

	swap(nxt, dp);
    }


    cout<<dp[n]<<endl;    

    return 0;
}


Measured memory_bytes: 32128
/**/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n;cin>>n;
	if(n%2==1){
		cout<<0<<"\n";
		exit(0);
	}
	ll z=n/2,p=1,ans=0;
	while(z>=(ll)pow(5,p))
	{
		ans+=z/((ll)pow(5,p));
		++p;
	}
	cout<<ans<<"\n";

	
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int N, L;
int x[101010];
int sparse[18][101010];
int main()
{
    scanf("%d", &N);
    for(int i=0; i<N; ++i) scanf("%d", x+i);
    x[N] = (int)2.1e9;
    scanf("%d", &L);
    
    for(int i=0; i<N; ++i)
        sparse[0][i] = upper_bound(x, x+N, x[i]+L) - 1 - x;
    for(int j=1; j<=17; ++j)
        for(int i=0; i<N; ++i)
            sparse[j][i] = sparse[j-1][sparse[j-1][i]];
    
    int Q; scanf("%d", &Q);
    for(int i=0; i<Q; ++i)
    {
        int a, b; scanf("%d%d", &a, &b); --a; --b;
        if(a>b) swap(a, b);
        int ans = 0;
        for(int j=17; j>=0; --j)
        {
            if(sparse[j][a] < b)
            {
                ans += (1<<j);
                a = sparse[j][a];
            }
        }
        printf("%d\n", ans+1);
    }
    return 0;
        
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,r;
	scanf("%d%d",&r,&n);
	if(r>=10)printf("%d\n",n);
	else printf("%d\n",n+100*(10-r));
}

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

int main(){
    int a,b,ma,mi=1;
    cin>>a>>b;
    ma=a;
    vector<int>c(100000000);
    vector<int>d(100000000);
    for(int i=0;i<b;i++){
        cin>>c[i]>>d[i];
        if(c[i]>mi){
            mi=c[i];
        }
        if(d[i]<ma){
            ma=d[i];
        }
    }

    cout<<max(ma-mi+1,0)<<endl;
}

Measured memory_bytes: 781568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // メインプログラムここから
    ll s,c;cin>>s>>c;
    ll ans=min(s,c/2);
    s=s-ans;
    c=c-ans*2;
    ans=ans+c/4;
    cout<<ans<<endl;
    // ここまで
}


Measured memory_bytes: 256
def valid(a, b, s):
    if len(s) == a + b + 1 and s[a] == '-':
        return all(map(lambda c: c in '0123456789', s[:a] + s[a+1:]))
    else:
        return False


if __name__ == '__main__':
    a, b = map(int, input().split())
    s = input()
    print('Yes') if valid(a, b, s) else print('No')

Measured memory_bytes: 3060