akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

/*
  階乗計算（MODで割った余りで返す）
*/

class Factorial {
    private:
        vector<long long> fac;
    public:
        Factorial();
        Factorial(long long n_max);
        void initialization(long long n_max);
        long long getFactorial(long long n);
};

Factorial::Factorial() {}
Factorial::Factorial(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
void Factorial::initialization(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
long long Factorial::getFactorial(long long n) {
    return fac[n];
}

/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u % m;
}

/*
    順列と組み合わせ (P, C, H)
*/

class PCH {
    private:
        Factorial fact;
    
    public:
        PCH(long long n_max);
        long long P(long long n, long long r);
        long long C(long long n, long long r);
        long long H(long long n, long long r);
};
PCH::PCH(long long n_max) {
    fact.initialization(n_max);
}
long long PCH::P(long long n, long long r) {
    return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD;
}

long long PCH::C(long long n, long long r) {
    return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD * modinv(fact.getFactorial(n - r), MOD) % MOD;
}

long long PCH::H(long long n, long long r) {
    return C(n - 1 + r, r);
}

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

    PCH pch(N);

    for (int i = 1; i <= K; i++) {
        if (i > K || (i - 1) > (N - K)) cout << 0 << endl;
        else cout << (pch.H(i, K - i) * pch.H(i + 1, (N - K) - (i - 1)) % MOD) << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int H,W; cin >> H >> W;
  int n; cin >> n;
  vi a(n); rep(i, n) cin >> a[i];
  vvi c(H,vi(W,-1));
  int i = 0, dir = 0;
  int h = 0, w = 0;
  while (1) {
    c[h][w] = i+1;
    a[i]--;
    if(a[i] == 0) i++;
    if(i == n) break;
    if(h+dh[dir] < 0 || h+dh[dir] == H || w+dw[dir] < 0 || w+dw[dir] == W){
      dir = (dir+1)%4;
    }
    if(c[h+dh[dir]][w+dw[dir]] != -1) {
      dir = (dir+1)%4;
    }
    h += dh[dir];
    w += dw[dir];
  }

  rep(h, H){
    rep(w, W){
      if(w < W-1) std::cout << c[h][w] << " ";
      else std::cout << c[h][w] << '\n';
    }
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<math.h>
#include<string.h>
#include<queue>

using namespace std;

#define M  100000+100
#define mod 998244353
typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    cout<<n*n;
    return 0;
}


Measured memory_bytes: 256
S = input()

start_0_count = 0
for i in range(len(S)):
    if i%2 == 0 and S[i] != "0":
        start_0_count += 1
    elif i%2 == 1 and S[i] != "1":
        start_0_count += 1
    else:
        pass
    
start_1_count = 0
for i in range(len(S)):
    if i%2 == 0 and S[i] != "1":
        start_1_count += 1
    elif i%2 == 1 and S[i] != "0":
        start_1_count += 1
    else:
        pass

print(min(start_0_count, start_1_count))

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

long *wt,*val;
long solve(long space_left, long n, long dp[][100]){
    if(space_left < 0)
        return INT32_MIN;
    if(n==0)
        return 0;
    if(dp[space_left][n] != -1)
        return dp[space_left][n];
    long op1 = val[n] + solve(space_left-wt[n],n-1,dp);
    long op2 = solve(space_left,n-1,dp);
    return dp[space_left][n] = max(op1,op2);
}
int main(){
    long n,space;
    cin>>n>>space;
    wt = new long[n+1];
    val = new long [n+1];
    long dp[space + 2][100];

    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++){
        cin>>wt[i]>>val[i];
    }
    cout<<solve(space,n,dp);
    return 0;
}

Measured memory_bytes: 81652
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

double sqr(double x) {
	return (double) x*x;
}

int main() {

	int n,d;
	cin>>n;
	string s;
	cin>>s;
	int w = 0;
	int i;
	for (i=0;i<n;i++)
	if (s[i] == 'W') w++;

	int k=0;
	for (i=n-1;i>=n-w;i--)
	if (s[i] == 'R') k++;

	cout<<k<<"\n";

    return 0;
}

Measured memory_bytes: 3712
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;
    static final String YES = "Yes";
    static final String NO = "No";

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        String S;
        S = sc.next();
        solve(S);
    }

    static void solve(String S){
        char[] c = S.toCharArray();
        if (c[2] == c[3] && c[4] == c[5]) System.out.println("Yes");
        else System.out.println("No");
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            return nn();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 23124
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n;
int a[2011];
bool u[2011];
vector<int> g[2011];
vector<int> merg(vector<int> x, vector<int> y){
	vector<int> c;
//	cerr << "IN " << (int)x.sz() << " " << (int)y.sz() << endl; 
	for(int i = 0, j = 0; i < x.sz() || j < y.sz();){
		if(i == (int)x.sz() || (j < (int)y.sz() && x[i] < y[j]))
			c.pb(y[j ++]);
		else
			c.pb(x[i ++]);
	}
	return c;
}
bool cmp(int x, int y){
	return a[x] < a[y];
}
vector<int> dfs(int v){
	u[v] = 1;
	vector<int> res;
	res.pb(inf);
	sort(g[v].beg(), g[v].end(), &cmp);
	for(auto to : g[v]){
		if(!u[to]){
			res = merg(res, dfs(to));
		}
	}
	res[0] = a[v];
	return res;
}
pair<int, int> b[2011];
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		for(int j = i + 1; j <= n; j ++){
			if(__gcd(a[i], a[j]) > 1){
				g[i].pb(j);
				g[j].pb(i);
			}
		}
		b[i] = mp(a[i], i);
	}	
	vector<int> ans;
	sort(b + 1, b + 1 + n);
	for(int i = 1; i <= n; i ++){
		if(!u[b[i].S]){
			ans = merg(ans, dfs(b[i].S));
		}
	}
	for(int i = 0; i < ans.sz(); i ++)
		cout << ans[i] << " ";
	return 0;
}

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

