akhauriyash/Code-Regression huggingface dataset:
public class Main {


  private static void solve() {
    int n = ni();
    int m = ni();
    int[] cnt = new int[n + 1];
    for (int i = 0; i < m; i ++) {
      int a = ni();
      int b = ni();
      cnt[a] ++;
      cnt[b] ++;
    }
    
    for (int i = 0; i < n; i ++) {
      if (cnt[i + 1] % 2 != 0) {
        System.out.println("NO");
        return;
      }
    }
    System.out.println("YES");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main() {
	int n;
	cin >> n;
	vector<int> h(n,0);
	for(int i = 0;i < n;i++)
	{
		cin >> h.at(i);
	}
	int c=0;
	for(int i=0;i<10000;i++)
	{
		int f=0;
		for(int j=0;j<n;j++)
		{
			if(h.at(j)>0)
			{
				h.at(j)--;
				f=1;
				if(j==n-1)
				{
					c++;
				}
				continue;
			}
			if(f==1&&h.at(j)==0)
			{
				c++;
				break;
			}
		}
		if(f==0)
		{
			break;
		}
	}
	cout << c << endl;
	return 0;
}


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

bool Judge(int m, int index, vector<int> &A)
{
	if(m == 0){
		return true;
	}
	if(index != A.size()){
		int l = m - A[index];
		index++;
		if(Judge(m, index, A) || Judge(l, index, A)){
			return true;
		}
	}
	return false;
}

int main()
{ 
	int n, q; //n:??´??°???????????? q:???????????° 
	cin >> n;
	vector<int> A, M;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	cin >> q;
	for(int i = 0; i < q; i++){
		int m;
		cin >> m;
		M.push_back(m);
	}
	for(int i = 0; i < q; i++){
		if(Judge(M[i], 0, A)){
			cout << "yes" << endl;
		}else{
			cout << "no"  << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3156
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
template<class T> inline ll gcd(T a, T b){ if (a % b == 0){ return b; } else{ return gcd(b, a%b); } }
template<class T> inline ll lcm(T a, T b){ return a * b / gcd(a, b); }
template<class T> inline ll fact(T a){ if (a == 1){ return a; } else{ return a * fact(a - 1); } }

int main(){
    ll N;
    ll cnt = 0;
    ll bef;
    cin >> N >> bef;
    ll tempCnt = 0;
    rep(i, 0, N - 1){
        ll temp;
        cin >> temp;
        if (temp <= bef){
            tempCnt++;
        }
        else{
            tempCnt = 0;
        }
        if (cnt < tempCnt) cnt = tempCnt;
        bef = temp;
    }

    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=500005;
const int mod=998244353;

int n,k,ans;
int fac[N],inv[N];

int quickpow(int x,int y){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%mod)
		if (y&1) s=1ll*s*x%mod;
	return s;
}

void init(int n){
	int i;
	fac[0]=inv[0]=1;
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=quickpow(fac[n],mod-2);
	for (i=n-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}

int C(int x,int y){
	if (x<y) return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
	int i;
	scanf("%d%d",&n,&k);
	init(k);
	for (i=n;i<=k;i++) (ans+=(C(k,k-i)-C(k,i+i-n+1))%mod)%=mod;
	ans=(ans%mod+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int t;
  cin >> t;
  int h,m,s;
  h=t/3600;
  t=t % 3600;
  m=t/60;
  t=t % 60;
  s=t;
  
  cout << h  << ":" << m << ":" << s <<endl;
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)
typedef long long ll;

int main()
{
  int D, G, maxnum;
  cin >> D >> G;
  vector<int> p(D), c(D);
  rep(i, D) cin >> p.at(i) >> c.at(i);
  int res = 1e9;
  rep(i, 1 << D)
  {
    int score = 0, cnt = 0, rest_max = -1;
    rep(j, D)
    {
      if (i >> j & 1)
      {
        score += (j + 1) * 100 * p[j] + c[j];
        cnt += p[j];
      }
      else
        rest_max = j;
    }
    if (rest_max >= 0)
      rep(j, p[rest_max])
      {
        if (score >= G)
          break;
        score += (rest_max + 1) * 100;
        cnt++;
      }
    if (score >= G)
      res = min(res, cnt);
  }
  cout << res << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  int n, a = 100;
  cin >> n;
  REP(i, n) {
    a = ceil(a*1.05);
    //cout << a << endl;
  }
  cout << a*1000 << endl;
  return 0;
}

Measured memory_bytes: 3068
#include<cstdio>

int main(){
  int n;scanf("%d",&n);
  for(int i=0;i<n;i++){
    long double d[8];
    for(int i=0;i<8;i++) scanf("%Lf",&d[i]);
    if((d[0]-d[2])*(d[5]-d[7])==(d[4]-d[6])*(d[1]-d[3]))
      puts("YES");
    else
      puts("NO");
  }
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, d[300003];

bool ch() {
  ll tmp = d[0];
  FOR(i, 1, n) {
    if(tmp < (i * 10)) return false;
    if(tmp < (i * 10) + d[i]) tmp = (i * 10) + d[i];
  }
  return true;
}

signed main() {
  cin >> n;
  rep(i, n) cin >> d[i];
  if(ch()) {
    reverse(d, d + n);
    if(ch()) {
      cout << "yes" << endl;
      return 0;
    }
  }
  cout << "no" << endl;

	return 0;
}


Measured memory_bytes: 5556
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c ;
	int x,y,z,flag=0;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF){
	
	while(a%2==0&&b%2==0&&c%2==0){
		if(a==b&&b==c) {
			cout << -1;
			return 0;
		}
		x=a;y=b,z=c;
		a=(y+z)/2;
		b=(x+z)/2;
		c=(x+y)/2;
		flag++;
	}
	cout << flag <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import groupby

S = input()
K = int(input())

s = [ len(list(j)) for i, j in groupby(S)]
ans = 0
for i in s:
    if i >= 2:
        ans += i // 2
ans *= K
if S[0] == S[-1] and s[0] % 2 == s[-1] % 2 == 1:
    ans += K - 1

if len(s) == 1:
    ans = (len(S) * K) // 2
print(ans)        
    

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;



long long A[100005];

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

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	int Y;
	long long temp = (A[N - 1] + 1) / 2;
	long long   Z = 1000000000;
	Y = A[0];
	for (int i = 0; i < N - 1; i++) {
		if (abs(temp- A[i]) < Z) {
			Z = abs(temp - A[i]);
			Y = A[i];
		}
		
	}

	cout << A[N - 1] << " " <<Y<< endl;
	return 0;
}



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

const int MAXN = 5e5 + 10;

int n, a[MAXN], suf[MAXN], pre[MAXN];

int main() {
	scanf("%d%d", &n, pre);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		pre[i] = min(pre[i - 1], abs(pre[i - 1] - a[i]));
	}
	suf[n + 1] = 0;
	for (int i = n; i; --i)
		if (a[i] / 2 <= suf[i + 1]) suf[i] = suf[i + 1] + a[i];
		else suf[i] = suf[i + 1];
	static int qn;
	for (scanf("%d", &qn); qn; --qn) {
		int x;
		scanf("%d", &x);
		puts(pre[x - 1] <= suf[x + 1] ? "NO" : "YES");
	}
}

Measured memory_bytes: 7808
while True:
    N = int(raw_input())

    if N == 0:
        break

    xy = [map(int, raw_input().split()) for _ in range(N)]

    table = [[False for _ in range(21)] for _ in range(21)]
    table[10][10] = True

    cur = [10, 10]

    M = int(raw_input())

    for _ in range(M):
        d, l = raw_input().split()
        l = int(l)
        if d == 'N':
            for i in range(l):
                cur[1] += 1
                table[cur[0]][cur[1]] = True
        if d == 'E':
            for i in range(l):
                cur[0] += 1
                table[cur[0]][cur[1]] = True
        if d == 'S':
            for i in range(l):
                cur[1] -= 1
                table[cur[0]][cur[1]] = True
        if d == 'W':
            for i in range(l):
                cur[0] -= 1
                table[cur[0]][cur[1]] = True

    flag = True

    for (x, y) in xy:
        if not table[x][y]:
            flag = False
            break

    print 'Yes' if flag else 'No'



Measured memory_bytes: 4688
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let a:i32 = read();
    let b:i32 = read();

    let k:i32 = (a+b)/2;

    if (a-k).abs() == (b-k).abs() {
        println!("{}", k);
    } else {
        println!("IMPOSSIBLE");
    }
    
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int a[1000],b[1000],c[1000],p[3][1000];
int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>p[j][i];
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<1000;j++)a[j]=0;
		for(int j=0;j<n;j++){b[j]=p[i][j];a[b[j]]++;}
		for(int j=0;j<n;j++){if(a[b[j]]==1)c[j]+=b[j];}
	}
	for(int i=0;i<n;i++)cout<<c[i]<<endl;
	return 0;
}

Measured memory_bytes: 3120
#include<stdio.h>
 
#define AMAX 20
#define MMAX 200

int gA[AMAX+1],gM[MMAX+1];
int gn;

int solve( int p, int t )
{
	if( 0 == t ) { return 1; }
	if( gn <= p ) { return 0; }
	
	int res = solve( p+1, t-gA[p] ) || solve( p+1, t ) ;
	
	return res;
}

int main( void ) 
{

    int i;
    int q;
    
    scanf( "%d", &gn );  
	for( i=0; i<gn; i++ ) {
	    scanf( "%d", &gA[i] );
	}   
    scanf( "%d", &q );  
    for( i=0; i<q; i++ ) {
        scanf( "%d", &gM[i] );
    	if( solve( 0, gM[i] ) ) {
    		printf( "yes\n" );    	
    	} else {
    		printf( "no\n" );
    	}
    }
 
    return 0;
}

Measured memory_bytes: 580
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val s = readLineStrings(sc)(0).toList.map(_ == '1').toArray
    val n = s.length
    if (!s.head || s.last) {
      println(-1)
      return
    }
    if (!(0 to (n - 2)).forall(i => s(i) == s(n - 2 - i))) {
      println(-1)
      return
    }
    var nodeIndex = 1
    while (nodeIndex < n - 1) {
      if (s(nodeIndex)) {
        println(s"$nodeIndex ${nodeIndex + 1}")
        nodeIndex += 1
      } else {
        var nextNodeIndex = nodeIndex
        while (!s(nextNodeIndex)) nextNodeIndex += 1
        nextNodeIndex += 1
        for (i <- nodeIndex until nextNodeIndex) {
          println(s"$i $nextNodeIndex")
        }
        nodeIndex = nextNodeIndex
      }
    }
    println(s"${n - 1} $n")
  }
}

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

using namespace std;

#define MAX 101

int H, W, sx, sy, gx, gy;
int color, dir, field[MAX][MAX];

struct P{
  int x, y;
  P(int x, int y) : x(x), y(y) {}
};

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

bool check(int y, int x){
  if(0 <= y && y < H && 0 <= x && x < W){
    return true;
  }
  return false;
}

void paint(int y, int x){
  if(!dir){
    for(int i = 0 ; i < 2 ; i++){
      for(int j = 0 ; j < 4 ; j++){
        field[y+i][x+j] = color;
      }
    }
  }else{
    for(int i = 0 ; i < 4 ; i++){
      for(int j = 0 ; j < 2 ; j++){
        field[y+i][x+j] = color;
      }
    }

  }
}

bool bfs(){
  bool used[MAX][MAX];
  memset(used, false, sizeof(used));
  used[sy][sx] = true;

  queue<P> Q;
  Q.push(P(sx, sy));

  while(!Q.empty()){
    P p = Q.front(); Q.pop();

    if(p.x == gx && p.y == gy){
      return true;
    }

    if(field[p.y][p.x] == -1) continue;

    for(int i = 0 ; i < 4 ; i++){
      int nx = p.x + dx[i];
      int ny = p.y + dy[i];

      if(!check(ny, nx) || used[ny][nx] || 
         field[p.y][p.x] != field[ny][nx]) continue;

      used[ny][nx] = true;
      Q.push(P(nx, ny));     
    }
  }

  return false;
}

int main(){
  int n, x, y;
  while(cin >> W >> H, (W | H)){
    memset(field, -1, sizeof(field));

    cin >> sx >> sy >> gx >> gy >> n;
    sy--, sx--, gy--, gx--;

    for(int i = 0 ; i < n ; i++){
      cin >> color >> dir >> x >> y;
      y--, x--;
      paint(y, x);
    }

    cout << (bfs() ? "OK" : "NG") << endl;
  }

  return 0;
}

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

int main() {
//入力
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i = 0; i < N; i++) cin >> cards.at(i);
  
//ソート、最適得点
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  int best = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) best += cards.at(i);
    else best -= cards.at(i);
  }
  cout << best << endl;
}


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

