akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n=ir.nextInt();
		int k=ir.nextInt();
		out.println(k*(int)Math.pow(k-1,n-1));
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int u[110000], v[110000], w[110000];
vector<pint> G[110000];
bool color[110000], visited[110000];

void dfs(int x, bool c) {
    visited[x] = true;
    color[x] = c;
    for (int i = 0; i < G[x].size(); i++) {
        if (visited[G[x][i].first])continue;
        if (G[x][i].second & 1)dfs(G[x][i].first, !c);
        else dfs(G[x][i].first, c);
    }
}

signed main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> u[i] >> v[i] >> w[i];
        G[u[i]].push_back(pint(v[i], w[i]));
        G[v[i]].push_back(pint(u[i], w[i]));
    }
    dfs(1, 0);
    for (int i = 1; i <= N; i++) {
        cout << color[i] << endl;
    }

}

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

int MAX = 1000000;

int f(int n) {
  if (n % 2 == 0) return n * 0.5;
  else return 3 * n + 1;
}

int main() {
  vector<int> a(MAX);
  int s;

  cin >> s;
  a.at(0) = s;

  int i = 0;
  while(i < MAX) {
    i++;
    a.at(i) = f(a.at(i - 1));

    for (int n = 0; n < i; n++) {
      //cout << i << ":" << n << ":" << a.at(n) << endl;
      if (a.at(n) == a.at(i)) {
        cout << i + 1 << endl;
        return 0;
      }
    }
  }

  for (int j = 0; j < 10; j++) {
    cout << a.at(j) << endl;
  }
}


Measured memory_bytes: 4096
using System;using System.Linq;class E{static int[]G()=>Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();static void Main(){long N=G()[0],a=1,l,r,i=0;int[]A=G(),B=G();for (;i<N;i++){l=i==0||A[i-1]<A[i]?A[i]:0;r=i==N-1||B[i]>B[i+1]?B[i]:0;if(l+r==0)a=a*Math.Min(A[i],B[i])%1000000007;else if(r>A[i]|l>B[i])a=0;}Console.WriteLine(a);}}

Measured memory_bytes: 25296
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define inf (1LL<<60)

int dp[22][1 << 22];


int solve2(int ladke, int ladki, vector<vector<int>> &a, int n) {
	if (ladke == n && ladki == 0)return 1;
	else if (ladke == n)return 0;
	if (dp[ladke][ladki] != -1)return dp[ladke][ladki];
	int i;
	int ans = 0;
	for (i = 0; i < n; i++) {
		if (a[ladke][i] == 1 && (ladki & (1<<i)) != 0) {
			ans = (ans + solve2(ladke + 1, (ladki ^ (1 << i)), a, n)) % mod;
		}
	}
	return dp[ladke][ladki] = ans;
}

void solve() {
	int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<vector<int>> a(n, vector<int>(n));
	int i, j;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++)cin >> a[i][j];
	}
	cout << solve2(0, (1 << n) - 1, a, n);
}

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 724556
n,m,x = map(int,input().split())
books = [list(map(int, input().split())) for _ in range(n)]

ans = []

for i in range( 1 << n):
    total = [0] * (m + 1)
    for j in range(n):
        if (i >> j) & 1:
            total = [total[k] + books[j][k] for k in range(m+1)]

    over = True
    for j in range(1, m+1):
        if total[j] < x:
            over = False
    if over:
        ans.append(total[0])

if len(ans) > 0:
    print(min(ans))
else:
    print('-1')


Measured memory_bytes: 9252
def is_poor(triple_numbers):
    count_map = {}
    for num in triple_numbers:
        if num not in count_map:
            count_map[num] = 1
        else:
            count_map[num] += 1
    
    for key, value in count_map.items():
        if value == 2:
            return True
    return False

is_p = is_poor(list(map(int, input().split())))

if is_p:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
N,M=map(int,input().split())
sc=[]
for i in range(M):
  sc.append(list(map(int,input().split())))

ans=-1
cnt=10**(N-1)
if cnt==1:cnt-=1
while True:
  if len(str(cnt))>N:break
  if len(str(cnt))!=N:continue
  ret=True
  for i in range(M):
    if str(cnt)[sc[i][0]-1]!=str(sc[i][1]):
      ret=False
      break
  if ret:
    ans=cnt
    break
  cnt+=1
print(ans)

Measured memory_bytes: 9216
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

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

    string S;
    cin >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }

    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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


