akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
 
int syr[10]; 
int s=0; 
 
int top() { 
    return syr[s-1];
}
void pop() {
    s--;
}
void push(int num) {
    if(num>0) {
        syr[s] = num;
        s++;
    }
}
 
int main() {
    int num;
    while(scanf("%d",&num) != EOF) {
        push(num);
        if(num==0) {
            printf("%d\n",top());
            pop();
        }
    }
    return 0;
}

Measured memory_bytes: 1800
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>

int main(void){
  double n=0;
  double k=0;
  int a=0;
  int position=0;
  long long int sum=0;
  std::vector<int> A;
  std::cin>>n>>k;

  for(int i=0; i<n; i++){
    std::cin>>a;
    A.push_back(a);
  }
  
  std::cout<<ceil((n-1)/(k-1))<<std::endl;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define Boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

long Solve(vector <vector <long> >& G) {
    long n = G.size();
    vector <long> A(n,0);
    long a,b,cnt,j=1,c;
    long comp,ans = 0;
    cnt = 0;
    c = 0;
    queue <long> Q;
    while(cnt<n) {
        while(j<n && A[j]!=0)
            j++;
        if(j==n) break;
        Q.push(j);
        cnt++;
        c++;
        comp = 0;
        while(!Q.empty()) {
            a = Q.front();
            Q.pop();
            A[a] = c;
            comp++;
            for(auto i=G[a].begin();i!=G[a].end();i++) {
                b = *i;
                if(A[b]==0) {
                    Q.push(b);
                    A[b] = c;
                    cnt++;
                }
            }
        }
        ans = max(ans,comp);
    }
    return ans;
}

void Crack() {
	long n,m,a,b;
    cin >> n >> m;
    vector <vector <long>> G(n);
    for(int i=0;i<m;i++) {
        cin >> a >> b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    cout << Solve(G) << endl;
}

int main() {
	Boost;
    Crack();
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s == "SUN") cout << "7" << endl;
  else if (s == "MON") cout << "6" << endl;
  else if (s == "TUE") cout << "5" << endl;
  else if (s == "WED") cout << "4" << endl;
  else if (s == "THU") cout << "3" << endl;
  else if (s == "FRI") cout << "2" << endl;
  else if (s == "SAT") cout << "1" << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(LLI i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


inline LLI p5(LLI x)
{
	return x * x * x * x * x;
}

int main()
{
	cout << fixed << setprecision(10);

	LLI x;
	cin >> x;

	LLI a5 = 0, b5 = 0;
	for (LLI a = -5000; a < 5000; a++)
	{
		a5 = p5(a);
		for (LLI b = -5000; b < 5000; b++)
		{
			b5 = p5(b);
			if (a5 - b5 == x)
			{
				cout << a << " " << b;
				return 0;
			}
		}
	}
	cout << "0 0";
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector> 
#include <utility>
using namespace std;



int main(void){
    int N; 
    cin >> N;
    int point[N];
    vector <string> W(N);
    int check[N];
    int ans[N];
    
    for (int i = 0; i < N; ++i) {
        cin >> W[i];
        cin >> point[i];
        check[i] = 0;
        ans[i] = i+1;
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(W[i] < W[j])
                check[i]++;
            if(W[i] == W[j] && point[i] > point[j])
                check[i]++;
        }
    }
    

    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++ ){
        if(check[i] < check[j]){
            swap(ans[i], ans[j]);
             swap(check[i], check[j]);
        }
        }
    }
    
     for(int i = 0; i < N; i++)
        cout << ans[i] << endl;    

    return 0;
}

Measured memory_bytes: 256
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10**15
N, M = map(int, input().split())
G = [[]for i in range(N)]
for i in range(1, N):
    G[i].append([i-1, 0])

for i in range(M):
    L, R, C = map(int, input().split())
    G[L-1].append([R-1, C])

S = 0

def dijkstra(N, S):
    d = [INF for i in range(N)]

    que = []
    d[S] = 0
    heapq.heappush(que, [0, S])

    while not(len(que) == 0):
        q = heapq.heappop(que)
        ver = q[1] # ノード
        dis = q[0] # 過去に更新された最短距離

        # vまで2番目に短い距離（最新）　＜　過去最短距離　の時、
        # キューから取り出した過去のものを無視する
        if d[ver] < dis:
            continue

        # 隣接リストに対してループ
        for i in range(len(G[ver])):
            e = G[ver][i]
            if d[e[0]] > d[ver] + e[1]:
                d[e[0]] = d[ver] + e[1]
                heapq.heappush(que, [d[e[0]], e[0]])

    return d[N-1]

ans = dijkstra(N, S)
if ans == INF:
    print(-1)
else:
    print(dijkstra(N, S))

Measured memory_bytes: 104496
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 

const string MINF = "-";

bool sgreater(string a, string b) {
    if (b == MINF) return true;

    if (a.size() > b.size()) return true;
    else if (a.size() == b.size() && a > b) return true;
    else return false;    
}

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

    int N, M; cin >> N >> M;
    vi A(M); REP(i, M) cin >> A[i];

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

    vs dp(N + MGN, MINF);
    dp[0] = "";
    REP(i, N+1) {
        if (dp[i] == MINF) continue;
        REP(j, M) {
            string t = dp[i] + to_string(A[j]);
            if (sgreater(t, dp[i + C[A[j]]])) {
                dp[i + C[A[j]]] = t;
            }
        }
    }

    string ans = dp[N];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 33024
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////


int main(){fastio
    ll n;cin>>n;
    ll x[n];rep(i,0,n-1)cin>>x[i];
    ll ans=inf;
    rep(i,1,100){
        ll sum=0;
        rep(j,0,n-1){
            sum+=(x[j]-i)*(x[j]-i);
        }
        Min(ans,sum);
    }cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

int main(){
    //最大値を出してくれるやつ!!
    priority_queue<long long> pque;

    int n,m;
    cin >> n >> m;
    long long yen;

    for(int i=0;i<n;i++){
        cin >> yen;
        pque.push(yen); 
    }
    //チケットが無くなるまで使っていく
    while(m>0){
        long long newyen=(long long)(pque.top()/2);
        pque.pop();
        pque.push(newyen);
        //cout << newyen << endl;
        m--;
    }
    //合計を求める
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=pque.top();
        //cout << pque.top() << endl;
        pque.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
import math
 
# Input the amount of money Takahashi paid
N = int(input())
 
# Find nearest integer price more than or equal to X/1.08
X = math.ceil(N / 1.08)
 
# Check if the "taxed price" is equal to N yen
if math.floor(X * 1.08) == N:
	print(X)
else:
	print(":(")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define int long long
signed main() {
	int a, b, c, n;
	cin >> a >> b >> c >> n;
	int Max = max(max(a, b), max(b, c));
	int sum = a + b + c - Max;
	cout << sum + (Max * pow(2, n)) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int main()
{
    int n;
    cin>>n;
    if(n%1000!=0) cout<<1000-n%1000<<endl;
    else cout<<0<<endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

  cout << a[K-1] << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  vector<int> z(a+1);
  string c ="Yes";
  for(int i = 1;i < a+1;i++){
    cin >> z.at(i);
    if(z.at(i-1)<z.at(i))z.at(i)--;
    if(z.at(i-1)>z.at(i)){c="No";break;}
  }
    cout << c << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define MAX 101
int A[MAX];//これがスタックの本体
int top=0;//スタックのてっぺん

int isFull(){//満タンだったら1 違ったら0
  if(top>=MAX-1){
      printf("full error\n");
      return 1;
    }
  return 0;
}

int isEmpty(){//空だったら1 　違ったら0
  if(top==0){
      printf("empty error\n");
      return 1;
    }
  return 0;
}

void push(int x){
  if(isFull()==1)return ;//error
  A[++top]=x;
}


int pop(void){
  if(isEmpty()==1)return -1;//0　が返ったらエラー
  top--;
  return A[top+1];
}


int main(){
  int x;
  char s[100];
  int a;

  
  while( scanf("%s", s) != EOF ){
      if ( s[0] == '+' ){
	  push(pop()+pop());
	}
      else if ( s[0] == '-' ){
	  a=pop();
	  push(pop()-a);
	}
      else if ( s[0] == '*' ){
	  push(pop()*pop());
	}
      else{
	  x = atoi(s);
	  push(x);
	}
    }
  printf("%d\n",pop());

  return 0;
}
//push(int)



Measured memory_bytes: 2112
import sys


def main():
    N = int(sys.stdin.readline().rstrip())

    X = [None] * N
    Y = [None] * N 
    Z = [None] * N

    for i in range(N):
        x, y = map(int, sys.stdin.readline().rstrip().split())
        X[i] = x
        Y[i] = y
    
    X_min = min(X)
    Y_min = min(Y)

    for i in range(N):
        X[i] = X[i] - X_min
        Y[i] = Y[i] - Y_min
        Z[i] = X[i] + Y[i]

    ans1 = max(Z) - min(Z)

    X_max = max(X)

    for i in range(N):
        X[i] = X_max - X[i]
        Y[i] = Y[i] - Y_min
        Z[i] = X[i] + Y[i]

    ans2 = max(Z) - min(Z)

    print(max(ans1, ans2))


main()

Measured memory_bytes: 32788
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
int n,m;
ll f[105][4][10][2];
char ch[105];
int main(){
	scanf("%s",ch+1);n=strlen(ch+1);
	scanf("%d",&m);
	for(reg int i=1;i<ch[1]-'0';i++)f[1][1][i][0]=1;
	f[1][0][0][0]=f[1][1][ch[1]-'0'][1]=1;
	for(reg int i=1;i<n;i++){
		for(reg int j=0;j<=m;j++){
			for(reg int k=0;k<10;k++){
				if(f[i][j][k][0]){
					f[i+1][j][0][0]+=f[i][j][k][0];
					if(j<m){
						for(reg int l=1;l<10;l++)
							f[i+1][j+1][l][0]+=f[i][j][k][0];
					}
				}
				if((k==ch[i]-'0')&&f[i][j][k][1]){
					if(j+(ch[i+1]-'0'>0)<=m)
						f[i+1][j+(ch[i+1]-'0'>0)][ch[i+1]-'0'][1]+=f[i][j][k][1];
					if(ch[i+1]-'0'>0)f[i+1][j][0][0]+=f[i][j][k][1];
					if(j<m)for(reg int l=1;l<ch[i+1]-'0';l++)f[i+1][j+1][l][0]+=f[i][j][k][1];
				}
			}
		}
	}
	reg ll Ans=0;
	for(reg int i=0;i<10;i++)
		Ans+=f[n][m][i][0]+f[n][m][i][1];
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,h[100005]={},ans=inf;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }
  sort(h,h+n);
  for(int i=0; i<n-k+1; i++) {
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str); // より高速なscanfを使用
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


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

const int INF = 1<<28;
int p;
string s;

int rec() {
  int res = INF;
  ++p;
  if(isdigit(s[p])) {
    string t;
    while(isdigit(s[p])) {
      t += s[p++];
    }
    res = atoi(t.c_str()) / 2 + 1;
  } else {
    vector<int> v;
    while(s[p] == '[') {
      v.push_back(rec());
    }
    sort(v.begin(), v.end());
    res = accumulate(v.begin(), v.begin() + v.size() / 2 + 1, 0);
  }
  ++p;
  return res;
}

int main() {
  int T; cin >> T;
  while(T--) {
    cin >> s;
    s += "$";
    p = 0;
    cout << rec() << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{s:chars};
    let mut mn = s.len() as i64;
    for i in 0..26 {
        let ch = ('a' as u8 + i) as char;
        //debug!(ch);

        let mut mx = 0i64;
        let mut cnt = 0i64;
        for j in 0..s.len() {
            if s[j] == ch {
                mx = max(mx, cnt);
                cnt = 0;
            } else {
                cnt += 1;
            }
        }
        mx = max(mx, cnt);

        mn = min(mn, mx);
    }
    println!("{}", mn);
}

Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

long long pow3[100001],a[100001],c[100001],q1[100001],q2[100001],count_=0,t1,t2,t3,t4;
string str;

int main()
{
    cin>>str;
    str.insert(0,"0");
    int lTl=str.size();
    pow3[0]=1;
    for(int i=1;i<=lTl;i++)
        pow3[i]=(pow3[i-1]*3)%1000000007;
    for(int i=1;i<=lTl;i++)
	{
        a[i]=a[i-1],q1[i]=q1[i-1];
        if(str[i]=='A')
            a[i]++;
        if(str[i]=='?')
            q1[i]++;
    }
    for(int i=lTl;i>=1;i--)
	{
        c[i]=c[i+1],q2[i]=q2[i+1];
        if(str[i]=='C')
            c[i]++;
        if(str[i]=='?')
            q2[i]++;
    }
    for(int i=1;i<=lTl;i++)
        if(str[i]=='B' || str[i]=='?')
		{
            t1=((a[i-1]*c[i+1])%1000000007*pow3[q1[i-1]+q2[i+1]])%1000000007;
            t2=((a[i-1]*q2[i+1])%1000000007*pow3[q1[i-1]+q2[i+1]-1])%1000000007;
            t3=((c[i+1]*q1[i-1])%1000000007*pow3[q1[i-1]+q2[i+1]-1])%1000000007;;
            t4=((q1[i-1]*q2[i+1])%1000000007*pow3[q1[i-1]+q2[i+1]-2])%1000000007;
            count_=(count_+((t1+t2)%1000000007+(t3+t4)%1000000007)%1000000007)%1000000007;
        }
    cout<<count_;
    return 0;
}

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

#define mod 1000000007
#define ll long long
#define MAXN 105
#define MAXK 100005

using namespace std;

ll dp[MAXN][MAXK], pre[MAXN][MAXK];

int main() {

    ll n, k;
    cin >> n >> k;

    ll a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];

    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= k; j++) {
            if(i == 0) {
                if(j <= a[0])
                    dp[0][j] = 1;
                else
                    dp[0][j] = 0;
                pre[0][j] = (j ? pre[0][j - 1] : 0) + dp[0][j];
                continue;
            }

            int left = j - a[i] - 1, right = j;

            dp[i][j] = (mod + pre[i - 1][right] - (left >= 0 ? pre[i - 1][left] : 0)) % mod;
            pre[i][j] = ((j ? pre[i][j - 1] : 0) + dp[i][j]) % mod;
        }
    }

    cout << dp[n - 1][k] << endl;
    return 0;
}


Measured memory_bytes: 160000
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

		int N = sc.nextInt();
		String S = sc.next();
		
		String Ss[] = S.split("");
		int max = 0;

		for (int i = 0; i < N; i++){
			
			Set<String> tmpA = new HashSet<String>();
			Set<String> tmpB = new HashSet<String>();
			
			for (int j = 0; j < i; j++) {
				tmpA.add(Ss[j]);
			}
			
			for (int j = 0; j < N - i; j++) {
				tmpB.add(Ss[N - 1 - j]);
			}

			
			tmpA.retainAll(tmpB);
			
			if (max < tmpA.size()) {
				max = tmpA.size();
			}

		}

		System.out.println(max);

	}
}

Measured memory_bytes: 24020
import sys
sys.setrecursionlimit(10**9)

n, m, q = map(int, input().split())
val = [list(map(int, input().split())) for _ in range(q)]
ans = 0

def dfs(A):
  global ans
  if len(A) == n+1:
    score = 0
    for a,b,c,d in val:
      if A[b]-A[a] == c:
        score += d
    ans = max(ans, score)
  else:
    A.append(A[-1])
    while(A[-1] <= m):
      dfs(A.copy())
      A[-1] += 1
A = [1]
dfs(A)
print(ans)


Measured memory_bytes: 9148
#include<stdio.h>
#define N 10000

int main(void){
  int i,num,j;
  int n,age,ans[N][7];

  for(i=0;;i++){
    for(j=0;j<7;j++) ans[i][j]=0;
    scanf("%d",&n);
    if(n==0) break; 
    for(j=0;j<n;j++){
      scanf("%d",&age);
      if(age<10) ans[i][0]++;
      else if(age<20) ans[i][1]++;
      else if(age<30) ans[i][2]++;
      else if(age<40) ans[i][3]++;
      else if(age<50) ans[i][4]++;
      else if(age<60) ans[i][5]++;
      else ans[i][6]++;
    }
  }
  
  num=i;

  for(i=0;i<num;i++)
    for(j=0;j<7;j++)
      printf("%d\n",ans[i][j]);
  return 0;
}

Measured memory_bytes: 372
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) { return (-data[find(k)]); }
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m), ans(m);
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  UnionFind uf(n);
  ans[m - 1] = n * (n - 1) / 2;
  REPR(i, m - 2) {
    if (uf.find(a[i + 1]) == uf.find(b[i + 1])) {
      ans[i] = ans[i + 1];
    } else {
      ll sa = uf.size(a[i + 1]), sb = uf.size(b[i + 1]);
      ans[i] = ans[i + 1] - sa * sb;
      uf.unite(a[i + 1], b[i + 1]);
    }
  }
  REP(i, m) { cout << ans[i] << endl; }
  return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 1000000009
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n;
    cin>>n;
    bool flag = true;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin>>a;
        if(a%2==0)
        {
            if(a%3==0 || a%5==0)
                continue;
            else
                flag = false;
        }
    }
    if(flag)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;

    //End();
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll n,i;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll pre[n];
    ll suff[n];
    ll x = arr[0];


    for(i=0;i<n;i++)
    {
        x = __gcd(arr[i],x);
        pre[i]=x;
    }
    ll y = arr[n-1];
    for(i=n-1;i>=0;i--)
    {
        y = __gcd(arr[i],y);
        suff[i]=y;
    }

    vector<ll>ans;

    for(i=1;i<n-1;i++)
    {
        ll p = pre[i-1];
        ll q = suff[i+1];
        ll r = __gcd(p,q);
        ans.pb(r);
    }

    ll p = __gcd(arr[0],x);
    ll q = __gcd(y,arr[n-1]);
    ans.pb(pre[n-2]);
    ans.pb(suff[1]);




    ll res = *max_element(ans.begin(), ans.end());
    cout<<res<<endl;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=2e5+9;
