akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>

using namespace std;

int board[9][9];

bool Solution(int x, int y)
{
    int count = 0;
    
    for (int i = 0; i < 9; i++)
    {
        if (board[x][i] == board[x][y])
        {
            count++;
        }
        
        if (board[i][y] == board[x][y])
        {
            count++;
        }
    }
    
    int devideX = x / 3;
    int devideY = y / 3;
    
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (board[devideX * 3 + i][devideY * 3 + j] == board[x][y])
            {
                count++;
            }
        }
    }
    
    return count == 3;
}

int main()
{
    int n;
 
    bool flag = true;
    
    cin>>n;
    
    while(n--)
    {
        if (flag)
        {
            flag = false;
        }
        else
        {
            cout << endl;
        }
        
        for (int j = 0; j < 9; j++)
        {
            for (int k = 0; k < 9; k++)
            {
                cin>>board[j][k];
            }
        }
        
        for (int j = 0; j < 9; j++)
        {
            for (int k = 0; k < 9; k++)
            {
                char c = ' ';
                
                if (!Solution(j, k))
                {
                    c = '*';
                }
                
                cout << c << board[j][k];
            }
            
            cout << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
  using namespace std;
  #define lp(i,n) for(int i=0;i<n;i++)
  #define fordebug int hoge;cin>>hoge;
  #define DEKAI 1000000007;
  #define INF (1<<28)
  int ch[100000];

  int main(){
    int n;
    cin>>n;
    int a[20];
    lp(i,n) cin>>a[i];
    int q;
    cin>>q;
    int  bit=0;
    lp(i,q){
      int target;
      scanf("%d",&target);
      if(i==0){
        bit=1;
       while(1){
        if(bit&(1<<n)) {
          break;
        }
        int sumn=0;
        lp(i,n){
          if(bit&(1<<i)) sumn+=a[i];
        }
        ch[sumn]=1;
       //cout<<bit<<" "<<sumn<<endl;
        ++bit;
       }
      }
      {
        if(ch[target]==0) cout<<"no"<<endl;
        else cout<<"yes"<<endl;
      }
    }
    
    return 0;
  }


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		long ans = -10000000000L;
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		long minv = stdin.nextLong();	long tmp;
		for(int i = 1; i < n; i++) {
			tmp = stdin.nextLong();
			ans = Long.max(ans,tmp - minv);
			minv = Long.min(minv, tmp);
		}
		stdin.close();
		System.out.println(ans);
	}
}


Measured memory_bytes: 99224
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
char st[105];
int flag[105][105],f[105][105];
int main()
{
	int n=read(),m=read();
	for (int i=1;i<=n;i++)
	{
		scanf("%s",st);
		for (int j=1;j<=m;j++)
			if (st[j-1]=='#') flag[i][j]=1;
			else flag[i][j]=0;
	}
	f[1][1]=flag[1][1];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		if (i!=1||j!=1)
		{
			f[i][j]=INF;
			if (i>1) upmin(f[i][j],f[i-1][j]+(flag[i][j]==1&&flag[i-1][j]==0));
			if (j>1) upmin(f[i][j],f[i][j-1]+(flag[i][j]==1&&flag[i][j-1]==0));
		}
	cout<<f[n][m]<<endl;
	return 0;
}


Measured memory_bytes: 384
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int a, b; cin >> a >> b;
  if (abs(a-b) % 2 == 0) {
    cout << min(a,b)+abs(a-b)/2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}



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

using namespace std;
#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__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll x, y;
  cin >> x >> y;

  if(x >= 0){

    if(y >= x){
      cout << y - x << endl;
      return 0;
    }

    if(y > 0){
      cout << 2 + (x-y) << endl;
      return 0;
    }

    cout << 1 + abs(x - abs(y)) << endl;

  }else{

    if(y < x){
      cout << 2 + abs(y-x) << endl;
      return 0;
    }

    if(y <= 0){
      cout << abs(y-x) << endl;
      return 0;
    }

    cout << 1 + abs(abs(y)-abs(x)) << endl;


  }




  return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    if ((n % 2) == 0)
    {
        if (n >= 2 * k)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    else
    {
        if (n >= 2 * k - 1)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    
}

Measured memory_bytes: 256
s = input()
ans = len(s)
temp1 = 0 #Sが連続
for i in range(len(s)):
  if s[i] == "S":
    temp1+=1
  elif s[i] == "T":
    if temp1 > 0:
      temp1-=1
      ans-=2
    else:
      temp1=0
  else:
    temp1=0
print(ans)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> XS(N), YS(N);
  for (int i = 0; i < N; i++) cin >> XS[i] >> YS[i];
  double sum = 0.0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double d = sqrt((XS[i] - XS[j]) * (XS[i] - XS[j]) +
                      (YS[i] - YS[j]) * (YS[i] - YS[j]));
      sum += d;
    }
  }
  double answer = sum * 2 / N;
  printf("%.10lf\n", answer);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip> // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <bits/stdc++.h>
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(void){

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a,a+3);

    (a[0] == a[1] && a[0] == 5) ? cout << "YES" << endl : cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int a,b,c;
	cin>>a>>b>>c;
	a=a*100+b*10+c;
	if(a%4==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}


}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        ReaderC.init(System.in);
        long n = ReaderC.nextLong();
        long m = ReaderC.nextLong();
        if (m == 1 && n == 1) System.out.println(1);
        else if (m == 1) System.out.println(n - 2);
        else if (n == 1) System.out.println(m - 2);
        else System.out.println((m - 2)*(n - 2));
    }
}

