akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;



int main() {
    
    long long N;
    long long ans = 0;
    
    
    vector<long long>A;
    
    cin >> N;
    
    
    bool is_exit = false;
    
    for ( int i = 0; i < N; i++ ) {
        long long temp;
        cin >> temp;
        A.push_back(temp);
        if ( temp == 2 ) {
            is_exit = true;
        }
    }
    
    if ( ! is_exit ) {
        cout << -1 << endl;
        return 0;
    }
    
    long long a = 1;
    
    is_exit = false;
    for ( int i = 0; i <= N; i++ ) {
        ans++;
        a = A[a-1];
        
        if ( a == 2 ) { 
            is_exit = true;
            break;
        }
    }
    
    if ( is_exit ) {
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A;
    map<int, int> ma;
    cin >> N;
    REP(i, N) {
        cin >> A;
        ma[A]++;
    }

    if (ma.size() == 3) {
        pii a[3];
        int i = 0;
        for (auto it = ma.begin(); it != ma.end(); it++) {
            a[i++] = *it;
        }

        if (((a[0].first ^ a[1].first) == a[2].first) && (a[0].second == a[1].second) && (a[1].second && a[2].second)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (ma[0] > 0) {
        if (ma[0] * 3 == N) {
            for (auto it = ma.begin(); it != ma.end(); it++) {
                if ((*it).first == 0) continue;
                if ((*it).second % 2 != 0) {
                    cout << "No" << endl;
                    return 0;
                }
            }
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (ma.size() == 1) {
        if ((*ma.begin()).first == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}

};

int main() {
	int n, m, in;
	ll sum = 0,ans=0;
	vl v, vm;
	cin >> n >> m;
	rep(i, n) {
		cin >> in;
		sum += in;
		v.push_back(in);
		vm.push_back(sum);
	}
	map<int, int> mp;
	mp[0] = 0;
	rep(i, n) {
		int tgt = vm[i] % m;
		if (mp.find(tgt) == mp.end()) {
			mp[tgt] = 1;
		}
		else mp[tgt]++;
	}
	mp[0]++;
	for (pair<int, int> p:mp) {
		ans += 1ll * p.sc*(p.sc - 1) / 2;
	}
	cout << ans << endl;


}


Measured memory_bytes: 4716
#include<iostream>
#include<string.h>
int main(){bool*v=new bool[1000000];for(int m,n,o,c,d,e,i;!(std::cin>>n).eof();){if(n<3)e=n>1;else{memset(v,1,c=(n&1?n:--n)/2+1);for(i=m=e=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;e++;for(d=o=m*2+1;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(i=1;i<c;)e+=v[i++];}printf("%d\n",e);}delete[]v;}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#define MOD 100000
#define FMAX 10946
#define NMMAX 20

int main(void)
{
  int i, j, k, m, n, fcheck, mask, ans = 1, res = 0, fcount = 0; 
  int k2b[FMAX], b2k[1<<19], dp[2][FMAX][2], (*src)[2], (*dst)[2];
  char field[NMMAX][NMMAX+1];
  scanf("%d %d%*c", &m, &n);
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      field[i][j] = getchar_unlocked();
      if (field[i][j] == '?') ans = (ans * 3) % MOD;
    }
    getchar_unlocked();
  }
  for (i = 0; i < (1 << (n - 1)); i++) {
    fcheck = 1;
    for (j = 0; j < n - 2; j++) {
      if (((i >> j) & 1) & ((i >> (j + 1)) & 1)) {
        fcheck = 0;
	break;
      }
    }
    if (fcheck) {
      k2b[fcount] = i;
      b2k[i] = fcount++;
    }
  }
  mask = (1 << (n - 1)) - 1;
  fcheck = 1;
  src = dp[0];
  dst = dp[1];
  src[0][0] = 1;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      int (*ftemp)[2];
      memset(dp[fcheck], 0, sizeof(dp[fcheck]));
      for (k = 0; k < fcount; k++) {
	 int nk, jflag;
	if (field[i][j] == 'J' || field[i][j] == '?') {
          nk = b2k[(k2b[k] << 1) & mask];
	  jflag = (j < n - 1);
	  dst[nk][jflag] = (dst[nk][jflag] + src[k][0] + src[k][1]) % MOD;
	} 
	if (field[i][j] == 'O' || field[i][j] == '?') {
	  nk = b2k[((k2b[k] << 1) & mask) | 0];
	  jflag = 0;
	  dst[nk][jflag] = (dst[nk][jflag] + src[k][0]) %  MOD;
	  nk = b2k[((k2b[k] << 1) & mask) | 1];
	  dst[nk][jflag] = (dst[nk][jflag] + src[k][1]) % MOD;
	}
	if (field[i][j] == 'I' || field[i][j] == '?') {
	  if (((~k2b[k]) >> (n - 2)) & 1) {
	    nk = b2k[(k2b[k] << 1) & mask];
	    jflag = 0;
	    dst[nk][jflag] = (dst[nk][jflag] + src[k][0] + src[k][1]) % MOD;
	  }
	}
      }
      ftemp = src;
      src = dst;
      dst = ftemp;
      fcheck ^= 1;
    }
  }
  for (i = 0; i < fcount; i++) res = (res + src[i][0] + src[i][1]) % MOD;
  printf("%d\n", (ans - res + MOD) % MOD);
}



Measured memory_bytes: 2396
#p=int(input())
n,p=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#素因数分解した結果を2次元配列にして返す
def prime_factorize(n):
    n_origin=n+0
    primelist=[]
    a=2
    while a*a<=n_origin:
        if n%a!=0:
            a+=1
            continue
        ex=0
        while n%a==0:
            ex+=1
            n=n//a
        primelist.append([a,ex])
        a+=1
    if n!=1:
        primelist.append([n,1])
    return primelist
pfs=prime_factorize(p)
ans=1

for pf in pfs:
    p=pf[0];ex=pf[1]
    ans=ans*(p**(ex//n))
print(ans)


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define maxn 100005
using namespace std;
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
typedef long long ll;
string s;
int main()
{
    while(cin>>s)
    {
        int index=0,maxleng=0;
        for(auto i:s)
        {
            if(i=='A'||i=='C'||i=='T'||i=='G')
            {
                index++;
            }
            else
            {
                maxleng=max(maxleng,index);
                index=0;
            }
        }
        maxleng=max(maxleng,index);
        cout<<maxleng<<"\n";
    }

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=2e5+10,mod=1e9+7;
int jc[N],inv[N],bit[N],B,W,sw[N],sb[N];
int ksm(int x,int k)
{
	int s=1;for(;k;k>>=1,x=1ll*x*x%mod)
				if(k&1) s=1ll*s*x%mod;return s;
}
int C(int n,int k) {return 1ll*jc[n]*inv[k]%mod*inv[n-k]%mod;}
int main()
{
	cin>>B>>W;
	jc[0]=bit[0]=inv[0]=1;
	for(int i=1;i<=B+W;i++) jc[i]=1ll*i*jc[i-1]%mod;
	for(int i=1;i<=B+W;i++) inv[i]=ksm(jc[i],mod-2);
	for(int i=1;i<=B+W;i++) bit[i]=1ll*bit[i-1]*inv[2]%mod;

	for(int i=W;i<B+W;i++)
		sw[i]=1ll*bit[i]*C(i-1,i-W)%mod;
	for(int i=B;i<B+W;i++)
		sb[i]=1ll*bit[i]*C(i-1,i-B)%mod;
//	for(int i=1;i<=B+W;i++)
//		printf("sw[%d]=%d,sb[%d]=%d\n",i,sw[i],i,sb[i]);
	for(int i=1;i<=B+W;i++)
	{
		(sw[i]+=sw[i-1])%=mod;
		(sb[i]+=sb[i-1])%=mod;
	}
	for(int i=1;i<=B+W;i++)
	{
		int w=(sw[i-1]+1ll*((mod+1-sw[i-1]-sb[i-1])%mod+mod)%mod*
			   (i==B+W?1:inv[2])%mod)%mod;
		cout<<w<<endl;
	}
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
signed main()
{
	scanf("%lld%lld",&n,&m);
	if(n==1||m==1)
	printf("1");
	else
	printf("%lld",n*m/2+n*m%2);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

int main(){
    int N,X,D[110],L[110],sum=1;
    cin>>N>>X;
    D[0]=0;
    for(int i=0;i<N;++i){
        cin>>L[i];
        D[i+1]=D[i]+L[i];
        if(D[i+1]<=X)sum+=1;
    }

    cout<<sum<<endl;
    return 0;

}

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

#define ll long long
#define mx 100005
int n,m;
int ar[mx][4];
char ch[mx];

int main()
{
    scanf("%d%s",&n,ch);
    for(int i=1;i<=n;i++)
    {
        ar[i][0]=ar[i-1][0];
        ar[i][1]=ar[i-1][1];
        ar[i][2]=ar[i-1][2];
        if(ch[i-1]=='R')ar[i][0]++;
        if(ch[i-1]=='B')ar[i][1]++;
        if(ch[i-1]=='G')ar[i][2]++;
    }

    ll re=0;
    for(int i=0;i<n-2;i++)
    {
        if(ch[i]=='R')
        {
            for(int j=i+1;j<n-1;j++)
            {
                if(ch[j]=='B')
                {
                    re+=ar[n][2]-ar[j+1][2];
                    if(ch[j+j-i]=='G')re--;
                }
                if(ch[j]=='G')
                {
                    re+=ar[n][1]-ar[j+1][1];
                    if(ch[j+j-i]=='B')re--;
                }
            }
        }
        if(ch[i]=='B')
        {
            for(int j=i+1;j<n-1;j++)
            {
                if(ch[j]=='R')
                {
                    re+=ar[n][2]-ar[j+1][2];
                    if(ch[j+j-i]=='G')re--;
                }
                if(ch[j]=='G')
                {
                    re+=ar[n][0]-ar[j+1][0];
                    if(ch[j+j-i]=='R')re--;
                }
            }
        }
        if(ch[i]=='G')
        {
            for(int j=i+1;j<n-1;j++)
            {
                if(ch[j]=='B')
                {
                    re+=ar[n][0]-ar[j+1][0];
                    if(ch[j+j-i]=='R')re--;
                }
                if(ch[j]=='R')
                {
                    re+=ar[n][1]-ar[j+1][1];
                    if(ch[j+j-i]=='B')re--;
                }
            }
        }
    }
    printf("%lld\n",re);
    return 0;

}


Measured memory_bytes: 3868
#include <algorithm>　　　 //STL 通用算法
#include <bitset>　　　　　//STL 位集容器
#include <cctype>         //字符处理
#include <cerrno> 　　　　 //定义错误码
#include <cfloat>　　　　 //浮点数处理
#include <ciso646>         //对应各种运算符的宏
#include <climits> 　　　　//定义各种数据类型最值的常量
#include <clocale> 　　　　//定义本地化函数
#include <cmath> 　　　　　//定义数学函数
#include <complex>　　　　 //复数类
#include <csignal>         //信号机制支持
#include <csetjmp>         //异常处理支持
#include <cstdarg>         //不定参数列表支持
#include <cstddef>         //常用常量
#include <cstdio> 　　　　 //定义输入／输出函数
#include <cstdlib> 　　　　//定义杂项函数及内存分配函数
#include <cstring> 　　　　//字符串处理
#include <ctime> 　　　　　//定义关于时间的函数
#include <cwchar> 　　　　 //宽字符处理及输入／输出
#include <cwctype> 　　　　//宽字符分类
#include <deque>　　　　　 //STL 双端队列容器
#include <exception>　　　 //异常处理类
#include <fstream> 　　　 //文件输入／输出
#include <functional>　　　//STL 定义运算函数（代替运算符）
#include <limits> 　　　　 //定义各种数据类型最值常量
#include <list>　　　　　　//STL 线性列表容器
#include <locale>         //本地化特定信息
#include <map>　　　　　　 //STL 映射容器
#include <memory>         //STL通过分配器进行的内存分配
#include<new>            //动态内存分配
#include <numeric>         //STL常用的数字操作
#include <iomanip> 　　　 //参数化输入／输出
#include <ios>　　　　　　 //基本输入／输出支持
#include <iosfwd>　　　　　//输入／输出系统使用的前置声明
#include <iostream> 　　　//数据流输入／输出
#include <istream>　　　　 //基本输入流
#include <iterator>        //STL迭代器
#include <ostream>　　　　 //基本输出流
#include <queue>　　　　　 //STL 队列容器
#include <set>　　　　　　 //STL 集合容器
#include <sstream>　　　　 //基于字符串的流
#include <stack>　　　　　 //STL 堆栈容器
#include <stdexcept>　　　 //标准异常类
#include <streambuf>　　　 //底层输入／输出支持
#include <string>　　　　　//字符串类
#include <typeinfo>        //运行期间类型信息
#include <utility>　　　　 //STL 通用模板类
#include <valarray>        //对包含值的数组的操作
#include <vector>　　　　　//STL 动态数组容器
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const int MAXN=1e5+10;
const int MOD=998244353;

inline int read(){
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0;int f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)) x=(x<<3ll)+(x<<1ll)+1ll*(c-'0'),c=getchar();
	return x*f;
}
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
ll gcd(ll x,ll y){
	return y?gcd(y,x%y):x;
}

int n,m,k,ans;
char s[10][10];

int main(){
	n=read(),m=read(),k=read();
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<(1<<m);j++){
			int cnt=0;
			for(int x=0;x<n;x++)
				for(int y=0;y<m;y++)
					if(!(1<<x&i)&&!(1<<y&j)&&s[x][y]=='#') ++cnt;
			if(cnt==k) ++ans;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,d1,d2,d3,d4;
    cin >> n;
    d1 = d3 = -INF;
    d2 = d4 = INF;
    for (int i = 0; i < n; ++i)
    {
    	ll x , y;
    	cin >> x >> y;
    	d1 = max(d1, x+y);
    	d3 = max(d3, x-y);
    	d2 = min(d2, x+y);
    	d4 = min(d4, x-y);
    }
    ll res = max(d1 - d2, d3 - d4);
    cout << res;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
char s;
cin >>s;
string find;
find= "abcdefghijklmnopqrstuvwxyz";

for (int i=0;i<26;i++){
  if(s == find.at(i)){
    s = find.at(i+1);
    break;
  }
}

cout<< s<<endl;
}

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

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);


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

  int n;
  cin >> n;

  deque<ll> ans;

  rep(i, n) {
    ll a; cin >> a;
    auto it = lower_bound(ALL(ans), a);
    if (it == ans.begin()) {
      ans.push_front(a);
    } else {
      *(--it) = a;
    }
  }

  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define M 1000000000
int MIN(int a,int b){return a<b?a:b;}
int zMIN(int a,int b){return a*b?MIN(a,b):a+b;}
int main(){
  int n,m,i,j,a,b,v,min;
  while(scanf("%d %d",&n,&m),n||m){
    int d[110][110]={0};
    while(m--){
      scanf("%d",&a);
      if(a){
	scanf("%d %d %d",&a,&b,&v);
	d[a][b]=d[b][a]=zMIN(v,d[a][b]);
      }
      else{
	scanf("%d %d",&a,&b);
	int f[110]={0};
	int c[110]={0};
	for(j=0;j<n;j++){
	  for(i=f[a]=1;i<=n;i++){
	    if(d[a][i])c[i]=zMIN(c[i],c[a]+d[a][i]);
	  }
	  min=M;
	  for(i=1;i<=n;i++){
	    if(f[i]==0&&c[i]&&min>c[i])min=c[a=i];
	  }
	}
	//for(i=0;i<n;i++)printf("%d ",c[i+1]);printf("\n");
	if(c[b])printf("%d\n",c[b]);
	else    printf("-1\n");
      }
      /*for(i=0;i<n;i++){
	for(j=0;j<n;j++)printf("%d ",d[i+1][j+1]);
	printf("\n");
	}//*/
    }
  }
  return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int> > abcd(q, vector<int>(4));
  for (auto &x: abcd) {
    cin >> x[0] >> x[1] >> x[2] >> x[3];
    x[0]--;
    x[1]--;
  }

  queue<vector<int> > que;
  for (int i = 0; i < m; i++) que.push(vector<int>({i}));
  ll ans = 0;
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if ((int) now.size() < n) {
      for (int i = now[now.size()-1]; i < m; i++) {
        auto next = now;
        next.push_back(i);
        que.push(next);
      }
    }
    else {
      ll score = 0;
      for (int i = 0; i < q; i++) {
        if (now[abcd[i][1]] - now[abcd[i][0]] == abcd[i][2]) score += abcd[i][3];
      }
      if (score > ans) ans = score;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9768
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0095
"""
import sys


def main(args):
    winner = [-1, -1]
    n = int(input())
    for _ in range(n):
        a, v = [int(x) for x in input().strip().split(' ')]
        if v > winner[1]:
            winner[0] = a
            winner[1] = v
        elif v == winner[1]:
            if a < winner[0]:
                winner[0] = a
    print('{} {}'.format(winner[0], winner[1]))


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

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int cnt[105];
signed main(void)
{
  int a, b;
  while(cin >> a >> b) {
    cnt[a-1]++;
    cnt[b-1]++;
    if(!a && !b) {
      bool flag = true;
      if(cnt[0]%2 == 0 || cnt[1]%2 == 0) flag = false;
      FOR(i, 2, 100) if(cnt[i]%2) flag = false;
      if(flag) cout << "OK" << endl;
      else cout << "NG" << endl;
      REP(i, 100) cnt[i] = 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3036
#include <iostream>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll quick_pow(ll a, ll b, ll mod) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}

int main() {
    ll n;
    cin >> n;
    cout << ((quick_pow(10, n, MOD) - 2 * quick_pow(9, n, MOD) % MOD + MOD) % MOD + quick_pow(8, n, MOD)) % MOD << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <stdio.h>

int main()
{
	int i, N, a[100001], b[100001];
	long long K;
	scanf("%d %lld", &N, &K);
	for (i = 1; i <= N; i++) scanf("%d %d", &(a[i]), &(b[i]));
	
	long long k, count[100001] = {};
	for (i = 1; i <= N; i++) count[a[i]] += b[i];
	for (i = 1, k = 0; k < K; i++) k += count[i];
	printf("%d\n", i - 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  string s, t, r;
  cin >> s >> t >> r;
  cout << s[0] <<  t[0] <<  r[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

int main() {
    int n,m;
    cin >> n>>m;
    priority_queue<pair <long,long> > q;
    long a;
    for(int i=0; i<n;i++) {
        cin >> a;
        q.push(make_pair(a, 1));
    } 

    long b,c;
    for(int i=0; i<m;i++) {
        cin >> b >> c;
        q.push(make_pair(c, b));
    } 

    long res =0;
    long num = 0;
    while (num < n){
        a = q.top().first;
        b = q.top().second;
        if(b < n - num) res += a * b;
        else res += a * (n-num);
        num += b;
        q.pop();
    } 
    cout << res << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S, T;
	cin >> S >> T;
	
	int result = T.size();
	for(int i = 0; i <= S.size() - T.size(); i++){
		int count = 0;
		for(int j = 0; j < T.size(); j++){
			if(S[i + j] != T[j]){
				count++;
			}
		}
		result = min(result, count);
	}
	
	cout << result << endl;
}

Measured memory_bytes: 3584
<?php
	fscanf(STDIN,"%s",$s);  
  
	$ansText = "";
	for($i = 0;$i < 10;$i++){
    	$ansText .= "hi";
      	if($s == $ansText){
        	echo "Yes";
          	exit;
        }
    }
	echo "No";
?>

Measured memory_bytes: 3956
import java.util.*;
import java.lang.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        while (sc.hasNext()) list.add(sc.nextInt());
        Collections.sort(list);
        for (int i = 0; i < 3; i++) System.out.println(list.get(list.size() - i - 1));
    }
}

Measured memory_bytes: 17340
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n;
	string s;

	cin >> n >> s;
	int res = 0;
	REP(i, n-2) {
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			res++;
		}
	}
	put(res);
	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[200000], b[200000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i] >> b[i]; }
	
	bool f = true;
	inc(i, n) { f &= (a[i] == b[i]); }
	if(f) { cout << 0 << endl; return 0; }
	
	LL ans = 0, v = 0, mi = 1e9;
	inc(i, n) { if(a[i] <= b[i]) { ans += a[i]; } else { v += a[i]; setmin(mi, b[i]); } }
	
	cout << ans + v - mi << endl;
	
	return 0;
}


Measured memory_bytes: 512
def ABC051D():
    N, M = map(int, input().split())
    DP = [[10000 for i in range(N)] for j in range(N)]
    check = [[1 for i in range(N)] for j in range(N)]
    pointlist = []
    for i in range(M):
        a, b, c = map(int, input().split())
        DP[a - 1][b - 1] = c
        DP[b - 1][a - 1] = c
        pointlist.append([a, b, c])

    for k in range(N):
        for i in range(N):
            for j in range(N):
                DP[i][j] = min([DP[i][j], DP[i][k] + DP[k][j]])

    cnt = 0
    for i in pointlist:
        if DP[i[0] - 1][i[1] - 1] != i[2]:
            cnt += 1

    print(cnt)
ABC051D()

Measured memory_bytes: 3556
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int x, y, z, k;
    cin >> x >> y >> z >> k;

    auto a = vector<large>(x);
    auto b = vector<large>(y);
    auto c = vector<large>(z);
    for (auto& a_i : a)
        cin >> a_i;
    for (auto& b_i : b)
        cin >> b_i;
    for (auto& c_i : c)
        cin >> c_i;
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());

    auto s = multiset<tuple<large, int, int, int>, greater<>>();
    for (auto ai = 0; ai < x; ++ai) {
        for (auto bi = 0; bi < y; ++bi) {
            s.insert(make_tuple(a[ai] + b[bi] + c[0], ai, bi, 0));
        }
    }


    while (!s.empty() && 0 < k) {
        auto itr = s.begin();
        auto [x, ai, bi, ci] = *itr;
        s.erase(itr);
        --k;
        cout << x << "\n";

        if (ci + 1 < z) {
            s.insert(make_tuple(x - c[ci] + c[ci + 1], ai, bi, ci + 1));
        }
    }

    return 0;
}


Measured memory_bytes: 66140
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  int co=0;
  bool han=true;
  rep(i,n){
    string in;int a;
    cin>>in>>a;
    if(in=="(")co+=a;
    else if(in==")")co-=a;
    if(co<0)han=false;
  }
  if(co!=0||han==false)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}
    /*  rep(j,a)s=s+in;
  }
  bool han=true;
  int co=0;
  rep(i,s.size()){
    if(s[i]=='(')co++;
    else if(s[i]==')')co--;
    if(co<0)han=false;
  }
  if(co!=0||han==false)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
*/

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

int main(){

    int l;
    cin>>l;
    int r=l%100;
    l/=100;

    if(1<=l&&l<=12){
        if(1<=r&&r<=12) cout<<"AMBIGUOUS"<<endl;
        else cout<<"MMYY"<<endl;
    }
    else{
        if(1<=r&&r<=12) cout<<"YYMM"<<endl;
        else cout<<"NA"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=(int)s;i<(int)n;i++)
int main() {
  int n; cin>>n;
  vector<int> d1(n);
  vector<int> d2(n);
  rep(i,0,n) cin>>d1[i]>>d2[i];
  int cnt=0;
  rep(i,0,n){
    if(d1[i]==d2[i]){
      cnt++;
      if(cnt==3){
        cout<<"Yes";
        return 0;
      }
    }else{
      cnt=0;
    }
  }
  cout<<"No";
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for (int i=0; i<H; i++) cin >> a.at(i);
  vector<bool> row(H, false), column(W, false);
  for (int i=0; i<H; i++)
    for (int j=0; j<W; j++)
      if (a.at(i).at(j) == '#') {
        row.at(i) = true;
        column.at(j) = true;
      }
  for (int i=0; i<row.size(); i++) {
    if (row.at(i)) {
      for (int j=0; j<column.size(); j++) {
        if (column.at(j)) {
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
  cout << endl;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  char C;
  cin >> C;
  cout << char(C + 1) << 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 __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;
bool cmp(PII a,PII b)
{
    return(a.s>b.s);
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>m)
    {
        ll ara[n];
        for(i=0;i<n;i++) cin>>ara[i];
        PII pr[m];
        
        for(i=0;i<m;i++) cin>>pr[i].f>>pr[i].s;
        sort(ara,ara+n);
        i=0,j=0;
        ll sum=0;
        sort(pr,pr+m,cmp);
        while(j<m && i<n){
            k=0;
            while(i<n && ara[i]<pr[j].s && k<pr[j].f){
                sum+=pr[j].s;
                ++i,++k;
            }
            ++j;
        }

        while(i<n){
            sum+=ara[i];
            ++i;
        }

        cout<<sum<<endl;
    }




}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
  char p0, p1, p2;
  char r0, r1, r2;
  
  cin >> p0 >> p1 >> p2;
  cin >> r0 >> r1 >> r2;
  int cnt = 0;
  if(r0==p0)
    cnt++;
  if(r1==p1)
    cnt++;
  if(r2==p2)
    cnt++;
  
  cout << cnt <<endl;
  
  
 return 0;
}

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

map<int ,int > mp;

int main()
{
int a,b,c;
cin>>a>>b>>c;
mp[a]++;mp[b]++;
mp[c]++;
if(mp[5]==2 && mp[7]==1)
cout<<"YES\n";
else
cout<<"NO\n";
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define hh putchar(10)
#define gc getchar()
#define ll long long
using namespace std;
#define mtm(a) memset(a,0x3f3f3f3f,sizeof a)
#define mt1(a) memset(a,-1,sizeof a)
#define mt0(a) memset(a,0,sizeof a)
#define fup(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define debug(a) cout<<#a<<'='<<a<<endl

class FIO
{
public:
    template<typename T>FIO& operator >>(T& x){_R(x);return *this;}
    template<typename T>FIO& operator <<(T x){_W(x);return *this;}
private:
    int f,c,a[24],i;
    template<typename T> inline void _R(T& x) {
        for(f=0;(c=getchar())<48;c==45&&(f=1));
        for(x=c^48;(c=getchar())>47;x=(x<<3)+(x<<1)+(c^48));
        if(f)x=-x;
    }
    template<typename T> inline void _W(T x) {
        if(sizeof(x)==1){putchar(x);return;}
        if(x<0)putchar(45),x=-x;
        if(x>99) {
            for(i=0;x;x/=10)a[i++]=x%10;
            while(i--)putchar(a[i]+48);
        } else if (x>9)putchar(x/10+48),putchar(x%10+48);
        else putchar(x+48);
    }
}io;


int aa[55];
int main()
{
    int n,k;
    io>>n>>k;
    fup(i,0,n-1)io>>aa[i];
    int ans=-10000000,sum;
    fup(a,0,k)fup(b,0,k)fup(c,0,k) {
        if((a+b+c)<=k&&(a+b)>=c&&(a+b)<=n)
        {
            priority_queue<int> q;
            fup(i,0,a-1)q.push(aa[i]);
            fup(i,0,b-1)q.push(aa[n-1-i]);
            sum=0;
            fup(i,0,a+b-c-1)
            {
                sum+=q.top();
                q.pop();
            }
            ans=max(ans,sum);
        }
    }
    io<<ans;
    return 0;
}





Measured memory_bytes: 3564
import collections

s = int(input())
A = [s]
for i in range(1000000+1):
  A.append(A[i]//2 if A[i]%2==0 else 3*A[i]+1)
  c = collections.Counter(A)
  if c.most_common()[0][1] == 2:
    print(len(A))
    break

Measured memory_bytes: 3316
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string str;
// Lib
int gcd(int x, int y) {
  int r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}
int lcm(int x, int y) {
  return (x * y / gcd(x, y));
}

int main() {
  cin >> str;
  // Parse
  string as, bs, cs;
  int pos;
  for (pos = 0; pos < str.size(); pos++) {
    if (str[pos] != '.') {
      as += str[pos];
    } else {
      break;
    }
  }
  for (pos++; pos < str.size(); pos++) {
    if (str[pos] != '(') {
      bs += str[pos];
    } else {
      break;
    }
  }
  for (pos++; pos < str.size(); pos++) {
    if (str[pos] != ')') {
      cs += str[pos];
    } else {
      break;
    }
  }

  pair<int, int> fd, id, ans;
  // 有限小数
  fd.first = atoi((as + bs).c_str());
  fd.second = pow(10, bs.size());
  // 無限小数
  if (cs.size() > 0) {
    id.first = atoi((cs).c_str());
    id.second = (pow(10, cs.size()) - 1) * pow(10, bs.size());
  } else {
    id.first = 0;
    id.second = 0;
  }
  // Answer
  if (cs.size() > 0) {
    ans.second = lcm(fd.second, id.second);
    ans.first = fd.first * (ans.second / fd.second) + id.first * (ans.second / id.second);
  } else {
    ans.second = fd.second;
    ans.first = fd.first;
  }
  int d = gcd(ans.first, ans.second);
  ans.first /= d;
  ans.second /= d;
  cout << ans.first << '/' << ans.second << '\n';
  return 0;
}


Measured memory_bytes: 3372
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <functional>

using namespace std;

typedef pair<int, int> pii;

#define fst first
#define scd second
#define PB push_back
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

#define MAX_N 5000

struct edge {
	int to, cost;
	edge(int to, int cost = inf) : to(to), cost(cost){}
};

int d[MAX_N];
vector<edge> G[MAX_N];
vector<edge> Gi[MAX_N];

int N, K;
int C[MAX_N], R[MAX_N];

void bfs(int v)
{
	fill_n(d, N, inf);
	d[v] = 0;
	queue<pii> q;
	q.push(pii(0, v));

	while (q.size()) {
		pii p = q.front(); q.pop();
		if (p.fst >= R[v]) continue;
		rep(i, G[p.scd].size()) {
			edge e = G[p.scd][i];
			if (d[e.to] <= p.fst + 1) continue;
			d[e.to] = p.fst + 1;
			q.push(pii(d[e.to], e.to));
		}
	}
}

void dijkstra(int s)
{
	priority_queue<pii, vector<pii>, greater<pii> > q;
	fill(d, d + N, inf);
	d[s] = 0;
	q.push(pii(0, s));
	while (q.size()) {
		pii p = q.top(); q.pop();
		int v = p.scd;
		if (d[v] < p.fst) continue;
		rep(i, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(pii(d[e.to], e.to));
			}
		}
	}
}

signed main()
{
	scanf("%d %d", &N, &K);

	rep(i, N) scanf("%d %d", &C[i], &R[i]);

	rep(i, K) {
		int A, B; scanf("%d %d", &A, &B), A--, B--;
		G[A].PB(edge(B));
		G[B].PB(edge(A));
	}

	rep(i, N) {
		bfs(i);

		rep(j, N) {
			if (i == j) continue;
			if (d[j] <= R[i]) Gi[i].PB(edge(j, C[i]));
		}
	}

	rep(i, N) G[i] = Gi[i];

	dijkstra(0);

	printf("%d\n", d[N - 1]);
}

Measured memory_bytes: 234564
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int X,A,B;
    cin >> X >> A >> B;
    cout << min(X + A,min(A + B,B + X));
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.IOException;
import java.util.Scanner;
import java.util.function.IntUnaryOperator;
 
public class Main {
    private static final int N;
    private static final int K;
    private static int[] T;
    static{
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        T = new int[N];
        for(int i = 0; i < N; ++i) T[i] = sc.nextInt();
    }
    
    public static void main(String[] args) throws IOException {
        
        long max = 100000 * 10000;
        long min = 0;
        long mid;
        while(max - min > 1){
            mid = (max + min) / 2;
            if(isAllStackable(mid)) max = mid;
            else                    min = mid;
        }
        System.out.println(max);
    }
    
    private static boolean isAllStackable(long p){
        IntUnaryOperator getCount = i -> {
            long sum = 0;
            int j = 0;
            for(; i < N && (sum += T[i]) <= p; ++i) ++j;
            return j;
        };
        
        int cnt = 0;
        for(int j = 0; j < K && cnt < N; ++j)
            cnt += getCount.applyAsInt(cnt);
        return cnt >= N;
    } 
}


Measured memory_bytes: 72712
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
)

func main() {
	sc := NewScanner(os.Stdin)
	s, _ := sc.NextString()
	if s == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextString reads a string from io stream
func (sc *Scanner) NextString() (string, error) {
	if !sc.Scan() {
		return "", errors.New("failed to scan")
	}
	return sc.Text(), nil
}


Measured memory_bytes: 1772
#include <iostream>
#include <vector>
using namespace std;
#define ll long long 
int n;
vector<int> g[200005];
int d1[100005],d2[100005];
inline void dfs(int r,int f,int d,int dist[])
{
    dist[r]=d;
    for(int x=0;x<g[r].size();x++){
        if(g[r][x]!=f){
        	dfs(g[r][x],r,d+1,dist);
		}
    }
}
int main()
{
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1,0,d1);
    dfs(n-1,-1,0,d2);
    int ans=0;
    for(int i=0;i<n;i++){
        if(d1[i]<=d2[i]){
            ans++;
		}
        else{
        	ans--;
        }
    }
    if(ans>0){
    	cout <<"Fennec"<< endl;
	}
    else{
    	cout<<"Snuke"<<endl;
	}
    return 0;
}

Measured memory_bytes: 12288
#include<bits/stdc++.h> 
#define double long double
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=55;
int n,a[N],mx=-1e9,mn=1e9,p1,p2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	cout<<2*n-1<<endl;
	for(int i=1;i<=n;i++){
		if(a[i]>mx) mx=a[i],p1=i;
		if(a[i]<mn) mn=a[i],p2=i;
	}
	  
	if(abs(mx)>abs(mn)){
		for(int i=1;i<=n;i++)
		  cout<<p1<<' '<<i<<endl;
		for(int i=2;i<=n;i++)
		  cout<<i-1<<' '<<i<<endl;
	}
	else{
		for(int i=1;i<=n;i++)
		  cout<<p2<<' '<<i<<endl;
		for(int i=n;i>=2;i--)
		  cout<<i<<' '<<i-1<<endl;
	}
	return 0;
}


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

def main():
    x,y = map(int,input().split())
    ans = 2*10**9
    if x <= y:
        ans = min(ans, y-x)
    if -x <= y:
        ans = min(ans, 1+y+x)
    if x <= -y:
        ans = min(ans, 1-y-x)
    if -x <= -y:
        ans = min(ans, 1-y+x+1)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    string s;
    int a,z;
    cin >> s;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i = s.size();i >= 0;i--){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    cout << z-a+1 << endl;
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf

#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)

#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()

#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))

#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >

#define endl "\n";
#define line puts("-------");
#define dbb(x) cout<<#x<<" : "<<x<<"\n";

const int N = 100005;
const int MOD = 1000000007;

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;} void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x)
{cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const queue<T> &x)
{queue<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.front() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const stack<T> &x)
{stack<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.top() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const T &x)
{int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v)
{__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
    #define db(x...) cerr << "[" << #x << "] = [", _print(x)
#endif
using ll = long long;

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt","w",stdout);
    #endif
    int i,n,k;
    string a;
    cin>>k>>a;
    if(a.size()<=k)
        cout<<a;
    else
        cout<<a.substr(0,k)+"...";
}


Measured memory_bytes: 3592
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0
for i in range(1, n+1):
    m = n // i
    ans += m * (2 * i + (m - 1) * i)
print(ans // 2)

Measured memory_bytes: 67964
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n;
	cin>>n;
	ll q;
	q=ceil(n/(double)(1000));
	ll ans= q*1000 - n;
	cout<<ans<<endl;
	return 0;	
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    int c1 = 0, c2 = 0;
    rep(i, n) {
        if(s[i] == '(') cnt++;
        if(s[i] == ')') cnt--;

        if(cnt < 0) {
            c1++;
            cnt = 0;
        }
    }
    rep(i, c1) cout << '(';
    cout << s;
    rep(i, cnt) cout << ')';
    cout << endl;
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int d=A%B;
    string ans="NO";
    REP(i,B+1){
        if((i*d+B)%B==C){
            ans = "YES";
            break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int A, B;

  std::cin >> A >> B;

  if (A < 6)
    std::cout << 0 << std::endl;
  else if (A < 13)
    std::cout << B/2 << std::endl;
  else
    std::cout << B << std::endl;

  return 0;
}


Measured memory_bytes: 256