akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 100000;
///----------------------------------------------
bool f[MAX_N];
int main() {
	
	///read
	string str; cin>>str;
	
	///work
	static string tab[4] = {"dream","dreamer","erase","eraser"};
	memset(f,false,sizeof(f));
	rep(i,0,sz(str)) {
		rep(j,0,4) if (i+1>=sz(tab[j])) {
			if (i-sz(tab[j])==-1 || f[i-sz(tab[j])])
				if (str.substr(i-sz(tab[j])+1,sz(tab[j]))==tab[j]) {
					f[i]=true;
					break;
				}
		}
		//debug(f[i]);
	}
	
	///print
	puts(f[sz(str)-1] ? "YES" : "NO");




}


Measured memory_bytes: 640
s = input()
t = input()

minCount = len(t)
l = len(s) - len(t) + 1
for i in range(l):
    count = 0
    for n in range(len(t)):
        if s[i+n] != t[n]:
            count+=1
    if count < minCount:
        minCount = count
print(minCount)

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>


struct Node {
    int idx;
    std::vector<int> x = std::vector<int>(2);
    Node* left = nullptr;
    Node* right = nullptr;
};


Node* kdtree(std::vector<Node>& nodes, int start, int end, int depth) {
    if (start == end) {
        return nullptr;
    }
    int axis = depth % 2;
    std::sort(nodes.begin() + start, nodes.begin() + end,
              [&axis](auto &lhs, auto &rhs) {return lhs.x[axis] < rhs.x[axis];});
    int center = (start + end) / 2;
    nodes[center].left = kdtree(nodes, start, center, depth + 1);
    nodes[center].right = kdtree(nodes, center + 1, end, depth + 1);
    return &nodes[center];
}


std::vector<int> search(Node * node, std::vector<int>& sxy, std::vector<int>& txy, int depth) {
    if (node == nullptr) {
        return std::vector<int>();
    }

    std::vector<int> indices;
    if (sxy[0] <= node->x[0] && node->x[0] <= txy[0] &&
        sxy[1] <= node->x[1] && node->x[1] <= txy[1]) {
        indices.emplace_back(node->idx);
    }

    int axis = depth % 2;
    int val = node->x[axis];
    if (sxy[axis] <= val) {
        auto ids = search(node->left, sxy, txy, depth + 1);
        indices.insert(indices.begin(), ids.begin(), ids.end());
    }
    if (val <= txy[axis]) {
        auto ids = search(node->right, sxy, txy, depth + 1);
        indices.insert(indices.begin(), ids.begin(), ids.end());
    }

    return indices;
}


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

    std::vector<Node> nodes(n, Node());
    for (int i = 0; i < n; i++) {
        nodes[i].idx = i;
        scanf("%d %d", &nodes[i].x[0], &nodes[i].x[1]);
    }
    Node* root = kdtree(nodes, 0, n, 0);

    int q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        std::vector<int> sxy(2), txy(2);
        scanf("%d %d %d %d", &sxy[0], &txy[0], &sxy[1], &txy[1]);
        auto indices = search(root, sxy, txy, 0);
        sort(indices.begin(), indices.end());
        for (auto && idx : indices) {
            printf("%d\n", idx);
        }
        printf("\n");
    }
}



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

using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    long long l,r;
    long long arr[n+1]={0};
    for(long long int i=0;i<m;i++)
    {
        cin>>l>>r;
        l--;
        arr[l]++;
        arr[r]--;
    }
    for(long long int i=1;i<n+1;i++){
        arr[i]+=arr[i-1];
    } 
    long long count=0;
    for(long long i=0;i<n+1;i++){ 
        if(arr[i]==m){
            count++;
        }
    } 
    cout<<count;
}

Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i = (n)-1; i >=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i =(b)-1; i >= a; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const double inf = 1e9;
int main(){
    int n; cin >> n;
    vector<double> t(n),v(n);
    rep(i,n) cin >> t[i];
    rep(i,n) cin >> v[i];
    double ts = 0.0;
    rep(i,n) ts += t[i];
    vector<double> mv(2*ts + 1, inf);
    double now = 0.0;
    rep(i,n){
        rep(j, t[i]){
            double tl = now + 2*j;
            double tr = now + 2*j + 1;
            mv[tl] = min(mv[tl], v[i]);
            mv[tr] = min(mv[tr], v[i]);
        }
        now += 2*t[i];
        mv[now] = min(mv[now], v[i]);
    }
    mv[0] = mv[2*ts] = 0;
    rep(i, 2*ts + 1) mv[i+1] = min(mv[i+1], mv[i] + 0.5);
    rrep(i, 2*ts + 1) mv[i] = min(mv[i], mv[i+1] + 0.5);
    double ans = 0.0;
    rep(i, 2*ts + 1) ans += (mv[i] + mv[i+1]) / 4.0;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<string.h>

int main(){
    int R;
    scanf("%d",&R);
    if(2800<=R) printf("AGC");
    else if(1200<=R) printf("ARC");
    else printf("ABC");
    return 0;
}

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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;


void solveBruteForce()
{

}

void solveOptimized()
{
	int x, y;
	cin >> x >> y;
	int t = 0, c = x;
	bool ans= 0;
	for (t; t <= x; t++)
	{
		c = x - t;
		if (4 * t + 2 * c == y)
			ans=  1;
	}
	if (ans)
		cout << "Yes\n";
	else
		cout << "No\n";
}

void solve()
{
	// solveBruteForce();
	solveOptimized();
}

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

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

	return 0;
}




