akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private final int N;
    private final int M;
    private final int R;
    private final List<Integer> rList;
    private final int[][] dist;
    private final static int INF = 1000_000_000;

    public Main() {
	N = Integer.parseInt(scan.next());
	M = Integer.parseInt(scan.next());
	R = Integer.parseInt(scan.next());

	rList= new ArrayList<Integer>(R);
	for (int i = 0; i < R; i++) {
	    rList.add(Integer.parseInt(scan.next()) - 1);
	}

	dist = new int[N][N];
	for (int i = 0; i < N; i++) {
	    for (int j = 0; j < N; j++) {
		if(i == j) dist[i][j] = 0;
		else dist[i][j] = INF;
	    }
	}

	for (int i = 0; i < M; i++) {
	    int A = Integer.parseInt(scan.next()) - 1;
	    int B = Integer.parseInt(scan.next()) - 1;
	    int C = Integer.parseInt(scan.next());

	    dist[A][B] = dist[B][A] = C;
	}
	
	scan.close();
    }

    public final void answer() {

	for (int k = 0; k < N; k++) {
	    for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
		    dist[i][j] = Integer.min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	    }
	}

	int min = INF;
	List<List<Integer>> list = permutate(rList);

	for(List<Integer> item: list) {
	    int tmp = 0;
	    for (int i = 1; i < item.size(); i++) {
		tmp += dist[item.get(i-1)][item.get(i)];
	    }
	    if(tmp < min) min = tmp;
	}

	System.out.println(min);
    }

    private List<List<Integer>> permutate(List<Integer> list) {

	List<List<Integer>> result = new ArrayList<List<Integer>>();

	if(list.size() == 1) {
	    result.add(list);
	    return result;
	}

	for(Integer i: list) {
	    List<Integer> newList = new ArrayList<Integer>(list);
	    newList.remove(i);

	    List<List<Integer>> eachResult = permutate(newList);
	    for(List<Integer> item: eachResult) {
		item.add(0, i);
	    }

	    result.addAll(eachResult);
	}

	return result;
    }
}


Measured memory_bytes: 48028
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;

//powをとりつつmodをとる
const ll MOD = 1000000007;

ll mod_pow(ll x,ll n,ll mod){
  if(n==0)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
 
int main() {

    ll n;
    cin >> n;

    ll ans = 0;
    ans += mod_pow(10,n,MOD) + mod_pow(8,n,MOD) - (2*mod_pow(9,n,MOD));

    ans = ans%MOD;
    if(ans<0)   ans += MOD;
    cout<<ans<<endl;
    
 return 0;
}


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

int main () {
  long long H;
  cin >> H;
  long long ans = 0;
  long long count = 1;
  while(H > 0){
    ans += count;
    H /= 2;
    count *= 2;
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a1 ,b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a7, b7; 
    cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3 >> a4 >> b4 >> a5 >> b5 >> a6 >> b6 >> a7 >> b7;
    cout << a1-b1 << endl << a2-b2 << endl << a3-b3 << endl << a4-b4 << endl << a5-b5 << endl << a6-b6 << endl << a7-b7 <<endl;
    
    
}



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

#define In inline
#define St static
#define Op operator
#define Ct continue
#define Rg register
#define Re return
#define inc(l, i, r) for(Rg int i=l; i<r; ++i)
#define dec(l, i, r) for(Rg int i=r; i>l; --i)
#define mP make_pair
#define fst first
#define snd second

typedef long long ll;

const int mxN=1<<20;

int cnt, n;
pair<int*, int> tag[mxN<<2];

struct BIT
{
    int b[mxN];
    In void add(int i, int x)
    {
        for(; i<=n+1; i+=i&-i)
            if(b[i]<x)
                tag[cnt++]=mP(b+i, b[i]), b[i]=x;
    }
    In int sum(int i)
    {
        Rg int r=-1e9;
        for(; i; i-=i&-i)
            r=max(r, b[i]);
        Re r;
    }
} t0, t1;

In bool chk(int i, int s)
{
    if(s<0) Re 0;
    if(s&1) Re t1.sum(i)>=s;
    Re t0.sum(i)>=s;
}

int main()
{
    St int p[mxN], v[mxN], l[mxN];
    scanf("%d", &n);
    inc(0, i, n)
    {
        scanf("%d", p+i);
        p[i]=n+1-p[i];
    }
    Rg int mn=1e9, Q=0;
    inc(0, i, n)
    {
        mn=min(mn, p[i]);
        v[i]=1+(mn==p[i]);
        Q+=(mn==p[i]);
    }
    memset(t1.b, 0x9f, sizeof t1.b);
    dec(-1, i, n-1)
    {
        Rg int v0=t0.sum(p[i]), v1=t1.sum(p[i]);
        if(v[i]==1)
            t0.add(p[i], v1+1), t1.add(p[i], v0+1);
        else
            t0.add(p[i], v0+2), t1.add(p[i], v1+2);
        l[i]=cnt;
    }
    if(!chk(n+1, Q))
    {
        puts("-1");
        Re 0;
    }
    Rg int cx=0, cy=0, hx=n+1, hy=n+1;
    inc(0, i, n)
    {
        Q-=(v[i]==2);
        for(; cnt>l[i+1]; *tag[cnt].fst=tag[cnt].snd)
            --cnt;
        Rg int dx=hx>p[i], h1=min(hx, p[i]);
        if(chk(hy, cx+dx-cy+Q) || chk(h1, cy-cx-dx+Q))
            cx+=dx, hx=h1, putchar('0');
        else
            cy+=hy>p[i], hy=min(hy, p[i]), putchar('1');
    }
    puts("");
    Re 0;
}


Measured memory_bytes: 72064
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 100001
#define INFTY 10000000
 
typedef struct{
  int prev;
  int next;
  int cost;
} Edge;
 
Edge G[500000];
int d[MAX];
 
void Dijkstra(int,int);
 
int main(void){
  int i, j, k, n, v, u, c;
  int count=0;
 
  scanf("%d", &n);
  //G = (int*)malloc(sizeof(int)*n);
 
  /*for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      G[i][j] = INFTY;
    }
    }*/
 
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      G[count].prev = u;
      scanf("%d%d", &G[count].next, &G[count].cost);
      count++;
    }
  }
 
  Dijkstra(n,count);
 
  //free(G);
 
  return 0;
}
 
