akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

void printArr(int N, int *arr){
    for(int i=0;i!=N;i++){
        if(i>0)cout<<" "; //隣接する要素の間に1つの空白を出力
        cout<<arr[i];
    }
    cout<<endl;
}

void insertionSort(int N, int *arr){
    int i, j, temp;
    for(int i=1;i!=N;i++){
        temp=arr[i];
        j=i-1;
        while(arr[j]>temp && j>=0){
            arr[j+1]=arr[j];
            j--;
        }
        arr[j+1]=temp;
        printArr(N, arr);
    }
}

int main(){

    int N;
    int arr[100];
    
    cin>>N;
    for(int i=0;i!=N;i++){
        cin>>arr[i];
    }

    printArr(N, arr);
    insertionSort(N, arr);

    return 0;
}



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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  string mb;
  cin>>mb;
mb.push_back(mb[0]);
  for(int kai=3;kai>=0;kai--){
  vector<int>a(n+2);
  a[0]=kai%2;
  a[1]=(kai/2)%2;
  int t=0;
  rep(i,n){
    if(a[i+1]==1){
      if(mb[i+1]=='o')t=a[i];
      else  if(mb[i+1]=='x')t=1-a[i];
    }
    else{
      if(mb[i+1]=='o')t=1-a[i];
      else t=a[i];
    }

    a[i+2]=t;
}
if(a[n+1]==a[1]&&a[n]==a[0]){
  rep(i,n){
    if(a[i]==0)cout<<'W';
    else cout<<'S';
  }
  exit(0);
}
}
  cout<<-1<<endl;
}


Measured memory_bytes: 4564
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    rep(i, N) cin >> H[i];

    vector<vector<int>> G(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    int ans = 0;
    rep(i, N) {
        int now = H[i];
        bool flag = true;

        rep(j, G[i].size()) {
            if (now <= H[G[i][j]])
                flag = false;
        }
        if (flag) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

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

const int N = 310;

double dp[N][N][N];
int ct[4], n;

double solve(int a, int b, int c) {
	if (a + b + c == 0) return 0.0;
	if (dp[a][b][c] > -0.5) return dp[a][b][c];

	dp[a][b][c] = (double)n/(a + b + c);
	if (a > 0)
		dp[a][b][c] += (double)solve(a-1, b, c) * ((double)a/(a+b+c));
	if (b > 0)
		dp[a][b][c] += (double)solve(a+1, b-1, c) * ((double)b/(a+b+c));
	if (c > 0)
		dp[a][b][c] += (double)solve(a, b+1, c-1) * ((double)c/(a+b+c));

	return dp[a][b][c];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x; cin >> x;
		ct[x]++;
	}
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k <= n; ++k)
				dp[i][j][k] = -1.0;
	cout << setprecision(15) << fixed;
	cout << solve(ct[1], ct[2], ct[3]) << "\n";
}


