akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
  string s; cin >> s;
  int k; cin >> k;
  rep(i, s.size()){
    if (s[i] == 'a') continue;
    if ('z'-s[i]+1 <= k){
      k -=('z'-s[i] + 1);
      s[i] = 'a';
    }
  }
  s[s.size()-1] = alpha[(s[s.size()-1]-'a'+k)%26];
  cout << s << endl;
}

Measured memory_bytes: 3744
def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    r = min(r, n - r)
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs = combs % mod * i % mod * pow(j, mod - 2, mod) % mod
    return combs


def main():
    n, a, b = [int(x) for x in input().split()]
    mod = 1000000007
    total = pow(2, n, mod) - 1
    ans = total - combinations_mod(n, a) - combinations_mod(n, b)
    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
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);
        AHappyBirthday solver = new AHappyBirthday();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHappyBirthday {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int res = Math.min(A, B) * 2 + Math.abs(A - B) * 2;
            System.err.println("res = " + res);
            out.println(res <= 16 ? "Yay!" : ":(");

        }

    }
}



Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>

long long fact(n) {
  if (n == 0) {
    return 1;
  } else {
    return n * fact(n - 1);
  }
}

int main(void) {
  int n;

  scanf("%d", &n);
  printf("%lld\n", fact(n));

  return EXIT_SUCCESS;
}

Measured memory_bytes: 592
#include<stdio.h>

