akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

string remove(string s, int x) {
   return s.substr(0, x) + s.substr(x+1, s.size()-1-x);
}
string insert(string s, int x, char c) {
   return s.substr(0, x) + c + s.substr(x, s.size()-x);
}

V<string> solve(string a, string b, int k) {
   if (k == 1) {
      return V<string>({a, b});
   }

   int x = -1;
   for (int i = 0; i < k; i++) {
      if (a[i] != b[i]) {
         x = i; break;
      }
   }

   string a_ = remove(a, x);
   string b_ = remove(b, x);
   string c_ = remove(a_, k-2) + (a_[k-2] == '0' ? "1" : "0");
   V<string> Q = solve(a_, c_, k-1);
   V<string> R = solve(c_, b_, k-1);

   V<string> P(1<<k);
   for (int i = 0; i < 1<<k-1; i++) {
      P[i] = insert(Q[i], x, a[x]);
      P[i + (1<<k-1)] = insert(R[i], x, b[x]);
   }
   return P;
}

signed main()
{
   int n, a, b; cin >> n >> a >> b;
   string A, B;
   for (int i = n-1; i >= 0; i--) {
      A = A + to_string(a >> i & 1);
      B = B + to_string(b >> i & 1);
   }

   int cnt = 0;
   for (int i = 0; i < n; i++) {
      if (A[i] != B[i]) {
         cnt++;
      }
   }
   if (cnt % 2 == 0) {
      cout << "NO" << endl;
      return 0;
   }

   cout << "YES" << endl;

   V<string> ans = solve(A, B, n);

   for (int i = 0; i < 1<<n; i++) {
      int tmp = 0;
      for (int j = 0; j < n; j++) {
         if (ans[i][j] == '1') {
            tmp |= 1<<n-1-j;
         }
      }
      cout << tmp << (i == (1<<n)-1 ? "\n" : " ");
   }

   return 0;
}


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

int main() {
	int D,N;
  	cin >> D >> N;
  
  	if(D == 0) {
      if(N != 100) {
    	cout << N << endl;
      }else {
      	cout << 101 << endl;
      }
    }else if(D == 1) {
      if(N != 100) {
    	cout << 100 * N << endl;
      }else {
      	cout << 10100 << endl;
      }
    }else  {
      if(N != 100) {
    	cout << 10000 * N << endl;
      }else {
      	cout << 1010000 << endl;
      }
    }
}
  

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();


      if(a==1&&b==2){
        System.out.println("3");
      }
      if(b==1&&a==2){
        System.out.println("3");
      }
      if(a==2&&b==3){
        System.out.println("1");
      }
      if(b==2&&a==3){
        System.out.println("1");
      }
      if(a==1&&b==3){
        System.out.println("2");
      }
      if(b==1&&a==3){
        System.out.println("2");
      }

  }
}