int main() {
	string a, b, c; cin >> a >> b >> c;
	if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


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

int main() {
  string o, e;
  cin >> o >> e;
  string s;
  for(int i = 0;i < o.size();i++){
    s += o[i];
    if(i < e.size()){
      s += e[i];
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
K, A, B = input().split()
K = int(K)
A = int(A)
B = int(B)
N = 1

if A+2 > B:
    N = N + K
else:
    # ビスケットを金にする価値がある
    if K > A:
        # 1回目
        K = K - (A + 1)
        N = B
        if K > 0:
            # 売る買うを繰り返す
            if K % 2 == 0:
                N = N + (B*K//2) - (A*K//2)
            else:
                K = K - 1
                N = N + (B*K//2) - (A*K//2) + 1
    else:
        # 価値はあるが交換にたどり着ける程残り回数がない
        N = N + K
print(N)

Measured memory_bytes: 3064
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define pi pair<ll,ll>
#define fi first
#define si second
#define mkp make_pair
#define pb push_back
#define clr(arr) memset(arr,0,sizeof(arr))
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
deque<ll>dq;
map<ll,ll>mp;
set<ll>st;
vector<ll>vt;
ll mod=1e9+7;
const int N=1e6+5;
ll arr[N];

int main()
{
    IOS;
    ll n,m,x,y,z,i,j,k,p,f=0,tc,cnt=0,sum=0,mul=1,mi=1e18,ma=-1e18,a,b,c,d,sz;
    string str;
    char ch;
    double db;
    //code
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i],mi=min(mi,arr[i]),ma=max(ma,arr[i]);
  x=ma;
  ll mi1=1e18;
  for(i=mi;i<=x;i++)
  {
      sum=0;
      for(j=0;j<n;j++)
      {
          p=abs(i-arr[j]);
          sum+=p*p;
      }
      mi1=min(sum,mi1);
  }

   cout<<mi1<<endl;



    //code
    return 0;
}



Measured memory_bytes: 3616
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
main(){
  double a,b,C;
  double S,L,h;
  cin >> a >> b >> C ;
  C=C/180*M_PI;
  S=(a*b*sin(C))/2;
  L=a+b+sqrt(a*a+b*b-2*a*b*cos(C));
  h=b*sin(C);
  printf("%.8f\n%.8f\n%.8f\n",S,L,h);
}

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


int main()
{
    int H, W;
    cin >> H >> W;
    char S[H+2][W+2];
    for (int i = 1; i <= H; ++i){
        for (int j = 1; j <= W; ++j){
            cin >> S[i][j];
        }
    }
    int cnt = 0;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if (S[i][j] == '#' && S[i][j - 1] != '#' && S[i - 1][j] != '#' && S[i][j + 1] != '#' && S[i + 1][j] != '#')
                cnt++;
        }
    }
    if (cnt == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    vector<int>ans;
    for(int i = a;i<a+k;i++) {
        ans.push_back(i);
    }
    for(int i = b;i>b-k;i--) {
        ans.push_back(i);
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    rep(i,ans.size()) {
        if(ans[i]<a) continue;
        if(ans[i]>b) break;
        cout << ans[i] << endl;
    }
    
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	char ch[3];
	int a = 0, b = 0;
	for (int i = 0; i < 3; ++i)
	{
		cin >> ch[i];
		if (ch[i] == 'A')
		{
			a++;
		}
		else
			b++;
	}
	if (a != 3 && b != 3)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int isEmpty(int*);
void Push(int*,int*,int);
int Pop(int[],int*);

main(){
  int S[101];
  int top=0;
  int x,y,a,b;
  char c,s[100];


  while( scanf(" %s", s) != EOF ){
    if ( s[0] == '+' ){
	x=Pop(S,&top)+Pop(S,&top);
	Push(S,&top,x);
	
    } else if ( s[0] == '-' ){
      
      a = Pop(S,&top);
      b = Pop(S,&top);
      x=b-a; 
      Push(S,&top,x);
      
    } else if ( s[0] == '*' ){
      x=Pop(S,&top)*Pop(S,&top);
      Push(S,&top,x);
      
      
    } else {
      y=atoi(s);
      Push(S,&top,y);
    }
  }
  printf("%d\n",S[top]);
  
  return 0;
  
}

int isEmpty(int *top){
  
  if(*top==0)return 0;
  else return 1;
}

void Push(int *S,int *top,int x){
  *top+=1;
  S[*top]=x;
}

int Pop(int S[],int *top){
  if(isEmpty(top)==0) printf("underflow\n");

  else{
    *top-=1;
    return S[*top+1];
  }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n);
    lint x = 0;
    REP(i, n){
        cin >> a[i];
        x ^= a[i];
    }
    REP(i,n){
        int aa = x ^ a[i];
        cout << aa << "\n";
    }
    return 0;
}

Measured memory_bytes: 4692
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

ll josephus(ll n, ll k, ll s) {
	// n : number of people
	// k : number of skips
	// s : number of turn
	ll ret = k * s;
	while(ret > n) {
		ret = ((ret - n) * k - 1) / (k - 1);
	}
	return ret;
}

int main() {
	int n, k, m;
	while(cin >> n >> k >> m, n) {
		int o = k % n;
		int diff = m - o;
		int ans = (josephus(n, k, n) + diff + n) % n;
		cout << (ans != 0 ? ans : n) << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;


int union_data[100005];
int union_weight[100005];

void union_init(int n){
  for(int i=0;i<n;i++){
    union_data[i] = i;
    union_weight[i] = 1;
  }
}

int union_root(int x){
  int tmp = x;
  while(x!=union_data[x]){
    x = union_data[x];
  }
  while(tmp != union_data[tmp]){
    tmp = union_data[tmp];
    union_data[tmp] = x;
  }
  return x;
}

bool union_eq(int x,int y){
  return union_root(x) == union_root(y);
}

int union_join(int x, int y){
  if(union_eq(x,y)) return 0;
  if(union_weight[y] > union_weight[x]){
    union_weight[union_root(x)] += union_weight[union_root(y)];
    union_data[union_root(y)] = union_root(x);
  } else {
    union_weight[union_root(y)] += union_weight[union_root(x)];
    union_data[union_root(x)] = union_root(y);
  }
  return 0;
}

int union_size(int x){
  return union_weight[union_root(x)];
}

int n,m;
pair<long long,int> a[100005];
long long tmp[100005];

int main(){
  cin>>n>>m;
  union_init(n);
  for(int i=0;i<n;i++){
    long long t;cin>>t;
    a[i] = make_pair(t,i);
  }

  sort(a,a+n);

  //for(int i=0;i<n;i++)cout<<a[i].first<<" "<<a[i].second<<endl;

  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    union_join(x,y);
  }

  int focnt = 0;
  for(int i=0;i<n;i++){
    if(union_root(i) == i) focnt++;
  }

  if(focnt == 1){
    cout<<"0"<<endl;
    return 0;
  }

  long long ans = 0;
  int lim = 2*(focnt-1);

  if(lim > n){
    cout<<"Impossible"<<endl;
    return 0;
  }

  //cout<<focnt<<endl;

  for(int i=0;i<n;i++){
    if(lim == 0) break;
    if(tmp[union_root(a[i].second)] == 0){
      //cout<<i<<endl;
      ans += a[i].first;
      tmp[union_root(a[i].second)] = 1;
      lim--;
    }
  }
  //cout<<ans<<endl;
  for(int i=0;i<n;i++){
    if(lim == 0) break;
    if(tmp[union_root(a[i].second)] == 1){
      tmp[union_root(a[i].second)] = 0;
    } else {
      lim--;
      ans += a[i].first;
    }
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	Scanner sc = new Scanner(System.in);
	final int NUM_CONTEST = 26;
	int D;
	int [] c  = new int[NUM_CONTEST];
	int [][] s ;
	int [] t ;
	int [] last_day;
	void A() {
		D = sc.nextInt();
		s = new int[D][NUM_CONTEST];
		for(int i = 0; i < NUM_CONTEST; i++) {
			c[i] = sc.nextInt();
		}
		for(int i = 0; i < D; i++) {
			for(int j = 0; j < NUM_CONTEST; j++) {
				s[i][j] = sc.nextInt();
			}
			//System.out.println(Arrays.toString(s[i]));
		}

//		t = new int[D];
		last_day = new int[NUM_CONTEST];
		Arrays.fill(last_day, -1);
//		for(int i = 0; i < D; i++) {
//			t[i] = sc.nextInt() - 1;
//		}
		long ans = 0;
		for(int d = 0; d < D; d++) {
			int max_contest = 0, max_value = Integer.MIN_VALUE;
			for(int cand = 0; cand < NUM_CONTEST; cand++) {
				int inc = s[d][cand];
				int last_day_old = last_day[cand];
				last_day[cand] = d;
				int dec = 0;
				for(int i = 0; i < NUM_CONTEST; i++) {
					dec += c[i] * (d - last_day[i]);
				}
				if(inc - dec > max_value) {
					max_value = inc - dec;
					max_contest = cand;
				}
				last_day[cand] = last_day_old;
			}
			last_day[max_contest] = d;
			System.out.println(max_contest + 1);
		}
	}
	void B() {
		D = sc.nextInt();
		s = new int[D][NUM_CONTEST];
		for(int i = 0; i < NUM_CONTEST; i++) {
			c[i] = sc.nextInt();
		}
		for(int i = 0; i < D; i++) {
			for(int j = 0; j < NUM_CONTEST; j++) {
				s[i][j] = sc.nextInt();
			}
			//System.out.println(Arrays.toString(s[i]));
		}

		t = new int[D];
		last_day = new int[NUM_CONTEST];
		Arrays.fill(last_day, -1);
		for(int i = 0; i < D; i++) {
			t[i] = sc.nextInt() - 1;
		}
		long ans = 0;
		for(int d = 0; d < D; d++) {
			int inc = s[d][t[d]];
			last_day[t[d]] = d;
			int dec = 0;
			for(int i = 0; i < NUM_CONTEST; i++) {
				dec += c[i] * (d - last_day[i]);
			}
			//System.out.println(inc + " " + dec + " " + (inc - dec));
			ans += (inc - dec);
			System.out.println(ans);

		}
	}
	void f(long [] ans) {
		last_day = new int[NUM_CONTEST];
		Arrays.fill(last_day, -1);
		for(int d = 0; d < D; d++) {
			int inc = s[d][t[d]];
			last_day[t[d]] = d;
			int dec = 0;
			for(int i = 0; i < NUM_CONTEST; i++) {
				dec += c[i] * (d - last_day[i]);
			}
			//System.out.println(inc + " " + dec + " " + (inc - dec));
			ans[d+1] = ans[d] + (inc - dec);

		}

	}
	void C() {

		D = sc.nextInt();
		s = new int[D][NUM_CONTEST];
		for(int i = 0; i < NUM_CONTEST; i++) {
			c[i] = sc.nextInt();
		}
		for(int i = 0; i < D; i++) {
			for(int j = 0; j < NUM_CONTEST; j++) {
				s[i][j] = sc.nextInt();
			}
			//System.out.println(Arrays.toString(s[i]));
		}

		t = new int[D];
		for(int i = 0; i < D; i++) {
			t[i] = sc.nextInt() - 1;
		}
		long [] ans = new long[D+1];
		f(ans);
		//System.out.println(Arrays.toString(ans));
		int M = sc.nextInt();
		for(int i = 0; i < M; i++) {
			int d = sc.nextInt() - 1;
			int q = sc.nextInt() - 1;
			t[d] = q;
			ans = new long[D+1];
			f(ans);
			//System.out.println(Arrays.toString(ans));
			System.out.println(ans[D]);
		}
	}
	void doIt() {
		C();
	}
	public static void main(String[] args) {
		new  Main().doIt();
	}

}


Measured memory_bytes: 59756
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define vll vector<ll>
#define G vector<vll >
#define gg vector<int>
#define F first
#define S second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define clr(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define rll read_ll();
#define gc getchar
#define pc putchar
typedef long long ll;
template<class T> inline T lcm(T a,T b){
        return a/gcd(a,b)*b;
}
template<typename T>
void debug(T first) {
    cout << first << "\n";
}
template<typename T, typename... Args>
void debug(T first, Args... args) {
    cout << first << " ";
    debug(args...);
}


ll read_ll(){char c=gc();while((c<'0'||c>'9')&&c!='-')c=gc();ll ret=0;int neg=0;if(c=='-')neg=1,c=gc();while(c>='0'&&c<='9'){ret=10*ret+c-48;c=gc();}return neg?-ret:ret;}

int main()
{
	ll n; 
	scanf("%lld", &n);
	string s; cin>>s;
	ll q; cin>>q;
	vector<pll>pos;
	FOR(i,1,q) {
		ll val; cin>>val;
		pos.emplace_back(val,i);
	}
	sort(all(pos));
	vector<pll>ans;
	ll i = 0;
	while(i < q) {
		ll d = 0, dm = 0, dmc = 0, m = 0;
		ll front = 0;
		FOR(k,0,n-1) {
			char c = s[k], oc = '|';
			if(k < pos[i].F) {
				if(c == 'C') dmc += dm;
				else if( c == 'D') d++;
				else if(c == 'M') m++, dm += d;
			} else {
				oc = s[front++];
				if(oc == 'D') dm -= m, d--;
				if(oc == 'M') m--;

				if(c == 'C') dmc += dm;
				else if( c == 'D') d++;
				else if(c == 'M') m++, dm += d;
			}
		}
		ans.emplace_back(pos[i++].S,dmc);
	}
	sort(all(ans));
	for(auto val : ans) cout<<val.S<<endl;
	return 0;
}

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

int N, W;
int w[110];
int v[110];

int dp[110][330][100];
//int dp[110][330];

/*
int search_max(int now, int maxnum, int weight, int id) {
  if (dp[now][id] != -1) {
     return dp[now][id];
   }

  if (now == maxnum) {
    if (weight < w[now]) {
      return dp[now][id] = 0;
      // return 0;
    } else {
      return dp[now][id] = v[now];
      // return v[now];
    }
  }

  else {
    int tempin, tempout, tempid;
    if (w[now] <= weight) {
      tempin = search_max(now + 1, maxnum, weight - w[now], id+w[now]-w[0]+1) + v[now];
      
    } else {
      tempin = -1;
    }
    tempout = search_max(now + 1, maxnum, weight, id);
    // printf("num:%d in:%d out:%d\n", now, tempin, tempout);
    if (tempin > tempout) {
      // printf("%d, %d\n", now, tempin);
      return dp[now][id] = tempin;
      // return tempin;
    } else {
      // printf("%d, %d\n", now, tempout);
      return dp[now][id] = tempout;
      // return tempout;
    }
  }
}
*/


int search_max(int now, int maxnum, int weight, int id, int count) {
  if (dp[now][id][count] != -1) {
     return dp[now][id][count];
   }

  if (now == maxnum) {
    if (weight < w[now]) {
      return dp[now][id][count] = 0;
      // return 0;
    } else {
      return dp[now][id][count] = v[now];
      // return v[now];
    }
  }

  else {
    int tempin, tempout, tempid, tempcount;
    if (w[now] <= weight) {
      tempid =id + w[now] - w[0]+1;
      tempcount = count + 1;
      tempin = search_max(now + 1, maxnum, weight - w[now], tempid, tempcount) + v[now];
      
    } else {
      tempin = -1;
    }
    tempout = search_max(now + 1, maxnum, weight, id, count);
    // printf("num:%d in:%d out:%d\n", now, tempin, tempout);
    if (tempin > tempout) {
      // printf("%d, %d\n", now, tempin);
      return dp[now][id][count] = tempin;
      // return tempin;
    } else {
      // printf("%d, %d\n", now, tempout);
      return dp[now][id][count] = tempout;
      // return tempout;
    }
  }
}


/*
int search(const int i, const int n, const int sum_v, const int sum_w)
{
  if (i == n) {
    return sum_v;
  }

  x[i] = 0;
  const double v0 = search(i + 1, n, sum_v, sum_w);

  x[i] = 1;
  const double v1 = search(i + 1, n, sum_v + v[i], sum_w + w[i]);

  return (v0 > v1) ? v0 : v1;
}
*/
/*
void solve_dp2() {
  for (int j = 0; j <= W; j++) {
    dp[n][j] = 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j <= W; j++) {
      if (j < w[i])
        dp[i][j] = dp[i + 1][j];
      else
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
    }
  }
  cout << dp[0][W] << endl;
}
*/

int main() {
  int i, j, l;
  int ans;

/*
  for (i = 0; i < 110;i++){
    for (j = 0; j < 330;j++){
      dp[i][j] = -1;
    } }
    */
  
    for (i = 0; i < 110;i++){
    for (j = 0; j < 330;j++){
      for (l = 0; l < 100; l++) {
        dp[i][j][l] = -1;
      }
    } }


  scanf("%d %d", &N, &W);
  for (i = 0; i < N; i++) {
    scanf("%d %d", &w[i], &v[i]);
  }

  ans = search_max(0, N - 1, W, 0, 0);
  //ans = search_max(0, N - 1, W, 0);
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 14336
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ogiekako
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		MyScanner in = new MyScanner(inputStream);
		MyPrintWriter out = new MyPrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, MyScanner in, MyPrintWriter out) {
        long res = Long.MAX_VALUE;
        int N = in.nextInt();
        int x = in.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) a[i] = in.nextInt();
        long[] min = new long[N];
        Arrays.fill(min, Long.MAX_VALUE);
        for (int i = 0; i < N; i++) {
            long val = 0;
            for (int j = 0; j < N; j++) {
                min[j] = Math.min(min[j], a[(i-j+N)%N]);
                val += min[j];
            }
            res = Math.min(res, val + (long) i * x);
        }
        out.println(res);
    }
}

class MyScanner {
    private final InputStream in;

    public MyScanner(InputStream in) {
        this.in = in;
    }

    private static final int BUFSIZE = 65536;
    int bufLen;
    int bufPtr;
    byte[] buf = new byte[BUFSIZE];

    public int read() {
        if (bufLen == -1)
            throw new InputMismatchException();
        if (bufPtr >= bufLen) {
            bufPtr = 0;
            try {
                bufLen = in.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bufLen <= 0)
                return -1;
        }
        return buf[bufPtr++];
    }

    public int nextInt() {
        int c = read();
        if (c == -1) throw new NoSuchElementException();
        while (c != '-' && (c < '0' || '9' < c)) {
            c = read();
            if (c == -1) throw new NoSuchElementException();
        }
        if (c == '-') return -nextInt();
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while ('0' <= c && c <= '9');
        return res;
    }

}

class MyPrintWriter {
    PrintWriter out;

    public MyPrintWriter(OutputStream outputStream) {
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void println(Object... os) {
        if (os.length == 0) {
            out.println();
            return;
        }
        for (int i = 0; i < os.length - 1; i++) {
            out.print(os[i]);
            out.print(' ');
        }
        out.println(os[os.length - 1]);
    }

    public void close() {
        out.close();
    }

}



Measured memory_bytes: 8404
#include <stdio.h>

#define MAX 10

void print( int val, int delim )
{
	if ( val != delim ) {
		printf( "%d ", val );
	} else if ( val == delim ) {
		printf( "%d", val );
	}
}

int main()
{
	int path[MAX][MAX], s, d;
	int num;

	scanf( "%d", &num );
	for ( int i = 0 ; i < num ; i++ ) {
		scanf( "%d %d", &s, &d );
		if ( i > 102 ) { break; }
		// 場合分け
		// s:d:5 x
		// d:s:5 x
		// s:5:d
		// d:5:s
		// 5:d:s o
		// 5:s:d o
		if ( s <= 5 && d <= 5 ) {
			if ( s < d ) {
				while ( s < d ) {
					print( s, d );
					s++;
				}
			} else if ( s > d ) {
				while ( s > d ) {
					print( s, d );
					s--;
				}
			}
		} else if ( s >= 5 && d >= 5 ) {
			if ( s < d ) {
				while ( s < d ) {
					print( s, d );
					s++;
				}
			} else if ( s > d ) {
				while ( s < MAX ) {
					print( s, d );
					s++;
				}
			s = 5;
				if ( s != d ) {

					while ( s > 0 ) {
						print( s, d );
						s--;
					}
					s = 0;
					while ( s < d ) {
						print( s, d );
						s++;
					}
				}
			}
		} else {
			if ( s < d ) {
				while ( s < d ) {
					print( s, d );
					s++;
				}
			} else if ( s > d ) {
				while ( s < MAX ) {
					print( s, d );
					s++;
				}
				s = 5;
				while ( s > d ) {
					print( s, d );
					s--;
				}
			}
		}
		print( s, d );
		printf( "\n" );
	}

	return 0;
}



Measured memory_bytes: 1988
#R…LやL…Rを選んでも意味がない
#L…L、R…Rを選んで反転（R…R、L…Lに）
#RL…LRを反転させると2増える
#LR…RLを反転させると2増える
#RLとLRとをそれぞれ数え上げ、min(RL数,LR数,K)を取ればよい
#例外としてLRorRLと端っこを反転したとき、1増える
#abs(LR-RL)=1 & K-min(RL,LR)>=1なら+1
#abs(LR-RL)>=1 & K-min(RL,LR)=1なら+1
#abs(LR-RL)>1 & K-min(RL,LR)>1なら+2
N,K = map(int,input().split())
S = input()
LL = 0
RR = 0
LR = 0
RL = 0
for i in range(N-1):
    if S[i]=="L" and S[i+1]=="L":
        LL += 1
    if S[i]=="R" and S[i+1]=="R":
        RR += 1
    if S[i]=="L" and S[i+1]=="R":
        LR += 1
    if S[i]=="R" and S[i+1]=="L":
        RL += 1
ans = 0
Kaisu = min(LR,RL,K)
ans += LL+RR+Kaisu*2

if abs(LR-RL)==1 and K-min(RL,LR)>=1:
    ans += 1
elif abs(LR-RL)>1 and K-min(RL,LR)==1:
    ans += 1
elif abs(LR-RL)>1 and K-min(RL,LR)>1:
    ans += 2

print(ans)

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, K;
  cin >> N >> K;
  int ret = INF;
  REP(i, N + 1) {
    int tmp = (1 << i) + K * (N - i);
    ret = min(ret, tmp);
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

#define N_MAX 100

using namespace std;

int selectionSort(int* A, const int N);

int main() {
	ios::sync_with_stdio(false);

	int N, A[N_MAX], swapCount;
	swapCount = 0;

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

	swapCount = selectionSort(A, N);

	for(int i = 0; i < N; ++i) {
		cout << A[i] << (N - 1 == i ? "\n" : " ");
	}
	cout << swapCount << endl;
	return 0;
}

int selectionSort(int* A, const int N) {
	int swapCount = 0;
	int minj;
	for(int i = 0; i < N; ++i) {
		minj = i;
		for(int j = i; j < N; ++j) {
			if(A[j] < A[minj]) {
				minj = j;
			}
		}
		if(i != minj) {
			swap(A[i], A[minj]);
			swapCount++;
		}
	}
	return swapCount;
}


Measured memory_bytes: 3212
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc172/tasks/abc172_c>
 問題文============================================================
 C - Tsundoku
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M,K; cin >> N >> M >> K;
    vector<ll> A(N),B(M);
    for(auto& in:A) cin >> in;
    for(auto& in:B) cin >> in;
    
    vector<ll> cusumA(N+1),cusumB(M+1);
    for(int i = 0; i < N;i++){
        cusumA[i+1] = cusumA[i] + A[i];
    }
    for(int i = 0; i < M;i++){
        cusumB[i+1] = cusumB[i] + B[i];
    }
    
    for(int i = 0; i <= N;i++){
        if(cusumA[i] > K) break;
        
        res = max(res,
                  (ll)i+(upper_bound(cusumB.begin()+1,cusumB.end(),K-cusumA[i])-(cusumB.begin()+1))
                  );
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 9536
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};

void dfs(int i, int j, int &s, int &cnt, vector<vector<int> > &g){
    
    cnt++;
    //cerr << cnt << endl;
    g[i][j] = 0;
    for(int h = 0; h < 4; h++){
        int ni = i + di[h];
        int nj = j + dj[h];
        if(s == 3){}
        else if(g[ni][nj] == 1){
            if(s == 1 || s == 0) s = 1;
            else s = 3;
        }else if(g[ni][nj] == 2){
            if(s == 2 || s == 0) s = 2;
            else s = 3;
        }
        
    }

    for(int h = 0; h < 4; h++){
        int ni = i + di[h];
        int nj = j + dj[h];

        if(g[ni][nj] == 3){
            dfs(ni, nj, s, cnt, g);
        }
    }

    return;

}

signed main(){

    while(1){
        int h, w; cin >> h >> w;

        swap(h, w);
        if(!h) break;
        vector<vector<int> > g(h + 2, vector<int> (w + 2, 0));
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                char c; cin >> c;
                if(c == '.') g[i][j] = 3;
                else if(c == 'B') g[i][j] = 1;
                else if(c == 'W') g[i][j] = 2;
                else assert(false);
            }
        }

        int B = 0;
        int W = 0;

        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                if(g[i][j] != 3) continue;

                int s = 0;
                int cnt = 0;
                dfs(i, j, s, cnt, g);
                if(s == 1) B += cnt;
                else if(s == 2) W += cnt;
            }
        }

        cout << B << " " << W << endl;

        /*
        for(int i = 0; i <= h + 1; i++){
            for(int j = 0; j <= w + 1; j++){
                cout << g[i][j] << " ";
                if(j == w + 1) cout << endl;
            }
        }*/
    }

    return 0;
}




Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<long long,int> P;

int main(){
	int N;
	int M;
	int num[100000];
	map<long long,int> mp;
	map<long long,int> mp2;
	vector<long long> vec[100000];
	long long Y[100000];
	map<long long,int> ans;

	scanf("%d %d",&N,&M);

	for(int i=0;i<N;i++) num[i] = 0;

	for(int i=0;i<M;i++){
		int p;
		long long y;
		scanf("%d %lld",&p,&y);
		mp[y] = i;
		mp2[y] = p;
		vec[p-1].push_back(y);
		Y[i] = y;
	}

	for(int i=0;i<N;i++){
		sort(vec[i].begin(),vec[i].end());
	}

	for(int i=0;i<N;i++){
		for(int j=0;j<vec[i].size();j++){
			int a = mp[vec[i][j]];
			int p = mp2[vec[i][j]];
			num[p-1]++;
			ans[vec[i][j]] = num[p-1];
		}
	}

	for(int i=0;i<M;i++){
		printf("%06d%06d\n",mp2[Y[i]],ans[Y[i]]);
	}

	return 0;
}


Measured memory_bytes: 26880
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

// Sequence Growing Easy

int main(){
  ll N,X[200007],sum=0;
  cin >> N ;
  rep(i,N){
    cin >> X[i+1];
  }
  bool T=0;
  X[0]=0;
  X[N+1]=0;
  rep(i,N+1){
    if(X[i+1]-X[i]>=2 || X[1]!=0){
      cout << -1 << endl;
      return 0;
    }
    if(X[i+1]!=X[i]+1){
      sum += X[i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
struct edge{int to,cost;};
int n,m,l,k,a,h,d[10100],inf=1e8;
bool isfr[100];
vector<edge> G[100];
typedef pair<int,int> P;
void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,s));
	rep(i,101*n) d[i]=inf;
	d[s]=0;
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.sc,ii=v/101,jj=v%101;
		if(d[v]<p.fs) continue;
		if(isfr[ii]){
			if(jj<m && d[ii*101+jj+1]>d[v]+1){
				d[ii*101+jj+1]=d[v]+1;
				que.push(P(d[ii*101+jj+1],ii*101+jj+1));
			}
		}
		rep(i,G[ii].size()){
			edge e=G[ii][i];
			if(jj-e.cost<0) continue;
			int nn=G[ii][i].to*101+jj-e.cost;
			if(d[nn]>d[v]+e.cost){
				d[nn]=d[v]+e.cost;
				que.push(P(d[nn],nn));
			}
		}
	}
}
int main(){
	while(true){
		cin >> n >> m >> l >> k >> a >> h;
		if(n==0) break;
		rep(i,n) isfr[i]=0,G[i].clear();
		rep(i,l){
			int hh;
			cin >> hh;
			isfr[hh]=1;
		}
		rep(i,k){
			int x,y,t;
			cin >> x >> y >> t;
			G[x].push_back({y,t});
			G[y].push_back({x,t});
		}
		dijkstra(a*101+m);
		int ans=inf;
		rep(i,m+1) ans=min(ans,d[h*101+i]);
		if(ans==inf) cout << "Help!\n";
		else cout << ans << endl;
	}
}

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

int main() {
	int N, M;

	cin >> N >> M;

	vector<int> H(N);

	for (int i = 0; i < N; i++)
	{
		cin >> H[i];
	}

	int A, B;
	vector<bool> Flag(N, true);

	for (int i = 0; i < M; i++)
	{
		cin >> A >> B;

		A -= 1;
		B -= 1;

		if (H[A] > H[B]) {
			Flag[B] = false;
		}
		else if (H[A] < H[B])
		{
			Flag[A] = false;
		}
		else
		{
			Flag[A] = false;
			Flag[B] = false;
		}
	}

	int num = 0;

	for (int i = 0; i < N; i++)
	{
		if (Flag[i])
		{
			num++;
		}
	}

	cout << num << endl;
}

Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using static System.Console;

namespace ABC124A
{
    static class Program
    {
        static void Main(string[] args)
        {
            var a = ReadLine().SplitTryParseToList<int>();
            int b = Math.Max(a[0], a[1]);
            b += a[0] > a[1] ? Math.Max(b - 1, a[1]) : Math.Max(a[0], b - 1);
            WriteLine(b);


        }

        public static T TryParse<T>(this String input)
        {
            try
            {
                var converter = TypeDescriptor.GetConverter(typeof(T));
                if (converter != null)
                {
                    return (T)converter.ConvertFromString(input);
                }
                else
                {
                    throw new InvalidCastException("");
                }
            }
            catch
            {
                throw new InvalidCastException(typeof(T) + " is not supported.");
            }
        }

        public static List<T> SplitTryParseToList<T>(this String input)
        {
            return input.Split().Select(n => n.TryParse<T>()).ToList();
        }

        public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2)
        {
            var t = list[index1];
            list[index1] = list[index2];
            list[index2] = t;
            return list;
        }

        public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list)
        {
            return list
                .GroupBy(i => i)
                .Where(g => g.Any())
                .Select(g => Tuple.Create(g.Key, g.Count()))
                .ToList();
        }
        public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list)
        {
            return list.OrderByDescending((x) => x.Item2).ToList();
        }
        public static List<T> ReadLineOne<T>(int n)
        {
            var list = new List<T>();
            foreach (var i in Enumerable.Range(1, n))
            {
                list.Add(Console.ReadLine().TryParse<T>());
            }
            return list;
        }
        public static void PrintAll<T>(this IEnumerable<T> list)
        {
            foreach (var i in list)
            {
                Console.Write($"{i} ");
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 14432
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[1010];
ll lcm(ll x, ll y){
  ll tmp;
  tmp=__gcd(x, y);
  tmp=x/tmp*y;
  return tmp;
}
int main(){
  int n;
  while(cin>>n){
    for(int i=0; i<n; ++i){
      cin>>a[i];
    }
    sort(a, a+n);
    ll ans=1;
    for(int i=0; i<n; ++i){
      ans=lcm(ans, a[i]);
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 256