akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  if((A + B) % 3 == 0 || A % 3 == 0 || B % 3 == 0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

std::string S;

int main(int argc, char **argv) {
    std::cin >> S;
    
    std::string a, b;
    a.push_back(S[0]);
    a.push_back(S[1]);
    b.push_back(S[2]);
    b.push_back(S[3]);

    int num1 = atoi(a.c_str());
    int num2 = atoi(b.c_str());

    if (1 <= num1 && num1 <= 12 && 1 <= num2 && num2 <= 12) {
        std::cout << "AMBIGUOUS" << std::endl;
    } else if (1 <= num1 && num1 <= 12) {
        std::cout << "MMYY" << std::endl;
    } else if (1 <= num2 && num2 <= 12) {
        std::cout << "YYMM" << std::endl;
    } else {
        std::cout << "NA" << std::endl;
    }

    return 0;

}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

for y in range(h):
  for x in range(w):
    if s[y][x]=='.':
      cnt=0
      for dy,dx in [[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]:
        ny=y+dy
        nx=x+dx
        if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
          cnt+=1
      s[y][x]=str(cnt)

for i in s:
  print(''.join(i))


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

signed main() {
	string s; cin >> s;
	if(s[0] == s[1] && s[1] == s[2]) {
		cout << "Yes" << endl;
		return 0;
	}
	if(s[1] == s[2] && s[2] == s[3]) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3604
//package Dynamic;
import java.io.*;
import java.util.*;
class Main{
    static public void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       int n=Integer.parseInt(br.readLine());
       int ar[]=new int[n];
       StringTokenizer st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)
        {
        	ar[x]=Integer.parseInt(st.nextToken());
        }
        int xor=0;
        for(int x=0;x<n;x++)
        {
        	xor=(xor^ar[x]);
        }
        if(xor==0)
        	System.out.println("Yes");
        else
        	System.out.println("No");
        //
       
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
//        int d=Integer.parseInt(st.nextToken());
//        System.out.println(); 
        //}
    }
}


Measured memory_bytes: 35540
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void solution(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool t = true;
  while(true){
    if(t){
      c = c - b;
    }else{
      a = a - d;
    }
    if(a <= 0){
      cout << "No" << endl;
      return;
    }else if(c <= 0){
      cout << "Yes" << endl;
      return;
    }
    t = !t;
  }
}     



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef signed long long lint;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int h, w, k, xs, ys, xg, yg;;
  cin >> h >> w >> k >> xs >> ys >> xg >> yg;
  xs--; ys--; xg--; yg--;
  vector< string > m(h);
  for (int i=0; i<h; ++i) cin >> m[i];
  vector< tuple< int, int, int > > q(h*w*2, make_tuple(xs, ys, 0));
  q[0] = make_tuple(xs, ys, 0);
  vector< vector< int > > v(h, vector< int >(w, -1));
  v[xs][ys] = 0;
  vector< int > dx = {1, 0, -1, 0};
  vector< int > dy = {0, 1, 0, -1};
  int vi = 1;
  for (int i=0; i<h*w; ++i) {
    int x=get<0>(q[i]), y=get<1>(q[i]), c=get<2>(q[i]);
    if (x == xg && y == yg) {
      cout << c << endl;
      return 0;
    }
    for (int dr=0; dr<4; ++dr) {
      for (int d=1; d<=k; ++d) {
	int xn = x+dx[dr]*d;
	int yn = y+dy[dr]*d;
	if (xn < 0 || h <= xn) break;
	if (yn < 0 || w <= yn) break;
	if (m[xn][yn] == '@') break;
	if (v[xn][yn]>=0) {
	  if (v[xn][yn] < c+1) break;
	  continue;
	}
	v[xn][yn] = c+1;
	q[vi] = make_tuple(xn, yn, c+1);
	vi++;
	//cout << xn << "/" << yn << " = " << c+1 << endl;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


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

using namespace std;

int main() {
	int N;
	string str, before;
	vector<string> words;
	bool ans = true;

	cin >> N;

	cin >> str;
	words.push_back(str);
	before = str;

	for (int i = 1; i < N; i++) {
		cin >> str;
		for (int j = 0; j < i; j++) {
			if (words[j] == str)
				ans = false;
		}
		if (before[before.length() - 1] != str[0]) {
			ans = false;
		}
		words.push_back(str);
		before = str;
	}

	if (ans) cout << "Yes";
	else cout << "No";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MAX(A,B) A>B?A:B
#define MIN(A,B) A<B?A:B
#define gcd(A,B) __gcd(A,B)
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define modulo 998244353
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<int,double> pid;

int arr[102000];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for (int i = 0; i<n; i++)
        scanf("%d",arr+i);
    sort(arr,arr+n);
    int sum = arr[k-1]-arr[0];
    for (int i = k; i<n; i++)
        sum = MIN(sum, (arr[i]-arr[i-k+1]));
    printf("%d",sum);
}

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

char line[200010];

bool can_get(int a,int goala){
	int p=0;
	for(int i=a;i<goala;i++){
		if(line[i]=='#')p++;
		if(line[i]=='.')p=0;
		if(p==2)return false;
	}
	return true;
}

bool have_stand(int a,int goala){
	int p=0;
	for(int i=a-1;i<=goala+1;i++){
		if(line[i]=='#')p=0;
		if(line[i]=='.')p++;
		if(p==3)return true;
	}
	return false;
}

bool can_do(int a,int b,int goala,int goalb){
    if((b>a&&goalb>goala)||a>b&&goala>goalb)return(can_get(a,goala)&&can_get(b,goalb));
    else{
    	if(have_stand(b,goalb)&&can_get(a,goala))return true;
    	else return false;
	}
}

int main(){
	int p=1;char c;
	int n,a,b,goala,goalb;
	cin>>n>>a>>b>>goala>>goalb;getchar();
	while((c=getchar())!=EOF&&c!='\n')line[p++]=c;
	if(can_do(a,b,goala,goalb))cout<<"Yes";
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>

using namespace std;
 
int main(void) {
    int a, b;
    cin >> a >> b;
    int ab = a * b;
    
    // find odd number (espanish: numero impar)
    if ((ab * 1) % 2 == 1 || (ab * 2) % 2 == 1 || (ab * 3) % 2 == 1) {
        cout << "Yes";
    } else {
        cout << "No";
    }
 
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

const static ll MOD = 1000000007;

class BinaryIndexedTree {
private:
  int* bit;
  int n;
public:
  BinaryIndexedTree(int _size){
    bit = new int[_size];
    n = _size;
    fill(bit,bit+_size,0);
  }
  int sum(int i){
    int s = 0;
    while(i > 0){
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  
  void add(int i, int x){
    while(i <= n){
      bit[i] += x;
      i += i & -i;
    }
  }
};

int main(){
  int N,R;
  ll dp[100001];
  ll target[100001];

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

    memset(dp,0,sizeof(dp));
    dp[0] = 1;

    for(int i=1;i<=N;i++){
      target[i] = i;
      // 4
      // v v v v
      //  1 2 3
      dp[i] = dp[i-1] * i % MOD;
    }
    for(int r = 0; r< R;r++){
      int from_idx;
      int to_idx;
      scanf("%d %d",&from_idx,&to_idx);
      swap(target[from_idx],target[to_idx]);
    }

    ll res = 0;
    BinaryIndexedTree BIT(100001);
    for(int i=N,j=0;i>=1;i--,j++){
      res += ((dp[j] % MOD) * (BIT.sum(target[i] - 1) % MOD) % MOD);
      res %= MOD;
      BIT.add(target[i],1);
    }
    printf("%lld\n",res);
  }
}

Measured memory_bytes: 41960
X,N = map(int, input().split())
p = list(map(int, input().split()))

i = 0

while X+i<=101 or X-i>=0:
    pflag = X+i in p
    mflag = X-i in p
    if pflag and mflag:
        i+=1
    else:
        if not mflag:
            print(X-i)
            exit()
        else:
            print(X+i)
            exit()

# if 101-X <= X:
#     print(0)
# else:
#     print(101)


Measured memory_bytes: 9128
N = gets.to_i
ans = 0
b = gets.split.map &:to_i
N.times do |i|
  if i == 0
    ans += b[i]
    next
  end
  if i == N-1
    ans += b[N-2]
    next
  end
  if b[i-1] <= b[i]
    ans += b[i-1]
  else
    ans += b[i]
  end
end
puts ans

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

const long long INF = 1LL << 50;
long max(long x, long y) {
	if (x > y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

int dig(long a) {
	int b=0;
	while (a > 0) {
		a /= 10;
		b++;
	}
	return b;
}

void m_sort(int a[], int tmp[], int left, int right);
void m_sort(int a[], int tmp[], int left, int right);
void sort(int a[], int total) {
	int tmp;
	for (int i = 0; i < total; i++) {
		for (int j = i + 1; j < total; j++) {
			if (a[i] < a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}

}

void mergeSort(int a[], int tmp[], int size)
{
	m_sort(a, tmp, 0, size - 1);
}
void merge(int a[], int tmp[], int left, int mid, int right)
{
	int i, left_end, num_elements, tmp_pos;

	left_end = mid - 1;
	tmp_pos = left;
	num_elements = right - left + 1; // 要素 

	while ((left <= left_end) && (mid <= right))
	{
		if (a[left] <= a[mid])
		{
			tmp[tmp_pos] = a[left];
			tmp_pos = tmp_pos + 1;
			left = left + 1;
		}
		else
		{
			tmp[tmp_pos] = a[mid];
			tmp_pos = tmp_pos + 1;
			mid = mid + 1;
		}
	}


	while (left <= left_end)
	{
		tmp[tmp_pos] = a[left];
		left = left + 1;
		tmp_pos = tmp_pos + 1;
	}

	while (mid <= right)
	{
		tmp[tmp_pos] = a[mid];
		mid = mid + 1;
		tmp_pos = tmp_pos + 1;
	}


	for (i = 0; i <= num_elements; i++)
	{
		a[right] = tmp[right];
		right = right - 1;
	}
}
void m_sort(int a[], int tmp[], int left, int right)
{
	int mid;

	if (right > left)
	{
		mid = (right + left) / 2;
		m_sort(a, tmp, left, mid);
		m_sort(a, tmp, mid + 1, right);

		merge(a, tmp, left, mid + 1, right);
	}
}

int N, M,a[2000],b[2000];
long long c[2000], dist[1000];

int main(){
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i]>>c[i];
		c[i] = -c[i];
	}

	for (int i = 0; i < N; i++) {
		dist[i] = INF;
	}

	dist[0] = 0;

	for (int loop = 0; loop < N - 1; loop++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i] - 1] == INF)continue;
			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
			}
		}
	}

	long long ans = dist[N - 1];

	bool nega[1000];
	for (int i = 0; i < N; i++) {
		nega[i] = false;
	}

	for (int loop = 0; loop < N; loop++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i] - 1] == INF)continue;

			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] > dist[a[i] - 1] + c[i];
				nega[b[i]-1] = true;
			}
			if (nega[a[i] - 1] == true) {
				nega[b[i] - 1] = true;
			}
		}
	}

	if (nega[N - 1])
		 cout << "inf" << endl;
	 else
		 cout << -ans << endl;

	return 0;
}

