akhauriyash/Code-Regression huggingface dataset:
n = int(input())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))

mons = arrA[n]
res = 0
for i in range(n-1,-1,-1):
    mons += arrA[i]
    if mons>=arrB[i]:
        res += arrB[i]
        mons = min(mons-arrB[i],arrA[i])
    else:
        res += mons
        mons = 0

print(res)

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

/*
MAX_DATASETは入力されるデータセットの最大個数
MAX_SHUFFLEはシャッフルする最大回数
CARD_MAXLENGTHは入力される最大の文字数
*/
#define MAX_DATASET 10
#define MAX_SHUFFLE 100
#define CARD_MAXLENGTH 200

int main(void)
{
	//data_countは入力されたデータセットを、first_pointは文字列の先頭位置を格納
	int i, j, data_count, first_point;
	//shuffle_pointはカードをシャッフルする位置を、shuffle_countはシャッフルする回数を格納
	int shuffle_point[MAX_DATASET][MAX_SHUFFLE], shuffle_count[MAX_DATASET];
	char work[CARD_MAXLENGTH];
	//cardはシャッフルする文字列を格納(連結用に2倍の領域を確保)
	char card[MAX_DATASET][2 * CARD_MAXLENGTH];

	data_count = 0;
	while(scanf("%s", card[data_count])){
		//データが '-' なら入力終了
		if(card[data_count][0] == '-'){
			break;
		}
		else{
			//シャッフルする回数を入力
			scanf("%d", &shuffle_count[data_count]);
			//シャッフルする位置を入力
			for(i = 0; i < shuffle_count[data_count]; i++){
				scanf("%d", &shuffle_point[data_count][i]);
			}
			data_count++;
		}
	}

	//入力されたデータセットの回数分繰り返す
	for(i = 0; i < data_count; i++){
		first_point = 0;
		for(j = 0; j < shuffle_count[i]; j++){
			//先頭位置からカードを取り出す位置までworkにコピー
			strncpy(work, &(card[i][first_point]), shuffle_point[i][j]);
			//文字列の最後に '\0' を挿入
			work[shuffle_point[i][j]] = '\0';
			//取り出したカードをシャッフルもとに連結
			strcat(card[i], work);
			//先頭位置をずらす
			first_point += shuffle_point[i][j];
		}
		//結果の出力
		printf("%s\n", &card[i][first_point]);
	}

	return 0;
}


Measured memory_bytes: 2108
//Volume0-0099
import java.util.*;

public class Main {
	public static void main(String[] args) {
	int n,q,a,v,top;
	int[] sum;
	
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		sum = new int[n+2];
		top = n+1;
		sum[top] = Integer.MIN_VALUE;
		q = sc.nextInt();
		for(int i=0;i<q;i++){
			a = sc.nextInt();
			v = sc.nextInt();
			sum[a] += v;
			if(v<0&&a==top){
				top = n+1;
				for(int j=1;j<=n;j++){
					if((sum[j]>sum[top])||(sum[j]==sum[top] && j<top)){
						top=j;
					}
				}
			} else {
				if((sum[a] > sum[top]) || (sum[a] == sum[top] && a < top)){
					top = a;
				}
			}
			System.out.println(top+" "+sum[top]);
		}
	}
}

Measured memory_bytes: 75532
a,b = list(map(int, input().split()))

