akhauriyash/Code-Regression huggingface dataset:
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
void sol() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);

    int k, n;
    cin >> k >> n;
    
    vi a(n);
    int mx(-1);
    cin >> a[0];

    int fir = a[0];
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        a[i - 1] = a[i] - a[i - 1];
        if (mx < a[i - 1])
            mx = a[i - 1];
    }

    a[n - 1] = k - a[n - 1] + fir;
    if (mx < a[n - 1])
        mx = a[n - 1];

    cout << (k - mx) << '\n';

    return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector < int >P(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}

	vector < int >Q(N);
	for (int i = 0; i < N; i++) {
		cin >> Q[i];
	}

	vector < int >nums(N);
	for (int i = 0; i < N; i++) {
		nums[i] = i + 1;
	}

	int pnum = -1;
	int qnum = -1;
	int index = 1;

	do {
		if (P == nums) {
			pnum = index;
		}
		if (Q == nums) {
			qnum = index;
		}
		index++;
	} while (next_permutation(nums.begin(), nums.end()));

	cout << abs(qnum - pnum) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    int m, d;
    cin >> m >> d;
    int cnt = 0;
    for (int mi = 1; mi <= m; mi++) {
        for (int di = 1; di <= d; di++) {
            int d1 = di % 10, d10 = di / 10;
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == mi) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    a, b = input().split()
    b = b.replace('.', '')
    # print(b)

    ans = int(a) * int(b)
    print(ans // 100)




if __name__ == '__main__':
    solve()


Measured memory_bytes: 9124
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const ll P=100000007,Q=1000000007;

int dec(char c){
	if('A'<=c && c<='Z') return c-'A';
	if('a'<=c && c<='z') return c-'a'+26;
	if('0'<=c && c<='9') return c-'0'+52;
	if(c=='+') return 62;
	return 63;
}

void parse(int h,int w,int B[1000][1000]){
	rep(i,h){
		char s[200]; scanf("%s",s);
		int x=0;
		for(int j=0;s[j];j++){
			int a=dec(s[j]);
			for(int k=5;k>=0;k--){
				if(x==w) break;
				B[i][x++]=a>>k&1;
			}
		}
	}
}

void rot(int n,int B[1000][1000]){ // 90 度回転
	static int tmp[1000][1000];
	rep(i,n) rep(j,n) tmp[j][n-i-1]=B[i][j];
	rep(i,n) rep(j,n) B[i][j]=tmp[i][j];
}

void mirror(int n,int B[1000][1000]){ // 鏡像反転
	rep(i,n) rep(j,n/2) swap(B[i][j],B[i][n-j-1]);
}

int main(){
	ll PP[200],QQ[200]; // PP[i] := P^i, QQ[i] := Q^i
	PP[0]=QQ[0]=1;
	rep(i,199) PP[i+1]=PP[i]*P, QQ[i+1]=QQ[i]*Q;

	for(int w,h,n;scanf("%d%d%d",&w,&h,&n),w;){
		static int A[1000][1000],B[1000][1000]; // image, pattern
		parse(h,w,A);
		parse(n,n,B);

		static ll AP[1001][1000]; // AP[i+1][j] := Σ_{k=0..i} A[k][j]*P^(i-k)
		rep(j,w){
			AP[0][j]=0;
			rep(i,h) AP[i+1][j]=AP[i][j]*P+A[i][j];
		}
		static ll AQ[1000][1001]; // AQ[i][j+1] := Σ_{k=0..j} A[i][k]*Q^(j-k)
		rep(i,h){
			AQ[i][0]=0;
			rep(j,w) AQ[i][j+1]=AQ[i][j]*Q+A[i][j];
		}

		bool checked[1000][1000]; // checked[i][j] := ( A[i][j] を左上とする位置にパターンがあるかどうか )
		rep(i,h) rep(j,w) checked[i][j]=false;

		rep(s,2) rep(t,4) {
			ll tar=0; // pattern の hash 値
			rep(i,n) rep(j,n) tar+=B[i][j]*PP[n-i-1]*QQ[n-j-1];

			ll H0=0; // A[i][0] を左上とする n*n マスの hash 値
			rep(i,n) rep(j,n) H0+=A[i][j]*PP[n-i-1]*QQ[n-j-1];
			rep(y,h-n+1){
				ll H=H0;
				rep(x,w-n+1){
					if(H==tar) checked[y][x]=true;
					if(x<w-n){
						// H を 1 列右にずらす
						H-=QQ[n-1]*(AP[y+n][x]-AP[y][x]*PP[n]);
						H*=Q;
						H+=AP[y+n][x+n]-AP[y][x+n]*PP[n];
					}
				}

				if(y<h-n){
					// H0 を 1 行下にずらす
					H0-=PP[n-1]*(AQ[y][n]-AQ[y][0]*QQ[n]);
					H0*=P;
					H0+=AQ[y+n][n]-AQ[y+n][0]*QQ[n];
				}
			}

			rot(n,B);
			if(t==3) mirror(n,B);
		}

		int ans=0;
		rep(i,h) rep(j,w) if(checked[i][j]) ans++;
		printf("%d\n",ans);
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n,k;

int main(){
    cin >> n >> k;
    double ans = 0;
    double p = 1.0 / (double)n;
    double g = 1.0;
    double f = 1.0;
    for(ll i = n;i >= 1;i--){
        while(i*g < k){
            g *= 2.0;
            f = f / 2.0;
        }
        ans += p*f;
    }
    printf("%.10lf\n",ans);
}

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

int main() {
    
    vector<string> ans;
    while(1){
        string s;
        int m;
        cin >> s >> m;

        if(s == "-"){
            break;
        }

        for(int i = 0; i < m; i++){
            int h;
            cin >> h;
            string ptmp, tmp;
            ptmp = s.substr(0, h);
            tmp = s.substr(h, s.size()-h);
            s = (tmp + ptmp);
        }
        cout << s << endl;

    }

}


Measured memory_bytes: 3184
n,x = map(int,input().split())

a,p = [1],[1]

#バーガーの厚みとパティの総数を求める

for i in range(n):
    a.append(2 * a[i] + 3)
    p.append(2 * p[i] + 1)

def f(N,X):
    if N == 0:
        if X <= 0:
            return 0

        else:
            return 1

    elif X <= 1 + a[N-1]:
        return f(N -1,X-1)

    else:#if X <= 2 + 2 * a[N-1]:
        return p[N-1] + 1 + f(N -1, X-2-a[N-1])

print(f(n,x))


Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main(void) {
	long long n,m;
	cin >> n >> m;
	if(n==2 || m==2)cout << 0 << endl;
	else cout << max(n-2,(long long)1)*max(m-2,(long long)1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef unsigned long long ll;

int main(){
    ll n;
    cin >> n;
    if(n%2 == 1){
        cout << 0 << endl;
        return 0;
    }
    ll five = 0;
    for(ll i = 10; i <= n; i *= 5){
        five += n/i;
    }
    cout << five << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(int argc, const char * argv[]) {
    // insert code here...
    int i, count[30]={0};
    char x[1201];
    while (scanf("%[^\n]\n", x)!=EOF) {

        for (i=0; x[i]!='\0'; i++) {
            //if (isalpha(x[i])) {
                count[tolower(x[i])-'a']++;
           // }
        }
    }
    for (char c='a'; c<='z'; c++) {
        printf("%c : %d\n", c, count[c-'a']);
    }
    return 0;
}



Measured memory_bytes: 2140
#include<stdio.h>
long long a[10005],b[10005];
long long num(long long m)
{
    long long cnt = 0;
    while(m%2==0)
    {
        cnt++;
        m /= 2;
    }
    return cnt;
}

int main()
{
    long long n;
    scanf("%lld",&n);
    long long cnt = 0;
    for(long long i = 0; i < n; i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]%2 == 0)
            b[cnt++] = a[i];
    }
    if(cnt == 0)
        printf("0\n");
    else
    {
        long long ans = 0;
        for(long long i = 0; i < cnt; i++)
            ans += num(b[i]);
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
n, c = map(int, input().split())
# input時に前処理として以下のことをしておく
#   * 開始時間を-1(-0.5の制約だが、-1しても変わらないので-1する)しておく

# テレビ局の番組をチャンネルごとに登録
r = [[0 for i in range(c)] for j in range(100000)]
for _ in range(n):
    s,t,c = map(int, input().split())
    for j in range(s-1, t):
        r[j][c - 1] = 1
# print(*r,sep='\n')

ans = 0
for i in range(len(r)):
    ans = max(ans, sum(r[i]))
print(ans)


# 補足
# チャンネル数4の場合以下のような配列ができる
# 1行でとある時間のチャンネル状態(1: 録画する, 0: 録画しない)がつく
#[0, 0, 0, 0]
#[0, 0, 1, 0]
#[1, 1, 1, 0]  <- この時間で3チャンネル録画が必要
#[1, 1, 0, 0]  <- この時間で2チャンネル録画が必要
#[1, 1, 0, 0]
#[1, 0, 0, 0]

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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    REP(i,4){
        ans += (S[i]=='+'?1:-1);}
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    vector<int> array(3);
    array[0] = A;
    array[1] = B;
    array[2] = C;
    sort(array.begin(), array.end());
    int t = 0;
    t = array[2] * 10 + array[1];
    cout << t + array[0] << endl;
}

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

using namespace std;

int main(void){
    int k;
    char s[110];
    cin>>k;
    cin>>s;
    int len = strlen(s);
    if(len <= k){
        cout<<s<<endl;
    }
    else{
        for(int i = 0; i < k; i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
int mi=0;
long min=1999999999;
long sum=0;
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++){
			a[i]=sc.nextInt();
		if(a[i]<0){
			mi++;
		}
		if(min>Math.abs(a[i])){
			min=Math.abs(a[i]);
		}
		sum=sum+Math.abs(a[i]);
		}


if(mi%2==0){
System.out.println(sum);
}else{
	System.out.println((sum-min-min));
}

	}
}

Measured memory_bytes: 51472
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;


int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    a[0]=0;
    multiset<ll> ms;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]+=a[i-1];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<i;j++){
            ms.insert(a[i]-a[j]);
        }
    }
    multiset<ll> ::iterator itr,i1,i2;
    ll now;
    itr=ms.end();
    itr--;
    for(ll i=0LL;;i++){
        if((1LL<<i)<=*itr)now=(1LL<<i);
        else break;
    }
    multiset<ll> tmp;
    ll maki=now;
    while(maki){
        i1=ms.lower_bound(now);
        i2=ms.lower_bound(now+maki);
        if(distance(i1,i2)>=k){
            maki>>=1;
            now+=maki; 
        }
        else{
            tmp.clear();
            for(itr=i1;itr!=i2;itr++){
                tmp.insert(*itr);
            }
            for(itr=tmp.begin();itr!=tmp.end();itr++){
                ms.erase(*itr);
                ms.insert(*itr-maki);
            }
            maki>>=1;
            now-=maki;
            if(!maki)now--;
        }
    }
    cout <<now<<endl;
    return 0;
}


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

struct RBQ{
  int n=(1<<18),data[(1<<19)];
  RBQ(){
    memset(data,0,sizeof(data));
  }
  void update(int k,int x){
    k+=n-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=max(data[k*2+1],data[k*2+2]);
    }
  }
  int find(int a,int b,int k=0,int l=0,int r=(1<<18)){
    if(r<=a || b<=l)return 0;
    if(a<=l && r<=b)return data[k];
    int v1=find(a,b,k*2+1,l,(l+r)/2);
    int v2=find(a,b,k*2+2,(l+r)/2,r);
    return max(v1,v2);
  }
};

main(){
  RBQ A;
  int n,ans=0;
  cin>>n;
  int h[n],a[n],dp[n];
  r(i,n)cin>>h[i];
  r(i,n)cin>>a[i];
  r(i,n){
    dp[i]=A.find(0,h[i])+a[i];
    ans=max(ans,dp[i]);
    A.update(h[i],dp[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll H, W; cin >> H >> W;
	vector<vector<ll>> c(10, vector<ll>(10));
	for (int i = 0; i < 10;i++) {
		for (int j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 0; i < 10;i++) {
		for (int j = 0; j < 10;j++) {
			for (int k = 0; k < 10;k++) {
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}
	}
	ll res = 0;
	for (int i = 0; i < H;i++) {
		for (int j = 0; j < W;j++) {
			ll A; cin >> A;
			if (A == -1) continue;
			res += c[A][1];
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,x,t,sum;
  scanf("%d %d %d", &n, &x, &t);
  if(n%x==0){
    sum = t*n/x;
    printf("%d", sum);
  }else{
    sum = t*(n/x+1);
    printf("%d", sum);
  }
  
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
   public:
    int n, m;
    string s[33];
    void solve() {
        cin >> n >> m;
        for (int i = 0; i < n; ++i) cin >> s[i];
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (s[i][j] == '.')
                    ans = max(bfs(i, j), ans);
            }
        }
        cout << ans << "\n";
    }
    int dis[33][33];
    int bfs(int x, int y) {
        memset(dis, -1, sizeof dis);
        vector<pi> que;
        que.emplace_back(x, y);
        dis[x][y] = 0;
        int res = 0;
        for (int i = 0; i < que.size(); ++i) {
            for (int j = 0; j < 4; ++j) {
                if (que[i].first + dx[j] >= n || que[i].second + dy[j] >= m || que[i].first + dx[j] < 0 || que[i].second + dy[j] < 0)
                    continue;
                if (s[que[i].first + dx[j]][que[i].second + dy[j]] == '#')
                    continue;
                if (dis[que[i].first + dx[j]][que[i].second + dy[j]] == -1) {
                    dis[que[i].first + dx[j]][que[i].second + dy[j]] = dis[que[i].first][que[i].second] + 1;
                    res = max(res, dis[que[i].first + dx[j]][que[i].second + dy[j]]);
                    que.emplace_back(que[i].first + dx[j], que[i].second + dy[j]);
                }
            }
        }
        return res;
    }
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int H ,W;
    int i, j;
    
    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 + j) % 2 == 0){
                    printf("#"); 
                }
                
                else 
                    printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    
   
    
    return 0;
}




Measured memory_bytes: 2140
<?php
	fscanf(STDIN,'%d%d',$n,$m);
	for($i=0;$i<$n;$i++)
	{
		fscanf(STDIN,'%d%d',$x,$y);
		$a[]=$x;
		$b[]=$y;
	}
	for($i=0;$i<$m;$i++)
	{
		fscanf(STDIN,'%d%d',$x,$y);
		$c[]=$x;
		$d[]=$y;
	}
	for($i=0;$i<$n;$i++)
	{
		$s=1000000000;
		for($j=0;$j<$m;$j++)
		{
			$t=abs($a[$i]-$c[$j])+abs($b[$i]-$d[$j]);
			if($t<$s)
			{
				$s=$t;
				$k=$j+1;
			}
		}
		echo $k,"\n";
	}


Measured memory_bytes: 3828
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    bool flag=0;
    rep(i,1,10){
        if(n/i>=1 && 9>=n/i && n%i==0) flag=1;
    }
    if(flag) cout << "Yes" ENDL;
    else cout << "No" ENDL;
    return 0;
}

Measured memory_bytes: 3652
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    unsigned int w,a,b;
    cin>>w>>a>>b;
    unsigned int ans = 0;
    if(b > a+w) ans = b - a - w;
    if(a > b + w) ans = a - b - w;
    cout << ans <<endl;
}


Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int maxn = 1e4 + 10 , maxk = 10 ;

bool mark [ maxk ] ;

int n , k ;

bool bad ( int p ) {
	while ( p ) {
		if ( mark [ p % 10 ] )
			return 1 ;
		p /= 10 ; 
	}
	return 0 ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k ;
	for ( int i = 0 ; i < k ; i ++ ) {
		int x ;
		cin >> x ;
		mark [ x ] = 1 ;
	}
	while ( bad ( n++ ) ) ;
	cout << --n << '\n' ; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = (int)1e4 + 4;
P DP[MAX_N];
int main()
{
	ios_base::sync_with_stdio(0);
	int N, M;
	while (cin >> N >> M, N ){
		rep (i, N ){
			int d, p; cin >> d >> p;
			DP[i].first = -p, DP[i].second = d;
		} // end rep
		sort (DP, DP+N );

		int res = 0;
		int j = -1;
		for (int i = 0; i < N; i++ ){
			if (M - DP[i].second < 0 ){
				j = i;	
				break;
			} // end if
			M -= DP[i].second;
		} // end for
				 
		if (j != -1 ){
			res -= DP[j].first*(DP[j].second - M);
			j++;
			for (; j<N; j++ ){
				res -= DP[j].first*DP[j].second;
			} // end for
		} // end if
		cout << res << endl;
	} // end while

	return 0;
}

Measured memory_bytes: 1276
K = int(input())
ans = [49+K//50] * 50

amari = K%50
if amari != 50:
  for i in range(amari):
    ans[i] = ans[i] + 50 - (amari-1)
  for i in range(amari, 50):
    ans[i] = ans[i] - amari
  
print(50)
ansstr = [str(i) for i in ans]
print(' '.join(ansstr))

Measured memory_bytes: 3064
program aaa
implicit none

character(1),dimension(4) :: g=['A','C','G','T']
character(1) :: s

read*, s

if(s==g(1)) write(*,'(a1)') g(4)
if(s==g(2)) write(*,'(a1)') g(3)
if(s==g(3)) write(*,'(a1)') g(2)
if(s==g(4)) write(*,'(a1)') g(1)

end program

Measured memory_bytes: 256
package main

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

func solve() {
	s := getRunes()

	ans := 0
	for i := 1; i < len(s); i++ {
		if s[i-1] == s[i] {
			continue
		}

		ans++
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	buf := 200001
	sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 1280
#https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod
N=int(input())
S=input()
R1=RollingHash(S,37,10**9+7)
R2=RollingHash(S,29,10**9+9)
ans=0
for ln in range(1,N//2+1):
    D=dict()
    for l in range(N-ln+1):
        tmp=(R1.get(l,l+ln),R2.get(l,l+ln))
        if tmp in D:
            if D[tmp]+ln<=l:
                ans=max(ln,ans)
        else:
            D[tmp]=l
print(ans)


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    rep(i, n) cin >> m[i];
    int a = accumulate(all(m), 0);
    int mn = MN(m);
    cout << n + (x - a) / mn << endl;
}
int main(void)
{
    solve();
}

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

typedef struct{
  int dt;
  int idx;
}date;

int cmp( const void *p, const void *q ) {
    return  ((date*)p)->dt - ((date*)q)->dt ;
}

int main() {
  int n;
  cin >> n;
  date p[n];
  for(int i = 0;i < n;i++){
    cin >> p[i].dt;
    p[i].idx = i;
  }

  int nn = sizeof p / sizeof(date);
  qsort(p,nn,sizeof(date),cmp);

  int ans = 0;
  int tmp = 0;
  int x = 0;
//  for(int i = 0;i < n;i++){
//    cout << p[i].dt << " " << p[i].idx << endl;
//  }
  for(int i = 0;i < n;i++){
    if(p[x].idx >= p[i].idx){
      ans++;
      x = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define ll long long
#define li long int
#define ld long double
#define pl pair<long long, long long>
#define pi pair<int, int>
#define ppl pair<pl, ll>
#define ppi pair<int, pi>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LLFOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define MOD 1000000007
#define M2 998244353
//std::cout <<setprecision(30) << av << endl;
using namespace std;
ll h[200000];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--){
       int n, k;
       cin >> n >> k;
       vector<set<int> > edges(n);
        FOR(i, 0, n){
            cin >> h[i];
        }
        int f, s;
        FOR(i, 0, k){
            cin >> f >> s;
            f--; s--;
            edges[f].insert(s);
            edges[s].insert(f);
        }
        int ans=0;
        FOR(i, 0, n){
            f=1;
            for(auto it : edges[i]){
                if(h[i]<=h[it]){
                    f=0;
                    break;
                }
            }
            if(f==1){
                ans++;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 17980
li = input()
count = 0
row = 0
if li[0] == "R":
  count += 1
  row = 1
if li[1] == "R":
  if row == 1:
    count += 1
  else:
    row = 1
    count = 1
else:
  row = 0

if li[2] == "R":
  if row == 1:
    count += 1
  else:
    row = 1
    count = 1
else:
  row = 0
print(count)
  

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var kami = int.Parse(S.Substring(0, 2));
            var simo = int.Parse(S.Substring(2, 2));
            var ans = "";
            if (kami >= 1 && kami <= 12 && simo >= 1 && simo <= 12)
            {
                ans = "AMBIGUOUS";
            }
            else if ((kami >= 13 || kami == 0) && simo >= 1 && simo <= 12)
            {
                ans = "YYMM";
            }
            else if (kami >= 1 && kami <= 12 && (simo == 0 || simo >= 13))
            {
                ans = "MMYY";
            }
            else
            {
                ans = "NA";
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
struct Edge{
	int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void dfs(int v, int c = -1, int p = -1) {
	int k = 1;
	rep (i, g[v].size()) {
		int u = g[v][i].to; int ei = g[v][i].id;
		if (u == p) continue;
		if (k == c) k++;
		ans[ei] = k; k++;	
		dfs(u, ans[ei], v);		
	}
}

void solve() {
		int n; cin >> n;
		g.resize(n);
		ans = vector<int>(n - 1);
		rep (i, n - 1) {
			int a, b; cin >> a >> b;
			a--; b--;
			g[a].push_back({ b, i });
			g[b].push_back({ a, i });
		}
		dfs(0);
		int mx = 0;
		rep (i, n) {
			mx = max(mx, int(g[i].size()));
		}
		cout << mx << endl;
		rep (i, n - 1) {
			cout << ans[i] << endl;
		}
    return;
}

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



Measured memory_bytes: 8320
fun main(args: Array<String>) {
    val (n, m) = readLine()?.split(" ")?.map { it.toLong() } ?: return

    // 全検索では間に合わない
    // あるマスが裏返られるパターンは1,2,4,6,9回ある
    // このうち裏返される回数が奇数のパターンに該当するマスが何個あるかを計算する

    // n, mの片方または両方が2以下の場合は特殊なので、
    // まずこれを計算する
    val max = Math.max(n, m)
    val min = Math.min(n, m)
    if (max == 1L && min == 1L) {
        println(1)
        return
    } else if (min == 1L) {
        // 両端以外が奇数回
        println(max - 2)
        return
    } else if (min == 2L) {
        // すべて偶数回
        println(0)
        return
    }

    // これより下は min >= 3 の場合
    // この場合、奇数回になるのは一番外側にくるマス以外全部
    println((n - 2) * (m - 2))
}

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

int main() {
    int a,b,c; scanf("%d %d %d", &a, &b, &c);

    int res = a + b + c;
    res = min(res, a + b);
    res = min(res, a + c);
    res = min(res, b + c);

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin() , (x).begin()
#define ll long long 
#define pb push_back
#define mp make_pair

using namespace std;

bool ok(pair<int , int > a , pair<int,int> b){
  return a.second < b.second;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int>v(5);
    for(int& i : v)cin>>i;
    int T = 0;
    vector<pair<int,int> > vp;
    for(int i = 0 ; i < 5; ++i){
      int c = 0;
      int x = v[i];
      while(x%10 != 0){c++;x++;};
      vp.pb({v[i] , c});
    }
    sort(vp.begin() , vp.end() , ok);
    for(auto i : vp)T += i.first+i.second;
    cout<<T - vp[4].second;

}


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

using namespace std;


int main()
{
	int k, t;
	cin >> k >> t;
	priority_queue<int> buffer;
	while(t--){
		int tmp;
		cin >> tmp;
		buffer.push(tmp);
	}

	while(buffer.size() > 1){
		int tmp_1 = buffer.top();
		buffer.pop();
		int tmp_2 = buffer.top();
		buffer.pop();
		if(tmp_1 == tmp_2) continue;

		buffer.push(tmp_1-tmp_2);
	}

	cout <<( buffer.empty()?0:buffer.top()-1 )<< endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int D; cin >> D;
    vl c(26);
    rep(i,26) cin >> c[i];
    vvl s(D, vl(26));
    rep(i,D) {
        int d = 0, mx = -1;
        rep(j,26) {
            cin >> s[i][j];
            if (s[i][j] > mx) {
                d = j;
                mx = s[i][j];
            }
        }
        cout << d+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
long long N,ans;
inline long long read(){
	long long x=0,f=1;
	char c;
	do{c=getchar();if(c=='-'){f*=-1;}}while(!isdigit(c));
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
int main(){
	N=read();ans=1e16;
	long long x=sqrt(N);
	for(int i=1;i<=x;i++){
		if(N%i==0){
			ans=min(ans,1ll*i+N/i-2);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

typedef struct
{
	int top;
	int east;
	int west;
	int south;
	int north;
	int buttom;
}DICE;

DICE getDice(void)
{
	DICE dice;
	dice.top = 1;
	dice.east = 3;
	dice.west = 4;
	dice.south = 2;
	dice.north = 5;
	dice.buttom = 6;
	
	return dice;
}

void North(DICE* dice)
{
	int buf;
	buf = dice->top;
	dice->top = dice->south;
	dice->south = dice->buttom;
	dice->buttom = dice->north;
	dice->north = buf;
}

void East(DICE* dice)
{
	int buf;
	buf = dice->top;
	dice->top = dice->west;
	dice->west = dice->buttom;
	dice->buttom = dice->east;
	dice->east = buf;
}

void West(DICE* dice)
{
	int buf;
	buf = dice->top;
	dice->top = dice->east;
	dice->east = dice->buttom;
	dice->buttom = dice->west;
	dice->west = buf;
}

void South(DICE* dice)
{
	int buf;
	buf = dice->top;
	dice->top = dice->north;
	dice->north = dice->buttom;
	dice->buttom = dice->south;
	dice->south = buf;
}

void Right(DICE* dice)
{
	int buf;
	buf = dice->south;
	dice->south = dice->east;
	dice->east = dice->north;
	dice->north = dice->west;
	dice->west = buf;
}

void Left(DICE* dice)
{
	int buf;
	buf = dice->south;
	dice->south = dice->west;
	dice->west = dice->north;
	dice->north = dice->east;
	dice->east = buf;
}

int main(void)
{
	int n;
	int i;
	int total;
	char message[16];
	
	while( scanf( "%d", &n ) && n != 0 )
	{
		DICE dice;
		dice = getDice();
		total = 1;
		for( i = 0; i < n; i++ )
		{
			scanf( "%s", message );
			switch( message[0] )
			{
				case 'N':
					North( &dice );
					break;
				case 'E':
					East( &dice );
					break;
				case 'S':
					South( &dice );
					break;
				case 'W':
					West( &dice );
					break;
				case 'R':
					Right( &dice );
					break;
				case 'L':
					Left( &dice );
					break;
			}
			total += dice.top;
		}
		printf( "%d\n", total );
	}
	
	return (0);
}

Measured memory_bytes: 604
a0 = list(map(int,input().split(" ")))
a1 = list(map(int,input().split(" ")))
a2 = list(map(int,input().split(" ")))
n = int(input())
b = []

for i in range(n):
    b.append(int(input()))

for i in range(n):
    for j in range(3):
        if b[i] == a0[j]:
            a0[j] = 0
        if b[i] == a1[j]:
            a1[j] = 0
        if b[i] == a2[j]:
            a2[j] = 0

ans = 0

if a0[0] + a0[1] + a0[2] == 0:
    ans += 1
if a1[0] + a1[1] + a1[2] == 0:
    ans += 1
if a2[0] + a2[1] + a2[2] == 0:
    ans += 1
if a0[0] + a1[0] + a2[0] == 0:
    ans += 1
if a0[1] + a1[1] + a2[1] == 0:
    ans += 1
if a0[2] + a1[2] + a2[2] == 0:
    ans += 1
if a0[0] + a1[1] + a2[2] == 0:
    ans += 1
if a0[2] + a1[1] + a2[0] ==0:
    ans += 1

if ans >= 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct student{
  int math, eng, nat;
  double ave;
};

string solve(student s){
  if(s.math == 100 || s.eng == 100 || s.nat == 100){
    return "A";
  }else if(s.ave >= 80){
    return "A";
  }else if((s.math + s.eng)/2.0 >= 90){
    return "A";
  }else if(s.ave >= 70){
    return "B";
  }else if(s.ave >= 50 && (s.math >= 80 || s.eng >= 80)){
    return "B";
  }
  return "C";
}
  
int main(){
  int n;
  while(std::cin >> n, n){
    for (int i = 0; i < n; i++) {
      student s;
      std::cin >> s.math >> s.eng >> s.nat;
      s.ave = (s.math + s.eng + s.nat)/3.0;
      std::cout << solve(s) << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1188
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

r1 = int(arr_data[0][0])
r2 = int(arr_data[0][1])


print(1/((r2+r1) /(r1*r2)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    ll a, b,n;
    cin>>n>>a>>b;
    cout<<a*((n)/(a+b))+min(a,n%(a+b))<<endl;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  int ans = 1;
  for ( int i = 0; i < N; i++ ) {
    int t;
    cin >> t;
    ans = ans / __gcd(ans, t) * t;    
  }

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


Measured memory_bytes: 256
package main

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

const Mod = 998244353

func main() {
	N, K := ReadInt(), ReadInt()
	L := make([]int, K)
	R := make([]int, K)
	for i := 0; i < K; i++ {
		L[i], R[i] = ReadInt(), ReadInt()
	}
	dp := make([]int, N+1)
	dpSum := make([]int, N+2)
	dp[1] = 1
	dpSum[2] = dpSum[1] + dp[1]
	for i := 2; i <= N; i++ {
		for k := 0; k < K; k++ {
			dp[i] += dpSum[Max(0, i-L[k]+1)] + Mod - dpSum[Max(0, i-R[k])]
			dp[i] %= Mod
		}
		dpSum[i+1] = dpSum[i] + dp[i]
		dpSum[i+1] %= Mod
	}
	fmt.Println(dp[N])
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 5100
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

Weight travel_salesman(const Graph &g) {
    size_t V=g.size();
    vector<vector<Weight>> dp(1<<V, vector<Weight>(V, INF));
    dp[(1<<V)-1][0] = 0;

    for (size_t s=(1<<V)-2; ~s; --s)
        for (size_t v=0; v<V; ++v)
            for (const Edge &e: g[v]) {
                size_t u=e.dst;
                if (!(1<<u & s))
                    dp[s][v] = min(dp[s][v], dp[1<<u|s][u]+e.weight);
            }

    return dp[0][0]<INF? dp[0][0]:-1;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight d;
        scanf("%zu %zu %lld", &s, &t, &d);

        connect(g, s, t, d);
    }

    printf("%lld\n", travel_salesman(g));
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

const ll N_MAX = 201010;
map<ll,ll> zip;
vector<ll> unzip(N_MAX);

template<class V, int ME> class BIT {
public:
    V bit[1<<ME];
    V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
    void add(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;}
};

ll compress(vector<ll> &x) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    for(int i = 0; i < x.size(); i++){
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
    unzip.resize(x.size());
    return x.size();
}

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

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

    ll N;
    cin >> N;
    vector<pll> p(N);
    REP(i, N){
    	cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
	vector<ll> ys(N);
	REP(i, N) ys[i] = p[i].second;
	compress(ys);

	BIT<ll, 18> bit1, bit2;
	const ll haji = (1ll<<18) - 2;
	REP(i, (1<<18)-1) bit1.bit[i] = 0, bit2.bit[i] = 0;
	REP(i, N){
		ll y = p[i].second;
		bit2.add(zip[y], 1);
	}

	ll res = 0;
	REP(i, N){
		ll y = p[i].second;
		ll lu = bit1.total(haji) - bit1.total(zip[y]);
		ll ld = bit1.total(zip[y]-1);
		ll ru = bit2.total(haji) - bit2.total(zip[y]);
		ll rd = bit2.total(zip[y]-1);
		//dump(lu) dump(ld) dump(ru) dump(rd)

		res += powLL(2, N) - 1;

		res -= powLL(2, lu+ld)-1;
		res += mod, res %= mod;
		res -= powLL(2, lu+ru)-1;
		res += mod, res %= mod;
		res -= powLL(2, ld+rd)-1;
		res += mod, res %= mod;
		res -= powLL(2, ru+rd)-1;
		res += mod, res %= mod;

		res += (powLL(2, lu)-1), res %= mod;
		res += (powLL(2, ld)-1), res %= mod;
		res += (powLL(2, ru)-1), res %= mod;
		res += (powLL(2, rd)-1), res %= mod;

		bit1.add(zip[y], 1);
		bit2.add(zip[y], -1);
	}

	cout << res << endl;

    return 0;
}

Measured memory_bytes: 23168
import sys
sys.setrecursionlimit(100000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1]%2
            if sum_d%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)


Measured memory_bytes: 93472
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

string tmp[100],a[100];

bool Ismatch(int i,int j,int n,int m){ 
    rep(k,m){
        rep(l,m){
            if(tmp[i + k][j+l] != a[k][l]) return false;
        }
    }   
    return true;
}

signed main(){
    int n,m;
    cin >> n >> m;
    rep(i,n){
        cin >> tmp[i];
    }   
    rep(i,m){
        cin >> a[i];
    }   
    rep(i,n-m+1){
        rep(j,n-m+1){
            if(Ismatch(i,j,n,m)){
                cout << "Yes\n";
                return 0;
            }
        }
    }   
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
x, y = gets.split().map(&:to_i)

money = [0, 300000, 200000, 100000]

plus = 0

plus = 400000 if x == 1 and y == 1

x = 0 if x > 3
y = 0 if y > 3

puts plus + money[x] + money[y]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF (1e9+7)
#define llINF 1e17
#define EPS 1e-9
#define pi acos(-1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;

const int MAX_n = pow(10,5);
int n,a[MAX_n];

signed main(){

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

    int max_a = *max_element(a,a+n);
    int min_a = *min_element(a,a+n);

    if(max_a - min_a > 1){
        printf("No\n");
        return 0;
    }

    int col = max_a;
    if(min_a == n-1){
        printf("Yes\n");
        return 0;
    }

    int h_num = 0;
    for(int i = 0;i < n;i++){
        if(a[i] == max_a){
            h_num++;
        }
    }

    if(n-col+1 <= h_num && h_num <=n-col+min(col,n-col)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,a[100000],sum;
  long long ans=1e18,cnt=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<2; i++) {
    sum=0;
    cnt=0;
    for(int j=0; j<n; j++) {
      sum+=a[j];
      if(sum>=0&&j%2==i) {
        cnt+=sum+1;
        sum=-1;
      }
      else if(sum<=0&&j%2!=i) {
        cnt+=1-sum;
        sum=1;
      }
    }
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n, x = gets.split.map{|i| i.to_i}
m = Array.new()
mina = 2<<100
n.times do |i|
    a = gets.to_i
    m.push(a)
    x-=a
    mina = [mina, a].min
end
ans = x/mina+n
puts ans

Measured memory_bytes: 1916