akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,l,r,ans;
int main(){
	
	ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		ans+=r;
		ans-=l;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  cin >> x >> y;
  vector<int> v(12);
  v={1,3,1,2,1,2,1,1,2,1,2,1};
  if (v[x-1]==v[y-1]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    string inp, str;
    int n;
    while(cin >> inp >> n){
        int ans = 0;
        rep(i,n){
            cin >> str;
            str+=str;
            rep(j,10){
                if(str.find(inp, j) != string::npos){
                    ans++;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,h[100000];
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>h[i];
	sort(h,h+n);
	int ans=1e9;
	for(int i=0;i+k-1<n;i++)
		ans=min(ans,h[i+k-1]-h[i]);
	cout<<ans<<endl;
}


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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll d[n];
  for(int i=0;i<n;i++)cin >> d[i];

  ll s=0;

  for(ll i=0;i<n-1;i++){
    for(ll j=i+1;j<n;j++){
      s+=d[i]*d[j];
    }
  }

  cout << s << endl;


}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
// using Graph = vector<vector<Edge>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

struct edge {
    ll to, cost;
};
typedef pair<ll, ll> P_dij;

vector<ll> dijkstra(ll s, ll n, vector<edge> G[])
{
    vector<ll> d = {};
    long long INF = 10000000000000000;
    d.resize(n);
    for (int i = 0; i < n; i++) {
        d[i] = INF;
    }
    priority_queue<P_dij, vector<P_dij>, greater<P_dij>> que;
    d[s] = 0;
    que.push(P_dij(0, s));
    while (!que.empty()) {
        P_dij p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) // ここを通り抜けたvに関して，確定
            continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P_dij(d[e.to], e.to));
            }
        }
    }
    return d;
}

ll i, j, k;
vector<edge> edge_yen[200001];
vector<edge> edge_snu[200001];
int main()
{
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    for (i = 0; i < m; i++) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        edge e1;
        e1.to = v, e1.cost = a;
        edge_yen[u].push_back(e1);
        edge e2;
        e2.to = u, e2.cost = a;
        edge_yen[v].push_back(e2);
        edge e3;
        e3.to = v, e3.cost = b;
        edge_snu[u].push_back(e3);
        edge e4;
        e4.to = u, e4.cost = b;
        edge_snu[v].push_back(e4);
    }

    vector<ll> dist_yen = dijkstra(s, n + 1, edge_yen);
    vector<ll> dist_snu = dijkstra(t, n + 1, edge_snu);

    ll ans[200001];
    ll Max = 0;
    ll FIRST = 1e15;
    // 強制約から考えていく
    for (i = n; i >= 1; i--) {
        ll val = FIRST - (dist_yen[i] + dist_snu[i]);
        Max = max(val, Max);
        ans[i] = Max;
    }
    for (i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 25804
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    auto n = sread();
    // writeln(n);
    if ((n[0] == n[1]) && (n[0] == n[2]))
    {
        writeln("Yes");
        return;
    }
    if ((n[1] == n[2]) && (n[1] == n[3]))
    {
        writeln("Yes");
        return;
    }
    writeln("No");

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


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

using namespace std;

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

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

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

  int total = accumulate(a.begin(), a.end(), 0);

  if (a[m - 1] < 1 / (4. * m) * total)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
void printer(char c, int dist) {
    for(int i = 0; i < dist; i++)
        cout << c;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, y, endx, endy;
    cin >> x >> y >> endx >> endy;
    int distx = abs(endx - x), disty = abs(endy - y);
    printer('U', disty);
    printer('R', distx);
    printer('D', disty);
    printer('L', distx);
    cout << 'L';
    printer('U', disty + 1);
    printer('R', distx + 1);
    cout << "DR";
    printer('D', disty + 1);
    printer('L', distx + 1);
    cout << 'U';
}

Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int k=scan.nextInt();
int n=scan.nextInt();
int[] a=new int[n];

int i=0;
for(i=0;i<n;i++){
    a[i]=scan.nextInt();
}
Arrays.sort(a);
int[] b=new int[n];
for(i=0;i<n-1;i++){
  b[i]=a[i+1]-a[i];
}
b[n-1]=k-a[n-1]+a[0];
Arrays.sort(b);

System.out.println(k-b[n-1]);


}
}