ans=0
ansli=[]
for ii in range(a):
    i=ii+1
    for jj in range(b):
        j=jj+1
        if(j//10>=2 and j%10>=2 and (j//10)*(j%10)==i):
            ans+=1
            ansli.append([i,j])
            
print(ans)

Measured memory_bytes: 39332
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  clr(d,0);
  rep(i,0,3){
    cin >> n;
    d[n]++;
  }
  m = 0;
  rep(i,0,103){
    if(d[i] != 0)m++;
  }
  print(m);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;

#define what_is(x) cerr << #x << " is " << x << endl;

const int N = 11;

string convert (ll x) {
	string ans = "";
	while (x != 0) {
		if (x%2 != 0) {
			x--;
			ans += "1";
		} else {
			ans += "0";
		}
		x /= -2;
	}
	if (ans.size() == 0)
		ans += "0";
	reverse(ans.begin(), ans.end());
	return ans;
}

ll n;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// cout.precision(1); cout << fixed;
	cin >> n; cout << convert(n) << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

ll read() {
  ll res = 0, w = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 2e5 + 10;

int st[N], p[N], a[N], nxt[N], las[N], x[N], n, pos, top;
ll k;

int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    nxt[las[a[i]]] = i;
    las[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    nxt[las[a[i]]] = i;
    las[a[i]] = i;
  }
  for (int i = 1; i < n; i++) x[i] = i + 1;
  x[n] = 1;
  st[++top] = 1, p[top] = 1, pos = 1;
  do {
    ++top, p[top] = p[top - 1] + (nxt[pos] <= pos) + (nxt[pos] == n);
    st[top] = pos = x[nxt[pos]];
  } while (st[top] != st[1]);
  k -= (k - 1) / (p[top] - 1) * (p[top] - 1);
  int j = 1;
  while (j <= top - 1 && p[j + 1] <= k) ++j;
  for (int i = st[j]; i <= n; ++i) {
    if (nxt[i] > i)
      i = nxt[i];
    else
      printf("%d ", a[i]);
  }
  return 0;
}

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

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();

            // 最小値を1000で初期化
            int min = 1000;

            // 先頭から連続する3つの数と753との差を求める。
            for(int i = 0; i < input.Length - 2; i++)
            {
                // 連続する3つの数
                int num = int.Parse(input[i].ToString() + input[i + 1].ToString() + input[i + 2].ToString());
                if(Math.Abs(num - 753) < min)
                {
                    min = Math.Abs(num - 753);
                }
            }

            // 標準出力に出力
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[3100][3100];

void chmax(ll &a, ll b){
  if( a < b){ swap(a,b);} return ;}

int main(){
  ll N,T; cin >> N >> T;
  vector<P> X(N);
  for(ll i = 0; i < N; i++){
    cin >> X[i].first >> X[i].second;}
  
  sort(X.begin(),X.end());
  
  dp[0][X[0].first] = X[0].second;
  
  for(ll i = 1; i < N; i++){
    for(ll t = 0; t < T; t++){
      
      chmax( dp[i][t], dp[i-1][t]);
      if( t+X[i].first < T){
      chmax( dp[i][t+X[i].first], dp[i-1][t]+X[i].second);}
    }
  }
  
  ll ans = 0;
  
  for(ll i = 0; i < N-1; i++){
    //全部選ぶのは、N-1個選んで最後にN個目をボーナスで達成する場合として実現される
    
     for(ll t = 0; t < T; t++){
       chmax(ans, dp[i][t]+X[i+1].second);
     }
    
  }
  
  cout << ans << endl; return 0;
}
      

Measured memory_bytes: 73984
N = int(raw_input())
A = raw_input()
B = raw_input()
C = raw_input()
count = 0
for i in range(N):
    if (A[i] == B[i]) & (B[i]==C[i]):
        count += 0
    elif (A[i] == B[i])|(A[i]==C[i])|(B[i]==C[i]):
        count += 1
    else:
        count += 2
print (count)

Measured memory_bytes: 2568
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

const double EPS = 1e-10;

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}

	Point operator + (Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double k) {
		return Point(k * x, k * y);
	}
	Point operator / (double k) {
		return Point(x / k, y / k);
	}

	double norm() {
		return x * x + y * y;
	}
	double abs() {
		return sqrt(norm());
	}

	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

class Segment {
public:
	Point p1, p2;
	Segment(Point p1, Point p2): p1(p1), p2(p2) {};

	double norm() {
		return (p2 - p1).x * (p2 - p1).x + (p2 - p1).y * (p2 - p1).y;
	}

	double abs() {
		return sqrt(norm());
	}

	Point project(Point p) { 
		Vector a = Vector(p.x - p1.x, p.y - p1.y);
		Vector b = Vector(p2.x - p1.x, p2.y - p1.y);
		return p1 + (p2 - p1) * (dot(a, b) / b.norm()); //???????????????
	}

	Point refrect(Point p) {
		Point pro = project(p);
		return pro * 2 - p;
	}
};

typedef Segment Line;

class Circle {
public:
	double cx, cy, r;
	Circle(double cx, double cy, double r): cx(cx), cy(cy), r(r) {}
	
	Segment crossPoints(Line l) {
		Point c = Point(cx, cy);
		Point p = l.project(c);
		double d2 = (p - c).norm();
		double t = sqrt(r * r - d2);
		Point p1 = p - (l.p2 - l.p1) / l.abs() * t;
		Point p2 = p + (l.p2 - l.p1) / l.abs() * t;
		if (p1 < p2) return Segment(p1, p2);
		else return Segment(p2, p1);
	}
};

int main() {
	int cx, cy, r, q;
	cin >> cx >> cy >> r >> q;
	Circle C = Circle(cx, cy, r);
	int x0, y0, x1, y1;
	for (int i = 0; i < q; i++) {
		cin >> x0 >> y0 >> x1 >> y1;
		Line l = Segment(Point(x0, y0), Point(x1, y1));
		Segment s = C.crossPoints(l);
		cout << fixed << setprecision(6) << s.p1.x << ' ' << s.p1.y << ' ' << s.p2.x << ' ' << s.p2.y << endl;
	}
	return 0;
}

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

