akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque
import java.util.Queue

data class Quad<F, S, T, Q>(val first: F, val second: S, val third: T, val fourth: Q)

fun solve(N: Int, range: Pair<Int,Int>): MutableMap<Int,Int> {
    val (X, Y) = Pair(range.first - 1, range.second -1 )
    val dist_map: MutableMap<Int, Int> = mutableMapOf()
    val acc = (1..N).map { (1..N).map { null as Int? }.toMutableList() }.toMutableList()
    for(i in 0 until N - 1) {
        for(j in (i + 1) until N) {
            if(i == X) {
                acc[i][j] = j - i
            }
            acc[i][j] = when(Quad(X < i, i < Y, X < j, j < Y)) {
                Quad(true, true, true, true) -> { // X <= i <= Y, X <= j <= Y
                    listOf(j - i, i - X + Y - j + 1).min()!!
                }
                Quad(true, false, true, false) , Quad(false, true, false, true) -> {
                    // i, j >= Y or i, j <= X
                    j - i
                }
                Quad(false, true, true, true) -> {
                    // i < X , X <= j <= Y
                    X - i + listOf(j - X, Y - j + 1).min()!!
                }
                Quad(true, true, true, false) -> {
                    // X <= i <= Y, j >= Y
                    listOf(Y - i, i - X + 1).min()!! + j - Y
                }
                Quad(false, true, true, false) -> {
                    // X < i, Y < j
                    X - i + 1 + j - Y
                }
                else -> null
            }
            // println("${i + 1}, ${j + 1} -> ${acc[i][j]}")
            dist_map[acc[i][j]!!] = (dist_map[acc[i][j]!!]?: 0) + 1
        }
    }
    return dist_map
}


fun main(args: Array<String>) {
    val (N, X, Y) = readLine()!!.split(" ").map(String::toInt)
    val dist_map = solve(N, Pair(X, Y))
    for(k in 1..(N - 1)) {
        println(dist_map[k]?: 0)
    }
}

Measured memory_bytes: 172956
#pragma target("avx")
#pragma optimize("O3")
#include<stdbool.h>

bool alp[26];
char c;

