akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;

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

    int n;
    string s;
    cin >> n >> s;

    int x = 0, tmp = 0;
    rep(i, n){
        if (s[i] == 'I'){
            tmp++;
            x = max(tmp, x);
        }
        else{
            tmp--;
            x = max(tmp, x);
        }
    }
    cout << x << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

vector<int> G[200];

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

	rep (i, 200) G[i].clear();
	int N; cin >> N;

	rep (i, N){
		for (int j = i + 1; j < N; ++j){
			string s(N, '0');
			s[i] = '1'; s[j] = '1';
			cout << "? " << s << endl;
			int d; cin >> d;
			if (d == 1){
				G[i].push_back(j);
			} // end if
		} // end for
	} // end rep
	
	vector<P> ans; ans.clear();
	rep (i, 200){
		if (G[i].empty()) continue;
		rep (j, (int)G[i].size()){
			ans.push_back(P(i, G[i][j]));
		} // end rep
	} // end rep

	cout << "! ";
	int m = (int)ans.size();
	rep (i,m){
		cout << '(' << ans[i].first << ',' << ans[i].second << ')' << (i != m - 1 ? ' ' : '\n');
	} // end rep
		
	return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

constexpr double pi = 3.141592653589793;

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double at = (H + M / 60.0) * pi / 6.0;
    double bt = M * pi / 30.0;
    double ax = A * cos(at);
    double ay = A * sin(at);
    double bx = B * cos(bt);
    double by = B * sin(bt);
    double dx = ax - bx;
    double dy = ay - by;

    double ans = sqrt(dx*dx+dy*dy);
    printf("%.20f\n", ans);
}

Measured memory_bytes: 4092
S = input()
flag = True
for i in range(len(S)):
    s = S[i]
    if (i + 1) % 2 == 0: # 偶数
        if s != 'L' and s != 'U' and s != 'D':
            flag = False
            break
    else: # 奇数
        if s != 'R' and s != 'U' and s != 'D':
            flag = False
            break

if flag == False:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
n = max(A)
tmp = 0
ans = -1
for i in range(N):
	if min(A[i], n-A[i]) >= tmp:
		tmp = min(A[i], n-A[i])
		ans = A[i]

print(n, ans)


Measured memory_bytes: 14060
#include <iostream>

