akhauriyash/Code-Regression huggingface dataset:
n = int(input())
As = list(map(int, input().split(" ")))

pos = [a for a in As if a > 0]
neg = [a for a in As if a < 0]

if len(neg) % 2 == 0:
    print(sum(pos + [0]) - sum(neg + [0]))
else:
    print(sum(pos) - sum(neg) - 2 * min(map(abs, As)))


Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
struct dis{
	long long a,b;
	}cak[100005];
bool cmp(dis x, dis y){
	int p = x.a - y.b;
	int q = y.a - x.b;
	return p > q;
	}
int main(){
	int n;
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>cak[i].a>>cak[i].b;
	sort(cak + 1, cak + n + 1,cmp);
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		if(i & 1) ans += cak[i].a;
		else ans -= cak[i].b;
		}
	printf("%lld\n",ans);
	return 0;
	}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
		long long N, Y;
		cin >> N >> Y;
		long left = Y/1000 - N;
		bool flag = true;

		long x_max = left/9 + 1;
		long y_max = left/4 + 1;

		for (int i = 0; i < x_max; i++) {
				for (int j = 0; j < y_max; j++) {
						if ( left == 9 * i + 4 * j && N - (i + j) >= 0) {
								cout << i << " " << j << " " << N - (i + j) << endl;
								flag = false;
								break;
						}
				}
				if (flag == false) {
						break;
				}
		}
		if (flag) {
				cout << -1 << " " << -1 << " " << -1 << endl;
		}

}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var abx = ReadLongArray();
            var bDiv = abx[1] / abx[2];
            long aDiv = -1;
            if (abx[0] != 0)
            {
                aDiv = (abx[0] - 1) / abx[2];
            }

            Console.WriteLine(bDiv - aDiv);

        }


        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
#include<stdio.h>