/**
 * Reader class based on the article at "https://www.cpe.ku.ac.th/~jim/java-io.html"
 */
class ReaderC {
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

//    static int nextInt() throws IOException {
//        return Integer.parseInt(next());
//    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

//    //    Get a whole line.
//    static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}



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

int main() {
  long n,p,ans=0;
  string s;
  cin >> n >> p >> s;
  vector<long> a(n+1);

  a[0]=0;
  long j=1;
  for (long i = n - 1; i >= 0; i--) {
    a[n-i]=((s[i]-'0')*j+a[n-i-1])%p;
    j=j*10%p;
  }
  sort(a.begin(),a.end());
  j=1;
  for(long i=1;i<n+1;i++) {
    if(a[i]==a[i-1]) {
      ans+=j;
      j++;
    } else {
      j=1;
    }
  }
  if(p==2||p==5) {
    ans=0;
    for(long i=0;i<n;i++) if((s[i]-'0')%p==0) ans+=i+1;
  }
  cout << ans << endl;
}

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

int N; 
int C;
int K;
int T[100005];
int buses=1;
int passengers=0;
int first=-1;

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

    for (int i=0; i<N; i++)
    {
        cin>>T[i];
    }

    sort(T, T+N);

    passengers=1;
    first=T[0];

    for (int i=1; i<N; i++)
    {
        if (passengers<C && T[i]<=first+K)
        {
            passengers++;
        }
        
        else
        {
            buses++;
            first=T[i];
            passengers=1;
        }
    }

    cout<<buses<<endl;
}

Measured memory_bytes: 3952
fun main(args: Array<String>) {
    val (n,q) = readLine()!!.split(" ").map{it.toInt()}
    val s =readLine()!!
    val td = Array(q){readLine()!!.split(" ").map { s->s[0] }}
    var min = 0
    var max = n-1
    for(i in q-1 downTo 0){
        if(min>max)break

        if(td[i][1]=='L'){
            if(s[min]==td[i][0]){
                min+=1
            }
            if(max<n-1&&s[max+1]==td[i][0]){
                max+=1
            }
        }else {
            if(s[max]==td[i][0]){
                max-=1
            }
            if(0<min&&s[min-1]==td[i][0]){
                min-=1
            }
        }

    }
    print(Math.max(max-min+1,0))
}

Measured memory_bytes: 82124
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int a, b;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> a >> b;
  int diff = max(a, b) - min(a, b);
  diff /= 2;
  if (max(a,b) - diff == diff + min(a,b)) {
    cout << max(a,b) - diff << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}




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

int main() {
  string S;
  cin >> S;
  
  vector<bool> alphabets(26, false);
  
  for (int i = 0; i < S.size(); i++) alphabets.at(S.at(i) - 'a') = true; 
  
  for (int i = 0; i < 26; i++) {
    if (!alphabets.at(i)) {
      cout << char(i + 'a') << endl;
      break;
    } else if (i == 25) {
      cout << "None" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <array>

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	--point;
	std::cout << stack[point] << std::endl;
}

int main(){
	int num;

	while(std::cin >> num){
		if(num == 0 && point > 0) pop();
		else if(0 < num && num <= 10) push(num);
	}

    return 0;
}


Measured memory_bytes: 3048
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int fac[4040], fac_inv[4040];
const int mod = 1000000007;

int pow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)res *= a;
        a *= a;
        res %= mod;
        a %= mod;
        b /= 2;
    }
    return res;
}

