akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define vll vector<ll>
#define vvll vector<vll>
#define pi pair<int, int>
#define ll long long

const int N = 1e5+5;
int n;
int wt[102], val[102];
vvll dp(102,vll(N,-1));

ll solve(int i, int vsum){
	if(vsum==0)
		return 0;
	if(i==n){
		return 1e12;
	}

	if(dp[i][vsum]==-1){

		if(val[i]<=vsum)
			dp[i][vsum] = min(wt[i]+solve(i+1,vsum-val[i]), solve(i+1,vsum));
		else
			dp[i][vsum] = solve(i+1, vsum);
	}
	return dp[i][vsum];
}

int main(){
	int W;
	cin >> n>> W;
	for(int i=0;i<n;++i){
		cin >> wt[i]>> val[i];
	}
	int x = solve(0,100001);
	int ans;
	for(int i=100000;i>=0;--i){
		ll x = solve(0,i);
		if(x<=W && x!=-1){
			ans = i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 81024
def gcd(n1,n2):
    if n2==0:
        return n1
    return gcd(n2,n1%n2)

def lcm(n1,n2):
    return n1/gcd(n1,n2)*n2

while True:
    try:
        a,b=[int(i) for i in input().split()]
        print("{} {}".format(int(gcd(a,b)),int(lcm(a,b))))
    except:
        break


Measured memory_bytes: 5604
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
double x[21], y[21], t[21], hx, hy, sx ,sy;


int solve(double sx, double sy, int b, double ct){
	if(b == (1<<n)-1) return 1;
	REP(i, n)if(0 == ((b>>i)&1)){
		double nt = ct + hypot(x[i]-sx, y[i]-sy);
		if(t[i]-EPS < nt) return 0;
	}
	REP(i, n)if(0 == ((b>>i)&1)){
		double nt = ct + hypot(x[i]-sx, y[i]-sy);
		if(t[i]-EPS < nt) continue;
		if(solve(x[i], y[i], b | (1<<i), nt)) return 1;
	}
	return 0;
}


int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	while(cin >> n >> sx >> sy >> hx >> hy, n){
		REP(i, n){
			cin >> x[i] >> y[i];
			t[i] = hypot(x[i]-hx, y[i] - hy);
		}
		cout << (solve(sx, sy, 0, 0) ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n; cin >>n;
  double sumyen; double sumbit;
  
  double x; string u;
  for (int i=0; i<n; i++){
    cin >>x >>u;
    if (u=="JPY") sumyen += x;
    else sumbit += x;
  }
  double ans = sumyen + 380000*sumbit;
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long LL;

const int maxn = 2005;
const int mod = 1000000007;

inline int pow(int a, int b)
{
    if (b < 0)
        return 1;
    int ans = 1;
    for (; b; b >>= 1, a = (LL) a * a % mod)
        if (b & 1)
            ans = (LL) ans * a % mod;
    return ans;
}

int dp[maxn];

int main()
{
    int n, k;
    cin >> n >> k;
    dp[n + 1] = 1;
    for (int i = n; i > n - k; --i)
    {
        for (int j = n; j; --j)
        {
            if (i < j)
                dp[j] = 0;
            else
            {
                dp[j] = dp[j + 1] + dp[j];
                if (dp[j] >= mod)
                    dp[j] -= mod;
            }
        }
    }
    cout << (LL) dp[1] * pow(2, n - k - 1) % mod;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

	int N, W;
	cin >> N >> W;
	vector<vector<long long>> products(N, vector<long long> (2));
	for(int i = 0; i < N; i++)
	{
		cin>> products[i][0] >> products[i][1]; 
	}
	long long dp[N+1][W+1];

	for(int i = 0; i <= N; i++)
	{
		for(int j = 0; j <= W; j++)
		{
			if( i  == 0 || j == 0)
				dp[i][j] = 0;

			else if( j >= products[i-1][0])
				dp[i][j] =  max( products[i-1][1] + dp[i-1][j - products[i-1][0]], dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	cout << dp[N][W] << endl;

}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#ifdef LOCAL
#include "1.h"
#else
#define dbg(...) 
#endif
ll n,m,i,j,k,in,cnt = 0,l,r,u,v,x,y,tc = 1,mod = 1000000007  ;
const ll  mx = 100001 ;
vector<ll> a(mx);
vector<int> dp(mx,-1);
ll foo(int src){
    if(dp[src]!=-1)
        return dp[src];
    if(src==n-1){
        return 0;
    }
    else{
        ll ans  = abs(a[src]- a[src+1]) + foo(src+1);
        if(src+2 < n)
            ans = min(ans,abs(a[src]- a[src+2]) + foo(src+2));
        return dp[src]=ans;
    }
}
void solve(){
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    cout<<foo(0)<<endl;
}
signed main(){                                          //F
    clock_t time = clock();                             //A
    ios_base::sync_with_stdio(0);                       //S
    cin.tie(0);                                         //T
    cout.tie(0);                                        //I
    cerr.tie(0);                                        //O
    if(0) cin>>tc;
    while(tc--)
        solve();
    dbg("Author - Amit dwivedi");
    return 0&fprintf(stderr, "Time ::%.3lf ms.\n",((clock() - time)*1000.0)/CLOCKS_PER_SEC);
}

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

int main(void) {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  int SugarWater = 0;
  int Sugar = 0;
  double MaxRatio = 0;
  for (int a = 0; a < F; a += 100 * A) {
    for (int b = 0; (a + b) < F; b += 100 * B) {
      if (a == 0 && b == 0)
        continue;
      for (int c = 0; (a + b + c) <= F; c += C) {
        if ((a + b) * E < (c * 100))
          break;
        for (int d = 0; (a + b + c + d) <= F; d += D) {
          if ((a + b) * E < ((c + d) * 100))
            break;
          double Ratio = (c + d) * 100.0 / (double)(a + b + c + d);
          if (Ratio >= MaxRatio) {
            SugarWater = a + b + c + d;
            Sugar = c + d;
            MaxRatio = Ratio;
          }
        }
      }
    }
  }
  cout << SugarWater << " " << Sugar << endl;
  return 0;
}

Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const int MAX_LIMIT = 100005;

int N;
ll arr[MAX_LIMIT];
ll toTake = 1, ans;
ll bottleNeck = 0;

int main()
{
	int i, j;
	cin >> N;

	fl(i,0,N)
	{
		cin >> arr[i];
	}



	fl(i,0,N)
	{
		// cout <<arr[i] << " " << bottleNeck; nline;
		toTake = bottleNeck + 1;
		if(arr[i] > toTake)
		{
			ll val = arr[i] / toTake;
			arr[i] -= toTake * val;
			if(arr[i] % toTake == 0)
			{
				arr[i] = 1;
				val--;
			}
			// cout << "(" << val << ")"; nline;
			ans += val;
		}
		bottleNeck = max(bottleNeck, arr[i]);
	}

	// fl(i,0,N)
	// 	cout << arr[i] << " ";

	cout << ans;

	return 0;
}
/*
	Powered by Buggy Plugin
*/


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


int main()
{
    string S;
    cin >> S;
    int len = S.size();
    deque<char> dq;
    for (int i = 0; i < len; i++) dq.push_back(S[i]);    
    int Q, Ti, Fi;
    char Ci;
    cin >> Q;
    bool rev = false;
    while (Q--) {
        cin >> Ti;
        if (Ti == 1) {
            rev = !rev;
        } else {
            cin >> Fi >> Ci;
            if (Fi == 1) {
                if (!rev) dq.push_front(Ci);
                else dq.push_back(Ci);
            } else {
                if (!rev) dq.push_back(Ci);
                else dq.push_front(Ci);
            }
        }
    }
    if (rev) reverse(dq.begin(), dq.end());
    for (const auto &c : dq) cout << c;
    cout << endl;
    
    return 0;
}


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

using namespace std;
int main(){
  int N,L;
  cin >> N >> L;
  int answer=N*L+(N*(N-1)/2);//純粋な合計

int Min=200000;
if(L<0){

if(L+N<=0){
    answer-=L+(N-1);
}


}

else if(L>=0){
answer-=L;




}
   
cout <<answer <<endl;

 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> vec(N);
    for (int64_t i=0; i<N; i++) {
        cin >> vec.at(i);
    }

    int64_t INF = 100000000000000;
    vector<int64_t> dp(N, INF);
    dp[0] = 0;
    for (int64_t i=0; i<N; i++) {
        for (int64_t j=i+1; j<=i+K && j<N; j++) {
            bool is = chmin(dp[j], dp[i] + abs(vec[j] - vec[i]));
        }
    }

    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 4680
N = int(input())
word_list = []
yes_or_no = []
for i in range(N):
    w = str(input())
    if w not in word_list:
        word_list.append(w)
    elif w in word_list:
        yes_or_no.append('No')
        
    if i == 0:
        continue
    else:
        if w[0] == word_list[i-1][-1]:
            yes_or_no.append('Yes')
        else:
            yes_or_no.append('No')
if 'No' in yes_or_no:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
import java.io.*;

public class Main {

	private static int count;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while (null != (str = in.readLine())) {
			doit(Integer.parseInt(str));
		}
	}

	private static void doit(int n) {
		count = 0;
		for (int i = 1; i <= n; i++) {
			if(isPrime(i))count++;
		}
		System.out.println(count);
	}

	private static boolean isPrime(int n) {
		if (n < 2)
			return false;
		else if (n == 2)
			return true;

		if (n % 2 == 0)
			return false;

		for (int i = 3; i <= n / i; i += 2)
			if (n % i == 0)
				return false;
		return true;
	}
}

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

const string YES = "Yes";
const string NO = "No";
int main(){
  vector<int> A(3); rep(i, 3) cin >> A[i];
  sort(A.begin(), A.end());
  if((A[0] == A[1]) ^ (A[1] == A[2])) cout << YES << endl;
  else  cout << NO << endl;
}


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

using namespace std;

vector <int> T1[101010], T2[101010];
vector <int> G[101010];
int C[101010];
int n, r1, r2;

int dfs(int p, int r, vector <int> *V)
{
	int k, ret;
	
	if(~(int)V[p].size() & 1) ret = p;
	else ret = -1;
	
	for(int t: V[p]){
		if(t != r){
			k = dfs(t, p, V);
			if(k != -1){
				if(ret != -1){
					G[ret].push_back(k);
					G[k].push_back(ret);
					ret = -1;
				}
				else ret = k;
			}
		}
	}
	
	return ret;
}

void color(int p, int c)
{
	C[p] = c;
	
	for(int t: G[p]){
		if(!C[t]) color(t, -c);
	}
}

int main()
{
	int i, a;
	
	scanf("%d", &n);
	
	for(i=1;i<=n;i++){
		scanf("%d", &a);
		if(a == -1) r1 = i;
		else T1[a].push_back(i);
	}
	
	for(i=1;i<=n;i++){
		scanf("%d", &a);
		if(a == -1) r2 = i;
		else T2[a].push_back(i);
	}
	
	for(i=1;i<=n;i++){
		if((int)(T1[i].size() + T2[i].size()) & 1){
			printf("IMPOSSIBLE\n");
			return 0;
		}
	}
	
	dfs(r1, 0, T1);
	dfs(r2, 0, T2);
	
	printf("POSSIBLE\n");
	
	for(i=1;i<=n;i++){
		if(~(int)T1[i].size() & 1){
			if(!C[i]) color(i, 1);
			printf("%d ", C[i]);
		}
		else printf("0 ");
	}
	
	printf("\n");
		
	return 0;
}

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

typedef long long ll;

#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define rep1(i, n) for(ll i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int H, W, N; cin >> H >> W >> N;
    vector<int> a(N); cin >> a;
    vector<vector<int>> ans(H, vector<int>(W, 0));

    int c = 1;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            ans[h][h%2==0?w:W-1-w] = c;
            a[c-1]--;
            if (a[c-1] == 0) c++;
        }
    }

    rep(i, H) cout_h(ans[i]);
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
bool comp(pair<int,int> &a,pair<int,int> &b){
  return a>b;
}
int main()
{
  int n;cin >> n;
  vector<pair<int,int>> p(n);
  rep(i,n){
    int a,b;cin >> a >> b;
    p[i] = {b,a};
  }

  sort(p.begin(), p.end(),comp);
  int t = 2e+9;
  rep(i,n){
    t=min(t,p[i].first);
    t -= p[i].second;
  }
  if(t<0) cout << "No" << "\n";  
  else cout << "Yes" << "\n";
  
  return 0;
}


Measured memory_bytes: 1792
def f(n):
    if n % 2 == 0:
        return n // 2
    return 3* n + 1

s = int(input())
lst = [s]
n = 2
while True:
    tmp = f(lst[-1])
    if tmp in lst:
        print(n)
        break
    lst.append(tmp)
    n += 1

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
  int b,d,n,f,a[1000001]={};
  a[0]=1,a[1]=1;
  for(int i=2;i<=1000;i++)if(a[i]==0)for(int j=2;j<=1000000/i;j++)a[i*j]=1;
       while(1){
    int count=0;
    cin>>b>>d>>n;
    if(b+d+n==0) break;
    for(int i=b;i<=1000000;i+=d){
      if(a[i]==0) count++;
       f=i;
       if(count==n) break;
      }
    	cout<<f<<endl;
  }
  return 0;
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

            Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = (int)inputArray[0];
			var X = inputArray[1];

			var p = new long[N+1];
			var all = new long[N+1];

			p[0] = 1;
			all[0] = 1;

			for (int i = 1; i <= N; i++) {
				p[i] = p[i - 1] * 2 + 1;
				all[i] = all[i - 1] * 2 + 3;
			}


			var shokuyoku = X;
			var current = N;
			long ans = 0;
			while (shokuyoku>0) {

				//currentのバーガーを食べきれる場合
				if (shokuyoku >= all[current]) {
					shokuyoku -= all[current];
					ans += p[current];
					if (shokuyoku >0) {//中間のパテを食べる
						ans += 1;
						shokuyoku -= 1;
					}
					continue;
				}

				//食べきれない場合
				shokuyoku -= 1;//端っこのバンを食べる
				current--;
			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 28244
#include<stdio.h>
#include<stack>

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], NEXT[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

int next(int i) {
    for (int j = NEXT[i]; j <= n; ++j) {
        NEXT[i] = j + 1;
        if (G[i][j] > 0) return j;
    }
    return -1;
}

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    while (!S.empty()) {
        int u = S.top();
        int n = next(u);
        if (n != -1) {
            if (STATE[n] == NOT_VISIT) {
                S.push(n);
                d[n] = ++tt;
                STATE[n] = DISCOVER;
            }
        }
        else {
            S.pop();
            f[u] = ++tt;
            STATE[u] = FOUND;
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

Measured memory_bytes: 2752
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    int K, X;
    std::cin >> K >> X;

    const int start = std::max(X - K + 1, -1000000);
    const int end   = std::min(X + K - 1,  1000000);
    
    for (int i = start; i <= end; ++i) {
        std::cout << i;
        if (i != end) {
            std::cout << " ";
        } else {
            std::cout << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int lli;

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

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

	lli A = 1;
		for (int i = 0;i<N;i++) {
			lli B = gcd(T[i], A);
			A = (T[i] / B)*A;
		}
	cout << A;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*a = map(int,read().split())

pos = []
neg = []
MOD = 10**9+7

for i in a:
    if i >= 0: pos.append(i)
    else: neg.append(i)

if n==k:
    ans = 1
    for i in a:
        ans *= i
        ans %= MOD
    print(ans)

elif pos == []: # 全部負
    if k%2==0:
        neg.sort()
        ans = 1
        for i in range(k):
            ans *= neg[i]
            ans %= MOD
        print(ans)
    else:
        neg.sort(reverse=True)
        ans = 1
        for i in range(k):
            ans *= neg[i]
            ans %= MOD
        print(ans%MOD)
            
else: #正もいる
    pos.sort()
    neg.sort(reverse=True)
    if k&1:
        ans = pos.pop()%MOD
    else:
        ans = 1
    
    res = []
    while len(pos)>1:
        x,y=pos.pop(),pos.pop()
        res.append(x*y)
    while len(neg)>1:
        x,y=neg.pop(),neg.pop()
        res.append(x*y)

    res.sort(reverse=True)
    for i in range(k//2):
        ans *= res[i]
        ans %= MOD
    print(ans)

    

Measured memory_bytes: 31240
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    ll n = a.size();
    ll m = b.size();
    if(n>m){
        cout<<"GREATER"<<endl;
    }else if(n<m){
        cout<<"LESS"<<endl;
    }else{
        for(ll i=0;i<n;++i){
            if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }else if(a[i]<b[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
        }
        cout<<"EQUAL"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int h,w,d,a,i,j,x[90001],y[90001],p[90001];main(){cin>>h>>w>>d;for(i=0;i<h;i++)for(j=0;j<w;j++)cin>>a,y[a]=i,x[a]=j;for(i=d;i<=h*w;i++)p[i]=p[i-d]+abs(x[i-d]-x[i])+abs(y[i-d]-y[i]);cin>>d;while(d--)cin>>h>>w,cout<<p[w]-p[h]<<'\n';}

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

int main() {
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
        cin >> h[i];
    
    int ans = 1;
    for (int i = 1; i < n; i++) {
        bool flag = true;
        for (int j = 0; j < i; j++) {
            if (h[j] > h[i]) {
                flag = false;
                break;
            }
        }
        if (flag)
            ans ++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef pair<int,char> P;

int main()
{
	string s;
	while(cin>>s,s!="#"){
	
		//notテ」ツ?佚」ツつε」ツ?ェテ」ツ??」ツ?ョテ」ツつ津・ツ?・テ」ツつ古」ツつ?notテ」ツ?ョテ」ツつ津・ツ?・テ」ツつ古」ツつ?
		set<char> sc1,sc2;
		bool ok=true;
		for(int i=0;i<s.size();i++){
			if(s[i]=='('){ok=true; sc1.clear(); sc2.clear();}
			if(s[i]==')' && ok) break;
			if('a'<=s[i] && s[i]<='z' || 'A'<=s[i] && s[i]<='Z'){
				if(s[i-1]=='~'){
				 if(sc1.find(s[i])!=sc1.end()) ok=false;
				 else sc2.insert(s[i]);
				}else{
					if(sc2.find(s[i])!=sc2.end()) ok=false;
					else sc1.insert(s[i]);
				}

			}
			
		}
	
		if(ok) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	
	}
	
	return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
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> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

double dp[3010][3010];
int main(){

    int n;
    cin >> n;
    vector<double> p(n);
    rep(i,n) cin >> p[i];
    dp[0][0] = 1;
    rep(i,n)rep(j,3010){
        dp[i+1][j] += dp[i][j]*(1-p[i]);
        dp[i+1][j+1] += dp[i][j]*p[i];
    }
    double ans = 0.;
    FOR(i,(n+1)/2,n+1) ans += dp[n][i];
    printf("%0.10f\n",ans);
    return 0;
}


Measured memory_bytes: 70784
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int w = kbd.nextInt();
	    int h = kbd.nextInt();
	    if(w!=0 && h!=0){
		solve(w, h);
	    }
	}
    }

    static void solve(int w, int h){
	int[][] field = new int[w][h];
	int i, j;
	for(i=0; i<h; i++){
	    for(j=0; j<w; j++){
		field[j][i] = kbd.nextInt();  // 0:海  1:陸
		//System.out.print(field[j][i]);
	    }
	    //System.out.println();
	}
	
	Stack[] s = new Stack[2];
	s[0] = new Stack(1000000);
	s[1] = new Stack(1000000);
	int count = 0;
	for(i=0; i<w; i++){
	    for(j=0; j<h; j++){
		int x = i;
		int y = j;
		if(field[x][y]==1) {
		    count++;
		    //System.out.println(x+" "+y);
		    search(s, field, x, y, w, h);
		    while(! (s[0].isEmpty() && s[1].isEmpty())){
			//System.out.println("＠"+x+" "+y);
			x = (Integer)s[0].pop();
			y = (Integer)s[1].pop();
			if(field[x][y]==1){
			    field[x][y] = -1; //通過済
			    search(s, field, x, y, w, h);
			}
		    }
		}
	    }
	}
	System.out.println(count);
    }

    static void search(Stack[] s, int[][]field, int x, int y, int w, int h){
	if(x+1<w && (field[x+1][y]==1)){      //右
	    if(!isExist(s, x+1, y)){
		s[0].push(x+1);
		s[1].push(y);
	    }
	}
	if(x-1>=0 && field[x-1][y]==1){   //左
	    if(!isExist(s, x-1, y)){
		s[0].push(x-1);
		s[1].push(y);
	    }
	}
	if(y+1<h && field[x][y+1]==1){    //上
	    if(!isExist(s, x, y+1)){
		s[0].push(x);
		s[1].push(y+1);
	    }
	}
	if(y-1>=0 && field[x][y-1]==1){    //下
	    if(!isExist(s, x, y-1)){
		s[0].push(x);
		s[1].push(y-1);
	    }
	}
	if(x+1<w && y+1<h && field[x+1][y+1]==1) { //右上
	    if(!isExist(s, x+1, y+1)){
		s[0].push(x+1);
		s[1].push(y+1);
	    }
	}
	if(x+1<w && y-1>=0 && field[x+1][y-1]==1) { //右下
	    if(!isExist(s, x+1, y-1)){
		s[0].push(x+1);
		s[1].push(y-1);
	    }
	}
	if(x-1>=0 && y+1<h && field[x-1][y+1]==1){  //左上
	    if(!isExist(s, x-1, y+1)){
		s[0].push(x-1);
		s[1].push(y+1);
	    }
	}
	if(x-1>=0 && y-1>=0 && field[x-1][y-1]==1){ //左下
	    if(!isExist(s, x-1, y-1)){
		s[0].push(x-1);
		s[1].push(y-1);
	    }
	}
    }

    static boolean isExist(Stack[] s, int x, int y){
	if(s[0].aru(x)!=-1 && s[0].aru(x) == s[1].aru(y)) return true;
	return false;
    }
}

class Stack{
    Object[] stack;
    int sp;
    public Stack(int n){
	stack = new Object[n];
	sp = 0;
    }
    public void push(Object x){
	stack[sp++] = x;
    }
    public Object pop(){
	return stack[--sp];
    }
    public boolean isEmpty(){
	return sp == 0;
    }
    public int aru(Object x){
	int i;
	for(i=0; stack[i]!=null; i++){
	    if(stack[i]==x) return i;
	}
	return -1;
    }
}

Measured memory_bytes: 98916
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int num1,num2,cnt,i,j,k,l,m,n,o,p,q;
	while(1){
		cnt = 0;
		scanf("%d %d",&num1,&num2);
		if (num1 == 0 && num2 == 0){
			break;
		}
		for(i = 0; i <= (10 - num1);i++){
			if (num1 == 1){
				if (i == num2){
					cnt++;
				}
			}
			for(j = i + 1;j <= (11 - num1);j++){
				if (num1 == 2){
					if ((i + j) == num2){
						cnt++;
					}
				}
				for(k = j + 1;k <= (12 - num1);k++){
					if (num1 == 3){
						if ((i + j + k) == num2){
							cnt++;
						}
					}
					for(l = k + 1;l <= (13 - num1);l++){
						if (num1 == 4){
							if((i + j + k + l) == num2){
								cnt++;
							}
						}
						for(m = l + 1;m <= (14 - num1);m++){
							if (num1 == 5){
								if ((i + j + k + l + m) == num2){
									cnt++;
								}
							}
							for(n = m + 1;n <= (15 - num1);n++){
								if (num1 == 6){
									if((i + j + k + l + m + n) == num2){
										cnt++;
									}
								}
								for(o = n + 1;o <= (16 - num1);o++){
									if (num1 == 7){
										if((i + j + k + l + m + n + o) == num2){
											cnt++;
										}
									}
									for(p = o + 1;p <= (17 - num1);p++){
										if (num1 == 8){
											if((i + j + k + l + m + n + o + p) == num2){
												cnt++;
											}
										}
										for(q = p + 1;q <= (18 - num1);q++){
											if (num1 == 9){
												if((i + j + k + l + m + n + o + p + q) == num2){
													cnt++;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

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

int main(){
    int N; cin >> N;
    ll ans = 0;
    map<int, int> M;
    int t;
    if(N % 2 == 1) t=0;
    else t=1;
    for(; t < N; t+=2){
        if(t == 0) M[t]++;
        else M[t]+=2;
    }
    for(int i = 0; i < N; i++){
        int x; cin >> x;
        M[x]--;
        if(M[x]<0){cout << 0 << endl; return 0;}
    }
    cout << modpow(2, N/2, MOD) << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<cmath>

using namespace std;

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

  string buf;
  getline(cin, buf);

  cout << ceil((float)(N - 1) / (float)(K - 1)) << endl;
  return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b >> c;

    cout << max({a*10+b+c, a+b*10+c, c*10+a+b}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 214748360

int main(){
  int n,m,s,p,q;
  while(cin>>n>>m>>s>>p>>q, n){
    s--;p--;q--;
    vector<vector<int>> d(n, vector<int>(n, INF));
    rep(i,m){
      int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      d[a][b] = c;
    }
    rep(i,n) d[i][i] = 0;
    rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

    int res = INF;
    rep(i,n) res = min(res, d[s][i]+d[i][p]+d[i][q]);

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 3048
import java.util.Scanner;

class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] T = new int[N];
        for (int i = 0; i < N; i++) {
            T[i] = in.nextInt();
        }
        int M = in.nextInt();
        int[] P = new int[M], X = new int[M];
        for (int i = 0; i < M; i++) {
            P[i] = in.nextInt();
            X[i] = in.nextInt();
        }

        for (int i = 0; i < M; i++) {
            int sum = 0;
            for (int j = 0; j < N; j++) {
                sum += j == P[i] - 1 ? X[i] : T[j];
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double area = r * r * Math.PI;
        double length = 2 * r * Math.PI;

        System.out.printf("%f %f",area,length);

    }
}



Measured memory_bytes: 28376
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, K, cnt;
char s[25][(1 << 20) + 5];
vector<int> v[25];
int dp[42000005];
int p0[25], p1[25];
int main()
{
	scanf("%d%d", &n, &K);
	for (int i = 0; i <= n; i++)
		scanf("%s", s[i]);
	for (int i = 1; i <= n; i++)
	{
		v[i].resize((i + 1) * (1 << i));
		int s = v[i].size();
		for (int j = 0; j < s; j++)
			v[i][j] = ++cnt;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < (1 << i); j++)
			if (s[i][j] == '1')
				dp[v[i][j * (i + 1) + i]]++;
    for (int i = n; i >= 1; i--)
	{
		for (int S = 0; S < (1 << i); S++)
		{
			p0[0] = -1, p1[0] = -1;
			for (int j = 0; j <= i; j++)
			{
				p1[j + 1] = p1[j];
				p0[j + 1] = p0[j];
				if (S & (1 << j))
					p1[j + 1] = j;
				else
					p0[j + 1] = j;
            }
			for (int j = i; j >= 0; j--)
			{
				int u = v[i][S * (i + 1) + j];
				int f = S >> j;
				if (dp[u])
				{
					if (p0[j] != -1)
					{
						int p = ((f << 1) << p0[j]) + (S & ((1 << p0[j]) - 1));
						int l = p0[j] + 1 + i - j;
						dp[v[l][p * (l + 1) + p0[j]]] += dp[u];
					}
                    if (p1[j] != -1)
					{
						int p = ((f << 1 | 1) << p1[j]) + (S & ((1 << p1[j]) - 1));
                        int l = p1[j] + 1 + i - j;
                        dp[v[l][p * (l + 1) + p1[j]]] += dp[u];
                    }
                    if (j != 0 && j != i)
					{
						int l = i - j;
						dp[v[l][f * (l + 1)]] += dp[u];
					}
				}
			}
		}
	}
	for (int i = n; i >= 1; i--)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			if (dp[v[i][j * (i + 1)]] >= K)
			{
				for (int k = i - 1; k >= 0; k--)
					putchar('0' + ((j >> k) & 1));
				putchar(10);
				return 0;
			}
		}
	}
	putchar(10);
}


Measured memory_bytes: 350592
#include <stdio.h>
#define N 10
 
int main( void ) {
  int i, j;
  int m[ N ];
  int ansI;
 
  for( i = 0; i < N; i++ )
    scanf( "%d", &m[ i ] );

  for( i = 0; i < 3; i++ ) {
    ansI = 0;
    for( j = 1; j < N; j++ ) {
      if( m[ ansI ] < m[ j ] ) {
        ansI = j;
      }
    }
    printf( "%d\n", m[ ansI ] );
    m[ ansI ] = 0;
  }

  return( 0 );
}

Measured memory_bytes: 0
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    char c;cin>>c;
    if('a'<=c && c<='z')cout<<"a\n";
    else cout<<"A\n";
}

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

long long modinv(long long n, long long p) {
  long long a = p, u = 1, v = 0;
  while (a) {
    long long t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  long long x, y, p = 1000000007;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if (x < (x + y) / 3 || y < (x + y) / 3) {
    cout << 0 << endl;
    return 0;
  }
  long long n = (x + y) / 3;
  long long r = min(x - (x + y) / 3, y - (x + y) / 3);
  long long ncr = 1;
  for (long long i = 0; i < r; i++) {
    ncr *= n - i;
    ncr %= p;
  }
  for (long long i = 0; i < r; i++) {
    ncr *= modinv(i + 1, p);
    ncr %= p;
  }
  cout << ncr % p << endl;
}

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

template<class M, class N>
constexpr common_type_t<M, N> gcd(M a, N b){
	if(a < b){
		common_type_t<M, N> tmp = a;
		a = b;
		b = tmp;
	}
	if(b==0) return a;
	else return gcd(b, a%b);
}

int main(void){
    long long n, ma = 0, poi = 0;
    cin >> n;
    vector<long long> a(n), rui(n+10), gyaku(n+10);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    //sort(a.begin(), a.end());
    long long tmp = a[0], now, ans=1;
    rui[0] = a[1];
    rui[1] = tmp;
    for(int i=1;i<n;++i){
        tmp = gcd(tmp, a[i]);
        rui[i+1] = tmp;
    }
    tmp = a[n-1];
    gyaku[n-1] = a[n-2];
    gyaku[n-2] = a[n-1];
    for(int i=n-2;i>0;--i){
        tmp = gcd(tmp, a[i]);
        gyaku[i-1] = tmp;
    }
    for(int i=0;i<n;++i){
        ma = max(ma, gcd(rui[i], gyaku[i]));
    }
    cout << ma << endl;
}

Measured memory_bytes: 2560
def main():
    N = int(input())
    B = list(int(x) for x in input().split())
    A = [0]*N

    for i in range(N-1):
        if i == 0:
            A[i] = B[i]
        elif B[i] < A[i]:
            A[i] = B[i]
        A[i+1] = B[i]
    print(sum(A))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

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

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll s=0;
		ll a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
			s+=a[i];
		}
		ll ans=0;
		for(int i=0;i<n-1;i++){
			s-=a[i];
			ans+=(a[i]*(s%mod))%mod;
			ans%=mod;
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 5220
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
mon = ([row[j:j+m] for row in a[i:i+m]]
      for i in range(n-m+1) for j in range(n-m+1))
print('Yes' if any(c == b for c in mon) else 'No')

Measured memory_bytes: 39152
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int h, w;
	cin >> h >> w;
	
	vector<string> a(h);
	for(int i = 0; i < h; ++i) {
		cin >> a[i];
	}
	
	vector< vector<int> > last(h);
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if( a[i][j] == '#' ) last[i].push_back(j);
		}
		
		if( last[i].size() == 0 ) last[i].push_back(100);
	}
	
	for(int i = 0; i < h - 1; ++i) {
		if( last[i].back() != 100 ) {
			if( last[i].back() > last[i + 1].front() ) {
				cout << "Impossible" << endl;
				return 0;
			}
		} else {
			if( last[i + 1].front() != 100 ) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	
	for(int i = 0; i < h - 1; ++i) {
		for(int j = 0; j < w - 1; ++j) {
			if( a[i][j] == '.') continue;
			
			if( a[i][j] == '#' ) {
				if( (a[i][j + 1] == '.' && a[i + 1][j] == '.') 
					|| (a[i][j + 1] == '#' && a[i + 1][j] == '#' && a[i + 1][j + 1] == '#' ) ) {
					cout << "Impossible" << endl;
					return 0;
				}
			}				
		}
	}
	
	cout << "Possible" << endl;
	
	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  string s; cin >> s;
  int n = s.size();

  rep(i,1,n) {
    if(s[i] == s[i-1]) {
      cout << i << " " << i+1 << endl;
      return 0;
    }
  }

  rep(i,2,n) {
    if(s[i] == s[i-2]) {
      cout << i-1 << " " << i+1 << endl;
      return 0;
    }
  }

  cout << "-1 -1" << endl;
}


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

typedef long long ll;

ll N;
ll R;

int main() {
  cin >> N;
  ll cnt = 0, prev = -1;
  for (ll i = 0; i < N; ++i) {
    ll h;
    cin >> h;
    if (prev < h) {
      cnt = 0;
    } else {
      ++cnt;
    }
    R = max(R, cnt);
    prev = h;
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#086 C Traveling
N =int(input())

List=[list(map(int,input().split())) for i in range(N)]
for i,l in enumerate(List):
    dt =List[i][0] - List[i-1][0]
    distance = abs(List[i][1] - List[i-1][1])+abs(List[i][2] - List[i-1][2])
        
    if i==0 and l[0] ==abs(l[1])+abs(l[2]):
        continue
    elif i==0 and l[0] !=abs(l[1])+abs(l[2]):
        print('No')
        exit()
    elif i!=0 and dt%2==distance%2 and distance<=dt:
        continue
    else:
        print('No')
        exit()
print('Yes')

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

ll n, ret;

void dfs(ll num, bool three, bool five, bool seven) {
	if (num > n) return ;
	if (three && five && seven) ret++;

	dfs(10 * num + 3, true, five, seven);
	dfs(10 * num + 5, three, true, seven);
	dfs(10 * num + 7, three, five, true);
	return ;
}

int main() {
	cin.tie(0)->sync_with_stdio(false);

	cin >> n;

	dfs(0, false, false, false);

	cout << ret << '\n';
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

template <typename T> inline T read(){
    T sum = 0;
    int fl = 1,ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') fl = -1;
    for(; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
    return sum * fl;
}

string s;

inline void Solve (){
	for(int i = 1; i <= s.size(); i += 2){
		if(s[i - 1] != 'R' && s[i - 1] != 'U' && s[i - 1] != 'D'){
			printf("No\n");
			return;
		}
	}
	for(int i = 2; i <= s.size(); i += 2){
		if(s[i - 1] != 'L' && s[i - 1] != 'U' && s[i - 1] != 'D'){
			printf("No\n");
			return;
		}
	}
	printf("Yes\n");
}

inline void Input (){
	cin >> s;
}

int main(){
	Input();
	Solve();
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define N 5555555
#define M 2020
using namespace std;

int vis[N];
vector<int> pri;

void sieve(int n) {
    for (int i = 2; i <= n; ++i) {
        if (!vis[i]) pri.push_back(i);
        for (int j : pri) {
            if (1ll * i * j > n) break;
            vis[i * j] = 1;
            if (i % j == 0) break;
        }
    }
}

long long a[M][M];
int n, top, p[2][M << 2];

long long lcm(long long x, long long y) {
    return x / __gcd(x, y) * y;
}

int get(int op, int x) {
    if (op) x += n;
    if (!p[op][x]) p[op][x] = pri[top++];
    return p[op][x];
}

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;

    if (n == 2) return puts("4 7\n23 10"), 0;

    sieve(10000);

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (!((i + j) & 1))
                a[i][j] = 1ll * pri[(i + j) / 2 - 1] * pri[n + (i - j) / 2 + (n + 1) / 2];

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (((i + j) & 1)) {
                a[i][j] = 1;
                if (i > 1) a[i][j] = lcm(a[i][j], a[i - 1][j]);
                if (j > 1) a[i][j] = lcm(a[i][j], a[i][j - 1]);
                if (i < n) a[i][j] = lcm(a[i][j], a[i + 1][j]);
                if (j < n) a[i][j] = lcm(a[i][j], a[i][j + 1]);
                ++a[i][j];
            }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            printf("%lld%c", a[i][j], " \n"[j == n]);

    return 0;
}


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

int arr[105];
int cnt = 0;
long long sum = 0;
bool add[105];

void dfs(int n) {
    if(n == cnt - 1) {
        long long cur = arr[0];
        for(int i = 0; i < n; i++) {
            if(add[i]) {
                sum += cur;
                cur = arr[i + 1];
            }
            else {
                cur = cur * 10 + arr[i + 1];
            }
        }
        sum += cur;
        return;
    }
    add[n] = true;
    dfs(n + 1);
    add[n] = false;
    dfs(n + 1);
}

int main()
{
    while(~scanf("%1d", &arr[cnt++]));
    cnt--;
    dfs(0);
    printf("%lld", sum);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  long long min=0;
  int A, B, C, K;
//  int sosu[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int cnt =0;
  int next_cnt = 0;
  int tmp_cnt =0;
  int tmp_next_cnt = 0;

//    int k=0;

  scanf("%d %d", &A, &B);
  //printf("%d\n", A);

 if(A>8 || B>8)      printf(":("); 
 else           printf("Yay!");      
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int a,b; cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0){
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256