int n,b[N];
int lx[N],ld[N],rx[N],rd[N];
int f[N];
struct T{int x,y;}a[N];
bool cmp(T t1,T t2){return t1.x<t2.x;}
inline int getid(int x){return lower_bound(b+1,b+n+1,x)-b;}
void add(int x,int y){
    for(;x<N;x+=(x&-x))f[x]+=y;
}
int query(int x){int ans=0;while(x)ans+=f[x],x-=(x&-x);return ans;}
int poww(int a,int b,int c){
    int ans=1,base=a;
    while(b){
        if(b&1)ans=1ll*ans*base%c;
        base=1ll*base*base%c;
        b>>=1;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y,b[i]=a[i].y;
    sort(a+1,a+n+1,cmp),sort(b+1,b+n+1);
    for(int i=1;i<=n;i++){
        lx[i]=query(getid(a[i].y));
        ld[i]=query(N-1)-query(getid(a[i].y));
        add(getid(a[i].y),1);
    }
    memset(f,0,sizeof(f));
    for(int i=n;i>=1;i--){
        rx[i]=query(getid(a[i].y));
        rd[i]=query(N-1)-query(getid(a[i].y));
        add(getid(a[i].y),1);
    }
    int ans=0;
    ans=1ll*n*poww(2,n-1,mod)%mod;
    for(int i=1;i<=n;i++)ans=(ans+1ll*(poww(2,lx[i],mod)-1+mod)*(poww(2,rd[i],mod)-1+mod)%mod*poww(2,ld[i],mod)%mod*poww(2,rx[i],mod)%mod+1ll*(poww(2,ld[i],mod)-1+mod)*(poww(2,rx[i],mod)-1+mod)%mod*poww(2,lx[i],mod)%mod*poww(2,rd[i],mod)%mod)%mod,
        ans=(ans-1ll*(poww(2,lx[i],mod)-1)*(poww(2,ld[i],mod)-1)%mod*(poww(2,rx[i],mod)-1)%mod*(poww(2,rd[i],mod)-1)%mod+mod)%mod;

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


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

int main() {
  // �����Ƀv���O������ǋL
  int r,s;
  
  cin >> r ;
  cin >> s ;

  if((r%500-s) <= 0){
	cout << "Yes" << endl;
}else{
	cout << "No" <<endl;
}




  
}

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

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

    int num[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << num[K-1] << endl;
    return 0;
}


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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))