int inv(int x) {
    return pow(x, mod - 2);
}

void calc() {
    fac[0] = 1;
    fac_inv[0] = 1;
    for (int i = 1; i < 4040; ++i) {
        fac[i] = fac[i - 1] * i % mod;
        fac_inv[i] = inv(fac[i]);
    }
}

int Comb(int n, int r) {
    return fac[n] * fac_inv[r] % mod * fac_inv[n - r] % mod;
}

int H(int n, int r) {
    return Comb(n + r - 1, r);
}
//calcを必ず実行
//mod書き換え
//fac,facinv配列長書き換え

int N;
int A, B, C, D;
int memo[1010][1010];
int cnt;

int rec(int remain, int group) {
    if (remain < 0) {
        return 0;
    }
    if (remain == 0) {
        return fac[N];
    }
    if (group == A - 1) {
        if (remain == 0) {
            return fac[N];
            /*
            int tmp = fac[N];
            for (int g = A; g <= B; ++g) {
                tmp *= pow(fac_inv[g], Num[g]);
                tmp %= mod;
                tmp *= fac_inv[Num[g]];
                tmp %= mod;
            }
            ans += tmp;
            ans %= mod;
             */
        } else {
            return 0;
        }
    }
    if (memo[remain][group] != -1) {
        return memo[remain][group];
    }
    int res = rec(remain, group - 1);
    for (int k = C; k <= D && remain - k * group >= 0; ++k) {
        int tmp = rec(remain - k * group, group - 1);
        tmp *= pow(fac_inv[group], k);
        tmp %= mod;
        tmp *= fac_inv[k];
        tmp %= mod;
        res += tmp;
    }
    res %= mod;
    return memo[remain][group] = res;
}

signed main() {
    calc();
    memset(memo, -1, sizeof(memo));
    cin >> N >> A >> B >> C >> D;
    int ans = rec(N, B);
    cout << ans << endl;
    return 0;
}


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

ll par[100010];
ll size[100010];

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}
ll find_size(int x) {
    return size[x] = size[find(x)];
}
bool same(int x, int y) {
    return find(x) == find(y);
}
void unit(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (!same(px, py)) {
        par[py] = px;
        size[px] += size[py];
        size[px] = size[px];
    } 
}

int main() {
    ll N, M;
    cin >> N >> M;
    
    ll A[M], B[M];
    rep(i, M) cin >> A[i] >> B[i];

    rep(i, N+1) par[i] = i, size[i] = 1;

    ll ans[M+1];
    ans[M] = N * (N-1) / 2;

    for(int i=M-1; i>=0; i--) {
        if (same(A[i], B[i])) {
            ans[i] = ans[i+1];
        } else {
            ans[i] = ans[i+1] - find_size(A[i]) * find_size(B[i]);
            unit(A[i], B[i]);
        }
    }

    rep(i, M) cout << ans[i+1] << endl;

    return 0;
}



Measured memory_bytes: 5248
#include<iostream>
#include<deque>
#define ll long long 
using namespace std;
deque<int> b;
deque<int>::iterator it;
ll mod=1e9+7;
void exgcd(ll a,ll b,ll& d,ll& x,ll& y)
{
    if(!b) { d = a; x = 1; y = 0; }
    else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); }
}

ll inv(ll a, ll p)
{
    ll d, x, y;
    exgcd(a, p, d, x, y);
    return d == 1 ? (x+p)%p : -1;
}
int f[100010],g[100010];
int main()
{
   ll n,i,x,y,c1,c2,p,pos;
   cin>>n;
   for (i=1;i<=n+1;i++)
   {
       cin>>x;
       if (f[x]) p=i,pos=g[x];
       g[x]=i;
       f[x]=1;
   }
   n++;
   int sum=pos-1+n-p;
   x=n;y=1;
   c1=n;c2=1;
   int c3;
   int t=0;
   ll x2=n-p,y2=1;
   for (i=1;i<=n;i++)
   {
       ll ans=(c1-c2+mod)%mod;
       while(ans<0) ans+=mod;
       cout<<ans<<endl;
       if (i==n) break;
       ll e=inv(i+1,mod);
       c1=(c1*(n-i))%mod;
       c1=(c1*e)%mod;
       if (i-1>sum) c2=0;
       else 
       {
           t=c2;
           e=inv(i,mod);
           c2=(c2*(sum-i+1))%mod;
           c2=(c2*e)%mod;
       }
   }
}


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

