akhauriyash/Code-Regression huggingface dataset:
import sys
h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        flag = 0
        for k in range(4):
            dh = i + dy[k]
            dw = j + dx[k]
            # print(dh, dw)
            if 0 <= dh < h and 0 <= dw < w and s[dh][dw] == '#':
                flag = 1
        if flag == 0:
            print('No')
            sys.exit()
print('Yes')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<int>value(10,0);
  
  for(int i=0;i<n;i++){
    cin >> value[i];
  }
 
  int max = 0;
  for(int i=0;i<n;i++){
    if(max < value[i])
      max = value[i];
  }
  
  int sum = 0;
  for(int i=0;i<n;i++){
    sum = sum + value[i];
  }
  
  cout << sum - max / 2 << endl;
  
  return 0;
}

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

int main(){
    int a, b;
    
    while(1){
        cin >> a >> b;
        if (a == 0 && b == 0)break;
        
        if(a < b)cout << a << " " << b << endl;
        else cout << b << " " << a << endl;
    }
   return 0;
}


Measured memory_bytes: 2988
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int s, w;
    cin >> s >> w;
    if(w>=s){cout << "unsafe" << endl;return 0;}
    else{cout << "safe" << endl; return 0;}

    return 0;
}


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

int ask(const std::deque<int>& a)
{
  for (int j = 0; j < 2; ++ j) {
    for (int x : a) {
      std::cout << ".#"[x >> j & 1];
    }
    std::cout << "\n";
  }
  std::cout << std::flush;
  std::string verdict;
  std::cin >> verdict;
  if (verdict == "end") {
    return -1;
  }
  return verdict == "T";
}

int main()
{
  int n;
  std::cin >> n;
  std::deque<int> guess;
  bool found = true;
  while (static_cast<int>(guess.size()) < n && found) {
    found = false;
    for (int a = 0; a < 4; ++ a) {
      guess.push_back(a);
      auto verdict = ask(guess);
      if (verdict == -1) {
        return 0;
      }
      if (verdict) {
        found = true;
        break;
      }
      guess.pop_back();
    }
  }
  while (static_cast<int>(guess.size()) < n) {
    for (int a = 0; a < 4; ++ a) {
      guess.push_front(a);
      auto verdict = ask(guess);
      if (verdict == -1) {
        return 0;
      }
      if (verdict) {
        break;
      }
      guess.pop_front();
    }
  }
}


Measured memory_bytes: 724
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pii pair<int,int>
using namespace std;
signed main()
{
    fast;
   	int a,b,c;
   	cin>>a>>b>>c;
   	set<int> st;
   	st.insert(a);
   	st.insert(b);
   	st.insert(c);
   	if((int)st.size() == 2)
   		cout<<"Yes";
   	else cout<<"No";
    
}   

Measured memory_bytes: 256
//080-a

#include <utility>
#include <vector>
#include <iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    if(a*n <= b)cout << a*n << endl;
    else    cout << b << endl;
}


Measured memory_bytes: 256
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)

#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);


#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define pb push_back
#define fir first
#define scn second
#define ednl endl


#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
 long long n,k;cin>>n>>k;n-=2;
 //11でわりましてー
 long long N = n/11;
 n = n%11;
 long long t = 0;
 long long a = 0;
 for(int i = 0; 11 > i; i++){
   long long nw;
   for(int j = 0; 5 > j; j++){
     if(!i&&!j){
       t = 4;
       nw = t;
     }else if(!j){
       t = (nw+63)%11;
       nw = t;
     }else{
       t = (t+9)%11;
     }
     if(t==k){
       if(n > i){
         a += (N+1);
       }else{
         a += (N);
       }
     }
   }
 }
 cout << a << endl;
}


Measured memory_bytes: 256
S = input()
li = list(S)
li_b = []
for i in range(len(li) - 2):
  a = int(li[i])*100 + int(li[i+1])*10 + int(li[i+2])
  b = abs(a - 753)
  li_b.append(b)
print(min(li_b))

  

Measured memory_bytes: 2940
#include<iostream>
#include<complex>
#include<utility>
#include<vector>

using namespace std;

#define double long double

typedef complex<double> P;

int x_1[100],y_1[100],x_2[100],y_2[100];
double eps=1e-5;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

bool on(P a,pair<P,P> l){
  return fabs(cross(a-l.first,l.second-l.first))<eps;
}

