akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        long k = sc.nextLong();
        int n = s.length();
        sc.close();

        long ans = 0;
        if(s.charAt(0) != s.charAt(n-1)){
            int idx = 0;
            while(idx < n-1){
                if(s.charAt(idx)==s.charAt(idx+1)){
                    ans++;
                    idx++;
                }
                idx++;
            }
            ans *= k;
        } else {
            if(allsame(s)){
                ans = (n*k)/2;
            } else {
                int l = 0;
                int r = n-1;
                while(s.charAt(l) == s.charAt(l+1)){
                    l++;
                }
                while(s.charAt(r) == s.charAt(r-1)){
                    r--;
                }
                int idx = 0;
                while(idx < n-1){
                    int count = 1;
                    while(idx < n-1 && s.charAt(idx)==s.charAt(idx+1)){
                        count++;
                        idx++;
                    }
                    ans += count/2;
                    idx++;
                }
                ans *= k;
                ans += ((l+1)+(n-r))/2*(k-1);
                ans -= (l+1)/2*(k-1);
                ans -= (n-r)/2*(k-1);
                
            }
            
        }
        System.out.println(ans);
    }

    static boolean allsame(String s){
        for(int i = 0; i < s.length()-1; i++){
            if(s.charAt(i)!=s.charAt(i+1))
                return false;
        }
        return true;
    }
}

Measured memory_bytes: 21844
x, n = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if len(a) == 0:
    print(x)
    quit()
y = x
while y in a:
    y -= 1
z = x
while z in a:
    z += 1
if x - y > z - x:
    print(z)