Measured memory_bytes: 19540
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  ll X, K, D;
  cin >> X >> K >> D;
  ll tmp, ans, cou;
  cou = tmp = ans = 0;
  X = abs(X);
  tmp = X / D;
  if (tmp > K) {
    ans = X - K * D;
  } else {
    cou = tmp;
  	tmp = X - cou * D;
  	ll tmp1 = K - cou;
    if (tmp1 % 2 == 0) {
      ans = tmp;
    } else {
      ans = abs(tmp-D);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3760
import sys
fin = sys.stdin.readline


MAX_NUM = float('inf')

def initialize_int(adj, s):
    """
    assume that all vertex in {0, 1, 2, ..., N - 1}
    """
    N = len(adj)
    d = [MAX_NUM] * N
    d[s] = 0
    parent = [None] * N
    return d, parent


def relax(d, w, source_v, target_v, parent):
    new_cost = d[source_v] + w[source_v][target_v]
    if new_cost < d[target_v]:
        d[target_v] = new_cost
        parent[target_v] = source_v


# Even if a negative weight exists, bellman-ford can find shortest paths.
# it also detects negative cycles,
# but not every edges that consist the negative cycles is stored.
# time complexity: O(VE + (V^2))
def bellman_ford(adj, w, s):
    d, parent = initialize_int(adj, s)

    # calculate shortest paths
    for _ in range(len(adj)):
        for vertex in range(len(adj)):
            for neighbor in adj[vertex]:
                relax(d, w, vertex, neighbor, parent)

    # detects negative cycles if exist
    negative_cycle_edges = set()
    for vertex in range(len(adj)):
        for neighbor in adj[vertex]:
            if d[neighbor] > d[vertex] + w[vertex][neighbor]:
                negative_cycle_edges.add((vertex, neighbor))
    return d, parent, negative_cycle_edges



V, E, r = [int(elem) for elem in fin().split()]
adj = [[] for _ in range(V)]
w = [[None] * V for _ in range(V)]
for _ in range(E):
    s, t, d = [int(elem) for elem in fin().split()]
    adj[s].append(t)
    w[s][t] = d

d, parent, negative_cycle_edges = bellman_ford(adj, w, r)
if len(negative_cycle_edges) > 0:
    print("NEGATIVE CYCLE")
else:
    for i in range(V):
        print("INF") if d[i] == MAX_NUM else print(d[i])




Measured memory_bytes: 13972
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
X = []
for i in range(N):
  if i == 0:
    cnt = A[i]
  else:
    if A[i] == cnt:
      X.append(A[i])
      cnt = 0
    else:
      cnt = A[i]
if len(X) >= 2:
    print(X[0]*X[1])
else:
  print(0)

Measured memory_bytes: 14252
using System;

class AOJ{
  static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());

    for (int i = 0; i < n; i++){

      string[] s = Console.ReadLine().Split(' ');
      double x1, y1, x2, y2, x3, y3, px, py, r;

      x1 = double.Parse(s[0]);
      y1 = double.Parse(s[1]);
      x2 = double.Parse(s[2]);
      y2 = double.Parse(s[3]);
      x3 = double.Parse(s[4]);
      y3 = double.Parse(s[5]);

      px = ((y2 - y3) * (x1 * x1 + y1 * y1) + (y3 - y1) * (x2 * x2 + y2 * y2) + (y1 - y2) * (x3 * x3 + y3 * y3)) / (2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)));
      py = ((x2 - x3) * (x1 * x1 + y1 * y1) + (x3 - x1) * (x2 * x2 + y2 * y2) + (x1 - x2) * (x3 * x3 + y3 * y3)) / (2 * (y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)));

      r = Math.Sqrt(Math.Pow((x1 - px), 2) + Math.Pow((y1 - py), 2));

      Console.WriteLine("{0:f3} {1:f3} {2:f3}", px, py, r);
    }
  }
}

Measured memory_bytes: 9428
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
  char s[100];
  cin >> s;
  int s_size = strlen(s);
  int flg = 0;
  if(s_size%2==1) {
    flg = 1;
  } else {
    REP(i,s_size/2) {
      if(s[2*i]!='h'||s[2*i+1]!='i') flg++;
    }
  }
  if(flg>=1) {
    cout << "No" << endl;
  } else {
    cout  << "Yes" << endl;
  }
  
  return 0;
}


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

#define ll long long int

ll n, a[3005], dp_mx[3005][3005], dp_mn[3005][3005];

ll f(ll i, ll j){

    if(i > j) return 0;
    if(i == j+1) return dp_mx[i][j] = max(a[i], a[j + 1]) - min(a[i], a[j + 1]);

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

    ll p = a[i] + min(f(i+2,j), f(i+1,j-1));
    ll q = a[j] + min(f(i+1, j-1), f(i, j-2));

    return dp_mx[i][j] = max(p,q);
}

ll g(ll i, ll j){

    if(i > j) return 0;
    if(i == j+1) return dp_mn[i][j] = max(a[i], a[j + 1]) - min(a[i], a[j + 1]);

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

    ll p = a[i] + min(f(i+2,j), f(i+1,j-1));
    ll q = a[j] + min(f(i+1, j-1), f(i, j-2));

    return dp_mn[i][j] = max(p,q);
}

int main() {

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

    cin>>n;
    for(ll z=0;z<n;z++) cin>>a[z];

    memset(dp_mx, -1, sizeof dp_mx);

    ll j = f(0,n-1);
    ll j1 = f(1,n-1), j2 = f(0, n-2);
    if(j1 < j2) cout<<j - j1;
    else cout<<j - j2;




    return 0;
}


Measured memory_bytes: 74380
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  int n,a[100000],dp[100000];
  memset(dp,0,sizeof(dp));
  scanf("%d",&n);
  for(int i=0;i<n;i+=1){
    scanf("%d",&a[i]);
  }
  dp[0]=0,dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i+=1){
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  printf("%d",dp[n-1]);
}

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

using namespace std;