using namespace std;
int MONTH[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char day_of_the_week[32][32] = {{"Thursday"},
								{"Friday"},
								{"Saturday"},
								{"Sunday"},
								{"Monday"},
								{"Tuesday"},
								{"Wednesday"},
};
void solve()
{
	int month, day;
	while(cin >> month >> day, month || day)
	{
		int sum = 0;
		for(int i = 0; i < month - 1; ++i)
		{
			sum += MONTH[i];
		}
		sum += day - 1;
		cout << day_of_the_week[sum % 7] << endl;
	}
}

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

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 1e5;
int n;
LL a[MaxN + 5], sum[MaxN + 5];

int main()
{
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
		sort(a + 1, a + n + 1);
		for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
		int ans = n;
		for (int i = n - 1; i >= 1; i--) {
			if (sum[i] * 2 < a[i + 1]) {
				ans = n - i;
				break;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,k;cin>>n>>k;
    ll arr[n+1];
    for(ll i=1;i<=n;i++)
        cin>>arr[i];
    ll dp[n+1];
    for(int i=2;i<=n;i++)
        dp[i]=1000000000;
    dp[0]=0;
    dp[1]=0;
    for(ll i=2;i<=n;i++)
    {

        for(ll j=i-1;j>=max(1LL,(i-k));j--)
        {
            dp[i]=min((dp[j]+abs(arr[j]-arr[i])),dp[i]);

        }
    }

    cout<<dp[n]<<endl;
}


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

using namespace std;

int main(void){
    while(1){
        int n; cin >> n;
        if(n == 0) break;

        int max_s = 0, min_s = 1000, sum = 0;
        for(int i = 0; i < n; i++){
            int s; cin >> s;
            
            max_s = max(max_s, s);
            min_s = min(min_s, s);
            sum  += s;
        }

        int res = (sum - min_s - max_s) / (n - 2);
        cout << res << endl;
    }

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int c200=n/15;
	int ans=800*n-200*c200;
	cout << ans << endl;				
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<string, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N;
   cin >> N;
   string s;
   int p;
   vector<ipair> log;
   map<ipair, int> ids;
   for (int i = 0; i < N; i++) {
      cin >> s >> p;
      log.push_back(ipair(s, -p));
      ids[ipair(s, -p)] = i + 1;
   }
   sort(log.begin(), log.end());
   for (auto it = log.begin(); it != log.end(); it++) {
      cout << ids[ipair(it->first, it->second)] << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll n, i, a, tem = 1, flag = 0;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> a;
        if(a == 0){
            cout << 0;
            return 0;
        }
        if((ll)1e18/a < tem) flag = 1;
        if(flag == 0){
            tem *= a;
        }
    }
    if(flag) cout << -1;
    else cout << tem;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const double eps = 1e-10;
const int maxn = 100 + 100;
string s;
vector<int> g[30];
int main() {
#ifdef ac
    //freopen("in.txt" , "r" , stdin);
//    freopen("out.txt" , "w" , stdout);
#endif
    cin >> s;
    for(int i=0;i<s.size();++i) {
        g[s[i]-'a'].push_back(i+1);
    }
    for(int i=0;i<26;++i) {
        if(g[i].size()>1) {
            for(int j=1;j<g[i].size();++j) {
                if(g[i][j]-g[i][j-1]<=2) {
                    cout << g[i][j-1] << " " << g[i][j] << endl;
                    return 0;
                }
            }
        }
    }
    cout <<-1 <<" " << -1 << endl;
    return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;

    ll n = (N+1)/2;
    cout << (double)n/(double)N << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
int n,m;
LL ai[1234];
LL bi[1234];
LL ci[1234];

void init(){
   
}



void play(){

}
void pri(){
   
}
struct he1 {
    int x;
    int id;
}need[100];
int vvv[100];
bool cmp1(LL a,LL b){
    return a>b;
}
bool vis[1234];
int status[4];
LL di[1234];
LL ans;
bool flag;
void DFS(int now){
    
    
    if(now==4){
        for(int i=1;i<=n;i++){
            LL a=ai[i];
            LL b=bi[i];
            LL c=ci[i];
            if(status[1]==0){
                a=-a;
            }
            if(status[2]==0){
                b=-b;
            }
            if(status[3]==0){
                c=-c;
            }
            di[i]=a+b+c;
        }
        sort(di+1, di+1+n, cmp1);
        LL sum=0;
        for(int i=1;i<=m;i++)sum+=di[i];
        if(!flag){ans=sum;flag=1;}
        else ans=max(ans,sum);
        return;
    }
    status[now]=1;
    DFS(now+1);
    status[now]=0;
    DFS(now+1);
}
int main() {
    while(scanf("%d%d",&n,&m)!=EOF){
        flag=0;
        memset(ai,0,sizeof(ai));
        LL sum[4];
        memset(vis, 0, sizeof(vis));
        sum[1]=sum[2]=sum[3]=0;
        for(int i=1;i<=n;i++){
          
            scanf("%lld%lld%lld",&ai[i],&bi[i],&ci[i]);
         
        }
        DFS(1);
           printf("%lld\n",ans);
        }
    
    

    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0&&W==0){
				break;
			}else{
				for(int i=0;i<H;i++){
					for(int j=0;j<W;j++){
						System.out.print("#");
					}
					System.out.println();
				}
			}
			System.out.println();
		}
	}
}

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

int N, K, R, S, P, SC;
string T;
char A[100005];
map<char, int> O;
map<char, char> Y;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K >> R >> S >> P >> T;
	O['r'] = P;
	O['p'] = S;
	O['s'] = R;
	Y['r'] = 'p';
	Y['p'] = 's';
	Y['s'] = 'r';
	for (int i = 0; i < N; i++) {
		if (i < K || A[i - K] ^ Y[T[i]]) SC += O[T[i]], A[i] = Y[T[i]];
		else A[i - K] = 0;
	}
	cout << SC << '\n';
}


Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main()
{
    int i,n,k,c=0,l;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>l;
        if(l>=k)
        {
            c++;
        }
    }
    cout<<c<<"\n";
    return 0;
}