Measured memory_bytes: 3644
a, b, c, d = map(int, input().split())

if b <= c or d <= a:
    print(0)
elif a <= c and d <= b:
    print(d - c)
elif a <= c and b <= d:
    print(b - c)
elif c <= a and b <= d:
    print(b - a)
elif c <= a and d <= b:
    print(d - a)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long func(long long b){
    if (b % 4 == 0) return b;
    if (b % 4 == 1) return 1;
    if (b % 4 == 2) return b+1;
    return 0;
}
int main(){
    long long A,B; cin >> A >> B;
    cout << (func(B)^func(A-1)) << endl;
    //cout << (0^0) << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string ans="yes";
    for(int i=0;i<s.size();i++){
    	for(int j=i+1;j<s.size();j++){
    		if(s[i]==s[j]){
    			ans="no";
			}
			}
		}
				cout<<ans<<endl;
				return 0;
	}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 3;
        int nums[] = new int[n];
        for(int j = 0; j < nums.length ;j++){
            nums[j] = sc.nextInt();
        }
        int cnt1 = 0;
        int cnt2 = 0;

        for(int i =0; i < nums.length; i++){
            if(nums[i]==5){
                cnt1 ++;
            }
            else if(nums[i]==7){
                cnt2 ++;
            }
            else{
                break;
            }
        }

        if(cnt1 ==2 && cnt2 ==1){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

int main(void) {
    int i;
    ll k;
    cin >> k;

    int n = 50;
    printf("%d\n",n);
    REP (i,n) printf("%lld ",n - i - 1 + k / n + (k % n > i));
    puts("");
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] tmp = br.readLine().split(" ");
			long h = Long.parseLong(tmp[0]);
			long w = Long.parseLong(tmp[1]);
			tmp = null;
			if (h == 0 && w == 0)
				break;
			else
				write(h, w);
		}
	}

	private static void write(long h, long w) {
		String[] charTable = { "#", "." };
		StringBuilder sb = new StringBuilder();
		
		for(int i = 0;i < w;i++){
			sb.append(charTable[i % 2]);
		}
		sb.append(String.format("%n"));
		String even = sb.toString();
		sb.delete(0, sb.length());
		
		for(int i = 0;i < w;i++){
			sb.append(charTable[(i+1) % 2]);
		}
		sb.append(String.format("%n"));
		String odd = sb.toString();
		sb.delete(0, sb.length());
		
		String[] lineTable = {even, odd};
		for(int i = 0;i < h;i++){
			sb.append(lineTable[i % 2]);
		}
		
		System.out.println(sb.toString());
		sb = null;
	}

}

Measured memory_bytes: 18540
/* Manish Pant - insider_pants, hello_my_friend */
    
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ", "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } 

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N = 2e3 + 5;
int n;
vector<pll> v;
ll dp[N][N];

void solve()
{
    sort(v.rbegin(), v.rend());

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j + i < n; j++)
        {
            // i from starting, j from ending
            int idx = i + j;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[idx].F * abs(v[idx].S - i));
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + v[idx].F * abs(v[idx].S - (n - j -1)));
        }
    }

    ll ans = 0;
    for(int i = 0; i <= n; i++)
    {
        ans = max(ans, dp[i][n - i]);
    }
    cout<<ans<<endl;
}

int main()
{
    fast();
    cin>>n;
    for(int i = 0; i < n; i++)
    {
        ll a; cin>>a;
        v.pb({a, i});
    }
    solve();
}

Measured memory_bytes: 26364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cs_006_start
{
    class ConsoleApp1
    {
        
        private static void Main(string[] args)
        {
            int[] values = GetConsole();
            int intMuluti = values[0] * values[1];
            Console.WriteLine(intMuluti);


        }

        private static int[] GetConsole()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
    }
}


Measured memory_bytes: 28088
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}

vector<int> v(200001, 0);

void update(int i, int va, int n)
{
	while(i<n)
	{
		v[i]+=va;
		i+=(i&-i);
	}
}