struct DATA{
  string s1, s2, s3, s4, s5, s6;
};

void Swap(string&, string&, string&, string&);
DATA MakeData(string, string, string, string, string, string);
int SearchTheSame(DATA, DATA);

int main(){
  int i, j, n, x;
  string s1, s2, s3, s4, s5, s6;
  DATA _data;
  vector<DATA> data;

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

    for(i=0; i<n; ++i){
      cin >> s1 >> s2 >> s3 >> s4 >> s5 >> s6;

      if(s2 == "Red"){
	Swap(s1, s2, s6, s5);
      }else if(s3 == "Red"){
	Swap(s1, s3, s6, s4);
      }else if(s4 == "Red"){
	Swap(s1, s4, s6, s3);
      }else if(s5 == "Red"){
	Swap(s1, s5, s6, s2);
      }else if(s6 == "Red"){
	Swap(s1, s2, s6, s5);
	Swap(s1, s2, s6, s5);
      }

      _data = MakeData(s1, s2, s3, s4, s5, s6);

      for(j=0, x=0; j<data.size(); ++j){
	if(SearchTheSame(data[j], _data) == 1){
	  x = 1;
	  break;
	}
      }
      if(x == 0) data.push_back(_data);
    }

    cout << n-data.size() << endl;
    data.clear();
  }
  return 0;
}

void Swap(string& a, string& b, string& c, string& d){
  string e;
  e = a;
  a = b;
  b = c;
  c = d;
  d = e;
}

DATA MakeData(string s1, string s2, string s3, string s4, string s5, string s6){
  DATA data;
  data.s1 = s1;
  data.s2 = s2;
  data.s3 = s3;
  data.s4 = s4;
  data.s5 = s5;
  data.s6 = s6;
  return data;
}

int SearchTheSame(DATA data1, DATA data2){
  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  Swap(data2.s2, data2.s3, data2.s5, data2.s4);

  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  Swap(data2.s2, data2.s3, data2.s5, data2.s4);

  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  Swap(data2.s2, data2.s3, data2.s5, data2.s4);

  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

using i64 = int64_t;

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

    int tmp8,tmp10;
    tmp8 = A * 100 / 8;
    tmp10 = B * 10;
    int ans = -1;
    for (int i = 0; i < 10; i++) {
        int tmp0 = (int)(tmp10 + i) * 0.08;
        for (int j = 0; j < 10; j++) {
            int tmp1 = (int)(tmp10 + j) * 0.1;
            if (tmp0 == A && tmp1 == B) {
                ans = tmp10 + i;
                goto fin;
            }
        }
    }
        
fin:
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll k;
    cin>>k;
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<a[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int e;
    e=min(b,d)-max(a,c);
    if(e>0){
        cout <<e;
    }else{
        cout<<0;
    }
    return 0;
}


Measured memory_bytes: 256
l = []
while True:
    try:
        a = list(map(int, input().split()))
        l.append(a)   
    except EOFError:
        break
    
for i in range(len(l)-1):
    x, y = l[i]
    if x >= y:
        print(y, x)
    
    else:
        print(x, y)


Measured memory_bytes: 6248
# AOJ 0298: Bus Timetable
# Python3 2018.6.25 bal4u

tbl = set()
for i in range(2):
	t = list(map(int, input().split()))
	for j in range(1, 2*t[0], 2): tbl.add((t[j], t[j+1]))
print(*[("{}:{:02}".format(*i)) for i in sorted(tbl)])


Measured memory_bytes: 5648
s=input()
t=input()
a=len(s)
b=len(t)
ans=1001
kari=0
for i in range(0,a-b+1):
    c=s[i:b+i]
    kari=0
    k=0

    for j in range(b):
        if t[j]!=c[j]:
            kari+=1
      
    if ans>kari:
        ans=kari
print(ans)  

Measured memory_bytes: 9120
def li():
    return [int(x) for x in input().split()]

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5 + 100)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)

Measured memory_bytes: 205416
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

void solve (int n)
{
    vi p(n), where(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        --p[i];
        where[p[i]] = i;
    }

    set<pair<int, int>> segm;
    segm.insert(mp(0, n));

    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        int pos = where[i];
        auto it = segm.lower_bound(mp(pos + 1, -1));
        assert(it != segm.begin());
        --it;
        assert(it != segm.end());
        int l = it -> first, r = it -> second;
        assert(l <= pos && pos < r);

        ll add = (ll)(i + 1) * (ll)(pos - l + 1) * (ll)(r - pos);
        ans += add;

        segm.erase(mp(l, r));
        if (l < pos)
            segm.insert(mp(l, pos));
        if (pos + 1 < r)
            segm.insert(mp(pos + 1, r));
    }

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

