akhauriyash/Code-Regression huggingface dataset:
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static final boolean debugMode = false;

	static final long DIV_INF = 1000000007l;

	static int n, m, x;
	static int[] c;
	static int[][] a;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = readInt(sc);
		m = readInt(sc);
		x = readInt(sc);

		c = new int[n];
		a = new int[n][m];

		for (int i = 0; i < n; i++) {
			c[i] = readInt(sc);
			for (int j = 0; j < m; j++) {
				a[i][j] = readInt(sc);
			}
		}

		int[] und = new int[m];// 理解度

		int res = dfs(0, 0, und);

		System.out.println(res == 99999999 ? -1 : res);

	}

	static int dfs(int depth, int cost, int[] und) {
		if (depth == n) {
			for (int u : und) {
				if (u < x) {
					return 99999999;
				}
			}
			return cost;
		}

		// depth番目の本を買う場合
		int[] und2 = Arrays.copyOf(und, und.length);
		for (int i = 0; i < m; i++) {
			und2[i] += a[depth][i];
		}

		return Math.min(dfs(depth + 1, cost, und), dfs(depth + 1, cost + c[depth], und2));

	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static Long readLong(Scanner sc) {
		return Long.parseLong(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class KrmlUtil {
	// a >= b
	static int gcd(int a, int b) {
		while (true) {
			if (b == 0)
				break;

			int mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// a >= b
	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	// a >= b
	static long gcd(long a, long b) {
		while (true) {
			if (b == 0)
				break;

			long mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// a >= b
	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static BigInteger gcd(BigInteger a, BigInteger b) {
		return a.gcd(b);
	}

	static BigInteger lcm(BigInteger a, BigInteger b) {
		return a.divide(a.gcd(b)).multiply(b);
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


Measured memory_bytes: 38240
#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;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    int n;
    while(cin>>n)
    {
        vector<ll> arr;
        ll cnt=1;
        for(int i=1;i<=n;i++)
        {
            ll x;
            cin>>x;
            if(x==cnt)
            {
                cnt++;
                arr.push_back(x);
            }
        }
        ll rem=n-arr.size();
        if(rem==n) cout<<-1<<endl;
        else cout<<rem<<endl;
    }

    return 0;
}


Measured memory_bytes: 3444
#include<stdio.h>
int main()
{
 char b;
 scanf("%c",&b);
 if(b=='A')
 {
     printf("T");
 }
 if(b=='G')
 {
     printf("C");
 }
 if(b=='C')
 {
     printf("G");
 }
 if(b=='T')
 {
     printf("A");
 }
 return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
#include <cstdio>
#define FOR(I,A,B) for(int I =(A);I<(B);++I)
#define FORE(I,B) for(int I =1;I<=(B);++I)
#define REP(I,A) FOR(I,0,A)
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const char dc[]={'E','N','W','S'};
const char dcc[]={'e','n','w','s'};
using namespace std;

int main() {
	// your code goes here
	int W,H;
	while (cin >> W >> H && W){
	char tmp;
	char maps[32][32]={};
	FORE(i,H)
		FORE(j,W)
			cin >> maps[i][j];
	bool ans;
	int next=0;
	while(true){
		ans=false;
		FORE(j,W)
			FORE(i,H){
				REP(k,4)
					if(maps[i][j]==dc[k]){
						REP(l,4){
							int n=(k+l+3)%4;
							if(maps[i+dy[n]][j+dx[n]]=='.'||maps[i+dy[n]][j+dx[n]]=='X'){
								maps[i][j]=dc[n];
								break;
							}
						}
					ans=true;
					break;
					}
			}
		FORE(i,H)
			FORE(j,W)
				if(maps[i][j]=='.'||maps[i][j]=='X'){
					REP(k,4)
						if(maps[i+dy[k]][j+dx[k]]==dc[(k+2)%4]){

							if(maps[i][j]=='.')
							maps[i][j]=dcc[(k+2)%4];
							maps[i+dy[k]][j+dx[k]]='x';
							break;
						}
				}
		FORE(i,H){
			FORE(j,W){
				if(maps[i][j]=='x')
					maps[i][j]='.';
				REP(k,4)
					if(maps[i][j]==dcc[k])
						maps[i][j]=dc[k];
			//	cout << maps[i][j];
			}
	//	cout << endl;
		}
		if(!ans || next>180)
			break;
		next++;
	}
	if(next>180)
	cout << "NA" << endl;
	else 
	cout << next << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
from collections import deque
n = int(input())

d = deque()

for _ in range(n):
    com = input()
    if (com[0] == 'i'):
        com ,i = com.split()
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (com[6] == ' '):
            com, i = com.split()
            try:
                d.remove(int(i))
            except ValueError:
                pass
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()
ans = map(str, d)
ans = " ".join(ans)
print(ans)

Measured memory_bytes: 48096
from math import gcd
from functools import reduce


class SmallestPrimeFactors:
    def __init__(self, n):
        self.spf = list(range(n + 1))
        for i in range(2, int(n ** 0.5) + 1):
            if self.spf[i] == i:
                for j in range(i * i, n + 1, i):
                    if self.spf[j] == j:
                        self.spf[j] = i

    def factor(self, x):
        if self.spf[x] == x:
            return [x]
        nxt = x // self.spf[x]
        return self.factor(nxt) + [self.spf[x]]


def is_PC():
    M = max(A)
    spf = SmallestPrimeFactors(M)
    counter = [0] * (M + 1)
    for a in A:
        if a == 1:
            continue
        new_primes = set(spf.factor(a))
        for np in new_primes:
            if counter[np]:
                return False
            counter[np] = 1
    return True


def is_SC():
    return reduce(gcd, A) == 1


N, *A = map(int, open(0).read().split())
if not is_SC():
    print("not coprime")
elif is_PC():
    print("pairwise coprime")
else:
    print("setwise coprime")


Measured memory_bytes: 121976
n=int(input())
list=[]
for i in range(0,n):
    a=int(input())
    list.append(a)
minv=list[0]
maxv=-10000000000
for i in range(1,n):
    maxv=max(maxv,list[i]-minv)
    minv=min(minv,list[i])
print(str(maxv))


Measured memory_bytes: 13592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factrial(int n){
//   if(n == 0) return 1;
//   return n*factrial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }

string s;

int main(){
  string s;
  cin >> s;
  bool f = true;
  int cnt = 0;
  if(s[0] == 'A'){
    for(int i = 1; i < s.size(); i++){
      int num = int(s[i]);
      if(s[i] == 'C' && i > 1 && i < s.size()-1) cnt++;
      else if(!(num >= int('a') && num <= int('z'))) f = false;
    }
  }
  if(cnt == 1 && f) cout << "AC" << endl;
  else cout << "WA" << endl;
}
  





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define fo(i,a) for(ll i=0;i<a;i++)
#define Fo(i,a,n) for(ll i=a; i<n; i++)
#define u_m unordered_map
#define u_s unordered_set
#define ff first
#define ss second
#define mp make_pair
using namespace std;
ll __pow(ll x, ll y) {ll res = 1;while(y>0){if(y&1) res*=x; y>>=1; x*=x;}return res;}
ll gcd(ll a , ll b){if(b==0) return a;a%=b;return gcd(b,a);}
bool isprime(ll n){for(ll i=2; i*i<=n; i++){if(n%i==0) return 0;}return 1;}
ll n,m,x,y,z,k;
ll dp(ll n){
    if(n<10) return max((ll)1, n);
    else return max((n%10)*dp(n/10), 9*dp(n/10-1));
}
void solve(){
    cin>>n;
    string s;
    ll r=0, w=0;
    cin>>s;
    fo(i,n){
        if(s[i]=='R') r++;
        else w++;
    }
    ll ans=0;
    fo(i,r){
        if(s[i]=='W') ans++;
    }
    cout<<ans<<endl;
}
int main(){
    ll t=1;
    //cin >> t;
    for(ll i=1; i<=t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

const int MAX = 210000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

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

double m(float a, float b)
{
	return a - std::floor(a / b) * b;
}

int main(){
  COMinit();
  int n;cin>>n;
  int ctr[n];
  rep(i,n)ctr[i]=-1;
  int a,b,c;
  rep(i,n+1){
    int x;cin>>x;
    if(ctr[--x]==-1)ctr[x]=i;
    else{
      a=ctr[x];
      b=i-a-1;
      c=n-i;
      break;
    }
  }
  rep(i,1,n+2){
    ll ans=0;
    ans+=COM(a+b+c,i);ans%=mod;
    ans+=COM(a+b+c,i-2);ans%=mod;
    ans+=COM(a+b+c,i-1);ans%=mod;
    ans+=COM(a+b+c,i-1);ans%=mod;
    ans-=COM(a+c,i-1);
    ans+=mod;ans%=mod;
    cout<<ans<<endl;
  }
}




Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (b<=c||a>=d) cout<<0<<endl;
	else if(a<=c&&b<=d&&c<=b) cout<<b-c<<endl;
	else if(a>=c&&b>=d&&d>=a) cout<<d-a<<endl;
	else if(a<=c&&b>=d) cout<<d-c<<endl;
	else if(a>=c&&b<=d) cout<<b-a<<endl;
	return 0;
}

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

using namespace std;

int n;
int k;
int cnt;

int main()
{
    int t;
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &t);
        if(t >= k) cnt++;
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = input()
t = input()

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    g = gcd(a, b)
    g_a = a // g
    g_b = b // g
    return g_a * g_b * g

L = lcm(n, m)
s1 = L // n
t1 = L // m
l = lcm(s1, t1)

flag = 0
for i in range(L//l):
    if s[i*t1] != t[i*s1]:
        flag = 1

if flag:
    print(-1)
else:
    print(L)

Measured memory_bytes: 3316
N = input()
arr = []

for i in range(N):
    arr.append(input())

arr.sort()
m = sum(arr)
length = len(arr)

for i in range(length):
    if (m % 10) != 0:
        break
    elif(arr[i] % 10) != 0:
        m -= arr[i]

if (m % 10) != 0:
    print m
else:
    print 0

Measured memory_bytes: 2568
a, b = map(int, input().split())
s = input()

for i in range(a):
    if s[i] == '-':
        print('No')
        exit()

if s[a] != '-':
    print('No')
    exit()

for i in range(a+1, a+b+1):
    if s[i] == '-':
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+100;
int a[N]; 
int main()
{
	ios::sync_with_stdio(false);
	int n,m;
    cin>>n;
    int mx=INT_MIN,c=INT_MIN;
    for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		if(mx<a[i])
		{
			c=mx;
			mx=a[i];
		}
		else if(c<a[i]) c=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==mx) cout<<c<<endl;
		else cout<<mx<<endl; 
	}
    return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>

int bubblesort(int a[],int N){
    int i,j,s,z,flag;
    s=0;
    z=0;
    flag=1;
    for(i=0;flag;i++){
      flag=0;
      for(j=N-1;j>=i+1;j--){
        if(a[j]<a[j-1]){
          z=a[j-1];
          a[j-1]=a[j];
          a[j]=z;
          flag=1;
          s++;
        }
      }
    }
  return s;
}

int main(void)
{
  int i,j,N,s,a[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  s=bubblesort(a,N);
  for(i=0;i<N;i++){
    if(i>0){
      printf(" ");
    }
    printf("%d",a[i]);
  }
  printf("\n");


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

    

Measured memory_bytes: 1852
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int a;
  int b=0,c=0;
  for(int i=0; i<3; i++){
    scanf("%d",&a);
    if(a==5){
      b++;
    }else if(a==7){
      c++;
    }
  }
  if(b==2 && c==1){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1652
n,m=list(map(int,input().split()))
B=[1]*n
R=[False]*n
R[0]=True

for i in range(m):
  x,y=list(map(int,input().split()))
  B[y-1]+=1
  B[x-1]-=1
#  print(B)
  if R[x-1]==True:
    if B[x-1]==0:
      R[x-1]=False
      R[y-1]=True
    else:
      R[y-1]=True      
#  print(R)
print(R.count(True))

Measured memory_bytes: 4596
from numba import njit

N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
dp = [0] * maxA

for i in range(N):
    if dp[A[i]-1] != 0:
        dp[A[i]-1] = 2
        continue
    else:
        for j in range(1, maxA//A[i]+1):
            dp[A[i]*j-1] += 1

ans = 0
for i in range(N):
    if dp[A[i]-1] == 1:
        ans += 1

print(ans)

Measured memory_bytes: 115000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, w[300];
int can[301][301], dp[301];

int rec(int l, int r){
	int &res = can[l][r];
	if(res >= 0) return res;
	if(l == r) return res = 1;
	if(l >= r - 1 || (r - l) % 2) return res = 0;
	
	if(abs(w[l] - w[r - 1]) < 2 && rec(l + 1, r - 1)) return res = 1;
	for(int i = l + 2; i < r; i += 2) if(rec(l, i) && rec(i, r)) return res = 1;
	return res = 0;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	while(cin >> n, n){
		memset(can, -1, sizeof(can));
		memset(dp, 0, sizeof(dp));
		
		rep(i, n) cin >> w[i];
		rep(i, n){
			dp[i + 1] = max(dp[i + 1], dp[i]);
			for(int j = i - 1; j >= 0; j -= 2) if(rec(j, i + 1))
				dp[i + 1] = max(dp[i + 1], dp[j] + i - j + 1);
		}
		cout << dp[n] << endl;
	}
	return 0;
}

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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	
    int n,m; cin >> n >> m;
    vector<bool> a(n);
    a[0] = true;
    vi c(n,1);
    forn(i,m){
        int x,y; cin >> x >> y; x--, y--;
        if(a[x]){
            if(c[x] == 1) a[x] = false;
            a[y] = true;
        }
        c[x]--, c[y]++;
    }
    int res = 0;
    forn(i,n) if(a[i]) res++;	
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define re register
#define M 998244353
#define int long long
inline void add(re int &x,re int y){(x+=y)>=M?x-=M:x;}
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,k,a[1000002],ans,tim,f[1000002];
char s[1000002];
signed main(){
	n=read();k=read(),m=read();
	while(!a[k]&&tim<=n)a[k]=++tim,f[tim]=f[tim-1]+k,k=k*k%m;
	if(tim==n+1){
		printf("%lld",f[tim-1]);
		return 0;
	}
	ans=f[tim];
	re int xhj=tim-a[k]+1;
	ans+=(f[tim]-f[a[k]-1])*((n-tim)/xhj);
	while((n-tim)%xhj)++tim,ans+=k,k=k*k%m;
	printf("%lld",ans);
}

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

// gcd,lcm,素因数分解,ax + by = k,euler_phi
using namespace std;
template<typename T>
class Integer {
public:
	T gcd(T a,T b) {
		if (a < b) swap(a,b);
 		return b != 0 ? gcd(b, a % b) : a;
	}

	T lcm(T a,T b) {
  		return (a / gcd(a, b))*b;
	}

	map<T,int> getFactMap(T n) { // 素因数分解 key->因数 val->因数の数
		map<T,int> fact;
		T maxiter = (T)(sqrt(n) + 1);
		T div = 2;
		while (div < maxiter && n != 1) {
			if (!(n % div)) {
				fact[div]++;
				n /= div;
			}
			else div++;
		}
		if (n != 1) fact[n]++;
		return fact;
	}

	vector<T> getFactVec(T n) {
		vector<T> fact;
		T maxiter = (T)(sqrt(n) + 1);
		T div = 2;
		while (div < maxiter && n != 1) {
			if (!(n % div)) {
				fact.push_back(div);
				n /= div;
			}
			else div++;
		}
		if (n != 1) fact.push_back(n);
		return fact;
	}

	pair<T,T> exEuclid(T a,T b,T k = 1) {
		if (k != 1) {
			T g = gcd(a,b);
			a /= g; b /= g;
		}
		T div,mod,cc = 1,gg = 1,ee = 0,ff = 0,hh,ii;
		while (b) {
			div = a / b;mod = a % b;
			hh = cc - div * ee;
			ii = ff - div * gg;
			swap(a,b);
			b = mod;
			swap(cc,ee);
			ee = hh;
			swap(ff,gg);
			gg = ii;
		}
		return make_pair(cc,ff);
	}
};

int main(void) {
	Integer<int> it;
	int n;
	cin >> n;
	vector<int> ans = it.getFactVec(n);
	cout << n << ":";
	for (int i = 0;i < ans.size();i++) {
		cout << " " << ans[i];
	}
	cout << endl;
}


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

int main() {
    int n; cin >> n;
    int a[n], b[n], c[n];
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    int dp[n][3];
    rep(i, n)rep(j, 3) dp[i][j] = 0;
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    rep(i, n-1){
        dp[i+1][0] = max(dp[i][1]+a[i+1], dp[i][2]+a[i+1]);
        dp[i+1][1] = max(dp[i][0]+b[i+1], dp[i][2]+b[i+1]);
        dp[i+1][2] = max(dp[i][1]+c[i+1], dp[i][0]+c[i+1]);
        // cout << dp[i+1][0] << " " << dp[i+1][1] << " " << dp[i+1][2] << endl;
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;

    return 0;
}

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

using namespace std;

typedef long long LL;

int main()
{
    //ifstream cin("input.txt");
    char s[1005];
    cin>>s;
    cout<<s;
    if (s[strlen(s)-1]=='s')
        cout<<"es";
    else
        cout<<'s';
}



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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 2e5 + 667;

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

    ll a, b, c;
    cin >> a >> b >> c;
    ll mx = max(a, max(b, c));
    if(mx == a){
        ll cnt = a / 2;
        if(a % 2 == 0){
            cout << 0;
            return 0;
        }
        ll sum1 = (a - cnt) - cnt;
        cout << sum1*b*c;
    }
    else if(mx == b){
        ll cnt = b / 2;
        if(b % 2 == 0){
            cout << 0;
            return 0;
        }
        ll sum1 = (b - cnt) - cnt;
        cout << sum1*a*c;
    }
    else{
        ll cnt = c / 2;
        if(c % 2 == 0){
            cout << 0;
            return 0;
        }
        ll sum1 = (c - cnt) - cnt;
        cout << sum1*b*a;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[333],n;
int main(){
  for(int i=2;i<18;i++)
    for(int j=i*i;j<333;j++)
      dp[j]+=dp[j-i*i]+1;
  while(cin>>n,n)
    cout<<dp[n]+1<<endl;
}

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

ll Min(ll x,ll y){
	if (x > y){
		return y;
	}else{
		return x;
	}
}
ll Max(ll x,ll y){
	if(x > y){
		return x;
	}else{
		return y;
	}
}

int main(){
	int N,_;
	ll Array[100010];
	ll input;
	ll mins[100010];
	ll min = 10000000000,max = 0;
	
	ll maxrieki = 0;
	cin >> N >> _;
	for(int i=0;i<N;i++){
		cin >> Array[i];
		min = Min(min,Array[i]);
		mins[i] = min;
		maxrieki = Max(maxrieki,Array[i] - mins[i]);
	}
	
	int answer = 0;
	for(int i=0;i<N;i++){
		if (maxrieki == Array[i] - mins[i]){
			answer ++;
		}
	}
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
int n,m,h,w;
int main(){
	scanf("%d%d%d%d",&n,&m,&h,&w);
	if (n%h!=0){
		puts("Yes");
		for (int i=1;i<=n;i++){
			for (int j=1;j<=m;j++)
				if (i%h==1)printf("%d ",1000*(h-1)-1);
				else printf("%d ",-1000);
			puts("");
		}
		return 0;
	}
	if (m%w!=0){
		puts("Yes");
		for (int i=1;i<=n;i++){
			for (int j=1;j<=m;j++)
				if (j%w==1)printf("%d ",1000*(w-1)-1);
				else printf("%d ",-1000);
			puts("");
		}
		return 0;
	}
	puts("No");
}

Measured memory_bytes: 1664
//problem-C
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include<string>
#include<queue>
#include<map>

using namespace std;

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

	int putFirst = 0;
	int putLast = 0;
	int nowCount = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == '(') {
			nowCount++;
		}
		else {
			nowCount--;
			if (nowCount == -1) {
				nowCount = 0;
				putFirst++;
			}
		}
	}
	putLast = nowCount;

	for (int i = 0; i < putFirst; i++)
	{
		cout << '(';
	}
	cout << S;
	for (int i = 0; i < putLast; i++)
	{
		cout << ')';
	}
	cout << endl;

	return 0;
}


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

using namespace std;

int main()
{
	int n;
	string s[50];
	string a;
	int cnt[26][50];
	int m[26];
	int j=0;
	int d=0;
	for(int i=0;i<26;i++)
	{
		m[i]=100;
		for(int j=0;j<50;j++)
		{
			cnt[i][j]=0;
		}
	}
	cin>>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());
		j=0;
		d=0;
		for(char c='a';c<'z'+1;c++)
		{
			while(s[i][j]==c)
			{
				cnt[d][i]++;
				j++;
			}
			cerr<<cnt[d][i];
			d++;
			if(j==s[i].size())
			{
				break;
			}
		}
	}

	for(int i=0;i<26;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(m[i]>cnt[i][j])
			{
				m[i]=cnt[i][j];
			}
		}
	}

	for(int i=0;i<26;i++)
	{
		cerr<<m[i];
		for(int j=0;j<m[i];j++)
		{
			a += ('a'+i);
		}
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A=list(map(int,input().split()))
cnt = 0
B=[None]*N
C=10**9+1
for i in range(len(A)):
  B[i]=abs(A[i])
  C=min(C,B[i])
  if A[i]<0:
    cnt+=1
ret = sum(B)-C+C*(-1)**cnt
print(ret)

Measured memory_bytes: 14412
import itertools
import math
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

seq = [i for i in range(1,n+1)]
s = list(itertools.permutations(seq))

# print(seq)
# print(s)

p_num = 0
q_num = 0

# print(p)
# print(q)
for i in range(math.factorial(n)):
    #print(s[i])
    if s[i] == p:
        p_num = i

    if s[i] == q:
        q_num = i
print(abs(p_num-q_num))

Measured memory_bytes: 7972
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	cin>>n>>k;
	vc a(n+1),dp(n+1);
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=2;i<=n;i++)
	{
	    l=MOD;
	    for(j=1;(j<=k)&&(i-j>0);j++)
	        l=min(dp[i-j]+llabs(a[i]-a[i-j]),l);
	    dp[i]=l;
	}
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 4776
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> A(T);
    for (int i = 0; i < T; ++i)
        cin >> A[i];

    int maxv = *max_element(A.begin(), A.end());
    if (maxv < (K + 1) / 2)
        cout << 0 << "\n";
    else
        cout << maxv - (K - maxv + 1) << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline long long read(){
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(long long a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(long long a){
    write(a); puts("");
}
long long s[5],n;
int main(){
    for(long long i=1;i<=4;i++)s[i]=read();
    n=read(); s[0]=100000000;
    for(long long i=1;i<=4;i++){
    	s[i]=min(s[i-1]*2,s[i]);
	}
	long long ans=n/2;
	ans*=s[4];
	n%=2;
	ans+=n*s[3];
	cout<<ans<<endl;
}

Measured memory_bytes: 888
def warshall_floid(graph):
    """warshall-floid法: 各頂点から各頂点への最短距離を求める
    重み付きグラフgraphは隣接リストで与えられる
    計算量: O(|N|^3)
    """
    n = len(graph)
    INF = 10**18
    dp = [[INF]*n for i in range(n)]
    for i in range(n):
        dp[i][i] = 0

    for i in range(n):
        for j, cost in graph[i]:
            dp[i][j] = cost
            dp[j][i] = cost

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp


def trace_route(start, goal):
    """warshall-floid法で求めた最短距離を通るための経路を復元する
    計算量: O(|N|^2)
    """
    pos = start
    ans = []
    while pos != goal:
        ans.append(pos)
        for next_pos in range(n):
            if next_pos != pos and dp[pos][next_pos] + dp[next_pos][goal] == dp[pos][goal]:
                pos = next_pos
                break
    ans.append(goal)
    return ans


# 値を入力する
n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
t_max = int(input())
query = [None] * t_max
for i in range(t_max):
    tmp = int(input())
    query[i] = [list(map(int, input().split())) for i in range(tmp)]

# グラフを構築
graph = [[] for i in range(n)]
for a, b, cost in info:
    a -= 1
    b -= 1
    graph[a].append((b, cost))
    graph[b].append((a, cost))

# 最短距離を求める
dp = warshall_floid(graph)

visited = [False] * n
visited[0] = True
route = [0]
pos = 0
total_cost = 0
while True:
    kyori = 10**9
    next_pos = -1
    for next_p, cost in enumerate(dp[pos]):
        if visited[next_p]:
            continue
        if cost< kyori:
            kyori = cost
            next_pos = next_p
    if next_pos == -1:
        break
    else:
        visited[next_pos] = True
        route.append(next_pos)
        total_cost += kyori

for i in range(n-1):
    pos = route[i]
    next_pos = route[i+1]

for i in range(t_max):
	print(-1)

Measured memory_bytes: 58072
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())
n = len(S)
K = I()

num = 0
flag = False
for i in range(1,n):
    if S[i]==S[i-1] and flag==False:
        num += 1
        flag = True
    else:
        flag = False

if flag==False and S[0]==S[-1]:
    num2 = 1
    flag2 = False
    for i in range(2,n):
        if S[i]==S[i-1] and flag2==False:
            num2 += 1
            flag2 = True
        else:
            flag2 = False
    if n==1:
        flag2 = True
    if flag2==False:
        print(num+num2*(K-1))
        exit()
    else:
        print(num2*(K//2) + num*(K-K//2))
        exit()
else:
    print(num*K)

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// ABC046B - AtCoDeerくんとボール色塗り
int main(){
  int N, K; // N個のぼーる K色のペンキ
  cin >> N >> K;
  int64_t ans = K;
  for (int i = 1; i < N; ++i) {
    ans *= K-1;
  }

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



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int dist[1005][1005];

int main() {
    //cout.precision(10);
    int H, W;
    cin >> H >> W;
    string field[1005];
    for(int h = 1; h <= H; h++) {
        cin >> field[h];
        field[h] = "&" + field[h];
    }
    queue<i_i> que;
    for(int h = 1; h <= H; h++) {
        for(int w = 1; w <= W; w++) {
            if(field[h][w] == '.') dist[h][w] = INF;
            else {
                dist[h][w] = 0;
                que.push({h, w});
            }
        }
    }
    int dh[4] = {1, 0, -1, 0};
    int dw[4] = {0, 1, 0, -1};
    while(!que.empty()) {
        i_i now = que.front();
        que.pop();
        int h = now.first;
        int w = now.second;
        //cerr << h << " " << w << " " << dist[h][w] << endl;
        for(int k = 0; k < 4; k++) {
            int newh = h + dh[k];
            int neww = w + dw[k];
            if(newh <= 0 || newh > H || neww <= 0 || neww > W) continue;
            if(dist[newh][neww] != INF) continue;
            dist[newh][neww] = dist[h][w] + 1;
            que.push({newh, neww});
        }
    }
    int ans = 0;
    for(int h = 1; h <= H; h++) {
        for(int w = 1; w <= W; w++) {
            ans = max(ans, dist[h][w]);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    long long x,k,d;
    cin >> x >> k >> d;
    if(x < 0) x *= -1;

    long long ans;
    long long r = x/d;
    if(r > k) ans = x - (k*d);
    else{
        if((k-r) % 2 == 0) ans = x - (r*d);
        else ans = (r+1) *d -x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < (n);i++)
#define lint long long
const lint mod=1e9+7;
const lint inf=2.19e15+1;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

signed main(){
    string s, t;
    int minv = 10000000;
    cin >> s >> t;
    REP(i, (int)s.size() - (int)t.size() + 1){
        int cnt = 0;
        REP(j, t.size()){
            if (s[i+j] != t[j]){
                cnt += 1;
            }
        }
        chmin(minv, cnt);
    }
    cout << minv << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    ll a,b;
    cin>>a>>b;
    ll x=0;
    ll y=0;
    ll c=(ll)b-a+1;
    if(a%2!=0){
        c--;
        x=a;
    }
    if(b%2==0){
        y=b;
        c--;
    }
    int t=(c/2)%2;
    ll ans=(ll)x^y^t;
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
  //stream
  friend ostream& operator<<(ostream& os, const mint a);
};
ostream& operator<<(ostream& os, const mint a){
  os << a.x;
  return os;
}

int main(void) {
	int n,m; cin >> n >> m;
	vi s(n),t(m);
	rep(i,n) cin >> s[i];
	rep(j,m) cin >> t[j];
	vector<vector<mint>> dp(n+1,vector<mint>(m+1,0));
	rep(i,n+1) dp[i][0]=1;
	rep(j,m+1) dp[0][j]=1;
	rep2(i,1,n+1)rep2(j,1,m+1){
		if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j]+dp[i][j-1];
		else dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
	}
	cout << dp[n][m] << endl;
}




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

using namespace std;
const int maxn=1e5+5;
int p[maxn];
int ac[maxn];
char tmp[10];
int main()
{
    int x, n, i, m, k, sum=0, j;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        scanf("%d%s", &x, tmp);
//        cout<<x<<tmp<<endl;
        if(tmp[0]=='W')
        {
            if(ac[x]==0)p[x]++;
        }
        else
        {
//            cout<<sum<<endl;
            sum+=(ac[x]==0);
            ac[x]=1;
        }
    }
    int psum=0;
    for(i=1; i<=n; i++)if(ac[i])psum+=p[i];
    printf("%d %d\n", sum, psum);
    return 0;
}


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

int main(){
  int N;

  cin >> N;
  
  vector<int> d;
  d.resize(N);

  for(int i=0;i<d.size(); ++i){
    cin >> d[i];
  }

  reverse(d.begin(), d.end());
  if(d[0] < 10){
      cout << "no" << endl;
      return 0;
  }
  for(int i=0;i<d.size();++i){

    if(d[i] < 10){
      int counter = 2;
      for(int ix=i+1;ix<d.size();++ix){
	if(d[ix] >= counter * 10){
	  i = ix;
	  break;
	}

	++counter;
	if(ix == d.size()-1){
	  cout << "no" << endl;
	  return 0;
	}
      }
    }
  }
  reverse(d.begin(), d.end());
  if(d[0] < 10){
    cout << "no" << endl;
    return 0;
  }
  for(int i=0;i<d.size();++i){
    if(d[i] < 10){
      int counter = 2;
      for(int ix=i+1;ix<d.size();++ix){
	if(d[ix] >= counter * 10){
	  i = ix;
	  break;
	}

	++counter;
	if(ix == d.size()-1){
	  cout << "no" << endl;
	  return 0;
	}
      }
    }
  }

  cout << "yes" << endl;
  
  return 0;
}


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

int main(){
int n;
string s;
string f[6]={"North","East","West","South","Right","Left"};
int cf[6][3]={{1,5,2},{4,1,0},{2,1,5},{3,0,2},{0,2,3},{0,4,1}};
int sum=1;
int a=0;
int me[6]={1,2,3,5,4,6};
int ne[3];
while(cin>>n){
	sum=1;
	int me[6]={1,2,3,5,4,6};
	if(n==0)break;
	a=0;
for(int i=0;i<n;i++){
cin>>s;
for(int j=0;j<6;j++){
if(s==f[j]){
for(int k=0;k<3;k++){
ne[k]=me[cf[j][k]];}
for(int k=0;k<3;k++){
me[k]=ne[k];}
me[3]=7-me[1];
me[4]=7-me[2];
me[5]=7-me[0];
break;
}}
sum+=me[0];}
cout<<sum<<endl;}
}

Measured memory_bytes: 1216
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

char b[1000][1002];
int  m[1000][1000];
int  px[10];
int  py[10];

int main(){
  int h,w,n;
  while(~scanf("%d%d%d", &h, &w, &n)){
    REP(i,h) scanf("%s", b[i]);
    REP(i,h)REP(j,w){
      if(isdigit(b[i][j]) || b[i][j] == 'S'){
        if(b[i][j] == 'S'){
          px[0] = j;
          py[0] = i;
        }else{
          px[b[i][j] - '0'] = j;
          py[b[i][j] - '0'] = i;
        }
        b[i][j] = '.';
      }
    }

    int ans = 0;

    REP(p,n){
      queue<pair<int,int> > q;

      REP(i,h) REP(j,w) m[i][j] = -1;
      m[py[p]][px[p]] = 0;
      q.push(mp(px[p], py[p]));

      while(!q.empty()){
        pair<int,int> pos = q.front();
        int x = pos.f;
        int y = pos.s;
        q.pop();

        if(x == px[p+1] && y == py[p+1]){
          //printf("%d: %d\n", p, m[y][x]);
          ans += m[y][x];
          break;
        }

        REP(d,4){
          int xx = x + _dx[d];
          int yy = y + _dy[d];

          if(ISIN(xx,yy,w,h) && b[yy][xx] == '.' && m[yy][xx] == -1){
            m[yy][xx] = m[y][x] + 1;
            q.push(mp(xx,yy));
          }
        }
      }
    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 5776
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>

using namespace std;

void ESequenceSum(std::istream& in, std::ostream& out) {
    long long n;
    in >> n;
    long long x, mod;
    in >> x >> mod;
    if (x == 1) {
        out << n << '\n';
        return;
    }
    if (x == 0) {
        out << 0 << '\n';
        return;
    }
    long long xx = x;
    long long ans = x;
    map<long long, int> mp;
    mp.insert({x, 1});
    int cur = 1;
    while (cur < n) {
        ++cur;
        xx *= xx;
        xx %= mod;
        //if (x == 10) cout << xx << '\n';
        if (mp.count(xx)) {
            // solve
            long long loop = cur - mp[xx];
            long long rest = n - cur + 1;
            long long loop_sum = xx;
            long long xxx = xx * xx % mod;
            while (xxx != xx) {
                loop_sum += xxx;
                xxx *= xxx;
                xxx %= mod;
            }
            ans += (rest / loop) * loop_sum;
            //ans %= mod;
            rest %= loop;
            //cout << rest << '\n';
            while (rest > 0) {
                rest--;
                ans += xx;
                xx *= xx;
                xx %= mod;
            }
            break;
        }
        ans += xx;
        //ans %= mod;
        mp.insert({xx, cur});
    }
    out << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    ESequenceSum(in, out);
    return 0;
}

Measured memory_bytes: 6672
import java.util.*;

public class Main {
    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int b = (int) Math.pow(2, S.length() - 1);
        long ans = 0;

        for (int i = 0; i < b; i++) {
            String s = "";
            for (int j = 0; j < S.length(); j++) {
                if ((i & (1 << j)) >= 1) {
                    s += String.valueOf(S.charAt(j)) + "+";
                } else {
                    s += String.valueOf(S.charAt(j));
                }
            }
            String[] sp = s.split("\\+");
            for (int j = 0; j < sp.length; j++) {
                if (!sp[j].isEmpty()) {
                    ans += Long.parseLong(sp[j]);
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24788
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		Set<Integer> setA = new TreeSet<>();
		Set<Integer> setB = new TreeSet<>();

		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			setA.add(sc.nextInt());
		}

		int m = sc.nextInt();
		for(int i = 0; i < m; i++) {
			setB.add(sc.nextInt());
		}

	
		setA.addAll(setB);

		for(int value : setA) {
			System.out.println(value);
		}
	}

}



Measured memory_bytes: 199188
i,j,k;
long a[444],p[444][444],S,T,P;
main()
{
	scanf("%*d");
	for(;~scanf("%d",a+j);)
	{
		for(S+=T=a[i=j++];i--;)
		{
			T+=a[i];
			P=9e18;
			for(k=i;++k<j;)
			{
				P=fmin(P,p[i][k]+p[k][j]+T);
			}
			p[i][j]=P;
		}
	}
	printf("%ld",P);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s,t;
    int cnt = 0;
    cin >> s >> t;
    for (int i = 0; i < 3; i++)
    {
        if(s.substr(i, 1) == t.substr(i, 1)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
using namespace std;main(){int n,c,m;for(;cin>>n,n;){string s,t;map<string,int>M;for(;n--;)cin>>s>>c,M[s]=c;for(cin>>n;n--;M[s]=min(M[s],c))for(c=0,cin>>s>>m;m--;)cin>>t,c+=M[t];cin>>s,cout<<M[s]<<endl;}}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    if(n>=m/2){
      cout<<m/2<<endl;
      return 0;
    }
    ll ans=n;
    m-=2*n;
    ans+=m/4;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var I=0;
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   if(I!=0)console.log("");
   I++;
   var rank=[];
   for(var i=0;i<n;i++){
      var arr=(Arr.shift()).split(" ");
      var score=(3*(arr[1]-0))+(arr[3]-0)+((10-i)*0.01);
      rank.push([arr[0],score]);
   }
   rank.sort(function(a,b){
      a=a[1];
      b=b[1];
      return b-a;
   });
   rank.forEach(function(v){
      console.log(v[0]+","+Math.floor(v[1]));
   });
}

Measured memory_bytes: 8508
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <chrono>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

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

  vector<uint64_t> A(N);
  cin >> A;

  vector<uint64_t> dp(N + 1, 0);
  dp[0] = 1000;
  N_TIMES(n, N) {
    dp[n + 1] = dp[n];
    N_TIMES(m, n) {
      uint64_t p = dp[m] / A[m], q = dp[m] % A[m];
      dp[n + 1] = max(dp[n + 1], p * A[n] + q);
    }
  }
  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 3536