akhauriyash/Code-Regression huggingface dataset:
def change(a):
    return int(a) - 1


n, k = map(int, input().split())

ls = list(map(change, input().split()))
visited = [False] * n
visited[0] = True
i = 0
while True:
    if not visited[ls[i]]:
        visited[ls[i]] = True
        i = ls[i]
    else:
        end = ls[i]
        break
loop = 0
i = end
while True:
    if ls[i] == end:
        loop += 1
        break
    else:
        i = ls[i]
        loop += 1

i = 0
till_loop = 0
while True:
    if ls[i] == end:
        till_loop += 1
        break
    else:
        i = ls[i]
        till_loop += 1
if till_loop + loop <= k:
    k -= till_loop
    k %= loop
    i = end
    while k > 0:
        i = ls[i]
        k -= 1
    print(i+1)
else:
    i = 0
    while k > 0:
        i = ls[i]
        k -= 1
    print(i+1)


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

using namespace std;

int main()
{
    string st1, st2;
    int count = 0;

    cin >> st1 >> st2;

    for(auto i = 0; i < st1.size(); i++) {
        if(st1[i] != st2[i]) ++count;
    }

    cout << count << endl;

    return 0;

}

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

using namespace std;

int p[1 << 17], q[1 << 18];
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	n = 1 << n;
	p[0] = a, p[n - 1] = b;
	a ^= b, b = 1;
	for (int i = 1; i < n; i <<= 1)
		if (a&i) b ^= 1;
	if (b) {
		cout << "NO" << endl;
		return 0;
	}
	for (int k = n >> 1; k > 1; k >>= 1) {
		for (int i = k; i < n; i += k << 1) {
			q[i] = q[i + k] | q[i - k];
			int r = p[i + k - 1] ^ p[i - k], x = 1, y = 1;
			while (!(r&x)) x <<= 1;
			q[i] ^= x;
			while (q[i] & y) y <<= 1;
			p[i - 1] = p[i - k] ^ y;
			p[i] = p[i - 1] ^ x;
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++)
		cout << p[i] << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 2048
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int count_1 = 0;
    int count_2 = 0;
    for(int i = 0; i < m; i++) {
      int next = sc.nextInt();
      if(x > next) count_2++;
      if(x < next) count_1++;
    }
    System.out.println(Math.min(count_1, count_2));
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5;
const int mod=1e9+7;
int h,w,a,b;
int inv[maxn+5],fac[maxn+5],facInv[maxn+5];
void setInv(int n)
{
    inv[0]=inv[1]=1;
    for (int i=2;i<=n;i++)
        inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
}
void setFac(int n)
{
    fac[0]=facInv[0]=1;
    for (int i=1;i<=n;i++) {
        fac[i]=1LL*fac[i-1]*i%mod;
        facInv[i]=1LL*facInv[i-1]*inv[i]%mod;
    }
}
int C(int n,int m)
{
    if (n<0||m<0) return 0;
    if (n<m) return 0;
    int ans=fac[n];
    ans=1LL*ans*facInv[m]%mod;
    ans=1LL*ans*facInv[n-m]%mod;
    return ans;
}
int calc(int n,int m)
{
    return C(n+m-2,n-1);
}
int main()
{
    setInv(maxn); setFac(maxn);
    scanf("%d%d%d%d",&h,&w,&a,&b);
    int ans=0;
    for (int i=b+1;i<=w;i++) {
        int t=1LL*calc(h-a,i)*calc(a,w-i+1)%mod;
        ans=(ans+t)%mod;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007
 
using namespace std;
 
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.first< right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.second < right.second;
}
 
void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}
 
lli gcd(lli a, lli b){
    if(a < b)return gcd(b, a);
    lli temp;
    while((temp = a%b)){
        a=b;
        b=temp;
    }
    return b;
}

struct nCr{
  vector<lli> f, rf;
  lli count=0;
  nCr(lli num): f(num), rf(num){
      count = num;
      f[0] = 1;
      rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
      rep0(i, num+1) rf[i] = inv(f[i]);
  }
    
  lli inv(lli x) {
      lli res = 1;
      lli k = MOD - 2;
      lli y = x;
      while (k) {
          if (k & 1) res = (res * y) % MOD;
          y = (y * y) % MOD;
          k /= 2;
      }
      return res;
  }
  lli C(lli n, lli k) {
      lli a = f[n];
      lli b = rf[n-k];
      lli c = rf[k];
   
      lli bc = (b * c) % MOD;
   
      return (a * bc) % MOD;
  }
};

struct UF{
    vector<int> par,size;

    UF(int N) : par(N), size(N, 1){
        rep0(i,N)par[i] = i;
    }

    int root(int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        size[rx] += size[ry];
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getSize(int x){
        return size[x];
    }
};
int main(){
  string n;
  cin >> n ;
  rep0(i,3)if(n[i]=='7'){
    cout << "Yes";
    return 0;
  }
  cout << "No";
}




Measured memory_bytes: 3632
N,C=[int(x) for x in str(input()).split()]
A=[]
for i in range(N):
  a,b,d=[int(x) for x in str(input()).split()]
  A.append([d,a,b])


br=200002

count=[0 for i in range(br)]

A.sort()
for i in range(1,C+1):
  ind=[0 for i in range(br)]
  end=0
  for j in range(N):
    if A[j][0]==i:
      if end!=A[j][1]:
        end=A[j][2]
        ind[2*A[j][1]-1]=1
        ind[2*end]=-1
      else:
        end=A[j][2]
        ind[2*A[j][1]]=0
        ind[2*end]=-1
  temp=0
  for j in range(br):
    temp+=ind[j]
    if temp>0:
      count[j]+=1

print(max(count))












Measured memory_bytes: 120620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl;
struct node {
	int x,y,c;
}e[2000100];
int id[2000100],fa[2000100],n,m,newn,d[2000100],used[2000100];
vector<int>v[2000100];
inline bool cmp(const node a,const node b){
	  return a.c<b.c;
}
inline int sf(int x){return fa[x]==x?x:fa[x]=sf(fa[x]);}
inline void deal(int le,int ri){
	  int i;
	  for(i=le;i<=ri;i++){
	  	fa[e[i].x]=e[i].x;
		fa[e[i].y]=e[i].y;
		used[e[i].x]=used[e[i].y]=0;
		id[e[i].x]=id[e[i].y]=-1;
	  }
	  for(i=le;i<=ri;i++)
	    if(sf(e[i].x)!=sf(e[i].y)){
	      fa[sf(e[i].x)]=sf(e[i].y);
		}
	  for(i=le;i<=ri;i++){
	  	int xx=sf(e[i].x),yy=sf(e[i].y);
	  	if(!used[e[i].x]){
	  	  if(id[xx]==-1)id[xx]=++newn;
	  	  v[e[i].x].push_back(id[xx]);
	  	  v[id[xx]].push_back(e[i].x);
	  	  used[e[i].x]=1;
	    }
	    if(!used[e[i].y]){
	  	  if(id[yy]==-1)id[yy]=++newn;
	  	  v[e[i].y].push_back(id[yy]);
	  	  v[id[yy]].push_back(e[i].y);
	  	  used[e[i].y]=1;
	    }
	  }
}
queue<int>q;
int main(){
      int i,l=1;
      scanf("%d%d",&n,&m);
      newn=n;
	  for(i=1;i<=m;i++)scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].c);
	  sort(e+1,e+m+1,cmp);
	  for(i=2;i<=m;i++)
	    if(e[i].c!=e[i-1].c){
	      deal(l,i-1);
	      l=i;
	    }
	  deal(l,m);
	  memset(d,-1,sizeof(d));
	  d[1]=0;
	  q.push(1);
	  while(!q.empty()){
	    int x=q.front();
		q.pop();
		for(i=0;i<(int)v[x].size();i++)
		  if(d[v[x][i]]==-1){
		    d[v[x][i]]=d[x]+1;
			q.push(v[x][i]);
		  }
	  }
	  if(d[n]==-1)puts("-1");
	    else cout<<d[n]/2<<endl;
	  return 0;
}