//#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
#define MAXN   1000005 
  
// stores smallest prime factor for every number 
int spf[MAXN+5]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<=MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step
unordered_set<int> temp[MAXN]; 
void getFactorization(int x,int i) 
{  
	int temp1 = x;
    while (x != 1) 
    { 
        temp[spf[x]].insert(temp1); 
        x = x / spf[x]; 
    } 
} 
int freq[MAXN];	
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		sieve();
		int arr[n];
		int maxx = 0;
		bool flag = false;
		for(int i=0;i<n;++i)
		{
			cin>>arr[i];
			freq[arr[i]]++;
			if(arr[i]>1 and freq[arr[i]]>1)
			flag = true;
			maxx = max(maxx,arr[i]);
			getFactorization(arr[i],i);
		}
		//cout<<spf[3]<<"\n";
		int gcdd = arr[0];
		
		for(int i=2;i<=maxx;++i)
		{
			if(temp[i].size()>1)
			{
				flag = true;
				//cout<<i;
				break;
			}
		}
		for(int i=1;i<n;++i)
		{
			gcdd = __gcd(gcdd,arr[i]);
		}
		if(!flag)
		{
			cout<<"pairwise coprime";
		}
		else if(gcdd==1)
		{
			cout<<"setwise coprime";
		}
		else
		{
			cout<<"not coprime";
		}		
    }
    return 0;
}


Measured memory_bytes: 190740
# https://atcoder.jp/contests/abc120/tasks/abc120_b

import itertools
import collections
import bisect

def main():
    A, B, K = map(int, input().split())
    count = 0
    for i in range(max(A, B) + 1, 0, -1):
        # print(i)
        if A % i == 0 and B % i == 0:
            count += 1
            # print(i)
            if count == K:
                print(i)
                exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
		int[] price = new int[N];
		for(int i=0; i<price.length; i++){
			price[i]=sc.nextInt();
		}
		int cnt=0,work=0;
		int[] cal = new int[price.length];
		for(int i=0; i<price.length; i++){
			for(int j=0; j<price.length; j++){
				if(price[i]>price[j]){
					work=price[i];
					price[i]=price[j];
					price[j]=work;
				}
			}
		}
		for(int i=0; i<price.length; i++){
			for(int j=0; j<i+1; j++){
				cnt+=price[j];
			}
			cnt+=C;
			cal[i]=cnt;
			cnt=0;
		}
		int[] result = new int[price.length];
		for(int i=0; i<price.length; i++){
			result[i]=(cal[i])/(A+((i+1)*B));
		}
		int max=result[0];
		for(int i=0; i<price.length; i++){
			if(max<result[i]){
				max=result[i];
			}
		}
		System.out.println(max);
		// TODO Auto-generated method stub

	}
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x7ffffff;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	stack<char> st;
	rep(i, n) {
		if (s[i] == 'S') {
			st.push('S');
		}
		else {
			if (st.size() != 0 && st.top() == 'S') st.pop();
			else st.push('T');
		}
	}
	cout << st.size() << endl;
	return 0;
}


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

