akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

vector<ll>path[101010];
ll flg[101010];

int main(){

    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    for(ll i = 0; i < M; i++){
        ll x, y, z;
        cin >> x >> y >> z;
        path[x].push_back(y);
        path[y].push_back(x);
    }
    for(ll i = 1; i <= N; i++){
        if(flg[i])continue;
        ans++;
        flg[i] = 1;
        stack<ll>S;
        S.push(i);
        while(!S.empty()){
            ll idx = S.top();
            S.pop();
            for(ll i = 0; i < path[idx].size(); i++){
                ll nxt = path[idx][i];
                if(flg[nxt])continue;
                flg[nxt] = 1;
                S.push(nxt);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8180
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

bool is_bi(long long a) {
  long long b = 1;
  while (b*b <= a) {
    if (b*b == a) {
      return true;
    }
    b++;
  }
  return false;
}

void solve(long long N, long long D, std::vector<std::vector<long long>> X){
  long long t;
  long long ans = 0;
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      t = 0;
      for (int k = 0; k < D; k++) {
        t += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      if (is_bi(t)) {
        ans++;
      }
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long D;
  scanf("%lld",&D);
  std::vector<std::vector<long long>> X(N, std::vector<long long>(D));
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < D ; j++){
      scanf("%lld",&X[i][j]);
    }
  }
  solve(N, D, std::move(X));
  return 0;
}


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

typedef long long LL;

const int N = 205;
const LL mod = 998244353LL;

LL ans, base[N];
bool done[N][N];
LL x[N], y[N];
int sta[N], top;

inline LL mul(int a, int b, int c) {
  return (x[b] - x[a]) * (y[c] - y[a]) - (x[c] - x[a]) * (y[b] - y[a]);
}

int main() {
  int n;
  scanf("%d", &n);
  ans = 1;
  base[0] = 1;
  for (int i = 1; i <= n; i ++) base[i] = base[i - 1] * 2LL % mod;
  ans = base[n];
  for (int i = 1; i <= n; i ++) scanf("%lld%lld", &x[i], &y[i]);
  ans = (ans + mod - n - 1) % mod;
  for (int i = 1; i <= n; i ++)
    for (int j = 1; j <= n; j ++)
      if (!done[i][j] && i != j) {
	top = 0;
	sta[++ top] = i;
	sta[++ top] = j;
	for (int k = 1; k <= n; k ++)
	  if (k != i && k != j && mul(i, j, k) == 0) sta[++ top] = k;
	ans = (mod + ans + top + 1 - base[top]) % mod;
	for (int k = 1; k <= top; k ++)
	  for (int l = 1; l < k; l ++) done[sta[k]][sta[l]] = done[sta[l]][sta[k]] = 1;
      }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct edge{int to,cost;};
typedef pair<int,int> P;
#define MAX_N 100005

int N,M,A[3];
vector< edge > G[MAX_N];
int D[(1<<3)][MAX_N];

void dijkstra(int bit,int* d){
  for(int i=0;i<MAX_N;i++)d[i]=1e9;
  priority_queue< P , vector<P> , greater<P> > Q;

  if( __builtin_popcount(bit) == 1){
    for(int i=0;i<3;i++){
      if(bit>>i&1){
        Q.push(P(0,N+i));
        d[N+i]=0;
      }
    }
  }else{
    for(int i=0;i<N+3;i++){
      d[i]=0;
      for(int j=0;j<3;j++){
        if(bit>>j&1){
          d[i]+=D[(1<<j)][i];
        }
      }
      Q.push(P(d[i],i));
    }
  }
  
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int pos=p.second;
    int cost=p.first;
    if(d[pos]<cost)continue;
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(cost+e.cost<d[e.to]){
        d[e.to]=cost+e.cost;
        Q.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  scanf("%d",&N);
  for(int k=0;k<3;k++)scanf("%d",&A[k]);
  for(int k=0;k<3;k++){
    for(int i=0;i<A[k];i++){
      int id;
      scanf("%d",&id);
      id--;
      G[N+k].push_back( (edge){id,0} );
      G[id].push_back( (edge){N+k,0} );
    }
  }
  scanf("%d",&M);
  for(int i=0;i<M;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--,b--;
    G[a].push_back((edge){b,1});
    G[b].push_back((edge){a,1});
  }
  
  for(int k=1;k<(1<<3);k++)dijkstra(k,D[k]);
  int ans=1e9,ans2=-1;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<(1<<3);j++){
      int k=(1<<3)-1-j;
      int cost=D[j][i]+D[k][i];
      if(ans>cost){
        ans=cost;
        ans2=i;
      }
    }
  }

  printf("%d %d\n",ans,ans2+1);
  return 0;
}

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

int main(){
  int N; cin >> N;
  int L[200];
  for(int i=0; i<2*N; i++){
    cin >> L[i];
  }
  sort(L,L+2*N);
  int result=0;
  for(int i=0; i<N; i++){
    result+=L[2*i];
  }
  cout << result << endl;
}

Measured memory_bytes: 256
package main

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

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var N, X int
	fmt.Scan(&N, &X)

	var m []int
	sum := 0
	mm := 10000000
	for sc.Scan() {
		i, _ := strconv.Atoi(sc.Text())
		sum += i
		mm = min(mm, i)
		m = append(m, i)
	}

	ans := N
	X -= sum
	ans += X / mm
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    map<pair<char, char>, ll> mp;
    vector<pair<char, char>> vec;
    for (ll i = 1; i <= N; i++)
    {
        string str = to_string(i);
        auto pa = make_pair(str[0], str[str.size() - 1]);
        if (mp[pa] == NULL)
        {
            mp[pa] = 1;
            vec.push_back(pa);
        }
        else
        {
            mp[pa]++;
        }
    }

    ll count = 0;
    for (auto a : vec)
    {
        for (auto b : vec)
        {
            if (a.first == b.second && b.first == a.second)
            {
                count += mp[a] * mp[b];
            }
        }
    }

    cout << count << endl;
}

int main()
{
    solve();
    return 0;
}


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

int n;

int main()
{
	cin>>n;
	if(n&1)
	{
		printf("%d\n",(n/2)*(n/2+1));
	}
	else
	{
		printf("%d\n",(n/2)*(n/2));
	}
}



Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
N -= 1

ans = ''
while N >= 0:
    d, m = divmod(N, 26)
    ans += chr(m+97)
    N = d - 1
ans = ans[::-1]
print(ans)


Measured memory_bytes: 9520
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string s,t;
  cin >> s >> t;
  int i,ans=0;
  for(i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  vector<vector<int>> G(N);
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int root = -1;
  int max_deg = 0;
  REP(i, N) {
    if (max_deg < int(G[i].size())) {
      max_deg = int(G[i].size());
      root = i;
    }
  }
  vector<i64> C(N);
  for (auto& x : C) cin >> x;
  sort(C.rbegin(), C.rend());
  i64 ans = accumulate(C.begin() + 1, C.end(), 0LL);
  cout << ans << endl;

  vector<i64> d(N, -1);
  int k = 0;
  auto dfs = [&](auto rec, int v, int p) {
    if (k == N) return;
    d[v] = C[k++];
    for (auto x : G[v]) {
      if (x == p) continue;
      rec(rec, x, v);
    }
  };
  dfs(dfs, root, -1);
  REP(i, N) { cout << (i == 0 ? "" : " ") << d[i]; }
  cout << endl;
}

Measured memory_bytes: 4636
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;
int n,m;
LL val[MAXN];
int fa[MAXN];
unordered_map<int, int> mp;
bool vis[MAXN];
LL other[MAXN];
int po;

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

inline bool merge(int x, int y) {
    int fx = find(x), fy = find(y);
    if(fx==fy) return false;
    fa[fx] = fy;
    return true;
}

inline void makeFa() {
    for(int i=0; i<n; i++) {
        fa[i] = i;
    }
}

inline int pmin(int a, int b) {
    return val[a]<=val[b]?a:b;
}

int main() {
    while(scanf("%d%d", &n, &m)==2) {
        makeFa();
        mp.clear();
        memset(vis, 0, sizeof vis);
        po = 0;
        for(int i=0; i<n; i++) {
            scanf("%lld", val+i);
        }
        for(int i=0; i<m; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            merge(x, y);
        }
        for(int i=0; i<n; i++) {
            int fx = find(i);
            if(mp.count(fx)) {
                mp[fx] = pmin(mp[fx], i);
            }
            else {
                mp[fx] = i;
            }
        }
        int N = mp.size();
        if(N==1) {
            puts("0");
            continue;
        }
        if(2*(N-1)>n) {
            puts("Impossible");
            continue;
        }
        LL ans = 0;
        for(auto& it : mp) {
            ans += val[it.second];
            vis[it.second] = true;
        }
        for(int i=0; i<n; i++) {
            if(!vis[i]) {
                other[po++] = val[i];
            }
        }
        sort(other, other+po);
        for(int i=0; i<2*(N-1)-N; i++) {
            ans += other[i];
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 5668
n, m = gets.chomp.split.map(&:to_i)

h = gets.chomp.split.map(&:to_i)
h.unshift(0)

t = Array.new(n+1) { Array.new }

m.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  t[a].push(b)
  t[b].push(a)
end

ans = 0
1.upto(n) do |i|
  if t[i].empty? || h[i] > t[i].map{|m| h[m]}.max
    ans += 1
  end
end
p ans


Measured memory_bytes: 27464
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		int d = in.nextInt();
		new AOJ0141().doIt();
		for(int i=1;i<d;i++){
			System.out.println();
			new AOJ0141().doIt();
		}
	}
	
	class AOJ0141{
		boolean[][] hyou;
		int[] sx = {0,1,0,-1};
		int[] sy = {-1,0,1,0};
		int x,y,n;
		int dir;
		void doIt(){
			n = in.nextInt();
			hyou = new boolean[n][n];
			x = 0;y = n-1;
			hyou[y][x] = true;
			dir = 3;//direction
			while(true){
				int nx = x+sx[dir];
				int ny = y+sy[dir];
				if(nx<0||nx>=n||ny<0||ny>=n||isEnd(nx,ny)){
					dir = (dir+1)%4;
					x = x+sx[dir];
					y = y+sy[dir];
					if(x<0||x>=n||y<0||y>=n||isEnd(x,y))break;
					hyou[y][x] = true;
					continue;
				}
				x = nx;
				y = ny;
				hyou[y][x] = true;
			}
			for(int i=0;i<n;i++){
				for(int s=0;s<n;s++)System.out.print(hyou[i][s]? "#":" ");
				System.out.println();
			}
		}
		
		boolean isEnd(int x,int y){
//			System.out.println(x+" "+y);
			int cnt = 0;
			for(int i=0;i<4;i++){
				int nx = x+sx[i];
				int ny = y+sy[i];
				if(nx<0||nx>=n||ny<0||ny>=n)continue;
				if(hyou[ny][nx])cnt++;
			}
			return cnt>1;
		}
		
	}
}

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

struct node {
    int a;
    string name;
    node(int aa = 0,string ss = "") {
        a = aa;
        name = ss;
    }
};

node a[100002];

class Queue {
private:
    int head;
    int tail;
    const int MaxSize = 100002;
public:
    Queue() {
        head = tail = 0;
    }
    int getSize() {
        return (tail-head+MaxSize) % MaxSize;
    }
    bool check_full() {
        return (tail+1)%MaxSize == head;
    }
    bool check_empty() {
        return tail == head;
    }
    void push(node x) {
        if(!check_full()) {
            a[tail] = x;
            tail = (tail+1) % MaxSize;
        }
    }
    void pop() {
        if(!check_empty()) {
            head = (head+1) % MaxSize;
        }
    }
    node top() {
        if(!check_empty()) {
            return a[head];
        }
    }
    ~Queue() {}
};

int main()
{
    Queue q;
    int n,limit; cin >> n >> limit;
    while(n--) {
        string name; int a;
        cin >> name >> a;
        q.push(node(a,name));
    }
    int sum = 0;
    while(!q.check_empty()) {
        node tmp = q.top();
        q.pop();
        if(tmp.a <= limit) {
            sum += tmp.a;
            cout << tmp.name << " " << sum << endl;
        } else {
            tmp.a -= limit;
            q.push(tmp);
            sum += limit;
        }
    }
    return 0;
}



Measured memory_bytes: 7080
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

int N;
int A[100];
int a, b;
string S;
string ans = "";

void _main() {
	cin >> N;
	cin >> S;
	string Z = "Z";
	string A = "A";

	rep(i, 0, S.length()) {
		//Nを足したらZを超えてしまう場合はA-1から超過分を足す
		//"A"-1なのは超過１の場合は"A",超過２の場合は"B"…と始めるから
		if (S[i]+N > Z[0]) 
			ans += A[0]-1 + (S[i]+N - Z[0]);
		else
			ans += S[i] + N;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
adj = Array.new(n).map{Array.new}
(n-1).times do
  a,b = gets.chomp.split(" ").map{|i|i.to_i-1}
  adj[a] << b
  adj[b] << a
end
vst = Array.new(n,false)
vst[0] = true
vst[n-1] = true
sum = [1,1]
q = [[],[]]
f = [[0],[n-1]]
while vst.include?(false)
  q = Marshal.load(Marshal.dump(f))
  f = [[],[]]
  2.times do |i|
    q[i].each do |j|
      adj[j].each do |k|
        if vst[k] == false
          vst[k] = true
          f[i] << k
        end
      end
    end
    sum[i] += f[i].size
  end
end
if sum[0] > sum[1]
  puts "Fennec"
else
  puts "Snuke"
end

Measured memory_bytes: 15508
import math

def A():
    x, a, b = [int(x) for x in input().split()]
    if abs(x-a) < abs(x-b):
        print('A')
    else:
        print('B')
def B():
    S = input()
    alphabet = [False for x in range(26)]
    for char in S:
        i = ord(char) - ord('a')
        alphabet[i] = True
    printed = False
    for i in range(len(alphabet)):
        if alphabet[i] == False:
            print(chr(ord('a')+i))
            printed = True
            break
    if printed == False:
        print("None")
B()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int p[m];
    string s;
    int ac=0, wa=0;
    int ac1flag[100001]={0};
    int wacnt[100001] = {0};
    for(int i=0; i<m; i++){
        cin >> p[i] >> s;
        if(s == "AC"){
            if(ac1flag[p[i]] == 0){
                ac++;
                ac1flag[p[i]] = 1;
            }
        }else if( s == "WA"){ // "WA"
            if(ac1flag[p[i]]==0){
                wacnt[p[i]] = wacnt[p[i]] +1;
            }
        }
    }
    for( int i=0; i<m; i++){
        if(ac1flag[p[i]]==0){
            wacnt[p[i]] = 0;
        }
    }
    wa = accumulate(wacnt,wacnt+100001,0);

    cout << ac << " " << wa << endl;
}




Measured memory_bytes: 1408
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int x = n;
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x /= 10;
	}
	if (n % sum == 0) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const S = arg[1].split("");
    const K = ~~arg[2];
    
    for(let i in S) {
        if(S[i] !== S[K-1]) {
            S[i] = "*";
        }
    }
    
    console.log(S.join(""));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

typedef long long ll;

vector<int> x, y, p;
vector<vector<int>> a, b;
vector<ll> ans;
int n;

int bitx = 0, bity = 0;

void dfs(int ind){
    if(ind == n){
        ll tmp = 0;
        for(int i = 0; i < n; i++){
            int diff = min({abs(x[i]), abs(y[i]), a[i][bitx], b[i][bity]});
            tmp += (ll)diff * p[i];
        }
        int pop = 0;
        for(int i = 0; i < n; i++)  pop += (bitx>>i&1) + (bity>>i&1);
        ans[pop] = min(ans[pop], tmp);
        return;
    }
    bitx ^= 1<<ind;
    dfs(ind+1);
    bitx ^= 1<<ind;
    bity ^= 1<<ind;
    dfs(ind+1);
    bity ^= 1<<ind;
    dfs(ind+1);
}

int main(){
    cin >> n;
    x.resize(n);
    y.resize(n);
    p.resize(n);
    ans.resize(n+1, 1ll<<60);
    a.resize(n, vector<int>(1<<n, 30000));
    b.resize(n, vector<int>(1<<n, 30000));
    for(int i = 0; i < n; i++)  cin >> x[i] >> y[i] >> p[i];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 1<<n; j++){
            for(int k = 0; k < n; k++){
                if(j>>k&1)  a[i][j] = min(a[i][j], abs(x[k]-x[i])), b[i][j] = min(b[i][j], abs(y[k]-y[i]));
            }
        }
    }
    dfs(0);
    for(int i = 0; i < n+1; i++)  cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7100
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define N 1000001
#define NN 1001
using namespace std;
LL n,a[N];
LL mod=1000000007;
int main()
{
	cin>>n;
	long long s=0,sum=0;
	for(LL i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(LL i=1;i<=n;i++)
	{
		sum-=a[i];
		s=(((a[i]%mod)*(sum%mod)%mod)+s)%mod;
	}
	cout<<s<<endl;
	return 0;		
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a>0){
    cout << "Positive" << endl;
  }
  else if(b>=0){
    cout << "Zero" << endl;
  }
  else{
    if((b-a)%2==0){
      cout << "Negative" << endl;
    }
    else{
      cout << "Positive" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using lb = long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

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

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

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/*-------------ここまで---------------------------------------------*/
int main(){
    int D;
    cin >> D;
    string ans;
    if (D == 25) ans = "Christmas";
    else if (D == 24) ans = "Christmas Eve";
    else if (D == 23) ans = "Christmas Eve Eve";
    else ans = "Christmas Eve Eve Eve";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> a(h,vector<int>(w));

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	vector<string> ans;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			stringstream ss;
			if (a[i][j] % 2 == 1) {
				if (j < w - 1) {
					a[i][j + 1]++;
					a[i][j]--;
					ss << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 ;
					ans.emplace_back(ss.str());
				}
				else if (i < h - 1) {
					a[i+1][j]++;
					a[i][j]--;
					ss << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1;
					ans.emplace_back(ss.str());
				}
			}
		}
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size();i++) {
		cout << ans[i] << endl;
	}

}


Measured memory_bytes: 12020
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)
	const w = args.slice(1, n + 1).map(arg => arg[0])
	const t1 = {}
	let t2 = true

	for (let i = 0; i < n; i++) {
		if (w[i] in t1) t1[w[i]]++
		else t1[w[i]] = 1
	}

	for (let i = 1; i < n; i++) {
		if (w[i - 1][w[i - 1].length - 1] !== w[i][0]) t2 = false
	}

	if ( Object.keys(t1).filter(key => t1[key] > 1).length === 0 && t2 ) console.log('Yes')
	else console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int A;
int B;

int main() {
  cin >> A >> B;
  if (13 <= A) cout << B << endl;
  else if (6 <= A && A <= 12) cout << B / 2 << endl;
  else if (A <= 5) cout << 0 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_V 100
#define min(a, b) ((a) < (b) ? (a) : (b))

const int INF = 100000000;
int cost[MAX_V][MAX_V];
int V;

int
prim()
{
	int mincost[MAX_V];
	bool used[MAX_V];
	int u, v;
	int i;

	for (i = 0; i < V; ++i)
	{
		mincost[i] = INF;
		used[i] = false;
	}

	int res = 0;
	mincost[0] = 0;
	while (true)
	{
		v = -1;
		for (u = 0; u < V; ++u)
		{
			if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
				v = u;
		}

		if (v == -1)
			break;

		used[v] = true;
		res += mincost[v];
		for (u = 0; u < V; ++u)
			mincost[u] = min(mincost[u], cost[v][u]);
	}

	return res;
}

int
main(int argc, char** argv)
{
	int c;
	int i, j;

	scanf("%d", &V);
	for (i = 0; i < V; ++i)
	{
		for (j = 0; j < V; ++j)
		{
			scanf("%d", &c);
			cost[i][j] = (c != -1) ? c : INF;
		}
	}

	printf("%d\n", prim());
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,c=0;
  cin>>n;
  reps(i,1,n+1){
    if(to_string(i).size()%2)c++;
  }
  cout<<c;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();
    for (int i = 1; i < N; i++) a[i] += a[i - 1];
    int[][] res = new int[H][W];
    for (int i = 0; i < H * W; i++) {
      int x = i / W;
      int y = i % W;
      if (x % 2 == 1) y = W - y - 1;
      res[x][y] = lowerBound(a, i + 1) + 1;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) sb.append(res[i][j]).append(' ');
      sb.setLength(sb.length() - 1);
      sb.append('\n');
    }
    System.out.print(sb.toString());
  }

  public static int lowerBound(int[] a, int k) {
    int left = -1;
    int right = a.length;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (k <= a[mid]) {
        right = mid;
      } else {
        left = mid;
      }
    }
    return right;
  }
}


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