int main()
{
  int N,A,B,a[100],i,j,k,b[100],X;
 
  scanf("%d",&N);

  for(i=0;i<100;i++)
  {
    a[i]=0;
    b[i]=0;    
  }
  
  for(i=0;i<N;i++)
  {
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<N;i++)
  {
    X=a[i];
    k=i;
    for(j=0;j<N;j++)
    {
      if(X<a[j])
      {
        X=a[j];
        k=j;
      }
      
    }
 
    b[i]=X;
    a[k]=0;
  }
  
  A=0;
  B=0;
  
  for(i=0;i<50;i++)
  {
    A+=b[2*i];
    B+=b[2*i+1];
    
  }
  
  printf("%d",A-B);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CColon {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            double a = s.nextInt(), b = s.nextInt(), h = s.nextInt(), m = s.nextInt();
            double thetaA = 2 * Math.PI * (h * 60 + m) / (12 * 60);
            double thetaB = 2 * Math.PI * m / 60;
            double xa = a * Math.cos(thetaA), ya = a * Math.sin(thetaA);
            double xb = b * Math.cos(thetaB), yb = b * Math.sin(thetaB);
            double dist = Math.sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
            w.println(dist);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 33276
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b=num)
{
    return ((a%b)+b)%b;
}
bool prime[200000];
vll v;
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            v.push(p);
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[60];
void power()
{
    powe[0]=1;
    REP(i,1,15)
    {
        powe[i]=2*powe[i-1];
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m=num) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll fact[100005];
void factorial()
{
    fact[0]=1;
    REP(i,1,100002)
    {
        fact[i]=mymod(i*fact[i-1], num);
    }
}
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool my(pll p1,pll p2)
{
    if(p1.f<p2.f) return true;
    if(p1.f==p2.f && p1.s<p2.s) return true;
    return false;
}
bool isprime(ll n)
{
    REP(i,2,sqrt(n))
    {
        if(n%i==0)
        return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h,a;
    cin>>h>>a;
    
    if(h%a)
    {
        cout<<h/a+1;
    }
    else
    {
        cout<<h/a;
    }
	return 0;
}


Measured memory_bytes: 256
S=input()
S=int(S)
h=S/3600
h=int(h)
m=(S-3600*h)/60
m=int(m)
s=S-h*3600-m*60
s=int(s)
h=str(h)
m=str(m)
s=str(s)
print(h+':'+m+':'+s)
 

Measured memory_bytes: 6732
#include <stdio.h>

#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}


Measured memory_bytes: 2624
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let a: Vec<usize> = parse!(it, n);
    let b: Vec<usize> = parse!(it, n);
    let mut dp = vec![vec![None; n]; 1 << n];
    let diff = |x, y| if x > y { x - y } else { y - x };
    let v = |i: usize, to: usize| {
        if diff(i, to) % 2 == 1 {
            b[i]
        } else {
            a[i]
        }
    };
    for i in 0..n {
        dp[1 << i][i] = Some(0);
    }
    for i in 1usize..(1 << n) {
        let r = i.count_ones() as usize;
        for j in 0..n {
            if let Some(x) = dp[i][j] {
                for k in 0..n {
                    if (i >> k) & 1 == 1 || j == k || v(j, r - 1) > v(k, r) {
                        continue;
                    }
                    let largerk = (i & (!((1 << k) - 1))).count_ones() as usize;
                    dp[i | (1 << k)][k] = match dp[i | 1 << k][k] {
                        Some(y) => Some(std::cmp::min(y, x + largerk)),
                        None => Some(x + largerk),
                    }
                }
            }
        }
    }
    let mut ret = None;
    for i in 0..n {
        ret = match dp[(1 << n) - 1][i] {
            None => ret,
            Some(x) => match ret {
                None => Some(x),
                Some(ret) => Some(std::cmp::min(x, ret)),
            },
        }
    }
    match ret {
        None => println!("{}", -1),
        Some(x) => println!("{}", x),
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
3
3 4 3
3 2 3
        ";
        solve(s);
    }
}


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

int main() {
  long long H;
  cin >> H;
  long long wari = 0;
 while(H > 1){
   H /= 2;
   wari++;
 }
  long long ans = 1;
 while(wari > -1){
   ans *= 2;
   wari--;
 }
  cout << ans-1 << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)

def kai(s):
  n = len(s)
  if n % 2 != 0:
    if s[:int((n-1)/2)] == s[int((n+1)/2):][::-1]:
      return True
    else:
      return False
  else:
    if s[:int(n/2)] == s[int(n/2):][::-1]:
      return True
    else:
      return False

s1 = s[:int((n-1)/2)]
s2 = s[int((n+1)/2):]
#print(s, s1, s2)
#print([kai(s),kai(s1),kai(s2)])
if sum([kai(s),kai(s1),kai(s2)]*1) == 3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(all(d));
    int ans = d[n/2] - d[n/2-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <tuple>
#include <vector>
#include <map>
#include <iterator>
#include <cmath>

using namespace std;
using lint = long long int;

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	}

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

	bool canDecrease = true;
	h[0] = max(h[0]-1, 1);

	for (int i = 1; i < n; i++) {
		int diff = h[i] - h[i - 1];
		if (diff >= 1) {
			h[i] = max(h[i]-1, 1);
		}
		else if (diff < 0) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

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

#define MAXN 1000010
#define mod 1000000007

int n,f[MAXN],add;

int main()
{
    scanf("%d",&n);
    f[n]=n;
    f[n-1]=(long long)n*n%mod;
    for(int i=n-2;i>=1;--i)
    {
        add=(add+f[i+3])%mod;
        f[i]=f[i+1];
        f[i]=(f[i]+(long long)(n-1)*(n-1)%mod)%mod;
        f[i]=(f[i]+add)%mod;
        f[i]=(f[i]+i+1)%mod;
    }
    printf("%d\n",f[1]);
}

Measured memory_bytes: 4096
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    val len = Array.fill[Array[Int]](N)(Array.fill[Int](N)(Int.MaxValue / 6))
    for (idx <- 0 until N) {
      len(idx)(idx) = 0
      val now = sc.nextInt - 1
      val count = sc.nextInt
      for (idx2 <- 0 until count) {
        len(now)(sc.nextInt - 1) = 1
      }
    }

    for (k <- 0 until N) {
      for (i <- 0 until N) {
        for (j <- 0 until N) {
          len(i)(j) = Math.min(len(i)(j), len(i)(k) + len(k)(j))
        }
      }
    }

    val P = sc.nextInt
    for (idx <- 0 until P) {
      val s, d = sc.nextInt - 1
      val v = sc.nextInt
      if (len(s)(d) + 1 <= v) {
        println(len(s)(d) + 1)
      } else {
        println("NA")
      }
    }
  }

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

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

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

vector<bool> sieve(1000007,true);

void help(){
     sieve[0] = false;
     sieve[1] = false;

     for(int i=2;i*i<=1000000;++i){
        if(sieve[i]){
            for(int j=i*i;j<=1000000;j+=i)
                sieve[j] = false;

        }
     }


}

int main() {
   fastIO



   int t;
   cin>>t;
   unordered_map<string,int> mp;
   int n = t;
   while(n--){
    string s;
    cin>>s;
   sort(s.begin(),s.end());

     mp[s]++;

   }

   ll ans = 0;
   for(auto x:mp)
   {
        ll n = x.second;
        ans+= (n*(n-1))/2;
   }

   cout<<ans;



   return 0 ;
      }


Measured memory_bytes: 10788
import java.util.Scanner;
 
public class Main{
 
public static void main(String[] args) {
 
Scanner keyboard = new Scanner(System.in);
int A, B, C;
 
A = keyboard.nextInt();
B = keyboard.nextInt();
C = (A-1) * (B-1);
 
System.out.print(C);
 
keyboard.close();
}
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define int long long 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int maxn=1e5+6;
const int mod=1e9+7;
const double pi = acos(-1.0);
int n,m;
int a[maxn];
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
void write(int x){        
    if(x < 0) {        
        putchar('-');        
        x = -x;        
    }        
    if(x > 9)        
        write(x/10);        
    putchar(x % 10 + '0');        
    return;        
}   
signed main(){
	cin>>n>>m;
	int ans=0;
	for(int i=1;i<=m;i++)
	   cin>>a[i],ans+=a[i];
	if(ans>n)
	    cout<<"-1"<<endl;
	else 
	    cout<<n-ans<<endl;
	return 0;
} 


Measured memory_bytes: 3664
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200

int V;
vector<int> G[NUM];
int match[NUM];
bool used[NUM];

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

int dfs(int node_id) {
	used[node_id] = true;

	for (int i = 0; i < G[node_id].size(); i++) {
		int adj_node_id = G[node_id][i], pair_id = match[adj_node_id];
		if ((pair_id < 0) || (used[pair_id] == false && dfs(pair_id) == true)) {
			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;
			return true;
		}
	}
	return false;
}


int bipartie_matching() {
	int ret = 0;
	for (int i = 0; i < V; i++)match[i] = -1;
	for (int node_id = 0; node_id < V; node_id++) {
		if (match[node_id] < 0) {
			for (int i = 0; i < V; i++)used[i] = false;
			if (dfs(node_id)) {
				ret++;
			}
		}
	}
	return ret;
}


int main() {

	int n;
	int redx[100], redy[100], bluex[100], bluey[100];

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

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

	int X, Y, E;

	X = n;
	Y = n;

	int from, to;

	for (int i = 0; i < n; i++) 
		for(int j=0;j<n;j++) {
			if (redx[i] < bluex[j] && redy[i] < bluey[j]) {
				from = i;
				to = j;
				add_edge(from, X + to);
			}
		}

	V = X + Y;

	printf("%d\n", bipartie_matching());

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int n;
	cin >> n;
	cout << 48 - n << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,now,ans;
char u;
int main()
{
    cin>>a;
    for(int s=0;s<a;s++)
    {
        cin>>u;
        if(u=='I')now++;
        else
        now--;
        ans=max(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  unordered_set<int> record;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (record.find(a) != record.end()) {
      cout << "NO" << endl;
      return 0;
    } else {
      record.insert(a);
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 8520
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

int main() {
		int N;
		cin >> N;
		vector<pair<int, int>> task(N);
		for (int i = 0; i < N; i++) {
				cin >> task[i].first >> task[i].second;
		}

		sort(ALL(task), [](const pair<int, int> &a, const pair<int, int> &b) {
				return a.second < b.second;
		});

		ll t = 0;
		for (int i = 0; i < N; i++) {
				t += task[i].first;
				if (t > task[i].second) {
						cout << "No" << endl;
						return 0;
				}
		}

		cout << "Yes" << endl;
		return 0;
}


Measured memory_bytes: 1792
/***************************************************************
	File name: A.cpp
	Author: ljfcnyali
	Create time: 2019年08月17日 星期六 19时45分34秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

/* dp[i][2] */

const int maxn = 200010;

int n, dp[maxn][3];
char s[maxn];

int main()
{
    scanf("%s", s + 1); n = str(s + 1);
    REP(i, 1, n)
    {
        if ( s[i] != s[i - 1] ) dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1);
        if ( i > 1 ) dp[i][1] = max(dp[i][1], dp[i - 1][2] + 1);
        if ( i > 1 ) dp[i][2] = max(dp[i][2], dp[i - 2][1] + 1);
        if ( i > 2 && s[i] != s[i - 2] && s[i - 1] != s[i - 3] ) dp[i][2] = max(dp[i][2], dp[i - 2][2] + 1);
    }
    printf("%d\n", max(dp[n][1], dp[n][2]));
    return 0;
}

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

using namespace std;

int main(){
 int n,m;
  cin >> n;
 vector<int> t(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> t[i];
    sum+=t[i];
  }
  
  cin >> m;
  int p,x;
  for(int i=0;i<m;i++){
   cin >> p >> x;
   cout << sum-t[p-1]+x << endl;
  }



}

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

int main()
{
  string s;
  cin >> s;
  
  int len = s.size();
  int count = 0;
  for (int i = 0; i < len / 2; i ++)
    if (s.at(i) != s.at(len - (i + 1)) ) count ++;
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll ans;

int main(void) {
    ll x;
    cin >> x;
    ans += (x/500)*1000;
    x %= 500;
    ans += (x/5)*5;
    

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
    int n;
    cin >> n;
    string x;
    cin >> x;
    int count = 0;
    int f=0;
    int l = n-1;
    while(f<l)
    {
        if(x[f]=='R')
        {
       f++;
       continue;
        }

        if(x[l]=='W')
        {
        l--;
        continue;
        }
        count++;
        f++;
        l--;
    }
    cout << count;
    return 0;
}

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

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

  int maxv = -1000000000;
  int minv;
  cin >> minv;
  // O(N)
  for (int i = 1; i < n; i++) {
    int r;
    cin >> r;
    maxv = max(maxv, r - minv);
    minv = min(minv, r); // 次のループで利用する、i-1 までの要素の中で最小の値を取得する
  }

  cout << maxv << endl;
  return 0;
}


Measured memory_bytes: 3096
H = int(input())
A = [None]
A.extend(list(map(int,input().split())))
for i in range(1, H+1):
    print(f"node {i}: key = {A[i]}, " 
        + (f"parent key = {A[int(i/2)]}, " if i > 1 else "")
        + (f"left key = {A[i*2]}, " if i*2 <= H else "")
        + (f"right key = {A[i*2+1]}, " if i*2+1 <= H else "")
    )


Measured memory_bytes: 5632
N = int(input())
v = list(map(int, input().split()))

v.sort()
while True:
  x = v[0]
  y = v[1]
  z = (x+y) / 2
  v.pop(0)
  v.pop(0)
  v.append(z)
  v.sort()
  if len(v) == 1:
    break
  else:
    pass
  

print(z)

Measured memory_bytes: 9104
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

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

void solve() {
    int H, W; cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) cin >> s[i];

    bool ok = true;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                bool flag = false;
                for (int k = 0; k < 4; k++) {
                    int nx = i + dx[k], ny = j + dy[k];
                    if (nx >= 0 && nx < H && ny >= 0 && ny < W) {
                        if (s[nx][ny] == '#') flag = true;
                    }
                }
                if (!flag) ok = false;
            }
        }
    }

    cout << (ok ? "Yes" : "No") << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3632
ds=gets.split(" ").map{|e| e.to_i}
n=ds[0]
k=ds[1]
mod=10**9+7
arr=[]
i=1
while i*i<=n
	arr<<i
	if i*i<n && n/i!=i
		arr<<n/i
	end
	i=i+1
end
arr.sort!.reverse!<<0
arr2=[]
arr3=[]
arr4=[]
(arr.size-1).times{|e|
	arr2<<(arr[e]-arr[e+1])
	arr3<<0
	arr4<<arr[e]-arr[e+1]
}

arr2<<0
arr3<<0

(k-1).times{
	sum=0
	arr2.size.times{|i|
		arr3[i]=arr2[i]
	}
	
	sum=0
	(arr2.size-1).times{|i|
		p2=i
		sum=(sum+arr3[arr2.size-2-i])%mod
		arr2[p2]=(sum*arr4[p2])%mod
	}
}
ans=0
arr2.each{|t| ans=(ans+t)%mod}
p ans

Measured memory_bytes: 7328
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n=int(input())
    a = [int(x)%2 for x in input().split()]
    print(sum(a[::2]))

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 62660
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

const int MOD=998244353;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    vi d(n);
    vi f(n);
    int maxD=-1;
    for(int i=0; i<n; i++) {
        cin>>d[i];
        f[d[i]]++;
        maxD=max(maxD, d[i]);
        if(i>0 && d[i]==0) {
            cout<<0<<endl;
            return 0;
        }
    }

    if(d[0]!=0) {
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;
    for(int i=2; i<=maxD; i++) {
        for(int j=0; j<f[i]; j++) {
            ans*=f[i-1];
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int T,N;
int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	cin>>T;
	cout<<arr[T-1]<<endl;


}

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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d), last(n);
	rep(i, d) {
		cin >> t[i];
		t[i]--;
	}
	int m;
	cin >> m;
	vector<int> qd(m), qq(m);
	rep(i, m) {
		cin >> qd[i] >> qq[i];
		qd[i]--;
		qq[i]--;
	}
	rep(Q, m) {
		// 点数のシミュレーション
		t[qd[Q]] = qq[Q];
		vector<int> nlast(n);
		ll now = 0;
		rep(i, d) {
			now += s[i][t[i]];
			nlast[t[i]] = i+1;
			rep(j, n) {
				now -= c[j] * (i+1-nlast[j]);
			}
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 3828
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int a[26];
char s[200100];
long long sum;
int main(void)
{
	int i,j,k,n,m,l;
	memset(a,0,sizeof(a));
	scanf("%s",s);
	l=strlen(s);
	sum=1;
	for(i=l-1;i>=0;i--)
	{
		a[s[i]-'a']++;
		for(j=0;j<26;j++)
		{
			if(j!=s[i]-'a')
			sum+=a[j];
		}
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 384
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n,m,X,Y = f()
x = f()
y = f()

if min(y) - max(x) >= 1 and min(y) - X >= 1 and Y - max(x) >= 1:
    print("No War")
else:
    print("War")

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


int main() {
int N;
cin >> N;
int worker[200010];
for(int i = 0; i < N-1; i++){
    cin >> worker[i];
}
int buka[200010];

for(int i = 0; i <= N; i++){
   buka[i] = 0;
}
for(int i = 0; i < N-1; i++){
   buka[worker[i]-1]++;
}
for(int i = 0; i < N; i++){
   cout << buka[i] << endl;
}

}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    std::vector<int>num;
    for(int i =0; i<n; i++)
    {
        int temp;
        cin>>temp;
        num.push_back(temp);
    }
    int temp=num[0], count =1;
    for(int i=1; i<n; i++)
    {
        temp= min(temp,num[i]);
        if(temp==num[i]) count++;
        
        
    }
    std::cout << count << std::endl;
    return 0;
}

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

int main(int argc, char* argv[])
{
    vector<int> vec;
    int a, b, c;
    cin >> a >> b >> c;
    vec.push_back(a);
    vec.push_back(b);
    vec.push_back(c);

    sort(vec.begin(), vec.end());
    cout << vec[0] << " " << vec[1] << " " << vec[2] << endl;
    //Junsang****for(vector<int>::iterator it=vec.begin(); it!=vec.end(); it++)
    //Junsang****{
        //Junsang****cout << *it << " ";
    //Junsang****}
    return 0;
}



Measured memory_bytes: 3152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define recp(I,Y,X) {q[I].x=X;q[I].y=Y;m[Y][X]='X';I++;}
char m[1005][1005],m2[1005][1005];
typedef struct point{
	int x,y;
}POINT;
POINT sq[500],q[500],g[11];
int h,w,n,i,j,ans=0,gx,gy,cx,cy,sqn,qn;
int main(){
	char s[1005];
	scanf("%d%d%d",&h,&w,&n);
	for(i=0;i<=w+1;i++)m[0][i]=m[h+1][i]='X';
	for(i=1;i<=h;i++){
		scanf("%s",s);
		strcat(m[i]+1,s);
		for(j=1;j<=w;j++){
			if(m[i][j]=='S')g[0].y=i,g[0].x=j;
			else if(m[i][j]!='.' && m[i][j]!='X')g[m[i][j]-'0'].y=i,g[m[i][j]-'0'].x=j;
		}
		m[i][0]=m[i][w+1]='X';
	}
	memcpy(m2,m,sizeof(m));
	for(i=1;i<=n;i++){
		sq[0].x=g[i-1].x,sq[0].y=g[i-1].y;
		m[g[i-1].y][g[i-1].x]='X',gx=g[i].x,gy=g[i].y;sqn=1;
		//printf("%d %d\n",sq[0].y,sq[0].x);
		//printf("%d %d\n",gy,gx);
		while(sqn){
			qn=0;
			//printf("\n");
			for(j=0;j<sqn;j++){
				cx=sq[j].x;cy=sq[j].y;
				//printf("%d %d\n",cy,cx);
				if(cx==gx && cy==gy)goto nex;
				if(m[cy-1][cx]!='X')recp(qn,cy-1,cx);
				if(m[cy+1][cx]!='X')recp(qn,cy+1,cx);
				if(m[cy][cx-1]!='X')recp(qn,cy,cx-1);
				if(m[cy][cx+1]!='X')recp(qn,cy,cx+1);
			}
			memcpy(sq,q,sizeof(POINT)*qn);
			//printf("%d\n",qn);
			sqn=qn;
			ans++;
		}
		nex:
		memcpy(m,m2,sizeof(m2));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2360
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int n;
    cin >> n;
    auto a = vector<int>(n);
    for (auto& a_i : a) {
        cin >> a_i;
    }
    sort(a.begin(), a.end());

    auto factors = vector<vector<int>>(1'000'005);
    for (int a_i = 1; a_i <= 1'000'000; ++a_i) {
        auto x = a_i;
        factors[a_i].push_back(1);

        if (x % 2 == 0) {
            do { x /= 2; } while (x % 2 == 0);
            factors[a_i].push_back(2);
        }
        if (x % 3 == 0) {
            do { x /= 3; } while (x % 3 == 0);
            factors[a_i].push_back(3);
        }

        for (int d = 5; d * d <= x;) {
            if (x % d == 0) {
                do { x /= d; } while (x % d == 0);
                factors[a_i].push_back(d);
            }
            d += 2;
            if (x % d == 0) {
                do { x /= d; } while (x % d == 0);
                factors[a_i].push_back(d);
            }
            d += 4;
        }

        if (x > 1) {
            factors[a_i].push_back(x);
        }
    }

    auto factor_count = vector<int>(1'000'000);
    for (auto a_i : a) {
        for (auto f : factors[a_i]) {
            factor_count[f]++;
        }
    }

    auto sharing = 0;
    for (auto f = 1; f <= 1'000'000; ++f) {
        if (f == 1) continue;
        sharing = max(sharing, factor_count[f]);
    }
    if (sharing <= 1) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    if (sharing < n) {
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 69768
import java.util.Scanner;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        char[] c = s.toCharArray();
        int maxcnt = 0;
        for(int i = 0;i < n;i++){
            String str1 = s.substring(0,i+1);
            String str2 = s.substring(i+1);
            char[] c1 = str1.toCharArray();
            char[] c2 = str2.toCharArray();
            Arrays.sort(c1);
            Arrays.sort(c2);
            //Map<Character,Integer> map2 = new HashMap<Character,Integer>();
            //for(int j = 0;j < c1.length;j++){
            //    map1.put(c1[j],1);
            //}
            //for(int j = 0;j < c2.length;j++){
            //    map2.put(c2[j],1);
            //}
            //System.out.println(Arrays.toString(c1));
            //System.out.println(Arrays.toString(c2));
            //for(Character str : map1.keySet()){
            //    for(Character val : map2.keySet()){
            //        if(map2.containsKey(map1.get(str))){
            //            cnt++;
            //        }
            //    }
            //}
            //System.out.println("str1 = " + str1);
            //System.out.println("str2 = " + str2);
            //System.out.println(Arrays.toString(c1));
            //System.out.println(Arrays.toString(c2));
            //System.out.println("cnt = " + cnt);
            int cnt = count(c1,c2);
            maxcnt = Math.max(maxcnt,cnt);
        }
        System.out.println(maxcnt);
    }
    public static int count(char[] c1,char[] c2){
        int cnt = 0;
        for(int j = 0;j < c1.length;j++){
            if(j < c1.length -1 && c1[j] == c1[j+1]){
                continue;
            }
            for(int k = 0;k < c2.length;k++){
                if(c1[j] == c2[k]){
                    cnt++;
                    break;
                }
            }
        }
        return cnt;
    }
}


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

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

  if (a < b) {
    cout << "a < b" << endl;
  }

  if (a > b) {
    cout << "a > b" << endl;
  }

  if (a == b) {
    cout << "a == b" << endl;
  }

return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define inf (1<<29)
#define sq(n) ((n)*(n))
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define MEMSET(a) memset(a,0,sizeof(a))
using namespace std;

int main(){
	int N,M,R;
	scanf("%d %d %d",&N,&M,&R);
	vector<int> r(R);
	rep(i,R){
		scanf("%d",&r[i]);
		r[i]--;
	}
	int g[N][N]={};
	rep(i,N)rep(j,N)if(i!=j)g[i][j]=inf;
	rep(i,M){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		a--;
		b--;
		g[a][b]=g[b][a]=c;
	}
	rep(k,N)rep(i,N)rep(j,N)if(g[i][j]>g[i][k]+g[k][j])g[i][j]=g[i][k]+g[k][j];
	sort(r.begin(),r.end());
	int ans=inf;
	do{
		int t=0;
		rep(i,R-1)t+=g[r[i]][r[i+1]];
		ans=min(ans,t);
	}while(next_permutation(r.begin(),r.end()));
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
vector<long long> v[100010];
int a[100010] = {};
int main(){
	int i,j,q;
	for(i=1;i<=100000;i++){
		for(j=i;j<=100000;j+=i){
			v[j].push_back(i);
		}
	}
	for(i=1;i<=100000;i++){
		a[i] = a[i-1];
		long long res = 1;
		for(j=0;j<v[i].size() - 1;j++){
			res *= v[i][j];
			if(res>=2*(long long)i){
				a[i]++;
				break;
			}
		}
	}
	cin >> q;
	for(i=0;i<q;i++){
		int n; cin >> n;
		cout << a[n] << endl;
	}
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans;
  cin >> n;
  vector<ll> a(n), b(n);

  rep(i, n) cin >> a[i] >> b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  if (n & 1) {
    ans = b[n / 2] - a[n / 2] + 1;
  } else {
    ans = b[n / 2] + b[n / 2 - 1] - (a[n / 2] + a[n / 2 - 1]) + 1;
  }

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


Measured memory_bytes: 6328
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[5111];
long long l[5011];
int j[5551];

long long x,y,z,mod=1000000007;
string r;
//char r[111];

P u[1];
queue<int> q;

stack<int> s;
map<int,int> p;
vector<int> v;

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

int main()
{
  scanf("%d %d",&a,&b);
  for(int t=1;t<=a;t++)
  scanf("%lld",&o[t]);
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d %d",&n,&c,&m);
    n--;
    x=c%m;
    for(int t=1;t<=a;t++)
    {
      l[t]=l[t-1]+o[t]%m;
      j[t]=j[t-1];
      if(o[t]%m==0) j[t]++;
    }
    x+=(n/a)*l[a]+l[n%a];
    printf("%lld\n",n-x/m-j[a]*(n/a)-j[n%a]);
  }
}





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

int main(){
    long long N, M, A[100000], sum = 0, ans = 0;
    unordered_map<long long, int> mp;
    cin >> N >> M;
    mp[0] = 1;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
        sum %= M;
        ans += mp[sum];
        mp[sum]++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 4108
n = int(input())
A = list(int(x) for x in input().split())

ma = max(A)
mi = min(A)

if ma - mi > 1:
    print("No")
    exit()

if ma == mi:
    if n >= ma * 2 or n == ma + 1:
        print("Yes")
    else:
        print("No")
    exit()

# ma = mi + 1
if A.count(mi) <= mi and A.count(ma) >= (ma - A.count(mi)) * 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 81672
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int ans;
bool used[10];
int table[10][10],position[10];

void recursive(int loc,int count){

	if(count == N){
		ans = min(ans,loc);
		return;
	}

	int next_loc;

	for(int i = 0; i < N; i++){
		if(used[i])continue;

		//既に配置済の人物から、次の配置場所を特定する

		next_loc = loc;
		for(int k = 0; k < N; k++){
			if(!used[k])continue;
			if(loc-position[k] >= table[i][k])continue; //必要以上離れていればSKIP

			next_loc = max(next_loc,position[k]+table[i][k]);
		}

		if(next_loc >= ans)continue; //次の場所がans以上ならskip

		used[i] = true;
		position[i] = next_loc;
		recursive(next_loc,count+1);
		used[i] = false;
		position[i] = -1;
	}
}

void func(){

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++)scanf("%d",&table[row][col]);
	}

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			table[row][col] = max(table[row][col],table[col][row]);
		}
	}

	for(int i = 0; i < N; i++){
		used[i] = false;
		position[i] = -1;
	}

	ans = BIG_NUM;

	for(int first = 0; first < N; first++){
		position[first] = 0;
		used[first] = true;
		recursive(0,1);
		position[first] = -1;
		used[first] = false;
	}

	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3092
def main():
	n, m, *L = map(int, open(0).read().split())
	AB = L[:2 * m]
	Q = L[2 * m + 1:][::-1]
	G = [[] for _ in range(n)]
	C = [0] * n
	D = [-1] * n
	for a, b in zip(*[iter(AB)] * 2):
		a -= 1
		b -= 1
		G[a] += [b]
		G[b] += [a]
	for c, d, v in zip(*[iter(Q)] * 3):
		if D[v - 1] >= d:
			continue
		D[v - 1] = d
		q = [v - 1]
		while q:
			cur = q.pop()
			dd = D[cur]
			if not C[cur]:
				C[cur] = c
			if not dd:
				continue
			for nxt in G[cur]:
				if D[nxt] >= dd - 1:
					continue
				D[nxt] = dd - 1
				q.append(nxt)
	print("\n".join(map(str, C)))

if __name__=="__main__":
	main()


Measured memory_bytes: 125764
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;
int o[105];
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    long long ans,sum;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>o[i];
        ans=1e9;
        for(int i=1;i<=100;i++)
        {
            sum=0;
            for(int j=0;j<n;j++)
            {
                sum+=(o[j]-i)*(o[j]-i);
            }
            ans=min(ans,sum);
        }
        cout<<ans<<endl;
    }
    return 0;
}



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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]==','){
      cout<<" "<<flush;
    }else{
      cout<<s[i]<<flush;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static StringBuilder builder = new StringBuilder();
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++)
			A[i] = scanner.nextInt();
		
		trace(A, n);

		for (int i = 1; i < n; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			trace(A, n);
		}
		System.out.print(builder);
	}

	private static void trace(int[] A, int n) {
		for (int i = 0; i < n; i++) {
			if (i > 0)
				builder.append(" ");
			builder.append(A[i]);
		}
		builder.append("\n");
	}
}

Measured memory_bytes: 18960
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

void dijkstra(int s, vector<int> &d, vector<vector<pair<int,int>>> &G){
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
	
	d.clear();
	d.resize(G.size(),INF);
	d[s] = 0;
	q.push(make_pair(0,s));
	
	while(!q.empty()){
		pair<int,int> p = q.top();q.pop();
		int v = p.second;
		
		if(d[v] < p.first) continue;
		
		for(pair<int,int> e : G[v]){
			if(d[e.first] > d[v] + e.second){
				d[e.first] = d[v] + e.second;
				q.push(make_pair(d[e.first],e.first));
			}
		}
	}	
}


signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, X, Y;
	vector<int> ans;
	vector<vector<pair<int,int>>> G;
	
	
	cin>>N>>X>>Y;
	
	ans.resize(N);
	G.resize(N);
	
	X--, Y--;
	
	G[X].push_back({Y,1});
	
	for(int i = 1; i < N; i++){
		G[i].push_back({i-1,1});
		G[i-1].push_back({i,1});
	}
	
	for(int i = 0; i < N; i++){
		vector<int> d;
		
		dijkstra(i,d,G);
		
		for(int j = i+1; j < N; j++){
			ans[d[j]]++;
		}
	}
	
	for(int i = 1; i < N; i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2020,oo=1000000000;
int i,j,k,n,m,ch,fga,fgb,num,ans,res;
int l[N],r[N],ma[N];
char A[N],B[N];
int main() {
	ans=oo;
	scanf("%s",A);
	scanf("%s",B);
	n=strlen(A);
	fga=fgb=-1;
	for (i=0;i<n;i++) if (A[i]=='1') { fga=i;break;}
	for (i=0;i<n;i++) if (B[i]=='1') { fgb=i;break;}
	if (fgb==-1) {
		if (fga==-1) puts("0");
		else puts("-1");
		return 0;
	}
	for (i=fgb;i<fgb+n;i++) {
		if (B[i%n]=='1') num=0;
		else num++;
		l[i%n]=num;
	}
	for (i=fgb+n;i>fgb;i--) {
		if (B[i%n]=='1') num=0;
		else num++;
		r[i%n]=num;
	}
	for (i=0;i<n;i++) {
		res=i;
		memset(ma,0,sizeof ma);
		for (j=0;j<n;j++) if (A[(j+i)%n]!=B[j]) {
			res++;
			int a=max(0,l[(j+i)%n]-i);
			ma[a]=max(ma[a],r[(j+i)%n]);
		}
		for (j=n-1;j>=0;j--) ma[j]=max(ma[j],ma[j+1]);
		for (j=0;j<n;j++) ans=min(ans,res+2*(j+ma[j+1]));
	}
	for (i=0;i<n;i++) {
		res=i;
		memset(ma,0,sizeof ma);
		for (j=0;j<n;j++) if (A[j]!=B[(i+j)%n]) {
			res++;
			int a=max(0,r[j%n]-i);
			ma[a]=max(ma[a],l[j%n]);
		}
		for (j=n-1;j>=0;j--) ma[j]=max(ma[j],ma[j+1]);
		for (j=0;j<n;j++) ans=min(ans,res+2*(j+ma[j+1]));
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256