akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		boolean go = false;
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			if(go==true) System.out.println();
			go = true;
			
			int max = 0;
			int[] sum = new int[n];
			String[] name = new String[n];
			
			for(int i=0;i<n;i++){
				name[i] = sc.next();
				sum[i] = sc.nextInt()*3 + sc.nextInt()*0 + sc.nextInt()*1;
				max = Math.max(max, sum[i]);
			}
			
			for(int i=max;i>=0;i--){
				for(int j=0;j<n;j++){
					if(sum[j]==i) System.out.println(name[j] + "," + sum[j]);
				}
			}
		}
	}	
}

Measured memory_bytes: 20652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

int main(){
    int a, b; cin >> a >> b;
    --a; --b;
    vector<vector<char>> field(100, vector<char>(100));
    for(int i=0; i<50; ++i) for(int j=0; j<100; ++j) field[i][j] = '#';
    for(int i=50; i<100; ++i) for(int j=0; j<100; ++j) field[i][j] = '.';

    for(int i=0; i<50; i+=2){
        if(a == 0) break;
        for(int j=0; j<100; j+=2){
            if(a == 0) break;
            field[i][j] = '.';
            --a;
        }
    }

    for(int i=51; i<100; i+=2){
        if(b == 0) break;
        for(int j=0; j<100; j+=2){
            if(b == 0) break;
            field[i][j] = '#';
            --b;
        }
    }


    printf("100 100\n");
    for(int i=0; i<100; ++i){
        for(int j=0; j<100; ++j){
            cout << field[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll &mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}



int main(){
  int n;cin>>n;
  vector<pair<int,int>> x;
  rep(i,n){
    int xa;cin>>xa;
    x.pb(mp(xa,(i+1)));
  }
  sort(ALL(x));
  vector<pair<int,int>> res;
  int h=n/2;
  rep(i,h)res.pb(mp(x[i].second,x[h].first));
  rep(i,h)res.pb(mp(x[i+h].second,x[h-1].first));
  sort(ALL(res));
  for(auto t:res)cout<<t.second<<endl;
}


Measured memory_bytes: 5872
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
int main() {
	int N, K, h[100000] = {},count=0,ans=1000000001;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	sort(h, h + N);
	for (int i = 0; i < N-K+1; i++)
	{
		ans = min(ans, h[i + K-1] - h[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int s = sc.nextInt();
            if ((x | y | s) == 0) {
                break;
            }
            System.out.println(solve(x, y, s));
        }
    }

    public static int solve(int x, int y, int s) {
        int max = 0;
        for (int i = 1; i < s; i++) {
            for (int j = 1; j < s; j++) {
                int t1 = ((x + 100) * i) / 100;
                int t2 = ((x + 100) * j) / 100;
                int pre = t1 + t2;
                if (pre != s) {
                    continue;
                }
                t1 = ((y + 100) * i) / 100;
                t2 = ((y + 100) * j) / 100;
                max = Math.max(max, t1 + t2);
            }
        }
        return max;
    }
}

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

const long long MOD=1e9+7;

int main(){
  int N;cin>>N;
  string s,s2;
  cin>>s>>s2;
  long long ans;
  int n;
  int sw=1;
  if(s[0]!=s[1]){
    ans=3;
    n=1;
  }else{
    ans=6;
    n=2;
    sw*=-1;
  }
  while(n<N){
    if(sw==1){
      if(n==N-1||s[n]!=s[n+1]){
        ans*=2;
        ans%=MOD;
        n++;
      }else if(s[n]==s[n+1]){
        ans*=2;
        ans%=MOD;
        n+=2;
        sw*=-1;
      }
    }else if(sw==-1){
      if(n==N-1||s[n]!=s[n+1]){
        ans*=1;
        ans%=MOD;
        n++;
        sw*=-1;
      }else if(s[n]==s[n+1]){
        ans*=3;
        ans%=MOD;
        n+=2;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
edge=[[] for _ in range(n)] #木
cnt=[0]*n #出力用
for i in range(n-1): #辺の本数は頂点数-1
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
for _ in range(q):
  p,x=map(int,input().split())
  p-=1
  cnt[p]+=x
done=[False]*n #到達
par=0 #0からスタート
done[par]=True
stack=[par]
while stack:
  par=stack.pop()
  for chi in edge[par]:
    if done[chi]:
      None
    else:
      done[chi]=True
      cnt[chi]+=cnt[par]
      stack.append(chi)
    
print(*cnt)


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

int main (void){
    string N;
    cin >> N;
    bool ans = false;
    for (char s : N) if (s == '7') ans = true;
    cout << (ans ? "Yes": "No");
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
long long a[111111];
int main()
{
	int n,q;
	long long sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long long tmp;
		cin>>tmp;
		a[tmp]++;
		sum+=tmp;
	}

	cin>>q;
	for(int i=0;i<q;i++)
	{
		int c,d;
		cin>>c>>d;
		sum+=(d-c)*a[c];
		a[d]+=a[c];
		a[c]=0;
		cout<<sum<<endl;	
	}
		
	return 0; 
 } 

Measured memory_bytes: 4400
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    println(prime(100004).first { it >= n })
}

fun prime(max: Int):List<Int> {
    var numbersForDivide =  (2..max).toList()
    var prime = mutableListOf<Int>()
    for(i in 2 .. max){
        if(numbersForDivide.isNotEmpty() && numbersForDivide[0] == i){
            prime.add(i)
            numbersForDivide = numbersForDivide.filter { it % i != 0 && it != i}
        }
    }
    return prime
}


Measured memory_bytes: 55088
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
using  namespace std;
typedef long long ll;
#define sc(x) scanf("%d",&x)
#define pd(x) printf("%d\n",x)
const int INF=1e9+10;
const int MOD=1e9+7;
const double eps=1e-5;
const double pi=acos(-1.0);
const int N=2e5+5;
int a[N];
int main()
{
    int n,p;
    while(~scanf("%d%d",&n,&p))
    {
        int x,ji=0,ou=0;
      for(int i=0;i<n;i++)
      {
          scanf("%d",&x);
          if(x&1) ji++;
          else ou++;
      }
      if(p)
      {
          if(ji==0) puts("0");
          else printf("%lld\n",ll(1)<<(n-1));
      }
      else
      {
          if(ji==0) printf("%lld\n",ll(1)<<n);
          else if(ji==1) printf("%lld\n",ll(1)<<(n-1));
          else printf("%lld\n",(ll(1)<<n)-(ll(1)<<(n-1)));
      }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll x = a, y = b, z = c;
	rep(t,100000){
		if(x%2==1 || y%2==1 || z%2==1){
			cout<<t<<endl;
			return 0;
		}
		ll nx = (y+z)/2, ny = (x+z)/2, nz = (x+y)/2;
		x = nx, y = ny, z = nz;
		if(x==a && y==b && z==c){
			puts("-1");
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N, D;
  cin >> N >> D;
  if(N % (2 * D + 1) == 0) {
    cout << N / (2 * D + 1) << endl;
  }
  else {
    cout << N / (2 * D + 1) + 1 << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

const ll inf=1LL<<59;

int n;
vector<pair<int, ll>> G[100005];
vector<ll> d(100005, inf);

void dfs(int from, int now, ll dist){
    d[now]=dist;
    
    for(auto p:G[now]){
        int to=p.first;
        ll w=p.second;
        if(to==from) continue;
        dfs(now, to, dist+w);
        
    }
}

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

    cin >> n;
    rep(i, n-1){
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        G[a].push_back(make_pair(b, c));
        G[b].push_back(make_pair(a, c));
    }

    int q, k; cin >> q >> k;
    --k;

    dfs(-1, k, 0);
    while(q--){
        int x,y; cin >> x >> y;
        --x; --y;
        cout << d[x]+d[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 14336
# -*- coding: utf-8 -*-
# D - Katana Thrower
# モジュールのインポート
import math

# 標準入力の取得
N,H = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = list(map(int, input().split()))
    a.append(a_n)
    b.append(b_n)

# 求解処理
# 最後の攻撃⇒・・・⇒最初の攻撃の順に遡って考える
# 大きい順にbで攻撃を行う。
# その際、max(a)よりも小さければ、当該bではなく、max(a)で残りのHPをすべて削る
max_a = max(a)
sorted_b = reversed(sorted(b))
min_count = 0
for b_n in sorted_b:
    if (b_n < max_a) or (H <= 0):
        break
    H -= b_n
    min_count += 1

if H > 0:
    min_count += math.ceil(H / max_a)

# 結果出力
print(min_count)

Measured memory_bytes: 12100
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int W,H;
char s[64][32];
int dy[]={2,1,1,0,0,0,-1,-1,-2};
int dx[]={1,1,2,1,2,3,1,2,1};

struct P{
  int y,x,cost,prev;
  P(int y, int x, int cost, int prev):y(y),x(x),cost(cost),prev(prev){}
  bool operator>(const P& a)const{ return cost > a.cost; }
};

void dijkstra(){
  int res = INF;
  rep(i,2){
    //    cout << i << endl;
    int foot = i?1:-1;
    int table[64][32][2];
    rep(l,64) rep(j,32) rep(k,2) table[l][j][k] = INF;

    priority_queue<P, vector<P>, greater<P> >q;
    rep(x,W) if(s[H-1][x]=='S'){
      q.push(P(H-1,x,0,foot));
      table[H-1][x][foot] = 0;
    }
    //    cout << q.size() << endl;
    while(!q.empty()){
      P p = q.top(); q.pop();
      int y = p.y, x = p.x, f = p.prev;
      //      cout << y << " " << x << " " << f << endl;
      if(table[y][x][(f+2)%3] < p.cost) continue;
      f*= -1;
      rep(d,9){
	int ny = y+dy[d], nx = x+f*dx[d];
	if(ny<0||ny>=H||nx<0||nx>=W||s[ny][nx]=='X') continue;
	if(s[ny][nx]=='T'){
	  res = min(res, p.cost);
	  break;
	}
	if(table[ny][nx][(2+f)%3] > p.cost + s[ny][nx]-'0'){
	  table[ny][nx][(2+f)%3] = p.cost+s[ny][nx]-'0';
	  q.push(P(ny, nx, table[ny][nx][(2+f)%3], f));
	}
      }
    }
  }
  cout << (res==INF?-1:res) << endl;
  return;
}

int main(){
  while(cin >> W >> H, W||H){
    //    cout << W << " " << H <<endl;
    rep(i,H) rep(j, W) cin >> s[i][j];
    dijkstra();
  }
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll g(ll n) {return n*(n+1)/2;}

int main()
{   
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += i * g(n/i);
    }
    cout << ans << endl;


    return 0;
}


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

using namespace std;

int main()
{
    char s1[3], s2[3]; 
    for(int i =0; i<3; i++)
    cin>>s1[i];
    for(int i =2; i>=0; i--)
    cin>>s2[i];
    int flag =0;
    for(int i =0; i<3; i++)
    {
        if(s1[i] != s2[i])
        {
            cout<<"NO"<<endl;
            flag =1;
            break;
        }
    }
    if(flag == 0)
    {
        cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 256
import numpy as np
i4 = np.int32
i8 = np.int64


def solve(a, b, H, W):
    ret = np.empty(H, i8)
    for i in range(H):
        ret[i] = -1
    dp0 = np.arange(W)
    dp = np.arange(W)
    arg0 = W - 1
    arg = 0
    for i in range(H):
        r1 = np.searchsorted(dp, a[i])
        r2 = np.searchsorted(dp, b[i])
        if b[i] == W:
            if r1 == 0:
                return ret
            else:
                dp0 = dp0[: r1]
                dp = dp[: r1]
        else:
            dp[r1:r2] = b[i]

        if arg0 > -1:
            if r1 <= arg0 < r2:
                for j in range(r1 - 1, -1, -1):
                    if dp[j] == dp0[j]:
                        arg0 = j
                        ret[i] = i + 1
                        break
                else:
                    arg0 = -1
                    arg = np.argmin(dp - dp0)
                    ret[i] = dp[arg] - dp0[arg] + i + 1
            else:
                ret[i] = i + 1
        else:
            if r1 <= arg < r2:
                arg = np.argmin(dp - dp0)
            ret[i] = dp[arg] - dp0[arg] + i + 1

        if i % 1000 == 999:
            m = 0
            prev = dp[0]
            for k in range(1, dp.shape[0]):
                if dp[k] > prev:
                    dp0[m] = dp0[k - 1]
                    dp[m] = prev
                    m += 1
                    prev = dp[k]
            else:
                dp0[m] = dp0[dp0.shape[0] - 1]
                dp[m] = prev
                m += 1
            dp0 = dp0[: m]
            dp = dp[: m]
            if arg0 > -1:
                for j in range(m - 1, -1, -1):
                    if dp[j] == dp0[j]:
                        arg0 = j
                        break
            else:
                arg = np.argmin(dp - dp0)
    return ret


def main(in_file):
    stdin = open(in_file)
    H, W = [int(x) for x in stdin.readline().split()]
    ab = np.fromstring(stdin.read(), i8, sep=' ').reshape((-1, 2)).T.copy()
    ans = solve(ab[0] - 1, ab[1], H, W)
    p = '\n'.join([str(x) for x in ans.tolist()])
    print(p)


def cc_export():
    from numba.pycc import CC
    from numba.types import Array, int64
    cc = CC('my_module')
    cc.export('solve', (Array(int64, 1, 'C'), Array(int64, 1, 'C'), int64, int64))(solve)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main('/dev/stdin')

Measured memory_bytes: 55176
import java.util.Scanner;
public class Main{
 public static void main(String args[]){
  boolean flag=false;
  Scanner scan=new Scanner(System.in);
  String s;

  s=scan.next();
  int n=Integer.parseInt(s);

  int l[]=new int[n+10];
  int r[]=new int[n+10];
  int mx=0; 

  for(int i=0;i<n;i++){
   s=scan.next();
   l[i]=Integer.parseInt(s);
   s=scan.next();
   r[i]=Integer.parseInt(s);
   if(mx<r[i])mx=r[i];
  }

  boolean f1,f2;
  long a[]=new long[mx+10];
  for(int i=0;i<mx+1;i++){
   f1=prime(i);
   f2=prime((i+1)/2);
   if(i>0)a[i]=a[i-1];
   if(f1&&f2&&i%2==1)a[i]++;
  }

  for(int i=0;i<n;i++)System.out.println(a[r[i]]-a[l[i]-1]);
 }
 public static boolean prime(long a){
  if(a<=1)return false;
  for(int i=2;i*i<=a;i++){
   if(a%i==0)return false;
  }
  return true;
 }
}



Measured memory_bytes: 60452
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 60;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int cnt = 0;
    vector<ll> coin;
    coin.pb(1);
    while (pow(6, cnt) <= N)
    {
        coin.pb(pow(6, cnt));
        cnt++;
    }
    cnt = 0;
    while (pow(9, cnt) <= N)
    {
        coin.pb(pow(9, cnt));
        cnt++;
    }
    ll C = coin.size();
    vector<vector<ll>> dp(C + 1, vector<ll>(N + 1, INF));
    dp[0][0] = 0;
    rep(i, C)
    {
        rep(j, N + 1)
        {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
            if(j + coin[i]>N)continue;
            dp[i + 1][j + coin[i]] = min(dp[i][j + coin[i]], dp[i + 1][j] + 1);
        }
    }
    cout << dp[C][N] << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 12800
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=107;
int a[N],b[N],n,i,ans;
int main(){
	for(scanf("%d",&n),i=1;i<=n;++i)scanf("%d",a+i);for(i=1;i<=n;++i)scanf("%d",b+i);
	for(i=1;i<=n;++i)a[i]+=a[i-1];for(i=n;i>=1;--i)b[i]+=b[i+1];
	for(i=1;i<=n;++i)ans=max(ans,a[i]+b[i]);
	printf("%d\n",ans);
} 

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    while(1){
        int N, M; cin>>N>>M;
        if(N == 0) return 0;

        vector<vector<bool>> use(M+10, vector<bool>(1300, false));
        vector<int> cnt(M+10, 0);
        vector<int> startTime(M+10, -1);
        int r; cin>>r;
        while(r--){
            int t, n, m, s; cin>>t>>n>>m>>s;
            if(s == 1){
                cnt[m]++;
                if(cnt[m] == 1){
                    startTime[m] = t;
                }
            }
            else{
                cnt[m]--;
            }

            if(cnt[m] == 0){
                int endTime = t;
                for(int i=startTime[m]; i<endTime; i++){
                    use[m][i] = true;
                }
            }
        }

        int q; cin>>q;
        while(q--){
            int s, t, m; cin>>s>>t>>m;
            int ans=0;
            for(int i=s; i<t; i++){
                if(use[m][i]) ans++;
            }

            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    //cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
static ll x;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
        x ++;
    }
}

ll fr(ll n){
    ll ans = 1;
    REP(i, n){
        ans *= i+1;
        ans %= MOD;
    }
    return ans;
}

ll conb(ll n, ll k){
    return fr(n)% MOD * modinv(fr(k) * fr(n-k) % MOD, MOD) % MOD;
}

int main() {
    ll k;
    cin >> k;
    ll itr = 1;
    ll e = 7 % k;
    vector<ll> R(k, 0);
    R[e] = 1;
    ll ans = 0;
    while(true){
        if(e == 0){
            ans = itr;
            break;
        }
        itr += 1;
        e = (10 * e + 7) % k;
        if(R[e] == 1){
            ans = -1;
            break;
        }else{ 
            R[e] = 1;
        }
    }
    cout << ans << endl;
}



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

using namespace std;

const int nmax = 3000 + 10;

int n;
int a[nmax];

vector < int > g[nmax];

bool win(int node) {
    for (auto &it : g[node])
        if (!win(it)) return true;
    return false;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i < n; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);

        if (a[x] > a[y]) g[x].push_back(y);
        if (a[y] > a[x]) g[y].push_back(x);
    }

    for (int i = 1; i <= n; ++i)
        if (win(i)) printf("%d ", i);

    return 0;
}


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

struct Info
{
    std::string name;
    int pt;
    int num;

    Info(std::string inputted_name, int inputted_age, int i_num)
    {
        name = inputted_name;
        pt = inputted_age;
        num = i_num;
    }
};

bool cmp_p(const Info &a, const Info &b)
{
    return a.pt > b.pt;
}

bool cmp_name(const Info &a, const Info &b)
{
    return a.name < b.name;
}

int main(int argc, char const *argv[])
{
    int n;cin>>n;
    vector<Info> info;
    for(int i=1;i<=n;++i){
        string s;cin>>s;
        int pt;cin>>pt;
        info.push_back((Info(s,pt,i)));
    }

    sort(info.begin(), info.end(), cmp_name);
    int begin =0;
    int end =0;
    string tmp=info[0].name;
    for(int i=0;i<n;++i){
        if(info[i].name != tmp){
            end = i;
            sort(info.begin()+begin, info.begin()+end, cmp_p);
            begin = end;
            tmp = info[i].name;
        }
        if(i==n-1){
            sort(info.begin()+end, info.end(),cmp_p);
        }
    }

    for(int i=0;i<n;++i){
        cout  <<info[i].num << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a,int b){
	return a>b;
}

int main(){
	int n,h,i,move=0,mx=-1,s=0;
	cin>>n>>h;
	int a[n],b[n];
	for(i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if (mx<a[i]) mx=a[i];
	}
	sort(b,b+n,cmp);
	for(i=0;i<n;i++){
		if (h<=0){
			cout<<i;
			return 0;
		}
		if(mx>=b[i]) break;
		h-=b[i];
	}
	if(h>0) move=(h-1)/mx+1;
	cout<<move+i;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    REP(i, n + 1) {
        if (i * 108 >= n * 100 && i * 108 < (n + 1) * 100) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if any(a>b for a,b in zip(A,B)):
    print(-1)
    exit()

def pb(i):
    return i-1 if i-1 >= 0 else N-1
def nx(i):
    return i+1 if i+1 < N else 0

hq = []
for i,(a,b) in enumerate(zip(A,B)):
    if a <= b - B[pb(i)] - B[nx(i)]:
        hq.append((-b,i))
heapq.heapify(hq)

ans = 0
while hq:
    _,i = heapq.heappop(hq)
    if B[i] == A[i]: continue
    l = B[pb(i)]
    r = B[nx(i)]
    if B[i]-l-r < A[i]: continue
    k = (B[i]-A[i]) // (l+r)
    ans += k
    B[i] -= k*(l+r)
    ll = B[pb(pb(i))]
    rr = B[nx(nx(i))]
    if A[nx(i)] <= r - B[i] - rr:
        heapq.heappush(hq, (-r,nx(i)))
    if A[pb(i)] <= l - B[i] - ll:
        heapq.heappush(hq, (-l,pb(i)))

if all(a==b for a,b in zip(A,B)):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 128276
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    std::string s;
    std::cin >> s;
    for (int i = 0; i < s.size(); ++i)
    {
        if (i % 2 == 0) { std::cout << s[i]; }
    }

    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 512
ipt = input().split()

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
i=int(ipt[0])
j=int(ipt[1])
if i==j:
    print('Yes')
elif i in a and j in a:
    print('Yes')
elif i in b and j in b:
    print('Yes')
else:
    print('No')
                

    

Measured memory_bytes: 3060
n=int(input())
A=[int(x) for x in input().split()]
q=int(input())
m=[int(x) for x in input().split()]

A_sum = []
for bit in range(1,2**n):
    a_sum = 0
    for i in range(n):
        if bin((bit>>i) & 0b1) == '0b1':
            a_sum += A[i]
    A_sum.append(a_sum)
            
for mi in m:
    if mi in A_sum:
        print('yes')
    else:
        print('no')


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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    string s;
    vector<string> a(h);

    for (int i = 0; i < h; ++i) {
        cin >> a.at(i);
    }

    for (int j = 0; j < w + 2; ++j) {
        cout << "#";
    }
    cout << endl;

    for (string x:a) {
        cout << "#" << x << "#" << endl;
    }

    for (int j = 0; j < w + 2; ++j) {
        cout << "#";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3640
# Ref: https://betrue12.hateblo.jp/entry/2020/07/12/060026
import sys
sys.setrecursionlimit(10**6)


def ext_euc(a, b):
    if b == 0:
        return 1, 0, a
    y, x, v = ext_euc(b, a % b)
    y -= (a // b) * x
    return x, y, v


def mod_inv(a, mod):
    x, _, _ = ext_euc(a, mod)
    return x % mod


def generate_points(is_odd, mod):
    # Lagrange補完するためのデータ点を計算
    n_points = 16
    points = [None] * n_points
    if is_odd:
        comb_1 = [0] * n_points  # (n+4)_C_4
        comb_2 = [0] * n_points  # (2n+10)_C_10
        comb_1[0] = 1
        comb_2[0] = 1
        for n in range(1, n_points):
            comb_1[n] = comb_1[n - 1] * (n + 4) * mod_inv(n, mod) % mod
            v = comb_2[n - 1] * (2 * n + 10) * (2 * n + 9) % mod
            v *= mod_inv(2 * n, mod) * mod_inv(2 * n - 1, mod) % mod
            comb_2[n] = v % mod
        for n in range(n_points):
            N = 2 * n + 5
            val = 0
            for k in range(n + 1):
                val += comb_1[k] * comb_2[n - k]
                val %= mod
            points[n] = (N, val)
    else:
        comb_1 = [0] * n_points  # (k+4)_C_4
        comb_2 = [0] * n_points  # (2n+11)_C_10
        comb_1[0] = 1
        comb_2[0] = 11  # 11_C_10
        for n in range(1, n_points):
            comb_1[n] = comb_1[n - 1] * (n + 4) * mod_inv(n, mod) % mod
            v = comb_2[n - 1] * (2 * n + 11) * (2 * n + 10) % mod
            v *= mod_inv(2 * n + 1, mod) * mod_inv(2 * n, mod) % mod
            comb_2[n] = v % mod
        for n in range(n_points):
            N = 2 * n + 6
            val = 0
            for k in range(n + 1):
                val += comb_1[k] * comb_2[n - k]
                val %= mod
            points[n] = (N, val)
    return points


def lagrange_interpolation(points, k, mod):
    n_points = len(points)
    # points を通る n_points - 1 次の多項式 の k での値を求める
    # ref: https://mathtrain.jp/hokan
    ret = 0
    for n in range(n_points):
        x, y = points[n]
        y_coef = 1
        for i in range(n_points):
            if i == n:
                continue
            xi, _ = points[i]
            y_coef *= k - xi
            y_coef *= mod_inv(x - xi, mod)
        ret += y * y_coef
        ret %= mod
    return ret


def main():
    MOD = 10**9 + 7
    T = int(input())
    test_cases = [int(input()) for _ in range(T)]
    odd_points = generate_points(True, MOD)
    even_points = generate_points(False, MOD)
    for N in test_cases:
        if N < 5:
            print(0)
        elif N % 2 == 0:
            print(lagrange_interpolation(even_points, N, MOD))
        else:
            print(lagrange_interpolation(odd_points, N, MOD))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
import java.util.*;
public class Main {
		
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int war[][] = new int[M][2];
		for(int i=0;i<M;i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			if(a > b) {
				int tmp = a;
				a = b;
				b = tmp;
			}
			war[i][0]=a;
			war[i][1]=b;
		}
		sc.close();
		
		//bで昇順にソート
		Arrays.sort(war, (w1,w2) -> w1[1] - w2[1] );
		int head = 0; 
		int cnt = 0;
		for(int i=0;i<M;i++) {
			int a = war[i][0];
			int b = war[i][1];
			if(a >= head) {
				cnt ++;
				head = b;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 90868
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 998244353,maxn = 3030;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;

    int cnt = 0;

    for (int i=0; i<(int)s.size(); i++){
        if (s[i] != t[i]) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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

int main() {
    int n, y;
    cin >> n >> y;
    int cnt10000 = -1;
    int cnt5000 = -1;
    int cnt1000 = -1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            for (int k = 0; k <= n -i -j; k++) {
                if ((y == 10000*i + 5000*j + 1000*k) && n == i + j + k) {
                    cnt10000 = i;
                    cnt5000 = j;
                    cnt1000 = k;
                    break;
                }
            }
        }
    }

    cout << cnt10000 << " " << cnt5000 << " " << cnt1000 <<  endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int a,b,length,area;
        //?¨??????\??????????????????????????§????????????
    	Scanner scanner = new Scanner(System.in);
    	//??\????????????int??????????????????
    	a = scanner.nextInt();
    	b = scanner.nextInt();
    	//??¨?????????????????¢???????¨????
    	length = 2*(a+b);
    	area   = a*b;
        System.out.println(area + " " + length);
    }
}

Measured memory_bytes: 25896
#include <bits/stdc++.h>
#define int long long
#define fr first
#define sc second
using namespace std;
const int inf = 2e18 + 7;
const int mod = 1e9 + 7;
const int maxn = 3007;
signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int x, k, d;
  cin >> x >> k >> d;
  if (x == 0) {
    if (k & 1 ^ 1) cout << 0;
    else cout << d;
  }
  else if (x > 0) {
    int q = min(k, x / d);
    x -= q * d;
    k -= q;
    if (x < 0 && abs(x) > abs(x + d)) {
      k++;
      x += d;
    }
    if (k & 1 ^ 1) cout << abs(x);
    else cout << min(abs(x - d), abs(x + d));
  }
  else {
    assert(x < 0);
    int q = min(k, -x / d);
    x += q * d;
    k -= q;
    if (x > 0 && abs(x) > abs(x - d)) {
      k++;
      x -= d;
    }

    if (k & 1 ^ 1) cout << abs(x);
    else cout << min(abs(x - d), abs(x + d));
  }
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void){
  int num,n,i,j,a[100],flag,count=0;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<num;i++){
	for(j=num-1;j>i-1;j--){
	  if(a[j]<a[j-1]){
	  n=a[j];
	  a[j]=a[j-1];
	  a[j-1]=n;
	  count+=1;
	  }
	  
	}     
  }
  for ( i=0; i<num; i++){
    if(i!=num-1) printf("%d ",a[i]);
    else printf("%d",a[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;
ll d[200][200];
int main(){
    int n;
    while(cin>>n && n){
        set<int> app;
        rep(i,200)rep(j,200)d[i][j]=1LL<<60;
        rep(i,200)d[i][i]=0;
        rep(i,n){
            ll a,b,c;
            cin>>a>>b>>c;
            d[a][b]=d[b][a]=c;
            app.insert(a);
            app.insert(b);
        }
        rep(k,200)rep(i,200)rep(j,200)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        int ans=0;
        ll ans_sum=1LL<<60;
        for(int i:app){
            ll sum=0;
            for(int j:app){
                sum+=d[i][j];
            }
            if(ans_sum > sum){
                ans_sum = sum;
                ans = i;
            }
        }

        cout << ans << " " << ans_sum << endl;
    }
}

Measured memory_bytes: 1520
#include<stdio.h>
#include<stdlib.h>
int main(){
  int *a,n,i,j,sum=0,b,mini;
  scanf("%d",&n);
  a=malloc(4*n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(a[mini]>a[j]){
	
	mini=j;
      }
    }
    if(i!=mini){
      sum++;
      b=a[mini];
      a[mini]=a[i];
      a[i]=b;
    }
  }
  for(i=0;i<n;i++){
    if(i==n-1)printf("%d\n",a[i]);
    else printf("%d ",a[i]);
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2104
import sys

def sub(field, x, y):
  if y < 0 or x < 0 or y >= len(field) or x >= len(field[y]):
    return True
  if field[y][x] == '#':
    return True
  return False

def isok(field, x, y):
  units = [(0, 1), (1, 0), (0, -1), (-1, 0)]
  for unit in units:
    _x = x + unit[0]
    _y = y + unit[1]
    if sub(field, _x, _y):
      return True
  return False


l = sys.stdin.readline()
xy = [int(x) for x in l.rstrip('\n').split(' ')]
height = xy[0]
width = xy[1]

field = []
for _ in xrange(height):
  field.append(sys.stdin.readline().rstrip('\n'))

for y in xrange(len(field)):
  for x in xrange(len(field[y])):
    if field[y][x] == '#' and not isok(field, x, y):
      print 'No'
      exit()
print 'Yes'

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

short dp[4002][4002];

int main(){
  string a, b;

  while(cin >> a >> b){
    int n = a.length();
    int m = b.length();

    memset(dp, 0, sizeof(dp));
    short res = 0;

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= m; j++){
        if(a[i - 1] == b[j - 1]){
          dp[i][j] = dp[i - 1][j - 1] + 1;
          res = max(res, dp[i][j]);
        }
      }
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 31000
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC50(void);
void ABC51(void);
void ABC52(void);
void ABC53(void);
void ABC54(void);
void ABC55(void);
void ABC56(void);
void ABC57(void);
void ABC58(void);
void ABC59(void);

int main(void){
    ABC51();
}

void ABC51(){
    int n,x=0,i,max;
    string s;
    cin>>n>>s;
    max=x;
    for(i=0;i<n;i++){
        if(s[i]=='I')x++;
        if(s[i]=='D')x--;
        if(x>max)max=x;
    }
    cout<<max<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <malloc.h>
int main()
{
	/*
	int n;
	scanf_s("%d", &n);
	//int count = 0;
	int* x = (int*)malloc(sizeof(int)*n);
	for (int m = 0; m < n; m++) {
		scanf_s("%d", x + m);
	}
	for (int k = 1; k <= n; k++) {
		int h = 0;
		while (1) {
			if (k == *(x + h)) {
				printf("%d ", h + 1);
				break;
			}
				h++;
		}
	}
	free(x);
	*/
	int x = 0,y=0;
	scanf("%d %d", &x, &y);
	x = x - 2 * y;
	if (x < 0) {
		x = 0;
	}
	printf("%d", x);

}

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

int n,x[200000],y[200000],ans=1e9,nx,ny;
char u[200000],nu;
vector<pair<int,char>> line[200001],diag[400001];

void Hor(){
  for(int i=0;i<200001;i++) line[i].clear();
  for(int i=0;i<n;i++) line[x[i]].push_back({y[i],u[i]});
  for(int i=0;i<200001;i++){
    sort(line[i].begin(),line[i].end());
    for(int j=1;j<line[i].size();j++){
      if(line[i][j-1].second=='U' && line[i][j].second=='D'){
        ans=min(5*(line[i][j].first-line[i][j-1].first),ans);
      }
    }
  }
}

void Ver(){
  for(int i=0;i<400001;i++) diag[i].clear();
  for(int i=0;i<n;i++) diag[x[i]+y[i]].push_back({y[i],u[i]});
  for(int i=0;i<400001;i++){
    sort(diag[i].begin(),diag[i].end());
    for(int j=1;j<diag[i].size();j++){
      if(diag[i][j-1].second=='U' && diag[i][j].second=='R'){
        ans=min(10*(diag[i][j].first-diag[i][j-1].first),ans);
      }
    }
  }
}

void Rot(){
  for(int i=0;i<n;i++){
    nx=200000-y[i];ny=x[i];
    if(u[i]=='R')nu='U';
    if(u[i]=='U')nu='L';
    if(u[i]=='L')nu='D';
    if(u[i]=='D')nu='R';
    x[i]=nx;y[i]=ny;u[i]=nu;
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>u[i];
  for(int i=0;i<4;i++){
    if(i<2)Hor();
    Ver();
    if(i<3)Rot();
  }
  if(ans<1e9)cout<<ans<<endl;
  else cout<<"SAFE"<<endl;
}


Measured memory_bytes: 39260
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
#define all(a) (a).begin(),(a).end()
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl

#ifdef CHEN_PC
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

const int N = 100010;
const int mod = 1000000007; // 10^9+7
int n;

int mark[N];

int solve() {
    clr(mark, 0);
    int v = 2;
    int s = 0;
    while (s < N) {
        s += v - 1;
        mark[s] = v;
        v++;
    }
//    forn (i, N) {
//        if (mark[i]) {
//            debug("%d %d\n", i, mark[i]);
//        }
//    }
    if (mark[n] == 0) {
        puts("No");
        return 0;
    }
    puts("Yes");
    int k = mark[n];
    vector<vi> ret(k, vi());
    int val = 1;
    forab (i, 1, k) {
        forn (j, i) {
            ret[j].push_back(val);
            ret[i].push_back(val);
            val++;
        }
    }

    printf("%d\n", k);
    for (auto arr : ret) {
        printf("%d", SZ(arr));
        for (auto u : arr) {
            printf(" %d", u);
        }
        puts("");
    }

    return 0;
}

int main(int argc, char *argv[]) {
#ifdef CHEN_PC
    freopen("D.in", "r", stdin);
#endif

    while (scanf("%d", &n) != EOF) {
        int ret = solve();
//        printf("%d\n", ret);
//        break;
    }
    return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
typedef long long ll;
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 1e15
const int N=5e5+5;

string arr;

ll interval[4*N];

ll build(ll s,ll e,ll p=1)
{
	if(s==e)
	{
		return interval[p]=(1LL<<((int)(arr[s]-'a')));
	}
	return interval[p]=build(s,(s+e)/2,2*p)|build((s+e)/2+1,e,2*p+1);
}

ll idx;
ll update(ll s,ll e,ll p=1)
{
	if(s==e)
	{
			return interval[p]=(1LL<<(arr[s]-'a'));
	}
	ll mid=(s+e)/2;
	if(idx<=mid)
		return interval[p]=update(s,mid,2*p)|interval[2*p+1];
	
	return interval[p]=interval[2*p]|update(mid+1,e,2*p+1);
}
ll from,to;
ll query(ll s,ll e,ll p=1)
{
	if(from<=s && to>=e)
		return interval[p];
	ll mid=(s+e)/2;
	if(to<s || from>e)
		return 0;
	if(to<=mid)
		return query(s,mid,2*p);
	if(from>mid)
		return query(mid+1,e,2*p+1);
	return query(s,mid,2*p)|query(mid+1,e,2*p+1);
}

int main()
{
	ll n;
	cin>>n;
	cin>>arr;
	build(0,n-1);

	ll q;
	cin>>q;
	while(q)
	{
		q--;
		ll ch;
		cin>>ch;
		if(ch==1)
		{
			ll i;
			char val;
			cin>>i>>val;
			i--;
			arr[i]=val;
			idx=i;
			update(0,n-1);
		}
		else
		{
			cin>>from>>to;
			from--;to--;
			cout<<__builtin_popcount(query(0,n-1))<<endl;
			
		}
	}
}
		


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

int main()
{
  int inf=1000000000;
  int n,k,s;cin>>n>>k>>s;
  vector<int> ans(n,inf);
  int i;
  if(s==inf)inf--;
  for(i=0;i<n;i++)
  {
    if(i<k)ans.at(i)=s;
    else ans.at(i)=inf;
  }
  for(i=0;i<n;i++)
  {
    if(i==0)cout<<ans.at(i);
    else cout<<' '<<ans.at(i);
  }
  cout<<endl;
}


Measured memory_bytes: 1664
def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

import heapq

n,x,mod = map(int,input().split())
c = [x]
heapq.heapify(c)
cc = [x]
num = x
count = 1
while True:
    num = pow(num, 2, mod)
    if binary_search(c, num) != -1:
        b = cc.index(num)
        l = count - b
        cycle = cc[b:]
        startl = b
        start = cc[:b]
        break
    count += 1
    heapq.heappush(c, num)
    cc.append(num)

# print(cc)
# print(cycle,l)
# print(start,startl)
ans = 0
if n <= startl:
    for i in range(n):
        ans += start[i]
    print(ans)
else:
    ans += sum(start)
    n -= startl
    # print(n)
    syo = n // l
    amari = n % l
    s = [0]*(l+1)
    for i in range(1,l+1):
        s[i] = s[i-1] + cycle[i-1]
    ans += s[l]*syo + s[amari]
    print(ans)

Measured memory_bytes: 77624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int n;
  cin >>n>> s;
  int ans =0;
  for(int i=0;i<n;i++){
    vector<int> S(30,0);
    int counter = 0;
    for(int j = 0;j<i;j++){
      S.at(s.at(j) - 'a') = 1;
    }
    for(int j = i;j<n;j++){
      if(S.at(s.at(j)-'a')==1){
        S.at(s.at(j) -'a') = 2;
      }
    }
    for(int j =0;j<30;j++){
      if(S.at(j) >=2){
        counter++;
      }
    }
    ans = max(ans,counter);
  }
  cout << ans;
}

Measured memory_bytes: 256
S = list(input())
ans = ['k','e','y','e','n','c','e']
for i in range(len(S)):
    for j in range(i,len(S)):
        new_str = S[:i] + S[j:]
        if new_str == ans:
            print("YES")
            break
    else:
        continue
    break
else:
    print("NO")

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def main():
    h, w = readIntN()
    a = []
    for _ in range(h):
        s = input()
        if list(set(s)) != ['.']:
            a.append(s)
    r = []
    for i in range(w):
        ll = [s[i] for s in a]
        if len(set(ll)) == 1 and '.' in ll:
            continue
        r.append(ll)

    for j in range(len(r[0])):
        u = [r[i][j] for i in range(len(r))]
        print(''.join(u))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5196