const ll MRINF = 5000000000000000;
int main() {

    int R; cin >> R;
    if(R < 1200){
        cout << "ABC" << endl;
    }else if(R < 2800){
        cout << "ARC" << endl;      
    }else{
        cout << "AGC" << endl;     
    }
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void)
{
  char roma[101]={'\0'};

  while(scanf("%s",roma)!=EOF){
    int i;
    int sum=0;
    int tmp[101]={0};

      if(roma[0]=='I')
	tmp[0]=1;
      else if(roma[0]=='V')
	tmp[0]=5;
      else if(roma[0]=='X')
	tmp[0]=10;
      else if(roma[0]=='L')
	tmp[0]=50;
      else if(roma[0]=='C')
	tmp[0]=100;
      else if(roma[0]=='D')
	tmp[0]=500;
      else
	tmp[0]=1000;

    for(i=1;roma[i]!='\0';i++){
      if(roma[i]=='I')
	tmp[i]=1;
      else if(roma[i]=='V')
	tmp[i]=5;
      else if(roma[i]=='X')
	tmp[i]=10;
      else if(roma[i]=='L')
	tmp[i]=50;
      else if(roma[i]=='C')
	tmp[i]=100;
      else if(roma[i]=='D')
	tmp[i]=500;
      else
	tmp[i]=1000;
      if(tmp[i-1]<tmp[i])
	tmp[i-1]=-tmp[i-1];
      sum+=tmp[i-1];
    }
    sum+=tmp[i-1];
    printf("%d\n",sum);

    char roma[101]={'\0'};
  }

  return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-6
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

long long high, low, chs, lis[55], n, ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	REP (i, n) cin >> lis[i];
	int cnt = 0;
	int i = 0;
	while (cnt <= n) {
		int pos = i % n;
		if (lis[pos] >= n) cnt = 0;
		else cnt++;
		ans += lis[pos] / n;
		REP (j, n) if (j != pos) lis[j] += lis[pos] / n;
		lis[pos] %= n;
		i++;
	}
	cout << ans;
}	


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
//        int b = int.Parse(input[2]);
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
            WriteLine(Max(n-m,0));
    }
}

Measured memory_bytes: 11092
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll n; cin >> n; string s; cin >> s;
    ll rc = 0, bc = 0;
    REP(i, n){
        if(s[i] == 'R') rc++;
        if(s[i] == 'B') bc++;
    }
    cout << (rc > bc ? "Yes" : "No") <<endstr;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main
}//class

Measured memory_bytes: 33156
#pragma region Imports
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#pragma endregion
#pragma region Macros
#pragma GCC optimize (2)
#define uns unsigned
#define out cout
#define in cin
#define au auto
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define elif else if
#define sz(x) x.size()
#define fl(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define fli(i, a, b, c) for(int (i)=a;(i)<(b);(i)+=(c))
#define fr(i, x) for(int (i)=(x)-1;(i)>=0;(i)--)
#define fb(i, x) for(int (i)=0;(i)<(x);(i)++)
#define fa(i, x) for(auto& (i):(x))
#define ia(a, n) for(int qw=0;qw<(n);qw++)cin>>(a)[qw];
#define oa(a, n) for(int qw=0;qw<(n);qw++)cout<<(a)[qw]<<" ";
#define im(a, n, m) fb(i,(n))fb(j,(m))cin>>(a)[i][j];
#define om(a, n, m) fb(i,(n))fb(j,(m))cout<<(a)[i][j]<<" \n"[j==(m)-1];
#define eb(v, x) (v).emplace_back(x);
#define seb(s, x) (s).emplace(x);
#define pr(x, y) pair<x,y>
#define vr(x) vector<x>
#define mp(x, y) make_pair(x,y)
#define hm(x, y) map<x,y>
#define um(x, y) unordered_map<x,y>
#define stk(x) stack<x>
#define qu(x) queue<x>
#define dq(x) deque<x>
#define pq(x) priority_queue<x>
#define pqm(x) priority_queue<x,vector<x>,greater<(x)>>
#define mem(a, x) memset(a,(x),sizeof(a));
#define fi(x) (x).first
#define se(x) (x).second
#define ql(x) int tc;tc=(x);if(tc==-1)cin>>tc;while(tc--)
#define srt(x) sort((x).begin(),(x).end());
#define pops(y, x) auto (y)=(x).front();(x).pop();
#define ppc(x) __builtin_popcount((x))
#define all(x) (x).begin(),(x).end()
#define sieve(b, n) bool (b)[(n)];mem((b),true);int sq=int(sqrt(n))+1;(b)[0]=(b)[1]=false;fl(i,2,sq)if((b)[i])fli(j,i*i,n,i)(b)[j]=false;
#define dbg(x) cout<<#x<<" "<<(x)<<"\n";
#pragma endregion
#pragma region Typedefs and Consts
typedef long long int ll;
typedef unsigned long long int ull;
typedef string stg;
typedef float flo;
typedef char chr;
typedef vector<int> vi;
const ull mod = 1000000007;
const int imx = INT_MAX;
const int imn = INT_MIN;
const ll lmx = LLONG_MAX;
const ll lmn = LLONG_MIN;
#pragma endregion
#pragma region Functions
inline ull powm(ull x,ull y,bool b=false,ull m=mod){ if(b){ ull t=1;x%=m;while(y>0){ if(y%2)t=(t*x)%m;y=y>>1;x=(x*x)%m; }return t; }else
    { ull t=1;while(y>0){ if(y&2)t*=x;y=y>>1;x*=x; }return t;}}
