akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
#include<ctime>
#include<complex>
#include<sstream>
#include<cstring>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

string conv(string a,string b){
    if(a.size()>b.size())return a;
    if(a.size()<b.size())return b;
    if(a<b)return b;
    return a;
}

int main(){
    int H,W;
    while(scanf("%d%d",&W,&H),H||W){
        char fld[100][100];
        rep(i,H)scanf("%s",fld[i]);
        string dp[100][100];
        string ans;

        rep(i,H){
            rep(j,W){
                string to=conv(dp[i][j+1],dp[i+1][j]);
                if(isalpha(fld[i][j])||(fld[i][j]=='0'&&to==""))continue;
                to+=fld[i][j];
                dp[i+1][j+1]=to;
                ans=conv(ans,to);
            }
        }

        printf("%s\n",ans.c_str());
    }
    return 0;
}

Measured memory_bytes: 1436
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N = in.i();
        char[] S = in.s().toCharArray();

        HashSet<Integer>[] one = new HashSet[N];
        one[N-1] = new HashSet<>();
        one[N-1].add(S[N-1]-'0');
        for(int i = N-2; i > -1; i--){
            one[i] = new HashSet<>(one[i+1]);
            one[i].add(S[i]-'0');
            if(one[i].size() == 10){
                for(int j = i-1; j > -1; j--){
                    one[j] = one[i];
                }
                break;
            }
        }

        HashSet<Integer>[] two = new HashSet[N];
        two[N-1] = new HashSet<>();
        for(int i = N-2; i > -1; i--){
            two[i] = new HashSet<>(two[i+1]);
            int ii = 10*(S[i]-'0');
            for(Integer j : one[i+1]){
                two[i].add(ii+j);
            }
            if(two[i].size() == 100){
                for(int j = i-1; j > -1; j--){
                    two[j] = two[i];
                }
                break;
            }
        }

        HashSet<Integer> three = new HashSet<>();
        for(int i = N-3; i > -1; i--){
            int ii = 100*(S[i]-'0');
            for(Integer j : two[i+1]){
                three.add(ii+j);
            }
            if(three.size() == 1000){
                System.out.println(1000);
                return;
            }
        }
        System.out.println(three.size());
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

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

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 183456
#include <iostream>
#include <string>

uint8_t k = 0;