int query(int i)
{
	int s=0;
	while(i>0)
	{
		s+=v[i];
		i-=(i&-i);
	}
	return s;
}

int32_t main()
{
	fast;

	int n;
	cin>>n;
	int c=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		int a=query(x-1);
		// cout<<x<<' '<<a<<endl;
		if(a==0)
			c++;
		update(x, 1, n);
	}
	cout<<c<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif


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

  ll A[N], B[N];
  rep(i, N) cin >> A[i] >> B[i];
  ll dp_l[N+2][T+1], dp_r[N+2][T+1];
  rep(i, N+2) rep(j, T+1) dp_l[i][j] = dp_r[i][j] = 0;

  rep(i, N) {
    rep(t, T+1) {
      if (t-A[i] >= 0)
        dp_l[i+1][t] = max(dp_l[i][t], B[i] + dp_l[i][t-A[i]]);
      else
        dp_l[i+1][t] = dp_l[i][t];
    }
  }
  // 右から
  rrep(i, N-1) {
    rep(t, T+1) {
      if (t-A[i] >= 0)
        dp_r[i][t] = max(dp_r[i+1][t], B[i]+dp_r[i+1][t-A[i]]);
      else
        dp_r[i][t] = dp_r[i+1][t];
    }
  }

  ll ans = max(dp_l[N][T-1], dp_r[0][T-1]);
  rep(i, N) {
    rep(t, T) {
      ans = max(ans, dp_l[i][t] + dp_r[i+1][T-t-1] + B[i]);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 141056
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;

int main(){
  ll N;
  cin>>N;
  vector<int> d(N);
  ll ans=0;
  for(int i=0;i<N;i++){
      cin>>d[i];
    }
  for(int i=0;i<N-1;i++){
     for(int j=i+1;j<N;j++){
       ans+=d[i]*d[j];
     }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from fractions import gcd


def solve(string):
    a, b, c, d = map(int, string.split())
    _gcd = gcd(c, d)
    lcm = (c // _gcd) * (d // _gcd) * _gcd
    return str(b - a + 1 - (b // c - (a - 1) // c + b // d - (a - 1) // d - b // lcm +
               (a - 1) // lcm))


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 5052
# 使うやつだけimportに変更
from bisect import bisect_left, bisect_right

N, M, K = map(int, input().split())
AA = list(map(int, input().split()))
BB = list(map(int, input().split()))
# CC、DDがKを超えない範囲の
# 初期条件をinfi=10**20に。
CC = [10 ** 20] * len(AA)
DD = [10 ** 20] * len(BB)
CC[0] = AA[0]
#
for i in range(N - 1):
    CC[i + 1] = CC[i] + AA[i + 1]
    if CC[i + 1] >= K:
        break

ans = max(0, bisect_right(CC, K))
DD[0] = BB[0]
if DD[0] <= K:
    ans = max(ans, bisect_right(CC, K - DD[0]) + 1)
for i in range(M - 1):
    DD[i + 1] = DD[i] + BB[i + 1]
    if DD[i + 1] <= K:
        ans = max(ans, bisect_right(CC, K - DD[i + 1]) + i + 2)
    else:
        break
print(ans)


Measured memory_bytes: 118244
import sys

# %%

n, m = list(map(int, sys.stdin.readline().split()))
ary = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
bry = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
mod = 10 ** 9 + 7

# %%

if len(set(ary)) != len(ary) or len(set(bry)) != len(bry):
    print(0)

else:
    ary.append(0)
    bry.append(0)

    cnt = 1
    i = 0
    j = 0
    for num in range(n * m, 0, -1):

        if (num == ary[i]) & (num == bry[j]):
            i += 1
            j += 1

        elif (num == ary[i]) ^ (num == bry[j]):
            if num == ary[i]:
                cnt *= j
                i += 1
            else:
                cnt *= i
                j += 1

        else:
            cnt *= (i * j - (n * m - num))

        cnt = cnt % mod

    print(cnt)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a==b && b==c) {
			System.out.println("1");
		} else if (a==b | b==c | a==c) {
			System.out.println("2");
		} else {
			System.out.println("3");		
		}
	}
}

Measured memory_bytes: 23764
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  private[this] val S = "0" + in.next()


  //
  private[this] def check(len: Int): Boolean = {
    val d: Map[String, Int] = Map()

    var flag = false
    breakable {
      for (i <- 1 to N-(len-1)) {
        val now = S.substring(i, i+len)
        if (d.contains(now)){
          if (i >= d(now)+len) {
            flag = true
            break
          }
        }
        else {
          d(now) = i
        }
      }
    }
    flag
  }

  // 条件を満たす最大の値を返す
  private[this] def binarySearch(min: Int, max: Int): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(max) match{
          case true  => max
          case false => min
        }
      case _ =>
        (check(mid)) match{
          case true  => binarySearch(mid, max)
          case false => binarySearch(min, mid)
        }
    }
  }

  val ans = binarySearch(0, N/2)
  println(ans)
}


class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 126212
#!/usr/bin/env python3
import re
No = "UNRESTORABLE"

def main():
    S = input()
    T = input()
    T_LEN = len(T)
    match_index = []

    for i in range(len(S) - T_LEN + 1):
        for idx in range(T_LEN):
            if S[i:i+T_LEN][idx] == T[idx] or S[i:i+T_LEN][idx] == "?":
                continue
            else:
                break
        else:
            match_index.append(i)
    
    if not match_index:
        print(No)
    
    else:
        answer = list(S)
        answer[match_index[0]:match_index[0] + T_LEN] = list(T)
        answer = "".join(answer)
        answer = answer.replace("?","a")

        if len(match_index) == 1:
            print(answer)

        else:
            for i in match_index[1:]:
                tmp_ans = list(S)
                tmp_ans[i:i + T_LEN] = list(T)
                tmp_ans = "".join(tmp_ans)
                tmp_ans = tmp_ans.replace("?","a")
                answer = min(tmp_ans,answer)

            print(answer)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
n,m,l=map(int,input().split())
inf=10000000000
g=[[inf for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])
r=[[inf for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j]<=l:
            r[i][j]=1
        elif g[i][j]>=inf:
            r[i][j]=inf
for k in range(n):
    for i in range(n):
        for j in range(n):
            r[i][j]=min(r[i][j],r[i][k]+r[k][j])
q=int(input())
for i in range(q):
    s,e=map(int,input().split())
    if r[s-1][e-1]>=inf:
        print(-1)
    else:
        print(r[s-1][e-1]-1)


Measured memory_bytes: 60632
def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum += c[i]*(d-last_d[i])
        
    return (score - sum)

def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    #print(c)

    #print(s)

    last_d = [0 for i in range(26)]
    
    ans = []
    
    score = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])):
                max = s[i][j] + c[j] * (i-last_d[j])
                idx = j
        last_d[idx] = i
        score += s[i][j]
        down_score(i+1,c,last_d,score)
        
        ans.append(idx)

    for i in range(D):
        print(ans[i]+1)