int main() {
    int n;
    cin >> n;
    auto h = vector<int>(n);
    for (auto &h_i : h)
        cin >> h_i;

    auto h_last = 2'000'000'000;
    for (int i = n - 1; i >= 0; i--) {
        if (h[i] <= h_last) {
            h_last = h[i];
            continue;
        }

        if (h[i] - 1 <= h_last) {
            h_last = h[i] - 1;
            continue;
        }

        goto fail;
    }

    cout << "Yes";
    return 0;

fail:
    cout << "No";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


void solve(){

    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll p=0;
    ll q=0;
    ll ans = 0;
    for(ll i=1; i<n; i++){
        string s1 = s.substr(0,i);
        string s2 = s.substr(i,n-i);
        set<char> st1, st2;
        rep(j,s1.length()){
            st1.insert(s1[j]);
        }
        rep(j,s2.length()){
            st2.insert(s2[j]);
        }
        set<char> result;
        set_intersection(st1.begin(), st1.end(),
                        st2.begin(), st2.end(),
                        std::inserter(result, result.end()));
        ans = max(ll(ans), ll(result.size()));
    }

    cout << ans << endl;

}

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


Measured memory_bytes: 256
from collections import deque
 
N,M = map(int, input().split())
nl = {i:[] for i in range(1,N+1)}
rlt = [-1]*(N+1)
 
for _ in range(M):
  a,b = map(int, input().split())
  nl[a].append(b)
  nl[b].append(a)

ds = [float('inf')]*(N+1)
ds[1] = 0
h = deque()
h.append(1)
 
while(len(h) > 0):
  v = h.popleft()
  for j in nl[v]:
    if ds[j] == float('inf'):
      ds[j] = ds[v] + 1
      rlt[j] = v
      h.append(j)

if -1 in rlt[2:]:
  print('No')
else:
  print('Yes')
  for i in rlt[2:]:
    print(i)

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

#define int long long
int f[1 << 6][303] , N , C , L[7] , id[6] , sum;

int dp(){
	memset(f , 0 , sizeof(f)); f[0][L[N] * N] = 1;
	for(int i = 1 ; i <= N * C ; ++i)
		if(i % N)
			for(int j = 0 ; j < 1 << (N - 1) ; ++j)
				if(!(j >> (id[i % N] - 1) & 1))
				   for(int k = i ; k <= N * C ; ++k)
					   f[j | (1 << (id[i % N] - 1))][min(N * C , max(k , i + N * L[id[i % N]]))] += f[j][k];
	return f[(1 << (N - 1)) - 1][C * N];
}

signed main(){
	cin >> N >> C; for(int i = 1 ; i <= N ; ++i) cin >> L[i];
	sort(L + 1 , L + N + 1); for(int i = 1 ; i < N ; ++i) id[i] = i;
	do{sum += dp();}while(next_permutation(id + 1 , id + N));
	int tms = 1; for(int i = 1 ; i < N ; ++i) tms *= i * C;
	cout << fixed << setprecision(15) << (long double)sum / tms; return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll cnt = K;

    // A
    ll ans = min(A, cnt);
    cnt -= min(A, cnt);

    // B
    cnt = max(0LL, cnt - B);

    // C
    ans -= cnt;

    cout << ans << endl;

    return 0;
}


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

int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll x = min({a, b, c, d, e});
    cout << ((n + x - 1) / x + 4) << endl;
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto & a : A)
    cin >> a;
  sort(A.begin(), A.end());
  int cnt = 0;
  for (int i = 0; i < N; ++i)
  {
    if (A[i] == A[i + 1])
      ++i;
    else
      ++cnt;
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

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

	for (int i = s.size() - 2; i > 0; i -= 2) {
		s = s.substr(0, i);
		string a = s.substr(0, i / 2);
		string b = s.substr(i / 2);

		if (a == b) {
			cout << a.size() * 2 << endl;
			return 0;
		}
	}

	cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

//組み合わせの数nCrを計算
ll calcNumOfCombination(ll n, ll r){
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }


  map<ll, ll> nums;
  vector<ll> s(n+1);
  s[0] = 0;
  nums[0]++;

  rep(i, n) {
    s[i+1] = s[i] + a[i];
    nums[s[i+1]]++;
  }

  ll ans = 0;
  for (auto itr = nums.begin(); itr != nums.end(); itr++) {
    if (itr->second < 2) continue;
    ans += calcNumOfCombination(itr->second, 2);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        //約数の数カウント
        int count=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)count++;
        }
        if(count==8)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