#define ll long long int 
#define ull unsigned long long
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
	_fastio
	ll a,b,c,k,sum=0;
	cin>>a>>b>>c>>k;
	if(a>=k)
	{
		sum=sum+(k*1);
	}
	else
	{
		sum=sum+(a*1);
		k=k-a;
		if(b<k)
		{
			k=k-b;
			sum=sum-(k*1);
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
int main(){
    int n;double d,x,ans=0;
    scanf("%d%lf%lf",&n,&d,&x);
    for(;n;--n)ans+=d+(n-0.5)*x,d=((2*n+2)*d+5*x)/(2*n),x=(2*n+4)*x/(2*n);
    printf("%.9f\n",ans);
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	string s, t; cin >> s >> t; cout << t << s << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String str = sc.nextLine();
		char[] cha = str.toCharArray();
		int i = 0;

		for(char c : cha) {
			if(c=='-') {
				i--;
			}else {
				i++;
			}
		}
		System.out.println(i);


	}
}



Measured memory_bytes: 22096
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  int ans = n % k == 0 ? 0 : 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math
A, B = map(float, input().split())
lowerA = math.ceil(A/0.08)
upperA = math.floor((A+1)/0.08)      
lowerB = math.ceil(B/0.1)
upperB = math.floor((B+1)/0.1)
answer = -1
for i in range(lowerA, upperA):
  if (lowerB <= i) and (i < upperB):
    answer = i
    break
print(answer)
      

Measured memory_bytes: 62164
#include<iostream>
#include<algorithm>

using namespace std;


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


  double gP = 0.0;
  for(int i=1; i<=N; i++)
  {
    int S;
    double P;
    S = i;
    P = 1.0/(double)N;

    while(S <= K-1)
    {
      P *= 0.5;
      S *= 2;
    }

    gP += P;
  }

  printf("%.12f\n",gP);

  return 0;
}


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

int count_black(char grid[][7], const int h, const int w, const int row, const int col)
{
    int count = 0;
    for (int i = 0; i < w; i++)
    {
        for (int j = 0; j < h; j++)
        {
            if ((((1 << i) & col) == 0) && (((1 << j) & row) == 0) && grid[j][i] == '#')
            {
                count++;
            }
        }
    }
    return count;
}

int main()
{
    char grid[7][7] = {
        {
            0,
        },
    };

    int h, w, k, ret = 0;
    scanf("%d %d %d", &h, &w, &k);

    for (int i = 0; i < h; i++)
    {
        scanf("%s", &grid[i]);
    }

    for (int i = 0; i < (1 << h); i++)
    {
        for (int j = 0; j < (1 << w); j++)
        {
            int temp = count_black(grid, h, w, i, j);
            if (temp == k)
                ret++;
        }
    }

    printf("%d", ret);

    return 0;
}

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

namespace practice_csharp
{