if __name__ == "__main__":
    main()

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

int main() {
  string s,t;  cin>>s>>t;
  int n=s.size();
  int ans=0;
  rep(i,n){
    if(s[i]!=t[i]){ans++;}
  }
  cout<<ans;
}

Measured memory_bytes: 3916
//https://atcoder.jp/contests/abc148/tasks/abc148_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N; cin>>N;
    vector<ll> an(N);    
    for(auto&& a:an){
        cin>>a;
    }
    ll c=1;
    ll ans=0;
    FOR(i,0,N){
        ll a=an.at(i);
        if(c==a){
            ++c;
        }else{
            ++ans;
        }
    }
    if(c==1)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

/*lld fac[500001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=500000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}
*/



lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k,m,g;
lld x,y,n1,a,b=0,n2,h,z,c;

void solve()
{
    cin>>n>>m;
    cout<<n*m;
        //cout<<"A";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
   //  getfac(p2);
    //check the value by which modulo is to be taken
    
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
                  solve();
    cout<<"\n";
    }
    return 0;
}

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


int N, M;

int main(){
    set<int> divisors;
    divisors.insert(1);

    cin >> N >> M;
    int M_orig = M;
    for(int p = 2; p * p <= M; p++){
        while(M % p == 0){
            M /= p;
            set<int> div_copy(divisors);
            for(set<int>::iterator itr = div_copy.begin(); itr != div_copy.end(); itr++){
                divisors.insert(p * (*itr));
            }
        }
    }
    set<int> div_copy(divisors);
    for(set<int>::iterator itr = div_copy.begin(); itr != div_copy.end(); itr++){
        divisors.insert(M * (*itr));
    }
    int ans = 1;
    for(auto itr = divisors.begin(); itr != divisors.end(); itr++){
        if(*itr <= M_orig/N){
            ans = max(ans, *itr);
        }
    }
    cout << ans << endl;
}
    


Measured memory_bytes: 384
def F(x,y):
    x = str(x)
    y = str(y)
    return max(len(x),len(y))
N = int(input())
fmin = 100
for x in range(1,int(N**0.5)+1):
    if N%x==0:
        y = N//x
        fmin = min(fmin,F(x,y))
print(fmin)

Measured memory_bytes: 65496
#include <iostream>
#include <map>
#include <queue>

using namespace std;

struct State {
  int city;
  int coins;
  long long time;