long long mx[21][1 << 21];

int main() {
  int n, q;
  cin >> n >> q;
  rep (i, q) {
    int a, v;
    cin >> a >> v;
    mx[0][a] += v;
    rep (j, 20) mx[j + 1][a >> (j + 1)]  = max(mx[j][a >> j], mx[j][a >> j ^ 1]);
    int r = 0;
    rep (j, 20) {
      if (mx[19 - j][2 * r] >= mx[19 - j][2 * r + 1]) r *= 2;
      else r = 2 * r + 1;
    }
    cout << r << " " << mx[20][0] << endl;
  }
  return 0;
}

Measured memory_bytes: 52352
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>
#include <bitset>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef pair<long long, long long> pllll;
typedef pair<long long, int> plli;
typedef pair<int,long long> pill;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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


    ll n; cin>>n;

    ll ret = 0;

    for (ll t = 1; t<=n; ++t) {
        if ( (t%3)!=0 && (t%5)!=0) {
            ret += t;
        }
    }
    cout<<ret<<el;
}

Measured memory_bytes: 3640
#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++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;
 
int main(){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(a < b){
        if(a + v * t < b + w * t){
        cout << "NO" << endl;
        }
        else{
            cout << "YES" << endl;
    	}
    }
    else if(a > b){
        if(a - v * t > b - w * t){
        	cout << "NO" << endl;
	    }
    	else{
    	    cout << "YES" << endl;
    	}
    }
 
}