#define ll long long
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  constexpr char nl = '\n';

  string s;
  string t;
  cin >> s >> t;

  int ls = s.length();
  int lt = t.length();
  vector<vector<pair<int, pair<int, int>>>> dp(ls,
                                               vector<pair<int, pair<int, int>>>(lt, make_pair(0, make_pair(-1, -1))));
  for (int i = 0; i < ls; ++i) {
    for (int j = 0; j < lt; ++j) {
      int left_length = 0;
      if (j - 1 >= 0) {
        left_length = dp[i][j - 1].first;
      } else {
        left_length = 0;
      }
      int up_length = 0;
      if (i - 1 >= 0) {
        up_length = dp[i - 1][j].first;
      } else {
        up_length = 0;
      }

      if (s[i] == t[j]) {
        if (i == 0 && j == 0) {
          dp[i][j].first = 1;
          dp[i][j].second = make_pair(-1, -1);
        } else if (i == 0) {
          dp[i][j].first = 1;
          dp[i][j].second = make_pair(-1, -1);
        } else if (j == 0) {
          dp[i][j].first = 1;
          dp[i][j].second = make_pair(-1, -1);
        } else {
          dp[i][j].first = dp[i - 1][j - 1].first + 1;
          dp[i][j].second = make_pair(i - 1, j - 1);
        }
      } else {
        if (left_length == 0 && up_length == 0) {
          dp[i][j].first = 0;
          dp[i][j].second = make_pair(-1, -1);
        } else if (left_length > up_length) {
          dp[i][j].first = dp[i][j - 1].first;
          dp[i][j].second = make_pair(i, j - 1);
        } else {
          dp[i][j].first = dp[i - 1][j].first;
          dp[i][j].second = make_pair(i - 1, j);
        }
      }
    }
  }

  int i = ls - 1;
  int j = lt - 1;
  string ans;
  while (i != -1 || j != -1) {
//    cout << i << " " << j << ' ' << (s[i] == t[j] ? s[i] : ' ') << nl;
    if (s[i] == t[j]) {
      ans.insert(0, 1, s[i]);
    }
    auto &coord = dp[i][j].second;
    i = coord.first;
    j = coord.second;
  }
  cout << ans << nl;

  return 0;
}