int main()
{
    #ifndef ONLINE_JUDGE
   // freopen("input.txt", "rt", stdin);
   // freopen("output.txt", "w", stdout);
    #endif

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

    int n;
    while (cin >> n)
        solve(n);
}


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

#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 INF (3e15)

using namespace std;

int H, W, N;
int A[10005];
int c[105][105];


signed main()
{
    cin >> H >> W;
    cin >> N;
    REP(i, N) cin >> A[i];

    int aindex = 0;
    REP(i, H) REP(j, W)
    {
        while (A[aindex] == 0) aindex++;
        A[aindex]--;
        c[i][i%2 == 0 ? j : W-1-j] = aindex+1;
    }
    REP(i, H) REP(j, W)
    {
        if (j != 0) printf(" ");
        printf("%lld", c[i][j]);
        if (j == W-1) printf("\n");
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    int cnt = 0;

    rep(i,n-2) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') cnt++;
    }

    cout << cnt << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a,b; 
int main()
{
    cin>>a>>b; 
    if(a%3==0||b%3==0||(a+b)%3==0) 
        cout<<"Possible\n"; 
    else
        cout<<"Impossible\n"; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int arr[101000];
void err(){
	cout<<"No\n";
	exit(0);
}
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	int n; cin>>n;
	for (int i = 0; i < n; ++i)
		cin>>arr[i];
	sort(arr, arr + n);
	if(arr[n-1] == n -1 && arr[0] == n - 1){
		cout<<"Yes\n"; return 0;
	}
	if(arr[n -1] - arr[0] > 1)
		err();
	// cout<<".";
	int counter = 0;
	if(arr[0] != arr[n-1])
		for (int i = 0; i < n; ++i)
			if(arr[i] == arr[0])
				counter++;
	int left_people = n - counter;
	if(arr[n-1] - counter <= 0)
		err();
	// cout<<".";
	if(left_people < 2*(arr[n-1] - counter) )
		err();
	cout<<"Yes\n";
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL a, b, x;
    cin >> a >> b >> x;
    if(a != 0) cout << (b / x) - ((a - 1) / x) << endl;
    else cout << b / x + 1 << endl;

    return 0;
}



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

using namespace std;
using namespace atcoder;

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

    vector<long long> av,bv;
    for(int i=0;i<N;i++){
        long long a;
        cin>>a;
        av.push_back(a);
    }
    for(int i=0;i<M;i++){
        long long b;
        cin>>b;
        bv.push_back(b);
    }

    vector<long long> ans=convolution(av,bv);
    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<endl;
        if(i==ans.size()-1) cout<<endl;
        else cout<<" ";
    }
}


