akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll li
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000000000000
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll> 
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 200050
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
 
 
// #define INTMAX 200000000 
 
// using namespace boost;
// #define si short int
 
using namespace std;
using namespace __gnu_pbds;             
typedef priority_queue<pii, vector<pii> ,greater < pii > > min_pq;
// typedef priority_queue<pii, vector<pii> , greater<pii >  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}
 
// using namespace __gnu_pbds;         
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define nn 2000005
ll x[ N ],y[ N ],h[ N ];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    for ( ll i = 1; i <= sqrt(m); i ++)
    {
        if ( m%i == 0 )
        {
            if ( (i*n)<= m and ((m-i*n)%i)== 0 )
                ans = max(ans,i);
            ll p = (m/i);
            if ( (p*n)<= m and ((m-p*n)%p)== 0 )
                ans = max(ans,p);
        }
    }
    cout << ans;


}

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

class Program
{
	static void Main(string[] args)
	{
        var N = int.Parse(Console.ReadLine());
		string[] blocks = Console.ReadLine().Split(' ');
        int next = 1;
        for (int i = 0; i < N; i++) {
            if (int.Parse(blocks[i]) == next) {
                next++;
            }
        }

        if (next == 1) {
            Console.WriteLine(-1); 
        }
        else {
            Console.WriteLine(N - next + 1); 
        }
	}
}

Measured memory_bytes: 30300
#include <iostream>
using namespace std;
int main()
{
  int a=700;
  string s;
  cin>>s;
  if (s[0]=='o'){
    a=a+100;
  }
  if (s[1]=='o'){
    a=a+100;
  }
  if (s[2]=='o'){
    a=a+100;
  }
  cout<<a;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int n, k;
  cin >> n >> k;

  vector<long> a(n);
  int plus = 0;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(a[i] > 0) {
      plus++;
    }
  }
  sort(a.begin(), a.end(), greater<int>());

  long ans = 1;
  if(plus == 0 && k % 2 == 1) {
    for(int i=0; i<k; i++) {
      ans *= a[i];
      ans %= 1000000007;
    }
    if(ans < 0) {
      ans += 1000000007;
    }
    cout << ans << endl;
  }
  else {
    int l = 0;
    int r = n - 1;
    for(int i=0; i<k/2; i++) {
      if(a[l] * a[l + 1] > a[r] * a[r - 1]) {
        ans *= ((a[l] * a[l + 1]) % 1000000007);
        ans %= 1000000007;
        l += 2;
      }
      else {
        ans *= ((a[r] * a[r - 1]) % 1000000007);
        ans %= 1000000007;
        r -= 2;
      }
    }
    if(k % 2 == 1) {
      ans *= max(a[l], a[r]);
      ans %= 1000000007;
    }
    if(ans < 0) {
      ans += 1000000007;
    }
    cout << ans << endl;
  }
}

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

int main(void){
  const int max = 30;
  vector<bool> ans(max,true);
  for(int i = 0 ; i < max - 2 ; i++){
    int in;
    cin>>in;
    ans[--in]=false;
  }
  for(int i = 0 ; i< max ; i++){
    if(ans[i])cout<<i+1<<endl;
  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>

using namespace std;



struct Point{
    int t1,t2;
    Point(int t1,int t2){
        this->t1=t1;
        this->t2=t2;
    }
};
vector<vector<int>> v;
vector<Point> points;
int n;
int ans=0;

void debug(){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
}

bool will_playoff(int t1){
    int win=0,lose=0,not_match=0;
    for(int i=0;i<n;i++){
        if(t1==i)continue;
        if(v[t1][i]==1)win++;
        else if(v[t1][i]==0)lose++;
        else not_match++;
    }
    if(abs(win-lose)>not_match)return false;
    else return true;
}

bool is_playoff(){
    for(int i=0;i<n;i++){
        int win=0,lose=0;
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(v[i][j]==1)win++;
            else if(v[i][j]==0)lose++;
        }
        if(win!=lose)return false;
    }
    return true;
}

void dfs(int idx){
    //debug(v);
    if(idx==points.size()){
        if(is_playoff())ans++;
        //ans++;
        return;
    }
    Point point=points[idx];
    v[point.t1][point.t2]=1;
    v[point.t2][point.t1]=0;
    if(will_playoff(point.t1))dfs(idx+1);

    v[point.t1][point.t2]=0;
    v[point.t2][point.t1]=1;
    if(will_playoff(point.t1))dfs(idx+1);

    v[point.t1][point.t2]=v[point.t2][point.t1]=-1;
    return;
}

int main(){
    while(cin>>n){
        if(n==0)break;
        v.clear();
        v.resize(10,vector<int>(10,-1));
        points.clear();
        ans=0;
        int m;cin>>m;
        for(int i=0;i<m;i++){
            int win,lose;
            cin>>win>>lose;
            win--; lose--;
            v[win][lose]=1;
            v[lose][win]=0;
        }
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(v[i][j]==-1 and i!=j)points.push_back(Point{i,j});
            }
        }
        dfs(0);
        cout<<ans<<endl;

    }


}


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

