akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
using lint = long long;

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

    int N;
    cin >> N;
    string S;
    cin >> S;
    S = '0' + S;

    vector<int> b(N + 2), w(N + 2);
    b[0] = 0;
    w[N] = 0;
    for (int i = 1; i <= N; i++) {
        if (S[i] == '#') {
            b[i] = b[i - 1] + 1;
        } else {
            b[i] = b[i - 1];
        }
    }
    for (int i = N - 1; i >= 0; i--) {
        if (S[i + 1] == '.') {
            w[i] = w[i + 1] + 1;
        } else {
            w[i] = w[i + 1];
        }
    }

    int ans = 1000000000;
    for (int i = 0; i <= N; i++) {
        ans = min(ans, b[i] + w[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2128
#include <stdio.h>
int main(void){
    // Your code here!
    int N,ans=0;
    scanf("%d",&N);
    for(int i = 0;i <= 25;i++){
        for(int j = 0;j <= 15;j++){
            if(4 * i + 7 * j == N)ans = 1;
        }
    }
    if(ans == 1)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
/*
------------------------------|بسم الله الرحمن الرحيم|------------------------------//
------------"IN THE NAME OF ALLAH, THE MOST GRACIUOS, THE MOST MERCIFUL"-------------//
__________________________________ShahnawazShaikh_____________________________________
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int int64_t
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);	
int n;
cin>>n;
if(n>=30)
   cout<<"Yes";
else
	cout<<"No";
return 0;	
}

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

int main() {
    int dict[26] = {};
    char c;
    while (cin >> c) {
        if (!isalpha(c)) continue;

        if (isupper(c)) c = tolower(c);
        dict[c - 'a'] += 1;
    }
    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", 'a' + i, dict[i]);
    }
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
bool ans[1024][1024];
void merge(int x1,int y1,int x2,int y2){
	if(x1==x2 || y1==y2) return;
	int x=(x1+x2)/2,y=(y1+y2)/2;
	ans[x][y]=0;
	merge(x1,y1,x-1,y-1);
	merge(x1,y+1,x-1,y2);
	merge(x+1,y1,x2,y-1);
	merge(x+1,y+1,x2,y2);
}
int main(){
	int n,m;
	cin>>n>>m;
	n=(1<<n)-1;m=(1<<m)-1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			ans[i][j]=1;
	merge(1,1,n,m);
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=m;++j)
			cout<<int(ans[i][j]);
	return 0;
}

Measured memory_bytes: 4616
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
int main(){
    pii ans=pii(0,0);
    int a,b,c; char hoge;
    while(cin>>a>>hoge>>b>>hoge>>c){
        if(a==b)ans.second++;
        else if(c*c==a*a+b*b)ans.first++;
    }
    cout<<ans.first<<"\n"<<ans.second<<endl;
}

Measured memory_bytes: 3096
import java.io.*;
import java.util.*;
public class Main {
static int [][] dp;
static char [][]hw ;

static int h;
static int w;

	public static int solve(int a,int b){
		
		dp[h-1][w-1]=1;
			for(int i=h-2,j=w-1;i>=0;i--){
				if(hw[i][j]=='#'){
					dp[i][j]=0%((int)1e9+7);
				}
				else{
					dp[i][j]=dp[i+1][j]%((int)1e9+7);
			}}
		for (int j=w-2,i=h-1;j>=0;j--){
			if(hw[i][j]=='#'){
				dp[i][j]=0%((int)1e9+7);
			}
			else{
				dp[i][j]=dp[i][j+1]%((int)1e9+7);
			}
		}
		for(int i=h-2;i>=0;i--){
			for(int j=w-2;j>=0;j--){
				if(hw[i][j]=='#'){
					dp[i][j]=0%((int)1e9+7);
				}
				else{
				dp[i][j]=(dp[i+1][j]+dp[i][j+1])%((int)1e9+7);
			}
		}
		
	}
		return dp[a][b];
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc=new Scanner(System.in);
		 h=sc.nextInt();
		 w=sc.nextInt();
		 hw=new char[h][w];
		 for(int i=0;i<h;i++){
			 hw[i]=sc.nextLine().toCharArray();}
		dp=new int[h][w];
for(int i=0;i<h;i++){
	Arrays.fill(dp[i], (-1));
}


		System.out.println(solve(0,0));
		
			
 }


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}}

Measured memory_bytes: 38108
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//�]���؂�グ�� =>  (a + b - 1) / b 

signed main(){
	int a; cin>>a;
  a*=2;
  double PI=3.14159265;
  cout<<a*PI;
	
	return 0;
}

Measured memory_bytes: 3800
#include <stdio.h>

int main()
{
  int r;
  scanf("%d", &r);

  if (r < 1200)
  {
    puts("ABC");
  }
  else if (r >= 2800)
  {
    puts("AGC");
  }
  else
  {
    puts("ARC");
  }

  return 0;
}

Measured memory_bytes: 128
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], m = tmp[1];
    long[] p = new long[m], y = new long[m];
    foreach (i; 0 .. m)
    {
        tmp = readln.split.to!(long[]);
        p[i] = tmp[0], y[i] = tmp[1];
    }

    long[] num = m.iota.array;
    zip(p, y, num).sort!(comp);
    long city = p[0];
    long cnt;
    long[][] id = new long[][](m, 2);
    foreach (i; 0 .. m)
    {
        if (p[i] == city)
        {
            ++cnt;
        }
        else
        {
            city = p[i];
            cnt = 1;
        }
        id[num[i]] = [p[i], cnt];
    }

    foreach (x; id)
    {
        writefln("%06d%06d", x[0], x[1]);
    }
}

alias comp = (x, y) => x[0] == y[0] ? x[1] < y[1] : x[0] < y[0];

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 13692
A,B,K=map(int,input().split())
L=[]
for i in range(K):
  if A+i<=B:
    L.append(A+i)
  else:
    break
for i in range(1-K,1):
  if B+i>=A and B+i not in L:
    L.append(B+i)
for i in range(len(L)):
  print(L[i])

Measured memory_bytes: 3060
#!/usr/bin/env python3

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

    d_list = [1]
    k = 1
    while True:
        if 6 ** k <= N:
            d_list.append(6 ** k)
            k += 1
        else:
            break
    k = 1
    while True:
        if 9 ** k <= N:
            d_list.append(9 ** k)
            k += 1
        else:
            break

    d_list.sort()

    dp = []
    for d in d_list:
        if d == 1:
            for i in range(N + 1):
                dp.append(i)
        else:
            for i in range(d, N + 1):
                dp[i] = min(dp[i], dp[i - d] + 1)


    print(dp[N])


if __name__ == '__main__':
    main()



Measured memory_bytes: 7064
from sys import stdin

n = int(stdin.readline().rstrip())
d = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]

for i in range(n):
    if (d[i][1] + d[i][2]) > d[i][0] or (d[i][1] + d[i][2] + d[i][0]) % 2 == 1:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 57692
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static int H;
    static int W;
    static String[][] matrix;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        H = Integer.parseInt(sc.next());
        W = Integer.parseInt(sc.next());

        // 初期化
        matrix = new String[H+2][W+2];
        for (String[] a : matrix) {
            Arrays.fill(a, "");
        }

        for (int i = 1; i <= H; i++) {
            String line = sc.next();
            for (int j = 0; j < line.length(); j++) {
                matrix[i][j+1] = String.valueOf(line.charAt(j));
            }
        }

        solve();
    }

    // 上下左右のどこかに#があればOK
    // 完全に孤立したマスがひとつでもあるとNG
    static void solve() {
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                String p = matrix[i][j];
                if (p.equals("#")) {
                    // 上下左右
                    String around = matrix[i-1][j] + matrix[i+1][j] + matrix[i][j-1] + matrix[i][j+1];
                    if (around.indexOf("#") == -1) {
                        System.out.println("No");
                        return;
                    }
                }
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
struct Process
{
    char name[11];
    int tim;
};

struct Process dequeue(struct Process *Q,int *head)
{
    *head = *head + 1;
    return Q[*head - 1];
}

void enqueue(struct Process x,struct Process *Q,int *tail)
{
    Q[*tail] = x;
    *tail +=1;
}


int main()
{
    int n,c,ksn=0;
    scanf("%d %d",&n,&c);
    int tail=n,head=0;
    struct Process p[n+1];
    for(int i=0;i<n;i++)
    {
        scanf("%s", p[i].name);
        scanf("%d", &p[i].tim);
    }
    while(head!=tail)
    {
        if(tail > n) tail = 0;
        struct Process x = dequeue(p,&head);
        if(head > n) head =0;
        if(x.tim < c)
        {
            ksn += x.tim;
            x.tim = 0;
        }
        else 
        {
            ksn += c;
            x.tim -= c;
        }
        if(x.tim == 0)
        {
            printf("%s %d\n", x.name,ksn);
        }
        else
        {
            enqueue(x,p,&tail);
        }
    }
    return 0;
}


Measured memory_bytes: 2500
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t=5;

    int arr[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    int f=0,l=0;

   for(int i=0;i<5;i++){
        if(arr[i]==0){
           cout<<++i<<endl;
           break;
   }
   }
}


Measured memory_bytes: 3592
import sys

while(True):
    a, op, b = sys.stdin.readline().split()
    if(op == '?'):
        break
    a, b = map(int, [a, b])
    ans = 0
    if(op == '+'):
        ans = a + b
    if(op == '-'):
        ans = a - b
    if(op == '*'):
        ans = a * b
    if(op == '/'):
        ans = int(a / b)
    print(ans)

Measured memory_bytes: 7632
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int f(int a, int b, int c, int n)
{
	if (a == b && b == c)
		return n;
	if (b == c)
	{
		if (a < b)
			a += 2;
		else
		{
			b++;
			c++;
		}
	}
	else if (a == b)
	{
		if (c < a)
		{
			c += 2;
		}
		else
		{
			a++;
			b++;
		}
	}
	else if (a == c)
	{
		if (b < a)
		{
			b += 2;
		}
		else
		{
			a++;
			c++;
		}
	}
	else
	{
		if (a < b && a < c)
		{
			a += 2;
		}
		else if (b < a && b < c)
		{
			b += 2;
		}
		else if (c < a && c < b)
		{
			c += 2;
		}
	}

	return f(a, b, c, n + 1);
}

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	cout << f(A, B, C, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

def it():
    for i in range(N//R+1):
        r = R*i
        for j in range((N-r)//G+1):
            g = G*j
            b = N - r - g
            if b % B == 0:
                yield 1

print(sum(it()))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

void bfs(int src, int n, vector<vector<int> > G);

int main() {
	int n;
	cin >> n;
	vector<vector<int> > G(n, vector<int>(n, 0));
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v_j;
			cin >> v_j;
			G[u - 1][v_j - 1] = 1;
		}
	}
	bfs(0, n, G);
}

void bfs(int src, int n, vector<vector<int> > G) {
	vector<int> D(n, -1);
	D[src] = 0;
	queue<int> Q;
	Q.push(src);
	while (!Q.empty()) {
		int cur = Q.front();
		Q.pop();
		for (int dst = 0; dst < n; dst++)
			if (G[cur][dst] == 1 && D[dst] == -1){
				D[dst] = D[cur] + 1;
				Q.push(dst);
			}
	}
	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << D[i] << endl;
}

Measured memory_bytes: 1304
object Main {
    def queens(n: Int): List[List[(Int, Int)]] = {
        def placeQueens(k: Int): List[List[(Int, Int)]] = {
            if(k == 0) List(List())
            else
                for {
                    queens <- placeQueens(k - 1)
                    col <- 1 to n
                    queen = (k, col)
                    if isSafe(queen, queens)
                } yield queen :: queens
        }
         placeQueens(n)
    }

    def isSafe(queen: (Int, Int), queens: List[(Int, Int)]) = {
        queens.forall(q => !inCheck(queen, q))
    }
    def inCheck(q1: (Int, Int), q2: (Int, Int)) = {
        q1._1 == q2._1 ||
        q1._2 == q2._2 ||
        (q1._1 - q2._1).abs == (q1._2 - q2._2).abs
    }
    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val list = List.fill(n)(sc.nextInt, sc.nextInt).map(p => (p._1 + 1, p._2 + 1))
        for(qs <- queens(8)) {
            if(list.forall(q => qs.contains(q))) {
                for(y <- 1 to 8) {
                    for(x <- 1 to 8) {
                        print(if(qs.contains((y, x))) "Q" else ".")
                    }
                    println
                }
            }
        }
    }
}

Measured memory_bytes: 50964
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

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

    void run() {

        long n = sc.nextLong();
        long k = sc.nextLong();

        if (k==0) {
            out.print(n*n);
            out.flush();
            return;
        }

        long ans = 0;

        for (long b=k+1; b<=n; b++) {
            long base = b-k;
            long div = n/b;
            long remain = n%b;
            ans += base*div;
            if (remain>=k) {
                ans += remain-k+1;
            }
        }

        out.print(ans);

        out.flush();

    }

}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	int t;
	int sum=0,num=0;
	cin>>t;
	for(int i=1;i<=t;i++){
		cin>>x>>y;		
		if(x==y){
			sum++;
			if(sum>=3){
				num=1;
			}
		}
		else{
			sum=0;
		}
	}
	if(num==1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462   
int main(){
    int n;
	cin>>n;
	int a[100];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		if(n-1-i!=0)
		cout<<a[n-1-i]<<" ";
		else
			cout<<a[0]<<endl;
	return 0;
}
//AAAAAAAAAAA!

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,i,j,a[101],b[101],c[101],x,y,cnt;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	{
		a[i]=0;	b[i]=0;	c[i]=0;
	}

	scanf("%d",&x);
	for(j=0;j<x;j++)	{
		scanf("%d",&y);
		a[y]=1;
	}
	scanf("%d",&x);
	for(j=0;j<x;j++)	{
		scanf("%d",&y);
		b[y]=1;
	}
	scanf("%d",&x);
	for(j=0;j<x;j++)	{
		scanf("%d",&y);
		c[y]=1;
	}
	
	cnt=0;
	for(i=1;i<=n;i++)	{
		if((a[i]==0 && c[i]==1) || (b[i]==1 && c[i]==1))	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

int main(){
//srandom((unsigned long)time(NULL));
long long n;
cin>>n;
vector<long long> d;
for(long long i=0;i<n;i++){
    long long x;
    cin>>x;
    d.emplace_back(x);
}
sort(d.begin(),d.end());
//135789  2 3  n=6

cout<<d[n/2]-d[n/2-1]<<endl;

return 0;
}

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

typedef long long ll;

const int N = 5e5 + 5;
const int ALPHA = 26;

int n;
string s;

set<int> pos[ALPHA];

int main() {
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		pos[s[i] - 'a'].insert(i);
	}
	int q;
	cin >> q;
	while (q--) {
		int typ;
		cin >> typ;
		if (typ == 1) {
			int idx;
			char c;
			cin >> idx >> c;
			idx--;
			pos[s[idx] - 'a'].erase(idx);
			pos[c - 'a'].insert(idx);
			s[idx] = c;
		} else {
			int L, R, res = 0;
			cin >> L >> R;
			L--, R--;
			for (int i = 0; i < ALPHA; i++) {
				auto it = pos[i].lower_bound(L);
				if (it != pos[i].end() && *it <= R)
					res++;
			}
			cout << res << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 24196
#include <stdio.h> 

int main() {
	int ans = 0,a=0,b=0;
	scanf("%d%d",&a,&b);
	if (a == b)ans = a * 2;
	else if (a > b)ans = a * 2 - 1;
	else ans = b * 2 - 1;
	printf("%d", ans);
	return 0;
}

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

int main() {
  int n, ans = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = 0; i < n; i++) {
    i % 2 ? ans -= a[i] : ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
	public static void main(String args[])
	{
		long a;
		long d=1;
		Scanner sc=new Scanner(System.in);
		a=sc.nextLong();
		while(a>1)
		{a=a/2;
			d*=2;}
			
		System.out.println(2*d-1);
	}
}

Measured memory_bytes: 25044
cnt="abcdefghijklmnopqrstuvwxyz"
s=input()
ans=[0 for i in range(26)]

for i in range(len(s)):
  a=cnt.index(s[i])
  ans[a]+=1
res=30
for i in range(26):
  if ans[i]==0:
    res=i
    break
if res==30:
  print("None")
else:
  print(cnt[res])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
using namespace std;
const int N=1e5+5;
void fast()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
map<vi,ll>mp;ll ans;
int n;string s;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		vi v(26,0);
		cin>>s;
		for(int j=0;j<s.size();j++)
		{
			v[s[j]-'a']++;
		}
		mp[v]++;
	}
	for(map<vi,ll>::iterator it=mp.begin();it!=mp.end();it++)
	{
		ans+=it->second*(it->second-1)/2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 18944
# N: 夏休みの日数，M: 宿題の数
N, M = list(map(int, input().split()))
# i番目の宿題にかかる日数
A = list(map(int, input().split()))

free_days = N - sum(A)

if (free_days >= 0):
    print(free_days)
else :
    print(-1)

Measured memory_bytes: 9872
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
int o, bp, rp, gp, bm, rm, gm;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    o = n;
    long long ans = 1;
    for (int i = 0; i < 3*n; i++) {
        if (s[i] == 'R') {
            if (rm > 0) {
                ans = ans * rm % mod;
                rm--;
            } else if (gp > 0) {
                ans = ans * gp % mod;
                gp--; bm++;
            } else if (bp > 0) {
                ans = ans * bp % mod;
                bp--; gm++;
            } else {
                ans = ans * o % mod;
                o--; rp++;
            }
        } else if (s[i] == 'B') {
            if (bm > 0) {
                ans = ans * bm % mod;
                bm--;
            } else if (gp > 0) {
                ans = ans * gp % mod;
                gp--; rm++;
            } else if (rp > 0) {
                ans = ans * rp % mod;
                rp--; gm++;
            } else {
                ans = ans * o % mod;
                o--; bp++;
            }
        } else if (s[i] == 'G') {
            if (gm > 0) {
                ans = ans * gm % mod;
                gm--;
            } else if (rp > 0) {
                ans = ans * rp % mod;
                rp--; bm++;
            } else if (bp > 0) {
                ans = ans * bp % mod;
                bp--; rm++;
            } else {
                ans = ans * o % mod;
                o--; gp++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 900
#include <iostream>

using namespace std;

int
main(int argc, char **argv)
{
    int n,a,b;
    cin >> n;
    cin >> a;
    cin >> b;
    int x = n * a;
    int y = b;

    if(x < y)
        cout << x << endl;
    else
        cout << y << endl;

    return 0;
}

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

typedef long long LL;

int N,L,a[100010];

int main()
{
    scanf("%d%d",&N,&L);
    for (int i=1;i<=N;i++)scanf("%d",&a[i]);
    for (int i=1;i<N;i++)
    {
        if (a[i] + a[i + 1] >= L)
        {
            puts("Possible");
            for (int j=1;j<i;j++)printf("%d\n",j);
            for (int j=N-1;j>i;j--)printf("%d\n",j);
            printf("%d\n",i);
            return 0;
        }
    }
    puts("Impossible");
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,m,n,ans;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<=b && a<=c){
		m=a-25;
	}
	else if(b<=a && b<=c){
		m=b-25;
	}
	else if(c<=a && c<=b){
		m=c-25;
	}
	if(d<=e){
		n=d-25;
	}
	if(e<=d){
		n=e-25;
	}
	ans=m+n;
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

#define ll long long

struct HopcroftKarp {
	vector< vector< int > > graph;
	vector< int > dist, match;
	vector< bool > used, vv;

	HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

	void add_edge(int u, int v) {
		graph[u].push_back(v);
	}

	void bfs() {
		dist.assign(graph.size(), -1);
		queue< int > que;
		for (int i = 0; i < graph.size(); i++) {
			if (!used[i]) {
				que.emplace(i);
				dist[i] = 0;
			}
		}

		while (!que.empty()) {
			int a = que.front();
			que.pop();
			for (auto &b : graph[a]) {
				int c = match[b];
				if (c >= 0 && dist[c] == -1) {
					dist[c] = dist[a] + 1;
					que.emplace(c);
				}
			}
		}
	}

	bool dfs(int a) {
		vv[a] = true;
		for (auto &b : graph[a]) {
			int c = match[b];
			if (c < 0 || (!vv[c] && dist[c] == dist[a] + 1 && dfs(c))) {
				match[b] = a;
				used[a] = true;
				return (true);
			}
		}
		return (false);
	}

	int bipartite_matching() {
		int ret = 0;
		while (true) {
			bfs();
			vv.assign(graph.size(), false);
			int flow = 0;
			for (int i = 0; i < graph.size(); i++) {
				if (!used[i] && dfs(i)) ++flow;
			}
			if (flow == 0) return (ret);
			ret += flow;
		}
	}

	void output() {
		for (int i = 0; i < match.size(); i++) {
			if (~match[i]) {
				cout << match[i] << "-" << i << endl;
			}
		}
	}
};

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> b(N);
	vector<int> c(N);
	vector<int> d(N);
	for (int i = 0; i < N; i++) 
		cin >> a[i] >> b[i];
	for (int i = 0; i < N; i++)
		cin >> c[i] >> d[i];
	HopcroftKarp g(N,N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (a[i] < c[j] && b[i] < d[j])
				g.add_edge(i, j);
		}
	}
	cout << g.bipartite_matching() << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
fir=0
sec=0
same=0
ret = 0
for i in range(n):
    s = input()
    if 'AB' in s:
        ret+=s.count('AB')
    if s[0]=='B' and s[-1]=='A':
        same+=1
    else:
        if s[0]=='B':
            fir+=1
        if s[-1]=='A':
            sec+=1
if same>0:
    ret+=same-1
    if fir>0:
        ret+=1
        fir-=1
    if sec>0:
        ret+=1
        sec-=1
print(ret+min(fir,sec))


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


vector<vector<long long> > dp(305, vector<long long>(305, 300000000000));
int main() {
  int N, K; cin >> N >> K;
  vector<int> H;
  H.push_back(0);
  dp[0][0] = 0;
  dp[0][1] = 0;
  rep(i, N) {
    int h; cin >> h;
    H.push_back(h);
    dp[i + 1][1] = h;
    dp[i + 1][0] = 0;
  }
  for (int y = 2; y <= N; y ++) {
    rep1(x, N) {
      for (int i = 1; i < x; i ++) {
        _min(dp[x][y], dp[i][y - 1] + max(0, H[x] - H[i]));
      }
    }
  }
  long long ans = 300000000000;
  //rep(i, N + 1) {
  //  rep(j, N + 1) {
  //    cout << dp[i][j] << " " ;
  //  }
  //  cout << endl;
  //}
  rep1(i, N) {
    _min(ans, dp[i][N - K]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
ABC=[list(map(int,input().split())) for i in range(N-1)]
Q,K=map(int,input().split())
XY=[list(map(int,input().split())) for i in range(Q)]
data=[[] for i in range(N+1)]
for a,b,c in ABC:
    data[a].append([b,c])
    data[b].append([a,c])

visited=set()
stack=deque([[K,0]])
lst=[0 for i in range(N+1)]
while stack:
    a,m=stack.popleft()
    lst[a]=m
    for p,c in data[a]:
        if not p in visited:
            visited.add(p)
            stack.append([p,m+c])

for x,y in XY:
    print(lst[x]+lst[y])


Measured memory_bytes: 125912
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ABC155 {
    public class C {
        public static void Main() {
            var num = int.Parse(Console.ReadLine());
            var count = new SortedDictionary<string, int>(StringComparer.OrdinalIgnoreCase);
            var max = 0;
            for (int i = 0; i < num; i++) {
                var word = Console.ReadLine();
                if (!count.ContainsKey(word)) count.Add(word, 0);
                count[word]++;
                if (max < count[word]) max = count[word];
            }

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            foreach (var word in count) {
                if(word.Value == max)
                sw.WriteLine(word.Key);
            }
            sw.Flush();
        }
    }
}

Measured memory_bytes: 36448
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int a,b,j,v;
    cin>>a>>b;
    if(a>=b){
        while(1){
          if(a%b==0){
            break;
          }else{
            j=a;
            a=b;
            b=j%b;

          }
        }

        cout<<b<<endl;
    }else if(b>=a){
        while(1){
          if(b%a==0){
            break;
          }else{
            j=b;
            b=a;
            a=j%a;

          }
        }
        cout<<a<<endl;
    }

    return 0;
}



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

using namespace std;

#define int long long
#define N 100005

int freq[N];


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

    for(int i=1;i<=n;i++)
    {
        freq[i%k]++;
    }

    int ans = 0;
    for(int i=0;i<k;i++)
    {
        int l = i;
        int r = (k-i)%k;
        if( (l+l)%k == 0)
            ans+=freq[l]*freq[r]*freq[l];
    }
    cout<<ans<<endl;
    return 0;
}

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

namespace Contest_02_Valeo_P1
{

    class Program
    {
        public static void Main(string[] args)
        {
            //while (true)
            //{
            //    Console.WriteLine("start problem");
                string input = Console.ReadLine();
                long n = long.Parse(input);
                string s = Console.ReadLine();

                long result = getSlimes(s);
                Console.WriteLine(result);
            //    Console.Write("press y to exit : ");
            //    if (Console.ReadLine() == "y")
            //        return;
            //}
        }

        private static long getSlimes(string s)
        {
            long count = 0;
            char c = Char.MinValue;
            foreach (var item in s)
            {
                if(item != c)
                {
                    count++;
                    c = item;
                }
            }
            return count;
        }
    }
}


Measured memory_bytes: 11232
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M), P(M);
    vector<set<int>> S(M);
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        A[x % M]++;
        if (S[x % M].count(x)) {
            P[x % M]++;
            S[x % M].erase(x);
        } else {
            S[x % M].insert(x);
        }
    }
    int ans = 0;
    for (int i = 0; i <= M / 2; i++) {
        if (i == 0 || i * 2 == M) {
            ans += A[i] / 2;
        } else {
            if (A[i] > A[M - i]) {
                ans += A[M - i] + min(P[i], (A[i] - A[M - i]) / 2);
            } else {
                ans += A[i] + min(P[M - i], (A[M - i] - A[i]) / 2);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 10368
import java.util.Arrays;
import java.util.HashMap;
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());
        boolean can = false;
        for (int i=1; i<10; i++) {
            for (int j=1; i*j<=n&&j<10;  j++) {
                if(i*j!=n){
                    continue;
                }
                can = true;
                break;
            }
            if(!can) {
                continue;
            }
            break;
        }
        if(can){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
    
    private static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left+right)/2];
        int l=left, r=right;
        int tmp;
        while(l<=r){
            while(d[l]>p){l++;}
            while(d[r]<p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++; r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}

Measured memory_bytes: 21716
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

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

    vector<Int> p(n + 1);
    p[0] = abs(a[0]);
    for (int i = 1; i < n; i++) {
        p[i] = abs(a[i] - a[i - 1]);
    }
    p[n] = abs(a[n - 1]);

    Int sum = accumulate(p.begin(), p.end(), 0);
    cout << sum - (p[0] + p[1]) + abs(a[1]) << endl;
    for (int i = 1; i < n - 1; i++) {
        Int ans = sum - (p[i] + p[i + 1]) + abs(a[i + 1] - a[i - 1]);
        cout << ans << endl;
    }
    cout << sum - (p[n - 1] + p[n]) + abs(a[n - 2]) << endl;
    ;

    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int n, m;
  cin >> n >> m;
  vector<int> data(n);
  double sum = 0;
  for(int i = 0; i < n ; i++)
  {
    cin >> data[i];
    sum += data[i];
  }
  sort(data.begin(), data.end(), greater<int>());
  for(int i = 0; i < m; i++)
  {
    if(data[i] < sum /(4 * m))
    {
      cout << "No" << endl;
      return (0);
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  string s,t;
  cin >> s >> t;
  ll ans=0;
  rep(i,s.size()) {
    if(s[i]!=t[i]) ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3800
l = list(map(int, input().split()))
A, B, C, X, Y = l[0], l[1], l[2], l[3], l[4]
s_1, s_2, s_3 = 0, 0, 0

s_1 = A*X + B*Y

maxv = max([X, Y])
s_2 = 2*C*max([X, Y])
if X >= Y:
    s_3 = 2*C*Y + A*(X-Y)
else:
    s_3 = 2*C*X + B*(Y-X)

print(min([s_1, s_2, s_3]))


Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
long long a[505][505];
int main() {
  int H, W, h, w;
  scanf("%d %d %d %d", &H, &W, &h, &w);
  long long sum = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (i % h == 0 && j % w == 0) {
        a[i][j] = -4000 * (h * w - 1) - 1;
      } else {
        a[i][j] = 4000;
      }
      sum += a[i][j];
    }
  }
  if (sum > 0) {
    printf("Yes\n");
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        printf("%lld%c", a[i][j], j == W ? '\n' : ' ');
      }
    }
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N=1e3+5;
int main(){
	ll n , k;
	cin>>n>>k;
	ll ok = n/k;
	cout<<min(abs(n-k*ok),abs(n-k*ok-k))<<endl;

}	

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

int N;
vector<int> a, b;

int main() {
    cin >> N;
    a.resize(N); for (int i = 0; i < N; ++i) cin >> a[i];
    b.resize(N); for (int i = 0; i < N; ++i) cin >> b[i];
    int res = 0;
    for (int digit = 29; digit >= 0; --digit) {
        int bekihigh = 1<<(digit+1), bekilow = 1<<digit;
        for (int i = 0; i < N; ++i) a[i] %= bekihigh, b[i] %= bekihigh;
        sort(b.begin(), b.end());
        long long num = 0;
        for (int i = 0; i < N; ++i) {
            int add = 0;
            if (bekilow - a[i] >= 0) {
                add += lower_bound(b.begin(), b.end(), bekihigh-a[i])
                        - lower_bound(b.begin(), b.end(), bekilow-a[i]);
                
            }
            else {
                add += lower_bound(b.begin(), b.end(), bekihigh-a[i]) - b.begin();
                add += lower_bound(b.begin(), b.end(), bekihigh)
                        - lower_bound(b.begin(), b.end(), bekihigh + bekilow - a[i]);
            }
            num += add;
        }
        if (num & 1) res += bekilow;
    }
    cout << res << endl;
}

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

using namespace std;

typedef long long int lli;

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

    int n, w[100], s[101] = { 0 };

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

    int ans = 10000000;
    for (int i=1; i<n; i++) {
        int l = s[i], r = s[n] - s[i];
        ans = min(ans, abs(l-r));
    }

    cout << ans << endl;

    return 0;
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nm[0];
            var m = nm[1];
            
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var improperList = new HashSet<int>();

            for (int i = 0; i < m; i++)
            {
                var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var a = ab[0];
                var b = ab[1];

                if(h[a - 1] >= h[b - 1])
                {
                    improperList.Add(b);
                }
                if(h[a - 1] <= h [b - 1])
                {
                    improperList.Add(a);
                }
            }
            Console.WriteLine(n - improperList.Count());
        }
    }
}


Measured memory_bytes: 55760
#include<iostream>
using namespace std;
int main()
{
	int n,maxv,minv,R;
	cin>>n;
	cin>>R;
	minv=R;
	maxv=-R;
	while(n>1)
	{
		cin>>R;
		if(R-minv>maxv)
			maxv=R-minv;
		if(R<minv)
			minv=R;
		n--;
	}
	cout<<maxv<<endl;
}


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

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            int[] s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A =s[0]; int B = s[1];int C = s[2];

            Console.WriteLine(C>=A && C<=B ? "Yes":"No");
            

        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
long n, a, b;
long H[MAX_N + 1];
bool check(long long mb)
{
    long long cnt = 0;
    long long x = a - b;
    for (int i = 0; i < n; i++)
    {
        long long h = H[i] - mb * b;
        if (h <= 0)
            continue;
        cnt += (h + x - 1) / x;
    }
    if (cnt <= mb)
        return true;
    else
        return false;
}
int main()
{
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++)
    {
        cin >> H[i];
    }
    long long lb = 0, ub = 1000000000;
    while (ub - lb > 1)
    {
        long long mb = (lb + ub) / 2;
        if (check(mb))
        {
            ub = mb;
        }
        else
        {
            lb = mb;
        }
    }
    cout << ub << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] dp = new int[n + 1];
        dp[0] = 1;
        Set<Integer> a = new HashSet<>();
        for (int i = 0; i < m; i++) {
            a.add(scanner.nextInt());
        }

        for (int i = 1; i <= n; i++) {
            if (!a.contains(i)) {
                dp[i] = (dp[i - 1] + (i == 1 ? 0 : dp[i - 2])) % 1000000007;
            }
        }
        System.out.println(dp[n]);
    }
}

Measured memory_bytes: 66620
import java.util.ArrayList;
import java.util.Collections;
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());
		ArrayList<Integer> A = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			A.add(Integer.parseInt(sc.next()));
		}
		int q = Integer.parseInt(sc.next());
		ArrayList<Integer> m = new ArrayList<>();
		for(int i = 0; i < q; i++) {
			m.add(Integer.parseInt(sc.next()));
		}
		sc.close();
		
		Collections.sort(A);
		
		
		for(int i = 0; i < q; i++) {
			if(solve(A, 0, m.get(i))) {
				System.out.println("yes");
			}else {
				System.out.println("no");
			}
		}
	}

	public static boolean solve(ArrayList<Integer> data, int i, int m) {
		if(m == 0) return true;
		if(i == data.size() - 1) {
			if(data.get(i) == m) {
				return true;
			}else {
				return false;
			}
		}
		return solve(data, i + 1, m) || solve(data , i + 1 , m -data.get(i));
	}

}


Measured memory_bytes: 27512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int dp[1000001],flg[1000001];
int main(void)
{
	for(int i=2;i<=1000000;i++) flg[i]=1;
	for(int i=2;i*i<=1000000;i++){
		if(flg[i]==1){
			for(int j=2;j*i<1000000;j++) flg[i*j]=0;
		}
	}
	int kin[30],n,x;
	while(1) {
		cin>>n>>x;
		if(n==0 && x==0) break;
		for(int i=0;i<n;i++) cin>>kin[i];
		for(int i=0;i<=x;i++) dp[i]=0;
		dp[0]=1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<=x;j++) 
				if(dp[j]==1) {
					if(j+kin[i]<=x) dp[j+kin[i]]=1;
				}
		}
		
		int no=0,data;
		for(int i=x;i>1;i--) {
			if(flg[i]==1 && dp[i]==1){data=i;no=1;break;}
		}
		if(no==0) cout<<"NA"<<endl;
		else cout<<data<<endl;
	}
}
		
	

Measured memory_bytes: 8972
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int x[100000],y[100000],z;
int main(){
	int a,b,m;
	cin>>a>>b>>m;
	int maxx=1e9,maxy=1e9;
	for(int i=0;i<a;i++){
		cin>>x[i];
		if(x[i]<maxx) maxx=x[i];
	} 
	for(int i=0;i<b;i++){
		cin>>y[i];
		if(y[i]<maxy) maxy=y[i];
	} 
	int ans=maxx+maxy;
	for(int i=0;i<m;i++){
		int p,q,z;
		cin>>p>>q>>z;
		if(x[p-1]+y[q-1]-z<ans) ans=x[p-1]+y[q-1]-z;
	}
	
	cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
ch = 0

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            ch = 1

if ch == 0:
    ans = 'APPROVED'
else:
    ans = 'DENIED'

print(ans)


Measured memory_bytes: 9156
#include<iostream>
#include<vector>
#include<deque>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	deque<char>d;
	while(n>0)
	{
		char ch;
		if(n%26==0)
		{
			ch=26;
			n=n-26;
			n=n/26;
		}
		else
		{
			ch=n%26;
			n=n-n%26;
			n=n/26;
		}
		ch=ch+'a'-1;
		d.push_back(ch);
	}
	while(d.size()>0)
	{
		cout<<d.back();
		d.pop_back();
	}
	cout<<endl;
	return 0;
}



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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b-1);
    cout << ll(a*x/b) - a * ll(x/b) << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    if (n % m == 0) return m;
    return gcd(m, n % m);
}

int lcm(int n, int m) {
    return (n * m) / gcd(n, m);
}

int main() {
    int N; cin >> N;
    cout << lcm(2, N) << endl;
}

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

int k = 0, sum = 0, a[1000000];
string s;

int main() {
	cin >> s;
	
	for(int i = 0; i < s.size(); i++){
		sum++;
		if(s[i] != s[i + 1]){
			for(int j = i - sum + 1; j <= i; j++){
				a[j] = sum;
				sum--;
			}
			sum = 0;
		}
	}
	
	for(int i = 0; i < s.size(); i++){
		if(a[i] > k && s[i] == 'J'){
			if(a[i + a[i]] == a[i] && s[i + a[i]] == 'O' && a[i + a[i] * 2] >= a[i] && s[i + a[i] * 2] == 'I'){
				k = a[i];
			}
		}
	}
	
	cout << k << endl;
	
	return 0;
}

Measured memory_bytes: 6000
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,K = MI()
mod = 10**9+7

def divisor(n):  # nの約数のリスト
    res = []
    for i in range(1,int(n**.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n//i:
                res.append(n//i)
    return res

A = divisor(N)

d = {}  # d[i] = iの約数のリスト(iはNの約数)
for a in A:
    d[a] = divisor(a)

prime = []  # Nの素因数のリスト
for i in range(2,int(N**.5)+1):
    if N % i == 0:
        prime.append(i)
        while N % i == 0:
            N //= i
if N != 1:
    prime.append(N)

mu = {}  # mu[i] = μ(i) (iはNの約数)
for a in A:
    b = a
    r = 1
    for p in prime:
        if b % p == 0:
            r *= -1
            if b//p % p == 0:
                r = 0
                break
    mu[a] = r


ans = 0
for a in A:
    for b in d[a]:
        if a % 2 == 0:
            ans += mu[a//b]*pow(K,(b+1)//2,mod)*(a//2)
            ans %= mod
        else:
            ans += mu[a//b]*pow(K,(b+1)//2,mod)*a
            ans %= mod

print(ans)

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

using namespace std;

const int MAX_N = 1e5;
const int MOD = 1e9 + 7;

vector <int> gr[1 + MAX_N];

#define pb push_back

long long dp[1 + MAX_N][2];


void dfs (int node, int father) {
	dp[node][0] = dp[node][1] = 1;
	for (int son : gr[node])
		if (son != father) {
            dfs (son, node);
            dp[node][0] *= (dp[son][0] + dp[son][1]);
            dp[node][0] %= MOD;
            dp[node][1] *= dp[son][0];
            dp[node][1] %= MOD;
		}
}

int main () {
    int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		gr[x].pb (y);
		gr[y].pb (x);
	}
	dfs (1, -1);
	cout << (dp[1][0] + dp[1][1]) % MOD << "\n";
}


Measured memory_bytes: 14208
def main
  input = gets.chomp
  ops = ["+", "-"]

  ops.each do |op_1|
    ops.each do |op_2|
      ops.each do |op_3|

        output = input[0].to_i

        if op_1 == "+"
          output += input[1].to_i
        else
          output -= input[1].to_i
        end

        if op_2 == "+"
          output += input[2].to_i
        else
          output -= input[2].to_i
        end

        if op_3 == "+"
          output += input[3].to_i
        else
          output -= input[3].to_i
        end
        if output == 7
          puts "#{input[0]}#{op_1}#{input[1]}#{op_2}#{input[2]}#{op_3}#{input[3]}=7"
          return
        end
      end
    end
  end
end

main()

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAXN = 1e5+2;
int n, a[MAXN]={}, L[MAXN]={}, R[MAXN]={};

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		L[i] = __gcd(L[i-1],a[i]);
	}

	for (int i = n; i >= 1; --i) {
		R[i] = __gcd(R[i+1],a[i]);
	}

	int ans = R[2];
	for (int i = 2; i <= n; ++i) {
		ans = max(ans, __gcd(L[i-1], (i < n ? R[i+1] : 0)));
	}

	cout << ans << '\n';
}

	/////////// End Solution ///////////////////////////////////////

	//////// Initialization ////////////////////////////////////

int main() {

		#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
		#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

		#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
		#endif

	return 0;
}

	//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 1408