akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    ll X; cin >> X;
    ll res = 0;
    res += (X/500) * 1000;
    res += ((X%500)/5) * 5;
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;


int main(){
    int N; cin>>N;
    vector<int> a(N+1),b(N);
    for (int i = 0; i <= N; ++i) {
        cin>>a[i];
    }

    for (int i = 0; i < N; ++i) {
        cin>>b[i];
    }
    ll ans=0ll;
    for(int i=0;i<N;i++){
        if(a[i]>=b[i]){
            ans+=(ll)b[i];
            b[i]=0;
        }else{
            ans+=(ll)a[i];
            b[i]-=a[i];
        }
        ans+=(ll)min(a[i+1],b[i]);
        a[i+1]=max(0,a[i+1]-b[i]);

    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

string s[15];
int cnt[15][1010];

int main(void){
	int h,w,x,i,j,k,ans=INF,tmp;
	bool flag;
	cin >> h >> w >> x;
	for(i=0; i<h; ++i){
		cin >> s[i];
		for(j=0; j<w; ++j){
			s[i][j] -= '0';
		}
	}
	for(i=(1<<(h-1)); i<(1<<h); ++i){
		fill(cnt[0],cnt[15],0);
		tmp = __builtin_popcount(i)-1;
		flag = false;
		for(j=0; j<w; ++j){
			for(k=0; k<h; ++k){
				cnt[k][j] += s[k][j];
				if(!(i&(1<<k))){
					cnt[k+1][j] += cnt[k][j]; 
					cnt[k][j] = 0;
				}
				if(cnt[k][j]>x){
					flag = true;
					break;
				}
			}
			if(flag){
				break;
			}
		}
		if(flag){
			continue;
		}
		for(j=1; j<w; ++j){
			flag = true;
			for(k=0; k<h; ++k){
				if(cnt[k][j-1]+cnt[k][j]>x){
					flag = false;
					++tmp;
					break;
				}
			}
			if(flag){
				for(k=0; k<h; ++k){
					cnt[k][j] += cnt[k][j-1];
				}
			}
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
ls_h = list(map(int, input().split()))

plc = 0
dlt = 10000

for i in range(n):
    if abs(a - (t - ls_h[i] * 0.006)) < dlt:
        dlt = abs(a - (t - ls_h[i] * 0.006))
        plc = i

print(plc+1)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
	int l, r, d, c = 0,n;
	cin >> l >> r >> d;
	n = d;
	while (r >= n) {
		if (l > n) {
			n += d;
			continue;
		}
		c++;
		n += d;
	}
	cout << c;
}

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

using namespace std;

int main()
{
    int n,q,C=0;
    cin>>n;
    vector<int> S(n);
    for(int i=0;i<n;i++)cin>>S.at(i);
    cin>>q;
    vector<int> T(q);
    for(int i=0;i<q;i++)cin>>T.at(i);

    for(int i=0;i<q;i++){
    if(binary_search(S.begin(),S.end(),T.at(i))){
    C+=1;
    }
    
    }
              
    cout<<C<<endl;
}



Measured memory_bytes: 3284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
int N,A,B;
int main(){
	//freopen("in","r",stdin);
	N=read(),A=read(),B=read();
	if(A*N<=B)
		printf("%d\n",A*N);
	else
		printf("%d\n",B);
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;
}

Measured memory_bytes: 256
K = int(input())
N = 50
if K <= N:
    ans = [N]*K + [0]*(N-K)
    print(N)
    print(*ans)
    exit()

ans = list(range(N,0,-1))
d,m = divmod(K,N)
for i in range(N):
    ans[i] += d-1 + int(i < m)

print(N)
print(*ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    long double n;
    cin >> n;
    long double r2 = 1.41421356237;
    printf("%.10Lf\n", max(n * r2, (long double)((int)n + 1)) );

    return 0;
}

Measured memory_bytes: 3296
#include<cstdio>
using namespace std;
int main()
{
	int n,k,ans=0,x;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x<=k/2)
		{
			ans+=x*2;
		}
		else
		{
			ans+=(k-x)*2;
		}
	}
	printf("%d\n",ans);
} 

Measured memory_bytes: 128
a,b,c=map(int,input().split())
As=[]
for i in range(1,a+1):
  if a%i==0:
    As.append(i)
Bs=[]
for i in range(1,b+11):
  if b%i==0:
    Bs.append(i)
ans=[]
for A in As:
  if A in Bs:
    ans.append(A)
ans.sort()
print(ans[-c])

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

int main(){
	int count = 0;
	int id;
	char c;
	double weight, tall;
	while(cin >> id >> c >> weight >> c >> tall){
		if(weight >= 25 * tall * tall){
			count++;
			cout << id << endl;
		}
	}
	if(count == 0) cout << "ツ該ツ督鳴づ按つオ" << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'A') cnt++;
    }

    if (cnt >= 5) {
        cout << "NO" << endl;
        return 0;
    } else {
        for (int i = 0; i <= N; i++) {
            for (int j = i; j <= N + 1; j++) {
                for (int k = j; k <= N + 2; k++) {
                    for (int l = k; l <= N + 3; l++) {
                        string tmp = S;
                        if (cnt <= 3) {
                            tmp.insert(i, "A");
                            if (cnt <= 2) {
                                tmp.insert(j, "A");
                                if (cnt <= 1) {
                                    tmp.insert(k, "A");
                                    if (cnt <= 0) {
                                        tmp.insert(l, "A");
                                    }
                                }
                            }
                        }
                        if (tmp == "AKIHABARA") {
                            cout << "YES" << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }

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


Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 450
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,H,f[MAX],In[MAX],Ot[MAX];bool vis[MAX];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
int main()
{
	n=read();H=read();
	for(int i=1;i<=H+H;++i)f[i]=i,vis[i]=false;
	for(int i=1;i<=n;++i)
	{
		int a=read(),b=read(),c=read(),d=read();
		int l=(c>0?c:-a)+H,r=(d>0?-d:b)+H;
		if(getf(l)!=getf(r))f[getf(l)]=getf(r);
		In[r]+=1;Ot[l]+=1;
	}
	for(int i=-H;i<0;++i)if(In[i+H]>Ot[i+H]){puts("NO");return 0;}
	for(int i=1;i<=H;++i)if(In[i+H]<Ot[i+H]){puts("NO");return 0;}
	for(int i=0;i<=H+H;++i)if(In[i]!=Ot[i])vis[getf(i)]=true;
	for(int i=0;i<=H+H;++i)if(In[i]&&Ot[i]&&!vis[getf(i)]){puts("NO");return 0;}
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split(" "))

if A>B:
  if A-1>B:
    print(int(A*2)-1)
  else:
    print(A+B)
else:
  if B-1>A:
    print(int(B*2)-1)
  else:
    print(A+B)
  

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L D(L a){L d;Z[a]=1;
for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L a,L i){for(a=M(i++G i);i<1e5;i+=i&-i)B[i]+=a;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;
for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Measured memory_bytes: 33476
#include <bits/stdc++.h>
#define rep( i, n ) for (ll i = 0; i < ( ll )(n); i++)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;

int main(){
    int k;
    cin>>k;
    rep(i,k){
        cout<<"ACL";
    }
}


Measured memory_bytes: 3588
// A - ><
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;

	long long ans = 0;
	for (int i = 0; i < s.size(); ) {
		long long n1 = 0, n2 = 0;
		for ( ; i < s.size() && s[i] == '<'; i++) n1++;
		for ( ; i < s.size() && s[i] == '>'; i++) n2++;
		ans += max(n1, n2);
		if (n1 > 0) ans += (n1 - 1 + 1) * (n1 - 1) / 2;
		if (n2 > 0) ans += (n2 - 1 + 1) * (n2 - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 900
x1, y1, x2, y2 = map(int, input().split())

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4)

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

int main()
{
  int n;
  cin >>  n;
  float a[n],s=0;
  rep(i,n){
    cin >> a[i];
}
  sort(a,a+n);
    s=(a[0]+a[1])/2;
  for(int i=2;i<n;i++)
  {
 	s=(s+a[i])/2;
  }
 
 cout << s;

return 0;
}

Measured memory_bytes: 256
def solve():
    s = input()
    nums = [int(s[i]) for i in range(len(s))]

    for op in range(0, 1<<3):
        val = nums[0]

        bits = [((op>>i)&1)!=0 for i in range(3)]

        for i in range(3):
            if bits[i]:
                val = val + nums[i+1]
            else:
                val = val - nums[i+1]
        if val == 7:
            ans = str(nums[0])
            for i in range(3):
                if bits[i]:
                    ans += "+" + str(nums[i+1])
                else:
                    ans += "-" + str(nums[i+1])
            ans += "=7"
            print(ans)
            return

solve()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    double T, X;
    cin >> T >> X;
    cout << T / X << endl;
    return 0;
}

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

int main(void) {
	string s; cin >> s;
	int i, a, ans = 1000;
	for (i = 0; i < s.size() - 2; i++) {
		a = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0';
		if (ans > abs(a - 753)) {
			ans = abs(a - 753);
		}
	}

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


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

using namespace std;

const int ms = 256 + 17;
int arr[ms];


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

    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i)
    {
        char x;
        cin >> x;

        ++arr[x];
    }

    int answer = 0;
    for(int i = 1; i <= 256; ++i)
    {
        if(arr[i])
            ++answer;
    }

    answer == 3? cout << "Three\n" : cout << "Four\n";
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
maxans=0
ans=0
for i in range(n-1):
    if h[i]>=h[i+1]:
        ans+=1
    else:
        if ans>maxans:
            maxans=ans
        ans=0
if ans>maxans:
    maxans=ans
print(maxans)


Measured memory_bytes: 15020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int ans = 1;
        while (ans <= n) {
            ans = ans * 2;
        }
        System.out.println(ans / 2);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int H,W;
vector<vector<int>>field;

void dfs(int h,int w) {
    field[h][w] = 0;
    for(int dh = -1;dh <= 1;dh++) {
        for(int dw = -1;dw <= 1;dw++) {
            int nh = h + dh, nw = w + dw;
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if(field[nh][nw] == 0) continue;
            
            dfs(nh,nw);
        }
    }
}

int main() {
    while(true){
        cin >> W >> H;
        if(W == 0 || H == 0) break;
        field.assign(H, vector<int>(W, 0));
        for(int h = 0; h < H;h++) {
            for(int w = 0;w < W;w++) {
             cin >> field[h][w];
            }
          }
        int count = 0;
        for(int h = 0;h < H;h++) {
            for(int w = 0; w < W;w++) {
                if(field[h][w] == 0) continue;
                dfs(h,w);
                count++;
            }
        }
    cout << count << endl;
    }
    return 0;
}






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

int const N = 1e6+1;
int a[N];

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

    int n;
    for (cin >> n; n--;) {
        int x;
        cin >> x;
        a[x]++;
    }
    for (int i = 1; i < N; i++) if (a[i]) {
        for (int j = i * 2; j < N; j += i)
            a[j] = 0;
    }
    cout << count(a + 1, a + N, 1) << '\n';
    return 0;
}


Measured memory_bytes: 7556
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string s; cin >> s;
	string t = "CODEFESTIVAL2016";
	int ans = 0;
	for (int i = 0; i < s.length(); ++i)
		if (s[i] != t[i])
			++ans;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3656
h,w = map(int,input().split())
x = []
for i in range(h):
    x.append(input())

l = [[0]*w for i in range(h)]
r = [[0]*w for i in range(h)]
u = [[0]*w for i in range(h)]
d = [[0]*w for i in range(h)]

for i in range(h):
    c = 0
    for j in range(w):
        if x[i][j] == '.':
            l[i][j] = c
            c += 1
        else: c=0


for i in range(h):
    c = 0
    for j in range(w):
        if x[i][w-1-j] == '.':
            r[i][w-1-j] = c
            c += 1
        else: c=0

for i in range(w):
    c = 0
    for j in range(h):
        if x[j][i] == '.':
            u[j][i] = c
            c += 1
        else: c=0

for i in range(w):
    c = 0
    for j in range(h):
        if x[h-1-j][i] == '.':
            d[h-1-j][i] = c
            c += 1
        else: c=0

ans = 0
for i in range(h):
    for j in range(w):
        c = l[i][j]+r[i][j]+u[i][j]+d[i][j]
        if x[i][j]=='.':c+=1
        ans = max(ans,c)

print(ans)

Measured memory_bytes: 179204
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main() {
  int N;
  while (1) {
	cin >> N;
	if (N == 0)return 0;

	int table[21][21];
	memset(table, 0, sizeof(table));
	for (int i = 0; i < N; i++) {
	  int a, b;
	  cin >> a >> b;
	  table[a][b] = 1;
	}
	int M;
	char c;
	int d;
	int x=10, y=10;
	int cnt=0;
	cin >> M;
	for (int i = 0; i < M; i++) {
	  cin >> c >> d;
	  for (int j = 0; j < d; j++) {
		switch (c) {
		case 'N':y += 1;
		  break;
		case 'E':x += 1;
		  break;
		case 'S':y -= 1;
		  break;
		case 'W':x -= 1;
		  break;
		}
		if (table[x][y] == 1) {
		  table[x][y] = 0;
		  cnt++;
		}
	  }
	}
	if (cnt == N) {
	  cout << "Yes" << endl;
	}
	else cout << "No" << endl;
  }
}

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;




int main() {
	int n, q;
	string s;

	cin >> n >> s >> q;

	vector<set<int>> v(26);
	for (int i = 0; i < n;i++) {
		v[s[i] - 'a'].insert(i);
	}

	

	for (int i = 0; i < q;i++) {
		int a;
		cin >> a;
		if (a == 1) {
			int id;
			char c;
			
			cin >> id >> c;
			id--;
			int num = s[id] - 'a';
			s[id] = c;
			c -= 'a';
			
			v[num].erase(id);
			v[c].insert(id);
			

		}
		else {
			int l,r;
			cin >> l >> r;
			l--;
			r--;
			int cnt = 0;
			for (int j = 0; j < 26; j++) {
				
				auto it = v[j].lower_bound(l);
				

				if (it!=v[j].end() && *it <= r) {
					
					cnt++;
				}
			}
			cout << cnt << endl;
		}
	}
	



}



Measured memory_bytes: 24196
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());

        var ans = (N % 10) switch
        {
            0 => "pon",
            1 => "pon",
            2 => "hon",
            3 => "bon",
            4 => "hon",
            5 => "hon",
            6 => "pon",
            7 => "hon",
            8 => "pon",
            9 => "hon",
            _ => ""
        };

        WriteLine(ans);
    }
}

Measured memory_bytes: 27284
import sys
from collections import Counter
from itertools import combinations
n = int(sys.stdin.readline().strip())
s_ls = []
cnt = Counter()
for i in range(n):
    s = sys.stdin.readline().strip()
    cnt.update(s[0])
_sum = 0
for combi in combinations("MARCH", 3):
    score = 1
    for c in combi:
        score *= cnt[c]
    _sum += score
print(_sum)

Measured memory_bytes: 3316
while 1:
  H,W = map(int,raw_input().split())
  if H == 0 and W == 0:
    break

  for i in range(H):
    if i%2 == 0:
      if W%2 == 0:
        print "#."*(W/2)
      else:
        print "#."*(W/2) + "#"
    else:
      if W%2 == 0:
        print ".#"*(W/2)
      else:
        print ".#"*(W/2) + "."
  print ""

Measured memory_bytes: 6436
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

int s[1024];

int main(void){
  int n;
  reps(i,1,999){
    int sum = i;
    reps(j,i+1,1000){
      sum += j;
      if( sum > 1000)break;
      s[sum]++;
    }
  }

  while(cin >> n,n){
    cout << s[n] << endl;
  }


  return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <algorithm>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a,b) (((a)-(b))>0?((a)-(b)):((b)-(a)))

using namespace std;

int main(){
	int K; cin >> K;
	bool d[K];	// �]�肪���ꂽ��
	rep(i,0,K) d[i]=false;
	
	int x=7;
	rep(i,1,2*K){
		x = x%K;
		if( x==0 ){
			cout << i;
			break;
		}
		if( d[x]==true || i==2*K-1 ){
			cout << "-1";
			break;
		}
		d[x]=true;
		x = (x*10)+7;
	}
	
	return 0;
}

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

int main(int argc, char *argv[]) {
  char str[12];
  int i;
  int len;
  int x, y;

  scanf("%s", str);
  len = strlen(str);

  for(i=2; i<len; i++) {
    x = (str[i-2] - '0') * 100 + (str[i-1] - '0') * 10 + str[i] - '0';
    if(i==2) {
      y = x;
    }
    if(abs(x - 753) < abs(y - 753)) {
      y = x;
    }
  }
  printf("%d\n", abs(753-y));
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	string s; cin >> s; int out = 0;
	int n = s.length();
	bool v[4];
	fill(v, v + 4, false);
	int now = 0;
	rep(i, n) {
		if (s[i] == 'R') {
			now = (now + 1) % 4;
			v[now] = true;
		}
		else {
			now = (now + 3) % 4;
		}
		if (now == 0) {
			bool add = true;
			rep(j, 4) {
				if (!v[j])add = false;
			}
			if (add) {
				out++;
			}
			fill(v, v + 4, false);
		}
	}
	cout << out << endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define el cout<<endl;
#define flog(n) 31-__builtin_clz((n))
#define clog(n) 32-__builtin_clz((n)-1)
#define fori(i,a,b) for(int i=(a);i<=(b);i++)
#define forib(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(n) fori(asdasdasd_RaNdOm_VaRiAbLe_NaMe_asdasdasd,1,(n))

using ui=unsigned int;
using ll=long long; using pi=pair<int,int>;
#define vec vector
using vb=vec<bool>; using vc=vec<char>; using vs=vec<string>; using vi=vec<int>; using vl=vec<ll>; using vpi=vec<pi>;
using sb=set<bool>; using sc=set<char>; using ss=set<string>; using si=set<int>; using sl=set<ll>; using spi=set<pi>;

void solve() {
    int k; cin>>k;
    string s; cin>>s;
    if(s.size()<=k){
        cout<<s<<" ";
    }else{
        cout<<s.substr(0,k)<<"... ";
    }
}

int main() {
    if(false){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    }
    int t=1;
    //cin>>t;
    rep(t) solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

struct custom_compare {
  bool operator()(const pair<ll, int>& lhs, const pair<ll, int>& rhs) {
    return lhs.first < rhs.first;
  }
};

int main(int argc, char* argv[]) {
  int N;
  vector<ll> part_sum;
  ll ans = LLONG_MAX;

  cin >> N;

  part_sum.resize(N+1);

  part_sum[0] = 0;
  FOR(i, N) {
    int tmp;

    cin >> tmp;

    part_sum[i+1] = part_sum[i] + tmp;
  }

  FOR(i, N-1) {
    ll x = abs(part_sum[N] - 2 * part_sum[i+1]);
    if (x < ans)
      ans = x;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long ul;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "OK\n";
[[maybe_unused]] const string no = "NG\n";
[[maybe_unused]] const double pi = acos(-1);

//....................................................................................................................//



int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(10);
    ll a, b, n;
    cin >> a >> b >> n;
    if (n + 1 >= b) {
        ll t = n / b;
        ll x = (t + 1) * b - 1;
        cout << floor(a * x * 1.0/b) - a*floor(x*1.0/b);
    } else {
        cout << floor(a * n * 1.0 / b);
    }
    return 0;
}

Measured memory_bytes: 3256
#include<stdio.h>
#include<math.h>
int main()
{
  int N,a[100000],b=0;
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
      scanf("%d",&a[i]);
  }
  a[0]=a[1];
  if(N==1){
      printf("Yes");
  }
  for(int i=N;i>=2;i--){
  if(a[i-1]-a[i]==1){
      a[i-1]=a[i-1]-1;
  }else if(a[i-1]-a[i]>1){
       i=1;
  }
  if(i==2){
      printf("Yes");
  }else if(i==1){
      printf("No");
  }
  }
return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c;
  in3(a, b, c);
  if((100 * a + 10 * b + c) % 4 == 0)
    out("YES");
  else
    out("NO");
  memi;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
bool flag=0;
int main()
{
    cin>>s;
    for(int i=0;i<=s.size()-1;i++)
    {
        if(flag==0&&s[i]=='C')
        {
            flag=1;
        }
        if(flag==1&&s[i]=='F')
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
	int i, j, k, l;
	int a, b;

	cin >> a >> b;

	if (2*b - 1 <= a)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int sum_a(int *A, int start, int end) {
  int sum = 0;
  for (int i=start; i<end; i++) sum += A[i];
  return sum;
}

int main() {
  int N;
  map<int, int> mp;
  cin >> N;
  if (N <= 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i=2; i<=N; i++) {
    int n = i;
    for (int j=2; j<=sqrt(i); j++) {
      if (n % j == 0) {
        while (n % j == 0) {
          n = n / j;
          mp[j]++;
        }
      }
    }
    if (n >= 2) mp[n]++;
  }
  // [3, 5, 15, 25, 75]
  int div_num[5] = {}, ans=0, tmp;
  for (auto& t : mp) {
    if (t.second >=74) div_num[4]++;
    else if (t.second >=24) div_num[3]++;
    else if (t.second >=14) div_num[2]++;
    else if (t.second >= 4) div_num[1]++;
    else if (t.second >= 2) div_num[0]++;
  }
  ans += div_num[4]; // 75 * 1
  tmp = (sum_a(div_num, 3, 5)) * (sum_a(div_num, 0, 5) - 1);
  if (tmp > 0) ans += tmp; //25 * 3
  tmp = (sum_a(div_num, 2, 5)) * (sum_a(div_num, 1, 5) - 1);
  if (tmp > 0) ans += tmp; //15 * 5
  tmp = (sum_a(div_num, 1, 5)*(sum_a(div_num, 1, 5)-1) / 2) * (sum_a(div_num, 0, 5) - 2);
  if (tmp > 0) ans += tmp; //5 * 5 * 3
  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() {
  int Ans=0;
  int A; cin >>A;
  //int B; cin >>B;
  if(A<600) {
    Ans=8;
  }else if(A<800){
    Ans=7;
  }else if(A<1000){
    Ans=6;
  }else if(A<1200){
    Ans=5;
  }else if(A<1400){
    Ans=4;
  }else if(A<1600){
    Ans=3;
  }else if(A<1800){
    Ans=2;
  }else if(A<2000){
    Ans=1;
  }
  cout << Ans << '\n';
  return 0;
}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n;
    cin >> n;
    vector<int> a(n);
    roop(i, n) cin >> a[i];

    int ans = 0;
    roop(i, n) ans ^= a[i];

    cout << (!ans ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N = int(input())
S = input()
Rs = S.count('R')
Ws = N - Rs

if Rs == 0 or Ws == 0:
	print(0)
	sys.exit()

C = list(S)

i = 0
j = N-1
ops = 0

while i < j:
	while i < N and C[i] == 'R': i += 1
	while j >= 0 and C[j] == 'W': j -= 1

	if i < j:
		C[i], C[j] = C[j], C[i]
		ops += 1

print(ops)


Measured memory_bytes: 77360
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

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

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> M(H);
    rep(i, H) cin >> M[i];

    int ans[H][W];
    rep(i, H) {
        rep(j, W) {
            int c = 0;
            reps(-1, k, 2) {
                reps(-1, l, 2) {
                    if (k == 0 && l == 0) continue;
                    if (0 <= i + k && i + k < H && 0 <= j + l && j + l < W) {
                        if (M[i + k][j + l] == '#') c++;
                    }
                }
            }
            ans[i][j] = c;
        }
    }

    rep(i, H) {
        rep(j, W) {
            if (M[i][j] == '.') M[i][j] = '0' + ans[i][j];
        }
        cout << M[i] << endl;
    }
}


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

int main(){
  string s;
  vector<vector<int> > field;
  while(getline(cin, s)){
    replace(s.begin(), s.end(), ',', ' ');
    int n;
    stringstream ss;
    ss << s;
    vector<int> v;
    while(ss >> n){
      v.push_back(n);
    }
    field.push_back(v);
  }
  
  int dp[101][101];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = field[0][0];
  for(int i = 1 ; i < field.size() ; i++){
    for(int j = 0 ; j < field[i].size() ; j++){
      if(i <= field.size() / 2){
	dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + field[i][j];
      }
      else{
	dp[i][j] = max(dp[i-1][j], dp[i-1][j+1]) + field[i][j];
      }
    }
  }  
  cout << dp[field.size()-1][0] << endl;
  return 0;
}

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

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

  long long m0 = 0;
  long long mk2 = 0;
  for ( int i =1; i <= n; i++ ) {
    m0 += ( i%k == 0 ) ? 1 : 0;
    mk2 += ( i%k == k/2 ) ? 1 : 0;
  }

  long long ans = ( k%2 != 0 ) ? m0*m0*m0 : m0*m0*m0 + mk2*mk2*mk2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#prdさんから参照
#最低でも1つはピラミッド内の座標がないと解けない？

N = int(input())
#これが唯一の事実データ
src = [tuple(map(int,input().split())) for i in range(N)]
 
INF = float('inf')
#ここ以降でかかれてあるcx,cyはあくまで頂上であると仮定しているだけで条件と合わない場合に不適切な座標となる。
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        maxh = INF
        for x,y,h in src:
            if h > 0:
                tmp = h + abs(x-cx) + abs(y-cy)
                if tmph is None:
                    tmph = tmp
                else:
                    if tmp != tmph:
                        break
                if tmph > maxh:
                    break
            else:
                #ここでmaxhがtmphよりも小さくなってしまった場合、hは0だから頂点からのxとyの差の和がtmphはなければならないのに、それを下回っているため
                #データx,yは絶対的な値なのでcx,cyが間違っていることになる。それを判定するのが上のtmph > maxh の時となり
                maxh = min(maxh, abs(x-cx) + abs(y-cy))
        else:
            for x,y,h in src:
                if max(tmph - abs(x-cx) - abs(y-cy), 0) != h:
                    break
            else:
                print(cx,cy,tmph)
                exit()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
template <typename T>
using V = vector<T>;
template <typename S, typename T>
using P = pair<S, T>;
using ll = long long;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define NREP(i, n) FOR(i, 1, n + 1)
// Natural REP runs from 1 to n 

/* ---------- ここまでマクロ ----------- */

ll N;
V<ll> A(200010), sum(200010, 0);


// 区間[b, e]をできるだけ均等に2等分したときの、
// 各配列の総和をペアで返す
P<ll, ll> divide(ll b, ll e) {
    ll ok = b, ng = e;
    ll ds = sum[e] - sum[b - 1];

    // 二分探索で[b, ok]の和が[b, e]の半分以下になる
    // 最大のokを探す
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll ps = sum[mid] - sum[b - 1];
        if (ps * 2 <= ds) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    // P <= Qの場合
    P<ll, ll> ret1 = make_pair(sum[ok] - sum[b - 1], sum[e] - sum[ok]);
    // P > Qの場合
    P<ll, ll> ret2 = make_pair(sum[ok + 1] - sum[b - 1], sum[e] - sum[ok + 1]);
    
    // 両者を比較
    if (ret1.first - ret1.second > ret2.second - ret2.first) {
        return ret1;
    } else {
        return ret2;
    }
}


// [0, itr)と[itr, N)に分割したときの最適解
ll cut(ll itr) {
    V<P<ll, ll>> psum(2);
    
    psum[0] = divide(1, itr);        // (P, Q)
    psum[1] = divide(itr + 1, N);    // (R, S)

    V<ll> elem;
    // psumを統合する
    
    for (auto p : psum) {
        elem.push_back(p.first);
        elem.push_back(p.second);
    }

    sort(elem.begin(), elem.end());
    return elem.back() - elem.front();
    // 最大値と最小値の差を返す(B問題その2を参照)
}


int main() {
    cin >> N;
    NREP(i, N) {
        cin >> A[i];
        sum[i] = sum[i - 1] + A[i];
        // 同時に累積和も計算
    }

    ll ans = sum[N];

    FOR(i, 2, N - 1) {
        // 全ての2分割を試す(ただし分割後の要素数>=2)
        ans = min(ans, cut(i));
    }

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

Measured memory_bytes: 3328
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), C(N-1);

    for(int i=0; i<N; i++) {
        cin >> A[i]; A[i]--;
    }
    for(int i=0; i<N; i++) {
        cin >> B[i];
    }
    for(int i=0; i<N-1; i++) {
        cin >> C[i];
    }

    int ans = 0;
    for(int i=0; i<N; i++) {
        ans += B[ A[i] ];
        if(i > 0 and A[i] - A[i-1] == 1) ans += C[ A[i-1] ];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/aising2020/tasks/aising2020_a
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++) {
		if (i%d==0)   ++ans;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

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

  ll n, p;
  cin >> n >> p;

  if(n == 1) {
    cout << p << endl;
    return 0;
  }
  if(n > 40) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = 1;
  ll idx = 1;
  while(1) {
    ll tmp = 1;
    REP(i, n) tmp *= idx;
    if(p % tmp == 0) {
      chmax(ans, idx);
    }
    if(tmp >= p) {
      break;
    }
    idx++;
  }
  cout << ans << endl;

//  ll t = p;
//  ll ans = 1;
//  for(ll i=2; i*i<=t; ++i) {
//    ll cnt = 0;
//    while(p%i==0) {
//      p /= i;
//      cnt++;
//    }
//    if(cnt >= n) ans *= cnt / n * i;
//  }
//  if(p != 1) {
//    if(n == 1) ans *= p;
//  }
//
//  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 1000000007
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
using namespace std;
typedef long long tint;
typedef pair<tint, tint> pii;
typedef vector<tint> vi;
typedef vector<vi> vvi;

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

int main()
{
	int n;
	cin >> n;
	
	int d = gcd(n, 360);
	cout << 360/d << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define outl(x) cout << x << endl
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,y;
	cin >> n >> y;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n - i;j++){
			if((y - i * 1000 - j * 5000) % 10000 == 0 && (y - i * 1000 - j * 5000) / 10000 == n - i - j){
				cout << n - i - j << " " << j << " " << i << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int w,n,a,b,i;
	int A[50];
	int t;
	scanf("%d\n", &w);
	scanf("%d\n", &n);

	for(i=0;i<w;i++) {
		A[i+1] = i+1;
	}
	
	for(i=0;i<n;i++) {
		scanf("%d,%d\n", &a, &b);
		t = A[a];
		A[a] = A[b];
		A[b] = t;
	}
	
	for(i=0;i<w;i++) {
		printf("%d\n", A[i+1]);
	}
	
	return 0;
}

Measured memory_bytes: 600
#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

my @c;
{
    my $in = <STDIN>;
    @c = split(" ", $in);
}
my %h;
for my $i (@c)
{
    $h{$i} = 0;
}

print "YES\n" if $n == keys %h;
print "NO\n" unless $n == keys %h;

Measured memory_bytes: 50596
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct edge {
    int v;
    int cost;
    int time;
    edge() {}
    edge(int v, int c, int t) : v(v), cost(c), time(t) {}
};

int N, M, S;
vector<vector<edge>> G;
vector<int> C, D;
vector<vector<ll>> cost;
const int smax = 2500;

void dijkstra() {
    if (S >= smax) S = smax;
    priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> Q;
    Q.push({0, {0, S}});
    cost[0][S] = 0;

    while(!Q.empty()) {
        auto q = Q.top(); Q.pop();
        int v = q.second.first;
        ll t = q.first;
        ll s = q.second.second;
        if (cost[v][s] < t) continue;

        if (s + C[v] <= smax) {
            ll nt = t + D[v];
            ll ns = s + C[v];
            if (cost[v][ns] > nt) {
                cost[v][ns] = nt;
                Q.push({nt, {v, ns}});
            }
        }

        for (auto e : G[v]) {
            if (s < e.cost) continue;
            ll ns = s - e.cost;
            ll nt = t + e.time;
            if (cost[e.v][ns] > nt) {
                cost[e.v][ns] = nt;
                Q.push({nt, {e.v, ns}});
            }
        }
    }
}

int main() {
    cin >> N >> M >> S;
    G.resize(N);
    REP(i, 0, M) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--; v--;
        G[u].push_back(edge(v, a, b));
        G[v].push_back(edge(u, a, b));
    }

    C.resize(N); D.resize(N);
    REP(i, 0, N) cin >> C[i] >> D[i];

    cost.resize(N, vector<ll>(smax + 1, 1LL << 60));
    dijkstra();

    REP(i, 1, N) {
        ll ans = 1LL << 60;
        for (auto elm : cost[i]) ans = min(ans, elm);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 7288
import java.util.Scanner;
/**
 * @author kawakami
 *
 */
class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner as = new Scanner(System.in);
         
        int n=as.nextInt();
        long tr,sum;
        int j = 0,k = 0;
        long jug[] = new long[n];
         
         
         
        jug[0]=as.nextInt();
        sum=jug[0];
         
         
        for(int i=1;i<n;i++){       //????¨????????¨????
            jug[i]=as.nextInt();
            sum=sum+jug[i];
        }
        while(j!=1){
            j=1;
            for(k = 0;k<n-1;k++){//?????????????´?????°????????????????????????????
                 
                if(jug[k]>jug[k+1]){
                    tr=jug[k];
                    jug[k]=jug[k+1];
                    jug[k+1]=tr;
                    j=0;
                }
            }
             
             
        }
        System.out.println(jug[0]+" "+jug[k]+" "+sum);
 
    }
 
}

Measured memory_bytes: 41608