Measured memory_bytes: 28484
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    constexpr int N = 393;
    int n; cin >> n;
    vector<int> s(n), l(n), p(n);
    REP(i, n) cin >> s[i] >> l[i] >> p[i];

    auto dp = make_v(n + 1, N + 1, 0);

    REP(i, n)REP(j, N + 1) {
        FOR(k, s[i], l[i] + 1) {
            if (j + k <= N) {
                dp[i][j + k] = max(dp[i][j + k], dp[i][j] + p[i]);
            }

            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }

    int m; cin >> m;
    vector<int> ans(m);
    REP(i, m) {
        int w; cin >> w;
        ans[i] = dp[n][w];
    }

    if (find(ans.begin(), ans.end(), 0) != ans.end()) {
        cout << -1 << endl;
    } else {
        REP(i, m) cout << ans[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3364
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
long long a[100000];
long long gcd(long long a,long long b)
{
	return b?gcd(b,a%b):a;
}

int cmp(const long long &a,const long long &b)
{
	if (a%2==0 && b%2==1) return 1;
	else if (a%2==1 && b%2==0) return 0;
	else return a<b;
}
int main()
{
	int N,n;
	while(1)
	{
		long long x,y,z,tmp,r1,r2,d2,m,p,q;
		scanf("%d",&n);
		if (n==0) break;
		N=(n+1)*n/2;
		for (int i=1;i<=N;i++) scanf("%lld",a+i);

		sort(a+1,a+N+1,cmp);
		x=a[n+1]; y=a[1];	z=a[2];

		tmp=gcd(y,z);	r1=y/tmp;	r2=z/tmp;
		d2=x/r1/r2;

		p=1;q=(1<<31)-1;
		while (p<=q)
		{
			m=(p+q)>>1;
			if (m*m==d2) break;
			else if (m*m<d2) p=m+1;
			else q=m-1;
		}
		tmp/=m;

		printf("%lld\n",tmp);
		for (int i=1;i<=n;i++)
			{
				if (i<n) printf("%lld ",a[i]/tmp);
				else printf("%lld\n",a[i]/tmp);
			}
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 310;
const ll INF = 1e18;

ll N, M, L, Q;
ll dist[MAX][MAX];
ll step[MAX][MAX];

int main() {
    cin >> N >> M >> L;
    REP (i, MAX) REP (j, MAX) dist[i][j] = (i == j ? 0 : INF);
    REP (i, M) {
        ll a, b, c; cin >> a >> b >> c;
        dist[a-1][b-1] = dist[b-1][a-1] = c;
    }

    REP (k, N) REP (a, N) REP (b, N) dist[a][b] = min(dist[a][b], dist[a][k] + dist[k][b]);
    REP (a, N) REP (b, N) step[a][b] = (a == b ? 0 : (dist[a][b] <= L ? 1 : INF));
    REP (k, N) REP (a, N) REP (b, N) step[a][b] = min(step[a][b], step[a][k] + step[k][b]);

    cin >> Q;
    REP (i, Q) {
        int s, t; cin >> s >> t;
        ll ans = step[s-1][t-1];
        if (ans >= INF) ans = 0;
        cout << ans - 1 << endl;
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
const int MAXN=5010,P=1e9+7;
int n,x,y,eg,hd[MAXN],ver[2*MAXN],nx[2*MAXN],dp[MAXN][MAXN],f[MAXN],fac[MAXN],siz[MAXN];
void add_edge (int x,int y) {
	ver[++eg]=y;
	nx[eg]=hd[x];
	hd[x]=eg;
	return;
}
void dfs (int x,int fa) {
	dp[x][1]=siz[x]=1;
	for (int i=hd[x];i;i=nx[i]) {
		if (ver[i]==fa) {continue;}
		dfs(ver[i],x);
		for (int j=siz[x];j>=1;j--) {
			for (int k=siz[ver[i]];k>=1;k--) {
				dp[x][j+k]=(dp[x][j+k]+(1ll*dp[x][j]*dp[ver[i]][k])%P)%P;
			}
			dp[x][j]=(1ll*dp[x][j]*(P-f[ver[i]]))%P;
		}
		siz[x]+=siz[ver[i]];
	}
	for (int i=1;i<=siz[x];i++) {f[x]=(f[x]+(1ll*dp[x][i]*fac[i])%P)%P;}
	return; 
}
int main () {
	scanf("%d",&n);
	fac[0]=1;
	for (int i=2;i<=n;i+=2) {fac[i]=(1ll*fac[i-2]*(i-1))%P;}
	for (int i=1;i<=n-1;i++) {
		scanf("%d%d",&x,&y);
		add_edge(x,y),add_edge(y,x);
	}
	dfs(1,0);
	printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 58180
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 1000000007
typedef long long ll;

int main(){
  ll count=0,B[210000],W[210000];
  ll N;
  string S;
  cin>>N>>S;
  B[0]=0;

  for(ll i=0;i<N;i++){
    if(i!=0) B[i]=count;
    if(S[i]=='#') count++;
  }
  count=0;

  for(ll i=N-1;i>=0;i--){
    W[i]=count;
    if(S[i]=='.') count++;
  }
  ll ans=210000;
  for(ll i=0;i<N;i++){
    ans=min(ans,B[i]+W[i]);
  }
  cout<<ans<<endl;
}



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

using namespace std;

using ll = long long;

int main (void){
  int n;
  cin >> n;
  cin.ignore();

  int a[n] = {0};
  bool e[n] = {false};
  for (int i = 0; i< n; i++){
    cin>>a[i];
    cin.ignore();
  }
  int p = 0;
  int cnt = 0;
  while(1){
    if(e[p] == true){
      cout << -1 << endl;
      return 0;
    }
    e[p] = true;
    p = a[p] - 1;
    cnt++;
    if(p == 1){
      cout << cnt << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 768
mod = 1000000007
N, K = map(int, input().split())

pos = []
neg = []
A = list(map(int, input().split()))
for i in range(N):
    if A[i] > 0:
        pos.append(A[i])
    else:
        neg.append(A[i])

ans = 1
if len(pos) == 0:
    if K % 2 == 0:
        neg.sort(reverse=True)
    else:
        neg.sort()
    for i in range(K):
        ans = (ans * neg.pop()) % mod
elif N == K:
    for i in pos:
        ans = (ans * i) % mod
    for i in neg:
        ans = (ans * i) % mod
else:
    pos.sort()
    neg.sort(reverse=True)
    if K % 2 == 1:
        ans = pos.pop()
    for i in range(K//2):
        if len(pos) > 1 and len(neg) > 1:
            if pos[-1] * pos[-2] > neg[-1] * neg[-2]:
                for _ in range(2):
                    ans = ans * pos.pop() % mod
            else:
                for _ in range(2):
                    ans = ans * neg.pop() % mod
        elif len(pos) > 1:
            for _ in range(2):
                ans = ans * pos.pop() % mod
        else:
            for _ in range(2):
                ans = ans * neg.pop() % mod


print(ans)


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

int main() {
  
  string S;
  cin >> S;
  
  int N = S.size();
  sort(S.begin(), S.end());
  
  for(char i='a'; i<='z'; i++){
    int ans =0;
    for(int j=0; j<N; j++){
      if(S.at(j) == i){
        ans++;
      }
    }
  
    if(ans == 0){
      cout << i << endl;
      return 0;
    }
    
  }
  
  cout << "None" << endl;
 
}


Measured memory_bytes: 3732
n = int(input())
a = [ int(i) for i in input().split() ]
res = 0
exist_odd = False
while exist_odd == False :
    for item in a:
        if item % 2 != 0:
            exist_odd = True
            break
    if exist_odd == False:
        res += 1
        a = list(map(lambda x:x/2, a))
print(res)


Measured memory_bytes: 2940
// https://atcoder.jp/contests/abc147/tasks/abc147_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        s: chars
    };
    let n = s.len();
    let mut total = 0;
    for i in 0..n/2 {
        if s[i] != s[n-1-i] {
            total += 1;
        }
    }
    println!("{}", total);
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] h = new int[101];
		while (sc.hasNext()) {
			h[Integer.parseInt(sc.next())]++;
		}
		long max = 0;
		for (int i = 0 ; i < 101 ; i++) max = Math.max(max, h[i]);
		for (int i = 0 ; i < 101 ; i++) if (max == h[i]) System.out.println(i);
    }
}

Measured memory_bytes: 17168
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;


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

	ll a, b, y = 1,c=0;
	cin >> a >> b;
	while (y < b) {
		y += a - 1;
		c++;
	}
	cout << c << endl;
}


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

int main(){


	int H,W;
	cin >> H >> W;
	int answer = 120441222;

	int point[25][25];

	for(int i=0;i<25;i++){
		for(int j=0;j<25;j++){
			point[i][j] = 0;
		}
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int A;
			cin >> A;
			point[i][j] = A;
		}
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int karians = 0;

			for(int m=0;m<H;m++){
				for(int n=0;n<W;n++){
					karians += point[m][n] * min( abs(i-m),abs(j-n) );
				}
			}

			if(karians < answer){
				answer = karians;
			}
		}
	}

	cout << answer << endl;
	return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i < h; i++) cin >> s[i];

    int L[h][w] = {}, R[h][w] = {}, U[h][w] = {}, D[h][w] = {};

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j] == '#') {
                L[i][j] = 0;
                U[i][j] = 0;
                continue;
            }

            if(i == 0) U[i][j] = 1;
            else U[i][j] = U[i - 1][j] + 1;

            if(j == 0) L[i][j] = 1;
            else L[i][j] = L[i][j - 1] + 1;
        }
    }

    for(int i = h - 1; i >= 0; i--) {
        for(int j = w - 1; j >= 0; j--) {
            if(s[i][j] == '#') {
                R[i][j] = 0;
                D[i][j] = 0;
                continue;
            }

            if(i == h - 1) D[i][j] = 1;
            else D[i][j] = D[i + 1][j] + 1;

            if(j == w - 1) R[i][j] = 1;
            else R[i][j] = R[i][j + 1] + 1;
        }
    }

    int ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            int temp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
            if(ans < temp) ans = temp;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 66816
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e5+10;

    int a[N];ll fac[N],facinv[N];ll C(int n,int m){return (n<0 or n<m)?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
    void main()
	{
        fac[0]=1;fo(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
        facinv[N-1]=invm(fac[N-1]);fd(i,N-1,1) facinv[i-1]=facinv[i]*i%MOD;
        int n=qread(),k=qread();fo(i,1,n) a[i]=qread();sort(a+1,a+n+1);
        ll ans=0;
        fo(i,1,n) add(ans,C(i-1,k-1)*a[i]%MOD);
        fo(i,1,n) add(ans,MOD-C(n-i,k-1)*a[i]%MOD);
        write((ans+MOD)%MOD);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if((a==5||a==7)&&(b==5||b==7)&&(c==5||c==7)){
    if(a+b+c==17)printf("YES");
  	else printf("NO");}
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N, T = na()
ct = nan(N)

ans = inf
for i in range(N):
    c, t = ct[i]
    if t <= T:
        ans = min(ans, c)

print(ans if ans != inf else "TLE")

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;

namespace ABC127 {
  class ProblemA {
    static void Main(string[] args) {
      int[] input = Input.nums;
      if (input[0] < 6) {
        System.Console.WriteLine(0);
      } else if (input[0] < 13) {
        System.Console.WriteLine(input[1] / 2);
      } else {
        System.Console.WriteLine(input[1]);
      }
    }
  }
  public class Input {
    public static string str => System.Console.ReadLine();
    public static string[] strs => str.Split(' ');
    public static char[] charArr => str.ToCharArray();
    public static int num => int.Parse(str);
    public static int[] nums => Array.ConvertAll(strs, int.Parse);
    public static long numL => long.Parse(str);
    public static long[] numLs => Array.ConvertAll(strs, long.Parse);
  }
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string div[4] = {"dream", "dreamer", "erase", "eraser"};

    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    REP(i, 4){ reverse( div[i].begin(), div[i].end()); }

    bool flag2 = false;

    for (int i = 0; i < s.size();){

        for ( int j = 0; j < 4; j++){
            string d = div[j];
            if ( d == s.substr(i, d.size()) ){  //sのi番目からd文字分取った時一致か
                flag2 = true;
                i += d.size();
                break;
            }
            else {
                flag2 = false;
            }
        }
        if( !flag2) break;
    }

    if(flag2){ cout << "YES" << endl;}
    else{ cout << "NO" << endl;}



    return 0;
}


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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define MAXN (1 << 19)
#define K 26

int n;
char s[MAXN];
int a[K];
int b[MAXN][K];

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%s", s);
	n = strlen(s);

	for (int i = 0; i < n ; ++i) {
		++a[s[i] - 'a'];
		memcpy(b[i], a, sizeof(a));
	}
	
	ll ans = 1;
	for (int i = 0; i < n ; ++i) {
		for (int j = 0; j < K; ++j) {
			if (j == s[i] - 'a') continue;
			ans += b[n - 1][j] - b[i][j]; 
	  }
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 20864
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


int main() {
	int a, b, k[35], l[35];
	cin >> a >> b;
	vector<int>ans(a);
	char c;
	for (int i = 0; i < a; ++i) { ans[i] = 1 + i; }
	for (int i = 0; i < b; ++i) { cin >> k[i] >> c >> l[i]; swap(ans[k[i] - 1], ans[l[i] - 1]); }
	for (auto i : ans) { cout << i << endl; }
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define contests_de_diya_kar 0
#define PB push_back
#define MP make_pair
#define int long long
#define MOD ((long long) (1000*1000*1000 + 7))
#define maxn 5000
#define inf (int) 2e15
#define exit(a, b) return cout << a, b;
#define eps (double)1e-8
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define vb vector<bool>
#define all(v) v.begin(), v.end() 
#define pii pair<int, int>
#define mii map<int, int> 
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

signed main () {
	start_routine;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;

	int arr[n];
	forn(0, n, i) cin >> arr[i];

	sort(arr, arr + n);

	cout << abs(arr[n - 1] - arr[0]) << endl;
	end_routine;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
bool comp(int a,int b){
return a>b;
}
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define sz 100100
int val[sz];
vector<int>adj[sz];
int ret(int a)
{
    if (val[a] != -1)  return val[a];
    int &mx = val[a];
    for (auto it : adj[a])
        mx = max(mx, 1 + ret(it));
    return mx;
}
int main()
{
    int n, m, a, b, mx;
    scanf("%d", &n); scanf("%d", &m);
    for (int i = 0; i < m; ++i)
    {
        scanf("%d", &a);
        scanf("%d", &b);
        adj[a].push_back(b);
        val[a] = -1;
    }
    mx = 0;
    for (int i = 1; i <= n; ++i)
    {
        mx = max(mx, ret(i));
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 7424
from math import ceil

n = int(input())
x = ceil(n / 1.08)
print(x if int(x * 1.08) == n else ':(')

# n=floor(x*1.08)
# n<=x*1.08<n+1
# n/1.08<=x<(n+1)/1.08

# xの必要条件は、
# n/1.08<=x<(n+1)/1.08
# xは整数

# xは整数とn/1.08<=xから、
# ceil(n/1.08)である必要があるので、これがnに一致すれば、
# n/1.08<=x<(n+1)/1.08
# この範囲に整数がある


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n);
	bool ok = true;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > i) ok = false;
	}
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1] + 1) {
			ok = false;
		} else if (a[i] != a[i - 1] + 1) {
			ans += a[i - 1];
		}
	}
	ans += a[n - 1];
	dump(ok ? ans : -1);

	return 0;
}


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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    vector<int> AA(N, 0);
    int asum = 0;
    int bsum = 0;
    rep(i, N){
        asum += A[i];
        AA[i] = asum;
        bsum += B[i];
    }
    vector<int> BB(N, bsum);
    bsum = 0;
    rep(i, N){
        BB[i] -= bsum;
        bsum += B[i];
    }
    int xam = 0;
    rep(i, N){
        if(AA[i] + BB[i] > xam){
            xam = AA[i] + BB[i];
        }
    }
    /*rep(i, N){
        cout << AA[i] << " ";
    }
    cout << endl;
    rep(i, N){
        cout << BB[i] << " ";
    }
    cout << endl;*/
    cout << xam << endl;
return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

set<int> st;
int n,m,a[300][300] = {0};

int main()
{
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			cin >> a[j][i];
		}
	}

	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}


	int cnt[301] = {0};

	int sol = INF;

	for(int i = 1; i <= m-1; i++)
	{

		for(int j = 0; j <= m; j++)
		{
			cnt[j] = 0;
		}

		for(int j = 0; j < n; j++)
		{
			for(int k = 0; k < m; k++)
			{
				if (st.count(a[k][j]) == 0)
				{
					//cout << "a = " << a[k][j] << endl;
					cnt[a[k][j]]++;
					break;
				}
			}
		}

		int max = 0,sl = 0;

			for(int j = 1; j <= m; j++)
			{
				//cout << "j = " << j << "  cnt[j] == " << cnt[j] << endl;
				if (cnt[j] > sl)
				{
					sl = cnt[j];
					max = j;
				}
			}

			//cout << "max = " << max << endl;

			if (sol > sl)
			{
				sol = sl;
			}

			st.insert(max);
	}

	cout << sol << endl;

	return 0;
}

