akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
大きめにとって全探索？
K^2がスタート地点
10^11はむり
全部やりなおすんじゃなくて　境界線だけ再考慮とか？
5
4
3
2
1
012345
K*2で割った余りで判断か
2Kでループしてるなら集約していい？
2K*2Kに
K=10
0,0 = 20,0 = 20,20
BW逆にすれば1/2で済むな
1個ずらし、ずらしたやつだけ判定、でいくか
XsortとYsortと、2つ用意する必要あるかも

3K盤面

BBWWBB
BBWWBB
WWBBWW
WWBBWW
BBWWBB
BBWWBB
0,0->1,1までの4通り
0123  1234
WWBB  WBBW
WWBB  WBBW
BBWW->BWWB
BBWW  BWWB
Kと2Kの境界が変わる
012345  012345
WWWBBB  WWBBBW
BBBWWW  BBWWWB
BBBWWW  BBWWWB
BBBWWW  BBWWWB
もともと2,5列目で一致してたものをひいて、あたらしく一致したものを足す。
K-2Kswap
K-1 2K-1 swap
んで、swapした行列だけ調査

入力値を二次元配列で管理しとけばいいか

......
.....B
.....B
.W....
W.....
......

WWBBBW
WWBBBW
WWBBBW
BBWWWB
BBWWWB
BBWWWB

WWW -> WWB
BBB    BBW
BBB    BBW

BBB
BBB
BBB
反転でいける！！！

すべてBだけで管理できるのか･･･。
いつも次善策だけ思いつくな。
それか、K*Kの中だけでBWにも集約できるのか
集約したとしてどう管理しよう･･･。
黒＝+1 白=-1とか
黒の場合は正、白の場合は負をかける
absが答えか
3secで微妙にTLE
きついな

6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

1 0 W
0 1 B
0 0 B
1 0 B
0 0 B
0 1 W

あれ･･･
どこが両立できるんだ

1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

1 2 B
2 1 W
2 2 B
1 0 B
0 2 W
0 1 W

....
WBB.
W.W.
.B..

ああ、合致しない場合、加算しないだけでマイナスではないな
K*2Kの中にBだけいれるとか
それで累積和とれる？とれるか
行でとるか、列でとるか
行でとったほうが早いか
WBBBWW
BWWWBB
切り替えあると面倒
どう管理しよう・・・

BBBWWW BBWWWB
BBBWWW BBWWWB
WWWBBB WWBBBW
5-2    4-1

BBBWWW BBWWWB BWWWBB
BBBWWW BBWWWB BWWWBB
BBBWWW BBWWWB BWWWBB
2+5-5  1+5-4  0+5-3

2      1
2      1
2      1

Bの開始位置で見ると境界つかめるかも

累積和と境界線の取り方わかんない
みえてきた
列での累積和も必要かな

*/
int main(){
  ll N,K; cin>>N>>K;
  ll K2=K*2;
  vector<vector<ll>> Z(K2,vector<ll>(K,0)), Sr(K2,vector<ll>(K,0)),Sc(K2,vector<ll>(K,0));
  for(ll i=0; i<N; i++){
    ll p,q,r=1; char c;
    cin>>p>>q>>c;
    p%=K2;
    q%=K2; 
    if(q>=K){
      q-=K;
      r*=-1;
      c=(c=='B')?'W':'B';
    }
    if(c=='W') p=(p+K)%K2;
    Z[p][q]++;
  }

/*for(ll i=K-1;i>=0;i--){
for(ll j=0;j<K2;j++){
cout<<Z[j][i];}
cout<<endl;}    
cout<<endl;*/
  
  Sr=Z;
  Sc=Z;
  //累積和つくる
  for(ll i=0; i<K; i++) for(ll j=1; j<K2; j++) Sr[j][i]+=Sr[j-1][i];
  for(ll i=0; i<K2; i++) for(ll j=1; j<K; j++) Sc[i][j]+=Sc[i][j-1];
  //00のとき
  ll ans=0,tmp=0;
  for(ll i=0; i<K; i++) tmp+=Sr[K-1][i];
  ll ytmp=tmp, xtmp;
  for(ll sy=0; sy<K; sy++){//スライドする値
    if(sy>0){
      //変更箇所ひいて
      ytmp-=Sr[K-1][sy-1];
      //足しなおし
      ytmp+=Sr[K2-1][sy-1]-Sr[K-1][sy-1];
    }
    for(ll sx=0; sx<K; sx++){//スライドする値
      if(sx==0) xtmp=ytmp;
      else if(sx>0){
        //K-1は、全体ひいて、syを2回足す
        xtmp-=Sc[K-sx][K-1];
        if(sy>0) xtmp+=Sc[K-sx][sy-1]*2;
        //K2-1、全体足して、syを2回ひく
        xtmp+=Sc[K2-sx][K-1];
        if(sy>0) xtmp-=Sc[K2-sx][sy-1]*2;
      }
      ans=max(ans,max(xtmp,N-xtmp));
//cout<<"sy:"<<sy<<" sx:"<<sx<<" xtmp:"<<xtmp<<endl;          
    }
  }
  cout<<ans<<endl;
}

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

int main() {
    int n;
    cin >>n;
    string s;
    cin >> s;
    char b=0;
    for (int i=n-1;i>=0;i--){
        if (b == s.at(i))
        s.erase(s.begin()+i);
        b=s.at(i);
    }
    cout << s.size() << endl;
    return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int a=sc.nextInt();//起きている時間
			int b=sc.nextInt();//寝ている時間
			int c=sc.nextInt();//到着時間
			int r=-1;
			while(c<14400){
				if(c%(a+b)<=a) {
					r=c;
					break;
				}
				c+=60;
			}
			System.out.println(r);

		}
	}
}