Measured memory_bytes: 82272
use std::io;


fn main() {
    let s = read_one::<String>();
    let ans = match s.as_str() {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => unreachable!(),
    };
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
from itertools import accumulate
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

def solve(N,queries):
    N -= 2
    X = [0]*(N+1)
    Y = [0]*(N+1)

    for a,b in queries:
        if b == 0:
            continue
        if a == 0:
            X[b] += 1
        else:
            Y[b] += 1
    X = tuple(accumulate(X))
    Y = tuple(accumulate(Y))
    w = N
    h = N

    res = 0
    for a,b in queries:
        # print('i',a,b)
        b -= 1
        if a == 0:
            if w > b:
                # print(X[w]-X[b],h)
                res += (X[w]-X[b])*h
                w = b
        else:
            if h > b:
                # print((Y[h]-Y[b]),w)
                res += (Y[h]-Y[b])*w
                h = b
    return N*N - res



if __name__ == '__main__':
    N,Q = map(int, readline().split())
    m = map(lambda x: int(x)-1, read().split())

    queries = tuple(zip(m,m))

    print(solve(N,queries))

Measured memory_bytes: 49656
#include <iostream>
#include <set>
using namespace std;
int main(void){
    int N;
    int d[110];
    
    cin >> N;
    for(int i = 0; i < N; ++i) cin >> d[i];
    
    set<int> values;
    for(int i = 0; i < N; ++i){
        values.insert(d[i]);
    }
    
    cout << values.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int x,y,z;
  cin >> x;
  y = x / 100;
  z = x - (y*100);
  if (z % 5 == 0){
    if (z/5 > y){
      cout << 0 << endl;
      return 0;
    }
    cout << 1 << endl;
    return 0;
  }
  if(z/5+1 > y){
    cout << 0 << endl;
    return 0;
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    deque<long long> d;
    for (int i = 0; i < N; i++)
    {
        long long A;
        cin >> A;
        auto itr = lower_bound(d.begin(), d.end(), A);
        if (itr == d.begin())
        {
            d.push_front(A);
        }
        else
        {
            --itr;
            *itr = A;
        }
    }
    cout << d.size() << endl;
}

Measured memory_bytes: 1024
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
S = list(input())[: -1]
table = [[] for _ in range(26)]
a = ord("a")
res = 1
for i in range(len(S)):
  table[ord(S[i]) - a].append(i)
for i in range(len(S)):
  x = bl(table[ord(S[i]) - a], i)
  res += len(S) - (len(table[ord(S[i]) - a]) - x) - i
  #print(res, (len(table[ord(S[i]) - a]) - x))
print(res)

Measured memory_bytes: 62448
#include<iostream>
#include<cstdio>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int N=200200;
int n,x,f[N],fd[N],b[N];
struct ele{
	int x,y,i;ll w;
	ele(int _x=0,int _y=0,int _i=0,ll _w=0){x=_x,y=_y,i=_i,w=_w;}
	bool operator < (const ele&a)const{return 1ll*y*a.x<1ll*a.y*x;}
	ele operator + (const ele&a)const{return ele(x+a.x,y+a.y,i,w+a.w+1ll*x*a.y);}
}g[N];
priority_queue<ele>q;
int fi(int x){return x==fd[x]?x:fd[x]=fi(fd[x]);}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	FOR(i,2,n) scanf("%d",&f[i]);
	FOR(i,1,n) scanf("%d",&x),g[i]=ele(x,!x,i,0),fd[i]=i;
	FOR(i,2,n) q.push(g[i]);
	while(q.size()){
		ele e=q.top();q.pop();
		int u=e.i,v=fi(f[u]);
		if(b[u]) continue;b[u]=1;
		g[v]=g[v]+g[u];fd[u]=v;
		if(v!=1) q.push(g[v]);
	}
	cout<<g[1].w<<'\n';
}

Measured memory_bytes: 15600
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	fmt.Println(fibonacci(n, make(map[int]int)))
}