int main(){
        while((c=getchar())!='\n') alp[c-'a'] = true;
        for(int i=0; i<26; i++) if(!alp[i]) {
                putchar(i+'a');
                return 0;
        }
        puts("None");
        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  

/////////////
signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int l,r;
	cin>>l>>r;
	if(r-l+1>2019)
	{
		cout<<0;
	}
	else
	{
		int mi=2019;
		for(int i=l;i<r;++i)
		{
			for(int j=i+1;j<=r;++j)
			{
				mi=min(mi,(i*j)%(2019));
			}
		}
	cout<<mi;
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def MI():
  return map(int,input().split())
def main():
  n,m=MI()
  G=[[] for _ in range(n)]
  for _ in range(m):
    u,v=MI()
    u-=1
    v-=1
    G[u].append(v)
  s,t=MI()
  s-=1
  t-=1
  
  fi=[True]*n
  se=[True]*n
  th=[True]*n
  th[s]=False

  dq=[s]
  depth=0
  
  while dq:
    depth+=1
    tank1=[]
    tank2=[]
    tank3=[]
    
    for p in dq:
      for c in G[p]:
        if fi[c]:
          fi[c]=False
          tank2.append(c)
    for p in tank2:
      for c in G[p]:
        if se[c]:
          se[c]=False
          tank3.append(c)
    for p in tank3:
      for c in G[p]:
        if th[c]:
          th[c]=False
          tank1.append(c)
        if c==t:
          print(depth)
          exit()
    dq=tank1
  print(-1)  
if __name__=='__main__':
  main()

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

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    static int parent[]; 

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
 
        long N = nextLong();
        
        HashMap<Long,Integer> map = new HashMap<Long,Integer>();
 
        for (int x=2; x<=Math.sqrt(N); x++) {  
            while(N % x==0){
                map.put((long) x, map.getOrDefault((long)x,0)+1);
                N = N / x;
            }
        }
        if(N!=1){
            map.put(N, map.getOrDefault(N,0)+1);
        }

        int ansList[] = new int[11]; //enough
        for (int x=1; x<=10; x++) {  
            ansList[x] = ansList[x-1] + x; 
        }

        int ans = 0;
        for (Map.Entry<Long,Integer> entry: map.entrySet()) {
            int temp =  entry.getValue();
            int index = Arrays.binarySearch(ansList, temp);
            if(index<0){
                index = -index-2;
            }
            ans += index;
        }

        System.out.println(ans);
    
    }
 
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

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

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 32844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

//コンビネーションをmodで割った余りを産出
int64_t nCk( int64_t n, int64_t k  )
{
    int64_t ans_x = 1;
    int64_t ans_y = 1;

    for( int i = n; i > n - k; i-- )
    {
        ans_x *= i;
    }

    for( int i = 1; i <= k; i++ )
    {
        ans_y *= i;
    }

    return ans_x / ans_y;
}

int main()
{
    std::string word = "aa";
    std::string w = "Yes";
    //int64_t a,b,c,d,e,f;
    double a, b;
    std::cin>> a;

    b = pow( a / 3, 3.0 );
    std::cout<< std::fixed << std::setprecision(12) << b;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d ",&a);
    scanf("%d\n",&b);
    if(a<b)
        printf("a < b\n");
    else if(a>b)
        printf("a > b\n");
    else
        printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define prDouble(x) cout << fixed << setprecision(10) << x 

double dp[3001][3001];
double solve(vector<double> &arr, int i, int x){
    if(x==0)
        return 1;
    if(i==0)
        return 0;

    if(dp[i][x]> -0.9){
        return dp[i][x];
    }

    return dp[i][x] = arr[i]*solve(arr, i-1,x-1) + (1-arr[i])*solve(arr, i-1, x);
}
int main() {
    int n;
    cin >> n;
    memset(dp, -1, sizeof dp);
    vector<double>arr(n+1);
    for(int i=1;i<=n;i++){
        cin >> arr[i];
    }
    prDouble(solve(arr, n, (n+1)/2));

}


Measured memory_bytes: 74380
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#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 FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class EStringsOfImpurity {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s, t;
        cin >> s >> t;

        vector<vector<int>> pos(50);
        REP(i, s.size()) {
            char c = s[i];
            pos[c - 'a'].push_back(i + 1);
        }

        int cur = 0;
        int res = 0;
        REP(i, t.size()) {
            char c = t[i];
            const auto& v = pos[c - 'a'];
            if (v.empty()) {
                cout << -1 << endl;
                return;
            }

            auto itr = upper_bound(v.begin(), v.end(), cur);
            if (itr != v.end()) {
                int next = *itr;
                res += next - cur;
                cur = next;
            } else {
                int next = v[0];
                res += s.size() - cur;
                res += next;
                cur = next;
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    EStringsOfImpurity solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1736
import sys
from collections import defaultdict
from math import gcd

MOD = 10 ** 9 + 7
n, *ab = map(int, sys.stdin.buffer.read().split())
ab_zero = 0
a_zero = 0
b_zero = 0
nonzero = defaultdict(int)

for a, b in zip(ab[0::2], ab[1::2]):
    if a == 0 and b == 0:
        ab_zero += 1
    elif a == 0:
        a_zero += 1
    elif b == 0:
        b_zero += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a, b = -a, -b
        if a == 0 and b < 0:
            b = -b
        nonzero[a, b] += 1

n -= ab_zero
# print(nonzero)

dame_pairs_pattern = 1
dame_pairs_cnt = 0

if a_zero > 0 and b_zero > 0:
    dame_pairs_pattern *= pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
    dame_pairs_cnt += a_zero + b_zero

checked = set()

for (a, b), cnt in nonzero.items():
    if (a, b) in checked:
        continue
    if b < 0:
        c, d = -b, a
    else:
        c, d = b, -a
    if (c, d) in nonzero:
        cnt2 = nonzero[c, d]
        dame_pairs_pattern *= pow(2, cnt, MOD) + pow(2, cnt2, MOD) - 1
        dame_pairs_pattern %= MOD
        dame_pairs_cnt += cnt + cnt2
        checked.add((c, d))

ans = dame_pairs_pattern * pow(2, n - dame_pairs_cnt, MOD) - 1

print((ans + ab_zero) % MOD)


Measured memory_bytes: 74008
from itertools import accumulate

N, M, Q = map(int, input().split())
DP = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    DP[l][r] += 1
Query = [tuple(map(int, input().split()))for _ in range(Q)]
for w in range(1, N):
    for i in range(N):
        j = i + w
        if j >= N:
            break
        DP[i][j] += DP[i][j-1]
        DP[i][j] += DP[i+1][j]
        DP[i][j] -= DP[i+1][j-1]
for p, q in Query:
    print(DP[p-1][q-1])



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

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

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    mp[num]++;
  }

  if ((int)mp.size() <= K) {
    cout << 0 << endl;
    return 0;
  }


  vector<int> v;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    v.push_back(itr->second);
  }

  sort(v.begin(), v.end());

  int ans = 0;
  int pattern = (int)v.size();
  for (int i = 0; i < (int)v.size(); i++) {
    ans += v.at(i);
    pattern--;
    if (pattern <= K) {
      break;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10748
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		sc.close();

		for (int X = 1; X <= 50000; X++) {
			if ((int) (X * 1.08) == N) {
				out.println(X);
				return;
			}
		}
		out.println(":(");

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(){

  int i,y;
  char a[1002];
  while(1){
    y=0;
    scanf("%s",&a);
    if(a[0] == '0')break;

    for(i=0;a[i]!='\0';i++){
      if('0'<=a[i] && a[i]<='9'){
      y+=a[i]-'0';
      }
    }
    printf("%d\n",y);
  }
  return 0;
}

Measured memory_bytes: 536
n = int(input())

soinsu_in_n = [0] * 50
seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
for i in range(1,n+1):
  a = i
  for j in seed_primes:
    while a%j == 0:
      a = a // j
      soinsu_in_n[j] += 1
    if a == 1:
      break

over74 = sum(item >= 74 for item in soinsu_in_n)
over24 = sum(item >= 24 for item in soinsu_in_n)
over14 = sum(item >= 14 for item in soinsu_in_n)
over4= sum(item >= 4 for item in soinsu_in_n)
over2= sum(item >= 2 for item in soinsu_in_n)

count = 0
# 74
if over74 >= 1:
  count += over74

# 24 2 or 2 24
if over24 >= 1:
  count += over24 * (over2 - over24)
if over14 >= 2:
  count += over24 * (over24 - 1)

# 14 4 or 4 14
if over14 >= 1:
  count += over14 * (over4 - over14)
if over14 >= 2:
  count += over14 * (over14-1)

# 442 or 424 or 244
if over4 >= 3:
  count += (over4) * (over4-1) * (over4-2) // 2
if over4 >= 2:
  count += (over4) * (over4-1) // 2 * (over2-over4)

print(count)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		
		// 計算
		long result = 2;
		if(n == 2) result = 1;
		for(long k = 2; k*k <= n; k++){
		    if(n%k == 0){
		        long tmp = n;
		        while(tmp%k == 0){
		            tmp /= k;
		        }
		        if(tmp%k == 1) result++;
		    }
		}
		for(long k = 2; k*k <= n; k++){
		    if(n%k != 0){
		        if((n-1)%k == 0){
		            result++;
		            if(k*k != (n-1)) result++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23124
#include<stdio.h>

int main()
{
    int long long n, t, i=0, j, prev_i=0;
    int long long out=0, k=0;
    scanf("%lld %lld", &n, &t);
    out=n*t;
    for(j=1; j<=n; j++)
    {
        scanf("%d", &i);

        if(i-prev_i<t&&j!=1)k=k+t-(i-prev_i);

        prev_i=i;

    }
    out=out-k;

    printf("%lld", out);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}

main(){
    int n=in();
    vec a;
    rep(i,n)a.pb(in());
    sort(all(a));
    reverse(all(a));
    a.pb(0);
    rep(i,n){
        if(a[i+1]<=i+1 and a[i]>=i+1){
            if(a[i]==i+1 and a[i+1]!=i+1){
                cout<<"Second\n";
            }
            else if(a[i]!=i+1 and a[i+1]==i+1){
                bool c=(i+1+a[i])&1;
                bool d=1;
                while(a[i+2]==a[i+1]){i++;d^=1;}
                c|=d;
                cout<<(c? "First\n":"Second\n");
            }
            else if(a[i]>i+1 and a[i+1]<i+1){
                cout<<((a[i]+i+1)&1 ?"First\n":"Second\n");
            }
            else {
                assert(a[i]==i+1 and a[i+1]==i+1);
                bool d=1;
                while(a[i+2]==a[i+1]){i++;d^=1;}
                cout<<(d?"First\n":"Second\n");
            }
            return 0;
        }
    }
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    string ss;
    cin >> ss;
    if(ss.at(0)!=ss.at(1)||ss.at(1)!=ss.at(2)||ss.at(0)!=ss.at(2)) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
    return 0;
}


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

int main(void){
	int n, k;
	cin >> n >> k;
	vector<long> h;

	for(int i=0; i<n; i++){
		long val;
		cin >> val;
		h.push_back(val);
	}
	sort(h.begin(), h.end());

	long min_diff = 10000000000;
	for(int i=0; i<n-k+1; i++){
		long diff = h[i+k-1] - h[i];
		min_diff = min(min_diff, diff);
	}
	cout << min_diff << endl;

	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int train = n * a;
        System.out.println(Math.min(train, b));
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 3e5+1;
int n, a[N], b[N], ans[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    int c;
    cin >> c;
    a[c]++;
  }
  FOR(i, 1, n+1) b[a[i]]++;
  b[0] = 0;
  int s=0, t=n;
  FORR(i, n, 1){
    maxs(ans[t/i], i);
    s += b[i];
    t -= s;
  }
  FORR(i, n, 1) maxs(ans[i-1], ans[i]);
  FOR(i, 1, n+1) cout << ans[i] << endl;
}

Measured memory_bytes: 3200
#define ma(a,b)(a>b?a:b)
T[999],X[999],q,n,A,a,B,b,h,m,p;N(){if(~T[0])for(q=1;q<999;q++)if(~T[q])X[q]+=1440-ma(T[q],T[0]),T[q]=-1;T[0]=-1;}main(){for(;scanf("%d",&n),n;printf("%d\n",m)){for(memset(T,0xff,3996),memset(X,0,3996),A=0;n--;){if(scanf("%d/%d%d:%d%s%d",&a,&b,&h,&m,&p,&p),A-a||B-b)N(),A=a,B=b;if(h=h*60+m,~T[p]){if(p==0){for(q=1;q<999;q++)if(~T[q])X[q]+=h-ma(T[q],T[0]);}else if(~T[0])X[p]+=h-ma(T[p],T[0]);T[p]=-1;}else T[p]=h;}for(N(),m=0,p=1;p<999;p++)if(m<X[p])m=X[p];}exit(0);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	char s;
	cin >> s;
	if (s >= 65 and s <= 90) {
		cout << "A";
	}
	else {
		cout << "a";
	}


	return 0;
}

Measured memory_bytes: 3648
import itertools
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[2])]
li=[x for x in range(1,s[1]+1)]
lity=list(itertools.combinations_with_replacement(li,s[0]))
ans=0
for k in lity:
  vmax=0
  for l in t:
    if k[l[1]-1]-k[l[0]-1]==l[2]:
      vmax+=l[3]
  ans=max(ans,vmax)
print(ans)

Measured memory_bytes: 21584
n,m = map(int, input().split())
q=[input() for i in range(n)]
l=[i+1 for i in range(m)]
l1=[i+1 for i in range(m)]
for i in q:
  t=list(map(int, i.split()))
  for k in l1:
    if (k not in t[1:]):
      if k in l:
      	l.remove(k)
print(len(l))


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main() {
	int x=0, m=0,N;
	scanf ("%d",&N);
	char s[100]; 
	scanf (" %s",s);
	for (int i=0;i<=N;i++){
	if (s[i]=='I') {x=x+1;}
	 else { x=x-1; }
	if(x>m) {m=x;} 
	} printf ("%d\n",m);
	return 0;
	}



Measured memory_bytes: 128
#A,B=map(int,input().split(" "))
N=int(input())
a=list(map(int,input().split(" ")))
b=[0 for i in range(N)]
for i in range(N):
    b[a[i]-1]=i+1
#print(b)
print(" ".join(repr(e) for e in b))

Measured memory_bytes: 18368
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>





const int N=1e5+10;
int n,sz;
bool dp[N];
char s[N];
string s2[6];


bool f(int i,int k)
{
	string t="";
	for(int j=0;j<s2[k].length();j++)
	{
		t+=s[i+j];
	}
	return t==s2[k];
}



void solve()
{
	s2[1]="dream";
	s2[2]="dreamer";
	s2[3]="erase";
	s2[4]="eraser";
	cin>>(s+1);
	n=strlen(s+1);
	dp[n+1]=1;
	for(int i=n;i>=1;i--)
	{
		dp[i]=0;
		for(int j=1;j<=4;j++)
		{
			sz=s2[j].length();
			if(n-i+1>=sz&&f(i,j))
			{
				dp[i]|=dp[i+sz];
			}
		}
	}
	if(dp[1])cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

int main() {
  // cout << fixed << setprecision(10);

  int N;
  cin >> N;
  map<string,int> m;
  REP(i, N) {
    string S;
    cin >> S;
    m[S] = 1;
  }
  cout << m.size() << endl;
  return 0;
}


Measured memory_bytes: 19204
import scala.io.StdIn

object Main extends App {
  val s  = StdIn.readLine()

  def solve(s :String): String = {
    val ss = s.sorted
    if (ss(0) == ss(1) && ss(2) == ss(3) && ss(1) != ss(2)) "Yes" else "No"
  }

  println(solve(s))
}
  



Measured memory_bytes: 25524
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll a ;
	ll sum = 0 ;
	for(int i=0;i<n;i++){
		ll x ; cin >> x ;
		sum += x ;
		if(x%10!=0) a.push_back(x) ;
	}
	if(a.size()==0) cout << 0 << endl ;
	else{
		mysort(a) ;
		if(sum%10!=0) cout << sum << endl ;
		else cout << sum-a.at(0) << endl ;
	}
}


Measured memory_bytes: 256
import math
s = input()
n = len(s)
r = 0
l = 0
p = 0
x = 0
ans = [0 for i in range(n)]
for i in range(n):
    if p == 0:
        if s[i] == "R":
            r += 1
        elif s[i] == "L":
            ans[i-1] = math.ceil(r/2)
            ans[i] = math.floor(r/2)
            r = 0
            l += 1
            p = 1
            x = i
            if i == n-1:
                ans[n-1] += 1
    elif p == 1:
        if s[i] == "L":
            l += 1
            if i == n-1:
                ans[x-1] += math.floor(l/2)
                ans[x] += math.ceil(l/2)
        elif s[i] == "R":
            ans[x-1] += math.floor(l/2)
            ans[x] += math.ceil(l/2)
            l = 0
            r += 1
            p = 0
print(" ".join(map(str,ans)))

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll a,b,ans,m;
	cin>>a>>b;
	m=a*b;
	if (a==1||b==1) cout<<1<<endl; 
	else{
	  if (m%2==0) cout<<m/2;
	  else cout<<m/2+1;
    }
	return 0;	
}

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

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

  string s, str;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if (i%2 == 0) str += s[i];
  }
  cout << str << endl;

  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>s;
 for(int i=0; i<s.size(); i++)
 {
  if(s[i]=='C')	
  for(int j=i+1; j<s.size(); j++)
  {
   if(s[j]=='F')
   {
    cout<<"Yes";
	return 0;	
   }
  }	
 }
 cout<<"No";
 return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	run()
}

func run() {
	var total int
	var N, a, b int
	fmt.Fscan(reader, &N, &a, &b)

	for i := 1; i <= N; i++ {
		var sum int

		for tmp := i; tmp > 0; tmp /= 10 {
			sum += tmp % 10
		}

		if sum < a || sum > b {
			continue
		}

		total += i
	}

	fmt.Fprintln(writer, total)
}


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

using namespace std;

int main() {
    int Q = 0;
    string X,Y;
    cin>>Q;
    for (int q = 0; q < Q; q++) {
        cin>>X>>Y;

        int len[1001][1001] = {};
        for (int s = 1; s <= X.length(); s++) {
            for (int t = 1; t <= Y.length(); t++) {
                if (X[s-1] == Y[t-1]) len[s][t] = 1 + len[s-1][t-1];
                else len[s][t] = max(len[s-1][t], len[s][t-1]);
            }
        }
        cout<<len[X.length()][Y.length()]<<endl;
    }
}

Measured memory_bytes: 7048
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
//
#define forn(i, n)for(ll i=0;i<n;i++)
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n;
map<string,priority_queue<pll> >m;
int main(){FAST;
cin>>n;
for(ll i=1;i<=n;i++){
	string s;cin>>s;
	ll x;cin>>x;
	m[s].push({x,i});
}
for(auto it:m){
	while(!it.se.empty()){
		cout<<it.se.top().se<<'\n';
		it.se.pop();
	}
}
return 0;
}

Measured memory_bytes: 256
using System;

namespace BeginnerContest_100_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] hoge = Console.ReadLine().Split(' ');
            int a = int.Parse(hoge[0]);
            int b = int.Parse(hoge[1]);

            if (a <= 8&& b<=8) Console.WriteLine("Yay!");
            else Console.WriteLine(":(");
           
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define VI vector<int>
#define VII vector<pair<int, int>>
#define PII pair<int, int>
#define MP make_pair
// #define log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define log(fmt, ...)
// #define check(...) assert(##__VA_ARGS__)
#define check(...)

#define INF (ll)1e15

int n;
int a[200000];
int min_dist = 100;
int max_dist = -100;

ll cache[5][5][200000];
ll total = 0, total_hit = 0;

ll solve(int index, int choose, int gap_left) {
    total++;
    max_dist = max(max_dist, index - 2 * choose);
    min_dist = min(min_dist, index - 2 * choose);
    if (choose >= n / 2) {
        return 0;
    }

    int k = index - 2 * choose;
    if (cache[k][gap_left][index] != -INF) {
        total_hit++;
        return cache[k][gap_left][index];
    }
    ll ans = a[index] + solve(index + 2, choose + 1, gap_left);
    if (gap_left > 0) {
        ans = max(ans, solve(index + 1, choose, gap_left - 1));
    }
    return cache[k][gap_left][index] = ans;
}

int myrandom() {
    if (rand() > RAND_MAX / 2) {
        return (int)(rand() * 1.0 / RAND_MAX * 1e9);
    } else {
        return -(int)(rand() * 1.0 / RAND_MAX * 1e9);
    }
}

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

    // log("RAND_MAX = %d", RAND_MAX);

    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
        // a[i] = myrandom();
        // log("%d ", a[i]);
    }
    // log("\n");

    rep(i, 0, 5) {
        rep(j, 0, 5) {
            fill_n(cache[i][j], n, -INF);
        }
    }

    if (n % 2 == 0) {
        cout << solve(0, 0, 1);
    } else {
        cout << solve(0, 0, 2);
    }

    log("\n");
    log("max dist = %d\n", max_dist);
    log("min dist = %d\n", min_dist);
    log("total = %lld\n", total);
    log("total hit = %lld\n", total_hit);
}


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

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

    for (int i=1; i<=n; i++) {
        ll ans = 0;
        for (int x=1; x<101; x++) {
            for (int y=1; y<101; y++) {
                ll p = 4*i-3*x*x-3*y*y-2*x*y;
                if (p > 0 && ((ll) sqrt(p))*((ll) sqrt(p)) == p && sqrt(p)-x-y > 1 && (((ll) sqrt(p))-x-y)%2 == 0) {
                    ans++;
                    // cout << i << " : " << x << " " << y << " " << (sqrt(p)-x-y)/2 << endl;
                }
            }
        }
        cout << ans << endl;
    }
        
}


Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int n, m, q, s[505][505];

