akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for(it = (a).begin(); it != (a).end; it++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

#define N 100

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

int bfs(bool M[N][N], int h, int w){
    int dis[N][N];
    queue<point> q;
    rep(i,N) rep(j,N) dis[i][j] = INF;
    point a;
    a.x = 2;
    a.y = 0;

    dis[0][2] = 0;
    q.push(a);

    point u;
    while(!q.empty()){
        u = q.front(); q.pop();
        rep(i,4){
            point next;
            next.x = u.x + dx[i];
            next.y = u.y + dy[i];
            if(M[next.y][next.x] != 1 && dis[next.y][next.x] == INF){
                dis[next.y][next.x] = dis[u.y][u.x] + 1;
                q.push(next);
            }
        }
    }
    return dis[h + h - 1][w + w] + 1;
}

void printMaze(int h, int w, bool M[N][N]){
    rep(i,h + h - 1){
        rep(j,w + w + 1){
            cout << M[i][j];
        }
        cout << endl;
    }
}

int main(){
    /*
    10101
    10111
    10001
    11101
    10101
    */
    int w, h;
    while(cin >> w >> h, w||h){
        bool M[N][N] = {0};
        rep(i,N) rep(j,N) M[i][j] = 1;
        rep(i,h + h - 1){
            if(i % 2){
                for(int j = 0; j <= w + w; j++){
                    if(j == 0 || j == w + w) M[i + 1][j + 1] = 1;
                    else if(j % 2 == 0) M[i + 1][j + 1] = 1;
                    else cin >> M[i + 1][j + 1];
                }
            }else{
                for(int j = 0; j <= w + w; j++){
                    if(j == 0 || j == w + w) M[i + 1][j + 1] = 1;
                    else if(j % 2 == 1) M[i + 1][j + 1] = 0;
                    else cin >> M[i + 1][j + 1];
                }
            }
        }
        long long ans = bfs(M,h,w);
        if(ans > 20000) cout << 0 << endl;
        else cout << ans / 2 << endl;
    }
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C')
        {
            for(int j=i+1;j<a.size();j++)
            {
                if(a[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

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

using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

ll shop[110][20];
ll v[110], w[110];
ll p[110][20];

//long longしか使わない
//素数は1より大きい
int main() {
	string s, t;
	cin >> s >> t;
	ll n = s.length();
	ll m = t.length();
	bool flag2 = false;
	for (ll i = n - m;i >= 0;--i) {
		if (s[i] == t[0] || s[i] == '?') {
			bool flag = true;
			for (ll j = 0;j < m;++j) {
				if (s[i + j] != t[j] && s[i + j] != '?')flag = false;
			}
			if (flag) {
				rep(j, m) {
					if (s[i + j] == '?')s[i + j] = t[j];
				}
				flag2 = true;
				break;
			}
		}
	}
	if (flag2) {
		rep(i, n) {
			if (s[i] == '?')s[i] = 'a';
		}
		cout << s << endl;
	}
	else {
		puts("UNRESTORABLE");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    map<int,int> m;
    rep(i,N){
        int a; cin >> a;
        m[a]++; m[a-1]++; m[a+1]++;
    }
    int ans=0;
    for(auto p:m){
        ans=max(ans,p.second);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6144
program ABC_083_B_SomeSums
   implicit none
   integer N, A, B, v, Sumrank, co, i, j, k, l, m
   read(*, *) N, A, B
   co = 0
   do m = 0, 1
       do l = 0, 9
           do k = 0,9
               do j = 0, 9
                   do i = 0, 9
                      v = i + 10*j + 100*k + 1000*l + 10000*m
				      Sumrank = i + j + k + l + m
	                  if( v > N ) then
	                      goto 1
	                  else if( (A <= Sumrank) .and. (Sumrank <= B) ) then
                          co = co + v
                      end if
                   end do
		       end do
	       end do
       end do
   end do
   1 continue
   write(*, *) co
end  program ABC_083_B_SomeSums

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char s[N];
int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	scanf("%s", s);
	int cnta = 0, cntb = 0;
	for (int i = 0; i < n; ++ i) {
		if (s[i] == 'a') {
			if (cnta + cntb < a + b) {
				cnta ++;
				puts("Yes");
			}
			else puts("No");
		}
		else if (s[i] == 'b') {
			if (cntb < b && cnta + cntb < a + b) {
				cntb ++;
				puts("Yes");
			}
			else puts("No");
		}
		else puts("No");
	}
}


Measured memory_bytes: 768
import sys

sys.setrecursionlimit(3000)

while True:

    w, h = map(int, input().split())

    if w == 0 and h == 0:
        exit() 

    C = []
    for i in range(h):
        c = list(map(int, input().split()))
        C.append(c)

    def is_island(i, j):
        if 0 <= i < h and 0 <= j < w and C[i][j] == 1:
            C[i][j] = 0
            return True
        else:
            return False

    def walk_to(i, j):
        if is_island(i - 1, j):
            walk_to(i - 1, j)
        if is_island(i - 1, j - 1):
            walk_to(i - 1, j - 1)
        if is_island(i, j - 1):
            walk_to(i, j - 1)
        if is_island(i + 1, j - 1):
            walk_to(i + 1, j - 1)
        if is_island(i + 1, j):
            walk_to(i + 1, j)
        if is_island(i + 1, j + 1):
            walk_to(i + 1, j + 1)
        if is_island(i, j + 1):
            walk_to(i, j + 1)
        if is_island(i - 1, j + 1):
            walk_to(i - 1, j + 1)

    count = 0        
    for i in range(h):
        for j in range(w):
            if is_island(i, j):
                count = count + 1
                walk_to(i, j)

    print(count)



Measured memory_bytes: 7604
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int R = sc.nextInt();
		int G = sc.nextInt();
		System.out.println(2 * G - R);
	}
}

Measured memory_bytes: 22612
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

if N == 2:
    print(max(A))
else:
    a = gcd(A[1], A[2])
    b = gcd(A[0], A[2])
    c = gcd(A[0], A[1])
    mx = max(a, b, c)
    mn = gcd(c, A[2])

    for a in A[3:]:
        new = gcd(mx, a)
        mx = max(new, mn)
        mn = gcd(mn, a)
    print(mx)

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> divid;
  for(int i=1;i<=(double)sqrt(M);i++){
    if(M%i==0){
      divid.push_back(i);
      divid.push_back(M/i);
    }
  }
  sort(divid.begin(),divid.end());

  int n=divid.size();
  for(int i=0;i<n;i++){
    if(divid.at(i)>=N){
      cout<<M/divid.at(i)<<endl;
      break;
    }
  }
}


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

#define int long long
#define MAX_N (200005)
#define INF (1LL<<60)
#define EPS (1e-7)
#define DEBUG(x) cerr << #x <<":"<< x << endl;
#define DEBUGVC(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define DEBUGVCP(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define DEBUG2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define DEBUG3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;

signed main() {
    int r,g,b,n;
    cin >> r >> g >> b >> n;

    int ans=0;
    for(int i=0; i<=3000; i++){
        for(int j=0; j<=3000; j++){
            int rc = i*r;
            int gc = j*g;
            int bc = n-rc-gc;
            if(bc < 0) continue;
            if(bc%b==0){
                ans++;
            }
        }
    }

    cout << ans << endl;

}

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

using namespace std;
typedef long long ll;

int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    vector<int> memo(H * W);
    vector<int> acc_a(N + 1);
    for (int i = 0; i < N; i++)
    {
        acc_a[i + 1] = acc_a[i] + a[i];
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = acc_a[i]; j < acc_a[i + 1]; j++)
        {
            memo[j] = i;
        }
    }

    vector<vector<int>> ans(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int jj = j;
            if (1 == i % 2)
            {
                jj = W - 1 - j;
            }
            ans[i][jj] = memo[W * i + j];
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << ans[i][j] +1<< ' ';
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    if(n==0)
    {
        cout<<0;
    }
    else if(n==1)
    {
        cout<<h[0];
    }
    int inf=1e9;
    vector<int>dp(n,inf);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+2;j++)
        {
            if(j<n)
            {dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));}
        }
    }
    cout<<dp[n-1];
}


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