Measured memory_bytes: 256
rStr = input()

A = int(rStr.split(' ')[0])
B = int(rStr.split(' ')[1])

result = 0
index = 0

while index < 2 :
    if A <= B :
        result += B
        B = B - 1
    else :
        result += A
        A = A - 1
    index = index + 1

print(result)

Measured memory_bytes: 9036
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(K: int):
    a = [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]
    print(a[K - 1])
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

const ll MOD = 998244353;
const ll INF = 1e18;
const ld E = 1e-12;
const ld PI=acos(-1);
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD, md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, a[1000001], b[1000001], pr[1000001];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l %= md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

#define dies_from_cringe exit(0)

void solve()
{
    ll k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) {cin >> b[i];pr[i]=pr[i-1]+b[i];}
    ll sm=0, ans=0;
    for (int i = 0; i <= n; i++)
    {
        k-=a[i];
        if (k<0) break;
        ll l=0, r=m;
        while (l<r)
        {
            int w=(l+r+1)/2;
            if (pr[w]>k) r=w-1; else l=w;
        }
        ans=max(ans, l+i);
    }
    cout << ans << "\n";
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

/*
1
3 3
10 1 2
5 1 1
*/


Measured memory_bytes: 8348
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def rev(n,mod=(10**9+7)):
    ni = n
    nm = 1
    m2 = mod-2
    while m2 > 0:
        if m2&1:
            nm = (nm*ni)%mod
        m2 >>= 1
        ni = (ni**2)%mod
    return nm