func fibonacci(x int, memo map[int]int) int {
	if x == 0 || x == 1 {
		return 1
	}
	if y, ok := memo[x]; ok {
		return y
	}
	z := fibonacci(x-1, memo) + fibonacci(x-2, memo)
	memo[x] = z
	return z
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}



Measured memory_bytes: 1108
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = [int(_) for _ in readline().split()]
ABCQST = np.array(read().split(), dtype=int)
ABC = ABCQST[:3 * M]
ST = ABCQST[3 * M + 1:]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
S, T = ST[::2], ST[1::2]
G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))
G2 = floyd_warshall(G, directed=0)
G3 = np.full((N + 1, N + 1), np.inf)
np.fill_diagonal(G3, 0)
G3[G2 <= L] = 1
G4 = floyd_warshall(G3, directed=0)
G4[G4 == np.inf] = 0
#print(*(G4.astype(int)[S, T] - 1), sep='\n')
print('\n'.join((G4.astype(int)[S, T] - 1).astype(str)))


Measured memory_bytes: 37276
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

bool check(int c, int N, int Q, string &s, vector<string> &t, vector<string> &d) {
    c--;
    for (int i = 0;i < Q; ++i) {
        if (s[c] == t[i][0]) {
            if (d[i][0] == 'L') {
                c--;
            } else {
                c++;
            }
        }
        if (c < 0) {
            return true;
        }
        if (c >= N) {
            return false;
        }
    }
    return false;
}

int func(int N, int Q, string &s, vector<string> &t, vector<string> &d) {
    int l = 0, r = N + 1;
    while(r - l > 1) {
        int c = (l + r) / 2;
        if (check(c, N, Q, s, t, d)) {
            l = c;
        } else {
            r = c;
        }
    }
    return l;
}

void solve(long long N, long long Q, std::string s, std::vector<std::string> t, std::vector<std::string> d){
    int res = 0;
    res += func(N,Q,s,t,d);
    reverse(ALL(s));
    for(int i = 0; i < Q; ++i) {
        if(d[i] =="L") {
            d[i] = "R";
        } else {
            d[i] = "L";
        }
    }
    res += func(N, Q, s, t, d);
    cout << N - res << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::string s;
    std::cin >> s;
    std::vector<std::string> t(Q);
    std::vector<std::string> d(Q);
    for(int i = 0 ; i < Q ; i++){
        std::cin >> t[i];
        std::cin >> d[i];
    }
    solve(N, Q, s, std::move(t), std::move(d));
    return 0;
}

Measured memory_bytes: 24452
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  vector<pair<int, int> > team;
  map<int,int> rank;
  int a,b;
  while(scanf("%d,%d",&a,&b),a||b) team.push_back(make_pair(b,a));
  sort(team.begin(),team.end());
  for(int i=team.size()-1,a=0,b=0; i>=0; i--){
    if(team[i].first != b){
      b = team[i].first;
      a++;
    }
    rank[team[i].second] = a;
  }
  int n;
  while(cin >>n) cout <<rank[n]<<endl;
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define TOP 0
#define RIGHT 1
#define BOTTOM 2
#define LEFT 3
#define DEBUG 0
#define DEBUG2 0
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.Path_on_a_Grid";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}
int grid[15][15];
const int dr[] = {-1, 0, 1, 0 };
const int dc[] = { 0, 1, 0,-1 };
const char Dir[] = { 'U', 'R', 'D', 'L' };