int		cnt;
bool	flag;
char	ans[100'001];
string	s[100'001];

void apply(int *a, int *b, string s, int index)
{
	(*a)++; (*b)--;
	ans[cnt++] = s[index];
}

bool solve(int *X, int *Y, string s)
{
	if (!(*X) && !(*Y)) return (false);
	if ((*X) > (*Y)) apply(Y, X, s, 1);
	else apply(X, Y, s, 0);
	return (true);
}

int	main(void)
{
	int n, A, B, C;
	cin >> n >> A >> B >> C;
	for (int i = 0; i < n; i++) cin >> s[i];
	s[n] = "AA";
	for (int i = 0; i < n; i++)
	{
		if (s[i] == "AB") flag = (s[i + 1] == "BC") ? solve(&B, &A, "BA") : solve(&A, &B, "AB");
		if (s[i] == "BC") flag = (s[i + 1] == "AC") ? solve(&C, &B, "CB") : solve(&B, &C, "BC");
		if (s[i] == "AC") flag = (s[i + 1] == "AB") ? solve(&A, &C, "AC") : solve(&C, &A, "CA");
		if (flag == false)
		{
			cout << "No" << endl;
			return (0);
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < n; i++) cout << ans[i] << endl;
	return (0);
}

Measured memory_bytes: 6808
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main() {
    int k;
    cin >> k;
    deque<LL> deq;
    for(int i = 1;i<=9;i++) {
        deq.push_back(i);
    }
    int cnt = 9;
    if(k <= 9) {
        cout << k << endl;
        return 0;
    }

    while(true) {
       LL tmp = deq.front();
       deq.pop_front();
       if(tmp > 9) {
            cnt++;
       }
       if(cnt == k) {
           cout << tmp << endl;
           return 0;
       }
       LL first =  tmp % 10;
       if(first == 0) {
            tmp *= 10;
            LL tmp1 = tmp + 1;
            deq.push_back(tmp);
            deq.push_back(tmp1);
       } else if(first == 9) {
           tmp *= 10;
           LL tmp1 = tmp + 8;
           LL tmp2 = tmp + 9;
           deq.push_back(tmp1);
           deq.push_back(tmp2);
       } else {
           tmp *= 10;
           LL tmp1 = tmp + first - 1;
           LL tmp2 = tmp + first;
           LL tmp3 = tmp + first + 1;
           deq.push_back(tmp1);
            deq.push_back(tmp2);
           deq.push_back(tmp3);
       }
    }
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

long long GCD(ll a, ll b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

vector<ll> prime(ll N) {
    vector<ll> res;
    for (ll a = 2; a * a <= N; a++) {
        if (N % a != 0)
            continue;
        while (N % a == 0) {
            N /= a;
        }
        res.push_back(a);
    }

    if (N != 1)
        res.push_back(N);
    res.push_back(1);
    return res;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll gcd = GCD(a, b);
    ll res = prime(gcd).size();
    cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0
for i in range(1,n-1):
    s1 = s[:i]
    s2 = s[i:]
    cnt =0 
    for x in 'abcdefghijklmnopqrstuvwxyz':
        if x in s1 and x in s2:
            cnt += 1
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<cmath>
#define bye return 0
#define speedOne ios::sync_with_stdio(false)
#define speedtwo cin.tie(0)
typedef long long int lli;
typedef long long ll;
using namespace std;
int main()
{
    speedOne;
    speedtwo;
	int a, b;
	cin >> a >>b;
	cout<<(b+a-3)/(a-1)<<"\n";
	bye;
}

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

fn main() {
    let inputs = read_vec::<i32>();
    let area = inputs[0] * inputs[1];
    let perimeter = inputs.iter().sum::<i32>() * 2;
    println!("{} {}", area, perimeter);
}


Measured memory_bytes: 5032
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

int main()
{
    //freopen("in", "r", stdin);
    int n;
    scanf("%d", &n);
    printf("%d\n", max(n/3, n/4));
    return 0;
}

Measured memory_bytes: 256
# include<iostream>
using namespace std;
int main ()
{
	  int M,D;
	  cin>>M>>D;
	  int sum=0;
	  for(int i=4;i<=M;i++)
	  {
	  	 for(int j=22;j<=D;j++)
	  	 {
	  	 	  if(i==(j/10)*(j%10)&&(j/10)>=2&&(j%10)>=2)
	  	 	  {
	  	 	  	 sum++;
				 }
		   }
	  }
	  cout<<sum<<endl;
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
ma = [["#" for _ in range(w+2)] for _ in range(h+2)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        ma[i+1][j+1] = tmp[j]
ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if ma[i][j] == "#":
            continue
        elif ma[i][j] == ".":
            p = [[-1 for _ in range(w+2)] for _ in range(h+2)]
            p[i][j] = 0
            q = deque()
            q.append([i, j])
            while q:
                y, x = q.popleft()
                if ma[y+1][x] == "." and p[y+1][x] == -1:
                    p[y+1][x] = p[y][x] + 1
                    q.append([y+1, x])
                if ma[y-1][x] == "." and p[y-1][x] == -1:
                    p[y-1][x] = p[y][x] + 1
                    q.append([y-1, x])
                if ma[y][x+1] == "." and p[y][x+1] == -1:
                    p[y][x+1] = p[y][x] + 1
                    q.append([y, x+1])
                if ma[y][x-1] == "." and p[y][x-1] == -1:
                    p[y][x-1] = p[y][x] + 1
                    q.append([y, x-1])
            for l in range(h+2):
                ans = max(ans, max(p[l]))
            # ans = max(ans, max(max(p)))
print(ans)

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

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

int main(){
	int a,b;
	cin>>a>>b;
	int c=1;
	
	for(int i=0;i<a;i++){
	
		c*=100;
	
	
	}
	if(a==0&&b<100){cout<<b;}
	else if(a==0&&b==100){cout<<101;}
	else if(b==100){cout<<c*b+c;}
	else cout<<c*b;
	
	
//	cout<<max(6,12387);
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new int[n];
  int s;
  long res = long.max;
  int best = -1;
  long check (int p) {
    long r;
    foreach (i; a) {
      r += (i - p) * (i - p);
    }
    if (res > r) {
      res = r;
      best = p;
    }
    debug stderr.writefln ("check(%d) = %d", p, r);
    return r;
  }
  int u = int.max;
  int v = int.min;
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
    s += a[t];
    u = min (u, a[t]);
    v = max (v, a[t]);
  }
  s /= n;
  foreach (step; u .. v+1) {
    check (step);
  }
  writeln (res);
}



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

int main()
{
    int h, w;
    int i, j;
    
    cin >> h >> w;
    
    char a[h][w];
    
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    
    for(i = 0; i < w+2; i++) {
        cout << "#";
    }
    cout << "\n";
    
    for(i = 0; i < h; i++) {
        cout << "#";
        for(j = 0; j < w; j++) {
            cout << a[i][j];
        }
        cout << "#\n";
    }
    
    for(i = 0; i < w+2; i++) {
        cout << "#";
    }
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main(){
	string a, b;
	int x, y;
	cin >> a >> b;
	x = a[0] - '0';
	y = b[0] - '0'; 
	string newA = "", newB = "";
	for(int i = 1; i <= y; i++){
		newB += a;
	}
	for(int i = 1; i <= x; i++){
		newA += b;
	}
	cout << min(newA, newB) << '\n';
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


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;
}

ll dp[51][51][3010];

int main() {
	
	int n, a;
	cin >> n >> a;
	vector<int> x(n);

	rep(i, n) {
		cin >> x[i];
	}

	dp[0][0][0] = 1;
	rep(i, n) {
		rep(j, n) {
			rep(k, 2500) {
				if (dp[i][j][k]) {
					dp[i + 1][j][k] += dp[i][j][k];
					dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				}
			}
		}
	}

	ll ans = 0;
	REP(i, 1, n + 1) ans += dp[n][i][i*a];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 58240
fun main (args:Array<String>) {
    val (numA, numB) = readLine()!!.split(" ").map(String::toInt)
    var culc = numA + numB
    if(culc < numA - numB){
        culc = numA - numB
        if(culc < numA * numB){
            culc = numA * numB
        }
    }
    if(culc < numA * numB) culc = numA * numB
    print(culc)
}

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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int res=0;
  rep(i,n){
    if(a[i]%2!=0) res++;
  }
  if(res%2==0) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#define N 100000

int oo[1 + (N - 1) * 2], oj[1 + (N - 1) * 2], ow[1 + (N - 1) * 2];

int link(int o, int j, int w) {
	static int _ = 1;

	oo[_] = o, oj[_] = j, ow[_] = w;
	return _++;
}

int ae[N], cc[N];

void dfs(int p, int i, int c) {
	int o;

	cc[i] = c;
	for (o = ae[i]; o; o = oo[o]) {
		int j = oj[o], w = ow[o];

		if (j != p)
			if (w % 2 == 0)
				dfs(i, j, c);
			else
				dfs(i, j, 1 - c);
	}
}

int main() {
	int n, h, i, j, w;

	scanf("%d", &n);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d%d", &i, &j, &w), i--, j--;
		ae[i] = link(ae[i], j, w);
		ae[j] = link(ae[j], i, w);
	}
	dfs(-1, 0, 0);
	for (i = 0; i < n; i++)
		printf("%d\n", cc[i]);
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    int d,r;
    double f;
    cin>>a>>b;
    d= a/b;
    r= a%b;
    f= (double)a/b;
   
    printf("%d %d %f\n",d,r,f);
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
    int N,P;
    cin>>N>>P;
    int no=0;
    int ne=0;
    for(int i=0;i<N;i++) {
        int x;
        cin>>x;
        if (x&1)
            no++;
        else
            ne++;
    }
    
    ll ans;
    if (P%2==0) {
        ans = (1ll<<ne)*(no==0 ? 1 : (1ll<<(no-1)));
    } else {
        ans = (1ll<<ne)*(no==0 ? 0 : (1ll<<(no-1)));
    }
    
    cout << ans << endl;
    
    // 2^ne*(B(no,0)+B(no,2)+...
    
}

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

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

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

    int a = 0, b = 0;
    sort(A.rbegin(), A.rend());
    for(int i = 0; i < n; i++){
        if(i % 2 == 0) a += A[i];
        else b += A[i];
    }

    cout << a - b << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
	public static long n, k, x, y, s1, s2 = 0;
	public static void main(String[] args) throws FileNotFoundException {
//		Scanner in = new Scanner(new File("input.txt"));
		Scanner in = new Scanner(System.in);
		n = in.nextLong();
		k = in.nextLong();
		x = in.nextLong();
		y = in.nextLong();
		if(n > k) System.out.println(x*k + (n-k)*y);
		else System.out.println(x*n);
	}
}

Measured memory_bytes: 10064
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
		static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		
		Console.WriteLine("{0}",n*n*3);
	}
}


public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        
        static void Solve()
        {
            int a = ReadAndParseInt();
            int b = ReadAndParseInt();
            int h = ReadAndParseInt();

            int ans = (a + b) * h / 2;
            Console.WriteLine(ans);
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int h,w,k,memo[800][800],ans=INF;
queue<pair<int,int>> que;
bool visited[800][800];
pair<int,int> st;
string a[800];

bool is_unsafe(int y, int x) {
    return x < 0 || y < 0 || x >= w || y >= h;
}

signed main() {
    cin >> h >> w >> k;
    rep(i,h) cin >> a[i];
    rep(i,h) rep(j,w) memo[i][j] = (min(min(i,j), min(h-i-1, w-j-1))+k-1)/k;
    rep11(i,h-1) rep11(j,w-1) memo[i][j] = max(memo[i][j], 1LL);
    rep(i,h) rep(j,w) if (a[i][j] == 'S') que.push({i,j});
    rep(hoge,k+1) {
        int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
        queue<pair<int,int>> tmpque;
        while(!que.empty()) {
            int y = que.front().fi, x = que.front().se;
            que.pop();
            if (visited[y][x]) continue;
            visited[y][x] = true;
            ans = min(ans, memo[y][x]);
            rep(i,4) {
                int Y = y+dy[i], X = x+dx[i];
                if (is_unsafe(Y,X)) continue;
                if (a[Y][X] == '#') continue;
                tmpque.push({Y,X});
            }
        }
        que = tmpque;
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, K;
  cin >> N >> K;
  if (K==1) cout << 0 << endl;
  else cout << N-K << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A, B, Q = LI()
    s = []
    t = []
    x = []
    for _ in range(A):
        s.append(I())
    for _ in range(B):
        t.append(I())
    for _ in range(Q):
        x.append(I())
    for pos in x:
        l_s = bisect.bisect_left(s, pos)
        l_t = bisect.bisect_left(t, pos)

        if l_s == 0:
            left_shrine = None
        else:
            left_shrine = s[l_s-1]
        if l_s == A:
            right_shrine = None
        else:
            right_shrine = s[l_s]

        if l_t == 0:
            left_temple = None
        else:
            left_temple = t[l_t-1]
        if l_t == B:
            right_temple = None
        else:
            right_temple = t[l_t]

        d1, d2, d3, d4, d5, d6 = inf, inf, inf, inf, inf, inf
        if left_shrine and left_temple:
            d1 = pos - min(left_shrine, left_temple)
        if right_shrine and right_temple:
            d2 = max(right_shrine, right_temple) - pos
        if left_shrine and right_temple:
            d3 = 2 * (pos - left_shrine) + (right_temple - pos)
            d4 = 2 * (right_temple - pos) + (pos - left_shrine)
        if left_temple and right_shrine:
            d5 = 2 * (pos - left_temple) + (right_shrine - pos)
            d6 = 2 * (right_shrine - pos) + (pos - left_temple)

        ans = min([
            d1, d2, d3, d4, d5, d6
        ])
        print(ans)
main()



Measured memory_bytes: 18720
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <list>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <ostream>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <iomanip>

#define N 30
#define INF (1 << 30)
#define NIL -1
using namespace std;
struct Node { int parent, lchild, rchild; } T[N];
void pre_order(int root)
{
	if (root == NIL)
		return;
	printf(" %d", root);
	pre_order(T[root].lchild);
	pre_order(T[root].rchild);
}
void in_order(int root)
{
	if (root == NIL)
		return;
	
	in_order(T[root].lchild);
	printf(" %d", root);
	in_order(T[root].rchild);
}
void post_order(int root)
{
	if (root == NIL)
		return;

	post_order(T[root].lchild);
	
	post_order(T[root].rchild);
	printf(" %d", root);
}
int main()
{
	int n, id, k, lchild, rchild;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		T[i].parent = NIL;
	}
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &id);
		scanf("%d %d", &T[id].lchild, &T[id].rchild);
		if (T[id].lchild != NIL)
		{
			T[T[id].lchild].parent = id;
		}
		if (T[id].rchild != NIL)
		{
			T[T[id].rchild].parent = id;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		if (T[i].parent == NIL)
		{
			puts("Preorder");
			pre_order(i);
			puts("\nInorder");
			in_order(i);
			puts("\nPostorder");
			post_order(i);
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N;
int A[5050],num[5050];
// dp[v][i]:vの部分木がi個のときの最小
ll dp[5050][5050],dpdp[5050];
// dp2:バッテリーのみ
bool dp2[5050][5050],dpdp2[5050];
vector<vector<int>> G(5050);
const ll INF=1e14;

void solve(int v,int p){
  num[v]=1;
  for(int u:G[v]){
    if(u==p) continue;
    solve(u,v);
    num[v]+=num[u];
  }
  fill(dpdp,dpdp+num[v]+1,INF);
  dpdp[0]=A[v];
  fill(dpdp2,dpdp2+num[v]+1,0);
  dpdp2[0]=(A[v]>0);
  int curnum=0;
  for(int u:G[v]) if(u!=p){
    for(int j=curnum;j>=0;j--){
      ll tmp=dpdp[j];
      bool tmp2=dpdp2[j];
      dpdp[j]=INF;
      dpdp2[j]=0;
      for(int k=0;k<=num[u];k++){
        // 辺を切らない
        dpdp[j+k]=min(dpdp[j+k],tmp+dp[u][k]);
        if(dp[u][k]<0||dp2[u][k]){
          // 辺を切る
          dpdp[j+k+1]=min(dpdp[j+k+1],tmp);
        }
        
        // 辺を切らない
        dpdp2[j+k]|=tmp2&&dp2[u][k];
        if(dp[u][k]<0||dp2[u][k]){
          // 辺を切る
          dpdp2[j+k+1]|=tmp2;
        }
      }
    }
    curnum+=num[u];
  }
  for(int j=0;j<=num[v];j++){
    dp[v][j]=dpdp[j];
    dp2[v][j]=dpdp2[j];
  }
}

int main(){
  cin>>N; rep(i,N) cin>>A[i];
  rep(i,N-1){
    int u,v; cin>>u>>v; u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  solve(0,-1);
  int ans=N;
  rep(i,N+1){
    if(dp[0][i]<0) ans=min(ans,i);
    if(dp2[0][i]) ans=min(ans,i);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 224128
R,G,B,N=[int(i) for i in input().split()]
rr=N//R
res=0
for i in range(rr+1):
	gb=N-R*i
	gg=gb//G
	for j in range(gg+1):
		if (gb-j*G)%B==0:
			res+=1
print(res)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

string solve(string S){
  vector<string> v;
  v.push_back(S);

  string T = "";
  map<char,int> memo;
  rep(i,S.size()){
    //cout << i << " " << S[i] << " " << T << endl;
    if(i>0) v.push_back(T);
    rep(j,26){
      if(memo.count((char)('a'+j)) == 0){
        v.push_back(T + (char)('a'+j));
      }
    }
    T += S[i];
    memo[S[i]] = 1;
  }
  if(S.size() < 26){
    rep(i,26){
      if(memo.count((char)('a'+i)) == 0){
        v.push_back(S + (char)('a'+i));
        break;
      }
    }
  }

  sort(ALLOF(v));
  v.erase(unique(ALLOF(v)), v.end());
  
  string ret = "";
  rep(i,v.size()){
    //cout << v[i] << endl;
    if(i>0 && v[i-1] == S) ret = v[i];
  }

  if(ret == "") return "-1";
  return ret;
}



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

  cout << solve(S) << endl;
  
  return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append("#")
    a = input()
    A[i] += a + "#"

A = ["#" * (W+2)] + A + ["#" * (W+2)]

for i in A:
    print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;
const int MAXN = 100005;
const int inf = 0x3f3f3f3f;
typedef long long LL;
int a[MAXN];
struct node{
    int from,to;
}edge[MAXN*2];
int head[MAXN];
int vis[MAXN];
int bin[MAXN];
int cnt;
void add(int u, int v)
{
    edge[cnt].to=v;
    edge[cnt].from=head[u];
    head[u]=cnt++;
}
int findx(int x)
{
    if(bin[x]==x)
        return x;
    return bin[x]=findx(bin[x]);
}
void merge(int u, int v)
{
    int fx=findx(u);
    int fy=findx(v);
    if(bin[fy]!=fx)
        bin[fy]=fx;
}
void dfs(int u)
{
    vis[u]=1;
    for(int i=head[u];~i;i=edge[i].from)
    {
        int v=edge[i].to;
        if(!vis[v])
        {
            bin[v]=cnt;
            dfs(v);
        }
    }
}
int main()
{
    int n, m;
    cnt=0;
    memset(head, -1, sizeof(head));
    memset(vis,0,sizeof(vis));
    scanf("%d %d", &n, &m);
    for(int i=1;i<=n;++i)
    {
        scanf("%d", &a[i]);
        bin[i]=i;
    }
    for(int i=0;i<m;++i)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        add(x,y);
        add(y,x);
    }
    int ans=0;
    cnt=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            bin[i]=cnt;
            dfs(i);
            cnt++;
        }
        if(bin[a[i]]==bin[i])
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}




Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX



 
void solve()
{
    int n;
    cin >> n;
    map<string, int> q;
    while(n--)
    {
        string s;
        cin >> s;
        q[s]++;
    } 

    cout << "AC x " << q["AC"] << endl;
    cout << "WA x " << q["WA"] << endl;
    cout << "TLE x " << q["TLE"] << endl;
    cout << "RE x " << q["RE"] << endl;
 


}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int query(int i){
  cout << i <<endl;
  string s;
  cin >> s;
  if(s[0] == 'V')exit(0);
  return (s[0] == 'M');
}
int main() {
  int n;
  cin >> n;

  int l=0,r = n-1;
  int eve = query(l);
  query(r);
  while(true){
    int mid = (l+r)/2;
    int a = query(mid);
    if(mid%2){
      if(a == eve) r = mid;
      else l = mid;
    }else{
      if(a == eve) l = mid;
      else r = mid;
    }
  }
  return 0;
}

Measured memory_bytes: 852
#include <stdio.h>

int main(void) {
	int n,m,i,j;
	int a[100][100],b[100],c[100]={0};
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(j=0;j<m;j++){
		scanf("%d",&b[j]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			c[i] += a[i][j]*b[j];
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

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

long long int N, M, A[101010], B[101010], C[101010], a, b;

int main(){
    scanf("%lld%lld", &N, &M);
    for(int i = 0; i < N; ++i){
        scanf("%lld", A + i);
        --A[i];
    }
    for(int i = 0; i < N - 1; ++i){
        ++B[A[i] + 1];
        --B[A[i + 1]];
        if(A[i] > A[i + 1]){
            ++B[0];
            a += 1 + A[i + 1];
        }else{
            a += A[i + 1] - A[i];
        }
        C[A[i + 1]] += (M - A[i] + A[i + 1]) % M - 1;
    }
    partial_sum(B, B + M, B);
    b = a;
    for(int i = 0; i < M - 1; ++i){
        b += C[i] - B[i];
        a = min(a, b);
    }
    cout << a << endl;
    return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int c = a* b;
  if ( c % 2 == 0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" <<endl;
  }
  
  return 0;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int input() { int t; cin >> t; return t; }
int d, c[30], l[30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26)if (k < c[j] * (i - l[j])) {
			k = c[j] * (i - l[j]);
			p = j;
		}
		else if (k == c[j] * (i - l[j]) && c[p] < c[j])p = j;
		puts(p);
		l[p] = i;
	}
}

Measured memory_bytes: 3636
board = Array.new
h,w = gets.split.map(&:to_i)
h.times do
	board.push(gets.chomp)
end
row = [-1,-1,-1,0,0,1,1,1]
col = [-1,0,1,-1,1,-1,0,1]

h.times do |i|
	w.times do |j|
		count = 0
		8.times do |k|
			ci = i + row[k]
			cj = j + col[k]
			if(ci >= 0 && ci < h && cj >= 0 && cj < w)
				count += 1 if board[ci][cj] == "#"
			end
		end
		str = board[i][j] == "#" ? "#" : count.to_s
		print "#{str}"
	end
	print "\n"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=53,INF=1<<30;
string dp[MAX][MAX];
bool can[MAX][MAX];
bool seen[MAX][MAX];
int N;
string S;

bool check(char c){
    if(c=='L'||c=='R'||c==','||c=='('||c==')') return false;
    return true;
}

string chmax(string A,string B){
    if(A.size()>B.size()) return A;
    if(A.size()<B.size()) return B;
    return max(A,B);
}

string solve(int l,int r){
    if(seen[l][r]) return dp[l][r];
    seen[l][r]=1;
    
    if(r-l<=3){
        string T=S.substr(l,r-l),U;
        bool ok=true;
        
        for(int i=0;i<r-l;i++){
            if(T[i]=='?') T[i]='9';
            if(!check(T[i])) ok=false;
        }
        if(r-l>=2&&T[0]=='0') ok=false;
        
        if(ok){
            can[l][r]=1;
            return dp[l][r]=T;
        }else{
            return U;
        }
    }
    
    string T=S.substr(l,r-l),ret;
    bool ok=true;
    
    for(int i=0;i<r-l;i++){
        if(T[i]=='?') T[i]='9';
        if(!check(T[i])) ok=false;
    }
    if(r-l>=2&&T[0]=='0') ok=false;
    
    if(ok){
        can[l][r]=1;
        return dp[l][r]=T;
    }
    
    T=S.substr(l,r-l);
    
    if((T[0]=='L'||T[0]=='?')&&(T[1]=='('||T[1]=='?')&&(T.back()==')'||T.back()=='?')){
        
        for(int m=3;m<=int(T.size())-3;m++){
            if(T[m]!='?'&&T[m]!=',') continue;
            string A=solve(l+2,l+m),B=solve(l+m+1,r-1);
            if(can[l+2][l+m]&&can[l+m+1][r-1]){
                ret=chmax(ret,A);
            }
        }
    }
    
    if((T[0]=='R'||T[0]=='?')&&(T[1]=='('||T[1]=='?')&&(T.back()==')'||T.back()=='?')){
        
        for(int m=3;m<=int(T.size())-3;m++){
            if(T[m]!='?'&&T[m]!=',') continue;
            string A=solve(l+2,l+m),B=solve(l+m+1,r-1);
            if(can[l+2][l+m]&&can[l+m+1][r-1]){
                ret=chmax(ret,B);
            }
        }
    }
    
    if(ret.size()>=1){
        can[l][r]=1;
        return dp[l][r]=ret;
    }
    
    return ret;
    
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>S;
    N=S.size();
    
    string ans=solve(0,N);
    if(can[0][N]) cout<<ans<<endl;
    else cout<<"invalid"<<endl;
}




Measured memory_bytes: 3284
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 2e5 + 7;

int dp[N][2];

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n = 2e5;
  cin >> n;
  vector <int> a(n);
  int x = 0, y =0 ;
  int inf = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) {
      if (a[i] < a[i - 1]) x++;
      else if (a[i] > a[i - 1]) y++;
    }
  }
  a.insert(a.begin(), 0);
  a.push_back(0);
  n += 2;
  vector <pair <int, int> > st;
  st.push_back({0, 0});
  auto mv = [&] (int x) {
    if (x >= 0) {
      vector <pair <int, int> > pts;
      for (auto c : st) {
        pts.push_back({c.first + x, c.second});
        pts.push_back({c.first, c.second + 1});
      }
      pts.push_back({0, st.back().second + 2});
      sort(pts.begin(), pts.end());
      int mx = 2 * n + 228;
      st.clear();
      for (auto c : pts) {
        if (c.second < mx) {
          st.push_back(c);
          mx = c.second;
        }
      }
    } else {
      vector <pair <int, int> > pts;
      for (auto c : st) {
        pts.push_back({max(0, c.first + x), c.second + 1});
        pts.push_back({c.first, c.second});
      }
      pts.push_back({0, st.back().second + 2});
      sort(pts.begin(), pts.end());
      int mx = 2 * n + 228;
      st.clear();
      for (auto c : pts) {
        if (c.second < mx) {
          st.push_back(c);
          mx = c.second;
        }
      }
    }
  };
  for (int i = 0; i + 1 < n; i++) {
    mv(a[i + 1] - a[i]);
    vector <pair <int, int> > go;
    for (auto c : st) {
      if (c.first <= a[i + 1]) {
        go.push_back(c);
      }
    }
    st = go;
  }
  cout << st.back().second << '\n';
  //cout << min(1 + min(x, y), st.back().second + 2) << '\n';
}



Measured memory_bytes: 1792
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
c = 0
for i in range(N):
  A = list(map(int, input().split()))
  S = [A[j]*B[j] for j in range(M)]
  if sum(S)+C>0:
    c += 1
print(c)

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

using namespace std;

long N;
long answer = 0;
vector<int> vec = {3, 5, 7}; 

// 深さ優先探索
void depthFirstSearch(long n, int three, int five, int seven)
{
	// 終了条件
	if (n > N)
	{
		return;
	}
	
	// 3、5、7が含まれた数が1以上の場合に七五三数の個数をカウントする
	if (three > 0 && five > 0 && seven > 0)
	{
		answer++;
	}
	
	// 整数Nまでの3または5または7を各桁に含んだ値を作成しながら、再帰呼び出しを行う
	for (vector<int>::iterator it = vec.begin(); it != vec.end(); it++)
	{
		long nValue = n * 10 + *it;
		//cout << nValue << endl;
		
		// 3の場合
		if (*it == 3)
		{
			depthFirstSearch(nValue, three + 1, five, seven);
		}
		// 5の場合
		else if (*it == 5)
		{
			depthFirstSearch(nValue, three, five + 1, seven);
		}
		// 7の場合
		else
		{
			depthFirstSearch(nValue, three, five, seven + 1);
		}
	}
}

int main()
{
	cin >> N;
	
	depthFirstSearch(0, 0, 0, 0);
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256