akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N, A, B, C;
vector<string> s(100010), ans(100010);

void g(char s, char t){
  if(s == 'A') A--; if(t == 'A') A++;
  if(s == 'B') B--; if(t == 'B') B++;
  if(s == 'C') C--; if(t == 'C') C++;
}
void f(int i, char s, char t){
  ans[i] = s;
  g(t, s);
}

void dfs(int n){
  if(A < 0 || B < 0 || C < 0) return;
  if(n == N){
    Yes;
    REP(i, N) cout << ans[i] << "\n";
    exit(0);
  }

  REP(i, 2){
    f(n, s[n][i], s[n][1-i]);
    dfs(n+1);
    g(s[n][i], s[n][1-i]);
  }
}

signed main() {
  cin >> N >> A >> B >> C;

  REP(i, N) cin >> s[i];

  dfs(0);

  No;

  return 0;
}

Measured memory_bytes: 15840
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define _GLIBCXX_DEBUG
const int INF=1e18;

signed main(){
  	string S;cin>>S;
    bool ok=false;
    REP(i,2){
        int d=S[i]-'0';
        if(d==9)ok=true;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 0x3f3f3f3f, N = 2e5 + 87;

int s[N], t[N], x[N], seg[4*N], lazy[4*N], d[N], n, q;

void push(int v) {
	lazy[v*2] = min(lazy[v*2], lazy[v]);
	seg[v*2] = min(seg[v*2], lazy[v]);
	lazy[v*2+1] = min(lazy[v*2+1], lazy[v]);
	seg[v*2+1] = min(seg[v*2+1], lazy[v]);	
}

void upd(int l, int r, int val, int v = 1, int tl = 0, int tr = q) {
	if(l > r) return;
	if(l == tl && r == tr) {
		seg[v] = min(seg[v], val);
		lazy[v] = min(lazy[v], val);
		return;
	}
	push(v);
	int tm = (tl + tr) / 2;
	upd(l, min(r, tm), val, v*2,  tl, tm);
	upd(max(tm+1, l), r, val, v*2+1, tm+1, tr);
	seg[v] = min(seg[v*2], seg[v*2+1]);
}

int qry(int i, int v = 1, int tl = 0, int tr = q) {
	if(tl == tr)
		return seg[v];
	int tm = (tl + tr) / 2;
	push(v);
	if(i <= tm)
		return qry(i, v*2, tl, tm);
	else
		return qry(i, v*2+1, tm+1, tr);
}

int32_t main()
{
//	IO_OP;

	memset(seg, 0x3f, sizeof seg);
	memset(lazy, 0x3f, sizeof lazy);

	cin >> n >> q;
	for(int i=0;i<n;i++)
		cin >> s[i] >> t[i] >> x[i];	
	for(int i=0;i<q;i++)
		cin >> d[i];
	for(int i=0;i<n;i++) {
		int l = s[i] - x[i];
		int r = t[i] - x[i] - 1;
		int li = lower_bound(d, d+q, l) - d;
		int ri = upper_bound(d, d+q, r) - d - 1;
		upd(li, ri, x[i]);
	}
	for(int i=0;i<q;i++) {
		int qq = qry(i);
		if(qq != INF)
			cout << qq << endl;
		else
			cout << -1 << endl;
	}
}



Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int Mfunc(int num,int p);
vector<int> primesearch(int num);
bool isprime(int num);

vector<int> ans;

int main(){
	while(1){
		int n,p;
		cin >> n >> p;
		if(n == -1 && p == -1)break;
		int tans = Mfunc(n,p);
		ans.push_back(tans);
	}
	for(int i= 0;i < ans.size();i++) cout << ans[i] << endl;
}

int Mfunc(int num,int p){
	vector<int> pri = primesearch(num);
	vector<int> M;
	for(int i = 0;i < pri.size();i++){
		for(int j = 0;j <= i;j++){
			int tm = pri[i] + pri[j];
			M.push_back(tm);
		}
	}
	sort(M.begin(),M.end());
	return M[p-1];
}

vector<int> primesearch(int num){
	num++;
	vector<int> primes;
	while(primes.size() < 100){
		if(isprime(num)) primes.push_back(num);
		num++;
	}
	return primes;
}

bool isprime(int num){
	if(num < 2) return false;
	for(int i = 2;i < num;i++){
		if(i*i > num) break;
		if(num % i == 0) return false;
	}
	return true;
}

Measured memory_bytes: 3088
from itertools import accumulate


N = int(input())
S = input()

black = [0]*N
white = [0]*N

for i, s in enumerate(S):
    if s == '#':
        black[i] = 1
    else:
        white[i] = 1

# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]

ans = []
for i in range(N+1):
    ans.append(black[i] + white[i])

print(min(ans))


Measured memory_bytes: 29176
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
ll dp[maxn], arr[maxn], n;

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }
    dp[1] = 0LL;
    dp[2] = abs(arr[2] - arr[1]);
    for(int i=3;i<=n;i++) {
        dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
    }
    cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int pos, key;
int queue[2000000];
char command[8];

void insert_key(int val) {
    int i = pos++;
    while (i > 0) {
        int p = (i - 1) / 2;
        if (queue[p] >= val) { break; }
        queue[i] = queue[p];
        i = p;
    }
    queue[i] = val;
}

int extract_key() {

    int result = queue[0];

    int val = queue[--pos], i = 0;
    for (int left, right; i * 2 + 1 < pos; ) {
        left = i * 2 + 1, right = i * 2 + 2;
        if (right < pos && queue[right] > queue[left]) {
            left = right;
        }
        if (queue[left] <= val) {
            break;
        }
        queue[i] = queue[left];
        i = left;
    }
    queue[i] = val;
    return result;
}

int main(void) {

    while (true) {
        scanf("%s", command);
        if (command[0] == 'i') {
            scanf("%d", &key);
            insert_key(key);
        }
        else if (command[1] == 'x') {
            printf("%d\n", extract_key());
        }
        else {
            break;
        }
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
  }
  
  sort(s.begin(), s.end());
  int count = 1;
  for(int i = 0; i < n - 1; i++) {
    if(s.at(i) != s.at(i+1)) count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 9596
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N,Z,W;
LL a[2001];
LL dp[2001][2];
int main(){
    cin>>N>>Z>>W;
    REP(i,N){
        cin>>a[i];
    }
    if(N==1){
       cout<<abs(a[0]-W)<<endl;
    }else{
       dp[N-2][0]=abs(a[N-2]-a[N-1]);
       dp[N-2][1]=abs(a[N-2]-a[N-1]);
       for(int i=N-3;i>=0;i--){
           dp[i][0]=abs(a[i]-a[N-1]);
           dp[i][1]=abs(a[i]-a[N-1]);
           for(int j=i+1;j<N-1;j++){
               dp[i][0]=min(dp[i][0],dp[j][1]);
               dp[i][1]=max(dp[i][1],dp[j][0]);
           }
       }
       LL ans=abs(a[N-1]-W);
       REP(i,N-1){
          ans=max(ans,dp[i][0]);
       }
       cout<<ans<<endl;
    }
    return(0);
}

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

int main() {
	// your code goes here
	
	long long int n,d,count=0;
	cin>>n>>d;
	while(n--){
	    long long int x1,x2,dist;
	    cin>>x1>>x2;
	    dist=pow(x1,2)+pow(x2,2);
	    if(sqrt(dist)<=d)
	    count++;
	    
	}
	cout<<count;
	return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    if(n>m)swap(n,m);
    if(n==1){
        if(m==1){
            cout << 1 << endl;
            return 0;
        }else{
            cout << m-2 << endl;
        }
    }else{
        cout << (n-2)*(m-2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/* Type alias */
using ll = long long;
using ld = long double;

using vec_i = std::vector<int>;
using vec_ll = std::vector<ll>;
using vec_ld = std::vector<ld>;

using set_i = std::set<int>;
using set_ll = std::set<ll>;
using set_ld = std::set<ld>;

using uset_i = std::unordered_set<int>;
using uset_ll = std::unordered_set<ll>;
using uset_ld = std::unordered_set<ld>;

/* IO macros */
#define in(i)            int i; std::cin >> i
#define in2(i, j)        int i, j; std::cin >> i >> j
#define in3(i, j, k)     int i, j, k; std::cin >> i >> j >> k
#define in_(i)           std::cin >> i
#define in2_(i, j)       std::cin >> i >> j
#define in3_(i, j, k)    std::cin >> i >> j >> k
#define in_ll(i)         ll i; std::cin >> i
#define in2_ll(i, j)     ll i, j; std::cin >> i >> j
#define in3_ll(i, j, k)  ll i, j, k; std::cin >> i >> j >> k
#define in_ll_(i)        std::cin >> i
#define in2_ll_(i, j)    std::cin >> i >> j
#define in3_ll_(i, j, k) std::cin >> i >> j >> k
#define in_ld(i)         ld i; std::cin >> i
#define in2_ld(i, j)     ld i, j; std::cin >> i >> j
#define in3_ld(i, j, k)  ld i, j, k; std::cin >> i >> j >> k
#define in_ld_(i)        std::cin >> i
#define in2_ld_(i, j)    std::cin >> i >> j
#define in3_ld_(i, j, k) std::cin >> i >> j >> k
#define in_c(i)          char i; std::cin >> i
#define in2_c(i, j)      char i, j; std::cin >> i >> j
#define in3_c(i, j, k)   char i, j, k; std::cin >> i >> j >> k
#define in_c_(i)         std::cin >> i
#define in2_c_(i, j)     std::cin >> i >> j
#define in3_c_(i, j, k)  std::cin >> i >> j >> k
#define in_str(s)        std::string s; std::cin >> s

#define vec_in(v, n)    auto v=vec_i(n); for(auto &x:v){std::cin>>x;}
#define vec_in_ll(v, n) auto v=vec_ll(n);for(auto &x:v){std::cin>>x;}
#define vec_in_ld(v, n) auto v=vec_ld(n);for(auto &x:v){std::cin>>x;}

#define print(x)   std::cout << x
#define println(x) std::cout << x << "\n"
#define print_vec(v) for (auto &x:v) { std::cout << x << " ";}
#define println_vec(v) for (auto &x:v) { std::cout << x << " ";} std::cout << "\n";
#define print_long_vec(v) for (auto &x:v) { std::cout << x << "\n";}
#define println_long_vec(v) for (auto &x:v) { std::cout << x << "\n";} std::cout << "\n";

/* Loops */
#define rep(i, n) for (auto i = 0; i < n; ++i)

/* Vector manipulation */
#define vec_sort(v) std::sort(v.begin(), v.end())

using namespace std;
/* Code Starts Here*/
int main () {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    in2(X, Y);
    for (int i = 0; i <= X; ++i) {
        int j = X - i;
        if (i * 2 + j * 4 == Y) {
            println("Yes");
            return 0;
        }
    }
    println("No");
    return 0;
}


Measured memory_bytes: 3640
#include "stdio.h"

int min_int(int a,int b){
  if(a>b){
    return b;
  }else{
    return a;
  }
}

int abs_int(int a){
  if (a>0) {
    return a;
  }else{
    return -a;
  }
}

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  int h[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &h[i]);
  }
  int c[N];
  c[0]=0;
  c[1]=abs_int(h[0]-h[1]);
  for (size_t i = 2; i < N; i++) {
    c[i]=min_int(c[i-1]+abs_int(h[i-1]-h[i]),c[i-2]+abs_int(h[i-2]-h[i]));
  }
  printf("%d", c[N-1]);
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;

int main()
{
	
	string q;
	getline(cin, q);
	for (int i = 0; i <= q.size(); i++)
	{
		if (q[i]>='a' && q[i]<='z') q[i] = toupper(q[i]);
		else if (q[i]>='A' && q[i]<='Z') q[i] = tolower(q[i]);
	}
	cout << q<<endl;
}
	


Measured memory_bytes: 3144
#include <stdio.h>

char s[110], t[110], res[220];
int n;

int main() {
    scanf("%d%s%s", &n, s, t);
    for (int i = 0; i < 2 * n; i++) {
        if (i & 1) res[i] = t[i / 2];
        else res[i] = s[i / 2];
    }
    printf("%s\n", res);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	ll ans = 0;
	for(ll i=1; i<=(ll)n; i++){
		if(i%3&&i%5) ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3648
/*Heian-Kyo Walking*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
#define le 1000000007;

int main(void){
  long long int a,b,c;
  cin >> a >> b >> c;
  if(a%2!=0 || b%2!=0 || c%2!=0){
    cout << 0 << endl;
    return 0;
  }
  if(a==b && b==c && c==a){
    cout << -1 << endl;
    return 0;
  }
  int tmp,tmp2,cnt=0;
  for(long long int i=0;i<=100000;i++){
    tmp=a;
    tmp2=b;
    a=b/2+c/2;
    b=tmp/2+c/2;
    c=tmp/2+tmp2/2;
    cnt++;
    if(a%2!=0||b%2!=0||c%2!=0){
      cout << cnt << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>

#define REP(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

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

    vi a(n);

    REP(i, 0, n) {
        scanf("%d", &a[i]);
    }

    int max, min, index_max, index_min;
    max = -1000000-1;
    min = 1000000+1;
    
    REP(i, 0, n) {
        if(a[i] > max) {
            max = a[i];
            index_max = i;
        }
        if(a[i] < min) {
            min = a[i];
            index_min = i;
        }
    }

    if (abs(max) > abs(min)) {
        if (max >= 0) {
            printf("%d\n", 2*n-1);

            REP(i, 0, n) {
                printf("%d %d\n", index_max+1, i+1);
            }
            REP(i, 0, n-1) {
                printf("%d %d\n", i+1, i+2);
            }
        } else {
            printf("%d\n", 2*n-1);

            REP(i, 0, n) {
                printf("%d %d\n", index_max+1, i+1);
            }
            REP(i, 0, n-1) {
                printf("%d %d\n", (n-i), (n-i)-1);
            }
        }
    } else {
        if (min >= 0) {
            printf("%d\n", 2*n-1);

            REP(i, 0, n) {
                printf("%d %d\n", index_min+1, i+1);
            }
            REP(i, 0, n-1) {
                printf("%d %d\n", i+1, i+2);
            }
        } else {
            printf("%d\n", 2*n-1);

            REP(i, 0, n) {
                printf("%d %d\n", index_min+1, i+1);
            }
            REP(i, 0, n-1) {
                printf("%d %d\n", (n-i), (n-i)-1);
            }
        }
    }

    return 0;
}

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

//AGC-A Range Product
//http://agc002.contest.atcoder.jp/tasks/agc002_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1 3");
            //Positive
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("-3 -1");
            //Negative
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("-1 1");
            //Zero
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int a = wkArr[0];
        int b = wkArr[1];

        int SignA = Math.Sign(a);
        int SignB = Math.Sign(b);

        if (SignA != SignB) { //場合1 符号が異なる
            Console.WriteLine("Zero");
        }
        else if (SignA == 1 && SignB == 1) { //場合2 両方とも正
            Console.WriteLine("Positive");
        }
        else if (SignA == 0 && SignB == 0) { //場合3 両方とも0
            Console.WriteLine("Zero");
        }
        else if (SignA == -1 && SignB == -1) { //場合4 両方ともマイナス
            int NumCnt = b - a + 1;
            Console.WriteLine(NumCnt % 2 == 0 ? "Positive" : "Negative");
        }
    }
}


Measured memory_bytes: 2904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int W=sc.nextInt();
		int H=sc.nextInt();
		pl(H*W);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}



Measured memory_bytes: 24356
#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 <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
string s;

signed main() {
    cin >> N >> s;
    int l = 0, sum = 0;
    rep(i,0,N) {
        if(s[i] == '(') sum++;
        else sum--;
        if(sum == -1) l++, sum = 0;
    }
    cout << string(l, '(') + s + string(sum, ')') << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main ()
 {
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   if (a + b < c + d) {
     cout << "Right" << endl;
   }
   else if (a + b > c + d) {
     cout << "Left" << endl;
   }
   else {
     cout << "Balanced" << endl;
   }
 }

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[4];
int main(){
	int a;
	while(scanf("%d",&a),a){
		if(a%1111==0){
			printf("NA\n");
			continue;
		}
		int count=0;
		while(a!=6174){
			for(int i=0;i<4;i++){
				d[i]=a%10;
				a/=10;
			}
			std::sort(d,d+4);
			int b=0;
			for(int i=0;i<4;i++){
				b*=10;
				b+=d[i];
			}
			int c=0;
			for(int i=3;i>=0;i--){
				c*=10;
				c+=d[i];
			}
			a=c-b;
			count++;
		}
		printf("%d\n",count);
	}
}

Measured memory_bytes: 1052
import sys
from itertools import accumulate
from math import log2
def input(): return sys.stdin.readline().strip()

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

    if 70 <= K:
        ans = [N] * N
        print(" ".join(map(str, ans)))
    else:
        for _ in range(K):
            B = [0] * (N + 1)
            for i in range(N):
                head = max(i - A[i], 0)
                tail = min(i + A[i] + 1, N)
                B[head] += 1
                B[tail] -= 1
            A = list(accumulate(B))[:N]
        print(" ".join(map(str, A)))
    

if __name__ == "__main__":
    main()


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

int main() {
    /*
    long long int x,y,z;
    const long long int num = 1000000007;
    
    cin >> x;
    cin >> y;
    cin >> z;
    
    
    if(x * y > num){
        x * y 
    }
    
    cout << x * y % num << endl;
    
    return 0;
    */
    
    string str;
    bool x = false;
    bool y = false;
    
    
    cin >> str;
    
    if(str.find("N") != -1 && str.find("S") != -1){
        y = true;
    }
    if(str.find("N") == -1 && str.find("S") == -1){
        y = true;
    }
    
    if(str.find("W") != -1 && str.find("E") != -1){
        x = true;
    }
    if(str.find("W") == -1 && str.find("E") == -1){
        x = true;
    }
    
    if(y == true && x == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <set>
#include <cstring>
#include <cctype>

#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 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};


llong pow(int x, int n){
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}


void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}


string toUpper(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = toupper(s[i]);
    }
    return t;
}

string toLower(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = tolower(s[i]);
    }
    return t;
}


int main() {
    int n, tmp;
    set<int>s;
    cin >> n;
    REP(i, n) {
        cin >> tmp;
        s.insert(tmp);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
int main()
{
  long long N;
  long long X,M,A;
  std::cin>>N>>X>>M;
  A = X;
  long long count = X;
  std::vector<long long> vec;
  vec.push_back(X);
  std::vector<long long>::iterator itr;
  long long a = 2;
  long long index = 0;
  for(; a <= N; a++)
  {
    X = (X * X) % M;
    count += X;
    itr = std::find(vec.begin(), vec.end(), X);
    
    if(itr != vec.end())
    {
      index = std::distance(vec.begin(), itr);
      vec.push_back(X);
      break;
    }
    vec.push_back(X);
  }
  long long XXX = A;
  long long counttt = A;
  for(long long c = 2; c <= index + 1; c++)
  {
    XXX = (XXX * XXX) % M;
    counttt += XXX;
  }
  long long b = (N-a)%(a-index-1);
  count = count + (count - counttt) * ((N-a-b)/(a-index-1));
  for(long long c = 1;c <= b; c++)
  {
    X = (X*X)%M;
    count += X;
  }
  std::cout<<count;
}


Measured memory_bytes: 3380
//
//  main.cpp
//  B - Roller Coaster
//
//  Created by Hashizo on 2019/09/28.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {

	ll ans = 0;
	ll n,k;
	cin >> n >> k;

	vector<ll> hight(n);
	REP(i, n) {
		cin >> hight[i];
	}
	
	SORT(hight);
	
	REP(i, n) {
		if (hight[i] >= k ){
			ans = n - i;
			break;
		}
	}
	
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c,d=0;
  cin>>a>>b>>c;
  if(a<b&&b<c){
    cout<<"Yes"<<"\n";
  }
  if(a>=b||b>=c||a>=c){
    cout<<"No"<<"\n";
  }
  return(0);
}



Measured memory_bytes: 3100
import java.util.*;

import com.sun.swing.internal.plaf.basic.resources.basic;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[m];
        int b[] = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        //答えがintに収まらないためlong型を使う
        long[] ans = new long[m];
        //最後は全ての橋が壊れているのでN個から2つを選ぶ分だけある（Combination）
        ans[m - 1] = (long) n * (n - 1) / 2;
        UnionFind uni = new UnionFind(n);
        for (int i = m - 1; i >= 1; i--) {
            //繋がってなかったのが繋がった時
            if (uni.root(a[i]) != uni.root(b[i])) {
                ans[i - 1] = (long) ans[i] - uni.size(a[i]) * uni.size(b[i]);
                uni.connect(a[i], b[i]);
            } else {
                ans[i - 1] = ans[i];
            }
        }
        for (int i = 0; i < m; i++){
            System.out.println(ans[i]);
        }
    }
    
    static class UnionFind{
        ArrayList<Integer> parent;

        UnionFind(int n) {
            parent = new ArrayList<Integer>();
            Integer[] values = new Integer[n];
            //初期値セット、作るときは全て-1にする。こうすることで全てバラバラになる
            Arrays.fill(values, -1);
            //初期値を配列に入れる
            parent.addAll(Arrays.asList(values));
        }
        //Aがどのグループに属しているか調べる
        int root(int a) {
            if (parent.get(a) < 0) {
                return a;
            } else {
                int root = root(parent.get(a));
                parent.set(a, root);
                return root;
            }
        }

        //自分のいるグループの頂点数を調べる
        int size(int a) {
            return -parent.get(root(a));
        }

        //AとBをくっつける
        boolean connect(int a, int b) {
            //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
            a = root(a);
            b = root(b);
            if (a == b) {
                //すでにくっついているのでくっつけない
                return false;
            }

            //大きい方に小さい方をくっつける
            //Bのほうが大きい場合はAとBを入れ替える
            if (size(a) < size(b)) {
                int tmp = a;
                a = b;
                b = tmp;

            }

            parent.set(a, parent.get(a) + parent.get(b));
            parent.set(b, a);

            return true;

        }



    }
}

Measured memory_bytes: 94184
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define READ(FILE) freopen(FILE,"r",stdin)
#define WRITE(FILE) freopen(FILE,"w",stdout)
#define loop(i,s,e) for(int i=s;i<e;i++)
#define mego fast();
using namespace std;
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll lcm(ll x, ll y)
{
    return (x*y)/__gcd(x,y);
}
int sum(string s)
{
    int x=0,sz=s.size();
    loop(i,0,sz)x+=(s[i]-'0');
    return x;
}

int main()
{
    mego
    int n,m,k;
   // cout<<(1<<1)<<endl<<(1<<2)<<endl;
   cin>>n>>m>>k;
   char arr[n][m];
   loop(i,0,n)
   loop(j,0,m)
   cin>>arr[i][j];
   int ans=0;
   int p1=1,p2=1;
   loop(i,0,n)p1*=2;
   loop(i,0,m)p2*=2;
   loop(c1,0,p1)
   loop(c2,0,p2)
   {int cur=0;
       loop(i,0,n)
       loop(j,0,m)
       if(arr[i][j]=='#' && !((1<<i & c1)||(1<<j & c2)))cur++;
   ans+=(cur==k);
   }
   cout<<ans;
        return 0;
}



Measured memory_bytes: 3652
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        int a = inp.nextInt();
        int b = inp.nextInt();
        if ((a + b) % 2 == 0) System.out.println((a + b) / 2);
        else System.out.println("IMPOSSIBLE");
    }
}


Measured memory_bytes: 23892
// ※※※ 解答不能 ※※※
// yokozuna57氏.
// https://atcoder.jp/contests/cf17-final/submissions/1805242
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1e9 + 7;
#define repx(i, a, b) for(LL i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(LL i = a; i >= b; i--)
LL dp[111][5050];

LL mPow(LL x, LL k){
    if(k == 0) return 1;
    LL ret = mPow(x, k / 2);
    ret *= ret;
    ret %= MOD;
    if(k % 2 == 1){
        ret *= x;
        ret %= MOD;
    }
    return ret;
}

int main(){
    LL N, K;
    scanf("%lld %lld", &N, &K);
    dp[K][0] = K;
    dp[K][1] = 1;
    repr(i, K - 1, 1){
        rep(j, 5050){
            dp[i][j] += dp[i + 1][j] * (K - i);
            dp[i][j + j / i] += dp[i + 1][j] * (i - j % i);
            dp[i][j + j / i + 1] += dp[i + 1][j] * (j % i + 1);
        }
        rep(j, 5050) dp[i][j] %= MOD;
    }
    
    LL ret = mPow(K + 1, K) * N * K;
    ret %= MOD;
    ret *= mPow(2, MOD - 2);
    ret %= MOD;
    repx(i, 1, 5049){
        dp[1][i] *= i;
        dp[1][i] %= MOD;
        ret += MOD - dp[1][i];
    }
    ret %= MOD;
    ret *= mPow(K + 1, N - K);
    ret %= MOD;
    printf("%lld\n", ret);
    return 0;
}

Measured memory_bytes: 4352
// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

int n;
int a[N];
map<int,int> mp;

bool divide(int x){
	int tmp=x;
	for(int i=2;i<=x/i;++i){
		if(x%i==0){
			int t=1;
			while(x%i==0){
				t*=i;
				if(mp[t] && t!=tmp) return false;
				x/=i;
				if(mp[x] && x!=tmp) return false;
			}
			x=tmp;
		}
	}
	return true;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	 for(int i=1;i<=n;++i){
	 	cin>>a[i];
	 	mp[a[i]]++;
	 }
	 int cnt=0;
	 if(mp[1]==1){
	 	cout<<1<<endl;
	 	return 0;
	 }
	 if(mp[1]>1){
	 	cout<<0<<endl;
	 	return 0;
	 }
	 for(int i=1;i<=n;++i){
	 	if(divide(a[i]) && mp[a[i]]==1) cnt++;
	 }
	 cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 33236
n=int(input())
a=list(map(int,input().split()))
ten=0
ans=0
s=[0]*n
for i in range(n):
    s[i]=a[i]+ten
    if i%2==0:
        if s[i]<=0:
            ans+=abs(1-s[i])
            ten=1
        else:
            ten=s[i]
    elif i%2==1:
        if 0<=s[i]:
            ans+=abs(-1-s[i])
            ten=-1
        else:
            ten=s[i]
ten_2=0
ans_2=0
s_2=[0]*n
for i in range(n):
    s_2[i]=a[i]+ten_2
    if i%2==0:
        if 0<=s_2[i]:
            ans_2+=abs(-1-s_2[i])
            ten_2=-1
        else:
            ten_2=s_2[i]
    elif i%2==1:
        if s_2[i]<=0:
            ans_2+=abs(1-s_2[i])
            ten_2=1
        else:
            ten_2=s_2[i]
print(min(ans,ans_2))
            
    

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

int main() {
	int N; cin >> N;
	vector<int> Q(N);
	for (int i = 0;i < N;i++) {
		cin >> Q[i];
	}
	sort(Q.begin(), Q.end());
	reverse(Q.begin(), Q.end());
	int h = Q[0]; int k;
	bool even;
	if (h % 2) {
		even = false;
		k = (h + 1) / 2;
	}
	else {
		even = true;
		k = h / 2;
	}
	int cnt = 0;
	bool j=true;
	for (int i = 0;i < N;i++) {
		if (Q[i] == h) {
			cnt++;
		}
		else {
			if (cnt < 2) {
				j = false;
				break;
			}
			h--;
			if (Q[i] != h) {
				j = false;
				break;
			}
			cnt = 1;
		}

	}
	if (h == k && j) {
		if (even) {
			if(cnt == 1)
				cout << "Possible" << endl;
			else
				cout << "Impossible" << endl;
		}
		else{
			if (cnt == 2)
				cout << "Possible" << endl;
			else
				cout << "Impossible" << endl;
		}
	}
	else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int a,b;

int main(){
	cin >> a >> b;
	
	cout << a*3/2 + (a*3%2 + b)/2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>
#include <cstring>

using namespace std;

//const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
//const int inf = 1e7;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 200500; //       e5
const int SZ = 20;


int main()
{
    //vector<int> a;lower_bound(a.begin(), a.end());
    //brute(); return 0;
    ios_base::sync_with_stdio(false);
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    string s;
    cin >> s;
    int ans = s.size() - 1;
    for(int c = 'a'; c <= 'z'; c++){
        string t = s;
        int cnt = 0;
        while(t.size() > 1){
            bool ok = true;
            for(int i = 0; i < t.size(); i++){
                if(t[i] != c) ok = false;
            }
            if(ok) break;
            cnt++;
            string t2 = "";
            for(int i = 0 ; i < t.size() - 1; i++){
                if(t[i] == c || t[i + 1] == c) t2 += c; else t2 += t[i];
            }
            t = t2;
        }
        if(cnt < ans) ans = cnt;
    }
    cout << ans << endl;
    return 0;
}

// 19 + 15 == 10


Measured memory_bytes: 256
H,W,h,w = map(int,input().split())
if H%h == 0 and W%w == 0:
    print('No')
    exit()
print('Yes')

n = 1000
if W%w:
    m = -((w-1)*n + 1)
    row = [m if i%w==w-1 else n for i in range(W)]
    for i in range(H):
        print(*row)
else:
    m = -((h-1)*n + 1)
    for i in range(H):
        if i%h == h-1:
            print(*([m] * W))
        else:
            print(*([n] * W))

Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n; cin >> n;
	vector<ll> cnt(n + 1, 1);
	
	ll ans = 0;
	rep(i, 1, n){
		ans += i * cnt[i];
		
		for(ll j = 2; i * j <= n; j++){
			cnt[i*j]++;
		}
	}
	print(ans)
	
	return 0;
}

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

int main(){
    string s,t;
    cin>>s;
    for (int i=0;i<s.size();i++){
        if (s.at(i)=='0'){
            t += "0";
        }else if(s.at(i)=='1'){
            t += "1";
        }else if(s.at(i)=='B'){
            if (t.empty()==false){
                t.erase(t.size()-1);
            }
        }
    }
    cout<<t<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#define ll long long
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_set>
#include <iomanip>
using namespace std;
ll dp[400][400] = {0};
vector<ll> elements;


ll sum(int start, int last)
{
    ll ans = 0;
    for(int i = start; i<=last; ++i)
    {
        ans+=elements[i];
    }
    return ans;

}


ll check(int start, int last)
{
    //cout<<start<<"\t"<<last<<endl;
    if(start == last)
    {
        dp[start][start] = 0;
        return 0;
    }

    if(dp[start][last] != -1)
    {
        return dp[start][last];
    }

    ll ans = 1e18+5;
    for(int i=start; i< last; ++i)
    {
       // cout<<ans<<" "<<" "<<start<<" "<<last<<endl;
        ans = min( (check(start, i) + check(i+1, last) + (sum(start, i)+sum(i+1, last))),ans);
    }
    dp[start][last] = ans;
    return ans;


}


int main()
{

    ll n;
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<n; ++j)
        {
            dp[i][j] = -1;
        }
    }
    ll temp;
    for(ll i=0; i< n; ++i){
        cin>>temp;
        elements.push_back(temp);
    }
    ll ans  = check(0 , n-1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1536
//Heaplax
#include<bits/stdc++.h>
#define N 100005
#define int long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int x,y,z,n,base,f[N];
struct node
{
	int a,b;
	bool operator < (const node& i)const
	{
		return a-b>i.a-i.b;
	}
}e[N];
main()
{
	re(x),re(y),re(z);
	n=x+y+z;
	for(int i=1;i<=n;++i)
	{
		re(e[i].a),re(e[i].b);
		int c;re(c);
		base+=c;
		e[i].a-=c;e[i].b-=c;
	}
	sort(e+1,e+n+1);
	priority_queue<int,vector<int>,greater<int>> que;
	for(int i=1;i<=n;++i)
	{
		f[i]=f[i-1]+e[i].a;
		que.push(e[i].a);
		if(que.size()>x)
		{
			f[i]-=que.top();
			que.pop();
		}
	}
	while(!que.empty())que.pop();
	int now=0,ans=0;
	for(int i=n;i>x;--i)
	{
		now+=e[i].b;
		que.push(e[i].b);
		if(que.size()>y)
		{
			now-=que.top();
			que.pop();
		}
		if(que.size()==y)
			ans=max(ans,base+now+f[i-1]);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 3704
n = gets.to_i
ary0 = gets.split.map(&:to_i)
ary1 = []

n.times do |i|
  ary1[i] = ary0[i] - (i + 1)
end

b = ary1.sort[n / 2]

n.times do |i|
  ary0[i] = (ary0[i] - (b + i + 1)).abs
end

puts ary0.inject(:+)


Measured memory_bytes: 20680
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 100010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int a[N<<1],last[N<<1],dp[N<<1];
int main(){
    //srand(time(NULL)+clock());
    int T,ca=0,k,i,j,m=0,n;
    //double start=clock();
    scanf("%d",&n);
    rep(i,0,n)scanf("%d",&a[i]);
    rep(i,0,n){
        j=i;
        while(j<n&&a[j]==a[i])j++;
        a[m++]=a[i];
        i=j-1;
    }
    n=m;
    memset(last,-1,sizeof(last));
    dp[n]=1;
    per(i,0,n){
        int x=a[i];
        if(last[x]>=0){
            dp[i]=dp[last[x]];
        }
        add(dp[i],dp[i+1]);
        last[x]=i;
    }
    printf("%d\n",dp[0]);
    //cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


Measured memory_bytes: 2560
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
ll n;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    ll ans=0;
    for(int i=0;i<100000;i++){
        for(int i=0;i<n;i++){
            if(a[i]<=n-1)continue;
            ll count=a[i]/n;
            ans+=count;
            a[i]-=count*n;
            for(int j=0;j<n;j++){
                if(i!=j){
                    a[j]+=count;
                }
            }
        }
    }
    cout<<ans<<"\n";
}



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

class Program
{
    public static void Main(string[] args)
    {
        string s = Console.ReadLine();


        int a = int.Parse(s);

        int ans = 180 * (a - 2);

        Console.WriteLine(ans);
        //Console.WriteLine(ans);


    }

}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//find_by_order(x) -> returns an iterator to the element at a given position
//order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;
//indexed_set s;

string s;

int main() {

    cin >> s;
    int cur=0,mx = 0;
    s=s+'S';
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') cur++;
        else {
            mx = max(mx, cur);
            cur = 0;
        }
    }

    cout << mx;

return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0181
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int[] nm = RIntAr();
                if (nm.Sum() == 0) break;

                int[] books = new int[nm[1]];
                for (int i = 0 ; i < nm[1] ; i++) books[i] = RInt();

                int left = -1;
                int right = 1500000;

                while (right - left > 1)
                {
                    int mid = (left + right) / 2;
                    if (CanStore(mid, nm[0], books)) right = mid; else left = mid;
                }

                Console.WriteLine(right);
            }

        }

        private static bool CanStore(int width, int MaxSteps, int[] books)
        {
            int steps = 1;
            int sum = 0;

            for (int i = 0 ; i < books.Length ; i++)
            {
                if (books[i] > width) return false;
                if (sum + books[i] > width)
                {
                    steps++;
                    sum = books[i];
                }
                else
                {
                    sum += books[i];
                }
            }

            return steps <= MaxSteps;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 14000
#include<iostream>
#include <algorithm>
using namespace std;
int main(){
  for(;;){
    int n,m,l;
    cin >> n;//島の数
    cin >> m;//出力数
    if(n==0&&m==0)break;
    int fare[n+1][n+1];
    for(int i=1; i<=n; i++){
      for(int j=1; j<=n; j++){
        fare[i][j]=1000000;
      }
      fare[i][i]=0;
    }
    int a,b,c,d;
    for(int i=0; i<m; i++){
      cin>>a;
      if(a==1){
        cin>>b>>c>>d;
        if(fare[b][c]>d){
          fare[b][c]=d;
          fare[c][b]=d;
          for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
              fare[j][k]=min(fare[j][k],fare[j][b]+fare[b][k]);
              fare[j][k]=fare[k][j]=min(fare[j][k],fare[j][c]+fare[c][k]);
            }
          }
        }
      }
      else{
        cin>>b>>c;
        if(fare[b][c]<1000000){
          cout << fare[b][c] << endl;

        }
        else{
          cout << -1 << endl;
        }
      }
    }
  }

  }



Measured memory_bytes: 3032
#include<stdio.h>
#define N 100

main(){
  int i, j, c, A[N], key;
  scanf("%d",&c);
  for(i = 0;i < c;i++){
    scanf("%d",&A[i]);
  }
  for(j = 0;j < c - 1;j++){
      printf("%d ",A[j]);
    }
    printf("%d\n", A[c-1]);
  for(i = 1;i < c;i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    for(j = 0;j < c - 1;j++){
      printf("%d ",A[j]);
    }
    printf("%d\n", A[c-1]);
  }
  return 0;
}

Measured memory_bytes: 600