int main() {
    std::string name;
    std::getline(std::cin, name);

    if (name == "Sunny" ){
        k = 0;
    }else if(name == "Cloudy"){
        k = 1;
    }else if(name == "Rainy"){
        k = 2;
    }

    switch (k)
    {
    case 2:
        std::cout << "Sunny" << std::endl;
        break;
    case 0:
        std::cout << "Cloudy" << std::endl;
        break;
    case 1:
        std::cout << "Rainy" << std::endl;
        break;
    default:
        break;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    tt=LI()
    s=sum(tt)
    m=II()
    for _ in range(m):
        p,x=MI()
        print(s-tt[p-1]+x)

main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>
int main(void)
{
	char c;
	while(scanf("%c", &c), c != '\n'){
	    if(isalpha(c)){
			if(isupper(c)){
				printf("%c", tolower(c));
			}else{
				printf("%c", toupper(c));
			}
		}else{
				printf("%c", c);
		}
	}
	puts("");
    return 0;
}

Measured memory_bytes: 528
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
int n,m,cnt=1000,aa[330000],ans=0,ab[220000];
pair<int,int> pp[220000];
string s,sa[220000];
char ca[220000];
queue<int> que;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>aa[i];
    }
    rep(i,n-1){
        if(aa[i]<aa[i+1]){
            cnt+=cnt/aa[i]*(aa[i+1]-aa[i]);
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 10508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vl;
typedef vector<vector<ll>> vll;
typedef vector<bool> vb;
typedef set<int> si; 
typedef queue<int> qi;
typedef stack<int> sti;
typedef priority_queue<int> pqi;
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
//#define __builtin_popcountll bitCountLL
//#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//std::uniform_int_distribution<long long> rg(1,1e18);
#define maxn 100005
#define Mod 1000000007
const int INF = 2e9;
const ll ML = 4e18;
    
void solve() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll p = x / d;
    if(k <= p) {
        cout << x - d * k << endl;
        return; 
    }
    ll t = x % d;
    if((k - p) % 2 == 0) {
        cout << t << endl;
    }
    else {
        cout << d - t << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
   
    solve();
   
    /*
    clock_t start,finish;
    start = clock();
    
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 3652
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n;
    while (cin >> n, n) {
        
        vector<string> l(n);
        vector<ld> eff(n);
        REP(i, n) {
            cin >> l[i];
            ll p, a, b, c, d, e, f, s, m;
            cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            eff[i] = (ld)(f * s * m - p) / (a + b + c + (d + e) * m);
        }

        vector<pair<ld, string>> crop; crop.reserve(n);
        REP(i, n) crop.emplace_back(eff[i], l[i]);
        sort(ALL_OF(crop), [](auto p, auto q) -> bool {
            if (p.first == q.first) {
                return p.second < q.second;
            } else {
                return p.first > q.first;
            }
        });
        REP(i, n) cout << crop[i].second << endl;
        cout << "#" << endl;

    }
    
}


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

int a[105];

int main(){
	int n, Min = 0x3f3f3f3f;
	int Max = -1;
	scanf("%d", &n);
	for(int i = 1; i<= n; i++){
		scanf("%d", &a[i]);
		if(a[i] < Min) 	
			Min = a[i];
		if(a[i] > Max)
			Max = a[i];
	}
	printf("%d\n",Max-Min);
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> ms;
    rep(i, h) {
        string s; cin >> s;
        ms.emplace_back(s);
    }
    int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    int dy[8] = {-1,-1,-1,  0, 0,  1, 1, 1};
    rep(i, h) {
        rep(j, w) {
            int cnt = 0;
            if (ms[i][j] == '.') {
                rep(k, 8) {
                    int x = i + dx[k], y = j + dy[k];
                    if (x >= 0 && x < h && y >= 0 && y < w && ms[x][y]=='#') ++cnt;
                }
                ms[i][j] = cnt + '0'; 
            } 
        }
    }
    for (auto& l : ms) {
        cout << l << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int Q;

ll get(ll pro) {
    ll lo = 0, hi = MOD;
    while (lo < hi) {
        ll mid = (lo+hi+1)/2;
        if (mid*(mid+1) < pro) lo = mid;
        else hi = mid-1;
    }
    return lo;
}

ll get(ll A, ll B) {
    // A*B > (x*(x+1))
    ll x = get(A*B);
    ll lo = A, hi = max(lo,(ll)ceil((ld)A*B/(x+1))-1);
    return x+hi-lo;
    // A*B/x >= A*B/(x+1)+1 
    // x from B-1 to 1 
    // ceil(A*B/x)-1
}

ll solve(ll A, ll B) {
    if (A > B) swap(A,B);
    return A-1+get(A,B);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> Q;
    F0R(i,Q) {
        int A,B; cin >> A >> B;
        cout << solve(A,B) << "\n";
    }
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
        String ac[] = a.split("");
		String b = sc.next(); 
        String bc[] = b.split("");
        int ans = 0;
        int count = 0;
      
        for(int i = 0;i < a.length() - (b.length() - 1);i++){
          for(int j = 0; j < b.length(); j ++){
            if(ac[i + j].equals(bc[j])){
              count += 1;
            }
          }
          if(ans < count){
            ans = count;
          }
          count = 0;
        }
      	System.out.println(b.length() - ans);
 
    }
}

Measured memory_bytes: 36600
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


int main(){
  ll n,m; cin >> n >> m;
  vector<int> a(n);
  vector<int> v(n+1);
  map<int,int> mp;
  rep(i,n) cin >> a[i];
  v[0] = 0;
  for(int i = 1; i <= n;i++){
    v[i] = (v[i-1] + a[i-1])%m;
  }
  ll ans = 0LL;
  rep(i,n+1){
    ans += mp[v[i]];
    mp[v[i]]++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3968
#include <iostream>
    #include <vector>
    #include <bits/stdc++.h>
    #define rep(i, n) for (int i = 0; i < (n); ++i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
     
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define se second
    #define bg begin()
    #define ed end()
    #define all(x) x.bg, x.ed
    #ifdef LOCAL
    #define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
    #else
    #define dmp(x) void(0)
    #endif
     
    template <class t, class u>
    void chmax(t &a, u b)
    {
      if (a < b)
        a = b;
    }
    template <class t, class u>
    void chmin(t &a, u b)
    {
      if (b < a)
        a = b;
    }
     
    template <class t>
    using vc = vector<t>;
    template <class t>
    using vvc = vc<vc<t>>;
     
    using vi = vc<int>;
    int gcd(int a, int b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    int lcm(int a, int b)
    {
      return (a * b) / gcd(a, b);
    }
    int fact(int n)
    {
      if (n == 0)
        return 1;
      return n * fact(n - 1);
    }
    int main()
    {
      int n;
      vi t(n);
      cin >> n;
      rep(i,n){
      cin>>t[i];
      }
       int m;cin>>m;
      	int sum=0;
      	int p,x;
      	int temp=0;
        rep(i,m){
          cin >> p >>x;
        //if(t[p-1]>x){
         	temp =t[p-1];
          	t[p-1]=x;
         //}
          rep(j,n){
          	sum+=t[j];
          }
          cout << sum<<endl;
          sum=0;
          t[p-1] = temp;
        }
    }

Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        long[] array = new long[a];

        Map<Long, Long> map = new HashMap<>();
        long originalSum = 0;
        for (int i=0; i<a; i++) {
            array[i] = sc.nextLong();
            originalSum+=array[i];
            if (map.containsKey(array[i])) map.put(array[i], map.get(array[i]) + 1);
            else map.put(array[i], 1L);
        }

        int q = sc.nextInt();
        for (int i=0; i<q; i++) {
            long b = sc.nextLong();
            long c = sc.nextLong();

            if (map.get(b) == null) {
                System.out.println(originalSum);
                continue;
            }

            long diff = (c - b) * map.get(b);
            originalSum += diff;
            System.out.println(originalSum);

            long countC = (map.get(c) != null) ? map.get(c) : 0;
            map.put(c, countC + map.get(b));
            map.put(b, 0L);
        }
    }
}


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

int main()
{
  int n;
  cin >> n;
  int cnt[n+1] = {};
  
  for (int i = 2; i <= n; ++i) {
    int x = i;
    for (int j = 2; j <= i; ++j) {
      while (x % j == 0) {
        ++cnt[j];
        x /= j;
      }
      if (x == 1) break;
    }
  }

  int ans = 0;	//(a)
  rep(i, n+1) {
    if (cnt[i] >= 74) {
      ++ans;
    }
  }
  
  rep(i, n+1) {		//(a, b)
    if (cnt[i] < 14) continue;
    if (cnt[i] >= 24) {
      rep(j, n+1) {
        if (i != j && cnt[j] >= 2) ++ans;
      }
    }
    rep(j, n+1) {
      if (i != j && cnt[j] >= 4) ++ans;
    }
  }
  
  
  int buf = 0;		//(a, b, c)
  rep(i, n+1) {
    if (cnt[i] < 4) continue;
    rep(j, n+1) {
      if (i == j || cnt[j] < 4) continue;
      rep(k, n+1) {
        if (i != k && j != k && cnt[k] >= 2) ++buf;
      }
    }
  }
  ans += buf/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	ll h, z, ans = 2;
	cin >> h;
	z = log2(h);
	REP(i, 1, z + 1) {
		ans = ans * 2;
	}
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
typedef unsigned long long int ull;

using namespace std;

int main(void){
  ull N,K,ans=0;
  cin >> N >> K;
  ull A[N];
  ull B[N]={};
  rep(i,N) cin >> A[i];
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(A[i]>A[j]) ans++;
    }
  }
  ans=(ans*K)%MOD;
  sort(A,A+N,greater<ull>());
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(A[i]>A[j]){
        B[i]=N-j;
        break;
      }
    }
  }
  rep(i,N) ans=(ans+(B[i]*((K*(K-1)/2)%MOD))%MOD)%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import namedtuple

Data = namedtuple("Data", "rate distance")

SENTINEL = None
NOTHING = None
RATE_TABLE = [
    [SENTINEL],
    [SENTINEL, NOTHING, Data(300, 6), Data(500, 13), Data(600, 18), Data(700, 23), Data(1350, 43), Data(1650, 58)],
    [SENTINEL, Data(300, 6), NOTHING, Data(350, 7), Data(450, 12), Data(600, 17), Data(1150, 37), Data(1500, 52)],
    [SENTINEL, Data(500, 13), Data(350, 7), NOTHING, Data(250, 5), Data(400, 10), Data(1000, 30), Data(1350, 45)],
    [SENTINEL, Data(600, 18), Data(450, 12), Data(250, 5), NOTHING, Data(250, 5), Data(850, 25), Data(1300, 40)],
    [SENTINEL, Data(700, 23), Data(600, 17), Data(400, 10), Data(250, 5), NOTHING, Data(600, 20), Data(1150, 35)],
    [SENTINEL, Data(1350, 43), Data(1150, 37), Data(1000, 30), Data(850, 25), Data(600, 20), NOTHING, Data(500, 15)],
    [SENTINEL, Data(1650, 58), Data(1500, 52), Data(1350, 45), Data(1300, 40), Data(1150, 35), Data(500, 15), NOTHING]
]
DISTANCE_LIMIT = 40
TIME_LIMIT1 = 17 * 60 + 30
TIME_LIMIT2 = 19 * 60 + 30

while True:

    leave_number = int(input())

    if leave_number == 0:
        break

    leave_time = [int(item) for item in input().split(" ")]

    arrive_number = int(input())
    arrive_time = [int(item) for item in input().split(" ")]

    data = RATE_TABLE[leave_number][arrive_number]

    rate = data.rate

    if data.distance <= DISTANCE_LIMIT:

        time1 = leave_time[0] * 60 + leave_time[1]
        time2 = arrive_time[0] * 60 + arrive_time[1]

        if TIME_LIMIT1 <= time1 <= TIME_LIMIT2 or TIME_LIMIT1 <= time2 <= TIME_LIMIT2:
            rate //= 2

            if rate % 50 != 0:
                rate = rate + 50 - rate % 50

    print(rate)



Measured memory_bytes: 6092
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let r: i64 = read();
    let mut score = r;

    if n < 10 {
        score = r + (10 - n as i64) * 100;
    }
    println!("{}", score);
}


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


int main()
{
    char c; cin >> c;
    if (isupper(c)) cout << "A" << endl;
    else cout << "a" << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 3620
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] elements = br.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(elements[i]);
        }

        int key;
        int i, j, k;
        printArray(A, N);
        for (i = 1; i < N; i++) {
            key = A[i];
            j = i - 1;
            while (j >= 0 && A[j] > key) {
                A[j+1] = A[j];
                j--;
            }
            A[j+1] = key;

            printArray(A, N);
        }
    }

    public static void printArray (int[] array, int length) {
        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < length; i++) {
            output.append(array[i]);
            if (i != length-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
    }
}

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

const int maxn = 5000005;
const long long mod = 1000000007;

int n, m;
long long ans;
long long fact[maxn];

long long add_mod (long long x, long long y) {
	return (x + y) % mod;
}

long long mul_mod (long long x, long long y) {
	return (x * y) % mod;
}

long long sub_mod (long long x, long long y) {
	return (x + mod - y) % mod;
}

long long pow_mod (long long x, long long y) {
	long long res = 1, t = x;
	while (y) {
		if (y & 1)
			res = mul_mod(res, t);
		t = mul_mod(t, t);
		y >>= 1;
	}
	return res;
}

long long div_mod (long long x, long long y) {
	return mul_mod(x, pow_mod(y, mod - 2));
}

long long npr_mod (int x, int y) {
	if (x < y)
		return 0LL;
	return div_mod(fact[x], fact[x - y]);
}

long long ncr_mod (int x, int y) {
	if (x < y)
		return 0LL;
	return div_mod(fact[x], mul_mod(fact[x - y], fact[y]));
}

void precalc () {
	fact[0] = 1;
	for (long long i = 1; i < maxn; ++i)
		fact[i] = mul_mod(i, fact[i - 1]);
}

signed main () {
	precalc();
	scanf("%d %d", &n, &m);
	ans = pow_mod(npr_mod(m, n), 2);
	for (int eq = 1; eq <= n; ++eq) { // iterating through amount of positions where a[i] == b[i]
		if (eq & 1)
			ans = sub_mod(ans, mul_mod(mul_mod(ncr_mod(n, eq), npr_mod(m, eq)), pow_mod(npr_mod(m - eq, n - eq), 2LL)));
		else
			ans = add_mod(ans, mul_mod(mul_mod(ncr_mod(n, eq), npr_mod(m, eq)), pow_mod(npr_mod(m - eq, n - eq), 2LL)));
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 42892
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

vector<ll> pn;

int solve(int n, int m){
  int ans = 0;
  for(int i=1; i*i <= m; i++){
    if(m % i == 0){
      if(i <= m/n) ans = std::max(ans, i);
      if((m/i) <= (m/n)) ans = std::max(ans, m/i);
    }
  }
  return ans;
}

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  int m;
  cin >> n >> m;

  /*
  ll ans = 0LL;
  REP(i, pn.size()) {
    if(m/n >= pn[i]) ans = max(pn[i], ans);
  }
  */

  int ans = solve(n, m);
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]

T.sort()

ans = 0

oko = 0
bus = False
cnt = 0
for i in range(N):
  t = T[i]
  
  if not bus:
    ans += 1
    bus = True
    oko = t + K
    cnt += 1
    continue
    
  if t <= oko:
    if cnt < C:
      cnt += 1
    else:
      bus = True
      oko = t + K
      cnt = 1
      ans += 1
  else:
    cnt = 1
    bus = True
    ans += 1
    oko = t + K
    
print(ans)
      


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int one = 0;
  int two = 0;
  one = A * N;
  two = B;
  if (one >= two) {
      cout << two << endl;
  }
  else {
      cout << one << endl;
  }

}

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

using namespace std;

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

signed main(){
	
  	long long a[100000];
  	long long n;
  	
  	cin >> n;
  	
  	rep(i,n){
    	
      	cin >> a[i];
    
    }

  	long long c1 = 0, c2 = 0;
  	long long sum = 0;
  	long long c = 1;
  	
	//奇数番目を正
  	REP(i,0,n){
      
    	sum += a[i];
      
      	if( sum * c <= 0 ){
        
        	c1 += (abs(sum)+1);
          	sum = c;
        
        }
      
      	c *= (-1);
    
    }
	
  	//偶数番目が正
  
  	//奇数番目を正
  	
  	c = -1;
  	sum = 0;
  	
  	REP(i,0,n){
      
    	sum += a[i];
      
      	if( sum * c <= 0 ){
        
        	c2 += (abs(sum)+1);
          	sum = c;
        
        }
  
      	c *= (-1);
    
    }
  
  	cout << min(c1,c2)<<endl;
  
}

Measured memory_bytes: 1024
/*
	Find the LONGEST COMMON SUBSEQ
	both methods: Memoize + Tabularize
*/
// solution by @pruvi007
#include<bits/stdc++.h>
using namespace std;

map<pair<int,int>,int> m;
int lcs(string s1,string s2,int i,int j)
{
	if(i>=s1.length() || j>=s2.length())
		return 0;
	if(m.find({i,j}) != m.end())
		return m[{i,j}];
	else if(s1[i]==s2[j])
	{
		m[{i,j}] = 1 + lcs(s1,s2,i+1,j+1);
		return m[{i,j}];
	}
	else
	{
		m[{i,j}] = max(lcs(s1,s2,i+1,j),lcs(s1,s2,i,j+1));
		return m[{i,j}];
	}
}

string sl = "";
int lcsT(string s1,string s2)
{
	int n = s1.length();
	int m = s2.length();
	int dp[n+1][m+1];
	for(int i=0;i<=m;i++)
		dp[0][i]=0;
	for(int j=0;j<=n;j++)
		dp[j][0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s1[i] == s2[j])
			{
				dp[i+1][j+1] = 1 + dp[i][j];
			}
			else
			{
				dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
			}
		}
	}


	stack<char> stk;
	int l=n,r=m;
	while(1)
	{
		if(dp[l][r] == 0)
			break;
		if(s1[l-1] == s2[r-1])
		{
			stk.push(s1[l-1]);
			l--;
			r--;
		}
		else if(s1[l-1]!=s2[r-1])
		{
			int a = dp[l-1][r];
			int b = dp[l][r-1];
			if(a > b)
				l--;
			else r--;
		}
	}

	while(!stk.empty())
	{
		sl += stk.top();
		stk.pop();
	}
	return dp[n][m];


}
int main()
{
	string s1,s2;
	cin >> s1;
	cin >> s2;
	int n1 = s1.length();
	int n2 = s2.length();

	int ans = lcsT(s1,s2);
	// cout << ans << endl;
	cout << sl << endl;
}


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