else:
    print(y)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    vll A(N + 1), B(N);
    for (size_t i = 0; i < N + 1; i++)
    {
        cin >> A[i];
    }
    for (size_t i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    ll ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (A[i] < B[i])
        {
            ll tmp = A[i + 1];
            A[i + 1] = max(0LL, A[i + 1] - (B[i] - A[i]));
            ans += tmp - A[i + 1] + A[i];
        }
        else
        {
            ans += B[i];
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

const int MAX_N = 202;

using vint = vector<int>;

vint G[MAX_N];
bool H[MAX_N][MAX_N];

int col[MAX_N];
bool dfs(int u, int c) {
 col[u] = c;
  for(int v : G[u]) {
    if(col[v] == c) assert(false);//return false;
    if(col[v] == 0) dfs(v, -c);
  }
  return true;
}

int main() {
  int n;
  while(cin >> n, n) {
    for(int i = 0; i < MAX_N; ++i) G[i].clear();
    memset(H, false, sizeof(H));
    memset(col, 0, sizeof(col));
    map<string, int> mp;
    int sz = 0;
    for(int i = 0; i < n; ++i) {
      string cross;
      cin >> cross;
      int idx = cross.find('-');
      string s = cross.substr(0, idx);
      string t = cross.substr(idx+1);
      if(!mp.count(s)) mp[s] = sz++;
      if(!mp.count(t)) mp[t] = sz++;
      int u = mp[s], v = mp[t];
      G[u].push_back(v);
      G[v].push_back(u);
      H[u][v] = true;
    }
    cout << sz << endl;
    for(int i = 0; i < sz; ++i) {
      if(!col[i]) dfs(i, 1);
    }
    for(int i = 0; i < sz; ++i) {
      for(int j = i+1; j < sz; ++j) {
	bool c = false;
	bool d = true;
	bool e = true;
	for(int k = 0; k < sz; ++k) {
	  if(i == k || j == k) continue;
	  if(H[i][k] && H[j][k]) c = true;
	  if(H[k][i] && H[k][j]) c = true;
	  if(H[k][i] && H[j][k]) d = false;
	  if(H[i][k] && H[k][j]) e = false;
	}
	H[i][j] |= (c&&d&&e);
	H[j][i] |= (c&&d&&e);
      }
    }
    for(int i = 0; i < sz; ++i) {
      for(int j = 0; j < sz; ++j) {
	for(int k = 0; k < sz; ++k) {
	  H[j][k] |= H[j][i]&H[i][k];
	}
      }
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; ++i) {
      string cross;
      cin >> cross;
      int idx = cross.find('-');
      string s = cross.substr(0, idx);
      string t = cross.substr(idx+1);
      if(!mp.count(s)) {
	cout << "NO" << endl;
	continue;
      }
      if(!mp.count(t)) {
	cout << "NO" << endl;
	continue;      
      }
      int u = mp[s], v = mp[t];
      //cout<<col[u]<<" "<<col[v]<<endl;      
      if(col[u] == col[v]) {
	cout << "NO" << endl;
	continue;
      }
      if(H[u][v]) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
  }
  return 0;
}


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

int main(){
	
	string abc;
	int m,h;
	
	while (1){
		cin >> abc;
		if (abc=="-") break;
		cin >> m;
		for (int i=0; i<m; i++){
			cin >> h;
			abc = abc.erase(0,h)+abc.substr(0,h);
		}
		cout << abc << endl;
	}
	return 0;
}

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

int main()
{
    int a, b;
    string op;

    while (true)
    {
        cin >> a >> op >> b;
        if (op == "?")
            break;
        else if (op == "+")
            cout << a + b << endl;
        else if (op == "-")
            cout << a - b << endl;
        else if (op == "*")
            cout << a * b << endl;
        else if (op == "/")
            cout << a / b << endl;
        else if (op == "%")
            cout << a % b << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
using namespace std;
 
 
int main(){
    int64_t n,ans=0;
    cin>>n;

    
    vector<int> l(n);
    for(int i=0;i<n;i++)cin>>l.at(i);
    sort(l.begin(),l.end());
    
   for(int i=0;i<n-2;i++){//1th smallest
       for(int j=i+1;j<n-1;j++){//2th smallest
           //3th <<1th + 2th
           /*
           for(int k=j+1;k<n;k++){
               if(l.at(k)<l.at(i)+l.at(j))ans++;
               else break;
           }*/
           int key=l.at(i)+l.at(j);
           //ans+=n-
           auto it =lower_bound(ALL(l), key);
           int index = it - l.begin();
           //if(index==n)--index;
           ans+=index-j-1;
          // cout<<l.at(i)<<" "<<l.at(j)<<" "<<l.at(index)<<endl;
           
       }
   }
    cout<<ans<<endl;
    
   
    
}

Measured memory_bytes: 384
#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int max_n = 2e5+10, inf = 1000111222;

int a[max_n];

int main() {
//    freopen("barik.in", "r", stdin);
//    freopen("barik.out", "w", stdout);

    int n;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);

    multiset<int> cur;
    cur.insert(a[0]);
    ll ans=0;
    for (int i=1;i<n;i++){
//        cout<<" i :: "<<*(--cur.end())<<"\n";
        ans+=*(--cur.end());
        cur.erase(--cur.end());
        cur.insert(a[i]);
        cur.insert(a[i]);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 13780
from itertools import zip_longest

MOD = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))

a = ['{:b}'.format(i)[::-1] for i in a]

ans = 0
for k, v in enumerate(zip_longest(*a, fillvalue='0')):
    x = v.count('1')
    ans += x * (n - x) * 2**k % MOD

print(ans % MOD)

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

int main(){
  int k,n;cin>>k>>n;
  vector<int> cir(n);
  int m=0;
  int a;cin>>a;
  int c=a;
  for(int i=0;i<n-1;i++){
    int b;cin>>b;
    cir[i]=b-a;a=b;
    m=max(m,cir[i]);
  }
  cir[n-1]=k-a+c;
  m=max(m,cir[n-1]);
  
  cout<<k-m<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<typeinfo>
#define ll  long long 
#define ull unsigned long long 
#define ld  long double
#define pb  push_back
#define pf  push_front
#define mp  make_pair
#define all(v)  v.begin(),v.end()
#define BP(n)  __builtin_popcount(n)
#define bs(v,x)  binary_search(all(v),x)
#define lb(v,x) lower_bound(all(v),x) //first equal to or lower than element
#define ub(v,x) upper_bound(all(v),x) //first greater than element
#define rep(i,n)  for(i=0;i<n;i++)
#define rep1(j,n)  for (j=i+1;j<n;j++)
#define Unique(v)  vector<int>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define M  1000000007
#define PI  acos(-1.0)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
using namespace std;
void input(vector<int>& v,int n){ int i,io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<int> v) { int i; rep(i,v.size()) cout<<v.at(i)<<" "; }
map<int,int>  frequency(vector<int> v){ int i; map<int,int> m; rep (i,v.size()) {  if (m.find(v[i])==m.end()) m.insert({v.at(i),1}); else m[v.at(i)]++; } return m; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(int n) { if (n&(n-1)==0) return true; else return false; }
int string_to_int(string s) { stringstream geek(s); long x = 0; geek >> x; return x; }
bool binary_pred(int a,int b){ return a==b; }
void getans() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<ll> v;
    v.pb(a*c),v.pb(a*d),v.pb(b*c),v.pb(b*d);
    cout<<*max_element(all(v))<<endl;
}
int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    #endif
    int T = 1;
    //cin >> T;
    while (T--) 
        getans();
}
// Check for corner cases
// Check for special case like n = 0 or n = INT_MAX
// Check for Buffer Overflow or use of unsigned variable if any
// Check if problem can be solved mathematically

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

int main(){
	double n,s[1005],sum;
	cin>>n;
	while(n != 0){
		sum = 0;
		for(int i=0;i<n;i++){
			cin>>s[i];
			sum+=s[i];
		}
		double average = sum / n;
		sum=0;
		for(int i=0;i<n;i++){
			sum+=(s[i]-average)*(s[i]-average);
		}
		cout<<fixed<<setprecision(4);
		cout<<sqrt(sum/n)<<endl;
		cin>>n;
	}
}


Measured memory_bytes: 3208
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (300001)
#define MOD (1000000007)

// 指定された要素以上の値が現れる最初の位置のイテレータ
// [l,r)
typedef int lb;
int lower_bound(lb* a, lb val, int l, int r)
{
    if(l==r) return l;
    int m = (l+r)/2;
    if(a[m]<val) return lower_bound(a,val,m+1,r);
    else return lower_bound(a,val,l,m);
}

int c[MAXN];
int cs[MAXN];
int main(void)
{
    ll n;
    scanf("%ld",&n);
    for(int i=0;i<n;i++)
    {
        ll a;
        scanf("%ld",&a);
        c[a]++;
    }
    qsort(c,MAXN,sizeof(int),acs);
    cs[0] = c[0];
    for(int i=1;i<MAXN;i++) cs[i]=cs[i-1]+c[i];
    
    for(int k=1;k<=n;k++)
    {
        int ans = n/k;
        for(;ans>0;ans--)
        {
            int i = lower_bound(c,ans,0,MAXN);
            int s = i>0 ? cs[i-1] : 0;
            s += (MAXN-i)*ans;
            if(s>=(ans*k)) break;
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3176
n = int(input())
d = {}
for a in list(map(int, input().split())):
    if a not in d:
        d[a] = 0
    d[a] += 1
r = sum(k*d[k] for k in d.keys())

q = int(input())
for _ in range(q):
    b,c = map(int, input().split())
    if b not in d:
        pass
    elif c not in d:
        d[c] = d[b]
        r = r - b*d[b] + c*d[c]
    else:
        d[c] += d[b]
        r = r - b*d[b] + c*d[b]
    d[b] = 0
    print(r)

Measured memory_bytes: 22964
#include<bits/stdc++.h>
using namespace std;
#define int long
int n,m,r;
main(){
	cin>>n>>m;
	vector<int> a(m),b(m),c(m),d(n,-1e18),nc(n,0);
	for(int i=0;i<m;++i){
		cin>>a[i]>>b[i]>>c[i];
		--a[i];--b[i];
	}
	d[0]=0;
	for(int i=0;i<2*n-1;++i)for(int j=0;j<m;++j){
		if(d[a[j]]+c[j]>d[b[j]]){
			if(i>n-2)nc[b[j]]=1;
			d[b[j]]=d[a[j]]+c[j];
		}
		nc[b[j]]|=nc[a[j]];
		if(i==n-2)r=d[n-1];
	}
	if(nc[n-1])cout<<"inf";
	else cout<<r;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];

    sort(ALL(l));

    int ans = 0;
    rep(i, n - 1) ans += l[i];
    if (ans > l[n - 1])
        OP("Yes");
    else
        OP("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const double pi = acosl(-1.0);
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  for (int i = 0; i < n; i++) {
    vector<double> ang;
    for (int j = 0; j < n; j++) {
      if (i != j) {
        ang.push_back(atan2(y[j] - y[i], x[j] - x[i]));
      }
    }
    sort(ang.begin(), ang.end());
    double mx = 0.0;
    for (int j = 0; j < n - 2; j++) {
      mx = max(mx, ang[j + 1] - ang[j]);
    }
    mx = max(mx, ang[0] + 2 * pi - ang[n - 2]);
    double res = (mx > pi ? (mx - pi) / 2 / pi : 0.0);
    cout << fixed << setprecision(17) << res << '\n';
  }
  return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int gcd(int A, int B)
{
	while (1)
	{
		A = A % B;
		if (A == 0)
			return B;
		B = B % A;
		if (B == 0)
			return A;
	}
}

int check(VI &a, int x) {
	int cnt = 0;
	int n = a.size();
	int mi = 2e9;
	int idx = -1;
	REP(i, n) {
		if (gcd(x, a[i]) < mi) {
			idx = i;
			mi = gcd(x, a[i]);
		}
	}
	REP(i, n) {
		if (i == idx)continue;
		x = gcd(x, a[i]);
	}
	return x;
}

int main() {
	int n;
	scanf("%d", &n);
	VI a(n);
	REP(i, n)scanf("%d", &a[i]);
	SORT(a);
	cout << max(check(a, a[0]), check(a, a[1])) << endl;
	
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    double h = nextDouble();

    //分裂する回数
    long num = (long)(Math.log(h)/Math.log(2.0));

    long ans = 0;

    while(num>=0){
      ans += (long)(Math.pow(2,num));
      num --;
    }


    System.out.println(ans);

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

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

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

int main() {
  int s,s1,s2,s3;
  cin >> s;
  s1 = s / 100;
  s2 = s % 100 / 10;
  s3 = s % 10;
  cout << s1+s2+s3 <<endl;
}

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

Measured memory_bytes: 128
while 1:
    n, m = map(int, input().split())
    if n == 0:
        break

    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            if m < a[i] + a[j]:
                continue

            ans = max(ans, a[i] + a[j])

    if ans == 0:
        print("NONE")
    else:
        print(ans)



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

int M=1e9+7;

main(){
  int n,k,a=1;
  cin>>n>>k;
  r(i,n)a=(a*k)%M;
  cout<<a<<endl;
}


Measured memory_bytes: 3112
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  s = InputLine.to_s

  if s == 'ABC' then
    puts 'ARC'
  else
    puts 'ABC'
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14416
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int n;
    ll p;
    string s;
    cin >> n >> p >> s;
    long long ans = 0;
    if(p==2 || p==5){
        rep(i,n) if((s[i]-'0')%p==0) ans+=(i+1);
        cout << ans << endl;
        return 0;
    }
    vector<ll> vec;
    ll now = (s[n-1]-'0')%p;
    vec.push_back(now);
    ll beki  = 10%p; 
    for(int i = n-2;i>=0;i--){
        vec.push_back((beki*(s[i]-'0')+now)%p);
        now = (beki*(s[i]-'0')+now)%p;
        beki*=10;
        beki%=p;
    }
    //Debug_Output_ALL(vec);
    vec.push_back(0);
    sort(All(vec));
    ll streak = 1;
    for(int i = 1;i<vec.size();i++){
        if(vec[i]!=vec[i-1]){
            ans+=((streak-1)*streak)/2;
            streak=1;
        }
        else streak++;
    }
    ans+=((streak-1)*streak)/2;
    cout << ans << endl;
}

Measured memory_bytes: 2680
#include <iostream>
using namespace std;
char m[100][101];
int h, w;
void dfs(int x, int y, char c)
{
	int i, j, nx, ny, dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
	m[y][x] = '.';
	for (i = 0; i < 4; i++)
	{
		nx = x + dx[i];
		ny = y + dy[i];
		if (0 <= nx && nx < w && 0 <= ny && ny < h && m[ny][nx] == c) dfs(nx, ny, c);
	}
	return;
}
int main()
{
	int i, j, n;
	while (cin >> h >> w)
	{
		if (h == 0 && w == 0) break;
		for (i = 0; i < h; i++)
		{
			cin >> m[i];
			if (cin.eof()) return 0;
		}
		n = 0;
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				if (m[i][j] != '.')
				{
					n++;
					dfs(j, i, m[i][j]);
				}
			}
		}
		cout << n << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll s, ans = 0;
    cin >> s;
    rep(i, 3){
        if(s % 10){
            ans++;
        }
        s /= 10;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin>>n>>k;
  vector<int>fruit(n);
  for(int i;i<n;i++) cin>>fruit.at(i);
  sort(fruit.begin(),fruit.end());
  int sum=0;
  for(int i;i<k;i++){
    //cout<<fruit.at(i)<<endl;
    sum+=fruit.at(i);
  }
  cout<<sum<<endl;

}

Measured memory_bytes: 3600
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

// repetition
// ----------------------------------------------------------------------------
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGINT(x) printf("%d\n", x);
#define DEBUGFLOAT(x) printf("%f\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORINT(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORFLOAT(i, a, b,x ) FOR(i, a, b){ printf("%f ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPINT(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPFLOAT(i, n, x) REP(i, n){ printf("%f ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    int n;
    int i, j;
    int list[6];
    double hight;

    scanf("%d", &n);

    memset(list, 0, sizeof(list));

    for (i = 0; i < n; ++i){
        scanf("%lf", &hight);
        
        if (hight < 165.0){
            list[0]++;
        }
        else if (hight >= 165.0 && hight < 170.0){
            list[1]++;
        }
        else if (hight >= 170.0 && hight < 175.0){
            list[2]++;
        }
        else if (hight >= 175.0 && hight < 180.0){
            list[3]++;
        }
        else if (hight >= 180.0 && hight < 185.0){
            list[4]++;
        }
        else if (hight >= 185.0){
            list[5]++;
        }
    }
    
    for (i = 0; i < 6; ++i){
        printf("%d:", i + 1);
        for (j = 0; j < list[i]; ++j){
            printf("*");
        }
        printf("\n");
    }

    return 0;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() { 
    int n;
    cin >> n;
    int a[110000];
    rep(i, n) cin >> a[i];
    int flag = 0;
    int count = 0;
    rep(i, n - 1) {
        if(a[i] < a[i + 1]) {
            if(flag == 2) {
                count++;
                flag = 0;
            }
            else flag = 1;
        }
        else if(a[i] > a[i + 1]) {
            if(flag == 1) {
                count++;
                flag = 0;
            }
            else flag = 2;
        }
    }
    cout << count + 1 << endl;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int arr[100008];
int main(){
 	int n,s,m;
 	cin>>n>>s>>m;
	 for(int i=1;i<=m;++i)
	 {
	 	int d;
	 	cin>>d;
	 	arr[d]++;
	  } 
	  for(int i=1;i<=n;++i)
	  {
	  	if(s+arr[i]>m)cout<<"Yes"<<endl;
	  	else cout<<"No"<<endl;
	  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int solve(int64_t n, int64_t t, std::vector<int64_t> hs) {
  int ret = 0;
  int64_t diff = INT64_MAX;
  for (int i = 0; i < n; ++i) {
    int64_t const average = abs(t - hs[i] * 6);
    if (average >= diff) {
      continue;
    }
    diff = average;
    ret = i + 1;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  int64_t t;
  std::cin >> t;
  t *= 1000;
  int64_t a;
  std::cin >> a;
  a *= 1000;
  t -= a;
  std::vector<int64_t> hs(n);
  for (int i = 0; i < n; i++) {
    std::cin >> hs[i];
  }
  auto const res = solve(n, t, std::move(hs));
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        int taro = 0;
        int hanako = 0;
        for(int i = 0; i < n; i++) {
            String line1 = sc.nextLine();
            String[] ani = line1.split(" ");
            if(ani[0].compareTo(ani[1]) < 0) {
                hanako += 3;
            } else if(ani[1].compareTo(ani[0]) < 0) {
                taro += 3;
            }else if(ani[1].compareTo(ani[0]) == 0) {
                taro += 1;
                hanako += 1;
            }
        }
        System.out.println(taro + " " + hanako);

    }
 }


Measured memory_bytes: 30824
#include <bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 5 ;

int freq[N] , dp[N] ;


int main () {


    int n ;
    cin >> n ;
    int ans = 0;
    for (int i = 1; i <= n ; i++) {
        int x ; cin >> x ;
        dp[x] = dp[x-1]+1 ;
        ans = max(ans , dp[x]) ;
    }

    cout << n - ans ;

}


Measured memory_bytes: 1024
N,m,*A = `dd`.split.map &:to_i
while m > 0 do
  A.sort_by!{ |a| -a }
  msb = nil
  A.each_with_index{ |a,i|
    msb ||= 1 << (a.bit_length-1)
    if (msb & a) == msb
      A[i] /= 2
      m -= 1
    end
    break if m == 0
  }
end

p A.reduce(0,:+)

Measured memory_bytes: 13640
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    char a[s.size()];
    for(int i=0;i<s.size();i++) a[i]=s[i];
    sort(a,a+s.size());
    int b=97;
    for(int i=0;i<s.size();i++){
        if(a[i]==b) b++;
        else if(a[i]>b){
            cout<<(char) b<<endl;
            return 0;
        }
    }
    if(b-123) cout<<(char) b<<endl;
    else cout<<"None"<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long int divCount(long long int n) 
{ 
    vector<int>a(n+1,0);
    long long int i,j;
    for(i=1;i<=n;i++)
    {
      for(j=0;j<=n;j+=i)
      {
        a[j]++;
      }
    }
    long long int k=0;
    for(i=1;i<=n;i++)
    {
      k+=i*a[i];
    }
    return k;
}
    int main()
    {
      long long int n,sum=0;
      cin>>n;
      cout<<divCount(n)<<endl;
} 

Measured memory_bytes: 42288
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
long long int dp[3001][3001];

vector<ll> v;

ll solve( int i, int j){


if(dp[i][j]!=-1){
    return dp[i][j];

}
if(i>j){
   return 0;

}

if(i==j){
    return v[i];
}

if(j==i+1){
    return max(v[i],v[j]);

}


long long int ans=max(v[i]+min(solve(i+2,j),solve(i+1,j-1)), v[j]+min(solve(i+1,j-1),solve(i,j-2)));

return dp[i][j]=ans;


}


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

    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=-1;

        }
    }

    

     ll totalsum=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        totalsum+=x;

        v.push_back(x);

    }

    ll X=solve(0,v.size()-1);

    

    ll Y=totalsum-X;

    cout<<X-Y;



   

}


Measured memory_bytes: 70784
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        a: [Usize1;n-1],
    }

    let mut ct = vec![0; n];
    for &x in &a {
        ct[x] += 1;
    }

    for &x in &ct {
        println!("{}", x);
    }
}


Measured memory_bytes: 5464
import java.util.Scanner;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
        }
        int s1 = 0;
        int min = 100;
        for (int i = 0; i < n; i++) {
            int s2 = 0;
            s1 += w[i];
            for (int t = i+1; t < n; t++) {
                s2 += w[t];
            }
            int sum = s2 - s1;
            if (sum < 0) {
                sum = -sum;
            }
            if (sum < min) {
                min = sum;
            }
        }
        System.out.println(min);
    }

}


Measured memory_bytes: 21588
n,k=map(int,input().split())
A=[int(x) for x in input().split()]

s,l=0,max(A)
while l-s>1:
  m=(s+l)//2
  if sum([(a-1)//m for a in A]) >k:
    s=m
  else:
    l=m

print(l)


Measured memory_bytes: 30852
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	ll r,d,x;
	cin>>r>>d>>x;
	for(int i=0;i<10;i++){
		cout<<r*x-d<<endl;
		x=r*x-d;
	}
	return 0;
}



Measured memory_bytes: 256
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for _ in range(n):
	s=list(input())
	s.sort()
	s=''.join(s)
	dic[s]+=1
ans=0
for (k,v) in dic.items():
	ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 18192
times = int(raw_input())
numbers = {}
result = 0

for x in xrange(times):
    number = int(raw_input())
    if number not in numbers:
        numbers[number] = 0
    numbers[number] += 1

for item in numbers:
    if numbers[item] % 2 != 0:
        result += 1

print result

Measured memory_bytes: 13884
#include <stdio.h>
int main()
{
	int l,r,d;
	scanf("%d%d%d",&l,&r,&d);
	int ans = 0;
	for (int i = l;i<= r;i++)
		if (i%d==0)
			ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1732
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
    auto a = readln.chomp.split.map!(to!int);
    int w = a[0], h = a[1], x = a[2], y = a[3], r = a[4];

    if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h) {
        writeln("Yes");
    } else {
        writeln("No");
    }
}

Measured memory_bytes: 1060
#include <iostream>

using namespace std;

#define MAX_N (30)

void swap(int *a, int *b)
{
    int tmp;
    
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int main()
{
    int w;  // 縦線
    int n;  // 横線
    int a, b;
    char c;
    int amida[MAX_N];
    
    cin >> w;
    for (int i = 0; i < w; i++){
        amida[i] = i + 1;
    }
    
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a >> c >> b;
        swap(&amida[a - 1], &amida[b - 1]);
    }
    
    for (int i = 0; i < w; i++){
        cout << amida[i] << endl;
    }
}

Measured memory_bytes: 1160
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

#define LL long long int
 
int N;

LL ans = 0;

pair<int,int> extract_top_and_bottom(int x){//xの最上位の桁と最下位の桁を取り出す
	int bottom = x%10;
	int top = x%10;
	while(1){
		x /= 10;
		if(x==0) break;
		top = x%10;
	}
	return make_pair(top,bottom);
}
 
void solve(){
	map<pair<int,int>,int> combnum;//(a,b)の組み合わせがいくつあるか
	for(int i=1;i<=N;i++){
		combnum[extract_top_and_bottom(i)]++;
	}
	for(int top=1;top<=9;top++){
		for(int bottom=1;bottom<=9;bottom++){
			ans += (combnum[make_pair(top,bottom)]*combnum[make_pair(bottom,top)]);
		}
	}
}
 
int main(){
	cin>>N;

	solve();

	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int h,w;
	string p[100];
	
	cin>>h>>w;
	for(int i=0;i<h;i++){
		cin>>p[i];
	}
	for(int i=0;i<h;i++){
		cout<<p[i]<<endl<<p[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	ll a, b;
	cin >> a >> b;

	if (a % 2 == 1 && b % 2 == 1) {
		ll t = (b - a) / 2;
		if (t % 2 == 0) t = 0;
		else t = 1;
		ll ans = a ^ t;
		cout << ans << endl;
	} else if (a % 2 == 0 && b % 2 == 0) {
		ll t = (b - a) / 2;
		if (t % 2 == 0) t = 0;
		else t = 1;
		ll ans = t ^ b;
		cout << ans << endl;
	} else if (a % 2 == 0 && b % 2 == 1) {
		ll t = (b + 1 - a) / 2;
		if (t % 2 == 0) cout << 0 << endl;
		else cout << 1 << endl;
	} else {
		ll t = (b - (a + 1)) / 2;
		if (t % 2 == 0) t = 0;
		else t = 1;
		ll ans = t ^ a ^ b;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3608
#include<iostream>

using namespace std;

#define rep(i,n) for(i=0;i<(n);i++)
#define For(i,a,b) for(i=(a);i<(b);i++)



int main(){
  int i,j,k;

  int w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;

  if(r<=x && r<=y && w-r>=x && h-r>=y) cout << "Yes";
  else cout << "No";
  cout << endl;
  
  return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

const ll INF = 1LL<<50;

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n);
	rep(i, n) cin >>a[i];
	
	vector<VL> dp(n+2, VL(2));
	dp[0] = VL{0, -INF};
	rep(i, n) rep(j, 2){
		dp[i+1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
		dp[i+1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
	}
	
	cout <<dp[n][0] <<"\n";

	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>>key;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		int s = 0;
		for (int j = 0; j < b; j++) {
			int c;
			cin >> c;
			--c;
			s |= 1 << c;
		}
		key.emplace_back(s, a);
	}
	vector<int>dp(1 << n, 0X3F3F3F3F);
	dp[0] = 0;
	for (int s=0; s < 1 << n; s++) {
		for (int i = 0; i < m; i++) {
			int t = s | key[i].first;
			int cost = dp[s] + key[i].second;
			dp[t] = min(cost, dp[t]);
		}
	}
	int ans = dp.back();
	if (ans == 0X3F3F3F3F)
		cout << -1;
	else
		cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

ll lcm(ll a, ll b) {
  return a/__gcd(a, b)*b;
}

ll f(ll n) {
  ll cnt = 0;
  while (n%2 == 0) {
    n /= 2;
    cnt++;
  }
  return cnt;
}

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

  ll n, m;
  cin >> n >> m;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
    a[i] /= 2;
  }

  rep(i, n) {
    if (f(a[0]) != f(a[i])) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll t = 1;
  rep(i, n) {
    t = lcm(t, a[i]);
  }
  cout << m/t-m/(2*t) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<ll> a(n), v(n);
  rep(i, 0, n) {
    cin >> a[i];
    v[i] = a[i] - (i + 1);
  }

  vector<ll> sv = v;
  sort(sv.begin(), sv.end());
  int mid = n / 2;
  int add1 = 0, add2 = 0;
  if (sv[mid] > 0)
    add1 = -sv[mid];

  if (n % 2 == 0)
    mid--;
  if (sv[mid] < 0)
    add2 = -sv[mid];

  ll ans1 = 0, ans2 = 0;
  rep(i, 0, n) ans1 += abs(v[i] + add1);
  rep(i, 0, n) ans2 += abs(v[i] + add2);

  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 4992
//kalyanchirla
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
#define int long long
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define csl ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007

int32_t main()
{ 
    csl;

    int n,t;
    cin >> n >> t;

    int arr[n];
    for(int i=0;i<n;i++) cin >> arr[i];

    int sum =t;
    for(int i=0;i<n-1;i++)
    {
        sum+=(min(t,arr[i+1]-arr[i]));
    }
    cout << sum << "\n";
}

Measured memory_bytes: 5164
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int n = sc.nextInt();
			if (n == 0) return;
			
			List<Bridge> bridges = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				bridges.add(new Bridge(sc.nextInt(), sc.nextInt()));
			}
			Collections.sort(bridges);
			
			boolean flag = true;
			int bag = 0;
			for (int i = 0; i < n; i++) {
				Bridge b = bridges.get(i);
				bag += b.tre;
				if (bag > b.max) {
					flag = false;
					break;
				}
			}
			if (flag) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
	
	static class Bridge implements Comparable<Bridge> {
		int tre, max;
		
		public Bridge(int tre, int max) {
			this.tre = tre;
			this.max = max;
		}
		
		@Override
		public int compareTo(Bridge b) {
			return this.max - b.max;
		}
		
	}
	
}

Measured memory_bytes: 32200
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes here
            var input =Console.ReadLine().Split(' ');
            string a = input[0];
            string b = input[1];
            string c = input[2];
            
            Console.WriteLine(""+ Char.ToUpper(a[0]) + Char.ToUpper(b[0])
                              + Char.ToUpper(c[0]));
            
        }
    }
}

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


double a[200020];
int sum[1010];
int main()
{
	for(int i=1;i<=1000;i++){
		sum[i] = sum[i-1] + i;
	}
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		scanf("%lf",&a[i]);
		a[i] = sum[(int)a[i]]/a[i];
	}
	double ans=0,t=0;
	int i=0,j=0;
	while(j<k) t+=a[j],j++;
	ans = max(ans,t);
	while(i<n&&j<n){
		t+=a[j];
		t-=a[i];
		i++,j++;
		ans = max(ans,t);
	}
	printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES

#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <cstring>
#include <unordered_set>
#include <cmath>
#include <iomanip>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::getline(stream, buf);
		std::stringstream sstr(buf);

		std::vector<int> retval;
		retval.reserve(num);

		std::string input;;
		for (int i = 0; i < num && std::getline(sstr, input, delim); ++i)
		{
			retval.push_back(std::stoi(input));
		}

		return retval;
	}

	int GetValue(std::istream& stream)
	{
		int in;
		stream >> in;

		return in;
	}

	std::vector<std::string> GetValueString(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<std::string> retval;
		retval.reserve(num);

		std::getline(stream, buf);
		std::stringstream sstr(buf);

		for (int i = 0; i < num && std::getline(sstr, buf, delim); ++i)
		{
			retval.push_back(std::move(buf));
		}

		return retval;
	}

	template<typename T>
	void PrintLine(const std::vector<T>& sequence)
	{
		std::cout << sequence[0];

		for (size_t i = 1; i < sequence.size(); ++i)
		{
			std::cout << ' ' << sequence[i];
		}

		std::cout << std::endl;
	}

	template<typename T>
	void Print(const std::vector<T>& sequence)
	{
		for (const auto& e : sequence)
		{
			std::cout << e << '\n';
		}

		std::cout << std::flush;
	}
}

int main(int argc, char* argv[])
{
	auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	std::istream& stream = (argc == 1) ? std::cin : file;
	if (argc == 1)
	{
		std::cin.tie(0);
		std::ios::sync_with_stdio(false);
	}

	int num = GetValue<1>(stream)[0];
	std::vector<int> sequence =
		GetValue(stream, num, ' ');
	std::vector<int> result(num);

	const int kMax = 10001;
	int ar[kMax] = {};
	//int result[2000000];

	for (int e : sequence)
	{
		++ar[e];
	}

	for (int i = 1; i < kMax; ++i)
	{
		ar[i] += ar[i - 1];
	}

	for (auto itr = sequence.rbegin(); itr != sequence.rend(); ++itr)
	{
		result[ar[*itr] - 1] = *itr;
		--ar[*itr];
	}

	std::cout << result[0];
	for (int i = 1; i < num; ++i)
	{
		std::cout << ' ' << result[i];
	}
	std::cout << std::endl;
}



Measured memory_bytes: 29904