string res;
void touch_wall (int row, int col, int dir, int hand )
{
	if ((1<<hand & grid[row][col] ) != 0 )
		res += Dir[dir];	
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	memset (grid, 0, sizeof (grid ) );
	string s = "";
	for (int i = 1;getline (cin, s ); i++  ){
//		if (getline (cin, s ) )
//		getline (cin, s );
//		cin >> s;
//		if (s.empty() ) break;
		rep (j, s.length() ){
			if (i % 2 != 0 ){
				if (s[j] == '1' ){
					grid[i/2][j+1] |= 1<<BOTTOM;
					grid[(i+1)/2][j+1] |= 1<<TOP;
				} // end if
			}else{
				if (s[j] == '1' ){
					grid[i/2][j] |= 1<<RIGHT;
					grid[i/2][j+1] |= 1<<LEFT;
				} // end if
			} // end if
		} // end rep
	} // end for

#if DEBUG2
	rep (i, 15 ){
		rep (j, 15 ){
			cout << setw(2) << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
#endif
	int row = 0, col = 1, dir = RIGHT;
	int hand = (dir+1)%4;
	res = "";
	do{
		touch_wall (row, col, dir, hand );
		if (((1<<hand) & grid[row][col] ) == 0 ){	// 右手の壁がなくなった、なくなった方向に回転
			dir = hand;
		}else{
			while (((1<<dir) & grid[row][col] ) != 0 ){ // 右手の壁があったとしても前に進めない
				dir = (4+dir-1)%4;
				touch_wall (row, col, dir, hand );
			} // end while 
		} // end if
		row = row + dr[dir];
		col = col + dc[dir];
		hand = (dir+1)%4;
#if DEBUG2
		cout << '(' << row << ',' << col << ')' << " dir: " << dir << endl;
#endif
	}while (!(row == 0 && col == 0 ) ); // end while
	cout << res << endl;

#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif
			
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int isp[1000000];

bool p(int n){
    // is prime ?
    if (isp[n] != -1) return isp[n];
    int & res = isp[n];

    // = 1,-1 ?
    res = true;
    for (int i = 7; i <= n; i += 7){
        if (i + 1 < n && n % (i + 1) == 0){
            res = false; break;
        }
        if (n % (i - 1) == 0){
            res = false; break;
        }
    }
    return res;
}

int main(){
    memset(isp, -1, sizeof(isp));
    int n;
    while (cin >> n && n != 1){
        vector<int> ans;
        for (int i = 7;; i += 7){
            for (int j : {-1, 1}){
                int x = i + j;
                if (x > n) goto end;
                if (n%x == 0 && p(x)){
                    ans.push_back(x);
                }
            }
        }
    end:;
        cout << n << ":";
        for (int i = 0; i<ans.size(); i++){
            cout << " " << ans[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 5120
/*
                    author         : TAPAN SAVANI 
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

long long int knapsack(long long int wt[], long long int val[], long long int n, long long int W)
{
    long long int dp[n + 1][W + 1];

    FOR(i, 0, n + 1)
    {
        FOR(j, 0, W + 1)
        {
            if (i == 0 || j == 0)
                dp[i][j] = 0;

            else if (j - wt[i - 1] >= 0)
                dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);

            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    return dp[n][W];
}

int main()
{
    HAPPY_CODING;

    long long int n, W;
    cin >> n >> W;

    long long int wt[n], val[n];
    FOR(i, 0, n)
    cin >> wt[i] >> val[i];

    long long int ans = knapsack(wt, val, n, W);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 82424
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    string s;cin>>s;
    int n=s.size();
    
    int nxt[n+1][26];
    rep(i,26) nxt[n][i]=-1;
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<26;j++)nxt[i][j]=nxt[i+1][j];
        nxt[i][s[i]-'a']=i;
    }

    ll dp[n+1];
    rep(i,n+1) dp[i]=LINF;
    pair<char,int> pre[n+1];
    rep(i,n+1)pre[i]=make_pair('?',n);
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        rep(j,26){
            if(nxt[i][j]<0){
                if(dp[i]>1){
                    //jの文字がないのでその文字一文字で終わり
                    //辞書順最小なのでjを0からあたり，見つかったらそれで終われるように
                    dp[i]=1;
                    pre[i]=make_pair('a'+j,n);
                }
            }else if(chmin(dp[i],dp[nxt[i][j]+1]+1)){
                //今考えているセットにはjの文字がまだないため，それを使うとよい
                pre[i]=make_pair('a'+j,nxt[i][j]+1);
            }
        }
    }
    
    string ans="";
    int idx=0;
    while(idx<n){
        ans.push_back(pre[idx].first);
        idx=pre[idx].second;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 24084
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long 
using namespace std;
int n, t, a, m;
float h[1005], x[1005];
int main()
{
	cin >> n >> t >> a;
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		x[i] = abs(t - h[i] * 0.006 - a);
	}
	float ans = x[0];
	for (int i = 0; i < n; i++)
	{
		if (ans > x[i])
			ans = x[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (ans == x[i])
		{
			m = i;
			break;
		}
	}
	cout << m + 1;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, Q;
  while (cin >> N >> Q) {
    vec<int, 2> g(N);
    for (int i = 0; i < N - 1; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    vector<ll> add(N, 0);
    for (int q = 0; q < Q; q++) {
      int p, x;
      cin >> p >> x;
      --p;
      add[p] += x;
    }
    vector<ll> res(N, 0);
    auto dfs = [&](auto& f, int v, int p = -1, ll s = 0) -> void {
      s += add[v];
      res[v] = s;
      for (int u : g[v]) {
        if (u == p) continue;
        f(f, u, v, s);
      }
    };
    dfs(dfs, 0);
    for (int v = 0; v < N; v++) cout << res[v] << " ";
    cout << endl;
  }
  return 0;
}


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

using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

//最大公約数
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}

//最小公倍数
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}

typedef long long ll;

char str[17];

int main(){
	char s[] = {"CODEFESTIVAL2016"};
	
	scanf("%s", str);
	
	int cnt = 0;
	
	REP(i,16){
		if (str[i] != s[i]) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

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

int mod10(int n){
  int p=n%10;
  if(p==0){p=10;}
  return p;
}

int ki(int q){
  int r=(q/10)*10+10;
  if(q%10==0){r-=10;}
  return r;
}


int main() {
int a,b,c,d,y;
  cin>>a>>b>>c>>d>>y;
  int e=mod10(a);
  int f=mod10(b);
  int g=mod10(c);
  int h=mod10(d);
  int i=mod10(e);
  int j=min(e,min(f,min(g,min(h,i))));
  
  cout<<ki(a)+ki(b)+ki(c)+ki(d)+ki(y)-(10-j)<<endl;
  
}
  
  

Measured memory_bytes: 256
import itertools
import collections
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = [0] + [int(m) for m in input().split()]
accua = itertools.accumulate(a)
#accua.append(0)
dict = collections.Counter(accua)
ans = 0
for i in dict:
    if dict[i] >= 2:
        ans += comb(dict[i], 2)
print(ans)


Measured memory_bytes: 39544
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cmath>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=1e5+11;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001LL;
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
struct Edge{int nxt,to;}edge[N<<1];
int col[N],num_edge,head[N];
bool flag;
ll ans,b,w,n,m;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void add_edge(int from,int to){
	edge[++num_edge].nxt=head[from];
	edge[num_edge].to=to;
	head[from]=num_edge;
}
void dfs(int u,int now){
	col[u]=now;
	if(now==0) b++;
	else w++;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(col[v]==-1) dfs(v,now^1);
		else if(col[v]!=(now^1)) flag=1;
	}
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();m=read();
	rep(i,m){
		int x=read(),y=read();
		add_edge(x,y);add_edge(y,x);
	}
	rep(i,n) col[i]=-1;
	dfs(1,0);
	if(flag) ans=n*(n-1)/2-m;
	else ans=b*w-m;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin >> p.at(i);
    }
    vector<int> q(N);
    q=p;
    sort(q.begin(),q.end());
    int cnt = 0;
    for(int i=0;i<N;i++){
        if(p.at(i)!=q.at(i)){
            cnt += 1;
        }
    }
    
    if(cnt==2||cnt==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define maxn 105
int main()
{
    int n,i;
    int temp;
    scanf("%d",&n);
    int find=maxn;
    int ans=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&temp);
        ans=ans+temp;
        if(temp%10!=0&&temp<find)
        {
            find =temp;
        }
    }
    if(ans%10!=0)
        printf("%d",ans);
    else
    {
        if(find==maxn)
            printf("0");
        else
           printf("%d",(ans-find));
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    vector<int> cards(N+2, 0);
    rep(i, 1, N+1) cin >> cards[i];

    vector<ll> sumsX(N+2, 0);
    vector<ll> sumsY(N+2, 0);
    rep(i, 1, N+2) sumsX[i] = sumsX[i-1] + cards[i];
    rrep(i, N, 0) sumsY[i] = sumsY[i+1] + cards[i];

    ll res = LLONG_MAX;
    rep(i, 1, N) res = min(res, abs(sumsX[i] - sumsY[i+1]));

    cout << res << "\n";
}

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

int main(){
	int c=0;string n,s; cin>>n>>s;
	for(int i=0;i<n.length();++i){
		if(n[i]!=s[i]){
			c++;
		}
	}
	cout<<c<<"\n";
	return 0;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[2][6] = {{0,1,0,-1,-1,1},{0,1,0,-1,-1,1}};
constexpr int dj[2][6] = {{1,0,-1,0,-1,-1},{1,0,-1,0,1,1}};


int main(){
    int w, h;
    cin >> w >> h;
    vector<vector<int> > a(h+2,vector<int>(w+2)), outside(h+2,vector<int>(w+2));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i+1][j+1];
        }
    }
    queue<P> que;
    que.push(P(0,0));
    outside[0][0] = true;
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int i = p.first, j = p.second;
        for(int k=0;k<6;k++){
            int ni = i+di[i&1][k], nj = j+dj[i&1][k];
            if(ni < 0 || ni > h+1) continue;
            if(nj < 0 || nj > w+1) continue;
            if(outside[ni][nj] || a[ni][nj]) continue;
            que.push(P(ni,nj));
            outside[ni][nj] = true;
        }
    }
    int ans = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(a[i][j]){
                for(int k=0;k<6;k++){
                    int ni = i+di[i&1][k], nj = j+dj[i&1][k];
                    if(outside[ni][nj]) ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3240
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

bool check(int x, set<int> d){
    string s = to_string(x);
    for (char c : s){
        if (d.count(c - '0')) return false;
    }
    return true;
}

void solve() {
    int n, k;
    cin >> n >> k;
    set<int> d;
    forn(i, k){
        int x;
        cin >> x;
        d.insert(x);
    }
    while (!check(n, d)) n++;
    cout << n << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstdio>
using namespace std;

#define next '\n'
#define rep(i, n) for(int (i) = (0); (i) < (n); (i++))
using ll = long long;
using ull = unsigned long long;

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

    string s;
    cin >> s;

    int u = (s[0] - '0') * 10 + (s[1] - '0');
    int d = (s[2] - '0') * 10 + (s[3] - '0');

    if((u >= 1 && u <= 12) && (d >= 1 && d <= 12)){
        cout << "AMBIGUOUS";
    }else if(u >= 1 && u <= 12){
        cout << "MMYY";
    }else if(d >= 1 && d <= 12){
        cout << "YYMM";
    }else{
        cout << "NA";
    }

    cout << next;
}

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

bool b[256][256];

int main()
{
  int n, m, d;
  cin >> n >> m >> d;

  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      char c;
      cin >> c;
      b[i][j] = (c == '.');
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      bool f = true;
      for (int k = 0; k < d; k++){
        f &= b[i + k][j];
      }

      ans += f;

      f = true;
      for (int k = 0; k < d; k++){
        f &= b[i][j + k];
      }

      ans += f;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3112
S = input()
not_odd = 'L'
not_even = 'R'

ans = 'Yes'
count = 1
for i in range(len(S)):
    if count % 2 == 1 and S[i] == not_odd:
        ans = 'No'
        break
    elif count % 2 == 0 and S[i] == not_even:
        ans = 'No'
        break

    count += 1

print(ans)

Measured memory_bytes: 3060
s=list(input())
k=int(input())
a,b,c=0,0,0
S=s*2
SS=s*3

for i in range(1,len(s)):
    if s[i-1]==s[i]:
        a+=1
        s[i]="A"

for i in range(1,len(S)):
    if S[i-1]==S[i]:
        b+=1
        S[i]="A"
for i in range(1,len(SS)):
    if SS[i-1]==SS[i]:
        c+=1
        SS[i]="A"        

x=a
y=c-a
z=c-b

if k%2==0:
    print(y*((k-2)//2)+x+z)
else:    
    print(y*(k//2)+x)   

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

typedef long long ll;

const int maxn = 1e5 + 5;

int n, m, k;
int w[maxn], f[maxn];
ll ans;
priority_queue <int, vector<int>, greater<int>> q[maxn];
multiset <int> s;

int find(int x)
{
	return f[x] == x ? x : f[x] = find(f[x]);
}

void merge(int x, int y)
{
	int fx = find(x);
	int fy = find(y);
	if(fx != fy)
		f[fx] = fy;
}

int main()
{
	int u, v;
	scanf("%d%d", &n, &m);
	k = n - m;
	if(2 * k - 2 > n)
	{
		puts("Impossible");
		return 0;
	}
	if(k == 1)
	{
		puts("0");
		return 0;
	}
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &w[i]);
		f[i] = i;
	}
	for(int i = 1; i <= m; i++)
	{
		scanf("%d%d", &u, &v);
		u++, v++;
		merge(u, v);
	}
	for(int i = 1; i <= n; i++)
	{
		find(i);
		q[f[i]].push(w[i]);
	}
	for(int i = 1; i <= n; i++)
		if(!q[i].empty())
		{
			ans += q[i].top();
			q[i].pop();
	//		printf("val = %lld\n", val);
		}
	for(int i = 1; i <= n; i++)
		while(!q[i].empty())
		{
			s.insert(q[i].top());
			q[i].pop();
		}	
//	for(auto it = s.begin(); it != s.end(); it++)
//		printf("%d\n", *it);
	auto it = s.begin();
	for(int i = 1; i <= k - 2; i++, it++)
	{
		ans += *it;
	//	printf("%lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9208
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1

if strings[0] != strings[-1]:
    print(counter * k)
else:
    # 文字列が１種類の時
    if (same_starts + 1) == len(strings):
        # 文字列の個数が偶数の時
        if len(strings) % 2 == 0:
            print(k * len(strings)//2)
        else:
        # 文字列が奇数の時
            # 文字列を繰り返す回数が偶数回の時
            if k % 2 == 0:
                print(counter * k // 2 + (counter + 1) * k // 2)
            else:
            # 文字列を繰り返す回数が奇数回の時
                print(counter * ((k - 1) // 2 + 1)+ (counter + 1) * (k - 1)//2)
    else:
        if (same_starts+1) % 2 == 0:
            print(counter * k)
        else:
            print((counter+1) * (k-1) + counter)


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

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

    int a, b, c;
    c = N % 10;
    b = (N / 10) % 10;
    a = (N / 100) % 10;
    int rev = 100 * c + 10 * b + a;

    if (N == rev) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){
  
  long long int n, tmp;
  std::vector<long long int> p;
  
  scanf("%lld", &n);
  for(long long int i = 0; i < n; i++){
    scanf("%lld", &tmp);
    p.push_back(tmp);
  }
  
  long long int ans = 0;
  for(int i = 1; i < n-1; i++){
    if((p[i-1] - p[i])*(p[i+1]-p[i]) < 0){
      ans++;
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  
  return 0;
}


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

public class Main{
	
	static long mod=(long)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			
			char [] s=in.next().toCharArray();
			int sum=0;
			for(char c: s) {
				sum+=(c-'0');
			}
			if(sum%9==0) out.println("Yes");
			else out.println("No");
		}
		out.close();		
		
	}

	
	
/*********************************** UTILITY CODE BELOW **************************************/	
		
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	
	static long max(long a, long b) {
		return a>b ? a : b;
	}
	
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

Measured memory_bytes: 37016
n=int(input())
S=input()
RGB=[[] for i in range(3)]
for i in range(n):
    if S[i]=="R":
        RGB[0].append(i)
    elif S[i]=="G":
        RGB[1].append(i)
    else:
        RGB[2].append(i)
L=[len(RGB[0]),len(RGB[1]),len(RGB[2])]
m=L.index(max(L))
A=[]
for i in range(3):
    if i==m:
        continue
    else:
        A.append(i)
C=RGB[A[0]]
D=RGB[A[1]]
E=RGB[m]

ans=0
for i in range(L[A[0]]):
    for j in range(L[A[1]]):
        r=C[i]
        g=D[j]
        d=abs(r-g)
        cnt=0
        if d%2==0:
            if (r+g)//2 in E:
                cnt+=1
        u=max(r,g)+d
        l=min(r,g)-d
        if 0<=u<=n-1:
            if u in E:
                cnt+=1
        if 0<=l<=n-1:
            if l in E:
                cnt+=1
        ans+=L[m]-cnt
print(ans)

Measured memory_bytes: 70608
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
string s,t;
cin>>s>>t;
int n=s.size();
for(int i=0;i<n;i++){
    if(t.size()==i)cout<<s[i];
    else cout<<s[i]<<t[i];
}
cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long int
#define FOR(i,a,b) for(ll (i)=(a);i<(ll)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define outi(a) printf("%lld\n",(a))
#define prial(a) cout << a << endl;
#define line cout << endl;
#define pb push_back
using namespace std;
inline ll read()
{
    ll x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
    return x;
}
//****************************
map<int, int>exist;
//****************************
int solve(int i);
int main()
{
  int n = read();
  ll sum =0;
  rep(i,n) sum ^= read();
  if(sum==0) cout << "Yes"<< endl;
  else
  cout<<"No"<<endl;
}


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

int n,m,x;
int c[15];
int a[15][15];
int now[15];

int main(void){
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int ans=-1;
	for(int i=0;i<(1<<n);i++){
		memset(now,0,sizeof(now));
		int co=0;
		for(int j=0;j<n;j++){
			if(i>>j & 1){
				for(int k=0;k<m;k++){
					now[k]+=a[j][k];
				}
				co+=c[j];
			}
		}
		bool flag=true;
		for(int j=0;j<m;j++){
			if(now[j]<x){
				flag=false;
			}
		}
		if(flag){
			if(ans==-1){
				ans=co;
			}
			ans=min(ans,co);
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3728
c1,c5,c10,c50,c100,c500 = map(int, raw_input().split())
money = 1 * c1 + 5 * c5 + 10 * c10 + 50 * c50 + 100 * c100 + 500 * c500
if money>=1000: print "1"
else: print "0"

Measured memory_bytes: 6448
/*
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#define M 201000
#define ll long long
using namespace std;

int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
ll poww[M];
multiset<ll> st;
multiset<ll>:: iterator it;
ll a[M], n;

int main() {
	//freopen(".in", "r", stdin), freopen(".out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i++)	a[i] = read();
	poww[0] = 1;
	for(int i = 1; i <= 31; i++) {
		poww[i] = poww[i - 1] << 1;
	}
	int ans = 0;
	sort(a + 1, a + n + 1, greater<ll>() );
	for(int i = 1; i <= n; i++) {
		bool f = false;
		for(int j = 1; j <= 31; j++) {
			if(poww[j] < a[i]) continue;
			ll op = poww[j] - a[i];
			it = st.find(op);
			if(it != st.end())
			{
				f = true;
				st.erase(it);
				ans++;
			//	cout << a[i] << " " << *it << "\n"; 
				break;
			}
		}
		if(!f) st.insert(a[i]);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 11136