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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
const int INF = 100100100;

int main() {
    int n,m; cin >> n >> m;
    string s; cin >> s;
    int dp[n+1]; rep(i,n+1) dp[i] = INF;
    dp[0] = 0;
    int check = 0;
    int to[n+1]; rep(i,n+1) to[i] = 1;
    int last[n+1]; rep(i,n+1) last[i] = -1;
    rep(i,n) {
        check = max(check, i);
        if (s[i] == '1') continue;
        if (dp[i] == INF) continue;
        for (int j = max(check+1, i+1); (j <= m+i && j <= n); j++) {
            check = max(check, j);
            if (s[j] == '1') continue;
            if (dp[j] > dp[i]+1) {
                dp[j] = dp[i]+1;
                last[j] = i;
            }
        }
    }
    if (dp[n] == INF) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    int now = n;
    while (now != -1) {
        ans.push_back(now);
        now = last[now];
    }
    int len = sz(ans);
    rep(i,len-1) {
        printf("%d ", ans[len-i-2] - ans[len-1-i]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 5012
import java.util.*;
import java.awt.*;

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

    int n = sc.nextInt();
    int[] p_index = new int[n];
    for (int i = 0; i < n; i++) {
      p_index[sc.nextInt()-1] = i;
    }

    int ans = 0;
    int count = 0;
    int prev_index = -1;

    for (int i = 0; i < n; i++) {
      if (p_index[i] > prev_index) {
        count++;
      } else {
        ans = Math.max(ans, count);
        count = 1;
      }

      prev_index = p_index[i];
    }

    ans = Math.max(ans, count);
    System.out.println(n - ans);
  }
}


Measured memory_bytes: 84392
#include<bits/stdc++.h>
using namespace std;
const int inf=2147483647;
#define N 100005
int n,m,S,T,cc=1,hd[1000005],iter[1000005],d[1000005],vis[N],t[N],t1[N],t2[N];
vector<int>g[N];
struct E{int v,nxt,w;}e[1000005];
void add(int u,int v,int w){e[++cc]=(E){v,hd[u],w};hd[u]=cc;e[++cc]=(E){u,hd[v],0};hd[v]=cc;}
bool bfs()
{
	for(int i=1;i<=T;i++)d[i]=inf;
	queue<int>q;q.push(S);d[S]=0;
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=hd[x];i;i=e[i].nxt)if(e[i].w&&d[e[i].v]==inf){d[e[i].v]=d[x]+1;q.push(e[i].v);}
	}
	return d[T]<inf;
}
int dfs(int x,int f)
{
	if(!f||x==T)return f;
	int sf=0;
	for(int &i=iter[x];i;i=e[i].nxt)if(e[i].w&&d[e[i].v]==d[x]+1)
	{
		int ff=dfs(e[i].v,min(f,e[i].w));
		if(ff){e[i].w-=ff;e[i^1].w+=ff;f-=ff;sf+=ff;}
	}
	return sf;
} 
int dinic()
{
	int ans=0;
	while(bfs())
	{
		memcpy(iter,hd,sizeof(iter));
		int f;while(f=dfs(S,inf))ans+=f;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);S=1;T=2*n;
	for(int i=2;i<=n;i++)add(S,i,1);
	for(int i=n+1;i<2*n;i++)add(i,T,1);
	for(int i=2;i<=n;i++)
	{
		int sz;scanf("%d",&sz);
		while(sz--)
		{
			int x;scanf("%d",&x);
			g[x].push_back(i);
			if(x>1)add(i,x+n-1,1);
		}
	}
	if(dinic()!=n-1){puts("-1");return 0;}
	for(int i=2;i<=n;i++)for(int j=hd[i];j;j=e[j].nxt)if(!e[j].w)t[i]=e[j].v-n+1;
	queue<int>q;q.push(1);
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=0;i<g[x].size();i++)
		{
			int y=g[x][i];
			if(vis[y])continue;
			vis[y]=1;t1[y]=x;t2[y]=t[y];
			q.push(t[y]);
		} 
	}
	for(int i=2;i<=n;i++)if(!t1[i]){puts("-1");return 0;}
	for(int i=2;i<=n;i++)printf("%d %d\n",t1[i],t2[i]);
	return 0;
}