#素因数分解
def factorization(n):
    d = dict()
    ni = n
    pn = 2
    t = 0
    while pn**2 <= n and ni > 1:
        if ni%pn == 0:
            t += 1
            ni //= pn
        else:
            if not t == 0:
                d[pn] = t
                t = 0
            if pn == 2:
                pn = 3
            else:
                pn += 2
    if t > 0:
        d[pn] = t
    if ni > 1:
        d[ni] = 1
    return d

def main():
    n = int(ipt())
    ans = 0
    a = [int(i) for i in ipt().split()]
    d = defaultdict(int)
    for i in a:
        ans += rev(i)
        di = factorization(i)
        for ki,vi in di.items():
            d[ki] = max(d[ki],vi)
        ans %= mod

    for ki,vi in d.items():
        ans *= pow(ki,vi,mod)
        ans %= mod

    print(ans)

    return None

if __name__ == '__main__':
    main()


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

#define ll long long

signed main()
{
  int a[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y; cin >> x >> y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    REP(i, N) {
        if (S.substr(i, N) + S.substr(0, i) == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int L = Integer.parseInt(st.nextToken());
         int R = Integer.parseInt(st.nextToken());
         int D = Integer.parseInt(st.nextToken());
         int res = 0;
        for(int i=L; i <= R; i++)
          if(i%D == 0) res++;
        System.out.println(res);
      }
   }

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

int main()
{
    int N;
    cin >> N;
    long long sum = 0;
    for( int i = 0; i <= N; ++i)
    {
        if ( i % 3 == 0 || i % 5 == 0)
        {
            continue;
        }else if ( i % 3 == 0){
            continue;
        }else if ( i % 5 == 0){
            continue;
        }else{
            sum+= i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main()
{
	int i, N;
	char W[101][11];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%s", W[i]);
	
	int j, k, l, flag = 1;
	for (i = 1; i <= N && flag == 1; i++) {
		if (i > 1 && W[i][0] != W[i-1][j-1]) {
			flag = 0;
			break;
		}
		for (j = 0; W[i][j] != 0; j++);
		for (k = 1; k < i; k++) {
			for (l = 0; W[i][l] == W[k][l] && l < j; l++);
			if (l == j && W[k][l] == 0) flag = 0;
		}
	}
	
	if (flag == 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
input_string = input()
input_list = []

for i in input_string:
    input_list.append(i)

if len(input_string) % 2 == 1:
    length = int((len(input_string) - 1)/2)
    input_list.pop()
else:
    length = int((len(input_string) - 2)/2)
    input_list.pop()
    input_list.pop()

while length > 0:
    if input_list[:length] == input_list[length:]:
        print(len(input_list))
        break
    else:
        length -= 1
        input_list.pop()
        input_list.pop()

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Greedy algorithms - Fractional Knapsack Problem
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_B&lang=jp

"""
N, W = map(int, input().split())
items = []
for _ in range(N):
    v, w = map(int, input().split())
    items.append((v/w, v, w))
items.sort()

ans = 0
while W > 0 and items:
    r, v, w = items.pop()
    if W >= w:
        W -= w
        ans += v
    else:
        ans += v * W / w
        W = 0
print(ans)


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

int main(void)
{
    string s;
    getline(cin, s);  // 1行読み込む
    for(int i = 0; i < s.size(); i++) {
        char c = s[i];
        if ('A' <= c && c <= 'Z') {
            //c = tolower(c);
            c = c + 32;
        }
        else if('a' <= c && c <= 'z') {
            c = c - 32;
        }
        cout << c;
    }
    cout << endl;
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1
#define all(x) (x).begin() ,(x).end()

const ll mod = 1e9 + 7;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}
const int N = 1e5 + 5;
void solve() {

	string s;
	cin >> s;

	if (s.back() != 's')
		cout << s + 's' << "\n";
	else
		cout << s + "es" << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin >> t;

	while (t--)
		solve();
	return 0;
}





Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    ll n, a, b, ans = 0;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    for (int i = 0; i < n - 1; ++i) {
        ans += min(b, (v[i+1]-v[i])*a);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
multiset<int>w;
int n,a[N],two[N],ans;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;for(int i=1;i<=n;++i)cin>>a[i];
	two[0]=1;for(int i=1;i<32;++i)two[i]=two[i-1]<<1;
	sort(a+1,a+1+n);for(int i=1;i<=n;++i)w.insert(a[i]);
	while(!w.empty()){
		int x=*w.rbegin();w.erase(w.lower_bound(x));
		for(int j=31;j;--j){
			if(w.count(two[j]-x)){
				++ans;w.erase(w.lower_bound(two[j]-x));
				break;
			}
		}
	}cout<<ans<<endl;return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i = 0; i < N;i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i+= b)

int main(){
	int N;

	cin >> N;
	int64_t prev = 2;
	int64_t now = 1;
	rep2(i, N + 1, 2, 1){
		int64_t save = now;
		now += prev;
		prev = save;
	}
	cout << now << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<string.h>
#include<assert.h>
#include<queue>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=500005,mod=19260817;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
long long a,b;
long long lcm(long long a,long long b)
{
	return a/gcd(a,b)*b;
}
int main()
{
	cin>>a>>b;
	cout<<lcm(a,b);
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] == S[i + 1]) {
			cout << i + 1 << " " << i + 2;
			goto END;
		}
	}
	for (int i = 0; i < S.size() - 2; i++) {
		if (S[i] == S[i + 2]) {
			cout << i + 1 << " " << i + 3;
			goto END;
		}
	}
	cout << "-1 -1";
END:;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
 
int main(){
    const int MX=2e5+9;
    int n=10, a[MX];
    string s;
    scanf("%d", &n);
    cin>>s;
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            a[1]=i;
            a[2]=j;
            if(s[0]=='o'&&a[1]==0)a[0]=a[2];
            if(s[0]=='o'&&a[1]==1)a[0]=a[2]^1;
            if(s[0]=='x'&&a[1]==0)a[0]=a[2]^1;
            if(s[0]=='x'&&a[1]==1)a[0]=a[2];
            for(int k=3; k<=n+1; k++){
                if(s[k-2]=='o'&&a[k-1]==0)a[k]=a[k-2];
                if(s[k-2]=='o'&&a[k-1]==1)a[k]=a[k-2]^1;
                if(s[k-2]=='x'&&a[k-1]==0)a[k]=a[k-2]^1;
                if(s[k-2]=='x'&&a[k-1]==1)a[k]=a[k-2];
         
            }
            if(a[n+1]==a[1]&&a[0]==a[n]){
                for(int k=1; k<n+1; k++){
                    if(a[k])printf("W");
                        else printf("S");
                }
                printf("\n");
                return 0;
            }
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
    int N, A, B, C; cin >> N >> A >> B >> C;
    if(A > B) swap(A, B);
    if(B > C) swap(B, C);
    if(A > B) swap(A, B);
    int l[N], a[N];
    for(int i = 0; i < N; i++) {
        cin >> l[i];
        a[i] = i;
    }

    int ans = INF, tmp;
    do
    {
        for (int i = 0; i < N; i++)
        {
            int x = 0;
            for (int m = 0; m <= i; m++)
            {
                x += l[a[m]];
            }
            for (int j = i+1; j < N; j++)
            {
                int y = 0;
                for (int m = i+1; m <= j; m++)
                {
                    y += l[a[m]];
                }
                for (int k = j+1; k < N; k++)
                {
                    int z = 0;
                    for (int m = j+1; m <= k; m++)
                    {
                        z += l[a[m]];
                    }
                    int xc = x, yc = y, zc = z;
                    if(xc > yc) swap(xc, yc);
                    if(yc > zc) swap(yc, zc);
                    if(xc > yc) swap(xc, yc);
                    tmp = abs(A - xc) + abs(B - yc) + abs(C - zc);
                    ans = min(ans, tmp + 10 * (k - 2));
                }
            }
        }
    } while (next_permutation(a, a + N));

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    ll res = 0LL;

    vector<vll> tbl(10, vll(10));
    rep(i, 1, n+1){
        int a = i;
        while(a / 10 > 0){
            a /= 10;
        }
        int b = i % 10;
        tbl[a][b]++;
    }

    rep(i, 1, n+1){
        int a = i;
        while(a / 10 > 0){
            a /= 10;
        }
        int b = i % 10;

        if(b == 0) continue;

        res += tbl[b][a];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a,b;
    cin>>a>>b;
    REP(i,100000){
      //  cerr << i << " " << i * 0.08 << " " << i * 0.10 << endl;
        if((int)(i*0.08)==a&&(int)(i*0.10)==b){
            cout<<i<<endl;
            return 0;
        }
    }    
    cout<<-1<<endl;

    return 0;
}


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

public class Prog
{
    public void run()
    {
        var input = Console.ReadLine().Split();
        int X = int.Parse(input[0]);
        int A = int.Parse(input[1]);
        if(X < A)
        {
            Console.WriteLine("0");
        }
        else
        {
            Console.WriteLine("10");
        }
    }
    public static void Main()
    {
        //var input = Console.ReadLine().Split();
        //int[] X = Array.ConvertAll(input, int.Parse);
        var prog = new Prog();
        prog.run();
    }
}

//Array.ConvertAll(int.Parse)

Measured memory_bytes: 11092
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

N, M, R = map(int, input().split())

s = [[10**9]*N for i in range(N)]
t = list(map(int, input().split()))
for i in range(M):
    a, b, c = map(int, input().split())
    s[a-1][b-1] = c
    s[b-1][a-1] = c
    
s = floyd_warshall(s)
ans = float('inf')
for i in permutations(t):
    A_n = 0
    for j in range(R-1):
        A_n += s[i[j] - 1][i[j+1] - 1]
    ans = min(ans, A_n)
    
print(int(ans))

Measured memory_bytes: 18808
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////
ll N, K;
ll fac[510000], finv[510000], inv[510000];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 510000; ++i) {
		fac[i] = fac[i - 1] * i%INF;//i!のmod INF
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}

ll ans(int k,int i) {
	ll key = COM(k - 1, i - 1);
	ll key2 = COM(N - k - 1, i - 2) + 2 * COM(N - k - 1, i - 1) + COM(N - k - 1, i);
	return key * key2%INF;
}
int main() {
    cin >> N >> K;
	COMinit();
	for (int i = 1; i <= K; ++i) {
		if (i == 1) {
			cout << N - K + 1 << endl;
		}
		else {
			cout << ans(K, i) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 12160
x,y,h,w,T;main(n){for(;~scanf("%d",&n);T&&printf("%d\n",T))for(T=0;n--;T+=x>8?0:x*200)scanf("%d%d%d%d",&x,&y,&h,&w),x=(x+y+h+19)/20,w=w<3?3:(w+19)/5,x=x>w?x:w;}

Measured memory_bytes: 0
#約数全列挙
def make_divisors(n):
	divisors = []
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n//i)
	return divisors


n=int(input())
#n%k!=0
cnt=len(make_divisors(n-1))-1

#n%k==0
lst=make_divisors(n)
for k in lst:
	if k!=1:
		t=n
		while t%k==0:
			t//=k
		if (t-1)%k==0:
			cnt+=1
print(cnt)

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

class Dice {
public:
  int u;
  int r;
  int l;
  int d;
  int b;
  int f;
  void S(void) {
    int temp;
    temp = u; u = b; b = d; d = f; f = temp;
  }
  void N(void) {
    int temp;
    temp = u; u = f; f = d; d = b; b = temp;
  }
  void E(void) {
    int temp;
    temp = u; u = l; l = d; d = r; r = temp;
  }
  void W(void) {
    int temp;
    temp = u; u = r; r = d; d = l; l = temp;
  }
};

int main() {

  Dice dice;
  std::string str;
  
  std::cin >> dice.u;
  std::cin >> dice.f;
  std::cin >> dice.r;
  std::cin >> dice.l;
  std::cin >> dice.b;
  std::cin >> dice.d;

  std::cin >> str;
  for(int i = 0; i < str.size(); ++i) {
    switch( str[i] ) {
    case 'N':
      dice.N();
      break;
    case 'S':
      dice.S();
      break;
    case 'W':
      dice.W();
      break;
    case 'E':
      dice.E();
      break;
    }
  }

  std::cout << dice.u << std::endl;
      
  
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,n)  for(long long i=0;i<n;++i)
#define rep1(i,n) for(long long i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
const int INF = 1e9;
 
int N, M;
VVI adj;
VI visited;
vector<int> bfs(int src){
    VI Parent(N,-1);
    visited[src] = true;
    queue<int> q;
    q.push(src);
    while(!q.empty()){
        int cur = q.front(); q.pop();
        for(auto u : adj[cur]){
            if(visited[u]) continue;
            visited[u] = true;
            //distance[u] = distance[cur] + 1;
            Parent[u] = cur;
            q.push(u);
        }
    }
    return Parent;
}
 
int main(){
    ios;
    cin >> N >> M;
    adj = VVI(N);
    visited = VI( N, 0);
    rep(i,M){
        int u, v;
        cin >> u >> v; --u; --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    VI ans = bfs(0);
    for(int i = 1; i < ans.size(); ++i)
        if(ans[i] == -1)
        {cout << "No"; return 0;}
    
    cout << "Yes\n";
    for(int i = 1; i < ans.size(); ++i)
        cout << ans[i] + 1 << '\n';
    
    return 0;
}


Measured memory_bytes: 10648
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
ll n;
ll memo[100001][3];
std::vector<struct pack> v;
struct pack{
	ll one,two,three;
};
int dp(ll i,ll k)
{
	//base case
	if(i==n)
	{
		return 0;
	}
	if(memo[i][k]==-1)
	{
		if(k==1)
		return memo[i][k]=max(v[i].one+dp(i+1,2),v[i].one+dp(i+1,3));
	else if(k==2)
		return memo[i][k]=max(v[i].two+dp(i+1,1),v[i].two+dp(i+1,3));
	else
		return memo[i][k]=max(v[i].three+dp(i+1,1),v[i].three+dp(i+1,2));
	}
	else
		return memo[i][k];
	

}
int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	memset(memo,-1,sizeof(memo));
	cin>>n;
	FOR(i,n)
	{
		ll x,y,z;
		cin>>x>>y>>z;
		struct pack a;
		a.one=x;
		a.two=y;
		a.three=z;
		v.pb(a);
	}

	cout<<max3(dp(0,1),dp(0,2),dp(0,3));	


}

Measured memory_bytes: 10224
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
// run : ctrl + c 

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

int n;

void dfs(int p,string s,char e){
    if(p==0){
        cout << s << "\n";
        return;
    }
    for(char c='a';c<=(e+1);c++){
        dfs(p-1,s+c,max(e,c));
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin>>n;
    dfs(n-1,"a",'a');
    
   
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int X[MAX] , Y[MAX] , X2[MAX] , Y2[MAX] ;

int n ;

bool cmp(int a , int b)
{
	return X[a] < X[b] ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	set< pair<int , int> >s ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>X[i]>>Y[i] ;
		X2[i] = X[i] , Y2[i] = Y[i] ;
		s.insert({X[i] , Y[i]}) ;
	}
	vector<int>idx ;
	for(int i = 0 ; i < n ; ++i)
		idx.push_back(i) ;
	sort(idx.begin() , idx.end() , cmp) ;
	for(int i = 0 ; i < n ; ++i)
		X[i] = X2[idx[i]] , Y[i] = Y2[idx[i]] ;
	vector<int>vx , vy ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = i-1 ; j >= 0 ; --j)
			vx.push_back(X[i] - X[j]) , vy.push_back(Y[i] - Y[j]) ;
	}
	int ans = n ;
	for(auto &p : vx)
	{
		for(auto &q : vy)
		{
			if(p == 0 && q == 0)
				continue ;
			int cnt = 0 ;
			for(int i = 0 ; i < n ; ++i)
			{
				int a = X[i] - p , b = Y[i] - q ;
				if(s.find({a , b}) == s.end())
					cnt++ ;
			}
			ans = min(ans , cnt) ;
		}
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 3676
#include <iostream>
#include <string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int ro,so,i,j,k,b[1000]={},p=0;
  while(str.size()!=1||str[0]!='.'){
    ro=0;so=0;k=0;p=0;
    for(i=0;i<str.size();i++){
      if(str[i]=='(') {
	ro++;
	p++;
	b[p]=1;
      }
      if(str[i]=='[') {
	so++;
	p++;
	b[p]=2;
      }	  
      if(str[i]==')') {
	if(b[p]==1) {
	  ro--;
	  p--;
	}
	else k=1;
      }
      if(str[i]==']') {
	if(b[p]==2) {
	  so--;
	  p--;
	}
	else k=1;
      }

      if(ro<0||so<0) k=1;
    }
    if(k==0&&ro==0&&so==0) cout << "yes" << endl;
    else cout << "no" << endl;
    getline(cin,str);
  }
  return 0;
}

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<long long>());

    if (N % 2 == 0) {
        long long res = 0;
        for (int i = 0; i < N/2 - 1; ++i) res += A[i] * 2;
        res += A[N/2 - 1];
        res -= A[N/2];
        for (int i = N/2 + 1; i < N; ++i) res -= A[i] * 2;
        cout << res << endl;
    }
    else {
        long long res1 = 0;
        for (int i = 0; i < N/2 - 1; ++i) res1 += A[i] * 2;
        res1 += A[N/2 - 1] + A[N/2];
        for (int i = N/2 + 1; i < N; ++i) res1 -= A[i] * 2;
        
        long long res2 = 0;
        for (int i = 0; i < N/2; ++i) res2 += A[i] * 2;
        res2 -= A[N/2] + A[N/2 + 1];
        for (int i = N/2 + 2; i < N; ++i) res2 -= A[i] * 2;
        cout << max(res1, res2) << endl;
    }
}

Measured memory_bytes: 4060
n,m=map(int,input().split())

ps=[]
pena=[[0,False] for _ in range(n)]
for i in range(m):
    ps.append(input().split())
 
for i in range(m):
    if pena[int(ps[i][0])-1][1]==False and ps[i][1]=="WA":
        pena[int(ps[i][0])-1][0]+=1
    else:
        pena[int(ps[i][0])-1][1]=True
ans=0
for i in range(n):
    if pena[i][1]==True:
        ans+=pena[i][0]
        
t=[pena[i][1] for i in range(len(pena))]
print(t.count(True),ans)


Measured memory_bytes: 43344
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll inf=1000000000000000000;

int main(){
    int n; cin >> n;
    ll ans=1;
    vector<ll> a(100100);
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]==0){
            cout << "0\n";
            return 0;
        }
    }
    for(int i=0; i<n; i++){
        if(a[i]<=inf/ans){
            ans *= a[i];
        }else{
            ans = -1;
            break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4028
#include<cstdio>
 
char have[200000];
 
int main(void) {
    int n;
    scanf("%d",&n);
 
    int dup=0;
    for(int i=0; i<n; i++) {
        int a;
        scanf("%d",&a);
        if(have[a]) dup++;
        else have[a]++;
    }
    printf("%d\n",n-(dup+1)/2*2);
    return 0;
}

Measured memory_bytes: 888
n = int(input())
A = [int(input()) for _ in range(n)]

p = {}
for a in A:
    if a in p:
        if p[a] == 1:
            p[a] = 0
            continue
    p[a] = 1
ans = 0
for i in p.values():ans += i
print(ans)

Measured memory_bytes: 20568
import collections

h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

black = collections.deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            black.append((i,j))
            
ans = 0
dx = [1,0,-1,0]
dy = [0,1,0,-1]

def bfs(y,x):
    for k in range(4):
        newy = y + dy[k]
        newx = x + dx[k]
        if 0<= newy < h and 0<= newx < w:
            if field[newy][newx] == ".":
                black.append((newy,newx))
                field[newy][newx] = "#"

while black:
    l = len(black)
    for i in range(l):
        s = black.popleft()
        y,x = s[0],s[1]
        bfs(y,x)
    ans += 1

print(ans-1)

Measured memory_bytes: 146952
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def dfs(k,l):
    if k==n+1:
        print(''.join(l))
    else:
        m = len(set(l))
        for i in range(m+1):
            c = chr(ord('a')+i)
            l.append(c)
            dfs(k+1,l)
            l.pop()

n = inn()
dfs(2,['a'])


Measured memory_bytes: 53592