P cp(pair<P,P> e,pair<P,P> f){
  P a=e.second-e.first;
  P b=f.second-f.first;
  double acb=cross(a,b);
  if(fabs(acb)<eps)throw 0;
  return e.first+a*cross(f.first-e.first,b)/acb;
}  

vector<pair<P,P> > elines(int x1,int x2){
  P a1=P(x_1[x1],y_1[x1]),a2=P(x_2[x1],y_2[x1]);
  P b1=P(x_1[x2],y_1[x2]),b2=P(x_2[x2],y_2[x2]);
  vector<pair<P,P> > v;
  try{
    auto cpab=cp(make_pair(a1,a2),make_pair(b1,b2));
    P ac=a1-a2,bc=b1-b2;
    P d=ac/abs(ac)+bc/abs(bc);
    v.emplace_back(cpab,cpab+d);
    v.emplace_back(cpab,cpab+d*P(0,1));
  }catch(...){
    P m=(a1+b1)/2.l;
    //    P m=(a1+b1)/2.;
    v.emplace_back(m,m+a2-a1);
  }
  return v;
}
    
int main(){
  for(int n;cin>>n,n;){
    vector<pair<P,P> > lines;
    vector<P> points;
    for(int i=0;i<n;i++){
      cin>>x_1[i]>>y_1[i]>>x_2[i]>>y_2[i];
      for(int j=0;j<i;j++){
	if(i==1){
	  lines=elines(i,j);
	}else{
	  vector<pair<P,P> > nl;
	  vector<P> np;
	  for(auto e:elines(i,j)){
	    for(auto f:lines){
	      try{
		auto cpef=cp(e,f);
		np.push_back(cpef);
	      }catch(...){
		if(on(f.first,e)&&on(f.second,e)){
		  nl.push_back(f);
		}
	      }
	    }
	    for(auto f:points){
	      if(on(f,e)){
		np.push_back(f);
	      }
	    }
	  }
	  lines=nl;
	  points.clear();
	  for(int i=0;i<np.size();i++){
	    bool has=false;
	    for(auto e:points){
	      has|=abs(e-np[i])<eps;
	    }
	    if(!has){
	      points.push_back(np[i]);
	    }
	  }
	}
      }
    }
    if(n==1||!lines.empty()||points.size()>1){
      cout<<"Many"<<endl;
    }else if(points.empty()){
      cout<<"None"<<endl;
    }else{
      cout<<fixed<<points[0].real()<<' '<<points[0].imag()<<endl;
    }
  }
}

Measured memory_bytes: 1352
import collections

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

g = [[] for i in range(n+1)]

for i in range(n-1):
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)

count = [0] * (n+1)
check = [0] * (n+1)

for i in range(q):
    p,x = map(int,input().split())
    count[p] += x

q = collections.deque()  
q.append(1)

while q:
    v = q.pop()
    check[v] = 1
    for u in g[v]:
        if check[u] == 1:
            continue
        count[u] += count[v]
        q.append(u)
        
print(*count[1:])

Measured memory_bytes: 105676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, K;
    ll S;
    cin >> N >> K >> S;
    ll a = 1e9;
    rep(i, K) cout << S << endl;
    if(S >= a/2){
        rep2(i, K, N-1) cout << 1 << endl;
    }
    else{
        rep2(i, K, N-1) cout << a << endl;
    }
}

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