int main() {
    int n;
    double t, a;
    cin >> n >> t >> a;
    int ans;
    double mind = 1e9;
    for (int i=0; i<n; ++i) {
        double h; cin >> h;
        double d = abs(a - (t - h * 0.006));
        if (d < mind) {
            ans = i + 1;
            mind = d;
        }
    }
    cout << ans << endl;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();

  int flag = 0;
  if(s[0] != 'A') flag = 1;

  int cnt = 0;
  int numc = 0;
  for(int i = 2; i < n-1; i++){
    if(s[i] == 'C') cnt++;
  }
  if(cnt != 1) flag = 1;

  for(int i = 1; i < n; i++){
    if(s[i] == 'C') continue;
    if(s[i] - 'a' < 0) flag = 1;
  }

  if(flag){
    cout << "WA" << endl;
  }else{
    cout << "AC" << endl;
  }

  return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt(), n = sc.nextInt();
        int count = 0;
        for(int i=x; i<=y; i++) {
            if(n%i==0){
                count++;
            }
        }
        System.out.printf("%d\n", count);
    }
}


Measured memory_bytes: 26380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  rep(i, 2) rep(j, N) cin >> A.at(i).at(j);
  int ans = 0;
  rep(i, N){
    int ame = 0;
    rep(j, N){
      if(j < i){
        ame += A.at(0).at(j);
      } else if (j == i) {
        ame += A.at(0).at(j) + A.at(1).at(j);
      } else {
        ame += A.at(1).at(j);
      }
    }
    ans = max(ame, ans);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {

int n;
cin>>n;
vector<int> v;

for(int i=0;i<n;i++)
{
	int x;
	cin>>x;
	v.push_back(x);
}
sort(v.begin(),v.end());
int max=v[n-1];

int arr[max+1];
for(int i=0;i<=max;i++)
arr[i]=0;

for(int i=0;i<n;i++)
{
	for(int j=v[i];j<=max;j+=v[i])
	{
		if(arr[j]==0 )
		{
			if(j==v[i])
			 arr[j]=1;
			 else
			 arr[j]=-1;
		}
		else if(arr[j]==1)
		{
			arr[j]=-1;
		}
	}
}

int count=0;
for(int i=0;i<n;i++)
{
	if(arr[v[i]]==1)
	count++;
}
cout<<count;
	return 0;
}

Measured memory_bytes: 8008
fun main(args: Array<String>) {
  val (X, t) = readInts()
  val v = X - t
  println(if (v < 0) 0 else v)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 37768
//#pragma Gbb optimize("Ofast") 
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<time.h>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

long long x, y, z;

int main()
{
	cin >> x >> y >> z;
	if (z - x - y <= 0) cout << "No";
	else
	{
		z = (z - x - y) * (z - x - y);
		if (z > 4 * x * y) cout << "Yes";
		else cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <algorithm>
using namespace std;
int n, m;
int hashp[20];

bool check(int &x){
	for (int i = n; i <= 10000; ++ i)
	{
		int j = i;
		while (j){
			int y = j % 10;
			if (hashp[y]) break;
			j /= 10;
		}
		if (j == 0) {
			//printf("x == %d\n", x);
			x = i;
			return true;
		}
	}
	return false;
}
int main(){
	int  i, j;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; ++ i){
		int x;
		scanf("%d", &x);
		hashp[x] = 1;
	}
	int ans = 0;
	if (check(ans)) {
		printf("%d\n", ans);
		return 0;
	}
	while (ans < n){
		for (j = (ans == 0 ? 1 : 0); j <= 9; ++ j)
		if (!hashp[j]) {
			ans = ans * 10 + j;
			break;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
  string s;
  cin>>s;
  ll q;
  cin>>q;
  list<char> l;
  for(int i=0;i<s.size();i++)l.push_back( s[i] );
  int state = 1;
  for(int i=0;i<q;i++){
   int t;
   cin>>t;
   if( t == 1 ){
    state *= -1;
   }else{
    int f;
    char c;
    cin>>f>>c;
    if( f == 2 ) f = -1;
    if( state * f == 1 ){
     l.push_front(c);
    }else{
     l.push_back(c);
    }
   }
  }
  if( state == -1 ){
   l.reverse();
  }
  for(auto i:l)cout<<i;
  cout<<endl;
    return 0;
}


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

const int INF = 1001001001;

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

  ll ans = 0;
  for(int i = 1; i < n+1; i++){
    if(i%3 != 0) {
      if(i%5 != 0){
        ans += i;
      }
    }
  }

  cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,t[100000];
  cin>>n>>k;
  for(int i=0;i<n;i++)cin>>t[i];
  vector<int> s;
  for(int i=1;i<n;i++)s.push_back(-(t[i]-t[i-1]-1));
  sort(s.begin(),s.end());
  int sum=t[n-1]-t[0]+1;
  for(int i=0;i<k-1;i++)sum+=s[i];
  cout<<sum<<endl;
  return 0;
}



Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;

ll n,m,q, a[55], b[55], c[55],d[55];
ll k[13];
ll dfs(ll* k, ll p, ll cn){
    ll res;
    if(p==n){
        res = 0;
        REP(i,q){
            if(k[b[i]-1]-k[a[i]-1]==c[i]){
                res+=d[i];
            }
        }
        return res;
    }
    res = 0;
    FOR(i,cn,m){
        k[p]=i;
        res = max(res, dfs(k,p+1,i));
    }
    return res;
}

int main(){FIN
    
    cin>>n>>m>>q;
    REP(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    cout<<dfs(k,0,1)<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int k;
  cin >> k;
  if(k < 10){
    cout << k << endl;
    return 0;
  }
  queue<ll> q;
  rep2(i, 1, 10) q.push(i);
  rep(i, k-1){
    ll now = q.front(); q.pop();
    int m = now % 10;
    now *= 10;
    if(m != 0){
      q.push(now + m - 1);
    }
    q.push(now + m);
    if(m != 9){
      q.push(now + m + 1);
    }
  }
  cout << q.front() << endl;
  return 0;
}

Measured memory_bytes: 5108
#include <stdio.h>

int main(void) {

	int  i, j, H, W;

	while (1) {

		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) {
			break;
		}

		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {

				

				if (i % 2 == 0 && j % 2 == 1) {
					printf(".");
				}

				else if (i % 2 == 1 && j % 2 == 0) {
					printf(".");
				}

				else {
					printf("#");
				}
			

			}

			printf("\n");

		}

		printf("\n");

	}

	return(0);

}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string res;
	if (N < 1200) {
		res = "ABC";
	}
	else if (N < 2800) {
		res = "ARC";
	}
	else {
		res = "AGC";
	}
	cout << res << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;


void go_karatsuba(auto a, auto b, auto ret, size_t n){
    if(n<=16){
        fill(ret, ret+n*2, 0);
        for(size_t i=0; i<n; ++i)
        for(size_t j=0; j<n; ++j) ret[i+j] += a[i]*b[j];
    }else
    if(n&1){
        go_karatsuba(a,b,ret,n-1);
        ret[n*2-3] = 0;
        for(size_t i=0; i<n-1; ++i) ret[i+n-1] += a[i]*b[n-1] + b[i]*a[n-1];
        ret[n*2-2] = a[n-1]*b[n-1];
    }else{
        auto ar = a, al = a+n/2, 
		     br = b, bl = b+n/2,
        	 asum = ret+n*5, bsum = asum+n/2,
        	 x1 = ret, x2 = x1+n, x3 = x2+n;
        for(size_t i=0; i<n/2; ++i){
            asum[i] = al[i] + ar[i];
            bsum[i] = bl[i] + br[i];
        }
        go_karatsuba(ar, br, x1, n/2);
        go_karatsuba(al, bl, x2, n/2);
        go_karatsuba(asum, bsum, x3, n/2);
        for(size_t i=0; i<n; ++i) x3[i] -= x1[i]+x2[i];
        for(size_t i=0; i<n; ++i) ret[i+n/2]+=x3[i];
	}
	ret[n*2-1] = 0;
}

template<class T>
vector<T> mul(const vector<T> &_a, const vector<T> &_b){
	vector<T> a = _a, b = _b;
	auto n = max(size(a), size(b));
	a.resize(n);
	b.resize(n);
	vector<T> ret(n*6);
	go_karatsuba(begin(a), begin(b), begin(ret), n);
	return vector<T>(begin(ret), begin(ret)+size(_a)+size(_b)-1);
} 


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	const int P = 2e5+3;
	const int g = 2;
	
	vector<int> f(P);
	for(int x=1,i=0;i<P-1;++i){
		f[x] = i;
		x = 1LL*x*g %P;
	}
	
	int n;
	cin>>n;
	
	vector<int> a(n);
	for(auto &_ : a) cin>>_;
	//ll answer = 0;
	//for(int i=0;i<n;++i) for(int j=0;j<n;++j) answer+=1LL*a[i]*a[j]%P;
	
	vector<ll> cnt(P-1);
	for(int x : a){
		x%=P;
		if(x) cnt[f[x]]++;
		//cerr<<x<<' '<<f[x]<<endl;
	}
	
	//for(int i=0;i<P;++i) cout<<cnt[i]<<' '; cout<<endl;
	
	auto m = mul(cnt,cnt);
	//for(auto x : m) cout<<x<<' '; cout<<endl;
	for(int i=P-1;i<size(m);++i) m[i%(P-1)]+=m[i];
	m.resize(P-1);
	//for(auto x : m) cout<<x<<' '; cout<<endl;
	
	ll ans = 0;
	for(int i=0,x=1; i<P-1; ++i, x=1LL*x*g%P) ans+=m[i]*x;
	
	for(int x:a) ans-=1LL*x*x%P;
	ans/=2;
	
	cout<<ans<<endl;
	
	//cout<<answer<<endl;
	
	return 0;
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool judge = true;
    for(int i = 0;i < s.size();i++){
        if(i % 2 == 0){
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
            else{
                judge = false;
                break;
            }
        }else{
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
            else{
                judge = false;
                break;
            }
        }
    }
    if(judge)cout << "Yes" << endl;
    else cout << "No" << endl;
    //cin >> s;
}


Measured memory_bytes: 256
N = int(input().rstrip())
judge = []
for _ in range(N):
  hap_lst = list(map(int, input().rstrip().split(' ')))
  if not judge:
    judge = hap_lst
  else:
    a_0, b_0, c_0 = judge
    a_1, b_1, c_1 = hap_lst
    judge = [a_1 + max(b_0, c_0), b_1 + max(a_0, c_0), c_1 + max(a_0, b_0)]
print(max(judge))


Measured memory_bytes: 9132
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		
		long total = 0;
		
		for(int a = 1; a < k+1; a++) {
			for(int b = 1; b < k+1; b++) {
				for(int c = 1; c < k+1; c++) {
					total += gcd(gcd(a, b), c);
				}
			}
		}
		System.out.println(total);
	}
	
	//ユークリッドの互除法
	static int gcd(int p, int q) {
		if(p % q == 0)	return q;	//最大公約数
		return gcd(q, p % q);		//答えが見つかるまで繰り返し
	}

}


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