inline ll gcd(ll a,ll b){a=abs(a);b=abs(b); while(b!=0){ ll c=a%b;a=b;b=c;}return a;}
#pragma endregion

//cout<<"Case #"+to_string(tc+1)+": "+to_string(z)<<endl;
int d[100001][2];
int f(int a[],int n,int k,int p){
  if(k==0)
    return p^1;
  if(k<0)
    return p;
  if(d[k][p]==-1){
    d[k][p]=p^1;
    fb(i,n)
      if(f(a,n,k-a[i],p^1)==p)
        return d[k][p]=p;
  }
  return d[k][p];
}
int main() {
  fio
  int n,k;
  in>>n>>k;
  int a[n];
  ia(a,n)
  fb(i,100001)
    d[i][0]=d[i][1]=-1;
  out<<(f(a,n,k,0)==0?"First":"Second");
  return 0;
}

Measured memory_bytes: 8832
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    rep(i,n-1){
        ans *= (k-1);
    }
    cout << ans << endl;
    return 0;
}


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

#define F first 
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, k;
int nxt[N], c[N];

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i ++ ) cin >> nxt[i];
    for (int i = 1; i <= n; i ++ ) cin >> c[i];

    LL res = -1e18;
    for (int i = 1; i <= n; i ++ )
    {
        int cycle_cnt = 0, v = i;
        LL cycle_sum = 0;
        while (true)
        {
            cycle_cnt ++ ;
            cycle_sum += c[v];
            v = nxt[v];
            if (v == i) break;
        }

        int cnt = 0;
        LL sum = 0;
        v = i;
        while (true)
        {
            cnt ++ ;
            sum += c[v];
            if (cnt > k) break;
            
            int num = (k - cnt) / cycle_cnt;
            LL t = sum + max(0LL, cycle_sum) * num;
            res = max(res, t);

            v = nxt[v];
            if (v == i) break;
        }
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int32_t main()
{
  long long n;cin>>n;
  long long ans=0;
  for(long long i=1;i<=n;i++)
  {
    for(long long j=1;j<=n;j++)
    {
      for(long long k=1;k<=n;k++)
      {
        ans+=__gcd(i,__gcd(j,k));
      
      }
    }
  }cout<<ans;
           return 0;
}

Measured memory_bytes: 3600
N = gets.to_i
D, X = gets.split.map(&:to_i)
c = 0
N.times do
  a = gets.to_i

  j = 0
  while true
    if a * j + 1 <= D
      c += 1
    else
      break
    end
    j += 1
  end
end

puts c + X

Measured memory_bytes: 1788
import sys 
N, M = map(int, input().split())
A = list(map(int, input().split()))  
A = sorted(A,reverse=True)
for i in range(M):
    if A[i] < sum(A)*1/(4*M):
        #print(A[i],sum(A)*1/(4*M))
        print('No')
        sys.exit()
print('Yes')
#print(sum(A)*1/(4*M))

Measured memory_bytes: 3060
N,K=(int(i) for i in input().split())
h=[int(input()) for i in range(N)]
h.sort()
m = h[K-1] - h[0] 
for i in range(N-K+1):
    d = h[i+K-1] -h[i]
    if m>d:
        m = d
print(m)

Measured memory_bytes: 7384
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: i64,
   }
   if n == 0 {
      println!("0");
   } else if n > 0 {
      let mut x = 1;
      let mut y = 0;
      while x < n {
         y += 2;
         x += 1 << y;
      }
      let d = x - n;
      let mut mt = vec![0u8; y + 1];
      mt[0] = 1;
      for i in 0..y {
         if (d >> i) & 1 == 1 {
            if i % 2 == 1 {
               mt[y - i] = 1;
            }
         } else {
            if i % 2 == 0 {
               mt[y - i] = 1;
            }
         }
      }
      for m in mt {
         print!("{}", m);
      }
      println!("");
   } else {
      let n = -n;
      let mut x = 2;
      let mut y = 1;
      while x < n {
         y += 2;
         x += 1 << y;
      }
      let d = x - n;
      let mut mt = vec![0u8; y + 1];
      mt[0] = 1;
      for i in 0..y {
         if (d >> i) & 1 == 0 {
            if i % 2 == 1 {
               mt[y - i] = 1;
            }
         } else {
            if i % 2 == 0 {
               mt[y - i] = 1;
            }
         }
      }
      for m in mt {
         print!("{}", m);
      }
      println!("");
   }
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using edge = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    set<edge> S;
    rep(i, 0, N) rep(j, i + 1, N) {
        S.insert(edge(i, j));
    }
    if (N % 2) {
        rep(i, 0, N - 1) {
            S.erase(edge(i, N - 2 - i));
        }
    } else {
        rep(i, 0, N) {
            S.erase(edge(i, N - 1 - i));
        }
    }
    cout << S.size() << endl;
    for (auto& e : S) {
        cout << e.first + 1 << ' ' << e.second + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;

class Program
{
  	static void Main(string[] args)
    {
    	var size = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        for(var i = 0; i < size[0]; i++)
        {
        	var pixel = Console.ReadLine();
            Console.WriteLine(pixel);
            Console.WriteLine(pixel);
        }
    }
}

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

typedef long long ll;
using namespace std;

int main() {
    int n;
    double t, a;
    cin >> n >> t >> a;
    int ans = 1;
    float cur_diff = 0;
    for (int i = 0; i < n; i++) {
        double h;
        cin >> h;
        double ave = t - 0.006 * h;
        if (i == 0) {
            cur_diff = abs(ave - a);
        } else {
            if (abs(ave - a) < cur_diff) {
                cur_diff = abs(ave - a);
                ans = i + 1;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807

void solve()
{

  int N;
  cin>>N;
  vector<int> vec(N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }

      for (int i_1 = 0; i_1 < N; i_1++)
    {
      cout<<vec[i_1];
      if(i_1 != N - 1) cout<<" ";
    }

    cout<<endl;

  for (int i = 1; i < vec.size(); i++)
  {
    int key = vec[i];
    int j = i - 1;
    while((j >= 0)&&(vec[j] > key) )
    {
      vec[j+1] = vec[j];
      j--;
    }
    vec[j + 1] = key;

    for (int i_1 = 0; i_1 < N; i_1++)
    {
      cout<<vec[i_1];
      if(i_1 != N - 1) cout<<" ";
    }

    cout<<endl;
    
    
  }
  
  
  
  return;
}

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

  solve();

  return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int x, y;
	while(1) {
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x < y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;

	}
}

Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >>h[i];
  vector<ll> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  vector<bool> is_high(n, true);
  rep(i, m) {
    if (h[a[i]] < h[b[i]]) {
      is_high[a[i]] = false;
    } else if(h[a[i]] > h[b[i]]) {
      is_high[b[i]] = false;
    } else {
      is_high[a[i]] = false;
      is_high[b[i]] = false;
    }
  }

  ll ans = 0;
  rep(i, n) {
    if (is_high[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5556
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int R, C, K;
    cin >> R >> C >> K;

    vector<vector<int>> M(R, vector<int>(C, 0));
    for (int i = 0; i < K; ++i) {
        int x, y, v;
        cin >> x >> y >> v;
        --x, --y;
        M[x][y] = v;
    }

    vector<vector<long long>> dp(C + 1, vector<long long>(4, -1));
    auto ndp = dp;
    dp[0 + 1][0] = 0;

    for (int i = 0; i < R; ++i) {
        for (auto& V : ndp) {
            fill(V.begin(), V.end(), 0);
        }

        for (int j = 0; j < C; ++j) {
            long long mx = 0;
            for (int k = 0; k <= 3; ++k) {
                mx = max(mx, dp[j + 1][k]);
            }
            for (int k = 0; k <= 3; ++k) {
                ndp[j + 1][k] = max(ndp[j + 1][k], max(ndp[j][k], mx));
                if (k > 0) {
                    ndp[j + 1][k] = max(ndp[j + 1][k], max(ndp[j][k - 1], mx) + M[i][j]);
                }
            }
        }
        swap(ndp, dp);
    }

    long long res = 0;
    for (int i = 0; i <= 3; ++i) {
        res = max(res, dp[C][i]);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 39300
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define ve vector<ll>
#define vell vector<ll>
#define ve_pa vector<pair<ll,ll> >
#define pb push_back
#define mod 1000000007
#define ld long double 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define mll map<ll,ll>
#define mii map<int,int>
#define m_ve map<ll,vell >
#define min3(x,y,z) min(x,min(y,z))
#define max3(x,y,z) max(x,max(y,z))
#define se second
#define check cout<<"s"
#define checkx(x) cout<<x
#define W(x) while(x--)
#define ld long double
#define popcount(x) __builtin_popcountll(x)
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
//int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); 
cout.tie(NULL);
int n;cin>>n;
ll a[n];
for(int i=0;i<n;i++)
cin>>a[i];
ll pre[n];
pre[n-1]=a[n-1];
for(int i=n-2;i>=0;i--)
pre[i]=(pre[i+1]+a[i])%mod;

ll ans=0;
for(int i=0;i<n-1;i++)
{
	ans=(ans+a[i]*pre[i+1])%mod;
}
cout<<ans;




}
 
 


Measured memory_bytes: 6760
n = int(input())
B = list(map(int,input().split()))
A = [0]*n
A[0] = B[0]
for i in range(1,n-1):
    if B[i-1] >= B[i]:
        A[i] = B[i]
    else:
        A[i] = B[i-1]
else:
    A[n-1] = B[n-2]
print(sum(A))

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

using namespace std;

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

    int N;
    cin>>N;

    int T[N+1];
    for(int i=1;i<=N;i++)
        cin>>T[i];

    int M,p,x;
    cin>>M;

    while(M--)
    {
        int res=0;
        cin>>p>>x;

        for(int i=1;i<=N;i++)
        {
            if(i==p)
                res+=x;
            else
                res+=T[i];


        }

        cout<<res<<endl;

    }


    return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  for(int i=1;i<1500;i++){
    if( i*8/100 == a && i*1/10 == b ){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;


int main()
{
	cin >> s;
	cout << s.substr(0, sz(s) - 8) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<int> H(N);
    int i;
    for(i=0; i<N; i++) cin >> H.at(i);

    int ans = 0;
    int tmp = 0;

    for(i=1; i<N; i++){
        if(H.at(i-1) >= H.at(i)){
            tmp++;
        }
        else{
            tmp = 0;
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640
n, c, k = map(int, input().split())
t = list(int(input()) for _ in range(n))

t.sort()
slash = 0
start = t[0]
bus = 1 
for i in range(1, n):
    if t[i] > start + k:
        start = t[i]
        slash += 1
        bus = 1
    elif bus < c:
        bus += 1
    else:
        start = t[i]
        slash += 1
        bus = 1

print(slash + 1)

Measured memory_bytes: 7396
N = int(input())
for m in range(int(N/4+1), 3501):
  for n in range(m, 3501):
    if 4 * m * n - N * n - N * m == 0:
      h = -10**10
    else:
      h = m * N * n / (4 * m * n - N * n - N * m)
    if h == int(h) and 0 <= h <= 3500:
      print(int(h),m,n)
      exit()
    

Measured memory_bytes: 9140
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです

int main(void){
  string s;
  map<char,int>cnt;
  while(getline(cin,s)){
    int l=s.size();
    if(l==0)break;
    for(int i=0;i<l;i++)cnt[(char)tolower(s[i])]++;
  }
  for(char c='a';c<='z';c++)printf("%c : %d\n",c,cnt[c]);
  return 0;
}



Measured memory_bytes: 3336
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>


int main(){
	int X;
	scanf("%d", &X);
	int n= int(X/100);
	int amari = X-n*100;
	if (amari>=0 && amari<=n*5){
		printf("1\n");
	} else {
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		
		int number = r * 100 + g * 10 + b;
		
		if (number % 4 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	ll sum = 0;
	ll m;
	cin >> m;
	ll c, d;
	REP(i, m){
		cin >> d >> c;
		sum += d * c;
		ans += c;
	}
	ans --;
	while(sum > 9){
		ll sho = sum / 10;
		sum -= sho * 9;
		ans += sho;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 101;
ll cnt[MAX_N * MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(ll x = 1; x <= MAX_N; x ++) {
        for(ll y = 1; y <= MAX_N; y ++) {
            for(ll z = 1; z <= MAX_N; z ++) {
                ll now = x * x + y * y + z * z + x * y + z * x + y * z;
                if(now <= n) {
                    cnt[now] ++;
                }
            }
        }
    }
    for(int i = 1; i <= n; i ++ ){
        cout << cnt[i] << endl;
    }
    return 0;
}




Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

// Segment Tree
template <class M = int> struct ST {
    int n, lev;
    vector<M> d;
    virtual M f(M, M) = 0;
    const M e1;

    ST(int n_, const M& e1) : e1(e1) {
        for (n = 1, lev = 0; n < n_; n <<= 1, ++lev);
        d.assign(n << 1, e1);
    }

    // k: 0-indexed
    void set(int k, const M& x) {
        d[k + n] = x;
    }

    void build() {
        for (int i = n - 1; i > 0; --i) {
            d[i] = f(d[(i << 1) | 0], d[(i << 1) | 1]);
        }
    }

    // k: 0-indexed
    void update(int k, const M& x) {
        for (d[k += n] = x; k > 1; k >>= 1) {
            d[k] = f(d[(k << 1) | 0], d[(k << 1) | 1]);
        }
    }

    // [l, r)
    // l, r: 0-indexed
    M query(int l, int r) {
        M L = e1, R = e1;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) L = f(L, d[l++]);
            if (r & 1) R = f(d[--r], R);
		}
        return f(L, R);
    }

    void dump(int);
};

// O(log max{a, b})
long long gcd(long long a, long long b) {
    while (b) {
        long long c = a % b;
        a = b;
        b = c;
    }
    return a;
}

// Range GCD Query (RGQ)
template <class M> struct RGQ : ST<M> {
    RGQ(int n, M e1 = 0) : ST<M>(n, e1) {}
    M f(M a, M b) override { return gcd(a, b); }
};

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP (i, N) cin >> A[i];
    RGQ<int> R(N);
    REP (i, N) R.set(i, A[i]);
    R.build();
    int ans = 0;
    REP (i, N) {
        ans = max(ans, gcd(R.query(0, i), R.query(i + 1, N)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3072
N, M, X, Y = map(int, input().split())
XY = []
for i in range(2):
    tmp = list(map(int, input().split()))
    XY.append(tmp)

max_x = max(XY[0])
max_x = max(X, max_x)
min_y = min(XY[1])
min_y = min(Y, min_y)

print("No War" if max_x < min_y else "War")


Measured memory_bytes: 3060
#include <iostream>

int main(void){
    int Map[4][4] = {0};
    
    for(int i = 0; i < 3; i++){
        int A, B;
        std::cin >> A >> B;
        Map[A-1][B-1] = Map[B-1][A-1] = 1;
    }

    for(int i = 0; i < 4; i++){
        bool isPass = false;
        for(int j = 0; j < 4; j++){
            if(i != j){
                if(Map[i][j] != 1){
                    isPass = true;
                }
            }
        }
        if(i <= 2){
            if(!isPass){
                std::cout << "NO";
                return 0;
            }
        }
        else{
            if(!isPass){
                std::cout << "NO";
                return 0;
            }
            else{
                std::cout << "YES";
                return 0;
            }            
        }

    }
}

Measured memory_bytes: 256
#include <iostream>
#define int long long
using namespace std;
signed main(){
  int N;
  cin >> N;
  for(int i = 1; i < 3500; ++i){
    for(int j = 1; j < 3500; ++j){
      if(4*i*j-N*(i+j) && (N*i*j)%(4*i*j-N*(i+j)) == 0 && (N*i*j)/(4*i*j-N*(i+j)) > 0){
	cout << i << " " << j << " " << (N*i*j)/(4*i*j-N*(i+j)) << endl;
	return 0;
      } 
    }    
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        Long[] X = new Long[N];
        Long[] Y = new Long[N];
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextLong();
            Y[i] = sc.nextLong();
        }

        int count = 0;

        for (int i = 0; i < N; i++) {
            Long p2 = X[i] * X[i];
            Long q2 = Y[i] * Y[i];
            double length = Math.sqrt(p2 + q2);

            if (length <= D){
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 61496
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int l; int m; int n;
        int savings;
        int month;
        int stop;
        
        while((l=sc.nextInt())!=0){
            savings=0;
            month=0;
            stop=0;
            for(int i=1;i<=12;i++){
                m=sc.nextInt();
                n=sc.nextInt();

                savings+=m-n;
                if(savings>=l && stop==0){ month=i; stop++; }
            }
            if(month!=0){ System.out.println(month); }
            else{ System.out.println("NA"); }

        }
    }
}


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

int main(){
    int s;
    cin >> s;
    map<int,int> mp;

    int i = 1;
    while (!mp.count(s)){
        mp[s] = i++;
        if (s % 2 == 0){
            s = s / 2;
        }
        else {
            s = 3*s + 1;
        }
    }
    cout << i << endl;
}

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

int main(){
    int n, W; cin >> n >> W;
    int v[n+1], w[n+1];
    ll ans = 0;
    vector<vector <ll> > dp(n+1, vector<ll>(W+1, 0));
    for(int i = 0; i < n; i++){
        cin >> w[i+1] >> v[i+1];
    }
    for(int i = 1; i < n+1; i++){
        for(int l = 1; l < W+1; l++){
            if(l-w[i] >= 0){
                dp[i][l] = max(dp[i-1][l-w[i]]+v[i], dp[i][l]);
                ans = max(ans, dp[i][l]);
            }
            dp[i][l] = max(dp[i][l], dp[i-1][l]);
        }
    }
    cout << ans << endl;
}

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

using namespace std;
 int main() {
   long long N;
   cin >> N;
   vector<long long> vec(N);
   for(long long i=0; i<N; i++) {
 cin >>vec.at(i);
   }
if (N==2) {
  cout << abs(vec.at(1)-vec.at(0)) << endl;
}
   

     
 else if(N >2) {
  long long dp[N+1];
   dp[0]=0;
   dp[1]=0;
   dp[2]=abs(vec.at(1)-vec.at(0));
   for (int i = 1; i < N-1; ++i) {
        dp[i + 2] = min(dp[i]+abs(vec.at(i+1)-vec.at(i-1)), dp[i+1]+abs(vec.at(i+1)-vec.at(i)));
   }
   cout << dp[N] << endl;
 }
}
   


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a_cost[100005];
vector<int>vec_edge[100005];
int bin[100005];
int deep[100005];
int fin(int n);
int uid[100005];
typedef struct node
{
    int id;
    LL val;
    bool operator <(const node &cx)const
    {
        return cx.val < val;
    }
} ss;
priority_queue<ss>que;
ss ans[100005];
bool cmp(node p,node q);
int main(void)
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0; i < n; i++)
        scanf("%lld",&a_cost[i]);
    for(int i = 0; i < n; i++)
        bin[i] = i,deep[i] = 1;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        int nx = fin(x);
        int ny = fin(y);
        if(nx!=ny)
        {
            if(deep[nx] > deep[ny])
            {
                deep[nx] += deep[ny];
                bin[ny] = nx;
            }
            else
            {
                deep[ny] += deep[nx];
                bin[nx] = ny;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        int id = fin(i);
        vec_edge[id].push_back(i);
    }
    int cn = 0;
    for(int i = 0; i < n; i++)
    {
        if(vec_edge[i].size())
        {
            ans[cn] = node{i,vec_edge[i].size()};
            cn++;
        }
    }
    sort(ans,ans+cn,cmp);
    LL sum = 0;
    int cnt = 0;
    for(int i = 0; i < cn; i++)
    {
        int ip = ans[i].id;
        if(vec_edge[ip].size())
        {
            int id = vec_edge[ip][0];
            LL min_val = a_cost[id];
            for(int j = 0; j < vec_edge[ip].size(); j++)
            {
                int ic = vec_edge[ip][j];
                if(min_val > a_cost[ic])
                    id = ic,min_val = a_cost[ic];
            }
            sum += min_val;
            cnt++;
            for(int j = 0; j < vec_edge[ip].size(); j++)
            {
                int ic = vec_edge[ip][j];
                if(ic!=id)
                que.push(node{ic,a_cost[ic]});
            }
        }
    }
    //cout<<cnt<<endl;
    if(cnt == 1)
        sum = 0;
    else
    {
        int cns = cnt - 2;
        int c_size = que.size();
        //cout<<c_size<<endl;
        if(c_size < cns)
        {
            sum = -1;
        }
        else
        {
            for(int i = 0; i < cns; i++)
            {
                sum += que.top().val;
                que.pop();
            }
        }
    }
    if(sum == -1)
        printf("Impossible\n");
    else printf("%lld\n",sum);
    return 0;
}
int fin(int n)
{
    while(n!=bin[n])
        n = bin[n];
    return n;
}
bool cmp(node p,node q)
{
    return p.val > q.val;
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <tuple>
#include <queue>
using namespace std;

int H, W, sx, sy, gx, gy, col[13][13], G[130], cnts, bit[130]; char c[13][13]; long long J[130], JJ[130];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
map<long long, int>Map[13][13];

void init() {
	H = 0; W = 0; sx = 0; sy = 0; gx = 0; gy = 0; cnts = 0;
	for (int i = 0; i < 13; i++) {
		for (int j = 0; j < 13; j++) { col[i][j] = 0; Map[i][j].clear(); c[i][j] = 0; }
	}
	for (int i = 0; i < 130; i++) { G[i] = 0; J[i] = 0; JJ[i] = 0; }
}

void dfs1(int px, int py) {
	if (px < 0 || py < 0 || px >= H || py >= W) return;
	if (col[px][py] >= 1 || c[px][py] != 'X') return;
	col[px][py] = cnts; G[cnts]++;
	for (int i = 0; i < 4; i++) {
		dfs1(px + dx[i], py + dy[i]);
	}
}

int main() {
	while (true) {
		init();
		cin >> W >> H; if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> c[i][j];
				if (c[i][j] == 'S') { sx = i; sy = j; c[i][j] = '.'; }
				if (c[i][j] == 'G') { gx = i; gy = j; c[i][j] = '.'; }
			}
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (c[i][j] != 'X' || col[i][j] >= 1) continue;
				cnts++; dfs1(i, j);
			}
		}
		JJ[1] = 1;
		for (int i = 1; i <= cnts; i++) { J[i] = (G[i] / 2 + 1); if (i >= 2) JJ[i] = JJ[i - 1] * J[i - 1]; }

		queue<tuple<int, int, long long>> Q;
		Q.push(make_tuple(sx, sy, 0)); Map[sx][sy][0] = 1;
		
		int ans = (1 << 30);

		while (!Q.empty()) {
			int px = get<0>(Q.front()), py = get<1>(Q.front()); long long V = get<2>(Q.front()); Q.pop();
			int cost = Map[px][py][V];
			if (px == gx && py == gy) {
				ans = min(ans, cost); break;
			}

			long long VV = V;
			for (int i = 1; i <= cnts; i++) { bit[i] = VV % J[i]; VV /= J[i]; }

			for (int i = 0; i < 4; i++) {
				int vx = px + dx[i], vy = py + dy[i];
				if (vx < 0 || vy < 0 || vx >= H || vy >= W || c[vx][vy] == '#') continue;

				long long I = V; bool die = false;
				if (col[vx][vy] >= 1) {
					I += JJ[col[vx][vy]];
					if (bit[col[vx][vy]] + 1 == J[col[vx][vy]]) die = true;
				}
				if (die == true) continue;
				
				if (Map[vx][vy][I] == 0) {
					Map[vx][vy][I] = cost + 1; Q.push(make_tuple(vx, vy, I));
				}
			}
		}
		cout << ans - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 50596
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	int cou[50][26] = { 0 };
	vector<string> s(50);
	int al[26] = { 0 };

	int n;
	cin >> n;
	rep(i, 0, n) {
		cin >> s[i];
	}

	rep(i, 0, 26) {
		al[i] = 2501;
	}

	rep(i, 0, n) {
		rep(j, 0, s[i].size()) {
			cou[i][(int)(s[i][j]) - 97]++;
		}
	}

	rep(i, 0, n) {
		rep(j, 0, 26) {
			al[j] = min(al[j], cou[i][j]);
		}
	}

	rep(i, 0, 26) {
		if (al[i] != 0 && al[i] != 2501) {
			while (al[i] > 0) {
				cout << (char)(i + 97);
				al[i]--;
			}
		}
	}

	cout << endl;


	return 0;
}

Measured memory_bytes: 256