akhauriyash/Code-Regression huggingface dataset:
using System;

 class Program
 {
     static void Main(string[] args)
     {
         double data1,data2,data3;
         String nyuryoku,result;
         nyuryoku = Console.ReadLine();
         string[] data = nyuryoku.Split(' ');
         data1 = Double.Parse(data[0]); 
         data2 = Double.Parse(data[1]);
         data3 = Double.Parse(data[2]);
         result = "No";
         if (data1 < data2)
             if(data2 < data3)
                 result = "Yes";
                  
         Console.WriteLine("{0}",result);
     }
 }



Measured memory_bytes: 17912
use std::io;

fn main() {
    let mut tmp_str = String::new();
    // 標準入力から一行受け取る
    io::stdin().read_line( &mut tmp_str );

    // 標準入力から受け取った文字を数字に変換する
    let linenum: i32 = tmp_str.trim().parse().expect( "expected val is inreger" );

    // 動的配列を宣言
    let mut numv: Vec<i32> = Vec::new();
    for i in 0..linenum {
        // enter区切りで標準入力から数値を受け取り, 動的配列の末尾へpushする
        tmp_str = String::new();
        io::stdin().read_line( &mut tmp_str );
        let tmp_val = tmp_str.trim().parse().expect( "Failed read line from standard input" );
        numv.push( tmp_val );
    }

    let mut max_val = -1000000000;
    let mut min_val = numv[0];
    for i in 1..linenum {
        if max_val < numv[i as usize] - min_val {
            max_val = numv[i as usize] - min_val;
        }

        if min_val > numv[i as usize] {
            min_val = numv[i as usize];
        }
    }
    println!( "{}", max_val );
}



Measured memory_bytes: 5044
import java.util.Scanner;

//private static int min,max,va;
//private static long total;

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int cnt = sc.nextInt();//cnt for loop

    int min,max,va;
    long total;

    va = sc.nextInt();
    min = va;
    max = va;
    total = va;

    for(int i = 0;i<cnt-1;i++){//total loop nuber is cnt minus one va. 
      va = sc.nextInt();
      if(va < min){
        min = va;
      }
      if(va > max){
        max = va;
      }

total = total + va;
    }

System.out.println(min+" "+max+" "+total);
  }

}


Measured memory_bytes: 41400
#include <stdio.h>

int main()
{
	int a,b;
	char c;
	while(1)
	{
	scanf("%d",&a);
	getchar();
	scanf("%c",&c);
	getchar();
	scanf("%d",&b);
	if(c=='?'){
	break;
	}
	if(c=='+'){
	printf("%d\n",a+b);
	}
	if(c=='-'){
	printf("%d\n",a-b);
	}
	if(c=='*'){
	printf("%d\n",a*b);
	}
	if(c=='/'){
	printf("%d\n",a/b);
	}
	}
	return 0;
}

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

int main()
{
	int n,a,sum=0;
	vector<pii>v;
	cin>>n>>a;
	for(int i=1;i<=n;i++)
	{
		sum+=a+i-1;
		v.push_back(make_pair(0,a+i-1));
	}
	for(int i=1;i<=n;i++)
	{
		v[i-1].first=max(sum,sum-v[i-1].second)-min(sum,sum-v[i-1].second);
	}
	sort(v.begin(),v.end());
	cout<<sum-v[0].second<<endl;
	return 0;
}

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