int main()
{
	cin >> n >> m >> q;
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		cin >> x >> y;
		s[x][y]++;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
	for (int i = 1; i <= q; i++)
	{
		int x, y;
		cin >> x >> y;
		swap(x, y);
		cout << s[x][x] - s[x][y - 1] - s[y - 1][x] + s[y - 1][y - 1] << endl;
	}
	return 0;
}

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

int getDate(int y, int m, int d){
	int cnt = 0;
	for(int yy=1; yy<=y; yy++){
		for(int mm=1; mm<=(yy==y?m:10); mm++){
			for(int dd=1; dd<=((yy==y&&mm==m)?d:yy%3==0?20:mm%2==0?19:20); dd++){
				cnt++;
			}
		}
	}
	return cnt;
}

int main(){
	int n;
	cin >> n;
	while(n--){
		int y, m, d;
		cin >> y >> m >> d;
		cout << 196471-getDate(y,m,d) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
	long x;
	cin>>x;
	long long init=100;
	long long yokin=0;
	long year=0;
	while(yokin<x){
		yokin=(long long)init*1.01;
		init = yokin;
		year++;
	}
	cout<<year<<endl;
	return 0;
}




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

ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

int main() {
  ll a, b, c;
  cin >> a >> b >>c;
  if(c % gcd(a,b) == 0){
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
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;}

const int INF = 1e9+5;
const ll LINF = 1e18;

int main(){
  int n,x;
  ll res;
  cin >> n>> x;
  vector<ll> a(n,0);
  rep(i,n) cin >> a[i];
  res = 0;
  for(int i=1;i<n;i++){
    ll eat = max((ll)0,(a[i-1]+a[i] - x));
    res+=eat;
    a[i] = max((ll)0,a[i]-eat);
  }
  cout << res << endl;
}

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

using namespace std;
                              
int n,l;

int main ()
{

cin>> n >>l;

string S[n];

for (int i=0 ; i<n ;++i){
cin>>S[i];
}

sort(S,S+n);
string totall="";

for (int i=0 ; i<n ;++i){
totall=totall + S[i];
}


cout<<totall<<endl;

return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int x;
  cin>>x;
  if(x%11>=7){
      cout<<2+(2*(long long int)(x/11));
  }else if(x%11!=0){
      cout<<1+(2*(long long int)(x/11));
  }else{
    cout<<(2*(long long int)(x/11));

  }

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10000000)

n,m = map(int,input().split())
to=[[] for _ in range(n)]
dist=[[0] *3 for _ in range(100005)]
INF=10**15

for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    to[a].append(b)

sv,tv=map(int,input().split())
sv-=1;tv-=1

for i in range(n):
    for j in range(3):
        dist[i][j] =INF

q=deque()
q.append((sv,0))
dist[sv][0]=0

while q:
    v,l=q.popleft()
    for u in to[v]:
        nl =(l+1)%3
        if dist[u][nl] != INF: continue
        dist[u][nl] = dist[v][l]+1
        q.append((u,nl))

ans=dist[tv][0]
if ans == INF:ans=-1
else: ans //=3
print(ans)

Measured memory_bytes: 38056
#include <bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;

#define M 2005
int n;
char s[M];
int a[M][M],f[M][M],l[M][M],r[M][M];

int main () {
//freopen("a.in","r",stdin);
//freopen("zj.out","w",stdout);
	scanf("%d",&n);
	for1(1,n,i) {
		scanf("%s",s+1);
		for1(1,n,j) a[i][j]= s[j]=='#'?0:s[j]-'0';
	}
	
	ll ans=0;
	FOR2(n,1,i) FOR2(n,1,j) { 
		if(a[i][j]) {
			bool t[2]={a[i+1][j],a[i][j+1]};
			if(!(t[0]|t[1])) {
				l[i][j]=r[i][j]=j;
				for1(i+1,n,k) l[k][j]=n+1,r[k][j]=0;
			}
			else if(t[0]&&!t[1]) {
				l[i][j]=r[i][j]=j;
				f[i][j]=f[i+1][j];
			}
			else if(!t[0]&&t[1]) {
				f[i][j]=f[i][j+1];
				l[i][j]=j,r[i][j]=r[i][j+1];
				for1(i+1,n,k) l[k][j]=l[k][j+1],r[k][j]=r[k][j+1];
			}
			else {
				int tot=f[i+1][j]+f[i][j+1];
				l[i][j]=j,r[i][j]=r[i][j+1];
				
				int las_r=0;
				for1(i+1,n,k) {
					if(l[k][j+1]<=r[k][j]&&l[k][j+1]>las_r) tot-=f[k][l[k][j+1]];
					las_r=max(las_r,r[k][j]);
					l[k][j]=min(l[k][j],l[k][j+1]);
					r[k][j]=max(r[k][j],r[k][j+1]);
				}
				f[i][j]=tot;
			}
		}
		else l[i][j]=n+1,r[i][j]=0;
		ans+=a[i][j]*f[i][j];
		f[i][j]+=a[i][j];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 20352
#include <stdio.h>
#include <math.h>

int main()
{
    unsigned long long int a,b,x;

    scanf("%llu %llu",&a,&b);

    x=(a+b)/2;

    if(abs(a-x)==abs(b-x))
        printf("%llu",x);
    else
        printf("IMPOSSIBLE");
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int N, K, T, U, V, L;
	cin >> N >> K >> T >> U >> V >> L;
	vector<int> D(N + 1);
	D[0] = 0;
	for(int i = 1; i <= N; ++i){ cin >> D[i]; }
	sort(D.begin(), D.end());
	D.push_back(L);
	int stock = 0;
	double answer = 0.0, remains = 0.0;
	for(int i = 1; i < D.size(); ++i){
//cerr << i << " : " << answer << ", " << remains << ", " << stock << endl;
		double len = D[i] - D[i - 1];
		if(stock == 0){
			answer += remains / V;
			answer += (len - remains) / U;
			++stock;
		}else{
			double d = remains;
			answer += remains / V;
			while(stock > 0 && d < len){
				d += V * T;
				answer += T;
				--stock;
			}
			if(d < len){
				remains = 0.0;
				answer += (len - d) / U;
				++stock;
			}else{
				remains = d - len;
				answer -= remains / V;
				if(stock == K){
					remains = V * T;
				}else{
					++stock;
				}
			}
		}
	}
	cout << setprecision(9) << setiosflags(ios::fixed) << answer << endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int p[1010];
    rep(i, N) cin >> p[i];
    sort(p, p + N);
    int ans = 0;
    rep(i, K) ans += p[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
from collections import deque
k = int(input())
d = deque()
d += [1,2,3,4,5,6,7,8,9]
for i in range(k):
#     print(d, now)
    now = d.popleft()
    if now%10 != 0:
        d.append(10 * now + now % 10 - 1)
    d.append(10 * now + now % 10)
    if now%10 != 9:
        d.append(10 * now + now % 10 + 1)
print(now)

Measured memory_bytes: 11908
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	long long a,b,c,d,max=0;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	max=a*c;
	if(max<a*d) max=a*d;
	if(max<b*c) max=b*c;
	if(max<b*d) max=b*d;
	printf("%lld\n",max);
	return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <map>
#include <algorithm>
typedef long long ll;
using namespace std;

map<int,int> p;
int ans;
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    p[a]++;
  }

  for(auto ite = p.rbegin(); ite != p.rend(); ++ite) {
    if((*ite).second == 0) continue;
    int tmp = (*ite).first;
    int k = 1;
    while(tmp >= k) k <<= 1;
    int tmp2 = k - tmp;
    //  cout <<"tmp = "<< tmp <<"  k = "<<k<<"  tmp2 = "<<tmp2<<endl;
    if(tmp == tmp2) {
      ans += p[tmp] / 2;
    }
    else {
      ans += min(p[tmp2],p[tmp]);
      p[tmp2] -= min(p[tmp2],p[tmp]);
    }
  }

  cout << ans << endl;
}
  


Measured memory_bytes: 18944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n){
		char c;
		scanf(" %c",&c);
		if(c=='Y'){
			puts("Four");
			return 0;
		}
	}
	puts("Three");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k;

signed main() {
	cin >> n >> k;
	int mi = 0, ma = k + 10;
	while (ma - mi > 1) {
		int md = (ma + mi) / 2;
		int ta = md;
		int cnt = 0;
		int cnt2 = 0;
		while (ta&&cnt2 < n) {
			cnt += ta;
			cnt2++;
			ta /= 2;
		}
		if (cnt <= k) {
			mi = md;
		}
		else ma = md;
	}
	cout << mi << endl;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    map<long long int,int>mp;
    //set<long long int>st;
    for(int i=0;i<n;i++)
    {
        long long num;
        cin>>num;
        mp[num]++;

    }
    auto it=mp.rbegin();
   // it--;
    long long mul=1;
    int d=4;
    while(it!=mp.rend())
    {
       // cout<<it->first<<" "<<it->second<<endl;
        if(it->second>=4&&d==4)
        {
            mul=mul*it->first*it->first;
            d-=4;

            //break;
        }
        else if(it->second>=2&&d>=2)
        {
            mul=mul*it->first;
            d-=2;
            //break;
        }
        if(d==0)break;
        it++;
    }
    if(d==4)cout<<0<<endl;
    else
        cout<<mul<<endl;
}


Measured memory_bytes: 6528