Measured memory_bytes: 3576
import Data.Array.IO
import Control.Monad

main = do
  getLine
  a <- return . (map (f . read)) . words =<< getLine

  arr <- newArray (0,8) 0 :: IO (IOArray Int Int)

  forM_ a $ \x -> do
    r <- readArray arr x
    writeArray arr x (r+1)

  putStrLn =<< return . unwords . map show . g =<< getElems arr

  where
    f n
      | n < 3200 = div n 400
      | otherwise = 8

    g xs = h c l
      where
        c = (length . (filter (/=0)) . init) xs
        l = last xs
        
    h c l
      | c == 0 = [1, l]
      | otherwise = [c, c+l]


Measured memory_bytes: 1020
s = input()
ans = 0
total = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "G" or s[i] == "C" or s[i] == "T":
        total += 1
    else:
        ans = max(ans, total)
        total = 0
print(max(ans, total))


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//const int RULE[3] = {10,20,26};
//const int MEM[3] = {3,2,1};

int main(){
  while(1){
    int n;
    cin >> n;

    if(n == 0)break;///// 正解数,−１＊ペナルテ,ID,所属
    
    vector<pair<pair<int,int>,
		pair<int,int>		
		>
	   > vec(n,pair<pair<int,int>,pair<int,int> >());
    for(int i = 0;i < n;i++){
      int l,u,a,p;
      cin >> l >> u >> a >> p;
      vec[i].first = pair<int,int>(-1*a,p);
      vec[i].second = pair<int,int>(l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    //int ii = 0;
    int f = 0;
    for(int i = 0;i < n;i++){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      
      cnt[vec[i].second.second]++;
      if(f < 10 && cnt[vec[i].second.second] > 3){
	
      }else if(10 <=f && f < 20&& cnt[vec[i].second.second] > 2){
       
      }else if(20 <= f && f < 26 && cnt[vec[i].second.second] > 1){
	
      }else{
	cout << vec[i].second.first << endl;
	f++;
	if(f == 26)break;
      } 
      
    }
  }
  return 0;
}

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

int main()
{
  string s;
  cin >> s;
  vector<int> v(4);
  for (int i = 0; i < 4; i++)
  {
    v[i] = s[i] - '0';
  }
  
  for (int j = 0; j < (1 << 3); j++)
  {
    int tmp = v[0]; //tmpの初期値をv[0]にしてtmpに対してBCDを足すか引くか。
    for (int k = 0; k < 3; k++)
    {
      if (j & (1 << k))
        tmp += v[k + 1];
      else
        tmp -= v[k + 1];
    }
    if (tmp == 7)
    {
      cout << v[0];
      for (int k = 0; k < 3; k++)
      {
      	if (j & (1 << k))
        	cout  << '+';
      	else
        	cout << '-';
      	cout << v[k + 1];
      }
      cout << "=7" << endl;
      return 0; //ないと2つ出力されちゃう。
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main() {
  int n;
  cin >> n;
  
  for ( int i = 1; i <= n; i++ ) {
    if ( i % 3 == 0 ) {
      cout << " " << i;
      continue;
    }
    int j = i;
    while ( j > 0 ) {
      if ( j % 10 == 3 ) {
         cout << " " << i;
         break;
      } else j /= 10;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		//int n=sc.I;
		var s=sc.Ia;
		long ans=int.MaxValue;
		if(s[1]-s[0]>=2019){Console.WriteLine("0");return;}
		for(int i = s[0];i<s[1];i++) {
			for(int j = i+1;j<=s[1];j++) {
				ans=Min(ans,((long)i*j)%2019);
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int n,count=0,ans=0;
    cin >> n;
    vector <int> h(n);
    cin >> h[0];
    for(int i=1;i<n;i++)
    {
        cin >> h[i];
        if(h[i-1]>=h[i]) count++;
        else count=0;
        ans=max(ans,count);
    }
    printf("%d\n",ans);
}

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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, M;
int h[MN];
vector<int> g[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> M;
    for (int i = 1; i <= N; i++) cin >> h[i];
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ret = 0;
    for (int i = 1; i <= N; i++) {
        bool f = true;
        for (int j : g[i]) {
            if (h[j] >= h[i]) {
                f = false;
                break;
            }
        }
        ret += f;
    }
    cout << ret << '\n';
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    if (s[s.size() - 1] == '3') {
        cout << "bon" << endl;
    } else if (s[s.size() - 1] == '0' || s[s.size() - 1] == '1' || s[s.size() - 1] == '6' || s[s.size() - 1] == '8') {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	char[][] map;
	int[] dx = {-1,1,0,0};
	int[] dy = {0,0,-1,1};
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int data = Integer.parseInt(scan.nextLine());
			for(int dcase = 0;dcase < data;dcase++){
				scan.nextLine();
				map = new char[8][];
				for(int i = 0;i < 8;i++){
					map[i] = scan.nextLine().toCharArray();
				}
				bomb(Integer.parseInt(scan.nextLine())-1,Integer.parseInt(scan.nextLine())-1,0,-1);
				printOut(dcase+1);
			}
		}
	}
	public void bomb(int x,int y,int depth,int dir){
		if(depth == 4){
			return;
		}
		if(map[y][x] == '1'){
			map[y][x] = '0';
			for(int i = 0;i < 4;i++){
				if(y+dy[i] >= 0 && y+dy[i] < 8 && x+dx[i] >= 0 && x+dx[i] < 8){
					bomb(x+dx[i],y+dy[i],1,i);
				}
			}
		}else if(dir >= 0 && y+dy[dir] >= 0 && y+dy[dir] < 8 && x+dx[dir] >= 0 && x+dx[dir] < 8){
			bomb(x+dx[dir],y+dy[dir],depth+1,dir);
		}
		return;
	}
	public void printOut(int d){
		System.out.println("Data " + d + ":");
		for(int i = 0;i < 8;i++){
			for(int j = 0;j < 8;j++){
				System.out.print(map[i][j]);
			}
			System.out.println();
		}
	}
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var xy = ReadLongs();
            var x = xy[0];
            var y = xy[1];

            var ans = 0;
            while (x<=y)
            {
                ans++;
                x *= 2;
            }
            WriteLine(ans);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
    int N;
    cin >> N;
    map<ll, int> mp;
    mp[0] = 1;
    ll sum = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        sum += a;
        ans += mp[sum];
        mp[sum]++;
        //cout << sum << " " <<  ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
using namespace std;
#define df 0
#define MAX 10000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)



int main(){
  int a,b; cin >>a >>b;
  if(a<10 and b<10)printf("%d",a*b);
  else printf("-1");
}

/// confirm df==0 ///


Measured memory_bytes: 256
(defn abs [a b]
  (if (>= a b)
      (- a b)
      (- b a)))

(defn solve [a b c d]
  (if (<= (abs a c) d)
      "Yes"
      (if (and (<= (abs a b) d) (<= (abs b c) d))
          "Yes"
          "No")))

(println (solve (read) (read) (read) (read)))





Measured memory_bytes: 77812
//
// Created by admin on 2020/6/20.
//
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    int i=1;
    cin>>x;
    while((360*i)%x!=0)
        i++;
    cout<<(360*i)/x<<endl;
    return 0;
}


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

struct UF{
    int par[200000];
    int rank[200000];
    
    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    
    int find(int x){
        if(par[x]==x)return x;
        return par[x]=find(par[x]);
    }
    
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x!=y){
            if(rank[x]<rank[y]){
                par[x]=y;
            }else{
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
            }
        }
    }
    
    bool same(int x, int y){
        return par[x]==par[y];
    }
};

int main(void){
    int n,k,l;
    map<pair<int, int>, int> u;
    cin>>n>>k>>l;
    UF a,b;
    a.init(n);
    b.init(n);
    
    for(int i=0;i<k;i++){
        int p,q;
        cin>>p>>q;
        a.unite(p, q);
    }
    for(int i=0;i<l;i++){
        int p,q;
        cin>>p>>q;
        b.unite(p, q);
    }
    for(int i=1;i<=n;i++){
        u[pair<int,int>(a.find(i),b.find(i))]++;
    }
    for(int i=1;i<=n;i++){
        cout<<u[pair<int,int>(a.find(i),b.find(i))];
        if(i<n)cout<<" ";
        else cout<<endl;
    }
    
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 102;
const int K = 100005;

int n, k;
int a[N];
bool dp[K];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int rem = a[0]; rem <= k; rem++) {
		for (int i = 0; i < n && a[i] <= rem; i++) {
			if (!dp[rem - a[i]]) {
				dp[rem] = 1;
				break;
			}
		}
	}
	dp[k] ? puts("First") : puts("Second");
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [int(input()) for _ in range(n)]

res = 0
for i in range(n):
    res += a[i] // 2
    a[i] %= 2
    if i!=n-1:
        if a[i] and a[i+1]:
            res += 1
            a[i] -= 1
            a[i+1] -= 1
print(res)


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

#define int long long
#define double long double

const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
const double eps=1e-12;

using namespace std;

int n,m;
vector<int> edge[100001];
bool vis[100001];
int cc;

void dfs(int v){

    for(int i=0;i<edge[v].size();i++){
        if(vis[ edge[v][i] ]==0){
            vis[ edge[v][i] ]=1;
            dfs( edge[v][i] );
        }
    }

}

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int v1,v2;

    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>v1;
        cin>>v2;
        v1--;
        v2--;
        edge[v1].push_back(v2);
        edge[v2].push_back(v1);
    }

    cc=0;
    for(int i=0;i<n;i++){
        if(vis[i]==0){
            vis[i]=1;
            dfs(i);
            cc++;
        }
    }

    cout<<cc-1<<endl;

    return 0;
}


Measured memory_bytes: 10444
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <random>
#include <chrono>
#include <bitset>
#include <fstream>
#include <sstream>

using namespace std;
typedef long long ll;
typedef long double ld;

ll big = 1000000007ll;
float likeabutterfly;
string likeabee;
ll n,m,q,d,h,k,w,x;
ll T;


ll rh(ll a, ll b){

//cout << a << " " << b << "\n";

//if(a == b){return a;}
if(a == 0){return b;}
if(b%a == 0){return (2*(b/a) - 1)*a;}
//if(a > b){return rh(b,a);}
return (2*(b/a))*a + rh(b%a,a);

}

int main()
{
   ll c1,c2,c3,c4,c5,c6;
    ll a,b,c,e,g;
    ll y,z;
    //freopen("stupd.txt","r",stdin);
    //freopen("output.txt","w",stdout);

   cin >> n >> x;


   ll ans = 0;

   ans = n+rh(x,n-x);
   cout << ans << "\n";


	return 0;

}

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


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

  if(S.at(0)==S.at(1)||S.at(2)==S.at(1)||S.at(2)==S.at(3)){
    cout << "Bad" <<endl;
  }
  else{
    cout << "Good" << endl;
  }

  


  }










Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,sum1,sum2,a[110];
int main()
{
    cin>>n;
    sum1=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum1+=a[i];
    }
    cin>>m;
    sum2=sum1;
    while(m--)
    {
        int p,x;
        scanf("%d%d",&p,&x);
        if(x>=a[p-1]) sum1+=x-a[p-1];
        else sum1-=a[p-1]-x;
        cout<<sum1<<endl;
        sum1=sum2;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while((line = in.readLine()) != null){
			int n = Integer.parseInt(line);
			long sum = 0;
			for(int i=0; i<n; i++){
				line = in.readLine();
				sum += Long.parseLong(line);
			}
			sum /= n;

			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll A,B; cin>>A>>B;
  cout<<A*B<<endl;
}

Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			int ans = (n - m) * 100 + 1900 * m;
			ans *= 1 << m;
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 23380
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main() {
	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (N, A, B) = tripleIntIntLong()
    val X = listOfLong()
    val F = LongArray(N)
    for (n in 1 until N) {
        F[n] = (X[n] - X[n - 1]) * A
    }
    var ans = 0L
    for (n in 1 until N) {
        ans += if (F[n] < B) F[n] else B
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map(String::toLong)
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }


Measured memory_bytes: 51920
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e5 + 10;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

ll gcd(ll a,ll b)
{
    ll m = max(a, b);
    b = a + b - m, a = m;
    while(a%b!=0)
    {
        ll temp = b;
        b = a % b;
        a = temp;
    }
    return b;
}
int main()
{
    int k;
    string s;
    cin >> k;
    cin >> s;
    for (int i = 0; i <s.length();i++)
    {
        if (i <k)
            cout << s[i];
        else
            {
                cout << "...";
                break;
            }
    }
        system("pause");
    return 0;
}

Measured memory_bytes: 3704
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


vector<int> graph[100010];
int color[100010];
bool visited[100010][10];
int v[100010], d[100010], c[100010];

void func(int d, int v, int c) {
	if (d == 0) {
		if(!visited[v][0])color[v] = c;
		visited[v][0] = true;
	}
	else {
		if (!visited[v][d - 1]) {
			func(d - 1, v, c);
			for(int i=0;i<=d-1;i++)visited[v][i] = true;
		}
		for (auto x : graph[v]) {
			if (!visited[x][d - 1]) {
				func(d - 1, x, c);
				for (int i = 0; i <= d - 1; i++)visited[x][i] = true;
			}
		}
	}
}

int main() {
	int N;
	int cnt = 0;
	cin >> N;
	REP(i, N) {
		int a;
		cin >> a;
		if (a % 2 == 1)cnt++;
	}
	if (cnt % 2 == 1) {
		cout << "NO" << endl;
	}
	else cout << "YES" << endl;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll MAXN = 3 * 1e5 + 5;
ll n, ans; 
ll bit[65];		// bit 1

int main()
{
	scanf("%lld", &n);
	
	for(ll i = 1; i <= n; i++){
		ll inp; scanf("%lld", &inp);
		
		for(ll j = 0; j < 60; j++){
			if((1LL << j) & inp) bit[j]++;
		}
	}
	for(ll i = 0; i < 60; i++){
		ans = (ans + ( ( ((1LL << i) % mod) * bit[i]) % mod * (n - bit[i])) % mod) % mod;
	}
	printf("%lld\n", ans);
}

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var a = int.Parse(list[0]);
        var b = int.Parse(list[1]);

        int fee;
        if (a <= 5)
            fee = 0;
        else if (a <= 12)
            fee = b / 2;
        else
            fee = b;

        Console.WriteLine(fee);
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,m,p[1000];

int main(){
	while(cin>>n>>m&&n){
		rep(i,n)cin>>p[i];
		sort(p,p+n,greater<int>());
		int ans=0;
		rep(i,n)if((i+1)%m)ans+=p[i];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define REP(i,n) for(int i=0;i<n;i++)
const ll maxn=200005;
const ll mod=1e9+7;



int main(){
	ll s,i,j;
	cin>>s;
	vector<ll> dp(s+1,0);
	dp[0]=1;
	for(i=3;i<=s;++i){
		for(j=i-3;j>=0;--j)
			(dp[i]+=dp[j])%=mod;
	}
	cout<<dp[s];
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int h, w;
	cin >> h >> w;
	vector<string> c(h);
	rep(i, h) cin >> c[i];
	int ans = 0;
	for (int x = 0; x < w - 1; x++) {
		string s, t;
		for (int i = h - 1; i >= 0; i--) s += c[i][x];
		for (int i = h - 1; i >= 0; i--) t += c[i][x + 1];
		vector<vector<int>> a(h + 1, vector<int>(h + 2));
		vector<vector<int>> b(h + 1, vector<int>(h + 2));
		rep(i, h + 1) {
			rep(j, h + 1) {
				a[i][j + 1] = a[i][j] + (j + i < h && s[j] == t[j + i]);
				b[i][j + 1] = b[i][j] + (j + i < h && s[j + i] == t[j]);
			}
		}
		vector<vector<int>> dp(h + 1, vector<int>(h + 1, inf));
		dp[0][0] = a[0][h];
		rep(i, h + 1) {
			rep(j, h + 1) {
				int pre = inf;
				if (i) chmin(pre, dp[i - 1][j]);
				if (j) chmin(pre, dp[i][j - 1]);
				if (i <= j) {
					pre += a[j - i][h] - a[j - i][i];
				}
				else {
					pre += b[i - j][h] - b[i - j][j];
				}
				chmin(dp[i][j], pre);
			}
		}
		ans += dp[h][h];
	}
	cout << ans << '\n';
}

Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define F first
#define S second
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define N 200010
using namespace std;
void solve()
{
    ll n; cin>>n;
    vector<int> v(n); rep(i,0,n) cin>>v[i];
    sort(allr(v));
    ll ans=0;
    ans+=v[0];
    int curr=2;
    for(int i=1;i<n;i++)
    {
        if(curr==n)break;
        if(n-curr>=2)
            ans+=2*v[i],curr+=2;
        else
            ans+=v[i],curr=n;
    }
    cout<<ans<<endl;
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int t=1;
  //cin>>t;
  //freopen("b2.in", "r", stdin);
  //freopen("output2.txt", "w", stdout);
  for(int i=1;i<=t;i++)
  {
      solve();
  }
  return 0;
}


Measured memory_bytes: 3988
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int A, B;
    int ans;
    cin >> A >> B;

    if ( A % 2 == 0 && B % 2 == 0 || A % 2 != 0 && B % 2 != 0 ){
        ans = abs(B + A) / 2 ;
        cout << ans << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
map<int,int> xmp; //座標圧縮
map<int,int> ymp; //座標圧縮
P win[100];
P car[4];
vector<int> x;
vector<int> y;

//横xmp[x]-xmp[x-1] 縦ymp[y]-ymp[y-1]の長方形がカーテンの領域でないかつ窓の領域ならその面積を出力
//そうでないなら0
ll addrect(int x,int y,int n)
{
	ll ret=0;
	//左下で判定（全部入ってるかそうでないかのどっちかしかない）
	pair<double,double> p=make_pair((double)(xmp[x]+xmp[x-1])/2.0,(double)(ymp[y]+ymp[y-1])/2.0);
	int cnt=0;
	//cerr<<p.first<<" "<<p.second<<endl;
	for(int i=1;i<5;i++)
	{
		int j=i-1;
		//調べている点よりも左にある縦線を調べる
		if(car[j].first<p.first && car[j].first==car[i%4].first)
		{
			if(p.second>min(car[j].second,car[i%4].second) && p.second<max(car[j].second,car[i%4].second))
				cnt++;
		}
	}
	if(cnt%2==1)
		return 0;
	cnt=0;
	for(int i=1;i<n+1;i++)
	{
		int j=i-1;
		//調べている点よりも左にある縦線を調べる
		if(win[j].first<p.first && win[j].first==win[i%n].first)
		{
			if(p.second>min(win[j].second,win[i%n].second) && p.second<max(win[j].second,win[i%n].second))
				cnt++;
		}
	}
	//cerr<<cnt<<endl;
	if(cnt%2==1)
		ret=(ll)(xmp[x]-xmp[x-1])*(ll)(ymp[y]-ymp[y-1]);
	return ret;
}

int main()
{
	while(1)
	{
		int n;
		ll ans=0;
		cin>>n;
		if(n==0)
			break;
		x.clear();
		y.clear();
		xmp.clear();
		ymp.clear();
		for(int i=0;i<n;i++)
		{
			int a,b;
			cin>>a>>b;
			win[i]=P(a,b);
			x.push_back(a);
			y.push_back(b);
		}
		for(int i=0;i<4;i++)
		{
			int a,b;
			cin>>a>>b;
			car[i]=P(a,b);
			x.push_back(a);
			y.push_back(b);
		}
		sort(x.begin(),x.end());
		x.erase(unique(x.begin(),x.end()),x.end());
		sort(y.begin(),y.end());
		y.erase(unique(y.begin(),y.end()),y.end());
		for(int i=0;i<x.size();i++)
			xmp[i]=x[i];
		for(int i=0;i<y.size();i++)
			ymp[i]=y[i];
		
		for(int i=1;i<x.size();i++)
		{
			for(int j=1;j<y.size();j++)
			{
				ans+=addrect(i,j,n);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;

const int N = 2e5 + 5;
int dp[N], b[N], cnt[N], n, q, st[4 * N];
vector <int> endPoints[N];

int Left(int x) {return (x << 1);}
int Right(int x) {return (x << 1) + 1;}

void update(int id, int L, int R, int i, int j, int val) {
	if (L > j || R < i) return;
	if (L >= i && R <= j) {
		st[id] = min(st[id], val);
		return;
	}
	int mid = (L + R) >> 1;
	update(Left(id), L, mid, i, j, val);
	update(Right(id), mid + 1, R, i, j, val);
}

int get(int id, int L, int R, int i) {
	if (i == 0) return 0;
	if (L > i || R < i) return N;
	if (L == R) return st[id];
	int mid = (L + R) >> 1;
	if (i <= mid) return min(st[id], get(Left(id), L, mid, i));
	else return min(st[id], get(Right(id), mid + 1, R, i));
}

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

	cin >> n;
	for (int i = 1; i <= 4 * n; ++i)
		st[i] = N;
	for (int i = 1; i <= n; ++i) {
		cin >> b[i];
		cnt[i] = cnt[i - 1] + (b[i] == 0 ? 1 : 0);
	}
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		endPoints[r].push_back(l);
	}
	for (int i = 1; i <= n; ++i) {
		update(1, 1, n, i, i, get(1, 1, n, i - 1) + (b[i] == 0 ? -1 : 1));
		for (int l : endPoints[i]) {
			update(1, 1, n, l, i, get(1, 1, n, l - 1));
		}
	}
	cout << cnt[n] + get(1, 1, n, n) << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    A = A * N;
    cout << ((A >= B) ? B : A) << endl;
} 

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

const int maxn=1e5+10;

int n,m,f[maxn],fk[maxn],dep[maxn];
LL k,x[maxn],y[maxn];

int main()
{
	int i,pos;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%lld",&x[i]);
	for (i=n;i>=1;i--) x[i]-=x[i-1];
	for (i=1;i<=n;i++) f[i]=i;
	scanf("%d%lld",&m,&k);
	for (i=1;i<=m;i++)
	{
		scanf("%d",&pos);
		swap(f[pos],f[pos+1]);
	}
	for (i=1;i<=n;i++)
		if (!dep[i])
		{
			int u=i,v,move;
			while (1)
			{
				dep[f[u]]=dep[u]+1;
				u=f[u];
				if (u==i) break;
			}
			for (move=k%dep[i],v=i;move--;) v=f[v];
			for (fk[i]=v;u=f[u],v=f[v],u!=i;) fk[u]=v;
		}
	for (i=1;i<=n;i++) y[i]=x[fk[i]];
	for (i=1;i<=n;i++)
		y[i]+=y[i-1],printf("%lld\n",y[i]);
}


Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[N+1000];
        int[] memo = new int[N+1000];

        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            memo[i]=-1;
        }

//        int[] dp = new int[N+1000];
//        for (int i = 0; i <dp.length ; i++) {
//            dp[i] = Integer.MAX_VALUE;
//        }
//        dp[1] = 0;
//        for (int i = 2; i <= N ; i++) {
//            for (int j = Math.max(1,i-K) ; j <= i-1 ; j++) {
//                int val  =Math.min(dp[i], dp[j] +Math.abs(arr[j-1]-arr[i-1]));
//                dp[i] = val;
//            }
//        }
//        System.out.println(dp[N]);
        System.out.println(recur(arr,memo,K,N-1));

    }

    static public int recur(int[] arr,int[] memo,int K, int idx){
        if(memo[idx]!=-1) return memo[idx];
        if(idx <=0){
            return 0;
        }

        int min = Integer.MAX_VALUE;
        for (int i = Math.max(0,idx-K); i <= idx-1; i++) {
            min = Math.min(min, recur(arr,memo,K,i) + Math.abs(arr[idx] - arr[i]));
        }

        memo[idx] =min;
        return min;
    }


}


Measured memory_bytes: 59836