int main() {
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;

  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if ( a + b == c + d) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3668
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  // 初めの上昇と平坦を除去
  while (line.length > 0 && line[0] !== '\\') line.shift();
  // 終わりの下降と平坦を除去
  while (line.length > 0 && line[line.length - 1] !== '/') line.pop();

  let height_list = [0];
  let current_height = 0;
  line.forEach(function(e, i){
      if (e === '\\') current_height -= 1
      else if (e === '/') current_height += 1
      height_list.push(current_height);
  });

  let h, sum = 0;
  let holes = [];
  while (height_list.length > 1) {
    if (h = makeHole(height_list)) {
      sum += h;
      holes.push(h);
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    let area = 0;
    if (list[0] < begin && begin <= list.reduce((a, b) => Math.max(a, b), -200000)) {
      while (!(list.length === 0 || begin <= list[0])) area += begin - list.shift();
    }
    return area;
}



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


Measured memory_bytes: 2036
fn main(){
  let mut sieve: Vec<bool> = vec![true; 999984];
  sieve[0] = false;
  sieve[1] = false;

  for i in 2 .. 1000 {
    if sieve[i] {
      let mut j = i * i;
      while j < 999984 {
        sieve[j] = false;
        j += i;
      }
    }
  }

  let mut pn: Vec<usize> = vec![0; 999984];
  
  for i in 1 .. 999984 {
    if sieve[i] {
      pn[i] = pn[i-1] + 1;
    } else {
      pn[i] = pn[i-1];
    }
  }
  
  loop {
    let n: usize = read();
    
    if n == 0 { break; }

    let mut ans: usize = 0;
    
    for _ in 0 .. n {
      let pm: Vec<usize> = read_vec();
      let p = pm[0];
      let m = pm[1];

      let rmn: usize = if p < m + 1 { 0 } else { p - m - 1 };
      let rmx: usize = if p + m > 999983 { 999983 } else { p + m };

      ans += pn[rmx] - pn[rmn];
    }

    ans -= n;
    
    println!("{}", ans);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 13224
#スペース区切りの整数の入力
N,M = map(int, input().split())

#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))
A_list_sum = sum(A_list)


count = 0
aa = A_list_sum/(4*M)
#print(aa)
for  i in range(len(A_list)):
  #print(i)
  if(A_list[i]>=aa):
    count = count + 1
    #print(count)
    
if(count >= M):
  print("Yes")
else:
  print("No")
#print(A_list_sum)



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

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


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int Partition(int* , int , int ,int);

int main(){
  int A[MAX], num, i, ans;
  scanf("%d", &num);
  for ( i = 0; i < num; i++ ) scanf("%d", &A[i]);
  ans = Partition(A, num, 0, num-1);

  for ( i = 0; i < num; i++ ) {
    if ( i ) printf(" ");
    if ( i == ans ) printf("[");
    printf("%d", A[i]);
    if ( i == ans) printf("]");
  }
  printf("\n");

  return 0;
}


int Partition(int A[], int num, int o, int m){
  int x, i, j, t;
  x = A[m];
  i = o - 1;
  for ( j = o; j < m; j++ ){
    if ( A[j] <= x ){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[m]; A[m] = t;
  return i+1;
}

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

int main() {
  int N,K,ans=0;
  cin>>N>>K;
  rep(i,N){
    int x;
    cin>>x;
    if (x<abs(K-x)) {
      ans+=x*2;
    }
    else{
      ans+=abs(K-x)*2;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M = map( int, input().split())
    E = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map( lambda x:int(x)-1, input().split())
        E[u].append(v)
        E[v].append(u)
    d = deque([0])
    V = [-1]*N
    V[0] = 0
    while d:
        u = d.popleft()
        for v in E[u]:
            if V[v] == -1:
                V[v] = u+1
                d.append(v)
    print("Yes")
    print( "\n".join( map( str, V[1:])))
if __name__ == '__main__':
    main()


Measured memory_bytes: 44660
#include<stdio.h>

int main()
{
    char c[4];
    int i,count=0;
    scanf("%s",c);
    
    for(i=0; i<3; i++) {
    
        if(c[i]=='7') {
        
            printf("Yes");
            count++;
            break;
        }
      
    }
    if(count==0)printf("No");

    return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n,q;
  cin >> n >> q;
  vector <int> res;
  int a[n];
  int sq = sqrt(n);
  int nsq = n/sq+1;
  int lazy[nsq];
  fill(a,a+n,2147483647);
  fill(lazy,lazy+nsq,-1);
  REP(i,q){
    int z;
    cin >> z;
    if(z == 0){
      int s,t,x;
      cin >> s >> t >> x;

      /*if(s == t){
	a[s] = x;
	}*/
      if(t/sq == s/sq){
	if(lazy[t/sq] >= 0){
	  fill_n(a+(t/sq)*sq,sq,lazy[t/sq]);
	  lazy[t/sq] = -1;
	}
	if(t-s+1 == sq){
	  lazy[t/sq] = x;
	}
	else{
	  fill_n(a+s,t-s+1,x);
	}
	//cout << "debug1" <<endl;
      }

      else{
	//cout << "debug3" << endl;
	int f = s,to = t;
	while(to%sq != (sq - 1)){
	  to--;
	}
	while(f%sq != 0){
	  f++;
	}
	if(lazy[t/sq] >= 0){
	  fill_n(a+(t/sq)*sq,sq,lazy[t/sq]);
	}
	if(lazy[s/sq] >= 0){
	  fill_n(a+(s/sq)*sq,sq,lazy[s/sq]);
	}
	fill_n(a+to+1,t-to,x);
	lazy[t/sq] = -1;
	fill_n(a+s,f-s,x);
	lazy[s/sq] = -1;
	f = f/sq;
	to = to/sq;
	if(f <= to){
	  fill_n(lazy+f,to-f+1,x);
	}
	
      }
      /*REP(i,n)
	cout << a[i] << "  ";
	cout << endl;*/
    }
    else{
      int x;
      cin >> x;
      int te = x / sq;
      
      if(lazy[te] < 0){
	//cout << a[x] << endl;
	res.pb(a[x]);
      }
      else{
	fill_n(a+te*sq,sq,lazy[te]);
	lazy[te] = -1;
	//cout << a[x] << endl;
	res.pb(a[x]);

      }
      
    }
    
  }
  for(int i = 0;i < res.size();i++){
    cout << res[i] << endl;
  }
  //cout << res.size() << endl;
  return 0;
}

Measured memory_bytes: 3868
from operator import itemgetter
N = int(input())
A = list(map(int, input().split()))

O = {}
E = {}

for i in range(N//2):
  if A[2*i] in O:
    O[A[2*i]] += 1
  else:
    O[A[2*i]] = 1
  if A[2*i+1] in E:
    E[A[2*i+1]] += 1
  else:
    E[A[2*i+1]] = 1

O = sorted(O.items(), key=itemgetter(1), reverse=True)      
E = sorted(E.items(), key=itemgetter(1), reverse=True)   

if O[0][0] != E[0][0]:
  print(N - O[0][1] - E[0][1])
else:
  print(min(N - O[0][1] - (E[1][1] if len(E) > 1 else 0), N - E[0][1] - (O[1][1] if len(O) > 1 else 0)))


Measured memory_bytes: 17816
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, m, a = 0, s = 0;
  cin >> n >> m;
  v1i v(n);
  rep(i, n){
    cin >> v[i];
    s += v[i];
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  ldouble d = (s+0.0) / 4 / m;
  while(v[a] >= d) ++a;
  if(a > m-1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define inp 200005
#define check exit(0)
#define nl cout<<endl;
#define mod 1000000007 
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }

using namespace std;

// No idea what the hell is going on ):

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

    int arr[n][n];

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

    vector<ll> dp(1<<n,0);
    dp[0]=1;

    for(int mask=0;mask<(1<<n);mask++)
    {
        //trace(mask);
        int taken = __builtin_popcount(mask);
        for(int b=0;b<n;b++)
        {
            if(!arr[b][taken] || (mask & (1<<b))) continue;
            dp[mask|(1<<b)]+=dp[mask];
            dp[mask|(1<<b)]%=mod;
        }
        //deb(dp);
    }
    cout << dp[(1<<n)-1];

    return 0;
}

Measured memory_bytes: 19568
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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

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

	vector<bool> l(10, 1);

	ll K;
	cin >> K;
	repn(i, K) {
		ll d;
		cin >> d;
		l[d] = 0;
	}
	

	ll ans = N;
	while (1 == 1) {
		ll b = 1;
		for (ll i = ans; i > 0; i /= 10) {
			if (l[i % 10] == 0) { b = 0; }
		}

		if (b == 1) { break; }
		ans++;
	}

	cout << ans;
	system("PAUSE");
}

Measured memory_bytes: 504
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 1;
        long a[] = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
            if(a[i]==0){
                ans=0;
                break;
            }
        }
        if(ans==0){
            System.out.println(ans);
        }
        else{
            for(int i = 0; i < n; i++){
                if(1000000000000000000l/ans>=a[i]){
                    ans *= a[i];
                }
                else{
                    ans = -1;
                    break;
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 61496
/*
 _     _    ___  ___  __ __ 
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;

//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		vi v;
		ll a=0;
		rep(i,0,n)
		{
			ll x;
			cin>>x;
			if(i%2==0)
				a+=x;
			else
				a-=x;
			v.pb(x);
		}
		cout<<a<<" ";
		rep(i,0,n-1)
		{
			a=(v[i]-a/2)*2;
			cout<<a<<" ";
		}
	}
	return 0;
}

Measured memory_bytes: 2292
MOD=10**9+7

def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    count=[3 if i==0 else 0 for i in range(N+1)]
    ans=1
    for a in A:
        ans = ans*count[a]%MOD
        if ans==0:
            break
        count[a]-=1
        count[a+1]+=1
    print(ans)

main()

Measured memory_bytes: 14396
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MAX 10000001

static bool gosei[MAX];

void a() {
	for (int i = 2; i <= sqrt(MAX); i++)
		if (gosei[i] == false) {
			for (int j = 2, k = 0; (k = i*j) <= MAX; j++)
				gosei[k] = true;
		}
}

int c(int a) {
	if (a == 2)return 1;
	if (a % 2 == 0)return 0;
	for (int i = 3; i <= sqrt(a); i += 2)
		if (a%i == 0)
			return 0;
	return 1;
}

int main() {
	int b = 0;
	for (int a; cin >> a;) {
		//if (a < MAX) {
		//	if (!gosei[a])b++;
		//}
		//else
		b += c(a);
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

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

		int n = sc.nextInt();

		int[] a = new int[n];
		int[] b = new int[n];

		long ans = 0;

		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		long added = 0;
        for (int i = n - 1; i >= 0; i--) {
            long cur = a[i] + added;
            if (cur % b[i] == 0) {
                continue;
            }
            added += b[i] - (cur % b[i]);
        }
        System.out.println(added);
	}
}


Measured memory_bytes: 69084
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;
#define MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )

void cinv(lls& llVec, ll n) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		llVec.push_back(val);
	}
}


int main()
{
	std::string S;

	cin >> S;

	bool fumiyasui = true;
	for (ll i = 0; i < S.size(); i++) {
		char c = S[i];
		if ((i+1) % 2 == 1) {
			if (c == 'R' || c == 'U' || c == 'D') {}
			else {
				fumiyasui = false;
				goto end;
			}
		}
		else {
			if (c == 'L' || c == 'U' || c == 'D') {}
			else {
				fumiyasui = false;
				goto end;
			}
		}
	}

	end:
	if (fumiyasui) cout << "Yes" << '\n';
	else           cout << "No" << '\n';

	return 0;
}



Measured memory_bytes: 256
while True :
    n = int(input())
    l = []
    if n == 0 :
        break
    s = list(map(int,input().split()))
    ave = sum(s)/n
    for i in range(n):
        l.append((s[i]-ave)**2)
    ans = sum(l)/n
    print(ans**0.5)



Measured memory_bytes: 5676
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;


int main() {
    int n;cin>>n;
    int a[n];for(int i=0;i<=n-1;i++)cin>>a[i];
    sort(a,a+n);
    long long int sum[n];
    for(int i=0;i<=n-1;i++){
        if(i==0)sum[i]=a[i];
        else sum[i]=a[i]+sum[i-1];
    }
    int i;
    for(i=n-2;i>=0;i--){
        if(sum[i]*2<a[i+1])break;
    }
    printf("%d",n-i-1);
    return 0;
}


Measured memory_bytes: 1408
n, t = gets.split.map(&:to_i)
ct = (1..n).map{|_| gets.split.map(&:to_i)}.sort{|a, b| a.last == b.last ? a.first <=> b.first : a.last <=> b.last}
x = ct.select{|v| v.last <= t}
puts x.length == 0 ? "TLE" : x.map(&:first).min

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 2000005;
const int K = 1000000;
int a[N], cnt[N];
int binpow(ll x, ll y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    ll z = binpow(x, y / 2);
    return z * z % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 1; i <= n; i++){
        a[i] = s[i - 1] - '0';
    }
    int q = 1;
    int t = 1;
    for (int i = n; i >= 1; i--){
        t = (t + a[i] * q) % mod;
        q = (q + q) % mod;
    }
    vector < int > d;
    int ans = 0;
    for (int i = 2; i * i <= 2 * n; i++){
        if ((2 * n) % i == 0){
            int j = (2 * n) / i;
            if (n % i != 0) d.pb(i);
            if (n % j != 0 && i * i != 2 * n) d.pb(j);
        }
    }
    sort(d.begin(), d.end());
    for (int i = 0; i < d.size(); i++){
        int p = d[i];
        int f = 1;
        for (int i = p / 2 + 1; i <= n; i++){
            if (a[i] > (a[i - p / 2] ^ 1)) break;
            if ((a[i] ^ a[i - p / 2]) == 0) f = 0;
        }
        for (int j = 1; j <= p / 2; j++){
            if (a[j] == 0) continue;
            cnt[i] = (cnt[i] + binpow(2, p / 2 - j)) % mod;
        }
        cnt[i] += f;
        t = (t - cnt[i] + mod) % mod;
        ans = (ans + p * cnt[i]) % mod;
        for (int j = i + 1; j < d.size(); j++){
            if (d[j] % d[i] == 0){
                cnt[j] = (cnt[j] - cnt[i] + mod) % mod;
            }
        }
    }
    cout << (ans + 2 * n * t) % mod;
}


Measured memory_bytes: 4688
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

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

	bool flag = true;
	int cnt = 0;
	rep(i, n) {
		char p; int x;
		cin >> p >> x;

		if (p == '(')cnt += x;
		else cnt -= x;

		if (cnt < 0)flag = false;
	}
	if (cnt != 0)flag = false;
	puts(flag ? "YES" : "NO");
}


Measured memory_bytes: 3088
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode().rstrip()
W_cnt = S.count('W')
R_cnt = S.count('R')
ans = 0
for i in range(R_cnt):
    if S[i] == 'W':
        ans += 1
print(ans)
    

Measured memory_bytes: 80184
# 28
# ALDS_11_C - 幅優先探索

from collections import deque

n = int(input())
u_l = []
k_l = []
v_l = []

for i in range(n):
    _v_l = []
    for j, _ in enumerate(input().split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l)
        
d_l = [-1]*n
d_l[0] = 0
s_dq = deque([1])
while len(s_dq) > 0:
    _s = s_dq.popleft()
    _s -= 1
    for i in range(k_l[_s]):
        _v = v_l[_s][i]
        if d_l[_v-1] == -1:
            s_dq.append(_v)
            d_l[_v-1] = d_l[_s] + 1

for _id, _d in zip(range(1,n+1), d_l):
    print(_id, _d)



Measured memory_bytes: 6032
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;
    vector<ll> v;
    for(int i=0;i<N;i++){
      ll vv; cin>>vv; v.push_back(vv);
    }
    int flag=0; int res;
    for(int i=0;i<40;i++){

        for(int j=0;j<N;j++){
          if(v[j]%2!=0) flag=1;
        }
        if(flag==1){
          cout<<i<<endl; return 0;
        }
        for(int j=0;j<N;j++){
          v[j] /= 2;
        }

    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, a, b, c, x;
	while (cin >> n >> a >> b >> c >> x, n){
		vector<int> hit(n);
		REP(i, n){
			cin >> hit[i];
		}
		int ans;
		int count = 0;
		for(ans = 0; ans <= 10000;ans++){
			if (hit[count] == x)
				count++;
			if (count == n)
				break;
			x = (a*x + b) % c;
		}
		if (ans == 10001)ans = -1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3064
n_nin,okasi=map(int,input().split())
okasi_have=[0]*n_nin
for i in range(1,okasi+1):
    di=int(input())
    ai_list=list(map(int,input().split()))
    for j in ai_list:
        okasi_have[j-1]+=1
    
print(okasi_have.count(0))
    

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

using namespace std;

#define MaxN 300000

int t[MaxN];

int read(int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += t[idx];
    idx -= idx & -idx;
  }
  return sum;
}

void write(int idx, int v) {
  while (idx < MaxN) {
    t[idx] += v;
    idx += idx & -idx;
  }
}

int main(void) {
  string s;
  cin >> s;
  
  vector<int> freq(26);
  for (char c : s) {
    freq[c-'a']++;
  }
  
  int odd = 0;
  for (int i = 0; i < 26; i++) {
    if (freq[i] % 2) {
      odd++;
    }
  }
  
  if (odd > 1) {
    cout << "-1" << endl;
    return 0;
  }

  vector<vector<int>> positions(26);
  int pos = 0;
  for (char c : s) {
    positions[c - 'a'].push_back(pos);
    pos++;
  }

  long long ans = 0;
  if (odd) {
    for (auto p : positions) {
      if (p.size() % 2) {
        int m = int(p.size()) / 2;
        int mid = p[m];
        for (auto q : positions) {
          int sz = int(q.size());
          for (int i = 0; i < int(q.size()) / 2; i++) {
            if (q[i] > mid) ans++;
            if (q[sz - i - 1] < mid) ans++;
          }
        }
        break;
      }
    }
  }

  vector<pair<int, int>> events;
  for (auto p : positions) {
    int m = int(p.size());
    for (int i = 0; i < m / 2; i++) {
      events.push_back(make_pair(p[i], p[m - i - 1]));
    }
  }

  sort(begin(events), end(events));

  for (auto e : events) {
    ans += 2 * read(e.first+1) + (read(e.second+1) - read(e.first+1));
    write(e.second+1, 1);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3796
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int bubbleSort(vector<int> &v, int N){
    bool flag = true;
    int val,count = 0;

    while(flag){
        flag = 0;
        
        repr(j, N - 1){
            if(j == 0){
                break;
            }

            if(v.at(j) < v.at(j - 1)){
                val = v.at(j - 1);
                v.at(j - 1) = v.at(j);
                v.at(j) = val;
                flag = true;
                count++;
            }
        }
    }

    return count;
}

int main()
{
    int N,count;
    cin >> N;
    vector<int> v(N);
 
    rep(i, N){
        cin >> v.at(i);
    }

    count = bubbleSort(v, N);

    rep(i, N){
        if(i > 0){
            cout << " ";
        }
        cout << v.at(i);
    }

    cout << endl << count << endl;
}


Measured memory_bytes: 3096
#include <cstdio>
#include <cstring>
char str[120];
int main()
{
	int ok = 1;
	scanf("%s", str);
	int len = strlen(str);
	int p1 = 0, p2 = len-1;
	while(p1<=p2)
	{
		if(str[p1]!=str[p2])
		{
			ok = 0;
			break;
		}
		p1++; p2--;
	}
	p1 = 0, p2 = (len-1)/2-1;
	while(p1<=p2)
	{
		if(str[p1]!=str[p2])
		{
			ok = 0;
			break;
		}
		p1++; p2--;
	}
	p1 = (len+3)/2-1; p2 = len-1;
	while(p1<=p2)
	{
		if(str[p1]!=str[p2])
		{
			ok = 0;
			break;
		}
		p1++; p2--;
	}
	if(ok)
	    printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//OK

int main(void){
	int N,ans=0;
	bool ng=true;
	scanf("%d",&N);
	irep(i,6){
		int d = (int)pow(10,i);
		if(d>N)continue;
		if(N/d==1 && ng){
			if(N%d==0){
				ans+=10;
				ng=false;
			}else{
				ans+=1;
			}
		}else{
			ans+=N/d;
			ng=false;
		}
		N-=N/d*d;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
   char num[3];
   scanf("%s",num);
   
   if(num[0] == '7' || num[1] == '7' || num[2] == '7') {
      printf("Yes");
   }else{
      printf("No");
   }
   printf("\n");
   return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
 
using namespace std;
 
int main ()
{
  string k;
  cin >> k;
  for (int i = 0; i < k.length() - 1; i++)
    if (k[i] == k[i + 1]) {
      cout << "Bad";
      return 0;
    }
  cout << "Good";
  return 0;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

typedef long long ll;



int main() {
    int r;
    cin >> r;


    cout << int(pow(r,2)) << endl;

    return 0;
}


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

int main() {
  int X, Y, a, b, c, d, e, f; 
  cin >>X >>Y;
  f = 0;
  for (int i=X; i<=Y; i++) {
    a = i/10000;
    b = (i-a*10000)/1000;
    c = (i-a*10000-b*1000)/100;
    d = (i-a*10000-b*1000-c*100)/10;
    e = (i-a*10000-b*1000-c*100-d*10);
    if (a==e) {
      if (b==d){
        f++;
      }
    }

  }
  cout << f <<endl;
  
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

vector <int> g[MAXN];
bool used[MAXN], T[MAXN];
int A[MAXN];
PII B[MAXN], mn;

void dfs(int v)
{
	used[v] = true;
	mn = min(mn, MP(A[v], v));
	REP(i, SZ(g[v]))
	{
		int to = g[v][i];
		if (!used[to])
			dfs(to);
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("sparse.in", "r", stdin);
	//freopen("sparse.out", "w", stdout);
	int n, m, k = 0, cnt;
	cin >> n >> m;
	if (m == n - 1)
	{
		cout << 0;
		return 0;
	}
	REP(i, n)
	{
		cin >> A[i];
		B[i] = MP(A[i], i);
	}
	REP(i, m)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	sort(B, B + n);
	LL ans = 0;
	REP(i, n)
	{
		if (!used[i])
		{
			++k;
			mn = MP(INF, INF);
			dfs(i);
			ans += mn.first;
			T[mn.second] = true;
		}
	}
	cnt = k - 2;
	REP(i, n)
	{
		if (cnt == 0 || T[B[i].second])
			continue;
		--cnt;
		ans += B[i].first;
	}
	if (cnt)
	{
		cout << "Impossible";
		return 0;
	}
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 7168
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var s = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51";
        var a = s.Split(',').Select(int.Parse).ToArray();
        var n = int.Parse(Console.ReadLine()) - 1;
        Console.WriteLine(a[n]);
    }
}

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

int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    int cnt=0;
    for(auto x:mp){
        if(x.second%2==0) cnt++;
    }
    if(cnt%2==0) cout << mp.size() << endl;
    else cout << mp.size()-1 << endl;
    
}

Measured memory_bytes: 8292
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    // long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), M = scanner.nextInt();
        scanner.nextLine();
        Map<Integer, Set<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            edges.put(i, new HashSet<>());
        }
        for (int i = 0; i < M; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            edges.get(e[0]).add(e[1]);
        }
        int S = scanner.nextInt(), T = scanner.nextInt();

        int[][] dist = new int[N + 1][3];
        for (int[] d : dist) {
            Arrays.fill(d, Integer.MAX_VALUE / 2);
        }
        Queue<Long> q = new ArrayDeque<>();
        Set<Long> visited = new HashSet<>();
        q.add(((long) S) << 32);
        while (!q.isEmpty()) {
            long top = q.poll();
            int node = (int) (top >> 32);
            int cost = (int) top;
            int rem = cost % 3;
            if (visited.add((((long) node) << 32) + rem)) {
                dist[node][rem] = cost;
                for (int next : edges.get(node)) {
                    q.add((((long) next) << 32) + cost + 1);
                }
            }
        }

        if (dist[T][0] == Integer.MAX_VALUE / 2) {
            System.out.println(-1);
            return;
        }

        System.out.println(dist[T][0] / 3);
    }

}


Measured memory_bytes: 184200
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
  char b;
  cin>>b;
  
  if(b=='A'){
   cout<<"T"<<endl; 
  }else if(b=='T'){
   cout<<"A"<<endl; 
  }else if(b=='C'){
   cout<<"G"<<endl; 
  }else{
    cout<<"C"<<endl; 
  }
  
}

Measured memory_bytes: 256
def main(a, b, c):
    ans = c - (a - b)
    if ans < 0:
        return 0
    return ans


if __name__ == '__main__':
    i = list(map(int, input().split()))
    a, b, c = i[0], i[1], i[2]
    print(main(a, b, c))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt(), m = fs.nextInt();
        adj = new ArrayList[n];
        for(int i = 0; i < n; i++) adj[i] = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            int a = fs.nextInt()-1, b = fs.nextInt()-1;
            adj[a].add(b);
            adj[b].add(a);
        }
        cnt = 0;
        boolean[] V = new boolean[n];
        V[0] = true;
        dfs(0, V, 1);
        out.println(cnt);
        out.close();
    }

    static int cnt;
    static ArrayList<Integer>[] adj;
    static void dfs(int at, boolean[] V, int seen) {
        boolean no = true;
        for(Integer i : adj[at]) {
            if(!V[i]) {
                V[i] = true;
                no = false;
                dfs(i, V, seen + 1);
                V[i] = false;
            }
        }
        if(no) {
            if(seen == V.length) {
                cnt++;
            }
        }
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

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

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,x=0,ans=0;
string S;
scanf("%d\n",&N);
getline(cin,S);
for(int i=0;i<=N;i++)
{
    if(S[i]=='I')
    ++x;
    else
    --x;
    if(x>=ans)
        ans=x;


}
printf("%d",ans);

}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int h1,m1,h2,m2,k;
  scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
  
  int t=(h2-h1)*60+(m2-m1);
  int ans=t-k;
  if(ans<0){
    ans=0;
  }
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
/////////////////////////////////
int main()
{
    ll a, b;
    cin >> a >> b;
    if ((a - b) % 2 == 0)
        cout << (a + b) / 2 << endl;
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 3600
def main():
    h, n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]
    dp = [10**10]*(h+1)
    dp[0] = 0
    for i in range(h):
        for a, b in ab:
            j = i+a
            if j > h:
                j = h
            dp[j] = min(dp[j], dp[i]+b)
    print(dp[-1])


main()


Measured memory_bytes: 42716
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include <bitset>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/******************************define*********************************/

/*****************************functions********************************/

/****************************main function*****************************/
int main(void) {

	ll N, M; cin >> N >> M;

	vector<ll> x(M), d(M - 1);
	for (ll i = 0; i < M; i++) {
		cin >> x[i];
	}

	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	sort(all(x));
	reverse(all(x));
	for (ll i = 0; i < M - 1; i++) {
		d[i] = x[i] - x[i + 1];
	}
	sort(all(d));
	reverse(all(d));
	ll s = 0;
	for (ll i = 0; i < N - 1; i++) {
		s += d[i];
	}
	cout << x[0] - x[M-1] - s << endl;

	return 0;
}

Measured memory_bytes: 1792
def main
  s = gets.chomp
  i = 0
  j = 0
  cnt = 0
  max = 0
  until s[j].nil?
    if ['A', 'T', 'G', 'C'].include? s[j]
      cnt += 1
      max = cnt if cnt > max
      j += 1
    else
      i = j + 1
      j = j + 1
      cnt = 0
    end
  end
  puts max
end

main



Measured memory_bytes: 14212
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 4000
#define offset 220010
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<double,double> iib;
typedef pair<ll,ii> iii;
typedef pair<map<ll,ll> ,ll> mi;
typedef pair<ii,ii> iiii;
typedef vector<ll> vi;
ll N,K;
vector<ll> divs;
map<ll,bool> vis;
map<ll,ll> dp;
const ll MOD=1e9+7;

ll pot(ll base,ll exp)
{
    base%=MOD;
    ll resp=1;
    while(exp>0)
    {
        if (exp&1)
            resp*=base,resp%=MOD;
        base*=base;base%=MOD;
        exp/=2;
    }
    return resp%MOD;
}
ll f(ll num)
{
    ll tot=0;
    if (vis[num]!=0)
        return dp[num];
    vis[num]=1;
    tot=pot(K,(num+1)/2);
    tot%=MOD;
    forr(i,0,divs.size())
    {
        if (divs[i]!=num && num%divs[i]==0)
            tot-=f(divs[i]),tot+=MOD,tot%=MOD;
    }
    return dp[num]=tot;
}
int  main()
{
    //cout<<pot(3,4)<<" "<<pot(2,10)<<endl;
    cin>>N>>K;
    if (N!=1)
    divs.pb(1);
    for(ll i=2;i*i<=N;i++)
    {
        if (N%i==0){
            if (N/i!=i)
            divs.pb(i),divs.pb(N/i);
            else
            divs.pb(i);
        }
    }
    sort(divs.begin(),divs.end());
    /*forr(i,0,divs.size())
    cout<<divs[i]<<" ";
    cout<<endl;
    cout<<divs.size()<<' ';
    cout<<unique(divs.begin(),divs.end())-divs.begin()<<endl;*/
    //cout<<f(N)<<endl;
    ll answer=f(N)%MOD;
    if (N%2==0) answer*=N/2;
    else answer*=N;
    answer%=MOD;
    //cout<<endl<<endl;
    forr(i,0,divs.size()){
        //cout<<divs[i]<<' ';
        if (divs[i]%2)
        answer+=(f(divs[i])*divs[i])%MOD,answer%=MOD;
        else
        answer+=(f(divs[i])*(divs[i]/2))%MOD,answer%=MOD;
        //cout<<answer<<' ';
    }
    cout<<answer<<endl;
} 

Measured memory_bytes: 384
a,b,c= (int(x) for x in input().split())
d=b
e=c
if b<a:
    b=a
    a=d
    d=b
if b>c:
    b=c
    c=d
    d=b
    e=c
if  b<a:
    b=a
    a=d
print(f"{a} {b} {c}")
    
    


Measured memory_bytes: 5612
#include<stdio.h>

int main(){
 int first,second,third,height;


 first=second=third=0;
 
 while(scanf("%d",&height)!=EOF){
  if(first<height){
   third=second;
   second=first;
   first=height;
  }else if(second<height){
   third=second;
   second=height;
  }else if(third<height){
   third=height;
  }
 }
 printf("%d\n%d\n%d\n",first,second,third);
 return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>

char s[100];

int main()
{
    scanf("%s",s);
    int n=strlen(s);
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n/2-1-i])
        {
            printf("No\n");
            return 0;
        }
        if(s[n/2+1+i]!=s[n-1-i])
        {
            printf("No\n");
            return 0;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

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

bool allTheSame(string s){
  char c = s[0];
  for(int i=0; i<s.size(); i++)
    if(s[i] != c) return false;
  return true;
}

string process(string t, char ch){
  string result = "";
  for(int i=0; i<t.size()-1; i++){
    if(t[i] == ch || t[i+1]==ch) result += ch;
    else result += t[i];
  }
  return result;
}

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

  int ans = 1e6;
  for(char ch='a'; ch<='z'; ch++){
    string t = s;

    int cnt = 0;
    while(!allTheSame(t)){
      string result = process(t, ch);
      t = result;
      cnt++;
      if(t == s){
        cnt = 1e6;
        break;
      }
    }

    ans = min(ans, cnt);
  }

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

Measured memory_bytes: 256
N,K = gets.split(" ").map(&:to_i);
a = gets.split(" ").map(&:to_i);
ainv = a.reverse
inv = 0
count = 0
for i in 0..N-2
    
    for j in i+1..N-1
        if a[i] > a[j]
            count += 1
        end
    end
end
inv += K*(K+1)/2*count
count = 0
for i in 0..N-2
    
    for j in i+1..N-1
        if ainv[i] > ainv[j]
            count += 1
        end
    end
end
inv += K*(K-1)/2*count

out = inv % (10**9+7)
puts out
    


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	ll target = min(b - 1, n);
	ll ans = a * target / b - target / b * a;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636