  bool operator<(const State& s) const {
    if (time != s.time) {
      return time > s.time;
    }
    if (coins != s.coins) {
      return coins < s.coins;
    }
    return city < s.city;
  }
};

map<State, long long> minimum;

void PushQueue(priority_queue<State>* que, const State& state) {
  State key = state;
  key.time = 0;
  map<State, long long>::iterator it = minimum.find(key);
  if (it != minimum.end() && it->second <= state.time) {
    return;
  }
  que->push(state);
  minimum[key] = state.time;
}

struct Edge {
  int V, A, B;
};

int C[50];
int D[50];

const int kMaxCoins = 50 * 100;

int main() {
  int N, M, S;
  cin >> N >> M >> S;

  vector<vector<Edge>> edges;
  edges.resize(N);
  for (int i = 0; i < M; ++i) {
    int U, V, A, B;
    cin >> U >> V >> A >> B;
    edges[U - 1].push_back(Edge{V - 1, A, B});
    edges[V - 1].push_back(Edge{U - 1, A, B});
  }

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

  State init;
  init.city = 0;
  init.coins = min(S, kMaxCoins);
  init.time = 0;

  priority_queue<State> que;
  que.push(init);

  while (!que.empty()) {
    State here = que.top();
    que.pop();

    // cout << "here: " << here.city << " " << here.coins << " " << here.time << endl;

    if (here.coins < kMaxCoins) {
      State there = here;
      there.coins += C[there.city];
      there.time += D[there.city];
      PushQueue(&que, there);
    }

    for (const Edge& e : edges[here.city]) {
      if (here.coins < e.A) {
        continue;
      }
      State there = here;
      there.city = e.V;
      there.coins -= e.A;
      there.time += e.B;
      PushQueue(&que, there);
    }
  }

  for (int i = 1; i < N; ++i) {
    long long ans = -1;
    for (int j = 0; j <= kMaxCoins; ++j) {
      map<State, long long>::iterator it = minimum.find(State{i, j, 0});
      if (it != minimum.end() && (ans == -1 || ans > it->second)) {
        ans = it->second;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 21428
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n;
lli arr[100000+5],dp[100000+5][2];
int main(){
    fastio;
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>arr[i];

    
    dp[1][0] = arr[1];
    dp[1][1] = -arr[1];
    for(int i = 2;i<n;i++){
        dp[i][0] = max(dp[i-1][0] + arr[i],dp[i-1][1] - arr[i]);
        dp[i][1] = max(dp[i-1][0] - arr[i],dp[i-1][1] + arr[i]);
    }
    dp[n][0] = max(dp[n-1][0] + arr[n],dp[n-1][1] - arr[n]);
    cout<<dp[n][0]<<endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <ll> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    vector <ll> fac(n + 1), inv(n + 1);
    fac[0] = inv[0] = fac[1] = inv[1] = 1;
    for (ll i = 2; i <= n; i++) {
        fac[i] = fac[i - 1] * i % MOD; // n!
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
    }

    // i番目の位置にいたスライムがjだけ移動する場合の数で考える
    ll ans = 0;
    for (int i = 1; i <= n - 2; i++) {
        ans = (ans + x[i] * i % MOD * inv[i + 1] % MOD) % MOD;
    }

    for (int i = 0; i <= n - 2; i++) {
        ans = (ans + MOD - x[i] * (n - i - 2) % MOD * inv[n - i - 1] % MOD) % MOD;
    }

    for (int i = 0; i < n - 1; i++) {
        ans = (ans + (x[n - 1] - x[i]) * inv[n - i - 1] % MOD) % MOD;
    }

    ans = ans * fac[n - 1] % MOD;

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace app01
{
    class Program
    {
        static void Main(string[] args)
        {
            string pass = Console.ReadLine();
            char[] cPass = pass.ToCharArray();
            bool flag = true;

            for (int i = 0; i < 3; i++)
            {
                if (cPass[i] == cPass[i + 1])
                {
                    flag = false;
                }
            }
            if (flag)
            {
                Console.WriteLine("Good");
            }
            else {
                Console.WriteLine("Bad");
            }

        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n  = sc.nextInt()
    val a=List.fill(n)(sc.nextInt())
    println(a.map(x=>f(x)).sum)
  }
  
  def f(n:Int):Int={
    if (n%2!=0){
      0
    }else{
      1+f(n/2)
    }
  }
}


Measured memory_bytes: 39508
def solve(N, Fs, Ps):
    profit = - 10 ** 10
    for k in range(1, 1025):
        b = "{:010b}".format(k)
        p = 0
        for P, F in zip(Ps, Fs):
           p += P[sum(F[i] * int(b[i]) for i in range(10))]
        profit = max(profit, p)
    return profit

if __name__ == "__main__":
    N = int(input())
    Fs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    Ps = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, Fs, Ps))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    int i;
	int n,m;
	cin>>n>>m;
	ll a[n+1],b[m+1];
	for (i = 1; i < n+1 ; i++) cin>>a[i];
	for (i = 1 ; i < m+1 ; i++) cin>>b[i];
	ll dp[n+1][m+1];
	for (i = 0; i < m+1; i++) dp[0][i] = 0;
	for (i = 0; i < n+1; i++) dp[i][0] = 0;
	for (i = 1; i < n+1 ; i++){
		for (int j = 1; j < m+1 ; j++){
			dp[i][j] = 0;
			if (a[i] == b[j]) dp[i][j] += dp[i-1][j-1]+1;
			dp[i][j] += dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
			dp[i][j] += mod;
			dp[i][j] %= mod;
			//cout<<i<<" "<<j<<" # "<<dp[i][j]<<"\n";
		}
	}
	cout<<(dp[n][m]+1)%mod<<"\n";
    return 0;
}


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

using namespace std;
vector<int> g[1001];
int main()
{
    for (int i = 0; i < 3; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int one, two;
    one = two = 0;
    for (int i = 1; i <= 4; i++) {
        if (g[i].size() == 1)
            one++;
        else if (g[i].size() == 2)
            two++;

    }
    if (one + two == 4)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


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

using namespace std;

using ull_t = unsigned long long;


char get(const string &S, ull_t K)
{
    const ull_t X = 5 * 1e12;

    for (auto &c : S)
    {
        if (c == '1')
        {
            if (--K == 0)
                return c;
        }
        else
            return c;
    }
    throw;
}


int main()
{
    string S;
    ull_t K;
    cin >> S >> K;
    cout << get(S, K) << endl;
}


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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        string S = cin.nextString();
        string T = cin.nextString();

        for (int i = 0; i < S.Length; i++)
        {
            bool flag = true;
            for (int j = 0; j < S.Length; j++)
            {
                if (T[j] != S[(i + j) % S.Length])
                {
                    flag = false;
                }
            }
            if (flag)
            {
                Console.WriteLine("Yes");
                return;
            }
        }

        Console.WriteLine("No");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

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

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    int ans = -1, mh = 1001001001;
    rep(i, n) cin >> h.at(i);

    rep(i, n) {
        int d = abs(1000 * a - (1000 * t - 6 * h.at(i)));
        if(mh > d) {
            ans = i;
            mh = d;
        }
    }

    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define _USE_MATH_DEFINES
using namespace std;

int main() {
	
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    int i,x,y,ans = 0;
    cin>>x>>y;
    if(y>=x*2&&y<=x*4&&(y%2==0)){
    	cout<<"Yes";
	}
	else cout<<"No";
	//cout<<ans+1;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int main(void) {
    std::ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    while(cin >> n >> a >> b) {
        if((b - a - 1) & 1) cout << "Alice" << endl;
        else cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int maxX = Integer.MIN_VALUE;
		int minY = Integer.MAX_VALUE;
		
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a > maxX) {
				maxX = a;
			}
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			if (a < minY) {
				minY = a;
			}
		}
		for (int i = -100; i <= 100; i++) {
			if (i > x && i > maxX && i <= y && i <= minY) {
				System.out.println("No War");
				return;
			}
		}
		System.out.println("War");
	}
	
	
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int MAXN = 100005;

int n, v[MAXN];

int main(){
	int i; LL a, b;
	scanf("%d", &n);
	for(i = 1; i <= n; ++ i)
		scanf("%d", &v[i]);
	a = b = 2;
	for(i = n; i; -- i){
		a = ((a - 1) / v[i] + 1) * v[i];
		b = (b / v[i] + 1) * v[i] - 1;
		if(a > b) break;
	}
	if(i) printf("-1\n");
	else printf("%lld %lld\n", a, b);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    char[] c = sc.next().toCharArray();
    int cnt = 1;
    for(int i=1;i<n;i++)if(c[i]!=c[i-1])cnt++;
    System.out.println(cnt);
  }
}

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

int main() {
    string n;
    cin>>n;
    if (n[0]==n[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

#define NMAX 1000

#define MAX(a, b) (a > b ? a : b)

using namespace std;

ifstream fin("f.in");
ofstream fout("f.out");

int n;
int weights[NMAX];
int partials[NMAX];
int minSum;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> weights[i];
        partials[i] = (i > 0 ? partials[i - 1] : 0) + weights[i];
    }
    minSum = partials[n - 1];
    for(int i = 0; i < n; i++)
    {
        int sum1 = partials[i];
        int sum2 = partials[n - 1] - partials[i];
        if(abs(sum1 - sum2) < minSum)
            minSum = abs(sum1 - sum2);
    }
    cout << minSum << '\n';
    return 0;
}


Measured memory_bytes: 256
//時刻tについて、移動→閉鎖→出現の順で進行。
//考察：
//i番目のユニットから移動を始めるj番目の人を考える。
//移動方法：左か右のどちらかへ移動。出口があれば速攻出る。(2通り、最大w回の移動)
//特徴：ユニットの出現が連続。j人目が脱出できる⇒j-1人目が脱出できる、が成り立つ。
//i番目のユニットから脱出できる人の数をjを2分探索することで求める。(関係ないけど、間違っても全員の移動2^(人数)を列挙してたら無駄)
//問題は、「どちらかに移動することで脱出できるか」を高速に求めることである。
//左側への移動の場合、i-1番目のユニットに来た時点で、i-1番目のユニットにおけるMaxjより時間が超過していれば脱出できない。それ以外は脱出できる。
//右側への移動の場合、i+1番目の(ry
//ということで、これは、ならしO(1)で求めることができる。
//全体でO(wlogMAX)
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;

int w;
int a[100000];
int lmax[100000];
int rmax[100000];

//左移動moveto = -1, 右移動moveto = 1
//ユニットiからスタート、j分目から移動開始。(これはj人目の行動)
bool canout(int i, int j, int moveto) {
	int k;
	int t = j;
	for( k = i; k >= 0 && k < w; k += moveto ) {
		if ( moveto > 0 && rmax[k] != -1 ) {
			if( rmax[k] - t >= 0 )
				return true;
			return false;
		}
		if ( moveto < 0 && lmax[k] != -1 ) {
			if( lmax[k] - t >= 0 )
				return true;
			return false;
		}
		
		if ( a[k] == 0 ) {
			return true;
		}
		if ( a[k] < 0 && t > -a[k] ) {
			return false;
		}
		t++;
	}
	return false;
}

int main() {
	int i;
	cin >> w;
	for( i = 0; i < w; i++ ) {
		cin >> a[i];
		lmax[i] = -1;
		rmax[i] = -1;
	}
	
	for( i = 0; i < w; i++ ) {
		if (a[i] > 0) {
			int st = 0, ed = 114514, medi;
			while( st <= ed ) {
				medi = st + ed;
				medi /= 2;
				if( canout(i, medi, -1) ) {
					if( !canout(i, medi+1, -1) )
						break;
					st = medi + 1;
				} else {
					ed = medi - 1;
				}
			}
			lmax[i] = medi;
		}
	}
	for( i = w-1; i >= 0; i-- ) {
		if (a[i] > 0) {
			int st = 0, ed = 114514, medi;
			while( st <= ed ) {
				medi = st + ed;
				medi /= 2;
				if( canout(i, medi, 1) ) {
					if( !canout(i, medi+1, 1) )
						break;
					st = medi + 1;
				} else {
					ed = medi - 1;
				}
			}
			rmax[i] = medi;
		}
	}
	
	int ans = 0;
	for( i = 0; i < w; i++ ) {
		ans += max(0, min( a[i] , max( lmax[i], rmax[i] )) );
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2332
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [list(map(int, sys.stdin.readline().split())) for _ in range(rows_number)]

def main():
    md=10**9+7
    n=int(input())
    aa=LLI(n)
    lov=[[] for _ in range(n)]
    for i,ar in enumerate(aa):
        for j,a in enumerate(ar):
            if a:lov[i].append(j)
    dp=[0]*(1<<n)
    dp[0]=1
    for s in range((1<<n)-1):
        pre=dp[s]
        if pre==0:continue
        i=bin(s).count("1")
        for j in lov[i]:
            if s>>j&1:continue
            ns=s|1<<j
            dp[ns]=(dp[ns]+pre)%md
    print(dp[-1])
    #print(dp)

main()

Measured memory_bytes: 59100
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 2e5 + 5 ; 
const int inf = 1e9 + 7 ; 
int n, m, c[N], w[N], tp[N], vis[N] ;
struct node {
	int a, b ;
} p[N] ;
struct Q {
	int l, r, id ; 
} q[N] ;
struct E {
	int to, next, id ; 
} e[N << 1] ;
int head[N], cnt, top, ans[N], idnum ; 
bool cmp( node x, node y ) {
	return x.a < y.a ; 
}
int check( int x ) {
	int l = 1, r = n + 1, ans = 0 ; 
	while( l <= r ) {
		int mid = ( l + r ) >> 1 ; 
		if( w[mid] >= x ) ans = mid, r = mid - 1 ; 
		else l = mid + 1 ; 
	} return ans ; 
}
int check2( int x ) {
	int l = 1, r = n, ans = 0 ; 
	while( l <= r ) {
		int mid = ( l + r ) >> 1 ; 
		if( w[mid] <= x ) ans = mid, l = mid + 1 ; 
		else r = mid - 1 ; 
	} return ans ; 
}
void add( int x, int y, int id ) {
	e[++ cnt] = (E){ y, head[x], id }, head[x] = cnt,
	e[++ cnt] = (E){ x, head[y], id }, head[y] = cnt ; 
}
int dfs( int x, int fa, int tt ) {
	int fl = 0 ; vis[x] = 1 ; 
	Next( i, x ) {
		int v = e[i].to ; if( vis[v] ) continue ; 
		fl ^= dfs( v, x, i ) ;
	}
	if( x == fa ) return fl ; 
	if( tp[x] ^ fl ) {
		ans[++ idnum] = e[tt].id ; 
		return 1 ; 
	}
	else return 0 ;
}
signed main()
{
	n = gi(), m = gi() ; 
	rep( i, 1, n ) p[i].a = gi(), p[i].b = gi() ; 
	sort( p + 1, p + n + 1, cmp ) ;
	rep( i, 1, n ) c[i] = p[i].b, w[i] = p[i].a ; 
	w[n + 1] = inf ; top = 0 ;
	rep( i, 1, m ) {
		int ll = gi(), rr = gi() ; 
		int l1 = check(ll), r1 = check2(rr) ;
		if( rr < ll ) continue ; 
		q[++ top].l = l1, q[top].r = r1, q[top].id = i ; 
	}
	rep( i, 1, n ) tp[i] = c[i] ^ c[i - 1] ; tp[0] = 0 ;
	rep( i, 1, top ) add( q[i].l, q[i].r + 1, q[i].id ) ;
	dfs( n + 1, n + 1, 0 ) ; int flag = 0 ;
	rep( i, 1, n ) {
		if( vis[i] ) continue ; 
		int u = dfs( i, i, 0 ) ;
		if( u != tp[i] ) flag = 1 ; 
	}
	if( flag ) puts("-1") ;
	else {
		printf("%d\n", idnum ) ;
		sort( ans + 1, ans + idnum + 1 ) ;
		rep( i, 1, idnum ) printf("%d ", ans[i] ) ;
	}
	return 0 ;
}

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

#define int long long

#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int mod = 1000000007;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int d, t, s; cin >> d >> t >> s;
	if (d <= t * s) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
s = input()
t = input()

s_map = [[] for i in range(26)]
t_map = [[] for i in range(26)]
n = len(s)

for i in range(n):
    si = ord(s[i]) - ord("a")
    ti = ord(t[i]) - ord("a")
    
    s_map[si].append(i)
    t_map[ti].append(i)

s_map = sorted(s_map)
t_map = sorted(t_map)

if s_map == t_map:
    print("Yes")
else:
    print("No")
# print(s_map)
# print(t_map)

Measured memory_bytes: 20732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		double x = 0, y = 0, r = 90;

		while (true) {
			String[] s = sc.nextLine().split(",");
			int a = Integer.parseInt(s[0]);
			int r2 = Integer.parseInt(s[1]);
			if (a == 0 && r2 == 0) break;
			x += a * Math.cos(Math.toRadians(r));
			y += a * Math.sin(Math.toRadians(r));
			r -= r2;
		}

		System.out.printf("%d\n%d\n", (int)x, (int)y);

	}

}

Measured memory_bytes: 17160
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
long long a[100010];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	long long pos=0,neg=0,ans,cnt=0;
	for(int i=0;i<k;i++){
		if(a[i]>0)pos+=a[i];
		else neg+=a[i];
	}
	for(int i=0;i<n;i++)if(a[i]>0)cnt+=a[i];
	ans=cnt+max(-pos,neg);
	for(int i=k;i<n;i++){
		if(a[i]>0)pos+=a[i];
		else neg+=a[i];
		if(a[i-k]>0)pos-=a[i-k];
		else neg-=a[i-k];
		ans=max(ans,cnt+max(-pos,neg));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long int A,B,N,X;
    cin>>A>>B>>N;
    if (N>=B) X=B-1;
    else X=N;
    X=(A*X)/B;
    cout<<X<<endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define int long long

signed main()
{
    int n;
    vector<string> s;
    map<string, int> s_count;

    cin >> n;

    s.resize(n);

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

    for(int i = 0; i < n; ++i)
    {
        sort(s[i].begin(), s[i].end());

        if(s_count.count(s[i]) == 0)
        {
            s_count[s[i]] = 1;
        }
        else
        {
            ++s_count[s[i]];
        }
    }

    int ans = 0;
    for(auto count : s_count)
    {
        ans += count.second * (count.second - 1) / 2LL;
    }

    cout << ans << endl;
}

Measured memory_bytes: 18176