Measured memory_bytes: 26372
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi V(n), C(n);
    for(auto& e : V) cin >> e;
    for(auto& e : C) cin >> e;

    vi VC(n);
    rep(i, n) VC[i] = V[i] - C[i];

    int res = 0;
    rep(i, n){
        if(VC[i] > 0) res += VC[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
#define EACH(a,A) for(auto a: A)
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 



void func(){
  LL H,W;
  cin >> H >> W;
  vector<string> M(H);
  REP(i,H){
    cin >>M[i];
  }
  set<pair<LL,LL>> S;
  REP(i,H){
    REP(j,W){
      if(M[i][j]=='#'){
        S.emplace(i,j);
      }      
    }
  }

  LL cnt=0;
  while( not S.empty()){
    //cerr << cnt<< endl;
    EACH(m,M){
      //PRINTSP(m);
    }

    set<pair<LL,LL>> T;
    for(auto s : S){
      LL y = s.first;
      LL x = s.second;
      if(y+1<H and M[y+1][x]=='.'){
        M[y+1][x] = '#';
        //T.emplace(y+1,x);
        T.insert(make_pair(y+1,x));
      }
      if(x+1<W and M[y][x+1]=='.'){
        M[y][x+1] = '#';
        //T.emplace(y,x+1);
        T.insert(make_pair(y,x+1));
      }
      if(y-1>=0 and M[y-1][x]=='.'){
        M[y-1][x] = '#';
        //T.emplace(y-1,x);
        T.insert(make_pair(y-1,x));
      }
      if(x-1>=0 and M[y][x-1]=='.'){
        M[y][x-1] = '#';
        //T.emplace(y,x-1);
        T.insert(make_pair(y,x-1));
      }
    }
    S=T;
    cnt++;
  }
  EACH(m,M){
    //PRINTSP(m);
  }
  cout << cnt-1;
  return;
}
  
void _func(){
  LL H,W;
  cin >> H >> W;
  vector<string> M(H);
  REP(i,H){
    cin >>M[i];
  }

  

  queue<pair<LL,LL>> Q;
  set<pair<LL,LL>> S;
  REP(i,H){
    REP(j,W){
      if(M[i][j]=='#'){
        Q.emplace(i,j);
        S.emplace(i,j);
      }      
    }
  }

  LL cnt=0;
  while( not S.empty()){
    cerr << cnt<< endl;
    EACH(m,M){
      PRINTSP(m);
    }

    set<pair<LL,LL>> T;
    for(auto s : S){
      LL y = s.first;
      LL x = s.second;
      if(y+1<H and M[y+1][x]=='.'){
        M[y+1][x] = '#';
        T.emplace(y+1,x);
      }
      if(x+1<W and M[y][x+1]=='.'){
        M[y][x+1] = '#';
        T.emplace(y,x+1);
      }
      if(y-1>=0 and M[y-1][x]=='.'){
        M[y-1][x] = '#';
        T.emplace(y-1,x);
      }
      if(x-1>=0 and M[y][x-1]=='.'){
        M[y][x-1] = '#';
        T.emplace(y,x-1);
      }
    }
    S=T;
    cnt++;
  }
  EACH(m,M){
    //PRINTSP(m);
  }
  cout << cnt-1;
  return;
}

 
int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 65152
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
vector<vector<int> > query;
int n,m,q;
ll sum=0,maxi=0;
int used[51];
void recurse(vector<int>&v,int i,int prev){
    if(i==v.size()){
        ll sum=0;
        for(i=0;i<query.size();i++){
            if(v[query[i][1]-1]-v[query[i][0]-1]==query[i][2]){
                sum+=query[i][3];
            }
        }
        maxi=max(maxi,sum);
        return;
    }
    for(int j=prev;j<=m;j++){
        v[i]=j;
        recurse(v,i+1,j);
    }
}
int main(){
FASTIO;
cin>>n>>m>>q;
for(int i=0;i<q;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    query.pb({a,b,c,d});
}
vector<int> v(n);
recurse(v,0,1);
cout<<maxi<<endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    REP(i,n) cin >> v[i];

    ll ans = 0;

    FOR(i,1,n) {
        ans += min(b , (v[i] - v[i-1]) * a);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>

int c0, c1, c2, c3;

int main() {
    int n;
    scanf("%d", &n);
    char s[10];
    for (int i = 0; i < n; ++i) {
        scanf("%s", s);
        if (!strcmp(s, "AC")) c0++;
        else if (!strcmp(s, "WA")) c1++;
        else if (!strcmp(s, "TLE")) c2++;
        else if (!strcmp(s, "RE")) c3++;
    }
    printf("AC x %d\n", c0);
    printf("WA x %d\n", c1);
    printf("TLE x %d\n", c2);
    printf("RE x %d\n", c3);
    return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
int dp[100];
int f(int n){
    if(n==0)return 2;
    if(n==1)return 1;
    if(dp[n]!=-1)return dp[n];
    return dp[n]=f(n-1)+f(n-2);
}
signed main(){
    int n;
    cin>>n;
    REP(i,100)dp[i]=-1;
    cout<<f(n)<<endl;
    return 0;
}

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


int main(){
	
	int N;
	cin>>N;
	int h[N];
	for(int i=0;i<N;i++){
		cin>>h[i];
	}
	int ans = 0;
	
	while(true){
		bool flag = false;
		bool flag2=false;
		for(int i=0;i<N;i++){
			if(!flag){
				if(h[i]>0){
					h[i]--;
					ans++;
					flag=true;
				}
			}
			else{
				if(h[i]>0)h[i]--;
				else flag=false;
			}
			if(h[i]!=0)flag2=true;
		}
		if(flag2==false)break;
	}
	cout<<ans<<endl;
			

	return 0;
}

Measured memory_bytes: 256
using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            bool b = new Calu().calu(s);
            if(b){
                Console.WriteLine("YES");
            }else{
                Console.WriteLine("NO");
            }
        }

        public class Calu {
            public Calu() { }
            public bool calu(string[] a){
                int b = int.Parse(a[0]);
                int c = int.Parse(a[1]);
                int d = int.Parse(a[2]);
                if (c - b == d - c) return true;
                return false;      
            }
        } 
    }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int w,h,n;
  cin >> w >> h >> n;
  
  vector<vector<int>> map(w,vector<int>(h)); //map[x][y]
  rep(i,n){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1){
      rep(xi,x) rep(yi,h) map[xi][yi] = 1;
    }
    if(a==2){
      rep(xi,w) if(xi>=x) rep(yi,h) map[xi][yi] = 1;
    }
    if(a==3){
      rep(xi,w) rep(yi,y) map[xi][yi] = 1;
    }
    if(a==4){
      rep(xi,w) rep(yi,h) if(yi>=y) map[xi][yi] = 1;
    }
  }
  
  int ans = 0;
  rep(i,w) rep(j,h) if(map[i][j] == 0) ans++;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int resNum = Integer.parseInt(sc.next());
		Map <String,List<Integer>> map = new TreeMap<>();
		List<Integer> out = new ArrayList<>();
      for(int x =1 ; x<=resNum; x++) {
        String a = sc.next();
        int b = Integer.parseInt(sc.next());
        if (map.containsKey(a)) {
          List<Integer> ls = map.get(a);
          ls.add(b);
          map.put(a, ls);
          out.add(b);
        } else {
          	List<Integer> ls = new ArrayList<>();
          ls.add(b);
         	map.put(a,ls);
         	out.add(b);
        }
      }
      // キーでソートする
      //Object[] mapkey = map.keySet().toArray();
      //Arrays.sort(mapkey);

      List<Integer> list = new ArrayList<>();
      for (String nKey : map.keySet())
      {
    	  List<Integer> ls =map.get(nKey);
    	  Collections.sort(ls, Collections.reverseOrder());
    	  ls.forEach(a -> {list.add(a);});
      }
      loop:for (Integer i : list) {
    	  for (int x =0; x < list.size(); x++) {
    		  if (i==out.get(x)) {
    			  System.out.println(x+1);
                continue loop;
    		  }
    	  }
      }
    }
	}