Measured memory_bytes: 29816
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define rgi register int
#define rgl register ll
#define maxn 1000005
#define mod 1000000003
#define inf 1000000007
namespace lib
{
	using namespace std;
	
	
	class fastio
	{
		private:
			#define _NUMLEN 111
			char _num[_NUMLEN],_ch;
			int _f,_head;
			bool _useSTD;
		public:
			inline void ioSTD()
			{
				_useSTD=1;
				ios::sync_with_stdio(false);
				cin.tie(0),cout.tie(0);
			}
			inline void gc(char & _c)
			{
				if(_useSTD)cin>>_c;
				else _c=getchar();
			}
			inline void pc(char _c)
			{
				if(_useSTD)cout<<_c;
				else putchar(_c);
			}
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_x=0;
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch);
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch);
					_f&&(_x=-_x,_f=0);
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_T _k;
					if(_x==0) {pc('0'),pc(' ');return *this;}
					if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
					while(_head>0) pc(_num[_head]),--_head;
					pc(' ');
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define endln pc('\n')
		fastio() {_f=0,_head=0,_useSTD=0,_ch=' ';}
	}io;
	
	
	inline void fileio(string _r,string _w)
	{
		if(_r[0]!='-')freopen(_r.c_str(),"r",stdin);
		if(_w[0]!='-')freopen(_w.c_str(),"w",stdout);
	}
}using namespace lib;

signed main()
{
//	fileio("tt.in","tt.out");
//	io.ioSTD();
	ll a,ans=0;
	io-a;
	if(a&1)io+0;
	else
	{
		for(rgl t=10;t<=a;t*=5)ans+=(a/t);
		io+ans;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        int[][] bingo = new int[3][3];
        boolean[][] bingoOK = new boolean[3][3];
        for (int i = 0; i < 3; i++) {
            bingo[i][0] = sc.nextInt();
            bingo[i][1] = sc.nextInt();
            bingo[i][2] = sc.nextInt();
        }
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int v = sc.nextInt();
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (bingo[j][k] == v) {
                        bingoOK[j][k] = true;
                        break;
                    }
                }
            }
        }

        // 横
        parent : for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3 ; j++) {
                if (!bingoOK[i][j]) {
                    continue parent;
                }
            }
            System.out.println("Yes");
            return;
        }

        // 縦
        parent : for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3 ; j++) {
                if (!bingoOK[j][i]) {
                    continue parent;
                }
            }
            System.out.println("Yes");
            return;
        }

        // 斜め
        if (bingoOK[0][0] && bingoOK[1][1] && bingoOK[2][2]) {
            System.out.println("Yes");
            return;
        }
        if (bingoOK[0][2] && bingoOK[1][1] && bingoOK[2][0]) {
            System.out.println("Yes");
            return;
        }

        System.out.println("No");
    }
}


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

namespace ALDS1_3B{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var Q = sr.Next<int>();
            var A = sr.Next<string>(N, 2).Select(a => new {Name = a[0], Time = int.Parse(a[1])});

            var qn = new Queue<string>();
            var qt = new Queue<int>();

            foreach(var a in A){
                qn.Enqueue(a.Name);
                qt.Enqueue(a.Time);
            }