using namespace std;
int main(void){
int n;
int p=0,w=0,g=0,y=0;
char s[101];
int count=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i];

if(s[i]=='Y')
y--;
}
if(y<0)
cout<<"Four"<<endl;
else cout<<"Three"<<endl;
}

Measured memory_bytes: 256
/*
AOJ - ITP1_7_b
Date: 20180930
Author: Mikoron
 */

#include<stdio.h>

int main(void) {
        short i, j, k, n, x, count;

        while(1) {
                scanf("%hd %hd", &n, &x);
                if(n == 0 && x == 0) break;
                count = 0;
                for(i = 1; i <= n; i++) {
                        for(j = i+1; j <= n; j++) {
                                for(k = j+1; k <= n; k++) {
                                        if(i + j + k == x) count++;
                                }
                        }
                }
                printf("%d\n", count);
        }

        return 0;
}



Measured memory_bytes: 2124
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    long N, A, B, BLUE, L;
    cin >> N >> A >> B;
    L = floor(N / (A + B));
    BLUE = L * A;
    N %= (A + B);
    BLUE += N > A ? A : N;
    cout << BLUE;
}

Measured memory_bytes: 256
n=int(input())
b=list(map(int,input().split()))
ans=0

for i in range(n):
  if i == 0:
    ans+=b[0]
  elif 0<i<n-1:
    ans+=min(b[i-1],b[i])
  else:
    ans+=b[n-2]
    
