akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            // writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n = sc.read();
    let mut dic = HashSet::new();
    for _ in 0..n {
        let com: String = sc.read();
        let s: String = sc.read();
        match com.as_str() {
            "insert" => {
                dic.insert(s);
            },
            _ => {
                if dic.contains(&s) {
                    println!("yes");
                } else {
                    println!("no");
                }
            },
        }
    }
}



Measured memory_bytes: 35532
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int n,m,a[1000005],sum = 0;

int main(){
    cin>>n>>m;
    for(int i = 0;i < m;i++){
        cin>>a[i];
        sum += a[i];
    }
    if(n-sum < 0) cout<<"-1"<<endl;
    else cout<<n-sum<<endl;
}


Measured memory_bytes: 3236
#include <iostream>
using namespace std;
int main(void){
    int N, A, c, ans=1000000000;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A;
        c=0;
        while(A>0&&A%2==0){
            A/=2;
            c++;
        }
        if(ans>c){
            ans=c;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val a = Array.fill[Int](N)(sc.nextInt())
    val b = Array.fill[Int](N)(sc.nextInt())
    val b1 = Array.ofDim[Int](N)

    def modArray(src: Array[Int], dist: Array[Int], m: Int)= {
      src.indices foreach { i =>
        dist(i) = src(i) % m
      }
    }

    var ans = 0
    (0 to 28) foreach { k =>
      val T = 1 << k
      modArray(b, b1, 2 * T)
      Sorting.quickSort(b1)
      var sum: Long = 0
      a.indices foreach { i =>
        val a1 = a(i) % (2 * T)
        // lowerBoundは b < x を満たすbの数
        val lb1 = lowerBound(b1, T - a1)
        val lb2 = lowerBound(b1, 2 * T - a1)
        val lb3 = lowerBound(b1, 3 * T - a1)
        val lb4 = N
        sum += lb2 - lb1 + lb4 - lb3
      }

      if (sum % 2 == 1) ans += T
    }

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  def lowerBound(a: Array[Int], x: Int): Int = {
    def step(l: Int, h: Int): Int = {
      if (h - l == 1) h
      else {
        val mid = l + (h - l) / 2
        if (a(mid) >= x) step(l, mid)
        else step(mid, h)
      }
    }
    step(-1, a.length)
  }
}


Measured memory_bytes: 66884
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0;
  vector<int> a(1,0);
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int d;
    cin >> d;
    if(a.back() < d){
      a.push_back(d);
      ++ans;
    }else{
      while(a.back() > d) a.pop_back();
      if(a.back()!=d){
        a.push_back(d);
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3744
def main():
  s = input()
  end = len(s)
  ind = 0
  ans = 0
  while ind < end:
    j_num = 0
    o_num = 0
    i_num = 0
    while ind < end and s[ind] != "J":
      ind += 1
    while ind < end and s[ind] == "J":
      j_num += 1
      ind += 1
    while ind < end and s[ind] == "O":
      o_num += 1
      ind += 1
    while ind < end and s[ind] == "I":
      i_num += 1
      ind += 1
    if o_num <= i_num and o_num <= j_num:
      ans = max(ans, o_num)
  print(ans)
main()


Measured memory_bytes: 7520
N, Y=[int(i) for i in input().split()]

for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j)==Y:
            print(i, j, N-i-j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    if N % 2 == 0:
        print((N//2)/N)
    else:
        print((N//2 + 1) / N)

if __name__ == '__main__':
    main()

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

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

  string t1, t2;
  t1 = s[0], t2 = s[1];
  int count = 1;
  int i = 1;
  while(true) {
    if (i == s.length() - 1 ) {
      if (t1 == t2) {
        break;
      } else {
        count++;
        break;
      }
    }else if (i > s.length() - 1) {
      break;
    } else if (t1 != t2) {
      t1 = t2;
      i++;
      t2 = s[i];
      count++;
    } else if((t2 += s[i+1]) != t1) {
      t1 = t2;
      i += 2;
      t2 = s[i];
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] c = new int[n];
		long[][] a = new long[n][m];

		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(sc.next());
			for (int j = 0; j < m; j++) {
				a[i][j] = Long.parseLong(sc.next());
			}
		}

		long min = 1000000000;
		char[] sp = new char[n];

		for (int i = 1; i < Math.pow(2, n); i++) {

			sp = String.format("%0" + n + "d", Long.parseLong(Integer.toBinaryString(i))).toCharArray();
			long[] ac = new long[m];

			for (int j = 0; j < n; j++) {
				if (sp[j] == '0')
					continue;
				for (int k = 0; k < m; k++) {
					ac[k] += a[j][k];
				}
			}
			boolean flg = true;
			for (int j = 0; j < m; j++) {
				if (ac[j] < x)
					flg = false;
			}
			if (flg) {
				long ans = 0;
				for (int j = 0; j < n; j++) {
					if (sp[j] == '1')
						ans += c[j];
				}
				min = Math.min(min, ans);
			}
		}
		if (min == 1000000000)
			min = -1;

		System.out.println(min);

	}

}


Measured memory_bytes: 38228
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

int a, b, c;

ll k;

void solve() {                   
	scanf("%d %d %d", &a, &b, &c);
	scanf("%lld", &k);
	printf("%d\n", k % 2 ? b - a : a - b);    
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    n = int(input())
    d = deque()

    for i in range(2 ** n):
        d.append(int(input()))

    while len(d) >= 2:
        x = d.popleft()
        y = d.popleft()
        winner = abs(x - y)
        d.append(winner)

    print(d[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 15860
import java.util.Scanner;
public class Main{
     
    public void solve(){
       Scanner sc = new Scanner(System.in);
       int ninzu,k;
       int ban;
       for(int i=0;i<4;i++){
        ban = sc.nextInt();
        if(ban == 1){
            k = 6000;
        }else if(ban == 2){
            k = 4000;
        }else if(ban == 3){
            k = 3000;
        }else{
            k = 2000;
        }
        ninzu = sc.nextInt();
        int uriage = k*ninzu;
        System.out.println(uriage);
       }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
  i64 N;
  string A;
  cin >> N;
  cin >> A;

  if (N % 2 == 1) {
    cout << "No" << endl;
  } else {
    if (A.substr(0, N / 2) == A.substr(N / 2)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

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

int main() {
	//input
	int64_t N;
	cin >> N;

	//calculation
	if (N == 2) {
		cout << 1 << endl;
		return 0;
	}

	int64_t output = 0;
	for (int64_t A = 1; A < N; A++) {
		if (A * A > N - 1) {
			output += A - 1;
			break;
		}
		output += 2 * ((N - 1) / A - A);
	}


	//output
	cout << output << endl;
	return 0;
}


Measured memory_bytes: 3612
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    if N % 2 == 1:
        print(N//2 + 1)
    else:
        print(N//2)

main()



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

int main() {
  int N, W; cin >> N >> W;
  int w[N], V[N]; for (int i = 0; i < N; i++) cin >> w[i] >> V[i];
  long dp[100001]; dp[0] = 0;
  for (int i = 1; i <= 100000; i++) dp[i] = (1L<<60);
  for (int i = 0; i < N; i++) {
    for (int j = 100000; j >= V[i]; j--) {
      dp[j] = min(dp[j], dp[j-V[i]] + w[i]);
    }
  }
  int max_v = 0;
  for (int i = 0; i <= 100000; i++) if (dp[i] <= W) max_v = i;
  cout << max_v << endl;
}

Measured memory_bytes: 4356
import java.util.*;
import java.awt.geom.*;
public class Main {

	//2332 start
	//2339 TLE
	//2351 TLE
	//2359 RE
	//0003 WA
	//0005 TLE
	//0006 TLE
	//0008 TLE
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int m = sc.nextInt();
			if((n|m|k) == 0) break;
			LinkedList<Integer> stones = new LinkedList<Integer>();
			for(int i = 0; i < n; i++){
				stones.add(i + 1);
			}
			int removeind = m-1;
			stones.remove(removeind);
			int restnum = n-1;
			if(stones.size() == 1){
				System.out.println(stones.get(0));
				continue;
			}
			
			while(true){
				int i = removeind + k - 1;
				removeind = i % restnum;
				restnum--;
				stones.remove(removeind);
				if(restnum == 1){
					System.out.println(stones.get(0));
					break;
				}
			}
		}
		
		
	}

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

Measured memory_bytes: 16000
X = int(input())
#print(X)
n = X
div = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    div.append(i)
    if i != n // i:
      div.append(n//i)
#print(div)

for i in div:
  for a in range(0, 10001): 
    b = a - i
    #print(a, b)
    if a**5 - b**5 == X:
      print(a, b)
      break
  else:
    continue
  break
   
    

Measured memory_bytes: 9444
#include <bits/stdc++.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;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(c, b/a) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int r[2010][2010], c[2010][2010];
char peta[2010][2010];

int main() {
	int h, w, temp, cnt, maxi = 0;
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++)
		scanf("%s", peta[i]);
	memset(r, 0, sizeof r);
	memset(c, 0, sizeof c);
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (peta[i][j] == '.') {
				temp = j;
				while ((peta[i][temp + 1] == '.') && (temp + 1 < w))
					temp++;
				cnt = temp - j + 1;
				for (int k = j; k <= temp; k++)
					r[i][k] = cnt;
				j = temp + 1;
			}
	for (int j = 0; j < w; j++)
		for (int i = 0; i < h; i++)
			if (peta[i][j] == '.') {
				temp = i;
				while ((peta[temp + 1][j] == '.') && (temp + 1 < h))
					temp++;
				cnt = temp - i + 1;
				for (int k = i; k <= temp; k++)
					c[k][j] = cnt;
				i = temp + 1;
			}
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			maxi = max(maxi, r[i][j] + c[i][j]);
	printf("%d\n", maxi - 1);
	return 0;
}

Measured memory_bytes: 35840
n=int(input())
s=list(input())
l=set()
l2=set()
l3=set()
for i in range(n):
  if i>=2:
    l2=list(l2)
    for j in range(len(l2)):
      l3.add(l2[j]+s[i])
    l2=set(l2)
  if i>=1:
    l=list(l)
    for j in range(len(l)):
      l2.add(l[j]+s[i])
    l=set(l)
  l.add(s[i])
print(len(l3))

Measured memory_bytes: 44140
// bear.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
bool cmp(int i, int j)
{
	return i < j;
}
int main()
{
	int n;
	cin >> n;
	int a = 0;
	int c = 0;
	int moznosti = 0;
	if (n == 1)
	{
		cout << 0 << endl;
		return 0;
	}
	if (n == 2)
	{
		cout << 1 << endl;
		return 0;
	}
	int jmoznosti = 0;
	for (int i = 1; i < n; i++)
	{
		moznosti += (n-1) / i;
	}
	cout << moznosti << endl;
	return 0;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
const long long mod = 1000000007;
const int maxn = 222222;
long long a[maxn], b[maxn];
long long tr[2][maxn<<2];
int n;
void modify(int id, int l, int r, int x, int aa, int bb){
    if(l == r){
        if(l == 1 || l == n){
            tr[0][id] = aa;
            tr[1][id] = -(1ll<<60);
        } else {
            tr[0][id] = aa;
            tr[1][id] = bb;
        }
    } else {
        int mid = (l + r)>>1;
        if(x <= mid) modify(id<<1, l, mid, x, aa, bb);
        else modify(id<<1|1, mid + 1, r, x, aa, bb);
        tr[0][id] = max(tr[0][id<<1] + tr[0][id<<1|1], tr[1][id<<1] + tr[1][id<<1|1]);
        tr[1][id] = max(tr[1][id<<1] + tr[0][id<<1|1], tr[0][id<<1] + tr[1][id<<1|1]);
    }
}
int main(){
    int q;
    scanf("%d %d", &n, &q);
    n *= 2;
    for(int e = 1; e <= n; e++){
        scanf("%lld", a + e);
    }
    for(int e = 1; e <= n; e++){
        scanf("%lld", b + e);
    }
    for(int e = 1; e <= n; e++){
        modify(1, 1, n, e, a[e], b[e]);
    }
    while(q--){
        int x, aa, bb;
        scanf("%d %d %d", &x, &aa, &bb);
        modify(1, 1, n, x, aa, bb);
        printf("%lld\n", tr[0][1]);
    }
	return 0;
}


Measured memory_bytes: 18944
#include<stdio.h>
int main(void)
{
	int x=0,i;
	char s[4],t[4];
	scanf("%s %s", s, t);
	for(i=0; i<3; i++)
	{
		if(s[i]==t[i])
		x++;
	}
	printf("%d\n", x);
	
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll n; std::cin >> n;
  ll sub = 1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) sub = i;
  }
  std::cout << sub-1 + n/sub-1 << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

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

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}


void oneCase () {
    vector<int> a(9);
    map<int, int> mp;
    for (int i = 0; i < 9; ++i) {
        cin >> a[i];
        mp[a[i]] = i;
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        if (mp.count(val) > 0) {
            a[mp[val]] = 0;
        }

    }
    auto l = a[0] + a[3] + a[6];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[1] + a[4] + a[7];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[2] + a[5] + a[8];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[0] + a[1] + a[2];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[3] + a[4] + a[5];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[6] + a[7] + a[8];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[0] + a[4] + a[8];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    l = a[2] + a[4] + a[6];
    if (l == 0) {
        cout << "Yes" << "\n";
        return;
    }
    cout << "No" << "\n";
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f;
LL n, m, s, t, h, w,ans,cnt, a[220000], b[220000],dp[220000];
vector<LL>S[220000];
LL sum[220000];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	dp[0] = 1;
	rep(i, n) {
		if (i)if (a[i] != a[i - 1])
		dp[i+1] += sum[a[i]];
		dp[i + 1] += dp[i];
		dp[i + 1] %= MOD;
		if (i)if (a[i] == a[i - 1])continue;
		sum[a[i]] += dp[i];
		sum[a[i]] %= MOD;
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 11904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int aaa=y+z;
		int bbb=x-z;
		int ans=0;
		ans = bbb/aaa;
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 23508
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    string s, p;
    cin >> s >> p;
    s = s + s;
    rep(i, s.size()) {
        // cout << *p.begin() << " " << *(s.begin() + i) << "\n";
        if (equal(p.begin(), p.end(), s.begin() + i)) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

int main(){
  string s,t;
  cin >>s >>t;
  rep(i,s.size()){
    cout <<s[i];
    if(i<t.size()) cout <<t[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int
main()
{
  int N;
  cin >> N;
  int fl[10][10] = {0};
  for (int i = 1; i <= N; ++i) {
    int f,l;
    if (i < 10) {
      f = i;
    }
    else if (i >= 10 && i < 100) {
      f = (int)i / 10;
    }
    else if (i >= 100 && i < 1000) {
      f = (int)i / 100;
    }
    else if (i >= 1000 && i < 10000) {
      f = (int)i / 1000;
    }
    else if (i >= 10000 && i < 100000) {
      f = (int)i / 10000;
    }
    else /* i >= 100000 */ {
      f = (int)i / 100000;
    }
    l = i % 10;
    fl[f][l]++;
  }
  int s = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      s += fl[i][j] * fl[j][i];
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));
    a.push_back(INF);

    vbool c(1e6+1, true);
    int ans = 0;
    rep(i, n) {
        int t = a[i];
        if (!c[t]) continue;
        if (a[i] != a[i+1]) ans++;
        while (t <= 1e6) {
            c[t] = false;
            t += a[i];
        }
    }

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

Measured memory_bytes: 4816
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

from collections import Counter

M = 10**9 + 7
cur = [0] * (1<<N)
cur[0] = 1
for B in A:
    nxt = [0] * (1 << N)
    C = [1 << i for i, v in enumerate(B) if v == 1]
    for s, v in enumerate(cur):
        if v == 0:
            continue
        v %= M
        for b in C:
            if (s & b) != 0:
                continue
            nxt[s | b] += v
    cur = nxt
print(cur[(1<<N) - 1] % M)


Measured memory_bytes: 132988
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int N, K; cin >> N >> K;
	int ans = K;
	rep(i, 1, N)ans *= (K - 1);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 101, M = 1e5 + 1;
int a[N], dp[M];
main() {
	int n, m;
	cin >> n >> m;

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

	for(int i = a[0]; i <= m; i++) {
		for(int j = 0; j < n; j++) {
			if(dp[i]) break;
			if(i - a[j] < 0) continue;
			if(dp[i - a[j]] == 0) dp[i] = 1;
		}
	}

	if(dp[m]) return cout << "First", 0;
	cout << "Second";
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int n2 = sc.nextInt();
        int ans = n1/n2;
        if(n1%n2>0){
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+4;
int n,m,fa[N],blo;
inline int find(int x) {
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void merge(int u,int v) {
	int fu=find(u),fv=find(v);
	if (fu^fv) {
		fa[fu]=fv;
		--blo;
	}
}
int main() {
	scanf("%d%d",&n,&m);
	for (register int i=1;i<=n;++i) {
		fa[i]=i;
	}
	blo=n;
	for (register int i=0;i<m;++i) {
		int u,v;
		scanf("%d%d",&u,&v);
		merge(u,v);
	}
	printf("%d\n",blo-1);
	return 0;
}

Measured memory_bytes: 4208
n, k = map(int, input().split())
a = list(map(int, input().split()))
#dp[i] := 残りi個になったときに先手が勝つかどうか？
dp = [False for i in range(k+1)]
for i in range(n):
    dp[a[i]] = True
#結局dp[k]がTrueなのかFalseなのかを知りたい
for i in range(k+1):
    if dp[i] == False:
        for j in range(n):
            if i + a[j] <= k:
                dp[i+a[j]] = True
if dp[k]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 45040
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		Stack<Integer> stack = new Stack<Integer>();
		Scanner sc = new Scanner(System.in);
		
		String line = sc.nextLine();
		String[] str = line.split(" ");
		
//		for(int i=0;i<str.length;i++)
//		{
//			System.out.println(str[i]);
//		}
		
		for(int i=0;i<str.length;i++)
		{
			if(str[i].equals("+"))
			{
				int ans = stack.pop()+stack.pop();
				stack.push(ans);
			}
			else if(str[i].equals("-"))
			{
				//不能直接减除
				int a = stack.pop();
				int b = stack.pop();
				int ans = b-a;
				//int ans = stack.pop()-stack.pop();
				stack.push(ans);
			}
			else if(str[i].equals("*"))
			{
				int ans = stack.pop()*stack.pop();
				stack.push(ans);
			}
			else
			{
				stack.push(Integer.parseInt(str[i]));
			}
		}
		System.out.println(stack.pop());
		
	}
}



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

int n,m,ans;
map<int,vector<int>> aaa;
vector<int> a,b;
vector<bool> is_searched;

void unti(int i,int x) {
  is_searched[x-1]=true;
  if(x==b[i]) return;
  if(aaa.count(x)) {
    for(int j=0;j<aaa[x].size();j++) {
      if((x!=a[i]||aaa[x][j]!=b[i])&&!(is_searched[aaa[x][j]-1])) unti(i,aaa[x][j]);
      if(is_searched[b[i]-1]) return;
    }
  }
  return;
}

int main() {
  ans=0;
  cin >> n >> m;
  for(int i=0;i<m;i++) {
    int aa,bb;
    cin >> aa >> bb;
    a.push_back(aa);
    b.push_back(bb);
    aaa[aa].push_back(bb);
    aaa[bb].push_back(aa);
  }
  for(int i=0;i<n;i++) is_searched.push_back(false);

  for(int i=0;i<m;i++) {
    for(int j=0;j<n;j++) is_searched[j]=false;
    unti(i,a[i]);
    if(!(is_searched[b[i]-1])) ans++;
  };


  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

void CountingSort(int *,int *,int );

int main(){
  unsigned short *A,*B;

  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<=VMAX;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }


  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8464
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	ll T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2;
	cin >> A1 >> A2;
	cin >> B1 >> B2;
	A1 *= T1;
	B1 *= T1;
	A2 *= T2;
	B2 *= T2;
	if (A1 + A2 == B1 + B2)
		cout << "infinity" << endl;
	else {
		ll ans = 0;
		if (A1 < B1)
		{
			swap(A1, B1);
			swap(A2, B2);
		}
		if (A1 + A2 < B1 + B2) {
			ans = 1;
			ans += ((A1 - B1) / (B1 + B2 - A1 - A2)) * 2;
			if ((A1 - B1) % (B1 + B2 - A1 - A2) == 0)
				ans--;
		}
		cout << ans << endl;
	}
	


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

int main() {
    string s;
    cin >> s;
    bool x = true;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if ((i + 1) % 2 == 1) {
            if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) {
                x = false;
            }
        }
        else {
            if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) {
                x = false;
            }
        }
    }
    dump(x ? "Yes" : "No");
    return 0;
}

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

using namespace std;
int dp[200005],n,m;
vector <int> DAG[200005];
int dfs(int x)
{
    if(dp[x]!=-1)
        return dp[x];
    int retVal=0;
    for(int i=0;i<DAG[x].size();i++)
    {   int child=DAG[x][i];
        retVal=max(retVal,dfs(child)+1);
    }
    dp[x]=retVal;
    return dp[x];
}
int main()
{
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        DAG[x].push_back(y);
    }
    memset(dp,-1,sizeof(dp));
    int longestPath=0;
    for(int i=1; i<=n; i++)
        longestPath=max(dfs(i),longestPath);

    cout << longestPath << endl;

    return 0;
}


Measured memory_bytes: 10880
import sys

N, M = map(int, input().split())
Xs = list(map(int, input().split()))

if N >= M:
    print(0)
    sys.exit()

Xs.sort()
diffs = []
for i in range(M-1):
    diffs.append(Xs[i+1]-Xs[i])
diffs.sort()

print(sum(diffs[:M-N]))


Measured memory_bytes: 13968
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<vector<Pll>> xy(n);
    rep(i,n){
        ll a; cin >> a;
        rep(j,a){
            ll x,y; cin >> x >> y;
            x--;
            xy[i].emplace_back(Pll(x,y));
        }
    }
    ll res = 0;
    rep(i,1LL << n){
        bool ok = true;
        bitset<30> bs(i);
        rep(j,n){
            if(i & (1LL << j)){
                for(auto k : xy[j]){
                    if(bs[k.first] != k.second)ok = false;
                }
            }
            // else{
            //     for(auto k : xy[j]){
            //         if(bs[k.first] == k.second)ok = false;
            //     }
            // }
        }
        ll t = bs.count();
        // debug(i);
        // debug(bs);
        // debug(t);
        if(ok){
            res = max(res, t);
            // debug(bs);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
N,T = map(int,input().split())

ct = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    #tmp = list(map(int,input().split()))
    ct.append(list(tmp))

res = 1001
for c,t in ct:
    if int(t) <= int(T):
        if res > int(c):
            res = int(c)

if res == 1001:
    print('TLE')
else:
    print(res)





Measured memory_bytes: 3060
package main

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

func main() {
	n, r := readInt(), readInt()
	if n >= 10 {
		fmt.Println(r)
	} else {
		fmt.Println(r + 100*(10-n))
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;

char buf[1<<15],*fs,*ft;
inline char getc() { return (ft==fs&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),ft==fs))?0:*fs++; }
template<typename T>inline void read(T &x)
{
    x=0;
    T f=1, ch=getchar();
    while (!isdigit(ch) && ch^'-') ch=getchar();
    if (ch=='-') f=-1, ch=getchar();
    while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
    x*=f;
}

int ver[maxn<<1],Next[maxn<<1],head[maxn],len,deg[maxn];
inline void add(int x,int y)
{
	ver[++len]=y,Next[len]=head[x],head[x]=len;
}

ll A[maxn];
bool flag=1;
inline void dfs(int x,int fa)
{
	ll sum=0,maxpart=0; int o=0;
	for (int i=head[x]; i; i=Next[i])
	{
		int y=ver[i];
		if (y==fa) continue;
		++o;
		dfs(y,x);
		sum+=A[y];
		maxpart=max(maxpart,A[y]);
	}
	if (!o) return ;
	ll a=sum-A[x],b=(A[x]<<1)-sum;
	if (a<0 || b<0 || a>min(sum-maxpart,sum>>1) || (fa==-1 && b)) flag=0;
	A[x]=b;
}

int main()
{
	int n;read(n);
	for (int i=1; i<=n; ++i) read(A[i]);
	for (int i=1,a,b; i<n; ++i) read(a),read(b),add(a,b),add(b,a),++deg[a],++deg[b];
	int root=0;
	for (int i=1; i<=n; ++i)
		if (deg[i]>1) { root=i; break; }
	if (root) dfs(root,-1);
	else flag=(A[1]==A[2]);
	puts(flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 7424
#include <stdio.h>

int main() {
    int n;
    int A[100];
    scanf("%d", &n);
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    int h;
    for(h=0;h<n-1;h++){
        printf("%d ",A[h]);
    }
    printf("%d\n",A[n-1]);
    int k;
    for(k=1;k<n;k++){
        int v=A[k];
        int j=k-1;
        while(j>=0&&A[j]>v){
            
            A[j+1]=A[j];
            j--;
            A[j+1]=v;
        }
        int m;
        for(m=0;m<n-1;m++){
            printf("%d ",A[m]);
           
        }
        printf("%d\n",A[n-1]);
       
        
    }
    return 0;

    

}

Measured memory_bytes: 600
def resolve():
    '''
    code here
    '''
    N, A, B = [int(item) for item in input().split()]

    if A <= B:
        if N >=3:
            res = (N-1)*B + A - ((N-1)*A + B) + 1

        elif N == 2:
            res = 1
        else:
            if A == B:
                res = 1
            else:
                res = 0
    else:
        res = 0

    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
char A[10]; int n, p, a;
void add(int q) {
	if (q == 11 && p <= 10) { a = 1; }
	if (q == 11 && p >= 11) { p += 1; }
	else { p += q; }
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		p = 0; a = 0; for (int j = 0; j < 10; j++)cin >> A[j];
		for (int j = 0; j < 10; j++) {
			if (p <= 16 || (p == 17 && a == 1)) {
				if (A[j] >= '1' && A[j] <= '9')add(A[j] - '0');
				else if (A[j] == 'A')add(11);
				else { add(10); }
				if (p >= 22 && a == 1) { p -= 10; a = 0; }
				if (p >= 22) { cout << "bust" << endl; }
				else if (p == 21 && j == 1)cout << "blackjack" << endl;
				else if (p >= 18 || (p == 17 && a == 0))cout << p << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import fractions
# import math as fractions
mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

g = fractions.gcd(a[0], a[1])
f = a[0]*a[1]//g
ans = a[0]//g+a[1]//g

for i in range(2, n):
    # print(ans, g, f)
    h = fractions.gcd(f, a[i])
    g = a[i] // h
    f = f*a[i]// h
    ans *= g
    ans += f // a[i]
    ans %= mod
print(ans%mod)


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

using namespace std;

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

    int n;
    cin >> n;

    int ans_counter[26];
    for (int i = 0; i < 26; ++i)
    {
        ans_counter[i] = 1e9;
    }

    for (int i = 0; i < n; ++i)
    {
        int counter[26] = {0};
        string S;
        cin >> S;
        for (int j = 0; j < S.size(); ++j)
        {
            ++counter[(int)S[j] - 'a'];
        }

        for (int j = 0; j < 26; ++j)
        {
            ans_counter[j] = min(ans_counter[j], counter[j]);
        }
    }

    string ans = "";
    for (int i = 0; i < 26; ++i)
    {
        for (int j = 0; j < ans_counter[i]; ++j)
        {
            ans += 'a' + i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

C = [0 for _ in A]
C[0] = A[0]
for i in range(1, len(A)):
    C[i] = C[i-1] + A[i]

from collections import Counter

count = Counter(C)

li = list(count.values())

res = 0
for l in li:
    if l == 1:
        pass
    else:
        res += l * (l - 1) / 2
res += count[0]

print(int(res))

Measured memory_bytes: 41540
#include <iostream>
#include <vector>
#include <math.h>

int main()
{
	int N = 0, D = 0, ans = 0;
	double dist = 0, ele = 0, eps = 10e-7;
	std::cin >> N >> D;

	std::vector<int> X(D);
	std::vector<std::vector<int>> P(N);

	for (int i = 0; i < N; i++){
		for (int j = 0; j < D; j++){
			std::cin >> X[j];
		}
		P[i] = X;
	}

	for (int i = 0; i < N - 1; i++){
		for (int j = i + 1; j < N; j++){
			ele = 0;
			for (int k = 0; k < D; k++){
				ele += (P[i][k] - P[j][k]) * (P[i][k] - P[j][k]);
			}
			dist = sqrt(ele);

			if (fabs(dist - ceil(dist)) < eps)
			{
				ans++;
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READAR(A,N);
    ll sum=0;
    FORI(i,0,N)
    {
        sum+=A[i];
    }
    ll cnt=(N*(N+1))/2;
    if(sum%cnt==0)
    {
        ll K=sum/cnt;
        bool ok=true;
        ll tot=0;
        FORI(i,0,N)
        {
            ll d=A[(i+1)%N]-A[i];
            if(K<d || (abs(K-d))%N!=0)
            {
                ok=false;
                break;
            }
            else
            {
                tot+=(K-d)/N;
            }
        }
        if(ok && tot==K)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    else
    {
        cout<<"NO"<<endl;
    }
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 4564