akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=1e10+7;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;

    int n,m,x,val;
    vi c;
    cin>>n>>m>>x;
    vi adj[n+2];
    int ans=INT_MAX;
    rep(i,n)
    {
        cin>>val;
        c.pb(val);

        rep(j,m)
        {
            cin>>val;
            adj[i].pb(val);
        }
    }

    repa(i,1,pow(2,n)-1)
    {
        vi curr(m,0);
        int sum=0,flag=0;
        rep(j,n)
        {
            if(i&(1<<j))
            {
                rep(k,m)
                {
                    curr[k]+=adj[j][k];
                }
                sum+=c[j];
            }
        }
        rep(j,m)
        {
            if(curr[j]<x)
            {
                flag=1;
                break;
            }
        }
        if(!flag)
        {
            ans=min(ans,sum);
        }
    }
    if(ans==INT_MAX) cout<<"-1";
    else cout<<ans<<endl;
}

Measured memory_bytes: 4096
#include<stdio.h>
char s[100][100];
int row[100], line[100];
int main(){
  int a, b, i, j, k = 0;
  
  scanf("%d %d", &a, &b);
  for(i = 0; i < a; i++){
    scanf("%s", s[i]);
  }
  
  for(i = 0; i < a; i++){
    for(j = 0; j < b; j++){
      if(s[i][j] == '#'){
        break;
      }
    }
    if(j != b){
      for(j = 0; j < b; j++){
        s[k][j] = s[i][j];
      }
      k++;
    }
  }
  a = k;
  k = 0;
  for(i = 0; i < b; i++){
    for(j = 0; j < a; j++){
      if(s[j][i] == '#'){
        break;
      }
    }
    if(j != a){
      for(j = 0; j < a; j++){
          s[j][k] = s[j][i];
      }
      k++;
    }
  }
  b = k;
  
  for(i = 0; i < a; i++){
    for(j = 0; j < b; j++){
      printf("%c", s[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;


int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        //???????????±?????§????????????
        char c1[1000],c2[1000];
        scanf("%s",&c1);
        scanf("%s",&c2);
        string s1,s2;
        s1=c1, s2=c2;
        if(s1=="0" && s2=="0"){
            printf("0\n");
            continue;
        }
        //?????¢?????????0????????§?????°???????????????
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        int n=max(s1.size(),s2.size())+1;
        for(int i=s1.size();i<n;i++){
            s1+='0';
        }
        for(int i=s2.size();i<n;i++){
            s2+='0';
        }
        string res;

        //b?????°?????????????????¨??????????????¨
        int b=0;
        for(int i=0;i<max(s1.size(),s2.size());i++){
            int u=s1[i]-'0'+s2[i]-'0'+b;
            b=(u>=10); u%=10;
            res+=u+'0';
        }

       
        reverse(res.begin(),res.end());
        string res2;

        //????????¨?????´???0??????????????????0??\????????°??????????????¨?????????????????¨???????????????????¶????
        int j=0;
        while(res[j]=='0') j++;
        for(;j<res.size();j++){
            res2+=res[j];
        }

        if(res2.size()>80){
            printf("overflow\n");
        }else{
            printf("%s\n",res2.c_str());
        }
    }
    return 0;
}

Measured memory_bytes: 3288
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL MOD = 1000000007LL;
LL a[50];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	LL ans = 0;
	while (1) {
		LL sum = 0;
		for (int i = 0; i < N; i++) sum += a[i] / N;
		if (sum == 0) break;
		ans += sum;
		for (int i = 0; i < N; i++) {
			LL d = a[i] / N;
			a[i] -= d*N;
			a[i] += sum - d;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		Set<Long>m=new HashSet<>();
		for(int n=s.nextInt();n>0;--n) {
			long v=s.nextLong();
			if(!m.remove(v))
				m.add(v);
		}
		System.out.println(m.size());
	}
}

Measured memory_bytes: 64660
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
	public class Program
	{
		public static void Main(string[] args)
		{
			new Program().Solve(new ConsoleInput(Console.In, ' '));
		}

		public void Solve(ConsoleInput cin)
		{
			var n = cin.ReadInt;
			var words = cin.ReadStrArray(n);

			for (var i = 1; i < words.Length; i++)
			{
				var current = words[i];
				var previous = words[i - 1];

				if (words.Take(i - 1).Contains(current) ||
					current.First() != previous.Last())
				{
					WriteLine("No");
					return;
				}
			}

			WriteLine("Yes");
		}
	}

	public class ConsoleInput
	{
		private readonly System.IO.TextReader _stream;
		private char _separator = ' ';
		private Queue<string> inputStream;
		public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
		{
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read
		{
			get
			{
				if (inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for (int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
		public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
	}
}


Measured memory_bytes: 13524
// atcoder/abc147/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, w;
  while (cin >> h >> w) {
    const int N = 80 + 3;
    int a[N][N];
    int b[N][N];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> b[i][j];
      }
    }

    const int D = 80 * N * 2;
    static bool dp[N][N][D];
    fill(&dp[0][0][0], &dp[N - 1][N - 1][D - 1] + 1, false);
    dp[0][0][a[0][0] - b[0][0] + (D / 2)] = true;
    dp[0][0][b[0][0] - a[0][0] + (D / 2)] = true;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        for (int k = 0; k < D; ++k) {
          if (dp[i][j][k]) {
            if (i + 1 < h) dp[i + 1][j][k + (a[i + 1][j] - b[i + 1][j])] |= dp[i][j][k];
            if (i + 1 < h) dp[i + 1][j][k + (b[i + 1][j] - a[i + 1][j])] |= dp[i][j][k];
            if (j + 1 < w) dp[i][j + 1][k + (a[i][j + 1] - b[i][j + 1])] |= dp[i][j][k];
            if (j + 1 < w) dp[i][j + 1][k + (b[i][j + 1] - a[i][j + 1])] |= dp[i][j][k];
          }
        }
      }
    }

    int mn = 1 << 29;
    for (int k = 0; k < D; ++k) {
      if (dp[h - 1][w - 1][k]) {
        setmin(mn, abs(k - (D / 2)));
      }
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 89728
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d %d", &a, &b);
	
	if(a>b) printf("a > b\n");
	if(a==b) printf("a == b\n");
	if(a<b) printf("a < b\n");
	
	return 0;
}

Measured memory_bytes: 580
S = input()
mojiretsu = ["A","C","G","T"]
s_bin = [int(s in mojiretsu) for s in S]
# print(s_bin)
cnt = 0
cnt_max = 0
for s in s_bin+[0]:
    if s == 0:
        # cnt_max = max(cnt_max, cnt)
        cnt = 0
    if s == 1:
        cnt += 1
        cnt_max = max(cnt_max, cnt)
    
    # print("s:{},cnt:{},cnt_max{}".format(s,cnt,cnt_max))

print(cnt_max)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{  
  int sum=0;
  int n;
  std::vector<int> v;
  while(std::cin>>n){
    v.push_back(n);
    //処理
  }
  // 並べ替える
  std::sort(v.begin(), v.end());
  sum+=v[1]-v[0];
  sum+=v[2]-v[1];
  std::cout << sum;
}

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

int main(void){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    int sum = 0;
    for(int i = 0;i < n;i++){
        if(a[i] % 2 == 1)sum++;
    }
    if(sum % 2 == 0)cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> a(N);
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  
  double bs = 1;
  for (int i=0; i<N; i++) {
    bs *= a[i];
  }
  
  double bb = 0;
  for (int i=0; i<N; i++) {
    bb += (bs / a[i]);
  }
  
  cout << bs/bb << endl;
}
    

Measured memory_bytes: 256
// LM10: The next Ballon d'Or
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }

    public static void main(String[] args)throws IOException {
        /*
3 4
...#
.#..
....
Sample Output 1
Copy
3
        */
        PrintWriter pw = new PrintWriter(System.out);
        FastReader fr = new FastReader();
        int n=fr.i();
        int m=fr.i();
        int mod=(int)(1e9+7);
        char [][] arr=new char[n][m];
        long [][] dp=new long [n][m];
        for(int ni=0;ni<n;++ni)
        {
            arr[ni]=fr.nextLine().toCharArray();
        }
        dp[0][0]=1;
        for(int i=0;i<n;++i)
        {
            for(int j=0;j<m;++j)
            {
                if(arr[i][j]=='#')
                    continue;
                if(i-1>=0)
                    dp[i][j]+=dp[i-1][j];
                if(j-1>=0)
                    dp[i][j]+=dp[i][j-1];
                dp[i][j]%=mod;
            }
        }
        pw.println(dp[n-1][m-1]);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 50276
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>

using namespace std;

int L, R;
void solve() {
	cin >> L >> R;
	if (R - L >= 2018) {
		cout << 0 << endl;
		return;
	}
	L %= 2019;
	R %= 2019;
	if (R <= L) {
		cout << 0 << endl;
		return;
	}
	int ans = 2018;
	for (int i = L; i <= R; i++) {
		for (int j = i+1; j <= R; j++) {
			ans = min(ans, (i * j) % 2019);
		}
	}
	cout << ans << endl;
	return;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d%d",&a,&b);
  int x=a+b,y=a-b,z=a*b;
  if(x>=y&&x>=z)printf("%d",x);
  else if(y>=x&&y>=z)printf("%d",y);
  else printf("%d",z);
  return 0;
}

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

int main()
{
    string T;

    cin >> T;

    for(int i=0; i<T.size(); i++) {
        if(T[i] == '?') {
            T[i] = 'D';
        }
    }

    cout << T << endl;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int main()
{
    ll n, ans = 0;
    string s;
    cin >> n >> s;
    unordered_set<ll> mp[3]; //r,g,b
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            mp[0].insert(i);
        if (s[i] == 'G')
            mp[1].insert(i);
        if (s[i] == 'B')
            mp[2].insert(i);
    }

    if (mp[0].size() > mp[2].size())
        swap(mp[0], mp[2]);
    if (mp[1].size() > mp[2].size())
        swap(mp[1], mp[2]);

    for (auto it0 = mp[0].begin(); it0 != mp[0].end(); it0++)
    {
        for (auto it1 = mp[1].begin(); it1 != mp[1].end(); it1++)
        {
            ll n0 = *it0;
            ll n1 = *it1;

            if (n0 > n1)
                swap(n0, n1); //n0<n1

            ans += mp[2].size();
            ll n2;
            n2 = 2 * n0 - n1;
            if (n2 >= 0 && mp[2].find(n2) != mp[2].end()) //n2,n0,n1
            {
                ans--;
            }
            n2 = 2 * n1 - n0;
            if (n2 < n && mp[2].find(n2) != mp[2].end()) //n0,n1,n2
            {
                ans--;
            }
            if ((n1 - n0) % 2 == 0)
            {
                n2 = (n1 + n0) / 2;
                if (mp[2].find(n2) != mp[2].end()) //n0,n1,n2
                {
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3768
import java.util.Scanner;

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

        int N = sc.nextInt();
        int W = sc.nextInt();

        long[][] dp = new long[N + 1][W + 1];
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= W; j++) {
                dp[i][j] = -1;
            }
        }

        dp[0][0] = 0;
        for (int i = 0; i < N; i++) {
            int w = sc.nextInt();
            int v = sc.nextInt();
            for (int j = 0; j <= W; j++) {
                if (dp[i][j] == -1) {
                    continue;
                }
                dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j]);
                if (j + w > W) {
                    continue;
                }
                dp[i + 1][j + w] = Math.max(dp[i + 1][j + w], dp[i][j] + v);
            }
        }

        long result = 0;
        for (int j = 0; j <= W; j++) {
            if (dp[N][j] > result) {
                result = dp[N][j];
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 126036
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef vector<int>vec;
typedef vector<vec>mat;
const int M=1000000007;
mat mul(mat A,mat B){
    mat C(A.size(),vec(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int j=0;j<B[0].size();j++){
            for(int k=0;k<A[0].size();k++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%M;
            }
        }
    }
    return C;
}
 
mat matpow(mat A,int k){
    mat B(A.size(),vec(A.size()));
    for(int i=0;i<A.size();i++)B[i][i]=1;
    while(k){
        if(k&1)B=mul(B,A);
        A=mul(A,A);
        k>>=1;
    }
    return B;
}
 
int sol(int n){
    mat A(2,vec(2));
    A[0][0]=1;A[0][1]=1;
    A[1][0]=1;A[1][1]=0;
    A=matpow(A,n);
    return A[1][0];
}

void out(int x,int y){
    cout<<(sol(x+1)*sol(y+1))%M<<endl;
    exit(0);
}

signed main(){
    int K;
    cin>>K;
    int l=0,r=(1e9)*4;
    while(l<r){
        int mid=(l+r)/2;
        if(mid*(mid+1)>=K)r=mid;
        else l=mid+1;
    }
    l--;
    int cnt=0;
    K-=l*(l+1);
    int x=r*2-1,p=0;
    if(K>r)K-=r,x++,p++;
    int y=1;
    while(x>=y){
        cnt++;
        if(cnt==K)out(x,y);
        x-=2;y+=2;
    }
    x+=2;
    y-=2;
   // cout<<r<<endl;
   // cout<<x<<' '<<y<<endl;
    if(!p){
        if((x==r+1&&y==r-1))x--,y++;
        else x++,y--;
    }
    else{
        if(x==y+x/2)x++,y--;
        else x--,y++;
    }
    //cout<<x<<' '<<y<<endl;

    while(1){
        cnt++;
        if(cnt==K)out(x,y);
        x+=2;y-=2;
    }
    //cout<<K<<' '<<l<<endl;
}


Measured memory_bytes: 3160
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ANS=[min(A[0],B[0])]
if A[0]>=B[0]:
  B[0]=0
else:
  B[0]=B[0]-A[0]
for i in range(N-1):
  ANS+=[min(A[i+1],B[i]+B[i+1])]
  if A[i+1]>=B[i]+B[i+1]:
    B[i+1]=0
  else:
    B[i+1]=min(B[i+1],B[i+1]-A[i+1]+B[i])
ANS+=[min(A[N],B[N-1])]
ans=sum(ANS)
print(ans)

Measured memory_bytes: 19004
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

M=max(B)
m=min(B)
for i in range(N):
    if B[i]==M:
        Mnum=A[i]
    if B[i]==m:
        mnum=A[i]

ans=mnum+m
print(ans)

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

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

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

    int n;
    cin >> n;

    vector<vector<int> > a(n, vector<int>(3));
    REP(i, n) REP(j, 3) cin >> a[i][j];

    vector<vector<int> > dp(n + 1, vector<int>(3, 0));

    REP(i, n) REP(j, 3) REP(k, 3) {
        if (j == k) continue ;
        chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
    }

    int ans = 0;
    REP(i, 3) chmax(ans, dp[n][i]);

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;
void io(string s="file"){freopen((s + ".in").c_str(), "r", stdin);freopen((s + ".out").c_str(), "w", stdout);}


signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b,c,d;cin>>a>>b>>c>>d;
    
    int ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
const int N(22), mod(1e9 + 7);
int n, dp[N][1 << N], x, newmask;
int main() {
    DAU
    cin >> n;
    vector<vector<int>> g(n + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            cin >> x;
            if (x) g[i].emplace_back(j);
        }
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i)
        for (int mask = 0; mask < (1 << n); ++mask)
            if (dp[i-1][mask] && __builtin_popcount(mask) == i - 1)
                for (const int& j : g[i])
                    if (!(mask & (1 << (j - 1)))) {
                        newmask = mask + (1 << (j - 1));
                        dp[i][newmask] = (dp[i][newmask] + dp[i - 1][mask]) % mod;
                    }
    cout << dp[n][(1 << n) - 1];
    PLEC
}


Measured memory_bytes: 180480
#include"bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

/* 採点コード
	vector<int> t(D);
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}
	vector<int> last(26, 0);

	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i+1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
		cout << v << endl;
	}
	*/

int main(void) {
	srand(time(NULL));
	int D; cin >> D;
	vector<int> c(26, 0);
	rep(i, 26)cin >> c[i];
	vector<vector<int>> s(D, vector<int>(26, 0));
	rep(i, D)rep(j, 26)cin >> s[i][j];

	vector<int> t(D, 0);
	rep(i, D) {
		rep(j, 26) {
			if (s[i][t[i]] <= s[i][j])t[i] = j;
		}
	}
	vector<int> ans = t;
	int best = 0;

	auto start = clock();
	while (clock() - start < 1500) {
		int idx = rand() % D;
		t[idx] = rand() % 26;

		//採点
		vector<int> last(26, 0);
		int v = 0;
		rep(i, D) {
			v += s[i][t[i]];
			last[t[i]] = i + 1;
			rep(j, 26) {
				v -= c[j] * (i + 1 - last[j]);
			}
		}
		//採点
		if (best <= v) {
			ans = t;
		}
	}

	for (auto x : ans) {
		cout << x + 1 << endl;
	}
	/*
	vector<int> last(26, 0);

	t = ans;

	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i + 1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
	}
	*/
	return 0;
}


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

using namespace std;

int main() {
  int n;
  cin>>n;
  string s=to_string(n);
  int a=s.size();
  int cnt=0,t=n;
  rep(i,a){
   cnt+=t%10;
    t/=10;
  }
  if(n%cnt==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
    string s;
    while (cin >> s) {
        while (1 < (int)s.size()) {
            stringstream ss;
            for (int i=0; i<(int)s.size()-1; ++i) {
                ss << ((s[i] - '0') + (s[i+1] - '0')) % 10;
            }
            s = ss.str();
        }
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin >> a >> b >> c;
    int sum = 0;
    for(int i=0; i<60; i++){
        if(sum%60<=c and c<=sum%60+a){
            cout << sum + (c-sum%60) << endl;
            return 0;
        }
        sum += (a+b);
    }
    cout << -1 << endl;
    return 0;
}


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


int main(){
    ll x; cin>>x;
    ll res=0;
    ll tmp=100;
    while(tmp<x){
        res++;
        tmp=tmp*1.01;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    ll h[N];
    ll out = 0;
    ll max = 0;
    rep(i,N){
        cin >> h[i];
        out += h[i];
        if(h[i]>max) max = h[i];
    }
    rep(i,max){
        rep(j,N-1){
            if(h[j]>0){
                h[j]--;
                if(h[j+1]>0) out--;
            }
        }
        if(h[N-1]>0) h[N-1]--;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

	int N;
	cin >> N;
	int ans = 0;
	rep(i,N){
		if((i+1) % 3 == 0 || (i+1) % 5 == 0) continue;
		ans += i+1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3648
n=int(input())
li = list(map(int,input().split()))
li.sort()
while True:
    if len(li) == 1:
        break;
    else:
        x=(li[0]+li[1])/2
        li.pop(0)
        li.pop(0)
        li.insert(0,x)
print(li[0])

Measured memory_bytes: 3060
loop {
	n = gets.to_i
	break if n == 0
	l = r = 0
	prev = 0
	count = 0
	gets.chomp.split.each{|s|
		case s
			when 'lu'; l = 1
			when 'ld'; l = 0
			when 'ru'; r = 1
			when 'rd'; r = 0
		end
		if l == r && l != prev
			count += 1
			prev = l
		end
	}
	p count
}

Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <int,int> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
ll mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vi a(n);
    map <ll,ll> m;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vi b(a);
    sort(b.begin(),b.end());
    ll ma1=b.back();
    ll ma2=b[b.size()-2];
    for(ll i=0;i<n;i++)
    {
        if(a[i]!=ma1)
        {
            cout<<ma1<<endl;
        }
        else
        {
            cout<<ma2<<endl;
        }
    }
}


Measured memory_bytes: 4736
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    counts = [0]*N
    combinations = [(0,0)] *N
    ncombinations =[0]*N
    for i in range(N):
        counts[A[i]] += 1
    sum = 0
    for i in range(N):
        c1 = counts[i] * (counts[i]-1)//2 if counts[i] >=2 else 0
        c2 = (counts[i] - 1) * (counts[i] - 2)//2 if counts[i] >= 3 else 0
        combinations[i] = (c1,c2)
        sum += c1
    for i in range(N):
        ncombinations[i] = sum - (combinations[i][0] - combinations[i][1])
    for i in range(N):
        print(ncombinations[A[i]])
    return

def int1(s):
    return int(s)-1
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int1(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main(){
  long double a, b, c;
  cin >> a >> b >> c;
  long double left = (a + b + 2 * (sqrt(a) * sqrt(b)));
  if(left < c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

char shift(const char c, int shift) {
  int result = c + shift;
  if (result > 'z') result -= 26;
  return result;
}

int main() {
  string str;
  while (getline(cin, str)) {
    for (int i = 0; i < 26; i++) {
      string decoded = str;
      for (unsigned int j = 0; j < str.size(); j++) {
        if ('a' <= str[j] && str[j] <= 'z') {
          decoded[j] = shift(str[j], i);
        }
      }
      if (decoded.find("the") != string::npos ||
          decoded.find("this") != string::npos ||
          decoded.find("that") != string::npos) {
        cout << decoded << endl;
        break;
      }
    }
  }


  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
const int INF=2147483647;
int main()
{
	int n, q; scanf("%d %d", &n, &q);
	SegmentTree<int> seg(n, [](int a, int b){ return min(a, b);}, INF);
	for(int z=0; z<q; z++){
		int c, x, y;
		scanf("%d %d %d", &c, &x, &y);
		if(c==0) seg.update(x, y);
		else printf("%d\n", seg.query(x, y+1));
	}
	return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<bool> D(10);

    for(int i = 0; i < K; i++) {
        int d;
        cin >> d;
        D[d] = true;
    }

    for(int i = N; ; i++) {
        int n = i;
        bool checker = false;
        while(n != 0) {
            for(int i = 0; i < 10; i++) {
                if(D[i]) {
                    if(n % 10 == i) {
                        checker = true;
                        break;
                    }
                }
            }
            if(checker) break;
            n /= 10;
        }
        if(checker) continue;
        cout << i << endl;
        return 0;
    }
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll n,m,l;
  cin>>n>>m>>l;
  vector<vector<ll>> dist1 (n,vector<ll>(n,INF));
  vector<vector<ll>> dist2 (n,vector<ll>(n,INF));
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmin(dist1[a][b],c);
    chmin(dist1[b][a],c);
  }
  ll q;
  cin>>q;
  vector<pair<ll,ll>> query;
  rep(i,q){
    ll s,t;
    cin>>s>>t;
    s--;t--;
    query.emplace_back(s,t);
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist1[i][j],dist1[i][k]+dist1[k][j]);
  }

  rep(i,n)rep(j,n){
    if(dist1[i][j]<=l)dist2[i][j]=1;
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }

  rep(i,q){
    ll s,t;tie(s,t)=query[i];
    if(dist2[s][t]==INF)cout<<(-1)<<endl;
    else cout<<(dist2[s][t]-1)<<endl;
  }

}


Measured memory_bytes: 3836
// atcoder/abc156/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, r;
  while (cin >> n >> r) {
    if (10 <= n) {
      cout << r << endl;
    } else {
      for (int k = 0; k < 10000; ++k) {
        if (k - (100 * (10 - n)) == r) {
          cout << k << endl;
          break;
        }
      }
    }
  }
  return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N;

int parse(string& line, int& num, char& op) {
    REP(i, line.length()) {
        if (line[i] != '.') {
            if (isdigit(line[i])) {
                num = line[i] - '0';
            } else {
                op = line[i];
            }
            return i;
        }
    }
    assert(0);
}

int dfs(int& idx, int level, char op, vs& lines) {
    int res = 0;
    if (op == '*') res = 1;
    for (; idx < N; idx++) {
        int num = 0;
        char c = 0;
        int lv = parse(lines[idx], num, c);
        if (lv != level) {
            idx--;
            break;
        }
        if (c != 0) {
            idx++;
            num = dfs(idx, lv+1, c, lines);
        }
        if (op == '+') {
            res += num;
        } else if (op == '*') {
            res *= num;
        }
    }
    return res;
}

int main() {
    while (cin >> N, N) {
        vs lines(N);
        REP(i, N) cin >> lines[i];
        int idx = 0;
        cout << dfs(idx, 0, '+', lines) << endl;
    }
}

Measured memory_bytes: 3140
d, g = map(int, input().split())
ps = [0]*d
cs = [0]*d

for i in range(d):
  p, c = map(int, input().split())
  ps[i] = p
  cs[i] = c

min_count = sum(ps)
for i in range(2**d-1):
  point = 0
  count = 0
  max_other_j = -1
  for j in range(d):
    if (i >> j) & 1:
      point += (j+1)*100*ps[j] + cs[j]
      count += ps[j]
    else:
      max_other_j = max(max_other_j, j)
  if point < g:
    if max_other_j < 0:
      continue
    else:
      if (g - point)%((max_other_j+1)*100) == 0:
        other_count = (g - point)//((max_other_j+1)*100)
      else:
        other_count = (g - point)//((max_other_j+1)*100)+1
      if other_count >= ps[max_other_j]:
        continue
      else:
        count += other_count
  if count <= min_count:
    min_count = count
  
print(min_count)

Measured memory_bytes: 3188
#include <stdio.h>
#define false 0
#define true 1

typedef struct cc{
    char mark;
    char num;
} Card;

void bubble(Card C[], int N){
    int i, j;
    Card card_tmp; 
    for ( i = 0; i < N; i++) {
        for ( j = N-1; j >= i; j--){
            if (C[j].num < C[j-1].num){
                card_tmp = C[j];
                C[j] = C[j-1];
                C[j-1]= card_tmp;
            }
        }
    }
}

void selection (Card C[], int N) {
    int i, j;
    int minj;
    Card card_tmp;
    for ( i = 0; i < N; i++) {
        minj = i;
        for  ( j = i; j < N; j++) {
            if (C[j].num < C[minj].num) minj = j;
        }
        card_tmp = C[i];
        C[i] = C[minj];
        C[minj]= card_tmp;
    }
}

int isStable (Card in[], Card out[], int N) {
    int i;
    for ( i = 0; i < N; i++) {
        if (in[i].mark != out[i].mark) return false;
    }
    return true;
}

void output (Card C[], int N) {
    int i;
    for ( i = 0; i < N; i++) {
        printf("%c%c",C[i].mark,C[i].num);
        if(i == N-1)printf("\n");
        else printf(" ");
    }
}

int main(){
    int N;
    int i;
    char trash;
    Card A[100], B[100];
    
    scanf("%d\n",&N);
    for(i=0; i < N; i++) scanf("%c%c%c",&A[i].mark,&A[i].num,&trash);
    
    for (i = 0; i < N; i++) B[i] = A[i];

    bubble(A, N);
    selection(B, N);

    output(A,N);
    printf("Stable\n");
    
    
    
    output(B,N);
    if(isStable(A, B, N) == true)printf("Stable\n");
    else printf("Not stable\n");
    
    return 0;
}



Measured memory_bytes: 2048
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
elif len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    S2 = S*2
    d = 0
    flg = False
    for i in range(len(S2)-1):
        if S2[i] == S2[i+1] and flg is False:
            d += 1
            flg = True
        else:
            flg = False

    ar = 0
    if c*2 != d:
        ar = 1

    if ar == 1:
        print((c+1)*K-1)
    else:
        print(c*K)


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

int main(){
    int n,k;
    double sump=0;
    cin >> n >> k;
    
    for(int i = 1;i <= n;++i){
        double p = (double)1/(double)n;
        //cout << p << " " << ceil(log2((double)k/(double)i)) << " ";
        for(int j = 0;j < ceil(log2((double)k/(double)i));++j)
            p *=0.5;
        //cout << p << endl;
        sump += p;
    }
    cout << fixed << setprecision(10) << sump << endl;
}

Measured memory_bytes: 256
#素因数分解
def Prime_Factorization(n):
    R=[]
    N=n

    for k in range(2,int(-(-n**0.5//1))+1):
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])

    if N!=1:
        R.append([N,1])
        
    if not R:
        R.append([N,1])

    return R

#約数全部
from copy import copy
def Divisors(n):
    if n==1:
        return [1]
    
    L=Prime_Factorization(n)
    U=[1]

    for (p,k) in L:
        T=copy(U)
        for t in T:
            r=t
            for _ in range(1,k+1):
                r*=p
                U.append(r)
    U.sort()
    return U


import sys
N=int(input())
if N==1:
    print(0)
    sys.exit()
    
L=Divisors(N)
L.remove(1)

K=0
for a in L:
    b=a-1
    if N//b==N%b:
        K+=b
print(K)


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

using namespace std;
typedef long long ll; 
int main(){
  ll N; cin >> N;
  vector<vector<ll>> v(10, vector<ll>(10, 0));
  
  for(int i = 1; i <= N; i++){
    string tmp = to_string(i);
    
    int head_num = tmp[0] - '0';
    int tail_num = tmp[tmp.size()-1] - '0';
    v[head_num][tail_num]++;
  }
  ll ans = 0;
  
  for(int i = 0; i <= 9; i++){
    for(int j = 0; j <= 9; j++){
      ans += v[i][j] * v[j][i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3668
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if ((a * 100 + b * 10 + c) % 4 == 0) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
        
    }
}

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

using namespace std;

typedef pair<int, int> P;
typedef pair<P, P> PP;

int w, h;
char s[66][33];

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

int mincost[2][66][33];

const int inf = 1 << 25;

int dijkstra()
{
  for(int i = 0; i < 66; i++) {
    for(int j = 0; j < 33; j++) {
      mincost[0][i][j] = inf;
      mincost[1][i][j] = inf;
    }
  }
  priority_queue<PP, vector<PP>, greater<PP> > que;  
  for(int i = 0; i < w; i++) {
    if(s[h-1][i] == 'S') {
      que.push(PP(P(0, 0), P(i, h-1))); mincost[0][h-1][i] = 0;
      que.push(PP(P(0, 1), P(i, h-1))); mincost[1][h-1][i] = 0;
    }
  }
  while(!que.empty()) {
    PP p = que.top(); que.pop();
    int c = p.first.first, lr = p.first.second;
    int x = p.second.first, y = p.second.second;
    if(s[y][x] == 'T') return c;
    if(mincost[lr][y][x] < c) continue;
    for(int i = 0; i < 9; i++) {
      int nx = x + (lr ? dx[i] : -dx[i]), ny = y + dy[i];
      if(0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] != 'X') {
	int d = isdigit(s[ny][nx]) ? s[ny][nx]-'0' : 0;
	if(c + d < mincost[(lr+1)%2][ny][nx]) {
	  mincost[(lr+1)%2][ny][nx] = c + d;
	  que.push(PP(P(c + d, (lr+1)%2), P(nx, ny)));
	}
      }
    }
  }
  return -1;
}

int main()
{
  while(cin >> w >> h, w || h) {
    memset(s, 0, sizeof(s));
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) cin >> s[i][j];
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 3128
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const Inf = 1 << 62

func main() {
	N, M := ReadInt(), ReadInt()
	S := ReadString()
	dp := make([]int, N+1)
	for i := 0; i < N; i++ {
		dp[i] = Inf
	}
	dp[N] = 0
	blockSize := int(math.Sqrt(float64(N + 1)))
	blockNum := (N + 1 + blockSize - 1) / blockSize
	blocks := make([]int, blockNum)
	for i := 0; i < blockNum; i++ {
		blocks[i] = Inf
	}
	blocks[N/blockSize] = 0
	for i := N - 1; i >= 0; i-- {
		if S[i] == '1' {
			continue
		}
		l := i + 1
		r := Min(i+M, N) + 1
		min := Inf
		for l < r && l%blockSize > 0 {
			min = Min(min, dp[l])
			l++
		}
		for l < r && r%blockSize > 0 {
			r--
			min = Min(min, dp[r])
		}
		for l < r {
			min = Min(min, blocks[l/blockSize])
			l += blockSize
		}
		dp[i] = min + 1
		blocks[i/blockSize] = Min(blocks[i/blockSize], dp[i])
	}

	if dp[0] >= Inf {
		fmt.Println(-1)
		return
	}

	x := 0
	rest := dp[0]
	for x < N {
		rest--
		i := 1
		for dp[x+i] != rest {
			i++
		}
		fmt.Printf("%d ", i)
		x += i
	}
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 4220
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int s;
	cin >> s;
	map<int,int> a;
	a[s]++;
	int i=1;
	while(true){
		i++;
		if(s%2)
			s = s*3+1;
		else
			s /= 2;
		if(a[s])
			break;
		else
			a[s]++;
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256