akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    if(n < 3){
        cout << -1 << endl;
        return 0;
    }
    if(n == 3){
        cout << "aab" << endl;
        cout << "b.b" << endl;
        cout << "baa" << endl;
        return 0;
    }
    vector<vector<char>> ans(n, vector<char>(n, '.'));
    if(n % 4 == 1){
        char d5[5][5] = 
        {
            'a', 'a', 'b', 'b', 'a',
            'b', 'c', 'c', '.', 'a',
            'b', 'a', 'a', 'b', 'b',
            'a', '.', '.', 'a', 'c',
            'a', '.', '.', 'a', 'c',
        };
        REP(i,5){
            REP(j,5){
                ans[i][j] = d5[i][j];
            }
        }
    }else if(n % 4 == 2){
        char d6[6][6] = 
        {
            'a', 'a', 'b', 'b', 'a', 'a',
            'b', 'c', 'a', '.', '.', '.',
            'b', 'c', 'a', '.', '.', '.',
            '.', '.', '.', 'a', 'b', 'a',
            '.', '.', '.', 'a', 'b', 'a',
            'a', 'a', 'b', 'b', 'c', 'c',
        };
        REP(i,6){
            REP(j,6){
                ans[i][j] = d6[i][j];
            }
        }
    }else if(n % 4 == 3){
        char d7[7][7] = 
        {
            'a', 'a', 'b', 'b', 'a', 'a', '.',
            'b', 'c', '.', '.', '.', '.', 'a',
            'b', 'c', '.', '.', '.', '.', 'a',
            'a', 'b', '.', '.', '.', '.', 'b',
            'a', 'b', '.', '.', '.', '.', 'b',
            '.', '.', 'a', 'a', 'b', 'b', 'c',
            '.', '.', 'b', 'b', 'a', 'a', 'c',
        };
        REP(i,7){
            REP(j,7){
                ans[i][j] = d7[i][j];
            }
        }
    }
    char d4[4][4] = 
    {
        'a', 'a', 'c', 'a',
        'b', 'b', 'c', 'a',
        'a', 'c', 'd', 'd',
        'a', 'c', 'a', 'a',
    };
    int t = 4;
    t += n % 4;
    if(n % 4 == 0) t = 0;
    for(int i = t; i < n; i++){
        for(int j = t; j < n; j++){
            if(i - t == j - t && (i - t) % 4 == 0 && (j - t) % 4 == 0){
                REP(k,4){
                    REP(l,4){
                        ans[i + k][j + l] = d4[k][l];
                    }
                }
            }
        }
    }
    REP(i,n){
        REP(j,n){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<pair<ll, ll>> A(N);
    rep(i, N) {
        ll x, l;
        cin >> x >> l;
        A[i] = mp(x + l, x - l);
    }
    sort(all(A));
    int cnt = 0;
    ll cur = -inf;
    rep(i, N) {
        if(cur <= A[i].second) {
            cnt++;
            cur = A[i].first;
        }
    }
    output(cnt);
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

const ull b=998244353;

int main()
{
	string s, t;
	cin>>s; cin>>t;
	vector<ull> v;
	ull th=0;
	for(int i=0; i<t.size(); i++){
		th=th*b+t[i];
	}
	ull bp=1;
	for(int i=t.size()-1; i>=0; i--){
		for(char c='a'; c<='z'; c++){
			if(t[i]==c) continue;
			v.push_back(th-bp*t[i]+bp*c);
		}
		for(char c='A'; c<='Z'; c++){
			if(t[i]==c) continue;
			v.push_back(th-bp*t[i]+bp*c);
		}
		bp*=b;
	}
	sort(v.begin(), v.end());
	ull sh=0;
	for(int i=0; i<t.size(); i++){
		sh=sh*b+s[i];
	}
	int ans=0;
	if(lower_bound(v.begin(), v.end(), sh)!=upper_bound(v.begin(), v.end(), sh)) ans++;
	for(int i=t.size(); i<s.size(); i++){
		sh=sh*b+s[i]-s[i-t.size()]*bp;
		if(lower_bound(v.begin(), v.end(), sh)!=upper_bound(v.begin(), v.end(), sh)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 69304
$N = gets.to_i
$ss, $sst = [], Array.new($N){Array.new($N)}
$N.times do |i|
    $ss[i] = gets.chomp.split('')
    $N.times do |j|
        $sst[j][i] = $ss[i][j]
    end
end

def check(a)
    (0...$N).each do |i|
        if $ss[i] != $sst[(i+a) % $N]
            return false
        end
    end
    true
end

sum = 0
(0...$N).each do |a|
    sum += $N if check(a)
    (0...$N).each { |i| $ss[i].rotate!(1) }
end
puts sum

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import Foundation

_ = readLine()
let ints = readLine()!.split(separator: " ").map { Decimal(string: String($0))! }
var r: Decimal = 1
if ints.contains(0) { r = 0 }
for i in ints {
    r *= i
    if r > 1_000_000_000_000_000_000 {
        r = -1
        break
    }
}
print(r)

Measured memory_bytes: 21896
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
signed main()
{
	int n = in();
	while (n >= 0)
	{
		if (n % 4 == 0)
		{
			cout << "Yes" << endl;
			return 0;
		}
		n -= 7;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, ll>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<P>> to(n);
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        to[a].push_back(make_pair(b, -c));
    }
    ll INF = 1001001001001001001;
    vector<ll> d(n, INF);
    d[0] = 0;
    ll ans = 0;
    rep(i, n){
        rep(v, n){
            for(P p : to[v]){
                int t = p.first;
                ll dist = p.second;
                if(d[v] != INF && d[t] > d[v] + dist){
                    d[t] = d[v] + dist;
                }
            }
        }
        if(i == n - 2)ans = d[n-1];
        else if(i == n - 1){
            if(ans != d[n-1])cout << "inf" << endl;
            else cout << -ans << endl;
        }
    }
}

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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var ans = GetInt() < 1200 ? "ABC" : "ARC";


            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 ll N;
  cin >>N;
  vl vec(N);
  rep(i,N) {
cin >>vec.at(i);
  }
bool ans=true;
 rep(i,N-1) {
   if(vec.at(N-2-i)<=vec.at(N-1-i)) {
     continue;
   }
else if (vec.at(N-2-i)>vec.at(N-1-i)) {
   if(vec.at(N-2-i)-1==vec.at(N-1-i)) {
     vec.at(N-2-i)=vec.at(N-2-i)-1;
       continue;
   }
  else {
ans=false;
    break;
  }
}
 }
  
  
  if(ans) {
    cout<< "Yes"<<endl;
  }
else {
cout<<"No"<<endl;
}
  
  
}
 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define M 500005
#define bug printf("bug\n")
#define ll long long
int n,k,arr[M],dp[M];
int c(int a,int b)
{
    return abs(arr[a]-arr[b]);
}
int f(int pos)
{
    if(pos>n) return INT_MAX/2;
    if(pos==n) return 0;
    if(dp[pos]!=-1) return dp[pos];
    int res = INT_MAX/2;
    for(int i=1;i<=k;i++)
    {
        if(pos+i<=n) res = min(res,f(pos+i)+c(pos,pos+i));
    }
    return dp[pos] = res;
}
int main()
{
    k = 2;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        dp[i] = -1;
        scanf("%d",&arr[i]);
    }
    printf("%d\n",f(1));
    return 0;
}


Measured memory_bytes: 5760
'use strict';
function Main(input) {
  input = input.split("\n");
  var total = parseInt(input[0], 10);
  var first = parseInt(input[1], 10);
  var billF = parseInt(input[2], 10);
  var billA = parseInt(input[3], 10);
  if(total <= first){
     console.log(total * billF);
  }else{
    var last = total - first;
  	console.log((first * billF) + (last * billA));
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size()
using namespace std;
typedef unsigned long long ll;

int main(void){
	int N;
	cin >> N;
	long long ans = 1;
	for(long long i = 1; i <= N; i++){
		ans *= i;
		ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 764
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
   static void Main(string[] args)
   {
      const string wrong = "Hoshino";
      const string correct = "Hoshina";

      var stringbuilder = new StringBuilder();

      int n = int.Parse(Console.ReadLine());
      while (n-- > 0)
      {
         char[] text = Console.ReadLine().ToCharArray();

         for (int i = 0; i + wrong.Length <= text.Length; i++)
         {
            bool match = true;

            for (int j = 0; j < wrong.Length; j++)
            {
               if (text[i + j] != wrong[j])
               {
                  match = false;
                  break;
               }
            }

            if (!match) { continue; }

            for (int j = 0; j < correct.Length; j++)
            {
               text[i + j] = correct[j];
            }
         }

         stringbuilder.AppendLine(new string(text));
      }

      Console.Write(stringbuilder.ToString());
   }
}

Measured memory_bytes: 8784
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;

int main(){
    DRI(n);
    VI d;
    REP(i,n){
        DRI(x);
        d.PB(x);
    }
    int lt=1;
    int now=1;
    LL an=1;
    REPP(i,1,n){
        if(d[i]==lt+1)an=an*(now+1)%MOD;
        else{
            now++;
            lt+=2;
        }
    }
    REPP(i,1,now+1)an=an*i%MOD;
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 892
import sys
def main():
    input=sys.stdin.readline
    N,K=map(int,input().split())
    H=list(map(int,input().split()))
    if N-1<=K:
        print(H[N-1]-H[0])
        return
    inf=10**9+7
    dp=[inf]*N
    dp[0]=0

    for i,h in enumerate(H):
        if i==0:continue
        m=inf
        M=max(0,i-K)
        dp[i]=min([dpt+abs(h-ht) for ht, dpt in zip(H[M:i],dp[M:i])])
    print(dp[N-1])
    return
if __name__=="__main__":
    main()


Measured memory_bytes: 14048
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>//こいつを注意しろ！！！！

using namespace std;





int main(){

  long long X,Y;
  cin>>X>>Y;
  int ans=0;
 
  for(int i=0;;i++){
    if(X<=Y){
      ans++;
      X=2*X;
    }
    else break;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri - 1][ci - 1] = vi

dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
    for j in range(c):
        dpj = dp[j][:]
        if j == 0:
            dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
        else:
            dp[j][0] = max(max(dpj), dp[j - 1][0])
            dp[j][1] = dp[j - 1][1]
            dp[j][2] = dp[j - 1][2]
            dp[j][3] = dp[j - 1][3]
            if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])

print(max(dp[c - 1]))


Measured memory_bytes: 156232
N,K=map(int,input().split())
P=list(map(int,input().split()))
X=[]
for a in P:
    X.append(a/2+0.5)
gou=sum(X[0:K])

han=-32
saigou=sum(X[N-K:N])
han=saigou
for a in range(N-K-1):

    if gou>han:
        han=gou
    gou=gou-X[a]+X[a+K]

print(han)

Measured memory_bytes: 101640
## abc070c: Multiple Clocks

def gcm(q,r): ## 最大公約数
    if q<r: q, r = r, q
    while(r>0): q, r = r, q%r,
    return q

def lcm(a,b): ## 最小公倍数
    return a//gcm(a,b)*b

n = int(input())
a = int(input())
for _ in range(n-1): a = lcm(a, int(input()))
print(a)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
     int n;
     cin >> n;
     vector<int> a(n);
     rep(i, n)cin >> a.at(i);
     sort(all(a));
     bool ans = true;
     REP(i, n-1)if(a.at(i) == a.at(i-1))ans = false;
     if(ans)cout << "YES" << endl;
     else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}


int n,k;

signed main(){
	read(n,k);
	if(k==1) k=n;
	write(n-k);
}

Measured memory_bytes: 3612
n,t=map(int,input().split())

way=[]
for i in range(n):
    way.append(list(map(int,input().split())))
#print(way)

ans=[]
for i in range(n):
    if way[i][1]<=t:
        ans.append(way[i][0])

if len(ans)==0:
    print("TLE")
else:
    print(min(ans))


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

#define rep(i, n) for (int i = 0; i < (n); i++)

struct LoCoAn {
  vector<vector<int>> g;
  vector<vector<int>> par;
  vector<int> dep;
  int L = 1;
  LoCoAn(const vector<vector<int>> &g) : g(g) {
    int n = g.size();
    dep.resize(n);
    while ((1 << L) <= n) {
      L += 1;
    }
    par.resize(n, vector<int>(L, -1));
    dfs(0);
    for (int j = 0; j + 1 < L; j++)
      rep(i, n) {
        if (par[i][j] >= 0) par[i][j + 1] = par[par[i][j]][j];
      }
  }
  void dfs(int i, int p = -1) {
    par[i][0] = p;
    dep[i] = p >= 0 ? dep[p] + 1 : 0;
    for (int j : g[i]) {
      if (j != p) dfs(j, i);
    }
  }
  int lca(int s, int t) {
    if (dep[s] < dep[t]) swap(s, t);
    rep(i, L) if ((dep[s] - dep[t]) >> i & 1) s = par[s][i];
    if (s == t) return s;
    for (int i = L - 1; i >= 0; i--) {
      if (par[s][i] != par[t][i]) {
        s = par[s][i];
        t = par[t][i];
      }
    }
    return par[s][0];
  }
};

int main() {

  int n;
  cin >> n;
  vector<vector<int>> g(n);
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k) {
      int c;
      cin >> c;
      g[i].emplace_back(c);
    }
  }
  LoCoAn lca(g);
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
  return 0;
}



Measured memory_bytes: 27436
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  const double PI = 3.141592653589793;

  int A, B, H, M;
  cin >> A >> B >> H >> M;

  // hours: 360 = 12h, 30 = 1h, 0.5 = 1m
  // minutes: 360 = 1h, 6 = 1m

  // c = sqrt(a^2+b^2-2ab*cosC)

  double degA = 30 * H + 0.5 * M;
  double degB = 6 * M;

  double mn = std::min(degA, degB);
  double mx = std::max(degA, degB);

  double degC = std::min(mx-mn, 360+mn-mx);

  double C = sqrt(A*A + B*B - 2 * A * B * std::cos(PI*degC/180));

  cout << std::fixed << std::setprecision(20) << C << endl;

  return 0;
}


Measured memory_bytes: 4188
import math
A,B,H,M = map(int,input().split())
rad = abs(( H + M/60 ) * 30 - 6 * M)
rad = math.radians(rad)
cos = math.cos(rad)
answer = math.sqrt( A*A + B*B - 2*A*B*cos)
print(answer)

Measured memory_bytes: 9504
/*input
1 2
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

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


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,k;
	ll x,y;
	cin>>x>>y;
	if(x*2>y||x*4<y||y%2){
		cout<<"No\n";
	}else cout<<"Yes\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 3668
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        x: i64, k: i64, d: i64
    };

    let x = x.abs();
    let c = x / d;
    if k <= c {
        let res = (x - (k * d)).abs();
        println!("{}", res);
        return;
    }
    let rest_c = k - c;
    if rest_c % 2 == 0 {
        let res = (x - (c * d)).abs();
        println!("{}", res);
    } else {
        let res = (x - (c * d) - d).abs();
        println!("{}", res);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2280
s=input()
turn=0 
a=''
b=''
for i in s: 
    if i=='+' or i=='-': 
        turn=1 
        if i=='+':
            op=1 
        else: 
            op=-1 
    elif turn==0 and i:
        a+=i 
    elif turn==1 and i: 
        b+=i 
if op==1:
    print(int(a)+int(b))
else:
    print(int(a)-int(b))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int numN;
		int numM;
		int numL;

		long[][] boxA;
		long[][] boxB;
		long[][] boxAnser;

		String outPut = "";

		Scanner sc = null;

		try {
			sc = new Scanner(System.in);

			//1???????????\???
			numN = sc.nextInt();
			numM = sc.nextInt();
			numL = sc.nextInt();

			boxA = new long[numN][numM];
			boxB = new long[numM][numL];
			boxAnser = new long[numN][numL];

			//???????????????

			//??????A?????????
			for (int i = 0; i < boxA.length; i++) {
				for (int j = 0; j < boxA[0].length; j++) {
					boxA[i][j] = sc.nextInt();
				}
			}
			//??????B?????????
			for (int i = 0; i < boxB.length; i++) {
				for (int j = 0; j < boxB[0].length; j++) {
					boxB[i][j] = sc.nextInt();
				}
			}
			//??????????£???§?¨????
			for (int i = 0; i < boxAnser.length; i++) {
				for (int j = 0; j < boxAnser[0].length; j++) {
					for (int k = 0; k < numM; k++) {

						boxAnser[i][j] += boxA[i][k] * boxB[k][j];
					}
				}
			}

			//???????????????
			for (int i = 0; i < boxAnser.length; i++) {
				for (int j = 0; j < boxAnser[0].length; j++) {
					if (!outPut.equals("")) {
						outPut += " ";
					}
					outPut += boxAnser[i][j];
				}
				System.out.println(outPut);
				outPut = "";
			}
		} finally {
			sc.close();
		}
	}

}

Measured memory_bytes: 87340
#include <iostream>

using namespace std;

constexpr auto MOD = 1000000007ll;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;

  ll cnt{0};
  for (auto i = k; i <= n+1; ++i) {
    cnt += i * (n-i+1) + 1;
    cnt %= MOD;
  }
  cout << cnt << endl;
  
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    for (int i = 0; i < n; ++i) {
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    long long ans=0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            int minl=l[j]-l[i];
            int maxl=l[i]+l[j];
            auto itl=upper_bound(l.begin(),l.end(),minl);
            auto itm=lower_bound(l.begin(),l.end(),maxl);
            int val=itm-itl;
            --itm;
            if(*itl<=l[i]&&l[i]<=*itm)--val;
            if(*itl<=l[j]&&l[j]<=*itm)--val;
            ans+=val;
        }
    }
    cout<<ans/3<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MAX 1000005
#define MOD 1000000007
ll n, m, i, j, k,mx;
ll arr[MAX];
map<ll,ll> mp;
vector<ll> vec, v[MAX];

int main()
{
   // #ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //#endif
    cin>>n>>k;
    m=0;mx=0;
    for(i=0;i<n;i++)
    {
        cin>>j;
        m = __gcd(m, j);mx = max(mx,j);
    }
    if(k%m || mx<k)cout<<"IMPOSSIBLE\n";
    else cout<<"POSSIBLE\n";
   return 0;
}

Measured memory_bytes: 24832
import re


def solve(s):
    # 'AC' か 'WA' を返す

    # Sの先頭の文字は大文字の A である。
    if s[0] != 'A':
        return 'WA'

    # Sの先頭から3文字目と末尾から
    # 2文字目の間（両端含む）に大文字の C
    # がちょうど  1  個含まれる。
    s_ = s[2:-1]
    if len([True for c in s_ if c == 'C']) != 1:
        return 'WA'

    # 以上の A, C を除くSのすべての文字は小文字である。
    n_capital = len(re.findall('[A-Z]', s))
    if (n_capital - 2) != 0:
        return 'WA'

    return 'AC'


s = input()
print(solve(s))


Measured memory_bytes: 3188
n = input()
a = map(int, raw_input().split())

max = a[0]
min = a[0]
sum = 0

for i in range(n):
    if a[i] > max:
        max = a[i]
    if a[i] < min:
        min = a[i]
    sum = sum + a[i]

print min,max,sum

Measured memory_bytes: 7196
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;

fn main() {
    let mut n:usize = read!();
    let mut b:usize = 0;
    let mut c:usize = 0;
    let mut bi:usize = 0;
    let mut ci:usize = 0;
    for i in 0..n {
        let a:usize = read!();
        if a>=b {
            c=b;
            b=a;
            ci=bi;
            bi=i;
        }
        else if a>c {
            c=a;
            ci=i;
        }
    }
    for i in 0..n {
        if i!=bi {
            println!("{}",b);
        }
        else {
            println!("{}",c);
        }
    }
}

Measured memory_bytes: 2128
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main()
{
    int health, hit, result;
    cin >> health >> hit;
    if(health > hit)
    {
        if(health % hit == 0)
    {
        result = health /  hit;
    }
    else if(health % hit != 0)
    {
        result = health / hit;
        result ++;
    }
    }

    else if(health < hit)
    {
        result = 1;
    }
    else if(health == hit)
    {
        result = 1;
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int K;
    cin >> K;
    sort(a, a + 3);
    for (int i = 0; i < K; i++)
    {
        a[2] *= 2;
    }
    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

items = [n for n in range(1,n)]
comb = []
for v in itertools.combinations(items,k-1):
    comb.append(v)

ans = sys.maxsize
for com in comb:
    tmpans = 0
    highest = data[0]
    for i in range(1, n):
        if i in com:
            if highest < data[i]:
                highest = data[i]
                continue
            else:
                highest += 1
                tmpans += highest - data[i]
        else:
            if highest < data[i]:
                highest = data[i]
                continue
  

    ans = min(ans, tmpans)

if k == 1:
    print(0)
else:
    print(ans)




Measured memory_bytes: 5252
use strict;
use warnings;
use 5.010;

use Data::Dumper;

my $n = <STDIN>;
chomp($n);

my $a = read_split();


my $res = [];
for (my $i = 0 ; $i < @$a ; $i++) {
        $res->[$a->[$i]-1] = $i+1;
}

my $out = "";
$out .=  "$_ " for @$res;
chop($out);
print($out);

sub read_split {
        my $line        = <STDIN>;
        chomp($line);
        return [split(/ /, $line)];
}


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

// o(n * log(m)) 累積和 + 二分探索

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> s(m + 1, 0);
  rep(i, m) s[i + 1] = s[i] + b[i];
  int ans = 0;
  ll t = 0;
  for (int i = 0; i <= n; i++) {
    if (i != 0) {
      t += a[i - 1];
    }
    if (t > k) break;
    int l = -1;
    int r = m + 1;
    while (l + 1 < r) {
      int mid = (l + r) / 2;
      if (t + s[mid] <= k) {
        l = mid;
      } else {
        r = mid;
      }
    }
    ans = max(ans, i + l);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7992
#include <iostream>
using namespace std;
int main(void){
    int x, y;
    while (1) {
        cin >> x >> y;
        if ( x == 0 && y == 0 ) { break; }
        cout << min(x,y) << " " << max(x,y) << endl;
    }
    return 0;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<ll> x(n + 1), y(m + 1);
	for (int i = 1; i <= n; ++i) scanf("%lld", &x[i]);
	for (int i = 1; i <= m; ++i) scanf("%lld", &y[i]);
	Mint xs = 0, ys = 0;
	for (int i = 1; i < n; ++i) xs += Mint(i) * (n - i) * (x[i + 1] - x[i]);
	for (int i = 1; i < m; ++i) ys += Mint(i) * (m - i) * (y[i + 1] - y[i]);
	printf("%d\n", (xs * ys).val);
}


Measured memory_bytes: 1792
N, Q = map(int, input().split())
a=input()

list=[0]*(N+1)

for i in range(N):
    list[i+1]=list[i]+1 if a[i:i+2]=="AC" else list[i]
    
for i in range(Q):
    l,r = map(int, input().split())
    print(list[r-1]-list[l-1])
    

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

const int maxn = 2e5 + 20, mod = 1e9 + 7;
int n, a[maxn], dp[maxn], ii, i = -1;
pair <int, int> cs[maxn];

int main() 
{    
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n;
    dp[0] = 1;
    for (int i = 0; i < maxn; i++)
        cs[i].second = -1;

    for (int z = 0; z < n; z++)
    {
        i++;
        cin >> a[i];
        if (i > 0 && a[i] == a[i - 1])
        {
            i--;
            continue;
        }
        if (i > 0)
            dp[i] = dp[i - 1];
        if (cs[a[i]].second != -1)
            dp[i] = (dp[i] + dp[cs[a[i]].second])%mod;
        cs[a[i]].first++;
        cs[a[i]].second = i;
        ii =  i;
    }
    cout << dp[ii] << endl;
    return 0;    
}



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

int main () {
int n, a, b; cin >> n;
  vector<int> p(n);
  rep(i,n) {
    cin >> p.at(i);
    a += p.at(i);
  }
  int ans = 1e9;
  rep(i,n) {
    b += p.at(i);
    a -= p.at(i);
    ans = min(ans,abs(a-b));
  }
  cout << ans;
}


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

int main(){
  int n{},m{},x{},y{};
  cin>>n>>m;
  if(n==0||n==1||n==2)
  x=((n==0||n==1)?0:1);

  if(m==0||m==1||m==2)
  y=((m==0||m==1)?0:1);
  
  if(n>2)
  x = (n*(n-1)/2);
  
  if(m>2)
  y = (m*(m-1)/2);

cout<<x+y;
  
  return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = unsigned long long;

int know_digit(ll n)
{
    int ans = 0;
    while(n){
        n /= 10;
        ++ans;
    }
    return ans-1;
}

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
        if(a.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ima = 1e18;
    sort(all(a), greater<ll>());
    if(a.front() > ima){
        cout << -1 << endl;
        return 0;
    }
    ll ans = 1;
    for(i = 0;i < n;++i){
        if(a.at(i) > ima){
            cout << -1 << endl;
            return 0;
        }
        if(know_digit(ans) + know_digit(a.at(i)) > 18){
            cout << -1 << endl;
            return 0;
        }
        ll tmp = ans*a.at(i);
        if(tmp < ans || tmp > ima){
            cout << -1 << endl;
            return 0;
        }
        ans = tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll r;
    if (a + b + 1 >= c) {
        r = b + c;
    } else {
        r = a + b + 1 + b;
    }

    cout << r << endl;

    return 0;
}

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

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

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


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}

int main() {

	string ans="";

	long long N;
	
	cin >> N;

	while (1) {
		ans.insert(ans.begin(), 'a' + ((N - 1) % 26));
		N = (N-1) / 26;
		if (N == 0) {
			break;
		}
	}
	

	cout << ans << endl;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int f(int x){
    int res = 0;
    for(int i = 1; i*i <= x; i++){
        if (x % i == 0) res += 2;
        if (i * i == x) res--;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i+=2){
        if (f(i) == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
using namespace std;
char s[110];

int main(){
	int k;
	scanf("%d",&k);
	getchar();
	scanf("%s",s);
	int len=strlen(s);
	if(len<=k)
        printf("%s\n",s);
    else
    {
        for(int i=0;i<k;i++)
            printf("%c",s[i]);
        printf("...\n");
    }
	return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<map>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const LL INF = (1 << 30);
const LL INFL = INF * INF;


//変数
LL N, M;
bool ans = true;
vector<map<LL, LL>> edge;// edge[from][to] = length




//vectorの中身を全部表示
template<typename T>
void show(vector<T> v)
{
	for (auto col : v)cout << col << " ";
	cout << endl;
}
template<typename T>
void show(vector<vector<T>> v)
{
	for (auto row : v)show(row);
	cout << endl;
}



//サブ関数
//入力
void input()
{
	cin >> N >> M;
	edge.resize(N);
	LL l, r, d;
	REP(i, M) {
		cin >> l >> r >> d;
		l--; r--;
		edge[l][r] = d;
		edge[r][l] = -d;
	}
}



//計算
void calc()
{
	vector<bool> went(N, false);
	vector<LL> place(N, INFL);
	queue<pair<LL, LL>> q;// first:from,  second:to
	int cnt = -1;//森を、木の単位でずらして、被らないようにする

	
	REP(i, N) 
	{
		//cout << "now:"<< i << endl;
		//枝切り
		if (went[i])continue;
		if (edge[i].size() == 0)continue;

		//init
		cnt++;
		place[i] = INF * cnt;
		went[i] = true;
		for (auto itr = edge[i].begin(); itr != edge[i].end(); ++itr) {
			q.push(make_pair(i, itr->first));
		}

		//各枝を確認していく
		while (!q.empty()) {
			auto now = q.front(); q.pop();
			went[now.first] = true;
			LL will = place[now.first] + edge[now.first][now.second];
			//辺の削除
			//edge[now.first].erase(now.second);
			//edge[now.second].erase(now.first);

			//show(place);
			//cout << now.first << " " << now.second << endl << endl;

			//既に探索済みに移行している場合
			if (place[now.second] != INFL) {
				//食い違いが出たら、終了
				if (place[now.second] != will) {
					//REP(i, N)cout << place[i] << endl << endl;
					//cout << now.first << " " << now.second << " " << edge[now.first][now.second] << endl;
					ans = false;
					return;
				}
			}
			else {
				//場所を更新
				place[now.second] = will;

				//そこから行ける道を、とりあえず全部ぶち込む
				for (auto itr = edge[now.second].begin(); itr != edge[now.second].end(); ++itr) {
					q.push(make_pair(now.second, itr->first));
				}
			}

			
		}
		//show(place);
	}

}


//出力
void output()
{
	cout << (ans ? "Yes" : "No") << endl;
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}



Measured memory_bytes: 35712
#!/bin/ruby
while 1
  n=gets.to_i
  break if n==0
  k=gets.split.map(&:to_i)
  s=gets.chomp
  a=[]
  ("a".."z").each do |e|
    a<< e
  end
  ("A".."Z").each do |e|
    a<< e
  end
  (0...s.size).each do |x|
    s[x]=a[(a.find_index(s[x])-k[x%k.size]+a.size)%a.size]
  end
  puts s
end

Measured memory_bytes: 6124
#coding: utf-8
N = int(raw_input())
P = map(int, raw_input().split(' '))

pos = [0] * N
for i, p in enumerate(P):
    pos[p - 1] = p - 1 - i

swap = 0
while 0 in pos:
    for i, p in enumerate(P):
        if pos[p - 1] == 0:
            if i == 0:
                pos[P[i] - 1] -= 1
                pos[P[i + 1] - 1] += 1
                P[i], P[i + 1] = P[i + 1], P[i]
            elif i == N - 1:
                pos[P[i] - 1] += 1
                pos[P[i - 1] - 1] -= 1
                P[i], P[i - 1] = P[i - 1], P[i]
            else:
                if P[i - 1] <= 0:
                    pos[P[i] - 1] += 1
                    pos[P[i - 1] - 1] -= 1
                    P[i], P[i - 1] = P[i - 1], P[i]
                elif P[i + 1] >= 0:
                    pos[P[i] - 1] -= 1
                    pos[P[i + 1] - 1] += 1
                    P[i], P[i + 1] = P[i + 1], P[i]
                else:
                    left_val = abs(P[i - 1])
                    right_val = abs(P[i + 1])
                    if left_val > right_val:
                        pos[P[i] - 1] += 1
                        pos[P[i - 1] - 1] -= 1
                        P[i], P[i - 1] = P[i - 1], P[i]
                    else:
                        pos[P[i] - 1] -= 1
                        pos[P[i + 1] - 1] += 1
                        P[i], P[i + 1] = P[i + 1], P[i]
            swap += 1
print swap

Measured memory_bytes: 11280
<?php
while (true) {
	$n = trim(fgets(STDIN));
	if ($n == 0) {
		break;
	}
	$m = array();
	for ($i = 0; $i < $n; $i++) {
		$row = explode(' ', trim(fgets(STDIN)));
		// 行の和をついでに計算
		$row[] = array_sum($row);
		$m[$i] = $row;
	}
	// 列の和
	$m[$n] = array();
	for ($j = 0; $j <= $n; $j++) {
		$m[$n][$j] = 0;
		for ($i = 0; $i < $n; $i++) {
			$m[$n][$j] += $m[$i][$j];
		}
	}
	// 出力
	for ($i = 0; $i <= $n; $i++) {
		for ($j = 0; $j <= $n; $j++) {
			printf("%5d", $m[$i][$j]);
		}
		echo "\n";
	}
}

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

int main() {
  string S, T;
  cin >> S >> T;
  bool answer = true;
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) != T.at(i)){
      answer = false;
      break;
    }
  }
  if (answer){
    cout << "Yes" <<endl;
  }
  else {
     cout << "No" << endl;
  }
    
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=a;i<b;i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF=INT_MAX;
const lli MOD=10e8+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout.precision(30);
	int m,n;cin>>n>>m;
	char a[n+1][m+1];
	lli dp[n+1][m+1];
	forr(i,0,n+1) forr(j,0,m+1)	{a[i][j]=0;dp[i][j]=0;}
	
	
	forr(i,1,n+1)	forr(j,1,m+1)	cin>>a[i][j];
	
	
	forr(i,1,n+1)	if(a[i][1]!='#')	dp[i][1]=1; else break;
	forr(i,1,m+1)	if(a[1][i]!='#')	dp[1][i]=1; else break;
	//~ forr(i,1,n+1)	{forr(j,1,m+1)	cout<<dp[i][j]<<" ";cout<<endl;}
	forr(i,1,n+1)
	{
		forr(j,1,m+1)
		{
			if(a[i][j]!='#' && i-1>0 && j-1>0)	
			{
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
				if(dp[i][j]>MOD)	dp[i][j]=dp[i][j]%MOD;
			}
		}
	}
	
	//~ forr(i,1,n+1)	{forr(j,1,m+1)	cout<<dp[i][j]<<" ";cout<<endl;}
	cout<<dp[n][m]%MOD<<endl;
    return 0;
}


Measured memory_bytes: 9088