int main() {
	int64_t a, b;
	cin >> a >> b;
	string k;
	if (a * b <= 0)cout << "Zero" << endl;
	else if (a > 0 && b > 0) cout << "Positive" << endl;
	else if (a < 0 && b < 0) {
		int k = b - a + 1;
		if (k % 2 == 1) {
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

int dp[55][55][200];
int a[55][55];
int n,k;

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

void solve(int cnt, int k)
{
    if (!k)
    {
        for (int i = 1; i <= n; i++)
        {
            dp[i][i][cnt] = 1;
        }
        return;
    }
    if (k & 1)
    {
        solve(cnt + 1, k - 1);
        for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++)
        {
            if (!a[j][k]) continue;
            add(dp[i][k][cnt], dp[i][j][cnt + 1]);
        }
    } else {
        solve(cnt + 1, k >> 1);
        for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++)
        {
            add(dp[i][k][cnt], dp[i][j][cnt + 1] * dp[j][k][cnt + 1]);
        }
    }
}

signed main()
{
    //freopen("file.inp","r",stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
    {
        cin >> a[i][j];
    }
    solve(1, k);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
    {
        add(ans, dp[i][j][1]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 7692
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

enum lim = 80 * 80 * 2;

void main() {
    int m1, d1;
    scan(m1, d1);
    int m2, d2;
    scan(m2, d2);
    writeln(m1 < m2 ? 1 : 0);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[10][10];
int main()
{
	for (int i=1; i<=3; i++)
		for (int j=1; j<=3; j++) cin >> a[i][j];
	int n;
	cin >> n;
	for (int i=1; i<=n; i++)
	{
		int x;
		cin >> x;
		for (int j=1; j<=3; j++)
			for (int h=1; h<=3; h++)
				if (a[j][h]==x) a[j][h]=-1; 
	 }
	for (int i=1; i<=3; i++)
		if (a[i][1]==-1&&a[i][2]==-1&&a[i][3]==-1)
		{
			cout << "Yes" << endl;
			return 0;
		}
	for (int i=1; i<=3; i++)
		if (a[1][i]==-1&&a[2][i]==-1&&a[3][i]==-1)
		{
			cout << "Yes" << endl;
			return 0;
		}
	if ((a[1][1]==-1&&a[2][2]==-1&&a[3][3]==-1)||(a[1][3]==-1&&a[2][2]==-1&&a[3][1]==-1))
	{
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define WHITE 0
#define BLACK 1
static const int MAX = 500;
static const int INF = (1<<21);

int main(void){
  int n, i, j, e, sum;
  int u, v;
  int minv;
  int M[MAX][MAX];
  int check[MAX];
  int p[MAX];
  int key[MAX];
  
  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INF:e;
    }
  }


  for(i = 0;i < n;i++){
    key[i] = INF;
    p[i] = NIL;

    //まだ訪れてない
    check[i] = WHITE;
  }


  key[0] = 0;
  //sum = 0;
  while(1){
    u = NIL;  
    minv = INF;

    //コストの少ないのーどみつける
    for(i = 0;i < n;i++){
      if(key[i] < minv && check[i] == WHITE){
	u = i;
	minv = key[i];
      }
    }

    if(u == NIL)
      break;  

    //使ったことにする    
    check[u] = BLACK;
    //sum += key[u];

    //隣接するそれぞれののーどに重みを入れる
    for(v = 0;v < n;v++){
      if(M[u][v] < key[v] && check[v] == WHITE){
	key[v] = M[u][v];
	p[v] = u;
      }
    }
  }  


  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }


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

Measured memory_bytes: 804
import java.util.Arrays;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scanner.nextLong();
        }
        Arrays.sort(A);

        BC[] bc = new BC[M];
        for (int i = 0; i < M; i++) {
            bc[i] = new BC(scanner.nextInt(), scanner.nextLong());
        }
        long[] D = new long[N];
        Arrays.sort(bc);
        reverse(bc);
        int idx = 0;
        outer: for (int i = 0; i < M; i++) {
            for (int j = 0; j < bc[i].B; j++) {
                if (idx == N) {
                    break outer;
                }
                D[idx++] = bc[i].C;
            }
        }
        Arrays.sort(D);
        reverse(D);

        for (int x = 0; x < N; x++) {
            if (A[x] < D[x]) {
                A[x] = D[x];
            }
        }
        long ans = 0;
        for (long a : A) {
            ans += a;
        }

        System.out.println(ans);

    }

    public static void reverse(BC[] arr) {
        for (int i = 0; i < arr.length / 2; i++) {
            BC tmp = arr[i];
            arr[i] = arr[arr.length - i - 1];
            arr[arr.length - i - 1] = tmp;
        }
    }

    public static void reverse(long[] arr) {
        for (int i = 0; i < arr.length / 2; i++) {
            long tmp = arr[i];
            arr[i] = arr[arr.length - i - 1];
            arr[arr.length - i - 1] = tmp;
        }
    }

    static class BC implements Comparable<BC> {
        int B;
        long C;

        public BC(int b, long c) {
            this.B = b;
            this.C = c;
        }

        @Override
        public int compareTo(BC o) {

            return Long.compare(this.C, o.C);
        }

    }
}


Measured memory_bytes: 96508
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define INF (1LL<<59)
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif 
   /********************* Code starts here ***********************/   
   int n;
   cin>>n;
   vector<int>a(n);
   for(int i=0;i<n;i++)
   	cin>>a[i];
   sort(all(a));
   int ans=0,k=0;
   vector<int>b;
   for(int i=1;i<=100000;i++)
   {
   	while(k<n&&a[k]<i){
   		b.pb(a[k]);
   		k++;
   	}
   	if(b.size()==n-b.size())
   		ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

int main() {
    int n, m;
    cin >> n >> m;
    vec k(n);
    vec l[100010];
    rep(i, n) {
        cin >> k[i];
        l[i].resize(k[i]);
        rep(j, k[i]) {
            cin >> l[i][j];
            --l[i][j];
        }
    }

    UnionFind uf(n);
    vec lv[100010];

    rep(i, n) {
        rep(j, k[i]) {
            for (auto&& k : lv[l[i][j]]) {
                uf.unite(i, k);
                break;
            }

            lv[l[i][j]].push_back(i);
        }
    }

    if (uf.size(0) == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  int a[N];
  for(int i=0;i<N;i++){
    cin >>a[i];
  }
  int hi=a[0];
  int ans=1;
  for(int i=1;i<N;i++){
if(hi<=a[i]){
ans++;
  hi=a[i];
}
  }
  cout <<ans;
  }
    

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1
#define MOD(x, m) ((x) % (m) + (m)) % (m)

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

template <typename T>
void join(vector<T>& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

const ll m = 2019;
void solve() {
    string s;
    cin >> s;

    unordered_map<ll, ll> mod_count;
    mod_count[0]++;

    ll ten_pow = 1;
    ll cur = 0;
    ll res = 0;
    REPREV(i, s.size()) {
        int d = s[i] - '0';
        d = d * ten_pow;
        ten_pow = (ten_pow * 10) % m;
        cur = (cur + d) % m;
        res += mod_count[cur];
        mod_count[cur]++;
    }

    cout << res << "\n";
}

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

    return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<cstdio>

using namespace std;

int n,m,x[100001],y[100001],ans;
bool check[401][401],c[401];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)scanf("%d%d",x+i,y+i);
	for(int i=1;i<=n;++i){
		check[i][i]=true;
		for(int j=m;j;--j){
			bool b1=check[i][x[j]],b2=check[i][y[j]];
			if(b1&&b2){c[i]=true;break;}else if(b1)check[i][y[j]]=true;else if(b2)check[i][x[j]]=true;  
		}
	}
	for(int i=1;i<n;++i)if(!c[i])for(int j=i+1;j<=n;++j)if(!c[j]){
		bool flag=true;
		for(int k=1;k<=n;++k)if(check[i][k]&&check[j][k]){flag=false;break;}
		ans+=flag;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(void){
  int H,W;
  do{
    int i,j;
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)
      return 0;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }while(H!=0||W!=0);
  return 0;
}

Measured memory_bytes: 572
N, K = gets.split.map(&:to_i)
S = gets.chomp

g = 0
a = S.chars.chunk(&:itself).map{|e, f| [e.to_i, g += f.size]}
a = [[1, 0]] + a if a[0][0] == 0
a = a + [[1, S.length]] if a[-1][0] == 0
z = a.size - 1
res = [a[[2*K, z].min][1]]
l, r = 1, 2*(K + 1)
while r <= z
  res << a[r][1] - a[l][1]
  l += 2; r += 2
end
puts res.max

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int x, n;
    cin >> x >> n;
    vector<bool> p(110);
    rep (i, n) {
        int a;
        cin >> a;
        p[a] = true;
    }
    if (n == 0) {
        cout << x << endl;
        return 0;
    }
    int res = 0;
    int diff = Inf;
    rep (i, 110) {
        if (p[i]) continue;
        int tmp = abs(x - i);
        if (tmp < diff) {
            diff = tmp;
            res = i;
        }
    }
    cout << res << endl;
    
    return 0;
}



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

int main(){
	int x,y;
	cin>>x>>y;
	int total=0;
	if(x==3) total+=100000;
	else if(x==2) total+=200000;
	else if(x==1) total+=300000;
	if(y==3) total+=100000;
	else if(y==2) total+=200000;
	else if(y==1) total+=300000;
	if(x==1 && y==1) total+=400000;
	cout<<total<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, x;
  cin >> N >> x;
  int ans = 0;
  vector<int> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  for(int i = 0; i < N; i++){
    if(data.at(i) > x){
      x = 0;
      break;
    } else {
      x -= data.at(i);
      ans++;
    }
  }
  if(x != 0)ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <set>

using namespace std;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  int q;
  cin >> q;
  int m[q];
  for (int i = 0; i < q; ++i)
    cin >> m[i];

  long long limit = pow(2, n);

  set<int> ans;
  for (int j = 0; j < limit; ++j) {
    int tmp = 0;
    for (int k = 0; k < n; ++k) {
      if ((j >> k) & 1)
        tmp += a[k];
    }
    ans.insert(tmp);
  }

  for (int i = 0; i < q; ++i) {
    if (ans.find(m[i]) != ans.end())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 3300
n = int(input())
dl = list(map(int, input().split()))

if 0 in dl:
    print(0)
    exit()

dl.sort()
dl1 = [0,24]
dl2 = [0,24]
for i, d in enumerate(dl):
    if i%2 == 0:
        dl1.append(d)
        dl2.append(24-d)
    else:
        dl1.append(24-d)
        dl2.append(d)

dl1.sort()
dl2.sort()

min_1 = 24
for a,b in zip(dl1[1:],dl1[:-1]):
    diff = a-b
    min_1 = min(min_1,diff)

min_2 = 24
for a,b in zip(dl2[1:],dl2[:-1]):
    diff = a-b
    min_2 = min(min_2,diff)

ans = max(min_1,min_2)
print(ans)


Measured memory_bytes: 62048
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), diff(m-1);
    for(int i=0;i<m;++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int i=0;i<m-1;++i) {
        diff[i] = a[i+1] - a[i];
    }
    sort(diff.rbegin(), diff.rend());

    if(n >= m) {
        cout << 0 << endl;
        return 0;
    }

    cout << accumulate(diff.begin()+n-1, diff.end(), 0) << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
//#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define C 410
#define N 410
ll S[C][N];
ll F[C][N];

ll inv[2*N], fact[2*N], ifact[2*N], pw[2*N][C];

int n, m;
ll a[N], b[N];

void init_fact(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n;i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
	rep(i, n) pw[i][0] = 1;
	rep(i, n) rep(j, C-1) pw[i][j+1] = (i*pw[i][j])%mod;
}

ll comb(ll a, ll b){
	return fact[a+b]*ifact[a]%mod*ifact[b]%mod;
}

ll recS(ll c, ll n){
	c++;
	ll res = S[c][n];
	if(res>=0) return res;
	if(c==1||n==0) return S[c][n] = n;
	res = (pw[n+1][c]-1)%mod;
	rep(i, c-1) (res-=S[i+1][n]*comb(c-i, i))%=mod;
	(res*=inv[c])%=mod;
	return S[c][n] = res;
}

ll recF(ll c, ll ix){
	ll res = F[c][ix];
	if(res>=0) return res;
	if(ix==n) return F[c][ix] = (c==0?1:0);
	res = 0;
	rep(i, c+1){
		(res+=(S[c-i+1][b[ix]]-S[c-i+1][a[ix]-1])*F[i][ix+1])%=mod;
	}
	(res+=mod)%=mod;
	//cerr<<c<<" "<<ix<<" "<<res<<endl;
	return F[c][ix] = res;
}

int main(){
	init_fact(2*N);
	mset(S, -1);
	mset(F, -1);
	//rep(i, 4) rep(j, 4) cerr<<i<<" "<<j<<" "<<recS(i, j)<<endl;
	cin>>n>>m;
	rep(i, n) cin>>a[i];
	rep(i, n) cin>>b[i];
	rep(i, m+2) rep(j, N) recS(i, j);
	rep(j, n) rep(i, m+1) recF(i, n-j);
	cout<<recF(m, 0)<<endl;
	return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
bool t[10];
int n,f[110][10],p[110][11];
int F(){
	int res=0;
	lol(i,n){
		int cnt=0;
		lol(j,10)if(f[i][j]==1&&t[j]==1)cnt++;
		res+=p[i][cnt];
	}
	return res;
}
int main(){
	cin>>n;
	lol(i,n)lol(j,10)cin>>f[i][j];
	lol(i,n)lol(j,11)cin>>p[i][j];
	int ans=-mod;
	for(int i=1;i<(1<<10);i++){
		lol(j,10){
			t[j]=(i%(1<<(j+1))>=(1<<j));
		}
		ans=max(ans,F());
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Reopard on 2014/06/05.
 */
public class Main{

    static Scanner sc = new Scanner(System.in);
    static Position[] direction = {new Position(-1, 0), new Position(0, -1), new Position(1, 0), new Position(0, 1)};

    public static void main(String args[]){
        int N, number, tmp_dire, right, left, top, bottom;
        Position[] square_pos;
        while((N = sc.nextInt()) != 0){
            right = 0;
            left = 0;
            top = 0;
            bottom = 0;
            square_pos = new Position[N];
            square_pos[0] = new Position(0, 0);
            for(int i = 1; i < N; i++){
                number = sc.nextInt();
                tmp_dire = sc.nextInt();
                square_pos[i] = new Position(square_pos[number].x, square_pos[number].y);
                square_pos[i].movePosition(direction[tmp_dire]);
            }
            for(int j = 0; j < square_pos.length; j++){
                if(square_pos[j].x < left) left = square_pos[j].x;
                else if(square_pos[j].x > right) right = square_pos[j].x;
                if(square_pos[j].y < bottom) bottom = square_pos[j].y;
                else if(square_pos[j].y > top) top = square_pos[j].y;
            }
            System.out.println((right - left +1) + " " + (top - bottom + 1));
        }
    }

    static class Position{
        int x, y;

        Position(int x, int y){
            this.x = x;
            this.y = y;
        }

        void movePosition(Position tmp){
            x += tmp.x;
            y += tmp.y;
        }
    }
}

Measured memory_bytes: 34784
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

A, B = na()
print(A * B)

Measured memory_bytes: 10928
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int r,d,x;
  cin >> r >> d >> x;
  int i;
  rep(i, 10){
    x = r * x - d;
    cout << x << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    if b == 0: 
        return a
    return gcd(b, a % b)


N, X = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
    A[i] = abs(A[i] - X)

if N > 1:
    g = gcd(A[0], A[1])
else:
    g = A[0]

for i in A:
    g = gcd(g, i)

print(g)


Measured memory_bytes: 14252
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(void){
  int x,y;
  int m[20][20];
  for( ; ; ){
    cin >> x >> y;
    if(!x && !y) break;

    memset(m,0,sizeof(m));

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

    long long dp[20][20] = {0};
    long long ans = 0;

    for(int i = 0;i < y; i++){
      for(int j = 0;j < x; j++){
	if(i == 0){
	  if(m[i][j] == 0) dp[i][j] = 1;
	}
	if(m[i][j] == 2 && m[i+2][j] != 1) dp[i+2][j] += dp[i][j];
	else if(!m[i][j] && !j){
	  dp[i+1][j] += dp[i][j];
	  if(!m[i+1][j+1]) dp[i+1][j+1] += dp[i][j];
	}
	else if(!m[i][j] && j == x-1){
	  dp[i+1][j] += dp[i][j];
	  if(!m[i+1][j-1]) dp[i+1][j-1] += dp[i][j];
	}
	else if(!m[i][j]){
	  if(!m[i+1][j-1]) dp[i+1][j-1] += dp[i][j];
	  dp[i+1][j] += dp[i][j];
	  if(!m[i+1][j+1]) dp[i+1][j+1] += dp[i][j];
	}
      }
    }

    for(int i = 0;i < x; i++){
      if(m[y-2][i] == 2) ans += dp[y-2][i];
      if(m[y-1][i] != 1) ans += dp[y-1][i];
    }

    cout << ans << endl;
  }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (accumulate(a.begin(), a.end(), 0) < h) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
  return 0;
} 

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <algorithm>

using int64 = long long;

const int M = 510, mod = 1e9 + 7;

int dp[M][M], binom[M][M];

void add(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m); m++;
  std::vector<int> cnt(m + 1);
  for (int i = 0, x; i < n; ++i) {
    scanf("%d", &x);
    cnt[x]++;
  }
  for (int i = 0; i <= m; ++i) {
    binom[i][0] = binom[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;
    }
  }
  dp[0][0] = mod - 1;
  for (int x = m; x >= 1; --x) {
    for (int i = m / x; i >= 0; --i) for (int j = 0; j <= m; ++j) {
      if (!dp[i][j]) continue;
      for (int k = 1; k * x + j <= m; ++k) {
        int w = (int64)dp[i][j] * binom[i + k][k] % mod;
        if (k & 1) add(dp[i + k][k * x + j], mod - w);
        else add(dp[i + k][k * x + j], w);
      }
    }
    if (cnt[x]) {
      for (int i = 0; i <= m; ++i) {
        for (int j = 0; j <= m; ++j) if (dp[i][j]) {
          for (int k = 0; k < cnt[x]; ++k) {
            dp[i][j] = (int64)dp[i][j] * (j - i * x + mod) % mod;
          }
        }
      }
    }
  }
  int64 ret = 0;
  for (int i = 1; i <= m; ++i) {
    ret += dp[i][m];
  }
  printf("%lld\n", ret % mod);
  return 0;
}


Measured memory_bytes: 2176
import math
x1, y1, x2, y2 = map(int, input().split())

diffx = x1 - x2
diffy = y1 - y2

len_of_v = int((diffx ** 2 + diffy ** 2) ** 0.5)

if diffx == 0:
    x3 = x2 + diffy
    x4 = x1 + diffy
    y3 = y2
    y4 = y1
elif diffy == 0:
    x3 = x2
    x4 = x1
    y3 = y2 - diffx
    y4 = y1 - diffx
else:
    grad = diffy / diffx
    counter_grad = -1 / grad

    x3 = x2 + diffy
    y3 = y2 + diffy * counter_grad

    x4 = x1 + diffy
    y4 = y1 + diffy * counter_grad

print(round(x3), round(y3), round(x4), round(y4))



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define lll __int128
#define ull unsigned long long
#define fi first
#define se second
#define db double
#define ld long double
#define lld __float128

/// order_of_key, find_by_order

template<class T, class COMP>
using custom_set = tree<T, null_type, COMP, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd_64(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    string s; cin >> s;
    ll l[s.size()+1], r[s.size()+1];
    l[0] = 0;
    ll cur = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '<')
        {
            cur++;
        }
        else
        {
            cur = 0;
        }
        l[i+1] = cur;
    }
    r[s.size()] = 0;
    cur = 0;
    for(int i = s.size()-1; i >= 0; i--)
    {
        if(s[i] == '>')
        {
            cur++;
        }
        else
        {
            cur = 0;
        }
        r[i] = cur;
    }
    ll ans = 0;
    for(int i = 0; i <= s.size(); i++)
    {
        bool b = 1;
        if(i && s[i-1] != '<')
            b = 0;
        if(i < s.size() && s[i] != '>')
            b = 0;
        if(b)
        {
            ans += l[i]*(l[i]-1)/2ll;
            ans += r[i]*(r[i]-1)/2ll;
            ans += max(l[i], r[i]);
        }
    }
    cout << ans;
}






































/// shche ne vmerla Ykraina


Measured memory_bytes: 8708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] array = new int[r+1][c+1];

		for(int i=0; i<r; i++) {
			int csum=0;
			for(int j=0; j<c; j++) {
				array[i][j]=sc.nextInt();
				csum +=array[i][j];
			}
			array[i][c]=csum;
		}
		int sum=0;
		for(int i=0; i<c;i++) {
			int rsum=0;
			for(int j=0; j<r; j++) {
				rsum+=array[j][i];
			}
			array[r][i]=rsum;
			sum+=rsum;
		}
		array[r][c]=sum;

		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c+1; j++) {
				if(j==0) {
					System.out.printf("%d",array[i][j]);
				}else {
					System.out.printf(" %d",array[i][j]);
				}

			}
				System.out.println();
		}

	}
}


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