int a[1000005];
int main()
{
    long long n,m,i;
    scanf("%lld",&n);
    m=0;
    a[m]=n;
    int flag=1;
    while(1)
    {
       
        m++;
        if(n%2==0){
            n=n/2;
            a[m]=n;
        }
        else{
            n=3*n+1;
            a[m]=n;
        }
       for(i=0;i<m;i++)
        if(n==a[i])flag=0;
       if(flag==0)break;
    }

    printf("%lld",m+1);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var A = Scanner.Scan<int>();
            Console.WriteLine(A + A * A + A * A * A);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28264
#include<stdio.h>
int main()
{
	int m,f,r,t;
	for(;;)
	{
		scanf("%d%d%d",&m,&f,&r);
		t=m+f;
		if(m+f+r==-3)return 0;
		if(m==-1||f==-1)puts("F");
		else if(t>=80)puts("A");
		else if(t>=65)puts("B");
		else if(t>=50||r>=50)puts("C");
		else if(t>=30)puts("D");
		else puts("F");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    cout << s[0][0] << s[1][0] << s[2][0] << endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;
vector<int> node[2005];
int main(){
  int n,k;
  cin>>n>>k;
  if(k%2==0){
    for(int i=0;i<n-1;i++){
      int a,b;
      cin>>a>>b;
      node[a].push_back(b);
      node[b].push_back(a);
    }
    int ans=1e5;
    for(int i=1;i<=n;i++){
      int kans=0;
      queue<P> que;
      que.push(P(i,0));
      bool used[2005];
      for(int j=0;j<2005;j++) used[j]=false;
      used[i]=true;
      while(!que.empty()){
        P p=que.front();
        que.pop();
        int pos=p.first,dis=p.second;
        if(dis>k/2) kans++;
        for(int j=0;j<node[pos].size();j++){
          int to=node[pos][j];
          if(!used[to]){
            used[to]=true;
            que.push(P(to,dis+1));
          }
        }
      }
      ans=min(ans,kans);
    }
    cout<<ans<<endl;
  }
  else{
    vector<P> v;
    for(int i=0;i<n-1;i++){
      int a,b;
      cin>>a>>b;
      node[a].push_back(b);
      node[b].push_back(a);
      v.push_back(P(a,b));
    }
    int ans=1e5;
    for(int i=0;i<n-1;i++){
      int kans=0;
      int dist[2005]={0};
      queue<P> que;
      que.push(P(v[i].first,0));
      que.push(P(v[i].second,0));
      bool used[2005];
      for(int j=0;j<2005;j++) used[j]=false;
      used[v[i].first]=true;
      used[v[i].second]=true;
      while(!que.empty()){
        P p=que.front();
        que.pop();
        int pos=p.first,dis=p.second;
        if(dis>(k-1)/2) kans++;
        for(int j=0;j<node[pos].size();j++){
          int to=node[pos][j];
          if(!used[to]){
            used[to]=true;
            que.push(P(to,dis+1));
          }
        }
      }
      ans=min(ans,kans);
    }
    cout<<ans<<endl;
  }
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 4; ++i) {
    putchar(s[i]);
  }
  putchar(' ');
  for (int j = 4; j < 12; ++j) {
    putchar(s[j]);
  }
  putchar('\n');
  return 0;
}

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

int main()
{
  int q;scanf("%d",&q);
  for(int Q=0;Q<q;Q++)
  {
  string X,Y;cin>>X>>Y;
  vector<vector<int>> dp(X.size()+1,vector<int>(Y.size()+1,0));
  for(int i=0;i<(int)X.size();i++)for(int j=0;j<(int)Y.size();j++)
  {
    if(X[i]==Y[j])dp[i+1][j+1]=dp[i][j]+1;//max({dp[i][j]+1,dp[i][j+1],dp[i+1][j]});
    else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
  }
  printf("%d\n",dp[X.size()][Y.size()]);
  }
}


Measured memory_bytes: 6888
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

const int M = 114514;
string l;
ll dp[M+10][2];

void print(int n) {
	rep(j,2) {
		rep(i,n) {
			cout << dp[i][j] << " ";
		}
		cout<<endl;
	}
}

int main(int argc, char const *argv[]) {
	cin>>l;
	l='0'+l;
	int n=l.length();
	memset(dp,0,sizeof(dp));
	dp[0][0]=1ll;

	rep(i,n) {
		// 1->1
		if (dp[i][1]!=0) {
			dp[i+1][1]+=(dp[i][1]*3);
			dp[i+1][1]%=MOD;
			// cout << "1->1" << endl;
			// cout << dp[i+1][1] << endl;
		}
		// 0->0
		if (dp[i][0]!=0) {
			if (l[i+1]=='1') dp[i+1][0]+=(dp[i][0]*2);
			else dp[i+1][0]+=dp[i][0];
			dp[i+1][0]%=MOD;
			// cout << "0->0" << endl;
			// cout << dp[i+1][0] << endl;
		}
		// 0->1
		if (l[i+1]=='1') {
			if (dp[i][0]!=0) {
				dp[i+1][1]+=dp[i][0];
				dp[i+1][1]%=MOD;
				// cout << "0->1" << endl;
				// cout << dp[i+1][1] << endl;
			}
		}
	}

	// print(n);

	cout << (dp[n-1][0]+dp[n-1][1])%MOD << endl;
	return 0;
}

Measured memory_bytes: 2300
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
def main():
    N = I()
    A = LI()
    B = LI()
    A_cnt = Counter(A)
    B_cnt = Counter(B)
    for key in B_cnt.keys():
        x = A_cnt[key]
        if B_cnt[key] > N - x:
            print('No')
            exit()
    print('Yes')
    A_m = A_cnt.most_common()
    A_ = []
    for a_m in A_m:
        A_ += [a_m[0]] * a_m[1]
    B_m = deque(B_cnt.most_common())
    ANS = []
    for i in range(N):
        x = B_m[0][0]
        if A_[i] != x:
            ANS.append([A_[i], x])
            B_cnt[x] -= 1
            if B_cnt[x] == 0:
                B_m.popleft()
        elif A_[i] == x:
            if len(B_m) != 1:
                B_m.popleft()
                B_m.append((x, B_cnt[x]))
                y = B_m[0][0]
                ANS.append([x, y])
                B_cnt[y] -= 1
                if B_cnt[y] == 0:
                    B_m.popleft()
            else:
                for ans in ANS:
                    if ans[0] != x and ans[1] != x:
                        ANS.append([x, ans[1]])
                        ans[1] = x
                        break

    ANS.sort(key=lambda tup: tup[0])
    ANS_ = []
    for ans in ANS:
        ANS_.append(ans[1])
    print(' '.join(map(str, ANS_)))

if __name__ == "__main__":
    main()



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

int main(int argc, char const *argv[])
{
	int r, c, n; cin >> r >> c >> n;
	vector<int> x1(n), y1(n), x2(n), y2(n); {
		rep(i, n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
	}

	vector<tuple<int, int, int>> v1, v2; {
		rep(i, n) {
			if (((x1[i] == 0 || x1[i] == r) || (y1[i] == 0 || y1[i] == c)) && 
				((x2[i] == 0 || x2[i] == r) || (y2[i] == 0 || y2[i] == c))) {
				// printf("ok %d %d %d %d\n", x1[i], y1[i], x2[i], y2[i]);
				if (x1[i] == 0 || y1[i] == c) v1.push_back(make_tuple(x1[i], y1[i], i));
				else v2.push_back(make_tuple(x1[i], y1[i], i));
				if (x2[i] == 0 || y2[i] == c) v1.push_back(make_tuple(x2[i], y2[i], i));
				else v2.push_back(make_tuple(x2[i], y2[i], i));
			}
		}
	}

/*
	for(auto u : v1) {
		int x, y, i; tie(x, y, i) = u;
		printf("%d %d %d   ", x, y, i);
	}
	printf("\n");

	for(auto u : v2) {
		int x, y, i; tie(x, y, i) = u;
		printf("%d %d %d    ", x, y, i);
	}
	printf("\n");
*/
	
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	reverse(v2.begin(), v2.end());

	vector<int> v; {
		for (auto u : v1) v.push_back(get<2>(u));
		for (auto u : v2) v.push_back(get<2>(u));
	}
	
	/*
	for (auto u : v) printf("%d ", u);
	printf("\n");
	*/

	stack<int> sp;
	set<int> st;
	bool f = true;
	for (auto u : v) {
		if (st.count(u)) {
			if (sp.empty()) f = false;
			else if (sp.top() == u) sp.pop();
			else f = false;
		} else {
			sp.push(u);
			st.insert(u);
		}
		if (!f) break;
	}

	if (f) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 9704
class Test
  def initialize(m, books)
    @m, @books = m, books
  end 

  def main
    l, r = 0, [1500000, @books.reduce { |v, x| v += x }].min

    while r - l > 1 do
      m = (r + l) / 2 
      if check(m)
        r = m 
      else
        l = m 
      end 
    end 
    r   
  end 

  def check(v)
    idx = 0 
    (1..@m).each do |x| 
      vv = v 
      while vv > 0 do
        vv -= @books[idx]
        next if vv < 0 
        return true if idx == @books.count - 1 
        idx += 1
      end 
    end 
    return false
  end 
end

while true do
  m, s = STDIN.gets.split(' ').map { |x| x.to_i}

  break if [m, s] == [0, 0]

  books = []
  (1..s).each do |x| 
    books.push STDIN.gets.chomp.to_i
  end 

  puts Test.new(m, books).main
end

Measured memory_bytes: 8716
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()
A=LI()
l=A[0]
num=[0]*(10**6+1)
for i in range(1,n):
    num[A[i]]+=1
    l=gcd(l,A[i])



if l!=1:
    print("not coprime")
    exit()


for j in range(2,10**6):
    ret=0
    for k in range(j,10**6+1,j):
        ret+=num[k]
    if ret>1:
        print("setwise coprime")
        exit()

print("pairwise coprime")








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

int main()
{
  int a,b;
  cin >> a >>b;
  int m=max(a,b);
  int ans,sum;
  sum=0;
  for(int i=0;i<m;i++)
    sum=sum+pow(10,i);
  cout << sum*(a+b-m) << endl;
  return 0;
}

Measured memory_bytes: 256
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
def ans():
    if m1==m2:
        print(0)
        return
    m=m1+1 if m1!=12 else 1
    if m2==m:
        print(1)
        return
    print(0)
ans()

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

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

fn naive(k: usize, n: usize) {
    let mut cnts = vec![0 as usize; n + 1];
    cnts[0] = 1;
    for i in 0..n {
        cnts[i + 1] = cnts[i] * k + 1;
        // println!("{}", cnts[i + 1]);
    }
    let mut rest = cnts[n] / 2;
    let mut ans = vec![];
    let mut pos = n - 1;
    while rest > 0 {
        // println!("{} {} {}", rest, pos, cnts[pos]);
        rest -= 1;
        let skip = rest / cnts[pos];
        ans.push(skip);
        rest -= cnts[pos] * skip;
        if pos == 0 {
            break;
        }
        pos -= 1;
    }
    for i in 0..ans.len() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", ans[i] + 1);
    }
    println!("");
}

fn minus(seq: &mut Vec<usize>, k: usize, n: usize) {
    for i in (0..n).rev() {
        if seq[i] == 0 {
            continue;
        }
        seq[i] -= 1;
        if seq[i] == 0 {
            return;
        }
        for j in i + 1..n {
            seq[j] = k;
        }
        break;
    }
}
fn solve(k: usize, n: usize) {
    let mut ans = vec![];
    if k % 2 == 0 {
        ans.push(k / 2);
        for _i in 0..n - 1 {
            ans.push(k);
        }
    } else {
        ans.push(k / 2 + 1);
        for _i in 0..n - 1 {
            ans.push(k / 2 + 1);
        }
        let offset = n / 2;
        for _i in 0..offset {
            minus(&mut ans, k, n);
        }
    }
    for i in 0..ans.len() {
        if ans[i] == 0 {
            break;
        }
        if i != 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!("");
}

fn main() {
    let k: usize = read();
    let n: usize = read();
    if k == 1 {
        naive(k, n)
    } else {
        solve(k, n);
    }
}


Measured memory_bytes: 11512
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  solve
  def solve: Unit = {
    val n = readLine.trim.toInt
    if (n == 0) return
    val words = List.tabulate(n){_ ⇒ readLine.trim}
    println(findTanka(words))
    solve
  }
  def findTanka(words: List[String]): Int= {
    val tankaNumber: List[Int] = List(5, 7, 5, 7, 7)
    def canMakeStraight(words: List[String], rest: List[Int] = tankaNumber): Boolean = {
      (words, rest) match {
        case (_, Nil) ⇒ true
        case (h::t, f::l) if h.length < f ⇒ canMakeStraight(t, f - h.length::l)
        case (h::t, f::l) if h.length == f ⇒ canMakeStraight(t, l)
        case _ ⇒ false
      }
    }
    def sub(words: List[String], index: Int = 1): Int = {
      if (canMakeStraight(words, tankaNumber)) index
      else sub(words.tail, index + 1)
    }
    sub(words)
  }

  @inline
  def lowerBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  @inline
  def upperBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

ll mpow(ll a,ll b){
    ll res=1;
    a%=mod;
    while(b){
    	if(b%2) res=res*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return res;
}

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

void solve(){
	//code
	string s,t;
	cin>>s>>t;
	cout<<t<<s;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,d;  cin>>n>>d;
    ll arr[n][d];
    ll count=0;
    rep(i,0,n)
    {
        rep(j,0,d)  cin>>arr[i][j];
    }
    rep(i,0,n)
    {
        rep(j,i+1,n)
        {
            ll ans=0;
            rep(k,0,d) ans+=(arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
            ll temp=sqrt(ans);
            if(temp*temp==ans)  count++;
        }
    }cout<<count;
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}

Measured memory_bytes: 3840
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

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



int main()
{
	string S;
	int K;
	set<string>M;
	cin>>S>>K;

	for(int i=0;i<S.size();i++)
	{
		for(int j=1;j<=5&&(i+j)<=S.length();j++)
		{
			string ss(S,i,j);
			M.insert(ss);
		}
	}
	int i=1;
	auto it=M.begin();
	for(;i<K;i++,it++);
	cout<<*it<<endl;
}

Measured memory_bytes: 1664
N = int(input())
S = str(input())
wnum = 0
for i in range(N):
  if S[i] == "W":
    wnum += 1
right = 0
Flag = False
wright = 0
for i in range(N):
  #print(i,Flag,S[-1-i])
  if S[-1-i] == "R" and not Flag:
    right += 1
  elif S[-1-i] == "W":
      wright += 1
      Flag = True
  else:
    break
ans = 0
for i in range(wnum):
  if S[-1-i] != "W":
    ans += 1
print(ans)

Measured memory_bytes: 9500
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cassert>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e5+1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define FAILNO {cout << "NO\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}

int N;
int A[MAXN];
int ans;

int main() {
#ifdef OJ
	freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
#endif

	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A,A+N);

	int a = A[N/2-1];
	int b = A[N/2];

	cout << b-a << endl;;

	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int h, w, n, in, inn, innn;
	cin >> w >> h >> n;
	vector<vector<bool>> vv(h, vector<bool>(w, true));
	rep(i, n) {
		cin >> in >> inn >> innn;
		if (innn == 1) {
			rep(i, in) {
				rep(j, h) {
					vv[j][i] = false;
				}
			}
		}
		if (innn == 2) {
			range(i, in ,w) {
				rep(j, h) {
					vv[j][i] = false;
				}
			}
		}
		if (innn == 3) {
			rep(i, inn) {
				rep(j, w) {
					vv[i][j] = false;
				}
			}
		}
		if (innn == 4) {
			range(i, inn, h) {
				rep(j, w) {
					vv[i][j] = false;
				}
			}
		}
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			if (vv[i][j])ans++;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const llong MOD = 1000000007;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

vector<vector<llong>> MEMO;

llong COMB(llong A, llong B) {
	if (B > A - B) return COMB(A, A - B);

	if (A == B || B == 0) return 1;
	else {
	

		return COMB(A - 1, B - 1) + COMB(A - 1, B);
	}
}

int N;
llong A[100010];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	sort(A, A + N, greater<llong>());
	llong ANS = A[1];

	for (int i = 1; i < N; i++) {
		if (abs(ANS * 2 - A[0]) > abs(2*A[i] - A[0])) ANS = A[i];
	}

	cout << A[0] << " " << ANS;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main(){
  double L;
  cin >> L;
  double a = L / (double)3;
  double ans = a * a * a;
  prints(ans);
  return 0;
}


Measured memory_bytes: 256
//test


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int n,m,a[N],h[N];
set<int>ans;
void check(int p)
{
    for(int i=0; i<p-1; i++)h[i]=0;
    for(int i=0,x; i<=n; i++)x=i%(p-1),h[x]=(h[x]+a[i])%p;
    for(int i=0; i<p-1; i++)if(h[i])return;
    ans.insert(p);
}
int main()
{
    scanf("%d",&n);
    for(int i=n; i>=0; i--)scanf("%d",&a[i]),m=__gcd(m,abs(a[i]));
    for(int i=2; i*i<=m; i++)
        if(m%i==0)
        {
            ans.insert(i);
            while(m%i==0)m/=i;
        }
    if(m!=1)ans.insert(m);
    for(int i=2; i<=n; i++)
        if(a[0]%i==0)
        {
            int flag=1;
            for(int j=2; j*j<=i; j++)if(i%j==0)
                {
                    flag=0;
                    break;
                }
            if(flag)check(i);
        }
    for(auto x:ans)printf("%d\n",x);
}

Measured memory_bytes: 384
#include<stdio.h>

int b[11][11];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				scanf("%d",&b[i][j]);
		
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				b[i][a]+=b[i][j];
			}
		}
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				b[a][i]+=b[j][i];
		
		for(int i=0;i<a;i++)
			b[a][a]+=b[i][a];
		
		for(int i=0;i<a+1;i++,printf("\n"))
			for(int j=0;j<a+1;j++)
				printf("%5d",b[i][j]);
		for(int i=0;i<a+1;i++)
			for(int j=0;j<a+1;j++)
				b[i][j]=0;
	}
}

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

int main(){

    int N, T;
    int cost, time;
    int ans = 1e8;

    cin >> N >> T;
    for(int i = 0; i < N; i++){
        cin >> cost >> time;
        if(T >= time && ans > cost) ans = cost;
    }
    if(ans == 1e8) cout << "TLE" << endl;
    else cout << ans << endl;

    return 0;
}

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

namespace AABC
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int len = int.Parse(Console.ReadLine());
            string astr = "";

            for (int i = 0; i < s.Length; i++)
            {
                if(i % len == 0)
                {
                    astr = astr + s.Substring(i, 1);
                }
            }
            Console.WriteLine(astr);
        }
    }
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var X = str[0];
            var Y = str[1];
            var Z = str[2];
            var K = str[3];

            var A = IO.GetLongList().OrderByDescending(a => a).ToArray();
            var B = IO.GetLongList().OrderByDescending(a => a).ToArray();
            var C = IO.GetLongList().OrderByDescending(a => a).ToArray();

            List<long> AB = new List<long>();
            for (int i = 0; i < X; i++)
            {
                for (int j = 0; j < Y; j++)
                {
                    AB.Add(A[i] + B[j]);
                }
            }

            AB.Sort();
            AB.Reverse();
            List<long> ABC = new List<long>();
            for (int i = 0; i < Math.Min(AB.Count,K); i++)
            {
                for (int j = 0; j < Z; j++)
                {
                    ABC.Add(AB[i] + C[j]);
                }
            }
            ABC.Sort();
            ABC.Reverse();
            for (int i = 0; i < K; i++)
            {
                Console.WriteLine(ABC[i]);
            }

            //Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 63644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;
  REP(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>

using namespace std;

typedef long long li;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

double eps = 1e-5;
const int INF = 1e9 + 7;


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

	int n;
	cin >> n;

	vector<int> a(n);
	map<int, int> m;
	forn(i, n) {
		cin >> a[i];
		m[a[i]]++;
	}

	li ans = 0;
	for (auto it : m) {
		if (it.second >= it.first)
			ans += it.second - it.first;
		else
			ans += it.second;
	}

	cout << ans << endl;
}


Measured memory_bytes: 5120
// AOJ 416 Stop Watch without Tick Mark
// 2019.12.7

#include <stdio.h>

int main()
{
	int a, t, r;

	scanf("%d%d%d", &a, &t, &r);
	printf("%.6lf\n", (double)r/a*t);
	return 0;
}




Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=200010;

ll power(ll x,ll n)
{
    if(n==0){return 1;}
    if(n==1){return x;}
    if(n%2==0){
        return power((x*x)%M,n/2);
    }
    if(n%2==1){
        return (power((x*x)%M,n/2)*x)%M;
    }
}

ll fac[N];
ll n;
vector<ll> adj[N];
ll size[N];
ll dp[N];
ll ans[N];

void dfs1(ll v,ll p)
{
    size[v]=0;
    dp[v]=1;
    ll ch=1;
    for(auto u:adj[v])
    {
        if(u==p){continue;}
        dfs1(u,v);
        size[v]+=size[u];
        dp[v]=(dp[v]*dp[u])%M;
        ch=(ch*fac[size[u]])%M;
    }
    ch=(fac[size[v]]*power(ch,M-2))%M;
    dp[v]=(dp[v]*ch)%M;
    ++size[v];
}

void dfs(ll v,ll p)
{
    ans[v]=dp[v];
    for(auto u:adj[v])
    {
        if(u==p){continue;}

        dp[v]=(dp[v]*power(dp[u],M-2))%M;
        dp[v]=(dp[v]*fac[size[u]])%M;
        dp[v]=(dp[v]*power(fac[size[v]-1],M-2))%M;
        size[v]-=size[u];
        dp[v]=(dp[v]*fac[size[v]-1])%M;
        dp[u]=(dp[u]*power(fac[size[u]-1],M-2))%M;
        size[u]+=size[v];
        dp[u]=(dp[u]*fac[size[u]-1])%M;
        dp[u]=(dp[u]*dp[v])%M;
        dp[u]=(dp[u]*power(fac[size[v]],M-2))%M;

        dfs(u,v);

        swap(u,v);
        dp[v]=(dp[v]*power(dp[u],M-2))%M;
        dp[v]=(dp[v]*fac[size[u]])%M;
        dp[v]=(dp[v]*power(fac[size[v]-1],M-2))%M;
        size[v]-=size[u];
        dp[v]=(dp[v]*fac[size[v]-1])%M;
        dp[u]=(dp[u]*power(fac[size[u]-1],M-2))%M;
        size[u]+=size[v];
        dp[u]=(dp[u]*fac[size[u]-1])%M;
        dp[u]=(dp[u]*dp[v])%M;
        dp[u]=(dp[u]*power(fac[size[v]],M-2))%M;
        swap(u,v);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    fac[0]=1;
    for(ll i=1;i<N;++i){
        fac[i]=(i*fac[i-1])%M;
    }

    cin>>n;
    for(ll i=0;i<n-1;++i){
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    dfs1(1,1);

    dfs(1,1);

    for(ll i=1;i<=n;++i){
        cout<<ans[i]<<endl;
    }

    return (0);
}


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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int n, p;
VI as;

int check(int c) {
	rep (i, as.size()) {
		if (as[i] == c) return i;
	}
	return -1;
}

int main(void) {
	while (1) {
		as.clear();
		cin >> n >> p;
		if (n == 0 && p == 0) break;
		as.resize(n);
		int ans;
		int c = p;
		rep (i, 1000010) {
			if ((ans = check(c)) != -1) {
				break;
			}
			if (p > 0) {
				as[i % n]++;
				p--;
			} else {
				p = as[i % n];
				as[i % n] = 0;
			}
		}
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 3076
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner) + 1
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	aa[n-1]--
	imos := make([]int64, n+1)
	imos[0] = 1
	imos[n] = -1

	cur := 0
	var ans, used int64
	ans = int64(n)
	for i := 0; i < n; i++ {
		if aa[i] == 0 {
			continue
		}

		for aa[i] > 0 {
			if cur >= i || imos[cur] == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			if imos[cur]-used < aa[i] {
				ans += int64(i-cur) * (imos[cur] - used)
				imos[cur+1] += imos[cur]
				update(imos[cur]-used, cur+1, i, imos)
				aa[i] -= imos[cur] - used
				imos[cur] = 0
				cur++
				used = 0
				continue
			}
			used += aa[i]
			update(aa[i], cur+1, i, imos)
			ans += int64(i-cur) * aa[i]
			aa[i] = 0
		}
	}
	fmt.Fprintln(writer, ans)
}
func update(x int64, l, r int, imos []int64) {
	if l >= len(imos) {
		return
	}
	if r >= len(imos) {
		return
	}
	imos[l] += x
	imos[r] -= x
}


Measured memory_bytes: 5128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  auto l = {a + b, a - b, a * b};
  cout << *max_element(l.begin(), l.end()) << endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

int abs(P a, P b){
  int x = a.first-b.first;
  if(x<0) x *= -1;
  int y = a.second-b.second;
  if(y<0) y *= -1;

  return x+y;
}

signed main(){
  int n;
  cin >> n;
  int m;
  cin >> m;
  P a[n], b[m];
  LOOP(i,n){
    int x,y;
    cin >> x >> y;
    a[i] = P(x,y);
  }
  LOOP(i,m){
    int x,y;
    cin >> x >> y;
    b[i] = P(x,y);
  }
  int go[n];
  LOOP(i,n){
    go[i] = 0;
    LOOP(j,m){
      if(
        abs(a[i], b[j]) < abs(a[i], b[go[i]])
      ){
        go[i] = j;
      }
    }
  }
  LOOP(i,n){
    cout << go[i]+1 << endl;
  }
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int xs[300], ys[300], finished[300][300];
const ll MOD = 998244353ll;

template <typename T>
T expt(T a, T n, T mod = std::numeric_limits<T>::max()){
    T res = 1;
    while(n){
        if(n & 1){res = res * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int cross(int x1, int y1, int x2, int y2){
    return x1 * y2 - x2 * y1;
}

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

    std::cin >> N;
    for(int i=0;i<N;++i){
        std::cin >> xs[i] >> ys[i];
    }

    ll score = (expt<ll>(2ll, N, MOD) - N - 1) % MOD;
    if(score < 0){score += MOD;}
    
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            if(finished[i][j]){continue;}

            vector<int> v;
            for(int k=0;k<N;++k){
                if(cross(xs[j] - xs[i], ys[j] - ys[i], xs[k] - xs[i], ys[k] - ys[i]) == 0){
                    v.emplace_back(k);
                }
            }

            int n = v.size();
            for(int k=0;k<n;++k){
                for(int l=k+1;l<n;++l){
                    finished[v[k]][v[l]] = true;
                }
            }

            score = (score - (expt<ll>(2ll, n, MOD) - n - 1)) % MOD;
            if(score < 0){score += MOD;}
        }
    }

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


Measured memory_bytes: 512
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 3e5 + 10; 

int R[N],C[N];
vector<int> G[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int h,w,m;
   cin >> h >> w >> m;
   multiset<int> mx;
   vector<pair<int, int>> A(m);
   for(auto &i : A){
      cin >> i.F >> i.S;
      G[i.F].push_back(i.S);
      R[i.F]++;
      C[i.S]++;
   }
   vector<int> K;
   for(int i = 1; i < N; ++i){
      if(R[i]){
         K.push_back(i);
      }
      if(C[i]){
         mx.insert(C[i]);
      }
   }
   int ans = 0;
   for(int e : K){
      for(int v : G[e]){
         auto k = mx.find(C[v]);
         mx.erase(k);
         C[v]--;
         mx.insert(C[v]);
      }
      if(mx.empty()){
         ans = max(ans,R[e]);
      }else{
         ans = max(ans,R[e]+*mx.rbegin());
      }
      for(int v : G[e]){
         auto k = mx.find(C[v]);
         mx.erase(k);
         C[v]++;
         mx.insert(C[v]);
      }
   }
   cout << ans << '\n';
   return 0;
} 


Measured memory_bytes: 45256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
double p[301][301][301],ev[301][301][301];
int main(){
	int n;cin>>n;
	int x;
	int cnt[4]={0};
	for (int i = 0; i < n; ++i)
	{
		cin>>x;
		cnt[x]++;
	}
	p[cnt[1]][cnt[2]][cnt[3]] = 1;
	for (int c =n; c>=0; c--)
	{
		for (int b = n; b>=0; b--)
		{
			for (int a = n; a>=0; a--)
			{
				if(!a && !b && !c)continue;
				if(a+b+c>n)continue;
				double p_w=(double)(n-(a+b+c))/n;
				double e_w=(double)1/(1-p_w);
				
				ev[a][b][c]+=e_w*p[a][b][c];
				
				
				if(a!=0)
				{
					double p_go=(double)a/(a+b+c);
					p[a-1][b][c]+=p[a][b][c]*p_go;
					ev[a-1][b][c]+=ev[a][b][c]*p_go;
				}
				if(b!=0)
				{
					double p_go=(double)b/(a+b+c);
					p[a+1][b-1][c]+=p[a][b][c]*p_go;
					ev[a+1][b-1][c]+=ev[a][b][c]*p_go;
				}
				if(c!=0)
				{
					double p_go=(double)c/(a+b+c);
					p[a][b+1][c-1]+=p[a][b][c]*p_go;
					ev[a][b+1][c-1]+=ev[a][b][c]*p_go;
				}
			}
		}
	}
	cout<<fixed<<setprecision(10)<<ev[0][0][0];
	return 0;
}


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

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

   if(K <= A) {
      cout << 1 * K << endl;
      return 0;
   }
   else if(K > A && K <= B) {
      cout << A * 1 << endl;
      return 0;
   }
   else {
      cout << A * 1 - (K - A - B) << endl;
      return 0;
   }
}

Measured memory_bytes: 3624
def check(s_di):
  for di in range(s_di,N):
    if D[di] == t:
      return di+1
  return None

N = int(input())
D = sorted(list(map(int,input().split())))
M = int(input())
T = sorted(list(map(int,input().split())))
s_di = 0
for t in T:
  res = check(s_di)
  if res is None:
    print('NO')
    exit()
  else:
    s_di = res
print('YES')

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

int main() {
  int n, a, b, c = 0;
  cin >> n;
  vector<int> p(n), q(n), pm;
  for(int i = 0; i < n; i++)
    pm.push_back(i + 1);
  for(int i = 0; i < n; i++)
    cin >> p.at(i);
  for(int i = 0; i < n; i++)
    cin >> q.at(i);
  do {
    if(pm == p)
      a = c;
    if(pm == q)
      b = c;
    c++;
  } while(next_permutation(pm.begin(), pm.end()));
  cout << abs(a - b) << endl;
}

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

int main()
{
  int N;
  cin >> N;
  
  if(N % 10 == 7)
  {
    cout << "Yes" << endl;
    return 0;
  }
  N /= 10;
  if(N % 10 == 7)
  {
    cout << "Yes" << endl;
    return 0;
  }
  if(N / 10 == 7)
  {
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3568
# coding: utf-8
# Your code here!
import sys
a = list(map(int, input().split()))

def recurciv(a0,a1,x,c):
    c+=1
    x=a0*x-a1
    print(x)
    if c==10:
        sys.exit()
    else:
        recurciv(a0,a1,x,c)

"""
x2001=a[0]*a[2]-a[1]
print(x2001)
x2002=a[0]*z2001-a[1]
"""
recurciv(a[0],a[1],a[2],0)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Reflection.Metadata.Ecma335;

namespace ABC165_a
{
    class Program
    {
        static void Main(string[] args)
        {
            //整数入力
            long k = long.Parse(Console.ReadLine());

            //整数配列入力
            long[] vals = Console.ReadLine().Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            long a = vals[0];
            long b = vals[1];

            long k_max = b / k * k;
                        
            if (k_max >= a){
                Console.WriteLine("OK");
            }   else {
                Console.WriteLine("NG");
            }
        }
    }
}


Measured memory_bytes: 28016
//Mix Juice
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int sum = 0;
    for (int i = 0; i < K; i++) {
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

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

int main()
{
    long long A, B;
    char op;
    cin >> A >> op >> B;
    long long ans = 0LL;
    if (op == '+')
        ans = A + B;
    else
        ans = A - B;
    cout << ans << endl;
    return 0;
}

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

int main(void){
    bool b[1200], s[1200];
    string moji;
    char c[1200];
    
        getline(cin,moji);    
    for(int i = 0; i < moji.size(); i++){
        s[i] = islower(moji[i]);
        b[i] = isupper(moji[i]);
    }
    
    for(int i = 0; i < moji.size(); i++){
        if(s[i] == true) c[i] = toupper(moji[i]);
        else if(b[i] == true) c[i] = tolower(moji[i]);
        else c[i] = moji[i];
    }
    
    for(int i = 0; i < moji.size(); i++){
        cout << c[i];
    }
    cout << endl;
    
    
    return 0;
}


Measured memory_bytes: 3132