Measured memory_bytes: 224460
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define int long long
template <typename T, typename U>
istream &operator>>(istream &in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD=1e9+7;
	int n,m;
	cin>>n>>m;
	if(n==m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):       #(要素数)の分だけリストを作る
        self.n = n               #負の数なら親、正の数なら親のノード番号を入力
        self.parents = [-1]*n    #負の数の絶対値はそのグループに属する要素数を意味する
   
    #xが属する親番号を返す
    def find(self, x):
        if self.parents[x-1] < 0:
            return x
        else:
            self.parents[x-1] = self.find(self.parents[x-1])
            return self.parents[x-1]
    
    #xとyに関係があるとき、xの属するグループとyの属するグループ統合する
    def union(self, x, y):
        x = self.find(x) #xの親番号を返す
        y = self.find(y) #yの親番号を返す

        if x == y: return
        else:
            #xに属するグループ数の方が大きいようにする
            if self.parents[x-1] > self.parents[y-1]:
                x, y = y, x
            self.parents[x-1] += self.parents[y-1]
            self.parents[y-1] = x 

    #xの属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)-1]
    
    #xとyが等しいかどうか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    #xの属するグループの要素を返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    #親となる要素だけを返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    #グループの数を返す
    def group_count(self):
        return len(self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    A,B = map(int, input().split())
    uf.union(A,B)
parents = uf.roots()
ans = 0
for p in parents:
    ans = max(ans, uf.size(p))
print(ans)


Measured memory_bytes: 18324
s = input()
n = len(s)
case0=0
case1=0

for i in range(n):
  if (i%2==0):
    if s[i]=='0':
      case0 += 1
    else:
      case1 += 1
  else :
    if s[i]=='0':
      case1 += 1
    else :
      case0 += 1

print(min(case0,case1))

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

int n, a[100000], t;

int main() {
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int mina = a[0], max = 0, ans = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] - mina > max) {
			ans = 1;
			max = a[i] - mina;
		}
		else if (a[i] - mina == max) {
			ans++;
		}
		if (a[i] < mina) mina = a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    EAlmostEverywhereZero solver = new EAlmostEverywhereZero();
    solver.solve(1, in, out);
    out.close();
  }

  static class EAlmostEverywhereZero {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      // Nのlengthで考える
      // 例えば349なら3
      // ギリギリ(制約がある)とセーフ確定(なんでもいい)とアウトがある
      // 例えば左から一桁目が2,1,0ならセーフ確定,3ならギリギリ
      String n = in.next();
      int k = in.nextInt();
      int len = n.length();
      // g[i][j] = "i文字目まで見た"ときにj個使っているものの通り数
    /*
    配った方が良さそう
    (i) i文字目が0でないとき(x)
    g[i][j+1] = g[i-1][j]
    s[i][j+1] = g[i-1][j] * x-1(1~x-1)
              + g[i-1][j+1] * 1(0)
              + s[i-1][j] * 9 (1~9)
              + s[i-1][j+1] * 1  (0)
    s[i][0] = 1
    g[i][0] = 0
    (ii) i文字目が0
    g[i][j+1] = g[i-1][j+1]
    s[i][j+1] = s[i-1][j] * 9 (1~9)
              + s[i-1][j+1] * 1  (0)
    s[i][0] = 1
    g[i][0] = 0
     */

      int[][] giriGiri = new int[len + 1][k + 1];
      int[][] safeSafe = new int[len + 1][k + 1];

      giriGiri[0][0] = 1;
      for (int i = 1; i <= len; i++) {
        int x = n.charAt(i - 1) - '0';
        for (int j = 0; j < k; j++) {
          if (x == 0) {
            giriGiri[i][j + 1] = giriGiri[i - 1][j + 1];
            safeSafe[i][j + 1] = safeSafe[i - 1][j] * 9 + safeSafe[i - 1][j + 1];
            safeSafe[i][0] = 1;
            giriGiri[i][0] = 0;
          } else {
            giriGiri[i][j + 1] = giriGiri[i - 1][j];
            safeSafe[i][j + 1] = giriGiri[i - 1][j] * (x - 1)
                + giriGiri[i - 1][j + 1]
                + safeSafe[i - 1][j] * 9
                + safeSafe[i - 1][j + 1];
            safeSafe[i][0] = 1;
            giriGiri[i][0] = 0;
          }
        }
      }
    /*
    out.println("Girigiri");
    for (int i = 0; i <= len; i++) {
      for (int j = 0; j <= k; j++) {
        out.print(giriGiri[i][j] + " ");
      }
      out.println();
    }
    out.println("safesafe");
    for (int i = 0; i <= len; i++) {
      for (int j = 0; j <= k; j++) {
        out.print(safeSafe[i][j] + " ");
      }
      out.println();
    }
    
     */

      out.println(giriGiri[len][k] + safeSafe[len][k]);
    }

  }
}



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

int main(void)
{
    using namespace std;
    int n;
    scanf("%d", &n);
    int num[n];

    for (int i = 0; i < n; i++) {
        scanf("%d", &num[i]);
    }

    for (int i = 0; i < n; i++) {
        printf("%d", num[(n - i - 1)]);
        if ( i < n - 1 ) {
            printf(" ");
        }
    }
    printf("\n");
}


Measured memory_bytes: 3208
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val x, n = sc.nextInt()
  val ps = Set.fill(n)(sc.nextInt())
  val ans = (0 to 100).flatMap(i => List(x-i, x+i)).find{!ps.contains(_)}.get
  println(ans)
}


Measured memory_bytes: 55732
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

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

  cout << N / 3 << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    ll n,k;
    cin >> n>> k;
    ll temp=n%k;
    ll ans=min(temp,k-temp);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPR(i,n)for(int i=n;i>=0;i--)
#define FOR(i,m,n)for(int i=m;i<n;i++)
#define INF 999999999
#define llong long long

using namespace std;