int main() {
    int n; cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    for (int i=0; i<n; ++i) {
        if (a[i] == b[i] && b[i] == c[i]) continue;
        else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ans++;
        else ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, m, sum = 0, count = 0;
    int a[100] = {};
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    for(int i = 0; i < n; i++){
        if((double)a[i] < (double)sum / (4*m)) continue;
        count++;
    }
    cout << (count >= m ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
R, C, K = map(int, input().split())

V = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v

max_p = [0]*(C+1)
for i in range(R+1):
    now0 = [0]*(C+1)
    now1 = [0]*(C+1)
    now2 = [0]*(C+1)
    now3 = [0]*(C+1)
    for j in range(C+1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now0[j-1]
            lb = now1[j-1]
            now2[j] = max(now2[j], now2[j-1], lb + v)
            now3[j] = max(now3[j], now3[j-1], now2[j-1] + v)
        if i > 0:
            now0[j] = max(now0[j], max_p[j], la)
            now1[j] = max(now1[j], max_p[j] + v, la + v, lb)
        max_p[j] = max(now0[j], now1[j], now2[j], now3[j])

print(max(now0[C], now1[C], now2[C], now3[C]))


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

using namespace std;

int main() {
    int A, B, AB;
    int X, Y;
    int sum = 0;
    int minR = 2000000000;
    cin >> A >> B >> AB >> X >> Y; 
    for(int i = 0; i <= 100000; i++) {
        sum = 2*AB*i + max(0, X-i)*A + max(0, Y-i)*B;
        minR = min(sum, minR);
    }
    cout << minR << endl;
    return 0;
}

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

using namespace std;

int main(){

    int L, R;
    cin >> L >> R;
    int ans = (1 << 30);

    if(R - L >= 2019){
        cout << 0 << endl;
        return 0;
    }

    int mod = 2019;
    int upper = min(R, L + 2018);
    for(int i = L; i <= upper; i++){
        for(int j = i + 1; j <= upper; j++){
            int tempI = i % mod;
            int tempJ = j % mod;
            int product = (tempI * tempJ) % mod;
            ans = min(ans, product);
        }
    }

    cout << ans << endl;

    return 0;
}

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


using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s;cin >> s;
    int mn=1e6;
    int l=s.size();
    for(int i=0;i<=l-3;i++)
    {
        int num=(100*(s[i]-'0'))+(10*(s[i+1]-'0'))+(s[i+2]-'0');
        mn=min(mn,abs(num-753));
    }

    cout << mn;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;

int main()
{
  ll x;
  cin >> x;

  FOR(a, -150, 150)
  {
    FOR(b, -150, 150)
    {
      if ((a * a * a * a * a) - (b * b * b * b * b) == x)
      {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll ret = max({a*c,a*d,b*c,b*d});
  pl(ret)

  // ll ans = -INFL;
  // for(int x = a; x <= b; ++x){
  //   for(int y = c; y <= d; ++y){
  //     ll z = x*y;
  //     chmax(ans,z);
  //   }
  // }
  // pl(ans)
  return 0;
}


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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

void solve(){
    ll n;
    string s;
    cin >> n >> s;

    ll c1=0,c2=0,c3=0;

    for(ll i=0;i<n;i++){
        if(s[i] == 'R')c1++;
        if(s[i] == 'G')c2++;
        if(s[i] == 'B')c3++;
    }
    ll ans = c1*c2*c3;
    for(ll d=1;d<=n;d++){
        for(ll i=0;i<n;i++){
            if(i-d < 0 or i+d >= n)
                continue;
            if(s[i-d] != s[i] and s[i-d] != s[i+d] and s[i] != s[i+d])
                ans--;
        }
    }

    cout << ans << endl;

}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}



Measured memory_bytes: 3612
//
// Binary Indexed Tree
//
// verified:
//   AOJ Course DSL_2_B Range Query - Range Sum Query (RSQ)
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
//

#include <iostream>
#include <vector>
using namespace std;


template <class Abel> struct BIT {
	vector<Abel> dat;
	Abel UNITY_SUM = 0;						// to be set

	/* [1, n] */
	BIT(int n) : dat(n + 1, UNITY_SUM) { }
	void init(int n) { dat.sssign(n + 1, UNITY_SUM); }

	/* a is 1-indexed */
	inline void add(int a, Abel x) {
		for (int i = a; i < (int)dat.size(); i += i & -i)
			dat[i] = dat[i] + x;
	}

	/* [1, a], a is 1-indexed */
	inline Abel sum(int a) {
		Abel res = UNITY_SUM;
		for (int i = a; i > 0; i -= i & -i)
			res = res + dat[i];
		return res;
	}

	/* [a, b), a and b are 1-indexed */
	inline Abel sum(int a, int b) {
		return sum(b - 1) - sum(a - 1);
	}

    /* debug */
	void print() {
		for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
		cout << endl;
	}
};



int main() {
    int N, Q; cin >> N >> Q;
    BIT<int> bit(N);
    for (int query = 0; query < Q; ++query) {
        int com, x, y; cin >> com >> x >> y;
        if (com == 0) bit.add(x, y);
        else cout << bit.sum(x, y+1) << endl;
    }
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
vector<int> E[101010];
ll mo=1000000007;
ll ret=1;

void dfs(int cur,int pre,int num) {
	ret=ret*num%mo;
	
	num=K-1;
	if(pre!=-1) num--;
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur,num);
		num--;
	}
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N-1) {
		cin>>x>>y;
		x--,y--;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	
	dfs(0,-1,K);
	cout<<ret<<endl;
}




int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[555][555];
ll pr[555][555];
ll pl[555][555];

ll suml(int r, int al, int ar)
{
	al=max(al,0);
	if(al==0) return pl[r][ar];
	return pl[r][ar]-pl[r][al-1];
}

ll sumr(int r, int al, int ar)
{
	al=max(al,0);
	if(al==0) return pr[r][ar];
	return pr[r][ar]-pr[r][al-1];
}

ll dp[2][511][511];

void amin(ll &x, ll y)
{
	if(y<x) x=y;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==j) continue;
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			pl[i][j]=a[j][i];
			if(j>0) pl[i][j]+=pl[i][j-1];
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			pr[i][j]=a[i][j];
			if(j>0) pr[i][j]+=pr[i][j-1];
		}
	}
	const ll INF = ll(1e18);
	dp[1][0][0]=0;
	for(int i=1;i<n;i++)
	{
		int cur=(i+1)&1; int pre=(cur^1);
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				dp[cur][i][j]=INF;
			}
		}
		for(int j=0;j<=i-1;j++)
		{
			for(int k=0;k<=j;k++)
			{
				ll ans = dp[pre][j][k];
				if(ans>=INF) continue;
				//cerr<<"DP "<<i<<' '<<j<<' '<<k<<'\n';
				//cerr<<i+1<<' '<<j<<' '<<k<<' '<<ans+suml(i,j,i-1)+sumr(i,0,k-1)<<'\n';
				//cerr<<i+1<<' '<<i<<' '<<j<<' '<<ans+sumr(i,0,j-1)<<'\n';
				amin(dp[cur][j][k],ans+suml(i,j,i-1)+sumr(i,0,k-1)); //extend
				amin(dp[cur][i][j],ans+sumr(i,0,j-1));
			}
		}
	}
	ll ans = INF;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			amin(ans,dp[n&1][i][j]);
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 11264
#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 <time.h>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	ll h;
	cin >> h;
	ll ans = 0;
	for (ll i = 0; i < 40; i++) {
		if (h&(1LL << i)) {
			ans = (1LL << (i + 1)) - 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main() {
	char b;

	cin >> b;

	if(b == 'A'){
		cout << "T" << endl;
	}
	else if(b == 'T'){
		cout << "A" << endl;
	}
	else if(b == 'C'){
		cout << "G" << endl;
	}
	else if(b == 'G'){
		cout << "C" << endl;
	}

	return 0;




}


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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using P = pair<int, int>;

int h, w;

void dfs(int x, int y, vector<string> &g, vector<vector<bool>> &seen) {
    if(seen[y][x] || g[y][x] == '#') {
        return;
    }
    seen[y][x] = true;
    for(int i = 0; i < 4; i++) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(0 <= nx && nx < w && 0 <= ny && ny < h && g[ny][nx] == '.' &&
           !seen[ny][nx]) {
            dfs(nx, ny, g, seen);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        cin >> w >> h;
        if(h == 0 && w == 0) {
            break;
        }
        vector<string> g(h);
        for(int i = 0; i < h; i++) {
            cin >> g[i];
        }
        vector<vector<bool>> seen(h, vector<bool>(w, false));
        int sx, sy;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(g[i][j] == '@') {
                    sy = i, sx = j;
                }
            }
        }
        dfs(sx, sy, g, seen);
        int ans = 0;
        for(int i = 0; i < h; i++) {
            ans += count(ALL(seen[i]), true);
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    class Program_D
    {
        static void Main(string[] args)
        {
            var N = Int32.Parse(Console.ReadLine());
            var a = new bool[N+1];
            var aaa = Console.ReadLine().Split(' ');
            for (var i = 0; i < N; i++)
            {
                a[i+1] = aaa[i] == "1";
            }

            for (var idx = N; idx > 0; idx--)
            {
                var c = false;
                for (var ii = idx; ii <= N; ii += idx)
                {
                    c ^= a[ii];
                }
                a[idx] = c;
            }

            var nn = a.Count(__ => __);
            Console.WriteLine(nn);
            var sb = new StringBuilder();
            for (var i = 0; i <= N; i++)
            {
                if (!a[i]) continue;
                Console.WriteLine(i);
            }
            

        }
    }



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

ans = 0
ab.sort(key=lambda x:x[1])

recent_cut = -1#直近で切り落とした橋の左の街
for i in range(M):
    if recent_cut < ab[i][0]:
        recent_cut = ab[i][1]-1
        ans+=1
print(ans)


Measured memory_bytes: 28576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n,m;
  cin >> n >> m;
  vector<pll> v;
  rep(i,n){
    ll a; cin >> a;
    v.pb({a,1});
  }
  rep(i,m){
    ll b,c; cin >> b >> c;
    v.pb({c,b});
  }
  sort(all(v),greater<pll>());
  ll cnt=0,ans=0;
  for(auto p:v){
    if(cnt+p.se<=n){
      ans+=p.fi*p.se;
      cnt+=p.se;
    }
    else {
      ans+=p.fi*(n-cnt);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define int long long
#define INF 1e+9
#define MAX_V 100008
const int MOD = 1e9 + 7;
const int inf = 1 << 30;



signed main(){
  IOS
  int n;
  cin >> n;
  vector<ll> L(n);
  for (int i=0; i<n; i++) cin >> L[i];
  int ans = 0;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n; j++){
      for (int k=j+1; k<n; k++){
        if(L[i] != L[j] && L[i] != L[k] && L[j] != L[k]){
          if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j])ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main (){
    string s,a,b,c,d;
    cin>>s;
    a=s[0];
    b=s[1];
    c=s[2];
    d=s[3];
    if((a==b&&c==d&&a!=c)||(a==c&&b==d&&a!=b)||(a==d&&c==b&&a!=c)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	int a[2];
	cin >> a[0] >> a[1];
	int b[2];
	for (int i = 0; i < 2; i++) {
		if (a[i] == 1 || a[i] == 3 || a[i] == 5 || a[i] == 7 || a[i] == 8 || a[i] == 10 || a[i] == 12) {
			b[i] = 1;
		}
		if (a[i] == 2) {
			b[i] = 2;
		}
		if (a[i] == 4 || a[i] == 6 || a[i] == 9 || a[i] == 11) {
			b[i] = 3;
		}
	}
	if (b[1] == b[0]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main(){
    int A, B, H, M, M_sum;
    double A_x, A_y, B_x, B_y, dis;
    double A_theta, B_theta;
    double pi = 3.14159265358979323846;

    cin >> A >> B >> H >> M;
    M_sum = H * 60 + M;
    A_theta = double(M_sum)/360 * pi;
    B_theta = double(M)/30 * pi;
    A_x = A * cos(A_theta);  A_y = A * sin(A_theta);
    B_x = B * cos(B_theta);  B_y = B * sin(B_theta);

    dis = sqrt(pow(A_x-B_x, 2) + pow(A_y-B_y, 2));
    cout << fixed << setprecision(20) << dis << endl;
    return 0;
}

Measured memory_bytes: 4132