Measured memory_bytes: 3636
#include<iostream>
#include<array>
#include<string>
#include<algorithm>

using namespace std;

int main(){                                                                      array<int,200000>a;
    int n;                                                                       cin>>n;                                                                      for(int i = 0; i < n; i++){
        cin>>a.at(i);
    }                                                                            sort(a.begin(),a.begin() + n);
    for(int i = 0; i < n-1; i++){
        if(a.at(i) == a.at(i + 1)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

}

Measured memory_bytes: 1024
/**
 * Let S(n, k) be the score of the game for player 1 using only the first n
 * elements of A if there are currently k stones in play.  If player 1 wins
 * the game, S(n, k) will be 1.  Otherwise, S(n, k) will be -1.
 * 
 * On player 1's turn, he has two types of options - he can either take A[n]
 * stones from the pile, or he can look through the remaining n-1 options to
 * take stones from the pile.  Then if he is playing optimally:
 * 
 * S(n, k) = max(-S(N, k - A[n]), S(n-1, k)) if k >= A[n]
 * S(n, k) = S(n-1, k) otherwise
 * S(0, k) = -1
 * S(n, 0) = -1
 */

#include <stdio.h>
#include <stdlib.h>

char max(char a, char b)
{
    return a > b ? a : b;
}

int solution(int *a, int N, int K)
{
    char S[N+1][K+1];
    int n, k;
    
    for (k=0; k<=K; k++)
    {
        S[0][k] = -1;
    }
    
    for (n=0; n<=N; n++)
    {
        S[n][0] = -1;
    }
    
    for (k=1; k<=K; k++)
    {
        for (n=1; n<=N; n++)
        {
            if (k >= a[n-1])
            {
                S[n][k] = max(-S[N][k-a[n-1]], S[n-1][k]);
            }
            else
            {
                S[n][k] = S[n-1][k];
            }
        }
    }
    
    /*for (n=0; n<=N; n++)
    {
        for (k=0; k<=K; k++)
        {
            printf("%d\t", S[n][k]);
        }
        printf("\n");
    }*/
    
    return S[N][K];
}

int main(int argc, char **argv)
{
	int N, K;
	int i;
	
	scanf("%d %d", &N, &K);
	
	int a[N];
	
	for (i=0; i<N; i++)
	{
	    scanf("%d", &a[i]);
	}
	
	printf("%s\n", solution(a, N, K) == 1 ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 10112
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using static System.Math;
using static System.Console;

class E { static void Main() => new J(); }
class J
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var n = F();
		var mc = new int[26];
		for (var i = 0; i < 26; i++) mc[i] = 100;
		for (var i = 0; i < n; i++)
		{
			var c = new int[26];
			var s = ReadLine();
			foreach (var ch in s) c[ch - 'a']++;
			for (var j = 0; j < 26; j++) mc[j] = Min(mc[j], c[j]);
		}
		for (var i = 0; i < 26; i++) for (var j = 0; j < mc[i]; j++) Write((char)('a' + i));
		WriteLine();
	}
}

Measured memory_bytes: 13140
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i*10000 + j*5000 + (n - i - j)*1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")


Measured memory_bytes: 2940
#include<iostream>
#include<string.h>

using namespace std;

int main() {
	int W, H, N;
	int x[105];
	int y[105];
	int a[105];
	int lx = 0, rx, uy, dy = 0;
	int ex, ey;

	cin >> W >> H >> N;

	rx = W;
	uy = H;

	for (int i = 0; i < N; i++)
		cin >> x[i] >> y[i] >> a[i];

	for (int i = 0; i < N; i++) {
		if (a[i] == 1 && lx < x[i])
			lx = x[i];
		else if (a[i] == 2 && rx > x[i])
			rx = x[i];
		else if (a[i] == 3 && dy < y[i])
			dy = y[i];
		else if (a[i] == 4 && uy > y[i])
			uy = y[i];
	}

	ex = rx - lx;
	ey = uy - dy;

	if (ex <= 0 || ey <= 0)
		cout << "0" << endl;
	else
		cout << ex * ey << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%lld",&(x));
#define pb push_back
#define fi first
#define se second
#define P pair<int,int>
#define endl '\n'
int _,t,a,b,n,m,k,x;

int A[500005];


signed main()
{
   cin>>n>>a>>b;
   int x = n%(a+b);
   int y=n/(a+b);
   int ans=0;
   ans+=y*a;
   if(x<=a)ans+=x;
   else ans+=a;
cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

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

  bool Yes = false;

  for (int i = 0; i < s.size(); i++) {
    s = s[s.size() - 1] + s;
    s.pop_back();

    // cout << s << "\n";

    if (s == t) {
      Yes = true;
      break;
    }
  }

  if (Yes) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
ll vis[200005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll x,i, j, k, l, n, m;
    cin >> n >> x >> m;
    ll cx = x;
    vector<ll> data;
    data.pb(x);
    for (i = 2;i<=1000000;i++){
        cx = (cx * cx) % m;
        data.pb(cx);
    }
    ll sz = data.size();
    ll repst, repl;
    for (i = 1; i <= sz;i++){
        if(vis[data[i-1]]!=0){
            repst = vis[data[i-1]];
            repl = i - vis[data[i-1]];
            break;
        }
        else{
            vis[data[i-1]] = i;
        }
    }
    ll ans = 0;
    for (i = 1; i < repst&&i<=n;i++){
        ans += data[i - 1];
    }
    if(n>=repst){
        ll kola = n - repst + 1;
        ll div = kola / repl;
        ll sum = 0;
        for (i = 1; i <= repl;i++){
            sum += data[i + repst - 2];
        }
        ans += (sum * div);
        ll extra = kola % repl;
        for (i = 1; i <= extra;i++){
            ans+=data[i + repst - 2];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 11972
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0549
AC
"""
import sys
from sys import stdin
from itertools import accumulate
input = stdin.readline
import array

def main(args):
    n, m = map(int, input().split())
    distances = [int(input()) for _ in range(n-1)]
    inns = list(accumulate(distances))
    moves = [int(input()) for _ in range(m)]

    inns.insert(0, 0)
    pos = 0
    total_distance = 0
    for m in moves:
        new_pos = pos + m
        total_distance += abs(inns[new_pos] - inns[pos])
        pos = new_pos

    print(total_distance % 100000)



def main2(args):
    n, m = map(int, input().split())

    pos = 0
    inns = array.array('Q', [0])
    for _ in range(n-1):
        pos += int(input())
        inns.append(pos)
    moves = [int(input()) for _ in range(m)]

    pos = 0
    total_distance = 0
    for m in moves:
        new_pos = pos + m
        total_distance += abs(inns[new_pos] - inns[pos])
        pos = new_pos

    print(total_distance % 100000)



if __name__ == '__main__':
    main2(sys.argv[1:])

Measured memory_bytes: 12468
//
// Created by Hideaki Imamura on 2020-04-04.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int x, y, z;

int main() {
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

int main(){
  int a[] = {1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin >> x >> y;
  if(a[x-1] == a[y-1]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

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

int main() {
	
	//解説PDFを見ました(迫真)

	int N;
	string S;
	cin >> N >> S;

	map<string, int> GODmae, GODato;

	rep(i, 1 << N) {
		string blue = "";
		string red = "";
		string blue2 = "";
		string red2 = "";
		rep(ii, N) {
			if ((i >> ii & 1) == 1) {
				blue += S.substr(ii, 1);
				blue2 += S.substr(2 * N - ii - 1, 1);
			}
			else {
				red += S.substr(ii, 1);
				red2 += S.substr(2 * N - ii - 1, 1);
			}
		}
		GODmae[blue + "," + red]++;
		GODato[blue2 + "," + red2]++;
	}

	long long kotae = 0;
	for (auto itr : GODmae) kotae += 1ll * GODmae[itr.first] * GODato[itr.first];
	cout << kotae << "\n";
	Would you please return 0;
}


Measured memory_bytes: 83584
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
int dp[ohara];

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

  cin >> n;
  dp[0] = 1;
  rrep(i, 1, n + 1) {
    if (dp[i - 100] == 1 && i >= 100) dp[i] = 1;
    if (dp[i - 101] == 1 && i >= 101) dp[i] = 1;
    if (dp[i - 102] == 1 && i >= 102) dp[i] = 1;
    if (dp[i - 103] == 1 && i >= 103) dp[i] = 1;
    if (dp[i - 104] == 1 && i >= 104) dp[i] = 1;
    if (dp[i - 105] == 1 && i >= 105) dp[i] = 1;
  }
  Cout(dp[n]);
  return 0;
}

Measured memory_bytes: 640