Measured memory_bytes: 105856
S = input()

dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(len(S)):
    for j in range(13):
        if S[i] == "?":
            for k in range(10):
                x = (j * 10 + k) % 13
                dp[i + 1][x] += dp[i][j]
                dp[i + 1][x] %= mod
        else:
            x = (j * 10 + int(S[i])) % 13
            dp[i + 1][x] += dp[i][j]
            dp[i + 1][x] %= mod
            
print(dp[-1][5])


Measured memory_bytes: 88420
S=list(input())
T=list(input())
SS=len(S)
TS=len(T)
ans=TS
for i in range(SS-TS+1):
  cnt=0 #
  for j in range(TS):
    #print(T[j] ,S[i+j])
    if T[j] != S[i+j] :
      cnt +=1
  ans=min(cnt,ans)
 
print(ans)

Measured memory_bytes: 9124
#include<vector>
#include <iostream>

using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    //int res = x * y;
    if(x >= 10 || y >= 10){
        cout << -1 << endl;
    }else{
        cout << x * y << endl;
    }
    return 0;
}

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

int main()
{
	int N, L;
	cin >> N >> L;
	int sum = L * N + N * (N - 1) / 2;
	int id = 0;
	for (int i = 1; i < N; i++) {
		int v0 = L + id, v1 = L + i;
		if (abs(v1) < abs(v0)) id = i;
	}
	cout << sum - (L + id) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>

#include <iomanip>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
// queue: first in first out
// stack: first in last out
typedef long long ll;

const long long int MOD = 1e9+7;
const ll INF = 1e17;
const ll NUM = 1e5+1;
// ll dp[100005][13];
ll dp[10005];

ll Query[NUM];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

void createString(int used, int indexRemain, string str) {
  if (indexRemain > 0) {
    int a = (int)'a';
    char c;
    for (int j = 0; j < used+1; j++) {
      c = a + j;
      createString(max(used, j+1), indexRemain-1, str + c);
      // createString(remain-1, used+1, indexRemain-1, str + c);
    }
  } else {
    cout << str << endl;
  }
}

signed main(void) {
  int N;
  cin >> N;
  createString(1, N-1, "a");
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#define INF 1<<20

using namespace std;

int main(void){
	int l; cin >> l;
	string str; cin >> str;

	int ans = 0;
	int i = 0;
	int count = -INF;
	while(i<l){
		if(str[i] == 'W') count = 0;
		else if(str[i] == 'B') count++;
		else{
			int j = i+1;
			while(j<l){
				if(str[j] == 'B'){
					count = -INF;
					break;
				} else if(str[j] == '.'){
					ans = max(ans, count);
					count = -INF;
					break;
				}
				j++;
			}
			ans = max(ans, count);
			count = -INF;
		}
		i++;
	}

	i = l-1;
	count = -INF;
	while(i>=0){
		if(str[i] == 'W') count = 0;
		else if(str[i] == 'B') count++;
		else{
			int j = i-1;
			while(j>=0){
				if(str[j] == 'B'){
					count = -INF;
					break;
				} else if(str[j] == '.'){
					ans = max(ans, count);
					count = -INF;
					break;
				}
				j--;
			}
			ans = max(ans, count);
			count = -INF;
		}
		i--;
	}

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


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    int n;
    cin>>n;
    ll a[n+1],b[n];
    ll ans=0;
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    for(int i=0;i<n;i++){
        int tmp=min(a[i],b[i]);
        ans+=tmp;
        b[i]-=tmp;
        a[i]-=tmp;
        tmp=min(a[i+1],b[i]);
        ans+=tmp;
        b[i]-=tmp;
        a[i+1]-=tmp;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        // input
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();
        int Y = scanner.nextInt();
        scanner.nextLine();

        List<Integer> x = Arrays.asList(scanner.nextLine().split(" ")).stream()
                .map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> y = Arrays.asList(scanner.nextLine().split(" ")).stream()
                .map(Integer::parseInt).collect(Collectors.toList());

        // xの最大値
        int xMax = x.get(0);
        for (int xi : x) {
            xMax = Math.max(xMax, xi);
        }

        // yの最小値
        int yMin = y.get(0);
        for (int yi : y) {
            yMin = Math.min(yMin, yi);
        }

        // Zが存在するかどうか
        if ((xMax < yMin) && (X < yMin) && (xMax < Y)) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }

    }
}


Measured memory_bytes: 28876
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	string s, t;
	cin >> s >> t;
	vector<vector<int> > appearance(26);
	for (int i = 0; i < s.length(); i++) {
		appearance[s[i] - 'a'].push_back(i);
	}
	long long int start = 0;
	for (int i = 0; i < t.length(); i++) {
		int tmp = t[i] - 'a';
		if (appearance[tmp].empty()) {
			cout << -1 << endl;
			return 0;
		}
		int idxx = lower_bound(appearance[tmp].begin(), appearance[tmp].end(),
		                       start % s.length()) -
		           appearance[tmp].begin();
		int idx = appearance[tmp][idxx];
		// cout << idx << endl;
		if (idxx == appearance[tmp].size()) {
			start += s.length() - (start % s.length());
			start += appearance[tmp][0] + 1;
		} else {
			start += idx - (start % s.length()) + 1;
		}
		// cout << i << " " << start << endl;
	}
	cout << start << endl;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,x,y;
int sum=0;
int v,z;
int main() {
	scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
	if(2*c<=a+b)
		sum+=min(x,y)*2*c;
	else sum+=min(x,y)*(a+b);
	if(y>x) z=y-x,v=b;
	else z=x-y,v=a;
	sum+=min(2*c*z,z*v);
	printf("%d\n",sum);
}

Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
void calc(const vector<ll> &a,vector<ll> &mi,vector<ll> &ma){
  ll tsum=0,idx=1,asum=0;
  ll n = a.size();
  asum=a[0];
  tsum=a[0];
  for(int i=1;i<n;i++){
    asum += a[i];
    while(idx<i){
      ll nt = tsum+a[idx];
      ll now = abs(asum-2*tsum);
      ll nxt = abs(asum-2*nt);
      if(now>nxt){
        tsum += a[idx];
        idx++;
      }else{
        break;
      }
    }
    mi[i] = min(tsum,asum-tsum);
    ma[i] = max(tsum,asum-tsum);
  }
}
signed main(){
  init_io();
  ll n;
  ll ans=1e18;
  cin >> n;
  vector<ll> a(n),sum(n,0);
  vector<ll> lvmin(n),rvmin(n);
  vector<ll> lvmax(n),rvmax(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  calc(a,lvmin,lvmax);
  reverse(a.begin(),a.end());
  calc(a,rvmin,rvmax);
  for(int i=1;i+2<n;i++){
    //cout << i<<" "<<lvmin[i]<<" "<<lvmax[i]<<" "<<rvmin[n-2-i]<<" "<<rvmax[n-2-i]<<endl;
    ans = min(ans,-min(lvmin[i],rvmin[n-2-i])+max(lvmax[i],rvmax[n-2-i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 12680
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back


template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







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

        Int T[200010];
        for(int i = 0; i < n; i++) cin >> T[i];

        sort(T,T+n);
        
        Int ans = T[0];
        for(int i = 1; i < n; i++){
                int tmp = T[i] - T[i-1];
                tmp = min(tmp,t);

                ans += tmp;
        }

        ans += t;

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










Measured memory_bytes: 1792
#include <iostream>

using namespace std;

const int N = 100;
int a[N];

void output(int a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i > 0)
            cout << " ";
        cout << a[i];
    }
    cout << endl;    
}

void insertionSort(int a[], int n) {
    for (int i = 1; i < n; i++) {
        int value = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > value) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = value;
        output(a, n);
    }
}

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

    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    output(a, n);
    insertionSort(a, n);

    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <math.h>
#define MAX_P 20

using namespace std;

/*〜概要〜
  binary_numにより，人iが正しいかどうかをtrue_personに格納する．
  例えば，i=20回目のループを考える．
  20は2進数で00101(左から数える)であり，これは
  人1が嘘つき，人2が嘘つき，人3は正直，人4は嘘つき，人5は正直
  であることを示しており，それをi=0からi=2^N-1まで繰り返すことにより
  全パターンを探索することができる．
*/

//引数numを2進数に直して配列true_personに左から格納する
void binary_num(int num, int N, int true_person[]){
  int i=1;
  while(num != 0){
    true_person[i] = num%2;
    i++;
    num /= 2;
  }
}


//true_person配列を参照することで，正直者の人数を返す関数
int honest_count(int true_person[], int N){
  int count = 0;
  for(int i=1; i<=N; i++)
    if(true_person[i] == 1)
      count++;
  return count;
}


int check(int x[MAX_P][MAX_P], int y[MAX_P][MAX_P], int A[],
		 int N, int true_person[]){
  int i, j;
  char word[2][MAX_P] = {"不親切", "正直者"}; //アルゴリズムには影響しない
  //cout << "以下は，正直者の証言" << endl;
  for(i=1; i<=N; i++){
    if(true_person[i] == 1){
      //cout << "・人" << i << "の証言" << endl;
      for(j=1; j<=A[i]; j++){
	//cout << "　人" << x[i][j] << "は" << word[y[i][j]] << "である．" << endl;
	if(y[i][j] != true_person[ x[i][j] ]){
	  //cout << "→矛盾" << endl;
	  return -1;
	}
      }
    }
  }
  int honest_num = honest_count(true_person, N);;
  //  cout << "正直者の数は" << honest_num << endl;
  return honest_num;
}


int main(void){
  int N, i, j;
  cin >> N;
  int A[N];
  int x[MAX_P][MAX_P], y[MAX_P][MAX_P];
  for(i=1; i<=N; i++){ //入力
    cin >> A[i];
    for(j=1; j<=A[i]; j++)
      cin >> x[i][j] >> y[i][j];
  }

  /*  for(i=1; i<=N; i++){ //入力                                                  
    cout << "A["<<i<<"]："<<A[i] << endl;
    for(j=1; j<=A[i]; j++){
      cout << "x["<<i<<"]"<<"["<<j<<"]："<<x[i][j];
      cout << " ,  y["<<i<<"]"<<"["<<j<<"]："<<y[i][j] << endl;
    }
    }*/
    
  //人iが正しいかどうか(正しいなら1，そうでないなら0)
  int true_person[MAX_P];
  
  /*binary_numにより，人iが正しいかどうかをtrue_personに格納する．
    例えば，i=20回目のループを考える．
    20は2進数で00101(左から数える)であり，これは
    人1が嘘つき，人2が嘘つき，人3は正直，人4は嘘つき，人5は正直
    であることを示しており，それをi=0からi=2^N-1まで繰り返すことにより
    全パターンを探索することができる．
   */
  int count_max = 0;
  int count;
  for(i=0; i<pow(2, N); i++){
    //cout << "------" << i << "回目の探索開始" << "------" << endl;
    binary_num(i, N, true_person);    
    count = check(x, y, A, N, true_person);
    if(count_max < count)
      count_max = count;
    //cout << "------" << i << "回目の探索終了" << "------" << endl << endl;
  }

  //  cout << "全ての探索終了" << endl;
  
  cout<< count_max << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		final int n = sc.nextInt();

		long list[] = new long[n + 1];

		for (int i = 0; i <= n; i++) {
			if (i == 0) {
				list[i] = 2;
			} else if (i == 1) {
				list[i] = 1;
			} else {
				list[i] = list[i - 2] + list[i - 1];
			}
		}

		System.out.print(list[n]);

	}

}


Measured memory_bytes: 23764
def main():
    N = int(input())
    H = [int(h) for h in input().split()]

    count = 0
    while max(H) > 0:
        count += 1
        maxH = max(H)
        is_found = False
        start, end = 0, N
        for i in range(N):
            if not is_found and H[i] == maxH:
                is_found = True
                start = i
            elif is_found and H[i] != maxH:
                end = i
                break
        for i in range(start, end):
            H[i] -= 1

    return count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

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

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int N;
string S1, S2;
int dp[64];
const int MOD7 = (int)1e9 + 7;

int f(int i)
{
    if (i == N)
        return 1;
    int& ans = dp[i];
    if (ans >= 0)
        return ans;

    ans = 0;
    if (S1[i] == S2[i]) {
        // vertical domino.
        if (i == N - 1) {
            return ans = 3;
        }

        if (S1[i + 1] == S2[i + 1]) {
            ans = 2 * f(i + 1);
            ans %= MOD7;
            return ans;
        } else {
            return ans = f(i + 1);
        }
    } else {
        // 2 horizontal dominos.
        if (i + 2 == N) {
            return ans = 6;
        }

        if (S1[i + 2] == S2[i + 2]) {
            ans = 2 * f(i + 2);
            ans %= MOD7;
            return ans;
        } else {
            return ans = (int)(3LL * f(i + 2) % MOD7);
        }
    }
};

void solveSingleCase(int caseNo)
{
    cin >> N;
    cin >> S1 >> S2;
    memset(dp, -1, sizeof dp);
    cout << f(0) << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include<chrono>
using namespace std::chrono; 
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
//#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	auto start = high_resolution_clock::now(); 
	cin>>n;
	ll k;
	cin>>k;
	v.resize(n);
	read(v);
	sor(v);
	ll mi=llmax;
	for(int i=0;i<=n-k;i++)
	{
		mi=min(mi,v[i+k-1]-v[i]);
		//cout<<mi;
	}
	cout<<mi;
	
	
	auto stop = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start); 
	//nl;
	//cout << duration.count()/1000 << endl; 
}

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

struct UnionFind{
	vector<ll> rnk,par,num;
	UnionFind(ll N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(ll i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	ll find(ll x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(ll x,ll y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(ll x,ll y){
		return (find(x) == find(y));
	}
	ll size(ll x){
		return num[find(x)];
	}
};

signed main(){
 ll n, m; cin >> n >> m;
 vector<ll> a(m), b(m);
 for(int i = 0; i < m; i++){
   cin >> a[i] >> b[i]; --a[i]; --b[i];
 }
 UnionFind tree(n);
 vector<ll> ans(m);
 ll num = n * (n - 1) / 2;
 for(ll i = m - 1; i >= 0; i--){
   ans[i] = num;
   ll x = a[i], y = b[i];
   if(!tree.same(x, y)){
     num -= tree.size(x) * tree.size(y);
   }
   tree.unite(x, y);
 }
  for(ll i : ans) cout << i << endl;
}


Measured memory_bytes: 6016
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Otoshidama solver = new Otoshidama();
        solver.solve(1, in, out);
        out.close();
    }

    static class Otoshidama {
        int n;
        long y;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            y = in.nextLong();
            for (int i = 0; i <= n; i++) {
                // 10,000
                for (int j = 0; i + j <= n; j++) {
                    // 5,000

                    int k = n - i - j;
                    if (y == calc(i, j, k)) {
                        out.println(String.format("%d %d %d", i, j, k));
                        return;
                    }
                }
            }
            out.println(String.format("%d %d %d", -1, -1, -1));
        }

        private int calc(int x, int y, int z) {
            return 10000 * x + 5000 * y + 1000 * z;
        }

    }
}



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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(ll size) {
        size = max((int) sqrt(size) + 1, 101010);
        prime.resize(size, 1);
        prime[0] = 0;
        prime[1] = 0;
        for (size_t i = 2; i * i <= size; ++i)
            if (prime[i]) {
                for (size_t j = 2; i * j <= size; ++j)prime[i * j] = false;
            }
    }
};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll t1, t2, a1, a2, b1, b2;
string s;
ll N;

int main() {
    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
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;


    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
sl = []
cl = []
for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    sl.append(s)
    cl.append(c)
for i in range(1000):
    digit = list(str(i))
    if len(digit) != N:
        continue
    flag = True

    for j in range(M):
        if int(digit[sl[j]]) != cl[j]:
            flag = False
    if flag:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N, H;

int main() {
  cin >> N >> H;
  vector<int> a(N);
  vector<int> b(N);
  int maxa = 0;
  for (int i=0; i<N; i++) {
    cin >> a.at(i) >> b.at(i);
    if (a.at(i) > maxa) {
      maxa = a.at(i);
    }
  }
  sort(b.begin(), b.end(), greater<>());
  int ans = 0;
  for (int i : b) {
    if (i < maxa) {
      break;
    }
    H -= i;
    ans++;
    if (H<=0) {
      break;
    }
  }
  while (H>0) {
    H -= maxa;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin >> n;
    ll arr[n];
    int mx = 0;
    int k;
    cin >> k;
    int temp;
    int cnt= 0;
    for(int i = 1; i < n; ++i)
    {
        temp = k;
        cin >> k;
        if(temp >= k)
        {
            ++cnt;
            mx = max(mx , cnt);
        }
        else
        {
            cnt = 0;
        }
    }
    cout << mx ;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"

typedef struct _List List;

struct _List {
    int num;
    List* tail;
};

List* Cons(int num,List* tail) {
    List *ret = (List *) malloc(sizeof(List));
    ret->num = num;
    ret->tail = tail;
    return ret;
}

List* gen_cards(uint count){
    List* head= NULL;
    for (uint i=1;i<=count;i++)
        head=Cons(i,head);

    return head;
}

List* cut_cards(List* cards,uint base,uint cut_cum){
    List *old_head=cards,*pth,*pcth,*p_1th;

    if (base==1) return old_head;

    p_1th=old_head;
    for(uint i=2;i<base;i++) p_1th=p_1th->tail;

    pth=p_1th->tail;
    pcth=p_1th;
    for(uint i=0;i<cut_cum;i++) pcth=pcth->tail;

    p_1th->tail=pcth->tail;
    pcth->tail=old_head;

    return pth;

}

void show_list_FILO(List* lst){
    if(lst){
        show_list_FILO(lst->tail);
        printf("%d\n",lst->num);
    }
}

void show_list_FIFO(List* lst){
    if(lst) {
        printf("%d\n", lst->num);
        show_list_FIFO(lst->tail);
    }
}

// read the input and return the first card's value
uint shuffle(){
    uint card_num,shuffle_times;
    scanf("%u %u",&card_num,&shuffle_times);

    //the ending case
    if(card_num==0&&shuffle_times==0)
        return 0;

    List* cards=gen_cards(card_num);
    for (uint i=0;i<shuffle_times;i++){
        uint p,c;
        scanf("%u %u",&p,&c);
        cards=cut_cards(cards,p,c);
    }

    return cards->num;
}

int main() {
    List* result= NULL;
    uint first_card;

    while (first_card=shuffle()){
        result=Cons(first_card,result);
    }

    show_list_FILO(result);

    return 0;
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
int n,m;
char ch[188][188];
int sum[188][188];
int dp[2][188][188][188];
bool eq(int x1,int y1,int x2,int y2)
{
    int siz=(x2-x1+1)*(y2-y1+1);
    int c1=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
    return c1==siz||c1==0;
}
void init()
{
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            sum[i][j]+=sum[i][j-1];
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            sum[i][j]+=sum[i-1][j];
    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
            for(int l=1,r;l<=m;l=r)
            {
                r=l;
                while(eq(i,l,j,r)&&r<=m)r++;
                for(int p=l;p<r;++p)dp[0][i][j][p]=r-1;
                if(l==r)dp[0][i][j][l]=l-1,r++;
            }
}
int find(int c,int u,int d,int L)
{
    int l=u,r=d-1,mid;
    int res=0;
    int v1,v2;
    while(l<=r)
    {
        mid=(l+r)/2;
        v1=dp[c][u][mid][L];
        v2=dp[c][mid+1][d][L];
        res=max(res,min(v1,v2));
        if(v1<v2)r=mid-1;
        else l=mid+1;
    }
    return res;
}
void DP(int c)
{
    int nv,lv;
    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
            for(int l=1;l<=m;++l)
            {
                lv=dp[c^1][i][j][l];
                if(lv!=m)
                {
                    nv=dp[c^1][i][j][lv+1];
                    nv=max(nv,find(c^1,i,j,l));
                }
                else nv=m;
                dp[c][i][j][l]=nv;
            }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        scanf("%s",ch[i]+1);
        for(int j=1;j<=m;++j)
            if(ch[i][j]=='#')sum[i][j]=1;
    }
    init();
    int ans=0;
    for(int i=1;dp[(i&1)^1][1][n][1]<m;++i) DP(i&1),ans=i;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 51584
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    for(;;){
        long long int n,a[5001]={},ma=0,sum=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ma=-1e9;
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ma=max(ma,sum);
            }
        }
        cout<<ma<<endl;
    }
return 0;
}

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

const int maxn = 5e2 + 5;
int a[maxn], b[maxn];

int main() {

    int n, k;
    scanf("%d%d", &n, &k);
    int sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%d", a+i);
        sum += a[i];
    }

    int ans = 0;
    for(int i = 1; i*i <= sum; i++)
        if(!(sum%i)) {

            int d[2] = {i, sum/i};
            for(int j = 0; j < 2; j++) {

                int ssum = 0;
                for(int k = 0; k < n; k++) {
                    b[k] = a[k] % d[j];
                    ssum += b[k];
                }


                nth_element(b, b+n-ssum/d[j]-1, b+n);
                partial_sum(b, b+n-ssum/d[j], b);
                if(b[n-ssum/d[j]-1] <= k)
                    ans = max(ans, d[j]);
            }
        }

    printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256