    class Program
    {
        static void Main(string[] args)
        {
            var dat = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

            System.Console.WriteLine(Lcm(dat[0],dat[1]));
        }



        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return (a * b) / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

Measured memory_bytes: 13396
fn main() {
    let s: String = read();
    let a = s.find('A').unwrap();
    let z = s.rfind('Z').unwrap();
    println!("{}", z - a + 1);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    use std::io::prelude::*;

    let stdin = std::io::stdin();
    let s: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().unwrap()
}

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

int main(){
  int n,max,min,d,sum;
  while(1){
    scanf("%d",&n);
    if(!n)break;
    max =  0;
    min = 500;
    for(int i=0;i<n;i++){
      sum = 0;
      for(int j=0;j<5;j++){
        scanf("%d",&d);
        sum += d;
      }
      max = sum > max ? sum : max;
      min = sum < min ? sum : min;
    }
    printf("%d %d\n",max,min);
  }
  return 0;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(c-a) <= d) cout << "Yes" << endl;
    else if (abs(a-b) <= d && abs(b-c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
    string s;
    cin >> s;
    if (s[2]==s[3] and s[4]==s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<int> scores;
		for(int i = 0; i < n; i++){
			int sum=0;
			for(int j = 0; j < 5; j++){
				int t;
				cin>>t;
				sum+=t;
			}
			scores.push_back(sum);
		}
		sort(scores.begin(),scores.end());
		cout<<scores[scores.size()-1]<<" "<<scores[0]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
N = int(input())
H = list(map(int,input().split(' ')))
DP = [float('inf')]*N
DP[0] = 0
DP[1] = abs(H[1] - H[0])

for i in range(2,N):
  DP[i] = min(DP[i-2] + abs(H[i] - H[i-2]),DP[i-1] + abs(H[i] - H[i-1]))
print(DP[-1])
        



Measured memory_bytes: 13980
using System;
using System.IO;
using System.Linq;
class sol
{
    static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static Scan sc = new Scan();

    static void Main(string[] args)
    {
        int n = sc.Int;
        var d = sc.IntArr;
        Array.Sort(d);
        foreach (int j in d)
        {
            //Console.WriteLine(j);
        }
        int ans = 0;
        int i = d.Count<int>();
        //Console.WriteLine(i);
        if(d[i/2-1] - d[i/2] == 0)
        {
            ans = 0;
        }
        else
        {
            ans = d[i/2] - d[i/2 - 1];
            //Console.WriteLine(d[i / 2] + "," + d[i / 2 -1]);
        }
        Prt(ans);
        sw.Flush();
    }
    static void Prt(string a) => sw.WriteLine(a);
    static void Prt(params object[] a) => Prt(string.Join(" ", a));
}

class Scan
{
    StreamReader sr;
    public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
    public string Str => sr.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => ct<T, int>(int.Parse(s));
    public void Multi<T, U, V>(out T a, out U b, out V c)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
}

Measured memory_bytes: 20064
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	int s;
	cin >> n >> s;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<ll> dp(s + 1);
	ll answer = 0;
	for (int i = 0; i < n; ++i) {
		++dp[0];
		for (int ss = s; ss >= 0; --ss) {
			if (ss + a[i] <= s) {
				dp[ss + a[i]] += dp[ss];
				dp[ss + a[i]] %= mod;
			}
		}
		answer += dp[s];
		answer %= mod;
	}
	cout << answer << '\n';
 	return 0;
}


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

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

  int ans=0, active=0;
  
  for (int i=0; i<n; i++){
    if(active <= h[i]){
      ans += h[i]-active;
      active = h[i];
    }else{
      active = h[i];
    }
  }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
coin = [100, 101, 102, 103, 104, 105]
X = int(input())
dp = [0]*(X+5)
dp[0]=1
for i in coin:
	for j in range(X+5):
		if i<=j:
			if dp[j-i]:
				dp[j]=1
print(1) if dp[X] else print(0)
	
	

Measured memory_bytes: 3828
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    m,d=map(int,input().split())
    cnt=0
    for i in range(10,d+1):
        if int(str(i)[0])>=2 and int(str(i)[1])>=2 and 1<=int(str(i)[0])*int(str(i)[1])<=m:
            cnt+=1
    print(cnt)
        
    
resolve()

Measured memory_bytes: 38256
/*  ex7_1
    takafumi_ueki*/
#include <stdio.h>
#include <math.h>
//頂点を表す構造体
typedef struct{
    int x_elem;
    int y_elem;
}point;

point shift_point(point start_point,point end_point){
    point target_point;
    /*  あるベクトルの始点の座標が(x1,y1)、終点の座標が(x2,y2)である時、
        始点を中心に終点を反時計回りに90度回転させて移った点の座標(x3,y3)は
        x3 = x1 + y1 -y2
        y3 = x2 + y1 -y1 で表される。 */
    target_point.x_elem = start_point.x_elem + start_point.y_elem - end_point.y_elem;
    target_point.y_elem = start_point.y_elem + end_point.x_elem - start_point.x_elem;
    return target_point;
}

int main(void){
    point point1,point2,point3,point4;
    //値を受け取る
    scanf("%d %d %d %d",&point1.x_elem,&point1.y_elem,&point2.x_elem,&point2.y_elem);
    //座標(x4, y4)を求める
    point4 = shift_point(point1,point2);
    //座標(x3, y3)を求める
    point3 = shift_point(point4,point1);
    //結果を出力する
    printf("%d %d %d %d\n",point3.x_elem,point3.y_elem,point4.x_elem,point4.y_elem);
    return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cou<<""<<endl;

int main(){
  int N,M;cin>>N>>M;vi H(N),A(M),B(M);
  rep(i,N)cin>>H[i];
  rep(i,M){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }
  vi ma(N);
  rep(i,M){
    ma[A[i]] = max(ma[A[i]],H[B[i]]);
    ma[B[i]] = max(ma[B[i]],H[A[i]]);
   
  }
  int cnt=0;
  rep(i,N){
    if(H[i]>ma[i])cnt++;
  }
  cout<<cnt<<endl;
}






Measured memory_bytes: 4912
#include<iostream>
using namespace std;
bool isprime(int n) {
	for(int i=2;i*i<=n;i++)
		if(n%i==0) return false;
	return true;
}
int main() {
	int x;
	cin>>x;
	while(true) {
		if(isprime(x)) {
			cout<<x<<endl;
			break;
		}
		x++;
	}
	return 0;
} 

Measured memory_bytes: 256
private val scanner = java.util.Scanner(System.`in`)

private fun readInts(n: Int) = Array(n) { scanner.nextInt() }
private fun readLongs(n: Int) = Array(n) { scanner.nextLong() }
private fun readLineInts() = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
private fun readLineLongs() = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

fun main(args: Array<String>) {
    var (A, B, C) = readInts(3)
    var ans = 0

    for (c in 0 until C) {
        if (A > 0) {
            A--
            ans++
            continue
        }

        if (B > 0) {
            B--
            ans += 2
            continue
        }

        ans++
        break
    }

    println(ans + B)
}

Measured memory_bytes: 31392
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define endl '\n'
#define loop(i, m, n) for (lli i = m; i < n; i++)
#define loope(i, m, n) for (lli i = m; i <= n; i++)
#define epool(i, m, n) for (lli i = m; i >= n; i--)
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define vt vector<lli>
#define fi first
#define se second
#define pb push_back
#define umap unordered_map
#define mmap multimap
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x << endl, 0;
#define all(v) v.begin(),v.end()

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
 
lli gcd(lli a, lli b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
 
lli modi( lli n, lli m=mod ){ 
    n%=m;
    n+=m;
    n%=m;
    return n;
}

lli mpow(lli base, lli exp){
    base %= mod;
    lli result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((lli)result * base) % mod;
        base = ((lli)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

const lli MIN=-1*1e18;
const lli INF=1e18+999999999999999999;
const lli N=2e5+5;
const ldb pi=4*atan(1);

string sortString(string &str){
    lli i = 0, j = 0, k = 0;
    lli charCount[26] = {0};
    loop(i, 0, str.length())
        charCount[str[i] - 'a']++;
    loop(i, 0, 26){
        loop(j, 0, charCount[i]){
            str[k++] = char('a' + i);
        }
    }
    return str;
}

int32_t main(){
    fast_io
    lli i = 0,j = 0;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout << fixed << setprecision(22);

    lli n,k;
    cin >> n >> k;
    lli arr[n+1];
    loope(i,1,n) cin >> arr[i];
    
    vector<lli> v;
    map<lli,lli> mp;
    mp[1]++;
    v.pb(1);
    i=1;
    i=arr[i];
    while(1){
        mp[i]++;
        if(mp[i]>=2) break;
        //lli cur=arr[i];
        v.pb(i);
        i=arr[i];
    }

    //loop(i,0,v.size()) cout << v[i] << " ";

    lli cur=arr[v[v.size()-1]];
    lli p=-1;
    loop(i,0,v.size()){
        if(v[i]==cur){
            p=i;
            break;
        }
    }

    if(k<=p){
        cout << v[k] << endl;
    }
    else{
        k=k-p;
        lli dist=v.size()-p;
        k=k%dist;
        cout << v[p+k] << endl;
    }

}



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

bool isvalid(const vector<int> &b,int m) {
    int target = -1;
    for(int i=0; i<3; ++i) {
        int t1 = 0,t2 = 0;
        for(int j=0; j<3; ++j) {
            t1 += b[i*3+j];
            t2 += b[j*3+i];
        }
        t1 %= m,t2 %= m;
        if(target == -1) target = t1;
        if(t1 != target || t2 != target) return false;
    }

    int tt = b[0] + b[4] + b[8],tt2 = b[2] + b[4] + b[6];

    tt %= m,tt2 %= m;
    if(tt != target || tt2 != target) return false;

    return true;
}

int dfs(vector<int> &b,int used,int remain) {
    if(remain == 0)
        return (isvalid(b,b[9])) ? 1:0;

    int next = 0, ret = 0;
    while(b[next] != 0) next++;

    for(int use=1; use<=10; ++use) {
        if((used>>use)&1) continue;
        b[next] = use;
        ret += dfs(b,used|(1<<use), remain-1);
        b[next] = 0;
    }

    return ret;
}

int main() {
    vector<int> b(10,0);
    while(true) {
        for(int i=0; i<10; ++i) cin>>b[i];
        for(int i=0; i<10; ++i) {
            if(b[i] != -1) break;
            if(i == 9) goto END;
        }

        int used = 1,rem = 0;
        for(int i=0; i<10; ++i) {
            used |= (1<<(b[i]));
            if(b[i]==0) rem++;
        }

        cout<<dfs(b,used,rem)<<endl;
    }
END:;
}

Measured memory_bytes: 908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<62;

ll dp[MAX],dpsum[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;ll A,B;cin>>N>>A>>B;
    if(A>B) swap(A,B);
    vector<ll> S(N+1,-INF),ok(N+1);
    for(int i=0;i<N;i++) cin>>S[i+1];
    for(int i=1;i<=N;i++){
        if(S[i]-S[i-1]>=A) ok[i]=1;
    }
    for(int i=1;i<=N;i++) ok[i]+=ok[i-1];
    
    dp[1]=1;
    dpsum[1]=1;
    
    for(int i=1;i<=N;i++){
        auto it=upper_bound(all(S),S[i]-B);
        it--;
        int lim=it-S.begin();
        
        int left=-1,right=max(0,i-2);
        
        while(right-left>1){
            int mid=(left+right)/2;
            if(ok[i-1]-ok[mid+1]==i-mid-2) right=mid;
            else left=mid;
        }
        
        if(right<=lim) dp[i+1]=(mod+dpsum[lim+1]-dpsum[right])%mod;
        
        dpsum[i+1]=(dpsum[i]+dp[i+1])%mod;
        
    }
    
    ll ans=0;
    
    for(int i=1;i<=N;i++){
        if(ok[N]-ok[i]==N-i) ans+=dp[i];
        ans%=mod;
    }
    ans+=dp[N+1];
    ans%=mod;
    
    for(int i=2;i<=N;i++){
        if(S[i]-S[i-2]<A) ans=0;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 3456
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 500000 + 5;
int n;
char s[kN];
int dp[kN][3];

void up(int &x, int y)
{
    if (x < y) x = y;
}

int main()
{
    scanf("%d%s", &n, s);
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++ i) {
        up(dp[i + 1][0], dp[i][0]);
        if (s[i] == '1') {
            if (dp[i][0] != -1) {
                up(dp[i + 1][1], dp[i][0] + 1);
            }
            if (dp[i][1] != -1) {
                up(dp[i + 1][1], dp[i][1] + 1);
            }

            if (dp[i][2] != -1) {
                up(dp[i + 1][2], dp[i][2] + 1);
                up(dp[i + 1][0], dp[i][2] + 1);
            }

            if (i + 1 < n && s[i + 1] == '0' && dp[i][0] != -1) {
                up(dp[i + 2][2], dp[i][0]);
            }
        } else {
            if (i + 1 < n && s[i + 1] == '1' && dp[i][1] != -1) {
                up(dp[i + 2][0], dp[i][1]);
            }
        }
    }
    printf("%d\n", dp[n][0]);
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	lint N, K;
	cin >> N >> K;

	vector<lint> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	// 2進法で表したときの各桁について注目する。（0の数が過半数ならmaxXのその桁は1となる。）
	// Kと比較してKのi桁目が1ならmaxXも1にできる。
	// (flag)上の桁から見ていってKが1なのにmaxXは0となる場合その先maxXはKによらず1,0を決めれる。
	lint one, maxX = 0;
	bool flag = false;
	for (int i = 39; i >= 0; i--) {

		// j桁目の1の数を数える
		one = 0;
		for (int j = 0; j < N; j++) if ((1LL << i) & A[j]) one++;

		// flagがtrueまたはKのi桁目が1 でかつ0が過半数ならmaxXのi桁目を1にする。
		if ((flag || (K & (1LL << i))) && one - N / 2 <= 0) maxX += (1LL << i);

		// Kが1でmaxXが0となるならそれ以降は必ずK>maxXが成立するのでflag=trueにしてmaxXの1,0は自由に決めれる。
		if (!flag && (K & (1LL << i)) && one - N / 2 > 0) flag = true;

	}

	lint ans = 0;
	for (int i = 0; i < N; i++) ans += A[i] ^ maxX;

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
  ll N,mod=1000000007,sum=0,ans=0,temp;
  cin >> N;
  vector<ll> A(N);
  rep(i,N)
  {
    cin >> A[i];
    sum += A[i];
    sum = sum % mod;
  }
  temp = sum + mod;
  rep(i,N)
  {
    if(temp-A[i]<0)
      temp = temp - A[i]+mod;
      else
        temp = temp - A[i];

    ans = (ans+((temp % mod) * A[i]) % mod)%mod;
  }

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


Measured memory_bytes: 4832