print(ans)
 

Measured memory_bytes: 3060
import java.util.Scanner;

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

		String abString = String.valueOf(a) + String.valueOf(b);
		int abInt = Integer.parseInt(abString);
		String result = "No";

		for (int i = 1 ; i <= abInt; i++) {
			if (i * i == abInt) {
				result = "Yes";
				break;
			}
		}
		System.out.println(result);

	}
}



Measured memory_bytes: 21844
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    a: usize,
    b: usize,
    k: usize,
    }
    if b - a + 1 <= 2 * k {
        for i in a..b + 1{
            println!("{}", i)
        }
        return
    }
    for i in 0..k {
        println!("{}", a + i)
    }
    for i in (0..k).rev() {
        println!("{}", b - i)
    }
}


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

int main(){
    long long n,k,s;cin>>n>>k>>s;

    for (long long i=0;i<k;i++){
        if (i == n-1){
            cout << s << endl;
        } else {
            cout << s << " ";
        }
    }
    for (long long i=0;i<n-k;i++){
        if (i == n - k - 1){
            if (s == 1000000000){
                cout << 1 << endl;
            } else {
                cout << s + 1 << endl;
            }
        } else {
            if (s == 1000000000){
                cout << 1 << endl;
            } else {
                cout << s + 1 <<" ";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
 
public class Main {
    static int rank1 = -1;
    static int rank2 = -1;
    static int rank3 = -1;
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for (int i=0; i < 10; i ++) {
 
            try {
                int readVal = Integer.parseInt(br.readLine());
                updateRank(readVal);
 
            } catch (Exception e) {
            }
        }
        System.out.println(rank1);
        System.out.println(rank2);
        System.out.println(rank3);
    }
 
    static void updateRank(int rank) {
 
        if (rank > rank1) {
            rank3 = rank2;
            rank2 = rank1;
            rank1 = rank;
        }
        else if ( rank > rank2) {
            rank3 = rank2;
            rank2 = rank;
        }
        else if (rank > rank3) {
            rank3 = rank;
        }
    }
}

Measured memory_bytes: 24124
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll test[1234];
signed main() {
	ll n, x, l, q, a = 0, b = 0, c = 0, d = 0, ans = 0;
	for (int h = 0; h < 4; h++) {
		cin >> test[h];
	}
	sort(test, test + 4);
	if (test[0] == 1 && test[1] == 4 && test[2] == 7 && test[3] == 9) {
		cout << "YES" << endl;
	}
	else { cout << "NO" << endl; }
	
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long

//DPバージョン
int main(void){
    int N,A,B;
    scanf("%d %d %d",&N,&A,&B);
    long long int v[51];
    rep(i,N)scanf("%lld",&v[i]);
    long double ave=0;
    long long int cas=0;
    long long int dp[51][51];//dp[j][k]=j番目まででkこ使った時の合計値の最大値
    long long int dp_case[51][51];//同様に選び方の場合の数
    rep(j,N){
        if(j==0){
            dp[0][0]=0;dp[0][1]=v[0];
            dp_case[0][0]=1;dp_case[0][1]=1;
        }else rep(k,j+2){
            dp[j][k]=-1;dp_case[j][k]=-1;
            if(dp[j][k]<dp[j-1][k]){
                dp[j][k]=dp[j-1][k];
                dp_case[j][k]=dp_case[j-1][k];
            }else if(dp[j][k]==dp[j-1][k]){
                dp_case[j][k]+=dp_case[j-1][k];
            }
            if(k-1>-1)if(dp[j][k]<dp[j-1][k-1]+v[j]){
                dp[j][k]=dp[j-1][k-1]+v[j];
                dp_case[j][k]=dp_case[j-1][k-1];
            }else if(dp[j][k]==dp[j-1][k-1]+v[j]){
                dp_case[j][k]+=dp_case[j-1][k-1];
            }
            if(j==N-1&&k>=A&&k<=B&&dp_case[j][k]>0){
                long double newave=(long double)(dp[j][k])/(long double)(k);
                if(ave<newave){
                    ave=newave;cas=dp_case[N-1][k];
                }else if(ave==newave){
                    cas+=dp_case[N-1][k];
                }
            }
        }
    }
    printf("%llf\n%lld\n",ave,cas);
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
vector<edge> es[114514];
int d[114514]={};
bool vis[214514]={};
bool ans=1;
void solve(int k){
    vis[k]=true;
    rep(i,0,es[k].size()){
        if(d[es[k][i].to]==inf){
            if(d[k]==inf)d[k]=0;
            d[es[k][i].to]=d[k]+es[k][i].cost;
        }
        else if(d[k]==inf)d[k]=d[es[k][i].to]-es[k][i].cost;
        else if(d[es[k][i].to]!=d[k]+es[k][i].cost){
            ans=0;
        }
        if(!vis[es[k][i].to]){
            solve(es[k][i].to);
        }
    }
}
signed main(){
    int n,m;cin>>n>>m;
    rep(i,0,m){
        int a,b,c;cin>>a>>b>>c;
        es[a].push_back(edge{b,c});
        es[b].push_back(edge{a,-c});
    }
    rep(i,1,n+1){
        d[i]=inf;
    }
    rep(i,1,n+1){
        if(vis[i])continue;
        else if(!ans){
            cout<<"No"<<endl;
            return 0;
        }
        solve(i);
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000009;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;cin>>n;
	if(n==0){
		cout<<1<<endl;
	}else if(n==1){
		cout<<2<<endl;
	}else if(n==2){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
    return 0;
}



Measured memory_bytes: 3092
def main(N,K,h):
    h.sort()
    count = 0
    for i in range(len(h)):
        if h[i] < K:
            count += 1
        else:
            break
    return N - count

N,K = map(int,input().split())
h = list(map(int, input().split()))
print(main(N,K,h))

Measured memory_bytes: 11908
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

template<typename T>
constexpr std::pair<T, T> eea(T a, T b) noexcept {
	T x = 1, y = 0, p = 0, q = 1;
	while (b != 0) {
		T s = a;
		a = b;
		T t = s / b;
		b = s % b;

		T i = x, j = y;
		x = p;
		y = q;
		p = i - t * p;
		q = j - t * q;
	}

	return pair<T, T>(x, y);
}

template<typename T>
constexpr T inv(T a, T mod) noexcept {
	T invA = eea(a, mod).first;
	if (invA < 0) invA += mod;

	return invA;
}

template<typename T>
constexpr T c(T n, T r, T mod) noexcept {
	T nCr = 1;
	for (T i = 0; i < r; ++i) {
		nCr *= n - i;
		nCr %= mod;
		nCr *= inv(1 + i, mod);
		nCr %= mod;
	}

	return nCr;
}

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

	ll x, y;
	cin >> x >> y;
	ll z = x + y;
	
	if (z % 3 != 0 || min(x, y) < (z / 3)) {
		cout << 0 << "\n";
	}
	else {
		ll a, b;
		a = z / 3;
		b = 2 * (z / 3) - x;

		cout << c(a, b, _MOD) << "\n";
	}

	return 0; 
}


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

int main()
{
    long long int n,i,mat[100005][3],dp[100005][3];
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>mat[i][1]>>mat[i][2]>>mat[i][3];
    }
    dp[1][1] = mat[1][1];
    dp[1][2] = mat[1][2];
    dp[1][3] = mat[1][3];
    for(i=2;i<=n;i++)
    {
        dp[i][1] = mat[i][1] + max(dp[i-1][2],dp[i-1][3]);
        dp[i][2] = mat[i][2] + max(dp[i-1][1],dp[i-1][3]);
        dp[i][3] = mat[i][3] + max(dp[i-1][2],dp[i-1][1]);
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional>
using namespace std;
#define rep(i, a, b) for (int(i) = a; (i) < (int)(b); (i)++)

int main()
{
    float A,B;
    cin >> A >> B;
    float tmp1 = floor(A/0.08);
    float tmp2 = floor(B/0.1);
    int start = int(min(tmp1,tmp2)-1);
    int end = int(max(tmp1,tmp2))+1;
    bool finFlag = false;
        
    for(int i=start;i<=end;i++){
        float i_t = float(i);
        if (floor(i_t*0.08)==A && floor(i_t*0.1) == B){
            cout << i << endl;
            finFlag = true;
            break;
            }
    }
    if(finFlag == false) cout << "-1"<<endl;
}

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

using ll=long long; 

int digit(int n){
	int sum=0;
	while(n>0){
		sum+=n%10;
		n/=10;
	}
	return sum;
}

bool hantei(int n, int a, int b){
	return digit(n)>=a&&digit(n)<=b;
}

void solve(){
	int n,a,b;
	cin>>n>>a>>b;
	int cnt=0;
	for(int i=1; i<=n; i++){
		if(hantei(i,a,b)){
			cnt+=i;
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> tree[100001];
ll dp[100001][2];
ll solve(ll u,bool constraint,ll parent)
{
	if(dp[u][constraint]!=-1)
		return dp[u][constraint];
	ll ans=0;
	ll ways_with_constraint=1; 
	for(ll child:tree[u])
	{
		if(child!=parent)
		{
			ways_with_constraint=(ways_with_constraint*solve(child,0,u))%1000000007;
		}
	}
	ans+=ways_with_constraint;
	if(!constraint)
	{
		ll ways_without_constraint=1;
		for(ll child:tree[u])
		{
			if(child!=parent)
			{
				ways_without_constraint=(ways_without_constraint*solve(child,1,u))%1000000007;
				//Children cannot be painted Black.
			}
		}
		ans=(ans+ways_without_constraint)%1000000007;
	}
	return dp[u][constraint]=ans;
}
int main()
{
	ll n;
	cin>>n;
	ll edges=n-1;
	memset(dp,-1,sizeof(dp));
	while(edges--)
	{
		ll x,y;
		cin>>x>>y;
		tree[x].push_back(y);
		tree[y].push_back(x);
	}
	cout<<solve(1,0,-1);//Parent of Node u is -1.
}

Measured memory_bytes: 17328
/**********************************************
 *Author*        :coderdz
 *Created Time*  : 2018/5/5 14:23:12

*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,n) for(int i=1;i<=n;i++)
#define m(a,b) memset(a,b,sizeof(a))
#define c(a) cout<<a<<endl;
typedef pair<int, int> PII;
typedef long long ll;
const int MAXN=1e5+10;

inline void OPEN(string s){
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int main(){
    IO;
    int a,b,ans;
    cin>>a>>b;
    ans=a;
    if (b<a)
    	ans-=1;
    c(ans)
    return 0;
}

Measured memory_bytes: 256
""" A
    https://atcoder.jp/contests/aising2020/tasks/aising2020_a
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(L, R, d):
    count = 0
    for i in range(L, R+1):
        if i % d == 0:
            count += 1
    return count

if __name__ == "__main__":
    _L, _R, _d = readIntegerSet(3)

    print(main(_L, _R, _d))

Measured memory_bytes: 9572
import sys
sys.setrecursionlimit(10**7)
n,m,p = map(int,input().split())
E1 = [[] for i in range(n)]
E2 = [[] for i in range(n)]
edge = []
for i in range(m):
    a,b,c = map(int,input().split())
    c = p-c
    a -= 1
    b -= 1
    E1[a].append(b)
    E2[b].append(a)
    edge.append((a,b,c))

dis1 = [False]*n
def dfs1(x):
    if dis1[x] == False:
        dis1[x] = True
        for nex in E1[x]:
            dfs1(nex)

dis2 = [False]*n
def dfs2(x):
    if dis2[x] == False:
        dis2[x] = True
        for nex in E2[x]:
            dfs2(nex)

dfs1(0)
dfs2(n-1)

ok = []
for i in  range(n):
    if dis1[i] and dis2[i]:
        ok.append(True)
    else:
        ok.append(False)
nedge = []
for a,b,c in edge:
    if ok[a] and ok[b]:
        nedge.append((a,b,c))

def belw():
    dis = [float("INF")]*n
    dis[0] = 0
    count = 0
    check = True

    while check:
        check = False
        for a,b,c in nedge:
            
            if dis[a] != float("INF") and dis[b] > dis[a]+c:
                check = True
                dis[b] = dis[a]+c
        count += 1

        if count > n+1 and check:
            return float("INF")
    
    return -dis[-1]

ans = belw()
if ans == float("INF"):
    print(-1)
else:
    print(max(ans,0))











Measured memory_bytes: 65368
def main(n,a):
  b=[-x for x in a]
  b.sort()
  from heapq import heappop,heappush,heapify
  heapify(b)
  ans=-1
  for i in range(n+2):
    v=heappop(b)
    if -v<=n-1:
      ans=i
      break
    b=[x-1 for x in b]
    v+=n
    heappush(b,v)
  if ans>=0:return ans
  suma=sum(a)
  # mod (n+1)で考える
  am=[x%(n+1) for x in a]
  sumam=0
  for i in range(n+1):
    am=[(x+1)%(n+1) for x in am]
    if max(am)<=n-1:
      sumam=max(sum(am),sumam)
  ans=suma-sumam
  return ans


n=int(input())
a=list(map(int,input().split()))
print(main(n,a))


Measured memory_bytes: 65808
#include<iostream>
#include<algorithm>
#include <stdio.h>
#include <time.h>
#include <queue>
using namespace std;
int a[200005]={0};
int b[200005]={0};
int main(){
    int n,m;
    cin>>n>>m;
    int x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        if(x==1) a[y]=1;
        if(y==n) b[x]=1;
    }
    for(int i=0;i<n;i++){
        if(b[i]==1&&a[i]==1){
        cout<<"POSSIBLE";
        return 0;
        }
    }
    cout<<"IMPOSSIBLE";
    return 0;
}



Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

 //最大公約数求める関数
auto my_gcd(auto n , auto m){
  if(n < m){
    auto tmp = n;
    n = m;
    m = tmp;
  }
  auto l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
int H,W;cin >> H >> W;
vector<string> S(H);
rep(i,H) cin >> S[i];

vector<int> dx = {0,0,-1,1};
vector<int> dy = {1,-1,0,0};
int cnt = 0;
bool flag = true;
rep(i,H){
	rep(j,W){
		if(S[i][j] == '#'){
			rep(k,4){
				if(i+dy[k] < H && 0 <= i+dy[k] && j+dx[k] < W && 0 <= j + dx[k] ){
				if(S[i+dy[k]][j+dx[k]] == '#'){
					cnt++;
				}
				
			}

			}
			if(cnt == 0){
				flag = false;
			}
			cnt = 0;
		}
	}
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
ans = 0
if h == 1 or w == 1:
    ans = 1
else:
    if h % 2 == 0:
        ans = (h // 2) * w
    else:
        if w % 2 == 0:
            ans = (h // 2 + 1) * (w // 2) + (h // 2) * (w // 2)
        else:
            ans = (h // 2 + 1) * (w // 2 + 1) + (h // 2) * (w // 2)
print(ans)

Measured memory_bytes: 3060
import numpy as np
n,m=map(int,input().split())
ks=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))

s=np.array([[0]*n for i in range(m)])
for i in range(m):
  for j in range(n):
    if j+1 in ks[i][1:]:
      s[i,j] = 1

cnt=0
for i in range(2**n):
  on_off=np.array(list(map(int,list(bin(i)[2:].zfill(n)))))
  flg=0
  for i in range(m):
    if sum(on_off*s[i])%2!=p[i]:
      flg=1
      break
  if flg==0:
    cnt+=1
print(cnt)

Measured memory_bytes: 12444
#include <iostream>
#include <cstdlib>


using namespace std;


struct node {
    long v;
    node *l, *r, *p;
};
node nodes[500000];


node *r, *z;
long c= 0;
node *get_node()
{
    nodes[c].l = z;
    nodes[c].r = z;
    nodes[c].p = z;
    return &nodes[c++];
}



void init()
{
    z = get_node();
    z->l = z;
    z->r = z;
    z->p = z;

    r = z;
    r->p = z;
}


void insert(long v)
{
    node *n = get_node();
    n->v = v;

    node *t, *p;
    t = r;
    p = z;
    while (t != z) {
        p = t;
        t = (t->v >= v) ? t->l : t->r;
    }

    n->p = p;
    if (p == z) { // root only
        r = n;
    } else if (p->v >= v) {
        p->l = n;
    } else {
        p->r = n;
    }
}


node *find(long v)
{
    node *t = r;
    while (t != z && t->v != v)
        t = (t->v >= v) ? t->l : t->r;
    return t;
}


node *get_next(node *n)
{
    node *t = n->r;
    while (t->l != z)
        t = t->l;
    return t;
}


void del(long v)
{
    node *t = find(v);
    if (t->l == z && t->r == z) {
        if (t->p->v >= v)
            t->p->l = z;
        else
            t->p->r = z;
    } else if (t->l != z && t->r != z) {
        node *next_node = get_next(t);
        del(next_node->v);
        t->v = next_node->v;
    } else {
        if (t->p->v >= v) {
            if (t->l != z) {
                t->l->p = t->p;
                t->p->l = t->l;
            } else {
                t->r->p = t->p;
                t->p->l = t->r;
            }
        } else {
            if (t->l != z) {
                t->l->p = t->p;
                t->p->r = t->l;
            } else {
                t->r->p = t->p;
                t->p->r = t->r;
            }
        }
    }
}


void inorder(node *x)
{
    if (x->l != z)
        inorder(x->l);
    cout << " " << x->v;
    if (x->r != z)
        inorder(x->r);
}


void preorder(node *x)
{
    cout << " " << x->v;
    if (x->l != z)
        preorder(x->l);
    if (x->r != z)
        preorder(x->r);
}


void prlong()
{
    inorder(r);
    cout << endl;
    preorder(r);
    cout << endl;
}


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


    for (long i = 0; i < n; i++) {
        string cmd;
        cin >> cmd;
        if (cmd[0] == 'i') {
            long k;
            cin >> k;
            insert(k);
        } else if (cmd[0] == 'p') {
            prlong();
        } else if (cmd[0] == 'f') {
            long k;
            cin >> k;
            if (find(k) == z)
                cout << "no" << endl;
            else
                cout << "yes" << endl;
        } else if (cmd[0] == 'd') {
            long k;
            cin >> k;
            del(k);
        }
    }
}



Measured memory_bytes: 15540
#include<bits/stdc++.h>
using namespace std;
long long a[200001]={0};
long long mina=1000000000000000;
int n,x;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		a[i]=a[i-1]+x;
	}
	for(int i=1;i<n;i++){
		mina=min(abs(a[n]-2*a[i]),mina);
	}
	cout<<mina<<endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
	int N, T; cin >> N >> T;
	int ans = T, tmp = 0;
	for (int i = 0; i < N; ++i) {
		int t; cin >> t;
		if (t - tmp > T) ans += T;
		else ans += t - tmp;
		tmp = t;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256