akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 100000000000000000
signed main(void){
    int n;cin>>n;
    vector<int>A(n),B(n);
    rep(i,n){
        A[i]=20010*(i+1);
        B[i]=20010*(n-i);
    }
    vector<int>P(n);
    rep(i,n){
        cin>>P[i];P[i]--;
    }
    rep(i,n-1){
        int x=max((int)0,(A[P[i]]+B[P[i]])-(A[P[i+1]]+B[P[i+1]]));
        A[P[i+1]]+=x/2+1;
        B[P[i+1]]+=x-x/2;
    }
    rep(i,n){
        cout<<A[i]<<' ';
    }
    cout<<endl;
    rep(i,n){
        cout<<B[i]<<' ';
    }
    cout<<endl;
}


Measured memory_bytes: 1152
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
inline void read (ll &x) {
	char ch = getchar(); int f = 0; x = 0;
	while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2e5 + 10, mod = 1e9 + 7;
ll n, res = 1, c, cc, a[N], b[N]; 
inline ll gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
#define pr pair<ll, ll>
#define fi first
#define se second
map<pr, int> cnt; vector< pr > v;
inline int Pow (int a, int b) {
	int tmp = 1;
	while (b) {
		if (b & 1) tmp = 1ll * tmp * a % mod;
		a = 1ll * a * a % mod, b >>= 1;
	} return tmp;
}
/*
3
1 0
0 6
-2 0
*/
signed main() {
	read (n);
	for (int i = 1; i <= n; ++i) {
		read (a[i]), read (b[i]); ll _ = gcd (labs (a[i]), labs (b[i]));
		if (a[i] == 0 && b[i] == 0) { ++cc; continue; }
		pr tmp = make_pair (a[i] / _, b[i] / _);
		if (tmp.fi < 0 || (tmp.fi == 0 && tmp.se > 0)) tmp.fi = -tmp.fi, tmp.se = -tmp.se;
	//	printf ("%lld %lld\n", tmp.fi, tmp.se);
		if ((++cnt[tmp]) == 1 && tmp.se >= 0) v.push_back (tmp);
	} for (int i = 0, a, b; i < v.size(); ++i) {
		pr tmp = v[i]; a = cnt[tmp]; //printf ("%lld %lld\n", tmp.fi, tmp.se);
		if ((b = cnt[make_pair (tmp.se, -tmp.fi)])) {
			c += a + b, res = res * (Pow (2, a) + Pow (2, b) - 1) % mod;
		//	printf ("%d %d\n", a, b);
		}
	} res = (res * Pow (2, n - c - cc) - 1 + cc) % mod; res = (res + mod) % mod;
	return printf ("%lld\n", res), 0;
}

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

int main() {
  int x,y;
  cin >> x >> y;
  
  for (int i=0; i<=x; i++) {
    if(i*2 + (x-i)*4 == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
void LCS( string s1, string s2, int m, int n )
{
   int L[m+1][n+1];
 
   
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (s1[i-1] == s2[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }
 
   
   int index = L[m][n];
   
   char LCS[index+1];
   LCS[index] = '\0'; 

   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      
      if (s1[i-1] == s2[j-1])
      {
          LCS[index-1] = s1[i-1]; 
          i--; j--; index--;  
      }
      
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }
 
   
   cout << LCS<< endl;
}
 

int main(){
  string s, t; cin>>s>>t;
  int m = s.length(), n = t.length();
  LCS(s, t, m , n);
  return 0;
}

Measured memory_bytes: 35456
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string a, b, c;
  cin>>a>>b>>c;
  if(a.back()==b[0]&&b.back()==c[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
	return 0;
}


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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

long long n;
vector<int> b;
long long dp[N][4][2];

bool read() {
    if (!(cin >> n))
        return false;

    return true;
}

void calc00(int i) {
    vector<long long> sum(2);

    for (int j = 0; j < 4; ++j)
        for (int k = 0; k < 2; ++k)
            sum[k] += dp[i - 1][j][k];

    dp[i][0][0] = sum[0];

    if (b[i] == 1)
        dp[i][0][0] += sum[1];

    if (b[i] == 0)
        dp[i][0][1] = sum[1] % MOD;

    dp[i][0][0] %= MOD;
    dp[i][0][1] %= MOD;
}

void calc01(int i) {
    vector<long long> sum(2);

    for (int j = 0; j < 2; ++j)
        for (int k = 0; k < 2; ++k)
            sum[k] += dp[i - 1][j][k];

    dp[i][1][0] = sum[0];

    if (b[i] == 1)
        dp[i][1][1] = sum[1];

    dp[i][1][0] %= MOD;
    dp[i][1][1] %= MOD;
}

void calc10(int i) {
    vector<long long> sum(2);

    for (int j = 0; j < 4; ++j)
        for (int k = 0; k < 2; ++k)
            sum[k] += dp[i - 1][j][k];

    dp[i][2][0] = sum[0];

    if (b[i] == 1)
        dp[i][2][1] = sum[1];

    dp[i][2][0] %= MOD;
    dp[i][2][1] %= MOD;
}

int pizdec(int l, int r) {
    vector<int> b1 = b;
    b1.resize(r + 1);
    vector<int> b2 = b1;
    b2[l] = 1;

    for (int i = l + 1; i <= r; ++i)
        b2[i] = 0;

    if (b2 < b1)
        return -1;

    if (b2 == b1)
        return 0;

    return 228;
}

void calc11(int i) {
    for (int j = i - 2; j >= 0; --j) {
        vector<long long> sum(2);

        for (int j1 = 0; j1 < 4; ++j1)
            for (int k = 0; k < 2; ++k)
                sum[k] += dp[j][j1][k];

        dp[i][3][0] += sum[0];
        auto kok = pizdec(j + 1, i);

        if (kok < 0) {
            dp[i][3][0] += sum[1];
        } else if (kok == 0) {
            dp[i][3][1] += sum[1];
        }

        dp[i][3][0] %= MOD;
        dp[i][3][1] %= MOD;
    }
}

void solve() {
    for (; n > 0; n /= 2)
        b.emplace_back(n & 1);

    b.emplace_back(0);
    reverse(b.begin(), b.end());
    n = b.size() - 1;

    dp[0][0][1] = 1;

    for (int i = 1; i <= n; ++i) {
        calc00(i);
        calc01(i);

        if (i != n) {
            calc10(i);
            calc11(i);
        }
    }

    auto ans = 0ll;

    for (int j = 0; j < 4; ++j)
        for (int k = 0; k < 2; ++k)
            ans += dp[n][j][k];

    cout << ans % MOD << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
from bisect import bisect_right
import sys
input = sys.stdin.readline

class SegmentTree:
    """
    0-indexed
    query : [L, R)
    """
    def __init__(self, size, initValue, cmpFunc):
        self.size = 1 << (size.bit_length())  # 完全二分木にする
        self.data = [initValue] * (2 * self.size - 1)
        self.initValue = initValue
        self.cmpFunc = cmpFunc

    def build(self, rawData):
        self.data[self.size - 1: self.size - 1 + len(rawData)] = rawData
        for i in range(self.size - 1)[:: -1]:
            self.data[i] = self.cmpFunc(self.data[2 * i + 1], self.data[2 * i + 2])

    def update(self, index, value):
        index += self.size - 1
        self.data[index] = value
        while index >= 0:
            index = (index - 1) // 2
            self.data[index] = self.cmpFunc(self.data[2 * index + 1], self.data[2 * index + 2])

    def query(self, left, right):
        L = left + self.size
        R = right + self.size
        ret = self.initValue
        while L < R:
            if R & 1:
                R -= 1
                ret = self.cmpFunc(ret, self.data[R - 1])
            if L & 1:
                ret = self.cmpFunc(ret, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return ret

N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [x for x, _ in XH]

tree = SegmentTree(N + 1, 0, lambda a, b: a + b)

ans = 0
for i, (x, h) in enumerate(XH):
    cnt = tree.query(0, i + 1)
    h -= cnt * A

    if h <= 0:
        continue

    ness = -(-h // A)
    ans += ness
    tree.update(i, tree.query(i, i + 1) + ness)
    j = bisect_right(X, x + 2 * D)
    tree.update(j, tree.query(j, j + 1) - ness)

print(ans)

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;cin>>S;
  int cnt=0;
  for(ll i=0;i<(ll)S.length();i++){
    cnt+=S[i]=='x';
  }
  cout<<(cnt<8? "YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

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

	void run() {
		for (;;) {
			m = sc.nextInt();
			n = sc.nextInt();
			if ((m | n) == 0) {
				break;
			}
			int x = 1, y = 1;
			int k = 0;
			for (;;) {
				String s = sc.next();
				if (s.equals("STOP")) {
					break;
				} else if (s.equals("FORWARD")) {
					int d = sc.nextInt();
					x += dx[k] * d;
					y += dy[k] * d;
				} else if (s.equals("BACKWARD")) {
					int d = sc.nextInt();
					x -= dx[k] * d;
					y -= dy[k] * d;
				} else if (s.equals("RIGHT")) {
					k = (k + 1) % 4;
				} else if (s.equals("LEFT")) {
					k = (k + 3) % 4;
				}
				x = max(1, min(m, x));
				y = max(1, min(n, y));
			}
			println(x + " " + y);
		}
	}

	void solve() {
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
listtest = ["S 1",
            "S 2",
            "S 3",
            "S 4",
            "S 5",
            "S 6",
            "S 7",
            "S 8",
            "S 9",
            "S 10",
            "S 11",
            "S 12",
            "S 13",
            "H 1",
            "H 2",
            "H 3",
            "H 4",
            "H 5",
            "H 6",
            "H 7",
            "H 8",
            "H 9",
            "H 10",
            "H 11",
            "H 12",
            "H 13",
            "C 1",
            "C 2",
            "C 3",
            "C 4",
            "C 5",
            "C 6",
            "C 7",
            "C 8",
            "C 9",
            "C 10",
            "C 11",
            "C 12",
            "C 13",
            "D 1",
            "D 2",
            "D 3",
            "D 4",
            "D 5",
            "D 6",
            "D 7",
            "D 8",
            "D 9",
            "D 10",
            "D 11",
            "D 12",
            "D 13",
            ]

y = int(input())

for i in range(y):
    a = input()
    listtest.remove(a)

for ans in listtest:
    print(ans)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define endl '\n'
#define LL long long
#define LD long double
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
int const MAXN = 2e6 + 9;
LL n, L;
LL get_grundy(LL x){
    LL ret = 1;
    while(x % 2 == 0){
        x /= 2;
        ret *= 2;
    }
    return ret;
}
struct Trie{
    static const int K = 2;
    struct Vertex {
        int next[K];
        bool leaf = false;
        int lvl = 0;
        Vertex() {
            fill(begin(next), end(next), -1);
        }
    };
    vector<Vertex> trie;
    Trie(){
        trie.emplace_back();
    }
    void add_string(string const& s) {
        int v = 0;
        for (char ch : s) {
            int c = ch - '0';
            if (trie[v].next[c] == -1) {
                trie[v].next[c] = trie.size();
                trie.emplace_back();
                int idx = sz(trie) - 1;
                trie[idx].lvl = trie[v].lvl+ 1;
            }
            v = trie[v].next[c];
        }
        trie[v].leaf = true;
    }
    int change = 0;
    int notchange = 0;
    bool diff(int x, int y){
        if (x > y) swap(x,y);
        return (x == -1 && y!= -1);
    }
    vector<LL> numbers;
    void dfs(int node){
        if(node == -1) return;
        if(diff(trie[node].next[0],trie[node].next[1])){
            numbers.push_back(get_grundy(L- trie[node].lvl));
        }
        dfs(trie[node].next[0]);
        dfs(trie[node].next[1]);
    }
    void solve(){
        dfs(0);
        LL ans = 0;
        for(auto x : numbers) ans = x  ^ ans;
        if(ans)
        cout << "Alice";
        else  cout << "Bob";
    }
};


int main(){
    ios_base::sync_with_stdio (0),cin.tie(0);
    cin >> n >> L;
    Trie trie;
    for(int i  = 0; i < n; i++){
        string s;
        cin >> s;
        trie.add_string(s);
    }
    trie.solve();
}

Measured memory_bytes: 5468
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
	int n; ll x; cin >> n >> x;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ll t = min(a[i], max(a[i - 1] + a[i] - x, 0ll));
		a[i] -= t; ans += t;
	}
	for (int i = n - 2; i >= 0; i--) {
		ll t = min(a[i], max(a[i + 1] + a[i] - x, 0ll));
		a[i] -= t; ans += t;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1024
import Data.Array.IO
import Control.Monad

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  input <- map (map read . words) . lines <$> getContents :: IO [[Int]]
  memo <- newArray (1, n) 0 :: IO (IOUArray Int Int)
  foldM memoize memo input
  ans <- getElems memo
  putStr $ unlines . map show $ ans

memoize :: IOUArray Int Int -> [Int] -> IO (IOUArray Int Int)
memoize memo [i, j] = do
  ii <- readArray memo i
  jj <- readArray memo j
  writeArray memo i (ii+1)
  writeArray memo j (jj+1)
  return memo


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x % y);
}

const int N = 100100;
char s[N], p[N];
int n, m;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	scanf("%s %s", s, p);
	int g = gcd(n, m);
	bool ok = true;
	for (int i = 0; i < g; i++)
		ok &= s[i * (n / g)] == p[i * (m / g)];
	if (!ok)
		printf("-1\n");
	else
		printf("%lld\n", (ll)n * m / g);

	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
int a[3][3];
int n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    for(int i = 0 ; i < 3 ; ++i){
        for(int j = 0 ; j < 3 ; ++j){
            cin >> a[i][j];
        }
    }
    cin >> n;
    for(int t = 0 ; t < n ; ++t){
        int x;cin >> x;
        for(int i = 0 ; i < n ; ++i){
            for(int j = 0 ; j < n ; ++j){
                if(a[i][j] == x)a[i][j] = 0;
            }
        }
    }
    for(int i = 0 ; i < 3 ; ++i){
        if(a[i][0] + a[i][1] + a[i][2] == 0)return cout << "Yes" , 0;
        if(a[0][i] + a[1][i] + a[2][i] == 0)return cout << "Yes" , 0;
    }
    if(a[0][0] + a[1][1] + a[2][2] == 0)return cout << "Yes" , 0;
    if(a[2][0] + a[1][1] + a[0][2] == 0)return cout << "Yes" , 0;
    cout << "No";

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        public class lower_bound<T> : IComparer<T> where T : IComparable<T>
        {
            public int Compare(T x, T y) => 0 <= x.CompareTo(y) ? 1 : -1;
        }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var N = Sarray()[0];
            var Ai = Sarray();
            var A = new long[N];
            for (var i = 0; i < N; ++i)
                ++A[Ai[i] - 1];
            Array.Sort(A);
            var S = new long[N + 1];

            var lb = new lower_bound<long>();
            Func<long, long, bool> ok = (cok, kok) =>
            {
                long i = ~Array.BinarySearch(A, cok, lb);
                long sum = cok * (N - i) + S[i];
                return cok * kok <= sum;
            };
            for (var i = 0; i < N; ++i) S[i + 1] = S[i] + A[i];
            long ans = N;
            for (var k = 1; k <= N; ++k)
            {
                while(true)
                {
                    if (ok(ans, k)) break;
                    --ans;
                }
                WriteLine(ans);
            }
            Out.Flush();
        }
    }
}

Measured memory_bytes: 48812
#include<bits/stdc++.h>
using namespace std;
string s;
int p,len;

string bnf(bool rev){
  string res;
  int cnt=0;
  while(p!=len){
    if(s[p]=='+')p++,cnt++;
    if(s[p]=='-')p++,cnt--;
    if('A'<=s[p]&&s[p]<='Z')res+=((s[p++]+cnt+26*100)-'A')%26+'A',cnt=0;
    if(s[p]=='?')res+=s[p++],cnt=0;
    if(s[p]=='[')p++,res+=bnf(true);
    if(s[p]==']'){
      p++;
      break;
    }
  }
  if(rev)reverse(res.begin(),res.end());
  return res;
}

int main(){
  while(1){
    cin>>s;
    if(s==".")break;
    len=s.size();
    p=0;
    string ans=bnf(false);
    for(int i=0;i<(int)ans.size();i++)
      if(ans[i]=='?')ans[i]='A';
    cout<<ans<<endl;
  }
  return 0;
}

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

int main()
{
  char c, str[10];
  int back = 0;

  while(~scanf("%1c", &c)){
    if (c == 'B'){
      if (back){
        back--;
      }
    }
    else {
      str[back] = c;
      back++;
    }
  }

  for (int i = 0; i < back; i++){
    cout << str[i];
  } 

  return 0;
}





Measured memory_bytes: 256
n,k=map(int,input().split())
ans=[[0]*(3*k+10) for i in range(4*k+10)]
for i in range(n):
    x,y,c=input().split()
    x=int(x)
    y=int(y)
    a=x//k%2
    b=x%k
    d=y//k%2
    e=y%k
    x=b+a*k
    y=e+d*k
    if (a+d)%2==0:
        if c=="B":

            x=k-b
            y=k-e

        else:
            x=2*k-b
            y=k-e
    else:
        if c == "W":
            x = k - b
            y = k - e

        else:
            x = 2 * k - b
            y = k - e

    ans[x][y]+=1
    ans[x][y+k]-=1
    ans[x+k][y]-=1
    ans[x+k][y+k]+=1


for i in range(4*k+9):
    for j in range(3*k+9):
        ans[i][j+1]=ans[i][j]+ans[i][j+1]
for i in range(4*k+9):
    for j in range(3*k+9):
        ans[i+1][j]=ans[i][j]+ans[i+1][j]
anser=0

for x in range(k,2*k):
    for y in range(k,2*k):
        p=ans[x][y]+ans[x-k][y-k]+ans[x-k][y+k]+ans[x+k][y+k]+ans[x+k][y-k]
        anser=max(anser,p)
for x in range(2*k,3*k):
    for y in range(k,2*k):
        p = ans[x][y] + ans[x - k][y - k] + ans[x - k][y + k] + ans[x + k][y + k] + ans[x + k][y - k]+ans[x-2*k][y]
        anser = max(anser, p)
print(anser)



Measured memory_bytes: 165552
#include <iostream>
using namespace std;
int main(void)
{
    int r, D, x2000;
    cin >> r >> D >> x2000;
    
    for (int i = 0; i < 10; i++)
    {
        x2000 = r * x2000 - D;
        cout << x2000 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const long double EPS = 0.0000001;

int main(){
	ll N,x;
	ll a[2002],b[2002];
	cin >> N >> x;
	for(int i = 0 ; i < N ; i ++){
		cin >> a[i];
		b[i] = a[i];
	}
	
	ll ret = 1000000000000000000;
	for(int i = 0 ; i <= N ; i ++){
		ll sum = 0;
		for(int j = 0 ; j < N ; j ++){
			sum += b[j];
		}
		ret = min ( ret , sum+x*i );
		if(i == N)break;
		for(int j = 0 ; j < N ; j ++){
			b[j] = min( b[j], a[(j-i-1+N)%N] );
		}
	}
	cout << ret << endl;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main(){ _

	int n, k; cin >> n >> k;
	vector<int> v(n);
	for(int& i : v) cin >> i;

	for(int i=k; i<n; i++) {
		if(v[i-k] < v[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;
const int nax = 200005;
int n,a[nax];
void solve()
  {
   cin>>n;
   loop(i,0,n)
    cin>>a[i];
   int ans = 0;
   int last = a[1];
   loop(i,1,n)
    {
      if(a[i] < a[i-1])
         {
          ans += a[i-1] - a[i];
          a[i] = a[i-1];
         }
      last = a[i];
    }
   cout<<ans;
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 5200
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, m;
    cin >> n >> m;
    vector<LP> A(n), C(m);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        A[i].first = a;
        A[i].second = b;
    } 
    rep(i, m) {
        int c, d;
        cin >> c >> d;
        C[i].first = c;
        C[i].second = d;
    }
    vector<ll> ans(n);
    rep(i, n) {
        ll value, minv = LINF;
        rep(j, m) {
            value = abs(A[i].first - C[j].first) + abs(A[i].second - C[j].second);
            if(minv > value) {
                minv = value;
                ans[i] = j;
            }
        }
    }
    rep(i, n) {
        cout << ans[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range (M)]
sc = []
sl = []
tc = []
tl = []
anslist = []
i = 0 
j = 0
k = 0
l = 0

s.sort()
t.sort()


while i < N:
  sc.append(s.count(s[i]))
  sl.append(s[i])
  i += s.count(s[i])
  
while j < M:
  tc.append(t.count(t[j]))
  tl.append(t[j])
  j += t.count(t[j])

for k in range(len(sl)):
  for l in range(len(tl)):
    if tl[l] == sl[k]:
      sc[k] -= tc[l]
  
print(max(max(sc), 0))
     
  

Measured memory_bytes: 3064
N=gets.to_i
S1=gets.chomp
S2=gets.chomp
MOD=10**9+7
pre=nil
c=0
ret=1
while c < N do
    if pre=="tate"
        if S1[c]==S2[c]
            ret*=2
            c+=1
        else
            ret*=2
            c+=2
            pre="yoko"
        end
    elsif pre=="yoko"
        if S1[c]==S2[c]
            ret*=1
            c+=1
            pre="tate"
        else
            ret*=3
            c+=2
        end
    else
        if S1[c]==S2[c]
            ret*=3
            c+=1
            pre="tate"
        else
            ret*=6
            c+=2
            pre="yoko"
        end
    end
    ret%=MOD
end
puts ret


Measured memory_bytes: 14288
def make_divisors(n):
    """
    約数を列挙
    入力：整数n
    戻り値：約数のリスト

    例
    入力：105
    戻り値：[1, 3, 5, 7, 15, 21, 35, 105]
    """
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())
ans = 0
for i in range(1, n + 1, 2):
    if len(make_divisors(i)) == 8:
        ans += 1
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#include <deque>
#define int long long
using namespace std;
int32_t main(){
    int n;
    cin >> n;
    int matrix[n][n];
    for (int i=0; i < n; i++){
        for (int j=0; j < n; j++){
            cin >> matrix[i][j];
        }
    }
    int ans = 0;
    for (int i=0; i < n; i++){
        for (int j=i+1; j < n; j++){
            int r = matrix[i][j];
            bool pl = true;
            for (int k=0; k < n; k++){
                if (k == i || k == j) continue;
                int d = matrix[i][k] + matrix[k][j];
                if (d < r){
                    cout << -1 << endl;
                    return 0;
                }
                if (d == r){
                    pl = false;
                }
            }
            if (pl){
                ans += r;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

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

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    ll n;
    cin >> n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ll no=n/i;
        ans+=no*(2*i+i*(no-1))/2;
        //cout << "ans: "<< ans << endl;
    }
    cout << ans << endl;
}


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

	return 0;
}

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

using namespace std;
using ll = long long int;

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
    cin >> A[i];

  for (ll i = K; i < N; i++)
  {
    if (A[i - K] < A[i])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  double x,ans=0;
  string u;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> x >> u;
    if(u=="JPY")ans+=x;
    else ans+=x*380000;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()
	a := scanInts(n)

	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		sum[i+1] = sum[i]+a[i]
	}

	// debug(sum)

	b := make([]int, 0, n*(n+1)/2)
	for i := 0; i < n; i++ {
		for j := i+1; j < n+1; j++ {
			b = append(b, sum[j]-sum[i])
		}
	}

	sort.Ints(b)

	f := make([]bool, len(b))

	for i := 0; i < 63; i++ {
		c := 0
		for j := 0; j < len(b); j++ {
			if f[j] {
				continue
			}
			if b[j] >> uint(62-i) & 1 == 1 {
				c++
			}
		}

		if c >= k {
			for j := 0; j < len(b); j++ {
				if f[j] {
					continue
				}

				if b[j] >> uint(62-i) & 1 == 0 {
					f[j] = true
				}
			}
		}
	}

	// debug(f)
	// debug(b)

	ans := 1<<63-1
	for i := 0; i < len(b); i++ {
		if f[len(b)-1-i] {
			continue
		}
		ans &= b[len(b)-1-i]
		// debug(b[len(b)-1-i])
		k--
		if k == 0 {
			break
		}
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007



//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }




int main() {

  ll H,W;
  cin>>H>>W;
  vvchar a(H, vchar(W));
  rep(i,H)rep(j,W)cin>>a[i][j];

  vvint dp(H+1, vint(W+1, 0));

  dp[0][1]=1;

  rep(i,H){
    rep(j,W){
      if(a[i][j]=='.'){
        dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j])%DIVIDER;
      }else{
        dp[i+1][j+1] = 0;
      }
    }
  }

  cout << dp[H][W] << endl;


}

















//


Measured memory_bytes: 9088
use std::io::{stdout, Write, BufWriter};

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<i64>();
    let (n, k, q) = (input[0], input[1], input[2]);
    let mut points = vec![0; n as usize];

    let need = q - k;

    for _ in 0..q {
        let a = read::<usize>() - 1;
        points[a] += 1;
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    for point in points {
        if point > need {
            writeln!(out, "Yes").unwrap();
        } else {
            writeln!(out, "No").unwrap();
        }
    }
}

Measured memory_bytes: 4732
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    n = int(input())
    students = [int(x) for x in input().split()]
    ret = [0] * n
    for i in range(n):
        ret[students[i] - 1] = i + 1
    print(" ".join([str(x) for x in ret]))
    return


if __name__ == "__main__":
    main()

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


int main() {
  int n;
  cin >> n;
  string s[n];
  rep(i, n) cin >> s[i];
  int m;
  cin >> m;
  string t[m];
  rep(i, m) cin >> t[i];
  
  map<string, int> card;
  rep(i, n){
    if(card.count(s[i])) card[s[i]]++;
    else card[s[i]] = 1;
  }
  rep(i, m){
    if(card.count(t[i])) card[t[i]]--;
    else card[t[i]] = -1;
  }
  int my_max = -m;
  for(auto p: card){
    my_max = max(my_max, p.second);
  }
  if(my_max < 0) my_max = 0;
  cout << my_max << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+234;

vector<int> g[N];
int c[N];
bool bio[N];

void dfs(int u, int x=0) {
  bio[u] = true;
  c[u] += x;
  for (int v: g[u]) {
    if (bio[v]) continue;
    dfs(v, c[u]);
  }
}

void solve() {
  int n, q; scanf("%d%d", &n, &q);
  for (int i = 0; i < n-1; ++i) {
    int a, b; scanf("%d%d", &a, &b);
    g[--a].push_back(--b);
    g[b].push_back(a);
  }
  for (int i = 0; i < q; ++i) {
    int p, x; scanf("%d%d", &p, &x);
    c[--p] += x;
  }
  dfs(0);
  for (int i = 0; i < n; ++i) {
    printf("%d ", c[i]);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 20608
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=100010;
const int P=1000000007;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;//a-b昇順
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// a^n mod 
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;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	int  n  ,a  ,b  ,c  ,d  ,e  ,f  ;
//	cin  >>n  >>a  >>b  >>c  >>d  >>e  >>f  ;

/*
	memset(b, '\0', sizeof(b));
初期化*/
/*
	len = strlen(s);
文字列長さ*/
/*
	string s;
	s.size()
*/
/*ソート
	qsort(b, 10, sizeof(int), compare_int);
*/
/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("YES");
	else puts("NO");
*/
/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

int main(){
	int m, d, ans=0;
	cin>>m>>d;
	rep(i,d+1){
		if((i%10>1)&&((i/10)%10>1)&&((i%10)*((i/10)%10)<=m)){
			ans++;
		}
	}

	cout<<ans<<endl;
		
}

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

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    int r, c;
    cin >> r >> c;
    string s, t;
    cin >> s >> t;
    bool remain = true;
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'L')  cnt++;
        if(cnt >= c)    remain = false;
        if(t[i] == 'R' && c-cnt != w)   cnt--;
    }

    cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R')  cnt++;
        if(cnt >= w-c+1) remain = false;
        if(t[i] == 'L' && c+cnt != 1)   cnt--;
    }

    cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'U')  cnt++;
        if(cnt >= r) remain = false;
        if(t[i] == 'D' && r-cnt != h)   cnt--;
    }

    cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'D')  cnt++;
        if(cnt >= h-r+1) remain = false;
        if(t[i] == 'U' && r+cnt != 1)   cnt--;
    }

    cout << (remain ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 904
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 7)
def dfs(u):
    cnt = 0
    res = 1
    for i in edges[u]:
        if visited[i] == -1:
            visited[i] = 0
            cnt += 1
            res *= dfs(i)
            res %= mod
    for i in range(cnt):
        res *= k - i - 2
        res %= mod
    return res
n, k = map(int, input().split())
edges = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
visited = [-1] * n
visited[0] = 0
ans = k
for i in range(len(edges[0])):
    ans *= (k - i - 1)
    ans %= mod
for i in edges[0]:
    visited[i] = 0
    ans *= dfs(i)
    ans %= mod
print(ans)

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

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

#define PRINT_VECTOR_MAX 100
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)min(v.size(),PRINT_VECTOR_MAX); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)min(v.size(),PRINT_VECTOR_MAX); i++) {for (ll j = 0; j < (ll)min(v[i].size(),PRINT_VECTOR_MAX); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();
int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

void Main(){
    int n,k; cin >> n >> k;
    vector<mint> dp(n+1, mint(0));
    vector<mint> dpsum(n+1, mint(0));
    vector<int> l(k), r(k);
    rep(i,k) cin >> l[i] >> r[i];
    dp[1] = mint(1);
    dpsum[1] = mint(1);
    mint s(1);
    for(int x = 2; x <= n; x++){
        rep(i, k){
            if(x - l[i] >= 1){
                dp[x] += (dpsum[x-l[i]] - dpsum[max(0, x-r[i]-1)]);
            }
        }
        s += dp[x];
        dpsum[x] = s;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 6328
#include <bits/stdc++.h>
#include <bits/extc++.h>
#include <atcoder/all>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
//#define inf 2000000000
#define inf 8000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;
using namespace atcoder;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=500005;
//i_am_noob
int n,q,o,p,x,l,r;
fenwick_tree<int> bit(maxn);

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> q;
  	rep(n){
		cin >> x;
      	bit.add(i,x);
    }
  	while(q--){
      	cin >> o;
      	if(o==1){
          	cin >> l >> r;
        	print1(bit.sum(l,r));
        }
      	else{
          	cin >> p >> x;
          	bit.add(p,x);
        }
    }
    return 0;
}


Measured memory_bytes: 8236
N, M = gets.split.map(&:to_i)
Job = Struct.new(:day, :money) do
  def <=>(other)
    n = other.money <=> money
    n == 0 ? day <=> other.day : n
  end
end
jobs = $<.read.split(?\n).map {|x| Job.new(*x.split.map(&:to_i))}.sort!

days = [*1..M]
sum_money = jobs.reduce(0) do |sum, job|
  next(sum) unless i = days.bsearch_index {|day| day >= job.day}
  days.delete_at(i)
  sum + job.money
end

puts sum_money


Measured memory_bytes: 20616
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
vector<vector<lint> > G;
vector<bool> visit;

void dfs(lint start, lint ago){
	visit[start] = true;
	for(lint i = 0; i < G[start].size(); i++){
		lint next = G[start][i];
		if(visit[next]) continue;
		dfs(next, start);
	}
}

signed main(){
	lint N, M; cin >> N >> M;
	G.reserve(N);
	visit.resize(N, false);
	for(lint i = 0; i < M; i++){
		lint x, y, z; cin >>x >> y >> z; --x; --y;
		G[x].push_back(y); G[y].push_back(x);
	}
	lint ans = 0;
	for(lint i = 0; i < N; i++){
		if(!visit[i]) ans++; dfs(i, -1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 10368
n = gets.chomp.split("").map(&:to_i)
if n[0] > n[1]
  puts n[0].to_s * 3
elsif n[0] == n[1]
  if n[1] >= n[2]
    puts n[0].to_s * 3
  else
    puts (n[0]+1).to_s * 3
  end
else
  puts (n[0]+1).to_s * 3
end

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

const int INF = 10000000;

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

    int dp[1000000]; //dp[i]はi円おろすときの最小回数
    for (int i = 0; i <= N; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 0; i <= N; i++) {
        for (int pow6 = 1; pow6 <= N; pow6 *= 6) {
            dp[i+pow6] = min(dp[i+pow6], dp[i] + 1);  
        }
        for (int pow9 = 1; pow9 <= N; pow9 *= 9) {
            dp[i+pow9] = min(dp[i+pow9], dp[i] + 1);
        }
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int bin(ll k,ll n)
{
   ll left = 0;
   ll right = n+1;
   while(1)
   {
      ll mid = (left+right)/2;
      if(n/mid<=k)right= mid;
      else left = mid;
      if(right-left==1)break;
   }
   return right;
}

int main()
{
   ll n;cin >>n;
   ll ans = 0;

   for(ll left = 2 ;left<n;left++)
   {
      ll right = n+1;
      ll now = n/left;
      while(1)
      {
         ll mid = (right+left)/2;
         if(n/mid<now)right=mid;
         else left = mid;
         
         if(right-left==1)break;
      }
      if(n%left==0)
      {
         if(n/(left-1)==n%(left-1))ans+=left-1;
      }
      //cout<<left<<' ';

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

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 0;i<9;i++){
            for(int j = 0;j<9;j++){
                if((i+1)*(j+1)==n){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
        sc.close();
    }
}

Measured memory_bytes: 22612
#include <iostream>

using namespace std;

int main(){
  int n,i,tn=0,hn=0;
  cin >> n;
  string t,h;
  for (i=0;i<n;i++) {
    cin >> t >> h;
    if (t == h) {
      tn+=1;
      hn+=1;
    } else if (t > h) {
      tn+=3;
    } else {
      hn+=3;
    }
  }
  cout << tn << " " << hn << endl;
  return 0;
}



Measured memory_bytes: 3204