int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
  a[i]--;
}
vector<ll> v(n,-1);
v[0]=0;
ll nw=0;
while(k>0){
  k--;
  if(v[a[nw]]!=-1)k%=v[nw]+1-v[a[nw]];
  v[a[nw]]=v[nw]+1;
  nw=a[nw];
}
cout << nw+1 << endl;
return 0;
}

Measured memory_bytes: 6428
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;

    if(a<b){
        for(int i=0;i<b;i++){
            cout<<a;
        }
        cout<<endl;
    }else{
        for(int i=0;i<a;i++){
            cout<<b;
        }
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) throws Exception{	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int x = sc.nextInt();
		
		int[] a = new int[n];
		
		long c=0;
		int t;
		
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
			if(a[i] > x){
				c += a[i] - x;
				a[i] = x;
			}
		}
		
		for(int i=1; i<n; i++){
			t = a[i-1] + a[i];
			if(t > x){
				t = t - x;
				c += t;
				a[i] -= t;
			}
		}
		
		System.out.println(c);
		
		sc.close();
	}
}

Measured memory_bytes: 33496
s = raw_input()
s_i = s.find("C")
if s_i == -1:
    print "No"
else:
    s_i2 = s.rfind("F")
    if s_i2 == -1:
        print "No"
    elif s_i > s_i2:
        print "No"
    else:
        print "Yes"


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  if (K == 0)
  {
    cout << N * N << endl;
    return 0;
  }

  int ans = 0;
  for (int b = K + 1; b <= N; b++)
  {
    int tmp = ((N + 1) / b) * (b - K);
    if ((N + 1) % b != 0) tmp += max((int)0, N % b - K + 1);
    ans += tmp;
  }

  cout << ans << endl;
}

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;