int main() {
    int array[3], k, max, rtn;
    cin >> array[0] >> array[1] >> array[2];
    cin >> k;

    sort(array, array+3, greater<int>());

    max = array[0];
    for(int i=0; i<k; i++)
        max *= 2;

    array[0] = max;

    rtn = 0;
    for(int i=0; i<COUNTOF(array); i++)
        rtn += array[i];
    cout << rtn;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int b;
    
    scanf("%d",&b);

    int a[b];
    int c=0;
    int x=0;
    int i=1;
    int total=0;
        for( i=0; i<b;i++){
        
            scanf("%d",&a[i]);
        
        }
        x=a[b-1];
        for( i=b-2; i>=0;i--){
        
            if(a[i]>=x){
                c++;
                if(c>total)
                    total=c;
            }else{
                
                c=0;
            }
            x=a[i];
        
        }
    printf("%d",total);
    return 0;
    
}


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

using namespace std;

#define int int64_t

const int maxn = 1e5 + 42;

set<pair<int, int>> comp[maxn];
int par[maxn];


void uni(int a, int b) {
    a = par[a];
    b = par[b];
    if(a == b) {
        return;
    }
    if(comp[a].size() > comp[b].size()) {
        swap(a, b);
    }
    for(auto it: comp[a]) {
        comp[b].insert(it);
        par[it.second] = b;
    }
    comp[a].clear();
}