Measured memory_bytes: 26964
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

bool solve(bitset<18>bs, vector<vector<int>>&dp,const vector<pair<int,int>>&vs,const int now) {
	if(dp[now][bs.to_ulong()]!=-1)return dp[now][bs.to_ulong()];

	bool ok = false;
	if(bs.count()==vs.size())ok=true;
	else {
		for (int i = 0; i < vs.size(); ++i) {
			if (bs[i]) {

			}
			else {
				if (vs[i].first == now || now == 7) {
					bs[i] = true;
					bool aok = solve(bs, dp, vs, vs[i].second);
					if (aok)ok = true;
					bs[i] = false;
				}
				if (vs[i].second == now || now == 7) {
					bs[i] = true;
					bool aok = solve(bs, dp, vs, vs[i].first);
					if(aok)ok=true;
					bs[i] = false;
				}
			}
		}
	
	}
	return dp[now][bs.to_ulong()]=ok;
}

void solve(vector<int>&memo,const int rest,const vector<int>&values, const vector<vector<int>>&rev_edges, int sum, int now,const vector<int>&perms,int&ans) {
	if (rest <= 0) {
		ans=min(ans,sum);
		return ;
	}
	else if (now == values.size()) {
		return;
	}
	else {
		solve(memo,rest,values,rev_edges,sum,now+1,perms,ans);

		bool ok=true;
		for (auto re : rev_edges[perms[now]]) {
			if(!memo[re])ok=false;
		}
		if (ok) {
			memo[perms[now]]=true;
			solve(memo,rest-values[perms[now]],values,rev_edges,sum+1,now+1,perms,ans);
			memo[perms[now]]=false;
		}
	}

}
int main()
{
	while (true) {
		int N,U;cin>>N>>U;
		if(!N)break;
		vector<int>values(N);
		vector<vector<int>>edges(N);
		vector<vector<int>>rev_edges(N);
		vector<int>comes(N);
		for (int i = 0; i < N; ++i) {
			int c,k;cin>>c>>k;
			values[i]=c;
			for (int j = 0; j < k; ++j) {
				int a;cin>>a;
				edges[a].push_back(i);
				rev_edges[i].push_back(a);
				comes[i]++;
			}
		}
		
		queue<int>que;
		for (int i = 0; i < N; ++i) {
			if (comes[i] == 0) {
				que.push(i);
			}
		}
		vector<int>perms;
		while (!que.empty()) {
			int atop(que.front());
			que.pop();
			perms.push_back(atop);
			for (auto e : edges[atop]) {
				comes[e]--;
				if (comes[e] == 0) {
					que.push(e);
				}
			}
		}
		vector<int>rev_perms(N);
		for (int i = 0; i < N; ++i) {
			rev_perms[perms[i]]=i;
		}
		int ans=100;
		vector<int>memo(N);
		solve(memo,U,values,rev_edges,0,0,perms,ans);
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(
        it,
        n: usize,
        a: [usize; n],
        q: usize,
        bc: [(usize, usize); q]
    );
    let mut s: usize = a.iter().sum();
    let mut counter = HashMap::<usize, usize>::new();
    for &ai in a.iter() {
        *counter.entry(ai).or_default() += 1usize;
    }
    for &(b, c) in bc.iter() {
        if let Some(&v) = counter.get(&b) {
            s -= v * b;
            s += v * c;
            *counter.entry(c).or_default() += v;
            *counter.get_mut(&b).unwrap() = 0;
        };
        println!("{}", s);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

int main(int argc, char *argv[])
{
    int A, B, C, X;
    std::cin >> A >> B >> C >> X;

    int res = 0;

    for (int a = 0; a <= A; a++) {
        for (int b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++) {
                int total = 500*a + 100*b + 50*c;
                if (total == X) {
                    res++;
                }
            }
        }
    }

    std::cout << res;
    return 0;
}

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

#define MAX (1000)
#define INF (1<<21)

struct Point{int x, y;};
int H, W, sy, sx, gy, gx, cnt[5];
Point P[5][MAX];
int dp[5][MAX];

int mdist(int x1, int y1, int x2, int y2){
  return (abs(x1-x2) + abs(y1-y2));
}

void compute(){
  int opts, optc = INF;
  int t;
  //s: スタートのお供パチクリの属性
  //t: 1).最初のパチクリが捕まえられるパチクリの属性, 2).最後に捕まえるべきパチクリの属性
  for(int s = 0; s < 5; s++){
    for(int i = 0; i < 5; i++) for(int j = 0; j < cnt[i]; j++) dp[i][j] = INF;

    //最初に捕まえるパチクリへの最短距離は、そのパチクリとスタートとのマンハッタン距離に等しい
    t = (s + 1) % 5;
    for(int j = 0; j < cnt[t]; j++) dp[t][j] = mdist(sx, sy, P[t][j].x, P[t][j].y);

    //その後は漸化式で最短距離を求めていく
    //b: 今の捕まえたパチクリ
    //e: 次に捕まえられるパチクリ
    for(int i = s + 1; i < s + 5; i++){
      int b = i % 5;
      int e = (i + 1) % 5;
      for(int k = 0; k < cnt[b]; k++) for(int l = 0; l < cnt[e]; l++){
        dp[e][l] = min(dp[e][l], dp[b][k] + mdist(P[b][k].x, P[b][k].y, P[e][l].x, P[e][l].y));
      }
    }

    t = (s + 4) % 5;
    for(int j = 0; j < cnt[t]; j++){
      if(dp[t][j] + mdist(gx, gy, P[t][j].x, P[t][j].y) < optc){
        optc = dp[t][j] + mdist(gx, gy, P[t][j].x, P[t][j].y);
        opts = s;
      }
    }
  }
  if(optc == INF) cout << "NA" << endl;
  else cout << opts+1 << " " << optc << endl;
}

int main(void){
  char ch;
  while(cin >> W >> H, W){
    for(int i = 0; i < 5; i++) cnt[i] = 0;
    for(int y = 0; y < H; y++){
      for(int x = 0; x < W; x++){
        cin >> ch;
        if(ch == '.') continue;
        if(ch == 'S'){
          sy = y; sx = x;
        }else if(ch == 'G'){
          gy = y; gx = x;
        }else{
          int p = ch - '0' - 1;
          //属性pのcnt[p]番目のパチクリの座標を設定する
          P[p][cnt[p]].x = x;
          P[p][cnt[p]].y = y;
          //属性pのパチクリの数をカウントする
          cnt[p]++;
        }
      }
    }
    compute();
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <string>

using namespace std;
typedef long long ll;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)

int main(){
    int N;
    cin >> N;
    vector<ll> cnts(5, 0);
    vector<char> hs = {'A', 'C', 'H', 'M', 'R'};
    rep(i, N){
       string s;
       cin >> s;
        rep(j, hs.size()){
            if(s[0] == hs[j]){
                cnts[j] ++;
            }
        }
    }
    ll ans = 0;
    rep(i, 5){
        for(int j = i + 1; j < 5; j ++){
            for(int k = j + 1; k < 5; k++){
                ans += cnts[i] * cnts[j] * cnts[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,k,tot=0;
	cin>>x>>y;
	for(int i=0;i<y;i++)	
		cin>>k,tot+=k;
	if(tot>=x)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#pragma GCC optimize ("unroll-loops")

#pragma GCC optimize("-Ofast")

#include <bits/stdc++.h>

using namespace std;

 

typedef int in;

#define int long long

#define pb push_back

#define f first

#define s second

#define double long double

 

const int MAX=2e5+10;

const int MAX2=2e5+4;

const int MAAX=2e18;

const int MOD=1e9+7;

string s;

int dp[10005][105][2];

int d;

int fun(int idx,int cur,bool gr)

{

 

    if(idx==s.size())

        return !cur;

    int &ret=dp[idx][cur][gr];

    if(ret!=-1)

    {

     return ret;

    }

    ret=0;

   if(gr)

   {

      for(int i=0;i<(s[idx]-'0');i++)

      {

          ret+=fun(idx+1,(cur+i)%(d),0);

          ret%=MOD;

 

      }

      ret+=fun(idx+1,(cur+(s[idx]-'0'))%(d),1);

   ret%=MOD;

   }

   else

   {

       for(int i=0;i<10;i++)

       {

           ret+=fun(idx+1,(cur+i)%(d),0);

           ret%=MOD;

 

       }

   }

   ret%=MOD;

   return ret;

}

 

in main()

{

    memset(dp,-1,sizeof dp);

   cin>>s;

   cin>>d;

        int ans=fun(0,0,1)-1;

        ans%=MOD;

if(ans<0) ans=MOD+ans;

   cout<<ans<<endl;

   return 0;

}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int D=365,A=26,K=1;

int d;
int c[A],s[D][A],last[A];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>d;
    for(int j=0;j<A;j++)
        cin>>c[j],
        last[j]=-1;
    for(int i=0;i<d;i++)
        for(int j=0;j<A;j++)
            cin>>s[i][j];
    for(int i=0;i<d;i++)
    {
        int best=0;
        for(int j=0;j<A;j++)
            if(s[i][j]+c[j]*(i-last[j])*min(K,d-i)>
               s[i][best]+c[best]*(i-last[best])*min(K,d-i))
                best=j;
        last[best]=i;
        cout<<best+1<<"\n";
    }
}


Measured memory_bytes: 3732
#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    int max = 0;
    cin >> a >> b;
    if (a + b >= a - b){
        max = a + b;
        if (a + b >= a * b){
            max = a + b;
        }else{
            max = a * b;
        }
    }else if (a - b >= a * b){
        max = a - b;
    }else{
        max = a * b;
    }
    cout << max;
    return 0;
}


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

ll gcd(ll x, ll y){//最大公約数 greatest common divison
    return y ? gcd(y, x%y) : x;
}

int main() {
  ll A,B;
  cin>>A>>B;
  set<ll> st;
  ll C = gcd(A,B);
  //Cの、2以上の素因数の数を求めるー＞答えは＋１する
  while(C%2==0){
    st.insert(2);
    C /=2;
  }
  //Cが奇数になった
  //√Cより大きい素因数は高々1個まで！（2個以上あると、それらをかけたときにCより大きくなってしまう）
  for(ll i=3;i<=pow(C,0.5);i++){
    while(C%i==0){
      st.insert(i);
      C /= i;
    }
    if(C==1)break;
  }
  ll ans=st.size()+1;
  if(C!=1) ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
per = gets.chomp.split(" ").map(&:to_i)
num = [*1..n]
differ = Array.new(n, false)
ans = 0
n.times do |i|
    differ[i] = true if num[i] == per[i]
end

n.times do |i|
    if differ[i]
        differ[i] = false
        differ[i+1] = false if differ[i+1]
        ans += 1
    end
end
puts ans

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


int main() {
    string s, ope, p, tmp;
    int i, j, h, num, start, end;
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed <<setprecision(10) << sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) << endl;

    return 0;
}



Measured memory_bytes: 3280
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
	    int A=sc.nextInt();
	    String OP=sc.next();
	    int B=sc.nextInt();
	    int K=0;
	    switch(OP) {
	    case "+":
	        K=A+B;
	    	System.out.println(K);
	    	break;
	    case "-":
	    	K=A-B;
	    	System.out.println(K);
	    }
	    
	}
}


Measured memory_bytes: 22612
import java.util.Scanner;

class Node {

	int id, left, right, parent;

	public Node(int id, int left, int right) {
		super();
		this.id = id;
		this.left = left;
		this.right = right;
	}


}

public class Main {

	static StringBuilder sb;

	public static void setNode(Node[] nodes, int id, int parent) {
		Node node = nodes[id];
		node.parent = parent;
		if (node.left != -1) {
			setNode(nodes, node.left, node.id);
		}
		if (node.right != -1) {
			setNode(nodes, node.right, node.id);
		}
	}

	public static void preorder(Node[] nodes, int id) {
		Node node = nodes[id];
		sb.append(" " + id );
		int left = node.left, right = node.right;
		if (left != -1) {
			preorder(nodes, left);
		}
		if (right != -1) {
			preorder(nodes, right);
		}
	}

	public static void inorder(Node[] nodes, int id) {
		Node node = nodes[id];
		int left = node.left, right = node.right;

		if (left != -1) {
			inorder(nodes, left);
		}
		sb.append(" " + id);
		if (right != -1) {
			inorder(nodes, right);
		}

	}

	public static void postorder(Node[] nodes, int id) {
		Node node = nodes[id];
		int left = node.left, right = node.right;

		if (left != -1) {
			postorder(nodes, left);
		}
		if (right != -1) {
			postorder(nodes, right);
		}
		sb.append(" " + id);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		Node[] nodes = new Node[n];
		int[] rootNode = new int[n];
		sb = new StringBuilder();

		for (int i = 0; i < n; i++) {
			int id = sc.nextInt(), left = sc.nextInt(), right = sc.nextInt();

			nodes[id] = new Node(id, left, right);

			if (left != -1) {
				rootNode[left] = 1;
			}
			if (right != -1) {
				rootNode[right] = 1;
			}
		}

		int root = 0;
		for (int i = 0; i < n; i++) {
			if (rootNode[i] == 0) {
				root = i;
			}
		}

		setNode(nodes, root, -1);


		sb.append("Preorder\n");
		preorder(nodes, root);
		sb.append("\n");


		sb.append("Inorder\n");
		inorder(nodes, root);
		sb.append("\n");

		sb.append("Postorder\n");
		postorder(nodes, root);


		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 26536
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int n, c;
vector<vector<int> > board;

int solve()
{
    int dy[] = {-1, -1, 0, 0, 1, 1};
    int dx[] = {-1, 0, -1, 1, 0, 1};
    vector<vector<bool> > check(n+2, vector<bool>(n+2, false));

    int ret = 0;
    for(int i=1; i<=n; ++i){
        for(int j=1; j<=i; ++j){
            if(board[i][j] == 0 || check[i][j])
                continue;
            check[i][j] = true;

            queue<pair<int, int> > q;
            q.push(make_pair(i, j));
            int num = 1;
            bool remove = true;
            while(!q.empty()){
                int y0 = q.front().first;
                int x0 = q.front().second;
                q.pop();
                for(int k=0; k<6; ++k){
                    int y = y0 + dy[k];
                    int x = x0 + dx[k];
                    if(board[y0][x0] == board[y][x] && !check[y][x]){
                        check[y][x] = true;
                        q.push(make_pair(y, x));
                        ++ num;
                    }else if(board[y][x] == 0){
                        remove = false;
                    }
                }
            }

            if(remove){
                if(c == board[i][j])
                    ret -= num;
                else
                    ret += num;
            }
        }
    }

    return ret;
}

int main()
{
    for(;;){
        cin >> n >> c;
        if(n == 0)
            return 0;

        board.assign(n+2, vector<int>(n+2, -1));
        for(int i=1; i<=n; ++i){
            for(int j=1; j<=i; ++j){
                cin >> board[i][j];
            }
        }

        int ret = INT_MIN;
        for(int i=1; i<=n; ++i){
            for(int j=1; j<=i; ++j){
                if(board[i][j] != 0)
                    continue;
                board[i][j] = c;
                ret = max(ret, solve());
                board[i][j] = 0;
            }
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
#include<vector>
int main()
{
  int n; cin>>n;
  vector<int> cnt(1e4+5);
  for(int x = 1 ; x <= 105; x++)
    for(int y = 1 ; y <= 105;y++)
      for(int z = 1 ; z <= 101 ; z++)
        if(x*x + y*y + z*z + x*y + y*z + z*x < 1e4 + 5)
          cnt[x*x + y*y + z*z + x*y + y*z + z*x]++;
  for(int i = 1 ; i <= n ; i++)
     cout<<cnt[i]<<endl;
  return 0;
}

Measured memory_bytes: 3164
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        int[] input = new int[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=int.Parse(Console.ReadLine());
        }
        int max= int.Parse(Console.ReadLine());
        //int[] input = "5 100".Split().Select(i=>int.Parse(i)).ToArray();
        bool f = true;
        for (int a = 0; a < 5; a++)
        {
            for (int b = a+1; b < 5; b++)
            {
                if (Math.Abs(input[b]-input[a])>max)
                {
                    f = false;
                }
            }
        }
        /*
        int n = input[0];
        int q = input[1];
        //int seed = Environment.TickCount;

    */
        Console.WriteLine(f?"Yay!": ":(");

        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法

        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();
        
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int main(){

  int a,b,d,r;
  double f;

  scanf("%d %d",&a,&b);

  d = a / b;
  r = a % b;

  printf("%d %d ",d,r);

  f = (double)a / b;

  printf("%f\n",f);

  return 0;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int foo[] = new int[N];
		int count = 1;
		boolean judge = true;
		for (int i = 0; i < N; i++) {
			foo[i] = sc.nextInt();

		}

		for (int i = 1; i < foo.length; i++) {

			for (int j = 0; j < i; j++) {

				if(foo[j] >  foo[i]) {
					judge = false;
				}

			}
			if(judge) {
				count++;
			}
			judge = true;

		}
		System.out.println(count);
	}

}


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

using namespace std;


int main() {
  #ifdef LOCAL
  freopen("sol.in", "r", stdin);
  freopen("sol.out", "w+", stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  vector<vector<pair<int, int>>> parent(n + 1, vector<pair<int, int>>(m + 1));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i - 1 < 0 || j - 1 < 0) {
        continue;
      }
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = 1 + dp[i - 1][j - 1];
        parent[i][j] = make_pair(i - 1, j - 1);
      } else {
        dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
        parent[i][j] = dp[i][j - 1] < dp[i - 1][j] ? make_pair(i - 1, j) : make_pair(i, j - 1);
      }
    }
  }
  int ans = 0;
  int ans_i = -1, ans_j = -1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (ans < dp[i][j]) {
        ans = max(ans, dp[i][j]);
        ans_i = i, ans_j = j;
      }
    }
  }
  string w;
  while (ans_i > 0 && ans_j > 0) {
    if (s[ans_i - 1] == t[ans_j - 1]) {
      w.push_back(s[ans_i - 1]);
    }
    pair<int, int> p = parent[ans_i][ans_j];
    ans_i = p.first, ans_j = p.second;
  }
  reverse(w.begin(), w.end());
  cout << w << '\n';
  return 0;
}

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

// #define DEBUG

using namespace std;

const int N = 5e3+7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-11;
typedef pair<int, int> pii;

int k, q, n, x, m;
int d[N];
long long sum[N];

inline void solve()
{
    cin >> k >> q;
    for (int i = 1; i <= k; ++i)
        cin >> d[i];
    while (q--) {
        cin >> n >> x >> m;
        long long res = n-1;
        for (int i = 1; i <= k; ++i) {
            sum[i] = sum[i-1]+d[i]%m;
            if (d[i]%m == 0) res -= (n-1)/k+((n-1)%k >= i);
        }
        long long last = (n-1)/k*sum[k]+sum[(n-1)%k]+x;
        res -= last/m-x/m;
        cout << res << endl;
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int x,p,q,cnt,max,m,n;
	scanf("%d",&x);
	while(x!=0){
		scanf("%d %d",&p,&q);
		cnt=0;
		max=p*p+q*q;
		for(m=0;m*m<=max;m++){
			for(n=0;m*m+n*n<=max;n++){
				if(m==0&&n==0){
					continue;
				}
				if((m*p+n*q)%(m*m+n*n)==0&&(m*q-n*p)%(m*m+n*n)==0){
					cnt++;
				}
				if(m!=0&&(-m*p+n*q)%(m*m+n*n)==0&&(-m*q-n*p)%(m*m+n*n)==0){
					cnt++;
				}
				if(n!=0&&(m*p-n*q)%(m*m+n*n)==0&&(m*q+n*p)%(m*m+n*n)==0){
					cnt++;
				}
				if(m!=0&&n!=0&&(-m*p-n*q)%(m*m+n*n)==0&&(-m*q+n*p)%(m*m+n*n)==0){
					cnt++;
				}
			}
		}
		if(cnt==8){
			printf("P\n");
		}
		else{
			printf("C\n");
		}
		x--;
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int n;
	cin>>n;
	int a[22];
	rb(i,1,n){
		cin>>a[i];
	}
	int res=0;
	rb(i,2,n-1){
		if(a[i]!=max(max(a[i-1],a[i+1]),a[i])&&a[i]!=min(min(a[i-1],a[i+1]),a[i])){
			res++;
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#
# Keitai Message
#

class Cellular < Hash
  def initialize
    @buf=[]
    reset
    self.store(1, %w". , ! ?"+[' '])
    self.store(2, %w"a b c")
    self.store(3, %w"d e f")
    self.store(4, %w"g h i")
    self.store(5, %w"j k l")
    self.store(6, %w"m n o")
    self.store(7, %w"p q r s")
    self.store(8, %w"t u v")
    self.store(9, %w"w x y z")
  end

  def push(b)
    if b=='0'
      enter
    else
      @ptr[0]=b.to_i
      @ptr[1]=@ptr[1]+1
      @ptr[1]-=self[@ptr[0]].size if @ptr[1]==self[@ptr[0]].size
    end
  end

  def reset
    @ptr=[0, -1]
  end

  def enter
    @buf<<self[@ptr[0]][@ptr[1]] if @ptr[0]>0
    reset
  end

  def message
    @buf.join('')
  end

end

gets.to_i.times do

  cell = Cellular.new
  gets.chomp.chars { |c| cell.push(c) }
  puts cell.message

end

Measured memory_bytes: 6112
N=int(input())
L=map(int,input().split())
from collections import defaultdict
d = defaultdict(int)
for l in L:
  d[l]+=1
def chkTRI(X,i,j,k):
  if X[i]+X[j]>X[k] and X[i]+X[k]>X[j] and X[k]+X[j]>X[i]:
    return True
  return False
ans=0
X=list(d.keys())
for i in range(len(X)-2):
  for j in range(i+1,len(X)-1):
    for k in range(j+1,len(X)):
      if chkTRI(X,i,j,k):
        ans+=d[X[i]]*d[X[j]]*d[X[k]]
print(ans)

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> a(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> a[i][j];

  set<int> I, J;

  rep(i, H) {
    int n = 0;
    rep(j, W) {
      if (a[i][j] == '.')
        n++;
    }
    if (n == W)
      I.insert(i);
  }

  rep(j, W) {
    int n = 0;
    rep(i, H) {
      if (a[i][j] == '.')
        n++;
    }
    if (n == H)
      J.insert(j);
  }

  rep(i, H) {
    if (I.find(i) != I.end())
      continue;
    rep(j, W) {
      if (J.find(j) == J.end())
        cout << a[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import numpy as np


N = int(input())
H = np.array(list(map(int, input().split())))

answer = 0

L1 = (H[:-1] >= H[1:])
#print(L1)

answer = 0
count = 0
for l in L1:
    if l:
        count += 1
    else:
        answer = max(answer, count)
        count = 0

print(max(answer, count))

Measured memory_bytes: 23388
N = int(input())
a = list(map(int, input().split()))
p = sum(a)/N
sa = 0
index = 0
min = abs(p-a[0])
for i in range(N):
    sa = abs(p-a[i])
    if min > sa:
        min = abs(p-a[i])
        index = i
print(index)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

struct SCC {
    int n, k;
    vector<vector<int>> G, R;
    vector<bool> used;
    vector<int> vs, cmp;

    SCC(int n) : n(n), G(n), R(n), used(n), cmp(n) {}

    int operator[](int k) {
        return cmp[k];
    };

    void add_edge(int from, int to) {
        G[from].emplace_back(to);
        R[to].emplace_back(from);
    }

    void dfs(int v) {
        used[v] = true;
        for (int u : G[v]) {
            if (!used[u]) dfs(u);
        }
        vs.emplace_back(v);
    }

    void rdfs(int v, int k) {
        used[v] = true;
        cmp[v] = k;
        for (int u : R[v]) {
            if (!used[u]) rdfs(u, k);
        }
    }

    int build() {
        for (int v = 0; v < n; v++) {
            if (!used[v]) dfs(v);
        }
        fill(used.begin(), used.end(), false);
        k = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (!used[vs[i]]) {
                rdfs(vs[i], k);
                k++;
            }
        }
        return k;
    }

    vector<vector<int>> makeGraph() {
        vector<vector<int>> res;
        res.resize(k, vector<int>());
        for (int v = 0; v < n; v++) {
            for (int u : G[v]) {
                if (cmp[v] != cmp[u]) res[cmp[v]].emplace_back(cmp[u]);
            }
        }
        for (int i = 0; i < k; i++) {
            sort(res[i].begin(), res[i].end());
            res[i].erase(unique(res[i].begin(), res[i].end()), res[i].end());
        }
        return res;
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    SCC scc(n);
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        scc.add_edge(a, b);
    }
    int k = scc.build();
    cout << k << endl;
    vector<int> vec[k];
    rep(v, n) {
        vec[scc[v]].emplace_back(v);
    }
    for (auto v : vec) {
        cout << v.size();
        for (int u : v) {
            cout << " " << u;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 79580
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll x,y;
    int ans=0;
    cin>>x>>y;
    while (x<=y)
    {
        ans++;
        x*=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import itertools

n = int(input())
p = input().split()
q = input().split()

pstr = "".join(p)
qstr = "".join(q)

# list N! elements
ary = list(map(str,range(1,n+1)))

elements = []

for element in itertools.permutations(ary, len(ary)):
    elements.append("".join(element))
    #print("".join(element))

print(abs(elements.index(pstr)-elements.index(qstr)))


Measured memory_bytes: 6040
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int[] a=new int[n];
		
		for(int i=0;i<n;i++)
			a[i]=scan.nextInt();
		
		for(int i=0;i<n;i++){
			System.out.printf("node %d: key = %d, ",i+1,a[i]);
			if(i!=0){
				if(i%2==0)
					System.out.printf("parent key = %d, ",a[i/2-1]);
				else
					System.out.printf("parent key = %d, ",a[i/2]);
			}
			if(i*2+1 < n)
				System.out.printf("left key = %d, ",a[i*2+1]);
			if(i*2+2 < n)
				System.out.printf("right key = %d, ",a[i*2+2]);
			System.out.println();
		}
		
	}
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;

vi v;

vi zero;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
    if (x == 0) {
      zero.pb(i);
    }
  }
}

int sol = 0;

void solve(int start, int stop, int nr) {
  if (start >= n || start > stop) {
    return;
  }

  int cmin = 1e9;
  vi ind;
  for(int i = start; i <= stop; ++i)
    if (v[i] - nr < cmin && v[i] - nr > 0) {
      cmin = v[i] - nr;
      ind.clear();
      ind.pb(i);
    }
    else if (v[i] - nr == cmin && v[i] - nr > 0) ind.pb(i);
  nr += cmin;
  sol += cmin;
  if (cmin == 0) {
    return;
  }
  solve(start, ind[0] - 1, nr);
  for(int i = 1; i < ind.size(); ++i)
    solve(ind[i - 1] + 1, ind[i] - 1, nr);
  solve(ind[ind.size() - 1] + 1, stop, nr);
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    if (zero.size() > 0) {
      solve(0, zero[0] - 1, 0);
      for(int i = 1; i < zero.size(); ++i)
        solve(zero[i - 1] + 1, zero[i] - 1, 0);
      solve(zero[zero.size() - 1] + 1, n - 1, 0);
    } else solve(0, n - 1, 0);
    cout << sol;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
//import java.math.BigInteger;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int D = sc.nextInt();
        int count = 0;
        //String str = sc.next();
        //char[] c = str.toCharArray();
        //int[] p = new int[N];
        //a[0] = Character.getNumericValue(str.charAt(0));
        //boolean test = false;
        
        for(int k=4; k<=M; k++){
        for(int i=2; i<=D/10; i++){
            for(int j=2; j<=9; j++){
                if(i==D/10 && j>D%10){
                    break;
                }
                if(i*j == k){
                    count++;
                    //System.out.println(i+":"+j);
                }
            }
            //System.out.println(count);
        }
        }
        System.out.println(count);
    }
}


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

int main() {
  int N;
  cin >> N;
  map<int, int> D;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    if (D.count(d)) D.at(d)++;
    else D[d] = 1;
  }
  int M;
  cin >> M;
  string ans = "YES";
  for (int i = 0; i < M; i++) {
    int t;
    cin >> t;
    if (D.count(t)) {
      D.at(t) -= 1;
      if (D.at(t) == 0) D.erase(t);
    }
    else {
      ans = "NO";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 12944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll int t,sum;
    cin>>t>>sum;
    ll int count=0;
    while(t--){
       ll int a,b;
        cin>>a>>b;
        double c=pow((a*a+b*b),0.5);
        if(c<=sum)
        count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 4296
/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */
/*my variables are anime character */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define vll vector<ll>
#define pll pair<ll , ll> 
#define vpll vector<pll>
#define umpll unordered_map<ll , ll>
#define mpll map<ll , ll>
#define sll set<ll>
#define stll stack<ll>
#define FIO  ios_base::sync_with_stdio(false);  cin.tie(0); cout.tie(0);



ll N,T;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
  char c;
  cin>>c;

  if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
    cout<<"vowel\n";

  else
    cout<<"consonant\n";
  
}



int main(){
  
  FIO 
  
 solve();

  return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int dp[100010];

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

    int N;
    cin >> N;
    fill_n(&dp[0], sizeof(dp) / sizeof(dp[0]), I_INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        if (dp[i] == I_INF) continue;
        int ni;
        ni = i + 1;
        if (i + 1 <= N)
            dp[ni] = min(dp[ni], dp[i] + 1);
        int base = 6;
        while (i + base <= N) {
            ni = i + base;
            dp[ni] = min(dp[ni], dp[i] + 1);
            base *= 6;
        }
        base = 9;
        while (i + base <= N) {
            ni = i + base;
            dp[ni] = min(dp[ni], dp[i] + 1);
            base *= 9;
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];



void solve() {
  int a,b;
  cin >> a >> b;

  if (a%2!=0 && b%2!=0) cout << "Yes" << endl;
  else cout << "No" << endl;

}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256