const int INF = 1001001001;
int n;
vector<int> to[1005];

vector<int> bfs(int sv) {
  vector<int> dist(n,INF), pre(n,-1);
  queue<int> q;
  dist[sv] = 0;
  q.push(sv);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      pre[u] = v;
      dist[u] = dist[v]+1;
      q.push(u);
    }
  }

  pair<int,int> best(INF,-1);
  rep(v,n) {
    if (v == sv) continue;
    for (int u : to[v]) {
      if (u == sv) {
        best = min(best, make_pair(dist[v],v));
      }
    }
  }
  if (best.first == INF) return vector<int>(n+1);
  int v = best.second;
  vector<int> res;
  while (v != -1) {
    res.push_back(v);
    v = pre[v];
  }
  return res;
}

int main() {
  int m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }

  vector<int> ans(n+1);
  rep(s,n) {
    auto now = bfs(s);
    if (now.size() < ans.size()) ans = now;
  }
  if (ans.size() == n+1) {
    cout<<-1<<endl;
    return 0;
  }
  cout << ans.size() << endl;
  for (int v : ans) {
    cout << v+1 << endl;
  }
  return 0;
}

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

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

    string s;
    cin >> s;
    
    int n = (int)s.size();
    
    vector<string> a(n);
    a[n-1] = s;
    
    int ans = 1e9;
    
    if(s == string((int)s.size(),s[0])) ans = 0;
    else {
        
        for(char c = 'a'; c <= 'z'; c++){
            for(int i = n - 2; i >= 0; i--){
                string t;
                for(int j = 0; j <= i; j++){
                    if(a[i+1][j] == c or a[i+1][j+1] == c) t.push_back(c);
                    else t.push_back(a[i+1][j]);
                }
                if(t == string((int)t.size(),t[0])){
                    ans = min(ans,n - (int)t.size());
                }
                a[i] = t;
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

void selectionSort(int *A, int N){
    int count = 0;
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        if(A[i] != A[minj]){
            int temp = A[i];
            A[i] = A[minj];
            A[minj] = temp;
            count++;
        }
    }
    for(int i = 0; i < N; i++){
        if(i != N-1){
            printf("%d ",A[i]);
        }
        else{
            printf("%d\n",A[i]);
        }
    }
    printf("%d\n",count);
}

int main(void){
    int N;
    scanf("%d",&N);
    int A[N];
    for(int i = 0; i < N; i++){
        scanf("%d",&A[i]);
    }
    selectionSort(A, N);
    return 0;
}


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

int main(){
 string s;
  cin>>s;
  int N=(int)s.size();
  int sum=0;
  for(int i=0;i<N/2;i++){
    if(s.at(i)!=s.at(N-1-i)){
      sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3532
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 n,k;
    cin >> n >> k;
    cout << k * (int64)pow(k-1,n-1) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int n;
  while(cin >> n && n){
    int top = 1, front = 2, right = 3, left = 4, rear = 5, under = 6;
    int sum = 1;
    for(int i = 0; i < n; i++){
      string s;
      cin >> s;
      if(s == "North"){
        swap(top, rear);
        swap(top, under);
        swap(top, front);
        sum += top;
      }
      if(s == "East"){
        swap(top, right);
        swap(top, under);
        swap(top, left);
        sum += top;
      }
      if(s == "West"){
        swap(top, left);
        swap(top, under);
        swap(top, right);
        sum += top;
      }
      if(s == "South"){
        swap(top, front);
        swap(top, under);
        swap(top, rear);
        sum += top;
      }
      if(s == "Right"){
        swap(front, left);
        swap(front, rear);
        swap(front, right);
        sum += top;
      }
      if(s == "Left"){
        swap(front, right);
        swap(front, rear);
        swap(front, left);
        sum += top;
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int x = Integer.parseInt(reader.readLine());
		int ans = x * x * x;
		System.out.println(ans);
	}
}

Measured memory_bytes: 24184