void Dijkstra(int n, int count){
  int i, min = 1;
  int d[MAX];
 
  d[0] = 0;
  for(i=1; i<n; i++){
    d[i] = INFTY;
  }
 
  while(min != 0){
    min = 0;
 
    /*for(i=0; i<n; i++){
      if(c[i] != 1 && d[i] < min){
        j = i;
        min = d[i];
      }
      }*/
 
    //if(min == INFTY) break;
 
    for(i=0; i<count; i++){
      if(d[G[i].prev] + G[i].cost < d[G[i].next]){
        d[G[i].next] = d[G[i].prev] + G[i].cost;
        min = 1;
      }
    }
  }
 
  for(i=0; i<n; i++) printf("%d %d\n", i, d[i]);
 
  return;
}

Measured memory_bytes: 6464
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2<<17;
int n;ll a[N],b[N],ans;
main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);
	for(int t=0;t<500;t++)
		for(int i=t&1;i<n;i+=2)
		{
			ll s=b[(i+n-1)%n]+b[(i+1)%n];
			ll t=(b[i]-a[i])/s;
			ans+=t;
			b[i]-=t*s;
		}
	for(int i=0;i<n;i++)
		if(a[i]!=b[i])
		{
			puts("-1");
			return 0;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int main( void ) {

    int N;
    cin >> N;

    bool flag = false;

    while ( N > 0 ) {
        if ( N % 4 == 0 || N % 7 == 0 ) {
            flag = true;
            break;
        }
        N -= 7;
    }

    if ( flag ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順


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

	int ans = n*(n-1)/2;
	ans += m*(m-1)/2;
	cout << ans << endl;
  return 0;
}


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

long long n,a,b,c,d;
long long INF = 1e18;
map<long long, long long> mp;

long long dfs(long long now){
  if(now<=0) return 1e15;
  if(mp[now]!=0) return mp[now];

  long long a1=INF,a2=INF,b1=INF,b2=INF,c1=INF,c2=INF,x=INF;

  if(now < INF/d) x = now*d;

  if(now%2==0) a1 = a+dfs(now/2);
  else a2 = a+d+min(dfs((now-1)/2), dfs((now+1)/2));

  if(now%3==0) b1 = b+dfs(now/3);
  else b2 = min(b+d*(now-now/3*3)+dfs(now/3), b+d*(now/3*3+3-now)+dfs(now/3+1));

  if(now%5==0) c1 = c+dfs(now/5);
  else c2 = min(c+d*(now-now/5*5)+dfs(now/5), c+d*(now/5*5+5-now)+dfs(now/5+1));

  return mp[now] = min({x,a1,a2,b1,b2,c1,c2});
}

int main(){
  int t;
  cin >> t;
  vector<long long> anss(t);
  for (int i = 0; i < t; i++)
  {
    mp = map<long long, long long>();
    cin >> n >> a >> b >> c >> d;
    mp[1] = d;
    long long ans = dfs(n);
    anss[i] = ans;
  }
  for (int i = 0; i < t; i++) cout << anss[i] << endl;
}

Measured memory_bytes: 4436
#include<bits/stdc++.h>
#define ll long long
const int N=1e9+5;
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	vector<ll>a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	ll dp[n];
  	memset(dp,N,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<n;i++){
      	for(int j=1;j<=k;j++){
        if(i>=j)
		dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

double solve(int n, std::vector<double> values)
{
  std::sort(values.begin(), values.end());

  while (values.size() >= 2) {
    const auto sum = (values[0] + values[1]) / 2.0;
    values.erase(values.begin(), values.begin() + 2);
    const auto lb = std::lower_bound(values.begin(), values.end(), sum);
    values.insert(lb, sum);
  }

  return values.front();
}

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

  std::vector<double> values(n);
  for (auto& v : values) {
    std::cin >> v;
  }

  std::cout << solve(n, values) << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
  int a,b,max;
  scanf("%d %d",&a,&b);
  max = a + b;
  if (a - b > max)
    max = a - b;
  if (a * b > max)
    max = a * b;
  printf("%d\n",max);
  return (0);
}


Measured memory_bytes: 128
n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in range(1<<(m+n)):
  a=[1]
  for j in range(m+n):
    if (i>>j)&1:a[-1]+=1
    else:a+=[a[-1]]
    if a[-1]>m:
      flag=0
      break
    if len(a)>n:
      flag=1
      break
  else:flag=1
  if flag==0 or len(a)<n:continue
  cnt=0
  for s,t,u,v in e:
    if a[t-1]-a[s-1]==u:cnt+=v
  ans=max(ans,cnt)
print(ans)

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

int main(){
	int x[3000],y[3000],a=0;
	do{
		cin>>x[a]>>y[a];
		a++;
	}while(x[a-1]>0||y[a-1]>0);
	for(int b=0;b+1<a;b++){
		if(x[b]<y[b]) cout<<x[b]<<' '<<y[b]<<endl;
		else cout<<y[b]<<' '<<x[b]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main()
{
  int n, k;
  cin >> n >> k;
  int d;
  int a;
  int s[n];
  for(int i = 0;i<n;++i) s[i] = 0;
  for(int i = 0;i<n;++i){
    cin >> d;
    for(int j = 0;j<d;++j){
      cin >> a;
      s[a-1]++;
    }
  }
  int c = 0;
  for(int i = 0;i<n;++i){
    if(s[i]==0) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}


int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    pr(min(b/a,c));
    
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
    int n;
    cin>>n;
    int k=2;
    while(1){
		if(k==n){
			cout<<k<<endl;
			break;
		}else if(k>n){
			cout<<k/2<<endl;
			break;
		}
		k=k*2;
    }

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int count = 0;

int binary_search( int A[], int n,  int key ){

    int left, right, j;

    int origin = 0;

    left = 0;
    right = n;

    while( left < right ){

        j = ( left + right ) / 2;

        if( A[j] == key ) return 1;

        else if ( A[j] > key ) right = j;

        else left = j + 1;

    }

    return 0;

}


int main(){

    int i, n, count;

    scanf("%d", &n);

    int S[n];

    for( i = 0 ; i < n ; i++ ){

        scanf("%d", &S[i]);

    }

    int m;

    scanf("%d", &m);

    int key;

    count = 0;

    for( i = 0; i < m ; i++){

        scanf("%d", &key);

        count += binary_search( S, n, key);

    }

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

}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define cl(x,a) memset(x,a,sizeof(x))
#define all(x) x.bein(),x.end()
#define INF 0x3f3f3f3f
#define EPS 1e-8
#define S 3 //矩阵大小
#define MAXN (ll)1000000000000000000
using namespace std;
typedef unsigned long long ll;
typedef unsigned long long LL;
int main()
{
    ios::sync_with_stdio(false);
    ll x, y;
    while(cin>>x>>y){
        LL lcm = x / __gcd(x, y) * y;
        LL k = lcm / x;
        if(k > 2)
            cout<< x * (k - 1)<<endl;
        else if(k==1) cout<<-1<<endl;
        else cout<< x*(k+1)<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
n=int(input())
patt=[-1]*100
l=0
for i in range(n):
    a,b=[int(x) for x in input().split(' ')]
    if a==b:
        l+=1
        patt[i]=1
count=0
flag=0
for i in range(100):
    if patt[i]==1:
        count+=1
    else:
        count=0
    if count==3:
        flag=1
        break
if flag==1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 62360
#include<bits/stdc++.h>
using namespace std;
long long n,a[10],ans=1000000000,target1,target2,target3,ans1,ans2,ans3;
void DFS(int i,int sum1,int sum2,int sum3,int cost){
    if(i>n){
        if((ans>abs(target1-sum1)+abs(target2-sum2)+abs(target3-sum3)+cost)&&(sum1!=0&&sum2!=0&&sum3!=0)){
            ans=abs(target1-sum1)+abs(target2-sum2)+abs(target3-sum3)+cost;
            ans1=sum1;
            ans2=sum2;
            ans3=sum3;
        }
    }
    else{
        DFS(i+1,sum1,sum2,sum3,cost);
        DFS(i+1,sum1+a[i],sum2,sum3,cost+10);
        DFS(i+1,sum1,sum2+a[i],sum3,cost+10);
        DFS(i+1,sum1,sum2,sum3+a[i],cost+10);
    }
}

int main(){
    cin>>n>>target1>>target2>>target3;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    DFS(1,0,0,0,0);
    cout<<ans-30;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define MAX 100000

int getGCD(int a,int b){
	if(b == 0)return a;
	
	if(a % b==0)return b;
	
	int r=a%b;
	
	return getGCD(b,r);
	
}

void factoring(int x){
	int idx=0;
	int b[MAX];
	
	for(int i=1;i<=sqrt(x);i++){
		if(x % i==0){
			b[idx++]=i;
			printf("%d\n",i);
		}
	}
	for(int i=idx-1;i>=0;i--){
		if(b[i]==sqrt(x))continue;
		printf("%d\n",x/b[i]);
	}
	
	return;
}

int main(){
	int n;
	int a[3]={0};
	int gcd1,gcd2,gcd3;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	gcd1=getGCD(a[0],a[1]);
	gcd2=getGCD(a[1],a[2]);
	gcd3=getGCD(gcd1,gcd2);
	
	factoring(gcd3);
	
	return 0;
	
}


Measured memory_bytes: 2036
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
A = lma()
r= 1
l = 0
ans = 0
xorA = A[0]
sumA = A[0]

for l in range(n):
    while r<=n-1:
        if l==r:
            r+=1
            sumA = A[l]
            xorA = A[l]
            continue
        if xorA^A[r] == sumA + A[r]:
            xorA ^= A[r]
            sumA +=A[r]
            r+=1
        else:
            xorA ^= A[l]
            sumA -=A[l]
            break
    ans+=r-l

print(ans)


Measured memory_bytes: 33552
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    set<int> st;
    for(int i=1;i<n;i++){
        st.insert(i);
    }
    int k=1;
    int pr=-1;
    set<int> check;
    while(k<=m){
        int v=*rbegin(st);
        st.erase(v);
        while(pr-v==1||check.count(n-v)||2*v==n){
            v=*rbegin(st);
            st.erase(v);
        }
        pr=v;
        check.insert(v);
        printf("%d %d\n",k,k+v);
        k++;
    }
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int cnt = 0;
  
  for(int i = a; i <= b; i++){
    string s = std::to_string(i);
    string s2 = s;
    reverse(s2.begin(), s2.end());
    
    if(s == s2){
      cnt++;
    }
  }
  cout << cnt << endl;
  
}


Measured memory_bytes: 256
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var s = t.ConvertIntList(t.ReadInput());
            if(s [0] < s[1] && s[1] < s[2])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
           
        }


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


        public List<int> ConvertIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }
}
}


Measured memory_bytes: 15988
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;

const int ms = 200005;

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    for (int i = 0; i < len; ++i)
    {
        if ((i & 1)==0)
        {
            if (s[i] != 'R'&&s[i] != 'U'&&s[i] != 'D')
            {
                cout << "No";
                return 0;
            }
        }
        else
        {
            if (s[i] != 'L'&&s[i] != 'U'&&s[i] != 'D')
            {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_L 10005
int N,K,T,L;
int A[MAX_L];
double U,V;

int main(){
  cin>>N>>K>>T>>U>>V>>L;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a]=1;
  }

  
  int p=0,cnt=0,cost=0,costb=0;
  for(int i=0;i<L;i++){
    
    cnt+=A[i];
    
    if(i>=p){
      if(cnt>0){
        cnt--;
        int d=T*V;
        d=min(d,L-i);
        p=i+d;
        costb++;
      }else{
        cost++;
      }
    }else{
      costb++;
    }
    
    if(cnt>K){
      int d=T*V;
      d=min(d,L-i);
      p=i+d;
    }
    
    cnt=min(cnt,K);
  }
  

  printf("%.8f\n",cost/U+costb/V);
  return 0;
}

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

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  //  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
    if ( size > 1000000 ) { printf("error"); }
  }

  
  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define chmax(a,x) a=max(a,x)

vector<bool> F[5];

bool eraser(int idx) {
  rep(i, 5) {
    if((int)F[i].size() <= idx) { return false; }
    if(!F[i][idx]) { return false; }
  }
  rep(i, 5) F[i].erase(F[i].begin()+idx);
  rep(i, 5) {
    while(1) {
      if(!F[i].empty() && !F[i].back()) { F[i].pop_back(); }
      else { break; }
    }
  }
  return true;
}

int main() {
  
  for(int N; cin>>N && N;) {
    rep(i, 5) F[i].clear();
    rep(i, N) {
      int type, len, pos; cin >> type >> len >> pos; pos --;
      if(type == 1) {
        int mx = -1;
        REP(i, pos, pos+len) { chmax(mx, int(F[i].size())); }
        REP(i, pos, pos+len) {
          REP(j, F[i].size(), mx) {
            F[i].push_back(false);
          }
          F[i].push_back(true);
        }
        eraser(mx);
      }
      else {
        rep(i, len) { F[pos].push_back(true); }
        int cnt = 0;
        rep(i, len) { if(!eraser((int)F[pos].size()-1-cnt)) cnt++; }
      }
    }
    int sum = 0;
    rep(i, 5) rep(j, F[i].size()) sum += F[i][j];
    cout << sum << endl;
  }
  return 0;
}

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

int main(){
  string s,t;
  cin>>s>>t;
  int ls = s.size();
  int lt = t.size();
  
  vector<vector<int>> dp(ls+1,vector<int>(lt+1));
  rep(i,ls){
    rep(j,lt){
      if(s[i]==t[j]){
        dp[i+1][j+1] = dp[i][j]+1;        
      }else{
        dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
      }      
    }
  }
  
  int p = ls, q = lt;
  string ans;
  while(p>0 && q>0){
    if(dp[p][q] == dp[p-1][q]) p--;
    else if(dp[p][q] == dp[p][q-1]) q--;
    else{
      p--; q--;
      ans = s[p] + ans;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 35584
#include <stdio.h>

#define N 100
#define INFTY (1<<21)
#define white 0
#define gray 1
#define black 2
int enq(int);
int deq(void);
void bfs(int);

int n,M[N][N],d[N],Q[N],head,tail;

int main(){
  int u,k,v,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  
  return 0;
}
void bfs(int s){
    int i,v,u;
    char color[N];
  for(i=0;i<n;i++){
      color[i]=white;
      d[i]=INFTY;
  }
  color[s]=gray;
  d[s]=0;
  enq(s);
  while(1){
      if(head==tail)break;
      u=deq();
      for(v=0;v<n;v++){
          if(M[u][v]&&color[v]==white){
              color[v]=gray;
              d[v]=d[u]+1;
              enq(v);
          }
      }
      color[u]=black;
  }
for(i=0;i<n;i++){
    printf("%d ",i+1);
    if(d[i]==INFTY)printf("-1");
    else printf("%d",d[i]);
    printf("\n");
}
}
int enq(int x){
  
  Q[tail]=x;
  tail=(tail+1)%N;
  return x;
}
int deq(){
  int x;
  
  x=Q[head];
  head=(head+1)%N;
  return x;
}



Measured memory_bytes: 2084
import bisect
N, M = map(int,input().split())
P = []
Y = []
B = [[] for _ in range(N)]
for _ in range(M):
    p, y = map(int,input().split())
    P.append(p)
    Y.append(y)
    B[p-1].append(y)

for i in range(N):
    B[i].sort()

for p, y in zip(P, Y):
    print("{:06}{:06}".format(p, bisect.bisect_left(B[p-1], y) + 1))






Measured memory_bytes: 24048
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int sum = 0;
	sum += min(a, b) + min(c, d);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ma 1e9

int main(){
  int n,k;cin>>n>>k;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  
  vector<int> ans(n,ma);
  ans[0]=0;
  for(int i=0;i<n-1;i++){
    for(int j=1;j<=k;j++){
      if(i+j==n)break;
      ans[i+j]=min(ans[i+j],abs(h[i]-h[i+j])+ans[i]);
    }
  }
  
  cout<<ans[n-1]<<endl;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; ++i) cin >> d[i];
    sort(d.begin(), d.end(), greater<int>());
    int count = 0;
    int cache = 1000;
    for(auto hoge : d) {
        if(cache > hoge)count++;
        cache = hoge;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)       (((a) > (b)) ? (a) : (b))               /* ２個の値の最大値 */
#define min(a, b)       (((a) < (b)) ? (a) : (b))               /* ２個の値の最小値 */
#define ENTER           printf("\n")                                    /* 改行プリント */
int DBG = 1;                                                                            /* デバッグプリント 提出時は0
 */
/* main *************************************************************/
int main()
{
        int             a,b,c,i,j,k,n,m,x,y,ans = 0;
        char    str[256];

        scanf("%d %d", &a, &b);
        printf("%d\n", abs(a-b));


        return 0;
}



Measured memory_bytes: 2076
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

double dp[3001][3001];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    dp[0][0]=1;
    int i,j;
    for(i=1; i<=n; i++) {
        double p;
        scanf("%lf", &p);
        for(j=0; j<=i; j++) {
            dp[i][j] = dp[i-1][j]*(1-p);
            if(j>0) dp[i][j] += dp[i-1][j-1] * p;
        }
    }

    double ans=0;
    for(i=n/2+1; i<=n; i++) {
        ans += dp[n][i];
    }
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 68864
#include <stdio.h>

int mat (int,int);

int main(){

  int x,y,z;

  scanf("%d%d",&x,&y);

  if(x > y)  z = mat(x,y);
  else  z = mat(y,x);

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

int mat (int a , int b){
  int c;

 while(1){
  c = a%b;
  if(c == 0) break;
  a = b;
  b = c;
 }
 
 return b;

}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int n;
cin>>n;
ll h[n];
for(ll i=0;i<n;i++)cin>>h[i];
ll max=0,count=0;
for(ll i=0;i<n;i++)
{
    if(h[i]>=h[i+1])
    {
        count++;
    }
    else
    {
        if(count>max)
        {
            max=count;
        }
    count=0;
    }
    
}
cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 1024
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
6.long double | 输出浮点数
7.注意特判!(prince and princess)
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
using namespace std;
const LL INF=10000000000000000;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL tree[800000+80];
int n,treen,m;
struct seg{
	int li,ri,ci;
}each[100000+10];
LL dp[100000+10];
bool cmp(seg A,seg B){
	return A.li<B.li;
}
void change(int now,LL val){
	now+=treen-1;
	tree[now]=min(tree[now],val);
	now>>=1;
	while(now){
		tree[now]=min(tree[now<<1],tree[(now<<1)+1]);
		now>>=1;
	}
}
LL query(int now,int l,int r,int a,int b){
	if(l>=b||r<=a) return INF;
	if(r<=b&&l>=a) return tree[now];
	int mid=(l+r)>>1;
	return min(query(now<<1,l,mid,a,b),query((now<<1)+1,mid,r,a,b));
}
int main(){
	memset(tree,0x3f,sizeof(tree));
	cin>>n>>m;
	rb(i,1,m) scanf("%d %d %d",&each[i].li,&each[i].ri,&each[i].ci);
	treen=1<<(int(ceil(log2(double(n)))));
	sort(each+1,each+1+m,cmp);
	rb(i,1,m){
		if(each[i].li==1){
			dp[i]=each[i].ci;
			change(each[i].ri,dp[i]);
		}
		else{
			dp[i]=query(1,1,treen+1,each[i].li,each[i].ri)+each[i].ci;
			change(each[i].ri,dp[i]);
		}
	}
	LL res=(LL)100000*(LL)1000000000+100000;
	rb(i,1,m){
//		cout<<each[i].
		if(each[i].ri==n){
			res=min(res,dp[i]);
		}
	}
	if(res>(LL)100000*(LL)1000000000){
		res=-1;
	}
	cout<<res<<endl;
	return 0;
}


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

int main() {
  int X, Y, Z; cin >> X >> Y >> Z;
  
  int ans = X / (Y+Z);
  if (X % (Y+Z) == 0 || X%(Y+Z) < Z) cout << ans-1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main () {
  ll n, x;
  cin >> n >> x;
  vector<int> l(n);
  rep(i, n) cin >> l.at(i);
  ll pnt, cnt;
  rep(i, n){
    pnt+=l.at(i);
      if(pnt>x) {
        cnt=i;
        break;
      }
    else{
    }
  }
  if(cnt != 0) cout << cnt+1 << endl;
  else cout << n+1 << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	cin >> N;
	vector<int>a(N);
	vector<int>b(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> M;
		b[M]++;
	}
	bool flag = true;
	for (int i = 1; i <= N; i++) {
		if (b[i] != 1) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	vector< int > g(N + 1);
	vector< int > f(N + 1);
	for (int i = 1; i <= N; i++) {
		if (b[i]) {
			f[i] = 1;
			g[i] = 1;
		}
		else {
			f[i] = 1;
			g[i] = 2;
		}
	}
	for (int i = 0; i < N; i++) {
		if (i) {
			cout << " ";
		}
		cout << f[a[i]];
	}
	cout << endl;
	for (int i = 0; i < N; i++) {
		if (i) {
			cout << " ";
		}
		cout << g[a[i]];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 4428
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)
#pragma warning (disable:4996)

using namespace std;
typedef long long int lint;


//***** Main Program *****

int main() {
	map<string, bool> mp;
	int n;
	cin >> n;
	Loop(i, n) {
		char query[10];
		string word;
		scanf("%s", query);
		cin >> word;
		if(query[0]=='i'){
			mp[word] = true;
		}
		else {
			if (mp[word]) printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 52560
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 9 || b >= 9)cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

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

/**
 * @author AnonymousP
 * @__WHEN YOU FEEL LIKE QUITTING, THINK ABOUT WHY YOU STARTED__@
 */
//COMBINATON = nCr = n*(n-1)/2
public class Main{

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        String s = sc.next();
        int ans = 0;
        /*
         i=======j
         0 ----> 1,2,3 (3-0)
         1 ----> 2,3   (3-1)
         2 ----> 3     (3-2)
         (s.length()-i)
        
         s.length()==4
         i<3(s.length()-1)
         j<s.length()-i
        
        
         */
        for (int i = 0; i < s.length() - 1; i++) {
            for (int j = 1; j < s.length() - i; j++) {
                //    System.out.println(i+" "+(j));
                //HAVE A LOOK HERE COMMMENT LINE//
                //    System.out.println(i+" "+(i+j));

                if (s.charAt(i) == s.charAt(i + j)) {
                    ans++;
                }
            }
        }
        if (ans == 2) {
            out.println("Yes");
            out.flush();
        } else {
            out.println("No");
            out.flush();
        }
    }

    //************************************************************************//
//CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_CLASS_//
//*******FAST IO*************FAST IO***************FAST IO****************//
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

   //*******FAST IO*************FAST IO***************FAST IO****************//
}


Measured memory_bytes: 32628
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
-- end of templete


main = length . filter (applyUni (==) reverse) . lines <$> getContents >>= print

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

int power(long long x,long long n,long long M){
    long long res=1;
    if(n>0){
        res=power(x,n/2,M);
        if(n%2==0){
            res=(res*res)%M;
        }
        else{
            res=(res*res)%M*x%M;
        }
    }
    return res;
}

int main(){
    int n,m;
    cin>>n>>m;
    cout<<power(n,m,1000000007)<<endl;
}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, x;
  cin >> n >> x;
  vector< int > l(n);
  for (int i=0; i<n; ++i) cin >> l[i];
  int ans = 1;
  int cur = 0;
  for (int i=0; i<n; ++i) {
    if (cur+l[i] > x) break;
    ans++;
    cur+=l[i];
  }
  cout << ans << endl;
  return 0;
}


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

struct st { int a, b, c; };
bool used[100000];
int main() {
	int r, c, n; scanf("%d%d%d", &r, &c, &n);
	vector<st>v;
	rep(i, n) {
		int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if ((x1 == 0 || x1 == r || y1 == 0 || y1 == c) && (x2 == 0 || x2 == r || y2 == 0 || y2 == c)) {
			v.push_back({ x1,y1,i }); v.push_back({ x2,y2,i });
		}
	}
	sort(v.begin(), v.end(), [&](st&a, st&b) {
		if (a.b == 0) {
			if (b.b == 0)return a.a < b.a;
			return true;
		}
		if (a.a == r) {
			if (b.b == 0)return false;
			if (b.a == r)return a.b < b.b;
			return true;
		}
		if (a.b == c) {
			if (b.b == 0 || b.a == r)return false;
			if (b.b == c)return a.a > b.a;
			return true;
		}
		if (b.b == 0 || b.a == r || b.b == c)return false;
		return a.b > b.b;
	});
	stack<int>s;
	for (st&p : v) {
		if (!used[p.c]) {
			used[p.c] = true; s.push(p.c);
		}
		else {
			if (s.empty() || s.top() != p.c) {
				puts("NO"); return 0;
			}
			s.pop();
		}
	}
	puts("YES");
}

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

ls, lt = len(s), len(t)
min_diff = 1000

for i in range(0, ls-lt+1):
	subs = s[i:i+lt]
	diff = lambda x, y: sum([1 if char1 != char2 else 0 for char1, char2 in zip(x, y)])
	min_diff = min(min_diff, diff(subs, t))

print(min_diff)


Measured memory_bytes: 9124
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if i!=n-1:
            if s_[i+1]=="AC" and c==0 and a==1:
                a,b,ans=(a+1,b-1,ans+"A")
            elif s_[i+1]=="BC" and c==0 and b==1:
                a,b,ans=(a-1,b+1,ans+"B")
            else:
                a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        else:
            a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if i!=n-1:
            if s_[i+1]=="AB" and b==0 and a==1:
                a,c,ans=(a+1,c-1,ans+"A")
            elif s_[i+1]=="BC" and b==0 and c==1:
                a,c,ans=(a-1,c+1,ans+"C")
            else:
                a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        else:
            a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        if min(a,c)==-1:
            print("No")
            break
    else:
        if i!=n-1:
            if s_[i+1]=="AB" and a==0 and b==1:
                b,c,ans=(b+1,c-1,ans+"B")
            elif s_[i+1]=="AC" and a==0 and c==1:
                b,c,ans=(b-1,c+1,ans+"C")
            else:
                b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        else:
            b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])



Measured memory_bytes: 16452
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    string S,T,U;
    ll A,B;
    cin >> S >> T >> A >> B >> U;
    if(S == U){
        A--;
    }
    else if(T == U)
    {
        B--;
    }
    cout << A << ' ' << B << endl;

    return 0;    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long a,b;
    string s="Negative";
    cin>>a>>b;
    if(a*b<=0)s="Zero";
    else if(a>0)s="Positive";
    else if(b>0&&(-a)%2==0)s="Positive";
    else if((a-b+1)%2==0)s="Positive";
    
    cout<<s<<endl;
}


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

using namespace std;
#define ll long long

#define mod 1000000007

ll dp[10005][105][2], d;
string s;


ll solve(ll pos, ll modi, bool tight){
	//base case
	if(pos == s.length()){
		return modi==0;
	}
	//recursive case
	if(dp[pos][modi][tight]!=-1){return dp[pos][modi][tight];}

	ll ans=0;
	ll end= (tight)?(s[pos]-'0'):9;
	for(ll i=0; i<=end; i++){
		ll t = (solve(pos+1, (modi+i)%d, tight&(i==end)))%mod;
		ans += t;
		ans %= mod;
	}
	return dp[pos][modi][tight] = ans;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	memset(dp, -1, sizeof(dp));
	cin>>s;
	cin>>d;
	cout<<(solve(0, 0, 1)-1+mod)%mod;
}

Measured memory_bytes: 17664
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;

int N, M;
int X[100000], Y[100000], Z;
    
int parent[100000];

int root_of(int v){
    if(parent[v] == -1){
        return v;
    }else{
        int ret = root_of(parent[v]);
        parent[v] = ret;
        return ret;
    }
}

int main(void) {
    
    scanf("%d %d", &N, &M);
    for(int i=0;i<N;i++){
        parent[i] = -1;
    }
    for(int i=0;i<M;i++){
        scanf("%d %d %d", &X[i], &Y[i], &Z);
        /*Y[i]-1の親をX[i]-1にする*/
        if(root_of(X[i]-1) != root_of(Y[i]-1)){
            parent[root_of(Y[i]-1)] = X[i]-1;
        }
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        if(parent[i] == -1){
            ans += 1;
        }
        //printf("%d\n", parent[i]);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1280
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long A, B, C;
    scan(A, B, C);
    bool[long] b;
    long n = A;
    b[A % B] = true;
    while (true)
    {
        if (C in b)
        {
            writeln("YES");
            return;
        }
        n += A;
        n %= B;
        if (n in b)
        {
            writeln("NO");
            return;
        }
        b[n] = true;
    }
}


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

//left is greater
void swp(int* i, int* j){
  if(*i < *j){
    int tmp = *i;
    *i = *j;
    *j = tmp;
  }
}

int main(void){
  int n1, n2;
  while(cin >> n1 >> n2){
    swp(&n1, &n2);
    while(n2 > 0){
      n1 = n1 % n2;
      swap(n1, n2);
    }
    cout << n1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
n, k, c = map(int, input().split())
S = list(input())
rS = S[::-1]
lcnt = 0
left = [0] * n
rcnt = 0
right = [0] * n
llimit = -1
rlimit = -1
for i in range(n):
    if S[i] == "o" and llimit < i:
        lcnt += 1
        left[i] = lcnt
        llimit = i + c
    if rS[i] == "o" and rlimit < i:
        rcnt += 1
        right[-(i + 1)] = k + 1 - rcnt
        rlimit = i + c
for i in range(n):
    if left[i] == right[i] and left[i] > 0:
        print(i + 1)


Measured memory_bytes: 23552
#include<stdio.h>

int main(void){

  int a=0, b=0, k=0;
  int i=0;

  scanf("%d %d %d", &a, &b, &k);

  if(a+(k-1) >= b-(k-1)){
      for(i=a; i<=b; i++)
	printf("%d\n", i);
      return 0;
  }
  
  for(i=a; i<a+k; i++)
    printf("%d\n", i);
  
  for(i=b-(k-1); i<=b; i++)
    printf("%d\n", i);
  
  return 0;
}



Measured memory_bytes: 128