            var res = 0;
            while(qn.Count > 0){
                var name = qn.Dequeue();
                var time = qt.Dequeue();
                if(time > Q){
                    qn.Enqueue(name);
                    qt.Enqueue(time - Q);
                    res += Q;
                } else{
                    res += time;
                    Console.WriteLine(name + " " + res);
                }
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 23208
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
int ctoi(char c){
  if(c>='0'&&c<='9'){
    return c-'0';
  }
  return 0;
}


//cout << setprecision(123)<<ans;
//int a=atoi(S.c_str());
//string S=to_string(a);
//int &a=b;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22)cout<<"bust"<<endl;
  else cout<<"win"<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

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

count = [0] * (N)
E = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    E[a - 1].append(b - 1)
    E[b - 1].append(a - 1)
    count[a - 1] += 1
    count[b - 1] += 1

count_sum = 0
count4 = 0
count6 = 0
node = 0

check = [False] * N

for i, temp in enumerate(count):
    if temp % 2 == 1:
        print("No")
        exit()
    else:
        if temp >= 4:
            count4 += 1
            check[i] = True
            node = i
        if temp >= 6:
            count6 += 1
        count_sum += temp

def dfs(v, first, depth):
    global E, check

    ret = 0
    for next_v in E[v]:
        if depth >= 2 and next_v == first:
            return 1
        elif not check[next_v]:
            check[next_v] = True
            ret += dfs(next_v, first, depth + 1)

    return ret

if count4 >= 3 or count6 >= 1:
    print("Yes")
elif count4 == 2:
    ret = dfs(node, node, 0)
    if ret > 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")
    


Measured memory_bytes: 45536
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;

ll L,R;
int main(){
    cin>> L>>R;
    ll count=0;
    ll ans=2019;
    if(L==0){
        cout<<'0'<<endl;
        return 0;
    }
    if(R-L>=2019){
        cout<<'0'<<endl;
        return 0;
    }
    for(ll i=L;i<=R;i++){
        for(ll j=i+1;j<=R;j++){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[110];
int main()
{
    int n,w;int minn=1000000000;
    scanf("%d",&n);
    int sum=0;a[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]+=sum;
        sum=a[i];
    }
    for(int i=0;i<=n;i++)
    {
        minn=min(minn,abs((a[i]-a[0])-(a[n]-a[i])));
    }
    printf("%d\n",minn);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)



int main()
{
    ll N;
    ll K;
    cin >> N >> K;
    ll small;
    if (abs(N%K-K) > N%K) {
        small = N % K;
        cout << small << endl;
    } else
    {
        small = abs(N%K-K);
        cout << small << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    string c1, c2;
    cin >> c1 >> c2;
    cout << ((c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cctype>

using namespace std;

typedef long long Board;

const int N = 9;
const Board GOAL = 0x087654321;

struct state {
    Board board;
    int count;
};

queue<state> q;
set<Board> history;

inline void swap(int numpos, int spacepos, Board& board) {
    long long num = (board >> (numpos*4)) & 15;
    board |= num << (spacepos*4);
    board &= ~(15LL << (numpos*4));
}

inline int swap_and_check(int numpos, int spacepos, state s) {
    swap(numpos, spacepos, s.board);
    if (s.board == GOAL) {
        return ++s.count;
    }
    if (history.insert(s.board).second) {
        ++s.count;
        q.push(s);
    }
    return -1;
}

void print(Board b) {
    for (int i = 0; i < N; ++i) {
        printf("%2lld", (b >> (i*4) & 15));
    }
    printf("\n");
}

// OK
int main(void) {

    Board board = 0;
    for (int i = 0; i < N; ) {
        char ch;
        scanf("%c", &ch);
        if (isdigit(ch)) {
            board |= static_cast<long long>((ch - '0')) << (i*4);
            ++i;
        }
    }
//    print(GOAL);
//    print(board);

    int count = 0;
    if (board == GOAL) {
        goto END;
    }

    q.push({ board, 0 });
    while (!q.empty()) {
        state s = q.front();
        q.pop();

        int pos = -1;
        while (++pos < N) {
            if (((s.board >> (pos*4)) & 15) == 0) {
                break;
            }
        }

        if (pos < 6) {
            if ((count = swap_and_check(pos + 3, pos, s)) > 0) {
                break;
            }
        }
        if (pos > 2) {
            if ((count = swap_and_check(pos - 3, pos, s)) > 0) {
                break;
            }
        }
        if (pos % 3 < 2) {
            if ((count = swap_and_check(pos + 1, pos, s)) > 0) {
                break;
            }
        }
        if (pos % 3 > 0) {
            if ((count = swap_and_check(pos - 1, pos, s)) > 0) {
                break;
            }
        }
    }

END:
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 9728
def minus2base(n):
    if n==0:
        return '0'
    elif n==1:
        return '1'
    elif n>1:
        k=1
        i=1
        a=n
        while a-k>=0:
            a=a-k
            if a==0:
                break
            k=4*k
            i=i+1
        if n-k>0:
            A='10'
            l=1
            j=1
            a=n-k
            while a-l>=0:
                a=a-l
                if a==0:
                    break
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n-k)
        elif n-k==0:
            i=0
            A='1'
            while k//4**i>1:
                A=A+'00'
                i=i+1
            return A
        else:
            A='1'
            l=2
            j=1
            a=n-k
            while 0>a+l:
                a=a+l
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n-k)
    else:
        k=2
        i=1
        a=n
        while 0>a+k:
            a=a+k
            k=4*k
            i=i+1
        if n+k<0:
            A='10'
            l=2
            j=1
            a=n+k
            while a+l<0:
                a=a+l
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n+k)
        elif n+k==0:
            i=0
            A='1'
            while k//4**i>1:
                A=A+'00'
                i=i+1
            return A[:-1]
        else:
            A='1'
            l=1
            j=1
            a=n+k
            while a-l>=0:
                a=a-l
                if a==0:
                    break
                l=4*l
                j=j+1
            m=i-j
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n+k)
N=int(input())
print(minus2base(N))

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b;
    cin >> a >> b;
    if (b % a == 0)
        OP(a + b);
    else
        OP(b - a);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int div[10000001]={0};
  for(int i=1;i<=10000000;i++)
  {
    for(int j=i;j<=10000000;j+=i)
    {
      div[j]++;
    }
  }
  for(int i=1;i<=10000000;i++)
     div[i]*=i;
 long long int sum=0; 
  for(int i=1;i<=n;i++)
    sum+=div[i];
  cout<<sum<<endl;
  return 0;
}  

Measured memory_bytes: 81756
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    print(S[:K-1] + S[K-1].lower() + S[K:])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>
int data[51], a[51], b[51], c1[51];
int n, t, count;

void shuffle(int);
int toridasia(int);
int toridasib(int);

main(){
  int r, i, c;

  while(1){
    if(scanf("%d %d", &n, &r)==EOF) break;

    for(i=0;i<n;i++){
      data[i]=i;
    }
    
    if(n%2==0) t=n/2;
    else t=n/2+1;

    for(i=0;i<r;i++){
      scanf("%d", &c);

      shuffle(c);
    }

    printf("%d\n", data[n-1]);
  }
  return 0;
}

void shuffle(int c){
  int i, j, p1, p2;

  for(i=0, j=0;i<n;i++, j++){
    if(i==n-t){
      b[j]=-1;
      j=0;
    }
    if(i<=n-t-1){
      b[j]=data[i];
    }
    else{
      a[j]=data[i];
    }
  }
  a[j]=-1;

  count=0;
  while(1){
    p1=toridasia(c);
    p2=toridasib(c);
    if(p1==1 && p2==1) break;
  }


  for(i=0;i<n;i++){
    data[i]=c1[i];
  }
}

int toridasia(int c){
  int temp[50];
  int i, j, temp1;

  for(i=0;i<c;i++){
    if(a[i]==-1) return 1;
    c1[count]=a[i];
    count++;
  }
  temp1=i;
  for(i=0;i<50;i++){
    if(a[temp1+i]==-1) break;
    temp[i]=a[temp1+i];
  }
  
  temp[i]=-1;

  for(i=0;i<50;i++){
    a[i]=temp[i];
    if(temp[i]==-1) break;
  }
  return 0;
}


int toridasib(int c){
  int temp[50];
  int i, j, temp1;

  for(i=0;i<c;i++){
    if(b[i]==-1) return 1;
    c1[count]=b[i];
    count++;
  }
  temp1=i;
  for(i=0;i<50;i++){
    if(b[temp1+i]==-1) break;
    temp[i]=b[temp1+i];
  }
  
  temp[i]=-1;

  for(i=0;i<50;i++){
    b[i]=temp[i];
    if(temp[i]==-1) break;
  }
  return 0;
}

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

#define MAXN 5005

string s;
int n;

const int mod1 = 1000*1000*1000 + 7, mod2 = 982451653;
const int p = 31;
int pow1[MAXN], pow2[MAXN], p_inv[2];

int mul(int a, int b, int mod) {
	return (1LL * a * b) % mod;
}

int mpow(int a, int m, int mod) {
	if(m == 0) return 1;
	int x = mpow(a, m/2, mod);
	x = mul(x, x, mod);
	if(m % 2 == 1) x = mul(x, a, mod);
	return x;
}

void add_self(int& a, int b, int mod) {
	a += b;
	if(a >= mod) a -= mod;
}

void sub_self(int& a, int b, int mod) {
	a -= b;
	if(a < 0) a += mod;
}

bool can(int len) {
	map<pair<int, int>, int> seen;
	int h1 = 0, h2 = 0;
	for(int i = 0; i < len; i++) {
		add_self(h1, mul(s[i]-'a'+1, pow1[i], mod1), mod1);
		add_self(h2, mul(s[i]-'a'+1, pow2[i], mod2), mod2);
	}
	
	pair<int, int> pr = {h1, h2};
	seen[pr] = -1;
	for(int i = 0; i < n-len; i++) {
		int j = i + len;
		sub_self(h1, s[i]-'a'+1, mod1);
		h1 = mul(h1, p_inv[0], mod1);
		add_self(h1, mul(s[j]-'a'+1, pow1[len-1], mod1), mod1);
		
		sub_self(h2, s[i]-'a'+1, mod2);
		h2 = mul(h2, p_inv[1], mod2);
		add_self(h2, mul(s[j]-'a'+1, pow2[len-1], mod2), mod2);
		
		pr = {h1, h2};
		if(seen.count(pr)) {
			if(seen[pr] + len <= i) {
				return true;
			}
		} else {
			seen[pr] = i;
		}
	}
	
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	pow1[0] = pow2[0] = 1;
	for(int i = 1; i < MAXN; i++) {
		pow1[i] = mul(p, pow1[i-1], mod1);
		pow2[i] = mul(p, pow2[i-1], mod2);
	}
	
	p_inv[0] = mpow(p, mod1-2, mod1), p_inv[1] = mpow(p, mod2-2, mod2);
	cin >> n >> s;
	
	int lo = 0, hi = n;
	
	while(lo < hi) {
		int mid = lo + (hi - lo + 1)/2;
		if(can(mid)) {
			lo = mid;
		} else {
			hi = mid - 1;
		}
	}
	
	cout << lo << endl;
	
}


Measured memory_bytes: 640
import math
def sann(n):
    print(math.sqrt(a**2+b**2-(2*a*b*(math.cos(math.radians(n))))))

a,b,c,d=map(int,input().split())
c=c*30+d*(1/2)
d=d*6
n=abs(c-d)

sann(n)

Measured memory_bytes: 9448
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  string s;
  cin>>s;
  int n=s.size();
  vector<int> cnt(26,0);
  int temp;
  int ans=100;
  REP(i,n){
    temp = s[i]-'a';
    cnt[temp]++;
    if(cnt[temp]==n){
      cout<<0<<endl;
      return 0;
    }
  }
  temp = 0;
  string S = s;
  char target;
  string t="";
  bool flag = true;
  REP(k,26){
    target = (char)('a'+k);
    REP(i,100){
      REP(j,n-1){
        if(s[j]==target){
          t += target;
          continue;
        }else if(s[j+1]==target){
          t += target;
          continue;
        }else{
          t += 'A';
          flag = false;
        }
      }
      //cout<<t<<endl;
      temp++;
      if(flag){
        ans = min(ans,temp);
        temp = 0;
        s = S;
        t = "";
        n = s.size();
        //flag = true;
        break;
      }else{
        s = t;
        t = "";
        n = s.size();
        flag = true;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char c[110];
int a=99999,b;
int main()
{
    cin>>c;
    for(int i=0;i<=105;i++)
    {
        if(c[i]=='C')
        {
            a=i; break;
        }
    }
    for(int i=0;i<=105;i++)
     if(c[i]=='F')
      b=i;
    if(a<b)
     printf("Yes\n");
    else
     printf("No\n");
     return 0;
}

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

int main() {
    int num = 0;
    cin >> num;
 
    int point = 0;
    cin >> point;

    int trial = 0;
    cin >> trial;

    vector<int> each_point(num, point-trial);

    for (int i = 0; i < trial; i++) {
        int correct_player_num = 0;
        cin >> correct_player_num;
        correct_player_num--;

        each_point[correct_player_num]++;
    }

    for (int i = 0; i < num; i++) {
        if (each_point[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  	int ans=0;
  	string S;
  	cin >> S;
  	for(int i=0; i<S.length()/2; i++){
    	if(S[i] != S[S.length()-i-1]){
        	ans++;
        }
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if(b < a) {
		swap(a, b);
	}
	a += w;

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

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  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};
  int n;
  cin>>n;
  cout<<a[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
namespace Domain
{
	class Result
	{
		int value;
	public:
		Result(int value=0):value(value){}
		int disp() {	return  value ;}
		bool isEnd(){return !value;}
	};


}
using namespace Domain;
namespace InterfaceAdapter
{
	class ResultDisp
	{
	public:
		int disp(Result result) {	return result.disp() ;}
	};
	class RectInput
	{
	public :
		void inp(Result& result)
		{
			int w;
			cin >> w;
			Result res(w);
			result=res;
		}
	};

}
using namespace Domain;
using namespace InterfaceAdapter;

namespace UseCase
{
	class Input
	{
	public :
		template <typename X>
		 static void inp(X shapeIn,Result& result)
		{
		   shapeIn.inp(result);
		}
	};
	class Display
	{
		static int count;

	public:
		template <typename U,typename V>
		static void disp(U& result,V& dispType) { 
			cout <<"Case "<<count<<": "<<dispType.disp(result)<<endl;
			count++;
		}
	};
	int Display::count=1;
	class CaseOver
	{
	public:
		static void check()
		{
			int cnt=1;
			for(;;){
				Result result;
				RectInput rectInput;
				Input::inp(rectInput,result);
				if(result.isEnd())break;
				
				ResultDisp resultDisp;
				Display::disp(result,resultDisp);
			}
		}
	};
}
using namespace UseCase;
int main()
{
	CaseOver::check();
	return 0;

}

Measured memory_bytes: 3084
import Data.Vector (Vector, (!))
import qualified Data.Vector as U

solve :: Int -> Int -> Mint
solve n k = sum $ U.map (uncurry(*)) idp where
  idp = U.zip dp $ U.enumFromTo 1 (Mint k)
  dp = U.constructrN k f
  f dp = Mint(div k i) ^ n - sum mul where
    i = k - U.length dp
    mul = [dp!(i*m-1) | m <- [1..U.length dp `div` i]]

main = do
  [n,k] <- map read.words <$> getLine
  print $ solve n k

modulus = 10^9 + 7
newtype Mint = Mint Int
instance Num Mint where
  (Mint a) + (Mint b) = Mint $ mod (a+b) modulus
  (Mint a) * (Mint b) = Mint $ mod (a*b) modulus
  abs = id
  signum = id
  fromInteger a = Mint $ mod (fromInteger a) modulus
  negate (Mint a) = Mint $ mod (-a) modulus
instance Enum Mint where
  fromEnum (Mint a) = a
  toEnum a = Mint a
instance Show Mint where
  show (Mint a) = show a

Measured memory_bytes: 14972
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  db n;
  ci(n);
  ll m=n/1;
  db one=1;
  co((m-m/2)/n)
}

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

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=300000000;
const LL MOD=1000000007;



int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0)cout<<a+b<<endl;
    else cout<<-a+b<<endl;
}

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

using namespace std;

int main(){
    int N;
    string w, x="a", y="a";
    cin >> N;
    string siri[N];
    for(int i=0; i<N; i++){
        cin >> w;
        siri[i] +=w;
    }
    for(int i=0; i<N; i++){
        if(i==N-1) break;
        x=siri[i].back();
        y=siri[i+1].front();
        if(x!=y){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=0; i<N; i++){
        if(i==N-1) break;
        for(int j=i+1; j<N; j++){
            if(siri[i]==siri[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

n,m,x = map(int,input().split())

ca = []
for i in range(n):
    ca.append(list(map(int,input().split())))

res = 10**20

for p in range(1<<n):
    tmp = 0
    cnt = [0]*m
    for j in range(n):
        if (p>>j)&1 == 1:
            tmp += ca[j][0]
            for i in range(1,m+1):
                cnt[i-1] += ca[j][i]
    
    if min(cnt) >= x:
        res = min(res,tmp)
if res == 10**20:
    print(-1)
else:
    print(res)

Measured memory_bytes: 68644
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
int n, m, r;
int a[8];
int x[22222], y[22222], z[22222];
int d[222][222];
signed main() {
	cin >> n >> m >> r;
	rep(i, r)cin >> a[i];
	rep(i, n + 1) {
		rep(j, n + 1)d[i][j] = inf;
	}
	rep(i, m) {
		cin >> x[i] >> y[i] >> z[i];
		d[x[i]][y[i]] = z[i];
		d[y[i]][x[i]] = z[i];
	}
	for(int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	sort(a, a + r);
	int ta = inf;
	do {
		int memo = a[0], ans = 0;
		for (int i = 1; i < r; i++) {
			ans += d[memo][a[i]];
			memo = a[i];
		}
		ta = min(ta, ans);
	} while (next_permutation(a, a + r));
	cout << ta << endl;
	ggr
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] arggs)
        {
            var i = int.Parse(System.Console.ReadLine());
            //var s = System.Console.ReadLine();
            //var ss = System.Console.ReadLine().Split(new char[] {' '});

            System.Console.WriteLine(Math.Pow(i,3));
        }
    }
}

Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long N;
    cin >> N;
    long A_plus[N];
    map<long, long> A_minus_count;
    for (long i = 0; i < N; i++)
    {
        long A;
        cin >> A;
        A_plus[i] = A + (i + 1);
        long A_minus = -A + (i + 1);
        if (A_minus_count.count(A_minus) == 0) {
            A_minus_count[A_minus] = 0;
        }
         A_minus_count[A_minus]++;
    }
    long count = 0;
    for (long i = 0; i < N; i++)
    {
        if (A_minus_count.count(A_plus[i]) != 0) {
            count += A_minus_count[A_plus[i]];
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 16772
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll n, m;
	cin >> n >> m;
	ll s = 0;
	rep(i, m) {
		ll a;
		cin >> a;
		s += a;
	}
	if (s > n) cout << -1;
	else cout << n - s;
	return 0;
}

Measured memory_bytes: 3636
Module Program
    Sub Main(args As String())
        Dim sInputS As String = Console.ReadLine()
        Dim sInputT As String = Console.ReadLine()

        If sInputS.Length > 0 And 10 >= sInputS.Length Then
            If sInputT.Length = sInputS.Length + 1 Then
                If sInputT.Remove(sInputT.Length - 1, 1) = sInputS Then
                    Console.WriteLine("Yes")
                Else
                    Console.WriteLine("No")
                End If
            Else
                Console.WriteLine("No")
            End If
        Else
            Console.WriteLine("No")
        End If
    End Sub
End Module


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

using ll = long long;

const int mod = 998244353;

int main() {
    string s; cin >> s;
    const int n = s.size();
    vector<int> rcnt(n + 1);
    for(int i = 0; i < n; ++i) {
        rcnt[i + 1] = rcnt[i];
        if(s[i] == '0') rcnt[i + 1] += 2;
        else if(s[i] == '1') rcnt[i + 1] += 1;
    }

    vector<vector<ll>> nCr(n + 1, vector<ll>(n + 1));
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= i; ++j) {
            if(j == 0 || i == j) {
                nCr[i][j] = 1;
            } else {
                nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod;
            }
        }
    }

    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= n; ++j) {
            if(dp[i][j] == 0) continue;
            int r = j, b = 2 * i - rcnt[i] - (i - (rcnt[i] - j));
            if(s[i] == '0') r += 2;
            if(s[i] == '1') {
                r += 1;
                b += 1;
            }
            if(s[i] == '2') {
                b += 2;
            }
            if(r > 0) {
                (dp[i + 1][r - 1] += dp[i][j]) %= mod;
            }
            if(b > 0) {
                //cout << i << ' ' << j << endl;
                (dp[i + 1][r] += dp[i][j]) %= mod;
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i <= n; ++i) {
        //cout << dp[n][i] << endl;
        (ans += dp[n][i] * nCr[n][i]) %= mod;
    }

    cout << ans << endl;
}


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

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

	for (int i = 1; i < 10; i++) {
		if (N%i == 0 && N / i < 10) {
			cout << "Yes" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
    ll N; cin>>N;
    string s=to_string(N);
    ll S=0;
    rep(i,0,s.size()){
        S+=s[i]-'0';
    }
    cout<<(N%S==0 ? "Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
aa = list(input())
bb = list(input())
cc = list(input())

ma = {'a':aa, 'b':bb, 'c':cc}

st = aa[0]
for i in range(10000):
    if len(ma[st])>0:
        st = ma[st].pop(0)
    else:
        print(st.upper())
        exit()

Measured memory_bytes: 38384
#include <bits/stdc++.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++)
 
int main() {
  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<2*a<<endl;
  }
  else{
    cout<<2*max(a,b)-1<<endl;
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() { 
  int a;
  cin >> a;
  cout << a + a*a + a*a*a << endl; 
  return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    for_(x,1,2000) {
        if (A <= x * K and x * K <= B) {
            puts("OK");
            return 0;
        }
    }
    puts("NG");
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int X,Y;
      int a,b,c;

      cin >> X >> Y;

      for (int i=0 ; i <= X ;i++){
          a = 2*i;
          b = 4*(X-i);
          c = a + b;
          if (c == Y){
            break;
          }
      }
        if (c == Y){
          cout << "Yes" << endl;
      }
        else {
          cout << "No" << endl;
        }
      }


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<vector>
 
#define INF 999999999
#define ll long long
 
using namespace std;
 
const int MAX_N = 100000;
const int MAX_M = 500000;
 
struct edge
{
    int from;  //?????????
    int to;    //??°??????
    int cost;  //??????
};
 
int d[MAX_N];
edge es[MAX_M];
bool flag;  //???????????????????????????
 
void shortest_path(int n,int m,int s)   //s???????????????????????????????????????????????¢????±???????
{
    int cnt = 0;
    fill(d,d+n,INF);
    d[s] = 0;
    while(true && cnt < n){
        bool update = false;
        for(int i=0;i<m;i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
        cnt++;
    }
    if(cnt == n){
        flag = true;
    }
}
 
int main()
{
    int i,n,m,s;
    cin >> n;  //????????°
    cin >> m;  //?????°
    cin >> s;  //???????????????
    for(int i=0;i<m;i++){
        scanf("%d",&es[i].from);
        scanf("%d",&es[i].to);
        scanf("%d",&es[i].cost);
    }
    flag = false;
    shortest_path(n,m,s);
    if(!flag){
        for(int i=0;i<n;i++){
            if(d[i] == INF){
                cout << "INF\n";
            }else{
                cout << d[i] << "\n";
            }
        }
    }else{
        cout << "NEGATIVE CYCLE\n";
    }
}


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=205,inf=1e6;
vector<ll> adj[N];
ll color[N],dist[N];
bool odd_cycle(ll u){
    for(auto &v:adj[u]){
        if(color[v]==0){
            color[v]=1^2^color[u];
            if(odd_cycle(v))return 1;
        }
        else if(color[v]==color[u])return 1;
    }
    return 0;
}
ll bfs(ll src,ll n){
    for(ll i=1;i<=n;i++)dist[i]=inf;
    dist[src]=0;
    ll ans = 0;
    queue<ll> q;
    q.push(src);
    while(!q.empty()){
        auto u = q.front();
        q.pop();
        for(auto &v:adj[u]){
            if(dist[v]==inf){
                dist[v]=dist[u]+1;
                q.push(v);
                ans=dist[v];
            }
        }
    }
    return ans+1;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            char ch;cin>>ch;
            if(ch=='1')adj[i].push_back(j);
        }
    }
    color[1]=1;
    if(odd_cycle(1))return cout<<"-1" , 0;
    ll ans = 0;
    for(ll i=1;i<=n;i++)ans=max(ans , bfs(i,n));
    cout<<ans;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vvi field(5000,vi(5));
		vi top(5);
		rep(k,n){
			int d,p,q; cin>>d>>p>>q;
			if(d==1){
				int t=*max_element(top.begin()+q-1,top.begin()+q-1+p);
				rep(i,p){
					field[t][q-1+i]=1;
					top[q-1+i]=t+1;
				}
			}
			else{
				rep(i,p)
					field[top[q-1]+i][q-1]=1;
				top[q-1]+=p;
			}
			
			int cnt=0;
			rep(i,field.size()){
				if(count(allof(field[i]),1)<5)
					field[i-cnt]=field[i];
				else
					cnt++;
			}
			
			repi(i,*max_element(allof(top))-cnt,field.size())
				field[i]=vi(5);
			fill(allof(top),0);
			rep(i,field.size())
				rep(j,5)
					if(field[i][j])
						top[j]=i+1;
		}
		int res=0;
		rep(i,field.size())
			res+=count(allof(field[i]),1)%5;
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
ll s;
ll calc(vector<ll> a){
    ll res=0;
    ll copy=s;
    for(int i=0; i<a.size(); i++){
        ll divide=pow(10,a[i]+1);
        res+=copy/divide;
        copy=copy%divide;
    }
    res+=copy;
    return res;
}
int main(){
    cin >> s;
    ll ss=s;
    ll n=0;
    while(ss>0){
        ss/=10;
        n++;
    }
    ll ans=0;
    for(int i=0; i<1<<n-1; i++){
        vector<ll> a;
        for(int j=0; j<n-1; j++){
            if(i>>j&1) a.push_back(j);
        }
        sort(a.rbegin(),a.rend()); 
        ans+=calc(a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
def inner_prod(v0, v1):
    ans = 0
    for x0, x1 in zip(v0, v1):
        ans += x0 * x1
    return ans


def vector_add(v0, v1):
    return [x0 + x1 for x0, x1 in zip(v0, v1)]


def vector_mul(vector, scaler):
    return [scaler * x for x in vector]


def matrix_mul(matrix, vector):
    ans = []
    for row in matrix:
        ans.append(inner_prod(row, vector))
    return ans


def koch(p0, p1, max_depth, depth=0):
    from math import sin, cos, pi

    if depth == max_depth:
        return []
    R = [[cos(pi / 3), -sin(pi / 3)], [sin(pi / 3), cos(pi / 3)]]
    p2 = vector_add(vector_mul(p0, 2 / 3), vector_mul(p1, 1 / 3))
    p3 = vector_add(vector_mul(p0, 1 / 3), vector_mul(p1, 2 / 3))
    p4 = vector_add(p2, matrix_mul(R, vector_add(p3, vector_mul(p2, -1))))
    return [
        koch(p0, p2, max_depth, depth + 1),
        p2,
        koch(p2, p4, max_depth, depth + 1),
        p4,
        koch(p4, p3, max_depth, depth + 1),
        p3,
        koch(p3, p1, max_depth, depth + 1),
    ]


def dfs_print(array):
    if not array:
        return
    if isinstance(array[0], int) or isinstance(array[0], float):
        print(*array)
    else:
        for child in array:
            dfs_print(child)


n = int(input())
result = [[0, 0], koch([0, 0], [100, 0], n), [100, 0]]
dfs_print(result)



Measured memory_bytes: 6800