int main() {
    int N;
    std::string S,T,ans;
    cin >> N;
    cin >> S >> T;
    for (int i = 0; i < N; i++) {
        ans = ans + S[i] + T[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define MAX 105
#define WHITE 0
#define BLACK 1
#define GRAY 2
 
int n,d[MAX],f[MAX],G[MAX][MAX],color[MAX],t=0;
 
void DFSVisit(int u){
  int v;
   
  color[u] = GRAY;
  t++;
  d[u] = t;
   
  for(v=1; v<=n; v++){
    if((G[u][v] == 1)&& (color[v] == WHITE)){
      DFSVisit(v);
 
    }
  }
 
  color[u] = BLACK;
  f[u]= ++t;
}
 
int main(){
  int i,j,u,v,k;
   
  scanf("%d",&n);
 
  /*array all 0*/
  for(i=1;i<= n; i++){
    for(j=1; j<= n; j++){
      G[i][j] = 0;
    }
  }
 
  for(i=1; i<= n; i++){
    scanf("%d%d",&u,&k);
    // u--;
    for(j=0; j<k; j++){
      scanf("%d",&v);
      // v--;
      G[u][v] = 1;
    }
  }
 
   for(i=1; i<=n; i++){
     color[i] = WHITE;
    }
 
   for(i=1; i<=n; i++){
     if(color[i] == WHITE) DFSVisit(i);
   }
 
  for(i=1; i<=n; i++){
    printf("%d ",i);
    printf("%d ",d[i]);
    printf("%d\n",f[i]);
  }
   
  return 0;
}

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

int main(){
	int counts = 0;
	vector<vector<int>> c(3, vector<int>(3));
	rep(i,3)rep(j,3) cin >> c[i][j];
	int maxim = 0;
	rep(i,3)rep(j,3) maxim = max(maxim,c[i][j]);
	vector<int> d(maxim);
	bool ok = false;
	rep(i,maxim +1)rep(j,maxim + 1){
		if(c[0][0] == i+j){
			int b1 = c[0][1] - j;
			int b2 = c[0][2] - j;
			int a1 = c[1][0] - i;
			int a2 = c[2][0] - i;
			if(c[1][1] == a1 + b1 && c[2][1] == a2 + b1 && c[1][2] == a1 + b2 && c[2][2] == a2 + b2) ok = true;
		}
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
    //inport
    string str;
    cin >> str;

    //process
    int a=0,b=0,c=0,d=0;
    for(int i=0;i<str.size();i++){
        if(i%2==0){
            if(str[i]=='0'){
                a++;
            }else{
                b++;
            }
        }else{
            if(str[i]=='1'){
                a++;
            }else{
                b++;
            }
        }
    }

    //output
    cout << min({a,b}) << endl;

    return 0;
}


Measured memory_bytes: 512
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str,str2;
    ll h,w;
    ll n,x;
    ll a,b,d;
    cin>>a>>b;
    if(a<0&&b<0){
        if((b-a)%2==0){
            cout<<"Negative"<<endl;
            return 0;
        }
    }else if(a<=0&&0<=b){
        cout<<"Zero"<<endl;
    return 0;
    } 
    cout<<"Positive";
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a, b; cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
		return;
	} else if (a >= 6) {
		cout << b / 2 << endl;
		return;
	}
	cout << 0 << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

int main(void){
    int S, h, m, s;
    cin >> S;
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    cout << h ;
    cout << ":";
    cout << m ;
    cout << ":";
    cout << s ;

    
    cout << endl;


    // Your code here!
    
}



Measured memory_bytes: 3116
// C - Walk on Multiplication Table
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll N; cin>>N;
	ll a = sqrt(N) + 1;
	while(a>=1) if(N%--a == 0) break;
	cout<< a + N/a - 2 <<endl;
}

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

#define ll long long 

using namespace std;

int H,W,h,w;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>H>>W>>h>>w;
    cout<<H*W-h*W-(H-h)*w;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define endl '\n'
#define int ll
#define gcd __gcd
#define popcount(x) __builtin_popcountll(x)
#define fill(x, y) memset(x, y, sizeof(x))
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
// default binary search returns a bool
 
// int dx[]={1,0,-1,0}; 
// int dy[]={0,1,0,-1}; //4 Direction 
 
// int dx[]={1,1,0,-1,-1,-1,0,1}; 
// int dy[]={0,1,1,1,0,-1,-1,-1};  // 8D
 
void solve(){

    
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int ans = 0;
    sort (a.begin() , a.end());
    for (int i = 0 ; i < n ; i++){
        for(int j = i+1 ; j < n ; j++){
            for (int k = j+1 ; k < n ; k++){
                if (a[i]!=a[k] && a[i]!=a[j] && a[k] != a[j]){
                    if(a[i]+a[j] > a[k]) ans++;
                }
            }
        }
    }
    cout << ans << endl;
}
 
 
int32_t main(){
 
    #ifndef ONLINE_JUDGE 
  
    freopen("input.txt", "r", stdin); 
  
    // freopen("output.txt", "w", stdout); 
  
    #endif 
 
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    int t = 1;
    // cin >> t;
    for (int tt = 0 ; tt < t ; tt++){
        // cout << "Case " << (tt+1) <<": " << endl;
        solve();
    }
    
}

Measured memory_bytes: 3660
#damedatta...
import itertools
def main():
    N, M, Q = map(int, input().split())
    l = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())       
        a -= 1
        b -= 1
        l.append((a,b,c,d))
    r = 0
    for i in itertools.combinations_with_replacement([i for i in range(1, M+1)],N):
        t = 0
        for j in l:
            a,b,c,d = j
            if i[b] - i[a] == c:
                t += d
        r = max(r, t)
    return r
print(main())


Measured memory_bytes: 67784
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> k(M, 0);
	vector<vector<int>> s(M, vector <int>());
	for (int ii = 0; ii < M; ++ii){
		cin >> k[ii];
		for (int jj = 0; jj < k[ii]; ++jj){
			int tmp;
			cin >> tmp;
			tmp -= 1;
			s[ii].push_back(tmp);
		}
	}
	vector <int> p(M, 0);
	for (int ii = 0; ii < M; ++ii){
		cin >> p[ii];
	}

	//N個のスイッチのパターンを全探索
	int total = (1 << N);
	int cnt = 0;
	for (int ii = 0; ii < total; ++ii){
		// cout << "pattern " << ii << endl;
		//スイッチの状態を作成
		int value = ii;
		vector <int> swt(N, 0);
		for (int jj = 0; jj < N; ++jj){
			swt[jj] = value & 1;
			value = value >> 1;
		}
		//それぞれの電球がつくかどうかチェック
		bool OK = true;
		for (int jj = 0; jj < M; ++jj){
			int onCnt = 0;
			for (int kk = 0; kk < k[jj]; ++kk){
				int index = s[jj][kk];
				// cout << "index " << index << endl;
				if (swt[index] == 1){
					onCnt++;
				}
			}
			// cout << "onCnt " << onCnt << endl;
			if (onCnt % 2 != p[jj]){
				OK = false;
				break;
			}
		}
		//結果を集計
		if (OK){
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    int W, H;
    PriorityQueue<Edge> qs;

    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        W = sc.nextInt();
        H = sc.nextInt();
        qs = new PriorityQueue<>((e1, e2) ->
           Long.compare(e1.cost, e2.cost));
        int i;
        long tmp;
        for (i = 0; i < W; i++) {
            tmp = sc.nextLong();
            qs.add(new Edge(i+1, i, tmp, true));
        }
        for (int j = 0; j < H; j++) {
            tmp = sc.nextLong();
            qs.add(new Edge(j+1, j, tmp, false));
        }
    }

    private void solve() {
        int a = H+1;
        int b = W+1;
        long ans = 0L;
        while (!qs.isEmpty()) {
            Edge e = qs.poll();
            if (e.isCol) {
                ans += e.cost * a;
                b--;
            } else {
                ans += e.cost * b;
                a--;
            }
        }
        System.out.println(ans);
    }

    private class Edge {
        boolean isCol;
        int to, from;
        long cost;
        Edge(int to, int from, long c, boolean isCol) {
            this.to = to;
            this.cost = c;
            this.from = from;
            this.isCol = isCol;
        }
    }

}


Measured memory_bytes: 102824
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

	

	clock_t startTime=clock();

	ll k,a,b;
	cin>>k>>a>>b;
	rep(i,a,b+1)
	{
		if(i%k==0)
		{	cout<<"OK";return 0;}
	}
	cout<<"NG";

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 3800
#include<stdio.h>

main()
{
    int H,W,i,j,k;
    for(k=0; ;k++)
   {

    scanf("%d %d",&H,&W);
    if(H==0 && W==0)

    break;

    for(i=1;i<=H;i++)
{
    for(j=1;j<=W;j++)
       {printf("#");}



 printf("\n") ;}
 printf("\n");}


}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	ll n,k;
	cin >> n >> k;
	/* (a mod k + b mod k + c mod k) * 2 = 3*p*k
	 */
	ll temp = n % k;
	ll answer=0;
	/*if(temp <= (k-1)/2) {
		answer = temp * ((n/k+1)*(n/k+1)*(n/k) + (n/k+1)*(n/k)*(n/k)) + ((k-1)/2-temp) * ((n/k)*(n/k)*(n/k)*2);
	}
	else {
		answer = (temp-(k-1)/2-1) * (n/k+1)*(n/k+1)*(n/k+1)*2 + (k-1-temp) * ((n/k+1)*(n/k+1)*(n/k) + (n/k+1)*(n/k)*(n/k));
	}*/
	if((k-1) % 2 != 0) {
		if(temp <= (k-1)/2) {
			answer += (n/k)*(n/k)*(n/k);
		}
		else {
			answer += (n/k+1)*(n/k+1)*(n/k+1);
		}
	}
	answer += (n/k)*(n/k)*(n/k);
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  double a,b;
  int rex;
    double x;
  scanf("%lf %lf",&a,&b);
  x = (a + b) / 2;
  rex = x;
  if((double)x - rex >= 0.5)
    rex += 1;
  
  printf("%d\n",rex);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int mod(
    int n,
    const std::string& x,
    const std::vector<int>& rems,
    int denominator)
{
  int result = 0;
  for (int i = 0; i < n; ++i) {
    if (x.at(i) == '1') {
      result = (result + rems.at(i)) % denominator;
    }
  }
  return result;
}

int popcount(int n)
{
  int result = 0;
  while (n > 0) {
    if (n & 1) ++result;
    n >>= 1;
  }
  return result;
}

int f(int value)
{
  for (int result = 1; ; ++result) {
    if (value <= 0) return result;
    value %= popcount(value);
  }
}

std::vector<int> solve(int n, const std::string& x)
{
  const int p0 = std::count(x.begin(), x.end(), '1');
  if (p0 == 0) return std::vector<int>(n, 1);

  std::vector<int> rems0(n);
  std::vector<int> rems1(n);
  int r0 = 1;
  int r1 = 1;
  for (int i = n - 1; i >= 0; --i) {
    if (p0 >= 2) {
      rems0.at(i) = r0;
      r0 = (r0 << 1) % (p0 - 1);
    }
    rems1.at(i) = r1;
    r1 = (r1 << 1) % (p0 + 1);
  }

  const auto mod0 = p0 == 1 ? 1 : mod(n, x, rems0, p0 - 1);
  const auto mod1 = mod(n, x, rems1, p0 + 1);

  std::vector<int> result(n);
  for (int i = 0; i < n; ++i) {
    if (x.at(i) == '1') {
      if (p0 == 1) {
        result.at(i) = 0;
      } else {
        auto v = mod0 - rems0.at(i);
        if (v < 0) v += p0 - 1;
        result.at(i) = f(v % (p0 - 1));
      }
    } else {
      result.at(i) = f((mod1 + rems1.at(i)) % (p0 + 1));
    }
  }
  return result;
}

int main()
{
  int n;
  std::string x;
  std::cin >> n >> x;

  std::cout << std::setprecision(20);
  const auto values = solve(n, x);
  for (auto v : values) {
    std::cout << v << std::endl;
  }
}


Measured memory_bytes: 5944
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? LONG_LONG_MAX : INT_MAX;
const int MOD = 1000000007;
const long double EPS = 1e-8;

signed main() {
	string s;
	cin >> s;
	int ans = s.size() / 2;
	int cnt = 0;
	char flag = s[s.size() / 2];
	for(;;cnt++) {
		int pear = (s.size() / 2) - (s.size() % 2 == 0) - cnt;
		int berry = (s.size() / 2) + cnt;
		if (s[pear] != s[berry] || s[pear] != flag) break;
		if (ans + cnt == s.size()) break;
	}
	cout << ans + cnt << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int max = Math.max(A,Math.max(B,C));
        int ans = A+B+C-max+max*(1<<K);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
import collections
def main():

    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    set_a = set(a)
    a = []
    a = list(set_a)
    a.sort(reverse=True)
    select = 0
    ans = 1
    tmp = 0
    flg = 0
    for i, aa in enumerate(a):
        if cnt[aa] >= 4 and flg == 0:
            tmp = aa * aa
            flg = 1
        if cnt[aa] >= 2:
            select += 1
            ans *= aa
        if select == 2:
            ans = max(tmp,ans)
            print(ans)
            return
    print(0)



if __name__ == '__main__':
    main()


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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 10;
char s[N][N];

int main()
{
	int n = read(), m = read(), k = read();
	int ans = 0;
	
	for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
	for (int i = 0; i < (1 << n); ++i)
		for (int j = 0; j < (1 << m); ++j)
		{
			int cnt = 0;
			for (int k = 1; k <= n; ++k)
				for (int l = 1; l <= m; ++l)
					if (s[k][l] == '#' && !((1 << (k - 1)) & i) && !((1 << (l - 1)) & j))
						++cnt;
			ans += (cnt == k);
		}
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 3828
$a{"00"} = "NA";
$a{"10"} = "MMYY";
$a{"01"} = "YYMM";
$a{"11"} = "AMBIGUOUS";

chomp($n = <>);
($f, $r) = ($1, $2) if($n =~ /^(\d{2})(\d{2})$/);
$f = ((int($f) >= 1) and (int($f) <= 12)) ? 1 : 0;
$r = ((int($r) >= 1) and (int($r) <= 12)) ? 1 : 0;

printf $a{"$f$r"} . "\n";

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<int> as(N); for (auto &ai : as) cin >> ai;
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		if (i % 2 == 0 && as[i] % 2 == 1)++ans;
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll


int32_t main(){
    FAST
    int x; cin >> x;
    for(int i = -1e3; i <= 1e3; i++){
        for(int j = -1e3; j <= 1e3; j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                cout << i << " " << j;
                return 0;
            }
        }
    }
    return 0;
}


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

int main()
{
    int n;
    long long a[100002],b[100002];
    cin>>n;
    for (size_t i = 0; i <= n; i++)
    {
        cin>>a[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        cin>>b[i];
    }
    long long  ans=0;
    for (size_t i = 0; i < n; i++)
    {
        if(a[i]+a[i+1]<b[i]){
            ans+=a[i]+a[i+1];
            a[i+1]=0;
        }else if(a[i]+a[i+1]>=b[i] && a[i]<b[i]){
            ans+=b[i];
            a[i+1]=a[i]+a[i+1]-b[i];
        }else{
            ans+=b[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

#define MAX_N 100001
int n;

int a[MAX_N+1];
int dp2[MAX_N+1];

/*
void solve1(){/*最終要素に対する最長の長さのdp

    int res = 0;
    for(int i =0;i <n;i++){
        dp1[i] = 1;
        for(int j = 0;j < i;j++){
            if(a[j]<a[i]){
                dp1[i] = max(dp1[i],dp1[j]+1);
            }
            res = max(res,dp1[i]);
        }
    }
    cout << res << endl;

}

*/


void solve2(){/*長さに対する最小の最終要素*/
    
    fill(dp2,dp2+n,INF);
    for(int i = 0;i < n;i++){
        *lower_bound(dp2,dp2+n,a[i]) = a[i];
    }
    cout << lower_bound(dp2,dp2+n,INF)-dp2 << endl;
    
    }
    

int main(){

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

    //solve1();
    solve2();

    return 0;
}


Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define forn(i,n) for(int i = 0; i< n;++i)
ll MOD = 1e9 + 7;
ll INF = 1e17 + 9;

ll dp(int mask, int women, vector<vector<bool>>&comp, int n, vector<vector<ll>>&save){
	if(mask == (1<<n) -1) return 1;
	else if(women >= n) return 0;
	else if(save[mask][women] != -1) return save[mask][women];
	
	ll res = 0;
	for(int bit = 0; bit < n; ++bit){
		if(((mask >> bit) & 1) == 0 && comp[bit][women]){
			res += dp(mask|(1<<bit), women + 1, comp, n,save);
			res %= MOD;
		}
	}
	save[mask][women] = res;
	return res;
}
			

int main() {
	int n;
	cin >> n;
	vector<vector<bool>> comp(n, vector<bool>(n,0));
	for(int i = 0; i< n; ++i){
		for(int j = 0; j < n; ++j){
			bool temp;
			cin >> temp;
			comp[i][j]=temp;
		}
	}
	vector<vector<ll>> save(1<<n, vector<ll> (n,-1));
	ll ans = dp(0,0,comp,n,save);
	
	cout << ans << endl;
}



Measured memory_bytes: 409856
#!python3

iim = lambda: map(int, input().rstrip().split())

def NKS(N, K, S):
    M5 = 10**5
    M9 = 10**9

    for i in range(K):
        yield S

    tmp = S + 1 if S < M9 else 1
    for i in range(N-K):
        yield tmp

def resolve():
    N, K, S = iim()

    it = NKS(N, K, S)
    for i in range(N-1):
        print(next(it), end=" ")
    print(next(it))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 4212
N,L=map(int,input().split())

list=[]
for i in range(1,N+1):
  s=i+L-1
  list.append(s)
if 0 in list:
  print(sum(list))
else:
  list=sorted(list)
  if list[0]>0:
    del list[0]
    print(sum(list))
  elif list[0]<0:
    list=sorted(list,reverse=True)
    del list[0]
    print(sum(list))

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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int n,m,c;
  cin >> n >> m >> c;
  
  vector<int> b(m);
  for ( int i = 0; i < m; i++){
    cin >> b[i];
  }
  
  vector<vector<int>> a(n,vector<int> (m));
  for ( int i = 0; i < n; i++){
    for ( int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  
  int count = 0;
  
  for ( int i = 0; i < n; i++){
    long long clc = 0;
    for ( int j = 0; j < m; j++){
      clc += a[i][j] * b[j];      
    }
    clc += c;
    if ( clc > 0 ){
      count++;
    }
  }
    
  cout << count << endl;

}

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

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a;i>0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7



int main() {
    string s;
    ll dp[100002][4] = {};
    cin >> s;
    for (ll i = s.size(); i >= 0; --i) {
        for (ll j = 3; j >= 0; --j) {
            if (i == s.size()) {
                dp[i][j] = (j == 3 ? 1 : 0);
            } else {
                dp[i][j] = dp[i + 1][j] * (s[i] == '?' ? 3LL : 1LL);
                if(j < 3 && (s[i] == '?' || s[i] == "ABC"[j])) {
                    dp[i][j] += dp[i + 1][j + 1];
                }
                dp[i][j] %= mod;
            }
        }
    }
    print(dp[0][0]);
}


Measured memory_bytes: 3584
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, y;
    cin >> n >> y;
    y /= 1000;

    int a = -1, b = -1, c = -1;

    int rhs = y - n;
    if (rhs < 0) {
        printf("%d %d %d\n", a, b, c);
        return 0;
    }

    int ord[] = { 0, 4, 8, 3, 7, 2, 6, 1, 5 };
    int i = 0;
    while (ord[i] != rhs % 9)
        i++;
    if (rhs - 4 * i < 0 || n - i - (rhs - 4 * i) / 9 < 0) {
        printf("%d %d %d\n", a, b, c);
    }
    else {
        b = i;
        a = (rhs - 4 * b) / 9;
        c = n - i - a;
        printf("%d %d %d\n", a, b, c);
    }



    return 0;
}

Measured memory_bytes: 256
H, W, D=map(int, input().split())
pos={}
for i in range(H):
    A=list(map(int, input().split()))
    for j in range(W):
        pos[A[j]]=(i, j)
p=[0]*(H*W+1)
for i in range(D+1,H*W+1):
    p[i]=p[i-D]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1])
Q=int(input())
for _ in range(Q):
    L, R=map(int, input().split())
    print(p[R]-p[L])


Measured memory_bytes: 22568
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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 main(void) {
    int N;
    cin >> N;
    vector<int> ls(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> ls[i];
        sum += ls[i];
    }

    bool ok = true;
    for (int i = 0; i < N; i++) {
        if (ls[i] >= sum - ls[i]) {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    int w, a, b;
    cin >> w >> a >> b;

    int res;
    if(b > a+w)         res = b-a-w;
    else if(b + w < a)  res = a-b-w;
    else                res = 0;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    string S;cin>>S;
    int ans=0;
    REP(i,N-2){
        if(S.substr(i,3)=="ABC") ans++;
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    ll a=1,b=1;
    while (n--){
        ll x,y;
        cin>>x>>y;
        ll mul= max((a+x-1)/x,(b+y-1)/y);
        a=x*mul,b=y*mul;
    }
    cout<<a+b;
}


Measured memory_bytes: 256
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
i = 0
while x > count:
    if i == N:
        break
    count += a[i]
    i += 1

if x == count:
  print(i)
else:
  print(i-1)

Measured memory_bytes: 3060
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

L = []
R = []

for i in range(H):
  R_cnt = 0
  for j in range(W):
    if A[i][j] == '.':
      R_cnt += 1
  if R_cnt == W:
    R.append(i)

for j in range(W):
  L_cnt = 0
  for i in range(H):
    if A[i][j] == '.':
      L_cnt += 1
  if L_cnt == H:
    L.append(j)

for i in range(H):
  S = []
  for j in range(W):
    if i in R:
      break
    elif j in L:
      continue
    else:
      S.append(A[i][j])
  if len(S) > 0:
    print(''.join(S))


Measured memory_bytes: 39408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int P=924844033;
int n,k,ed[4010],dp[4010][2010][2],fac[4010],ans,cnt;
int main(){
	scanf("%d%d",&n,&k);
	rep(i,1,k) rep(j,0,1){
		for(int w=i,t=j;w<=n;w+=k,t^=1) ++cnt;
		ed[cnt]=1;
	}dp[1][0][0]=1;
	rep(i,1,n*2) rep(j,0,n){
		dp[i+1][j][0]=(dp[i][j][0]+dp[i][j][1])%P;
		if(!ed[i]) dp[i+1][j+1][1]=dp[i][j][0];
	}
	fac[0]=1;rep(i,1,n) fac[i]=1ll*fac[i-1]*i%P;
	rep(i,0,n)
		if(i&1) ans=(ans-1ll*(dp[n*2][i][0]+dp[n*2][i][1])%P*fac[n-i]%P+P)%P;
		else ans=(ans+1ll*(dp[n*2][i][0]+dp[n*2][i][1])%P*fac[n-i]%P)%P;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 63104
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int s[111][111];
int main(void){
  cin >> n;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      cin >> s[i][j];
    }
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      s[i][j] += s[i][j-1];
    }
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      s[i][j] += s[i-1][j];
    }
  }

  int best = -(1<<30);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      for(int k = i+1; k <= n; k++){
	for(int l = j+1; l <= n; l++){
	  best = max(best,s[k][l]-s[i][l]-s[k][j]+s[i][j]);
	}
      }
    }
  }
  cout << best << endl;
}

Measured memory_bytes: 1212
// AtCoder
    // Beginner Contest 137
    // B. Alternating Current
    #include <bits/stdc++.h>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <string> 
    #include <vector>
    #include <numeric>
    using namespace std;
    typedef long long int ll;
    typedef long double ld;
    typedef pair<ll, int> PLI;
    typedef pair<int, int> PII;
    const ll mxsize = 1e5 + 15;
    const ll linf = 1e9;
    const long double inf = 10000000000.0;
    #define fastIO                                                                 \
      ios_base::sync_with_stdio(false);                                            \
      cin.tie(NULL);                                                               \
      cout.tie(NULL);
    const ll mod = 1e9 + 7;
    /******************************************* IMPORTANT CODE SNIPPETS ************************************************/ 
    
    ll pow(ll x, ll n) {
      if (n == 0)
        return 1ll;
      ll temp;
      temp = pow(x, n / 2);
      if (n % 2 == 0)
        return temp * temp;
      else
        return x * temp * temp;
    }

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

    int sum_digit(int val) {
      if (val < 0)
        return -1;
      if (val == 0)
        return 0;
      int ans = 0;
      while (val > 0) {
        ans = ans + val % 10;
        val = val / 10;
      }
      return ans;
    }

    ll count_div(ll l, ll r, ll val) {
      if (l % val == 0)
        return (((r / val) - (l / val)) + 1);
      else
        return ((r / val) - (l / val));
    }

    int powmod(int x, int y, int m) {
      int res = 1;
      // x = x % mod;
      while (y > 0) {
        if (y & 1)
          res = (res * x) % m;
        cout << res << endl;
        y = y / 2;
        cout << x << endl;
        x = (x * x) % m;
      }
      // cout << res << endl;
      return res;
    }
    /******************************************** CODE STARTS FROM HERE *************************************************/ 
    
    int main()
    {
      int A , B;
      cin >> A >> B;
      cout << max(A + B , max(A - B , A * B)) << endl;
    }

Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

  int x, y, a;

  for(x=1;x<=9;x++){

    for(y=1;y<=9;y++){



      a=x*y;


    printf("%dx%d=%d\n", x, y, a);

  }

  }


  return 0;

}

Measured memory_bytes: 524
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> x(n); rep(i, n)cin >> x[i];
	int res = 1e9;
	rep(i, 100)
	{
		int tmp = 0;
		rep(j, n)tmp += pow(x[j] - i, 2);
		res = min(res, tmp);
	}
	cout << res << endl;
}

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


int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  sort(all(p),greater<int>());
  int ans = 0;
  rep(i,n){
    if(i == 0) ans += p[i]/2;
    else ans += p[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    string s;cin >> s;
    vector<vector<int>> a(3,vector<int>(n));
    int x=0,y=0,z=0;
    vector<int> c(n);
    for(int i=n-1;i>=0;i--){
        if(s[i]=='R'){
            x++;
            c[i]=0;
        }
        else if(s[i]=='G'){
            y++;
            c[i]=1;
        }
        else{
            z++;
            c[i]=2;
        }
        a[0][i]=x;
        a[1][i]=y;
        a[2][i]=z;
    }
    ll ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            int p=j-i;
            if(c[i]==c[j]){
                continue;
            }
            if(j+p<n){
                if(c[i]==c[j+p]||c[j]==c[j+p]){
                    ans+=a[3-c[i]-c[j]][j+1];
                }
                else{
                    ans+=a[3-c[i]-c[j]][j+1]-1;
                }
            }
            else{
                ans+=a[3-c[i]-c[j]][j+1];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3684
#include <stdio.h>

 int main(){
 int a,b;scanf("%d%d",&a,&b);
 if(a<b){
 for(int i=0;i<b;i++)printf("%d",a);
 }else{
 for(int i=0;i<a;i++)printf("%d",b);
 }
 printf("\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	pair<ll, ll> p[200020];
	cin >> n >> m;
	for (int i = 0; i < m; i++)cin >> p[i].first >> p[i].second;
	sort(p, p + m);
	bool s[200020] = {}, ans = 0;
	for (int i = 0; i < m; i++) {
		if (p[i].first == 1)s[p[i].second] = 1;
		if (s[p[i].first] && p[i].second == n) {
			ans = 1;
			break;
		}
	}
	if (ans)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 3584
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	string ans = "No";

	int cnt = 0;
	for (int i=0; i<N; i++) {
		int D1, D2;
		cin >> D1 >> D2;
		if (D1 == D2) {
			cnt++;
			if (cnt == 3) {
				ans = "Yes";
			}
		} else {
			cnt = 0;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
	long long n;
	cin >> n;
	long long k;
	cin >> k;
	multimap<long long, long long> map1;
	for(long long i=0;i<n;i++){
		long long a;
		cin>>a;
		long long b;
		cin>>b;
		map1.insert(pair<long long, long long>(a, b));
	}
	long long ans=0;
	for (auto& x: map1) {
		if(x.second < k){
			ans+=(x.first)*(x.second);
			k-=x.second;
		}else{
			ans+=(x.first)*k;
			break;
		}
	}

	cout<<ans;
	return 0;
}


Measured memory_bytes: 9824
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

ll n,x,y,m,k,ans,cnt,mini=N,flag;
ll a[N],c[N],b[N],dp[N][3];
vector<pair<ll,ll > > v;
string s;
map<char,ll>mp;
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];

    for(ll i=2;i<=n;i++){
        a[i]+=max(b[i-1],c[i-1]);
        b[i]+=max(a[i-1],c[i-1]);
        c[i]+=max(b[i-1],a[i-1]);
    }
    cout<<max(a[n],max(b[n],c[n]));
return 0;
}


Measured memory_bytes: 4736
use std::io::*;
use std::str::FromStr;

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")
}

fn main() {
    let a: u32 = read();
    let b: u32 = read();
    let c: u32 = read();
    let mut count: u32 = 0;

    for number in a..(b+1) {
        if c % number == 0 {
            count += 1;
        }
    }
    println!("{}", count);
}



Measured memory_bytes: 5024
A, B, K = map(int, input().split())

def d(num):
    if num == 1:
        return [1]
    else:
        dl = []
        dl.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                dl.append(i)
        dl.append(num)

        return dl

ad = set(d(A))
bd = set(d(B))

div = sorted(set.intersection(ad, bd), reverse=True)

print(div[K-1])


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}


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

    int a = (N[0] - '1') + (N.size() - 1) * 9;
    int b = accumulate(N.begin(), N.end(), 0, [](int acc, char c) { return acc + c - '0';});

    cout << max(a,b) <<endl;
}


Measured memory_bytes: 256