Measured memory_bytes: 76032
import sys
from queue import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, q = list(map(int, input().split()))

adjacent_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
tree_value = [0]*(n+1)
for i in range(q):
    p, x = map(int, input().split())
    tree_value[p] += x
searched = set()
"""
def dfs(node, count):
    searched.add(node)
    tree_value[node] += count
    for i in adjacent_list[node]:
        if i not in searched:
            dfs(i, tree_value[node])
"""
used = [0 for i in range(n+1)]
que = Queue()
que.put(1)
while que.qsize() != 0:
    m = que.get()
    used[m] = 1
    for i in adjacent_list[m]:
        if not used[i]:
            tree_value[i] += tree_value[m]
            que.put(i)
for i in range(1,n+1):
    print("{} ".format(tree_value[i]), end = "")


Measured memory_bytes: 98760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 0, n - 2) {
        if (s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}


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

string s;
int main () {
    cin >> s;
    int ans = 999;
    for(int i=2; i<s.length(); i++) {
        int tmp = (s[i-2] - '0') * 100 + (s[i-1] - '0') * 10 + s[i] - '0';
        ans = min( ans, abs(tmp - 753));
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n)cin >>a[i];

  set<int> st;
  for (ll i=0;i<n;++i){
    st.insert(a[i]);
  }
  int ans = sizeof(a)/sizeof(a[0]);
  if(ans==st.size())cout<<"YES";
  else cout<<"NO";

}


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

int main() {
  int a,b;
  cin >> a >> b;
  int ans = 0;
  if(a == 1) {
    ans = b == 2 ? 3 : 2;
  } else if(a == 2) {
    ans = b == 1 ? 3 : 1;
  } else {
    ans = b == 1 ? 2 : 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int N, K;
int tmp;
int main()
{
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%d", &tmp);
    }
    printf("%d\n", (N - 1 + K - 2) / (K - 1));
    return 0;
}


Measured memory_bytes: 128
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int N; cin >> N;
  int p[N], q[N];
  for(int i=0; i < N; i++){
    cin >> p[i];
  }
  copy(p, p+N, q);
  sort(p, p+N);
  int count = 0;
  for(int i=0; i < N; i++){
    if(p[i] != q[i]){
      count++;
    }
  }
  if(count < 3){
    cout << "YES" << endl;
  } else{
    cout << "NO" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
	using namespace std;
	int main()
	{
	      int a,b,c,x,ans=0;
	      cin>>a>>b>>c>>x;
	      for (int i=0;i<=a; ++i)
	           for (int j=0; j<=b; ++j)
	                for (int k=0; k<=c; ++k )
	                       if (i*500+j*100+k*50==x)
	                               ans++;
	       cout<<ans<<endl;
	}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int a[100000+100];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int minx=0;
	memset(a,0,sizeof(a));
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(minx==0){
			minx=x;
		}
		if(minx>x){
			minx=x;
		}
		int min=a[x];
		if(min==0){
			a[x]=y;
		}else if(min>y){
			a[x]=y;
		}
	}
	int flag=1;
	int k=a[minx];
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			continue;
		}
		if(i>=k){
			flag++;
			k=a[i];
		}
		else if(k>a[i]){
			k=a[i];
		}
	}
	printf("%d\n",flag);
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Maximize_the_Formula
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = Console.ReadLine().Split(null).ToArray();
            int res;

            num = num.OrderByDescending(x => x).ToArray();

            res = int.Parse(string.Join(null, num.Take(2))) + int.Parse(string.Join(null, num.Skip(2).Take(1)));

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13664
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	int result = -1;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
	}

	void calc() {
		int val = (int) Math.floor((double) N / 1.08);
		for (int i = val - 1; i <= val + 1; ++i) {
			int v = (int) Math.floor((double) i * 1.08);
			if (v == N) {
				result = i;
				break;
			}
		}
	}

	void showResult() {
		if (result < 0) {
			System.out.println(":(");
		} else {
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 22484
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int r;
	cin >> r;
	cout << 3 * r * r;
}

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

int main()
{
    int a,b,n;
    while(~scanf("%d",&n))
    {
        if(n==1)
        {
            printf("Hello World\n");
        }
        else
        {
            scanf("%d %d",&a,&b);
            printf("%d\n",a+b);
        }
    }
    return 0;
}


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

struct Rest {
  int id, point;
  string city;
  Rest(int id, string city, int point) 
    : id(id), point(point), city(city){}
  bool operator< (const Rest& rest) const {
    if (rest.city == city) {
      return rest.point < point;
    } else {
      return city < rest.city;
    }
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<Rest> rests;
  for (int i = 0; i < N; i++) {
    string S;
    int P;
    cin >> S >> P;
    rests.push_back(Rest(i + 1, S, P));
  }
  sort(rests.begin(), rests.end());
  for (Rest rest : rests) {
    cout << rest.id << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const ll MaxN = 1500000;


int main()
{
	int n, a;
	cin >> n >> a;
	int m = n % 500;
	if(m <= a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
LR = [[int(i) for i in input().split()] for _ in range(N)]

for i in range(N) :
    LR[i][1] += 1

a, b = 0, 0
la, ra = 0, float('inf')
lb, rb = -float('inf'), 0

for i, (l, r) in enumerate(LR) :
    if r < ra or (r == ra and l < la) :
        la, ra = l, r
        a = i
        
    if l > lb or (l == rb and r > rb) :
        lb, rb = l, r
        b = i

ret = 0

Md = 0
for i, (l, r) in enumerate(LR) :
    if i != a and i != b :
        Md = max(Md, r - l)
ret = max(ret, max(0, ra - lb) + Md)

LR.sort(key=lambda x: x[1])
LR.sort()
dpl = [0] * N
dpr = [0] * N

dpl[0] = max(la, LR[0][0])
dpr[N-1] = min(rb, LR[N-1][1])

for i in range(1, N) :
    dpl[i] = max(dpl[i-1], LR[i][0])
    dpr[N-1-i] = min(dpr[N-i], LR[N-1-i][1])
    
for i in range(N - 1) :
    ret = max(ret, max(0, ra - dpl[i]) + max(0, dpr[i + 1] - lb))
    
print(ret)

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

int a[6];

int main()
{
  for(int i =0; i<6; i++)
  {
    scanf("%d", &a[i]);
  }
  
  for(int i =0; i<5; i++)
  {
    for(int j = 0; j < 5; j++)
    {
      if(!(abs(a[i] - a[j]) <= a[5]))
      {
        printf(":(");
        return 0;
      }
    }
  }
  printf("Yay!");
  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

N = int(input())

news = []

for i in range(N):
  hoge = input().split()
  news.append((str(hoge[0]),int(hoge[1])))

b = sorted(news, key=itemgetter(1), reverse=True)
c = sorted(b, key=itemgetter(0))

for i in range(N):
  for j in range(N):
    if c[i] ==news[j]:
      print(j+1)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			long h = cin.Long();
			long ans = 0;
			long cnt = 1;
			while (h > 1) {
				ans += cnt;
				h /= 2;
				cnt *= 2;
			}

			ans += cnt;
			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 11092
package main

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

func main() {
	var n int
	var a []int
	n, a = receiveStdin()

	maxv := -math.MaxInt64
	min := a[0]
	for i := 1; i < n; i++ {
		if maxv < a[i]-min {
			maxv = a[i] - min
		}
		if min > a[i] {
			min = a[i]
		}
	}

	fmt.Println(maxv)
}

func receiveStdin() (int, []int) {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	n, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	var a []int
	for i := 0; i < n; i++ {
		sc.Scan()
		x := sc.Text()

		b, e := strconv.Atoi(x)
		if e != nil {
			panic(e)
		}

		a = append(a, b)
	}

	return n, a
}



Measured memory_bytes: 9512
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print((n-2)*180)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39024
#include <stdio.h>
#include <string.h>
int main(void){
    int n,a,b,c;
    char x[1000000];
    while(~scanf("%d",&n)){
        memset(x,0,sizeof(x));
        for(a=2,c=0;a<=n;a++){
            if(x[a])continue;
            c++;
            for(b=a*2;b<=n;b+=a)x[b]=1;
        }
        printf("%d\n",c);
    }
    return 0;
}

Measured memory_bytes: 2008
#include<iostream>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<deque>
#include<string>
#include<math.h>
using namespace std;
#define ll long long int 






int main() {
	

	int n;

	cin >> n;

	cout << (double)(2.0*3.1416*(double)n) << endl;

	

	return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    IOS;
    int n;
    cin>>n;
    pair<ll,ll> p[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i].se>>p[i].fi;
        p[i].se*=(-1);
    }
    sort(p,p+n);
    ll t=0;
    bool f=true;
    for(int i=0;i<n;i++)
    {
        if(t-p[i].se>p[i].fi) 
        {
            f=false;
            break;
        }
        t-=p[i].se;
    }
    if(f) cout<<"Yes\n";
    else cout<<"No\n";
}
 

Measured memory_bytes: 3328
#include <stdio.h>
int main(void){
    int x,y;
    scanf("%d %d",&x,&y);
    
    while(1){
        
        if (x == 0 && y == 0)break;
        
        if (x < y){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
        
        scanf("%d %d\n",&x,&y);
    }
    return 0;
}

Measured memory_bytes: 604
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
    
#pragma endregion library
template <class T>
struct Edge{
    int src;
    int to;
    T cost;
    Edge(int t,T c) : to(t),cost(c) {}
    Edge(int src, int t,T c) : src(src),to(t),cost(c) {}
};
template<class T> using WeightedGraph = vector<vector<Edge<T>>>;

template<class T>
vector<T> dijkstra(WeightedGraph<T>& g, int s){
    const auto INFD = numeric_limits<T>::max();
    vector<T> dist(g.size(),INFD);
    dist[s] = 0ll;
    using pd = pair<T, int>;
    priority_queue<pd,vector<pd>,greater<pd>> que;
    que.emplace(dist[s],s);
    while(!que.empty()){
        T cost; int idx;
        tie(cost,idx) = que.top(); que.pop();
        if(dist[idx]<cost) continue;
        for(auto& e: g[idx]){
            if(dist[e.to] > dist[idx]+e.cost){
                dist[e.to] = dist[idx]+e.cost;
                que.emplace(dist[e.to],e.to);
            }
        }
    }
    return dist;
}
int main(){
    int n,m,s,t; cin >> n >> m >> s >> t;
    s--;t--;
    WeightedGraph<ll> gs(n),gt(n);
    rep(i,m){
        int u,v;ll a,b;
        cin >> u >> v >> a >> b;
        u--;v--;
        gs[u].emplace_back(v,a);
        gs[v].emplace_back(u,a);
        gt[u].emplace_back(v,b);
        gt[v].emplace_back(u,b);
    }
    vll dists = dijkstra<ll>(gs,s),distt = dijkstra<ll>(gt,t);
    vll dist(n,LINF);
    dist[n-1] = distt[n-1] + dists[n-1];
    for(int i=n-2; i >= 0; i--){
        dist[i] = min(distt[i]+dists[i],dist[i+1]);
    }
    const ll init = 1000000000000000ll;
    rep(i,n){
        cout << init - dist[i] << '\n';
        
    }
}

Measured memory_bytes: 19016
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int m,d; cin>>m>>d;
  int ans=0;
  
  rep(i,m+1){
    rep(k,d+1){ if(k%10>=2 && k>=20){ if((k%10)*(k/10)==i) ans++;} }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


void odds_of_oddness()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


void blackjack()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  if (accumulate(a.begin(), a.end(), 0) >= 22) cout << "bust\n";
  else cout << "win\n";
}


void round_one()
{
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b;
}


int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  //cant_wait_for_holiday();
  //blackjack();
  round_one();
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    
    if(S.substring(0,N/2). equals (S.substring(N/2))) {
    	System.out.println("Yes");
    }else{
    	System.out.println("No");
    }
}
}

Measured memory_bytes: 35772
#include <iostream>

using namespace std;

const int SIZE = 90;
int board[SIZE][SIZE];
int n,m;

int dfs(int y, int x){
	int dx[] = {0, -1, 1, 0}, dy[] = {-1, 0, 0, 1};
	int nx, ny, max = 0, tmp;
	board[y][x] = 0;
	for(int i = 0;i < 4;++i){
		nx = x + dx[i];
		ny = y + dy[i];
		if (0 <= nx && 0 <= ny && nx < m && ny < n && board[ny][nx]) {
			tmp = dfs(ny, nx);
			max = tmp > max ? tmp : max;
		}
	}
	board[y][x] = 1;

	return max + 1;
}

int main(){
	int max, buf;
	while(cin >> m >> n, m != 0, n != 0){
		max = 0;
		for(int i = 0;i < n;++i){
			for(int j = 0;j < m;++j){
				cin >> board[i][j];
			}
		}
		for(int i = 0;i < n;++i){
			for(int j = 0;j < m;++j){
				if(board[i][j]) {
					buf = dfs(i, j);
					max = buf > max ? buf : max;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    // long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), K = scanner.nextInt();
        scanner.nextLine();
        int[][] sushi = new int[N][2];
        for (int i = 0; i < N; i++) {
            sushi[i] = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        }
        Arrays.sort(sushi, Comparator.comparingInt(x -> -x[1]));
        Set<Integer> added = new HashSet<>();
        List<Integer> deletable = new ArrayList<>();
        long kind = 0;
        long delicious = 0;
        for (int i = 0; i < K; i++) {
            delicious += sushi[i][1];
            if (added.add(sushi[i][0])) {
                kind++;
            } else {
                deletable.add(sushi[i][1]);
            }
        }
        Collections.reverse(deletable);

        List<Integer> addable = new ArrayList<>();
        for (int i = K; i < N; i++) {
            if (added.add(sushi[i][0])) {
                addable.add(sushi[i][1]);
            }
        }

        long ans = delicious + kind * kind;
        int i1 = 0;
        int i2 = 0;
        while (i1 < deletable.size() && i2 < addable.size()) {
            delicious -= deletable.get(i1++);
            delicious += addable.get(i2++);
            kind++;
            ans = Math.max(ans, delicious + kind * kind);
        }

        System.out.println(ans);

    }

}


Measured memory_bytes: 153764
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;


       cin>>a>>b;

       for(i=b-a+1; i<=a+b-1; i++)
        cout<<i<<" ";

       cout<<endl;











}



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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u) {
    cout << a - 1 << " " << b <<  endl;
  }
  if (t == u) {
    cout << a << " " << b - 1 << endl;
  }

return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

#define pb(x) push_back(x)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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;}

int x,y,a,b,c;


int main() {
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a),q(b),r(c);
  rep(i,a)cin >> p[i];
  rep(i,b)cin >> q[i];
  rep(i,c)cin >> r[i];

  sort(rALL(p));
  sort(rALL(q));
  
  vector<int> d;
  rep(i,x)d.pb(p[i]);
  rep(i,y)d.pb(q[i]);
  rep(i,c)d.pb(r[i]);

  sort(rALL(d));

  ll ans=0;
  rep(i,(x+y)) ans+= d[i];
  cout << ans;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x;
	cin>>n>>x;
	ll ans=n;
	ll a=x, b=n-x;
	while(1){
		//tie(a,b)=minmax(a,b); 何で動かないんですか？？？
		if(a>b)swap(a,b);
		//puta(a,b,ans);
		if(a==0){
			ans-=b;
			break;
		}
		ans+=2*a*(b/a);
		b%=a;
	}
	puta(ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

  vector<bool> from(n, false);
  vector<bool> to(n, false);
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (a == 0) {
      from[b] = true;
    }
    if (b == n - 1) {
      to[a] = true;
    }
  }
  bool is_ok = false;
  for (int i = 0; i < n; i++) {
    if (from[i] && to[i]) {
      is_ok = true;
      break;
    }
  }
  cout << (is_ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

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

int main()
{
    long long int h,n;
    cin >> h >> n;
    int a[n];
    int count = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        count += a[i];
    }
    
    if (count >= h)
        cout << "Yes\n";
    else
        cout << "No\n";
       
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  ll K;
  cin >> N >> K;
  ll A[N];
  vector<ll> B;
  vector<ll> C;
  ll z = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0)
      z++;
    else if (A[i] < 0)
      B.push_back(A[i]);
    else
      C.push_back(A[i]);
  }
  ll nb = B.size();
  ll nc = C.size();
  ll f0 = B.size() * C.size();
  ll f1 = f0 + z * (B.size() + C.size()) + (z * (z - 1)) / 2;
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  if (K <= f0) {
    ll l = -1e18 - 1ll;
    ll r = 0;
    while (r - l > 1) {
      ll m = (l + r) / 2;
      ll sum = 0;
      int j = nc - 1;
      for (int i = B.size() - 1; i >= 0; i--) {
        while (j >= 0 && B[i] * C[j] <= m)
          j--;
        sum += nc - 1 - j;
      }
      //cout << sum << " " << m << "\n";
      if (sum < K)
        l = m;
      else
        r = m;
    }

    cout << r << "\n";
  } else if (K <= f1) {
    cout << "0\n";
  } else {
    ll l = 0;
    ll r = 1e18 + 1ll;
    while (r - l > 1) {
      ll m = (l + r) / 2;
      ll sum = f1;
      int j = nb - 1;
      for (int i = 0; i < nb - 1; i++) {
        while (j >= 0 && B[i] * B[j] <= m)
          j--;
        sum += min((int) nb - j - 1, (int) nb - i - 1);
      }

      j = 0;
      for (int i = nc - 1; i >= 1; i--) {
        while (j < nc && C[i] * C[j] <= m)
          j++;
        sum += min(i, j);
      }
      // cout << sum << " " << m << "\n";
      if (sum < K)
        l = m;
      else
        r = m;
    }
    cout << r << "\n";
  }
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    ll num;
    cin >> num;

    // vector<ll> transport(5);
    ll x;
    ll temp;
    ll maximum = -1;
    for (int i = 0; i < 5; i++)
    {
        cin >> x;
        if (num % x == 0)
        {
            temp = num / x;
        }
        else
        {
            temp = num / x + 1;
        }
        maximum = max(maximum, temp);
    }
    ll ans = maximum + 4;
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef vector<ll>   vll;
typedef vector<int>   vi;
typedef set<ll>      sll;
typedef set<int>      si;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

ll i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}

// #define cerr if(0)cerr
void solve()
{
	ll n,x; cin>>n>>x;
	ll l[n+1]={0};
	rep(i,1,n) cin>>l[i];
	ll d[n+2]={0};
	rep(i,2,n+1)
     d[i]=d[i-1]+l[i-1];

ll ct=0;
     rep(i,1,n+1)
      if(d[i]>x) break;
      else ++ct;

      cout<<ct<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int n, m;
int c[21];
int dp[50001];

int main(){
	rep(i, 50001)dp[i] = infi;

	std::cin >> n >> m;
	rep(i, m){
		int c;
		std::cin >> c;
		dp[c] = 1;
		rep(j, 50001){
			if (dp[j] != infi && j + c < 50001)dp[j + c] = std::min(dp[j + c], dp[j] + 1);
		}
	}
	std::cout << dp[n] << std::endl;
	return 0;
}

Measured memory_bytes: 1356
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
int n,k;
int a[110];
mint dp[110][100010];
int main()
{
  cin >> n >> k;
  rep(i,n) cin >> a[i];

  rep(i,n+1) dp[i][0].x = 1;
  
  rep(i,n){
    rep1(j,k){
      if( j <= a[i] ) dp[i+1][j] = dp[i][j] + dp[i+1][j-1];
      else dp[i+1][j] = dp[i][j] + dp[i+1][j-1] - dp[i][j-1-a[i]];
     }
  }

  cout << dp[n][k].x << "\n";
  
  return 0;
}


Measured memory_bytes: 86144
#include <stdio.h>
#define thousand 1000

int main(){
    int value;
    int over;
    int ans;

    scanf("%d", &value);

    over = value % thousand;
    if (over == 0){
        ans = 0;
    }
    else{
        ans = thousand - over;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 2156
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int a, b, c;
	int A[1001], B[1001], C[1001], D[1001];
	int ans[10001];
	int n;
	while (cin >> a >> b >> c&&a != 0 && b != 0 && c != 0) {
		cin >> n;
		for (int i = 1; i <= a + b + c; i++) {
			ans[i] = 2;
		}
		for (int i = 0; i < n; i++) {
			cin >> A[i] >> B[i] >> C[i] >> D[i];
			if (D[i] == 1) {
				ans[A[i]] = ans[B[i]] = ans[C[i]] = 1;
			}
		}
		for (int i = 0; i < n; i++) {
			if(D[i] == 0) {
				if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1)ans[A[i]] = 0;
				if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1)ans[B[i]] = 0;
				if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2)ans[C[i]] = 0;
			}
		}
		for (int i = 1; i <= a + b + c; i++)cout << ans[i] << endl;
	}
}

Measured memory_bytes: 2992
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

#define MAXN 524288
#define MAXC 1048576
#define NO_VALUE -1

#define LEFT(x) ( 2*(x) )
#define RIGHT(x) ( 2*(x)+1 )

int A, B, C, M;

int r() {
    A = 36969 * (A & M) + (A >> 16);
    B = 18000 * (B & M) + (B >> 16);
    return (C & ((A << 16) + B)) % 1000000;
}

int x[MAXN], y[MAXN], z[MAXN], ox[MAXN], val[MAXN];

bool cmp_x(const int &a, const int &b) {
    if (x[a] != x[b]) return x[a] < x[b];
    else if (y[a] != y[b]) return y[a] < y[b];
    else return z[a] < z[b];
}

map<int, int> bit[MAXC];

int answer(int idx, int th) {
    map<int, int>::iterator it = bit[idx].lower_bound(th);
    if (it != bit[idx].begin()) return (--it)->second;
    else return NO_VALUE;
}

int query(int idx, int th) {
    int res = NO_VALUE;
    while (idx > 0) {
        res = max(res, answer(idx, th));
        idx &= idx-1;
    }
    return res;
}

void update(int idx, int th, int v) {
    map<int,int>::iterator it1, it2;
    while (idx < MAXC) {
        it1 = it2 = bit[idx].upper_bound(th);
        while (it2 != bit[idx].end() && it2->second <= v) it2++;
        bit[idx].erase(it1, it2);
    
        it1 = bit[idx].upper_bound(th);
        if (it1 == bit[idx].begin() || (--it1)->second < v) bit[idx][th] = v;
        idx += idx&(-idx);
    }
}

int main() {
    int m, n, i, j, N;

    while (scanf("%d %d %d %d", &m, &n, &A, &B) && (m || n || A || B)) {
        C = ~(1<<31); M = (1<<16)-1;
        for (i=0; i<m; i++) scanf("%d %d %d", &x[i], &y[i], &z[i]);
        for (i=m; i<m+n; i++) { x[i] = r(); y[i] = r(); z[i] = r(); }
        N = m+n;

        for (i=0; i<N; i++) { ox[i] = i; y[i] += 1; }
        sort(ox, ox+N, cmp_x);

        for (i=0; i<MAXC; i++) bit[i].clear();

        i = 0;
        do {
            for (j=i; j<N && x[ox[j]]==x[ox[i]]; j++) val[ox[j]] = max(1, query(y[ox[j]]-1, z[ox[j]])+1);
            for (; i<j; i++) update(y[ox[i]], z[ox[i]], val[ox[i]]);
        } while (i < N);
        printf("%d\n", query(MAXC-1, MAXC));
    }

    return 0;
}

Measured memory_bytes: 107340
import scala.io.StdIn
import scala.annotation.tailrec

object Main extends App {
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toLong)

  val init1 = if(a.head <= 0) 1 - a.head else 0
  val ans1 = a.tail./:(a.head + init1, init1.abs)((acc,i) => {
    val (bsum, bcnt) = acc
    val sum = bsum + i
    val cnt = if(bsum < 0 && sum < 0) 1 - sum
    else if(bsum > 0 && sum > 0) -1 - sum
    else if(sum == 0) if(bsum < 0) 1 else -1
    else 0
    // if(bcnt+cnt.abs < 0) println(i + " " + sum + " " + cnt)
    (sum+cnt, bcnt+cnt.abs)
  })._2

  val init2 = if(a.head < 0) 0 else -1 - a.head
  val ans2 = a.tail./:(a.head + init2, init2.abs)((acc,i) => {
    val (bsum, bcnt) = acc
    val sum = bsum + i
    val cnt = if(bsum < 0 && sum < 0) 1 - sum
    else if(bsum > 0 && sum > 0) -1 - sum
    else if(sum == 0) if(bsum < 0) 1 else -1
    else 0
    // if(bcnt+cnt.abs < 0) println(i + " " + sum + " " + cnt)
    (sum+cnt, bcnt+cnt.abs)
  })._2

  println(math.min(ans1, ans2))
}

Measured memory_bytes: 50880
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

int d[201];
char ss[201][202];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%s",ss[i]+1);
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			d[j]=0;
		queue<int>q;
		q.push(i);
		d[i]=1;
		while(!q.empty()){
			int u=q.front();
			q.pop();
			for(int j=1;j<=n;j++)
				if(ss[u][j]=='1'){
					if(!d[j]){
						d[j]=d[u]+1;
						q.push(j);
					}
					else if((d[u]&1)==(d[j]&1)){
						printf("-1\n");
						return 0;
					}
			}
		}
		for(int j=1;j<=n;j++)
			ans=max(ans,d[j]);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <cstring>
#include <set>
#include <bitset>
#include <map>
#include <chrono>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;
const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);

#define all(c) (c).begin(),(c).end()
#define forn(i, a, b) for(int i = a; i < b; i++)
#define read(x) scanf("%d", &x)
#define readv(x, n) vi x(n); forn(i,0,n) scanf("%d", &x[i])

#define pb push_back
#define mp make_pair


int main()
{

    int n;
    int a,b;
    cin>>n>>a>>b;
    if((b-a) % 2 == 0) cout<<"Alice";
    else cout<<"Borys";
    
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if pf > ma:
            ma = pf
    print(ma)

def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for pi in prefix:
        if ma < pi:
            ma = pi
    return ma

if __name__ == '__main__':
    main()


Measured memory_bytes: 47960