signed main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    set<pair<int, int>> all;
    for(int i = 0; i < n; i++) {
        par[i] = i;
        comp[i] = {{a[i], i}};
        all.insert({a[i], i});
    }
    int x[m], y[m];
    for(int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        uni(x[i], y[i]);
    }
    int ans = 0;
    int need = -2;
    for(int i = 0; i < n; i++) {
        if(i == par[i]) {
            ans += begin(comp[i])->first;
            all.erase(*begin(comp[i]));
            need++;
        }
    }
    if(need < 0) {
        cout << 0 << endl;
        return 0;
    }
    if(need > all.size()) {
        cout << "Impossible" << endl;
        return 0;
    }
    for(auto it: all) {
        if(need == 0) {
            break;
        }
        ans += it.first;
        need--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20864
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

int main()
{
  ll a[5];ll ans=0;
  for(ll i=0;i<5;i++)
  {
      cin >> a[i];
      if(a[i]==0)
      ans=i+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn score(c: &[i64], s: &[Vec<i64>], t: &[usize]) -> Vec<i64> {
    let d = t.len();
    let mut last = vec![0; 26];
    let mut sc = 0;
    let mut scs = vec![];
    for i in 0..d {
        last[t[i]] = i as i64 + 1;
        sc += s[i][t[i]];
        for j in 0..26 {
            sc -= (i as i64 - last[j] + 1) * c[j];
        }
        scs.push(sc);
    }
    scs
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
        t: [usize1; d],
    }
    let scs = score(&c, &s, &t);
    for i in 0..d {
        puts!("{}\n", scs[i]);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int A;
  cin >> A;
  int G = A, M = A;
  for (int i = 1; i < N; i++) {
    int a;
    cin >> a;
    G = __gcd(a, G);
    M = max(a, M);
  }
  if (K <= M && K % G == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
import sys


def solve(lines):
    split = lines[0].strip().split()
    H = int(split[0])
    W = int(split[1])

    board = list(map(lambda x: list(x.strip()), lines[1:]))
    result = [[0 for _ in range(W)] for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if board[i][j] == '#':
                result[i][j] = '#'
                continue

            count = 0
            if i > 0:
                count += board[i - 1][j] == '#'
                if j > 0:
                    count += board[i - 1][j - 1] == '#'
                if j < W - 1:
                    count += board[i - 1][j + 1] == '#'
            if i < H - 1:
                count += board[i + 1][j] == '#'
                if j > 0:
                    count += board[i + 1][j - 1] == '#'
                if j < W - 1:
                    count += board[i + 1][j + 1] == '#'
            if j > 0:
                count += board[i][j - 1] == '#'
            if j < W - 1:
                count += board[i][j + 1] == '#'

            result[i][j] = str(count)

    return '\n'.join([''.join(r) for r in result])


if __name__ == '__main__':
    print(solve(sys.stdin.readlines()))


Measured memory_bytes: 3444
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve():
    s = input()
    n = int(input())
    idx = 0
    slen = len(s)
    while idx < slen and s[idx] == "1":
        idx += 1
        if idx == n:
            print(1)
            return
    if idx == slen:
        print(1)
    else:
        print(s[idx])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<sstream>
#include<cmath>

using namespace std;

const int MAX = 13;
vector<double> Cake;
double box;
double dp[(1<<MAX)][MAX];

void init(){
  Cake.clear();
  fill(dp[0],dp[0]+(1<<MAX)*MAX,100000000);
  dp[0][0] = 0;
}

void make(){
  string s;
  getline(cin,s);
  stringstream ss(s);
  double num;
  while(ss >> num) Cake.push_back(num);
}

void solve(){


  for(int i = 0; i < (1<<Cake.size()); i++)
    for(int j = 0; j < (int)Cake.size(); j++){
      if(i == 0) {dp[(1<<j)][j] = Cake[j]; continue;}
      for(int k = 0; k < (int)Cake.size(); k++)
	if(!(i&(1<<k)) && j != k){
	  dp[i+(1<<k)][k] = min(dp[i+(1<<k)][k],dp[i][j]+2.0*sqrt(Cake[j]*Cake[k]));
	  //	  if(dp[i][j] == 0) cout << "error" << endl;
	}
    }

  for(int i = 0; i < (int)Cake.size(); i++){
    //    cout << "cake " << Cake[i] << endl;
    //cout << dp[(1<<Cake.size())-1][i]+Cake[i] << endl;
    if(dp[(1<<Cake.size())-1][i]+Cake[i] <= box) {cout << "OK" << endl;return;}
  }
  cout << "NA" << endl;
}

int main(){

  while(cin >> box){
    init();
    make();
    solve();
  }
  return 0;
}

Measured memory_bytes: 2092
import sys
# sys.setrecursionlimit(10**10)
# N = int(sys.stdin.readline().rstrip())
# S = sys.stdin.readline().rstrip()
N, K = map(int, sys.stdin.readline().rstrip().split())
# A = list(map(int, sys.stdin.readline().rstrip().split()))
print(N*K)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    ll q;
    cin >> q;
    vi b(q), c(q);
    rep(i,q) cin >> b.at(i) >> c.at(i);
    vi num(100007,0);
    ll sum = 0;
    rep(i,n){
        num.at(a.at(i))++;
        sum += a.at(i);
    }
    rep(i,q){
        ll diff = c.at(i) - b.at(i);
        sum += diff * num.at(b.at(i));
        num.at(c.at(i)) += num.at(b.at(i));
        num.at(b.at(i)) = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 6360
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };
	static ArrayList<Integer> prime = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		prime.add(6);
		for (int base = 7; base < 300010; base += 7) {
			if (isPrime(base + 1)) prime.add(base + 1);
			if (isPrime(base + 6)) prime.add(base + 6);
		}
		while (true) {
			int N = sc.nextInt();
			if (N == 1) break;
			System.out.print(N + ":");
			for (int i = 0; prime.get(i) <= N; ++i) {
				if (N % prime.get(i) == 0) System.out.print(" " + prime.get(i));
			}
			System.out.println();
		}
	}

	static boolean isPrime(int n) {
		for (int p : prime) {
			if (n % p == 0) return false;
			if (p * p >= n) break;
		}
		return true;
	}

}

Measured memory_bytes: 29336
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    solve <$> getl (wrds toInt) >>= mapM_ print
    main

solve :: [Int] -> [Int]
solve xs = concat $ zipWith f [31,26,21,16,11,6,1] (cycle xs)
  where
    f x y = [x,max 0 (x-y)]

toInt :: String -> Int
toInt s = read s

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4084
import java.util.Scanner;
class Main{
    int n,i,a;
    int max = -9999999;
    int min = 9999999;
    long sam = 0;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(i = 0; i < n; i++){
            a = sc.nextInt();
            sam += a;
            if(n == 0){
                min = 0;
                max = 0;
            }else if(n == 1){
                max = a;
                min = a;
            }else if(a < min){
                min = a;
            }else if(a > max){
                max = a;
            }else if(a == min || a == max){
                continue;
            }
            
        }
    System.out.println(min + " " + max + " " + sam);
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 31780
using System;
 
class Sample{
	public static void Main(){
    	var str = int.Parse(Console.ReadLine());
       
        if(str == 25)
        {
        	Console.WriteLine("Christmas");
        }
      
        else if(str == 24)
   		{
        	Console.WriteLine("Christmas Eve");
        }
      	else if(str == 23)
   		{
        	Console.WriteLine("Christmas Eve Eve");
        }
        else if(str == 22)
   		{
        	Console.WriteLine("Christmas Eve Eve Eve");
        }
   }
}

Measured memory_bytes: 11220
#include<iostream>
using namespace std;
int main(){
	int c,t,ans=9999999,in,ti;
	cin>>c>>t;
	for(int i=0;i<c;i++){
		cin>>in>>ti;
		if(ti>t)continue;
		if(in<ans)ans=in;
	}
	if(ans==9999999)cout<<"TLE";
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = sorted(list(map(str,input().split())))
def runlength(S):
    ans = []
    for s in S:
        if len(ans) == 0 or ans[-1][0] != s:
            ans.append([s,1])
        else:
            ans[-1][1] += 1
    return ans
a = runlength(a)
a.sort(key = lambda x:x[1],reverse = True)
b = a[k:]
ans = 0
for i in range(len(b)):
  ans += b[i][1]
print(ans)

Measured memory_bytes: 103632
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair
 
using namespace std;
 
const ll MOD = 1000000007LL;
const long double pi=3.1415926535897;
 
ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];
 
ll ar[5000056];
ll br[5000056];
vector<int> adj[5000005];
set<vector<int> > st;
set<ll> sets;
 
bool vis[520];
ll sum;
 
bool prime[10000006];
 
vector<int> primes,vec,pec;
 
 
 
ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;
 
}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}
 
inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}
 
ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
 
void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {
 
      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 
 
      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}
 
void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}
 
map<ll,ll> has,occur[1000005];
bool flag;
 
 
void dfs0(int s)
{
	
	vis[s]=1;
	vector<int>::iterator it;
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
			sum^=ar[*it];
			dfs0(*it);
		}
	}
	
}
 
 

int main() 
{
    ll n,m,t,p,q,s,a,b,c,d,e,f,g,h,res,u,v,i,j,l,k,len,ans=0,tot,rad,ds,rs,x,y,r,z,maxm,minm,pos,start,en;
    
    string str,ptr;
    
    cin>>n;
    
    for(i=0;i<n;i++)
    {
    	cin>>a;
    	
    	if(has[a])
    	{
    		has[a]=0;
    		sets.erase(a);
    		continue;
		}
		
		has[a]=1;
		sets.insert(a);
	}
     
    cout<<sets.size();
	return 0;
    
}

Measured memory_bytes: 177024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int mod = 1e9+7;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

long long C(int n, int k) {
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main() {
  int n; cin >> n;
  vector<int> a(n+1);
  init();
  map<int, int> alr;
  int left = -1, right = -1;
  for(int i = 0; i < n + 1; ++i) {
    cin >> a[i];
    if(alr.count(a[i])) left = alr[a[i]], right = i;
    else alr[a[i]] = i;
  }

  for(int k = 1; k <= n+1; ++k) {
    long long ans = 0;
    ans = (ans + C(n+1, k)) % mod;
    ans = (ans - C(left + n - right, k-1) + mod) % mod;

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 18304