Measured memory_bytes: 640
LIMIT = 10000000
 
isPrime = [True for _ in range(LIMIT)]

isPrime[0] = isPrime[1] = False
 
for i in range(2, int(LIMIT ** 0.5)+1):
  if isPrime[i]:
    for j in range(i * i, LIMIT, i):
      isPrime[j] = False
 
try:
    while True:
        n = int(input())

        count = 0
        if n >= 2:
            count = 1

        for i in range(3, n+1, 2):
            if isPrime[i]:
                count += 1

        print(count)
except EOFError:
  pass

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

int main() {
    long long n;
    cin >> n;
    long long a[n+2];
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    a[n+1]=0;
    long long count=0;
    for(int i=1;i<=n+1;i++){
        count+=abs(a[i]-a[i-1]);
    }
    for(int i=1;i<=n;i++){
        long long ans=count;
        ans=ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 2048
package main

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

func main() {
	n := ReadInt()
	a := ReadInts(n)
	max := Max(a...)
	k := 1 << 61
	for _, v := range a {
		if max != v && Abs(max-2*v) < Abs(max-2*k) {
			k = v
		}
	}
	fmt.Println(max, k)
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

func Combination(n int, k int) int { return Permutation(n, k) / Factorial(k) }
func Factorial(n int) int          { return Permutation(n, n-1) }
func Permutation(n int, r int) int {
	v := 1
	for i := 0; i < r; i++ {
		v *= n - i
	}
	return v
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4284