int main(){
	int N;
	cin>>N;
	int H[N];
	REP(i,N){cin>>H[i];}

	int num=1;
	int flag;
	for(int i=N-1;0<i;i--){
		flag=0;
		for(int j=i-1;0<=j;j--){
			if(H[i]<H[j]){
				flag=-1;
				break;
			}
		}
		if(flag==0){num++;}

	}
	cout<<num<<endl;
	
	
	return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
map<P,vector<int> > MAP; // 同じ会社で行けるところ
map<P,int> dis; // 駅i会社jまでの距離
set<int> kaisatu[100005]; // 駅iから乗れる会社
// 会社変える->改札入るイメージ、コスト1かかる
// 0-1BFS->deque
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //std::ifstream in("in/05.txt");
  //std::cin.rdbuf(in.rdbuf());
  int N,M;
  cin>>N>>M;
  FOR(i,0,M){
    int p,q,c;
    cin>>p>>q>>c;
    MAP[P(p,c)].push_back(q);
    MAP[P(q,c)].push_back(p);
    kaisatu[p].insert(c); // 駅pから乗れる会社
    kaisatu[q].insert(c); // 駅qから乗れる会社
  }
  deque<P> deq;
  dis[P(1,0)]=0;
  deq.push_front(P(1,0));
  while(deq.size()>0){
    P p=deq.front();
    deq.pop_front();
    int d=dis[p];
    int st=p.first;
    int com=p.second;
    //cout<<st<<" "<<com<<" "<<d<<endl;
    if(st==N){
      cout<<dis[p]<<endl;
      return 0;
    }
    // 改札にいる場合、乗り換え
    if(com==0){
      for(int ch : kaisatu[st]){
        if(dis.count(P(st,ch))==0||dis[P(st,ch)]>d+1){
          dis[P(st,ch)]=d+1;
          deq.push_back(P(st,ch));
        }
      }
    }else{
      // 同じ会社
      for(int to : MAP[p]){
        if(dis.count(P(to,com))==0||dis[P(to,com)]>d){
          dis[P(to,com)]=d;
          deq.push_front(P(to,com));
        }
      }
      // 改札にいく
      if(dis.count(P(st,0))==0||dis[P(st,0)]>d){
        dis[P(st,0)]=d;
        deq.push_front(P(st,0));
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 92672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
const ll mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(void){
    int a,b,c,d;cin>>a>>b>>c>>d;
    vector<vector<mint>> dp(c+100,vector<mint>(d+100,0));
    dp[a][b]=1;
    for(int i=0;i<c;i++){
        for(int j=0;j<d;j++){
            dp[i+1][j+1]+=dp[i+1][j]*(i+1)+dp[i][j+1]*(j+1)-dp[i][j]*i*j;
        }
    }
    cout<<dp[c][d].x<<endl;
}

Measured memory_bytes: 78372
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  struct node *parent;
  struct node *right;
  struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
int Find(int);
void Preorder(Node);
void Inorder(Node);
int main()
{
  int n,i,key;
  char S[7];
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",S);
    if(S[0]=='i'){
      scanf("%d",&key);
      Insert(key);
    }
    else if(S[0]=='f'){
      scanf("%d",&key);
      if(Find(key))printf("yes\n");
      else printf("no\n");
    }
    else{
      Inorder(T);
      printf("\n");
      Preorder(T);
      printf("\n");
 
    }
  }
  return 0;
}
 
void Insert(int key)
{
  Node y,x,z;
  y=NIL;
  x=T;
  z=malloc(sizeof(struct node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;
  while(x!=NULL){
    y=x;
    if( z->key < x->key )x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NULL){
    T=z;
  }
 else if(z->key<y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
}
 
int Find(int key)
{
  Node TT;
  TT=T;
  while(TT!=NULL && TT->key!=key){
    if(key<TT->key)TT=TT->left;
    else TT=TT->right;
  }
  if(TT==NULL)return 0;
  else return 1;
}
void Preorder(Node T)
{
  printf(" %d",T->key);
  if(T->left!=NULL){
    Preorder(T->left);
  }
  if(T->right!=NULL){
    Preorder(T->right);
  }
 
}
 
void Inorder(Node T)
{
  if(T->left!=NULL && T->right!=NULL){
    Inorder(T->left);
    printf(" %d",T->key);
    Inorder(T->right);
 
  }
  if(T->left!=NULL && T->right==NULL){
   Inorder(T->left);
     printf(" %d",T->key);
  }
 
  if(T->right!=NULL && T->left==NULL){
  printf(" %d",T->key);
 Inorder(T->right);
 
  }
  if(T->left==NULL && T->right==NULL)printf(" %d",T->key);
 
}


Measured memory_bytes: 20452
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool yes = false;
  for(int i=0; 4*i<=N; i++){
    for(int j=0; 4*i+7*j<=N; j++){
      if(4*i+7*j == N){
        yes = true;
      }
    }
  }
  if(yes == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){

    int A, B, C, m = 0, n = 0;

    cin >> A >> B >> C;

    if(A == 5)m++;
    if(A == 7)n++;
    if(B == 5)m++;
    if(B == 7)n++;
    if(C == 5)m++;
    if(C == 7)n++;

    if(m == 2 && n == 1)cout << "YES" << endl;
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
num=len(str(n))-1
l=[]
ans=1
mod=10**9+7
for i in range(num):
  ans=(ans*3)%mod
  l.append(ans)
w=str(n)
now=2
for i in range(1,num):
  if w[i]=="0":
    pass
  else:
    ans=(ans+now*l[-i-1])%mod
    now=(now*2)%mod
if w[-1]=="0":
  ans=(ans+now)%mod
else:
  ans=(ans+3*now)%mod
if n==1:
  print(3)
else:
  print(ans)

Measured memory_bytes: 7156
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    void solve(int n, vector<int>& balls) {
        unordered_map<int, int> freq;
        for(const auto& b : balls) ++freq[b];
        int64 ret = 0;
        for(const auto& p : freq) ret += (int64)(p.second - 1) * p.second / 2;
        for(int i = 0; i < n; ++i) {
            cout << ret - freq[balls[i]] + 1 << endl;
        }
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> balls(n);
    for(int i = 0; i < n; ++i) cin >> balls[i];
    Solution sol;
    sol.solve(n, balls);
}

Measured memory_bytes: 8392
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;

    REP(i, 3)
    {
        if(s[i] == '1')cout << '9';
        else if(s[i] == '9') cout << '1';
        else cout << s[i];
    }

    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;
int dp[3005][3005];

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  int N, T;

  cin >> N >> T;
  vector<pair<int, int>> cooking;

  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    cooking.push_back(make_pair(A, B));
  }
  cooking.push_back(make_pair(0, 0));

  sort(cooking.begin(), cooking.end());

  int ans = 0;
  dp[0][0] = 0;

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < T; j++) {
      dp[i][j] = dp[i - 1][j];
      ans = max(ans, cooking[i].second + dp[i - 1][j]);
      if (j - cooking[i].first >= 0) {
        dp[i][j] =
            max(dp[i][j], dp[i - 1][j - cooking[i].first] + cooking[i].second);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int w,a,b;

int main(){
    cin >> w >> a >> b;
    if(a > b) swap(a, b);
    int Out = b - a - w;
    if(Out <= 0) puts("0");
    else cout << Out << endl;
    return 0;
}


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

using namespace std;
const int N = 2e3 + 3, MOD = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
	int n, l;
	scanf("%d %d", &n, &l);
	int sum = 0, miniN = 1e9, miniP = 1e9;
	for (int i = 0; i < n; ++i) {
		int a = l + i;
		sum += a;
		if (a <= 0)
			miniN = min(miniN, -a);
		else
			miniP = min(miniP, a);
	}
	if (miniP > miniN)
		printf("%d\n", sum + miniN);
	else
		printf("%d\n", sum - miniP);
	return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
a = [int(x) for x in input().split()]
b = [i for i in range(0,102) if i not in a] 
b_tmp = list(map(lambda s:abs(s-x), b)) #b_tmpはbとxの差分のリストをさくせい
address = b_tmp.index(min(b_tmp))
print(b[address])

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

int main(){

	int x,y;

	while(1){
		cin >> x >> y;

		if((x == 0)&&(y ==0))break;
		else{
			if(x<=y)cout << x << " " << y << endl;
			else{
				cout << y << " " << x << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
gets
s=$<.map{|s|s.split.map &:to_i}
z=s.select{|x,y,h|h==0}
a=s.select{|x,y,h|h>0}
(0..100).map{|v|
  (0..100).map{|w|
    i=0
    k=0
    a.all?{|x,y,h|
      d=(x-v).abs+(w-y).abs
      i+=1
      if i==1
        k=d+h
        true
      else
        d+h==k
      end
    }&&z.all?{|x,y,h|
      d=(x-v).abs+(w-y).abs
      d>=k
    }&&(
      puts [v,w,k]*" "
      exit
    )
  }
}

Measured memory_bytes: 1916
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */

#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>


#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>



int getTheAnswer() {
    return 42;
}

template< class InputIt>
void incAll(const InputIt &first, const InputIt &last){
  for(auto it = first; it != last; ++it){
    ++*it;
  }
}

template <class InputIt>
void printAll(const InputIt &first, const InputIt &last, std::ostream& out){
  for(InputIt it = first; it != last; ++it){
    out << *it << " ";
  }
}

// only for positive integers
int gcd(int a, int b){
  int tmp;
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  while(b != 0){
    tmp = a;
    a = b;
    b = tmp % b;
  }
  return a;
}

int lcm(int a, int b){
  return abs(a*b) / gcd(a, b);
}


using namespace std;

class TaskD {
public:
  void solve(std::istream &in, std::ostream &out) {
    ios::sync_with_stdio(false);
    int n, tmp;
    in >> n;
    map<int, int> a;
    auto it = a.begin();
    for (int i = 0; i < n; ++i) {
      in >> tmp;
      it = a.find(tmp);
      if (it == a.end()) {
        // tmp has not been seen before
        a.insert({tmp, 1});
      } else {
        // tmp is a dup
        it->second++;
      }
    }
    int res = 0;
    // count number of even counts:
    for (auto it = a.begin(); it != a.end(); ++it) {
      res += (it->second + 1) % 2;
    }
    // if number of even numbers is even,  erverything will work out
    // otherwise 1 number must be deleted
    if(res % 2){
      res = a.size() - 1;
    }else{
      res = a.size();
    }

//    // elimate dups for free as long as possible
//    map<int, int> :: iterator l = a.begin();
//    map<int, int> :: reverse_iterator r = a.rbegin();
//    while (*l != *r) {
//      if (l->second == 1) {
//        ++l;
//      } else if (r->second == 1) {
//        ++r;
//      } else {
//        auto i = l;
//        if(*++i < *r){
//          // theres sth in the middle, so its safe to delete
//          while (r->second > 1 && l->second > 1) {
//            --l->second;
//            --r->second;
//          }
//        }else{
//          // theres nothing in between any more, so loop must be stopped
//          break;
//        }
//      }
//    }
//    // all remaining duplicates must be deleted costly
//    int res = a.size();
//
//    for(it = a.begin(); it != a.end(); ++it){
//      if(it->second > 1){
//        it->second =
//      }
//    }

//    for(auto &el : a){
//      out << "(" << el.first << ", " << el.second << ") " ;
//    }
    out << res << endl;
  }
};


int main() {
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 // freopen("in.txt","r",stdin);
  int n,m;cin>>n>>m;int a,b;cin>>a>>b;
  char ch='0';
  for(int i=0;i<n;i++){
    if(i>=b)ch=(char)'1';
    for(int j=0;j<m;j++)
      if(j<a)cout<<ch;
      else cout<<(char)('1'+'0'-ch);
    cout<<"\n";
  }
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,d,n,m;
    while(~scanf("%d",&a))
    {
        scanf("%d",&b);
        scanf("%d",&c);
        scanf("%d",&d);
        if(a<=b)
        {
            printf("%d\n",a*c);
        }
        else
        {
            printf("%d\n",b*c+(a-b)*d);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
const int maxm=1e5+4;
int arr[maxm];
int dp[maxm];
int n,k;
int cal(int i)
{   
	if(i==0)return 0;
	if(dp[i]!=-1)return dp[i];
	if(i==1)return abs(arr[1]-arr[0]);
	int mn=INT_MAX;
	for(int j=1;j<=k and i-j>=0;j++)mn=min(mn,abs(arr[i]-arr[i-j])+cal(i-j));
	//cout<<i<<" "<<mn<<"\n";
	return dp[i]=mn;
	
}
int main()
{
   memset(dp,-1,sizeof(dp));
  cin>>n>>k;
  fr(i,n)cin>>arr[i];
  cout<<cal(n-1);
}

Measured memory_bytes: 7296
def f (x,y,h,w)
  l = x + y + h
  return 600 if l<=60 and w<=2
  return 800 if l<=80 and w<=5
  return 1000 if l<=100 and w<=10
  return 1200 if l<=120 and w<=15
  return 1400 if l<=140 and w<=20
  return 1600 if l<=160 and w<=25
  return 0
end

loop{
  n = gets.to_i
  break if n==0
  puts n.times.map{f(*gets.split.map(&:to_i))}.reduce(:+)
}


Measured memory_bytes: 9248
def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    dx = [-1, 0, 1, -1, 1, -1, 0, 1]
    dy = [-1, -1, -1, 0, 0, 1, 1, 1]

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                continue

            cnt = 0
            for k in range(8):
                x = j + dx[k]
                y = i + dy[k]
                if x >= 0 and x < W and y >= 0 and y < H:
                    if S[y][x] == "#":
                        cnt += 1

            S[i][j] = str(cnt)

    for i in range(H):
        print("".join(S[i]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	
	ll n,k;
	cin >> n >> k;
	ll cnt=0;
	while(n){
		n/=k;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stack>
using namespace std;
using ll = long long;

struct dat{
    char op;
    ll val;
    dat(ll op_,ll val_){
        op=op_;
        val=val_;
    }
};

void push_op(stack<dat>&st,char op){
    if (op=='+') st.push(dat('+',0));
    if (op=='*') st.push(dat('*',1));
}

void cal_st(stack<dat>& st,ll val){
    dat d=st.top();
    st.pop();
    if (d.op=='+') d.val+=val;
    if (d.op=='*') d.val*=val;
    st.push(d);
}

void del_st(stack<dat>& st){
    dat d=st.top();
    st.pop();
    cal_st(st,d.val);
}

int main(){
    bool noend=true;
    while (noend){
        ll n;
        cin >> n;
        if (n==0){
            noend=false;
            continue;
        }
        stack<dat> st;
        string s;
        ll g_lev=0;
        push_op(st,'+');
        for (ll i=0;i<n;i++){
            cin >> s;
            ll lev = 0;
            ll val = 0;
            for (ll i=0;i<s.size();i++){
                val*=10;
                if (s[i]=='.') lev++;
                else if(s[i]>='0'&& s[i]<='9') val+=s[i]-'0';
            }
            while (g_lev>lev){
                g_lev--;
                del_st(st);
            }
            if(s[lev]=='+'){
                g_lev++;
                push_op(st,'+');
            }
            else if(s[lev]=='*'){
                g_lev++;
                push_op(st,'*');
            }
            else {
                cal_st(st,val);
            }
        }
        while (g_lev>0){
            g_lev--;
            del_st(st);
        }
        cout << st.top().val << endl;
    }
}


Measured memory_bytes: 3128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
string str;

int main() {
  while (cin >> N >> str) {
	stack<char> st;
	for (int i = 0; i < str.size(); ++i) {
	  if (st.empty()) st.push(str[i]);
	  else {
		if (st.top() == '(' && str[i] == ')') st.pop();
		else st.push(str[i]);
	  }
	}
	while (!st.empty()) {
	  char c = st.top();
	  st.pop();
	  if (c == '(') str += ')';
	  else str = "(" + str;
	}
	cout << str << endl;
  }
}














Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    int x = s.find('A');
    int y = s.rfind('Z');
    cout << y - x + 1 << endl;
    
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int n;
int x;
ll dp[202][100010];
const ll mod=1e9+7;
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
	//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
	gbtb;
	cin>>n>>x;
	repd(i,1,n)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n,[&](int x,int y){return x>y;});
	dp[0][x]=1;
	repd(i,1,n)
	{
		repd(j,0,x)
		{
			dp[i][j%a[i]]+=dp[i-1][j];
			dp[i][j%a[i]]=(dp[i][j%a[i]]+mod)%mod;
			dp[i][j]+=dp[i-1][j]*(n-i)%mod;
			dp[i][j]=(dp[i][j]+mod)%mod;
		}
	}
	ll ans=0ll;
	repd(i,0,x)
	{
		ans+=(dp[n][i]*i)%mod;
		ans=(ans+mod)%mod;
	}
	cout<<ans<<endl;



    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 159232
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000000000
using ll=long long;
using P=pair<ll,int>;

int N;
#define index(a,b) ((a)*50*N+(b))
struct node{
    vector<int> to;
    vector<int> cost;
    ll min_cost;
    vector<int> path;
    node(){
        min_cost=INF;
    }
};
void dijkstra(int start_index,vector<node> &nodes){
    priority_queue<P,vector<P>,greater<P>> q;
    nodes[start_index].min_cost=0;
    q.push(P(0,start_index));
    while (q.size()!=0)
    {
        P p=q.top();
        q.pop();
        int v=p.second;
        if(nodes[v].min_cost<p.first)continue;
        for (int i = 0; i < nodes[v].to.size(); i++){
            int to=nodes[v].to[i];
            ll tmp_cost=nodes[v].min_cost+nodes[v].cost[i];
            if(nodes[to].min_cost>tmp_cost){
                nodes[to].min_cost=tmp_cost;
                q.push(P(nodes[to].min_cost,to));
            }
        }
    }

}

int main() {
    int M,S;
    cin>>N>>M>>S;
    S=min(S,50*N-1);
    vector<node> nodes(N*50*N);
    for (int i = 0; i < M; i++){
        int U,V,A,B;
        cin>>U>>V>>A>>B;
        for (int j = 50*N-1; j-A >=0; j--){
            nodes[index(U-1,j)].to.push_back(index(V-1,j-A));
            nodes[index(V-1,j)].to.push_back(index(U-1,j-A));
            nodes[index(U-1,j)].cost.push_back(B);
            nodes[index(V-1,j)].cost.push_back(B);
        }
    }
    for (int i = 0; i < N; i++){
        int C,D;
        cin>>C>>D;
        for (int j = 0; j<50*N; j++){
            nodes[index(i,j)].to.push_back(index(i,min(j+C,50*N-1)));
            nodes[index(i,j)].cost.push_back(D);
        }
    }

    dijkstra(S,nodes);
    for (int i = 1; i < N; i++){
        ll ans=INF;
        for (int j = 0; j < 50*N; j++){
            ans=min(ans,nodes[index(i,j)].min_cost);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 26396
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
const int INF = 1001001001;
vector<int> to[100005]; //to[x]それぞれが配列

int main(){
  int n,m; cin >> n >> m;
  rep(i,m){
    int a,b; cin >> a >> b;
    a--; b--; //indexに統一
    to[a].push_back(b); to[b].push_back(a); //to[a]はaにつながる頂点のベクトル
  }
  
  queue<int> q;
  vector<int> dist(n,INF); dist[0]=0; //nodeのrootからの距離
  vector<int> pre(n,-1); //直前のnode
  q.push(0); //root node=0と繋がっているnodeからsearch
  while(!q.empty()){
    int v=q.front(); q.pop();
    for(int u: to[v]){ //vと繋がっているnode=u
      if (dist[u] != INF)continue; //uが既にある=最短を求め済みなので飛ばす
      //else
      dist[u] = dist[v]+1; //直前のnodeの階層+1
      pre[u] = v; //
      q.push(u); //次はuに繋がっているnodeを探す
    }
  }
  
  cout << "Yes" << endl;
  rep(i,n){
    if(i==0) continue;
    int ans = pre[i]; //道しるべをoutputしている
    ans++; //index表記してたのでもとに戻す
    cout << ans << endl;
  }
}

Measured memory_bytes: 10604
import time
import random
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


# 各日に一番満足度の増加が大きいコンテストを開催する
T = [S[i].index(max(S[i])) for i in range(d)]
score = calc_score(T)
start = time.time()
while True:
    now = time.time()
    if now - start > 1.5:
        break
    p = random.choice(range(d))
    q = random.choice(range(26))
    memo = T[p]
    T[p] = q
    new_score = calc_score(T)
    temp = 20000 * (1 - (now - start) / 2)
    prob = 2**((new_score - score) / temp)
    if random.random() < prob:
        score = new_score
    else:
        T[p] = memo

for t in T:
    print(t + 1)


Measured memory_bytes: 82576
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//Integer[] array = new Integer[m];
		int n = sc.nextInt();
		int count=0;
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			count=count+a;
			list.add(a);
		}

		int max = Collections.max(list);
		count=count-max/2;
		System.out.println(count);
	}
}

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

long long N, S = 1, cnt;

int main() {
	cin >> N;
	for (long long i = 2; i * i <= N; i++) {
		long long cx = N;
		while (cx >= i) {
			if (cx % i == 0) cx /= i;
			else cx %= i;
		}
		if (cx == 1) cnt++;
		S = i;
	}

	vector<long long> V;
	for (long long i = 1; i * i <= N - 1; i++) {
		if ((N - 1) % i != 0) continue;
		V.push_back(i);
		V.push_back((N - 1) / i);
	}
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());

	for (int i = 0; i < V.size(); i++) {
		if (V[i] > S) cnt++;
	}
	cnt++;

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3612
import sys
input = sys.stdin.readline

d = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(d)]
# T = [int(input()) for i in range(d)]
c = 26
# m = int(input())
# Q = [list(map(int,input().split())) for i in range(m)]

ans = 0
L = [[-1] * c for i in range(d)]
T = [-1] * d  # この中には0-25を入れる
K = [[] for i in range(d)]  # この中は0-indexed
pp = 10

for i in range(d):
    ANS = [0] * c
    L[i] = L[i-1][:]
    for k in range(c):
        ANS[k] = S[i][k] + C[k] * (i - L[i][k])
    ANSS = [[ANS[j], j] for j in range(c)]
    ANSS.sort(reverse=True)
    for j in range(pp):
        if j > 0 and ANSS[j][0] < 0:
            break
        K[i].append(ANSS[j][1])
    ind = ANSS[0][1]
    ans += S[i][ind]
    L[i][ind] = i
    for j in range(c):
        ans -= C[j] * (i - L[i][j])
    # print(ans)
    # print(ind + 1)
    T[i] = ind

fans = ans
# print("fans",fans)
# print(L)
# print(T)



# cp = 3
# dp = 3

# CC = [[C[i], i] for i in range(c)]
# CC.sort(reverse=True)
# for i in range(d):
#     for k in range(cp):
#         K[i].append(CC[k][1])

# for i in range(d):
#     DD = [[S[i][j], j] for j in range(c)]
#     DD.sort(reverse=True)
#     for k in range(dp):
#         K[i].append(DD[k][1])

# print("K",K)
    
from random import randint

m = 10*10**5

Q = [[0] * 2 for i in range(m)]
for i in range(m):
    dd = randint(0, d-1)
    # print("dd",dd)
    # print(dd-1,randint(0, len(K[dd-1])-1))
    q = K[dd][randint(0, len(K[dd])-1)]
    Q[i][0] = dd
    Q[i][1] = q

# print(Q)

for i in range(m):
    # print(*T)
    # print(Q)
    dd = Q[i][0]
    q = Q[i][1]
    nans = ans
    # print("dd",dd)
    nans -= S[dd][T[dd]]
    nans += S[dd][q]
    for j in range(dd, d):
        # print("j",j)
        if T[j] == q:
            # print("break")
            break
        nans += C[q] * (j - L[j][q])
        nans -= C[q] * (j - dd)
        L[j][q] = dd
    
    old = T[dd]
    T[dd] = q

    for j in range(dd, d):
        # print("j",j)
        if T[j] == old:
            # print("break")
            break
        oldl = L[j-1][old] if j > 0 else -1
        nans += C[old] * (j - dd)
        nans -= C[old] * (j - oldl)
        L[j][old] = oldl

    # print(nans, ans)

    if nans < ans:
        if i != m-1:
            Q[i+1] = [dd, old]
        else:
            T[dd] = old
    
    ans = nans

# print(max(ans,fans))
for i in T:
    print(i+1)


Measured memory_bytes: 219984
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
ll N, K, ans;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N >> K;
	N = N%K; ans = N;
	if(N<=K)ans = min(ans, abs(N-K)%K);
	cout << ans << nl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    N = int(sys.stdin.readline())
    #s = sys.stdin.readline().rstrip()
    #N, K = map(int, sys.stdin.readline().split())
    #P = list(map(int, sys.stdin.readline().split()))
    #P.sort()
    #print(N)
    al = 'zabcdefghijklmnopqrstuvwxy'
    ans =''
    while True:
        if N==0:
            break
        ans +=al[(N %26)]
        if N%26==0:
            N = N//26 -1
        else:
            N = N//26
        
    print(ans[::-1])



if __name__=='__main__':
    main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;

LL tr[N << 1];
int a[N], n, s[N], tmp[N];
void update(int i, LL x) { for (; i <= n + N; i += i & -i) tr[i] += x; }
LL query(int i, LL ret = 0) { for (; i; i -= i & -i) ret += tr[i]; return ret; }

LL check(int num)
{
    LL ans = 0;
    memset(tr,0,sizeof tr);
    update(s[0]+N,1);
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < num) s[i] = s[i - 1] - 1;
        if (a[i] >= num) s[i] = s[i - 1] + 1;
        ans += query(s[i] + N);
        update(s[i] + N, 1);
    }
    return ans;
}

int main()
{
    LL ans;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    memcpy(tmp, a, sizeof a);
    sort(tmp + 1, tmp + n + 1);
    int cnt = unique(tmp + 1, tmp + n + 1) - tmp - 1;
    LL k = ((LL)n * (n + 1 ) / 2)/2;
    for (int l = 1, r = cnt, mid = l + r >> 1; l <= r; mid = l + r >> 1)
    {
        if (check(tmp[mid]) >= k) ans = tmp[mid], l = mid + 1;
        else r = mid - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

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

    int r_sum = 0;
    for (int i = 0; i < N; ++i){
        if (S[i] == 'R') r_sum++;
    }
    int res = 0;
    for (int i = 0; i < r_sum; ++i){
        if (S[i] != 'R') res++;
    }

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

Measured memory_bytes: 3748
r = input()
a = int(r[0])
b = int(r[1])
c = int(r[2])
d = int(r[3])
import sys

if a+b+c+d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"+"+r[2]+"+"+r[3]+"=7")
elif a+b+c-d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"+"+r[2]+"-"+r[3]+"=7")
elif a+b-c+d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"-"+r[2]+"+"+r[3]+"=7")
elif a+b-c-d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"-"+r[2]+"-"+r[3]+"=7")
elif a-b+c+d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"+"+r[2]+"+"+r[3]+"=7")
elif a-b+c-d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"+"+r[2]+"-"+r[3]+"=7")
elif a-b-c+d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"-"+r[2]+"+"+r[3]+"=7")
else:
  sys.stdout.write(r[0]+"-"+r[1]+"-"+r[2]+"-"+r[3]+"=7")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int K; cin>>K;
  int N=S.size();
  rep(i,0,N-1){
    int P='z'-S[i];
    P++;
    P%=26;
    if(K>=P){
      K-=P;
      S[i]='a';
    }
  }
  int P=S[N-1]-'a';
  P+=K;
  P%=26;
  S[N-1]='a'+P;
  cout<<S<<endl;
  }



Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  cout<<(n==m?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
      	int count  = Integer.valueOf(sc.nextLine());
      	String input = sc.nextLine();
      	String inputs[] = input.split(" ");
      	int poss[] = new int[100002];
      	for( int i= 0 ; i<count; i++) 
        {
          	int value = Integer.valueOf(inputs[i]);
          	value++;
            poss[value]+=1;
          	poss[value-1]+=1;
          	poss[value+1]+=1;
        }
      	 int max  =Integer.MIN_VALUE;
      	for( int i = 0 ; i<100002 ; i++) 
        {
          //System.out.println("i: "+poss[i]);
         	if(poss[i]>=max)
            {
              	max = poss[i];
            }
        }
      	System.out.println("\n"+max);
      
    }
}

Measured memory_bytes: 48992
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int n;
	double d = 100000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		d *=  1.05 / 1000;
		if (d - floor(d) > 0.00001) {
			d = ceil(d) * 1000;
		}else d *= 1000;
	}
	cout << (int)d <<endl;
		
	return 0;
}

Measured memory_bytes: 1164