akhauriyash/Code-Regression huggingface dataset:
S = input()

if S[0] != "A":
    print("WA")
    exit()

if S[1].isupper():
    print("WA")
    exit()

if S[-1].isupper():
    print("WA")
    exit()

ok = False
for i in range(2, len(S) - 1):
    if S[i].isupper():
        if ok:
            print("WA")
            exit()
        else:
            ok = True
if ok is False:
    print("WA")
else:
    print("AC")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int n;
int l[105];
int main(){
	cin >> n;
	FOR(i,0,n) cin >> l[i];
	int tot = 0;
	FOR(i,0,n) tot += l[i];
	FOR(i,0,n){
		if (l[i] >= tot-l[i]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

int main(){
    int n; cin >> n;
    vector<vector<int>> abcs(n, vector<int>(3));
    for(int i=0; i<n; ++i){
        for(int j=0; j<3; ++j){
            cin >> abcs[i][j];
        }
    }
    vector<int> res(3);
    for(int i=0; i<n; ++i){
        vector<int> next(3);
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; ++k){
                if(j==k) continue;
                next[j]=max(next[j], res[k]);
            }
            next[j]+=abcs[i][j];
        }
        res.swap(next);
    }
    int ans=0;
    for(int i=0; i<3; ++i){
        ans=max(ans, res[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
# -*- coding: utf-8 -*-
n, m = map(int,input().split())
h = [int(i) for i in input().split()]
ab = []
for i in range(m):
    ab.append([int(i) for i in input().split()])

#tmp1 = len(ab)
ab = list(map(list, set(map(tuple, ab))))
tmp2 = len(ab)

#print(ab, tmp2)
ans = 0
flag = [0 for _ in range(n)]
count = [0 for _ in range(n)]
for i in range(tmp2):
    #print(i, ab[i][0], ab[i][1])
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        count[ab[i][0]-1] += 1
        count[ab[i][1]-1] += 1
        flag[ab[i][1]-1] += 1
    elif h[ab[i][0]-1] > h[ab[i][1]-1]:
        count[ab[i][0]-1] += 1
        count[ab[i][1]-1] += 1
        flag[ab[i][0]-1] += 1
    else:
        count[ab[i][0]-1] += 1
        count[ab[i][1]-1] += 1
#print(count)
#print(flag)
for i in range(n):
    if flag[i] == count[i]:
        ans += 1
        #print(i)
print(ans)


Measured memory_bytes: 130120
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

answer="War"
Z_x=max(x)+1
Z_y=min(y)

if Z_x<=Z_y:
    for z in range(Z_x,Z_y+1):
        if X<z<=Y:
            answer="No War"
            break
print(answer)

Measured memory_bytes: 3064
#include <stdio.h>
int main (){
	int c, d;
	scanf ("%d %d", &c, &d);
	if (c % d == 0 || d % c == 0){
		printf ("%d", c + d);
	}else{
		printf ("%d", d - c);
	}
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>

int main(){
int N,i,j,v,a;
int *A;


scanf("%d",&N);
A = (int *)malloc(N * sizeof(int));
for(i=0;i<N;i++)
scanf(" %d",&A[i]);






// insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
  for (i=0; i<=N-1;i++ ){
    v = A[i];
    j = i - 1;

     while( j >= 0 && A[j] > v){
           A[j+1] = A[j];
           j--;
           A[j+1] = v;
     

     }
   a = i;
   for(i=0;i<N;i++){
   printf("%d",A[i]);
        if(i != N-1) printf(" ");
               
   }
   printf("\n");
   i = a;
  }



free(A);
return 0;

}


Measured memory_bytes: 2036
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    static long[] fact = new long[100];
        public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int m = sc.nextInt();
            if(n<=m){
                System.out.println("unsafe");
            }else{
                System.out.println("safe");
            }
    }
    
}


Measured memory_bytes: 35792
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int m;
  cin>>m;
  for(h=0;h<m;h++){
    int n;
    cin>>n;
    bool a[10001][2];
    memset(a,0,10001*2);
    for(i=0;i<2;i++){
      char s;
      cin>>s;
      if(s=='Y')
	a[0][i]=1;
      for(j=1;j<n;j++){
	char s,t;
	cin>>s>>t;
	if(s=='Y'||t=='Y')
	  a[j][i]=1;
      }
      cin>>s;
      if(s=='Y')
	a[n][i]=1;
    }
    unsigned b[10001][2];
    memset(b,-1,sizeof(b));
    if(0){
    }else if(a[0][0]&&a[0][1]){
      b[1][0]=4;
      b[1][1]=3;
    }else if(a[0][0]){
      b[1][0]=2;
      b[1][1]=2;
    }else if(a[0][1]){
      b[1][0]=4;
      b[1][1]=3;
    }else{
      b[1][0]=1;
      b[1][1]=2;
    }
    for(i=1;i<n;i++){
      if(0){
      }else if(a[i][0]&&a[i][1]){
	b[i+1][0]=min(b[i+1][0],b[i][0]+4);
	b[i+1][0]=min(b[i+1][0],b[i][1]+3);
	b[i+1][1]=min(b[i+1][1],b[i][0]+3);
	b[i+1][1]=min(b[i+1][1],b[i][1]+3);
      }else if(a[i][0]){
	b[i+1][0]=min(b[i+1][0],b[i][0]+2);
	b[i+1][0]=min(b[i+1][0],b[i][1]+2);
	b[i+1][1]=min(b[i+1][1],b[i][0]+2);
	b[i+1][1]=min(b[i+1][1],b[i][1]+2);
      }else if(a[i][1]){
	b[i+1][0]=min(b[i+1][0],b[i][0]+4);
	b[i+1][0]=min(b[i+1][0],b[i][1]+3);
	b[i+1][1]=min(b[i+1][1],b[i][0]+3);
	b[i+1][1]=min(b[i+1][1],b[i][1]+2);
      }else{
	b[i+1][0]=min(b[i+1][0],b[i][0]+1);
	b[i+1][0]=min(b[i+1][0],b[i][1]+2);
	b[i+1][1]=min(b[i+1][1],b[i][0]+2);
	b[i+1][1]=min(b[i+1][1],b[i][1]+1);
      }
    }
    unsigned mn=-1;
    if(0){
    }else if(a[n][0]&&a[n][1]){
      mn=min(mn,b[n][0]+3);
      mn=min(mn,b[n][1]+2);
    }else if(a[n][0]){
      mn=min(mn,b[n][0]+1);
      mn=min(mn,b[n][1]+1);
    }else if(a[n][1]){
      mn=min(mn,b[n][0]+3);
      mn=min(mn,b[n][1]+2);
    }else{
      mn=min(mn,b[n][0]);
      mn=min(mn,b[n][1]+1);
    }
    cout<<mn<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
  {
  int r,d,x,a[11];
  cin>>r>>d>>x;
  a[0]=x;
  for(int i=0;i<=10;i++)
  {
    a[i+1]=r*a[i]-d;

  }
  for(int i=1;i<=10;i++)
    cout<<a[i]<<endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
K = int(input())

def count(S, K):
    S += S * (K-1)
    tmp = ''
    cnt = 0
    for i in range(len(S)):
        if S[i] == tmp:
            cnt += 1
            tmp = 'X'
        else:
            tmp = S[i]
    return cnt

cnt1 = count(S,1)
cnt21 = count(S, 2) - cnt1
cnt32 = count(S, 3) - count(S, 2)

print(cnt1 + cnt21*(K//2) + cnt32*((K-1)//2))

Measured memory_bytes: 3064
def conv(sec):
    h = sec // (60 * 60)
    m = (sec - h * (60 * 60)) // 60
    s = sec - m * 60 - h * (60 * 60) 
    return ":".join([str(h), str(m), str(s)])

# inp = list(map(int, input().split()))
print(conv(int(input())))

Measured memory_bytes: 6452
#include<iostream>
using namespace std;
#define abs(x) ((x>0)?x:(-(x)))

int px[900001],py[900001];
int d[900001];

int main(){
	int h,w,D; cin >> h >> w >> D;
	int a;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a;
			px[a]=i;
			py[a]=j;
		}
	}
	for(int i=D+1;i<=h*w;i++)
		d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
	int q; cin >> q;
	int l,r;
	for(int i=0;i<q;i++){
		cin >> l >> r;
		cout << d[r]-d[l] << endl;
	}
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << ENDL;
}

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

namespace ABC118D
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            var N = ss.Next(int.Parse);
            var M = ss.Next(int.Parse);
            var A = ss.Next(int.Parse, M);

            var match = new[] {114514, 2, 5, 5, 4, 5, 6, 3, 7, 6}.ToArray();
            var dp = new BigInteger[N + 10];
            for (var i = 1; i < N + 10; i++) dp[i] = -1;

            for (var i = 0; i < N; i++)
            {
                if (dp[i] == -1) continue;

                foreach (var a in A)
                {
                    dp[i + match[a]] = BigInteger.Max(dp[i + match[a]], dp[i] * 10 + a);
                }
            }

            sw.WriteLine(dp[N]);
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = { ' ' };
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public bool EndOfStream { get { return streamReader.EndOfStream && index >= line.Length; } }

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (EndOfStream) throw new EndOfStreamException();
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

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

int W,H;
int divW[1501*1000];
int divH[1501*1000];
int w[1502];
int h[1502];

main(){
	int i,j,k;
	while(cin>>H>>W, H){
		fill(divW, divW+W*1000, 0);
		fill(divH, divH+H*1000, 0);
		for(i=1;i<=H;i++){
			cin>>h[i];
			h[i] += h[i-1];
			for(j=0;j<i;j++) divH[h[i]-h[j]]++;
		}
		for(i=1;i<=W;i++){
			cin>>w[i];
			w[i] += w[i-1];
			for(j=0;j<i;j++) divW[w[i]-w[j]]++;
		}
		int ans = 0;
		for(i=0;i<=w[W]&&i<=h[H];i++) ans+= divH[i]*divW[i];
		cout<<ans<<endl;
	}
	return 0;
}

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


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    int a[n][m];
    int ans = INF;
    rep(i,n) {
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    rep(s,1<<n) {
        int cost = 0;
        vector<int> d(m);
        rep(i,n) {
            if (s>>i&1) {
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if (d[j] < x) ok = false;
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    int n;
    long k;
    long[] as;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextLong();
        as = new long[n];
        for (int i = 0; i < n; i++)
            as[i] = sc.nextLong();
    }

    private void solve() {
        long gcd = as[0];
        long max = as[0];
        for (int i = 1; i < n; i++) {
            gcd = gcd(as[i], gcd);
            max = Math.max(max, as[i]);
        }
        if (k <= max && k % gcd == 0)
            System.out.println("POSSIBLE");
        else
            System.out.println("IMPOSSIBLE");
    }

    private long gcd(long x, long y) {
        if (y == 0)
            return x;
        return gcd(y, x % y);
    }
}


Measured memory_bytes: 49744
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

	int n;
	cin >> n;

	vector<int> points(n, 0);

	for(int i = 0; i < n * (n - 1) / 2; ++i) {
		int a, b, score_a, score_b;
		cin >> a >> b >> score_a >> score_b;
		if(score_a > score_b) {
			points[a - 1] += 3;
		}
		else if(score_a == score_b) {
			++points[a - 1];
			++points[b - 1];
		}
		else {
			points[b - 1] += 3;
		}
	}

	vector<int> tmp(points);
	sort(tmp.rbegin(), tmp.rend());

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(points[i] == tmp[j]) {
				cout << j + 1 << endl;
				break;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1220
from collections import defaultdict
total = defaultdict(int)

n = int(input())
red = [input() for _ in range(n)]

m = int(input())
blue = [input() for _ in range(m)]

words = set(red) | set(blue)

for key in red:
    total[key] += 1

for key in blue:
    total[key] -= 1

print(max(max(total.values()), 0))


Measured memory_bytes: 3316
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 
const int MAX_N = 200005;

ll a[MAX_N],b[MAX_N];

int main(){
  int N; scanf("%d",&N);
  rep(i,N) scanf("%lld",a+i);
  rep(i,N) scanf("%lld",b+i);
  vl a_2(N),b_2(N);
  ll ans = 0LL;
  rep(k,30){
    ll cnt = 0;
    rep(i,N) if((a[i]&(1LL<<k))!=0LL) cnt += ll(N);
    rep(i,N) if((b[i]&(1LL<<k))!=0LL) cnt += ll(N);
    if(k!=0){
      rep(i,N) a_2[i] = a[i] & ((1LL<<k)-1LL);
      rep(i,N) b_2[i] = b[i] & ((1LL<<k)-1LL);
      sort(ALL(a_2)); sort(ALL(b_2));
      rep(i,N){
        ll num = ll(N) - ll(lower_bound(b_2.begin(),b_2.end(),(1LL<<k)-a_2[i]) - b_2.begin()); 
        dump(num);
        cnt += num;
      }
    }
    if(cnt%2) ans ^= (1<<k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc =new Scanner(System.in);

        int m[]=new int[50];
        int f[]=new int[50];
        int r[]=new int[50];
        int count=0;
        
        while(true){
        m[count]=sc.nextInt();
        f[count]=sc.nextInt();
        r[count]=sc.nextInt();
        if(m[count]+f[count]+r[count]==-3) break;
        count++;
        }
        
        for(int i=0;i<count;i++)
         if(m[i]==-1||f[i]==-1)
           System.out.println("F");
         else if(m[i]+f[i]>=80)
            System.out.println("A");
         else if(m[i]+f[i]>=65)
            System.out.println("B");
         else if(m[i]+f[i]>=50||m[i]+f[i]>=30&&r[i]>=50)
            System.out.println("C");
         else if(m[i]+f[i]>=30)
            System.out.println("D");
         else
            System.out.println("F");
}
}


Measured memory_bytes: 26312
N = int(input())

A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

count = 0
for n in range(N):
    count += B[A[n] - 1]
    if n != N - 1:
        if A[n + 1] - 1 == A[n]:
            count += C[A[n] - 1]
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define Mx 4000000
using namespace std;
const int p=1e9+7;
int n,k;
int f[2010][2010],a[4000010],i_a[4000010];
int calc(int x,int y){ return (((a[y]*i_a[x])%p)*i_a[y-x])%p; }
int power(int x,int y)
{
    int s1=1,s2=x;
    while(y)
	{
        if(y%2)s1*=s2,s1%=p;
        s2*=s2;
        s2%=p;
        y/=2;
    }
    return s1;
}
signed main()
{
    cin>>n>>k;
    if(k==1)
	{
		cout<<1;
		return 0;
	}
    a[0]=1; 
	for(int i=1;i<=Mx;i++)a[i]=(a[i-1]*i)%p;
    i_a[Mx]=power(a[Mx],p-2); 
	for(int i=Mx-1;i>=0;i--)i_a[i]=(i_a[i+1]*(i+1))%p;
    f[0][0]=1;
    for(int i=1;i<=n;i++)
	  for(int j=0;j<=i;j++)
	  {
          f[i][j]=f[i-1][j];
          if(j)f[i][j]+=(f[i][j-1]*(n-j+1)%p*calc(k-2,n-i+(n-j+1)*(k-1)-1)%p)%p;
      }
    cout<<f[n][n];
    return 0;
}

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

using static Input;
using static Util;
class Program
{
    static string S;
    static void INPUT()
    {
        S = NextString();
    }

    static void OUT()
    {
        Console.WriteLine(S == "ABC" ? "ARC":"ABC");
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 17604
# coding: utf-8


def main():
    N = int(input())
    A = list(map(int, input().split()))

    for a in A:
        if a % 2 == 0:
            if a % 3 > 0 and a % 5 > 0:
                return "DENIED"

    return "APPROVED"


print(main())


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

int main(){
  int A, B, C, K; cin >> A >> B >> C >> K;
  bool yes = false;
  
  for (int i=0; i<K; i++){
     for (int j=0; j<K-i; j++){
       int l = K-i-j;
       int postA, postB, postC;
       postA=A*pow(2, i);
       postB=B*pow(2, j);
       postC=C*pow(2, l);
       if (postA < postB && postB < postC){
         yes = true;
       }
     }
  }
  if(yes){ cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}
  
  

Measured memory_bytes: 4092
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

/** 二項係数計算
    (1 ≦ k ≦ n ≦ 107 程度)
*/
class Combination {
public:
    Combination(int64_t max, int64_t mod) : mod_(mod) {
        fac_.resize(max+1);
        inv_.resize(max+1);
        finv_.resize(max+1);

        fac_[0] = fac_[1] = 1;
        finv_[0] = finv_[1] = 1;
        inv_[1] = 1;
        for (int64_t 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;
        }
    }

    int64_t get(int64_t n, int64_t k) const {
        if (n < k) {
            return 0;
        }
        if (n < 0 || k < 0) {
            return 0;
        }
        return fac_[n] * (finv_[k] * finv_[n - k] % mod_) % mod_;
    }

    std::vector<int64_t> fac_;
    std::vector<int64_t> finv_;
    std::vector<int64_t> inv_;

    int64_t mod_;
};


int main()
{
    int64_t H, W, A, B;
    std::cin >> H >> W >> A >> B;

    Combination C(100000*2, DIV1097);

    int64_t ans = 0;
    for (int64_t x = B; x <= W-1; ++x) {
        /*
          下に H-A-1 回, 右にx回移動と、
          下に A-1回, 右にW-1-x回移動の組み合わせ
        */
        ans += C.get(H-A-1+x, x) * C.get(A-1+W-1-x, A-1);
        ans %= DIV1097;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<sstream>
using namespace std;

string itos(int n){
	std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main(){
	int n;
	cin >> n;
	
	int data[10][10] = {0};
	
	for(int i=1;i<=n;++i){
		string s = itos(i);
		int a = '9' - s[0];
		int b = '9' - s[s.size()-1];
		data[a][b]++;
	}
	
	unsigned long long res = 0;
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			res += data[i][j] * data[j][i];
		}
	}
	cout << res <<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;


int main(){
    int N, a[100];
    float ave = 0.0;
    
    cin >> N;
    for (int i=0;i<N;i++) cin >> a[i];
    for (int i=0;i<N;i++) ave += a[i];
    ave /= N;
    
    float min_value = abs(ave-a[0]);
    int min_index = 0;
    for (int i=0;i<N;i++) {
        if (abs(a[i]-ave)<min_value) {
            min_value = abs(a[i]-ave);
            min_index = i;
        }
    }
    
    cout << min_index << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  bool mi=false;
  rep(i,n){
    ll x;
    cin>>x;
    if(x==0){
      cout << 0 << endl;
      return 0;
    }
    if(1000000000000000000/x<ans) {
      mi=true;
    }
    if(!mi)ans*=x;
  }

  if(mi) {
    cout << -1 << endl;
    return 0;
  }

  cout << ans << endl;       
}


Measured memory_bytes: 3636
N,K = map(int,input().split())
p = list(map(int,input().split()))
for i in range(N):
    p[i] = p[i]/2+0.5
ans = [sum(p[0:K])]
for i in range(K,N):
    ans.append(ans[-1]-p[i-K]+p[i])
print(max(ans))


Measured memory_bytes: 24548
#include <stdio.h>
int main(){
    int x,a,b,c;
    scanf("%d%d%d",&x,&a,&b);
   c = b - a;
  if(c<=0){
      printf("delicious");
     return 0;
  }else if(x+1<=c){
       printf("dangerous");
       return 0;
  }else if(c<x+1){
      printf("safe");
     return 0;
  }
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<numeric>
int main() {
	using usize = unsigned int;
	using i64 = long long int;
	usize n, q;
	std::cin >> n >> q;
	std::vector<i64> a(n), x(q), ans(q);
	std::vector<usize> index(q);
	i64 sum = 0;
	for (usize i = n;i--;) {
		std::cin >> a[i];
		if (i % 2 == 0) {
			sum += a[i];
		}
	}
	for (auto &e : x) {
		std::cin >> e;
	}
	std::iota(index.begin(), index.end(), 0);
	std::sort(index.begin(), index.end(),
		[&x](usize l, usize r) {return x[l] > x[r];});
	usize l = 0, r = 0;
	for (const auto i : index) {
		while (r < n&&std::abs(a[l] - x[i]) >= std::abs(a[r] - x[i])) {
			sum -= a[r];
			sum += a[l];
			l += 1;
			r += 2;
		}
		ans[i] = sum;
	}
	for (const auto e : ans) {
		std::cout << e << std::endl;
	}
	return 0;
}


Measured memory_bytes: 4480
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
y = sorted([list(map(int, input().split())) for _ in range(N)])

cnt = 0
for c, d in y:
  for a, b in x:
    if a < c and b < d:
      x.remove([a, b])
      cnt += 1
      break

print(cnt)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define PI 3.141592653589793


int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int ao = (b+c-1)/b; int taka = (a+d-1)/d;
    //cout << taka << " " << ao << endl;
    if(taka>=ao) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;
#define print(v) { cout<<#v<<": [ "; for(auto _ : v) cout<<_<<", "; cout<<"]"<<endl; }

int n;
vector<ll> a;
ll calc(ll x){
    ll res = 0;
    rep(i,n){
        res += abs(a[i]-x);
    }
    return res;
}

int main(void){
    cin>>n;
    a.resize(n);
    rep(i,n){
        cin>>a[i];
        a[i] -= i+1;
    }
    sort(all(a));
    ll l = *min_element(all(a)), r = *max_element(all(a));
    while(l + 10 < r){
        ll m1 = (l*2+r)/3, m2 = (l+r*2)/3;
        ll res1 = calc(m1);
        ll res2 = calc(m2);
        if(res1<res2){
            r = m2;
        }else{
            l = m1;
        }
    }
    ll res = 1e15;
    for(ll x = l; x <= r; x++){
        res = min(calc(x),res);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;



public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int data= sc.nextInt();

		int fmflag=0;
		int fyflag=0;
		int lmflag=0;
		int lyflag=0;
		if((data%100)<13 && (data%100)>0 ) {
			lmflag=1;
			lyflag=1;
		}else {
			lyflag=1;
		}
		if(data/100<13&&(data/100)>0){
			fmflag=1;
			fyflag=1;
		}else {
			fyflag=1;
		}
	if(fmflag==1 && fyflag==1 && lyflag==1 && lmflag==1){
      System.out.println("AMBIGUOUS");
    }else if(fyflag==1 && lmflag==1 ) {
			System.out.println("YYMM");
		}else if(fmflag==1 && lyflag==1) {
			System.out.println("MMYY");
		}else if(fmflag==0 && lmflag==0) {
			System.out.println("NA");
		}

	}
}




Measured memory_bytes: 23764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n;

ll dfs(ll num){
    ll ret = 0;
    if(1 <= num && num <= n){
        bool s = false, f = false, t = false;
        ll m = num;
        while(m > 0){
            if(m%10 == 7) s = true;
            if(m%10 == 5) f = true;
            if(m%10 == 3) t = true;
            m /= 10;
        }
        if(s && f && t) ++ret;
    }
    if(num > n) return 0;
    ret += dfs(num*10 + 7);
    ret += dfs(num*10 + 5);
    ret += dfs(num*10 + 3);
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll ans = dfs(0);
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int numn, numk;
    cin >> numn >> numk;
    string str;
    cin >> str;

    string s = "1";
    string t = "0";

    int max=0;
    //出力するもの

    int number[100000] ={};
    int judge = 1,now = 0,count = 0;

    size_t size = str.length();

    for(int i=0; i<size; i++){
        if(judge == 1){
            if(str.compare(i,1,s) == 0){
                count ++;
            }else{
                number[now]=count;
                now++;
                count = 1;
                judge = 0;
            }
        }else{
            if(str.compare(i,1,t)==0){
                count ++;
            }else{
                number[now]=count;
                now++;
                count = 1;
                judge =1;
            }
        }
    }
    number [now] = count;

    numk = numk *2 +1;

    int current=0;

    for(int i=0;i<size;i++){
        current += number[i];
        if(i>=numk){
            current-=number[i-numk];
        }


        if((current >= max)&&(i%2==0)){
            max = current;
        }
    }
    cout << max << endl;


    return 0;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main(){
     int a,b;
     char op;

     cin >> a >> op >> b;
     while(op!='?'){
          switch (op){
          case '+':
               cout << a+b << endl;
               break;
          case '-':
               cout << a-b << endl;
               break;
          case '*':
               cout << a*b << endl;
               break;
          case '/':
               cout << a/b << endl;
               break;
          }
          cin >> a >> op >> b;
     }
     return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int x[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  sort(all(a));
  reverse(all(a));

  const int inf = -100000;
  vector<int> dp(n + 1, inf);
  dp[0] = 0;
  for (int i = 1; i <= n; i ++) {
    int t = inf;
    for (int j = 0; j < m; j ++) {
      if (i - x[a[j]] >= 0) {
        t = max(t, dp[i - x[a[j]]] + 1);
      }
    }
    dp[i] = t;
  }

  while (n > 0) {
    for (int i = 0; i < m; i ++) {
      if (n - x[a[i]] >= 0) {
        if (dp[n - x[a[i]]] == dp[n] - 1) {
          cout << a[i];
          n -= x[a[i]];
          break;
        }
      }
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
import heapq

n = int(input())
lis = [int(input()) for _ in range(n)]

r, s = heapq.nlargest(2, lis)

if lis.count(r) == 1:
    for x in lis:
        if x == r:
            print(s)
        else:
            print(r)

else:
    for _ in range(n):
        print(r)


Measured memory_bytes: 12552
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s = br.readLine();
    StringBuilder left = new StringBuilder();
    StringBuilder right = new StringBuilder();
    int q = Integer.parseInt(br.readLine());
    int reverse = 0;
    for (int i = 0; i < q; i++) {
      String[] query = br.readLine().split(" ");
      if ("1".equals(query[0])) {
        reverse = (reverse + 1) % 2;
      } else {
        if (("1".equals(query[1]) && reverse == 0) || ("2".equals(query[1]) && reverse == 1)) {
          left.insert(0, query[2]);
        } else {
          right.append(query[2]);
        }
      }
    }
    br.close();
    String str = left.toString() + s + right.toString();
    if(reverse == 0){
      System.out.println(str);
    } else {
      System.out.println(new StringBuilder(str).reverse().toString());
    }
  }
}


Measured memory_bytes: 57488
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  int sum=0;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    sum+=b-a+1;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
ac = [0] * n
wa = [0] * n

for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1] == 0:
        if s == "AC":
            ac[p-1] = 1
        else:
            wa[p-1] += 1

ans1 = sum(ac)
ans2 = 0
for i in range(n):
    if ac[i] == 1:
        ans2 += wa[i]

print(ans1,ans2)

Measured memory_bytes: 45528
a,b = map(int,input().split()) 
li1 = set(map(int,input().split()))
li2 = {1,2,3,4,5,6,7,8,9,0}
nu = list(li1^li2)

i = 1
while True:
    aa = list(str(a))
    aa = [int(x) for x in aa]
    if set(aa).issubset(set(nu)):
        print(a)
        break
    a += i

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

using namespace std;
typedef long long ll;

int main()
{
  ll r,D,x;
  cin>>r>>D>>x;
  for(int i=1;i<=10;i++){
    x=x*r-D;
    cout<<x<<endl;
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t)cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

void Eratosthenes(int N, vector<int> &check){
	for(int i = 0; i < N; i++){
		check[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(check[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				check[i *(j + 2)] = 0;
			}
		}
	}
}

int main(){
    int Q;
    cin>>Q;
    vector<int> left(Q);
    vector<int> right(Q);
    for(int i=0; i<Q; i++) cin>>left[i]>>right[i];
    vector<int> check(100100);
    vector<int> sum(100100,0);

    Eratosthenes(100100,check);

    for(int i=3; i<100100; i++){
        sum[i] = sum[i-1];      
        if(check[i] && check[(i+1)/2]) sum[i]++;
    }

    for(int i=0; i<Q; i++){
        cout<<(sum[right[i]]-sum[left[i]-1])<<endl;   
    }

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define r2 1.41421356237
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  ll n,x,m,gg;
  cin>>n>>x>>m;
  ll sa=0;
  ll c=1;
  set<ll>s;
  vector<ll>v;
  v.pb(0);
  v.pb(x);
  s.insert(x);
  for(int i=2;i<=n;i++) {
  	x=(x*x)%m;
  	if(s.count(x)) { break; }
  	else { c=i; v.pb(x); s.insert(x); }
  }
  for(int i=1;i<=n;i++) { if(v[i]==x) { gg=i; break; } }
  for(int i=0;i<gg;i++) { sa+=v[i]; }
  for(int i=gg;i<=c;i++) {
  	ll w=(n-i)/(c-gg+1);
  	sa+=(w+1)*v[i];
  }
  cout<<sa;
  //}
  return 0;
}


Measured memory_bytes: 5972
# coding: utf-8
N, M = gets.split.map {|e| e.to_i}

evena = Array.new(N, 2)
odda = Array.new(M, 1)

a = evena + odda

puts a.combination(2).map{|e|e.reduce(&:+)}.select{|e| e.even?}.size



Measured memory_bytes: 2044
#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 = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end(), greater<int>());
    cout << accumulate(l.begin(), l.begin() + K, 0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int c[26][N];

int lowbit(int x)
{
    return x & (-x);
}

void update(int i, int k, int x)
{
    for (; i <= N; i += lowbit(i))
        c[x][i] += k;
}

int qu(int i, int x)
{
    int ans = 0;
    for (; i > 0; i -= lowbit(i))
        ans += c[x][i];
    return ans;
}
char s[N + 10];
int main()
{
    int n, q;
    scanf("%d", &n);
    scanf("%s", s + 1);

    scanf("%d", &q);
    for (int i = 1; i <= n; i++)
    {
        update(i, 1, s[i] - 'a');
    }
    int op, a, b;
    for (int i = 1; i <= q; i++)
    {
        scanf("%d", &op);
        if (op == 1)
        {
            int aa;
            char b[20];
            scanf("%d", &aa);
            scanf("%s", b);
            update(aa, -1, s[aa] - 'a');
            s[aa] = b[0];
            update(aa, 1, s[aa] - 'a');
        }
        else
        {
            int aa, b;
            scanf("%d%d", &aa, &b);
            int ans = 0;
            for (int i = 0; i < 26; i++)
            {
                if (aa > 1 && qu(b, i) - qu(aa - 1, i) || aa == 1 && qu(b, i))
                    ans++;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

Measured memory_bytes: 51584
from itertools import permutations
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = 0
count = 0
for i in permutations(range(n), n):
  for j in range(n-1):
    ans += ((xy[i[j]][0] - xy[i[j+1]][0])**2 + (xy[i[j]][1] - xy[i[j+1]][1])**2)**0.5
  count += 1

print(ans/count)

Measured memory_bytes: 9404
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
#define GOAL 2019
#define NUM 105
 
int N,M;
int loc[NUM];
bool check[GOAL+1];
 
int main(){
 
    scanf("%d",&N);
 
    for(int i = 1; i <= GOAL; i++){
 
        check[i] = false;
    }
 
    for(int i = 1; i <= N; i++){
 
        scanf("%d",&loc[i]);
        check[loc[i]] = true;
    }
 
    scanf("%d",&M);
 
    int tmp;
 
    for(int loop = 0; loop < M; loop++){
 
        scanf("%d",&tmp);
 
        if(loc[tmp] == GOAL)continue;
        if(check[loc[tmp]+1])continue;
 
        check[loc[tmp]] = false;
        loc[tmp]++;
        check[loc[tmp]] = true;
    }
 
    for(int i = 1; i <= N; i++){
 
        printf("%d\n",loc[i]);
    }
 
    return 0;
}


Measured memory_bytes: 3232
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String B = sc.nextLine();
    int max = 0; //the longest sequence of ACGT.
    int count = 0; //the longest current sequence of ACGT.
    for(int i=0; i<B.length(); i++) {
      if(B.charAt(i) == 'A' || B.charAt(i) == 'C' || B.charAt(i) == 'G' || B.charAt(i) == 'T') {
        count++;
      } else {
        
        max = Math.max(max, count);
        count = 0;
      }
    }
    max = Math.max(max, count);
    System.out.println(max);
  }
}


Measured memory_bytes: 35632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;

	cin >> n;

	for(i=1;i<=n;i++) {
		if (i%3!=0 && i%5!=0) ans += i;
	}
	cout << ans << endl;
	return 0;
}


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

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

        vector<vector<int>> dp(N,vector<int>(2));
        dp[0][0]=1;
        for(int i=0;i<Q;i++){
                /*
                for(int j=0;j<N;j++) cout<<dp[j][0]<<' '; cout<<endl;
                for(int j=0;j<N;j++) cout<<dp[j][1]<<' '; cout<<endl;
                cout<<endl;
                */
                /*
                for(int j=0;j<N;j++) if(dp[j][0]){
                        if(j-1>=0) dp[j-1][1]|=1;
                        if(j+1<N) dp[j+1][1]|=1;
                }
                */
                if(dp[a[i]][0]){
                        if(a[i]-1>=0) dp[a[i]-1][1]|=1;
                        if(a[i]+1< N) dp[a[i]+1][1]|=1;
                }
                if(dp[b[i]][0]){
                        if(b[i]-1>=0) dp[b[i]-1][1]|=1;
                        if(b[i]+1< N) dp[b[i]+1][1]|=1;
                }
                if(a[i]-1>=0 and dp[a[i]-1][0]) dp[a[i]][1]|=1;
                if(a[i]+1< N and dp[a[i]+1][0]) dp[a[i]][1]|=1;
                if(b[i]-1>=0 and dp[b[i]-1][0]) dp[b[i]][1]|=1;
                if(b[i]+1< N and dp[b[i]+1][0]) dp[b[i]][1]|=1;
                /*
                for(int j=0;j<N;j++) cout<<dp[j][0]<<' '; cout<<endl;
                for(int j=0;j<N;j++) cout<<dp[j][1]<<' '; cout<<endl;
                cout<<endl;
                */
                swap(dp[a[i]],dp[b[i]]);
        }
        for(int j=0;j<N;j++) if(dp[j][0]){
                if(j-1>=0) dp[j-1][1]|=1;
                if(j+1<N) dp[j+1][1]|=1;
        }
        /*
        for(int j=0;j<N;j++) cout<<dp[j][0]<<' '; cout<<endl;
        for(int j=0;j<N;j++) cout<<dp[j][1]<<' '; cout<<endl;
        cout<<endl;
        */
        int cnt=0;
        for(int j=0;j<N;j++) if(dp[j][0] or dp[j][1]) cnt++;
        cout<<cnt<<endl;
        return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <atcoder/all>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
using namespace atcoder;
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; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  int n,q; cin >> n >> q;

  fenwick_tree<ll> fw(n);
  rep(i,n) {
    ll a; cin >> a;
    fw.add(i, a);
  }

  rep(i,q) {
    int t; cin >> t;
    if(t == 0) {
      int p, x; cin >> p >> x;
      fw.add(p, x);
    }
    else {
      int l, r; cin >> l >> r;
      cout << fw.sum(l, r) << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 8232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, 1, n + 1) {
		int t;
		cin >> t;
		if (i & 1) {
			if (t & 1)ans++;
		}
	}
	cout << ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3608
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
 
typedef long long ll;
using namespace std;
int main(){
    int S,W;
    cin >> S >>W;
    if(S > W){
        cout << "safe";
    }else{
        cout <<"unsafe";
    }
    return 0;
}

Measured memory_bytes: 3592